<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

$wordform_template_categories = SftcyWordformFormtemplates::get_template_categories();
$wordform_builder_templates   = SftcyWordformFormtemplates::get_form_templates_registry();
?>

<div id="WordFormTemplatesModal" title="<?php esc_attr_e( 'Form Templates', 'wordform-pro' ); ?>" style="display: none;">
	<textarea class="wordform-builder-templates-registry" hidden><?php echo esc_textarea( wp_json_encode( $wordform_builder_templates ) ); ?></textarea>

	<div class="wordform-templates-modal-layout">
		<aside class="wordform-templates-sidebar">
			<div class="wordform-templates-search-wrapper">
				<span class="dashicons dashicons-search" aria-hidden="true"></span>
				<input type="search" id="WordFormTemplateSearch" class="wordform-templates-search-input" placeholder="<?php esc_attr_e( 'Search templates', 'wordform-pro' ); ?>" autocomplete="off" />
			</div>

			<div class="wordform-templates-category-list" role="tablist" aria-label="<?php esc_attr_e( 'Template categories', 'wordform-pro' ); ?>">
				<?php foreach ( $wordform_template_categories as $category_slug => $category_data ) { ?>
				<button type="button" class="wordform-template-category-item <?php echo 'all' === $category_slug ? 'is-active' : ''; ?>" data-template-category="<?php echo esc_attr( $category_slug ); ?>">
					<span class="wordform-template-category-label"><?php echo esc_html( $category_data['label'] ); ?></span>
					<small class="wordform-template-category-description"><?php echo esc_html( $category_data['description'] ); ?></small>
				</button>
				<?php } ?>
			</div>
		</aside>

		<div class="wordform-templates-main">
			<div class="wordform-templates-header">
				<h3><?php esc_html_e( 'Start with a professionally structured form', 'wordform-pro' ); ?></h3>
				<p><?php esc_html_e( 'Choose a template, load it into the builder, then customize the fields and publish faster.', 'wordform-pro' ); ?></p>
			</div>

			<div class="wordform-templates-grid"></div>

			<div class="wordform-templates-empty-state" style="display: none;">
				<span class="dashicons dashicons-search"></span>
				<h4><?php esc_html_e( 'No templates found', 'wordform-pro' ); ?></h4>
				<p><?php esc_html_e( 'Try a different search term or switch to another category.', 'wordform-pro' ); ?></p>
			</div>
		</div>
	</div>
</div>
