<x-ui.layout.page :title="__('attendance.holidays.title')" page-icon="fe fe-calendar">
    <x-ui.operational.index-shell>
        <x-slot:toolbar>
            @can('attendance.manage')
            <form method="POST" action="{{ $editing ? route('hr.attendance.holidays.update', $editing) : route('hr.attendance.holidays.store') }}" class="row g-2">
                @csrf
                @if ($editing) @method('PUT') @endif
                <div class="col-md-4">
                    <input class="form-control" name="name" required value="{{ old('name', $editing?->name) }}" placeholder="{{ __('attendance.holidays.name') }}">
                </div>
                <div class="col-md-3">
                    <input class="form-control" type="date" name="date" required value="{{ old('date', $editing?->date?->format('Y-m-d')) }}">
                </div>
                <div class="col-md-3 form-check pt-2">
                    <input type="hidden" name="is_active" value="1">
                    <input class="form-check-input" type="checkbox" name="is_recurring_yearly" value="1" @checked(old('is_recurring_yearly', $editing?->is_recurring_yearly))>
                    <label class="form-check-label">{{ __('attendance.holidays.recurring') }}</label>
                </div>
                <div class="col-md-2">
                    <x-ui.buttons.primary type="submit">{{ __('common.save') }}</x-ui.buttons.primary>
                </div>
            </form>
            @endcan
        </x-slot:toolbar>

        <x-ui.table.table :columns="[
            ['label' => __('attendance.holidays.name')],
            ['label' => __('attendance.holidays.date')],
            ['label' => __('attendance.holidays.recurring')],
            ['label' => __('common.actions'), 'align' => 'end'],
        ]">
            @forelse ($holidays as $holiday)
                <x-ui.table.row>
                    <td>{{ $holiday->name }}</td>
                    <td>{{ $holiday->date->format('Y-m-d') }}</td>
                    <td>{{ $holiday->is_recurring_yearly ? __('common.yes') : __('common.no') }}</td>
                    <td class="text-end">
                        @can('attendance.manage')
                        <x-ui.buttons.secondary size="sm" :href="route('hr.attendance.holidays.index', ['edit' => $holiday->id])">
                            {{ __('common.edit') }}
                        </x-ui.buttons.secondary>
                        <form method="POST" action="{{ route('hr.attendance.holidays.destroy', $holiday) }}">
                            @csrf @method('DELETE')
                            <x-ui.buttons.danger 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">{{ __('common.no_results') }}</td></x-ui.table.row>
            @endforelse
        </x-ui.table.table>
        <x-slot:pagination>{{ $holidays->links() }}</x-slot:pagination>
    </x-ui.operational.index-shell>
</x-ui.layout.page>
