
<?php
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

/* =========================================
   ADMIN LOGIN CHECK
========================================= */
if (empty($_SESSION['ADMIN_ID'])) {
    header("Location: login.php");
    exit;
}

/* =========================================
   DATABASE CONNECTION
========================================= */
$dbFile = __DIR__ . '/includes/db.php';

if (!file_exists($dbFile)) {
    die("Database file not found: includes/db.php");
}

require_once $dbFile;

if (!isset($con) || !($con instanceof mysqli)) {
    die("Database connection variable \$con not found in includes/db.php");
}

mysqli_set_charset($con, "utf8mb4");

/* =========================================
   HELPER FUNCTIONS
========================================= */
if (!function_exists('e')) {
    function e($value) {
        return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
    }
}

function jobsRedirect() {
    header("Location: jobs.php");
    exit;
}

function validJobDate($date) {
    if ($date === '') {
        return true;
    }

    $d = DateTime::createFromFormat('!Y-m-d', $date);

    return $d && $d->format('Y-m-d') === $date;
}

/* =========================================
   CSRF SECURITY
========================================= */
if (empty($_SESSION['jobs_csrf'])) {
    $_SESSION['jobs_csrf'] = bin2hex(random_bytes(32));
}

$csrf = $_SESSION['jobs_csrf'];

$error = '';

/* =========================================
   ADD / EDIT / DELETE JOB
========================================= */
if ($_SERVER['REQUEST_METHOD'] === 'POST') {

    $token = $_POST['csrf_token'] ?? '';

    if (!hash_equals($csrf, $token)) {

        $error = "Invalid security token. Please refresh the page.";

    } else {

        $action = $_POST['action'] ?? '';

        /* =================================
           ADD JOB
        ================================= */
        if ($action === 'add' || $action === 'edit') {

            $id = (int)($_POST['id'] ?? 0);

            $job_title = trim($_POST['job_title'] ?? '');
            $country = trim($_POST['country'] ?? '');
            $salary = trim($_POST['salary'] ?? '');
            $description = trim($_POST['description'] ?? '');
            $posted_date = trim($_POST['posted_date'] ?? '');
            $last_date = trim($_POST['last_date'] ?? '');

            if (
                $job_title === '' ||
                $country === ''
            ) {

                $error = "Job Title and Country are required.";

            } elseif (
                mb_strlen($job_title) > 255 ||
                mb_strlen($country) > 255 ||
                mb_strlen($salary) > 255
            ) {

                $error = "Job Title, Country and Salary must not exceed 255 characters.";

            } elseif (
                !validJobDate($posted_date) ||
                !validJobDate($last_date)
            ) {

                $error = "Please enter valid dates.";

            } elseif (
                $last_date !== '' &&
                $posted_date !== '' &&
                $last_date < $posted_date
            ) {

                $error = "Last Date cannot be earlier than Posted Date.";

            } else {

                if ($posted_date === '') {
                    $posted_date = date('Y-m-d');
                }

                $last_date_value = ($last_date === '') ? null : $last_date;
                $salary_value = ($salary === '') ? null : $salary;
                $description_value = ($description === '') ? null : $description;

                if ($action === 'add') {

                    $stmt = mysqli_prepare(
                        $con,
                        "INSERT INTO jobs
                        (job_title, country, salary, description, posted_date, last_date)
                        VALUES (?, ?, ?, ?, ?, ?)"
                    );

                    if (!$stmt) {
                        $error = "Database query error: " . mysqli_error($con);
                    } else {

                        mysqli_stmt_bind_param(
                            $stmt,
                            "ssssss",
                            $job_title,
                            $country,
                            $salary_value,
                            $description_value,
                            $posted_date,
                            $last_date_value
                        );

                        if (mysqli_stmt_execute($stmt)) {

                            mysqli_stmt_close($stmt);

                            $_SESSION['jobs_message'] =
                                "New job added successfully!";

                            jobsRedirect();

                        } else {

                            $error = "Unable to add job: " . mysqli_stmt_error($stmt);
                            mysqli_stmt_close($stmt);
                        }
                    }

                } elseif ($action === 'edit') {

                    if ($id <= 0) {

                        $error = "Invalid Job ID.";

                    } else {

                        $stmt = mysqli_prepare(
                            $con,
                            "UPDATE jobs SET
                                job_title = ?,
                                country = ?,
                                salary = ?,
                                description = ?,
                                posted_date = ?,
                                last_date = ?
                             WHERE id = ?"
                        );

                        if (!$stmt) {

                            $error = "Database query error: " . mysqli_error($con);

                        } else {

                            mysqli_stmt_bind_param(
                                $stmt,
                                "ssssssi",
                                $job_title,
                                $country,
                                $salary_value,
                                $description_value,
                                $posted_date,
                                $last_date_value,
                                $id
                            );

                            if (mysqli_stmt_execute($stmt)) {

                                mysqli_stmt_close($stmt);

                                $_SESSION['jobs_message'] =
                                    "Job updated successfully!";

                                jobsRedirect();

                            } else {

                                $error = "Unable to update job: " . mysqli_stmt_error($stmt);
                                mysqli_stmt_close($stmt);
                            }
                        }
                    }
                }
            }
        }

        /* =================================
           DELETE JOB
        ================================= */
        elseif ($action === 'delete') {

            $id = (int)($_POST['id'] ?? 0);

            if ($id <= 0) {

                $error = "Invalid Job ID.";

            } else {

                $stmt = mysqli_prepare(
                    $con,
                    "DELETE FROM jobs WHERE id = ?"
                );

                if (!$stmt) {

                    $error = "Database query error.";

                } else {

                    mysqli_stmt_bind_param($stmt, "i", $id);

                    if (mysqli_stmt_execute($stmt)) {

                        if (mysqli_stmt_affected_rows($stmt) > 0) {

                            mysqli_stmt_close($stmt);

                            $_SESSION['jobs_message'] =
                                "Job deleted successfully!";

                            jobsRedirect();

                        } else {

                            $error = "Job record not found.";
                            mysqli_stmt_close($stmt);
                        }

                    } else {

                        $error = "Unable to delete job.";
                        mysqli_stmt_close($stmt);
                    }
                }
            }
        }
    }
}

/* =========================================
   EDIT JOB FETCH
========================================= */
$editData = null;

if (isset($_GET['edit'])) {

    $editId = (int)$_GET['edit'];

    if ($editId > 0) {

        $stmt = mysqli_prepare(
            $con,
            "SELECT id, job_title, country, salary,
                    description, posted_date, last_date
             FROM jobs
             WHERE id = ?
             LIMIT 1"
        );

        if ($stmt) {

            mysqli_stmt_bind_param($stmt, "i", $editId);
            mysqli_stmt_execute($stmt);

            mysqli_stmt_bind_result(
                $stmt,
                $rowId,
                $rowTitle,
                $rowCountry,
                $rowSalary,
                $rowDescription,
                $rowPosted,
                $rowLast
            );

            if (mysqli_stmt_fetch($stmt)) {

                $editData = [
                    'id' => $rowId,
                    'job_title' => $rowTitle,
                    'country' => $rowCountry,
                    'salary' => $rowSalary,
                    'description' => $rowDescription,
                    'posted_date' => $rowPosted,
                    'last_date' => $rowLast
                ];
            }

            mysqli_stmt_close($stmt);
        }
    }
}

/* =========================================
   SEARCH JOBS
========================================= */
$search = trim($_GET['search'] ?? '');

if ($search !== '') {

    $searchTerm = '%' . $search . '%';

    $stmt = mysqli_prepare(
        $con,
        "SELECT * FROM jobs
         WHERE job_title LIKE ?
            OR country LIKE ?
            OR salary LIKE ?
         ORDER BY id DESC"
    );

    mysqli_stmt_bind_param(
        $stmt,
        "sss",
        $searchTerm,
        $searchTerm,
        $searchTerm
    );

    mysqli_stmt_execute($stmt);
    $jobsResult = mysqli_stmt_get_result($stmt);

} else {

    $jobsResult = mysqli_query(
        $con,
        "SELECT * FROM jobs ORDER BY id DESC"
    );
}

/* =========================================
   DASHBOARD COUNTS
========================================= */
$countResult = mysqli_query(
    $con,
    "SELECT COUNT(*) AS total FROM jobs"
);

$totalJobs = (int)(mysqli_fetch_assoc($countResult)['total'] ?? 0);

$today = date('Y-m-d');

$countResult = mysqli_query(
    $con,
    "SELECT COUNT(*) AS total FROM jobs WHERE last_date IS NULL OR last_date >= '$today'"
);

$openJobs = (int)(mysqli_fetch_assoc($countResult)['total'] ?? 0);

$countResult = mysqli_query(
    $con,
    "SELECT COUNT(*) AS total FROM jobs WHERE last_date < '$today'"
);

$expiredJobs = (int)(mysqli_fetch_assoc($countResult)['total'] ?? 0);

$flashMessage = $_SESSION['jobs_message'] ?? '';
unset($_SESSION['jobs_message']);

$adminName = $_SESSION['ADMIN_NAME'] ?? 'Administrator';

?>
<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Jobs Management | International Adventures</title>

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">

<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" rel="stylesheet">

<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">

<style>

:root {
    --navy: #101d3a;
    --blue: #315bea;
    --bg: #f4f7fc;
    --text: #26344d;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    font-family: 'Inter', sans-serif;
    color: var(--text);
}

/* SIDEBAR */

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 250px;
    height: 100vh;
    background: var(--navy);
    padding: 25px 17px;
    z-index: 1000;
    transition: .3s;
}

.brand {
    color: white;
    font-size: 15px;
    font-weight: 800;
    line-height: 1.5;
    padding: 5px 10px 25px;
    border-bottom: 1px solid rgba(255,255,255,.12);
}

.brand small {
    display: block;
    color: #9eacc9;
    font-size: 10px;
    letter-spacing: 2px;
}

.menu-title {
    color: #8b9bb9;
    font-size: 10px;
    letter-spacing: 1.5px;
    font-weight: 700;
    margin: 28px 12px 12px;
}

.sidebar a {
    display: block;
    color: #bdc9df;
    padding: 13px 14px;
    border-radius: 9px;
    margin-bottom: 6px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
}

.sidebar a i {
    width: 23px;
}

.sidebar a:hover,
.sidebar a.active {
    background: var(--blue);
    color: white;
}

/* MAIN */

.main {
    margin-left: 250px;
    padding: 30px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    margin-bottom: 28px;
}

.topbar h2 {
    font-size: 24px;
    font-weight: 800;
    color: var(--navy);
    margin: 0 0 6px;
}

.topbar p {
    color: #8994a8;
    font-size: 12px;
    margin: 0;
}

.logout {
    color: #e34c4c;
    background: #fff0f0;
    padding: 11px 15px;
    border-radius: 9px;
    text-decoration: none;
    font-size: 12px;
    font-weight: 700;
}

/* STATISTICS */

.stat-card {
    background: white;
    border: 1px solid #e9edf5;
    border-radius: 14px;
    padding: 20px;
    height: 100%;
}

.stat-card small {
    color: #8994a8;
    font-size: 11px;
    font-weight: 700;
}

.stat-card h3 {
    color: var(--navy);
    font-size: 27px;
    font-weight: 800;
    margin: 9px 0 0;
}

.stat-icon {
    width: 45px;
    height: 45px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

/* PANELS */

.panel {
    background: white;
    border: 1px solid #e9edf5;
    border-radius: 15px;
    padding: 23px;
    margin-bottom: 25px;
    box-shadow: 0 5px 20px rgba(20,40,80,.025);
}

.panel-heading {
    font-size: 16px;
    font-weight: 800;
    color: var(--navy);
    margin-bottom: 20px;
}

.form-label {
    font-size: 12px;
    font-weight: 700;
    color: #42506a;
    margin-bottom: 8px;
}

.form-control {
    border: 1px solid #e0e6ef;
    padding: 11px 13px;
    border-radius: 9px;
    font-size: 13px;
    box-shadow: none !important;
}

.form-control:focus {
    border-color: var(--blue);
}

.btn-primary {
    background: var(--blue);
    border-color: var(--blue);
    border-radius: 9px;
    padding: 11px 20px;
    font-size: 12px;
    font-weight: 700;
}

.btn-secondary {
    border-radius: 9px;
    padding: 11px 18px;
    font-size: 12px;
}

/* TABLE */

.table {
    vertical-align: middle;
}

.table thead th {
    background: #f7f9fd;
    color: #77839a;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .6px;
    padding: 15px 12px;
    white-space: nowrap;
}

.table tbody td {
    font-size: 12px;
    padding: 14px 12px;
    color: #4d5a70;
}

.action-btn {
    width: 33px;
    height: 33px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 7px;
    text-decoration: none;
    font-size: 12px;
}

.edit-btn {
    color: #315bea;
    background: #edf1ff;
}

.delete-btn {
    color: #e34c4c;
    background: #fff0f0;
}

.open-badge {
    background: #e5f8ef;
    color: #15945b;
    padding: 7px 10px;
    border-radius: 20px;
    font-size: 10px;
}

.expired-badge {
    background: #fff0e5;
    color: #d17b27;
    padding: 7px 10px;
    border-radius: 20px;
    font-size: 10px;
}

.search-box {
    max-width: 300px;
}

.mobile-toggle {
    display: none;
    border: 0;
    background: var(--navy);
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 9px;
}

.overlay {
    display: none;
}

@media(max-width:768px) {

    .sidebar {
        left: -260px;
    }

    .sidebar.show {
        left: 0;
    }

    .overlay.show {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.4);
        z-index: 999;
    }

    .main {
        margin-left: 0;
        padding: 18px 13px;
    }

    .mobile-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .topbar h2 {
        font-size: 18px;
    }

    .topbar {
        align-items: flex-start;
    }

    .panel {
        padding: 16px;
    }

    .search-box {
        max-width: 100%;
        width: 100%;
    }
}

</style>
</head>

<body>

<div class="overlay" id="overlay" onClick="closeSidebar()"></div>

<!-- SIDEBAR -->

<aside class="sidebar" id="sidebar">

    <div class="brand">
        <i class="fa-solid fa-earth-asia me-2"></i>
        INTERNATIONAL<br>ADVENTURES
        <small>ADMIN PANEL</small>
    </div>

    <div class="menu-title">MAIN MENU</div>

    <a href="index.php">
        <i class="fa-solid fa-house"></i> Dashboard
    </a>

    <a href="gallery.php">
        <i class="fa-regular fa-images"></i> Gallery
    </a>

    <a href="jobs.php" class="active">
        <i class="fa-solid fa-briefcase"></i> Jobs
    </a>

    <a href="enquiry.php">
        <i class="fa-solid fa-envelope-open-text"></i> Enquiry Form
    </a>

    <div style="position:absolute;bottom:25px;left:20px;color:#aab8d1;font-size:11px;">
        <i class="fa-solid fa-user-shield me-2"></i>
        <?php echo e($adminName); ?>
    </div>

</aside>

<!-- MAIN CONTENT -->

<main class="main">

    <div class="topbar">

        <div class="d-flex align-items-center gap-3">

            <button class="mobile-toggle" onClick="openSidebar()">
                <i class="fa-solid fa-bars"></i>
            </button>

            <div>
                <h2>Jobs Management</h2>
                <p>Add, edit, delete and manage job vacancies.</p>
            </div>

        </div>

        <a href="logout.php" class="logout"
           onclick="return confirm('Are you sure you want to logout?')">
            <i class="fa-solid fa-right-from-bracket me-1"></i>
            Logout
        </a>

    </div>

    <!-- SUCCESS MESSAGE -->

    <?php if ($flashMessage): ?>
        <div class="alert alert-success">
            <i class="fa-solid fa-circle-check me-2"></i>
            <?php echo e($flashMessage); ?>
        </div>
    <?php endif; ?>

    <!-- ERROR MESSAGE -->

    <?php if ($error): ?>
        <div class="alert alert-danger">
            <i class="fa-solid fa-circle-exclamation me-2"></i>
            <?php echo e($error); ?>
        </div>
    <?php endif; ?>

    <!-- STATISTICS -->

    <div class="row g-3 mb-4">

        <div class="col-md-4">

            <div class="stat-card d-flex justify-content-between align-items-center">

                <div>
                    <small>TOTAL JOBS</small>
                    <h3><?php echo $totalJobs; ?></h3>
                </div>

                <div class="stat-icon" style="background:#edf1ff;color:#315bea;">
                    <i class="fa-solid fa-briefcase"></i>
                </div>

            </div>

        </div>

        <div class="col-md-4">

            <div class="stat-card d-flex justify-content-between align-items-center">

                <div>
                    <small>OPEN JOBS</small>
                    <h3><?php echo $openJobs; ?></h3>
                </div>

                <div class="stat-icon" style="background:#e5f8ef;color:#15945b;">
                    <i class="fa-solid fa-circle-check"></i>
                </div>

            </div>

        </div>

        <div class="col-md-4">

            <div class="stat-card d-flex justify-content-between align-items-center">

                <div>
                    <small>EXPIRED JOBS</small>
                    <h3><?php echo $expiredJobs; ?></h3>
                </div>

                <div class="stat-icon" style="background:#fff0e5;color:#d17b27;">
                    <i class="fa-solid fa-calendar-xmark"></i>
                </div>

            </div>

        </div>

    </div>

    <!-- ADD / EDIT JOB FORM -->

    <div class="panel">

        <div class="panel-heading">

            <i class="fa-solid fa-<?php echo $editData ? 'pen-to-square' : 'plus-circle'; ?> me-2"
               style="color:#315bea;"></i>

            <?php echo $editData ? 'Edit Job Details' : 'Add New Job'; ?>

        </div>

        <form method="POST">

            <input type="hidden" name="csrf_token"
                   value="<?php echo e($csrf); ?>">

            <input type="hidden" name="action"
                   value="<?php echo $editData ? 'edit' : 'add'; ?>">

            <?php if ($editData): ?>

                <input type="hidden" name="id"
                       value="<?php echo (int)$editData['id']; ?>">

            <?php endif; ?>

            <div class="row g-3">

                <div class="col-md-6">

                    <label class="form-label">Job Title *</label>

                    <input type="text"
                           name="job_title"
                           class="form-control"
                           placeholder="Example: Hotel Staff"
                           maxlength="255"
                           value="<?php echo e($editData['job_title'] ?? ''); ?>"
                           required>

                </div>

                <div class="col-md-6">

                    <label class="form-label">Country *</label>

                    <input type="text"
                           name="country"
                           class="form-control"
                           placeholder="Example: Dubai, UAE"
                           maxlength="255"
                           value="<?php echo e($editData['country'] ?? ''); ?>"
                           required>

                </div>

                <div class="col-md-6">

                    <label class="form-label">Salary</label>

                    <input type="text"
                           name="salary"
                           class="form-control"
                           placeholder="Example: 1500 - 2000 AED"
                           maxlength="255"
                           value="<?php echo e($editData['salary'] ?? ''); ?>">

                </div>

                <div class="col-md-6">

                    <label class="form-label">Posted Date</label>

                    <input type="date"
                           name="posted_date"
                           class="form-control"
                           value="<?php echo e($editData['posted_date'] ?? date('Y-m-d')); ?>">

                </div>

                <div class="col-md-6">

                    <label class="form-label">Last Date</label>

                    <input type="date"
                           name="last_date"
                           class="form-control"
                           value="<?php echo e($editData['last_date'] ?? ''); ?>">

                    <small class="text-muted">
                        Leave blank if there is no closing date.
                    </small>

                </div>

                <div class="col-12">

                    <label class="form-label">Job Description</label>

                    <textarea name="description"
                              class="form-control"
                              rows="5"
                              placeholder="Enter complete job details, requirements and benefits..."><?php
                        echo e($editData['description'] ?? '');
                    ?></textarea>

                </div>

                <div class="col-12 d-flex gap-2 flex-wrap mt-3">

                    <button type="submit" class="btn btn-primary">

                        <i class="fa-solid fa-<?php echo $editData ? 'floppy-disk' : 'plus'; ?> me-2"></i>

                        <?php echo $editData ? 'Update Job' : 'Add New Job'; ?>

                    </button>

                    <?php if ($editData): ?>

                        <a href="jobs.php" class="btn btn-secondary">
                            Cancel Edit
                        </a>

                    <?php endif; ?>

                </div>

            </div>

        </form>

    </div>

    <!-- ALL JOBS TABLE -->

    <div class="panel">

        <div class="d-flex justify-content-between align-items-center flex-wrap gap-3 mb-4">

            <div class="panel-heading mb-0">
                <i class="fa-solid fa-list-check me-2" style="color:#315bea;"></i>
                All Job Listings
            </div>

            <form method="GET" class="d-flex gap-2 search-box">

                <input type="text"
                       name="search"
                       class="form-control"
                       placeholder="Search title, country..."
                       value="<?php echo e($search); ?>">

                <button type="submit" class="btn btn-primary">
                    <i class="fa-solid fa-search"></i>
                </button>

                <?php if ($search !== ''): ?>

                    <a href="jobs.php" class="btn btn-secondary">
                        <i class="fa-solid fa-xmark"></i>
                    </a>

                <?php endif; ?>

            </form>

        </div>

        <div class="table-responsive">

            <table class="table table-hover">

                <thead>

                    <tr>
                        <th>#</th>
                        <th>Job Title</th>
                        <th>Country</th>
                        <th>Salary</th>
                        <th>Posted Date</th>
                        <th>Last Date</th>
                        <th>Status</th>
                        <th>Actions</th>
                    </tr>

                </thead>

                <tbody>

                <?php if ($jobsResult && mysqli_num_rows($jobsResult) > 0): ?>

                    <?php $i = 1; ?>

                    <?php while ($job = mysqli_fetch_assoc($jobsResult)): ?>

                        <?php
                        $isExpired = (
                            !empty($job['last_date']) &&
                            $job['last_date'] < $today
                        );
                        ?>

                        <tr>

                            <td><?php echo $i++; ?></td>

                            <td>
                                <strong><?php echo e($job['job_title']); ?></strong>

                                <?php if (!empty($job['description'])): ?>

                                    <div class="text-muted mt-1"
                                         style="font-size:10px;max-width:220px;">
                                        <?php
                                        echo e(mb_strimwidth(
                                            $job['description'],
                                            0,
                                            75,
                                            '...'
                                        ));
                                        ?>
                                    </div>

                                <?php endif; ?>

                            </td>

                            <td>
                                <i class="fa-solid fa-location-dot text-muted me-1"></i>
                                <?php echo e($job['country']); ?>
                            </td>

                            <td>
                                <?php
                                echo $job['salary'] !== null && $job['salary'] !== ''
                                    ? e($job['salary'])
                                    : 'Not specified';
                                ?>
                            </td>

                            <td>
                                <?php
                                echo !empty($job['posted_date'])
                                    ? e(date('d M Y', strtotime($job['posted_date'])))
                                    : '-';
                                ?>
                            </td>

                            <td>
                                <?php
                                echo !empty($job['last_date'])
                                    ? e(date('d M Y', strtotime($job['last_date'])))
                                    : 'Not specified';
                                ?>
                            </td>

                            <td>

                                <?php if ($isExpired): ?>

                                    <span class="expired-badge">Expired</span>

                                <?php else: ?>

                                    <span class="open-badge">Open</span>

                                <?php endif; ?>

                            </td>

                            <td>

                                <div class="d-flex gap-2">

                                    <a href="jobs.php?edit=<?php echo (int)$job['id']; ?>"
                                       class="action-btn edit-btn"
                                       title="Edit Job">

                                        <i class="fa-solid fa-pen"></i>

                                    </a>

                                    <form method="POST"
                                          onsubmit="return confirm('Are you sure you want to delete this job?');">

                                        <input type="hidden"
                                               name="csrf_token"
                                               value="<?php echo e($csrf); ?>">

                                        <input type="hidden"
                                               name="action"
                                               value="delete">

                                        <input type="hidden"
                                               name="id"
                                               value="<?php echo (int)$job['id']; ?>">

                                        <button type="submit"
                                                class="action-btn delete-btn"
                                                title="Delete Job">

                                            <i class="fa-solid fa-trash"></i>

                                        </button>

                                    </form>

                                </div>

                            </td>

                        </tr>

                    <?php endwhile; ?>

                <?php else: ?>

                    <tr>

                        <td colspan="8" class="text-center py-5">

                            <i class="fa-solid fa-briefcase fs-1 text-muted"></i>

                            <h6 class="mt-3 fw-bold">No Jobs Found</h6>

                            <p class="text-muted small mb-0">
                                Add your first job using the form above.
                            </p>

                        </td>

                    </tr>

                <?php endif; ?>

                </tbody>

            </table>

        </div>

    </div>

    <div class="text-center text-muted small mt-4">

        © <?php echo date('Y'); ?>
        International Adventures Overseas Services.
        All Rights Reserved.

    </div>

</main>

<script>

function openSidebar() {
    document.getElementById('sidebar').classList.add('show');
    document.getElementById('overlay').classList.add('show');
}

function closeSidebar() {
    document.getElementById('sidebar').classList.remove('show');
    document.getElementById('overlay').classList.remove('show');
}

</script>

</body>
</html>
