<?php

if ( ! function_exists( 'ginevra_core_add_fonts_options' ) ) {
	/**
	 * Function that add options for this module
	 */
	function ginevra_core_add_fonts_options() {
		$qode_framework = qode_framework_get_framework_root();

		$page = $qode_framework->add_options_page(
			array(
				'scope'       => GINEVRA_CORE_OPTIONS_NAME,
				'type'        => 'admin',
				'slug'        => 'fonts',
				'title'       => esc_html__( 'Fonts', 'ginevra-core' ),
				'description' => esc_html__( 'Global Fonts Options', 'ginevra-core' ),
				'icon'        => 'fa fa-cog',
			)
		);

		if ( $page ) {
			$page->add_field_element(
				array(
					'field_type'    => 'yesno',
					'name'          => 'qodef_enable_google_fonts',
					'title'         => esc_html__( 'Enable Google Fonts', 'ginevra-core' ),
					'default_value' => 'yes',
					'args'          => array(
						'custom_class' => 'qodef-enable-google-fonts',
					),
				)
			);

			$google_fonts_section = $page->add_section_element(
				array(
					'name'       => 'qodef_google_fonts_section',
					'title'      => esc_html__( 'Google Fonts Options', 'ginevra-core' ),
					'dependency' => array(
						'show' => array(
							'qodef_enable_google_fonts' => array(
								'values'        => 'yes',
								'default_value' => '',
							),
						),
					),
				)
			);

			$page_repeater = $google_fonts_section->add_repeater_element(
				array(
					'name'        => 'qodef_choose_google_fonts',
					'title'       => esc_html__( 'Google Fonts to Include', 'ginevra-core' ),
					'description' => esc_html__( 'Choose Google Fonts which you want to use on your website', 'ginevra-core' ),
					'button_text' => esc_html__( 'Add New Google Font', 'ginevra-core' ),
				)
			);

			$page_repeater->add_field_element(
				array(
					'field_type'  => 'googlefont',
					'name'        => 'qodef_choose_google_font',
					'title'       => esc_html__( 'Google Font', 'ginevra-core' ),
					'description' => esc_html__( 'Choose Google Font', 'ginevra-core' ),
					'args'        => array(
						'include' => 'google-fonts',
					),
				)
			);

			$google_fonts_section->add_field_element(
				array(
					'field_type'  => 'checkbox',
					'name'        => 'qodef_google_fonts_weight',
					'title'       => esc_html__( 'Google Fonts Weight', 'ginevra-core' ),
					'description' => esc_html__( 'Choose a default Google Fonts weights for your website. Impact on page load time', 'ginevra-core' ),
					'options'     => array(
						'100'  => esc_html__( '100 Thin', 'ginevra-core' ),
						'100i' => esc_html__( '100 Thin Italic', 'ginevra-core' ),
						'200'  => esc_html__( '200 Extra-Light', 'ginevra-core' ),
						'200i' => esc_html__( '200 Extra-Light Italic', 'ginevra-core' ),
						'300'  => esc_html__( '300 Light', 'ginevra-core' ),
						'300i' => esc_html__( '300 Light Italic', 'ginevra-core' ),
						'400'  => esc_html__( '400 Regular', 'ginevra-core' ),
						'400i' => esc_html__( '400 Regular Italic', 'ginevra-core' ),
						'500'  => esc_html__( '500 Medium', 'ginevra-core' ),
						'500i' => esc_html__( '500 Medium Italic', 'ginevra-core' ),
						'600'  => esc_html__( '600 Semi-Bold', 'ginevra-core' ),
						'600i' => esc_html__( '600 Semi-Bold Italic', 'ginevra-core' ),
						'700'  => esc_html__( '700 Bold', 'ginevra-core' ),
						'700i' => esc_html__( '700 Bold Italic', 'ginevra-core' ),
						'800'  => esc_html__( '800 Extra-Bold', 'ginevra-core' ),
						'800i' => esc_html__( '800 Extra-Bold Italic', 'ginevra-core' ),
						'900'  => esc_html__( '900 Ultra-Bold', 'ginevra-core' ),
						'900i' => esc_html__( '900 Ultra-Bold Italic', 'ginevra-core' ),
					),
				)
			);

			$google_fonts_section->add_field_element(
				array(
					'field_type'  => 'checkbox',
					'name'        => 'qodef_google_fonts_subset',
					'title'       => esc_html__( 'Google Fonts Style', 'ginevra-core' ),
					'description' => esc_html__( 'Choose a default Google Fonts style for your website. Impact on page load time', 'ginevra-core' ),
					'options'     => array(
						'latin'        => esc_html__( 'Latin', 'ginevra-core' ),
						'latin-ext'    => esc_html__( 'Latin Extended', 'ginevra-core' ),
						'cyrillic'     => esc_html__( 'Cyrillic', 'ginevra-core' ),
						'cyrillic-ext' => esc_html__( 'Cyrillic Extended', 'ginevra-core' ),
						'greek'        => esc_html__( 'Greek', 'ginevra-core' ),
						'greek-ext'    => esc_html__( 'Greek Extended', 'ginevra-core' ),
						'vietnamese'   => esc_html__( 'Vietnamese', 'ginevra-core' ),
					),
				)
			);

			$page_repeater = $page->add_repeater_element(
				array(
					'name'        => 'qodef_custom_fonts',
					'title'       => esc_html__( 'Custom Fonts', 'ginevra-core' ),
					'description' => esc_html__( 'Add custom fonts', 'ginevra-core' ),
					'button_text' => esc_html__( 'Add New Custom Font', 'ginevra-core' ),
				)
			);

			$page_repeater->add_field_element(
				array(
					'field_type' => 'file',
					'name'       => 'qodef_custom_font_ttf',
					'title'      => esc_html__( 'Custom Font TTF', 'ginevra-core' ),
					'args'       => array(
						'allowed_type' => 'application/octet-stream',
					),
				)
			);

			$page_repeater->add_field_element(
				array(
					'field_type' => 'file',
					'name'       => 'qodef_custom_font_otf',
					'title'      => esc_html__( 'Custom Font OTF', 'ginevra-core' ),
					'args'       => array(
						'allowed_type' => 'application/octet-stream',
					),
				)
			);

			$page_repeater->add_field_element(
				array(
					'field_type' => 'file',
					'name'       => 'qodef_custom_font_woff',
					'title'      => esc_html__( 'Custom Font WOFF', 'ginevra-core' ),
					'args'       => array(
						'allowed_type' => 'application/octet-stream',
					),
				)
			);

			$page_repeater->add_field_element(
				array(
					'field_type' => 'file',
					'name'       => 'qodef_custom_font_woff2',
					'title'      => esc_html__( 'Custom Font WOFF2', 'ginevra-core' ),
					'args'       => array(
						'allowed_type' => 'application/octet-stream',
					),
				)
			);

			$page_repeater->add_field_element(
				array(
					'field_type' => 'text',
					'name'       => 'qodef_custom_font_name',
					'title'      => esc_html__( 'Custom Font Name', 'ginevra-core' ),
				)
			);

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

	add_action( 'ginevra_core_action_default_options_init', 'ginevra_core_add_fonts_options', ginevra_core_get_admin_options_map_position( 'fonts' ) );
}
