<?php
/**
 * Adds the theme options sections, settings, and controls to the theme customizer
 *
 * @package Weddi_Pro
 */

class Weddi_Pro_Theme_Options {
	public function __construct() {
		// Register our Panel.
		add_action( 'customize_register', array( $this, 'add_panel' ) );

		// Register Breadcrumb Options.
		add_action( 'customize_register', array( $this, 'register_breadcrumb_options' ) );

		// Register Excerpt Options.
		add_action( 'customize_register', array( $this, 'register_excerpt_options' ) );

		// Register Homepage Options.
		add_action( 'customize_register', array( $this, 'register_homepage_options' ) );

		// Register Layout Options.
		add_action( 'customize_register', array( $this, 'register_layout_options' ) );

		// Register Search Options.
		add_action( 'customize_register', array( $this, 'register_search_options' ) );

		// Add default options.
		add_filter( 'weddi_pro_customizer_defaults', array( $this, 'add_defaults' ) );
	}

	/**
	 * Add options to defaults
	 */
	public function add_defaults( $default_options ) {
		$defaults = array(
			// Header Media.
			'weddi_pro_header_image_visibility' => 'entire-site',

			// Breadcrumb
			'weddi_pro_breadcrumb_show' => 1,

			// Layout Options.
			'weddi_pro_default_layout'          => 'right-sidebar',
			'weddi_pro_homepage_archive_layout' => 'no-sidebar-full-width',

			// Excerpt Options
			'weddi_pro_excerpt_length'    => 30,
			'weddi_pro_excerpt_more_text' => esc_html__( 'Continue reading', 'weddi-pro' ),

			// Footer Options.
			'weddi_pro_footer_editor_style'      => 'one-column',
			'weddi_pro_footer_editor_text'       => sprintf( _x( 'Copyright &copy; %1$s %2$s. All Rights Reserved. %3$s', '1: Year, 2: Site Title with home URL, 3: Privacy Policy Link', 'weddi-pro' ), '[the-year]', '[site-link]', '[privacy-policy-link]' ) . ' &#124; ' . esc_html__( 'Weddi Proby', 'weddi-pro' ). '&nbsp;<a target="_blank" href="'. esc_url( 'https://netnus.com' ) .'">Netnus</a>',
			'weddi_pro_footer_editor_text_left'  => sprintf( _x( 'Copyright &copy; %1$s %2$s. All Rights Reserved. %3$s', '1: Year, 2: Site Title with home URL, 3: Privacy Policy Link', 'weddi-pro' ), '[the-year]', '[site-link]', '[privacy-policy-link]' ),
			'weddi_pro_footer_editor_text_right' => esc_html__( 'Weddi Proby', 'weddi-pro' ). '&nbsp;<a target="_blank" href="'. esc_url( 'https://netnus.com' ) .'">Netnus</a>',

			// Homepage/Frontpage Options.
			'weddi_pro_front_page_category'   => '',
			'weddi_pro_show_homepage_content' => 1,

			// Search Options.
			'weddi_pro_search_text'         => esc_html__( 'Search...', 'weddi-pro' ),
		);


		$updated_defaults = wp_parse_args( $defaults, $default_options );

		return $updated_defaults;
	}

	/**
	 * Register the Customizer panels
	 */
	public function add_panel( $wp_customize ) {
		/**
		 * Add our Header & Navigation Panel
		 */
		 $wp_customize->add_panel( 'weddi_pro_theme_options',
		 	array(
				'title' => esc_html__( 'Theme Options', 'weddi-pro' ),
			)
		);
	}

	/**
	 * Add breadcrumb section and its controls
	 */
	public function register_breadcrumb_options( $wp_customize ) {
		// Add Excerpt Options section.
		$wp_customize->add_section( 'weddi_pro_breadcrumb_options',
			array(
				'title' => esc_html__( 'Breadcrumb', 'weddi-pro' ),
				'panel' => 'weddi_pro_theme_options',
			)
		);

		if ( function_exists( 'bcn_display' ) ) {
			Weddi_Pro_Customizer_Utilities::register_option(
				array(
					'custom_control'    => 'Weddi_Pro_Simple_Notice_Custom_Control',
					'sanitize_callback' => 'sanitize_text_field',
					'settings'          => 'ff_multiputpose_breadcrumb_plugin_notice',
					'label'             =>  esc_html__( 'Info', 'weddi-pro' ),
					'description'       =>  sprintf( esc_html__( 'Since Breadcrumb NavXT Plugin is installed, edit plugin\'s settings %1$shere%2$s', 'weddi-pro' ), '<a href="' . esc_url( get_admin_url( null, 'options-general.php?page=breadcrumb-navxt' ) ) . '" target="_blank">', '</a>' ),
					'section'           => 'ff_multiputpose_breadcrumb_options',
				)
			);

			return;
		}

		Weddi_Pro_Customizer_Utilities::register_option(
			array(
				'custom_control'    => 'Weddi_Pro_Toggle_Switch_Custom_control',
				'settings'          => 'weddi_pro_breadcrumb_show',
				'sanitize_callback' => 'weddi_pro_switch_sanitization',
				'label'             => esc_html__( 'Display Breadcrumb?', 'weddi-pro' ),
				'section'           => 'weddi_pro_breadcrumb_options',
			)
		);

		Weddi_Pro_Customizer_Utilities::register_option(
			array(
				'custom_control'    => 'Weddi_Pro_Toggle_Switch_Custom_control',
				'settings'          => 'weddi_pro_breadcrumb_show_home',
				'sanitize_callback' => 'weddi_pro_switch_sanitization',
				'label'             => esc_html__( 'Show on homepage?', 'weddi-pro' ),
				'section'           => 'weddi_pro_breadcrumb_options',
			)
		);
	}

	/**
	 * Add layouts section and its controls
	 */
	public function register_layout_options( $wp_customize ) {
		// Add layouts section.
		$wp_customize->add_section( 'weddi_pro_layouts',
			array(
				'title' => esc_html__( 'Layouts', 'weddi-pro' ),
				'panel' => 'weddi_pro_theme_options'
			)
		);

		Weddi_Pro_Customizer_Utilities::register_option(
			array(
				'type'              => 'select',
				'settings'          => 'weddi_pro_default_layout',
				'sanitize_callback' => 'weddi_pro_sanitize_select',
				'label'             => esc_html__( 'Default Layout', 'weddi-pro' ),
				'section'           => 'weddi_pro_layouts',
				'choices'           => array(
					'right-sidebar'         => esc_html__( 'Right Sidebar', 'weddi-pro' ),
					'no-sidebar-full-width' => esc_html__( 'No Sidebar: Full Width', 'weddi-pro' ),
				),
			)
		);

		Weddi_Pro_Customizer_Utilities::register_option(
			array(
				'type'              => 'select',
				'settings'          => 'weddi_pro_homepage_archive_layout',
				'sanitize_callback' => 'weddi_pro_sanitize_select',
				'label'             => esc_html__( 'Homepage/Archive Layout', 'weddi-pro' ),
				'section'           => 'weddi_pro_layouts',
				'choices'           => array(
					'right-sidebar'         => esc_html__( 'Right Sidebar', 'weddi-pro' ),
					'no-sidebar-full-width' => esc_html__( 'No Sidebar: Full Width', 'weddi-pro' ),
				),
			)
		);
	}

	/**
	 * Add excerpt section and its controls
	 */
	public function register_excerpt_options( $wp_customize ) {
		// Add Excerpt Options section.
		$wp_customize->add_section( 'weddi_pro_excerpt_options',
			array(
				'title' => esc_html__( 'Excerpt Options', 'weddi-pro' ),
				'panel' => 'weddi_pro_theme_options',
			)
		);

		Weddi_Pro_Customizer_Utilities::register_option(
			array(
				'type'              => 'number',
				'settings'          => 'weddi_pro_excerpt_length',
				'sanitize_callback' => 'absint',
				'label'             => esc_html__( 'Excerpt Length (Words)', 'weddi-pro' ),
				'section'           => 'weddi_pro_excerpt_options',
			)
		);

		Weddi_Pro_Customizer_Utilities::register_option(
			array(
				'type'              => 'text',
				'settings'          => 'weddi_pro_excerpt_more_text',
				'sanitize_callback' => 'sanitize_text_field',
				'label'             => esc_html__( 'Excerpt More Text', 'weddi-pro' ),
				'section'           => 'weddi_pro_excerpt_options',
			)
		);
	}

	/**
	 * Add Homepage/Frontpage section and its controls
	 */
	public function register_homepage_options( $wp_customize ) {
		Weddi_Pro_Customizer_Utilities::register_option(
			array(
				'custom_control'    => 'Weddi_Pro_Dropdown_Select2_Custom_Control',
				'sanitize_callback' => 'weddi_pro_text_sanitization',
				'settings'          => 'weddi_pro_front_page_category',
				'description'       => esc_html__( 'Filter Homepage/Blog page posts by following categories', 'weddi-pro' ),
				'label'             => esc_html__( 'Categories', 'weddi-pro' ),
				'section'           => 'static_front_page',
				'input_attrs'       => array(
					'multiselect' => true,
				),
				'choices'           => array( esc_html__( '--Select--', 'weddi-pro' ) => Weddi_Pro_Customizer_Utilities::get_terms( 'category' ) ),
			)
		);

		Weddi_Pro_Customizer_Utilities::register_option(
			array(
				'custom_control'    => 'Weddi_Pro_Toggle_Switch_Custom_control',
				'settings'          => 'weddi_pro_show_homepage_content',
				'sanitize_callback' => 'weddi_pro_switch_sanitization',
				'label'             => esc_html__( 'Show Home Content/Blog', 'weddi-pro' ),
				'section'           => 'static_front_page',
			)
		);
	}

	/**
	 * Add Homepage/Frontpage section and its controls
	 */
	public function register_search_options( $wp_customize ) {
		// Add Homepage/Frontpage Section.
		$wp_customize->add_section( 'weddi_pro_search',
			array(
				'title' => esc_html__( 'Search', 'weddi-pro' ),
				'panel' => 'weddi_pro_theme_options',
			)
		);

		Weddi_Pro_Customizer_Utilities::register_option(
			array(
				'settings'          => 'weddi_pro_search_text',
				'sanitize_callback' => 'weddi_pro_text_sanitization',
				'label'             => esc_html__( 'Search Text', 'weddi-pro' ),
				'section'           => 'weddi_pro_search',
				'type'              => 'text',
			)
		);
	}
}

/**
 * Initialize class
 */
$weddi_pro_theme_options = new Weddi_Pro_Theme_Options();
