<?php
/**
 * This file contains SplendorStudio accessibility features.
 *
 * @package SplendorStudio\Framework\API\HTML
 *
 * @since   1.5.0
 */

/**
 * Build the skip links.
 *
 * @since 1.5.0
 *
 * @return void
 */
function fancify_lite_build_skip_links() {
	$skip_links = array();
	$layout     = fancify_lite_get_layout();

	$skip_links['fancify-content'] = __( 'Skip to the content.', 'fancify-lite' );

	if ( 'c' !== $layout ) {

		if ( fancify_lite_has_primary_sidebar( $layout ) ) {
			$skip_links['fancify-primary-sidebar'] = __( 'Skip to the primary sidebar.', 'fancify-lite' );
		}

		if ( fancify_lite_has_secondary_sidebar( $layout ) ) {
			$skip_links['fancify-secondary-sidebar'] = __( 'Skip to the secondary sidebar.', 'fancify-lite' );
		}
	}

	/**
	 * Filter the skip links.
	 *
	 * @since 1.5.0
	 *
	 * @param array $skip_links {
	 *     Default skip links.
	 *
	 *     @type string HTML ID attribute value to link to.
	 *     @type string Anchor text.
	 * }
	 */
	$skip_links = (array) apply_filters( 'fancify_lite_skip_links_list', $skip_links );

	fancify_lite_output_skip_links( $skip_links );
}

/**
 * Skip links output.
 *
 * @since 1.5.0
 *
 * @param array $skip_links Array of skip links to render.
 *
 * @return void
 */
function fancify_lite_output_skip_links( array $skip_links ) {
	fancify_lite_open_markup_e( 'fancify_lite_skip_links_list', 'ul', array( 'class' => 'fancify-skip-links' ) );

	foreach ( $skip_links as $link => $link_name ) {
		fancify_lite_open_markup_e( 'fancify_lite_skip_links_item', 'li' );

			fancify_lite_open_markup_e(
				'fancify_lite_skip_links_item_link',
				'a',
				array(
					'href'  => '#' . $link,
					'class' => 'screen-reader-shortcut skip-link screen-reader-text',
					'tabindex' => '1'
				)
			);

				echo esc_html( $link_name );

			fancify_lite_close_markup_e( 'fancify_lite_skip_links_item', 'a' );

		fancify_lite_close_markup_e( 'fancify_lite_skip_links_item', 'li' );
	}
	fancify_lite_close_markup_e( 'fancify_lite_skiplinks', 'ul' );
}


Fancify_Lite_Actions::add_smart_action( 'fancify_lite_accessibility_enqueue_skip_link_fix', 'fancify_lite_accessibility_skip_link_fix' );
/**
 * Enqueue the JavaScript fix for Internet Explorer 11
 *
 * @since 1.5.0
 *
 * return void
 */
function fancify_lite_accessibility_skip_link_fix() {
	$js = FANCIFY_API_URL . 'html/assets/js/skip-link-fix' . FANCIFY_MIN_JS . '.js';
	wp_enqueue_script( 'fancify-skip-link-fix', $js, array(), FANCIFY_VERSION );
}
