<?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 online_mobile_accessories
 */
$online_mobile_accessories_scroll_top  = get_theme_mod( 'online_mobile_accessories_scroll_to_top', true );
$online_mobile_accessories_footer_background = get_theme_mod('online_mobile_accessories_footer_background_image');
$online_mobile_accessories_footer_background_url = '';
if(!empty($online_mobile_accessories_footer_background)){
    $online_mobile_accessories_footer_background = absint($online_mobile_accessories_footer_background);
    $online_mobile_accessories_footer_background_url = wp_get_attachment_url($online_mobile_accessories_footer_background);
}

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

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

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

<footer class="site-footer" <?php echo $online_mobile_accessories_footer_background_style; ?>>

    <?php 
    $online_mobile_accessories_active_areas = absint(get_theme_mod('online_mobile_accessories_footer_widget_areas', 4));

    if (
        is_active_sidebar('footer-1') ||
        is_active_sidebar('footer-2') ||
        is_active_sidebar('footer-3') ||
        is_active_sidebar('footer-4')
    ) : 
    ?>

    <div class="footer-t">
        <div class="container">
            <div class="row wow bounceInUp center delay-1000" data-wow-duration="2s">

            <?php
            $online_mobile_accessories_col = 12 / $online_mobile_accessories_active_areas;

            for ($online_mobile_accessories_i = 1; $online_mobile_accessories_i <= $online_mobile_accessories_active_areas; $online_mobile_accessories_i++) {

                if (is_active_sidebar('footer-' . $online_mobile_accessories_i)) {
            ?>

            <div class="col-xl-<?php echo esc_attr($online_mobile_accessories_col); ?> col-lg-<?php echo esc_attr($online_mobile_accessories_col); ?> col-md-6 col-sm-6">
                <?php dynamic_sidebar('footer-' . $online_mobile_accessories_i); ?>
            </div>

            <?php } } ?>

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

    <?php else : ?>

    <!-- Default Footer Widgets -->

    <div class="footer-t">
        <div class="container">
            <div class="row wow bounceInUp center delay-1000" data-wow-duration="2s">

            <?php $online_mobile_accessories_col = 12 / $online_mobile_accessories_active_areas; ?>

            <!-- Archive -->
            <aside class="widget widget_archive col-xl-<?php echo esc_attr($online_mobile_accessories_col); ?> col-lg-<?php echo esc_attr($online_mobile_accessories_col); ?> col-md-6 col-sm-6">
                <h2 class="widget-title"><?php esc_html_e('Archive List', 'online-mobile-accessories'); ?></h2>
                <ul>
                    <?php wp_get_archives('type=monthly'); ?>
                </ul>
            </aside>

            <!-- Recent Posts -->
            <aside class="widget widget_recent_entries col-xl-<?php echo esc_attr($online_mobile_accessories_col); ?> col-lg-<?php echo esc_attr($online_mobile_accessories_col); ?> col-md-6 col-sm-6">
                <h2 class="widget-title"><?php esc_html_e('Recent Posts', 'online-mobile-accessories'); ?></h2>
                <ul>
                    <?php
                    $recent_posts = new WP_Query(array(
                        'post_type' => 'post',
                        'posts_per_page' => 5
                    ));

                    while ($recent_posts->have_posts()) : $recent_posts->the_post();
                    ?>
                        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
                    <?php endwhile; wp_reset_postdata(); ?>
                </ul>
            </aside>

            <!-- Categories -->
            <aside class="widget widget_categories col-xl-<?php echo esc_attr($online_mobile_accessories_col); ?> col-lg-<?php echo esc_attr($online_mobile_accessories_col); ?> col-md-6 col-sm-6">
                <h2 class="widget-title"><?php esc_html_e('Categories', 'online-mobile-accessories'); ?></h2>
                <ul>
                    <?php wp_list_categories(array('title_li' => '')); ?>
                </ul>
            </aside>

            <!-- Tags -->
            <aside class="widget widget_tag_cloud col-xl-<?php echo esc_attr($online_mobile_accessories_col); ?> col-lg-<?php echo esc_attr($online_mobile_accessories_col); ?> col-md-6 col-sm-6">
                <h2 class="widget-title"><?php esc_html_e('Tags', 'online-mobile-accessories'); ?></h2>
                <div class="tagcloud">
                    <?php wp_tag_cloud(); ?>
                </div>
            </aside>

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

    <?php endif; ?>


    <?php do_action('online_mobile_accessories_footer'); ?>

    <?php if ( get_theme_mod('online_mobile_accessories_enable_footer_icon_section', true) ) : ?>
        <div class="footer-social-icons text-center">
            <div class="container">
                <?php if ( get_theme_mod('online_mobile_accessories_footer_facebook_link', 'https://www.facebook.com/') != '' ) { ?>
                    <a target="_blank" href="<?php echo esc_url(get_theme_mod('online_mobile_accessories_footer_facebook_link', 'https://www.facebook.com/')); ?>">
                        <i class="<?php echo esc_attr(get_theme_mod('online_mobile_accessories_facebook_icon', 'fa-brands fa-facebook')); ?>"></i>
                        <span class="screen-reader-text"><?php esc_html_e('Facebook', 'online-mobile-accessories'); ?></span>
                    </a>
                <?php } ?>
                <?php if ( get_theme_mod('online_mobile_accessories_footer_twitter_link', 'https://twitter.com/') != '' ) { ?>
                    <a target="_blank" href="<?php echo esc_url(get_theme_mod('online_mobile_accessories_footer_twitter_link', 'https://x.com/')); ?>">
                        <i class="<?php echo esc_attr(get_theme_mod('online_mobile_accessories_twitter_icon', 'fa-brands fa-twitter')); ?>"></i>
                        <span class="screen-reader-text"><?php esc_html_e('Twitter', 'online-mobile-accessories'); ?></span>
                    </a>
                <?php } ?>
                <?php if ( get_theme_mod('online_mobile_accessories_footer_instagram_link', 'https://www.instagram.com/') != '' ) { ?>
                    <a target="_blank" href="<?php echo esc_url(get_theme_mod('online_mobile_accessories_footer_instagram_link', 'https://www.instagram.com/')); ?>">
                        <i class="<?php echo esc_attr(get_theme_mod('online_mobile_accessories_instagram_icon', 'fa-brands fa-instagram')); ?>"></i>
                        <span class="screen-reader-text"><?php esc_html_e('Instagram', 'online-mobile-accessories'); ?></span>
                    </a>
                <?php } ?>
                <?php if ( get_theme_mod('online_mobile_accessories_footer_linkedin_link', 'https://in.linkedin.com/') != '' ) { ?>
                    <a target="_blank" href="<?php echo esc_url(get_theme_mod('online_mobile_accessories_footer_linkedin_link', 'https://in.linkedin.com/')); ?>">
                        <i class="<?php echo esc_attr(get_theme_mod('online_mobile_accessories_linkedin_icon', 'fa-brands fa-linkedin')); ?>"></i>
                        <span class="screen-reader-text"><?php esc_html_e('Linkedin', 'online-mobile-accessories'); ?></span>
                    </a>
                <?php } ?>
                <?php if ( get_theme_mod('online_mobile_accessories_footer_youtube_link', 'https://www.youtube.com/') != '' ) { ?>
                    <a target="_blank" href="<?php echo esc_url(get_theme_mod('online_mobile_accessories_footer_youtube_link', 'https://www.youtube.com/')); ?>">
                        <i class="<?php echo esc_attr(get_theme_mod('online_mobile_accessories_youtube_icon', 'fa-brands fa-youtube')); ?>"></i>
                        <span class="screen-reader-text"><?php esc_html_e('Youtube', 'online-mobile-accessories'); ?></span>
                    </a>
                <?php } ?>
            </div>
        </div>
    <?php endif; ?>

    <?php if (get_theme_mod('online_mobile_accessories_scroll_top', true)) : ?>

    <a id="button">
        <i class="<?php echo esc_attr(get_theme_mod('online_mobile_accessories_scroll_icon', 'fas fa-arrow-up')); ?>"></i>
    </a>

    <?php endif; ?>

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

<?php wp_footer(); ?>

</body>
</html>