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

?>

<!-- FOOTER -->
<footer class="site-footer">
    <div class="footer-inner">
        <?php $widget_num = absint(get_theme_mod( 'shop_zen_footer_widgets', '5' )); ?>
        <div class="footer-grid footer-cols-<?php echo esc_attr( $widget_num ); ?>">
            <!-- Footer Widget Columns -->
            <?php
            for ( $i = 1; $i <= $widget_num; $i++ ) :
                if ( is_active_sidebar( 'footer-' . $i ) ) :
            ?>
            <div class="footer-col<?php echo ( $i === 1 ) ? ' footer-brand-col' : ''; ?>">
                <?php dynamic_sidebar( 'footer-' . $i ); ?>
            </div>
            <?php endif; ?>
            <?php endfor; ?>
        </div>

        <!-- Footer Bottom -->
        <div class="footer-bottom">
            <span class="footer-copyright">
                <?php
                $footer_text = get_theme_mod( 'shop_zen_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.', 'shop-zen' );
                endif;
                if ( apply_filters( 'shop_zen_show_footer_credit', true ) ) :
                ?>
                <span class="footer-credit">
                    <?php
                    printf(
                        __( ' | Theme by %s', 'shop-zen' ),
                        '<a href="' . esc_url( 'https://spiraclethemes.com/' ) . '" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Spiracle Themes', 'shop-zen' ) . '</a>'
                    );
                    ?>
                </span>
                <?php endif; ?>
            </span>
            <div class="footer-bottom-right">
                <div class="footer-bottom-links">
                    <?php
                    $privacy_url = get_theme_mod( 'shop_zen_footer_privacy_policy_url', '' );
                    $cookie_url  = get_theme_mod( 'shop_zen_footer_cookie_policy_url', '' );
                    $terms_url   = get_theme_mod( 'shop_zen_footer_terms_url', '' );

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

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

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

                <?php
                $secure_checkout_enable = get_theme_mod( 'shop_zen_footer_secure_checkout_enable', false );
                $free_returns_enable    = get_theme_mod( 'shop_zen_footer_free_returns_enable', false );
                $carbon_neutral_enable  = get_theme_mod( 'shop_zen_footer_carbon_neutral_enable', false );

                if ( $secure_checkout_enable || $free_returns_enable || $carbon_neutral_enable ) :
                    $show_icons           = get_theme_mod( 'shop_zen_footer_trust_badges_icons', false );
                    $secure_checkout_text = get_theme_mod( 'shop_zen_footer_secure_checkout_text', __( 'Secure Checkout', 'shop-zen' ) );
                    $free_returns_text    = get_theme_mod( 'shop_zen_footer_free_returns_text', __( 'Free Returns', 'shop-zen' ) );
                    $carbon_neutral_text  = get_theme_mod( 'shop_zen_footer_carbon_neutral_text', __( 'Carbon Neutral', 'shop-zen' ) );
                ?>
                <div class="footer-trust-badges" aria-label="<?php esc_attr_e( 'Store guarantees', 'shop-zen' ); ?>">
                    <?php if ( $secure_checkout_enable ) : ?>
                    <span class="trust-badge">
                        <?php if ( $show_icons ) : ?>
                        <svg width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M12 2l8 4v5c0 5-3.5 9-8 11-4.5-2-8-6-8-11V6l8-4z"/></svg>
                        <?php endif; ?>
                        <?php echo esc_html( $secure_checkout_text ); ?>
                    </span>
                    <?php endif; ?>
                    <?php if ( $free_returns_enable ) : ?>
                    <span class="trust-badge">
                        <?php if ( $show_icons ) : ?>
                        <svg width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M9 12l2 2 4-4"/><circle cx="12" cy="12" r="10"/></svg>
                        <?php endif; ?>
                        <?php echo esc_html( $free_returns_text ); ?>
                    </span>
                    <?php endif; ?>
                    <?php if ( $carbon_neutral_enable ) : ?>
                    <span class="trust-badge">
                        <?php if ( $show_icons ) : ?>
                        <svg width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M7 20c3-5 5-7 10-9 -2 4-3 7-5 9M12 4c-4 3-6 7-5 12 3-2 6-4 8-8 -1 5-2 8-3 10"/></svg>
                        <?php endif; ?>
                        <?php echo esc_html( $carbon_neutral_text ); ?>
                    </span>
                    <?php endif; ?>
                </div>
                <?php endif; ?>
            </div>
        </div>
    </div>
</footer>

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