<?php
// ============================================================
//  MediCore — Requisition Module Tab Bar (shared component)
//  File: includes/requisition-tabs.php
//  Include after header.php on every requisition-related page.
//  Expects $__page (set in each page) to highlight active tab.
// ============================================================

$__reqTabs = [
    'product/smart-requisition' => ['🤖', 'Smart Requisition',     'smart-requisition.php'],
    'product/requisition'       => ['📝', 'Manual Requisition',    'requisition.php'],
    'product/stock-alert'       => ['🔔', 'Low Stock Alert Qty',   'stock-alert.php'],
    'product/req-record'        => ['🗂',  'Requisition Records',  'req-record.php'],
    'purchase/list'             => ['📥', 'Purchase Orders',       '../purchase/list.php'],
];

// Reports dropdown links (shared with sidebar — see includes/header.php)
$__reqReportLinks = $reportLinks ?? [
    ['accounting/profit',            '📈', 'Profit Report'],
    ['accounting/reports-inventory', '📋', 'Inventory Reports'],
    ['accounting/reports-sales',     '💊', 'Sales Reports'],
    ['accounting/reports-purchase',  '📦', 'Purchase Reports'],
    ['accounting/reports-financial', '💰', 'Financial Reports'],
    ['accounting/returns-report',    '↩',  'Returns Report'],
];
$__reqReportPages = array_column($__reqReportLinks, 0);
$__reqReportsActive = in_array($__page, $__reqReportPages);
?>
<div style="display:flex;gap:0;margin-bottom:14px;border-bottom:2px solid var(--border);
            overflow-x:auto;white-space:nowrap;align-items:center">
  <?php foreach ($__reqTabs as $key => [$icon, $label, $href]):
      $active = ($__page === $key);
  ?>
  <a href="<?= htmlspecialchars($href) ?>"
     style="padding:9px 18px;font-size:12.5px;font-weight:600;text-decoration:none;
            border-bottom:3px solid <?= $active ? 'var(--brand)' : 'transparent' ?>;
            color:<?= $active ? 'var(--brand)' : 'var(--text2)' ?>;
            background:<?= $active ? 'var(--brand-xlight)' : 'transparent' ?>;
            margin-bottom:-2px;white-space:nowrap;transition:all .15s">
    <?= $icon ?> <?= $label ?>
  </a>
  <?php endforeach; ?>

  <!-- Reports dropdown -->
  <div class="rep-dd">
    <button type="button"
            class="rep-dd-btn<?= $__reqReportsActive ? ' active' : '' ?>"
            onclick="toggleReqReportsDD(event)">
      📊 Reports <span style="font-size:9px">▾</span>
    </button>
    <div class="rep-dd-menu" id="req-reports-dd">
      <?php foreach ($__reqReportLinks as [$rSlug, $rIcon, $rLabel]):
          $rActive = ($__page === $rSlug);
          $rHref   = '../' . $rSlug . '.php';
      ?>
      <a href="<?= htmlspecialchars($rHref) ?>"
         class="<?= $rActive ? 'active' : '' ?>">
        <?= $rIcon ?> <?= htmlspecialchars($rLabel) ?>
      </a>
      <?php endforeach; ?>
    </div>
  </div>
</div>

<script>
function toggleReqReportsDD(e) {
  e.stopPropagation();
  const menu = document.getElementById('req-reports-dd');
  menu.classList.toggle('show');
}
document.addEventListener('click', (e) => {
  const menu = document.getElementById('req-reports-dd');
  if (menu && !e.target.closest('.rep-dd')) menu.classList.remove('show');
});
</script>
