<?php
// ========================================
// ELEMENTOR FOOTER LOCATION
// ========================================
if (!function_exists('elementor_theme_do_location') || !elementor_theme_do_location('footer')):

    // Get Footer Widget Columns
    $footer_columns = absint(get_theme_mod('paws_and_care_footer_columns', 4));

    // Calculate Bootstrap column class based on number of columns
    $column_classes = array(
        1 => 'col-12',
        2 => 'col-md-6',
        3 => 'col-md-6 col-lg-4',
        4 => 'col-md-6 col-lg-3',
    );
    $col_class = isset($column_classes[$footer_columns]) ? $column_classes[$footer_columns] : 'col-md-6 col-lg-3';

    // Get Copyright Text
    $copyright_default = '&copy; {year} {site_name}. All Rights Reserved.';
    $copyright_text = get_theme_mod('paws_and_care_copyright', $copyright_default);

    // Replace placeholders in copyright text
    $copyright_text = str_replace('{year}', date('Y'), $copyright_text);
    $copyright_text = str_replace('{site_name}', get_bloginfo('name'), $copyright_text);

    // Check if any footer widget is active
    $has_footer_widgets = false;
    for ($i = 1; $i <= $footer_columns; $i++) {
        if (is_active_sidebar('footer-' . $i)) {
            $has_footer_widgets = true;
            break;
        }
    }
    ?>

    <!-- Footer -->
    <footer>
        <div class="container">
            <?php if ($has_footer_widgets): ?>
                <div class="row g-4">
                    <?php for ($i = 1; $i <= $footer_columns; $i++): ?>
                        <?php if (is_active_sidebar('footer-' . $i)): ?>
                            <div class="<?php echo esc_attr($col_class); ?>">
                                <div class="footer-widget">
                                    <?php dynamic_sidebar('footer-' . $i); ?>
                                </div>
                            </div>
                        <?php endif; ?>
                    <?php endfor; ?>
                </div>
            <?php endif; ?>
            <div class="copyright text-center">
                <p class="mb-0">
                    <?php echo wp_kses_post($copyright_text); ?>
                </p>
            </div>
        </div>
    </footer>

    <?php
endif;
// ========================================
// ELEMENTOR FOOTER LOCATION - END
// ========================================
?>

<!-- Scroll to Top Button -->
<button class="scroll-to-top" id="scrollToTop" aria-label="<?php esc_attr_e('Scroll to top', 'paws-and-care'); ?>">
    <i class="fa-solid fa-arrow-up"></i>
</button>

</div><!-- .site-wrapper -->

<?php wp_footer(); ?>
</body>

</html>