<?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() );

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

$show_thank_you_title    = ! isset( $settings['showThankYouTitle'] ) || (bool) $settings['showThankYouTitle'];
$show_thank_you_subtitle = ! isset( $settings['showThankYouSubtitle'] ) || (bool) $settings['showThankYouSubtitle'];

$thank_you_title_text    = ! empty( $settings['thankYouTitleText'] ) ? $settings['thankYouTitleText'] : __( 'Thank you!', 'ugcify' );
$thank_you_subtitle_text = ! empty( $settings['thankYouSubtitleText'] ) ? $settings['thankYouSubtitleText'] : __( "Your review has been received and is currently under moderation. We'll notify you by email once it's approved.", 'ugcify' );
$thank_you_button_text   = ! empty( $settings['thankYouButtonText'] ) ? $settings['thankYouButtonText'] : __( 'Continue Shopping', 'ugcify' );

$thank_you_title_size_map = array(
	'small'  => 20,
	'medium' => 24,
	'large'  => 30,
);
$thank_you_subtitle_size_map = array(
	'small'  => 14,
	'medium' => 16,
	'large'  => 18,
);
$thank_you_weight_map = array(
	'regular'  => 400,
	'semibold' => 600,
	'bold'     => 700,
);

$thank_you_title_size_key      = $settings['thankYouTitleSize'] ?? 'large';
$thank_you_title_weight_key    = $settings['thankYouTitleWeight'] ?? 'bold';
$thank_you_subtitle_size_key   = $settings['thankYouSubtitleSize'] ?? 'medium';
$thank_you_subtitle_weight_key = $settings['thankYouSubtitleWeight'] ?? 'regular';

$thank_you_title_size = isset( $thank_you_title_size_map[ $thank_you_title_size_key ] ) ? $thank_you_title_size_map[ $thank_you_title_size_key ] : $thank_you_title_size_map['large'];
$thank_you_title_weight = isset( $thank_you_weight_map[ $thank_you_title_weight_key ] ) ? $thank_you_weight_map[ $thank_you_title_weight_key ] : $thank_you_weight_map['bold'];
$thank_you_subtitle_size = isset( $thank_you_subtitle_size_map[ $thank_you_subtitle_size_key ] ) ? $thank_you_subtitle_size_map[ $thank_you_subtitle_size_key ] : $thank_you_subtitle_size_map['medium'];
$thank_you_subtitle_weight = isset( $thank_you_weight_map[ $thank_you_subtitle_weight_key ] ) ? $thank_you_weight_map[ $thank_you_subtitle_weight_key ] : $thank_you_weight_map['regular'];

$thank_you_title_color        = sanitize_hex_color( $settings['thankYouTitleColor'] ?? '' );
$thank_you_subtitle_color     = sanitize_hex_color( $settings['thankYouSubtitleColor'] ?? '' );
$thank_you_button_fill_color  = sanitize_hex_color( $settings['thankYouButtonFillColor'] ?? '' );
$thank_you_button_stroke_color = sanitize_hex_color( $settings['thankYouButtonStrokeColor'] ?? '' );
$thank_you_button_font_color  = sanitize_hex_color( $settings['thankYouButtonFontColor'] ?? '' );

$thank_you_title_color         = $thank_you_title_color ? $thank_you_title_color : '#201CFE';
$thank_you_subtitle_color      = $thank_you_subtitle_color ? $thank_you_subtitle_color : '#666666';
$thank_you_button_fill_color   = $thank_you_button_fill_color ? $thank_you_button_fill_color : '#201CFE';
$thank_you_button_stroke_color = $thank_you_button_stroke_color ? $thank_you_button_stroke_color : '#201CFE';
$thank_you_button_font_color   = $thank_you_button_font_color ? $thank_you_button_font_color : '#FFFFFF';
?>

<!-- Step 5: Thank You -->
<div class="ugcify-form-step ugcify-step-thank-you" data-step="5" style="display: none;">
	<?php if ( $show_thank_you_title ) : ?>
		<h2
			class="ugcify-step-thank-title"
			style="color: <?php echo esc_attr( $thank_you_title_color ); ?>; font-size: <?php echo esc_attr( $thank_you_title_size ); ?>px; font-weight: <?php echo esc_attr( $thank_you_title_weight ); ?>;"
		>
			<?php echo esc_html( $thank_you_title_text ); ?>
		</h2>
	<?php endif; ?>

	<?php if ( $show_thank_you_subtitle ) : ?>
		<p
			class="ugcify-thank-you-subtitle"
			style="color: <?php echo esc_attr( $thank_you_subtitle_color ); ?>; font-size: <?php echo esc_attr( $thank_you_subtitle_size ); ?>px; font-weight: <?php echo esc_attr( $thank_you_subtitle_weight ); ?>;"
		>
			<?php echo esc_html( $thank_you_subtitle_text ); ?>
		</p>
	<?php endif; ?>

	<button
		type="button"
		class="ugcify-button ugcify-button-primary ugcify-modal-close-btn"
		style="background: <?php echo esc_attr( $thank_you_button_fill_color ); ?>; border-color: <?php echo esc_attr( $thank_you_button_stroke_color ); ?>; color: <?php echo esc_attr( $thank_you_button_font_color ); ?>;"
	>
		<?php echo esc_html( $thank_you_button_text ); ?>
	</button>
</div>
