<?php 
error_reporting(-1);
ini_set('display_errors', 1);

include_once('../header.php');
if (!check_login()) {
  header("Location: " . WEB_URL . "logout.php");
  die();
}

include_once(ROOT_PATH.'language/'.$lang_code_global.'/lang_maintenance_cost_list.php');

// --- Alerts (delete / add / update) ---
$delinfo = 'none';
$addinfo = 'none';
$msg     = "";

// Safe input helper
function v($arr, $key, $default = '') {
  return isset($arr[$key]) ? $arr[$key] : $default;
}

$get_data = get_input_serilization();

// Deletion (keep same param name `id` for compatibility)
if (isset($get_data['id']) && $get_data['id'] != '' && (int)$get_data['id'] > 0) {
  $del_id = (int)$get_data['id'];
  $stmtDel = $link->prepare("DELETE FROM `maintenance` WHERE mcid = ?");
  if ($stmtDel) {
    $stmtDel->bind_param("i", $del_id);
    $stmtDel->execute();
    $stmtDel->close();
    $delinfo = 'block';
  }
}

// Messages
if (v($get_data, 'm') === 'add') { $addinfo = 'block'; $msg = $_data['add_msg']; }
if (v($get_data, 'm') === 'up')  { $addinfo = 'block'; $msg = $_data['update_msg']; }

// --- Filters (type / month / year / keyword) ---
$filter_type  = trim((string)v($get_data, 'type'));
$filter_month = (int)v($get_data, 'month', 0);
$filter_year  = (int)v($get_data, 'year', 0);
$filter_q     = trim((string)v($get_data, 'q'));

// Build SQL WHERE safely
$where = [];
if ($filter_type !== '') { 
  $esc = mysqli_real_escape_string($link, $filter_type);
  $where[] = "m.maintenance_type = '{$esc}'";
}
if ($filter_month > 0 && $filter_month <= 12) { 
  $where[] = "m.xmonth = ".(int)$filter_month; 
}
if ($filter_year > 0) { 
  $where[] = "m.xyear = ".(int)$filter_year; 
}
if ($filter_q !== '') {
  $esc = mysqli_real_escape_string($link, $filter_q);
  $where[] = "(m.m_title LIKE '%{$esc}%' OR m.m_details LIKE '%{$esc}%')";
}
$where_sql = count($where) ? ('WHERE ' . implode(' AND ', $where)) : '';

// Distinct types for filter dropdown
$type_options = [];
$typers = mysqli_query($link, "SELECT DISTINCT maintenance_type FROM maintenance WHERE maintenance_type IS NOT NULL AND maintenance_type <> '' ORDER BY maintenance_type ASC");
while ($trow = mysqli_fetch_assoc($typers)) {
  $type_options[] = $trow['maintenance_type'];
}
mysqli_free_result($typers);

// Years for filter (from earliest to current)
$year_min = (int)date('Y');
$year_max = (int)date('Y');
$yrq = mysqli_query($link, "SELECT MIN(xyear) AS ymin, MAX(xyear) AS ymax FROM maintenance WHERE xyear IS NOT NULL AND xyear > 0");
if ($yrq && ($yr = mysqli_fetch_assoc($yrq))) {
  if (!empty($yr['ymin'])) $year_min = min($year_min, (int)$yr['ymin']);
  if (!empty($yr['ymax'])) $year_max = max($year_max, (int)$yr['ymax']);
}
mysqli_free_result($yrq);
if ($year_min > $year_max) { $year_min = $year_max = (int)date('Y'); }

/* =========================
   MAIN QUERY — FIXED JOINS
   =========================
   - Join unit_view ONLY by uid to get unit_no and the unit’s block name
   - Join blocks table by bid for the explicit block on the record
   - This avoids row multiplication that happened with `unit_view` joined by bid
*/
$sql = "
  SELECT 
    m.mcid, m.m_title, m.maintenance_type, m.bid, m.uid, m.m_date, m.m_amount, m.m_details, m.xmonth, m.xyear,
    uv.unit_no               AS unit_no_from_uid,
    uv.b_name                AS b_name_from_uid,
    b.b_name                 AS b_name_from_bid
  FROM maintenance m
  LEFT JOIN unit_view uv   ON uv.uid = m.uid
  LEFT JOIN blocks    b    ON b.bid  = m.bid
  $where_sql
  ORDER BY m.m_date DESC, m.mcid DESC
";
$result = mysqli_query($link, $sql);

// Small helpers
function month_name_from_int($m) {
  $m = (int)$m;
  if ($m < 1 || $m > 12) return '';
  return date('F', mktime(0,0,0, $m, 1, 2000));
}

function badge_for_type($type) {
  $type = strtolower(trim((string)$type));
  // map style classes
  $map = [
    'repair'   => 'badge-repair',
    'service'  => 'badge-service',
    'utility'  => 'badge-utility',
    'cleaning' => 'badge-clean',
    'security' => 'badge-sec',
    'other'    => 'badge-other',
    'general'  => 'badge-other',
    'specific' => 'badge-other'
  ];
  $cls = isset($map[$type]) ? $map[$type] : 'badge-other';
  return '<span class="pill-badge '.$cls.'">'.htmlspecialchars(ucfirst($type)).'</span>';
}
?>
<!-- Content Header -->
<section class="content-header">
  <h1 style="display:flex;align-items:center;gap:10px;">
    <i class="fa fa-wrench" aria-hidden="true"></i> <?= $_data['add_title_text'];?>
  </h1>
  <ol class="breadcrumb">
    <li><a href="<?= WEB_URL?>dashboard.php"><i class="fa fa-dashboard"></i> <?= $_data['home_breadcam'];?></a></li>
    <li class="active"><?= $_data['m_cost'];?></li>
    <li class="active"><?= $_data['add_title_text'];?></li>
  </ol>
</section>

<style>
/* ===== Polished, readable UI ===== */
:root{
  --ink:#0f172a; --ink2:#334155; --muted:#64748b; --line:#e5e7eb;
  --soft:#f8fafc; --soft2:#eef2ff; --brand:#2563eb; --ok:#10b981; --warn:#f59e0b; --danger:#ef4444;
}
.card {
  background:#fff; border:1px solid var(--line); border-radius:14px;
  box-shadow:0 12px 30px rgba(2,6,23,.06); overflow:hidden; margin-bottom:18px;
}
.card-header {
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  padding:14px 16px; background:linear-gradient(135deg,#f8fafc,#eef2ff); border-bottom:1px solid var(--line);
}
.card-title { margin:0; font-weight:800; color:var(--ink); letter-spacing:.2px; }
.toolbar { display:flex; gap:8px; flex-wrap:wrap; }
.btn-pill { border-radius:999px !important; padding:8px 14px; font-weight:700; letter-spacing:.2px; }
.btn-primary { background:#2563eb; border-color:#2563eb; }
.btn-primary:hover { background:#1e40af; border-color:#1e40af; }
.btn-success { background:#16a34a; border-color:#16a34a; }
.btn-success:hover { background:#15803d; border-color:#15803d; }
.btn-ghost { background:#fff; color:#1f2937; border:1px solid var(--line); }
.btn-ghost:hover { background:#f8fafc; }

.filter-row {
  display:grid; grid-template-columns:1fr 140px 140px 180px auto; gap:10px;
  padding:14px 16px; border-bottom:1px dashed var(--line); background:#fbfdff;
}
@media(max-width: 900px){
  .filter-row { grid-template-columns: 1fr 1fr; }
}
.input, .select {
  width:100%; border:1px solid var(--line); border-radius:12px; padding:8px 12px; outline:none;
}
.input:focus, .select:focus { border-color:#93c5fd; box-shadow:0 0 0 3px rgba(59,130,246,.15); }

/* Table polish */
.table-polished { width:100%; border-collapse:separate; border-spacing:0 8px; }
.table-polished thead th {
  font-weight:800; color:var(--ink2); text-transform:uppercase; font-size:12px; letter-spacing:.35px;
  border-bottom:1px solid var(--line); padding:10px 12px;
}
.table-polished tbody tr {
  background:#fff; border:1px solid var(--line);
}
.table-polished tbody td {
  padding:12px; border-top:1px solid var(--line);
}
.table-polished tbody tr:first-child td { border-top:none; }
.table-polished tbody tr td:first-child { border-left:1px solid var(--line); border-radius:12px 0 0 12px; }
.table-polished tbody tr td:last-child { border-right:1px solid var(--line); border-radius:0 12px 12px 0; }

.pill-badge {
  display:inline-block; padding:6px 10px; border-radius:999px; font-weight:800; font-size:12px; letter-spacing:.25px;
  border:1px solid var(--line);
}
.badge-repair  { background:#fef3c7; color:#92400e; }
.badge-service { background:#dcfce7; color:#065f46; }
.badge-utility { background:#e0e7ff; color:#3730a3; }
.badge-clean   { background:#f5f3ff; color:#6d28d9; }
.badge-sec     { background:#ffe4e6; color:#9f1239; }
.badge-other   { background:#f3f4f6; color:#374151; }

.actions { display:flex; gap:6px; }
.actions .btn { padding:6px 10px; border-radius:10px; }

.modal-body h4.section-title {
  margin:0 0 10px; font-weight:800; color:var(--ink); border-bottom:1px dashed var(--line); padding-bottom:6px;
}

.kv { display:flex; gap:8px; }
.kv .k { min-width:130px; color:var(--muted); font-weight:700; }
.kv .v { color:#111827; font-weight:700; }

/* Alert subtle styling */
.alert { border-radius:12px; }
</style>

<section class="content">
  <!-- Alerts -->
  <div id="me" class="alert alert-danger alert-dismissable" style="display:<?= $delinfo; ?>">
    <button aria-hidden="true" data-dismiss="alert" class="close" type="button"><i class="fa fa-close"></i></button>
    <h4><i class="icon fa fa-ban"></i> <?= $_data['delete_text'];?>!</h4>
    <?= $_data['delete_msg'];?>
  </div>
  <div id="you" class="alert alert-success alert-dismissable" style="display:<?= $addinfo; ?>">
    <button aria-hidden="true" data-dismiss="alert" class="close" type="button"><i class="fa fa-close"></i></button>
    <h4><i class="icon fa fa-check"></i> <?= $_data['success'];?>!</h4>
    <?= $msg; ?>
  </div>

  <!-- Card: Filters + Actions -->
  <div class="card">
    <div class="card-header">
      <h3 class="card-title"><i class="fa fa-list-ul"></i> <?= $_data['add_title_text'];?></h3>
      <div class="toolbar">
        <a class="btn btn-success btn-pill" data-toggle="tooltip" href="<?= WEB_URL; ?>maintenance/add_maintenance_cost.php" title="<?= $_data['add_m_cost'];?>">
          <i class="fa fa-plus"></i> <?= $_data['add_m_cost'];?>
        </a>
        <a class="btn btn-ghost btn-pill" data-toggle="tooltip" href="<?= WEB_URL; ?>dashboard.php" title="<?= $_data['home_breadcam'];?>">
          <i class="fa fa-dashboard"></i> <?= $_data['home_breadcam'];?>
        </a>
      </div>
    </div>

    <!-- Filters -->
    <form method="get" class="filter-row">
      <input type="text" class="input" name="q" placeholder="Search title or details…" value="<?= htmlspecialchars($filter_q); ?>">
      <select class="select" name="type">
        <option value="">All Types</option>
        <?php foreach ($type_options as $t): ?>
          <option value="<?= htmlspecialchars($t) ?>" <?= ($filter_type === $t ? 'selected' : '') ?>>
            <?= htmlspecialchars(ucfirst($t)) ?>
          </option>
        <?php endforeach; ?>
      </select>
      <select class="select" name="month">
        <option value="0"><?= $_data['month']; ?></option>
        <?php for ($m=1; $m<=12; $m++): ?>
          <option value="<?= $m ?>" <?= ($filter_month === $m ? 'selected' : '') ?>><?= month_name_from_int($m) ?></option>
        <?php endfor; ?>
      </select>
      <select class="select" name="year">
        <option value="0"><?= $_data['year']; ?></option>
        <?php for ($y=$year_max; $y >= $year_min; $y--): ?>
          <option value="<?= $y ?>" <?= ($filter_year === $y ? 'selected' : '') ?>><?= $y ?></option>
        <?php endfor; ?>
      </select>
      <div style="display:flex; gap:8px;">
        <button type="submit" class="btn btn-primary btn-pill"><i class="fa fa-search"></i> Filter</button>
        <a href="<?= WEB_URL; ?>maintenance/maintenance_cost_list.php" class="btn btn-ghost btn-pill"><i class="fa fa-undo"></i> Reset</a>
      </div>
    </form>

    <!-- Table -->
    <div class="box-body" style="padding:14px 16px 18px;">
      <div class="table-responsive">
        <table id="maintenanceTable" class="table table-polished table-bordered dt-responsive">
          <thead>
            <tr>
              <th><?= $_data['text_1']; ?></th>
              <th>Type</th>
              <th>Block</th>
              <th>Unit</th>
              <th><?= $_data['date']; ?></th>
              <th><?= $_data['text_2']; ?></th>
              <th><?= $_data['action_text']; ?></th>
            </tr>
          </thead>
          <tbody>
            <?php while($row = mysqli_fetch_assoc($result)): 
              // Prefer an explicit block on the record; else fall back to unit's block name
              $block_name = $row['b_name_from_bid'] ?: $row['b_name_from_uid'] ?: '';
              $unit_no    = $row['unit_no_from_uid'] ?: '';
              $modal_id   = 'mc_view_' . (int)$row['mcid'];
            ?>
            <tr>
              <td>
                <div style="font-weight:800; color:#0f172a;"><?= htmlspecialchars($row['m_title']); ?></div>
                <div style="color:#64748b; font-size:12px;"><?= $row['m_details'] ? htmlspecialchars(mb_strimwidth($row['m_details'],0,90,'…','UTF-8')) : '' ?></div>
              </td>
              <td><?= badge_for_type($row['maintenance_type']); ?></td>
              <td><?= htmlspecialchars($block_name) ?></td>
              <td><?= htmlspecialchars($unit_no) ?></td>
              <td><?= htmlspecialchars(date("jS F, Y" ,strtotime($row['m_date']))) ?></td>
              <td style="white-space:nowrap;"><?= money_print($row['m_amount']); ?></td>
              <td>
                <div class="actions">
                  <a class="btn btn-success ams_btn_special" data-toggle="tooltip" href="javascript:void(0);" onclick="$('#<?= $modal_id ?>').modal('show');" title="<?= $_data['view_text'];?>">
                    <i class="fa fa-eye"></i>
                  </a>
                  <a class="btn btn-warning ams_btn_special" data-toggle="tooltip" href="<?= WEB_URL;?>maintenance/add_maintenance_cost.php?id=<?= (int)$row['mcid']; ?>" title="<?= $_data['edit_text'];?>">
                    <i class="fa fa-pencil"></i>
                  </a>
                  <a class="btn btn-danger ams_btn_special" data-toggle="tooltip" href="javascript:void(0);" onclick="deleteMaintenanceCost(<?= (int)$row['mcid']; ?>);" title="<?= $_data['delete_text'];?>">
                    <i class="fa fa-trash-o"></i>
                  </a>
                </div>

             <!-- Stylish Maintenance Cost Details Modal -->
<div id="<?= $modal_id ?>" class="modal fade mcost-modal" tabindex="-1" role="dialog" aria-labelledby="mcost_title_<?= $modal_id ?>" aria-modal="true" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">

      <!-- Header -->
      <div class="modal-header mcost-header">
        <h3 class="modal-title" id="mcost_title_<?= $modal_id ?>">
          <span class="mcost-title-icon"><i class="fa fa-file-text-o" aria-hidden="true"></i></span>
          <?= $_data['m_cost_details']; ?>
        </h3>
        <button aria-label="Close" data-dismiss="modal" class="close mcost-close" type="button">
          <span aria-hidden="true"><i class="fa fa-close"></i></span>
        </button>
      </div>

      <!-- Body -->
      <div class="modal-body">

        <!-- Summary Card -->
        <div class="mcost-summary">
          <div class="mcost-summary-main">
            <div class="mcost-title">
              <?= htmlspecialchars($row['m_title']); ?>
            </div>

            <div class="mcost-chips">
              <span class="mcost-chip mcost-chip-type" title="Type">
                <i class="fa fa-wrench" aria-hidden="true"></i>
                <?= htmlspecialchars(ucfirst($row['maintenance_type'])); ?>
              </span>

              <span class="mcost-chip mcost-chip-amount" title="<?= $_data['text_2']; ?>">
                <i class="fa fa-money" aria-hidden="true"></i>
                <?= money_print($row['m_amount']); ?>
              </span>

              <span class="mcost-chip mcost-chip-date" title="<?= $_data['date']; ?>">
                <i class="fa fa-calendar" aria-hidden="true"></i>
                <?= htmlspecialchars(date("jS F, Y" ,strtotime($row['m_date']))); ?>
              </span>
            </div>
          </div>
        </div>

        <!-- Section Title -->
        <h4 class="mcost-section-title">
          <i class="fa fa-list-ul" aria-hidden="true"></i>
          <?= $_data['details_information']; ?>
        </h4>

        <!-- Details Grid -->
        <div class="mcost-grid">
          <div class="mcost-col">
            <div class="mcost-kv">
              <div class="mcost-k"><i class="fa fa-tag" aria-hidden="true"></i> <?= $_data['text_1']; ?>:</div>
              <div class="mcost-v"><?= htmlspecialchars($row['m_title']); ?></div>
            </div>

            <div class="mcost-kv">
              <div class="mcost-k"><i class="fa fa-wrench" aria-hidden="true"></i> Type:</div>
              <div class="mcost-v"><?= htmlspecialchars(ucfirst($row['maintenance_type'])); ?></div>
            </div>

            <div class="mcost-kv">
              <div class="mcost-k"><i class="fa fa-money" aria-hidden="true"></i> <?= $_data['text_2']; ?>:</div>
              <div class="mcost-v"><?= money_print($row['m_amount']); ?></div>
            </div>

            <div class="mcost-kv">
              <div class="mcost-k"><i class="fa fa-calendar-o" aria-hidden="true"></i> <?= $_data['date']; ?>:</div>
              <div class="mcost-v"><?= htmlspecialchars(date("jS F, Y" ,strtotime($row['m_date']))); ?></div>
            </div>
          </div>

          <div class="mcost-col">
            <div class="mcost-kv">
              <div class="mcost-k"><i class="fa fa-building" aria-hidden="true"></i> Block:</div>
              <div class="mcost-v"><?= htmlspecialchars($block_name); ?></div>
            </div>

            <div class="mcost-kv">
              <div class="mcost-k"><i class="fa fa-home" aria-hidden="true"></i> Unit:</div>
              <div class="mcost-v"><?= htmlspecialchars($unit_no); ?></div>
            </div>

            <div class="mcost-kv">
              <div class="mcost-k"><i class="fa fa-calendar" aria-hidden="true"></i> <?= $_data['month']; ?>:</div>
              <div class="mcost-v"><?= month_name_from_int($row['xmonth']); ?></div>
            </div>

            <div class="mcost-kv">
              <div class="mcost-k"><i class="fa fa-calendar-check-o" aria-hidden="true"></i> <?= $_data['year']; ?>:</div>
              <div class="mcost-v"><?= (int)$row['xyear']; ?></div>
            </div>
          </div>
        </div>

        <!-- Description -->
        <div class="mcost-desc">
          <div class="mcost-desc-title">
            <i class="fa fa-sticky-note" aria-hidden="true"></i> <?= $_data['text_3']; ?>:
          </div>
          <div class="mcost-desc-box">
            <?= nl2br(htmlspecialchars($row['m_details'])); ?>
          </div>
        </div>
      </div>

      <!-- Footer -->
      <div class="modal-footer mcost-footer">
        <button type="button" data-dismiss="modal" class="btn btn-ghost btn-pill">
          <i class="fa fa-close"></i> Close
        </button>
        <a class="btn btn-warning btn-pill" href="<?= WEB_URL;?>maintenance/add_maintenance_cost.php?id=<?= (int)$row['mcid']; ?>">
          <i class="fa fa-pencil"></i> <?= $_data['edit_text']; ?>
        </a>
      </div>
    </div>
  </div>
</div>

<!-- Scoped Styles -->
<style>
  /* ---------- Palette & base ---------- */
  .mcost-modal :root { color-scheme: light; }
  .mcost-modal .modal-content {
    border-radius: 16px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 24px 60px rgba(2, 6, 23, 0.12);
    overflow: hidden;
    font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
    color: #0f172a;
  }

  /* ---------- Header ---------- */
  .mcost-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px;
    background: linear-gradient(135deg, #f8fafc, #eef2ff);
    border-bottom: 1px solid #e5e7eb;
  }
  .mcost-title-icon {
    display:inline-flex; align-items:center; justify-content:center;
    width: 34px; height: 34px; border-radius: 999px;
    background: #e0e7ff; color: #3730a3; margin-right: 10px;
  }
  .mcost-header .modal-title {
    margin: 0; font-weight: 800; letter-spacing: .2px; display: flex; align-items:center;
    color: #0f172a;
  }
  .mcost-close { opacity: .75; }
  .mcost-close:hover { opacity: 1; }

  /* ---------- Summary ---------- */
  .mcost-summary {
    border: 1px dashed #e5e7eb; border-radius: 14px; padding: 14px;
    background: #f8fafc; margin-bottom: 14px;
  }
  .mcost-title {
    font-size: 18px; font-weight: 900; letter-spacing: .2px; color: #0f172a;
  }
  .mcost-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
  .mcost-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 10px; border-radius: 999px; font-weight: 800; font-size: 12px;
    border: 1px solid transparent; background: #fff;
  }
  .mcost-chip i { opacity: .9; }
  .mcost-chip-type   { background: #eef2ff; color:#3730a3; border-color:#e0e7ff; }
  .mcost-chip-amount { background: #ecfeff; color:#075985; border-color:#bae6fd; }
  .mcost-chip-date   { background: #fefce8; color:#7c2d12; border-color:#fde68a; }

  /* ---------- Section Title ---------- */
  .mcost-section-title {
    display: flex; align-items: center; gap: 8px;
    font-weight: 800; color: #0f172a; margin: 14px 0 12px;
  }

  /* ---------- Details Grid ---------- */
  .mcost-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 12px 24px;
  }
  @media (max-width: 600px){
    .mcost-grid { grid-template-columns: 1fr; }
  }
  .mcost-col { display: grid; gap: 8px; }

  .mcost-kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px; align-items: center; }
  @media (max-width: 600px){
    .mcost-kv { grid-template-columns: 1fr; gap: 2px; }
  }
  .mcost-k {
    color: #64748b; font-weight: 700; text-transform: uppercase; letter-spacing: .3px; font-size: 11px;
    display:flex; align-items:center; gap: 6px;
  }
  .mcost-v { color: #0f172a; font-weight: 800; }

  /* ---------- Description ---------- */
  .mcost-desc { margin-top: 14px; }
  .mcost-desc-title {
    color: #64748b; font-weight: 800; text-transform: uppercase; letter-spacing: .3px;
    font-size: 11px; display:flex; align-items:center; gap:6px; margin-bottom: 8px;
  }
  .mcost-desc-box {
    border: 1px solid #e5e7eb; border-radius: 12px; background: #fff;
    padding: 12px; white-space: pre-wrap; line-height: 1.55;
  }

  /* ---------- Footer ---------- */
  .mcost-footer {
    display:flex; justify-content:flex-end; gap:8px;
    border-top: 1px solid #e5e7eb; background: #fbfdff;
  }
  .btn.btn-pill { border-radius: 999px; }
  .btn.btn-ghost {
    background: #fff; border: 1px solid #e5e7eb; color:#0f172a;
  }
  .btn.btn-ghost:hover {
    background: #f8fafc;
  }
</style>

                <!-- /Modal -->
              </td>
            </tr>
            <?php endwhile; mysqli_free_result($result); ?>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</section>

<script type="text/javascript">
  function deleteMaintenanceCost(Id){
    var go = function(){
      window.location = '<?= WEB_URL; ?>maintenance/maintenance_cost_list.php?id=' + Id;
    };
    if (typeof sweetConfirmDelete === 'function') {
      sweetConfirmDelete(go);
    } else {
      if (confirm('<?= addslashes($_data['delete_text']);?>?')) go();
    }
  }

  $(document).ready(function() {
    setTimeout(function() {
      $("#me").fadeOut(300);
      $("#you").fadeOut(300);
    }, 3000);

    // Enhance table if DataTables is present
    if ($.fn.DataTable) {
      $('#maintenanceTable').DataTable({
        pageLength: 10,
        order: [],
        responsive: true,
        columnDefs: [
          { orderable: false, targets: [6] } // action column
        ],
        language: {
          search: "Quick Search:",
          searchPlaceholder: "Type to filter…"
        }
      });
    }
  });
</script>

<?php include_once('../footer.php'); ?> 
