<?php
$theme = theme_settings();
$primary = $theme['primary'] ?? '#711F37';
$accent = $theme['accent'] ?? '#9B3B58';
$dark = $theme['dark'] ?? '#111113';
$gray = $theme['gray'] ?? '#73737A';
$surface = $theme['surface'] ?? '#F2F2F3';
$container = $theme['container'] ?? '1180';
$headerMenu = site_menu_items(menu_items('header'));
$footerMenu = menu_items('footer');
if (!$headerMenu) {
 $headerMenu = [
 ['label' => site_ui('nav.home'), 'url' => '/'],
 ['label' => site_ui('nav.services'), 'url' => '/services'],
 ['label' => site_ui('nav.about'), 'url' => '/about-us'],
 ['label' => site_ui('nav.blog'), 'url' => '/blog'],
 ['label' => site_ui('nav.contact'), 'url' => '/contact-us'],
 ];
}

// Blog is a core public section. Keep it visible even when an older custom menu
// was saved before the blog module was introduced.
$hasBlog = false;
foreach ($headerMenu as $menuItem) {
 if (rtrim((string)($menuItem['url'] ?? ''), '/') === '/blog') { $hasBlog = true; break; }
}
if (!$hasBlog) $headerMenu[] = ['label' => site_ui('nav.blog'), 'url' => '/blog'];

$hasFooterBlog = false;
foreach ($footerMenu as $menuItem) {
 if (rtrim((string)($menuItem['url'] ?? ''), '/') === '/blog') { $hasFooterBlog = true; break; }
}
if ($footerMenu && !$hasFooterBlog) $footerMenu[] = ['label' => site_ui('nav.blog'), 'url' => '/blog'];

$publicHref = static function (string $href): string {
 return page_block_href($href);
};
$headerLogo = branding_asset('site_logo_header');
$footerLogo = branding_asset('site_logo_footer');
$favicon = branding_asset('site_favicon');
$globalFooter = itx_global_footer_data();
$digitFa = static function(string $v): string { return site_is_en() ? $v : strtr($v, ['0'=>'۰','1'=>'۱','2'=>'۲','3'=>'۳','4'=>'۴','5'=>'۵','6'=>'۶','7'=>'۷','8'=>'۸','9'=>'۹']); };
$languageSwitch = site_language_switch_url(site_is_en() ? 'fa' : 'en');
?>
<!doctype html>
<html lang="<?=e(site_lang())?>" dir="<?=e(site_dir())?>">
<head>
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title><?=e($title ?? setting('site_name', 'ITX Trade'))?></title>
 <link rel="alternate" hreflang="fa" href="<?=e(site_language_switch_url('fa'))?>">
 <link rel="alternate" hreflang="en" href="<?=e(site_language_switch_url('en'))?>">
 <?php if (!empty($meta_description)): ?>
 <meta name="description" content="<?=e($meta_description)?>">
 <?php endif; ?>
 <meta name="theme-color" content="<?=e($dark)?>">
 <?php if ($favicon !== ''): ?>
 <link rel="icon" href="<?=e($favicon)?>">
 <link rel="shortcut icon" href="<?=e($favicon)?>">
 <?php endif; ?>

 <link rel="preconnect" href="https://cdn.jsdelivr.net">
 <link rel="preconnect" href="https://cdnjs.cloudflare.com">
 <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/rastikerdar/vazirmatn@v33.003/Vazirmatn-font-face.css">
 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" referrerpolicy="no-referrer">
 <link rel="stylesheet" href="<?=url('assets/css/itx-trade.css?v=8.6.0')?>">
 <link rel="stylesheet" href="<?=url('assets/css/shared-public-footer.css?v=8.6.0')?>">
 <style>
 :root {
 --maroon: <?=e($primary)?>;
 --maroon-2: <?=e($accent)?>;
 --ink: <?=e($dark)?>;
 --gray: <?=e($gray)?>;
 --surface: <?=e($surface)?>;
 --blue: <?=e($primary)?>;
 --blue-2: <?=e($accent)?>;
 --navy-950: <?=e($dark)?>;
 --navy-900: <?=e($dark)?>;
 --silver-500: <?=e($gray)?>;
 --silver-100: <?=e($surface)?>;
 --container: <?=e($container)?>px;
 }
 .brand-logo-image { display:block; width:auto; max-width:190px; height:52px; object-fit:contain; }
 .footer-brand .brand-logo-image { max-width:190px; height:58px; }
 .language-switch{display:inline-grid;place-items:center;min-width:42px;height:42px;padding:0 10px;border:1px solid rgba(113,31,55,.28);border-radius:12px;font-size:.78rem;font-weight:900;color:var(--ink);background:#fff;text-decoration:none}
 html[dir="ltr"] body{text-align:left} html[dir="ltr"] .nav-dropdown-menu{right:auto;left:-28px} html[dir="ltr"] .nav-dropdown-arrow{transform:scaleX(-1)}
 @media (max-width: 520px) { .site-header .brand-logo-image { max-width:145px; height:44px; } }
 </style>
</head>
<body class="<?=e($body_class ?? '')?>">
<header class="site-header" id="top">
 <div class="container header-inner">
 <a href="<?=e(site_public_url('/'))?>" class="brand" aria-label="<?=e(setting('site_name', 'ITX Trade'))?>">
 <?php if ($headerLogo !== ''): ?>
 <img class="brand-logo-image" src="<?=e($headerLogo)?>" alt="<?=e(setting('site_name', 'ITX Trade'))?>">
 <?php else: ?>
 <span class="brand-mark"><span>ITX</span></span>
 <span class="brand-copy">
 <strong><?=e(setting('site_name', 'ITX Trade'))?></strong>
 <small><?=e(site_company_name())?></small>
 </span>
 <?php endif; ?>
 </a>

 <nav class="main-nav" id="mainNav" aria-label="<?=e(site_ui('nav.main_aria'))?>">
 <?php foreach ($headerMenu as $item): ?>
 <?php
 $href = (string)($item['url'] ?? '#');
 $menuPath = rtrim((string)(parse_url($href, PHP_URL_PATH) ?: $href), '/');
 $isServicesMenu = $menuPath === '/services';
 $serviceSectionActive = in_array(rtrim(site_path_without_locale(current_path()), '/'), ['/services', '/it-services', '/trade-services', '/network-infrastructure', '/data-center-cloud', '/international-trade', '/technology-consulting'], true);
 ?>
 <?php if ($isServicesMenu): ?>
 <div class="nav-dropdown <?=$serviceSectionActive ? 'active' : ''?>">
 <div class="nav-dropdown-trigger">
 <a href="<?=e($publicHref($href))?>" class="nav-parent-link <?=$serviceSectionActive ? 'active' : ''?>"><?=e($item['label'] ?? site_ui('nav.services'))?></a>
 <button class="nav-dropdown-toggle" type="button" aria-label="<?=e(site_ui('nav.services_aria'))?>" aria-expanded="false"><i class="fa-solid fa-chevron-down"></i></button>
 </div>
 <div class="nav-dropdown-menu">
 <a href="<?=e(site_public_url('/it-services'))?>" class="<?=menu_link_active('/it-services') ? 'active' : ''?>">
 <span class="nav-dropdown-icon"><i class="fa-solid fa-network-wired"></i></span>
 <span><strong><?=e(site_ui('nav.it'))?></strong><small><?=e(site_ui('nav.it_sub'))?></small></span>
 <i class="fa-solid <?=site_is_en()?'fa-arrow-right':'fa-arrow-left'?> nav-dropdown-arrow"></i>
 </a>
 <a href="<?=e(site_public_url('/trade-services'))?>" class="<?=menu_link_active('/trade-services') ? 'active' : ''?>">
 <span class="nav-dropdown-icon"><i class="fa-solid fa-briefcase"></i></span>
 <span><strong><?=e(site_ui('nav.trade'))?></strong><small><?=e(site_ui('nav.trade_sub'))?></small></span>
 <i class="fa-solid <?=site_is_en()?'fa-arrow-right':'fa-arrow-left'?> nav-dropdown-arrow"></i>
 </a>
 </div>
 </div>
 <?php else: ?>
 <a href="<?=e($publicHref($href))?>" class="<?=menu_link_active($href) ? 'active' : ''?>"><?=e($item['label'] ?? '')?></a>
 <?php endif; ?>
 <?php endforeach; ?>
 </nav>

 <div class="header-actions">
 <a class="language-switch" href="<?=e($languageSwitch)?>" hreflang="<?=site_is_en()?'fa':'en'?>" aria-label="<?=site_is_en()?'View Persian version':'مشاهده نسخه انگلیسی'?>"><?=site_is_en()?'FA':'EN'?></a>
 <a class="header-cta" href="<?=e(site_public_url('/contact-us'))?>"><?=e(site_ui('nav.consult'))?> <i class="fa-solid <?=site_is_en()?'fa-arrow-right':'fa-arrow-left'?>"></i></a>
 <button class="menu-toggle" id="menuToggle" type="button" aria-controls="mainNav" aria-label="<?=e(site_ui('nav.menu_aria'))?>" aria-expanded="false">
 <i class="fa-solid fa-bars"></i>
 </button>
 </div>
 </div>
</header>

<main>
 <?php echo $this->yieldContent('content'); ?>
</main>

<footer class="itx7-footer"><div class="itx7-container"><div class="itx7-footer-grid">
 <div><div class="itx7-brand"><?php if($footerLogo!==''):?><img class="brand-logo-image" src="<?=e($footerLogo)?>" alt="<?=e(setting('site_name', 'ITX Trade'))?>"><?php elseif($headerLogo!==''):?><img class="brand-logo-image" src="<?=e($headerLogo)?>" alt="<?=e(setting('site_name', 'ITX Trade'))?>"><?php else:?><span class="itx7-brand-mark">ITX</span><span class="itx7-brand-name"><?=e(site_company_name())?></span><?php endif;?></div><p><?=e($globalFooter['about'])?></p></div>
 <div><h4><?=e(site_ui('footer.contact'))?></h4><ul><li><?=$digitFa($globalFooter['mobile1'])?></li><li><?=$digitFa($globalFooter['mobile2'])?></li><li><?=$digitFa($globalFooter['phone'])?></li><li><a href="mailto:<?=e($globalFooter['email'])?>"><?=e($globalFooter['email'])?></a></li></ul></div>
 <div><h4><?=e(site_ui('footer.address'))?></h4><ul><li><?=e($globalFooter['address1'])?></li><li><?=e($globalFooter['address2'])?></li></ul></div>
 <div><h4><?=e(site_ui('footer.quick'))?></h4><ul><li><a href="<?=e(site_public_url('/about-us'))?>"><?=e(site_ui('nav.about'))?></a></li><li><a href="<?=e(site_public_url('/#services'))?>"><?=e(site_ui('nav.services'))?></a></li><li><a href="<?=e(site_public_url('/#blog'))?>"><?=e(site_ui('footer.news'))?></a></li><li><a href="<?=e(site_public_url('/#contact'))?>"><?=e(site_ui('footer.consult'))?></a></li></ul></div>
 </div>
 <div class="itx7-footer-bottom"><p>itxtrade © <?=e($globalFooter['copyright_year'])?>. <?=e($globalFooter['copyright'])?></p><div class="itx7-social"><a href="<?=e($globalFooter['twitter'])?>" aria-label="X">X</a><a href="<?=e($globalFooter['linkedin'])?>" aria-label="LinkedIn">in</a><a href="<?=e($globalFooter['instagram'])?>" aria-label="Instagram">◎</a></div></div>
</div></footer>
<button class="back-to-top" id="backToTop" type="button" aria-label="<?=e(site_ui('common.back_top'))?>">
 <i class="fa-solid fa-arrow-up"></i>
</button>

<script src="<?=url('assets/js/itx-trade.js?v=8.1.0')?>"></script>
</body>
</html>
