<?php
/**
 * Plugin admin field: Payout list
 *
 * @package YITH\PayPalPayouts\Admin
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

wp_enqueue_style( 'yith_payouts_status' );
$table_column = array(
	'payout_item_id'     => __( 'Payout item ID', 'yith-paypal-payouts-for-woocommerce' ),
	'transaction_id'     => __( 'Transaction ID', 'yith-paypal-payouts-for-woocommerce' ),
	'amount'             => __( 'Amount', 'yith-paypal-payouts-for-woocommerce' ),
	'transaction_status' => __( 'Transaction Status', 'yith-paypal-payouts-for-woocommerce' ),
);
?>
<div class="yith_payouts_container">
	<?php
	if ( count( $user_log_items ) > 0 ) {
		?>
		<table class="shop_table shop_table_responsive my_account_orders">
			<thead>
			<tr>
				<?php foreach ( $table_column as $column ) : ?>
					<th><?php echo esc_html( $column ); ?></th>
				<?php endforeach; ?>
			</tr>
			</thead>
			<tbody>
			<?php
			foreach ( $user_log_items as $single_row ) {
				?>
				<tr class="order">
					<?php
					foreach ( $single_row as $column_name => $item ) {

						if ( 'currency' === $column_name ) {
							continue;
						}
						$output = '';
						$title  = ''; //phpcs:ignore
						switch ( $column_name ) {
							case 'amount':
								$currency = $single_row['currency'];
								$output   = wc_price( $item, array( 'currency' => $currency ) );
								break;
							case 'transaction_status':
								$status = YITH_Payout_Items()->get_transaction_status(); //phpcs:ignore
								$output = isset( $status[ $item ] ) ? $status[ $item ] : $item;
								$output = sprintf( '<span class="payouts-status %1$s">%2$s</span>', $item, $output );

								break;
							case 'transaction_id':
							case 'payout_item_id':
								$output = empty( $item ) ? _x( 'N/A', 'Not available', 'yith-woocommerce-account-funds' ) : $item;
								break;


						}
						?>
						<td class="<?php echo esc_attr( $column_name ); ?>"
							data-title="<?php echo esc_attr( $table_column[ $column_name ] ); ?>">
							<?php echo wp_kses_post( $output ); ?>
						</td>
						<?php
					}
					?>
				</tr>
				<?php
			}
			?>
			<?php
			if ( isset( $page_links ) ) :
				?>

				<tr class="pagination-row">
					<td colspan="<?php echo esc_attr( count( $table_column ) ); ?>">
						<?php echo $page_links; //phpcs:ignore WordPress.Security.EscapeOutput ?>
					</td>
				</tr>

			<?php endif; ?>
			</tbody>
		</table>
		<?php
	} else {
		?>
		<div class="woocommerce-message woocommerce-message--info woocommerce-Message woocommerce-Message--info woocommerce-info">
			<a class="woocommerce-Button button"  href="<?php echo esc_url( apply_filters( 'woocommerce_return_to_shop_redirect', wc_get_page_permalink( 'shop' ) ) ); ?>">
				<?php esc_html_e( 'Go to the shop', 'yith-paypal-payouts-for-woocommerce' ); ?>
			</a>
			<?php esc_html_e( 'No payout has been processed yet.', 'yith-paypal-payouts-for-woocommerce' ); ?>

		</div>
		<?php

	}
	?>
</div>
