@extends('layouts.app')

@section('title', 'Edit Termination')
@section('heading', 'Edit Termination')

@section('content')
    @include('hr.top-submenu')
    <x-card class="max-w-3xl">
        <form action="{{ route('terminations.update', $termination) }}" method="POST" class="space-y-6" novalidate data-termination-form="edit">
            @csrf
            @method('PUT')
            <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">
                        @foreach($users as $u)<option value="{{ $u->id }}" {{ old('user_id', $termination->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">Termination Date <span class="text-red-500">*</span></label>
                    <input type="date" name="termination_date" value="{{ old('termination_date', $termination->termination_date?->format('Y-m-d')) }}" class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2">
                    @error('termination_date')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
                    <p data-js-error="termination_date" class="mt-1 text-sm text-red-600 hidden"></p>
                </div>
                <div>
                    <label class="block text-sm font-medium text-slate-700">Reason Type</label>
                    <input type="text" name="reason_type" value="{{ old('reason_type', $termination->reason_type) }}" class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2">
                    @error('reason_type')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
                    <p data-js-error="reason_type" class="mt-1 text-sm text-red-600 hidden"></p>
                </div>
                <div>
                    <label class="block text-sm font-medium text-slate-700">Status</label>
                    <select name="status" class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2 js-select2">
                        <option value="active" {{ old('status', $termination->status) === 'active' ? 'selected' : '' }}>Active</option>
                        <option value="inactive" {{ old('status', $termination->status) === 'inactive' ? 'selected' : '' }}>Inactive</option>
                    </select>
                </div>
                <div class="sm:col-span-2">
                    <label class="block text-sm font-medium text-slate-700">Reason</label>
                    <textarea name="reason" rows="3" class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2">{{ old('reason', $termination->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', $termination->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">
                <button type="submit" class="rounded-lg bg-primary px-4 py-2 text-sm font-medium text-white">Update</button>
                <a href="{{ route('terminations.index') }}" class="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
