<?php
/**
 * View: Widget Appearance metabox.
 *
 * @package Ilabs\Firevert\Modules\PromoTimeWidget
 *
 * @var WP_Post $post
 * @var string  $firevert_promo_time_widget_text
 * @var string  $firevert_promo_time_widget_background
 * @var string  $firevert_promo_time_widget_accent_color
 * @var string  $firevert_promo_time_widget_primary_text
 * @var string  $firevert_promo_time_widget_counter_background
 * @var string  $firevert_promo_time_widget_counter_text
 * @var bool    $firevert_promo_time_widget_add_shadow
 * @var int     $firevert_promo_time_widget_border_radius
 */

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

use Ilabs\Firevert\Core\Services\Helper\Integration\LanguageHelper;
use Ilabs\Firevert\Modules\PromoTimeWidget\Services\Type\SectionType;

firevert_view(
	'_partials/language-switcher.view.php',
	array(
		'languages' => LanguageHelper::get_available_languages(),
		'current'   => LanguageHelper::get_active_region_code(),
	)
);
?>

<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" class="firevert-form">
	<?php wp_nonce_field( 'firevert_promo_time_widget_save', 'firevert_promo_time_widget_nonce' ); ?>
	<input type="hidden" name="action" value="firevert_save_promo_time_widget">
	<input type="hidden" name="section" value="<?php echo esc_attr( SectionType::APPEARANCE ); ?>">
	<input type="hidden" name="post_ID" value="<?php echo esc_attr( $post->ID ); ?>">

	<div class="metabox-holder woocommerce">

		<div class="postbox wc-metabox">
			<div class="postbox-header">
				<h2 class="hndle">
					<span><?php esc_html_e( 'Widget Text Content', 'firevert' ); ?></span>
				</h2>
			</div>
			<div class="inside">
				<p>
					<label for='firevert_promo_time_widget_text'>
						<?php echo esc_html( firevert_label_with_lang( __( 'Text', 'firevert' ) ) ); ?>
					</label>
				</p>

				<?php
				wp_editor(
					$firevert_promo_time_widget_text,
					'firevert_promo_time_widget_text',
					array(
						'textarea_name' => 'firevert_promo_time_widget_text',
						'textarea_rows' => 4,
						'media_buttons' => false,
						'teeny'         => true,
						'editor_class'  => '',
					)
				);
				?>
			</div>
		</div>

		<div class="postbox wc-metabox">
			<div class="postbox-header">
				<h2 class="hndle">
					<span><?php esc_html_e( 'Color Scheme', 'firevert' ); ?></span>
				</h2>
			</div>
			<div class="inside">
				<?php
				$colors = array(
					'background'         => __( 'Background', 'firevert' ),
					'accent_color'       => __( 'Accent color', 'firevert' ),
					'primary_text'       => __( 'Primary text color', 'firevert' ),
					'counter_background' => __( 'Counter background', 'firevert' ),
					'counter_text'       => __( 'Counter text color', 'firevert' ),
				);

				foreach ( $colors as $suffix => $label ) :
					$key   = 'firevert_promo_time_widget_' . $suffix;
					$value = $$key ?? '';
					?>
					<p>
						<label for="<?php echo esc_attr( $key ); ?>">
							<?php echo esc_html( $label ); ?>
						</label><br/>
						<input type="color" name="<?php echo esc_attr( $key ); ?>"
								id="<?php echo esc_attr( $key ); ?>"
								value="<?php echo esc_attr( $value ); ?>"/>
					</p>
				<?php endforeach; ?>

				<p>
					<label for='firevert_promo_time_widget_border_radius'>
						<?php esc_html_e( 'Border radius (px)', 'firevert' ); ?>
					</label><br/>
					<input type="number" name="firevert_promo_time_widget_border_radius"
						id="firevert_promo_time_widget_border_radius"
						value="<?php echo esc_attr( $firevert_promo_time_widget_border_radius ?? 20 ); ?>"
						min="0" step="1"/>
				</p>

				<p>
					<label>
						<input type="checkbox" name="firevert_promo_time_widget_add_shadow"
								value="1" <?php checked( true, $firevert_promo_time_widget_add_shadow ); ?> />
						<?php esc_html_e( 'Add shadow', 'firevert' ); ?>
					</label>
				</p>
			</div>
		</div>
	</div>

	<?php submit_button( __( 'Save', 'firevert' ) ); ?>
</form>
