@extends('layouts.app')

@push('styles')
<link rel="stylesheet" href="{{ asset('css/adminHeader.css') }}">
<link rel="stylesheet" href="{{ asset('css/ulasanAdmin.css') }}">
@endpush

@section('content')
<div class="container">
    {{-- Header --}}
    <div class="admin-header-box">
        <div>
            <h4>Nota Post-Mortem</h4>
            <p>Klik kad untuk baca ulasan penuh.</p>
        </div>

        <div class="d-flex gap-2 align-items-center">
            <a href="{{ route('admin.surveys.ulasan.export') }}" class="btn btn-sm btn-success rounded-pill px-3 fw-bold me-2">
                <i class="bi bi-file-earmark-excel me-1"></i> Export
            </a>

            {{-- Search Form --}}
            <form method="GET" action="{{ route('admin.surveys.ulasan') }}" class="d-flex gap-2 mb-0">
                <div class="input-group input-group-sm">
                    <input type="text" name="search" value="{{ request('search') }}" class="form-control rounded-pill px-3" placeholder="Cari tajuk..." style="width: 200px;">
                    <button class="btn btn-light rounded-circle ms-1 p-1 d-flex align-items-center justify-content-center" type="submit" style="width: 30px; height: 30px;">
                        <i class="bi bi-search text-primary"></i>
                    </button>
                    @if(request('search'))
                        <a href="{{ route('admin.surveys.ulasan') }}" class="btn btn-light rounded-circle ms-1 p-1 d-flex align-items-center justify-content-center" style="width: 30px; height: 30px;">
                            <i class="bi bi-x-lg text-danger"></i>
                        </a>
                    @endif
                </div>
            </form>

            <a href="{{ route('admin.surveys.index') }}" class="btn btn-sm btn-light rounded-pill px-3 fw-bold text-primary">
                <i class="bi bi-arrow-left me-1"></i> Kembali
            </a>
        </div>
    </div>

    <div class="row g-3">
        @forelse($surveys as $survey)
            <div class="col-6 col-md-4 col-lg-3 mb-2">
                <div class="card h-100 border-0 shadow-sm rounded-4 position-relative overflow-hidden cursor-pointer ulasan-hover-effect"
                     data-bs-toggle="modal"
                     data-bs-target="#ulasanModal{{ $survey->id }}"
                     style="cursor: pointer; background: #ffffff;">

                    <div class="position-absolute top-0 start-0 h-100 bg-primary-subtle" style="width: 3px;"></div>

                    <div class="card-body p-3">
                        <div class="d-flex justify-content-between mb-2">
                            <small class="text-primary fw-bold" style="font-size: 0.65rem;">#{{ $survey->id }}</small>
                            <small class="text-muted" style="font-size: 0.65rem;">{{ $survey->updated_at->format('d/m/y') }}</small>
                        </div>

                        <h6 class="fw-bold text-dark mb-2 text-truncate" style="text-transform: uppercase; font-size: 0.9rem;">
                            {{ $survey->title }}
                        </h6>

                        <div class="p-2 rounded-3" style="background-color: #f8f9fa;">
                            <p class="text-secondary mb-0" style="font-size: 0.75rem; line-height: 1.4;">
                                {{ Str::limit($survey->ulasan, 60) }}
                                @if(strlen($survey->ulasan) > 60)
                                    <span class="text-primary fw-bold" style="font-size: 0.7rem;">...more</span>
                                @endif
                            </p>
                        </div>
                    </div>
                </div>
            </div>

            {{-- MODAL UNTUK AYAT PENUH --}}
            <div class="modal fade" id="ulasanModal{{ $survey->id }}" tabindex="-1" aria-hidden="true">
                <div class="modal-dialog modal-dialog-centered">
                    <div class="modal-content border-0 rounded-4 shadow">
                        <div class="modal-header border-0 pb-0">
                            <h6 class="modal-title fw-bold text-primary">Ulasan Penuh</h6>
                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                        </div>
                        <div class="modal-body pt-2">
                            <p class="text-muted small mb-1">Tajuk Borang:</p>
                            <h6 class="fw-bold mb-3">{{ $survey->title }}</h6>
                            <hr class="opacity-10">
                            <p class="text-dark" style="white-space: pre-line; line-height: 1.6; font-size: 0.9rem;">
                                {{ $survey->ulasan }}
                            </p>
                        </div>
                        <div class="modal-footer border-0 pt-0">
                            <small class="text-muted me-auto" style="font-size: 0.7rem;">Oleh: {{ $survey->user->name ?? 'Admin' }}</small>
                            <button type="button" class="btn btn-sm btn-secondary rounded-pill px-3" data-bs-dismiss="modal">Tutup</button>
                        </div>
                    </div>
                </div>
            </div>

        @empty
            <div class="col-12 text-center py-5">
                <p class="text-muted small">Tiada ulasan ditemui.</p>
            </div>
        @endforelse
    </div>
</div>
@endsection
