<?php
require_once __DIR__.'/../includes/i18n.php';
if (!isset($breadcrumb)) $breadcrumb = "";
if (!isset($user_name)) $user_name = "User";

/* Packages */
$pack_defs = [
  "CAR" => "#00ff8c",
  "TRUCK" => "#00ff8c",
  "TRACTOR" => "#00ff8c",
  "MACHINERY" => "#00ff8c",
  "FULL" => "#00ff8c"
];

function lang_url($code){
  $uri = $_SERVER['REQUEST_URI'] ?? '';
  $path = strtok($uri, '?');
  $query = parse_url($uri, PHP_URL_QUERY);
  $params = [];
  if ($query) parse_str($query, $params);
  $params['lang'] = $code;
  $qs = http_build_query($params);
  return $path . ($qs ? ('?' . $qs) : '');
}
?>
<header class="topbar topbar-wide">
  <div class="tb-left">
    <a class="logo" href="dashboard.php">
      <span class="logo-mark">ECU</span>
      <span class="logo-text">
        <div class="logo-title">ECUPRATIX</div>
        <div class="logo-sub">TUNE PORTAL</div>
      </span>
    </a>
  </div>

  <nav class="tb-nav">
    <a class="tb-link<?= ($active??'')==='dashboard'?' active':'' ?>" href="dashboard.php"><?= t('menu_panel') ?></a>
    <a class="tb-link<?= ($active??'')==='chiptuning'?' active':'' ?>" href="chiptuning.php"><?= t('menu_chiptuning') ?></a>
    <a class="tb-link<?= ($active??'')==='dtc'?' active':'' ?>" href="dtc.php"><?= t('menu_dtc') ?></a>
    <a class="tb-link<?= ($active??'')==='requests'?' active':'' ?>" href="requests.php"><?= t('menu_requests') ?></a>
    <a class="tb-link<?= ($active??'')==='account'?' active':'' ?>" href="account.php"><?= t('menu_account') ?></a>
    <a class="tb-link<?= ($active??'')==='support'?' active':'' ?>" href="support.php"><?= t('menu_support') ?></a>
  </nav>

  <div class="tb-right">
    <div class="tb-packs">
      <?php foreach($pack_defs as $label=>$color): ?>
        <span class="pack-pill">
          <span class="pack-dot" style="background: <?= $color ?>;"></span>
          <?= $label ?>
        </span>
      <?php endforeach; ?>
    </div>
    
    <div class="user">
      <div class="avatar"><?= substr($user_name, 0, 1) ?></div>
      <select class="lang-select" onchange="location.href=this.value;">
  <option value="<?= htmlspecialchars(lang_url('tr')) ?>" <?= (($_SESSION['lang']??'tr')==='tr')?'selected':''; ?>>🇹🇷 TR - TÜRKÇE</option>
  <option value="<?= htmlspecialchars(lang_url('en')) ?>" <?= (($_SESSION['lang']??'tr')==='en')?'selected':''; ?>>🇬🇧 ENG - İNGİLİZCE</option>
  <option value="<?= htmlspecialchars(lang_url('es')) ?>" <?= (($_SESSION['lang']??'tr')==='es')?'selected':''; ?>>🇪🇸 ESP - ESPANYOL</option>
  <option value="<?= htmlspecialchars(lang_url('pt')) ?>" <?= (($_SESSION['lang']??'tr')==='pt')?'selected':''; ?>>🇵🇹 PT - PORTEKİZCE</option>
  <option value="<?= htmlspecialchars(lang_url('nl')) ?>" <?= (($_SESSION['lang']??'tr')==='nl')?'selected':''; ?>>🇳🇱 NL - FLEMENCE</option>
  <option value="<?= htmlspecialchars(lang_url('de')) ?>" <?= (($_SESSION['lang']??'tr')==='de')?'selected':''; ?>>🇩🇪 DE - ALMANCA</option>
  <option value="<?= htmlspecialchars(lang_url('ru')) ?>" <?= (($_SESSION['lang']??'tr')==='ru')?'selected':''; ?>>🇷🇺 RU - RUSÇA</option>
  <option value="<?= htmlspecialchars(lang_url('it')) ?>" <?= (($_SESSION['lang']??'tr')==='it')?'selected':''; ?>>🇮🇹 IT - İTALYANCA</option>
</select>
      <a class="chip danger" href="logout.php">Çıkış</a>
    </div>
  </div>
</header>

<link rel="stylesheet" href="assets/css/i18n_readability.css">