<?php
/**
 * Order details Summary on Tahn you page
 *
 * This template displays a summary of Desposit payments
 *
 * @version 1.5
 */

use Bright_Deposits_For_WooCommerce\Core\OrderDeposit;
use Bright_Deposits_For_WooCommerce\Helpers\Helper;

if ( !defined( 'ABSPATH' ) ) {
    exit;
}
if ( !$order ) {
    return;
}
$bdfwbp_args = array(
    'type'   => 'shop_deposit',
    'parent' => $order->get_id(),
);

$bdfwbp_deposit_list = wc_get_orders( $bdfwbp_args );

?>
<h4><?php echo esc_html( Helper::getOptionValue( 'bdfw_deposit_payments_summary_label', __( 'Deposit payments summary', 'bright-deposits-for-woocommerce' ) ) ); ?></h4>

<table class="woocommerce-table  woocommerce_deposits_parent_order_summary">
    <thead>
        <tr>
            <th ><?php echo esc_html( Helper::getOptionValue( 'bdfw_payment_label', __( 'Payment', 'bright-deposits-for-woocommerce' ) ) ); ?></th>
            <th ><?php echo esc_html( Helper::getOptionValue( 'bdfw_payment_id_label', __( 'Payment ID', 'bright-deposits-for-woocommerce' ) ) ); ?></th>
            <th><?php echo esc_html( Helper::getOptionValue( 'bdfw_status_label', __( 'Status', 'bright-deposits-for-woocommerce' ) ) ); ?></th>
            <th><?php echo esc_html( Helper::getOptionValue( 'bdfw_amount_label', __( 'Amount', 'bright-deposits-for-woocommerce' ) ) ); ?></th>
            <th><?php echo esc_html( Helper::getOptionValue( 'bdfw_actions_label', __( 'Actions', 'bright-deposits-for-woocommerce' ) ) ); ?></th>
        </tr>
    </thead>

    <tbody>
    <?php
foreach ( $bdfwbp_deposit_list as $bdfwbp_key => $bdfwbp_deposit ) {
    $bdfwbp_deposit_order = new OrderDeposit( $bdfwbp_deposit->get_id() );

    if ( $bdfwbp_deposit_order->get_status() == 'completed' ) {
        $bdfwbp_payment_status = Helper::getOptionValue( 'bdfw_deposit_label', __( 'Deposit', 'bright-deposits-for-woocommerce' ) );
    } else {
        $bdfwbp_payment_status = Helper::getOptionValue( 'bdfw_due_payment_label', __( 'Balance', 'bright-deposits-for-woocommerce' ) );
    }
    ?>

        <tr class="order_item">
            <td>
               <?php echo esc_html( $bdfwbp_payment_status ); ?>
            </td>
            <td>
              <?php echo '<strong>#' . esc_html( $bdfwbp_deposit_order->get_meta( '_deposit_id', true ) ) . '</strong>'; ?>
            </td>
            <td>
            <?php
                $bdfwbp_deposit_status = $bdfwbp_deposit_order->get_status();
                echo esc_html( wc_get_order_status_name( $bdfwbp_deposit_status ) );?>
            </td>
            <td>
            <?php echo wp_kses_post( wc_price( $bdfwbp_deposit_order->get_total() ) ); ?>
            </td>

            <td>

            <?php
if ( $bdfwbp_deposit_order->get_status() == 'pending' ) {
        echo '<a href="' . esc_url( $bdfwbp_deposit_order->get_checkout_payment_url() ) . '" class="woocommerce-button button deposit-pay-button"> ' . esc_html( Helper::getOptionValue( 'bdfw_make_payment_label' ) ) . ' </a>';
    } else {
        echo '-';
    }
    ?>
            </td>
        </tr>
        <?php
}?>

    </tbody>
    <tfoot>
    </tfoot>
</table>
