<?php

if ( ! function_exists( 'ginevra_core_add_general_page_meta_box' ) ) {
	/**
	 * Function that add general meta box options for this module
	 *
	 * @param object $page
	 */
	function ginevra_core_add_general_page_meta_box( $page ) {

		$general_tab = $page->add_tab_element(
			array(
				'name'        => 'tab-page',
				'icon'        => 'fa fa-cog',
				'title'       => esc_html__( 'Page Settings', 'ginevra-core' ),
				'description' => esc_html__( 'General page layout settings', 'ginevra-core' ),
			)
		);

		$general_tab->add_field_element(
			array(
				'field_type'  => 'color',
				'name'        => 'qodef_page_background_color',
				'title'       => esc_html__( 'Page Background Color', 'ginevra-core' ),
				'description' => esc_html__( 'Set background color', 'ginevra-core' ),
			)
		);

		$general_tab->add_field_element(
			array(
				'field_type'  => 'image',
				'name'        => 'qodef_page_background_image',
				'title'       => esc_html__( 'Page Background Image', 'ginevra-core' ),
				'description' => esc_html__( 'Set background image', 'ginevra-core' ),
			)
		);

		$general_tab->add_field_element(
			array(
				'field_type'  => 'select',
				'name'        => 'qodef_page_background_repeat',
				'title'       => esc_html__( 'Page Background Image Repeat', 'ginevra-core' ),
				'description' => esc_html__( 'Set background image repeat', 'ginevra-core' ),
				'options'     => array(
					''          => esc_html__( 'Default', 'ginevra-core' ),
					'no-repeat' => esc_html__( 'No Repeat', 'ginevra-core' ),
					'repeat'    => esc_html__( 'Repeat', 'ginevra-core' ),
					'repeat-x'  => esc_html__( 'Repeat-x', 'ginevra-core' ),
					'repeat-y'  => esc_html__( 'Repeat-y', 'ginevra-core' ),
				),
			)
		);

		$general_tab->add_field_element(
			array(
				'field_type'  => 'select',
				'name'        => 'qodef_page_background_size',
				'title'       => esc_html__( 'Page Background Image Size', 'ginevra-core' ),
				'description' => esc_html__( 'Set background image size', 'ginevra-core' ),
				'options'     => array(
					''        => esc_html__( 'Default', 'ginevra-core' ),
					'contain' => esc_html__( 'Contain', 'ginevra-core' ),
					'cover'   => esc_html__( 'Cover', 'ginevra-core' ),
				),
			)
		);

		$general_tab->add_field_element(
			array(
				'field_type'  => 'select',
				'name'        => 'qodef_page_background_attachment',
				'title'       => esc_html__( 'Page Background Image Attachment', 'ginevra-core' ),
				'description' => esc_html__( 'Set background image attachment', 'ginevra-core' ),
				'options'     => array(
					''       => esc_html__( 'Default', 'ginevra-core' ),
					'fixed'  => esc_html__( 'Fixed', 'ginevra-core' ),
					'scroll' => esc_html__( 'Scroll', 'ginevra-core' ),
				),
			)
		);

		$general_tab->add_field_element(
			array(
				'field_type'  => 'text',
				'name'        => 'qodef_page_content_padding',
				'title'       => esc_html__( 'Page Content Padding', 'ginevra-core' ),
				'description' => esc_html__( 'Set padding that will be applied for page content in format: top right bottom left (e.g. 10px 5px 10px 5px)', 'ginevra-core' ),
			)
		);

		$general_tab->add_field_element(
			array(
				'field_type'  => 'text',
				'name'        => 'qodef_page_content_padding_mobile',
				'title'       => esc_html__( 'Page Content Padding Mobile', 'ginevra-core' ),
				'description' => esc_html__( 'Set padding that will be applied for page content on mobile screens (1024px and below) in format: top right bottom left (e.g. 10px 5px 10px 5px)', 'ginevra-core' ),
			)
		);

		$general_tab->add_field_element(
			array(
				'field_type'    => 'select',
				'name'          => 'qodef_boxed',
				'title'         => esc_html__( 'Boxed Layout', 'ginevra-core' ),
				'description'   => esc_html__( 'Set boxed layout', 'ginevra-core' ),
				'default_value' => '',
				'options'       => ginevra_core_get_select_type_options_pool( 'yes_no' ),
			)
		);

		$boxed_section = $general_tab->add_section_element(
			array(
				'name'       => 'qodef_boxed_section',
				'title'      => esc_html__( 'Boxed Layout Section', 'ginevra-core' ),
				'dependency' => array(
					'hide' => array(
						'qodef_boxed' => array(
							'values'        => 'no',
							'default_value' => '',
						),
					),
				),
			)
		);

		$boxed_section->add_field_element(
			array(
				'field_type'  => 'color',
				'name'        => 'qodef_boxed_background_color',
				'title'       => esc_html__( 'Boxed Background Color', 'ginevra-core' ),
				'description' => esc_html__( 'Set boxed background color', 'ginevra-core' ),
			)
		);

		$boxed_section->add_field_element(
			array(
				'field_type'  => 'image',
				'name'        => 'qodef_boxed_background_pattern',
				'title'       => esc_html__( 'Boxed Background Pattern', 'ginevra-core' ),
				'description' => esc_html__( 'Set boxed background pattern', 'ginevra-core' ),
			)
		);

		$boxed_section->add_field_element(
			array(
				'field_type'  => 'select',
				'name'        => 'qodef_boxed_background_pattern_behavior',
				'title'       => esc_html__( 'Boxed Background Pattern Behavior', 'ginevra-core' ),
				'description' => esc_html__( 'Set boxed background pattern behavior', 'ginevra-core' ),
				'options'     => array(
					''       => esc_html__( 'Default', 'ginevra-core' ),
					'fixed'  => esc_html__( 'Fixed', 'ginevra-core' ),
					'scroll' => esc_html__( 'Scroll', 'ginevra-core' ),
				),
			)
		);

		$general_tab->add_field_element(
			array(
				'field_type'    => 'select',
				'name'          => 'qodef_passepartout',
				'title'         => esc_html__( 'Passepartout', 'ginevra-core' ),
				'description'   => esc_html__( 'Enabling this option will display a passepartout around website content', 'ginevra-core' ),
				'default_value' => '',
				'options'       => ginevra_core_get_select_type_options_pool( 'yes_no' ),
			)
		);

		$passepartout_section = $general_tab->add_section_element(
			array(
				'name'       => 'qodef_passepartout_section',
				'dependency' => array(
					'hide' => array(
						'qodef_passepartout' => array(
							'values'        => 'no',
							'default_value' => '',
						),
					),
				),
			)
		);

		$passepartout_section->add_field_element(
			array(
				'field_type'  => 'color',
				'name'        => 'qodef_passepartout_color',
				'title'       => esc_html__( 'Passepartout Color', 'ginevra-core' ),
				'description' => esc_html__( 'Choose background color for passepartout', 'ginevra-core' ),
			)
		);

		$passepartout_section->add_field_element(
			array(
				'field_type'  => 'image',
				'name'        => 'qodef_passepartout_image',
				'title'       => esc_html__( 'Passepartout Background Image', 'ginevra-core' ),
				'description' => esc_html__( 'Set background image for passepartout', 'ginevra-core' ),
			)
		);

		$passepartout_section->add_field_element(
			array(
				'field_type'  => 'text',
				'name'        => 'qodef_passepartout_size',
				'title'       => esc_html__( 'Passepartout Size', 'ginevra-core' ),
				'description' => esc_html__( 'Enter size amount for passepartout', 'ginevra-core' ),
				'args'        => array(
					'suffix' => esc_html__( 'px or %', 'ginevra-core' ),
				),
			)
		);

		$passepartout_section->add_field_element(
			array(
				'field_type'  => 'text',
				'name'        => 'qodef_passepartout_size_responsive',
				'title'       => esc_html__( 'Passepartout Responsive Size', 'ginevra-core' ),
				'description' => esc_html__( 'Enter size amount for passepartout for smaller screens (1024px and below)', 'ginevra-core' ),
				'args'        => array(
					'suffix' => esc_html__( 'px or %', 'ginevra-core' ),
				),
			)
		);

		$general_tab->add_field_element(
			array(
				'field_type'  => 'select',
				'name'        => 'qodef_content_width',
				'title'       => esc_html__( 'Initial Width of Content', 'ginevra-core' ),
				'description' => esc_html__( 'Choose the initial width of content which is in grid (applies to pages set to "Default Template" and rows set to "In Grid")', 'ginevra-core' ),
				'options'     => ginevra_core_get_select_type_options_pool( 'content_width' ),
			)
		);

		$general_tab->add_field_element(
			array(
				'field_type'    => 'yesno',
				'default_value' => 'no',
				'name'          => 'qodef_content_behind_header',
				'title'         => esc_html__( 'Always put content behind header', 'ginevra-core' ),
				'description'   => esc_html__( 'Enabling this option will put page content behind page header', 'ginevra-core' ),
			)
		);

		// Hook to include additional options after module options
		do_action( 'ginevra_core_action_after_general_page_meta_box_map', $general_tab );
	}

	add_action( 'ginevra_core_action_after_general_meta_box_map', 'ginevra_core_add_general_page_meta_box', 9 );
}

if ( ! function_exists( 'ginevra_core_add_general_page_meta_box_callback' ) ) {
	/**
	 * Function that set current meta box callback as general callback functions
	 *
	 * @param array $callbacks
	 *
	 * @return array
	 */
	function ginevra_core_add_general_page_meta_box_callback( $callbacks ) {
		$callbacks['page'] = 'ginevra_core_add_general_page_meta_box';

		return $callbacks;
	}

	add_filter( 'ginevra_core_filter_general_meta_box_callbacks', 'ginevra_core_add_general_page_meta_box_callback' );
}
