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

add_filter( 'rwmb_meta_boxes', 'kktfwp_meta_boxes');

function kktfwp_meta_boxes( $meta_boxes )
{
	/**
	 * Prefix of meta keys (optional)
	 * Use underscore (_) at the beginning to make keys hidden
	 * Alt.: You also can make prefix empty to disable it
	 */
	// Better has an underscore as last sign
	$prefix = 'kk_';
	$bgMeta = array( 
		array(
			'name'             => esc_html__( 'Background type', 'toppic' ),
			'id'               => "_custom_bg_type_value",
			'type'             => 'select',
			'tab'  			   => 'background',
			'options'          => array (
								'Default' => esc_html__( 'Default', 'toppic' ),
								'Custom Slideshow' => esc_html__( 'Custom Slideshow', 'toppic' ),
								'Video' => esc_html__( 'Video', 'toppic' ),
								'Image' => esc_html__( 'Image', 'toppic' ),
							),
			
			'std'              => 'default',
			'hidden'  =>  array( 'page_template', 'template-homepage-grid.php' )
		),
		array(
			'name'             => esc_html__( 'Images/Slides', 'toppic' ),
			'id'               => "{$prefix}homegrid",
			'type'             => 'image_advanced',
			'tab'  			   => 'background',
			'max_file_uploads' => 0,
			'visible' 		   => array('_custom_bg_type_value', 'Custom Slideshow'),
		),
		array(
			'name'             => esc_html__( 'Background video', 'toppic' ),
			'desc'             => esc_html__( 'Enter an URL to the background video file for this page. Supports: HTML5 video (mp4), YouTube. If you prefer to use YouTube, simply add an URL to the YouTube page where your video is.', 'toppic' ),
			'id'               => "_bg_video_value",
			'tab'  			   => 'background',
			'type' => 'input',
			'visible' 		   => array('_custom_bg_type_value', 'Video'),
		),
		array(
			'name'             => esc_html__( 'Fallback background image', 'toppic' ),
			'desc'             => esc_html__( 'This image will be displayed if mobile device doesn\'t support background video. Strongly recommend to use this option', 'toppic' ),
			'id'               => "_bg_image_fallback_value",
			'tab'  			   => 'background',
			'type'             => 'file_input',
			'visible' 		   => array('_custom_bg_type_value', 'Video' ),
		),
		array(
			'name'             => esc_html__( 'Background image', 'toppic' ),
			'id'               => "_bg_image_value",
			'tab'  			   => 'background',
			'type'             => 'file_input',
			'visible' 		   => array('_custom_bg_type_value', 'Image' ),
		),	
		array(
			'name'             => esc_html__( 'Background-repeat property', 'toppic' ),
			'id'               => '_custom_bg_repeat_value',
			'type'             => 'select',
			'tab'  			   => 'background',
			'options'          => array (
								'repeat' => esc_html__( 'Repeat', 'toppic' ),
								'no-repeat' => esc_html__( 'No repeat', 'toppic' ),
								'repeat-x' => esc_html__( 'Repeat X', 'toppic' ),
								'repeat-y' => esc_html__( 'Repeat Y', 'toppic' ),
							),
			
			'std'              => 'no-repeat',
			'visible' 		   => array('_custom_bg_type_value', 'Image' ),
		),	
		array(
			'name'             => esc_html__( 'Background-position property', 'toppic' ),
			'id'               => '_custom_bg_position_value',
			'type'             => 'select',
			'tab'  			   => 'background',
			'options'          => array (
								'Top Left' => esc_html__( 'Top Left', 'toppic' ),
								'Top Center' => esc_html__( 'Top Center', 'toppic' ),
								'Top Right' => esc_html__( 'Top Right', 'toppic' ),
								'Center' => esc_html__( 'Center', 'toppic' ),
							),
			
			'std'              => 'Top Left',
			'visible' 		   => array('_custom_bg_type_value', 'Image' ),
		),		
		array(
			'name'             => esc_html__( 'Background size', 'toppic' ),
			'id'               => '_custom_bg_size_value',
			'type'             => 'select',
			'tab'  			   => 'background',
			'options'          => array (
								'Full' => esc_html__( 'Full', 'toppic' ),
								'Original' => esc_html__( 'Original', 'toppic' ),
							),
			
			'std'              => 'Original',
			'visible' 		   => array('_custom_bg_type_value', 'Image' ),
		)
	);
	
	$pageMeta = array(
		array(
			'name'             => esc_html__( 'Image proportions', 'toppic' ),
			'id'               => "_kk_homepage_layout_value",
			'type'             => 'select',
			'tab'			   => 'page',
			'options' => array(
							'Random'			=>	esc_html__( 'Original', 'toppic' ),	
							'Square'			=>  esc_html__( 'Square', 'toppic' ),
							'Landscape'			=>	esc_html__( 'Landscape', 'toppic' ),
							'Portrait'			=>	esc_html__( 'Portrait', 'toppic' ),		
						),
			'std' 			=> 'Random',
			'hidden'  		=>  array( 'page_template', '!=', 'template-homepage-grid.php' )
		),
		array(
			'name'             => esc_html__( 'Images', 'toppic' ),
			'id'               => "{$prefix}grid",
			'type'             => 'image_advanced',
			'tab'			   => 'page',
			'max_file_uploads' => 0,
			'hidden'  		=>  array( 'page_template', '!=', 'template-homepage-grid.php' )
		),
		array(
			'name'             => esc_html__( 'Album columns', 'toppic' ),
			'id'               => "_album_layout_value",
			'type'             => 'select',
			'tab'			   => 'page',
			'options' => array(
							'3-column' 		   => esc_html__( '3 columns', 'toppic' ),
							'3-column (wide)'  => esc_html__( '3 columns (wide)', 'toppic' ),
							'4-column'  	   => esc_html__( '4 columns', 'toppic' ),
							'4-column (wide)'  => esc_html__( '4 columns (wide)', 'toppic' ),
						),
			'std' 			=> '3-column',
			'hidden'  		=>  array( 'page_template', '!=', 'template-gallery.php' )
		),
		array(
			'name'             => esc_html__( 'Portfolio columns', 'toppic' ),
			'id'               => "_portfolio_layout_value",
			'type'             => 'select',
			'tab'			   => 'page',
			'options' => array(
							'3-column' 		   => esc_html__( '3 columns', 'toppic' ),
							'3-column (wide)'  => esc_html__( '3 columns (wide)', 'toppic' ),
							'4-column'  	   => esc_html__( '4 columns', 'toppic' ),
							'4-column (wide)'  => esc_html__( '4 columns (wide)', 'toppic' ),
						),
			'std' 			=> '3-column',
			'hidden'  		=>  array( 'page_template', '!=', 'template-portfolio.php' )
		),
		array(
			'name' 			=> esc_html__( 'Categories to display in this portfolio', 'toppic' ),
			'id' 			=> "{$prefix}filter-portfolio",
			'type'			=> 'taxonomy',
			'tab'			=> 'page',
			'taxonomy' 		=> 'portfolio-type',
			'field_type' 	=> 'checkbox_list',
			'visible'  		=>  array( 'page_template', 'template-portfolio.php' )
		),
		array(
			'name' 			=> esc_html__( 'Categories to display in this gallery', 'toppic' ),
			'id' 			=> "{$prefix}filter",
			'type' 			=> 'taxonomy',
			'tab'			=> 'page',
			'taxonomy' 		=> 'gallery-type',
			'field_type' 	=> 'checkbox_list',
			'hidden'  		=>  array( 'page_template', '!=', 'template-gallery.php' )
		),
		
	);
	
	$parallax = array(
			array(
				'name'             => esc_html__( 'Title type', 'toppic' ),
				'id'               => "{$prefix}title_type",
				'type'             => 'button_group',
				'tab'			   => 'page',
				'options' => array(
							'default'  => esc_html__( 'Default', 'toppic' ),
							'parallax' => esc_html__( 'Parallax', 'toppic' ),			
							'disabled' => esc_html__( 'No title', 'toppic' ),				
							),
				'std' => 'default',
				'hidden'  =>  array( 'page_template', 'in', array( 'template-homepage-slider.php', 'template-homepage-grid.php' ) )
			),				
			array(
				'name'             => esc_html__( 'Parallax height', 'toppic' ),
				'id'               => "{$prefix}title_size",
				'type'             => 'button_group',
				'tab'			   => 'page',
				'options' => array(
							'standard'  => esc_html__( 'Standard', 'toppic' ),
							'full'  	=> esc_html__( 'Full', 'toppic' ),			
							),
				'std' 			   => 'standard',
				'visible' 		   => array('kk_title_type', 'parallax' ),
			),			
			array(
				'name'             => esc_html__( 'Parallax background', 'toppic' ),
				'desc'      => esc_html__( 'Recommended image size: min width - 1920px', 'toppic' ),
				'id'               => "{$prefix}title_bg",
				'type'             => 'image_advanced',
				'tab'			   => 'page',
				'max_file_uploads' => 1,
				'visible' 		   => array('kk_title_type', 'parallax' ),
			),
		);
	
	if ( get_option( 'toppic_theme_menu_style' ) !== 'kk-menu-left-boxed' && get_option( 'toppic_theme_content_style' ) === 'kk-full' ) {
		
		$pageMeta = array_merge(
			$pageMeta, $parallax
		
		);		
	}

	
	// PAGE META
	
	$meta_boxes[] = array(
		'title' => esc_html__( 'Page Attributes', 'toppic' ),
		'post_types'  => array ( 'page' ),
		'id' => 'kktfwp-page-settings',
		'context' => 'normal',
		'priority' => 'high',
		
		'tabs'      => array(
			'page' => array(
				'label'      => esc_html__( 'Page', 'toppic' ),
				'icon'  => 'dashicons-admin-page', // Dashicon
			),
			'background' => array(
				'label'      => esc_html__( 'Background', 'toppic' ),
				'icon'  => 'dashicons-welcome-view-site', // Dashicon
			),		
		),
		
		// Tab style: 'default', 'box' or 'left'. Optional
		'tab_style' => 'left',

		'fields' => array_merge(			
			$bgMeta, $pageMeta
			)		
	);
	
	
	// PRODUCT META
	
	$meta_boxes[] = array(
		'title' => esc_html__( 'Page Attributes', 'toppic' ),
		'post_types'  => array ( 'product' ),
		'id' => 'kktfwp-page-settings',
		'context' => 'normal',
		'priority' => 'high',
		
		'tabs'      => array(
			'background' => array(
				'label'      => esc_html__( 'Background', 'toppic' ),
				'icon'  => 'dashicons-welcome-view-site', // Dashicon
			),		
		),
		
		// Tab style: 'default', 'box' or 'left'. Optional
		'tab_style' => 'left',

		'fields' => array_merge(			
			$bgMeta
			)		
	);
	
	
	// PORTFOLIO META
	
	$meta_boxes[] = array(
		'title' => esc_html__( 'Page Attributes', 'toppic' ),
		'post_types'  => array ( 'portfolio' ),
		'id' => 'kktfwp-page-settings',
		'context' => 'normal',
		'priority' => 'high',
		
		'tabs'      => array(
			'page' => array(
				'label'      => esc_html__( 'Project', 'toppic' ),
				'icon'  => 'dashicons-format-image', // Dashicon
			),	
			'background' => array(
				'label'      => esc_html__( 'Background', 'toppic' ),
				'icon'  => 'dashicons-welcome-view-site', // Dashicon
			),		
		),
		
		// Tab style: 'default', 'box' or 'left'. Optional
		'tab_style' => 'left',

		'fields' => array_merge(			
			$bgMeta, $parallax,
			
			array(
				array(
				'name'             => esc_html__( 'Sidebar', 'toppic' ),
				'id'               => "{$prefix}project_layout",
				'type'             => 'button_group',
				'tab'			   => 'page',
				'options' => array(
							'sidebar_off' => esc_html__( 'Disable', 'toppic' ),
							'sidebar_on'  => esc_html__( 'Enable', 'toppic' ),
							),
				'std' => 'sidebar_off'
				),
				array(
					'name'             => esc_html__( 'Project Type', 'toppic' ),
					'id'               => "{$prefix}project_type",
					'type'             => 'button_group',
					'tab'			   => 'page',
					'options' => array(
								'image'  => esc_html__( 'Image(s)', 'toppic' ),
								'slideshow' => esc_html__( 'Slider', 'toppic' ),
								'video' => esc_html__( 'Video', 'toppic' ),
								),
					'std' => 'image'
				),
				array(
					'name'             => esc_html__( 'Slider Autostart', 'toppic' ),
					'id'               => "{$prefix}slider_auto",
					'class'			   => 'slider-auto-wrapper',
					'type'             => 'button_group',
					'tab'			   => 'page',
					'options' => array(
								'yes'  => esc_html__( 'Yes', 'toppic' ),
								'no' => esc_html__( 'No', 'toppic' ),
								),
					'std' => 'no',
					'visible' 		   => array('kk_project_type', 'slideshow' ),
				),
				array(
					'id' 				=> "{$prefix}sliderDelay",
					'class'				=> 'slider-auto-wrapper',
					'type' 				=> 'number',
					'tab'			    => 'page',
					'name'				=> esc_html__( 'Delay between transitions (ms)', 'toppic' ),
					'std' 				=> '3000',
					'min' 				=> '1',
					'step' 				=> '1',
					'visible' 		   => array('kk_project_type', 'slideshow' ),
				),
				
				array(
					'name'             => esc_html__( 'Upload project images', 'toppic' ),
					'id'               => "{$prefix}projimg",
					'class'			   => 'projimg_wrapper',
					'type'             => 'image_advanced',
					'tab'			   => 'page',
					'max_file_uploads' => 0,
					'hidden' 		   => array('kk_project_type', 'video' ),
				),
				
				array(
					'name'             => esc_html__( 'Paste your embedded video code', 'toppic' ),
					'id'               => "{$prefix}projvid",
					'class'			   => 'projvid_wrapper',
					'type'             => 'textarea',
					'tab'			   => 'page',
					'clone'            => false,
					'visible' 		   => array('kk_project_type', 'video' ),
				),				
			)
		)			
					
	);
	
	
	// GALLERY META
	
	$meta_boxes[] = array(
		'title' => esc_html__( 'Page Attributes', 'toppic' ),
		'post_types'  => array ( 'gallery' ),
		'id' => 'kktfwp-page-settings',
		'context' => 'normal',
		'priority' => 'high',
		
		'tabs'      => array(
			'page' => array(
				'label'      => esc_html__( 'Gallery', 'toppic' ),
				'icon'  => 'dashicons-format-gallery', // Dashicon
			),	
			'background' => array(
				'label'      => esc_html__( 'Background', 'toppic' ),
				'icon'  => 'dashicons-welcome-view-site', // Dashicon
			),		
		),
		
		// Tab style: 'default', 'box' or 'left'. Optional
		'tab_style' => 'left',

		'fields' => array_merge(			
			$bgMeta, $parallax,
			
			array(
				array(
					'name'             => esc_html__( 'Gallery layout', 'toppic' ),
					'id'               => '_gallery_layout_value',
					'type'             => 'select',
					'tab'			   => 'page',
					'options' => array(
								'2-column'			=>  esc_html__( '2 Columns', 'toppic' ),
								'3-column'			=>	esc_html__( '3 Columns', 'toppic' ),
								'4-column'			=>	esc_html__( '4 Columns', 'toppic' ),
								'Thumbnails'		=>	esc_html__( 'Thumbnails', 'toppic' ),
								'Fullscreen-Grid'	=>	esc_html__( 'Grid (fullscreen)', 'toppic' ),
								'Fullscreen'		=>	esc_html__( 'Fullscreen', 'toppic' ),							
							),
					'std' => '2-column',
				),
				array(
					'name'             => esc_html__( 'Gallery type', 'toppic' ),
					'id'               => "{$prefix}proof",
					'type'             => 'select',
					'tab'			   => 'page',
					'class'			   => 'kk-proofing-gallery',
					'options' => array(
								'normal' => esc_html__( 'Normal', 'toppic' ),
								'proofing' => esc_html__( 'Photo proofing', 'toppic' )							
								),
					'std' 		 => 'normal',
					'hidden' 	 => array( '_gallery_layout_value', 'Fullscreen' )
				),
				array(
					'name'             => esc_html__( 'Crop images', 'toppic' ),
					'desc'			   => esc_html__( 'Thumbnails are cropped to align', 'toppic' ),
					'id'               => '_is_masonry_value',
					'type'             => 'button_group',
					'tab'			   => 'page',
					'options' => array(
								'No'	=>	esc_html__( 'Yes', 'toppic' ),						
								'Yes'	=>  esc_html__( 'No', 'toppic' ),
							),
					'std' 			  => 'No',
					'hidden' 		  => array( '_gallery_layout_value', 'in', array( 'Fullscreen-Grid', 'Fullscreen' ) )
				),
				array(
					'name'             => esc_html__( 'Image proportions', 'toppic' ),
					'id'               => '_grid_type_value',
					'type'             => 'select',
					'tab'			   => 'page',
					'options' => array(
								'Random'			=>	esc_html__( 'Original', 'toppic' ),	
								'Square'			=>  esc_html__( 'Square', 'toppic' ),
								'Landscape'			=>	esc_html__( 'Landscape', 'toppic' ),
								'Portrait'			=>	esc_html__( 'Portrait', 'toppic' ),														
							),
					'std' 		=> 'Random',
					'visible' 	 => array( '_gallery_layout_value', 'Fullscreen-Grid' )
				),
				array(
					'name'             => esc_html__( 'Transition effect', 'toppic' ),
					'id'               => '_full_style_value',
					'type'             => 'select',
					'tab'			   => 'page',
					'options' => array(
								'Default'		=>	esc_html__( 'Default', 'toppic' ),	
								'Fade'			=>  esc_html__( 'Fade', 'toppic' ),
								'Move'			=>	esc_html__( 'Move', 'toppic' )													
							),
					'std' 		=> 'Default',
					'visible' 	 => array( '_gallery_layout_value', 'Fullscreen' )
				),
				array(
					'name'             => esc_html__( 'Image scaling', 'toppic' ),
					'id'               => '_scale_mode_value',
					'type'             => 'button_group',
					'tab'			   => 'page',
					'options' => array(
								'Fill'		=>	esc_html__( 'Fill', 'toppic' ),	
								'Fit'			=>  esc_html__( 'Fit', 'toppic' )												
							),
					'std' 		=> 'Fill',
					'visible' 	 => array( '_gallery_layout_value', 'Fullscreen' )
				),
				array(
					'name'             => esc_html__( 'Display nearby images', 'toppic' ),
					'id'               => '_near_by_value',
					'type'             => 'button_group',
					'tab'			   => 'page',
					'options' => array(
								'Yes'		=>	esc_html__( 'Yes', 'toppic' ),	
								'No'		=>  esc_html__( 'No', 'toppic' )												
							),
					'std' 		=> 'No',
					'visible' => array(
						'when' => array(
							 array( '_gallery_layout_value', 'Fullscreen' ),
							 array( '_scale_mode_value', 'Fit' )
						 ),
						 'relation' => 'and'
					)
				),
				array(
					'name'             => esc_html__( 'Gallery images', 'toppic' ),
					'desc'			   => esc_html__( 'Select or upload images. Use drag and drop if you need to reorder images. ', 'toppic' ),
					'id'               => "{$prefix}imgadv",
					'type'             => 'image_advanced',
					'tab'			   => 'page',
					'max_file_uploads' => 0,
				),
			)
		)			
					
	);
	
	
	// POST META
	
	$meta_boxes[] = array(
		'title' => esc_html__( 'Page Attributes', 'toppic' ),
		'post_types'  => array ( 'post' ),
		'id' => 'kktfwp-page-settings',
		'context' => 'normal',
		'priority' => 'high',
		
		'tabs'      => array(			
			'page' => array(
				'label' => esc_html__( 'Post Settings', 'toppic' ),
				'icon'  => 'dashicons-welcome-write-blog', // Dashicon
			),	
			'background' => array(
				'label'      => esc_html__( 'Background', 'toppic' ),
				'icon'  => 'dashicons-welcome-view-site', // Dashicon
			),			
		),
		
		// Tab style: 'default', 'box' or 'left'. Optional
		'tab_style' => 'left',

		'fields' => array_merge(
			
			$bgMeta,	
			
			array(
				array(
					'name'             => esc_html__( 'Gallery images', 'toppic' ),
					'id'               => "{$prefix}imgpost",
					'tab'  			   => 'page',
					'type'             => 'image_advanced',
					'max_file_uploads' => 0,
					'visible' => array( 'post_format', 'gallery' )
				),
				array(
					'name' 			   => esc_html__( 'Link URL', 'toppic' ),
					'desc' 			   => esc_html__( 'Enter the link URL (e.g. http://***.com or http://www.***.com)', 'toppic' ),
					'id' 			   => '_post_link_value',
					'type' 			   => 'url',
					'tab'  			   => 'page',
					'visible' => array( 'post_format', 'link' )				
				),
				array(
					'name' 			   => esc_html__( 'Quote', 'toppic' ),
					'desc' 			   => esc_html__( 'Write your quote here', 'toppic' ),
					'id' 			   => '_post_quote_value',
					'type' 			   => 'textarea',
					'tab'  			   => 'page',
					'visible' => array( 'post_format', 'quote' )				
				),
				array(
					'name' 			   => esc_html__( 'Quote source', 'toppic' ),
					'desc' 			   => esc_html__( 'Write quote source or leave this field blank. HTML tags are allowed.', 'toppic' ),
					'id' 			   => '_post_quote_source_value',
					'type' 			   => 'text',
					'tab'  			   => 'page',
					'visible' => array( 'post_format', 'quote' )				
				),
				array(
					'name' 			   => esc_html__( 'oEmbed video', 'toppic' ),
					'desc' 			   => esc_html__( 'Paste here your oEmbeded code', 'toppic' ),
					'id' 			   => '_post_video_value',
					'type' 			   => 'textarea',
					'tab'  			   => 'page',
					'visible' => array( 'post_format', 'video' )				
				)
			), $parallax			
		)			
	);

	return $meta_boxes;
}