<?php
/**
 * GGM Commerce Review Form Widget
 *
 * Displays a form for submitting product reviews.
 *
 * @package GGM Commerce
 * @subpackage Widgets
 */

// Prevent direct access
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

require_once __DIR__ . '/widget-review-form/elementor-render.php';

class GGM_Commerce_Widget_Review_Form extends GGM_Commerce_Premium_Widget {

	/**
	 * Premium widget slug for license activation check.
	 *
	 * @var string
	 */
	protected $premium_widget_slug = 'product-reviews';

	public function get_name() {
		return 'ggmc-review-form';
	}

	public function get_title() {
		return 'Product Review Form';
	}

	public function get_icon() {
		return 'eicon-form-horizontal';
	}

	public function get_keywords() {
		return [ 'review', 'form', 'rating', 'comment', 'feedback', 'product', 'ggm', 'premium' ];
	}

	protected function register_controls() {
		require __DIR__ . '/widget-review-form/elementor-controls.php';
		require __DIR__ . '/widget-review-form/elementor-controls-style.php';
	}

	protected function render_premium_content() {
		ggmc_review_form_render_premium_content( $this );
	}

	protected function content_template() {
		?>
		<#
		var formTitle = settings.form_title;
		var titleTag = settings.title_html_tag || 'h3';
		var ratingLabel = settings.rating_label;
		var titleLabel = settings.title_label;
		var contentLabel = settings.content_label;
		var nameLabel = settings.name_label;
		var emailLabel = settings.email_label;
		var submitText = settings.submit_button_text;
		var showTitleField = settings.show_title_field === 'yes';
		#>
		<div class="ggmc-review-form-wrapper">
			<# if (formTitle) { #>
				<{{{ titleTag }}} class="ggmc-review-form-title">{{{ formTitle }}}</{{{ titleTag }}}>
			<# } #>

			<form class="ggmc-review-form">
				<!-- Star Rating -->
				<div class="ggmc-form-field ggmc-rating-field">
					<label>{{{ ratingLabel }}} <span class="required">*</span></label>
					<div class="ggmc-star-rating-input" data-rating="0">
						<span class="star" data-value="1">&#9733;</span>
						<span class="star" data-value="2">&#9733;</span>
						<span class="star" data-value="3">&#9733;</span>
						<span class="star" data-value="4">&#9733;</span>
						<span class="star" data-value="5">&#9733;</span>
					</div>
					<span class="ggmc-rating-text"></span>
				</div>

				<# if (showTitleField) { #>
				<!-- Review Title -->
				<div class="ggmc-form-field">
					<label>{{{ titleLabel }}}</label>
					<input type="text" name="title" placeholder="Summarize your review">
				</div>
				<# } #>

				<!-- Review Content -->
				<div class="ggmc-form-field">
					<label>{{{ contentLabel }}} <span class="required">*</span></label>
					<textarea name="content" rows="5" placeholder="What did you like or dislike about this product?"></textarea>
				</div>

				<!-- Name Field -->
				<div class="ggmc-form-field">
					<label>{{{ nameLabel }}} <span class="required">*</span></label>
					<input type="text" name="author_name">
				</div>

				<!-- Email Field -->
				<div class="ggmc-form-field">
					<label>{{{ emailLabel }}} <span class="required">*</span></label>
					<input type="email" name="author_email">
				</div>

				<!-- Submit Button -->
				<div class="ggmc-form-field ggmc-submit-field">
					<button type="submit" class="ggmc-submit-review-btn">
						<span class="button-text">{{{ submitText }}}</span>
					</button>
				</div>
			</form>
		</div>
		<?php
	}

	/**
	 * Get default styles for this widget.
	 * Uses centralized configuration from default-widget-styles.php.
	 *
	 * @return array Default styles.
	 */
	public static function get_static_default_styles() {
		return self::get_defaults_from_config();
	}
}
