<?php
/**
 * Orders
 *
 * Shows orders on the account page.
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/myaccount/orders.php.
 *
 * HOWEVER, on occasion WooCommerce 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/
 * @package WooCommerce\Templates
 * @version 9.2.0
 */

defined( 'ABSPATH' ) || exit;

do_action( 'woocommerce_before_account_orders', $has_orders ); ?>
<div class="wpstream-orders">
	<?php if ( $has_orders ) : ?>
		<h2><?php echo apply_filters( 'woocommerce_my_account_my_orders_title', esc_html__( 'Orders', 'hello-wpstream' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></h2>

		<div class="wpstream-orders__table woocommerce-orders-table woocommerce-MyAccount-orders shop_table shop_table_responsive my_account_orders account-orders-table">
			<div class="wpstream-orders__table-header">
				<?php foreach ( wc_get_account_orders_columns() as $column_id => $column_name ) : ?>
					<div class="wpstream-orders__table-header-item woocommerce-orders-table__header woocommerce-orders-table__header-<?php echo esc_attr( $column_id ); ?>"><span class="nobr"><?php echo esc_html( $column_name ); ?></span></div>
				<?php endforeach; ?>
			</div>

			<div class="wpstream-orders__table-body">
			<?php
			foreach ( $customer_orders->orders as $customer_order ) :
				$order      = wc_get_order( $customer_order ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
				$item_count = $order->get_item_count() - $order->get_item_count_refunded();
				?>
				<div class="wpstream-orders__table-body-row woocommerce-orders-table__row woocommerce-orders-table__row--status-<?php echo esc_attr( $order->get_status() ); ?> order">
					<div class="wpstream-orders__table-header-mobile">
						<?php foreach ( wc_get_account_orders_columns() as $column_id => $column_name ) : ?>
							<div class="wpstream-orders__table-header-item woocommerce-orders-table__header woocommerce-orders-table__header-<?php echo esc_attr( $column_id ); ?>"><span class="nobr"><?php echo esc_html( $column_name ); ?></span></div>
						<?php endforeach; ?>
					</div>
					
					<div class="wpstream-orders__table-body-row-inner">
						<?php foreach ( wc_get_account_orders_columns() as $column_id => $column_name ) : ?>
							<div class="wpstream-orders__table-body-item woocommerce-orders-table__cell woocommerce-orders-table__cell-<?php echo esc_attr( $column_id ); ?>" data-title="<?php echo esc_attr( $column_name ); ?>">
								<?php if ( has_action( 'woocommerce_my_account_my_orders_column_' . $column_id ) ) : ?>
									<?php do_action( 'woocommerce_my_account_my_orders_column_' . $column_id, $order ); ?>

								<?php elseif ( 'order-number' === $column_id ) : ?>
									<a href="<?php echo esc_url( $order->get_view_order_url() ); ?>">
										<?php echo esc_html( _x( '#', 'hash before order number', 'hello-wpstream' ) . $order->get_order_number() ); ?>
									</a>

								<?php elseif ( 'order-date' === $column_id ) : ?>
									<time datetime="<?php echo esc_attr( $order->get_date_created()->date( 'c' ) ); ?>"><?php echo esc_html( wc_format_datetime( $order->get_date_created() ) ); ?></time>

								<?php elseif ( 'order-status' === $column_id ) : ?>
									<?php echo esc_html( wc_get_order_status_name( $order->get_status() ) ); ?>

								<?php elseif ( 'order-total' === $column_id ) : ?>
									<?php
									/* translators: 1: formatted order total 2: total order items */
									echo wp_kses_post( sprintf( _n( '%1$s for %2$s item', '%1$s for %2$s items', $item_count, 'hello-wpstream' ), $order->get_formatted_order_total(), $item_count ) );
									?>

								<?php elseif ( 'order-actions' === $column_id ) : ?>
									<?php $actions = wc_get_account_orders_actions( $order ); ?>

									<?php if ( ! empty( $actions ) ) : ?>
										<?php foreach ( $actions as $key => $action ) : // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited ?>
											<a href="<?php echo esc_url( $action['url'] ); ?>" class="wpstream-orders__action-btn woocommerce-button button <?php echo esc_attr( $wp_button_class ); ?> <?php echo sanitize_html_class( $key ); ?>">
											<?php echo wpstream_theme_get_svg_icon( 'dashboard_view_order.svg' ) ?>
											</a>
										<?php endforeach; ?>
									<?php endif; ?>
								<?php endif; ?>
							</div>
						<?php endforeach; ?>
					</div>
				</div>
			<?php endforeach; ?>

				<?php do_action( 'woocommerce_before_account_orders_pagination' ); ?>

				<?php if ( 1 < $customer_orders->max_num_pages ) : ?>
					<div class="wpstream-orders__pagination woocommerce-pagination woocommerce-pagination--without-numbers woocommerce-Pagination">
						<?php if ( 1 == $current_page ) : ?>
							<a class="wpstream-orders__pagination-btn wpstream-orders__pagination-btn--disabled woocommerce-button woocommerce-button--previous woocommerce-Button woocommerce-Button--previous button<?php echo esc_attr( $wp_button_class ); ?>" href="<?php echo esc_url( wc_get_endpoint_url( 'orders', $current_page - 1 ) ); ?>">
								<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
									<path d="M11.0303 8.53033C11.3232 8.23744 11.3232 7.76256 11.0303 7.46967C10.7374 7.17678 10.2626 7.17678 9.96967 7.46967L5.96967 11.4697C5.82322 11.6161 5.75 11.8081 5.75 12C5.75 12.1017 5.77024 12.1987 5.80691 12.2871C5.84351 12.3755 5.89776 12.4584 5.96967 12.5303L9.96967 16.5303C10.2626 16.8232 10.7374 16.8232 11.0303 16.5303C11.3232 16.2374 11.3232 15.7626 11.0303 15.4697L8.31066 12.75H18C18.4142 12.75 18.75 12.4142 18.75 12C18.75 11.5858 18.4142 11.25 18 11.25H8.31066L11.0303 8.53033Z" fill="#0F0F0F"/>
								</svg>

								<?php esc_html_e( 'Previous', 'hello-wpstream' ); ?>
							</a>
						<?php else : ?>
							<a class="wpstream-orders__pagination-btn woocommerce-button woocommerce-button--previous woocommerce-Button woocommerce-Button--previous button<?php echo esc_attr( $wp_button_class ); ?>" href="<?php echo esc_url( wc_get_endpoint_url( 'orders', $current_page - 1 ) ); ?>">
								<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
									<path d="M11.0303 8.53033C11.3232 8.23744 11.3232 7.76256 11.0303 7.46967C10.7374 7.17678 10.2626 7.17678 9.96967 7.46967L5.96967 11.4697C5.82322 11.6161 5.75 11.8081 5.75 12C5.75 12.1017 5.77024 12.1987 5.80691 12.2871C5.84351 12.3755 5.89776 12.4584 5.96967 12.5303L9.96967 16.5303C10.2626 16.8232 10.7374 16.8232 11.0303 16.5303C11.3232 16.2374 11.3232 15.7626 11.0303 15.4697L8.31066 12.75H18C18.4142 12.75 18.75 12.4142 18.75 12C18.75 11.5858 18.4142 11.25 18 11.25H8.31066L11.0303 8.53033Z" fill="#0F0F0F"/>
								</svg>

								<?php esc_html_e( 'Previous', 'hello-wpstream' ); ?>
							</a>
						<?php endif; ?>

						<div class="wpstream-orders__pagination-links-wrap">
							<?php for ( $i = 1; $i <= $customer_orders->max_num_pages; $i++ ) : ?>
								<?php $active_class = ( $current_page === $i ) ? 'wpstream-orders__pagination-page--active' : ''; ?>
								<a class="wpstream-orders__pagination-page woocommerce-pagination__page <?php echo esc_attr($active_class); ?>" href="<?php echo esc_url( wc_get_endpoint_url( 'orders', $i ) ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>"><?php echo esc_html($i); ?></a>
							<?php endfor; ?>
						</div>

						<?php if ( intval( $customer_orders->max_num_pages ) === $current_page ) : ?>
							<a class="wpstream-orders__pagination-btn wpstream-orders__pagination-btn--disabled woocommerce-button woocommerce-button--next woocommerce-Button woocommerce-Button--next button<?php echo esc_attr( $wp_button_class ); ?>" href="<?php echo esc_url( wc_get_endpoint_url( 'orders', $current_page + 1 ) ); ?>">
								<?php esc_html_e( 'Next', 'hello-wpstream' ); ?>

								<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
									<path d="M13.4697 8.53033C13.1768 8.23744 13.1768 7.76256 13.4697 7.46967C13.7626 7.17678 14.2374 7.17678 14.5303 7.46967L18.5303 11.4697C18.8232 11.7626 18.8232 12.2374 18.5303 12.5303L14.5303 16.5303C14.2374 16.8232 13.7626 16.8232 13.4697 16.5303C13.1768 16.2374 13.1768 15.7626 13.4697 15.4697L16.1893 12.75H6.5C6.08579 12.75 5.75 12.4142 5.75 12C5.75 11.5858 6.08579 11.25 6.5 11.25H16.1893L13.4697 8.53033Z" fill="#0F0F0F"/>
								</svg>
							</a>
						<?php else : ?>
							<a class="wpstream-orders__pagination-btn woocommerce-button woocommerce-button--next woocommerce-Button woocommerce-Button--next button<?php echo esc_attr( $wp_button_class ); ?>" href="<?php echo esc_url( wc_get_endpoint_url( 'orders', $current_page + 1 ) ); ?>">
								<?php esc_html_e( 'Next', 'hello-wpstream' ); ?>

								<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
									<path d="M13.4697 8.53033C13.1768 8.23744 13.1768 7.76256 13.4697 7.46967C13.7626 7.17678 14.2374 7.17678 14.5303 7.46967L18.5303 11.4697C18.8232 11.7626 18.8232 12.2374 18.5303 12.5303L14.5303 16.5303C14.2374 16.8232 13.7626 16.8232 13.4697 16.5303C13.1768 16.2374 13.1768 15.7626 13.4697 15.4697L16.1893 12.75H6.5C6.08579 12.75 5.75 12.4142 5.75 12C5.75 11.5858 6.08579 11.25 6.5 11.25H16.1893L13.4697 8.53033Z" fill="#0F0F0F"/>
								</svg>
							</a>
						<?php endif; ?>
					</div>
				<?php endif; ?>
			</div>
		</div>

	<?php else : ?>

		<?php wc_print_notice( esc_html__( 'No order has been made yet.', 'hello-wpstream' ) . ' <a class="woocommerce-Button wc-forward button' . esc_attr( $wp_button_class ) . '" href="' . esc_url( apply_filters( 'woocommerce_return_to_shop_redirect', wc_get_page_permalink( 'shop' ) ) ) . '">' . esc_html__( 'Browse products', 'hello-wpstream' ) . '</a>', 'notice' ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment ?>

	<?php endif; ?>

	<?php do_action( 'woocommerce_after_account_orders', $has_orders ); ?>
</div>
