@extends('layouts.app')

@section('title', 'Add Offboarding')
@section('heading', 'Add Offboarding')

@section('content')
    <x-card class="max-w-3xl">
        <form action="{{ route('offboardings.store') }}" method="POST" class="space-y-6" novalidate data-offboarding-form="create">
            @csrf
            <div class="grid gap-4 sm:grid-cols-2">
                <div>
                    <label class="block text-sm font-medium text-slate-700">Employee <span class="text-red-500">*</span></label>
                    <select name="user_id" class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2 js-select2">
                        <option value="">Select</option>
                        @foreach($users as $u)<option value="{{ $u->id }}" {{ old('user_id') == $u->id ? 'selected' : '' }}>{{ $u->name }}</option>@endforeach
                    </select>
                    @error('user_id')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
                    <p data-js-error="user_id" class="mt-1 text-sm text-red-600 hidden"></p>
                </div>
                <div>
                    <label class="block text-sm font-medium text-slate-700">Offboarding Date <span class="text-red-500">*</span></label>
                    <input type="date" name="offboarding_date" value="{{ old('offboarding_date', date('Y-m-d')) }}" class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2">
                    @error('offboarding_date')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
                    <p data-js-error="offboarding_date" class="mt-1 text-sm text-red-600 hidden"></p>
                </div>
                <div>
                    <label class="block text-sm font-medium text-slate-700">Last working day</label>
                    <input type="date" name="last_working_date" value="{{ old('last_working_date') }}" class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2">
                    @error('last_working_date')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
                </div>
                <div>
                    <label class="block text-sm font-medium text-slate-700">Notice period (days)</label>
                    <input type="number" name="notice_period_days" min="0" max="180" value="{{ old('notice_period_days', 30) }}" class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2">
                </div>
                <div>
                    <label class="block text-sm font-medium text-slate-700">Type <span class="text-red-500">*</span></label>
                    <select name="type" class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2 js-select2">
                        <option value="resignation" {{ old('type') === 'resignation' ? 'selected' : '' }}>Resignation</option>
                        <option value="termination" {{ old('type') === 'termination' ? 'selected' : '' }}>Termination</option>
                        <option value="retirement" {{ old('type') === 'retirement' ? 'selected' : '' }}>Retirement</option>
                        <option value="contract_end" {{ old('type') === 'contract_end' ? 'selected' : '' }}>Contract End</option>
                        <option value="other" {{ old('type') === 'other' ? 'selected' : '' }}>Other</option>
                    </select>
                    @error('type')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
                    <p data-js-error="type" class="mt-1 text-sm text-red-600 hidden"></p>
                </div>
                <div class="sm:col-span-2">
                    <label class="block text-sm font-medium text-slate-700">Reason</label>
                    <textarea name="reason" rows="2" class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2">{{ old('reason') }}</textarea>
                    @error('reason')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
                    <p data-js-error="reason" class="mt-1 text-sm text-red-600 hidden"></p>
                </div>
                <div class="sm:col-span-2">
                    <label class="block text-sm font-medium text-slate-700">Notes</label>
                    <textarea name="notes" rows="2" class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2">{{ old('notes') }}</textarea>
                    @error('notes')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
                    <p data-js-error="notes" class="mt-1 text-sm text-red-600 hidden"></p>
                </div>
            </div>
            <div class="flex gap-2">
                <x-button type="submit" variant="primary">Start offboarding</x-button>
                <a href="{{ route('offboardings.index') }}" class="inline-flex items-center rounded-lg bg-slate-100 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-200">Cancel</a>
            </div>
        </form>
    </x-card>
@endsection

@push('scripts')
<script src="{{ asset('js/form-validation.js') }}"></script>
<script src="{{ asset('js/form-text-rules.js') }}"></script>
<script src="{{ asset('js/hr-lifecycle-form-validation.js') }}"></script>
@endpush
