@extends('layouts.app')
@section('title', 'Inquiries')
@section('page_title', 'Admission Inquiries')
@section('breadcrumbs')
    <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">Home</a></li>
    <li class="breadcrumb-item active">Inquiries</li>
@endsection
@section('page_actions')
    @can('create', App\Models\Inquiry::class)
        <a href="{{ route('inquiries.create') }}" class="btn btn-primary"><i class="bi bi-plus-lg me-1"></i>New Inquiry</a>
    @endcan
@endsection

@section('content')
    <div class="card">
        <div class="card-header"><i class="bi bi-chat-left-dots me-1"></i>Inquiries ({{ $inquiries->count() }})</div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-hover align-middle js-datatable">
                    <thead><tr><th>#</th><th>Student</th><th>Parent</th><th>Contact</th><th>Class</th><th>Follow-up</th><th>Status</th><th class="text-end">Actions</th></tr></thead>
                    <tbody>
                        @foreach($inquiries as $inq)
                            <tr>
                                <td class="small">{{ $inq->inquiry_number }}</td>
                                <td class="fw-semibold">{{ $inq->student_name }}</td>
                                <td>{{ $inq->parent_name ?: '—' }}</td>
                                <td>{{ $inq->contact }}</td>
                                <td class="small">{{ $inq->schoolClass?->name ?? '—' }}</td>
                                <td class="small">{{ optional($inq->follow_up_date)->format('d M Y') ?? '—' }}</td>
                                <td><span class="badge bg-soft-{{ $inq->status_color }} text-capitalize">{{ $inq->status }}</span></td>
                                <td class="text-end">
                                    @can('update', $inq)
                                        <a href="{{ route('inquiries.edit', $inq) }}" class="btn btn-sm btn-light border"><i class="bi bi-pencil"></i></a>
                                        @if($inq->status !== 'converted')
                                            <form method="POST" action="{{ route('inquiries.convert', $inq) }}" class="d-inline" data-confirm="Convert this inquiry to an admission application?">
                                                @csrf <button class="btn btn-sm btn-outline-primary" title="Convert to admission"><i class="bi bi-arrow-right-circle me-1"></i>Convert</button>
                                            </form>
                                        @endif
                                    @endcan
                                    @can('delete', $inq)
                                        <form method="POST" action="{{ route('inquiries.destroy', $inq) }}" class="d-inline" data-confirm="Delete inquiry?">
                                            @csrf @method('DELETE')<button class="btn btn-sm btn-light border text-danger"><i class="bi bi-trash"></i></button>
                                        </form>
                                    @endcan
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        </div>
    </div>
@endsection
