<?php
/**
 * Items Purchased List Template
 *
 * @var array      $product_array
 * @var WC_Product $product
 * @package wpstream-theme
 */

$product              = $product_array['product'];
$order_id             = $product_array['order_id'];
$order_url            = wpstream_get_my_account_order_url( $order_id );
$price                = $product_array['price'];
$purchase_date        = $product_array['order_date'];
$post_id              = $product->get_id(); //phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$title                = $product->get_name(); //phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$url                  = $product->get_permalink();
$product_date_created = $product->get_date_created();


$date_string    = $product_date_created;
$date_object    = new DateTime( $date_string );
$formatted_date = $date_object->format( 'M d, Y &#183; g:i A' );
$product_id     = $product->get_id();
$product_type   = get_post_meta( $product_id, '_product_type', true );
?>

<div class="card-body wpstream-dashboard-card">
	<div class="wpstream-dashboard-card__info">
		<div class="wpstream-dashboard-card-featured-image">
			<a href="<?php echo esc_url( $url ); ?>">
				<?php echo wpstream_theme_featured_image( $post_id, 'wpstream_featured_unit_cards' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
			</a>
		</div>
		<div class="wpstream-dashboard-card-title-section">
			<a href="<?php echo esc_url( $url ); ?>">
				<?php echo esc_html( $title ); ?>
			</a>

			<div class="wpstream-dashboard-card-categories">
				<?php
				$categories = get_the_terms( $post_id, 'category' );

				echo esc_html( $formatted_date );

				if ( $categories ) {
					print ' <span>&#183;</span> ';
				}
				?>

				<?php
				if ( $categories && ! is_wp_error( $categories ) ) {
					foreach ( $categories as $category ) {
						echo esc_html( $category->name );
						print ' <span>&#183;</span> ';
					}
				}

				?>

			</div>
		</div>
		<div class="wpstream-dashboard-card-purchase-section">
			<div class="wpstream_dashboard_list_purchased_price">
				<?php
				if ( function_exists( 'get_woocommerce_currency_symbol' ) ) :

					print esc_html__( 'Paid', 'hello-wpstream' ) . ': ' . $price . get_woocommerce_currency_symbol(); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

				endif;
				?>

			</div>
			<div class="wpstream_dashboard_list_purchased_on">
				<?php print esc_html__( 'Purchased on', 'hello-wpstream' ) . ': ' . $purchase_date; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
			</div>
		</div>
	</div>

	<div class="wpstream-dashboard-card__actions">
		<div class="wpstream-dashboard-card-actions">
			<a href="<?php echo esc_url( $url ); ?>" data-toggle="tooltip" data-placement="top" title="<?php esc_attr_e( 'View media', 'hello-wpstream' ); ?>">
				<?php if ( 'live_stream' == $product_type ) : ?>
					<?php echo wpstream_theme_get_svg_icon( 'play_icon_white.svg' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
				<?php else : ?>
					<?php echo wpstream_theme_get_svg_icon( 'purchased-events-icon.svg' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
				<?php endif; ?>
			</a>

			<a href="<?php echo esc_url( $order_url ); ?>" data-toggle="tooltip" data-placement="top" title="<?php esc_attr_e( 'View order', 'hello-wpstream' ); ?>">
				<?php echo wpstream_theme_get_svg_icon( 'orders-icon.svg' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
			</a>
		</div>
	</div>
</div>
