<?php
/**
 * footer.php - Displaying dynamic content from footer_settings table
 * Matches the structure of admin_footer_settings.php
 */

require_once('db_config.php');

// ডাটাবেস থেকে ফুটার সেটিংস নিয়ে আসা
$footer_query = mysqli_query($conn, "SELECT * FROM footer_settings WHERE id = 1");
$footer_data = mysqli_fetch_assoc($footer_query);

// JSON ডাটা ডিকোড করা
$social_links = json_decode($footer_data['social_links'] ?? '[]', true) ?: [];
$services_links = json_decode($footer_data['services_links'] ?? '[]', true) ?: [];
$quick_links = json_decode($footer_data['quick_links'] ?? '[]', true) ?: [];
$contact_info = json_decode($footer_data['phone'] ?? '[]', true) ?: [];

// কলাম টাইটেলসমূহ (ডিফল্ট ভ্যালুসহ)
$col1_title = $footer_data['col1_title'] ?: "আমাদের সম্পর্কে";
$col2_title = $footer_data['col2_title'] ?: "আমাদের সেবা";
$col3_title = $footer_data['col3_title'] ?: "গুরুত্বপূর্ণ লিঙ্ক";
$col4_title = $footer_data['col4_title'] ?: "যোগাযোগ করুন";
?>
<style>
    /* Global Glassmorphism Styles */
    .footer-col {
        background: rgba(255, 255, 255, 0.03);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.07);
        border-radius: 20px;
        padding: 6px 10px;
        transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    }

    .footer-col:hover {
        background: rgba(255, 255, 255, 0.06);
        transform: translateY(-8px);
        border-color: rgba(49, 130, 206, 0.4);
        box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3);
    }

    .footer-col h4 {
        color: #fff;
        margin-bottom: 5px;
        font-size: 1.25rem;
        border-bottom: 2px solid #3182ce;
        display: inline-block;
        padding-bottom: 5px;
        border-radius: 0 0 20px 20px;
        padding: 0px 10px 0px 10px;
        transition: all 0.3s ease;
    }

    .footer-col:hover h4 {
        letter-spacing: 1px;
        padding-left: 15px;
        padding-right: 15px;
    }

    /* Hover Effects for Links */
    .footer-col ul li a {
        display: inline-block;
        transition: all 0.3s ease;
    }

    .footer-col ul li a:hover {
        color: #63b3ed !important;
        transform: translateX(8px);
    }

    /* Social Icons Animation */
    .social-icons a {
        transition: all 0.4s ease;
        border: 1px solid rgba(255, 255, 255, 0.1);
    }

    .social-icons a:hover {
        background: #3182ce !important;
        transform: rotate(360deg) scale(1.2);
        box-shadow: 0 0 15px rgba(49, 130, 206, 0.6);
    }

    /* Newsletter Styles */
    .newsletter-form {
        margin-top: 10px;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    .newsletter-form input {
        background: rgba(255, 255, 255, 0.1);
        border: 1px solid rgba(255, 255, 255, 0.2);
        padding: 8px 12px;
        border-radius: 8px;
        color: #fff;
        outline: none;
    }
    .newsletter-form button {
        background: var(--primary-color);
        color: white;
        border: none;
        padding: 8px;
        border-radius: 8px;
        cursor: pointer;
        transition: 0.3s;
    }
    .newsletter-form button:hover {
        background: var(--secondary-color);
    }
</style>
<!-- Premium Symmetric Curve Shape Divider -->
<div class="footer-shape" style="background: transparent; height: 120px; overflow: hidden; line-height: 0; margin-bottom: -1px; width: 100%;">
    <svg viewBox="0 0 1000 100" preserveAspectRatio="none" style="height: 100%; width: 100%;">
        <!-- Background Layer (Semi-transparent) -->
        <path d="M0,100 C150,0 350,0 500,100 C650,0 850,0 1000,100 L1000,100 L0,100 Z" style="stroke: none; fill: var(--secondary-color); opacity: 0.4;"></path>
        <!-- Foreground Main Layer (Solid) -->
        <path d="M0,100 C250,0 750,0 1000,100 L1000,100 L0,100 Z" style="stroke: none; fill: #1a202c;"></path>
    </svg>
</div>

<footer class="footer-area" style="background-color: #1a202c; color: #e2e8f0; margin-top: -50px; padding: 30px 0 20px; font-family: 'SolaimanLipi', sans-serif; position: relative;">
    
    <!-- Subtle Gradient Glow -->
    <div style="position: absolute; top: 0; left: 10%; width: 80%; height: 1px; background: linear-gradient(90deg, transparent, #3182ce, transparent); opacity: 0.3;"></div>

    <div class="container" style="max-width: 1400px; margin: 0 auto; padding: 0 15px;">
        <div class="footer-row" style="display: flex; flex-wrap: wrap; gap: 20px; justify-content: space-between;">
            
            <!-- Column 1: About & Social -->
            <div class="footer-col" style="flex: 1; min-width: 260px; display: flex; flex-direction: column; align-items: center;">
                <h4>
                    <?php echo htmlspecialchars($col1_title); ?>
                </h4>
                
                <!-- Footer Logo - Centered -->
                <?php if(!empty($footer_data['logo_url'])): ?>
                <div class="footer-logo" style="margin: 5px 0; display: flex; justify-content: center; width: 100%;">
                    <img src="<?php echo htmlspecialchars($footer_data['logo_url']); ?>" alt="Logo" style="max-height: 60px; width: auto; filter: /** drop-shadow(0 0 5px rgba(255,255,255,0.2));**/">
                </div>
                <?php endif; ?>

                <p style="line-height: 1.6; margin-bottom: 10px; text-align: justify;">
                    <?php echo nl2br(htmlspecialchars($footer_data['about_text'])); ?>
                </p>
                <div class="social-icons" style="display: flex; gap: 12px; justify-content: center;">
                    <?php foreach($social_links as $social): ?>
                        <a href="<?php echo htmlspecialchars($social['link']); ?>" target="_blank" title="<?php echo htmlspecialchars($social['name']); ?>" 
                           style="background: rgba(255,255,255,0.05); color: #fff; width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; border-radius: 50%; text-decoration: none;">
                            <i class="<?php echo htmlspecialchars($social['icon']); ?>"></i>
                        </a>
                    <?php endforeach; ?>
                </div>
            </div>

            <!-- Column 2: Services -->
            <div class="footer-col" style="flex: 1; max-width: 200px;">
                <h4>
                    <?php echo htmlspecialchars($col2_title); ?>
                </h4>
                <ul style="text-align: left; list-style: none; padding: 0; margin: 0;">
                    <?php foreach($services_links as $service): ?>
                        <li style="margin-bottom: 10px;">
                            <a href="<?php echo htmlspecialchars($service['link']); ?>" style="color: #cbd5e0; text-decoration: none;">
                                <i class="fas fa-chevron-right" style="font-size: 10px; margin-right: 8px; color: #3182ce;"></i>
                                <?php echo htmlspecialchars($service['name']); ?>
                            </a>
                        </li>
                    <?php endforeach; ?>
                </ul>
            </div>

            <!-- Column 3: Quick Links -->
            <div class="footer-col" style="flex: 1; max-width: 200px;">
                <h4>
                    <?php echo htmlspecialchars($col3_title); ?>
                </h4>
                <ul style="list-style: none; padding: 0; margin: 0; text-align: left;">
                    <?php foreach($quick_links as $quick): ?>
                        <li style="margin-bottom: 10px;">
                            <a href="<?php echo htmlspecialchars($quick['link']); ?>" style="color: #cbd5e0; text-decoration: none;">
                                <i class="fas fa-chevron-right" style="font-size: 10px; margin-right: 8px; color: #3182ce;"></i>
                                <?php echo htmlspecialchars($quick['name']); ?>
                            </a>
                        </li>
                    <?php endforeach; ?>
                </ul>
            </div>

            <!-- Column 4: Multi-Contact Info & Newsletter -->
            <div class="footer-col" style="flex: 1; min-width: 260px;">
                <h4>
                    <?php echo htmlspecialchars($col4_title); ?>
                </h4>
                
                <?php foreach($contact_info as $office): ?>
                <div class="office-block" style="margin-bottom: 10px; text-align: left;">
                    <p style="color: #fff; font-weight: bold; margin-bottom: 5px; font-size: 0.95rem;">
                        <i class="fas fa-building" style="color: #3182ce; margin-right: 5px;"></i> 
                        <?php echo htmlspecialchars($office['label']); ?>
                    </p>
                    <p style="font-size: 14px; margin-bottom: 8px; color: #a0aec0;">
                        <?php echo htmlspecialchars($office['address']); ?>
                    </p>
                    <div class="contacts" style="font-size: 14px;">
                        <?php foreach($office['details'] as $item): ?>
                            <div style="margin-bottom: 4px;">
                                <a href="<?php echo htmlspecialchars($item['link']); ?>" style="color: #cbd5e0; text-decoration: none; transition: 0.3s;" onmouseover="this.style.color='#fff'" onmouseout="this.style.color='#cbd5e0'">
                                    <i class="<?php echo htmlspecialchars($item['type']); ?>" style="color: #3182ce; width: 18px;"></i>
                                    <?php echo htmlspecialchars($item['value']); ?>
                                </a>
                            </div>
                        <?php endforeach; ?>
                    </div>
                </div>
                <?php endforeach; ?>

                <!-- Newsletter Option (Integrated into Contact Column) -->
                <?php if(isset($footer_data['newsletter_enable']) && $footer_data['newsletter_enable'] == 1): ?>
                <div class="newsletter-section" style="margin-top: 10px; padding-top: 5px; border-top: 1px solid rgba(255,255,255,0.1);">
                    <p style="color: #fff; font-weight: bold; margin-bottom: 5px; font-size: 0.95rem;">
                        <i class="fas fa-paper-plane" style="color: #3182ce; margin-right: 5px;"></i> নিউজলেটার
                    </p>
                    <p style="font-size: 13px; color: #a0aec0; margin-bottom: 5px; line-height: 1.4;">
                        <?php echo nl2br(htmlspecialchars($footer_data['newsletter_text'] ?? 'আমাদের সর্বশেষ আপডেট পেতে সাবস্ক্রাইব করুন।')); ?>
                    </p>
                    <form class="newsletter-form">
                        <input type="email" placeholder="আপনার ইমেইল দিন..." required>
                        <button type="submit">সাবস্ক্রাইব করুন</button>
                    </form>
                </div>
                <?php endif; ?>
            </div>

        </div>

        <!-- Copyright Area -->
        <div class="footer-bottom" style="margin-top: 30px; padding-top: 20px; border-top: 1px solid rgba(255,255,255,0.05); text-align: center; font-size: 16px;">
            <div class="footer-copyright">
                <?php echo $footer_data['copyright_text']; ?>
            </div>
            <div class="developer-credit" style="margin-top: 5px; color: #718096;">
                Developed by: <a href="<?php echo htmlspecialchars($footer_data['dev_url']); ?>" style="color: #3182ce; text-decoration: none; font-weight: bold;">
                    <?php echo $footer_data['dev_text']; ?>
                </a>
            </div>
        </div>
    </div>
</footer>

<style>
    @media (max-width: 991px) {
        .footer-col { flex: 1 1 45%; }
    }
    
    @media (max-width: 768px) {
        .footer-row { flex-direction: column; }
        .footer-col { text-align: center; flex: 1 1 100%; }
        .footer-col h4 { border-bottom: none; }
        .footer-col h4::after { content: ''; display: block; width: 50px; height: 2px; background: #3182ce; margin: 10px auto; }
        .social-icons { justify-content: center; }
        .newsletter-form { max-width: 300px; margin: 15px auto 0; }
        .footer-logo { text-align: center !important; }
    }
</style>
<!-- Floating WhatsApp Chat Button -->
<a href="https://wa.me/+8801900000000" target="_blank" style="position: fixed; bottom: 220px; right: 30px; background-color: #25d366; color: white; width: 60px; height: 60px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 30px; box-shadow: 0 4px 10px rgba(0,0,0,0.3); z-index: 1000; text-decoration: none; transition: 0.3s;" onmouseover="this.style.transform='scale(1.1)'" onmouseout="this.style.transform='scale(1)'">
    <i class="fab fa-whatsapp"></i>
</a>

<!--Start of Tawk.to Script-->
<script type="text/javascript">
var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
(function(){
var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
s1.async=true;
s1.src='https://embed.tawk.to/69e19b2ef337951c3c3cd4e7/1jmckccah';
s1.charset='UTF-8';
s1.setAttribute('crossorigin','*');
s0.parentNode.insertBefore(s1,s0);
})();
</script>
<!--End of Tawk.to Script-->