@extends('backend.layouts.app')

@section('title')
    Edit Staff - Hotel Management System
@endsection

@section('content')
    <!-- Breadcrumb -->
    <div class="bg-white shadow-sm border-b border-gray-200 px-6 py-4">
        <div class="flex items-center justify-between">
            <div class="flex items-center text-sm text-gray-600">
                <i class="fas fa-home mr-2"></i>
                <span>/ Staff Section / <a href="{{ route('staff.index') }}" class="text-blue-600 hover:text-blue-800">Staff List</a> / Edit Staff</span>
            </div>
        </div>
    </div>

    <!-- Content -->
    <div class="p-6">
        @if($errors->any())
            <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
                <ul class="list-disc list-inside">
                    @foreach($errors->all() as $error)
                        <li>{{ $error }}</li>
                    @endforeach
                </ul>
            </div>
        @endif

        <div class="bg-white rounded-lg shadow-md">
            <div class="px-6 py-4 border-b border-gray-200">
                <h2 class="text-xl font-semibold text-gray-800">Edit Staff Member</h2>
                <p class="text-sm text-gray-600 mt-1">Editing: {{ $staff->first_name }} {{ $staff->last_name }}</p>
            </div>
            
            <form action="{{ route('staff.update', $staff) }}" method="POST" class="p-6">
                @csrf
                @method('PUT')
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                    <!-- First Name -->
                    <div>
                        <label for="first_name" class="block text-sm font-medium text-gray-700 mb-2">First Name *</label>
                        <input type="text" name="first_name" id="first_name" value="{{ old('first_name', $staff->first_name) }}" 
                               class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" required>
                    </div>

                    <!-- Last Name -->
                    <div>
                        <label for="last_name" class="block text-sm font-medium text-gray-700 mb-2">Last Name *</label>
                        <input type="text" name="last_name" id="last_name" value="{{ old('last_name', $staff->last_name) }}" 
                               class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" required>
                    </div>

                    <!-- Email -->
                    <div>
                        <label for="email" class="block text-sm font-medium text-gray-700 mb-2">Email *</label>
                        <input type="email" name="email" id="email" value="{{ old('email', $staff->email) }}" 
                               class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" required>
                    </div>

                    <!-- Contact Number -->
                    <div>
                        <label for="contact_no" class="block text-sm font-medium text-gray-700 mb-2">Contact Number *</label>
                        <input type="text" name="contact_no" id="contact_no" value="{{ old('contact_no', $staff->contact_no) }}" 
                               class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" required>
                    </div>

                    <!-- Staff Type -->
                    <div>
                        <label for="staff_type_id" class="block text-sm font-medium text-gray-700 mb-2">Staff Type *</label>
                        <select name="staff_type_id" id="staff_type_id" 
                                class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" required>
                            <option value="">Select Staff Type</option>
                            @foreach($staffTypes as $staffType)
                                <option value="{{ $staffType->staff_type_id }}" 
                                    {{ old('staff_type_id', $staff->staff_type_id) == $staffType->staff_type_id ? 'selected' : '' }}>
                                    {{ $staffType->staff_type }}
                                </option>
                            @endforeach
                        </select>
                    </div>

                    <!-- Role -->
                    <div>
                        <label for="role_id" class="block text-sm font-medium text-gray-700 mb-2">Role *</label>
                        <select name="role_id" id="role_id" 
                                class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" required>
                            <option value="">Select Role</option>
                            @foreach($roles as $role)
                                <option value="{{ $role->id }}" 
                                    {{ old('role_id', $staff->role_id) == $role->id ? 'selected' : '' }}>
                                    {{ $role->name }}
                                </option>
                            @endforeach
                        </select>
                    </div>

                    <!-- Shift -->
                    <div>
                        <label for="shift_id" class="block text-sm font-medium text-gray-700 mb-2">Shift *</label>
                        <select name="shift_id" id="shift_id" 
                                class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" required>
                            <option value="">Select Shift</option>
                            @foreach($shifts as $shift)
                                <option value="{{ $shift->shift_id }}" 
                                    {{ old('shift_id', $staff->shift_id) == $shift->shift_id ? 'selected' : '' }}>
                                    {{ $shift->shift_name }}
                                </option>
                            @endforeach
                        </select>
                    </div>

                    <!-- ID Card Type -->
                    <div>
                        <label for="id_card_type" class="block text-sm font-medium text-gray-700 mb-2">ID Card Type *</label>
                        <select name="id_card_type" id="id_card_type" 
                                class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" required>
                            <option value="">Select ID Card Type</option>
                            @foreach($idCardTypes as $idCardType)
                                <option value="{{ $idCardType->id_card_type_id }}" 
                                    {{ old('id_card_type', $staff->id_card_type) == $idCardType->id_card_type_id ? 'selected' : '' }}>
                                    {{ $idCardType->id_card_type }}
                                </option>
                            @endforeach
                        </select>
                    </div>

                    <!-- ID Card Number -->
                    <div>
                        <label for="id_card_no" class="block text-sm font-medium text-gray-700 mb-2">ID Card Number *</label>
                        <input type="text" name="id_card_no" id="id_card_no" value="{{ old('id_card_no', $staff->id_card_no) }}" 
                               class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" required>
                    </div>

                    <!-- Salary -->
                    <div>
                        <label for="salary" class="block text-sm font-medium text-gray-700 mb-2">Salary ({{ \App\Models\SiteSetting::getCurrency() }})</label>
                        <input type="number" name="salary" id="salary" value="{{ old('salary', $staff->salary) }}" step="0.01" min="0"
                               class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent">
                    </div>

                    <!-- Address -->
                    <div>
                        <label for="address" class="block text-sm font-medium text-gray-700 mb-2">Address *</label>
                        <input name="address" id="address" 
                                class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" value="{{ old('address', $staff->address) }}" required>
                    </div>

                    <!-- Username -->
                    <div>
                        <label for="username" class="block text-sm font-medium text-gray-700 mb-2">Username *</label>
                        <input type="text" name="username" id="username" value="{{ old('username', $staff->username) }}" 
                               placeholder="e.g., john.doe"
                               disabled
                               class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" required>
                    </div>

                    <div class="hidden">
                        <label for="username" class="block text-sm font-medium text-gray-700 mb-2">Username *</label>
                        <input type="text" name="username" id="username" value="{{ old('username', $staff->username) }}" 
                               placeholder="e.g., john.doe"
                               class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" required>
                    </div>

                    <!-- Password -->
                    <div>
                        <label for="password" class="block text-sm font-medium text-gray-700 mb-2">Password</label>
                        <input type="password" name="password" id="password" 
                               placeholder="Leave blank to keep current password"
                               class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent">
                        <p class="text-xs text-gray-500 mt-1">Leave blank to keep the current password</p>
                    </div>
                </div>

                <!-- Form Actions -->
                <div class="flex items-center justify-end space-x-3 mt-8 pt-6 border-t border-gray-200">
                    <a href="{{ route('staff.show', $staff) }}" class="bg-gray-300 hover:bg-gray-400 text-gray-800 px-6 py-2 rounded-lg transition-colors">
                        Cancel
                    </a>
                    <button type="submit" class="bg-blue-600 hover:bg-blue-700 text-white px-6 py-2 rounded-lg transition-colors">
                        <i class="fas fa-save mr-2"></i>Update Staff Member
                    </button>
                </div>
            </form>
        </div>
    </div>
@endsection 