<?php
/**
 * StickyHeader.
 *
 * @package MadeByAura\Prime\Customizer\Fields
 * @author  MadeByAura.com
 */

namespace MadeByAura\Prime\Customizer\Fields;

use MadeByAura\Prime\Customizer\Modules\Add;
use MadeByAura\Prime\Customizer\Modules\Value;
use MadeByAura\Prime\Helpers\SingletonTrait;

defined( 'ABSPATH' ) || die();

/**
 * StickyHeader.
 */
class StickyHeader {
	use SingletonTrait;

	/**
	 * Constructor.
	 */
	protected function __construct() {
		add_action( 'after_setup_theme', [ __CLASS__, 'add_section' ] );
	}

	/**
	 * Add section.
	 */
	public static function add_section() {
		$section  = 'sticky_header';
		$priority = 10;

		// Section.
		Add::section(
			$section,
			[
				'title'    => esc_attr__( 'Sticky Header', 'aura-prime' ),
				'priority' => 0,
			],
		);

		// Enable.
		$id       = 'enabled';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'   => esc_attr__( 'Enable sticky header', 'aura-prime' ),
				'type'    => 'checkbox',
				'default' => Value::get_default( $section, $id ),
			],
		);

		// Resent selector.
		$id       = 'resent_selector';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'           => esc_attr__( 'Resent selector', 'aura-prime' ),
				'type'            => 'text',
				'description'     => __( 'Target used in Intersection Observer API.', 'aura-prime' ),
				'default'         => Value::get_default( $section, $id ),
				'active_callback' => [
					[
						'setting'  => "aura_{$section}_enabled",
						'operator' => '!=',
						'value'    => false,
					],
				],
			],
		);

		// Resent threshold.
		$id       = 'resent_threshold';
		$priority = Add::field(
			$section,
			$id,
			$priority,
			[
				'label'           => esc_attr__( 'Resent threshold', 'aura-prime' ),
				'description'     => __( 'Threshold used in Intersection Observer API.', 'aura-prime' ),
				'type'            => 'slider',
				'default'         => Value::get_default( $section, $id ),
				'choices'         => [
					'min'  => 0,
					'max'  => 1,
					'step' => 0.1,
				],
				'active_callback' => [
					[
						'setting'  => "aura_{$section}_enabled",
						'operator' => '!=',
						'value'    => false,
					],
				],
			],
		);
	}
}
