@props([
    'action',
    'method' => 'POST',
    'shift' => null,
    'submitLabel',
    'weekdayOptions',
])

@php
    $start = old('start_time', $shift ? substr((string) ($shift->getAttributes()['start_time'] ?? ''), 0, 5) : '09:00');
    $end = old('end_time', $shift ? substr((string) ($shift->getAttributes()['end_time'] ?? ''), 0, 5) : '17:00');
    $selectedDays = old('working_days', $shift?->working_days ?? [\App\Modules\HR\Shifts\Support\ShiftWeekday::MONDAY]);
@endphp

<form method="POST" action="{{ $action }}" novalidate>
    @csrf
    @if (strtoupper($method) !== 'POST')
        @method($method)
    @endif

    <div class="card">
        <div class="card-body">
            <div class="row g-3">
                <div class="col-md-6">
                    <x-ui.form.input name="name" :label="__('shifts.fields.name')" :value="old('name', $shift?->name)" required />
                </div>
                <div class="col-md-3">
                    <x-ui.form.input name="start_time" type="time" :label="__('shifts.fields.start_time')" :value="$start" required />
                </div>
                <div class="col-md-3">
                    <x-ui.form.input name="end_time" type="time" :label="__('shifts.fields.end_time')" :value="$end" required />
                </div>
                <div class="col-md-3">
                    <x-ui.form.input name="grace_minutes" type="number" :label="__('shifts.fields.grace_minutes')" :value="old('grace_minutes', $shift?->grace_minutes ?? 0)" />
                </div>
                <div class="col-md-3">
                    <x-ui.form.input name="late_after_minutes" type="number" :label="__('shifts.fields.late_after_minutes')" :value="old('late_after_minutes', $shift?->late_after_minutes ?? 0)" />
                </div>
                <div class="col-md-3">
                    <x-ui.form.input name="overtime_after_minutes" type="number" :label="__('shifts.fields.overtime_after_minutes')" :value="old('overtime_after_minutes', $shift?->overtime_after_minutes ?? 0)" />
                </div>
                <div class="col-md-3">
                    <x-ui.form.input name="break_minutes" type="number" :label="__('shifts.fields.break_minutes')" :value="old('break_minutes', $shift?->break_minutes ?? 0)" />
                </div>
                <div class="col-12">
                    <x-ui.form.checkbox-list
                        name="working_days"
                        :label="__('shifts.fields.working_days')"
                        :options="$weekdayOptions"
                        :selected="$selectedDays"
                        :columns="3"
                        required
                    />
                </div>
                <div class="col-12">
                    <x-ui.form.checkbox name="is_night_shift" :label="__('shifts.fields.is_night_shift')" :checked="old('is_night_shift', $shift?->is_night_shift)" />
                </div>
                <div class="col-12">
                    <x-ui.buttons.primary type="submit" icon="fe fe-save">
                        {{ $submitLabel }}
                    </x-ui.buttons.primary>
                </div>
            </div>
        </div>
    </div>
</form>
