<?php
/**
 * View: Widget Settings metabox (Woo-style layout).
 *
 * @package Ilabs\Firevert\Modules\PromoTimeWidget
 *
 * @var WP_Post $post
 * @var string  $firevert_promo_time_widget_name
 * @var string  $firevert_promo_time_widget_coupon
 * @var bool    $firevert_promo_time_widget_visible_admin_only
 * @var string  $firevert_promo_time_widget_display_position
 * @var string  $firevert_promo_time_widget_display_start
 * @var string  $firevert_promo_time_widget_display_end
 * @var bool    $firevert_promo_time_widget_display_counter
 */

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

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

$positions = PositionType::get_all();

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::SETTINGS ); ?>">
	<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( 'General Display Settings', 'firevert' ); ?></span>
				</h2>
			</div>
			<div class="inside">

				<p>
					<label for="firevert_promo_time_widget_name">
						<?php echo esc_html( firevert_label_with_lang( __( 'Name', 'firevert' ) ) ); ?>
					</label><br/>
					<input type="text" name="firevert_promo_time_widget_name" id="firevert_promo_time_widget_name"
							value="<?php echo esc_attr( $firevert_promo_time_widget_name ); ?>" />
				</p>

				<p>
					<label for="firevert_promo_time_widget_coupon">
						<?php esc_html_e( 'Coupon (linked in Coupons tab)', 'firevert' ); ?>
					</label><br/>
					<input type="text" name="firevert_promo_time_widget_coupon" id="firevert_promo_time_widget_coupon"
							value="<?php echo esc_attr( $firevert_promo_time_widget_coupon ); ?>" />
				</p>

				<p>
					<label>
						<input type="checkbox" name="firevert_promo_time_widget_visible_admin_only"
								value="1" <?php checked( true, $firevert_promo_time_widget_visible_admin_only ); ?> />
						<?php esc_html_e( 'Visibility for admin only', 'firevert' ); ?>
					</label>
				</p>

				<p>
					<label for="firevert_promo_time_widget_display_position">
						<?php esc_html_e( 'Widget display position', 'firevert' ); ?>
					</label><br/>
					<select name="firevert_promo_time_widget_display_position" id="firevert_promo_time_widget_display_position">
						<?php foreach ( $positions as $value => $label ) : ?>
							<option value="<?php echo esc_attr( $value ); ?>" <?php selected( $firevert_promo_time_widget_display_position, $value ); ?>>
								<?php echo esc_html( $label ); ?>
							</option>
						<?php endforeach; ?>
					</select>
				</p>

			</div>
		</div>

		<div class="postbox wc-metabox">
			<div class="postbox-header">
				<h2 class="hndle">
					<span><?php esc_html_e( 'Set widget display date', 'firevert' ); ?></span>
				</h2>
			</div>
			<div class="inside">
				<p>
					<label>
						<input type='checkbox' name='firevert_promo_time_widget_display_counter'
								value='1' <?php checked( true, $firevert_promo_time_widget_display_counter ); ?> />
						<?php esc_html_e( 'Display counter on widget', 'firevert' ); ?>
					</label>
				</p>

				<p>
					<label for="firevert_promo_time_widget_display_start">
						<?php esc_html_e( 'Start date', 'firevert' ); ?>
					</label><br/>
					<input type="datetime-local" name="firevert_promo_time_widget_display_start"
							id="firevert_promo_time_widget_display_start"
							value="<?php echo esc_attr( $firevert_promo_time_widget_display_start ); ?>" />
				</p>

				<p>
					<label for="firevert_promo_time_widget_display_end">
						<?php esc_html_e( 'End date', 'firevert' ); ?>
					</label><br/>
					<input type="datetime-local" name="firevert_promo_time_widget_display_end"
							id="firevert_promo_time_widget_display_end"
							value="<?php echo esc_attr( $firevert_promo_time_widget_display_end ); ?>" />
				</p>
			</div>
		</div>
	</div>

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