<?php use App\Helpers\Helper; ?>
<!DOCTYPE html>
<html lang="en" data-bs-theme="light">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= isset($title) ? htmlspecialchars($title) : 'Tenant Portal - '.APP_NAME ?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
<link href="<?= APP_URL ?>/assets/css/style.css" rel="stylesheet">
<link href="<?= APP_URL ?>/assets/css/admin.css" rel="stylesheet">
</head>
<body class="admin-body">

<div class="admin-sidebar" id="sidebar">
  <div class="sidebar-header">
    <a href="<?= APP_URL ?>/tenant" class="d-flex align-items-center gap-2 text-decoration-none">
      <i class="bi bi-buildings-fill text-primary fs-2"></i>
      <div><div class="fw-700 text-white fs-6 lh-1">Zabibu</div><div class="text-muted small">Tenant Portal</div></div>
    </a>
  </div>
  <div class="sidebar-user">
    <div class="d-flex align-items-center gap-2">
      <div class="avatar-sm bg-success rounded-circle d-flex align-items-center justify-content-center text-white fw-600">
        <?= strtoupper(substr($tenant['first_name']??'T',0,1)) ?>
      </div>
      <div>
        <div class="text-white fw-500 small"><?= htmlspecialchars(($tenant['first_name']??'').' '.($tenant['last_name']??'')) ?></div>
        <div class="text-muted x-small"><?= Helper::e($tenant['tenant_code']??'') ?></div>
      </div>
    </div>
  </div>
  <nav class="sidebar-nav">
    <div class="nav-section">PORTAL</div>
    <a href="<?= APP_URL ?>/tenant" class="nav-link <?= str_ends_with($_SERVER['REQUEST_URI'],'/tenant')?'active':'' ?>"><i class="bi bi-speedometer2"></i>Dashboard</a>
    <a href="<?= APP_URL ?>/tenant/payments" class="nav-link <?= str_contains($_SERVER['REQUEST_URI'],'/tenant/payments')?'active':'' ?>"><i class="bi bi-credit-card"></i>Payments</a>
    <a href="<?= APP_URL ?>/tenant/maintenance" class="nav-link <?= str_contains($_SERVER['REQUEST_URI'],'/tenant/maintenance')?'active':'' ?>"><i class="bi bi-tools"></i>Maintenance</a>
    <a href="<?= APP_URL ?>/tenant/profile" class="nav-link <?= str_contains($_SERVER['REQUEST_URI'],'/tenant/profile')?'active':'' ?>"><i class="bi bi-person"></i>My Profile</a>
    <div class="nav-section">BROWSE</div>
    <a href="<?= APP_URL ?>/residences" class="nav-link"><i class="bi bi-buildings"></i>Properties</a>
    <a href="<?= APP_URL ?>/logout" class="nav-link text-danger"><i class="bi bi-box-arrow-right"></i>Logout</a>
  </nav>
</div>

<div class="admin-main" id="adminMain">
  <header class="admin-topbar">
    <div class="d-flex align-items-center gap-3">
      <button class="btn btn-sm btn-link text-dark p-0" id="sidebarToggleBtn"><i class="bi bi-list fs-4"></i></button>
      <span class="small text-muted">Tenant Portal</span>
    </div>
    <div class="d-flex align-items-center gap-2">
      <button class="btn btn-sm btn-outline-secondary rounded-circle" id="darkModeBtn"><i class="bi bi-moon-fill" id="darkModeIcon"></i></button>
      <a href="<?= APP_URL ?>/logout" class="btn btn-sm btn-outline-danger"><i class="bi bi-box-arrow-right me-1"></i>Logout</a>
    </div>
  </header>
  <div class="admin-content">
    <?php $flash=Helper::getFlash(); if($flash): ?>
    <div class="alert alert-<?= $flash['type'] ?> alert-dismissible fade show">
      <?= $flash['message'] ?><button type="button" class="btn-close" data-bs-dismiss="alert"></button>
    </div>
    <?php endif; ?>
    <?= $content ?>
  </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="<?= APP_URL ?>/assets/js/app.js"></script>
<script src="<?= APP_URL ?>/assets/js/admin.js"></script>
</body>
</html>
