@extends('layouts.app')

@section('title', 'Feedback')

@section('content')
<div class="page-content">
    <div class="container-fluid">
        <!-- Page Title -->
        <div class="row">
            <div class="col-12">
                <div class="page-title-box d-sm-flex align-items-center justify-content-between">
                    <h4 class="mb-sm-0">Feedback Management</h4>
                    <div class="page-title-right">
                        <ol class="breadcrumb m-0">
                            <li class="breadcrumb-item"><a href="{{ route('home') }}">Home</a></li>
                            <li class="breadcrumb-item active">Feedback</li>
                        </ol>
                    </div>
                </div>
            </div>
        </div>

        <!-- Statistics Card -->
        <div class="row mb-4">
            <div class="col-12">
                <div class="card border-0 shadow-sm" style="background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);">
                    <div class="card-body text-white p-4">
                        <div class="row align-items-center">
                            <div class="col-md-8">
                                <h4 class="mb-2">
                                    <i class="ri-feedback-line me-2"></i> User Feedback
                                </h4>
                                <p class="mb-0 opacity-75">View and manage all user feedback submissions.</p>
                            </div>
                            <div class="col-md-4 text-end">
                                <div class="d-flex align-items-center justify-content-end">
                                    <div class="me-3">
                                        <h2 class="mb-0">{{ $totalFeedbacks }}</h2>
                                        <small class="opacity-75">Total Feedbacks</small>
                                    </div>
                                    <i class="ri-feedback-line" style="font-size: 60px; opacity: 0.2;"></i>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12">
                <div class="card border-0 shadow-sm">
                    <div class="card-header bg-transparent border-bottom">
                        <div class="d-flex justify-content-between align-items-center">
                            <h5 class="card-title mb-0">
                                <i class="ri-feedback-line text-primary me-2"></i> All Feedbacks
                                <span class="badge bg-soft-primary text-primary ms-2">{{ $feedbacks->total() }}</span>
                            </h5>
                        </div>
                    </div>
                    <div class="card-body">
                        @if(session('success'))
                            <div class="alert alert-success alert-dismissible fade show" role="alert">
                                <i class="ri-check-line me-2"></i>{{ session('success') }}
                                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                            </div>
                        @endif

                        <div class="table-responsive">
                            <table class="table table-hover align-middle mb-0">
                                <thead class="table-light">
                                    <tr>
                                        <th style="width: 60px;">#</th>
                                        <th>Name</th>
                                        <th>Email</th>
                                        <th>Message</th>
                                        <th>Date</th>
                                        <th style="width: 120px;">Actions</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @forelse($feedbacks as $feedback)
                                    <tr class="table-row-hover">
                                        <td>
                                            <span class="badge bg-primary rounded-pill">{{ $feedback->id }}</span>
                                        </td>
                                        <td>
                                            <div class="d-flex align-items-center">
                                                <div class="flex-grow-1">
                                                    <h6 class="mb-0 fw-semibold">{{ $feedback->name }}</h6>
                                                </div>
                                            </div>
                                        </td>
                                        <td>
                                            <a href="mailto:{{ $feedback->email }}" class="text-decoration-none">
                                                <i class="ri-mail-line me-1"></i>{{ $feedback->email }}
                                            </a>
                                        </td>
                                        <td>
                                            <div class="text-truncate" style="max-width: 300px;" title="{{ $feedback->message }}">
                                                {{ Str::limit($feedback->message, 80) }}
                                            </div>
                                        </td>
                                        <td>
                                            <small class="text-muted">
                                                <i class="ri-calendar-line me-1"></i>
                                                {{ $feedback->created_at->format('M d, Y') }}<br>
                                                <i class="ri-time-line me-1"></i>
                                                {{ $feedback->created_at->format('h:i A') }}
                                            </small>
                                        </td>
                                        <td>
                                            <div class="d-flex gap-2">
                                                <a href="{{ route('feedback.show', $feedback->id) }}" class="btn btn-sm btn-primary rounded-pill" title="View Details">
                                                    <i class="ri-eye-line"></i>
                                                </a>
                                                <form action="{{ route('feedback.destroy', $feedback->id) }}" method="POST" class="d-inline" onsubmit="return confirm('Are you sure you want to delete this feedback?');">
                                                    @csrf
                                                    @method('DELETE')
                                                    <button type="submit" class="btn btn-sm btn-danger rounded-pill" title="Delete">
                                                        <i class="ri-delete-bin-line"></i>
                                                    </button>
                                                </form>
                                            </div>
                                        </td>
                                    </tr>
                                    @empty
                                    <tr>
                                        <td colspan="6" class="text-center py-5">
                                            <div class="text-muted">
                                                <i class="ri-inbox-line fs-1 d-block mb-2"></i>
                                                No feedback found
                                            </div>
                                        </td>
                                    </tr>
                                    @endforelse
                                </tbody>
                            </table>
                        </div>
                        
                        <!-- Pagination -->
                        @if($feedbacks->hasPages())
                        <div class="d-flex justify-content-between align-items-center mt-4 pt-3 border-top">
                            <div class="text-muted">
                                <span class="fw-semibold text-dark">Showing</span> 
                                <span class="fw-semibold text-primary">{{ $feedbacks->firstItem() ?? 0 }}</span> 
                                <span class="fw-semibold text-dark">to</span> 
                                <span class="fw-semibold text-primary">{{ $feedbacks->lastItem() ?? 0 }}</span> 
                                <span class="fw-semibold text-dark">of</span> 
                                <span class="fw-semibold text-primary">{{ $feedbacks->total() }}</span> 
                                <span class="fw-semibold text-dark">entries</span>
                            </div>
                            <div>
                                {{ $feedbacks->links() }}
                            </div>
                        </div>
                        @endif
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

@push('styles')
<style>
    .table-row-hover:hover {
        background-color: #f8f9fa;
        transition: background-color 0.2s ease;
    }
</style>
@endpush
@endsection

