<?php

defined( 'ABSPATH' ) or exit;

$offers = pwlpar_get_offers( array(
    'status__not_in' => array( 'trash' ),
    'active' => 'any'
) );

if ( empty( $offers ) ) {
    return;
}

?>
<table id="pwlpara-offers-table" class="pwlpara-table">
    <thead>
        <tr>
            <th><?php esc_html_e( 'Status', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?></th>
            <th><?php esc_html_e( 'Offer name', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?></th>
            <th><?php esc_html_e( 'Description', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?></th>
            <th><?php esc_html_e( 'Points', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?></th>
            <th><?php esc_html_e( 'Coupon', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?></th>
            <th><?php esc_html_e( 'Claimed / Redeemed', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?> <?php echo wp_kses_post( wc_help_tip( esc_html__( 'Claimed offers are pending, Redeemed offers have been used.', 'pw-loyalty-points-and-rewards-for-woocommerce' ) ) ); ?></th>
            <th><?php esc_html_e( 'Actions', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?></th>
            <th>&nbsp;</th>
        </tr>
    </thead>
    <tbody>
        <?php foreach ( $offers as $offer ) : ?>
            <tr class="pwlpar-offers-table-offer" data-id="<?php echo esc_attr( $offer->get_id() ); ?>">
                <td style="white-space: nowrap;">
                    <?php if ( $offer->is_active() ) : ?>
                        <span style="color: #00DD00;">&#9679;</span> <?php esc_html_e( 'Active', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?>
                    <?php else : ?>
                        <span style="color: #777777;">&#9679;</span> <?php esc_html_e( 'Draft', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?>
                    <?php endif; ?>
                </td>
                <td>
                    <a href="<?php echo esc_attr( $offer->get_edit_url() ); ?>"><?php echo wp_kses_post( $offer->get_title() ); ?></a>
                </td>
                <td class="pwlpara-offer-table-description pwlpar-nl2br"><?php echo wp_kses_post( $offer->get_description() ); ?></td>
                <td style="white-space: nowrap;"><?php echo esc_html( $offer->get_points() ); ?></td>
                <td>
                    <?php
                        echo esc_html( $offer->get_coupon_type() );
                        echo '<br>';
                        echo wp_kses_post( $offer->get_coupon_amount() );
                    ?>
                </td>
                <td><?php esc_html( sprintf( '%s / %s', number_format_i18n( $offer->get_claimed_count() ), number_format_i18n( $offer->get_redeemed_count() ) ) ); ?></td>
                <td style="white-space: nowrap;">
                    <a href="<?php echo esc_attr( $offer->get_edit_url() ); ?>" class="button button-primary"><?php esc_html_e( 'Edit', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?></a>
                    <a href="#" class="pwlpara-delete-offer-button button button-secondary pwlpara-button-danger"><?php esc_html_e( 'Delete', 'pw-loyalty-points-and-rewards-for-woocommerce' ); ?></a>
                </td>
                <td class="pwlpar-sort-handle"></td>
            </tr>
        <?php endforeach; ?>
    </tbody>
</table>
<?php
