
<?php
// $start_time = $_SERVER["REQUEST_TIME_FLOAT"] ?? microtime(true);
//  $load_time = round(microtime(true) - $start_time, 2);
 // echo "Sayfa yüklenme süresi: {$load_time} saniye";
?>
<style>
  /* Mobil alt menü */
  .aeg-mobile-nav{position:fixed;left:0;right:0;bottom:0;background:#0b1739;color:#fff;z-index:9500;border-top:1px solid rgba(255,255,255,.08)}
  .aeg-mobile-nav__list{display:flex;align-items:stretch;justify-content:space-between;gap:2px;margin:0;padding:0;list-style:none}
  .aeg-mobile-nav__item{flex:1}
  .aeg-mobile-nav__link{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;padding:10px 6px;color:#fff;text-decoration:none;font-size:12px;line-height:1.1}
  .aeg-mobile-nav__icon{font-family:'Material Symbols Rounded';font-size:22px;line-height:1;display:inline-flex;align-items:center;justify-content:center}
  @media (min-width: 992px){.aeg-mobile-nav{display:none}}
  body{padding-bottom:68px}
  @media (min-width: 992px){body{padding-bottom:0}}
</style>

<?php 
  // WhatsApp linkini ayarlardan türet (whatsapp > phone fallback)
  $__lang = m_get_session('editor_lang');
  $__whatsapp = (string) settings('whatsapp', $__lang);
  $__phone = (string) settings('phone', $__lang);
  $__wa = '';
  $src = $__whatsapp ?: $__phone;
  if ($src) {
    $p = preg_replace('/[^0-9]/', '', $src);
    if ($p && strlen($p) == 10) { $p = '90' . $p; }
    $__wa = $p ? ('https://wa.me/' . $p) : '';
  }
?>

<nav class="aeg-mobile-nav" aria-label="Mobil Alt Menü">
  <ul class="aeg-mobile-nav__list">
    <li class="aeg-mobile-nav__item">
      <a class="aeg-mobile-nav__link" href="<?= DOMAIN ?>" aria-label="<?= lang('mobile.nav.home') ?>">
        <span class="aeg-mobile-nav__icon">home</span>
        <span><?= lang('mobile.nav.home') ?></span>
      </a>
    </li>
    <li class="aeg-mobile-nav__item">
      <a class="aeg-mobile-nav__link" href="?modal=contact" aria-label="<?= lang('mobile.nav.demo') ?>">
        <span class="aeg-mobile-nav__icon">bolt</span>
        <span><?= lang('mobile.nav.demo') ?></span>
      </a>
    </li>
    <?php if ($__wa) : ?>
    <li class="aeg-mobile-nav__item">
      <a class="aeg-mobile-nav__link" href="<?= $__wa ?>" target="_blank" rel="noopener" aria-label="<?= lang('mobile.nav.whatsapp') ?>">
        <span class="aeg-mobile-nav__icon">chat</span>
        <span><?= lang('mobile.nav.whatsapp') ?></span>
      </a>
    </li>
    <?php endif; ?>
    <li class="aeg-mobile-nav__item">
      <a class="aeg-mobile-nav__link" href="tel:<?=settings('phone', $__lang )?>" aria-label="<?= lang('mobile.nav.contact') ?>">
        <span class="aeg-mobile-nav__icon">mail</span>
        <span><?= lang('mobile.nav.contact') ?></span>
      </a>
    </li>
  </ul>
</nav>

<script src="<?=SITE_THEME_URL?>/assets/js/jquery.plugins.min.js"></script>
<script src="<?=SITE_THEME_URL?>/assets/js/jquery.main.js"></script>
<script src="<?=SITE_THEME_URL?>/assets/js/script.js"></script>
<script src="<?=SITE_THEME_URL?>/assets/js/custom.js"></script>
<script>
  (function(){
    var modal = document.getElementById('aeg-contact-modal');
    if(!modal) return;
    function openModal(){ modal.classList.add('is-open'); document.body.classList.add('aeg-modal-open'); }
    function closeModal(){ modal.classList.remove('is-open'); document.body.classList.remove('aeg-modal-open'); }
    modal.addEventListener('click', function(e){ if(e.target.hasAttribute('data-aeg-close')) closeModal(); });
    modal.querySelectorAll('[data-aeg-close]').forEach(function(btn){ btn.addEventListener('click', closeModal); });
    window.AEGModal = { open: openModal, close: closeModal };
    // data-attribute ile tetikleme
    document.querySelectorAll('[data-aeg-open-modal]').forEach(function(trigger){
      trigger.addEventListener('click', function(ev){ ev.preventDefault(); openModal(); });
    });

    // URL ile tetikleme (live editör dostu)
    function shouldOpenFromUrl(){
      var hash = (window.location.hash || '').toLowerCase();
      var qp = new URLSearchParams(window.location.search);
      return hash === '#aeg-contact-modal' || (qp.get('modal') === 'contact');
    }

    if (shouldOpenFromUrl()) { openModal(); }
    window.addEventListener('hashchange', function(){ if (shouldOpenFromUrl()) openModal(); });

    // href ile tetikleme: #aeg-contact-modal ve ?modal=contact linklerine tıklanınca aç
    document.querySelectorAll('a[href="#aeg-contact-modal"], a[href*="modal=contact"]').forEach(function(a){
      a.addEventListener('click', function(ev){ ev.preventDefault(); openModal(); });
    });
  })();
  // Açma linki: <a href="#" data-aeg-open-modal>İletişim</a>
  // Doğrudan URL: /#aeg-contact-modal veya /?modal=contact
</script>
</body>
</html>