<?php
/**
 * PW Rewards Home
 *
 * Shows the main rewards dashboard.
 *
 * This template can be overridden by copying it to yourtheme/pw-rewards/home.php.
 *
 * HOWEVER, on occasion Pimwick will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see https://woocommerce.com/document/template-structure/
 */

defined( 'ABSPATH' ) || exit;

pwlpar_heading();

do_action( 'pwlpar_before_home' );

?>
<div id="pwlpar-home">
    <div id="pwlpar-section-buttons">
        <div class="pwlpar-section-button <?php if ( $section == 'rewards' ) { echo 'pwlpar-section-button-active'; } ?>" data-section="rewards">
            <?php esc_html_e( 'Rewards', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?>
        </div>
        <div class="pwlpar-section-button <?php if ( $section == 'earn' ) { echo 'pwlpar-section-button-active'; } ?>" data-section="earn">
            <?php esc_html_e( 'Earn', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?>
        </div>
        <div class="pwlpar-section-button <?php if ( $section == 'offers' ) { echo 'pwlpar-section-button-active'; } ?>" data-section="offers">
            <?php esc_html_e( 'Claim', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?>
        </div>
    </div>

    <div class="pwlpar-section <?php if ( $section != 'rewards' ) { echo 'pwlpar-hidden'; } ?>" data-section="rewards">
        <?php
            if ( count( $rewards ) > 0 ) {
                ?>
                <div class="pwlpar-heading">
                    <?php
                        /* translators: %s: number of rewards */
                        printf( esc_html( _n( 'You have %s reward ready to use!', 'You have %s rewards ready to use!', count( $rewards ), 'pw-loyalty-points-and-rewards-for-woocommerce' ) ), esc_html( number_format_i18n( count( $rewards ) ) ) );
                    ?>
                </div>
                <div class="pwlpar-subheading">
                    <?php esc_html_e( 'You can apply rewards to your cart or save them for later.', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?>
                </div>
                <?php
                    foreach ( $rewards as $reward ) {
                        pwlpar_reward( array( 'reward' => $reward ) );
                    }
            } else {
                ?>
                <div class="pwlpar-heading">
                    <?php
                        esc_html_e( 'No rewards ready to use?', 'pw-loyalty-points-and-rewards-for-woocommerce' );
                    ?>
                </div>
                <div class="pwlpar-subheading">
                    <?php esc_html_e( "Let's fix that. Check to see if you have enough points to claim a reward.", 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?>
                </div>
                <div id="pwlpar-rewards-empty-buttons">
                    <div class="pwlpar-rewards-empty-section">
                        <img src="<?php echo esc_attr( pwlpar_earn_logo_url_default() ); ?>" class="pwlpar-rewards-empty-button-icon">
                        <div class="pwlpar-rewards-empty-text">
                            <?php esc_html_e( 'See where you can start earning', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?>
                        </div>
                        <a href="#" class="pwlpar-button pwlpar-rewards-empty-button" data-section="earn"><?php esc_html_e( 'Get started', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?></a>
                    </div>
                    <div class="pwlpar-rewards-empty-section">
                        <img src="<?php echo esc_attr( pwlpar_offer_logo_url_default() ); ?>" class="pwlpar-rewards-empty-button-icon">
                        <div class="pwlpar-rewards-empty-text">
                            <?php esc_html_e( 'Claim rewards to redeem to your cart', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?>
                        </div>
                        <a href="#" class="pwlpar-button pwlpar-rewards-empty-button" data-section="offers"><?php esc_html_e( 'Claim rewards', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?></a>
                    </div>
                </div>
                <?php
            }
        ?>
    </div>

    <div class="pwlpar-section <?php if ( $section != 'earn' ) { echo 'pwlpar-hidden'; } ?>" data-section="earn">
        <div class="pwlpar-heading">
            <?php
                esc_html_e( 'Shop more to earn points and claim rewards', 'pw-loyalty-points-and-rewards-for-woocommerce' );
            ?>
        </div>
        <div class="pwlpar-subheading">
            <?php esc_html_e( 'Start earning points and rewards by buying qualifying items or opting into hand-picked savings.', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?>
        </div>
        <div class="pwlpar-earn">
            <div class="pwlpar-earn-details">
                <div>
                    <img src="<?php echo esc_attr( pwlpar_earn_logo_url_default() ); ?>" class="pwlpar-earn-image">
                </div>
                <div class="pwlpar-earn-name">
                    <div class="pwlpar-earn-title">
                        <?php
                            echo esc_html( sprintf(
                                /* translators: %s: points */
                                __( 'Earn %s points', 'pw-loyalty-points-and-rewards-for-woocommerce' ),
                                wp_strip_all_tags( pwlpar_reward_points() ),
                            ) );
                        ?>
                    </div>
                    <div class="pwlpar-earn-description pwlpar-nl2br">
                        <?php
                            echo esc_html( sprintf(
                                /* translators: %s: currency amount */
                                __( 'For every %s you spend on your total purchase', 'pw-loyalty-points-and-rewards-for-woocommerce' ),
                                wp_strip_all_tags( wc_price( pwlpar_reward_value() ) ),
                            ) );
                        ?>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="pwlpar-section <?php if ( $section != 'offers' ) { echo 'pwlpar-hidden'; } ?>" data-section="offers">
        <?php if ( count( $offers ) == 0 ) : ?>
            <div><?php esc_html_e( 'No offers currently available. Check back later!', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?></div>
        <?php else : ?>
            <div>
                <?php
                    foreach ( $offers as $offer ) {
                        pwlpar_offer( $offer );
                    }
                ?>
            </div>

        <?php endif; ?>
    </div>
</div>
<?php

do_action( 'pwlpar_after_home' );
