@php
    $breadcrumbs = [
        ['label' => __('common.home'), 'url' => route('dashboard.index')],
        ['label' => __('common.hr')],
        ['label' => __('recruitment.interview_scorecards.title')],
    ];
    $interviewFilter = ['' => __('recruitment.filters.all')] + ($interviewOptions ?? []);
@endphp

<x-ui.layout.page
    :title="__('recruitment.interview_scorecards.title')"
    :subtitle="__('recruitment.interview_scorecards.subtitle')"
    page-icon="fe fe-check-square"
    :breadcrumbs="$breadcrumbs"
>
    <x-ui.operational.index-shell>
        <x-slot:toolbar>
            <x-ui.operational.action-bar>
                <x-slot:primary>
                    <x-ui.operational.create-button
                        :href="route('hr.recruitment.interview-scorecards.create')"
                        :label="__('recruitment.interview_scorecards.actions.add')"
                        permission="recruitment.create"
                    />
                </x-slot:primary>
            </x-ui.operational.action-bar>
        </x-slot:toolbar>

        <div class="card border-0 shadow-sm mb-4">
            <div class="card-body">
                <form method="GET" class="row g-3 align-items-end">
                    <div class="col-md-3">
                        <x-ui.form.input name="q" :label="__('recruitment.filters.search')" :value="request('q')" />
                    </div>
                    <div class="col-md-3">
                        <x-ui.form.select name="recommendation" :label="__('recruitment.interview_scorecards.fields.recommendation')" :options="$recommendationOptions" :selected="request('recommendation')" />
                    </div>
                    <div class="col-md-3">
                        <x-ui.form.select name="interview_id" :label="__('recruitment.interview_scorecards.fields.interview')" :options="$interviewFilter" :selected="request('interview_id')" />
                    </div>
                    <div class="col-md-2">
                        <x-ui.buttons.primary type="submit" icon="fe fe-filter">{{ __('recruitment.filters.apply') }}</x-ui.buttons.primary>
                    </div>
                </form>
            </div>
        </div>

        <form method="POST" action="{{ route('hr.recruitment.interview-scorecards.bulk-destroy') }}">
            @csrf
            @can('recruitment.manage')
                <div class="mb-2">
                    <x-ui.buttons.danger outline size="sm" type="submit">{{ __('recruitment.interview_scorecards.actions.bulk_delete') }}</x-ui.buttons.danger>
                </div>
            @endcan

            <x-ui.table.table :columns="[
                ['label' => '', 'width' => '36px'],
                ['label' => __('recruitment.interview_scorecards.fields.reference')],
                ['label' => __('recruitment.interview_scorecards.fields.interview')],
                ['label' => __('recruitment.interview_scorecards.fields.candidate')],
                ['label' => __('recruitment.interview_scorecards.fields.overall_score')],
                ['label' => __('recruitment.interview_scorecards.fields.recommendation')],
                ['label' => __('common.actions'), 'align' => 'end', 'width' => '180px'],
            ]">
                @forelse ($scorecards as $row)
                    <x-ui.table.row>
                        <td>
                            @can('delete', $row)
                                <input type="checkbox" name="ids[]" value="{{ $row->id }}" class="form-check-input">
                            @endcan
                        </td>
                        <td><code>{{ $row->reference_code }}</code></td>
                        <td>{{ $row->interview?->reference_code ?? '—' }}</td>
                        <td><strong>{{ $row->interview?->application?->candidate?->full_name ?? '—' }}</strong></td>
                        <td>{{ $row->overall_score }}</td>
                        <td>
                            <x-ui.operational.status-badge :label="__('recruitment.interview_scorecards.recommendation.'.$row->recommendation)" variant="neutral" />
                        </td>
                        <td class="text-end">
                            @can('update', $row)
                                <x-ui.buttons.secondary size="sm" :href="route('hr.recruitment.interview-scorecards.edit', $row)">{{ __('common.edit') }}</x-ui.buttons.secondary>
                            @endcan
                            @can('delete', $row)
                                <form method="POST" action="{{ route('hr.recruitment.interview-scorecards.destroy', $row) }}" class="d-inline">
                                    @csrf @method('DELETE')
                                    <x-ui.buttons.danger outline size="sm" type="submit">{{ __('common.delete') }}</x-ui.buttons.danger>
                                </form>
                            @endcan
                        </td>
                    </x-ui.table.row>
                @empty
                    <x-ui.table.row>
                        <td colspan="7" class="p-0"><x-ui.operational.empty-state :title="__('recruitment.interview_scorecards.empty')" /></td>
                    </x-ui.table.row>
                @endforelse
            </x-ui.table.table>
        </form>

        <x-slot:pagination>
            @if ($scorecards->hasPages())
                <div class="d-flex justify-content-center">{{ $scorecards->links() }}</div>
            @endif
        </x-slot:pagination>
    </x-ui.operational.index-shell>
</x-ui.layout.page>
