<?php
/**
 * Drawer summary view.
 *
 * @package Awesomemotive\Rewardswp\Views\Admin\Parts
 * @since 1.0.0
 */

namespace Awesomemotive\Rewardswp\Views\Admin\Parts;

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

use Awesomemotive\Rewardswp\Abstracts\AbstractView;
use Awesomemotive\Rewardswp\Interfaces\ViewInterface;
use function Awesomemotive\Rewardswp\Helpers\is_rewardswp_pro_plan;

/**
 * Drawer Summary View
 *
 * Displays a summary at the bottom of drawers for rewards and exports.
 * Shows contextual information based on the drawer type.
 *
 * @since 1.1.0
 */
class DrawerSummaryView extends AbstractView implements ViewInterface {
	/**
	 * Render the template.
	 *
	 * @since 1.1.0
	 *
	 * @param array $args
	 *
	 * @return void
	 */
	public function render( array $args = [] ): void {

		?>

	<!-- Show reward summary for EARN actions -->
	<template x-if="$store.drawer.type === 'earn' && $store.drawer.selectedAction && $store.drawer.view === 'config' && !($store.drawer.selectedAction.id === 'product_review' && $store.earnActions.scriptData.isEdd && $store.earnActions.scriptData.eddReviewsStatus !== 'active')">
		<div class="border-t border-blue-100 bg-blue-50 px-6 py-4"
			x-bind:class="{ 'blur-sm': $store.drawer.isUpgrade }">
				<h4 class="text-xs uppercase tracking-wide text-gray-500 mb-1 mt-0">
					<?php esc_html_e( 'Summary', 'rewardswp' ); ?>
				</h4>
				<p class="text-sm font-semibold text-gray-900"
					x-text="window.getEarnActionSummary({...$store.drawer.selectedAction})">
				</p>
			</div>
		</template>

		<!-- Show reward summary for SPEND actions -->
		<template x-if="$store.drawer.type === 'spend' && $store.drawer.selectedAction && $store.drawer.view === 'config'">
			<div class="border-t border-blue-100 bg-blue-50 px-6 py-4"
				x-bind:class="{ 'blur-sm': $store.drawer.isUpgrade }">
				<h4 class="text-xs uppercase tracking-wide text-gray-500 mb-1 mt-0">
					<?php esc_html_e( 'Summary', 'rewardswp' ); ?>
				</h4>
				<p class="text-sm font-semibold text-gray-900"
					x-text="window.getSpendActionSummary($store.drawer.selectedAction)">
				</p>
			</div>
		</template>

		<!-- Show reward summary for REFERRAL rewards (uses $store.drawer.selectedAction) -->
		<template x-if="$store.drawer.type === 'referral' && $store.drawer.selectedAction && $store.drawer.view === 'config' && !($store.drawer.selectedAction.type === 'points' && !$store.referrals.pointsProgramEnabled)">
			<div class="border-t border-blue-100 bg-blue-50 px-6 py-4"
				x-bind:class="{ 'blur-sm': $store.drawer.isUpgrade }">
				<h4 class="text-xs uppercase tracking-wide text-gray-500 mb-1 mt-0">
					<?php esc_html_e( 'Summary', 'rewardswp' ); ?>
				</h4>
				<p class="text-base font-semibold text-gray-900 mb-3"
					x-text="$store.referrals.getDescription($store.drawer.selectedAction, $store.drawer.actionId)">
				</p>
				<div class="space-y-1 text-sm text-gray-600">
					<div class="flex items-start" x-show="$store.drawer.selectedAction.type !== 'points' && $store.drawer.selectedAction.minimum_order_amount > 0">
						<span class="text-gray-400 mr-2">•</span>
						<span><?php echo esc_html__( 'Applies to orders over', 'rewardswp' ); ?> <span class="font-medium text-gray-900" x-text="<?php echo \Awesomemotive\Rewardswp\Helpers\js_money_expr( '$store.drawer.selectedAction.minimum_order_amount', 'window.currencySymbol' ); ?>"></span></span>
					</div>
					<div class="flex items-start" x-show="$store.drawer.selectedAction.type !== 'points' && (!$store.drawer.selectedAction.minimum_order_amount || $store.drawer.selectedAction.minimum_order_amount <= 0)">
						<span class="text-gray-400 mr-2">•</span>
						<span><?php echo esc_html__( 'Applies to orders of any amount', 'rewardswp' ); ?></span>
					</div>
					<div class="flex items-start" x-show="$store.drawer.selectedAction.type !== 'points' && $store.drawer.selectedAction.reward_expiration">
						<span class="text-gray-400 mr-2">•</span>
						<span><?php echo esc_html__( 'Expires after', 'rewardswp' ); ?> <span class="font-medium text-gray-900" x-text="$store.drawer.selectedAction.reward_expiration.toString().replace(/^\+/, '')"></span></span>
					</div>
				<div class="flex items-start" x-show="$store.drawer.selectedAction.type === 'free_product' && $store.drawer.selectedAction.products_included && $store.drawer.selectedAction.products_included.length && window.getRewardProductName( $store.drawer.selectedAction.products_included[0] )">
					<span class="text-gray-400 mr-2">•</span>
					<span x-html="`<?php echo esc_js( esc_html__( 'Applies to', 'rewardswp' ) ); ?> <span class='font-medium text-gray-900'>${ window.getRewardProductName( $store.drawer.selectedAction.products_included?.[0] ) || '' }</span>`"></span>
				</div>
				</div>
			</div>
		</template>

		<template x-if="$store.exportDrawer && $store.exportDrawer.isOpen && $store.exportDrawer.selectedType && !$store.exportDrawer.isUpgrade">
			<div class="border-t border-blue-100 bg-blue-50 px-6 py-4">
				<h4 class="text-xs uppercase tracking-wide text-gray-500 mb-1 mt-0">
					<?php esc_html_e( 'What happens next', 'rewardswp' ); ?>
				</h4>
				<div class="space-y-1 text-sm text-gray-600">
					<div class="flex items-start">
						<span class="text-gray-400 mr-2">•</span>
						<span><?php esc_html_e( 'Your export will be queued for processing in the background', 'rewardswp' ); ?></span>
					</div>
					<div class="flex items-start">
						<span class="text-gray-400 mr-2">•</span>
						<span><?php esc_html_e( 'Download will be available for 7 days', 'rewardswp' ); ?></span>
					</div>
					<div class="flex items-start" x-show="$store.exportDrawer.emailCopy" x-cloak>
						<span class="text-gray-400 mr-2">•</span>
						<span><?php esc_html_e( 'Email copy will be sent when ready', 'rewardswp' ); ?></span>
					</div>
				</div>
			</div>
		</template>

		<?php
	}
}
