<?php
namespace dpcdCategoryDesign;

if (!defined('ABSPATH')) {
	exit;
}

/**
 * metabox Class .
 */
class Cat_Design_Metabox
{

	private $prefix;

	/**
	 * Define the metabox and field configurations.
	 */
	public function __construct()
	{

		$this->prefix = 'wc_pcd_';

		add_action('cmb2_init', [$this, 'create_cat_design_metaboxes']);

	}

	function create_cat_design_metaboxes()
	{

		$post_id = isset($_GET['post']) && is_numeric($_GET['post']) ? intval($_GET['post']) : (get_the_ID() ?: 0);
		$string_velue = '<?php echo do_shortcode( "[dpcd_categories_design id=\'' . $post_id . '\']" ); ?>';
		$title = 'Copy and Past this on page or post';
		$des = 'Copy and Past this on page or post';
		$button_link = 'Get started step by step following our documentation.<br/><br/><a href="https://wordpress.org/plugins/dynamic-product-categories-design/#faq-header" target="_blank">Documentation</a>';
		$need_help_link = 'Stuck with something?<br/>For emergency case join. <br/><br/><a href="https://dynamicweblab.com/submit-a-request/" target="_blank">Get Support</a>';

	
		$cmb = new_cmb2_box(
			array(
				'id' => 'wc_pcd_metabox',
				'title' => esc_html__('Product Category Design Settings', 'dynamic-product-categories-design'),
				'object_types' => ['dpcd_category_design'],
				'context' => 'normal',
				'priority' => 'high',
				'show_names' => true,
				'vertical_tabs' => false, // Set vertical tabs, default false
				'tabs' => array(
					array(
						'id' => 'general',
						'icon' => 'dashicons-admin-generic',
						'title' => __('General Settings', 'dynamic-product-categories-design'),
						'fields' => array(
							$this->prefix . 'featured_cats',
							$this->prefix . 'hide_empty_cats',
							$this->prefix . 'select_category_order',
						),
					),
					array(
						'id' => 'layout-settings',
						'icon' => 'dashicons-screenoptions',
						'title' => __('Layout Settings', 'dynamic-product-categories-design'),
						'fields' => array(
							$this->prefix . 'layout',
							$this->prefix . 'content_position',
							$this->prefix . 'autoplay',
							$this->prefix . 'show_arrow',
							$this->prefix . 'arrow_position',
							$this->prefix . 'dot_nav',
						),
					),
					array(
						'id' => 'display-options',
						'icon' => 'dashicons-visibility',
						'title' => __('Display Options', 'dynamic-product-categories-design'),
						'fields' => array(
							$this->prefix . 'section_title',
							$this->prefix . 'section_title_margin',
							$this->prefix . 'show_hide_special_offer',
							$this->prefix . 'space_between_categories',
							$this->prefix . 'display_category_name',
							$this->prefix . 'show_category_description',
							$this->prefix . 'show_hide_shop_now_btn',
							$this->prefix . 'shop_now_button_label',
						),
					),
					array(
						'id' => 'image-settings',
						'icon' => 'dashicons-format-image',
						'title' => __('Image Settings', 'dynamic-product-categories-design'),
						'fields' => array(
							$this->prefix . 'category_thumbnail',
							$this->prefix . 'category_thumbnail_sizes',
						),
					),
					array(
						'id' => 'style-settings',
						'icon' => 'dashicons-admin-customizer',
						'title' => __('Styling & Theming', 'dynamic-product-categories-design'),
						'fields' => array(
							$this->prefix . 'section_title_color',
							$this->prefix . 'shop_now_button_color',
							$this->prefix . 'shop_now_hover_button_color',
							$this->prefix . 'shop_now_button_bg_color',
							$this->prefix . 'category_description_color',
							$this->prefix . 'section_category_name_color',
							$this->prefix . 'section_category_name_bg_color',
							$this->prefix . 'offer_color',
							$this->prefix . 'section_category_content',
							$this->prefix . 'section_category_content_hover',
						),
					),
				)
			)
		);


		$cmb->add_field(
			array(
				'name' => esc_html__('Select Categories', 'dynamic-product-categories-design'),
				'desc' => esc_html__('Select Woocommerce Product Categories', 'dynamic-product-categories-design'),
				'id' => $this->prefix . 'featured_cats',
				'type' => 'multicheck',
				'options_cb' => 'dpcd_options_taxonomy_terms'
			)
		);

		$cmb->add_field(
			array(
				'name' => esc_html__('Order By', 'dynamic-product-categories-design'),
				'desc' => esc_html__('Select an order option.', 'dynamic-product-categories-design'),
				'id' => $this->prefix . 'select_category_order',
				'type' => 'select',
				'default' => 'ASC',
				'options' => array(
					'DESC' => __('DESC', 'dynamic-product-categories-design'),
					'ASC' => __('ASC ', 'dynamic-product-categories-design'),
				),
			)
		);

		$cmb->add_field(
			array(
				'name' => esc_html__('Hide Empty Categories', 'dynamic-product-categories-design'),
				'desc' => esc_html__('Check to hide empty categories', 'dynamic-product-categories-design'),
				'id' => $this->prefix . 'hide_empty_cats',
				'type' => 'checkbox',
			)
		);

		$cmb->add_field(
			array(
				'name' => __('Select Layout', 'dynamic-product-categories-design'),
				'desc' => __('Select your favorite Layout for woocommerce Product Categories', 'dynamic-product-categories-design'),
				'id' => $this->prefix . 'layout',
				'type' => 'radio_image',
				'options' => array(
					'layout_grid' => __('Grid', 'dynamic-product-categories-design'),
					'layout_slider' => __('Slider', 'dynamic-product-categories-design'),
				),
				'images_path' => DPCD_ASSETS,
				'images' => array(
					'layout_grid' => 'images/grid.svg',
					'layout_slider' => 'images/slider.svg',
				),
				'default' => 'layout_grid',
			)
		);

		$cmb->add_field(
			array(
				'name' => __('Content Position', 'dynamic-product-categories-design'),
				//'desc'           => __( '', 'cmb2' ),
				'id' => $this->prefix . 'content_position',
				'type' => 'radio_image',
				'options' => array(
					'below-content' => __('Below Content', 'dynamic-product-categories-design'),
					'overlay-content' => __('Overlay Content', 'dynamic-product-categories-design'),
				),
				'images_path' => DPCD_ASSETS,
				'images' => array(
					'below-content' => 'images/below-content.svg',
					'overlay-content' => 'images/overlay-content.svg',
				),
				'default' => 'below-content',
			)
		);


		$cmb->add_field(
			array(
				'name' => __('Enable Autoplay', 'dynamic-product-categories-design'),
				'desc' => __('Enables Autoplay on the slider', 'dynamic-product-categories-design'),
				'id' => $this->prefix . 'autoplay',
				'classes' => '',
				'type' => 'select',
				'show_option_none' => false,
				'default' => 'yes',
				'options' => array(
					'yes' => __('Yes', 'dynamic-product-categories-design'),
					'no' => __('No', 'dynamic-product-categories-design'),
				),
				'attributes' => array(
					'data-conditional-id' => $this->prefix . 'layout',
					'data-conditional-value' => 'layout_slider',
				),
			)
		);

		$cmb->add_field(
			array(
				'name' => __('Show Arrow', 'dynamic-product-categories-design'),
				'desc' => __('Show hide next previous button', 'dynamic-product-categories-design'),
				'id' => $this->prefix . 'show_arrow',
				'classes' => '',
				'type' => 'select',
				'show_option_none' => false,
				'default' => 'yes',
				'options' => array(
					'yes' => __('Yes', 'dynamic-product-categories-design'),
					'no' => __('No', 'dynamic-product-categories-design'),
				),
				'attributes' => array(
					'data-conditional-id' => $this->prefix . 'layout',
					'data-conditional-value' => 'layout_slider',
				),
			)
		);

		$cmb->add_field(
			array(
				'name' => __('Arrow Position', 'dynamic-product-categories-design'),
				//'desc'                     => 'Show hide next previous button',
				'id' => $this->prefix . 'arrow_position',
				'classes' => '',
				'type' => 'select',
				'show_option_none' => false,
				'default' => 'side',
				'options' => array(
					'top-right' => __('Top Right', 'dynamic-product-categories-design'),
					'side' => __('Side', 'dynamic-product-categories-design'),
				),
				'attributes' => array(
					'data-conditional-id' => $this->prefix . 'layout',
					'data-conditional-value' => 'layout_slider',
				),
			)
		);


		$cmb->add_field(
			array(
				'name' => __('Show Dot navigation', 'dynamic-product-categories-design'),
				'desc' => __('Show hide dot navigation', 'dynamic-product-categories-design'),
				'id' => $this->prefix . 'dot_nav',
				'classes' => '',
				'type' => 'select',
				'show_option_none' => false,
				'default' => 'yes',
				'options' => array(
					'yes' => __('Yes', 'dynamic-product-categories-design'),
					'no' => __('No', 'dynamic-product-categories-design'),
				),
				'attributes' => array(
					'data-conditional-id' => $this->prefix . 'layout',
					'data-conditional-value' => 'layout_slider',
				),
			)
		);

		// $cmb->add_field( 
		// 		array(
		// 		'name'             => __( 'Section Title', 'dynamic-product-categories-design' ),
		// 		'desc'             => __( 'Show hide Section Title', 'dynamic-product-categories-design' ),
		// 		'id'               => $this->prefix . 'section_title',
		// 		'classes'          => 'wc-pcd-nice-checkbox',
		// 		'type'             => 'checkbox',
		// 	)
		// );


		// $cmb->add_field( 
		// 	array(
		// 		'name'             => __( 'Section Title Color', 'dynamic-product-categories-design' ),
		// 		'desc'             => __( 'Change Section Title Color.', 'dynamic-product-categories-design' ),
		// 		'id'               => $this->prefix . 'section_title_color',
		// 		'classes'          => 'wc-pcd-heading-color',
		// 		'type'             => 'colorpicker',
		// 		'default' => '#ffffff',
		// 	)
		// );

		$cmb->add_field(
			array(
				'name' => __('Background', 'dynamic-product-categories-design'),
				'desc' => __('Set color for the category content background.', 'dynamic-product-categories-design'),
				'id' => $this->prefix . 'section_category_content',
				'classes' => 'wc-pcd-category-content',
				'type' => 'colorpicker',
				'default' => '',
			)
		);

		$cmb->add_field(
			array(
				'name' => __('Hover Background', 'dynamic-product-categories-design'),
				'desc' => __('Set color for the category content hover background.', 'dynamic-product-categories-design'),
				'id' => $this->prefix . 'section_category_content_hover',
				'classes' => 'wc-pcd-category-content_hover',
				'type' => 'colorpicker',
				'default' => '',
			)
		);

		$cmb->add_field(
			array(
				'name' => __('Offer Color', 'dynamic-product-categories-design'),
				'desc' => __('Set color for the offer text.', 'dynamic-product-categories-design'),
				'id' => $this->prefix . 'offer_color',
				'classes' => 'wc-pcd-offer_color',
				'type' => 'colorpicker',
				'default' => '',
			)
		);

		$cmb->add_field(
			array(
				'name' => __('Special offer', 'dynamic-product-categories-design'),
				'desc' => __('Show/Hide Special offer.', 'dynamic-product-categories-design'),
				'id' => $this->prefix . 'show_hide_special_offer',
				'classes' => 'pcd-grid-special-offer',
				'type' => 'checkbox',
			)
		);

		$cmb->add_field(
			array(
				'name' => __('Category Name', 'dynamic-product-categories-design'),
				'desc' => __('Hide/Show cateogry name.', 'dynamic-product-categories-design'),
				'id' => $this->prefix . 'display_category_name',
				'classes' => 'wc-pcd-category-name',
				'type' => 'checkbox',
			)
		);

		$cmb->add_field(
			array(
				'name' => __('Category Name Color', 'dynamic-product-categories-design'),
				'desc' => __('Set category name color.', 'dynamic-product-categories-design'),
				'id' => $this->prefix . 'section_category_name_color',
				'classes' => 'wc-pcd-category-content',
				'type' => 'colorpicker',
				'default' => '',
			)
		);

		$cmb->add_field(
			array(
				'name' => __('Category Name Background', 'dynamic-product-categories-design'),
				'desc' => __('Set category name background color.', 'dynamic-product-categories-design'),
				'id' => $this->prefix . 'section_category_name_bg_color',
				'classes' => 'wc-pcd-category-content',
				'type' => 'colorpicker',
				'default' => '',
			)
		);

		$cmb->add_field(
			array(
				'name' => __('Category Description', 'dynamic-product-categories-design'),
				'desc' => __('Hide/show description.', 'dynamic-product-categories-design'),
				'id' => $this->prefix . 'show_category_description',
				'classes' => 'wc-pcd-category-description',
				'type' => 'checkbox',
			)
		);

		$cmb->add_field(
			array(
				'name' => __('Category Description Color', 'dynamic-product-categories-design'),
				'desc' => __('Set category description color.', 'dynamic-product-categories-design'),
				'id' => $this->prefix . 'category_description_color',
				'classes' => 'wc-pcd-category-description',
				'type' => 'colorpicker',
				'default' => '',
			)
		);

		$cmb->add_field(
			array(
				'name' => __('Shop Now Button', 'dynamic-product-categories-design'),
				'desc' => __('Show/Hide shop now button.', 'dynamic-product-categories-design'),
				'id' => $this->prefix . 'show_hide_shop_now_btn',
				'classes' => 'wc-pcd-shop-now-button',
				'type' => 'checkbox',
			)
		);

		$cmb->add_field(
			array(
				'name' => __('Shop Now Button Label', 'dynamic-product-categories-design'),
				'desc' => __('Type shop now button label', 'dynamic-product-categories-design'),
				'default' => __('Shop Now', 'dynamic-product-categories-design'),
				'id' => $this->prefix . 'shop_now_button_label',
				'classes' => 'wc-pcd-shop-now-button-label',
				'type' => 'text',
			)
		);

		$cmb->add_field(
			array(
				'name' => __('Shop Now Button Color', 'dynamic-product-categories-design'),
				'desc' => __('Set shop now button color.', 'dynamic-product-categories-design'),
				'id' => $this->prefix . 'shop_now_button_color',
				'classes' => 'wc-pcd-shop-now-btn-color',
				'type' => 'colorpicker',
				'default' => '',
			)
		);

		$cmb->add_field(
			array(
				'name' => __('Shop Now Background Color', 'dynamic-product-categories-design'),
				'desc' => __('Set shop now button background color.', 'dynamic-product-categories-design'),
				'id' => $this->prefix . 'shop_now_button_bg_color',
				'classes' => 'wc-pcd-shop-now-btn-bg-color',
				'type' => 'colorpicker',
				'default' => '',
			)
		);

		$cmb->add_field(
			array(
				'name' => __('Shop Now Hover Color', 'dynamic-product-categories-design'),
				'desc' => __('Set shop now button hover color.', 'dynamic-product-categories-design'),
				'id' => $this->prefix . 'shop_now_hover_button_color',
				'classes' => 'wc-pcd-shop-now-btn-hover-color',
				'type' => 'colorpicker',
				'default' => '',
			)
		);

		$cmb->add_field(
			array(
				'name' => __('Space Between Categories', 'dynamic-product-categories-design'),
				'desc' => __('PX', 'dynamic-product-categories-design'),
				'default' => '',
				'id' => $this->prefix . 'space_between_categories',
				'type' => 'text_small',
				'attributes' => array(
					'type' => 'number',
				),
			)
		);


		$cmb->add_field(
			array(
				'name' => __('Thumbnail', 'dynamic-product-categories-design'),
				'desc' => __('Hide/show thumbnail.', 'dynamic-product-categories-design'),
				'id' => $this->prefix . 'category_thumbnail',
				'classes' => 'wc-pcd-nice-checkbox',
				'type' => 'checkbox',
			)
		);

		$cmb->add_field(
			array(
				'name' => __('Thumbnail Sizes', 'dynamic-product-categories-design'),
				'desc' => __('Set size for thumbnail.', 'dynamic-product-categories-design'),
				'id' => $this->prefix . 'category_thumbnail_sizes',
				'classes' => 'wc-pcd-thumbnail-size',
				'type' => 'select',
				'options' => array(
					'thumbnail' => __('Thumbnail (default 150px x 150px)', 'dynamic-product-categories-design'),
					'medium' => __('Medium resolution (default 300px x 300px)', 'dynamic-product-categories-design'),
					'medium_large' => __('Medium Large resolution (default 768px x 0px)', 'dynamic-product-categories-design'),
					'large' => __('Large resolution (default 1024px x 1024px)', 'dynamic-product-categories-design'),
					'full' => __('Original image resolution (unmodified)', 'dynamic-product-categories-design'),
				),
			)
		);



		$cmb_term = new_cmb2_box(array(
			'id' => $this->prefix . 'term_metabox',
			'title' => esc_html__('Product Categories Design settings', 'dynamic-product-categories-design'),
			'object_types' => array('term'),
			'taxonomies' => 'product_cat',
		));

		$cmb_term->add_field(array(
			'name' => esc_html__('Category Slider Alternative Image', 'dynamic-product-categories-design'),
			'desc' => esc_html__('Add or Upload File for the category slider', 'dynamic-product-categories-design'),
			'id' => $this->prefix . 'category_slider_image',
			'type' => 'file',
			'options' => array(
				'url' => false, // Hide the text input for the url
			),
		));
		$cmb_term->add_field(array(
			'name' => esc_html__('Special offer text', 'dynamic-product-categories-design'),
			'desc' => esc_html__('Add special offer text for the category product', 'dynamic-product-categories-design'),
			'id' => $this->prefix . 'cat_special_offer',
			'type' => 'textarea_small',
		));


		$cmbhelp = new_cmb2_box(
			array(
				'id' => 'wc_pcd_metabox_help',
				'title' => esc_html__('Instructions', 'dynamic-product-categories-design'),
				'object_types' => ['dpcd_category_design'],
				'context' => 'normal',
				'priority' => 'high',
				'show_names' => true,

			)
		);

		$cmbhelp->add_field(array(
			'name' => __('How to display this?', 'dynamic-product-categories-design'),
			'desc' => $title,
			'type' => 'title',
			'id' => 'dpcd_settings_title'
		));


		$cmbhelp->add_field(array(
			'name' => __('Shortcode', 'dynamic-product-categories-design'),
			'desc' => 'Copy',
			'type' => 'text',
			'default' => '',
			'id' => 'dpcd_settings_shortcode'
		));


		// $dpcDocument = new_cmb2_box( 
		//     array(
		//         'id'            => 'wc_pcd_metabox_document',
		//         'title'         =>  esc_html__( 'Documentation', 'dynamic-product-categories-design' ),
		//         'object_types'  => ['dpcd_category_design'], 
		//         'context'       => 'side',
		//         'priority'      => 'low',
		//         'show_names'    => true,
		//     ) 
		// );

		// $dpcDocument->add_field( array(
		//     'name' => __( '', 'dynamic-product-categories-design' ),
		//     'desc' => $button_link,
		//     'type' => 'title',
		//     'id'   => 'dpcd_settings_document'
		// ) );

		$need_help = new_cmb2_box(
			array(
				'id' => 'wc_pcd_metabox_need_help',
				'title' => esc_html__('Need Help ?', 'dynamic-product-categories-design'),
				'object_types' => ['dpcd_category_design'],
				'context' => 'side',
				'priority' => 'low',
				'show_names' => true,
			)
		);

		$need_help->add_field(array(
			'name' => __('Support', 'dynamic-product-categories-design'),
			'desc' => $need_help_link,
			'type' => 'title',
			'id' => 'dpcd_settings_need_help',
		));


	}

}
new Cat_Design_Metabox();