<x-app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            {{ __('Edit Department') }}: {{ $department->name }}
        </h2>
    </x-slot>

    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6 text-gray-900">
                    <form action="{{ route('departments.update', $department) }}" method="POST">
                        @csrf
                        @method('PATCH')
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                            <div class="mb-4">
                                <x-input-label for="code" :value="__('Code')" />
                                <x-text-input id="code" class="block mt-1 w-full" type="text" name="code" :value="old('code', $department->code)" required />
                                <x-input-error :messages="$errors->get('code')" class="mt-2" />
                            </div>

                            <div class="mb-4">
                                <x-input-label for="name" :value="__('Name')" />
                                <x-text-input id="name" class="block mt-1 w-full" type="text" name="name" :value="old('name', $department->name)" required />
                                <x-input-error :messages="$errors->get('name')" class="mt-2" />
                            </div>

                            <div class="mb-4">
                                <x-input-label for="shift_start" :value="__('Shift Start')" />
                                <x-text-input id="shift_start" class="block mt-1 w-full" type="time" name="shift_start" :value="old('shift_start', \Carbon\Carbon::parse($department->shift_start)->format('H:i'))" required />
                                <x-input-error :messages="$errors->get('shift_start')" class="mt-2" />
                            </div>

                            <div class="mb-4">
                                <x-input-label for="shift_end" :value="__('Shift End')" />
                                <x-text-input id="shift_end" class="block mt-1 w-full" type="time" name="shift_end" :value="old('shift_end', \Carbon\Carbon::parse($department->shift_end)->format('H:i'))" required />
                                <x-input-error :messages="$errors->get('shift_end')" class="mt-2" />
                            </div>

                            <div class="mb-4">
                                <x-input-label for="grace_period" :value="__('Grace Period (Minutes)')" />
                                <x-text-input id="grace_period" class="block mt-1 w-full" type="number" name="grace_period" :value="old('grace_period', $department->grace_period)" required />
                                <x-input-error :messages="$errors->get('grace_period')" class="mt-2" />
                            </div>

                            <div class="mb-4 md:col-span-2">
                                <x-input-label for="description" :value="__('Description')" />
                                <textarea id="description" name="description" class="block mt-1 w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm" rows="3">{{ old('description', $department->description) }}</textarea>
                                <x-input-error :messages="$errors->get('description')" class="mt-2" />
                            </div>

                            <div class="mb-4">
                                <label for="active" class="inline-flex items-center">
                                    <input id="active" type="checkbox" name="active" value="1" {{ old('active', $department->active) ? 'checked' : '' }} class="rounded border-gray-300 text-indigo-600 shadow-sm focus:ring-indigo-500">
                                    <span class="ml-2 text-sm text-gray-600">{{ __('Active') }}</span>
                                </label>
                            </div>
                        </div>

                        <div class="flex items-center justify-end mt-4">
                            <a href="{{ route('departments.index') }}" class="mr-4 text-sm text-gray-600 hover:text-gray-900">Cancel</a>
                            <x-primary-button>
                                {{ __('Update Department') }}
                            </x-primary-button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</x-app-layout>