@extends('layouts.app')

@section('title', 'Form Submissions')
@section('heading', 'Form Submissions')

@section('content')
@include('documents.top-submenu')
    <x-card>
        <div class="mb-4 flex flex-wrap items-center justify-between gap-3">
            <p class="text-slate-600">Review employee form responses.</p>
            <div class="flex flex-wrap gap-3">
                <a href="{{ route('form-submissions.export', request()->only('form_id')) }}" class="rounded-lg border border-slate-300 px-3 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50">Export CSV</a>
                <a href="{{ route('forms.portal') }}" class="text-sm text-primary hover:underline self-center">Employee portal</a>
            </div>
        </div>

        <form method="get" class="mb-4 flex flex-nowrap gap-3 justify-end">
            <select name="form_id" class="rounded-lg border border-slate-300 px-3 py-2 text-sm js-select2" style="width: 120px;">
                <option value="">All forms</option>
                @foreach($forms as $form)
                    <option value="{{ $form->id }}" {{ request('form_id') == $form->id ? 'selected' : '' }}>{{ $form->name }}</option>
                @endforeach
            </select>
            <button type="submit" class="rounded-lg bg-slate-800 px-3 py-2 text-sm font-medium text-white">Filter</button>
        </form>

        <x-table>
            <x-slot name="head">
                <tr>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Form</th>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Employee</th>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Submitted</th>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Actions</th>
                </tr>
            </x-slot>
            @forelse($submissions as $submission)
                <tr>
                    <td class="px-4 py-3 text-sm text-slate-900">{{ $submission->form?->name }}</td>
                    <td class="px-4 py-3 text-sm text-slate-600">{{ $submission->user?->name }}</td>
                    <td class="px-4 py-3 text-sm text-slate-600">{{ $submission->created_at?->format('d M Y H:i') }}</td>
                    <td class="px-4 py-3 text-sm">
                        <a href="{{ route('form-submissions.show', $submission) }}" class="btn-icon-action btn-icon-action--view" title="View" aria-label="View"><i class="bi bi-eye"></i></a>
                    </td>
                </tr>
            @empty
                <tr><td colspan="4" class="px-4 py-8 text-center text-sm text-slate-500">No submissions yet.</td></tr>
            @endforelse
        </x-table>
        @if($submissions->hasPages())<div class="mt-4">{{ $submissions->links() }}</div>@endif
    </x-card>
@endsection
