@php
    $breadcrumbs = [
        ['label' => __('common.home'), 'url' => route('dashboard.index')],
        ['label' => __('common.hr')],
        ['label' => __('recruitment.candidates.title'), 'url' => route('hr.recruitment.candidates.index')],
        ['label' => __('recruitment.candidates.actions.edit')],
    ];
@endphp

<x-ui.layout.page
    :title="__('recruitment.candidates.actions.edit')"
    :subtitle="$candidate->reference_code"
    page-icon="fe fe-edit-2"
    :breadcrumbs="$breadcrumbs"
>
    @include('pages.hr.recruitment.candidates._form', [
        'action' => route('hr.recruitment.candidates.update', $candidate),
        'method' => 'PUT',
        'candidate' => $candidate,
        'submitLabel' => __('common.save'),
    ])

    <div class="card mt-4">
        <div class="card-header"><strong>{{ __('recruitment.cvs.title') }}</strong></div>
        <div class="card-body">
            <form method="POST" action="{{ route('hr.recruitment.candidates.cvs.store', $candidate) }}" enctype="multipart/form-data" class="row g-3 mb-4">
                @csrf
                <div class="col-md-5">
                    <x-ui.form.input name="file" type="file" :label="__('recruitment.cvs.fields.file')" required />
                </div>
                <div class="col-md-3">
                    <x-ui.form.input name="notes" :label="__('recruitment.cvs.fields.notes')" />
                </div>
                <div class="col-md-2 d-flex align-items-end">
                    <label class="form-check">
                        <input type="checkbox" name="is_primary" value="1" class="form-check-input">
                        <span class="form-check-label">{{ __('recruitment.cvs.fields.is_primary') }}</span>
                    </label>
                </div>
                <div class="col-md-2 d-flex align-items-end">
                    <x-ui.buttons.primary type="submit">{{ __('recruitment.cvs.upload') }}</x-ui.buttons.primary>
                </div>
            </form>

            <x-ui.table.table :columns="[
                ['label' => __('recruitment.cvs.fields.reference')],
                ['label' => __('recruitment.cvs.fields.original_name')],
                ['label' => __('recruitment.cvs.fields.is_primary')],
                ['label' => __('common.actions'), 'align' => 'end'],
            ]">
                @forelse ($cvs as $cv)
                    <x-ui.table.row>
                        <td><code>{{ $cv->reference_code }}</code></td>
                        <td>{{ $cv->original_name }}</td>
                        <td>{{ $cv->is_primary ? __('common.yes') : __('common.no') }}</td>
                        <td class="text-end">
                            <x-ui.buttons.secondary size="sm" :href="route('hr.recruitment.cvs.download', $cv)" icon="fe fe-download">
                                {{ __('recruitment.cvs.actions.download') }}
                            </x-ui.buttons.secondary>
                            @can('delete', $cv)
                                <form method="POST" action="{{ route('hr.recruitment.cvs.destroy', $cv) }}" class="d-inline">
                                    @csrf
                                    @method('DELETE')
                                    <x-ui.buttons.danger outline type="submit" size="sm">{{ __('common.delete') }}</x-ui.buttons.danger>
                                </form>
                            @endcan
                        </td>
                    </x-ui.table.row>
                @empty
                    <x-ui.table.row>
                        <td colspan="4" class="p-0">
                            <x-ui.operational.empty-state :title="__('recruitment.cvs.empty')" />
                        </td>
                    </x-ui.table.row>
                @endforelse
            </x-ui.table.table>
        </div>
    </div>
</x-ui.layout.page>
