<?php
/**
 * Empty state component view.
 *
 * @package Awesomemotive\Rewardswp\Views\Admin\Components
 * @since 1.1.0
 */

namespace Awesomemotive\Rewardswp\Views\Admin\Components;

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

use Awesomemotive\Rewardswp\Abstracts\AbstractView;
use Awesomemotive\Rewardswp\Helpers\IconHelper;
use Awesomemotive\Rewardswp\Interfaces\ViewInterface;
use function Awesomemotive\Rewardswp\Helpers\svg_kses;

/**
 * Empty State Component View.
 *
 * Displays a centered empty state with an icon, title, and description.
 *
 * @since 1.1.0
 */
class EmptyStateComponentView extends AbstractView implements ViewInterface {

	/**
	 * Icon helper instance.
	 *
	 * @since 1.1.0
	 *
	 * @var IconHelper
	 */
	private IconHelper $icon_helper;

	/**
	 * Constructor.
	 *
	 * @since 1.1.0
	 *
	 * @param IconHelper $icon_helper Icon helper instance.
	 */
	public function __construct( IconHelper $icon_helper ) {
		$this->icon_helper = $icon_helper;
	}

	/**
	 * Render the empty state component.
	 *
	 * @since 1.1.0
	 *
	 * @param array $args {
	 *     Optional. Array of arguments.
	 *
	 *     @type string $icon        The icon name from IconHelper. Required.
	 *     @type string $title       The title text. Required.
	 *     @type string $description The description text. Required.
	 *     @type string $x_show      Optional. Alpine.js x-show directive value.
	 * }
	 * @return void
	 */
	public function render( array $args = [] ): void {
		$args = wp_parse_args(
			$args,
			[
				'icon'        => '',
				'title'       => '',
				'description' => '',
				'x_show'      => '',
				'x_cloak'     => false,
			]
		);

		// Return early if required args are missing.
		if ( empty( $args['icon'] ) || empty( $args['title'] ) || empty( $args['description'] ) ) {
			return;
		}

		$x_show_attr  = ! empty( $args['x_show'] ) ? sprintf( ' x-show="%s"', esc_attr( $args['x_show'] ) ) : '';
		$x_cloak_attr = ! empty( $args['x_cloak'] ) ? ' x-cloak' : '';
		?>
		<div class="text-center py-12"<?php echo $x_show_attr . $x_cloak_attr; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Already escaped above ?>>
			<div class="mx-auto flex items-center justify-center">
				<?php echo wp_kses( $this->icon_helper->get_icon( $args['icon'], 'size-10 text-gray-400' ), svg_kses() ); ?>
			</div>
			<h3 class="mt-3 text-base font-medium text-gray-900"><?php echo esc_html( $args['title'] ); ?></h3>
			<p class="mt-1 text-sm text-gray-500"><?php echo esc_html( $args['description'] ); ?></p>
		</div>
		<?php
	}
}
