<?php

defined( 'ABSPATH' ) or exit;

$customer_count = pwlpara_get_customer_count();
$member_count = pwlpar_get_member_count();
$member_revenue = pwlpar_get_member_revenue();
$top_offers = pwlpar_get_top_offers();

?>
<?php pwlpara_section_opening_tag( 'dashboard' ); ?>
    <div id="pwlpara-dashboard-summary-container">
        <div class="pwlpara-summary-item">
            <div class="pwlpara-summary-item-header"><?php echo esc_html( number_format_i18n( $member_count ) ); ?></div>
            <div><?php esc_html_e( 'Members', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?></div>
        </div>
        <div class="pwlpara-summary-item">
            <div class="pwlpara-summary-item-header"><?php echo esc_html( number_format_i18n( $customer_count ) ); ?></div>
            <div><?php esc_html_e( 'Total customers', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?></div>
        </div>
        <div class="pwlpara-summary-item">
            <div class="pwlpara-summary-item-header">
                <?php
                    if ( $customer_count > 0 ) {
                        echo esc_html( number_format_i18n( ( $member_count / $customer_count ) * 100, 0, '.', '' ) ) . '%';
                    } else {
                        echo '0%';
                    }
                ?>
            </div>
            <div><?php esc_html_e( 'Enrolled percentage', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?></div>
        </div>
        <div class="pwlpara-summary-item">
            <div class="pwlpara-summary-item-header">
                <?php
                    echo wp_kses_post( wc_price( $member_revenue, array( 'decimals' => 0 ) ) );
                ?>
            </div>
            <div><?php esc_html_e( 'Member revenue', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?></div>
        </div>
    </div>
    <?php if ( !empty( $top_offers ) ): ?>
        <div>
            <div id="pwlpara-dashboard-top-offers-title">
                <?php esc_html_e( 'Most popular Offers', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?>
            </div>
            <?php
                foreach ( $top_offers as $top_offer ) {
                    $offer = $top_offer['offer'];

                    ?>
                    <div class="pwlpara-dashboard-top-offer">
                        <div>
                            <img src="<?php echo esc_attr( $offer->get_image_url() ); ?>" class="pwlpara-dashboard-top-offer-image" />
                        </div>
                        <div>
                            <div class="pwlpara-dashboard-top-offer-title">
                                <?php echo wp_kses_post( $offer->get_title() ); ?>
                            </div>
                            <div class="pwlpar-nl2br">
                                <?php echo wp_kses_post( $offer->get_description() ); ?>
                            </div>
                        </div>
                        <div class="pwlpara-dashboard-top-offer-claimed">
                            <div class="pwlpara-dashboard-top-offer-claimed-count">
                                <?php echo esc_html( number_format_i18n( $top_offer['claimed_count'] ) ); ?>
                            </div>
                            <div><?php esc_html_e( 'Claimed', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?></div>
                        </div>
                    </div>
                    <?php
                }
            ?>
        </div>
    <?php endif; ?>
</div>
<?php

do_action( 'pwlpara_after_dashboard' );
