<?php

namespace EACCustomWidgets\Admin\Settings;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}
use EACCustomWidgets\Core\Eac_Load_Config;
?>
<form action='' method='POST' id='eac-form-elements' name='eac-form-elements'>
	<!-- Onglet 'Advanced' -->
	<div id='tab-1' style='display: none;'>
		<div class='eac-settings-tabs'>
			<div class='eac-elements__table-common'>
				<?php
				ob_start();
				foreach ( Eac_Load_Config::get_widgets_advanced_active() as $key => $active ) {
					if ( ! Eac_Load_Config::are_widget_dependencies_enabled( $key ) ) {
						continue;
					}

					$widget_title  = Eac_Load_Config::get_widget_title( $key );
					$href          = Eac_Load_Config::get_widget_help_url( $key );
					$href_class    = Eac_Load_Config::get_widget_help_url_class( $key );
					$class_wrapper = 'eac-elements__common-item widgets advanced' . Eac_Load_Config::get_widget_badge_class( $key );
					$readable_key  = ucwords( str_replace( array( '-', '_' ), ' ', $key ) );

					if ( 'all-advanced' === $key ) { ?>
						<div class='eac-elements__table-common header'>
							<div class='eac-elements__common-item header'>
								<span class='eac-elements__item-content header'><?php echo wp_kses_post( $widget_title ); ?></span>
								<span>
									<label class='switch'>
										<input tabindex='-1' aria-hidden='true' type='checkbox' class='ios-switch bigswitch' id="<?php echo esc_attr( $key ); ?>" name="<?php echo esc_attr( $key ); ?>" <?php checked( 1, $active, true ); ?>>
										<div tabindex='0' role='checkbox' <?php checked( 1, $active, true ); ?> aria-label="<?php esc_html_e( 'Enable/Disable advanced components', 'eac-components' ); ?>"><div></div></div>
									</label>
								</span>
							</div>
						</div>
					<?php } else { ?>
						<div class="<?php echo esc_attr( $class_wrapper ); ?>">
							<span class='eac-elements__item-content'><?php echo wp_kses_post( $widget_title ); ?>
								<?php if ( ! empty( $href ) ) : ?>
									<a class='eac-accessible-link' href="<?php echo esc_url( $href ); ?>" target='_blank' rel='noopener noreferrer' aria-label="<?php esc_html_e( 'Open content in a new tab', 'eac-components' ); ?>">
										<span class="<?php echo esc_attr( $href_class ); ?>"></span>
									</a>
								<?php endif; ?>
							</span>
							<span>
								<label class='switch'>
									<input tabindex='-1' aria-hidden='true' type='checkbox' class='ios-switch bigswitch' id="<?php echo esc_attr( $key ); ?>" name="<?php echo esc_attr( $key ); ?>" <?php checked( 1, $active, true ); ?>>
									<div tabindex='0' role='checkbox' <?php checked( 1, $active, true ); ?> aria-label="<?php printf( '%1$s - %2$s', esc_html__( 'Enable/Disable', 'eac-components' ), esc_html( $readable_key ) ); ?>"><div></div></div>
								</label>
							</span>
						</div>
					<?php }
				}
				echo ob_get_clean(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
				?>
			</div> <!-- Table common -->
		</div> <!-- Settings TAB -->
	</div> <!-- TAB 1 -->

	<!-- Onglet 'Basic' -->
	<div id='tab-2' style='display: none;'>
		<div class='eac-settings-tabs'>
			<div class='eac-elements__table-common'>
				<?php
				ob_start();
				foreach ( Eac_Load_Config::get_widgets_common_active() as $key => $active ) {
					if ( ! Eac_Load_Config::are_widget_dependencies_enabled( $key ) ) {
						continue;
					}

					$widget_title  = Eac_Load_Config::get_widget_title( $key );
					$href          = Eac_Load_Config::get_widget_help_url( $key );
					$href_class    = Eac_Load_Config::get_widget_help_url_class( $key );
					$class_wrapper = 'eac-elements__common-item widgets common' . Eac_Load_Config::get_widget_badge_class( $key );
					$readable_key  = ucwords( str_replace( array( '-', '_' ), ' ', $key ) );

					if ( 'all-components' === $key ) { ?>
						<div class='eac-elements__table-common header'>
							<div class='eac-elements__common-item header'>
								<span class='eac-elements__item-content header'><?php echo wp_kses_post( $widget_title ); ?></span>
								<span>
									<label class='switch'>
										<input tabindex='-1' aria-hidden='true' type='checkbox' class='ios-switch bigswitch' id="<?php echo esc_attr( $key ); ?>" name="<?php echo esc_attr( $key ); ?>" <?php checked( 1, $active, true ); ?>>
										<div tabindex='0' role='checkbox' <?php checked( 1, $active, true ); ?> aria-label="<?php esc_html_e( 'Enable/Disable all Common components', 'eac-components' ); ?>"><div></div></div>
									</label>
								</span>
							</div>
						</div>
					<?php } else { ?>
						<div class="<?php echo esc_attr( $class_wrapper ); ?>">
							<span class='eac-elements__item-content'><?php echo wp_kses_post( $widget_title ); ?>
								<?php if ( ! empty( $href ) ) : ?>
									<a class='eac-accessible-link' href="<?php echo esc_url( $href ); ?>" target='_blank' rel='noopener noreferrer' aria-label="<?php esc_html_e( 'Open content in a new tab', 'eac-components' ); ?>">
										<span class="<?php echo esc_attr( $href_class ); ?>"></span>
									</a>
								<?php endif; ?>
							</span>
							<span>
								<label class='switch'>
									<input tabindex='-1' aria-hidden='true' type='checkbox' class='ios-switch bigswitch' id="<?php echo esc_attr( $key ); ?>" name="<?php echo esc_attr( $key ); ?>" <?php checked( 1, $active, true ); ?>>
									<div tabindex='0' role='checkbox' <?php checked( 1, $active, true ); ?> aria-label="<?php printf( '%1$s - %2$s', esc_html__( 'Enable/Disable', 'eac-components' ), esc_html( $readable_key ) ); ?>"><div></div></div>
								</label>
							</span>
						</div>
					<?php }
				}
				echo ob_get_clean(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
				?>
			</div> <!-- Table common -->
		</div> <!-- Settings TAB -->
	</div> <!-- TAB 2 -->

	<!-- Onglet 'Header & Footer ' -->
	<div id='tab-3' style='display: none;'>
		<div class='eac-settings-tabs'>
			<div class='eac-elements__table-common'>
			<?php
			ob_start();
			foreach ( Eac_Load_Config::get_widgets_ehf_active() as $key => $active ) {
				if ( ! Eac_Load_Config::are_widget_dependencies_enabled( $key ) ) {
					continue;
				}

				$widget_title  = Eac_Load_Config::get_widget_title( $key );
				$href          = Eac_Load_Config::get_widget_help_url( $key );
				$href_class    = Eac_Load_Config::get_widget_help_url_class( $key );
				$class_wrapper = 'eac-elements__common-item widgets ehf' . Eac_Load_Config::get_widget_badge_class( $key );
				$readable_key  = ucwords( str_replace( array( '-', '_' ), ' ', $key ) );

				if ( 'all-ehf' === $key ) { ?>
					<div class='eac-elements__table-common header'>
						<div class='eac-elements__common-item header'>
							<span class='eac-elements__item-content header'><?php echo wp_kses_post( $widget_title ); ?></span>
							<span>
								<label class='switch'>
									<input tabindex='-1' aria-hidden='true' type='checkbox' class='ios-switch bigswitch' id="<?php echo esc_attr( $key ); ?>" name="<?php echo esc_attr( $key ); ?>" <?php checked( 1, $active, true ); ?>>
									<div tabindex='0' role='checkbox' <?php checked( 1, $active, true ); ?> aria-label="<?php esc_html_e( 'Enable/Disable all Header/Footer components', 'eac-components' ); ?>"><div></div></div>
								</label>
							</span>
						</div>
					</div>
				<?php } else { ?>
					<div class="<?php echo esc_attr( $class_wrapper ); ?>">
						<span class='eac-elements__item-content'><?php echo wp_kses_post( $widget_title ); ?>
							<?php if ( ! empty( $href ) ) : ?>
								<a class='eac-accessible-link' href="<?php echo esc_url( $href ); ?>" target='_blank' rel='noopener noreferrer' aria-label="<?php esc_html_e( 'Open content in a new tab', 'eac-components' ); ?>">
									<span class="<?php echo esc_attr( $href_class ); ?>"></span>
								</a>
							<?php endif; ?>
						</span>
						<span>
							<label class='switch'>
								<input tabindex='-1' aria-hidden='true' type='checkbox' class='ios-switch bigswitch' id="<?php echo esc_attr( $key ); ?>" name="<?php echo esc_attr( $key ); ?>" <?php checked( 1, $active, true ); ?>>
								<div tabindex='0' role='checkbox' <?php checked( 1, $active, true ); ?> aria-label="<?php printf( '%1$s - %2$s', esc_html__( 'Enable/Disable', 'eac-components' ), esc_html( $readable_key ) ); ?>"><div></div></div>
							</label>
						</span>
					</div>
				<?php }
			}
			echo ob_get_clean(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
			?>
			</div> <!-- Table common -->
		</div> <!-- Settings TAB -->
	</div> <!-- TAB 3 -->

	<!-- Onglet 'Features' -->
	<div id='tab-4' style='display: none;'>
		<div class='eac-settings-tabs'>
			<div class='eac-elements__table-common'>
				<?php
				ob_start();
				foreach ( Eac_Load_Config::get_features_advanced_active() as $key => $active ) {
					if ( ! Eac_Load_Config::are_feature_dependencies_enabled( $key ) ) {
						continue;
					}

					$widget_title  = Eac_Load_Config::get_feature_title( $key );
					$href          = Eac_Load_Config::get_feature_help_url( $key );
					$href_class    = Eac_Load_Config::get_feature_help_url_class( $key );
					$class_wrapper = 'eac-elements__common-item features advanced' . Eac_Load_Config::get_feature_badge_class( $key );

					if ( 'all-features-advanced' === $key ) { ?>
						<div class='eac-elements__table-common header'>
							<div class='eac-elements__common-item header'>
								<span class='eac-elements__item-content header'><?php echo wp_kses_post( $widget_title ); ?></span>
								<span>
									<label class='switch'>
										<input tabindex='-1' aria-hidden='true' type='checkbox' class='ios-switch bigswitch' id="<?php echo esc_attr( $key ); ?>" name="<?php echo esc_attr( $key ); ?>" <?php checked( 1, $active, true ); ?>>
										<div tabindex='0' role='checkbox' <?php checked( 1, $active, true ); ?> aria-label="<?php esc_html_e( 'Enable/Disable all features', 'eac-components' ); ?>"><div></div></div>
									</label>
								</span>
							</div>
						</div>
					<?php } else { ?>
						<div class="<?php echo esc_attr( $class_wrapper ); ?>">
							<span class='eac-elements__item-content'><?php echo wp_kses_post( $widget_title ); ?>
								<?php if ( ! empty( $href ) ) : ?>
									<a class='eac-accessible-link' href="<?php echo esc_url( $href ); ?>" target='_blank' rel='noopener noreferrer' aria-label="<?php esc_html_e( 'Open content in a new tab', 'eac-components' ); ?>">
										<span class="<?php echo esc_attr( $href_class ); ?>"></span>
									</a>
								<?php endif; ?>
							</span>
							<span>
								<label class='switch'>
									<input tabindex='-1' aria-hidden='true' type='checkbox' class='ios-switch bigswitch' id="<?php echo esc_attr( $key ); ?>" name="<?php echo esc_attr( $key ); ?>" <?php checked( 1, $active, true ); ?>>
									<div tabindex='0' role='checkbox' <?php checked( 1, $active, true ); ?> aria-label="<?php printf( '%1$s - %2$s', esc_html__( 'Enable/Disable', 'eac-components' ), esc_html( $widget_title ) ); ?>"><div></div></div>
								</label>
							</span>
						</div>
					<?php }
				}
				echo ob_get_clean(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
				?>
			</div> <!-- Table common -->
		</div> <!-- Settings TAB -->
	</div> <!-- TAB 4 -->

	<!-- Onglet 'WordPress' -->
	<div id='tab-5' style='display: none;'>
		<div class='eac-settings-tabs'>
			<div class='eac-elements__table-common'>
				<?php
				ob_start();
				foreach ( Eac_Load_Config::get_features_common_active() as $key => $active ) {
					if ( ! Eac_Load_Config::are_feature_dependencies_enabled( $key ) ) {
						continue;
					}

					$widget_title  = Eac_Load_Config::get_feature_title( $key );
					$href          = Eac_Load_Config::get_feature_help_url( $key );
					$href_class    = Eac_Load_Config::get_feature_help_url_class( $key );
					$class_wrapper = 'eac-elements__common-item features common' . Eac_Load_Config::get_feature_badge_class( $key );

					if ( 'all-features-common' === $key ) { ?>
						<div class='eac-elements__table-common header'>
							<div class='eac-elements__common-item header'>
								<span class='eac-elements__item-content header'><?php echo wp_kses_post( $widget_title ); ?></span>
								<span>
									<label class='switch'>
										<input tabindex='-1' aria-hidden='true' type='checkbox' class='ios-switch bigswitch' id="<?php echo esc_attr( $key ); ?>" name="<?php echo esc_attr( $key ); ?>" <?php checked( 1, $active, true ); ?>>
										<div tabindex='0' role='checkbox' <?php checked( 1, $active, true ); ?> aria-label="<?php esc_html_e( 'Enable/Disable all WordPress components', 'eac-components' ); ?>"><div></div></div>
									</label>
								</span>
							</div>
						</div>
					<?php } else { ?>
						<div class="<?php echo esc_attr( $class_wrapper ); ?>">
							<span class='eac-elements__item-content'><?php echo wp_kses_post( $widget_title ); ?>
								<?php if ( ! empty( $href ) ) : ?>
									<a class='eac-accessible-link' href="<?php echo esc_url( $href ); ?>" target='_blank' rel='noopener noreferrer' aria-label="<?php esc_html_e( 'Open content in a new tab', 'eac-components' ); ?>">
										<span class="<?php echo esc_attr( $href_class ); ?>"></span>
									</a>
								<?php endif; ?>
							</span>
							<span>
								<label class='switch'>
									<input tabindex='-1' aria-hidden='true' type='checkbox' class='ios-switch bigswitch' id="<?php echo esc_attr( $key ); ?>" name="<?php echo esc_attr( $key ); ?>" <?php checked( 1, $active, true ); ?>>
									<div tabindex='0' role='checkbox' <?php checked( 1, $active, true ); ?> aria-label="<?php printf( '%1$s - %2$s', esc_html__( 'Enable/Disable', 'eac-components' ), esc_html( $widget_title ) ); ?>"><div></div></div>
								</label>
							</span>
						</div>
					<?php }
				}
				echo ob_get_clean(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
				?>
			</div> <!-- Table common -->
		</div> <!-- Settings TAB -->
	</div> <!-- TAB 5 -->

	<div class='eac-saving-box'>
		<div id='eac-elements-to-save'><?php esc_html_e( 'You need to save the settings', 'eac-components' ); ?></div>
		<input id='eac-submit' type='submit' value="<?php esc_html_e( 'Save changes', 'eac-components' ); ?>">
		<div id='eac-elements-saved'></div>
		<div id='eac-elements-notsaved'></div>
	</div>
</form>
