@extends('layouts.seller')

@section('title', 'Manage Testimonials')

@section('content')
@section('content')
<div class="page-header">
    <div>
        <h4 class="page-title">Client Testimonials</h4>
        <p class="text-muted mb-0">Add reviews and testimonials to showcase on your microsite</p>
    </div>
    <a href="{{ route('seller.microsite.settings') }}" class="btn btn-light border shadow-sm">
        <i class="bi bi-arrow-left me-1"></i> Back to Settings
    </a>
</div>

@if(session('success'))
    <div class="alert alert-success alert-dismissible fade show border-0 shadow-sm" role="alert">
        <i class="bi bi-check-circle-fill me-2"></i>{{ session('success') }}
        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
    </div>
@endif

<div class="row g-4">
    <!-- Add New -->
    <div class="col-lg-4">
        <div class="card border-0 shadow-sm sticky-top" style="top: 100px;">
            <div class="card-header bg-white py-3 border-bottom">
                <h5 class="mb-0 fw-bold text-success"><i class="bi bi-plus-circle me-2"></i>Add Testimonial</h5>
            </div>
            <div class="card-body p-4">
                <form action="{{ route('seller.microsite.testimonials.store') }}" method="POST" enctype="multipart/form-data">
                    @csrf
                    <div class="mb-3">
                        <label class="form-label fw-bold">Client Name <span class="text-danger">*</span></label>
                        <input type="text" name="client_name" class="form-control" required maxlength="100" placeholder="John Doe">
                    </div>
                    <div class="mb-3">
                        <label class="form-label fw-bold">Company Name</label>
                        <input type="text" name="company_name" class="form-control" maxlength="100" placeholder="Acme Corp">
                    </div>
                    <div class="mb-3">
                        <label class="form-label fw-bold">Designation</label>
                        <input type="text" name="designation" class="form-control" maxlength="100" placeholder="e.g., CEO, Manager">
                    </div>
                    <div class="mb-3">
                        <label class="form-label fw-bold">Rating <span class="text-danger">*</span></label>
                        <select name="rating" class="form-select" required>
                            <option value="5">⭐⭐⭐⭐⭐ (5 stars)</option>
                            <option value="4">⭐⭐⭐⭐ (4 stars)</option>
                            <option value="3">⭐⭐⭐ (3 stars)</option>
                            <option value="2">⭐⭐ (2 stars)</option>
                            <option value="1">⭐ (1 star)</option>
                        </select>
                    </div>
                    <div class="mb-3">
                        <label class="form-label fw-bold">Review Message <span class="text-danger">*</span></label>
                        <textarea name="message" class="form-control" rows="4" required maxlength="500" 
                                  placeholder="Write the client's testimonial..."></textarea>
                    </div>
                    <div class="mb-4">
                        <label class="form-label fw-bold">Client Photo <small class="text-muted fw-normal">(Optional)</small></label>
                        <input type="file" name="image" class="form-control" accept="image/*">
                    </div>
                    <button type="submit" class="btn btn-primary-gradient w-100 py-2 fw-bold">
                        <i class="bi bi-plus-lg me-1"></i> Add Testimonial
                    </button>
                </form>
            </div>
        </div>
    </div>

    <!-- List -->
    <div class="col-lg-8">
        <div class="card border-0 shadow-sm">
            <div class="card-header bg-white py-3 border-bottom d-flex justify-content-between align-items-center">
                <h5 class="mb-0 fw-bold text-primary"><i class="bi bi-list-ul me-2"></i>All Testimonials <span class="badge bg-primary-subtle text-primary rounded-pill ms-2">{{ $testimonials->count() }}</span></h5>
            </div>
            <div class="card-body p-0">
                @forelse($testimonials as $item)
                    <div class="d-flex align-items-start p-4 border-bottom hover-bg transition-all">
                        @if($item->image)
                            <img src="{{ asset('storage/' . $item->image) }}" class="rounded-circle me-4 shadow-sm" 
                                 style="width: 64px; height: 64px; object-fit: cover;">
                        @else
                            <div class="rounded-circle bg-light d-flex align-items-center justify-content-center me-4 text-primary fw-bold shadow-sm border" 
                                 style="width: 64px; height: 64px; font-size: 1.5rem;">{{ substr($item->client_name, 0, 1) }}</div>
                        @endif
                        <div class="flex-grow-1">
                            <div class="d-flex justify-content-between align-items-start mb-2">
                                <div>
                                    <h6 class="fw-bold mb-1 text-dark">{{ $item->client_name }}</h6>
                                    <small class="text-muted d-block">{{ $item->designation }}{{ $item->company_name ? ' at ' . $item->company_name : '' }}</small>
                                </div>
                                <form action="{{ route('seller.microsite.testimonials.destroy', $item) }}" method="POST" 
                                      onsubmit="return confirm('Delete this testimonial?')">
                                    @csrf @method('DELETE')
                                    <button type="submit" class="btn btn-sm btn-outline-danger border-0" title="Delete"><i class="bi bi-trash"></i></button>
                                </form>
                            </div>
                            <div class="mb-2">
                                @for($i = 1; $i <= 5; $i++)
                                    <i class="bi bi-star-fill {{ $i <= $item->rating ? 'text-warning' : 'text-muted opacity-25' }} small"></i>
                                @endfor
                            </div>
                            <div class="bg-light p-3 rounded-3 fst-italic text-muted border-start border-4 border-primary">
                                "{{ $item->message }}"
                            </div>
                        </div>
                    </div>
                @empty
                    <div class="text-center py-5">
                        <div class="text-muted opacity-50 mb-3">
                            <i class="bi bi-chat-quote display-4"></i>
                        </div>
                        <h5 class="fw-bold text-muted">No testimonials yet</h5>
                        <p class="text-muted mb-0">Add your first client review to build trust.</p>
                    </div>
                @endforelse
            </div>
        </div>
    </div>
</div>

<style>
    .hover-bg:hover { background-color: #f8f9fa; }
    .transition-all { transition: all 0.2s ease; }
</style>
@endsection
