<?php
use App\Core\Lang;
use App\Models\Page;
use function App\Core\{e, logo_asset, site_setting, url};

$logoAsset = logo_asset('main');
$footerDescription = (string) site_setting('footer_description', site_setting('site_description', 'Modlar, muzikler ve creator abonelikleri icin saf PHP ile gelisen Zalorox platformu.'));
$footerCopyright = (string) site_setting('footer_copyright', 'Zalorox Network');
$socialLinks = [
    'X' => (string) site_setting('social_x', ''),
    'YT' => (string) site_setting('social_youtube', ''),
    'IG' => (string) site_setting('social_instagram', ''),
    'DC' => (string) site_setting('social_discord', ''),
];
$footerPages = [];
try {
    $footerPages = (new Page())->footerLinks(Lang::current(), 10);
} catch (Throwable) {
    $footerPages = [
        ['title' => 'Gizlilik Politikasi', 'slug' => 'gizlilik-politikasi'],
        ['title' => 'Hakkimizda', 'slug' => 'hakkimizda'],
        ['title' => 'Kullanim Sartlari', 'slug' => 'kullanim-sartlari'],
        ['title' => 'Cerez Politikasi', 'slug' => 'cerez-politikasi'],
    ];
}
?>
<footer class="site-footer">
    <div class="container footer-grid">
        <div class="footer-brand">
            <a class="brand <?= $logoAsset ? 'has-logo' : 'has-fallback' ?>" href="<?= url('/') ?>">
                <?php if ($logoAsset): ?>
                    <img src="<?= url($logoAsset) ?>" alt="Zalorox" loading="eager" class="footer-logo">
                <?php else: ?>
                    <span class="brand-text">Zalorox</span>
                <?php endif; ?>
            </a>
            <p><?= e($footerDescription) ?></p>
            <small>&copy; <?= date('Y') ?> <?= e($footerCopyright) ?></small>
        </div>
        <div class="footer-links">
            <h4>Sayfalar</h4>
            <?php foreach ($footerPages as $footerPage): ?>
                <a href="<?= url('/sayfa/' . $footerPage['slug']) ?>"><?= \App\Core\e($footerPage['title']) ?></a>
            <?php endforeach; ?>
        </div>
        <div class="footer-links">
            <h4>Ag</h4>
            <a href="<?= url('/music') ?>">Music</a>
            <a href="<?= url('/studyo') ?>">Studio</a>
            <a href="<?= url('/zpanel') ?>">ZPanel</a>
            <div class="social-links" aria-label="Sosyal linkler">
                <?php foreach ($socialLinks as $label => $href): ?>
                    <?php if ($href !== ''): ?><a href="<?= e($href) ?>" target="_blank" rel="noopener noreferrer" aria-label="<?= e($label) ?>"><?= e($label) ?></a><?php endif; ?>
                <?php endforeach; ?>
            </div>
            <?php require BASE_PATH . '/app/Views/partials/language-switcher.php'; ?>
        </div>
    </div>
</footer>
