<?php
use App\Models\Settings;
use App\Services\TranslationService;
use App\Services\CurrencyService;

$cart = (new \App\Core\Session())->getCart();
$cartCount = array_sum($cart);
?>

<!-- ═══════════════════════════════════════════════════════
     SITE FOOTER
═══════════════════════════════════════════════════════ -->
<footer class="site-footer">
    <div class="footer-body">

        <!-- Brand Column -->
        <div class="footer-col">
            <div class="footer-logo-text">
                <i class="fa fa-print" style="color:var(--orange);font-size:22px;"></i>
                EVEREST<span>BÜRO</span>
            </div>
            <p><?php echo htmlspecialchars(Settings::get('store_description', 'Bodrum\'un güvenilir büro makinaları, yazıcı ve teknik servis uzmanı.')); ?></p>
            <div style="margin-top:20px;display:flex;flex-direction:column;gap:10px;">
                <div style="display:flex;align-items:center;gap:10px;font-size:13px;color:var(--text-3);">
                    <i class="fa fa-map-marker" style="color:var(--orange);width:16px;text-align:center;"></i>
                    <?php echo htmlspecialchars(Settings::get('address', '')); ?>
                </div>
                <div style="display:flex;align-items:center;gap:10px;font-size:13px;color:var(--text-3);">
                    <i class="fa fa-phone" style="color:var(--orange);width:16px;text-align:center;"></i>
                    <?php echo htmlspecialchars(Settings::get('telephone', '')); ?>
                </div>
                <div style="display:flex;align-items:center;gap:10px;font-size:13px;color:var(--text-3);">
                    <i class="fa fa-envelope" style="color:var(--orange);width:16px;text-align:center;"></i>
                    <?php echo htmlspecialchars(Settings::get('email', '')); ?>
                </div>
            </div>
            
            <?php $socials = Settings::get('social_links', []); if (!empty($socials)): ?>
            <div style="margin-top:20px; display:flex; gap:15px;">
                <?php if (!empty($socials['facebook'])): ?><a href="<?php echo htmlspecialchars($socials['facebook']); ?>" target="_blank" style="color:var(--text-3); font-size:20px;"><i class="fa fa-facebook"></i></a><?php endif; ?>
                <?php if (!empty($socials['instagram'])): ?><a href="<?php echo htmlspecialchars($socials['instagram']); ?>" target="_blank" style="color:var(--text-3); font-size:20px;"><i class="fa fa-instagram"></i></a><?php endif; ?>
                <?php if (!empty($socials['twitter'])): ?><a href="<?php echo htmlspecialchars($socials['twitter']); ?>" target="_blank" style="color:var(--text-3); font-size:20px;"><i class="fa fa-twitter"></i></a><?php endif; ?>
                <?php if (!empty($socials['youtube'])): ?><a href="<?php echo htmlspecialchars($socials['youtube']); ?>" target="_blank" style="color:var(--text-3); font-size:20px;"><i class="fa fa-youtube"></i></a><?php endif; ?>
                <?php if (!empty($socials['linkedin'])): ?><a href="<?php echo htmlspecialchars($socials['linkedin']); ?>" target="_blank" style="color:var(--text-3); font-size:20px;"><i class="fa fa-linkedin"></i></a><?php endif; ?>
            </div>
            <?php endif; ?>
            
        </div>

        <!-- Quick Links -->
        <div class="footer-col">
            <h5>Hızlı Menü</h5>
            <ul>
                <?php 
                $quickLinks = Settings::get('footer_quick_links', []);
                if (empty($quickLinks)):
                ?>
                    <li><a href="<?php echo $baseUrl; ?>/"><?php echo TranslationService::t('home'); ?></a></li>
                    <?php foreach (\App\Models\Page::all() as $p): ?>
                    <li><a href="<?php echo $baseUrl; ?>/<?php echo htmlspecialchars($p->slug); ?>"><?php echo htmlspecialchars($p->title); ?></a></li>
                    <?php endforeach; ?>
                    <li><a href="<?php echo $baseUrl; ?>/contact">İletişim</a></li>
                <?php 
                else: 
                    foreach ($quickLinks as $link): 
                ?>
                    <li><a href="<?php echo htmlspecialchars($link['url']); ?>"><?php echo htmlspecialchars($link['name']); ?></a></li>
                <?php 
                    endforeach; 
                endif; 
                ?>
            </ul>
        </div>

        <!-- Partners -->
        <div class="footer-col">
            <h5>Çözüm Ortaklarımız</h5>
            <ul>
                <?php 
                $allBrands = Settings::get('brands', []);
                shuffle($allBrands);
                $partners = array_slice($allBrands, 0, 5);
                foreach ($partners as $partner): 
                ?>
                <li><a href="<?php echo $baseUrl; ?>/<?php echo htmlspecialchars($partner['slug']); ?>"><?php echo htmlspecialchars($partner['name']); ?></a></li>
                <?php endforeach; ?>
                <li><a href="<?php echo $baseUrl; ?>/product/manufacturer" style="font-weight:700;color:var(--primary);"><i class="fa fa-plus-circle"></i> Tüm Markalar</a></li>
            </ul>
            <div style="margin-top:20px;">
                <p style="font-size:12px;line-height:1.8;">
                    OKI, Canon, HP, Epson başta olmak üzere tüm yazıcı markalarına uzman teknik servis ve yedek parça hizmeti.
                </p>
            </div>
        </div>

    </div>

    <!-- Footer Bottom -->
    <div class="footer-bottom" style="padding-left:24px;padding-right:24px;">
        <span>&copy; <?php echo date('Y'); ?> <?php echo htmlspecialchars(Settings::get('store_name', 'Everest Büro Makinaları')); ?>. Tüm Hakları Saklıdır.</span>
        <span>Bodrum Büro &amp; Yazıcı Teknik Servisi</span>
    </div>
</footer>

<!-- ═══════════════════════════════════════════════════════
     PREMIUM MOBILE BOTTOM NAV
═══════════════════════════════════════════════════════ -->
<nav class="premium-bottom-nav">
    <div class="nav-items-container">
        <!-- Left Items -->
        <a href="<?php echo $baseUrl; ?>/teknik-destek" class="mob-nav-item <?php echo (isset($_GET['route']) && strpos($_GET['route'], 'teknik') !== false) ? 'active' : ''; ?>">
            <i class="fa fa-wrench"></i>
            <span>Servis</span>
        </a>
        <button class="mob-nav-item" onclick="focusMobileSearch()">
            <i class="fa fa-search"></i>
            <span>Arama</span>
        </button>
        
        <!-- Center FAB (Categories Menu) -->
        <div class="nav-item-center">
            <button class="nav-fab" onclick="openBottomSheet('menu-sheet')">
                <i class="fa fa-th-large"></i>
            </button>
        </div>

        <!-- Right Items -->
        <a href="<?php echo $baseUrl; ?>/cart" class="mob-nav-item <?php echo (isset($_GET['route']) && strpos($_GET['route'], 'cart') !== false) ? 'active' : ''; ?>">
            <div class="icon-wrapper">
                <i class="fa fa-shopping-bag"></i>
                <?php if ($cartCount > 0): ?>
                <span class="mob-badge"><?php echo $cartCount; ?></span>
                <?php endif; ?>
            </div>
            <span>Sepet</span>
        </a>
        <button class="mob-nav-item" onclick="openBottomSheet('settings-sheet')">
            <i class="fa fa-cog"></i>
            <span>Ayar</span>
        </button>
    </div>
</nav>

<!-- ═══════════════════════════════════════════════════════
     BOTTOM SHEETS
═══════════════════════════════════════════════════════ -->
<div class="sheet-backdrop" id="sheetBackdrop" onclick="closeAllBottomSheets()"></div>

<!-- Menu Sheet -->
<div class="bottom-sheet" id="menu-sheet">
    <div class="sheet-header">
        <h3>Kategoriler</h3>
        <button class="close-sheet" onclick="closeAllBottomSheets()"><i class="fa fa-times"></i></button>
    </div>
    <div class="sheet-body">
        <?php if (isset($categories) && !empty($categories)): ?>
            <div class="sheet-menu-grid">
                <?php foreach ($categories as $cat): ?>
                <a href="<?php echo $baseUrl; ?>/<?php echo $cat->slug; ?>" class="sheet-menu-item">
                    <i class="fa fa-folder-o"></i>
                    <span><?php echo htmlspecialchars($cat->name); ?></span>
                </a>
                <?php endforeach; ?>
            </div>
        <?php else: ?>
            <!-- Fallback if $categories is not available in footer context -->
            <button class="sheet-menu-item w-full" style="text-align:center" onclick="openDrawer(); closeAllBottomSheets();">
                Tüm Kategoriler İçin Tıklayın
            </button>
        <?php endif; ?>
    </div>
</div>

<!-- Settings Sheet -->
<div class="bottom-sheet" id="settings-sheet">
    <div class="sheet-header">
        <h3>Ayarlar</h3>
        <button class="close-sheet" onclick="closeAllBottomSheets()"><i class="fa fa-times"></i></button>
    </div>
    <div class="sheet-body settings-body">
        <!-- Theme Toggle -->
        <div class="settings-group">
            <label>Görünüm Modu</label>
            <div class="segmented-control" id="theme-control">
                <button class="seg-btn active" data-theme-val="dark"><i class="fa fa-moon-o"></i> Koyu</button>
                <button class="seg-btn" data-theme-val="light"><i class="fa fa-sun-o"></i> Açık</button>
            </div>
        </div>

        <!-- Language Selector -->
        <div class="settings-group">
            <label>Dil (Language)</label>
            <div class="segmented-control" id="lang-control" style="flex-wrap: wrap;">
                <button class="seg-btn notranslate" translate="no" data-val="tr"><img src="https://flagcdn.com/w20/tr.png" alt="TR"> TR</button>
                <button class="seg-btn notranslate" translate="no" data-val="en"><img src="https://flagcdn.com/w20/gb.png" alt="EN"> EN</button>
                <button class="seg-btn notranslate" translate="no" data-val="fr"><img src="https://flagcdn.com/w20/fr.png" alt="FR"> FR</button>
                <button class="seg-btn notranslate" translate="no" data-val="de"><img src="https://flagcdn.com/w20/de.png" alt="DE"> DE</button>
                <button class="seg-btn notranslate" translate="no" data-val="ru"><img src="https://flagcdn.com/w20/ru.png" alt="RU"> RU</button>
            </div>
        </div>

        <!-- Currency Selector -->
        <div class="settings-group">
            <label>Para Birimi</label>
            <div class="segmented-control" id="currency-control" style="flex-wrap: wrap;">
                <button class="seg-btn notranslate" translate="no" data-val="TRY">₺ TRY</button>
                <button class="seg-btn notranslate" translate="no" data-val="USD">$ USD</button>
                <button class="seg-btn notranslate" translate="no" data-val="EUR">€ EUR</button>
                <button class="seg-btn notranslate" translate="no" data-val="GBP">£ GBP</button>
                <button class="seg-btn notranslate" translate="no" data-val="RUB">₽ RUB</button>
            </div>
        </div>

        <!-- PWA Install Button -->
        <div class="settings-group" id="pwa-install-group" style="display: none; margin-top: 24px;">
            <label>Uygulama</label>
            <button class="seg-btn" id="pwa-install-btn" style="width: 100%; justify-content: center; background: linear-gradient(135deg, var(--orange), var(--orange-dark)); color: white; border: none; box-shadow: 0 4px 12px var(--orange-glow);">
                <i class="fa fa-download"></i> Uygulamayı Yükle
            </button>
        </div>
    </div>
</div>

<!-- ═══════════════════════════════════════════════════════
     PWA INSTALL BANNER
═══════════════════════════════════════════════════════ -->
<div id="pwa-install-banner" class="pwa-banner" style="display:none;">
    <div class="pwa-banner-content">
        <div class="pwa-icon-wrap">
            <img src="<?php echo $baseUrl; ?>/assets/images/logo.png" alt="App Icon">
        </div>
        <div class="pwa-text-wrap">
            <strong>Everest Büro Uygulaması</strong>
            <span>Daha hızlı erişim için ana ekrana ekleyin.</span>
        </div>
        <button id="pwa-banner-install" class="pwa-install-btn">Yükle</button>
        <button id="pwa-banner-close" class="pwa-close-btn"><i class="fa fa-times"></i></button>
    </div>
</div>

<!-- Main JS -->
<script src="<?php echo $baseUrl; ?>/assets/js/main.js"></script>
</body>
</html>
