<?php
$items = [
  ['home', 'Home', 'bi-house-door', 'home'],
  ['invoices', 'Invoices', 'bi-receipt', 'invoices'],
  ['documents', 'Documents', 'bi-folder2-open', 'documents'],
  ['sign', 'Sign a paper', 'bi-pen', 'sign'],
  ['orders', 'My orders', 'bi-bag-check', 'orders'],
  ['contract', 'My contract', 'bi-file-earmark-ruled', 'contract'],
  ['service_request', 'Service request', 'bi-tools', 'service'],
  ['equipment', 'My equipment', 'bi-cpu', 'equipment'],
];
$path = trim(parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH) ?: '', '/');
$account = current_account();
$user = current_user();
$fullName = trim(($user['first_name'] ?? '') . ' ' . ($user['last_name'] ?? ''));
?>
<aside class="cpt-nav">
  <a class="cpt-brand" href="<?= e(url('home')) ?>">
    <img class="cpt-brand-logo" src="<?= e(asset('img/aosware-crm-logo.jpg')) ?>" alt="AOSWARE CRM">
  </a>
  <div class="cpt-portal-label">Customer Portal</div>
  <div class="cpt-company">
    <i class="bi bi-building"></i>
    <span><?= e($account['name'] ?? '') ?></span>
  </div>
  <nav>
    <?php foreach ($items as $item):
      if (!can_see($item[0])) continue;
      $active = str_contains($path, $item[3]) || ($item[3] === 'home' && (str_ends_with($path, 'customer-portal') || str_ends_with($path, 'home') || str_ends_with($path, 'customer-portal/')));
    ?>
      <a class="cpt-link <?= $active ? 'is-on' : '' ?>" href="<?= e(url($item[3])) ?>">
        <i class="bi <?= e($item[2]) ?>"></i>
        <span><?= e($item[1]) ?></span>
      </a>
    <?php endforeach; ?>
  </nav>
  <div class="cpt-foot">
    <div class="cpt-user">
      <span class="cpt-avatar"><?= e(name_initials($user['first_name'] ?? '', $user['last_name'] ?? '')) ?></span>
      <div>
        <div class="cpt-user-name"><?= e($fullName) ?></div>
        <div class="cpt-user-mail"><?= e($user['email'] ?? '') ?></div>
      </div>
    </div>
    <a class="cpt-link" href="<?= e(url('logout')) ?>"><i class="bi bi-box-arrow-left"></i> <span>Sign out</span></a>
  </div>
</aside>
