<?php
/**
 * Export drawer view for the export configuration panel.
 *
 * @package Awesomemotive\Rewardswp\Views\Admin\Parts
 * @since 1.1.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\can_access_rewardswp_feature;
use function Awesomemotive\Rewardswp\Helpers\get_view_component;

/**
 * Export Drawer View.
 *
 * Renders the export configuration drawer content including the upgrade overlay
 * for Lite users.
 *
 * @since 1.1.0
 */
class ExportDrawerView extends AbstractView implements ViewInterface {

	/**
	 * Render the export drawer content.
	 *
	 * @since 1.1.0
	 *
	 * @param array $args Render arguments.
	 * @return void
	 */
	public function render( array $args = [] ): void {
		$can_export = can_access_rewardswp_feature( 'exports' );
		?>

		<div class="relative h-full">
			<?php if ( ! $can_export ) : ?>
				<!-- Upgrade Overlay for Lite Users -->
				<?php
				// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Component handles its own sanitization
				echo get_view_component(
					'upgrade-overlay',
					[
						'icon_name'    => 'data-export',
						'title'        => __( 'Data exports', 'rewardswp' ),
						'description'  => __( 'Export members, points activity, referrals, and rewards to CSV.', 'rewardswp' ),
						'features'     => [
							__( 'Export all 4 data types', 'rewardswp' ),
							__( 'Filter by date range', 'rewardswp' ),
							__( '7-day download history', 'rewardswp' ),
						],
						'feature_slug' => 'exports',
						'feature_name' => __( 'Data Exports', 'rewardswp' ),
						'location'     => 'drawer',
						'overlay'      => true,
					]
				);
				?>
			<?php else : ?>
				<!-- Export Configuration Form -->
				<div class="divide-y divide-gray-200">
					<!-- Date Range Display -->
					<div class="pb-6">
						<label class="text-sm font-medium text-gray-900">
							<?php esc_html_e( 'Date Range', 'rewardswp' ); ?>
						</label>
						<div class="text-sm text-gray-700">
							<span x-text="$store.exportDrawer.formatDateRange()"></span>
						</div>
						<p class="mt-3 text-sm text-gray-500">
							<?php esc_html_e( "We'll export this as a CSV file (works with Excel, Google Sheets, and Numbers).", 'rewardswp' ); ?>
						</p>
					</div>

					<!-- Email Copy Option -->
					<div class="flex items-center justify-between pt-6">
						<label class="cursor-pointer" x-on:click="$store.exportDrawer.emailCopy = !$store.exportDrawer.emailCopy">
							<p class="text-sm font-medium text-gray-900"><?php esc_html_e( 'Email me a copy', 'rewardswp' ); ?></p>
							<p class="text-sm text-gray-500"><?php esc_html_e( 'Receive the download link by email', 'rewardswp' ); ?></p>
						</label>
						<?php
						// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output is escaped within the component
						echo get_view_component(
							'toggle',
							[
								'section'      => '',
								'name'         => '',
								'is_checked'   => false,
								'x_model'      => '$store.exportDrawer.emailCopy',
								'no_input'     => true,
								'button_align' => 'right',
							]
						);
						?>
					</div>
				</div>
			<?php endif; ?>
		</div>
		<?php
	}
}
