@extends('layouts.app')

@section('title', 'Create Employee Record')

@section('content')
<div class="max-w-4xl mx-auto space-y-6">

    <div class="flex items-center justify-between">
        <div>
            <h1 class="text-xl font-bold text-slate-900 dark:text-white">Create Employee Master Record</h1>
            <p class="text-xs text-slate-500 dark:text-slate-400">Add employee personal, employment, and compliance details.</p>
        </div>
        <a href="{{ route('app.employees.index') }}" class="px-4 py-2 bg-slate-200 dark:bg-slate-700 text-slate-700 dark:text-slate-200 font-semibold text-xs rounded-xl">Back to Directory</a>
    </div>

    <form action="{{ route('app.employees.store') }}" method="POST" class="space-y-6">
        @csrf

        <div class="bg-white dark:bg-slate-800 rounded-3xl p-6 border border-slate-200 dark:border-slate-700/60 shadow-sm space-y-4">
            <h3 class="text-sm font-bold text-slate-900 dark:text-white uppercase tracking-wider">Employee Information</h3>

            <div class="grid grid-cols-1 md:grid-cols-2 gap-4 text-xs">
                <div>
                    <label for="employee_code" class="block font-semibold text-slate-700 dark:text-slate-300 mb-1">Employee Code *</label>
                    <input type="text" name="employee_code" id="employee_code" required value="EMP-{{ rand(100, 999) }}" class="w-full px-3 py-2 bg-slate-50 dark:bg-slate-900 border border-slate-300 dark:border-slate-700 rounded-xl text-slate-900 dark:text-white font-mono">
                </div>

                <div>
                    <label for="branch_id" class="block font-semibold text-slate-700 dark:text-slate-300 mb-1">Assigned Branch *</label>
                    <select name="branch_id" id="branch_id" required class="w-full px-3 py-2 bg-slate-50 dark:bg-slate-900 border border-slate-300 dark:border-slate-700 rounded-xl text-slate-900 dark:text-white">
                        @foreach($branches as $b)
                            <option value="{{ $b->id }}">{{ $b->name }}</option>
                        @endforeach
                    </select>
                </div>

                <div>
                    <label for="first_name" class="block font-semibold text-slate-700 dark:text-slate-300 mb-1">First Name *</label>
                    <input type="text" name="first_name" id="first_name" required class="w-full px-3 py-2 bg-slate-50 dark:bg-slate-900 border border-slate-300 dark:border-slate-700 rounded-xl text-slate-900 dark:text-white">
                </div>

                <div>
                    <label for="last_name" class="block font-semibold text-slate-700 dark:text-slate-300 mb-1">Last Name</label>
                    <input type="text" name="last_name" id="last_name" class="w-full px-3 py-2 bg-slate-50 dark:bg-slate-900 border border-slate-300 dark:border-slate-700 rounded-xl text-slate-900 dark:text-white">
                </div>

                <div>
                    <label for="email" class="block font-semibold text-slate-700 dark:text-slate-300 mb-1">Email Address</label>
                    <input type="email" name="email" id="email" class="w-full px-3 py-2 bg-slate-50 dark:bg-slate-900 border border-slate-300 dark:border-slate-700 rounded-xl text-slate-900 dark:text-white">
                </div>

                <div>
                    <label for="mobile" class="block font-semibold text-slate-700 dark:text-slate-300 mb-1">Mobile Number</label>
                    <input type="text" name="mobile" id="mobile" placeholder="+971 50 123 4567" class="w-full px-3 py-2 bg-slate-50 dark:bg-slate-900 border border-slate-300 dark:border-slate-700 rounded-xl text-slate-900 dark:text-white">
                </div>

                <div>
                    <label for="designation" class="block font-semibold text-slate-700 dark:text-slate-300 mb-1">Designation</label>
                    <input type="text" name="designation" id="designation" placeholder="e.g. Senior Typist / Receptionist" class="w-full px-3 py-2 bg-slate-50 dark:bg-slate-900 border border-slate-300 dark:border-slate-700 rounded-xl text-slate-900 dark:text-white">
                </div>

                <div>
                    <label for="department_id" class="block font-semibold text-slate-700 dark:text-slate-300 mb-1">Department</label>
                    <select name="department_id" id="department_id" class="w-full px-3 py-2 bg-slate-50 dark:bg-slate-900 border border-slate-300 dark:border-slate-700 rounded-xl text-slate-900 dark:text-white">
                        <option value="">-- Unassigned --</option>
                        @foreach($departments as $dept)
                            <option value="{{ $dept->id }}">{{ $dept->name }}</option>
                        @endforeach
                    </select>
                </div>
            </div>
        </div>

        <div class="bg-white dark:bg-slate-800 rounded-3xl p-6 border border-slate-200 dark:border-slate-700/60 shadow-sm space-y-4">
            <h3 class="text-sm font-bold text-slate-900 dark:text-white uppercase tracking-wider">Compliance & Documents</h3>

            <div class="grid grid-cols-1 md:grid-cols-3 gap-4 text-xs">
                <div>
                    <label for="emirates_id" class="block font-semibold text-slate-700 dark:text-slate-300 mb-1">Emirates ID</label>
                    <input type="text" name="emirates_id" id="emirates_id" placeholder="784-1990-1234567-1" class="w-full px-3 py-2 bg-slate-50 dark:bg-slate-900 border border-slate-300 dark:border-slate-700 rounded-xl text-slate-900 dark:text-white">
                </div>

                <div>
                    <label for="passport_expiry" class="block font-semibold text-slate-700 dark:text-slate-300 mb-1">Passport Expiry</label>
                    <input type="date" name="passport_expiry" id="passport_expiry" class="w-full px-3 py-2 bg-slate-50 dark:bg-slate-900 border border-slate-300 dark:border-slate-700 rounded-xl text-slate-900 dark:text-white">
                </div>

                <div>
                    <label for="visa_expiry" class="block font-semibold text-slate-700 dark:text-slate-300 mb-1">Visa Expiry</label>
                    <input type="date" name="visa_expiry" id="visa_expiry" class="w-full px-3 py-2 bg-slate-50 dark:bg-slate-900 border border-slate-300 dark:border-slate-700 rounded-xl text-slate-900 dark:text-white">
                </div>
            </div>
        </div>

        <!-- Mandatory Workflow Checkbox (Requirement 56) -->
        <div class="p-4 rounded-2xl bg-sky-50 dark:bg-sky-950/60 border border-sky-200 dark:border-sky-800 text-xs">
            <label class="flex items-center space-x-3 rtl:space-x-reverse cursor-pointer">
                <input type="checkbox" name="give_erp_access" value="1" checked class="w-5 h-5 text-sky-600 rounded focus:ring-sky-500">
                <div>
                    <span class="font-bold text-sky-900 dark:text-sky-200 block text-sm">Give ERP Access Immediately</span>
                    <span class="text-sky-700 dark:text-sky-300">Proceed directly to create a linked login account for this employee after saving.</span>
                </div>
            </label>
        </div>

        <div class="flex justify-end space-x-3 rtl:space-x-reverse">
            <a href="{{ route('app.employees.index') }}" class="px-5 py-2.5 bg-slate-200 dark:bg-slate-700 text-slate-700 dark:text-slate-200 font-bold text-xs rounded-xl">Cancel</a>
            <button type="submit" class="px-6 py-2.5 bg-sky-600 hover:bg-sky-700 text-white font-bold text-xs rounded-xl shadow-lg shadow-sky-600/25">
                Save Employee Record
            </button>
        </div>
    </form>
</div>
@endsection
