@extends('layouts.app')
@section('title','Edit — '.$employee->full_name)
@section('page-title','Employees')

@section('content')
<div class="page-header">
    <div class="d-flex align-items-center gap-2 flex-wrap">
        <a href="{{ route('employees.show', $employee) }}" class="btn btn-sm btn-outline-secondary"><i class="bi bi-arrow-left"></i></a>
        <div>
            <h1>Edit: {{ $employee->full_name }}</h1>
            <nav aria-label="breadcrumb"><ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="{{ route('employees.index') }}">Employees</a></li>
                <li class="breadcrumb-item"><a href="{{ route('employees.show', $employee) }}">{{ $employee->full_name }}</a></li>
                <li class="breadcrumb-item active">Edit</li>
            </ol></nav>
        </div>
    </div>
</div>

<form method="POST" action="{{ route('employees.update', $employee) }}">
@csrf @method('PUT')

<div class="row g-3">
    <div class="col-12">
        <div class="card">
            <div class="card-header"><i class="bi bi-person me-2" style="color:var(--ul-primary);"></i>Personal Information</div>
            <div class="card-body">
                <div class="row g-3">
                    <div class="col-12 col-sm-4">
                        <label class="form-label">Last Name *</label>
                        <input type="text" name="last_name" class="form-control" value="{{ old('last_name', $employee->last_name) }}" required>
                    </div>
                    <div class="col-12 col-sm-4">
                        <label class="form-label">First Name *</label>
                        <input type="text" name="first_name" class="form-control" value="{{ old('first_name', $employee->first_name) }}" required>
                    </div>
                    <div class="col-12 col-sm-4">
                        <label class="form-label">Middle Name</label>
                        <input type="text" name="middle_name" class="form-control" value="{{ old('middle_name', $employee->middle_name) }}">
                    </div>
                    <div class="col-12">
                        <label class="form-label">Present Address</label>
                        <input type="text" name="present_address" class="form-control" value="{{ old('present_address', $employee->present_address) }}">
                    </div>
                    <div class="col-6 col-sm-3">
                        <label class="form-label">Date of Birth</label>
                        <input type="date" name="date_of_birth" class="form-control" value="{{ old('date_of_birth', $employee->date_of_birth?->format('Y-m-d')) }}">
                    </div>
                    <div class="col-6 col-sm-3">
                        <label class="form-label">Gender</label>
                        <select name="gender" class="form-select">
                            <option value="">— Select —</option>
                            <option value="Male"   {{ old('gender',$employee->gender)==='Male'?'selected':'' }}>Male</option>
                            <option value="Female" {{ old('gender',$employee->gender)==='Female'?'selected':'' }}>Female</option>
                        </select>
                    </div>
                    <div class="col-6 col-sm-3">
                        <label class="form-label">Marital Status</label>
                        <select name="marital_status" class="form-select">
                            <option value="">— Select —</option>
                            @foreach(['Single','Married','Divorced','Widowed'] as $ms)
                            <option value="{{ $ms }}" {{ old('marital_status',$employee->marital_status)===$ms?'selected':'' }}>{{ $ms }}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="col-6 col-sm-3">
                        <label class="form-label">Citizenship</label>
                        <input type="text" name="citizenship" class="form-control" value="{{ old('citizenship', $employee->citizenship) }}">
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="col-12">
        <div class="card">
            <div class="card-header"><i class="bi bi-briefcase me-2" style="color:var(--ul-primary);"></i>Employment Details</div>
            <div class="card-body">
                <div class="row g-3">
                    <div class="col-12 col-sm-6">
                        <label class="form-label">Position *</label>
                        <input type="text" name="position" class="form-control" value="{{ old('position', $employee->position) }}" required>
                    </div>
                    <div class="col-12 col-sm-6">
                        <label class="form-label">Department *</label>
                        <select name="department_id" class="form-select" required>
                            <option value="">— Select —</option>
                            @foreach($departments as $d)
                            <option value="{{ $d->id }}" {{ old('department_id',$employee->department_id)==$d->id?'selected':'' }}>{{ $d->name }}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="col-6 col-sm-3">
                        <label class="form-label">Date of Employment</label>
                        <input type="date" name="date_of_employment" class="form-control" value="{{ old('date_of_employment', $employee->date_of_employment?->format('Y-m-d')) }}">
                    </div>
                    <div class="col-6 col-sm-3">
                        <label class="form-label">Employment Type</label>
                        <select name="employment_type" class="form-select">
                            @foreach(['full_time'=>'Full Time','part_time'=>'Part Time','contract'=>'Contract','temporary'=>'Temporary'] as $val=>$label)
                            <option value="{{ $val }}" {{ old('employment_type',$employee->employment_type)===$val?'selected':'' }}>{{ $label }}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="col-6 col-sm-3">
                        <label class="form-label">Salary (USD)</label>
                        <input type="number" name="salary_usd" class="form-control" value="{{ old('salary_usd', $employee->salary_usd) }}" step="0.01" min="0">
                    </div>
                    <div class="col-6 col-sm-3">
                        <label class="form-label">Status</label>
                        <select name="status" class="form-select">
                            @foreach(['active','on_leave','suspended','terminated','retired'] as $s)
                            <option value="{{ $s }}" {{ old('status',$employee->status)===$s?'selected':'' }}>{{ ucfirst(str_replace('_',' ',$s)) }}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="col-6 col-sm-4">
                        <label class="form-label">Email</label>
                        <input type="email" name="email" class="form-control" value="{{ old('email', $employee->user->email ?? '') }}">
                    </div>
                    <div class="col-6 col-sm-4">
                        <label class="form-label">Phone</label>
                        <input type="text" name="phone" class="form-control" value="{{ old('phone', $employee->user->phone ?? '') }}">
                    </div>
                    <div class="col-6 col-sm-4">
                        <label class="form-label">Bank Name</label>
                        <input type="text" name="bank_name" class="form-control" value="{{ old('bank_name', $employee->bank_name) }}">
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="col-12">
        <div class="card">
            <div class="card-body d-flex gap-2">
                <button type="submit" class="btn btn-primary"><i class="bi bi-check-lg me-1"></i>Save Changes</button>
                <a href="{{ route('employees.show', $employee) }}" class="btn btn-outline-secondary">Cancel</a>
            </div>
        </div>
    </div>
</div>
</form>
@endsection
