<?php

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

// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$settings = isset( $settings ) && is_array( $settings ) ? $settings : get_option( 'ugcify_review_form_settings', array() );

$review_option_settings = get_option( 'ugcify_review_form_review_settings', array() );
if ( is_array( $review_option_settings ) && ! empty( $review_option_settings ) ) {
	$settings = array_merge( $settings, $review_option_settings );
}

$show_review_title = ! isset( $settings['showReviewTitle'] ) || (bool) $settings['showReviewTitle'];
$review_title_text = ! empty( $settings['reviewTitleText'] ) ? $settings['reviewTitleText'] : __( 'Share your experience', 'ugcify' );

$review_title_size_map = array(
	'small'  => 14,
	'medium' => 18,
	'large'  => 24,
);
$review_title_weight_map = array(
	'regular'  => 400,
	'semibold' => 600,
	'bold'     => 700,
);
$review_title_size_key   = $settings['reviewTitleSize'] ?? 'medium';
$review_title_weight_key = $settings['reviewTitleWeight'] ?? 'semibold';

$review_title_size   = isset( $review_title_size_map[ $review_title_size_key ] ) ? $review_title_size_map[ $review_title_size_key ] : $review_title_size_map['medium'];
$review_title_weight = isset( $review_title_weight_map[ $review_title_weight_key ] ) ? $review_title_weight_map[ $review_title_weight_key ] : $review_title_weight_map['semibold'];

$review_title_color               = sanitize_hex_color( $settings['reviewTitleColor'] ?? '' );
$review_message_label             = ! empty( $settings['reviewMessageLabel'] ) ? $settings['reviewMessageLabel'] : __( 'Your review', 'ugcify' );
$review_message_label_color       = sanitize_hex_color( $settings['reviewMessageLabelColor'] ?? '' );
$review_message_placeholder       = ! empty( $settings['reviewMessagePlaceholder'] ) ? $settings['reviewMessagePlaceholder'] : __( 'Write here', 'ugcify' );
$review_textarea_border_color     = sanitize_hex_color( $settings['reviewTextareaBorderColor'] ?? '' );
$review_textarea_placeholder_color = sanitize_hex_color( $settings['reviewTextareaPlaceholderColor'] ?? '' );

$review_back_text   = ! empty( $settings['reviewBackButtonText'] ) ? $settings['reviewBackButtonText'] : __( 'Back', 'ugcify' );
$review_submit_text = ! empty( $settings['reviewSubmitButtonText'] ) ? $settings['reviewSubmitButtonText'] : __( 'Submit Review', 'ugcify' );

$review_submit_fill_color   = sanitize_hex_color( $settings['reviewSubmitButtonFillColor'] ?? '' );
$review_submit_stroke_color = sanitize_hex_color( $settings['reviewSubmitButtonStrokeColor'] ?? '' );
$review_submit_font_color   = sanitize_hex_color( $settings['reviewSubmitButtonFontColor'] ?? '' );
$review_back_fill_color     = sanitize_hex_color( $settings['reviewBackButtonFillColor'] ?? '' );
$review_back_stroke_color   = sanitize_hex_color( $settings['reviewBackButtonStrokeColor'] ?? '' );
$review_back_font_color     = sanitize_hex_color( $settings['reviewBackButtonFontColor'] ?? '' );

$review_title_color                = $review_title_color ? $review_title_color : '#000000';
$review_message_label_color        = $review_message_label_color ? $review_message_label_color : '#000000';
$review_textarea_border_color      = $review_textarea_border_color ? $review_textarea_border_color : '#BFBFE9';
$review_textarea_placeholder_color = $review_textarea_placeholder_color ? $review_textarea_placeholder_color : '#7D7D7D';
$review_submit_fill_color          = $review_submit_fill_color ? $review_submit_fill_color : '#201CFE';
$review_submit_stroke_color        = $review_submit_stroke_color ? $review_submit_stroke_color : '#201CFE';
$review_submit_font_color          = $review_submit_font_color ? $review_submit_font_color : '#FFFFFF';
$review_back_fill_color            = $review_back_fill_color ? $review_back_fill_color : '#FFFFFF';
$review_back_stroke_color          = $review_back_stroke_color ? $review_back_stroke_color : '#201CFE';
$review_back_font_color            = $review_back_font_color ? $review_back_font_color : '#000000';
?>

<!-- Step 4: Review Text -->
<div class="ugcify-form-step ugcify-step-review-text" data-step="4" style="display: none;">
	<?php if ( $show_review_title ) : ?>
		<h2
			class="ugcify-step-subtitle"
			style="color: <?php echo esc_attr( $review_title_color ); ?>; font-size: <?php echo esc_attr( $review_title_size ); ?>px; font-weight: <?php echo esc_attr( $review_title_weight ); ?>;"
		>
			<?php echo esc_html( $review_title_text ); ?>
		</h2>
	<?php endif; ?>

	<div class="ugcify-form-field">
		<label for="ugcify-message" class="ugcify-form-label" style="color: <?php echo esc_attr( $review_message_label_color ); ?>;">
			<?php echo esc_html( $review_message_label ); ?> <span class="ugcify-required">*</span>
		</label>
		<textarea
			id="ugcify-message"
			name="message"
			class="ugcify-form-textarea"
			placeholder="<?php echo esc_attr( $review_message_placeholder ); ?>"
			rows="8"
			required
			style="border-color: <?php echo esc_attr( $review_textarea_border_color ); ?>; --ugcify-review-placeholder-color: <?php echo esc_attr( $review_textarea_placeholder_color ); ?>;"
		></textarea>
	</div>

	<?php if ( ! empty( $settings['recaptchaEnabled'] ) && ! empty( $settings['recaptchaSiteKey'] ) ) : ?>
		<div class="ugcify-form-field ugcify-recaptcha-container">
			<div class="g-recaptcha" data-sitekey="<?php echo esc_attr( $settings['recaptchaSiteKey'] ); ?>"></div>
		</div>
	<?php endif; ?>

	<div class="ugcify-step-actions">
		<button
			type="button"
			class="ugcify-button ugcify-button-outline ugcify-step-back"
			style="background: <?php echo esc_attr( $review_back_fill_color ); ?>; border-color: <?php echo esc_attr( $review_back_stroke_color ); ?>; color: <?php echo esc_attr( $review_back_font_color ); ?>;"
		>
			<?php echo esc_html( $review_back_text ); ?>
		</button>
		<svg xmlns="http://www.w3.org/2000/svg" width="131" height="27" viewBox="0 0 131 27" fill="none">
			<circle cx="13.5" cy="13.5" r="12.5" stroke="#201CFE" stroke-width="2"/>
			<path d="M8.1333 14.7506L11.1761 17.7934L19.3027 9.66669" stroke="#201CFE" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/>
			<circle cx="47.5" cy="13.5" r="12.5" stroke="#201CFE" stroke-width="2"/>
			<path d="M42.1333 14.7506L45.1761 17.7934L53.3027 9.66669" stroke="#201CFE" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/>
			<circle cx="81.5" cy="13.5" r="12.5" stroke="#E0DFFF" stroke-width="2"/>
			<circle cx="81.5" cy="13.5" r="12.5" stroke="#201CFE" stroke-width="2"/>
			<path d="M76.1333 14.7506L79.1761 17.7934L87.3027 9.66669" stroke="#201CFE" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/>
			<circle cx="117.5" cy="13.5" r="12.5" stroke="#E0DFFF" stroke-width="2"/>
		</svg>
		<button
			type="button"
			class="ugcify-button ugcify-button-primary ugcify-step-submit"
			style="background: <?php echo esc_attr( $review_submit_fill_color ); ?>; border-color: <?php echo esc_attr( $review_submit_stroke_color ); ?>; color: <?php echo esc_attr( $review_submit_font_color ); ?>;"
			disabled
		>
			<?php echo esc_html( $review_submit_text ); ?>
		</button>
	</div>
</div>
