<?php
use App\Core\PortalAuth;
use App\Core\Config;

$contact = PortalAuth::contact();
$path = \App\Core\Request::path();
function portal_active(string $needle, string $path): string {
    return (strpos($path, $needle) === 0) ? ' active' : '';
}
?><!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?= e(Config::get('app.name')) ?> — Customer Portal</title>
<link rel="icon" type="image/png" href="<?= asset('img/erpcombd-favicon.png') ?>">
<link rel="stylesheet" href="<?= asset('css/app.css') ?>">
</head>
<body class="portal-body">
<div class="portal-header">
  <div class="flex items-center gap-3">
    <img src="<?= asset('img/erpcombd-logo.png') ?>" alt="ERP.COM.BD" style="height:26px;width:auto">
    <span class="text-faint">|</span>
    <div>
      <div style="font-weight:700;font-size:14.5px"><?= e($contact['customer_name'] ?? '') ?></div>
      <div class="text-faint text-sm">Customer Portal</div>
    </div>
  </div>
  <nav class="flex items-center gap-3" style="font-size:13.5px;font-weight:600">
    <a href="<?= url('/portal') ?>" class="<?= $path === '/portal' ? '' : '' ?>" style="color:<?= $path==='/portal'?'var(--brand)':'var(--ink-soft)' ?>">Dashboard</a>
    <a href="<?= url('/portal/tickets') ?>" style="color:<?= portal_active('/portal/tickets',$path)?'var(--brand)':'var(--ink-soft)' ?>">My Tickets</a>
    <span class="text-faint">|</span>
    <div class="user-chip">
      <div class="avatar" style="width:26px;height:26px;font-size:11px"><?= e(strtoupper(substr($contact['name'] ?? '?', 0, 1))) ?></div>
      <span><?= e($contact['name'] ?? '') ?></span>
    </div>
    <a href="<?= url('/portal/logout') ?>" class="btn btn-sm">Log out</a>
  </nav>
</div>

<div class="portal-shell">
  <div class="portal-content">
    <?php if ($msg = flash_get('success')) : ?><div class="alert alert-success" data-flash><?= e($msg) ?></div><?php endif; ?>
    <?php if ($msg = flash_get('error')) : ?><div class="alert alert-error" data-flash><?= e($msg) ?></div><?php endif; ?>
    <?php $content(); ?>
  </div>
</div>
<script src="<?= asset('js/app.js') ?>"></script>
</body>
</html>
