<?php

require_once __DIR__ . '/../includes/auth.php';
require_once __DIR__ . '/../config/db.php';
require_once __DIR__ . '/../includes/role_filter.php';

/*
|--------------------------------------------------------------------------
| CSRF token
|--------------------------------------------------------------------------
*/

if (
    empty($_SESSION['csrf_token']) ||
    !is_string($_SESSION['csrf_token'])
) {
    $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}

$csrfToken = $_SESSION['csrf_token'];

/*
|--------------------------------------------------------------------------
| Helper functions
|--------------------------------------------------------------------------
*/

/**
 * Bind a dynamic list of parameters to a prepared statement.
 */
function bindSurveyStatementParams(
    mysqli_stmt $statement,
    string $types,
    array &$parameters
): void {
    if ($types === '' || $parameters === []) {
        return;
    }

    $references = [];

    foreach ($parameters as $key => &$value) {
        $references[$key] = &$value;
    }

    mysqli_stmt_bind_param(
        $statement,
        $types,
        ...$references
    );
}

/**
 * Create a pagination URL while preserving current filters.
 */
function buildSurveyPageUrl(int $page): string
{
    $parameters = $_GET;
    $parameters['page'] = $page;

    return '?' . http_build_query($parameters);
}

/**
 * Return a safe formatted date.
 */
function formatSurveyDate(?string $date): string
{
    if (!$date) {
        return '-';
    }

    $timestamp = strtotime($date);

    if ($timestamp === false) {
        return $date;
    }

    return date('Y-m-d H:i', $timestamp);
}

/*
|--------------------------------------------------------------------------
| Current role
|--------------------------------------------------------------------------
*/

$role = $_SESSION['role'] ?? '';

if (!in_array($role, ['admin', 'zonal_director', 'user'], true)) {
    http_response_code(403);
    exit('Access denied.');
}

/*
|--------------------------------------------------------------------------
| Search and filters
|--------------------------------------------------------------------------
*/

$keyword = trim((string)($_GET['keyword'] ?? ''));
$district = trim((string)($_GET['district'] ?? ''));
$zoneName = trim((string)($_GET['zone_name'] ?? ''));
$dateFrom = trim((string)($_GET['date_from'] ?? ''));
$dateTo = trim((string)($_GET['date_to'] ?? ''));

$allowedPerPage = [10, 25, 50, 100];

$perPage = filter_input(
    INPUT_GET,
    'per_page',
    FILTER_VALIDATE_INT
);

if (!in_array($perPage, $allowedPerPage, true)) {
    $perPage = 10;
}

$page = filter_input(
    INPUT_GET,
    'page',
    FILTER_VALIDATE_INT,
    [
        'options' => [
            'default' => 1,
            'min_range' => 1
        ]
    ]
);

if (!$page) {
    $page = 1;
}

/*
|--------------------------------------------------------------------------
| Build prepared WHERE clause
|--------------------------------------------------------------------------
*/

$roleFilter = getSurveyRoleFilter('s');

$whereSql = ' WHERE 1 = 1 ';
$whereSql .= $roleFilter['sql'];

$parameterTypes = $roleFilter['types'];
$parameterValues = $roleFilter['params'];

/*
|--------------------------------------------------------------------------
| Keyword search
|--------------------------------------------------------------------------
*/

if ($keyword !== '') {
    $whereSql .= '
        AND (
            s.census_no LIKE ?
            OR s.school_name LIKE ?
            OR s.district LIKE ?
            OR s.zone_name LIKE ?
            OR s.division_name LIKE ?
            OR s.entered_by LIKE ?
        )
    ';

    $searchKeyword = '%' . $keyword . '%';

    $parameterTypes .= 'ssssss';

    $parameterValues[] = $searchKeyword;
    $parameterValues[] = $searchKeyword;
    $parameterValues[] = $searchKeyword;
    $parameterValues[] = $searchKeyword;
    $parameterValues[] = $searchKeyword;
    $parameterValues[] = $searchKeyword;
}

/*
|--------------------------------------------------------------------------
| District filter
|--------------------------------------------------------------------------
*/

if ($district !== '') {
    $whereSql .= ' AND s.district LIKE ? ';

    $parameterTypes .= 's';
    $parameterValues[] = '%' . $district . '%';
}

/*
|--------------------------------------------------------------------------
| Zone filter
|--------------------------------------------------------------------------
*/

if ($zoneName !== '') {
    $whereSql .= ' AND s.zone_name LIKE ? ';

    $parameterTypes .= 's';
    $parameterValues[] = '%' . $zoneName . '%';
}

/*
|--------------------------------------------------------------------------
| Date filters
|--------------------------------------------------------------------------
*/

if ($dateFrom !== '') {
    $dateFromObject = DateTime::createFromFormat('Y-m-d', $dateFrom);

    if ($dateFromObject && $dateFromObject->format('Y-m-d') === $dateFrom) {
        $whereSql .= ' AND DATE(s.survey_date) >= ? ';

        $parameterTypes .= 's';
        $parameterValues[] = $dateFrom;
    } else {
        $dateFrom = '';
    }
}

if ($dateTo !== '') {
    $dateToObject = DateTime::createFromFormat('Y-m-d', $dateTo);

    if ($dateToObject && $dateToObject->format('Y-m-d') === $dateTo) {
        $whereSql .= ' AND DATE(s.survey_date) <= ? ';

        $parameterTypes .= 's';
        $parameterValues[] = $dateTo;
    } else {
        $dateTo = '';
    }
}

/*
|--------------------------------------------------------------------------
| Count surveys
|--------------------------------------------------------------------------
*/

$countSql = '
    SELECT COUNT(*) AS total
    FROM surveys s
    ' . $whereSql;

$countStatement = mysqli_prepare($conn, $countSql);

if (!$countStatement) {
    exit('Unable to count inventory records.');
}

$countParameterValues = $parameterValues;

bindSurveyStatementParams(
    $countStatement,
    $parameterTypes,
    $countParameterValues
);

mysqli_stmt_execute($countStatement);

$countResult = mysqli_stmt_get_result($countStatement);
$countRow = mysqli_fetch_assoc($countResult);

$totalRecords = (int)($countRow['total'] ?? 0);

mysqli_stmt_close($countStatement);

/*
|--------------------------------------------------------------------------
| Pagination calculation
|--------------------------------------------------------------------------
*/

$totalPages = max(
    1,
    (int)ceil($totalRecords / $perPage)
);

if ($page > $totalPages) {
    $page = $totalPages;
}

$offset = ($page - 1) * $perPage;

/*
|--------------------------------------------------------------------------
| Load surveys
|--------------------------------------------------------------------------
*/

$surveySql = '
    SELECT
        s.id,
        s.survey_date,
        s.entered_by,
        s.census_no,
        s.district,
        s.zone_name,
        s.division_name,
        s.school_name,
        s.school_category,
        s.school_type
    FROM surveys s
    ' . $whereSql . '
    ORDER BY
        s.survey_date DESC,
        s.id DESC
    LIMIT ? OFFSET ?
';

$surveyStatement = mysqli_prepare($conn, $surveySql);

if (!$surveyStatement) {
    exit('Unable to load inventory records.');
}

$listParameterTypes = $parameterTypes . 'ii';
$listParameterValues = $parameterValues;

$listParameterValues[] = $perPage;
$listParameterValues[] = $offset;

bindSurveyStatementParams(
    $surveyStatement,
    $listParameterTypes,
    $listParameterValues
);

mysqli_stmt_execute($surveyStatement);

$surveyResult = mysqli_stmt_get_result($surveyStatement);

$surveys = [];

while ($surveyRow = mysqli_fetch_assoc($surveyResult)) {
    $surveys[] = $surveyRow;
}

mysqli_stmt_close($surveyStatement);

/*
|--------------------------------------------------------------------------
| Record range
|--------------------------------------------------------------------------
*/

$firstRecord = $totalRecords > 0
    ? $offset + 1
    : 0;

$lastRecord = min(
    $offset + $perPage,
    $totalRecords
);

/*
|--------------------------------------------------------------------------
| Flash messages
|--------------------------------------------------------------------------
*/

$successMessage = $_SESSION['success_message'] ?? '';
$errorMessage = $_SESSION['error_message'] ?? '';

unset(
    $_SESSION['success_message'],
    $_SESSION['error_message']
);

include __DIR__ . '/../includes/header.php';
include __DIR__ . '/../includes/navbar.php';
?>

<main class="container-fluid px-3 px-lg-4 mt-4 mb-5">

    <div
        class="d-flex flex-column flex-lg-row
               justify-content-between align-items-lg-center
               gap-3 mb-4"
    >
        <div>
            <h4 class="mb-1">
                <i class="fa-solid fa-clipboard-list me-1"></i>
                Survey Management
            </h4>

            <p class="text-muted mb-0">
                Search, view and manage school hardware inventory surveys.
            </p>
        </div>

        <div>
            <a
                href="<?= htmlspecialchars(
                    BASE_URL . 'surveys/add_survey.php',
                    ENT_QUOTES,
                    'UTF-8'
                ) ?>"
                class="btn btn-primary"
            >
                <i class="fa-solid fa-plus me-1"></i>
                New Survey
            </a>
        </div>
    </div>

    <?php if ($successMessage !== ''): ?>
        <div
            class="alert alert-success alert-dismissible fade show"
            role="alert"
        >
            <i class="fa-solid fa-circle-check me-1"></i>

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

            <button
                type="button"
                class="btn-close"
                data-bs-dismiss="alert"
                aria-label="Close"
            ></button>
        </div>
    <?php endif; ?>

    <?php if ($errorMessage !== ''): ?>
        <div
            class="alert alert-danger alert-dismissible fade show"
            role="alert"
        >
            <i class="fa-solid fa-circle-exclamation me-1"></i>

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

            <button
                type="button"
                class="btn-close"
                data-bs-dismiss="alert"
                aria-label="Close"
            ></button>
        </div>
    <?php endif; ?>

    <!-- Search and filters -->
    <div class="card shadow-sm mb-4">

        <div class="card-header bg-light">
            <strong>
                <i class="fa-solid fa-filter me-1"></i>
                Search and Filters
            </strong>
        </div>

        <div class="card-body">

            <form
                action=""
                method="get"
                class="row g-3"
            >

                <div class="col-12 col-lg-4">
                    <label
                        for="keyword"
                        class="form-label"
                    >
                        Search
                    </label>

                    <input
                        type="search"
                        name="keyword"
                        id="keyword"
                        class="form-control"
                        value="<?= htmlspecialchars(
                            $keyword,
                            ENT_QUOTES,
                            'UTF-8'
                        ) ?>"
                        placeholder="Census no, school, district, zone..."
                    >
                </div>

                <div class="col-12 col-md-6 col-lg-2">
                    <label
                        for="district"
                        class="form-label"
                    >
                        District
                    </label>

                    <input
                        type="text"
                        name="district"
                        id="district"
                        class="form-control"
                        value="<?= htmlspecialchars(
                            $district,
                            ENT_QUOTES,
                            'UTF-8'
                        ) ?>"
                        placeholder="District"
                    >
                </div>

                <?php if ($role === 'admin'): ?>
                    <div class="col-12 col-md-6 col-lg-2">
                        <label
                            for="zone_name"
                            class="form-label"
                        >
                            Zone
                        </label>

                        <input
                            type="text"
                            name="zone_name"
                            id="zone_name"
                            class="form-control"
                            value="<?= htmlspecialchars(
                                $zoneName,
                                ENT_QUOTES,
                                'UTF-8'
                            ) ?>"
                            placeholder="Zone"
                        >
                    </div>
                <?php endif; ?>

                <div class="col-12 col-md-6 col-lg-2">
                    <label
                        for="date_from"
                        class="form-label"
                    >
                        Date From
                    </label>

                    <input
                        type="date"
                        name="date_from"
                        id="date_from"
                        class="form-control"
                        value="<?= htmlspecialchars(
                            $dateFrom,
                            ENT_QUOTES,
                            'UTF-8'
                        ) ?>"
                    >
                </div>

                <div class="col-12 col-md-6 col-lg-2">
                    <label
                        for="date_to"
                        class="form-label"
                    >
                        Date To
                    </label>

                    <input
                        type="date"
                        name="date_to"
                        id="date_to"
                        class="form-control"
                        value="<?= htmlspecialchars(
                            $dateTo,
                            ENT_QUOTES,
                            'UTF-8'
                        ) ?>"
                    >
                </div>

                <div class="col-12 col-md-4 col-lg-2">
                    <label
                        for="per_page"
                        class="form-label"
                    >
                        Rows
                    </label>

                    <select
                        name="per_page"
                        id="per_page"
                        class="form-select"
                    >
                        <?php foreach ($allowedPerPage as $allowed): ?>
                            <option
                                value="<?= $allowed ?>"
                                <?= $perPage === $allowed
                                    ? 'selected'
                                    : '' ?>
                            >
                                <?= $allowed ?>
                            </option>
                        <?php endforeach; ?>
                    </select>
                </div>

                <div class="col-12 d-flex flex-wrap gap-2">
                    <button
                        type="submit"
                        class="btn btn-primary"
                    >
                        <i class="fa-solid fa-magnifying-glass me-1"></i>
                        Search
                    </button>

                    <a
                        href="<?= htmlspecialchars(
                            BASE_URL . 'surveys/view_surveys.php',
                            ENT_QUOTES,
                            'UTF-8'
                        ) ?>"
                        class="btn btn-outline-secondary"
                    >
                        <i class="fa-solid fa-rotate-left me-1"></i>
                        Reset
                    </a>
                </div>

            </form>

        </div>

    </div>

    <!-- Survey list -->
    <div class="card shadow-sm">

        <div
            class="card-header bg-primary text-white
                   d-flex flex-column flex-md-row
                   justify-content-between align-items-md-center gap-2"
        >
            <strong>
                <i class="fa-solid fa-table-list me-1"></i>
                Survey Records
            </strong>

            <span>
                <?= number_format($totalRecords) ?>
                record<?= $totalRecords === 1 ? '' : 's' ?>
            </span>
        </div>

        <div class="card-body p-0">

            <?php if ($surveys === []): ?>

                <div class="text-center py-5">

                    <i
                        class="fa-solid fa-folder-open
                               fa-3x text-muted mb-3"
                    ></i>

                    <h5>No survey records found</h5>

                    <p class="text-muted mb-0">
                        Try changing the search or filter values.
                    </p>

                </div>

            <?php else: ?>

                <div class="table-responsive">

                    <table
                        class="table table-hover table-bordered
                               align-middle mb-0"
                    >

                        <thead class="table-light">

                            <tr>
                                <th style="width: 70px;">
                                    #
                                </th>

                                <th>
                                    Survey Date
                                </th>

                                <th>
                                    Census No.
                                </th>

                                <th>
                                    School
                                </th>

                                <th>
                                    District
                                </th>

                                <th>
                                    Zone
                                </th>

                                <th>
                                    Division
                                </th>

                                <th>
                                    Entered By
                                </th>

                                <th
                                    class="text-center"
                                    style="min-width: 245px;"
                                >
                                    Actions
                                </th>
                            </tr>

                        </thead>

                        <tbody>

                            <?php foreach ($surveys as $index => $survey): ?>

                                <tr>

                                    <td>
                                        <?= $offset + $index + 1 ?>
                                    </td>

                                    <td>
                                        <?= htmlspecialchars(
                                            formatSurveyDate(
                                                $survey['survey_date']
                                            ),
                                            ENT_QUOTES,
                                            'UTF-8'
                                        ) ?>
                                    </td>

                                    <td>
                                        <?= htmlspecialchars(
                                            $survey['census_no'] ?: '-',
                                            ENT_QUOTES,
                                            'UTF-8'
                                        ) ?>
                                    </td>

                                    <td>
                                        <strong>
                                            <?= htmlspecialchars(
                                                $survey['school_name'],
                                                ENT_QUOTES,
                                                'UTF-8'
                                            ) ?>
                                        </strong>

                                        <div class="small text-muted">
                                            <?= htmlspecialchars(
                                                $survey['school_category']
                                                    ?: '-',
                                                ENT_QUOTES,
                                                'UTF-8'
                                            ) ?>

                                            /

                                            <?= htmlspecialchars(
                                                $survey['school_type']
                                                    ?: '-',
                                                ENT_QUOTES,
                                                'UTF-8'
                                            ) ?>
                                        </div>
                                    </td>

                                    <td>
                                        <?= htmlspecialchars(
                                            $survey['district'] ?: '-',
                                            ENT_QUOTES,
                                            'UTF-8'
                                        ) ?>
                                    </td>

                                    <td>
                                        <?= htmlspecialchars(
                                            $survey['zone_name'] ?: '-',
                                            ENT_QUOTES,
                                            'UTF-8'
                                        ) ?>
                                    </td>

                                    <td>
                                        <?= htmlspecialchars(
                                            $survey['division_name'] ?: '-',
                                            ENT_QUOTES,
                                            'UTF-8'
                                        ) ?>
                                    </td>

                                    <td>
                                        <?= htmlspecialchars(
                                            $survey['entered_by'] ?: '-',
                                            ENT_QUOTES,
                                            'UTF-8'
                                        ) ?>
                                    </td>

                                    <td class="text-center">

                                        <div
                                            class="d-flex flex-wrap
                                                   justify-content-center gap-1"
                                        >

                                            <a
                                                href="<?= htmlspecialchars(
                                                    BASE_URL
                                                    . 'surveys/view_survey.php?id='
                                                    . (int)$survey['id'],
                                                    ENT_QUOTES,
                                                    'UTF-8'
                                                ) ?>"
                                                class="btn btn-sm btn-info"
                                                title="View survey"
                                            >
                                                <i class="fa-solid fa-eye"></i>
                                                <span class="d-none d-xl-inline">
                                                    View
                                                </span>
                                            </a>

                                            <a
                                                href="<?= htmlspecialchars(
                                                    BASE_URL
                                                    . 'surveys/edit_survey.php?id='
                                                    . (int)$survey['id'],
                                                    ENT_QUOTES,
                                                    'UTF-8'
                                                ) ?>"
                                                class="btn btn-sm btn-warning"
                                                title="Edit survey"
                                            >
                                                <i
                                                    class="fa-solid
                                                           fa-pen-to-square"
                                                ></i>
                                                <span class="d-none d-xl-inline">
                                                    Edit
                                                </span>
                                            </a>

                                            <a
                                                href="<?= htmlspecialchars(
                                                    BASE_URL
                                                    . 'surveys/print_survey.php?id='
                                                    . (int)$survey['id'],
                                                    ENT_QUOTES,
                                                    'UTF-8'
                                                ) ?>"
                                                class="btn btn-sm btn-secondary"
                                                target="_blank"
                                                rel="noopener"
                                                title="Print survey"
                                            >
                                                <i class="fa-solid fa-print"></i>
                                                <span class="d-none d-xl-inline">
                                                    Print
                                                </span>
                                            </a>

                                            <button
                                                type="button"
                                                class="btn btn-sm btn-danger"
                                                data-bs-toggle="modal"
                                                data-bs-target="#deleteSurveyModal"
                                                data-survey-id="<?=
                                                    (int)$survey['id']
                                                ?>"
                                                data-school-name="<?=
                                                    htmlspecialchars(
                                                        $survey['school_name'],
                                                        ENT_QUOTES,
                                                        'UTF-8'
                                                    )
                                                ?>"
                                                title="Delete survey"
                                            >
                                                <i
                                                    class="fa-solid
                                                           fa-trash-can"
                                                ></i>
                                                <span class="d-none d-xl-inline">
                                                    Delete
                                                </span>
                                            </button>

                                        </div>

                                    </td>

                                </tr>

                            <?php endforeach; ?>

                        </tbody>

                    </table>

                </div>

            <?php endif; ?>

        </div>

        <?php if ($totalRecords > 0): ?>

            <div
                class="card-footer d-flex flex-column flex-md-row
                       justify-content-between align-items-md-center gap-3"
            >

                <div class="text-muted">
                    Showing
                    <?= number_format($firstRecord) ?>
                    to
                    <?= number_format($lastRecord) ?>
                    of
                    <?= number_format($totalRecords) ?>
                    records
                </div>

                <?php if ($totalPages > 1): ?>

                    <nav aria-label="Survey pagination">

                        <ul class="pagination mb-0">

                            <li
                                class="page-item
                                <?= $page <= 1 ? 'disabled' : '' ?>"
                            >
                                <a
                                    class="page-link"
                                    href="<?= $page > 1
                                        ? htmlspecialchars(
                                            buildSurveyPageUrl($page - 1),
                                            ENT_QUOTES,
                                            'UTF-8'
                                        )
                                        : '#' ?>"
                                >
                                    Previous
                                </a>
                            </li>

                            <?php
                            $startPage = max(1, $page - 2);
                            $endPage = min($totalPages, $page + 2);
                            ?>

                            <?php if ($startPage > 1): ?>
                                <li class="page-item">
                                    <a
                                        class="page-link"
                                        href="<?= htmlspecialchars(
                                            buildSurveyPageUrl(1),
                                            ENT_QUOTES,
                                            'UTF-8'
                                        ) ?>"
                                    >
                                        1
                                    </a>
                                </li>

                                <?php if ($startPage > 2): ?>
                                    <li class="page-item disabled">
                                        <span class="page-link">…</span>
                                    </li>
                                <?php endif; ?>
                            <?php endif; ?>

                            <?php for (
                                $pageNumber = $startPage;
                                $pageNumber <= $endPage;
                                $pageNumber++
                            ): ?>

                                <li
                                    class="page-item
                                    <?= $pageNumber === $page
                                        ? 'active'
                                        : '' ?>"
                                >
                                    <a
                                        class="page-link"
                                        href="<?= htmlspecialchars(
                                            buildSurveyPageUrl($pageNumber),
                                            ENT_QUOTES,
                                            'UTF-8'
                                        ) ?>"
                                    >
                                        <?= $pageNumber ?>
                                    </a>
                                </li>

                            <?php endfor; ?>

                            <?php if ($endPage < $totalPages): ?>

                                <?php if (
                                    $endPage < $totalPages - 1
                                ): ?>
                                    <li class="page-item disabled">
                                        <span class="page-link">…</span>
                                    </li>
                                <?php endif; ?>

                                <li class="page-item">
                                    <a
                                        class="page-link"
                                        href="<?= htmlspecialchars(
                                            buildSurveyPageUrl($totalPages),
                                            ENT_QUOTES,
                                            'UTF-8'
                                        ) ?>"
                                    >
                                        <?= $totalPages ?>
                                    </a>
                                </li>

                            <?php endif; ?>

                            <li
                                class="page-item
                                <?= $page >= $totalPages
                                    ? 'disabled'
                                    : '' ?>"
                            >
                                <a
                                    class="page-link"
                                    href="<?= $page < $totalPages
                                        ? htmlspecialchars(
                                            buildSurveyPageUrl($page + 1),
                                            ENT_QUOTES,
                                            'UTF-8'
                                        )
                                        : '#' ?>"
                                >
                                    Next
                                </a>
                            </li>

                        </ul>

                    </nav>

                <?php endif; ?>

            </div>

        <?php endif; ?>

    </div>

</main>

<!-- Delete confirmation modal -->
<div
    class="modal fade"
    id="deleteSurveyModal"
    tabindex="-1"
    aria-labelledby="deleteSurveyModalLabel"
    aria-hidden="true"
>
    <div class="modal-dialog modal-dialog-centered">

        <div class="modal-content">

            <div class="modal-header bg-danger text-white">

                <h5
                    class="modal-title"
                    id="deleteSurveyModalLabel"
                >
                    <i class="fa-solid fa-triangle-exclamation me-1"></i>
                    Delete Survey
                </h5>

                <button
                    type="button"
                    class="btn-close btn-close-white"
                    data-bs-dismiss="modal"
                    aria-label="Close"
                ></button>

            </div>

            <form
                action="<?= htmlspecialchars(
                    BASE_URL . 'surveys/delete_survey.php',
                    ENT_QUOTES,
                    'UTF-8'
                ) ?>"
                method="post"
                id="deleteSurveyForm"
            >

                <div class="modal-body">

                    <input
                        type="hidden"
                        name="csrf_token"
                        value="<?= htmlspecialchars(
                            $csrfToken,
                            ENT_QUOTES,
                            'UTF-8'
                        ) ?>"
                    >

                    <input
                        type="hidden"
                        name="id"
                        id="deleteSurveyId"
                        value=""
                    >

                    <p class="mb-2">
                        Are you sure you want to delete this survey?
                    </p>

                    <div class="alert alert-warning mb-0">
                        <strong id="deleteSurveySchoolName">
                            Selected survey
                        </strong>

                        <div class="small mt-1">
                            This action cannot be undone.
                        </div>
                    </div>

                </div>

                <div class="modal-footer">

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

                    <button
                        type="submit"
                        class="btn btn-danger"
                    >
                        <i class="fa-solid fa-trash-can me-1"></i>
                        Delete
                    </button>

                </div>

            </form>

        </div>

    </div>
</div>

<script src="<?= BASE_URL ?>assets/js/survey_wizard.js?v=<?= urlencode(SYSTEM_VERSION) ?>"></script>

<?php include __DIR__ . '/../includes/footer.php'; ?>