<?php

declare(strict_types=1);

ob_start();

$fullName = trim(
    (string) ($employee['first_name'] ?? '')
    . ' '
    . (string) ($employee['middle_name'] ?? '')
    . ' '
    . (string) ($employee['last_name'] ?? '')
);

$employmentStatus = (string) (
    $employee['employment_status']
    ?? 'INACTIVE'
);

$biometricStatus = (string) (
    $employee['biometric_status']
    ?? 'NOT_REGISTERED'
);

?>

<div class="d-flex justify-content-between align-items-center mb-4">

<div>

    <h2 class="mb-1">
        Employee Profile
    </h2>

    <p class="text-muted mb-0">

        <?= htmlspecialchars(
            (string) (
                $employee['employee_id']
                ?? ''
            ),
            ENT_QUOTES,
            'UTF-8'
        ) ?>

    </p>

</div>

<div class="d-flex gap-2">

    <a
        href="/public/employees/edit?id=<?= (int) ($employee['id'] ?? 0) ?>"
        class="btn btn-primary">

        <i class="bi bi-pencil me-1"></i>
        Edit Employee

    </a>

    <a
        href="/public/employees"
        class="btn btn-outline-secondary">

        <i class="bi bi-arrow-left me-1"></i>
        Back

    </a>

</div>

</div>

<div class="row g-4">

<!-- LEFT PROFILE CARD -->

<div class="col-lg-4">

    <div class="card shadow-sm border-0">

        <div class="card-body text-center p-4">

            <?php if (
                !empty($employee['photo'])
            ): ?>

                <img
                    src="/public/<?= htmlspecialchars(
                        (string) $employee['photo'],
                        ENT_QUOTES,
                        'UTF-8'
                    ) ?>"
                    class="rounded mb-3"
                    style="
                        width: 180px;
                        height: 220px;
                        object-fit: cover;
                    "
                    alt="Employee Photo">

            <?php else: ?>

                <div
                    class="
                        bg-light
                        rounded
                        d-flex
                        align-items-center
                        justify-content-center
                        mx-auto
                        mb-3
                    "
                    style="
                        width: 180px;
                        height: 220px;
                    ">

                    <i
                        class="
                            bi
                            bi-person
                            display-1
                            text-muted
                        ">
                    </i>

                </div>

            <?php endif; ?>


            <h4 class="mb-1">

                <?= htmlspecialchars(
                    $fullName,
                    ENT_QUOTES,
                    'UTF-8'
                ) ?>

            </h4>


            <div class="text-muted mb-3">

                <?= htmlspecialchars(
                    (string) (
                        $employee['rank_name']
                        ?? 'No Rank Assigned'
                    ),
                    ENT_QUOTES,
                    'UTF-8'
                ) ?>

            </div>


            <span class="badge text-bg-primary fs-6">

                <?= htmlspecialchars(
                    (string) (
                        $employee['employee_id']
                        ?? ''
                    ),
                    ENT_QUOTES,
                    'UTF-8'
                ) ?>

            </span>


            <hr class="my-4">


            <div class="text-start">

                <div class="mb-3">

                    <small class="text-muted d-block">
                        Employment Status
                    </small>

                    <?php

                    $employmentClass =
                        $employmentStatus === 'ACTIVE'
                            ? 'text-bg-success'
                            : 'text-bg-secondary';

                    ?>

                    <span
                        class="badge <?= $employmentClass ?>">

                        <?= htmlspecialchars(
                            ucwords(
                                strtolower(
                                    str_replace(
                                        '_',
                                        ' ',
                                        $employmentStatus
                                    )
                                )
                            ),
                            ENT_QUOTES,
                            'UTF-8'
                        ) ?>

                    </span>

                </div>


                <div>

                    <small class="text-muted d-block">
                        Biometric Status
                    </small>

                    <?php

                    $biometricClass =
                        in_array(
                            $biometricStatus,
                            [
                                'REGISTERED',
                                'VERIFIED'
                            ],
                            true
                        )
                            ? 'text-bg-success'
                            : 'text-bg-warning';

                    ?>

                    <span
                        class="badge <?= $biometricClass ?>">

                        <?= htmlspecialchars(
                            ucwords(
                                strtolower(
                                    str_replace(
                                        '_',
                                        ' ',
                                        $biometricStatus
                                    )
                                )
                            ),
                            ENT_QUOTES,
                            'UTF-8'
                        ) ?>

                    </span>

                </div>

            </div>

        </div>

    </div>

</div>


<!-- RIGHT CONTENT -->

<div class="col-lg-8">


    <!-- PERSONAL INFORMATION -->

    <div class="card shadow-sm border-0 mb-4">

        <div class="card-header bg-white py-3">

            <h5 class="mb-0">

                <i class="bi bi-person me-2"></i>

                Personal Information

            </h5>

        </div>


        <div class="card-body">

            <div class="row g-4">


                <div class="col-md-6">

                    <small class="text-muted d-block">
                        Full Name
                    </small>

                    <strong>

                        <?= htmlspecialchars(
                            $fullName,
                            ENT_QUOTES,
                            'UTF-8'
                        ) ?>

                    </strong>

                </div>


                <div class="col-md-6">

                    <small class="text-muted d-block">
                        Gender
                    </small>

                    <strong>

                        <?= htmlspecialchars(
                            ucfirst(
                                strtolower(
                                    (string) (
                                        $employee['gender']
                                        ?? ''
                                    )
                                )
                            ),
                            ENT_QUOTES,
                            'UTF-8'
                        ) ?>

                    </strong>

                </div>


                <div class="col-md-6">

                    <small class="text-muted d-block">
                        Date of Birth
                    </small>

                    <strong>

                        <?= htmlspecialchars(
                            (string) (
                                $employee[
                                    'date_of_birth'
                                ]
                                ?? '—'
                            ),
                            ENT_QUOTES,
                            'UTF-8'
                        ) ?>

                    </strong>

                </div>


                <div class="col-md-6">

                    <small class="text-muted d-block">
                        Nationality Number
                    </small>

                    <strong>

                        <?= htmlspecialchars(
                            (string) (
                                $employee[
                                    'nationality_number'
                                ]
                                ?? '—'
                            ),
                            ENT_QUOTES,
                            'UTF-8'
                        ) ?>

                    </strong>

                </div>
<div class="col-md-6">

    <small class="text-muted d-block">
        Police ID Number
    </small>

    <strong>

        <?= htmlspecialchars(
            (string) (
                $employee[
                    'police_id_number'
                ]
                ?? '—'
            ),
            ENT_QUOTES,
            'UTF-8'
        ) ?>

    </strong>

</div>

                <div class="col-md-6">

                    <small class="text-muted d-block">
                        Hire Date
                    </small>

                    <strong>

                        <?= htmlspecialchars(
                            (string) (
                                $employee['hire_date']
                                ?? '—'
                            ),
                            ENT_QUOTES,
                            'UTF-8'
                        ) ?>

                    </strong>

                </div>


                <div class="col-md-6">

                    <small class="text-muted d-block">
                        Employee ID
                    </small>

                    <strong>

                        <?= htmlspecialchars(
                            (string) (
                                $employee['employee_id']
                                ?? '—'
                            ),
                            ENT_QUOTES,
                            'UTF-8'
                        ) ?>

                    </strong>

                </div>

            </div>

        </div>

    </div>


    <!-- ORGANIZATIONAL ASSIGNMENT -->

    <div class="card shadow-sm border-0 mb-4">

        <div class="card-header bg-white py-3">

            <h5 class="mb-0">

                <i class="bi bi-building me-2"></i>

                Organizational Assignment

            </h5>

        </div>


        <div class="card-body">

            <div class="row g-4">


                <div class="col-md-4">

                    <small class="text-muted d-block">
                        Rank
                    </small>

                    <strong>

                        <?= htmlspecialchars(
                            (string) (
                                $employee['rank_name']
                                ?? '—'
                            ),
                            ENT_QUOTES,
                            'UTF-8'
                        ) ?>

                    </strong>

                </div>


                <div class="col-md-4">

                    <small class="text-muted d-block">
                        Department
                    </small>

                    <strong>

                        <?= htmlspecialchars(
                            (string) (
                                $employee[
                                    'department_name'
                                ]
                                ?? '—'
                            ),
                            ENT_QUOTES,
                            'UTF-8'
                        ) ?>

                    </strong>

                </div>


                <div class="col-md-4">

                    <small class="text-muted d-block">
                        Position
                    </small>

                    <strong>

                        <?= htmlspecialchars(
                            (string) (
                                $employee['position_name']
                                ?? '—'
                            ),
                            ENT_QUOTES,
                            'UTF-8'
                        ) ?>

                    </strong>

                </div>

            </div>

        </div>

    </div>


    <!-- LOCATION -->

    <div class="card shadow-sm border-0 mb-4">

        <div class="card-header bg-white py-3">

            <h5 class="mb-0">

                <i class="bi bi-geo-alt me-2"></i>

                Location Information

            </h5>

        </div>


        <div class="card-body">

            <div class="row g-4">


                <div class="col-md-4">

                    <small class="text-muted d-block">
                        State / Administrative Area
                    </small>

                    <strong>

                        <?= htmlspecialchars(
                            (string) (
                                $employee['state_name']
                                ?? '—'
                            ),
                            ENT_QUOTES,
                            'UTF-8'
                        ) ?>

                    </strong>

                </div>


                <div class="col-md-4">

                    <small class="text-muted d-block">
                        County
                    </small>

                    <strong>

                        <?= htmlspecialchars(
                            (string) (
                                $employee['county_name']
                                ?? '—'
                            ),
                            ENT_QUOTES,
                            'UTF-8'
                        ) ?>

                    </strong>

                </div>


                <div class="col-md-4">

                    <small class="text-muted d-block">
                        Payam
                    </small>

                    <strong>

                        <?= htmlspecialchars(
                            (string) (
                                $employee['payam_name']
                                ?? '—'
                            ),
                            ENT_QUOTES,
                            'UTF-8'
                        ) ?>

                    </strong>

                </div>

            </div>

        </div>

    </div>

<!-- FAMILY INFORMATION -->

<div class="card shadow-sm border-0 mb-4">

<div class="card-header bg-white py-3">

    <div class="d-flex justify-content-between align-items-center">

        <h5 class="mb-0">
            <i class="bi bi-people me-2"></i>
            Family Information
        </h5>

        <button
            type="button"
            class="btn btn-sm btn-primary"
            data-bs-toggle="modal"
            data-bs-target="#addFamilyModal">

            <i class="bi bi-plus-circle me-1"></i>
            Add Family Member

        </button>

    </div>

</div>


<div class="card-body">

    <?php if (!empty($familyCreated)): ?>

        <div class="alert alert-success">
            Family member added successfully.
        </div>

    <?php endif; ?>


    <?php if (!empty($familyUpdated)): ?>

        <div class="alert alert-success">
            Family member updated successfully.
        </div>

    <?php endif; ?>


    <?php if (!empty($familyDeactivated)): ?>

        <div class="alert alert-success">
            Family member deactivated successfully.
        </div>

    <?php endif; ?>


    <?php if (!empty($familyError)): ?>

        <div class="alert alert-danger">

            <?= htmlspecialchars(
                (string) $familyError,
                ENT_QUOTES,
                'UTF-8'
            ) ?>

        </div>

    <?php endif; ?>


    <div class="table-responsive">

        <table class="table table-hover align-middle">

            <thead>

                <tr>
                    <th>Name</th>
                    <th>Relationship</th>
                    <th>Gender</th>
                    <th>Phone</th>
                    <th>Emergency</th>
                    <th>Status</th>
                    <th class="text-end">
                        Actions
                    </th>
                </tr>

            </thead>

            <tbody>

            <?php if (empty($familyMembers)): ?>

                <tr>

                    <td
                        colspan="7"
                        class="text-center text-muted py-4">

                        No family information recorded.

                    </td>

                </tr>

            <?php else: ?>

                <?php foreach (
                    $familyMembers as $family
                ): ?>

                    <tr>

                        <td>

                            <strong>

                                <?= htmlspecialchars(
                                    (string) (
                                        $family['full_name']
                                        ?? ''
                                    ),
                                    ENT_QUOTES,
                                    'UTF-8'
                                ) ?>

                            </strong>

                        </td>


                        <td>

                            <?= htmlspecialchars(
                                ucwords(
                                    strtolower(
                                        str_replace(
                                            '_',
                                            ' ',
                                            (string) (
                                                $family[
                                                    'relationship_type'
                                                ]
                                                ?? ''
                                            )
                                        )
                                    )
                                ),
                                ENT_QUOTES,
                                'UTF-8'
                            ) ?>

                        </td>


                        <td>

                            <?= htmlspecialchars(
                                ucfirst(
                                    strtolower(
                                        (string) (
                                            $family['gender']
                                            ?? '—'
                                        )
                                    )
                                ),
                                ENT_QUOTES,
                                'UTF-8'
                            ) ?>

                        </td>


                        <td>

                            <?= htmlspecialchars(
                                (string) (
                                    $family['phone_number']
                                    ?? '—'
                                ),
                                ENT_QUOTES,
                                'UTF-8'
                            ) ?>

                        </td>


                        <td>

                            <?php if (
                                (int) (
                                    $family[
                                        'is_emergency_contact'
                                    ]
                                    ?? 0
                                ) === 1
                            ): ?>

                                <span class="badge text-bg-danger">
                                    Emergency Contact
                                </span>

                            <?php else: ?>

                                <span class="text-muted">
                                    —
                                </span>

                            <?php endif; ?>

                        </td>


                        <td>

                            <?php if (
                                (int) (
                                    $family['status']
                                    ?? 0
                                ) === 1
                            ): ?>

                                <span class="badge text-bg-success">
                                    Active
                                </span>

                            <?php else: ?>

                                <span class="badge text-bg-secondary">
                                    Inactive
                                </span>

                            <?php endif; ?>

                        </td>


                        <td class="text-end">

 <button
    type="button"
    class="btn btn-sm btn-outline-primary edit-family-btn"

    data-bs-toggle="modal"
    data-bs-target="#editFamilyModal"

    data-id="<?= (int) $family['id'] ?>"

    data-full-name="<?= htmlspecialchars(
        (string) ($family['full_name'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-relationship="<?= htmlspecialchars(
        (string) ($family['relationship_type'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-gender="<?= htmlspecialchars(
        (string) ($family['gender'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-date-of-birth="<?= htmlspecialchars(
        (string) ($family['date_of_birth'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-phone-number="<?= htmlspecialchars(
        (string) ($family['phone_number'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-occupation="<?= htmlspecialchars(
        (string) ($family['occupation'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-address="<?= htmlspecialchars(
        (string) ($family['address'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-emergency="<?= (int) (
        $family['is_emergency_contact'] ?? 0
    ) ?>">

    <i class="bi bi-pencil"></i>

</button>


                            <?php if (
                                (int) (
                                    $family['status']
                                    ?? 0
                                ) === 1
                            ): ?>

                                <form
                                    method="POST"
                                    action="/public/employees/family/deactivate"
                                    class="d-inline"
                                    onsubmit="return confirm('Deactivate this family member?');">

                                    <input
                                        type="hidden"
                                        name="id"
                                        value="<?= (int) $family['id'] ?>">

                                    <input
                                        type="hidden"
                                        name="employee_id"
                                        value="<?= (int) $employee['id'] ?>">

                                    <button
                                        type="submit"
                                        class="btn btn-sm btn-outline-danger">

                                        <i class="bi bi-person-x"></i>

                                    </button>

                                </form>

                            <?php endif; ?>

                        </td>

                    </tr>

                <?php endforeach; ?>

            <?php endif; ?>

            </tbody>

        </table>

    </div>

</div>

</div>
<!-- EMPLOYEE DOCUMENTS -->

<div class="card shadow-sm border-0 mb-4">

    <div class="card-header bg-white py-3">

        <div class="d-flex justify-content-between align-items-center">

            <h5 class="mb-0">
                <i class="bi bi-folder2-open me-2"></i>
                Employee Documents
            </h5>

            <button
                type="button"
                class="btn btn-sm btn-primary"
                data-bs-toggle="modal"
                data-bs-target="#uploadDocumentModal">

                <i class="bi bi-cloud-upload me-1"></i>
                Upload Document

            </button>

        </div>

    </div>

    <div class="card-body">

        <?php if (!empty($documentCreated)): ?>

            <div class="alert alert-success">
                Document uploaded successfully.
            </div>

        <?php endif; ?>

        <?php if (!empty($documentDeactivated)): ?>

            <div class="alert alert-success">
                Document deactivated successfully.
            </div>

        <?php endif; ?>

        <?php if (!empty($documentError)): ?>

            <div class="alert alert-danger">

                <?= htmlspecialchars(
                    (string) $documentError,
                    ENT_QUOTES,
                    'UTF-8'
                ) ?>

            </div>

        <?php endif; ?>

        <div class="table-responsive">

            <table class="table table-hover align-middle">

                <thead>

                    <tr>
                        <th>Document</th>
                        <th>Type</th>
                        <th>Number</th>
                        <th>Issue Date</th>
                        <th>Expiry Date</th>
                        <th>Status</th>
                        <th class="text-end">
                            Actions
                        </th>
                    </tr>

                </thead>

                <tbody>

                <?php if (empty($documents)): ?>

                    <tr>

                        <td
                            colspan="7"
                            class="text-center text-muted py-4">

                            No employee documents uploaded.

                        </td>

                    </tr>

                <?php else: ?>

                    <?php foreach ($documents as $document): ?>

                        <tr>

                            <td>

                                <strong>

                                    <?= htmlspecialchars(
                                        (string) (
                                            $document['document_title']
                                            ?? ''
                                        ),
                                        ENT_QUOTES,
                                        'UTF-8'
                                    ) ?>

                                </strong>

                                <?php if (
                                    !empty(
                                        $document['original_file_name']
                                    )
                                ): ?>

                                    <small class="d-block text-muted">

                                        <?= htmlspecialchars(
                                            (string) $document[
                                                'original_file_name'
                                            ],
                                            ENT_QUOTES,
                                            'UTF-8'
                                        ) ?>

                                    </small>

                                <?php endif; ?>

                            </td>

                            <td>

                                <?= htmlspecialchars(
                                    (string) (
                                        $document['document_type']
                                        ?? ''
                                    ),
                                    ENT_QUOTES,
                                    'UTF-8'
                                ) ?>

                            </td>

                            <td>

                                <?= htmlspecialchars(
                                    (string) (
                                        $document['document_number']
                                        ?? '—'
                                    ),
                                    ENT_QUOTES,
                                    'UTF-8'
                                ) ?>

                            </td>

                            <td>

                                <?= htmlspecialchars(
                                    (string) (
                                        $document['issue_date']
                                        ?? '—'
                                    ),
                                    ENT_QUOTES,
                                    'UTF-8'
                                ) ?>

                            </td>

                            <td>

                                <?= htmlspecialchars(
                                    (string) (
                                        $document['expiry_date']
                                        ?? '—'
                                    ),
                                    ENT_QUOTES,
                                    'UTF-8'
                                ) ?>

                            </td>
                        <td>

                            <?php if (
                                (int) (
                                    $document['status']
                                    ?? 0
                                ) === 1
                            ): ?>

                                <span class="badge text-bg-success">
                                    Active
                                </span>

                            <?php else: ?>

                                <span class="badge text-bg-secondary">
                                    Inactive
                                </span>

                            <?php endif; ?>

                        </td>

                            <td class="text-end">

                                <div class="d-inline-flex align-items-center justify-content-end gap-1">

                                    <?php if (
                                        !empty($document['file_path'])
                                        && (int) ($document['status'] ?? 0) === 1
                                    ): ?>

                                        <a
                                            href="/public/employees/documents/view?id=<?= (int) $document['id'] ?>"
                                            target="_blank"
                                            class="btn btn-sm btn-outline-primary"
                                            title="View Document">

                                            <i class="bi bi-eye"></i>

                                        </a>

                                    <?php endif; ?>


                                    <form
                                        method="POST"
                                        action="/public/employees/documents/toggle-status"
                                        class="d-inline">

                                        <input
                                            type="hidden"
                                            name="id"
                                            value="<?= (int) $document['id'] ?>">

                                        <input
                                            type="hidden"
                                            name="employee_id"
                                            value="<?= (int) $employee['id'] ?>">

                                        <?php if (
                                            (int) ($document['status'] ?? 0) === 1
                                        ): ?>

                                            <button
                                                type="submit"
                                                class="btn btn-sm btn-outline-danger"
                                                title="Deactivate Document"
                                                onclick="return confirm('Deactivate this document?');">

                                                <i class="bi bi-x-circle"></i>

                                            </button>

                                        <?php else: ?>

                                            <button
                                                type="submit"
                                                class="btn btn-sm btn-outline-success"
                                                title="Activate Document"
                                                onclick="return confirm('Activate this document?');">

                                                <i class="bi bi-check-circle"></i>

                                            </button>

                                        <?php endif; ?>

                                    </form>

                                </div>

                            </td>

                        </tr>

                    <?php endforeach; ?>

                <?php endif; ?>

                </tbody>

            </table>

        </div>

    </div>

</div>
<!-- =========================================================
     TRAINING HISTORY
========================================================= -->
<br>
<div class="card shadow-sm border-0 mb-4">

    <div class="card-header bg-white py-3">

        <div class="d-flex justify-content-between align-items-center">

            <h5 class="mb-0">
                <i class="bi bi-mortarboard me-2"></i>
                Training History
            </h5>

            <button
                type="button"
                class="btn btn-sm btn-primary"
                data-bs-toggle="modal"
                data-bs-target="#addTrainingModal">

                <i class="bi bi-plus-circle me-1"></i>
                Add Training

            </button>

        </div>

    </div>


    <div class="card-body">

        <?php if (!empty($trainingCreated)): ?>

            <div class="alert alert-success alert-dismissible fade show">

                Training record added successfully.

                <button
                    type="button"
                    class="btn-close"
                    data-bs-dismiss="alert">
                </button>

            </div>

        <?php endif; ?>


        <?php if (!empty($trainingStatusUpdated)): ?>

            <div class="alert alert-success alert-dismissible fade show">

                Training status updated successfully.

                <button
                    type="button"
                    class="btn-close"
                    data-bs-dismiss="alert">
                </button>

            </div>

        <?php endif; ?>


        <?php if (!empty($trainingError)): ?>

            <div class="alert alert-danger alert-dismissible fade show">

                <?= htmlspecialchars(
                    (string) $trainingError,
                    ENT_QUOTES,
                    'UTF-8'
                ) ?>

                <button
                    type="button"
                    class="btn-close"
                    data-bs-dismiss="alert">
                </button>

            </div>

        <?php endif; ?>


        <div class="table-responsive">

            <table class="table table-hover align-middle">

                <thead>

                    <tr>

                        <th>Training</th>

                        <th>Type</th>

                        <th>Institution</th>

                        <th>Period</th>

                        <th>Qualification</th>

                        <th>Certificate</th>

                        <th>Status</th>

                        <th class="text-end">
                            Actions
                        </th>

                    </tr>

                </thead>


                <tbody>

                <?php if (empty($trainingHistory)): ?>

                    <tr>

                        <td
                            colspan="8"
                            class="text-center text-muted py-4">

                            No training history recorded.

                        </td>

                    </tr>

                <?php else: ?>


                    <?php foreach ($trainingHistory as $training): ?>

                        <tr>

                            <!-- TRAINING TITLE -->

                            <td>

                                <strong>

                                    <?= htmlspecialchars(
                                        (string) (
                                            $training['training_title']
                                            ?? ''
                                        ),
                                        ENT_QUOTES,
                                        'UTF-8'
                                    ) ?>

                                </strong>


                                <?php if (
                                    !empty($training['location'])
                                    || !empty($training['country'])
                                ): ?>

                                    <small class="d-block text-muted">

                                        <?= htmlspecialchars(
                                            trim(
                                                (string) (
                                                    $training['location']
                                                    ?? ''
                                                )
                                                . (
                                                    !empty($training['location'])
                                                    && !empty($training['country'])
                                                        ? ', '
                                                        : ''
                                                )
                                                . (string) (
                                                    $training['country']
                                                    ?? ''
                                                )
                                            ),
                                            ENT_QUOTES,
                                            'UTF-8'
                                        ) ?>

                                    </small>

                                <?php endif; ?>

                            </td>


                            <!-- TYPE -->

                            <td>

                                <?= htmlspecialchars(
                                    (string) (
                                        $training['training_type']
                                        ?? '—'
                                    ),
                                    ENT_QUOTES,
                                    'UTF-8'
                                ) ?>

                            </td>


                            <!-- INSTITUTION -->

                            <td>

                                <?= htmlspecialchars(
                                    (string) (
                                        $training['institution']
                                        ?? '—'
                                    ),
                                    ENT_QUOTES,
                                    'UTF-8'
                                ) ?>

                            </td>


                            <!-- PERIOD -->

                            <td>

                                <?php

                                $trainingStart =
                                    $training['start_date']
                                    ?? null;

                                $trainingEnd =
                                    $training['end_date']
                                    ?? null;

                                ?>

                                <?php if (
                                    !empty($trainingStart)
                                    || !empty($trainingEnd)
                                ): ?>

                                    <?= htmlspecialchars(
                                        (string) (
                                            $trainingStart
                                            ?? '—'
                                        ),
                                        ENT_QUOTES,
                                        'UTF-8'
                                    ) ?>

                                    <br>

                                    <small class="text-muted">

                                        to

                                        <?= htmlspecialchars(
                                            (string) (
                                                $trainingEnd
                                                ?? 'Ongoing'
                                            ),
                                            ENT_QUOTES,
                                            'UTF-8'
                                        ) ?>

                                    </small>

                                <?php else: ?>

                                    —

                                <?php endif; ?>

                            </td>


                            <!-- QUALIFICATION -->

                            <td>

                                <?= htmlspecialchars(
                                    (string) (
                                        $training['qualification']
                                        ?? '—'
                                    ),
                                    ENT_QUOTES,
                                    'UTF-8'
                                ) ?>

                            </td>


                            <!-- CERTIFICATE -->

                            <td>

                                <?php if (
                                    !empty(
                                        $training[
                                            'certificate_file_path'
                                        ]
                                    )
                                    && (int) (
                                        $training['status']
                                        ?? 0
                                    ) === 1
                                ): ?>

                                    <a
                                        href="/public/employees/training/certificate?id=<?= (int) $training['id'] ?>"
                                        target="_blank"
                                        class="btn btn-sm btn-outline-primary"
                                        title="View Certificate">

                                        <i class="bi bi-file-earmark-text"></i>

                                    </a>

                                <?php else: ?>

                                    <span class="text-muted">
                                        —
                                    </span>

                                <?php endif; ?>

                            </td>


                            <!-- STATUS -->

                            <td>

                                <?php if (
                                    (int) (
                                        $training['status']
                                        ?? 0
                                    ) === 1
                                ): ?>

                                    <span class="badge text-bg-success">
                                        Active
                                    </span>

                                <?php else: ?>

                                    <span class="badge text-bg-secondary">
                                        Inactive
                                    </span>

                                <?php endif; ?>

                            </td>


                            <!-- ACTIONS -->

                            <td class="text-end">
<button
    type="button"
    class="btn btn-sm btn-outline-warning edit-training-btn"
    title="Edit Training"
    data-bs-toggle="modal"
    data-bs-target="#editTrainingModal"

    data-id="<?= (int) $training['id'] ?>"

    data-title="<?= htmlspecialchars(
        (string) ($training['training_title'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-type="<?= htmlspecialchars(
        (string) ($training['training_type'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-institution="<?= htmlspecialchars(
        (string) ($training['institution'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-sponsor="<?= htmlspecialchars(
        (string) ($training['sponsor'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-country="<?= htmlspecialchars(
        (string) ($training['country'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-location="<?= htmlspecialchars(
        (string) ($training['location'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-start-date="<?= htmlspecialchars(
        (string) ($training['start_date'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-end-date="<?= htmlspecialchars(
        (string) ($training['end_date'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-certificate-number="<?= htmlspecialchars(
        (string) ($training['certificate_number'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-qualification="<?= htmlspecialchars(
        (string) ($training['qualification'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-notes="<?= htmlspecialchars(
        (string) ($training['notes'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>">

    <i class="bi bi-pencil"></i>

</button>
                                <form
                                    method="POST"
                                    action="/public/employees/training/toggle-status"
                                    class="d-inline">

                                    <input
                                        type="hidden"
                                        name="id"
                                        value="<?= (int) $training['id'] ?>">

                                    <input
                                        type="hidden"
                                        name="employee_id"
                                        value="<?= (int) $employee['id'] ?>">


                                    <?php if (
                                        (int) (
                                            $training['status']
                                            ?? 0
                                        ) === 1
                                    ): ?>

                                        <button
                                            type="submit"
                                            class="btn btn-sm btn-outline-danger"
                                            title="Deactivate Training"
                                            onclick="return confirm('Deactivate this training record?');">

                                            <i class="bi bi-x-circle"></i>

                                        </button>

                                    <?php else: ?>

                                        <button
                                            type="submit"
                                            class="btn btn-sm btn-outline-success"
                                            title="Activate Training"
                                            onclick="return confirm('Activate this training record?');">

                                            <i class="bi bi-check-circle"></i>

                                        </button>

                                    <?php endif; ?>

                                </form>

                            </td>

                        </tr>

                    <?php endforeach; ?>

                <?php endif; ?>

                </tbody>

            </table>

        </div>

    </div>

</div>
<!-- =========================================================
     TRANSFER HISTORY
========================================================= -->

<div class="card shadow-sm border-0 mb-4">

    <div class="card-header bg-white py-3">

        <div class="d-flex justify-content-between align-items-center">

            <h5 class="mb-0">
                <i class="bi bi-arrow-left-right me-2"></i>
                Transfer History
            </h5>

            <button
                type="button"
                class="btn btn-sm btn-primary"
                data-bs-toggle="modal"
                data-bs-target="#addTransferModal">

                <i class="bi bi-plus-circle me-1"></i>
                Add Transfer

            </button>

        </div>

    </div>


    <div class="card-body">

        <?php if (!empty($transferCreated)): ?>

            <div class="alert alert-success alert-dismissible fade show">

                Transfer record added successfully.

                <button
                    type="button"
                    class="btn-close"
                    data-bs-dismiss="alert">
                </button>

            </div>

        <?php endif; ?>


        <?php if (!empty($transferStatusUpdated)): ?>

            <div class="alert alert-success alert-dismissible fade show">

                Transfer status updated successfully.

                <button
                    type="button"
                    class="btn-close"
                    data-bs-dismiss="alert">
                </button>

            </div>

        <?php endif; ?>
<?php if (!empty($transferUpdated)): ?>

    <div class="alert alert-success alert-dismissible fade show">

        Transfer record updated successfully.

        <button
            type="button"
            class="btn-close"
            data-bs-dismiss="alert">
        </button>

    </div>

<?php endif; ?>

        <?php if (!empty($transferError)): ?>

            <div class="alert alert-danger alert-dismissible fade show">

                <?= htmlspecialchars(
                    (string) $transferError,
                    ENT_QUOTES,
                    'UTF-8'
                ) ?>

                <button
                    type="button"
                    class="btn-close"
                    data-bs-dismiss="alert">
                </button>

            </div>

        <?php endif; ?>


        <div class="table-responsive">

            <table class="table table-hover align-middle">

                <thead>

                    <tr>
                        <th>Effective Date</th>
                        <th>Type</th>
                        <th>Previous Assignment</th>
                        <th>New Assignment</th>
                        <th>Order No.</th>
                        <th>Document</th>
                        <th>Status</th>

                        <th class="text-end">
                            Actions
                        </th>
                    </tr>

                </thead>


                <tbody>

                <?php if (empty($transferHistory)): ?>

                    <tr>

                        <td
                            colspan="8"
                            class="text-center text-muted py-4">

                            No transfer history recorded.

                        </td>

                    </tr>

                <?php else: ?>

                    <?php foreach ($transferHistory as $transfer): ?>

                        <tr>

                            <td>
                                <?= htmlspecialchars(
                                    (string) (
                                        $transfer['effective_date']
                                        ?? '—'
                                    ),
                                    ENT_QUOTES,
                                    'UTF-8'
                                ) ?>
                            </td>


                            <td>
                                <?= htmlspecialchars(
                                    (string) (
                                        $transfer['transfer_type']
                                        ?? '—'
                                    ),
                                    ENT_QUOTES,
                                    'UTF-8'
                                ) ?>
                            </td>


                            <td>

                                <strong>
                                    <?= htmlspecialchars(
                                        (string) (
                                            $transfer['previous_branch']
                                            ?? '—'
                                        ),
                                        ENT_QUOTES,
                                        'UTF-8'
                                    ) ?>
                                </strong>

                                <?php if (
                                    !empty(
                                        $transfer['previous_department']
                                    )
                                ): ?>

                                    <small class="d-block text-muted">

                                        <?= htmlspecialchars(
                                            (string) $transfer[
                                                'previous_department'
                                            ],
                                            ENT_QUOTES,
                                            'UTF-8'
                                        ) ?>

                                    </small>

                                <?php endif; ?>


                                <?php if (
                                    !empty(
                                        $transfer['previous_position']
                                    )
                                ): ?>

                                    <small class="d-block text-muted">

                                        <?= htmlspecialchars(
                                            (string) $transfer[
                                                'previous_position'
                                            ],
                                            ENT_QUOTES,
                                            'UTF-8'
                                        ) ?>

                                    </small>

                                <?php endif; ?>

                            </td>


                            <td>

                                <strong>
                                    <?= htmlspecialchars(
                                        (string) (
                                            $transfer['new_branch']
                                            ?? '—'
                                        ),
                                        ENT_QUOTES,
                                        'UTF-8'
                                    ) ?>
                                </strong>

                                <?php if (
                                    !empty(
                                        $transfer['new_department']
                                    )
                                ): ?>

                                    <small class="d-block text-muted">

                                        <?= htmlspecialchars(
                                            (string) $transfer[
                                                'new_department'
                                            ],
                                            ENT_QUOTES,
                                            'UTF-8'
                                        ) ?>

                                    </small>

                                <?php endif; ?>


                                <?php if (
                                    !empty(
                                        $transfer['new_position']
                                    )
                                ): ?>

                                    <small class="d-block text-muted">

                                        <?= htmlspecialchars(
                                            (string) $transfer[
                                                'new_position'
                                            ],
                                            ENT_QUOTES,
                                            'UTF-8'
                                        ) ?>

                                    </small>

                                <?php endif; ?>

                            </td>


                            <td>
                                <?= htmlspecialchars(
                                    (string) (
                                        $transfer['order_number']
                                        ?? '—'
                                    ),
                                    ENT_QUOTES,
                                    'UTF-8'
                                ) ?>
                            </td>


                            <td>

                                <?php if (
                                    !empty(
                                        $transfer[
                                            'document_file_path'
                                        ]
                                    )
                                    && (int) (
                                        $transfer['status']
                                        ?? 0
                                    ) === 1
                                ): ?>

                                    <a
                                        href="/public/employees/transfers/document?id=<?= (int) $transfer['id'] ?>"
                                        target="_blank"
                                        class="btn btn-sm btn-outline-primary"
                                        title="View Transfer Document">

                                        <i class="bi bi-file-earmark-text"></i>

                                    </a>

                                <?php else: ?>

                                    <span class="text-muted">
                                        —
                                    </span>

                                <?php endif; ?>

                            </td>


                            <td>

                                <?php if (
                                    (int) (
                                        $transfer['status']
                                        ?? 0
                                    ) === 1
                                ): ?>

                                    <span class="badge text-bg-success">
                                        Active
                                    </span>

                                <?php else: ?>

                                    <span class="badge text-bg-secondary">
                                        Inactive
                                    </span>

                                <?php endif; ?>

                            </td>


                            <td class="text-end">
<button
    type="button"
    class="btn btn-sm btn-outline-warning edit-transfer-btn"
    title="Edit Transfer"
    data-bs-toggle="modal"
    data-bs-target="#editTransferModal"

    data-id="<?= (int) $transfer['id'] ?>"

    data-transfer-type="<?= htmlspecialchars(
        (string) ($transfer['transfer_type'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-effective-date="<?= htmlspecialchars(
        (string) ($transfer['effective_date'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-order-number="<?= htmlspecialchars(
        (string) ($transfer['order_number'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-previous-branch="<?= htmlspecialchars(
        (string) ($transfer['previous_branch'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-previous-department="<?= htmlspecialchars(
        (string) ($transfer['previous_department'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-previous-position="<?= htmlspecialchars(
        (string) ($transfer['previous_position'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-previous-state="<?= htmlspecialchars(
        (string) ($transfer['previous_state'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-previous-county="<?= htmlspecialchars(
        (string) ($transfer['previous_county'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-previous-payam="<?= htmlspecialchars(
        (string) ($transfer['previous_payam'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-new-branch="<?= htmlspecialchars(
        (string) ($transfer['new_branch'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-new-department="<?= htmlspecialchars(
        (string) ($transfer['new_department'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-new-position="<?= htmlspecialchars(
        (string) ($transfer['new_position'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-new-state="<?= htmlspecialchars(
        (string) ($transfer['new_state'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-new-county="<?= htmlspecialchars(
        (string) ($transfer['new_county'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-new-payam="<?= htmlspecialchars(
        (string) ($transfer['new_payam'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-reason="<?= htmlspecialchars(
        (string) ($transfer['reason'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>"

    data-notes="<?= htmlspecialchars(
        (string) ($transfer['notes'] ?? ''),
        ENT_QUOTES,
        'UTF-8'
    ) ?>">

    <i class="bi bi-pencil"></i>

</button>

                                <form
                                    method="POST"
                                    action="/public/employees/transfers/toggle-status"
                                    class="d-inline">

                                    <input
                                        type="hidden"
                                        name="id"
                                        value="<?= (int) $transfer['id'] ?>">

                                    <input
                                        type="hidden"
                                        name="employee_id"
                                        value="<?= (int) $employee['id'] ?>">


                                    <?php if (
                                        (int) (
                                            $transfer['status']
                                            ?? 0
                                        ) === 1
                                    ): ?>

                                        <button
                                            type="submit"
                                            class="btn btn-sm btn-outline-danger"
                                            title="Deactivate Transfer"
                                            onclick="return confirm('Deactivate this transfer record?');">

                                            <i class="bi bi-x-circle"></i>

                                        </button>

                                    <?php else: ?>

                                        <button
                                            type="submit"
                                            class="btn btn-sm btn-outline-success"
                                            title="Activate Transfer"
                                            onclick="return confirm('Activate this transfer record?');">

                                            <i class="bi bi-check-circle"></i>

                                        </button>

                                    <?php endif; ?>

                                </form>

                            </td>

                        </tr>

                    <?php endforeach; ?>

                <?php endif; ?>

                </tbody>

            </table>

        </div>

    </div>

</div>
    <!-- REGISTRATION STATUS -->

    <div class="card shadow-sm border-0">

        <div class="card-header bg-white py-3">

            <h5 class="mb-0">

                <i class="bi bi-shield-check me-2"></i>

                Registration Status

            </h5>

        </div>


        <div class="card-body">

            <div class="row g-4">


                <div class="col-md-6">

                    <small class="text-muted d-block">
                        Employment Status
                    </small>

                    <span
                        class="badge <?= $employmentClass ?>">

                        <?= htmlspecialchars(
                            ucwords(
                                strtolower(
                                    str_replace(
                                        '_',
                                        ' ',
                                        $employmentStatus
                                    )
                                )
                            ),
                            ENT_QUOTES,
                            'UTF-8'
                        ) ?>

                    </span>

                </div>


                <div class="col-md-6">

                    <small class="text-muted d-block">
                        Biometric Status
                    </small>

                    <span
                        class="badge <?= $biometricClass ?>">

                        <?= htmlspecialchars(
                            ucwords(
                                strtolower(
                                    str_replace(
                                        '_',
                                        ' ',
                                        $biometricStatus
                                    )
                                )
                            ),
                            ENT_QUOTES,
                            'UTF-8'
                        ) ?>

                    </span>

                </div>

            </div>

        </div>

    </div>

</div>

</div>

<!-- ADD FAMILY MEMBER MODAL -->

<div
    class="modal fade"
    id="addFamilyModal"
    tabindex="-1">

    <div class="modal-dialog modal-lg">

        <div class="modal-content">

            <form
                method="POST"
                action="/public/employees/family/create">

                <input
                    type="hidden"
                    name="employee_id"
                    value="<?= (int) $employee['id'] ?>">

                <div class="modal-header">

                    <h5 class="modal-title">
                        Add Family Member
                    </h5>

                    <button
                        type="button"
                        class="btn-close"
                        data-bs-dismiss="modal">
                    </button>

                </div>

                <div class="modal-body">

                    <div class="row g-3">

                        <div class="col-md-6">
                            <label class="form-label">
                                Full Name
                            </label>

                            <input
                                type="text"
                                name="full_name"
                                class="form-control"
                                required>
                        </div>

                        <div class="col-md-6">
                            <label class="form-label">
                                Relationship
                            </label>

                            <select
                                name="relationship_type"
                                class="form-select"
                                required>

                                <option value="">
                                    Select Relationship
                                </option>

                                <option value="SPOUSE">Spouse</option>
                                <option value="FATHER">Father</option>
                                <option value="MOTHER">Mother</option>
                                <option value="SON">Son</option>
                                <option value="DAUGHTER">Daughter</option>
                                <option value="BROTHER">Brother</option>
                                <option value="SISTER">Sister</option>
                                <option value="GUARDIAN">Guardian</option>
                                <option value="OTHER">Other</option>

                            </select>
                        </div>

                        <div class="col-md-6">
                            <label class="form-label">
                                Gender
                            </label>

                            <select
                                name="gender"
                                class="form-select">

                                <option value="">
                                    Select Gender
                                </option>

                                <option value="MALE">Male</option>
                                <option value="FEMALE">Female</option>
                                <option value="OTHER">Other</option>

                            </select>
                        </div>

                        <div class="col-md-6">
                            <label class="form-label">
                                Date of Birth
                            </label>

                            <input
                                type="date"
                                name="date_of_birth"
                                class="form-control">
                        </div>

                        <div class="col-md-6">
                            <label class="form-label">
                                Phone Number
                            </label>

                            <input
                                type="text"
                                name="phone_number"
                                class="form-control">
                        </div>

                        <div class="col-md-6">
                            <label class="form-label">
                                Occupation
                            </label>

                            <input
                                type="text"
                                name="occupation"
                                class="form-control">
                        </div>

                        <div class="col-12">
                            <label class="form-label">
                                Address
                            </label>

                            <textarea
                                name="address"
                                class="form-control"
                                rows="3"></textarea>
                        </div>

                        <div class="col-12">

                            <div class="form-check form-switch">

                                <input
                                    type="checkbox"
                                    name="is_emergency_contact"
                                    value="1"
                                    id="is_emergency_contact"
                                    class="form-check-input">

                                <label
                                    for="is_emergency_contact"
                                    class="form-check-label">

                                    Emergency Contact

                                </label>

                            </div>

                        </div>

                    </div>

                </div>

                <div class="modal-footer">

                    <button
                        type="button"
                        class="btn btn-light"
                        data-bs-dismiss="modal">

                        Cancel

                    </button>

                    <button
                        type="submit"
                        class="btn btn-primary">

                        <i class="bi bi-save me-1"></i>
                        Save Family Member

                    </button>

                </div>

            </form>

        </div>

    </div>

</div>

<!-- EDIT FAMILY MEMBER MODAL -->

<div
    class="modal fade"
    id="editFamilyModal"
    tabindex="-1">

    <div class="modal-dialog modal-lg">

        <div class="modal-content">

            <form
                method="POST"
                action="/public/employees/family/update">

                <input
                    type="hidden"
                    name="id"
                    id="edit_family_id">

                <input
                    type="hidden"
                    name="employee_id"
                    value="<?= (int) $employee['id'] ?>">

                <div class="modal-header">

                    <h5 class="modal-title">
                        Edit Family Member
                    </h5>

                    <button
                        type="button"
                        class="btn-close"
                        data-bs-dismiss="modal">
                    </button>

                </div>

                <div class="modal-body">

                    <div class="row g-3">

                        <div class="col-md-6">

                            <label class="form-label">
                                Full Name
                            </label>

                            <input
                                type="text"
                                name="full_name"
                                id="edit_family_full_name"
                                class="form-control"
                                required>

                        </div>

                        <div class="col-md-6">

                            <label class="form-label">
                                Relationship
                            </label>

                            <select
                                name="relationship_type"
                                id="edit_family_relationship"
                                class="form-select"
                                required>

                                <option value="SPOUSE">Spouse</option>
                                <option value="FATHER">Father</option>
                                <option value="MOTHER">Mother</option>
                                <option value="SON">Son</option>
                                <option value="DAUGHTER">Daughter</option>
                                <option value="BROTHER">Brother</option>
                                <option value="SISTER">Sister</option>
                                <option value="GUARDIAN">Guardian</option>
                                <option value="OTHER">Other</option>

                            </select>

                        </div>

                        <div class="col-md-6">

                            <label class="form-label">
                                Gender
                            </label>

                            <select
                                name="gender"
                                id="edit_family_gender"
                                class="form-select">

                                <option value="">
                                    Select Gender
                                </option>

                                <option value="MALE">
                                    Male
                                </option>

                                <option value="FEMALE">
                                    Female
                                </option>

                                <option value="OTHER">
                                    Other
                                </option>

                            </select>

                        </div>

                        <div class="col-md-6">

                            <label class="form-label">
                                Date of Birth
                            </label>

                            <input
                                type="date"
                                name="date_of_birth"
                                id="edit_family_date_of_birth"
                                class="form-control">

                        </div>

                        <div class="col-md-6">

                            <label class="form-label">
                                Phone Number
                            </label>

                            <input
                                type="text"
                                name="phone_number"
                                id="edit_family_phone_number"
                                class="form-control">

                        </div>

                        <div class="col-md-6">

                            <label class="form-label">
                                Occupation
                            </label>

                            <input
                                type="text"
                                name="occupation"
                                id="edit_family_occupation"
                                class="form-control">

                        </div>

                        <div class="col-12">

                            <label class="form-label">
                                Address
                            </label>

                            <textarea
                                name="address"
                                id="edit_family_address"
                                class="form-control"
                                rows="3"></textarea>

                        </div>

                        <div class="col-12">

                            <div class="form-check form-switch">

                                <input
                                    type="checkbox"
                                    name="is_emergency_contact"
                                    value="1"
                                    id="edit_family_emergency"
                                    class="form-check-input">

                                <label
                                    for="edit_family_emergency"
                                    class="form-check-label">

                                    Emergency Contact

                                </label>

                            </div>

                        </div>

                    </div>

                </div>

                <div class="modal-footer">

                    <button
                        type="button"
                        class="btn btn-light"
                        data-bs-dismiss="modal">

                        Cancel

                    </button>

                    <button
                        type="submit"
                        class="btn btn-primary">

                        <i class="bi bi-save me-1"></i>
                        Save Changes

                    </button>

                </div>

            </form>

        </div>

    </div>

</div>


<!-- UPLOAD DOCUMENT MODAL -->

<div
    class="modal fade"
    id="uploadDocumentModal"
    tabindex="-1">

    <div class="modal-dialog modal-lg">

        <div class="modal-content">

            <form
                method="POST"
                action="/public/employees/documents/create"
                enctype="multipart/form-data">

                <input
                    type="hidden"
                    name="employee_id"
                    value="<?= (int) $employee['id'] ?>">

                <div class="modal-header">

                    <h5 class="modal-title">
                        Upload Employee Document
                    </h5>

                    <button
                        type="button"
                        class="btn-close"
                        data-bs-dismiss="modal">
                    </button>

                </div>

                <div class="modal-body">

                    <div class="row g-3">

                        <div class="col-md-6">

                            <label class="form-label">
                                Document Type
                            </label>

                            <select
                                name="document_type"
                                class="form-select"
                                required>

                                <option value="">
                                    Select Document Type
                                </option>

                                <option value="National ID">
                                    National ID
                                </option>

                                <option value="Passport">
                                    Passport
                                </option>

                                <option value="Appointment Letter">
                                    Appointment Letter
                                </option>

                                <option value="Promotion Order">
                                    Promotion Order
                                </option>

                                <option value="Transfer Order">
                                    Transfer Order
                                </option>

                                <option value="Training Certificate">
                                    Training Certificate
                                </option>

                                <option value="Education Certificate">
                                    Education Certificate
                                </option>

                                <option value="Medical Document">
                                    Medical Document
                                </option>

                                <option value="Disciplinary Document">
                                    Disciplinary Document
                                </option>

                                <option value="Other">
                                    Other
                                </option>

                            </select>

                        </div>

                        <div class="col-md-6">

                            <label class="form-label">
                                Document Title
                            </label>

                            <input
                                type="text"
                                name="document_title"
                                class="form-control"
                                required>

                        </div>

                        <div class="col-md-6">

                            <label class="form-label">
                                Document Number
                            </label>

                            <input
                                type="text"
                                name="document_number"
                                class="form-control">

                        </div>

                        <div class="col-md-6">

                            <label class="form-label">
                                Issuing Authority
                            </label>

                            <input
                                type="text"
                                name="issuing_authority"
                                class="form-control">

                        </div>

                        <div class="col-md-6">

                            <label class="form-label">
                                Issue Date
                            </label>

                            <input
                                type="date"
                                name="issue_date"
                                class="form-control">

                        </div>

                        <div class="col-md-6">

                            <label class="form-label">
                                Expiry Date
                            </label>

                            <input
                                type="date"
                                name="expiry_date"
                                class="form-control">

                        </div>

                        <div class="col-12">

                            <label class="form-label">
                                Document File
                            </label>

                            <input
                                type="file"
                                name="document_file"
                                class="form-control"
                                accept=".pdf,.jpg,.jpeg,.png,.doc,.docx"
                                required>

                            <div class="form-text">
                                PDF, JPG, PNG, DOC or DOCX. Maximum 10 MB.
                            </div>

                        </div>

                        <div class="col-12">

                            <label class="form-label">
                                Notes
                            </label>

                            <textarea
                                name="notes"
                                class="form-control"
                                rows="3"></textarea>

                        </div>

                    </div>

                </div>

                <div class="modal-footer">

                    <button
                        type="button"
                        class="btn btn-light"
                        data-bs-dismiss="modal">

                        Cancel

                    </button>

                    <button
                        type="submit"
                        class="btn btn-primary">

                        <i class="bi bi-cloud-upload me-1"></i>
                        Upload Document

                    </button>

                </div>

            </form>

        </div>

    </div>

</div>
<!-- =========================================================
     ADD TRAINING MODAL
========================================================= -->

<div
    class="modal fade"
    id="addTrainingModal"
    tabindex="-1"
    aria-hidden="true">

    <div class="modal-dialog modal-xl modal-dialog-scrollable">

        <div class="modal-content">

            <form
                method="POST"
                action="/public/employees/training/create"
                enctype="multipart/form-data">

                <input
                    type="hidden"
                    name="employee_id"
                    value="<?= (int) $employee['id'] ?>">


                <div class="modal-header">

                    <h5 class="modal-title">

                        <i class="bi bi-mortarboard me-2"></i>

                        Add Training Record

                    </h5>

                    <button
                        type="button"
                        class="btn-close"
                        data-bs-dismiss="modal">
                    </button>

                </div>


                <div class="modal-body">

                    <div class="row g-3">


                        <!-- TITLE -->

                        <div class="col-md-8">

                            <label class="form-label">
                                Training Title
                                <span class="text-danger">*</span>
                            </label>

                            <input
                                type="text"
                                name="training_title"
                                class="form-control"
                                required>

                        </div>


                        <!-- TYPE -->

                        <div class="col-md-4">

                            <label class="form-label">
                                Training Type
                            </label>

                            <select
                                name="training_type"
                                class="form-select">

                                <option value="">
                                    Select Type
                                </option>

                                <option value="Basic Training">
                                    Basic Training
                                </option>

                                <option value="Specialized Training">
                                    Specialized Training
                                </option>

                                <option value="Leadership and Command">
                                    Leadership and Command
                                </option>

                                <option value="ICT">
                                    ICT
                                </option>

                                <option value="Investigation">
                                    Investigation
                                </option>

                                <option value="Traffic">
                                    Traffic
                                </option>

                                <option value="Public Order">
                                    Public Order
                                </option>

                                <option value="Human Rights">
                                    Human Rights
                                </option>

                                <option value="Community Policing">
                                    Community Policing
                                </option>

                                <option value="UN Training">
                                    UN Training
                                </option>

                                <option value="International Training">
                                    International Training
                                </option>

                                <option value="Other">
                                    Other
                                </option>

                            </select>

                        </div>


                        <!-- INSTITUTION -->

                        <div class="col-md-6">

                            <label class="form-label">
                                Training Institution
                            </label>

                            <input
                                type="text"
                                name="institution"
                                class="form-control">

                        </div>


                        <!-- SPONSOR -->

                        <div class="col-md-6">

                            <label class="form-label">
                                Sponsor
                            </label>

                            <input
                                type="text"
                                name="sponsor"
                                class="form-control">

                        </div>


                        <!-- COUNTRY -->

                        <div class="col-md-6">

                            <label class="form-label">
                                Country
                            </label>

                            <input
                                type="text"
                                name="country"
                                class="form-control">

                        </div>


                        <!-- LOCATION -->

                        <div class="col-md-6">

                            <label class="form-label">
                                Location
                            </label>

                            <input
                                type="text"
                                name="location"
                                class="form-control">

                        </div>


                        <!-- START DATE -->

                        <div class="col-md-6">

                            <label class="form-label">
                                Start Date
                            </label>

                            <input
                                type="date"
                                name="start_date"
                                class="form-control">

                        </div>


                        <!-- END DATE -->

                        <div class="col-md-6">

                            <label class="form-label">
                                End Date
                            </label>

                            <input
                                type="date"
                                name="end_date"
                                class="form-control">

                        </div>


                        <!-- CERTIFICATE NUMBER -->

                        <div class="col-md-6">

                            <label class="form-label">
                                Certificate Number
                            </label>

                            <input
                                type="text"
                                name="certificate_number"
                                class="form-control">

                        </div>


                        <!-- QUALIFICATION -->

                        <div class="col-md-6">

                            <label class="form-label">
                                Qualification / Result
                            </label>

                            <input
                                type="text"
                                name="qualification"
                                class="form-control"
                                placeholder="Example: Certificate, Diploma, Passed">

                        </div>


                        <!-- CERTIFICATE FILE -->

                        <div class="col-12">

                            <label class="form-label">
                                Certificate or Supporting Document
                            </label>

                            <input
                                type="file"
                                name="certificate_file"
                                class="form-control"
                                accept=".pdf,.jpg,.jpeg,.png,.doc,.docx">

                            <div class="form-text">

                                Optional. PDF, JPG, PNG, DOC or DOCX.
                                Maximum 10 MB.

                                The file will be stored in this employee's
                                training folder.

                            </div>

                        </div>


                        <!-- NOTES -->

                        <div class="col-12">

                            <label class="form-label">
                                Notes
                            </label>

                            <textarea
                                name="notes"
                                class="form-control"
                                rows="3"></textarea>

                        </div>


                    </div>

                </div>


                <div class="modal-footer">

                    <button
                        type="button"
                        class="btn btn-light"
                        data-bs-dismiss="modal">

                        Cancel

                    </button>

                    <button
                        type="submit"
                        class="btn btn-primary">

                        <i class="bi bi-save me-1"></i>

                        Save Training

                    </button>

                </div>

            </form>

        </div>

    </div>

</div>

<!-- =========================================================
     EDIT TRAINING MODAL
========================================================= -->
<br>
<div
    class="modal fade"
    id="editTrainingModal"
    tabindex="-1"
    aria-hidden="true">

    <div class="modal-dialog modal-xl modal-dialog-scrollable">

        <div class="modal-content">

            <form
                method="POST"
                action="/public/employees/training/update"
                enctype="multipart/form-data">

                <input
                    type="hidden"
                    name="id"
                    id="editTrainingId">

                <input
                    type="hidden"
                    name="employee_id"
                    value="<?= (int) $employee['id'] ?>">

                <div class="modal-header">

                    <h5 class="modal-title">
                        <i class="bi bi-pencil-square me-2"></i>
                        Edit Training Record
                    </h5>

                    <button
                        type="button"
                        class="btn-close"
                        data-bs-dismiss="modal">
                    </button>

                </div>

                <div class="modal-body">

                    <div class="row g-3">

                        <div class="col-md-8">

                            <label class="form-label">
                                Training Title
                                <span class="text-danger">*</span>
                            </label>

                            <input
                                type="text"
                                name="training_title"
                                id="editTrainingTitle"
                                class="form-control"
                                required>

                        </div>

                        <div class="col-md-4">

                            <label class="form-label">
                                Training Type
                            </label>

                            <select
                                name="training_type"
                                id="editTrainingType"
                                class="form-select">

                                <option value="">
                                    Select Type
                                </option>

                                <option value="Basic Training">
                                    Basic Training
                                </option>

                                <option value="Specialized Training">
                                    Specialized Training
                                </option>

                                <option value="Leadership and Command">
                                    Leadership and Command
                                </option>

                                <option value="ICT">
                                    ICT
                                </option>

                                <option value="Investigation">
                                    Investigation
                                </option>

                                <option value="Traffic">
                                    Traffic
                                </option>

                                <option value="Public Order">
                                    Public Order
                                </option>

                                <option value="Human Rights">
                                    Human Rights
                                </option>

                                <option value="Community Policing">
                                    Community Policing
                                </option>

                                <option value="UN Training">
                                    UN Training
                                </option>

                                <option value="International Training">
                                    International Training
                                </option>

                                <option value="Other">
                                    Other
                                </option>

                            </select>

                        </div>

                        <div class="col-md-6">

                            <label class="form-label">
                                Training Institution
                            </label>

                            <input
                                type="text"
                                name="institution"
                                id="editTrainingInstitution"
                                class="form-control">

                        </div>

                        <div class="col-md-6">

                            <label class="form-label">
                                Sponsor
                            </label>

                            <input
                                type="text"
                                name="sponsor"
                                id="editTrainingSponsor"
                                class="form-control">

                        </div>

                        <div class="col-md-6">

                            <label class="form-label">
                                Country
                            </label>

                            <input
                                type="text"
                                name="country"
                                id="editTrainingCountry"
                                class="form-control">

                        </div>

                        <div class="col-md-6">

                            <label class="form-label">
                                Location
                            </label>

                            <input
                                type="text"
                                name="location"
                                id="editTrainingLocation"
                                class="form-control">

                        </div>

                        <div class="col-md-6">

                            <label class="form-label">
                                Start Date
                            </label>

                            <input
                                type="date"
                                name="start_date"
                                id="editTrainingStartDate"
                                class="form-control">

                        </div>

                        <div class="col-md-6">

                            <label class="form-label">
                                End Date
                            </label>

                            <input
                                type="date"
                                name="end_date"
                                id="editTrainingEndDate"
                                class="form-control">

                        </div>

                        <div class="col-md-6">

                            <label class="form-label">
                                Certificate Number
                            </label>

                            <input
                                type="text"
                                name="certificate_number"
                                id="editTrainingCertificateNumber"
                                class="form-control">

                        </div>

                        <div class="col-md-6">

                            <label class="form-label">
                                Qualification / Result
                            </label>

                            <input
                                type="text"
                                name="qualification"
                                id="editTrainingQualification"
                                class="form-control">

                        </div>

                        <div class="col-12">

                            <label class="form-label">
                                Replace Certificate
                            </label>

                            <input
                                type="file"
                                name="certificate_file"
                                class="form-control"
                                accept=".pdf,.jpg,.jpeg,.png,.doc,.docx">

                            <div class="form-text">
                                Leave this empty to keep the current certificate.
                                Uploading a new file will replace the existing certificate.
                            </div>

                        </div>

                        <div class="col-12">

                            <label class="form-label">
                                Notes
                            </label>

                            <textarea
                                name="notes"
                                id="editTrainingNotes"
                                class="form-control"
                                rows="3"></textarea>

                        </div>

                    </div>

                </div>

                <div class="modal-footer">

                    <button
                        type="button"
                        class="btn btn-light"
                        data-bs-dismiss="modal">

                        Cancel

                    </button>

                    <button
                        type="submit"
                        class="btn btn-primary">

                        <i class="bi bi-save me-1"></i>
                        Update Training

                    </button>

                </div>

            </form>

        </div>

    </div>

</div>
  <!-- =========================================================
     ADD TRANSFER MODAL
========================================================= -->

<div
    class="modal fade"
    id="addTransferModal"
    tabindex="-1"
    aria-hidden="true">

<div class="modal-dialog modal-lg modal-dialog-scrollable">

        <div class="modal-content">

            <form
                method="POST"
                action="/public/employees/transfers/create"
                enctype="multipart/form-data">

                <input
                    type="hidden"
                    name="employee_id"
                    value="<?= (int) $employee['id'] ?>">


                <div class="modal-header">

                    <h5 class="modal-title">

                        <i class="bi bi-arrow-left-right me-2"></i>
                        Add Transfer Record

                    </h5>

                    <button
                        type="button"
                        class="btn-close"
                        data-bs-dismiss="modal">
                    </button>

                </div>


                <div class="modal-body">

                    <div class="row g-3">


                        <div class="col-md-4">

                            <label class="form-label">
                                Transfer Type
                                <span class="text-danger">*</span>
                            </label>

                            <select
                                name="transfer_type"
                                class="form-select"
                                required>

                                <option value="">
                                    Select Type
                                </option>

                                <option value="Permanent Transfer">
                                    Permanent Transfer
                                </option>

                                <option value="Temporary Transfer">
                                    Temporary Transfer
                                </option>

                                <option value="Deployment">
                                    Deployment
                                </option>

                                <option value="Secondment">
                                    Secondment
                                </option>

                                <option value="Reassignment">
                                    Reassignment
                                </option>

                                <option value="Posting">
                                    Posting
                                </option>

                                <option value="Other">
                                    Other
                                </option>

                            </select>

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Effective Date
                                <span class="text-danger">*</span>
                            </label>

                            <input
                                type="date"
                                name="effective_date"
                                class="form-control"
                                required>

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Order / Reference Number
                            </label>

                            <input
                                type="text"
                                name="order_number"
                                class="form-control">

                        </div>


                        <!-- PREVIOUS ASSIGNMENT -->

                        <div class="col-12 mt-4">

                            <h6 class="border-bottom pb-2">
                                Previous Assignment
                            </h6>

                            <div class="form-text">
                                These fields preserve the employee's assignment
                                before the transfer.
                            </div>

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Previous Branch
                            </label>

                            <input
                                type="text"
                                name="previous_branch"
                                class="form-control"
                                value="<?= htmlspecialchars(
                                    (string) (
                                        $employee['branch_name']
                                        ?? ''
                                    ),
                                    ENT_QUOTES,
                                    'UTF-8'
                                ) ?>">

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Previous Department
                            </label>

                            <input
                                type="text"
                                name="previous_department"
                                class="form-control"
                                value="<?= htmlspecialchars(
                                    (string) (
                                        $employee['department_name']
                                        ?? ''
                                    ),
                                    ENT_QUOTES,
                                    'UTF-8'
                                ) ?>">

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Previous Position
                            </label>

                            <input
                                type="text"
                                name="previous_position"
                                class="form-control"
                                value="<?= htmlspecialchars(
                                    (string) (
                                        $employee['position_name']
                                        ?? ''
                                    ),
                                    ENT_QUOTES,
                                    'UTF-8'
                                ) ?>">

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Previous State
                            </label>

                            <input
                                type="text"
                                name="previous_state"
                                class="form-control"
                                value="<?= htmlspecialchars(
                                    (string) (
                                        $employee['state_name']
                                        ?? ''
                                    ),
                                    ENT_QUOTES,
                                    'UTF-8'
                                ) ?>">

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Previous County
                            </label>

                            <input
                                type="text"
                                name="previous_county"
                                class="form-control"
                                value="<?= htmlspecialchars(
                                    (string) (
                                        $employee['county_name']
                                        ?? ''
                                    ),
                                    ENT_QUOTES,
                                    'UTF-8'
                                ) ?>">

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Previous Payam
                            </label>

                            <input
                                type="text"
                                name="previous_payam"
                                class="form-control"
                                value="<?= htmlspecialchars(
                                    (string) (
                                        $employee['payam_name']
                                        ?? ''
                                    ),
                                    ENT_QUOTES,
                                    'UTF-8'
                                ) ?>">

                        </div>


                        <!-- NEW ASSIGNMENT -->

                        <div class="col-12 mt-4">

                            <h6 class="border-bottom pb-2">
                                New Assignment
                            </h6>

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                New Branch
                            </label>

                            <input
                                type="text"
                                name="new_branch"
                                class="form-control">

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                New Department
                            </label>

                            <input
                                type="text"
                                name="new_department"
                                class="form-control">

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                New Position
                            </label>

                            <input
                                type="text"
                                name="new_position"
                                class="form-control">

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                New State
                            </label>

                            <input
                                type="text"
                                name="new_state"
                                class="form-control">

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                New County
                            </label>

                            <input
                                type="text"
                                name="new_county"
                                class="form-control">

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                New Payam
                            </label>

                            <input
                                type="text"
                                name="new_payam"
                                class="form-control">

                        </div>


                        <div class="col-12">

                            <label class="form-label">
                                Reason for Transfer
                            </label>

                            <textarea
                                name="reason"
                                class="form-control"
                                rows="3"></textarea>

                        </div>


                        <div class="col-12">

                            <label class="form-label">
                                Transfer Order / Supporting Document
                            </label>

                            <input
                                type="file"
                                name="document_file"
                                class="form-control"
                                accept=".pdf,.jpg,.jpeg,.png,.doc,.docx">

                            <div class="form-text">
                                Optional. PDF, JPG, PNG, DOC or DOCX.
                                Maximum 10 MB. The file will be stored in
                                this employee's transfers folder.
                            </div>

                        </div>


                        <div class="col-12">

                            <label class="form-label">
                                Notes
                            </label>

                            <textarea
                                name="notes"
                                class="form-control"
                                rows="3"></textarea>

                        </div>

                    </div>

                </div>


<div class="modal-footer bg-white sticky-bottom">
                    <button
                        type="button"
                        class="btn btn-light"
                        data-bs-dismiss="modal">

                        Cancel

                    </button>

                    <button
                        type="submit"
                        class="btn btn-primary">

                        <i class="bi bi-save me-1"></i>
                        Save Transfer

                    </button>

                </div>

            </form>

        </div>

    </div>

</div>
<!-- =========================================================
     RANK PROMOTION HISTORY
========================================================= -->

<div class="card shadow-sm border-0 mb-4">

    <div class="card-header bg-white py-3">

        <div class="d-flex justify-content-between align-items-center">

            <h5 class="mb-0">
                <i class="bi bi-award me-2"></i>
                Rank Promotion History
            </h5>

            <button
                type="button"
                class="btn btn-sm btn-primary"
                data-bs-toggle="modal"
                data-bs-target="#addPromotionModal">

                <i class="bi bi-plus-circle me-1"></i>
                Add Promotion

            </button>

        </div>

    </div>


    <div class="card-body">

        <?php if (!empty($promotionCreated)): ?>

            <div class="alert alert-success alert-dismissible fade show">

                Promotion record added successfully.

                <button
                    type="button"
                    class="btn-close"
                    data-bs-dismiss="alert">
                </button>

            </div>

        <?php endif; ?>
<?php if (!empty($promotionUpdated)): ?>

    <div class="alert alert-success alert-dismissible fade show">

        Promotion record updated successfully.

        <button
            type="button"
            class="btn-close"
            data-bs-dismiss="alert">
        </button>

    </div>

<?php endif; ?>

        <?php if (!empty($promotionStatusUpdated)): ?>

            <div class="alert alert-success alert-dismissible fade show">

                Promotion status updated successfully.

                <button
                    type="button"
                    class="btn-close"
                    data-bs-dismiss="alert">
                </button>

            </div>

        <?php endif; ?>


        <?php if (!empty($promotionError)): ?>

            <div class="alert alert-danger alert-dismissible fade show">

                <?= htmlspecialchars(
                    (string) $promotionError,
                    ENT_QUOTES,
                    'UTF-8'
                ) ?>

                <button
                    type="button"
                    class="btn-close"
                    data-bs-dismiss="alert">
                </button>

            </div>

        <?php endif; ?>


        <div class="table-responsive">

            <table class="table table-hover align-middle">

                <thead>

                    <tr>
                        <th>Effective Date</th>
                        <th>Promotion Type</th>
                        <th>Previous Rank</th>
                        <th>New Rank</th>
                        <th>Order No.</th>
                        <th>Document</th>
                        <th>Status</th>
                        <th class="text-end">
                            Actions
                        </th>
                    </tr>

                </thead>


                <tbody>

                <?php if (empty($promotionHistory)): ?>

                    <tr>

                        <td
                            colspan="8"
                            class="text-center text-muted py-4">

                            No promotion history recorded.

                        </td>

                    </tr>

                <?php else: ?>

                    <?php foreach ($promotionHistory as $promotion): ?>

                        <tr>

                            <td>
                                <?= htmlspecialchars(
                                    (string) (
                                        $promotion['effective_date']
                                        ?? '—'
                                    ),
                                    ENT_QUOTES,
                                    'UTF-8'
                                ) ?>
                            </td>


                            <td>
                                <?= htmlspecialchars(
                                    (string) (
                                        $promotion['promotion_type']
                                        ?? '—'
                                    ),
                                    ENT_QUOTES,
                                    'UTF-8'
                                ) ?>
                            </td>


                            <td>
                                <?= htmlspecialchars(
                                    (string) (
                                        $promotion['previous_rank_name']
                                        ?? '—'
                                    ),
                                    ENT_QUOTES,
                                    'UTF-8'
                                ) ?>
                            </td>


                            <td>

                                <strong>
                                    <?= htmlspecialchars(
                                        (string) (
                                            $promotion['new_rank_name']
                                            ?? '—'
                                        ),
                                        ENT_QUOTES,
                                        'UTF-8'
                                    ) ?>
                                </strong>

                            </td>


                            <td>
                                <?= htmlspecialchars(
                                    (string) (
                                        $promotion['order_number']
                                        ?? '—'
                                    ),
                                    ENT_QUOTES,
                                    'UTF-8'
                                ) ?>
                            </td>


                            <td>

                                <?php if (
                                    !empty(
                                        $promotion[
                                            'document_file_path'
                                        ]
                                    )
                                    && (int) (
                                        $promotion['status']
                                        ?? 0
                                    ) === 1
                                ): ?>

                                    <a
                                        href="/public/employees/promotions/document?id=<?= (int) $promotion['id'] ?>"
                                        target="_blank"
                                        class="btn btn-sm btn-outline-primary"
                                        title="View Promotion Document">

                                        <i class="bi bi-file-earmark-text"></i>

                                    </a>

                                <?php else: ?>

                                    <span class="text-muted">
                                        —
                                    </span>

                                <?php endif; ?>

                            </td>


                            <td>

                                <?php if (
                                    (int) (
                                        $promotion['status']
                                        ?? 0
                                    ) === 1
                                ): ?>

                                    <span class="badge text-bg-success">
                                        Active
                                    </span>

                                <?php else: ?>

                                    <span class="badge text-bg-secondary">
                                        Inactive
                                    </span>

                                <?php endif; ?>

                            </td>


<td class="text-end">

    <div class="d-inline-flex align-items-center justify-content-end gap-1">

        <button
            type="button"
            class="btn btn-sm btn-outline-warning edit-promotion-btn"
            title="Edit Promotion"
            data-bs-toggle="modal"
            data-bs-target="#editPromotionModal"

            data-id="<?= (int) $promotion['id'] ?>"

            data-previous-rank-id="<?= (int) (
                $promotion['previous_rank_id']
                ?? 0
            ) ?>"

            data-new-rank-id="<?= (int) (
                $promotion['new_rank_id']
                ?? 0
            ) ?>"

            data-promotion-type="<?= htmlspecialchars(
                (string) (
                    $promotion['promotion_type']
                    ?? ''
                ),
                ENT_QUOTES,
                'UTF-8'
            ) ?>"

            data-effective-date="<?= htmlspecialchars(
                (string) (
                    $promotion['effective_date']
                    ?? ''
                ),
                ENT_QUOTES,
                'UTF-8'
            ) ?>"

            data-order-number="<?= htmlspecialchars(
                (string) (
                    $promotion['order_number']
                    ?? ''
                ),
                ENT_QUOTES,
                'UTF-8'
            ) ?>"

            data-promotion-reason="<?= htmlspecialchars(
                (string) (
                    $promotion['promotion_reason']
                    ?? ''
                ),
                ENT_QUOTES,
                'UTF-8'
            ) ?>"

            data-notes="<?= htmlspecialchars(
                (string) (
                    $promotion['notes']
                    ?? ''
                ),
                ENT_QUOTES,
                'UTF-8'
            ) ?>">

            <i class="bi bi-pencil"></i>

        </button>


        <form
            method="POST"
            action="/public/employees/promotions/toggle-status"
            class="d-inline">
                                </form>
                            </div>
                            </td>

                        </tr>

                    <?php endforeach; ?>

                <?php endif; ?>

                </tbody>

            </table>

        </div>

    </div>

</div>
<!-- =========================================================
     EDIT TRANSFER MODAL
========================================================= -->

<div
    class="modal fade"
    id="editTransferModal"
    tabindex="-1"
    aria-hidden="true">

    <div class="modal-dialog modal-lg modal-dialog-scrollable">

        <div class="modal-content">

            <form
                method="POST"
                action="/public/employees/transfers/update"
                enctype="multipart/form-data">

                <input
                    type="hidden"
                    name="id"
                    id="editTransferId">

                <input
                    type="hidden"
                    name="employee_id"
                    value="<?= (int) $employee['id'] ?>">


                <div class="modal-header">

                    <h5 class="modal-title">

                        <i class="bi bi-pencil-square me-2"></i>
                        Edit Transfer Record

                    </h5>

                    <button
                        type="button"
                        class="btn-close"
                        data-bs-dismiss="modal">
                    </button>

                </div>


                <div class="modal-body">

                    <div class="row g-3">


                        <div class="col-md-4">

                            <label class="form-label">
                                Transfer Type
                            </label>

                            <select
                                name="transfer_type"
                                id="editTransferType"
                                class="form-select"
                                required>

                                <option value="">
                                    Select Type
                                </option>

                                <option value="Permanent Transfer">
                                    Permanent Transfer
                                </option>

                                <option value="Temporary Transfer">
                                    Temporary Transfer
                                </option>

                                <option value="Deployment">
                                    Deployment
                                </option>

                                <option value="Secondment">
                                    Secondment
                                </option>

                                <option value="Reassignment">
                                    Reassignment
                                </option>

                                <option value="Posting">
                                    Posting
                                </option>

                                <option value="Other">
                                    Other
                                </option>

                            </select>

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Effective Date
                            </label>

                            <input
                                type="date"
                                name="effective_date"
                                id="editTransferEffectiveDate"
                                class="form-control"
                                required>

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Order / Reference Number
                            </label>

                            <input
                                type="text"
                                name="order_number"
                                id="editTransferOrderNumber"
                                class="form-control">

                        </div>


                        <!-- PREVIOUS ASSIGNMENT -->

                        <div class="col-12 mt-4">

                            <h6 class="border-bottom pb-2">
                                Previous Assignment
                            </h6>

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Branch
                            </label>

                            <input
                                type="text"
                                name="previous_branch"
                                id="editTransferPreviousBranch"
                                class="form-control">

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Department
                            </label>

                            <input
                                type="text"
                                name="previous_department"
                                id="editTransferPreviousDepartment"
                                class="form-control">

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Position
                            </label>

                            <input
                                type="text"
                                name="previous_position"
                                id="editTransferPreviousPosition"
                                class="form-control">

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                State
                            </label>

                            <input
                                type="text"
                                name="previous_state"
                                id="editTransferPreviousState"
                                class="form-control">

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                County
                            </label>

                            <input
                                type="text"
                                name="previous_county"
                                id="editTransferPreviousCounty"
                                class="form-control">

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Payam
                            </label>

                            <input
                                type="text"
                                name="previous_payam"
                                id="editTransferPreviousPayam"
                                class="form-control">

                        </div>


                        <!-- NEW ASSIGNMENT -->

                        <div class="col-12 mt-4">

                            <h6 class="border-bottom pb-2">
                                New Assignment
                            </h6>

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Branch
                            </label>

                            <input
                                type="text"
                                name="new_branch"
                                id="editTransferNewBranch"
                                class="form-control">

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Department
                            </label>

                            <input
                                type="text"
                                name="new_department"
                                id="editTransferNewDepartment"
                                class="form-control">

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Position
                            </label>

                            <input
                                type="text"
                                name="new_position"
                                id="editTransferNewPosition"
                                class="form-control">

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                State
                            </label>

                            <input
                                type="text"
                                name="new_state"
                                id="editTransferNewState"
                                class="form-control">

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                County
                            </label>

                            <input
                                type="text"
                                name="new_county"
                                id="editTransferNewCounty"
                                class="form-control">

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Payam
                            </label>

                            <input
                                type="text"
                                name="new_payam"
                                id="editTransferNewPayam"
                                class="form-control">

                        </div>


                        <div class="col-12">

                            <label class="form-label">
                                Reason for Transfer
                            </label>

                            <textarea
                                name="reason"
                                id="editTransferReason"
                                class="form-control"
                                rows="3"></textarea>

                        </div>


                        <div class="col-12">

                            <label class="form-label">
                                Replace Transfer Document
                            </label>

                            <input
                                type="file"
                                name="document_file"
                                class="form-control"
                                accept=".pdf,.jpg,.jpeg,.png,.doc,.docx">

                            <div class="form-text">
                                Leave empty to keep the existing document.
                            </div>

                        </div>


                        <div class="col-12">

                            <label class="form-label">
                                Notes
                            </label>

                            <textarea
                                name="notes"
                                id="editTransferNotes"
                                class="form-control"
                                rows="3"></textarea>

                        </div>

                    </div>

                </div>


                <div class="modal-footer bg-white sticky-bottom">

                    <button
                        type="button"
                        class="btn btn-light"
                        data-bs-dismiss="modal">

                        Cancel

                    </button>

                    <button
                        type="submit"
                        class="btn btn-primary">

                        <i class="bi bi-save me-1"></i>
                        Update Transfer

                    </button>

                </div>

            </form>

        </div>

    </div>

</div>
<!-- =========================================================
     ADD PROMOTION MODAL
========================================================= -->

<div
    class="modal fade"
    id="addPromotionModal"
    tabindex="-1"
    aria-hidden="true">

    <div class="modal-dialog modal-lg modal-dialog-scrollable">

        <div class="modal-content">

            <form
                method="POST"
                action="/public/employees/promotions/create"
                enctype="multipart/form-data">

                <input
                    type="hidden"
                    name="employee_id"
                    value="<?= (int) $employee['id'] ?>">


                <div class="modal-header">

                    <h5 class="modal-title">

                        <i class="bi bi-award me-2"></i>
                        Add Rank Promotion

                    </h5>

                    <button
                        type="button"
                        class="btn-close"
                        data-bs-dismiss="modal">
                    </button>

                </div>


                <div class="modal-body">

                    <div class="row g-3">


                        <div class="col-md-6">

                            <label class="form-label">
                                Previous Rank
                            </label>

                            <select
                                name="previous_rank_id"
                                class="form-select">

                                <option value="">
                                    Select Previous Rank
                                </option>

                                <?php foreach (
                                    $promotionRanks ?? []
                                    as $rank
                                ): ?>

                                    <?php
                                    $rankId = (int) (
                                        $rank['id']
                                        ?? 0
                                    );

                                    $currentRankId = (int) (
                                        $employee['rank_id']
                                        ?? 0
                                    );
                                    ?>

                                    <option
                                        value="<?= $rankId ?>"
                                        <?= $rankId === $currentRankId
                                            ? 'selected'
                                            : '' ?>>

                                        <?= htmlspecialchars(
                                            (string) (
                                                $rank['name']
                                                ?? $rank['rank_name']
                                                ?? ''
                                            ),
                                            ENT_QUOTES,
                                            'UTF-8'
                                        ) ?>

                                    </option>

                                <?php endforeach; ?>

                            </select>

                            <div class="form-text">
                                Current employee rank is selected automatically.
                            </div>

                        </div>


                        <div class="col-md-6">

                            <label class="form-label">
                                New Rank
                                <span class="text-danger">*</span>
                            </label>

                            <select
                                name="new_rank_id"
                                class="form-select"
                                required>

                                <option value="">
                                    Select New Rank
                                </option>

                                <?php foreach (
                                    $promotionRanks ?? []
                                    as $rank
                                ): ?>

                                    <option
                                        value="<?= (int) (
                                            $rank['id']
                                            ?? 0
                                        ) ?>">

                                        <?= htmlspecialchars(
                                            (string) (
                                                $rank['name']
                                                ?? $rank['rank_name']
                                                ?? ''
                                            ),
                                            ENT_QUOTES,
                                            'UTF-8'
                                        ) ?>

                                    </option>

                                <?php endforeach; ?>

                            </select>

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Promotion Type
                                <span class="text-danger">*</span>
                            </label>

                            <select
                                name="promotion_type"
                                class="form-select"
                                required>

                                <option value="">
                                    Select Type
                                </option>

                                <option value="Regular Promotion">
                                    Regular Promotion
                                </option>

                                <option value="Meritorious Promotion">
                                    Meritorious Promotion
                                </option>

                                <option value="Acting Promotion">
                                    Acting Promotion
                                </option>

                                <option value="Special Promotion">
                                    Special Promotion
                                </option>

                                <option value="Posthumous Promotion">
                                    Posthumous Promotion
                                </option>

                                <option value="Other">
                                    Other
                                </option>

                            </select>

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Effective Date
                                <span class="text-danger">*</span>
                            </label>

                            <input
                                type="date"
                                name="effective_date"
                                class="form-control"
                                required>

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Order / Reference Number
                            </label>

                            <input
                                type="text"
                                name="order_number"
                                class="form-control">

                        </div>


                        <div class="col-12">

                            <label class="form-label">
                                Promotion Reason
                            </label>

                            <textarea
                                name="promotion_reason"
                                class="form-control"
                                rows="3"></textarea>

                        </div>


                        <div class="col-12">

                            <label class="form-label">
                                Promotion Order / Supporting Document
                            </label>

                            <input
                                type="file"
                                name="document_file"
                                class="form-control"
                                accept=".pdf,.jpg,.jpeg,.png,.doc,.docx">

                            <div class="form-text">
                                Optional. PDF, JPG, PNG, DOC or DOCX.
                                Maximum 10 MB.
                            </div>

                        </div>


                        <div class="col-12">

                            <label class="form-label">
                                Notes
                            </label>

                            <textarea
                                name="notes"
                                class="form-control"
                                rows="3"></textarea>

                        </div>

                    </div>

                </div>


                <div class="modal-footer bg-white sticky-bottom">

                    <button
                        type="button"
                        class="btn btn-light"
                        data-bs-dismiss="modal">

                        Cancel

                    </button>

                    <button
                        type="submit"
                        class="btn btn-primary">

                        <i class="bi bi-save me-1"></i>
                        Save Promotion

                    </button>

                </div>

            </form>

        </div>

    </div>

</div>
<!-- =========================================================
     EDIT PROMOTION MODAL
========================================================= -->

<div
    class="modal fade"
    id="editPromotionModal"
    tabindex="-1"
    aria-hidden="true">

    <div class="modal-dialog modal-lg modal-dialog-scrollable">

        <div class="modal-content">

            <form
                method="POST"
                action="/public/employees/promotions/update"
                enctype="multipart/form-data">

                <input
                    type="hidden"
                    name="id"
                    id="editPromotionId">

                <input
                    type="hidden"
                    name="employee_id"
                    value="<?= (int) $employee['id'] ?>">


                <div class="modal-header">

                    <h5 class="modal-title">

                        <i class="bi bi-pencil-square me-2"></i>
                        Edit Rank Promotion

                    </h5>

                    <button
                        type="button"
                        class="btn-close"
                        data-bs-dismiss="modal">
                    </button>

                </div>


                <div class="modal-body">

                    <div class="row g-3">


                        <div class="col-md-6">

                            <label class="form-label">
                                Previous Rank
                            </label>

                            <select
                                name="previous_rank_id"
                                id="editPromotionPreviousRank"
                                class="form-select">

                                <option value="">
                                    Select Previous Rank
                                </option>

                                <?php foreach (
                                    $promotionRanks ?? []
                                    as $rank
                                ): ?>

                                    <option
                                        value="<?= (int) (
                                            $rank['id']
                                            ?? 0
                                        ) ?>">

                                        <?= htmlspecialchars(
                                            (string) (
                                                $rank['name']
                                                ?? $rank['rank_name']
                                                ?? ''
                                            ),
                                            ENT_QUOTES,
                                            'UTF-8'
                                        ) ?>

                                    </option>

                                <?php endforeach; ?>

                            </select>

                        </div>


                        <div class="col-md-6">

                            <label class="form-label">
                                New Rank
                                <span class="text-danger">*</span>
                            </label>

                            <select
                                name="new_rank_id"
                                id="editPromotionNewRank"
                                class="form-select"
                                required>

                                <option value="">
                                    Select New Rank
                                </option>

                                <?php foreach (
                                    $promotionRanks ?? []
                                    as $rank
                                ): ?>

                                    <option
                                        value="<?= (int) (
                                            $rank['id']
                                            ?? 0
                                        ) ?>">

                                        <?= htmlspecialchars(
                                            (string) (
                                                $rank['name']
                                                ?? $rank['rank_name']
                                                ?? ''
                                            ),
                                            ENT_QUOTES,
                                            'UTF-8'
                                        ) ?>

                                    </option>

                                <?php endforeach; ?>

                            </select>

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Promotion Type
                            </label>

                            <select
                                name="promotion_type"
                                id="editPromotionType"
                                class="form-select"
                                required>

                                <option value="">
                                    Select Type
                                </option>

                                <option value="Regular Promotion">
                                    Regular Promotion
                                </option>

                                <option value="Meritorious Promotion">
                                    Meritorious Promotion
                                </option>

                                <option value="Acting Promotion">
                                    Acting Promotion
                                </option>

                                <option value="Special Promotion">
                                    Special Promotion
                                </option>

                                <option value="Posthumous Promotion">
                                    Posthumous Promotion
                                </option>

                                <option value="Other">
                                    Other
                                </option>

                            </select>

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Effective Date
                            </label>

                            <input
                                type="date"
                                name="effective_date"
                                id="editPromotionEffectiveDate"
                                class="form-control"
                                required>

                        </div>


                        <div class="col-md-4">

                            <label class="form-label">
                                Order / Reference Number
                            </label>

                            <input
                                type="text"
                                name="order_number"
                                id="editPromotionOrderNumber"
                                class="form-control">

                        </div>


                        <div class="col-12">

                            <label class="form-label">
                                Promotion Reason
                            </label>

                            <textarea
                                name="promotion_reason"
                                id="editPromotionReason"
                                class="form-control"
                                rows="3"></textarea>

                        </div>


                        <div class="col-12">

                            <label class="form-label">
                                Replace Promotion Document
                            </label>

                            <input
                                type="file"
                                name="document_file"
                                class="form-control"
                                accept=".pdf,.jpg,.jpeg,.png,.doc,.docx">

                            <div class="form-text">
                                Leave empty to keep the existing document.
                            </div>

                        </div>


                        <div class="col-12">

                            <label class="form-label">
                                Notes
                            </label>

                            <textarea
                                name="notes"
                                id="editPromotionNotes"
                                class="form-control"
                                rows="3"></textarea>

                        </div>

                    </div>

                </div>


                <div class="modal-footer bg-white sticky-bottom">

                    <button
                        type="button"
                        class="btn btn-light"
                        data-bs-dismiss="modal">

                        Cancel

                    </button>

                    <button
                        type="submit"
                        class="btn btn-primary">

                        <i class="bi bi-save me-1"></i>
                        Update Promotion

                    </button>

                </div>

            </form>

        </div>

    </div>

</div>
<script>
document.addEventListener(
    'DOMContentLoaded',
    function () {

        const buttons =
            document.querySelectorAll(
                '.edit-family-btn'
            );

        buttons.forEach(function (button) {

            button.addEventListener(
                'click',
                function () {

                    document.getElementById(
                        'edit_family_id'
                    ).value =
                        this.dataset.id || '';

                    document.getElementById(
                        'edit_family_full_name'
                    ).value =
                        this.dataset.fullName || '';

                    document.getElementById(
                        'edit_family_relationship'
                    ).value =
                        this.dataset.relationship || '';

                    document.getElementById(
                        'edit_family_gender'
                    ).value =
                        this.dataset.gender || '';

                    document.getElementById(
                        'edit_family_date_of_birth'
                    ).value =
                        this.dataset.dateOfBirth || '';

                    document.getElementById(
                        'edit_family_phone_number'
                    ).value =
                        this.dataset.phoneNumber || '';

                    document.getElementById(
                        'edit_family_occupation'
                    ).value =
                        this.dataset.occupation || '';

                    document.getElementById(
                        'edit_family_address'
                    ).value =
                        this.dataset.address || '';

                    document.getElementById(
                        'edit_family_emergency'
                    ).checked =
                        this.dataset.emergency === '1';

                }
            );

        });

    }
);
document.querySelectorAll(
    '.edit-training-btn'
).forEach(function (button) {

    button.addEventListener(
        'click',
        function () {

            document.getElementById(
                'editTrainingId'
            ).value =
                this.dataset.id || '';

            document.getElementById(
                'editTrainingTitle'
            ).value =
                this.dataset.title || '';

            document.getElementById(
                'editTrainingType'
            ).value =
                this.dataset.type || '';

            document.getElementById(
                'editTrainingInstitution'
            ).value =
                this.dataset.institution || '';

            document.getElementById(
                'editTrainingSponsor'
            ).value =
                this.dataset.sponsor || '';

            document.getElementById(
                'editTrainingCountry'
            ).value =
                this.dataset.country || '';

            document.getElementById(
                'editTrainingLocation'
            ).value =
                this.dataset.location || '';

            document.getElementById(
                'editTrainingStartDate'
            ).value =
                this.dataset.startDate || '';

            document.getElementById(
                'editTrainingEndDate'
            ).value =
                this.dataset.endDate || '';

            document.getElementById(
                'editTrainingCertificateNumber'
            ).value =
                this.dataset.certificateNumber || '';

            document.getElementById(
                'editTrainingQualification'
            ).value =
                this.dataset.qualification || '';

            document.getElementById(
                'editTrainingNotes'
            ).value =
                this.dataset.notes || '';
        }
    );
});

document.addEventListener(
    'DOMContentLoaded',
    function () {

        const transferButtons =
            document.querySelectorAll(
                '.edit-transfer-btn'
            );

        transferButtons.forEach(
            function (button) {

                button.addEventListener(
                    'click',
                    function () {

                        document.getElementById(
                            'editTransferId'
                        ).value =
                            this.dataset.id || '';

                        document.getElementById(
                            'editTransferType'
                        ).value =
                            this.dataset.transferType || '';

                        document.getElementById(
                            'editTransferEffectiveDate'
                        ).value =
                            this.dataset.effectiveDate || '';

                        document.getElementById(
                            'editTransferOrderNumber'
                        ).value =
                            this.dataset.orderNumber || '';

                        document.getElementById(
                            'editTransferPreviousBranch'
                        ).value =
                            this.dataset.previousBranch || '';

                        document.getElementById(
                            'editTransferPreviousDepartment'
                        ).value =
                            this.dataset.previousDepartment || '';

                        document.getElementById(
                            'editTransferPreviousPosition'
                        ).value =
                            this.dataset.previousPosition || '';

                        document.getElementById(
                            'editTransferPreviousState'
                        ).value =
                            this.dataset.previousState || '';

                        document.getElementById(
                            'editTransferPreviousCounty'
                        ).value =
                            this.dataset.previousCounty || '';

                        document.getElementById(
                            'editTransferPreviousPayam'
                        ).value =
                            this.dataset.previousPayam || '';

                        document.getElementById(
                            'editTransferNewBranch'
                        ).value =
                            this.dataset.newBranch || '';

                        document.getElementById(
                            'editTransferNewDepartment'
                        ).value =
                            this.dataset.newDepartment || '';

                        document.getElementById(
                            'editTransferNewPosition'
                        ).value =
                            this.dataset.newPosition || '';

                        document.getElementById(
                            'editTransferNewState'
                        ).value =
                            this.dataset.newState || '';

                        document.getElementById(
                            'editTransferNewCounty'
                        ).value =
                            this.dataset.newCounty || '';

                        document.getElementById(
                            'editTransferNewPayam'
                        ).value =
                            this.dataset.newPayam || '';

                        document.getElementById(
                            'editTransferReason'
                        ).value =
                            this.dataset.reason || '';

                        document.getElementById(
                            'editTransferNotes'
                        ).value =
                            this.dataset.notes || '';
                    }
                );

            }
        );

    }
);
document.addEventListener(
    'DOMContentLoaded',
    function () {

        const promotionButtons =
            document.querySelectorAll(
                '.edit-promotion-btn'
            );

        promotionButtons.forEach(
            function (button) {

                button.addEventListener(
                    'click',
                    function () {

                        document.getElementById(
                            'editPromotionId'
                        ).value =
                            this.dataset.id || '';

                        document.getElementById(
                            'editPromotionPreviousRank'
                        ).value =
                            this.dataset.previousRankId || '';

                        document.getElementById(
                            'editPromotionNewRank'
                        ).value =
                            this.dataset.newRankId || '';

                        document.getElementById(
                            'editPromotionType'
                        ).value =
                            this.dataset.promotionType || '';

                        document.getElementById(
                            'editPromotionEffectiveDate'
                        ).value =
                            this.dataset.effectiveDate || '';

                        document.getElementById(
                            'editPromotionOrderNumber'
                        ).value =
                            this.dataset.orderNumber || '';

                        document.getElementById(
                            'editPromotionReason'
                        ).value =
                            this.dataset.promotionReason || '';

                        document.getElementById(
                            'editPromotionNotes'
                        ).value =
                            this.dataset.notes || '';
                    }
                );

            }
        );

    }
);
</script>
<?php

$content = ob_get_clean();

$title = 'Employee Profile';

include APP_PATH
    . '/Modules/Administration/Views/layouts/admin.php';