@extends('admin.layouts.app')

@section('title', 'Student Success Stories')

@section('content')
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="d-flex justify-content-between align-items-center mb-4">
                <h1 class="h3 mb-0 text-gray-800">Student Success Stories</h1>
                <a href="{{ route('admin.testimonials.edit') }}" class="btn btn-primary">
                    <i class="fas fa-edit"></i> Edit Testimonials
                </a>
            </div>

            @if(session('success'))
                <div class="alert alert-success alert-dismissible fade show" role="alert">
                    {{ session('success') }}
                    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                </div>
            @endif

            @if(session('error'))
                <div class="alert alert-danger alert-dismissible fade show" role="alert">
                    {{ session('error') }}
                    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                </div>
            @endif

            <div class="card shadow mb-4">
                <div class="card-header py-3">
                    <h6 class="m-0 font-weight-bold text-primary">Section Information</h6>
                </div>
                <div class="card-body">
                    @if($testimonialsSection)
                        <div class="row">
                            <div class="col-md-6">
                                <h5>Title:</h5>
                                <p class="text-muted">{{ $testimonialsSection->title ?? 'Not set' }}</p>
                            </div>
                            <div class="col-md-6">
                                <h5>Description:</h5>
                                <p class="text-muted">{{ $testimonialsSection->content ?? 'Not set' }}</p>
                            </div>
                        </div>
                        <div class="row mt-3">
                            <div class="col-md-6">
                                <h5>Status:</h5>
                                <span class="badge {{ $testimonialsSection->is_active ? 'bg-success' : 'bg-secondary' }}">
                                    {{ $testimonialsSection->is_active ? 'Active' : 'Inactive' }}
                                </span>
                            </div>
                            <div class="col-md-6">
                                <h5>Total Testimonials:</h5>
                                <span class="badge bg-info">
                                    {{ $testimonialsSection->data && isset($testimonialsSection->data['testimonials']) ? count($testimonialsSection->data['testimonials']) : 0 }}
                                </span>
                            </div>
                        </div>
                    @else
                        <p class="text-muted">No testimonials section found. Please create one first.</p>
                    @endif
                </div>
            </div>

            @if($testimonialsSection && $testimonialsSection->data && isset($testimonialsSection->data['testimonials']))
                <div class="card shadow">
                    <div class="card-header py-3">
                        <h6 class="m-0 font-weight-bold text-primary">Current Testimonials</h6>
                    </div>
                    <div class="card-body">
                        @if(count($testimonialsSection->data['testimonials']) > 0)
                            <div class="row">
                                @foreach($testimonialsSection->data['testimonials'] as $index => $testimonial)
                                    <div class="col-md-6 col-lg-4 mb-4">
                                        <div class="card h-100 border-left-primary">
                                            <div class="card-body">
                                                <div class="d-flex justify-content-between align-items-start mb-2">
                                                    <h6 class="card-title text-primary mb-0">{{ $testimonial['name'] ?? 'Unknown' }}</h6>
                                                    <div class="text-warning">
                                                        @for($i = 1; $i <= 5; $i++)
                                                            @if($i <= ($testimonial['rating'] ?? 0))
                                                                <i class="fas fa-star"></i>
                                                            @else
                                                                <i class="far fa-star"></i>
                                                            @endif
                                                        @endfor
                                                    </div>
                                                </div>
                                                <p class="card-subtitle mb-2 text-muted small">{{ $testimonial['position'] ?? 'No position' }}</p>
                                                <p class="card-text small">{{ Str::limit($testimonial['message'] ?? 'No message', 100) }}</p>
                                            </div>
                                        </div>
                                    </div>
                                @endforeach
                            </div>
                        @else
                            <p class="text-muted text-center py-4">No testimonials found. <a href="{{ route('admin.testimonials.edit') }}">Add some testimonials</a> to get started.</p>
                        @endif
                    </div>
                </div>
            @endif
        </div>
    </div>
</div>
@endsection