<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}
if ( ! class_exists( 'Draly_Dropshipping_Starter_Theme_Option' ) ) {
	class Draly_Dropshipping_Starter_Theme_Option {
		/**
		 * Variable to hold the initialization state.
		 *
		 * @var  boolean
		 */
		protected static $initialized = false;
		public static $args = array();
		public static $sections = array();
		public static $theme;
		public static $ReduxFramework;

		public function __construct() {
			self::initialize();
		}

		public static function initialize() {
			// Prevent re-initialization
			if ( self::$initialized ) {
				return;
			}
			add_action( 'init', array( __CLASS__, 'init_theme_options' ) );
			self::$initialized = true;
		}

		public static function init_theme_options() {
			self::$theme = wp_get_theme();
			self::set_arguments();
			self::set_sections();
			self::$ReduxFramework = new ReduxFramework( self::$sections, self::$args );
		}

		public static function set_arguments() {
			self::$args = array(
				// TYPICAL -> Change these values as you need/desire
				'opt_name'            => 'villco',
				// This is where your data is stored in the database and also becomes your global variable name.
				'display_name'        => '<span class="theme-name">' . self::$theme->get( 'Name' ) . '</span>',
				// Name that appears at the top of your panel
				'display_version'     => self::$theme->get( 'Version' ),
				// Version that appears at the top of your panel
				'menu_type'           => 'submenu',
				//Specify if the admin menu should appear or not. Options: menu or submenu (Under appearance only)
				'allow_sub_menu'      => false,
				// Show the sections below the admin menu item or not
				'menu_title'          => esc_html__( 'Theme Options', 'draly-dropshipping-starter' ),
				'page_title'          => esc_html__( 'Theme Options', 'draly-dropshipping-starter' ),
				// You will need to generate a Google API key to use this feature.
				// Please visit: https://developers.google.com/fonts/docs/developer_api#Auth
				//'google_api_key'      => '',
				// Must be defined to add google fonts to the typography module
				//'async_typography'    => true, // Use a asynchronous font on the front end or font string
				//'admin_bar'           => false, // Show the panel pages on the admin bar
				'global_variable'     => 'villco',
				// Set a different name for your global variable other than the opt_name
				'dev_mode'            => false,
				// Show the time the page took to load, etc
				'customizer'          => true,
				'disable_tracking'    => true,
				'update_notice'       => false,
				// Enable basic customizer support
				// OPTIONAL -> Give you extra features
				'page_priority'       => null,
				// Order where the menu appears in the admin area. If there is any conflict, something will not show. Warning.
				'page_parent'         => 'villco_dashboard',
				// For a full list of options, visit: http://codex.wordpress.org/Function_Reference/add_submenu_page#Parameters
				'page_permissions'    => 'manage_options',
				// Permissions needed to access the options panel.
				//'menu_icon'           => '',
				// Specify a custom URL to an icon
				'last_tab'            => '',
				// Force your panel to always open to a specific tab (by id)
				'page_icon'           => 'icon-themes',
				// Icon displayed in the admin panel next to your menu_title
				'page_slug'           => 'villco_options',
				// Page slug used to denote the panel
				'save_defaults'       => true,
				// On load save the defaults to DB before user clicks save or not
				'default_show'        => false,
				// If true, shows the default value next to each field that is not the default value.
				'default_mark'        => '',
				// What to print by the field's title if the value shown is default. Suggested: *
				// CAREFUL -> These options are for advanced use only
				'transient_time'      => 60 * MINUTE_IN_SECONDS,
				'output'              => true,
				// Global shut-off for dynamic CSS output by the framework. Will also disable google fonts output
				'output_tag'          => true,
				// Allows dynamic CSS to be generated for customizer and google fonts, but stops the dynamic CSS from going to the head
				'footer_credit'       => esc_html__( 'Villa Theme', 'draly-dropshipping-starter' ),
				// Disable the footer credit of Redux. Please leave if you can help it.
				// FUTURE -> Not in use yet, but reserved or partially implemented. Use at your own risk.
				'database'            => '',
				// possible: options, theme_mods, theme_mods_expanded, transient. Not fully functional, warning!
				'show_import_export'  => true,
				// REMOVE
				'system_info'         => false,
				// REMOVE
				'help_tabs'           => array(),
				'help_sidebar'        => '',
				'show_options_object' => false,
			);
		}

		public static function get_footer_preview() {
			$options = array(
				'none' => esc_html__( 'None', 'draly-dropshipping-starter' ),
			);
			$args    = array(
				'post_type'      => 'villco_footer',
				'posts_per_page' => - 1,
				'orderby'        => 'title',
				'order'          => 'ASC',
			);
			$posts   = get_posts( $args );
			if ( ! empty( $posts ) ) {
				foreach ( $posts as $post ) {
					setup_postdata( $post );
					$options[ $post->post_name ] = $post->post_title;
				}
			}
			wp_reset_postdata();

			return $options;
		}

		public static function get_sidebar_preview() {
			$options = array(
				'left'  => array(
					'alt' => esc_attr__( 'Left Sidebar', 'draly-dropshipping-starter' ),
					'img' => Redux_Core::$url . 'assets/img/2cl.png',
				),
				'right' => array(
					'alt' => esc_attr__( 'Right Sidebar', 'draly-dropshipping-starter' ),
					'img' => Redux_Core::$url . 'assets/img/2cr.png',
				),
				'full'  => array(
					'alt' => esc_attr__( 'No Sidebar', 'draly-dropshipping-starter' ),
					'img' => Redux_Core::$url . 'assets/img/1col.png',
				)
			);

			return $options;
		}

		public static function get_items_per_row() {
			$options = array(
				'12' => esc_html__( '1 item', 'draly-dropshipping-starter' ),
				'6'  => esc_html__( '2 items', 'draly-dropshipping-starter' ),
				'4'  => esc_html__( '3 items', 'draly-dropshipping-starter' ),
				'3'  => esc_html__( '4 items', 'draly-dropshipping-starter' ),
				'15' => esc_html__( '5 items', 'draly-dropshipping-starter' ),
				'2'  => esc_html__( '6 items', 'draly-dropshipping-starter' ),
			);

			return $options;
		}

		public static function set_sections() {
			self::$sections = array_merge( self::$sections, self::set_general_section() );
			self::$sections = array_merge( self::$sections, self::set_header_section() );
			self::$sections = array_merge( self::$sections, self::set_footer_section() );
			self::$sections = array_merge( self::$sections, self::set_blog_section() );
			if ( class_exists( 'WooCommerce' ) ) {
				self::$sections = array_merge( self::$sections, self::set_woocommerce_section() );
			}
		}

		public static function set_general_section() {
			$section = array(
				array(
					'title'            => esc_html__( 'General Settings', 'draly-dropshipping-starter' ),
					'id'               => 'general',
					'customizer_width' => '400px',
					'icon'             => 'villco-icon',
				),
				array(
					'title'      => esc_html__( 'Typography', 'draly-dropshipping-starter' ),
					'subsection' => true,
					'fields'     => array(
						array(
							'id'               => 'typography_body',
							'type'             => 'typography',
							'title'            => esc_html__( 'Body', 'draly-dropshipping-starter' ),
							'google'           => true,
							'text-align'       => false,
							'subsets'          => false,
							'line-height-unit' => 'em',
							'output'           => 'body',
						),
						array(
							'id'               => 'typography_h1',
							'type'             => 'typography',
							'title'            => esc_html__( 'Heading 1(h1)', 'draly-dropshipping-starter' ),
							'google'           => true,
							'text-align'       => false,
							'subsets'          => false,
							'line-height-unit' => 'em',
							'output'           => 'h1',
						),
						array(
							'id'               => 'typography_h2',
							'type'             => 'typography',
							'title'            => esc_html__( 'Heading 2(h2)', 'draly-dropshipping-starter' ),
							'google'           => true,
							'text-align'       => false,
							'subsets'          => false,
							'line-height-unit' => 'em',
							'output'           => 'h2',
						),
						array(
							'id'               => 'typography_h3',
							'type'             => 'typography',
							'title'            => esc_html__( 'Heading 3(h3)', 'draly-dropshipping-starter' ),
							'google'           => true,
							'text-align'       => false,
							'subsets'          => false,
							'line-height-unit' => 'em',
							'output'           => 'h3',
						),
						array(
							'id'               => 'typography_h4',
							'type'             => 'typography',
							'title'            => esc_html__( 'Heading 4(h4)', 'draly-dropshipping-starter' ),
							'google'           => true,
							'text-align'       => false,
							'subsets'          => false,
							'line-height-unit' => 'em',
							'output'           => 'h4',
						),
						array(
							'id'               => 'typography_h5',
							'type'             => 'typography',
							'title'            => esc_html__( 'Heading 5(h5)', 'draly-dropshipping-starter' ),
							'google'           => true,
							'text-align'       => false,
							'subsets'          => false,
							'line-height-unit' => 'em',
							'output'           => 'h5',
						),
						array(
							'id'               => 'typography_h6',
							'type'             => 'typography',
							'title'            => esc_html__( 'Heading 6(h6)', 'draly-dropshipping-starter' ),
							'google'           => true,
							'text-align'       => false,
							'subsets'          => false,
							'line-height-unit' => 'em',
							'output'           => 'h6',
						),
					),
				),
				array(
					'title'      => esc_html__( 'Color', 'draly-dropshipping-starter' ),
					'subsection' => true,
					'fields'     => array(
						array(
							'id'          => 'main_color',
							'type'        => 'color',
							'title'       => esc_html__( 'Main Color', 'draly-dropshipping-starter' ),
							'default'     => '',
							'transparent' => false,
							'validate'    => 'color',
						),
						array(
							'id'          => 'blockquote_color',
							'type'        => 'color',
							'title'       => esc_html__( 'Blockquote Color', 'draly-dropshipping-starter' ),
							'default'     => '',
							'transparent' => false,
							'validate'    => 'color',
						),
					),
				),
			);

			return $section;
		}

		public static function set_header_section() {
			$section = array(
				array(
					'title'            => esc_html__( 'Header Settings', 'draly-dropshipping-starter' ),
					'id'               => 'header',
					'customizer_width' => '400px',
					'icon'             => 'villco-icon',
				),
				array(
					'title'      => esc_html__( 'Logo', 'draly-dropshipping-starter' ),
					'subsection' => true,
					'fields'     => array(
						array(
							'id'       => 'logo',
							'type'     => 'media',
							'url'      => true,
							'title'    => esc_html__( 'Logo Image', 'draly-dropshipping-starter' ),
							'compiler' => 'true',
							'default'  => array(
								'url'       => '',
								'id'        => '',
								'width'     => '141',
								'height'    => '49',
								'thumbnail' => '',
								'title'     => get_bloginfo( 'name' )
							),
						),
						array(
							'id'            => 'logo_width',
							'type'          => 'slider',
							'title'         => esc_html__( 'Logo Width (Unit px)', 'draly-dropshipping-starter' ),
							'default'       => 133,
							'min'           => 50,
							'step'          => 1,
							'max'           => 400,
							'display_value' => 'label'
						),
						array(
							'id'            => 'mobile_logo_width',
							'type'          => 'slider',
							'title'         => esc_html__( 'Mobile Logo Width (Unit px)', 'draly-dropshipping-starter' ),
							'default'       => 82,
							'min'           => 50,
							'step'          => 1,
							'max'           => 200,
							'display_value' => 'label'
						),
					),
				),
				array(
					'title'      => esc_html__( 'Breadcrumb', 'draly-dropshipping-starter' ),
					'subsection' => true,
					'fields'     => array(
						array(
							'id'      => 'enable_breadcrumb',
							'type'    => 'switch',
							'title'   => esc_html__( 'Enable Breadcrumb', 'draly-dropshipping-starter' ),
							'default' => true
						),
					),
				),
				array(
					'title'      => esc_html__( 'Contact', 'draly-dropshipping-starter' ),
					'subsection' => true,
					'fields'     => array(
						array(
							'id'      => 'enable_contact',
							'type'    => 'switch',
							'title'   => esc_html__( 'Enable Contact', 'draly-dropshipping-starter' ),
							'default' => 0
						),
						array(
							'id'       => 'contact_icon',
							'title'    => esc_html__( 'Contact Icon', 'draly-dropshipping-starter' ),
							'type'     => 'media',
							'compiler' => 'true',
							'required' => array( 'enable_contact', '=', 1 )
						),
						array(
							'id'       => 'contact_title',
							'type'     => 'text',
							'title'    => esc_html__( 'Contact Title', 'draly-dropshipping-starter' ),
							'required' => array( 'enable_contact', '=', 1 )
						),
						array(
							'id'       => 'contact_phone',
							'type'     => 'text',
							'title'    => esc_html__( 'Contact Phone Number', 'draly-dropshipping-starter' ),
							'required' => array( 'enable_contact', '=', 1 )
						),
					),
				),
			);

			return $section;
		}

		public static function set_footer_section() {
			$section = array(
				array(
					'title'            => esc_html__( 'Footer Settings', 'draly-dropshipping-starter' ),
					'customizer_width' => '400px',
					'icon'             => 'villco-icon',
					'fields'           => array(
						array(
							'id'       => 'footer_options',
							'type'     => 'select',
							'title'    => esc_html__( 'Footer Layout', 'draly-dropshipping-starter' ),
							'subtitle' => esc_html__( 'When no featured image is assigned to the footer, the preview will display a placeholder image together with its title.', 'draly-dropshipping-starter' ),
							'options'  => self::get_footer_preview(),
							'select2' => array(
								'allowClear'              => false,
								'minimumResultsForSearch' => - 1
							),
							'default'  => 'none',
						),
					)
				)
			);

			return $section;
		}

		public static function set_blog_section() {
			$section = array(
				array(
					'title'            => esc_html__( 'Blog Settings', 'draly-dropshipping-starter' ),
					'id'               => 'blog',
					'customizer_width' => '400px',
					'icon'             => 'villco-icon',
				),
				array(
					'title'      => esc_html__( 'Blog', 'draly-dropshipping-starter' ),
					'subsection' => true,
					'fields'     => array(
						array(
							'id'       => 'blog_sidebar_layout',
							'type'     => 'image_select',
							'compiler' => true,
							'title'    => esc_html__( 'Blog Sidebar Layout', 'draly-dropshipping-starter' ),
							'options'  => self::get_sidebar_preview(),
							'default'  => 'left',
						),
					),
				),
				array(
					'title'      => esc_html__( 'Single Post', 'draly-dropshipping-starter' ),
					'subsection' => true,
					'fields'     => array(
						array(
							'id'      => 'enable_post_shares',
							'type'    => 'switch',
							'title'   => esc_html__( 'Enable Post Shares', 'draly-dropshipping-starter' ),
							'default' => false
						),
						array(
							'id'       => 'post_sidebar_layout',
							'type'     => 'image_select',
							'compiler' => true,
							'title'    => esc_html__( 'Post Sidebar Layout', 'draly-dropshipping-starter' ),
							'options'  => self::get_sidebar_preview(),
							'default'  => 'left',
						),
					),
				),
			);

			return $section;
		}

		public static function set_woocommerce_section() {
			$section = array(
				array(
					'title'            => esc_html__( 'WooCommerce Settings', 'draly-dropshipping-starter' ),
					'id'               => 'woocommerce_main',
					'customizer_width' => '400px',
					'icon'             => 'villco-icon',
				),
				array(
					'title'      => esc_html__( 'Shop', 'draly-dropshipping-starter' ),
					'subsection' => true,
					'fields'     => array(
						array(
							'id'            => 'product_newness',
							'type'          => 'slider',
							'title'         => esc_html__( 'Products Newness (Days)', 'draly-dropshipping-starter' ),
							'default'       => 10,
							'min'           => 1,
							'step'          => 1,
							'max'           => 100,
							'display_value' => 'label'
						),
						array(
							'id'            => 'product_per_page',
							'type'          => 'slider',
							'title'         => esc_html__( 'Number Of Products On Shop Page', 'draly-dropshipping-starter' ),
							'default'       => 12,
							'min'           => 1,
							'step'          => 1,
							'max'           => 100,
							'display_value' => 'label'
						),
						array(
							'id'      => 'enable_shop_fullwidth',
							'type'    => 'switch',
							'title'   => esc_html__( 'Enable Shop Full Width', 'draly-dropshipping-starter' ),
							'default' => false
						),
						array(
							'id'       => 'shop_sidebar_layout',
							'type'     => 'image_select',
							'compiler' => true,
							'title'    => esc_html__( 'Shop Sidebar Layout', 'draly-dropshipping-starter' ),
							'options'  => self::get_sidebar_preview(),
							'default'  => 'left',
						),
						array(
							'id'       => 'shop_style',
							'type'     => 'radio',
							'compiler' => true,
							'title'    => esc_html__( 'Shop Layout', 'draly-dropshipping-starter' ),
							'options'  => array(
								'grid' => esc_html__( 'Grid', 'draly-dropshipping-starter' ),
								'list' => esc_html__( 'List', 'draly-dropshipping-starter' ),
							),
							'default'  => 'grid',
						),
						array(
							'id'      => 'woo_items',
							'type'    => 'select',
							'title'   => esc_html__( 'Shop Grid - Items per row on Extra small devices (e.g., phones) - default for anything smaller', 'draly-dropshipping-starter' ),
							'desc'    => esc_html__( 'Screen resolution of device > 0px', 'draly-dropshipping-starter' ),
							'options' => self::get_items_per_row(),
							'select2' => array(
								'allowClear'              => false,
								'minimumResultsForSearch' => - 1
							),
							'default' => '12',
						),
						array(
							'id'      => 'woo_sm_items',
							'type'    => 'select',
							'title'   => esc_html__( 'Shop Grid - Items per row on Small devices (e.g., phones in landscape mode)', 'draly-dropshipping-starter' ),
							'desc'    => esc_html__( 'Screen resolution of device >= 576px', 'draly-dropshipping-starter' ),
							'options' => self::get_items_per_row(),
							'select2' => array(
								'allowClear'              => false,
								'minimumResultsForSearch' => - 1
							),
							'default' => '6',
						),
						array(
							'id'      => 'woo_md_items',
							'type'    => 'select',
							'title'   => esc_html__( 'Shop Grid - Items per row on Medium devices (e.g., tablets)', 'draly-dropshipping-starter' ),
							'desc'    => esc_html__( 'Screen resolution of device >= 768px', 'draly-dropshipping-starter' ),
							'options' => self::get_items_per_row(),
							'select2' => array(
								'allowClear'              => false,
								'minimumResultsForSearch' => - 1
							),
							'default' => '6',
						),
						array(
							'id'      => 'woo_lg_items',
							'type'    => 'select',
							'title'   => esc_html__( 'Shop Grid - Items per row on Large devices (e.g., small laptops)', 'draly-dropshipping-starter' ),
							'desc'    => esc_html__( 'Screen resolution of device >= 992px', 'draly-dropshipping-starter' ),
							'options' => self::get_items_per_row(),
							'select2' => array(
								'allowClear'              => false,
								'minimumResultsForSearch' => - 1
							),
							'default' => '6',
						),
						array(
							'id'      => 'woo_xl_items',
							'type'    => 'select',
							'title'   => esc_html__( 'Shop Grid - Items per row on Extra large devices (e.g., desktops)', 'draly-dropshipping-starter' ),
							'desc'    => esc_html__( 'Screen resolution of device >= 1200px', 'draly-dropshipping-starter' ),
							'options' => self::get_items_per_row(),
							'select2' => array(
								'allowClear'              => false,
								'minimumResultsForSearch' => - 1
							),
							'default' => '4',
						),
						array(
							'id'      => 'woo_xxl_items',
							'type'    => 'select',
							'title'   => esc_html__( 'Shop Grid - Items per row on Extra extra large devices (e.g., large desktops or high-res displays)', 'draly-dropshipping-starter' ),
							'desc'    => esc_html__( 'Screen resolution of device >= 1400', 'draly-dropshipping-starter' ),
							'options' => self::get_items_per_row(),
							'select2' => array(
								'allowClear'              => false,
								'minimumResultsForSearch' => - 1
							),
							'default' => '4',
						),
					),
				),
				array(
					'title'      => esc_html__( 'Single Product', 'draly-dropshipping-starter' ),
					'subsection' => true,
					'fields'     => array(
						array(
							'id'      => 'enable_product_shares',
							'type'    => 'switch',
							'title'   => esc_html__( 'Enable Single Product Shares', 'draly-dropshipping-starter' ),
							'default' => false
						),
						array(
							'id'      => 'enable_product_fullwidth',
							'type'    => 'switch',
							'title'   => esc_html__( 'Enable Single Product Full Width', 'draly-dropshipping-starter' ),
							'default' => false
						),
						array(
							'id'       => 'product_sidebar_layout',
							'type'     => 'image_select',
							'compiler' => true,
							'title'    => esc_html__( 'Single Product Sidebar Layout', 'draly-dropshipping-starter' ),
							'options'  => self::get_sidebar_preview(),
							'default'  => 'left',
						),
						array(
							'id'    => 'we_accept',
							'type'  => 'info',
							'style' => 'warning',
							'title' => esc_html__( 'We accept payment', 'draly-dropshipping-starter' ),
							/* translators: %s: Product Widget admin URL */
							'desc'  => sprintf(
								wp_kses(
									__( 'This setting applies only when the <strong>Single Product Sidebar Layout</strong> is configured as <strong>Left Sidebar</strong> or <strong>Right Sidebar</strong>. For the <strong>No Sidebar</strong> layout, customization can be done via the <a href="%s">Product Widget</a> settings.', 'draly-dropshipping-starter' ),
									array(
										'strong' => array(),
										'a'      => array( 'href' => array() ),
									)
								),
								esc_url( admin_url( 'widgets.php' ) )
							),
						),
						array(
							'id'    => 'we_accept_title',
							'type'  => 'text',
							'title' => esc_html__( 'We Accept Title', 'draly-dropshipping-starter' ),
						),
						array(
							'id'       => 'we_accept_image',
							'type'     => 'media',
							'url'      => true,
							'title'    => esc_html__( 'We Accept Image', 'draly-dropshipping-starter' ),
							'compiler' => 'true',
						),
					),
				)
			);

			return $section;
		}
	}

	new Draly_Dropshipping_Starter_Theme_Option();
}
