<?php
/**
 * The template for displaying the footer.
 *
 *
 * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
 *
 * @package shopbar
 */

?>

<!-- FOOTER -->
<footer class="site-footer">
    <div class="footer-inner sb-footer-grid <?php echo is_active_sidebar( 'footer-5' ) ? 'sb-footer-cols-5' : 'sb-footer-cols-4'; ?>">

        <!-- Brand / About -->
        <div class="footer-col sb-footer-brand">
            <?php if ( is_active_sidebar( 'footer-1' ) ) : ?>
                <?php dynamic_sidebar( 'footer-1' ); ?>
            <?php else : ?>
                <a href="<?php echo esc_url( home_url( '/' ) ); ?>" class="footer-logo">
                    <?php if ( has_custom_logo() ) : ?>
                        <?php
                        $shopbar_footer_logo_id = get_theme_mod( 'custom_logo' );
                        $shopbar_footer_logo_img = wp_get_attachment_image_url( $shopbar_footer_logo_id, 'full' );
                        if ( $shopbar_footer_logo_img ) :
                        ?>
                            <img src="<?php echo esc_url( $shopbar_footer_logo_img ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>" class="footer-logo-img">
                        <?php endif; ?>
                    <?php else : ?>
                        <span class="footer-logo-icon"><?php shopbar_icon( 'bag', 22 ); ?></span>
                        <span class="footer-logo-name"><?php echo esc_html( get_bloginfo( 'name' ) ); ?></span>
                    <?php endif; ?>
                </a>
                <p class="footer-about-text">
                    <?php
                    $shopbar_footer_desc = get_theme_mod( 'shopbar_footer_about_text' );
                    if ( ! empty( $shopbar_footer_desc ) ) {
                        echo esc_html( $shopbar_footer_desc );
                    } else {
                        esc_html_e( 'Your one-stop shop for top quality products at the best prices. Smart choices, fast delivery, happy you.', 'shopbar' );
                    }
                    ?>
                </p>
                <div class="footer-social">
                    <a href="#" class="sb-social-icon" aria-label="<?php esc_attr_e( 'Facebook', 'shopbar' ); ?>"><?php shopbar_icon( 'facebook', 16 ); ?></a>
                    <a href="#" class="sb-social-icon" aria-label="<?php esc_attr_e( 'Instagram', 'shopbar' ); ?>"><?php shopbar_icon( 'instagram', 16 ); ?></a>
                    <a href="#" class="sb-social-icon" aria-label="<?php esc_attr_e( 'X (Twitter)', 'shopbar' ); ?>"><?php shopbar_icon( 'twitter', 16 ); ?></a>
                    <a href="#" class="sb-social-icon" aria-label="<?php esc_attr_e( 'YouTube', 'shopbar' ); ?>"><?php shopbar_icon( 'youtube', 16 ); ?></a>
                    <a href="#" class="sb-social-icon" aria-label="<?php esc_attr_e( 'Pinterest', 'shopbar' ); ?>"><?php shopbar_icon( 'pinterest', 16 ); ?></a>
                </div>
            <?php endif; ?>
        </div>

        <!-- Shop Links -->
        <div class="footer-col sb-footer-links">
            <?php if ( is_active_sidebar( 'footer-2' ) ) : ?>
                <?php dynamic_sidebar( 'footer-2' ); ?>
            <?php else : ?>
                <h4 class="sb-footer-title"><?php esc_html_e( 'Shop', 'shopbar' ); ?></h4>
                <?php
                wp_nav_menu( array(
                    'theme_location'  => 'footer-shop',
                    'container'       => false,
                    'menu_class'      => 'sb-footer-menu',
                    'depth'           => 1,
                    'fallback_cb'     => 'shopbar_footer_menu_fallback',
                ) );
                ?>
            <?php endif; ?>
        </div>

        <!-- Customer Service Links -->
        <div class="footer-col sb-footer-links">
            <?php if ( is_active_sidebar( 'footer-3' ) ) : ?>
                <?php dynamic_sidebar( 'footer-3' ); ?>
            <?php else : ?>
                <h4 class="sb-footer-title"><?php esc_html_e( 'Customer Service', 'shopbar' ); ?></h4>
                <?php
                wp_nav_menu( array(
                    'theme_location'  => 'footer-service',
                    'container'       => false,
                    'menu_class'      => 'sb-footer-menu',
                    'depth'           => 1,
                    'fallback_cb'     => 'shopbar_footer_menu_fallback',
                ) );
                ?>
            <?php endif; ?>
        </div>

        <!-- About Links -->
        <div class="footer-col sb-footer-links">
            <?php if ( is_active_sidebar( 'footer-4' ) ) : ?>
                <?php dynamic_sidebar( 'footer-4' ); ?>
            <?php else : ?>
                <h4 class="sb-footer-title"><?php esc_html_e( 'About Us', 'shopbar' ); ?></h4>
                <?php
                wp_nav_menu( array(
                    'theme_location'  => 'footer-about',
                    'container'       => false,
                    'menu_class'      => 'sb-footer-menu',
                    'depth'           => 1,
                    'fallback_cb'     => 'shopbar_footer_menu_fallback',
                ) );
                ?>
            <?php endif; ?>
        </div>

        <!-- Newsletter -->
        <?php if ( is_active_sidebar( 'footer-5' ) ) : ?>
        <div class="footer-col sb-footer-newsletter">
            <?php dynamic_sidebar( 'footer-5' ); ?>
        </div>
        <?php endif; ?>

        <!-- Footer Bottom -->
        <div class="sb-footer-bottom">
            <span class="footer-copyright">
                <?php
                $footer_text = get_theme_mod( 'shopbar_footer_copyright_text', '' );
                if ( ! empty( $footer_text ) ) :
                    echo esc_html( $footer_text );
                else :
                    echo '&copy; ' . esc_html( date( 'Y' ) ) . ' ' . esc_html( get_bloginfo( 'name' ) );
                    esc_html_e( '. All Rights Reserved.', 'shopbar' );
                endif;
                if ( apply_filters( 'shopbar_show_footer_credit', true ) ) :
                ?>
                <span class="footer-credit">
                    <?php
                    printf(
                        __( ' | Theme by %s', 'shopbar' ),
                        '<a href="' . esc_url( 'https://spiraclethemes.com/' ) . '" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Spiracle Themes', 'shopbar' ) . '</a>'
                    );
                    ?>
                </span>
                <?php endif; ?>
            </span>
            <div class="footer-bottom-links">
                <?php
                $privacy_url = get_theme_mod( 'shopbar_footer_privacy_policy_url', '' );
                $cookie_url  = get_theme_mod( 'shopbar_footer_cookie_policy_url', '' );
                $terms_url   = get_theme_mod( 'shopbar_footer_terms_url', '' );

                if ( ! empty( $privacy_url ) ) :
                ?>
                    <a href="<?php echo esc_url( $privacy_url ); ?>"><?php esc_html_e( 'Privacy Policy', 'shopbar' ); ?></a>
                <?php endif; ?>

                <?php if ( ! empty( $cookie_url ) ) : ?>
                    <a href="<?php echo esc_url( $cookie_url ); ?>"><?php esc_html_e( 'Cookie Policy', 'shopbar' ); ?></a>
                <?php endif; ?>

                <?php if ( ! empty( $terms_url ) ) : ?>
                    <a href="<?php echo esc_url( $terms_url ); ?>"><?php esc_html_e( 'Terms &amp; Conditions', 'shopbar' ); ?></a>
                <?php endif; ?>
            </div>
        </div>
    </div>
</footer>

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