<?php
declare(strict_types=1);

require_once __DIR__ . '/includes/auth.php';
require_once __DIR__ . '/includes/helpers.php';

require_scope();
ensure_session();

$pdo = pdo();
$u = current_user();
$sc = scope();
$companyId = (int)($sc['company_id'] ?? 0);
$locationId = (int)($sc['location_id'] ?? 0);

$companyName = '';
$locationName = '';
try {
  $st = $pdo->prepare("SELECT name FROM companies WHERE id=? LIMIT 1");
  $st->execute([$companyId]);
  $companyName = (string)($st->fetchColumn() ?: ('Empresa #' . $companyId));

  $st = $pdo->prepare("SELECT name FROM locations WHERE id=? AND company_id=? LIMIT 1");
  $st->execute([$locationId, $companyId]);
  $locationName = (string)($st->fetchColumn() ?: ('Localidad #' . $locationId));
} catch (Throwable $e) {
  $companyName = 'Empresa #' . $companyId;
  $locationName = 'Localidad #' . $locationId;
}

$title = 'Producción Hielo Bolsa';
$description = 'Captura y control operativo de producción para planta Hielo Bolsa.';
?>
<!doctype html>
<html lang="es">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>BReport · <?= h($title) ?></title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/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">
  <style>
    body{background:#f6f7fb;}
    .topbar{background:linear-gradient(135deg,#061b2b,#0b2f55);color:#fff;}
    .panel{border-radius:22px;border:1px solid rgba(0,0,0,.06);}
    .badge-scope{background:rgba(255,255,255,.14);border:1px solid rgba(255,255,255,.18);}
  </style>
</head>
<body>
  <div class="topbar p-3 shadow-sm">
    <div class="container-fluid d-flex flex-wrap align-items-center gap-2">
      <div>
        <h1 class="h4 m-0">BReport · <?= h($title) ?></h1>
        <div class="small opacity-75"><?= h($description) ?></div>
      </div>
      <div class="ms-auto d-flex flex-wrap gap-2 align-items-center">
        <span class="badge badge-scope rounded-pill px-3 py-2"><i class="bi bi-building"></i> <?= h($companyName) ?></span>
        <span class="badge badge-scope rounded-pill px-3 py-2"><i class="bi bi-pin-map"></i> <?= h($locationName) ?></span>
        <a class="btn btn-light btn-sm" href="dashboard.php"><i class="bi bi-arrow-left"></i> Dashboard</a>
      </div>
    </div>
  </div>

  <main class="container py-4">
    <section class="card panel shadow-sm">
      <div class="card-body p-4">
        <div class="d-flex gap-3 align-items-start">
          <div class="rounded-4 bg-primary bg-opacity-10 text-primary d-flex align-items-center justify-content-center" style="width:56px;height:56px;flex:0 0 auto;">
            <i class="bi bi-bag-check fs-3"></i>
          </div>
          <div>
            <h2 class="h5 mb-2"><?= h($title) ?></h2>
            <p class="text-muted mb-3">
              Archivo base creado para separar la lógica de producción por tipo de planta.
              Este módulo ya queda protegido por sesión y alcance activo de BReport.
            </p>
            <div class="alert alert-info mb-0">
              <strong>Siguiente paso:</strong> aquí se debe implementar la lógica específica de captura, inventario y reportaje para esta planta,
              siempre filtrando por <code>company_id = <?= h((string)$companyId) ?></code> y <code>location_id = <?= h((string)$locationId) ?></code>.
            </div>
          </div>
        </div>
      </div>
    </section>
  </main>
</body>
</html>
