<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

if( !class_exists( 'Vouge_Shop_Metabox_Single_Upsell_Related' ) ) {
    class Vouge_Shop_Metabox_Single_Upsell_Related {

        private static $_instance = null;

        public static function instance() {
            if ( is_null( self::$_instance ) ) {
                self::$_instance = new self();
            }

            return self::$_instance;
        }

        function __construct() {

			add_filter( 'vouge_shop_product_custom_settings', array( $this, 'vouge_shop_product_custom_settings' ), 10 );

		}

        function vouge_shop_product_custom_settings( $options ) {

			$ct_dependency      = array ();
			$upsell_dependency  = array ( 'show-upsell', '==', 'true');
			$related_dependency = array ( 'show-related', '==', 'true');
			if( function_exists('vouge_shop_single_module_custom_template') ) {
				$ct_dependency['dependency'] 	= array ( 'product-template', '!=', 'custom-template');
				$upsell_dependency 				= array ( 'product-template|show-upsell', '!=|==', 'custom-template|true');
				$related_dependency 			= array ( 'product-template|show-related', '!=|==', 'custom-template|true');
			}

			$product_options = array (

				array_merge (
					array(
						'id'         => 'show-upsell',
						'type'       => 'select',
						'title'      => esc_html__('Show Upsell Products', 'vouge'),
						'class'      => 'chosen',
						'default'    => 'admin-option',
						'attributes' => array( 'data-depend-id' => 'show-upsell' ),
						'options'    => array(
							'admin-option' => esc_html__( 'Admin Option', 'vouge' ),
							'true'         => esc_html__( 'Show', 'vouge'),
							null           => esc_html__( 'Hide', 'vouge'),
						)
					),
					$ct_dependency
				),

				array(
					'id'         => 'upsell-column',
					'type'       => 'select',
					'title'      => esc_html__('Choose Upsell Column', 'vouge'),
					'class'      => 'chosen',
					'default'    => 4,
					'options'    => array(
						'admin-option' => esc_html__( 'Admin Option', 'vouge' ),
						1              => esc_html__( 'One Column', 'vouge' ),
						2              => esc_html__( 'Two Columns', 'vouge' ),
						3              => esc_html__( 'Three Columns', 'vouge' ),
						4              => esc_html__( 'Four Columns', 'vouge' ),
					),
					'dependency' => $upsell_dependency
				),

				array(
					'id'         => 'upsell-limit',
					'type'       => 'select',
					'title'      => esc_html__('Choose Upsell Limit', 'vouge'),
					'class'      => 'chosen',
					'default'    => 4,
					'options'    => array(
						'admin-option' => esc_html__( 'Admin Option', 'vouge' ),
						1              => esc_html__( 'One', 'vouge' ),
						2              => esc_html__( 'Two', 'vouge' ),
						3              => esc_html__( 'Three', 'vouge' ),
						4              => esc_html__( 'Four', 'vouge' ),
						5              => esc_html__( 'Five', 'vouge' ),
						6              => esc_html__( 'Six', 'vouge' ),
						7              => esc_html__( 'Seven', 'vouge' ),
						8              => esc_html__( 'Eight', 'vouge' ),
						9              => esc_html__( 'Nine', 'vouge' ),
						10              => esc_html__( 'Ten', 'vouge' ),
					),
					'dependency' => $upsell_dependency
				),

				array_merge (
					array(
						'id'         => 'show-related',
						'type'       => 'select',
						'title'      => esc_html__('Show Related Products', 'vouge'),
						'class'      => 'chosen',
						'default'    => 'admin-option',
						'attributes' => array( 'data-depend-id' => 'show-related' ),
						'options'    => array(
							'admin-option' => esc_html__( 'Admin Option', 'vouge' ),
							'true'         => esc_html__( 'Show', 'vouge'),
							null           => esc_html__( 'Hide', 'vouge'),
						)
					),
					$ct_dependency
				),

				array(
					'id'         => 'related-column',
					'type'       => 'select',
					'title'      => esc_html__('Choose Related Column', 'vouge'),
					'class'      => 'chosen',
					'default'    => 4,
					'options'    => array(
						'admin-option' => esc_html__( 'Admin Option', 'vouge' ),
						2              => esc_html__( 'Two Columns', 'vouge' ),
						3              => esc_html__( 'Three Columns', 'vouge' ),
						4              => esc_html__( 'Four Columns', 'vouge' ),
					),
					'dependency' => $related_dependency
				),

				array(
					'id'         => 'related-limit',
					'type'       => 'select',
					'title'      => esc_html__('Choose Related Limit', 'vouge'),
					'class'      => 'chosen',
					'default'    => 4,
					'options'    => array(
						'admin-option' => esc_html__( 'Admin Option', 'vouge' ),
						1              => esc_html__( 'One', 'vouge' ),
						2              => esc_html__( 'Two', 'vouge' ),
						3              => esc_html__( 'Three', 'vouge' ),
						4              => esc_html__( 'Four', 'vouge' ),
						5              => esc_html__( 'Five', 'vouge' ),
						6              => esc_html__( 'Six', 'vouge' ),
						7              => esc_html__( 'Seven', 'vouge' ),
						8              => esc_html__( 'Eight', 'vouge' ),
						9              => esc_html__( 'Nine', 'vouge' ),
						10              => esc_html__( 'Ten', 'vouge' ),
					),
					'dependency' => $related_dependency
				)

			);

			$options = array_merge( $options, $product_options );

			return $options;

		}

    }
}

Vouge_Shop_Metabox_Single_Upsell_Related::instance();