<?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 shoes_footwear
 */
$shoes_footwear_scroll_top  = get_theme_mod( 'shoes_footwear_scroll_to_top', true );
$shoes_footwear_footer_background = get_theme_mod('shoes_footwear_footer_background_image');
$shoes_footwear_footer_background_url = '';
if(!empty($shoes_footwear_footer_background)){
    $shoes_footwear_footer_background = absint($shoes_footwear_footer_background);
    $shoes_footwear_footer_background_url = wp_get_attachment_url($shoes_footwear_footer_background);
}

$shoes_footwear_footer_background_color = get_theme_mod('shoes_footwear_footer_background_color', 'var(--primary-color)'); // New line

$shoes_footwear_footer_background_style = '';
if (!empty($shoes_footwear_footer_background_url)) {
    $shoes_footwear_footer_background_style = ' style="background-image: url(\'' . esc_url($shoes_footwear_footer_background_url) . '\'); background-repeat: no-repeat; background-size: cover;"';
} else {
    $shoes_footwear_footer_background_style = ' style="background-color: ' . esc_attr($shoes_footwear_footer_background_color) . ';"'; // Updated line
}
?>

</div>
</div>
</div>
</div>

<footer class="site-footer"<?php echo $shoes_footwear_footer_background_style  ?>>
    <?php if( is_active_sidebar( 'footer-one' ) || is_active_sidebar( 'footer-two' ) || is_active_sidebar( 'footer-three' ) || is_active_sidebar( 'footer-four' ) ){ ?>
        <div class="footer-t">
            <div class="container">
                <div class="row">
                    <?php 
                    if( is_active_sidebar( 'footer-one') ) {
                        echo '<div class="col-xl-3 col-lg-3 col-md-4 col-sm-6">';
                        dynamic_sidebar( 'footer-one' ); 
                        echo '</div>';
                    }
                    
                    if( is_active_sidebar( 'footer-two') ) {
                        echo '<div class="col-xl-3 col-lg-3 col-md-4 col-sm-6">';
                        dynamic_sidebar( 'footer-two' );
                        echo '</div>';
                    }
                    
                    if( is_active_sidebar( 'footer-three') ) {
                        echo '<div class="col-xl-3 col-lg-3 col-md-4 col-sm-6">';
                        dynamic_sidebar( 'footer-three' );
                        echo '</div>';
                    }
                    
                    if( is_active_sidebar( 'footer-four' ) ) {
                        echo '<div class="col-xl-3 col-lg-3 col-md-4 col-sm-6">';
                        dynamic_sidebar( 'footer-four' );
                        echo '</div>';
                    }
                    ?>
                </div>
            </div>
        </div>
    <?php } else { ?>
        <div class="footer-t">
            <div class="container">
                <div class="row">
                    <!-- Archive -->
                    <aside id="archive" class="widget widget_archive col-xl-3 col-lg-3 col-md-4 col-sm-6" role="complementary" aria-label="<?php esc_attr_e('secondsidebar', 'shoes-footwear'); ?>">
                        <h2 class="widget-title"><?php esc_html_e('Archive List', 'shoes-footwear'); ?></h2>
                        <ul>
                            <?php wp_get_archives('type=monthly'); ?>
                        </ul>
                    </aside>
                    <!-- Recent Posts -->
                    <aside id="recent-posts" class="widget widget_recent_posts col-xl-3 col-lg-3 col-md-4 col-sm-6" role="complementary" aria-label="<?php esc_attr_e('thirdsidebar', 'shoes-footwear'); ?>">
                        <h2 class="widget-title"><?php esc_html_e('Recent Posts', 'shoes-footwear'); ?></h2>
                        <ul>
                            <?php
                            $args = array(
                                'post_type'      => 'post',
                                'posts_per_page' => 5,
                            );
                            $shoes_footwear_recent_posts = new WP_Query($args);

                            while ($shoes_footwear_recent_posts->have_posts()) : $shoes_footwear_recent_posts->the_post();
                            ?>
                                <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
                            <?php endwhile; ?>
                            <?php wp_reset_postdata(); ?>
                        </ul>
                    </aside>
                    <!-- Categories -->
                    <aside id="categories" class="widget widget_categories col-xl-3 col-lg-3 col-md-4 col-sm-6" role="complementary"  aria-label="<?php esc_attr_e('fourthsidebar', 'shoes-footwear'); ?>">
                        <h2 class="widget-title"><?php esc_html_e('Categories', 'shoes-footwear'); ?></h2>
                        <ul>
                            <?php
                            $args = array(
                                'title_li' => '',
                            );
                            wp_list_categories($args);
                            ?>
                        </ul>
                    </aside>
                    <!-- Tags Widget -->
                    <aside id="tags" class="widget widget_tags col-xl-3 col-lg-3 col-md-4 col-sm-6" role="complementary" aria-label="<?php esc_attr_e('fifthsidebar', 'shoes-footwear'); ?>">
                        <h2 class="widget-title"><?php esc_html_e('Tags', 'shoes-footwear'); ?></h2>
                        <div class="tag-cloud">
                            <?php wp_tag_cloud(); ?>
                        </div>
                    </aside>
                </div>
            </div>
        </div>
    <?php } 
    do_action( 'shoes_footwear_footer' );
    ?>
    <?php if ( get_theme_mod('shoes_footwear_enable_footer_icon_section', true) ) : ?>
        <div class="footer-social-icons text-center">
            <div class="container">
                <?php if ( get_theme_mod('shoes_footwear_footer_facebook_link', 'https://www.facebook.com/') != '' ) { ?>
                    <a target="_blank" href="<?php echo esc_url(get_theme_mod('shoes_footwear_footer_facebook_link', 'https://www.facebook.com/')); ?>">
                        <i class="<?php echo esc_attr(get_theme_mod('shoes_footwear_facebook_icon', 'fa-brands fa-facebook')); ?>"></i>
                        <span class="screen-reader-text"><?php esc_html_e('Facebook', 'shoes-footwear'); ?></span>
                    </a>
                <?php } ?>
                <?php if ( get_theme_mod('shoes_footwear_footer_twitter_link', 'https://twitter.com/') != '' ) { ?>
                    <a target="_blank" href="<?php echo esc_url(get_theme_mod('shoes_footwear_footer_twitter_link', 'https://x.com/')); ?>">
                        <i class="<?php echo esc_attr(get_theme_mod('shoes_footwear_twitter_icon', 'fa-brands fa-twitter')); ?>"></i>
                        <span class="screen-reader-text"><?php esc_html_e('Twitter', 'shoes-footwear'); ?></span>
                    </a>
                <?php } ?>
                <?php if ( get_theme_mod('shoes_footwear_footer_instagram_link', 'https://www.instagram.com/') != '' ) { ?>
                    <a target="_blank" href="<?php echo esc_url(get_theme_mod('shoes_footwear_footer_instagram_link', 'https://www.instagram.com/')); ?>">
                        <i class="<?php echo esc_attr(get_theme_mod('shoes_footwear_instagram_icon', 'fa-brands fa-instagram')); ?>"></i>
                        <span class="screen-reader-text"><?php esc_html_e('Instagram', 'shoes-footwear'); ?></span>
                    </a>
                <?php } ?>
                <?php if ( get_theme_mod('shoes_footwear_footer_linkedin_link', 'https://in.linkedin.com/') != '' ) { ?>
                    <a target="_blank" href="<?php echo esc_url(get_theme_mod('shoes_footwear_footer_linkedin_link', 'https://in.linkedin.com/')); ?>">
                        <i class="<?php echo esc_attr(get_theme_mod('shoes_footwear_linkedin_icon', 'fa-brands fa-linkedin')); ?>"></i>
                        <span class="screen-reader-text"><?php esc_html_e('Linkedin', 'shoes-footwear'); ?></span>
                    </a>
                <?php } ?>
                <?php if ( get_theme_mod('shoes_footwear_footer_youtube_link', 'https://www.youtube.com/') != '' ) { ?>
                    <a target="_blank" href="<?php echo esc_url(get_theme_mod('shoes_footwear_footer_youtube_link', 'https://www.youtube.com/')); ?>">
                        <i class="<?php echo esc_attr(get_theme_mod('shoes_footwear_youtube_icon', 'fa-brands fa-youtube')); ?>"></i>
                        <span class="screen-reader-text"><?php esc_html_e('Youtube', 'shoes-footwear'); ?></span>
                    </a>
                <?php } ?>
            </div>
        </div>
    <?php endif; ?>

    <?php  
    if ( $shoes_footwear_scroll_top ){ ?>
        <a id="button"><i class="<?php echo esc_attr(get_theme_mod('shoes_footwear_scroll_icon','fas fa-arrow-up')); ?>"></i></a>
    <?php } ?>
</footer>
</div>
</div>

<?php wp_footer(); ?>

</body>
</html>