<?php
// File: /fuelpos/admin/index.php
require __DIR__ . '/../init.php';
require_login();

// Provide esc() if not defined to avoid "undefined function" errors
if (!function_exists('esc')) {
    function esc($s){ return htmlspecialchars((string)$s, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); }
}

// Determine admin status (from session set at login) and username
$is_admin = !empty($_SESSION['is_admin']);
$username = $_SESSION['username'] ?? '';

?>
<!doctype html>
<html lang="es">
<head>
  <meta charset="utf-8">
  <title>SolutionPOS - Admin</title>
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
  <style>
    .admin-card .card-body { min-height:110px; }
  </style>
</head>
<body class="bg-light">
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm mb-4">
  <div class="container">
    <a class="navbar-brand fw-bold" href="<?= site('index.php') ?>">SolutionPOS - Admin</a>
    <div class="ms-auto d-flex gap-2">
      <?php if ($is_admin): ?>
        <a class="btn btn-outline-secondary btn-sm" href="<?= site('index.php') ?>">Panel Inicial</a>
      <?php endif; ?>
	  <a class="btn btn-outline-primary btn-sm" href="<?= site('index.php') ?>">Panel Inicial</a>
      <a class="btn btn-outline-primary btn-sm" href="<?= site('pos/index.php') ?>">Abrir POS</a>
      <a class="btn btn-outline-danger btn-sm" href="<?= site('admin_logout.php') ?>">Salir</a>
    </div>
  </div>
</nav>

<div class="container">
  <h3>Panel de administración</h3>
  <p class="text-muted">Bienvenido, <?= esc($username) ?> <?= $is_admin ? '(Administrador)' : '' ?></p>

  <div class="row g-3">
    <div class="col-12 col-md-3">
      <div class="card admin-card shadow-sm">
        <div class="card-body">
          <h5>Usuarios</h5>
          <p class="mb-2 text-muted small">Crear / editar usuarios</p>
          <a class="btn btn-primary" href="<?= site('admin/users.php') ?>">Gestionar usuarios</a>
        </div>
      </div>
    </div>

    <div class="col-12 col-md-3">
      <div class="card admin-card shadow-sm">
        <div class="card-body">
          <h5>Productos</h5>
          <p class="mb-2 text-muted small">Agregar / editar productos</p>
          <a class="btn btn-outline-primary" href="<?= site('admin/products.php') ?>">Gestionar productos</a>
        </div>
      </div>
    </div>

    <div class="col-12 col-md-3">
      <div class="card admin-card shadow-sm">
        <div class="card-body">
          <h5>Mangueras</h5>
          <p class="mb-2 text-muted small">Crear / gestionar mangueras de bombas</p>
          <a class="btn btn-outline-primary" href="<?= site('admin/pumps.php') ?>">Gestionar bombas y mangueras</a>
        </div>
      </div>
    </div>

    <div class="col-12 col-md-3">
      <div class="card admin-card shadow-sm">
        <div class="card-body">
          <h5>Estación</h5>
          <p class="mb-2 text-muted small">Gestionar estación</p>
          <a class="btn btn-outline-primary" href="<?= esc(site('admin/stations.php')) ?>">Gestionar estación</a>
        </div>
      </div>
    </div>

    <!-- NUEVA TARJETA: Comprobantes Fiscales -->
    <div class="col-12 col-md-3">
      <div class="card admin-card shadow-sm">
        <div class="card-body">
          <h5>Comprobantes Fiscales</h5>
          <p class="mb-2 text-muted small">Crear / gestionar comprobantes fiscales</p>
          <a class="btn btn-outline-primary" href="<?= esc(site('ncf/index.php')) ?>">Gestionar comprobantes</a>
        </div>
      </div>
    </div>

    <div class="col-12 col-md-3">
      <div class="card admin-card shadow-sm">
        <div class="card-body">
          <h5>Tanques</h5>
          <p class="mb-2 text-muted small">Gestionar tanques e inventario inicial</p>
          <a class="btn btn-outline-primary" href="<?= esc(site('admin/tanques.php')) ?>">Gestionar tanques</a>
        </div>
      </div>
    </div>
  </div>
</div>
</body>
</html>