<?php
/**
 * The template for displaying the footer
 *
 * Contains the closing of the #content div and all content after.
 *
 * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
 *
 * @package wheelify
 */

?>
<style>
.w_footer {
    padding: 50px 0;
    background: #192538;
}

.widget-heading {
    padding: 30px 15px;
}

.widget-heading h1 {
    border-bottom: 2px solid #f4c201;
    display: inline-block;
    font-size: 24px;
    padding: 5px 5px 5px 0;
    color: #fff;
}

#calendar_wrap {
    padding: 10px;
}

table.table,
table {
    width: 100%;
    background-color: transparent;
    text-align: left;
}

#wp-calendar caption {
    padding: 10px;
    color: #fff;
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    background-color: #f4c201;
}

.footer-widget #wp-calendar thead tr th,
.footer-widget table td,
#wp-calendar thead tr th,
#wp-calendar tbody tr td {
    color: #fff;
    text-align: center;
}

table th,
table td {
    border: 1px solid #dddddd;
    padding: 6px;
    line-height: 20px;
    vertical-align: top;
}

.footer-widget ul {
    list-style: none;
    padding-left: 20px;
    margin: 0;
}

.footer-widget ul li {
    display: block;
}

.footer-widget ul li a,
.wp-block-latest-posts.wp-block-latest-posts__list li a {
    color: #fff;
    font-size: 16px;
}

.wp-block-latest-posts.wp-block-latest-posts__list {
    list-style: none;
}
</style>

<?php
// Check for footer areas enabled by the theme settings
$Wheelify_footer_areas = get_theme_mod('Wheelify_footer_areas', '1');
if ($Wheelify_footer_areas == '1' && (
    is_active_sidebar('footer-widget-area-1') || 
    is_active_sidebar('footer-widget-area-2') || 
    is_active_sidebar('footer-widget-area-3') || 
    is_active_sidebar('footer-widget-area-4'))) : ?>
    <!-- Footer -->
    <footer class="w_footer">
        <div class="container">
            <!-- Footer Widgets Section -->
            <div class="footer-widgets container animate fadeInDownLarge" data-anim-type="fadeInDownLarge" data-anim-delay="400">
                <div class="row">
                    <?php 
                    // Define an array with footer widget areas and titles
                    $footer_areas = [
                        'footer-widget-area-1' => __('Calendar', 'wheelify'),
                        'footer-widget-area-2' => __('Recent Posts', 'wheelify'),
                        'footer-widget-area-3' => __('Recent Comments', 'wheelify'),
                        'footer-widget-area-4' => __('Archives', 'wheelify')
                    ];

                    // Loop through the areas and display widgets
                    foreach ($footer_areas as $area => $widget_title) : ?>
                        <div class="col-lg-3 col-md-6 col-sm-12">
                            <?php 
                            if (is_active_sidebar($area)) {
                                dynamic_sidebar($area);
                            } else {
                                // Fallback widget for each area based on the footer
                                switch ($area) {
                                    case 'footer-widget-area-1':
                                        the_widget('WP_Widget_Calendar', 'title=' . $widget_title, array(
                                            'before_widget' => '<div class="footer-widget">',
                                            'after_widget' => '</div>',
                                            'before_title' => '<div class="widget-heading"><h1>',
                                            'after_title' => '</h1></div>',
                                        ));
                                        break;
                                    case 'footer-widget-area-2':
                                        the_widget('WP_Widget_Recent_Posts', 'title=' . $widget_title, array(
                                            'before_widget' => '<div class="footer-widget">',
                                            'after_widget' => '</div>',
                                            'before_title' => '<div class="widget-heading"><h1>',
                                            'after_title' => '</h1></div>',
                                        ));
                                        break;
                                    case 'footer-widget-area-3':
                                        the_widget('WP_Widget_Recent_Comments', 'title=' . $widget_title, array(
                                            'before_widget' => '<div class="footer-widget">',
                                            'after_widget' => '</div>',
                                            'before_title' => '<div class="widget-heading"><h1>',
                                            'after_title' => '</h1></div>',
                                        ));
                                        break;
                                    case 'footer-widget-area-4':
                                        the_widget('WP_Widget_Archives', 'title=' . $widget_title, array(
                                            'before_widget' => '<div class="footer-widget">',
                                            'after_widget' => '</div>',
                                            'before_title' => '<div class="widget-heading"><h1>',
                                            'after_title' => '</h1></div>',
                                        ));
                                        break;
                                }
                            }
                            ?>
                        </div>
                    <?php endforeach; ?>
                </div>
            </div>
        </div>
    </footer>
<?php endif; ?>

<!-- Copyright Section -->
<div class="row coppy-right">
    <div class="container">
        <div class="col-md-12">
            <p>
                <?php 
                // Correct usage of esc_html_e for proper escaping of translatable strings
                echo esc_html__('Proudly powered by', 'wheelify'); ?>
                <a href="<?php echo esc_url('https://wordpress.org/'); ?>" target="_blank" rel="noopener noreferrer" aria-label="Visit WordPress">
                    <?php echo esc_html__('WordPress.', 'wheelify'); ?>
                </a>
                <?php echo esc_html__('Theme by', 'wheelify'); ?>
                <a href="<?php echo esc_url('https://infigosoftware.in/'); ?>" target="_blank" rel="noopener noreferrer" aria-label="Visit Infigo Software">
                    <?php echo esc_html__('Infigo Software.', 'wheelify'); ?>
                </a>
            </p>
        </div>
    </div>
</div>
<!-- Copyright Section End -->

<!-- Return to Top Button -->
<?php if (get_theme_mod('enable_scroll', '1') == 1) : ?>
    <a href="javascript:" id="return-to-top" aria-label="Return to top">
        <i class="fas fa-arrow-alt-circle-up h4"></i>
    </a>
<?php endif; ?>

</div><!-- #page -->
<?php wp_footer(); ?>
</body>
</html>
