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

add_filter( 'amvg-options', 'AMVG_options_page' );
function AMVG_options_page( $options_table ) {

	$output = '
			<div id="wp-script">
        <div class="content-tabs">
            <div class="row">
                <div class="col-xs-12 padding-top-10 padding-bottom-10">
									<div class="logo"><h2><a href="https://www.wp-script.com" target="_blank"><img class="panda" src="' . WPSCORE_URL . 'admin/assets/images/logo-wp-script.svg" width="250"/></a></h2></div>
                </div>
            </div>';
	$output .= WPSCORE()->display_tabs(false);

	$output .= '
		<div class="tab-content tab-options">
			<div class="tab-pane fade in active" id="AMVG-options-tab">
				<div v-cloak>
					<ul class="list-inline">
						<li><a href="admin.php?page=amvg-import-videos"><i class="fa fa-cloud-download"></i> ' . __("Import videos", AMVG_LANG) . '</a></li>
						<li>|</li>
						<li class="active"><a href="admin.php?page=amvg-options"><i class="fa fa-wrench"></i> ' . __('Options', AMVG_LANG) . '</a></li>
					</ul>
				</div>
			</div>
		';

	$output .= $options_table;

	$output .= '</div></div></div>';

	return $output;

	//return WPSCORE()->display_options_page( 'AMVG-options-tab', $options_table, false );
}


add_action( 'xbox_init', 'AMVG_options');
function AMVG_options(){
	$options = array(
		'id' => 'AMVG-options',
		'icon' => XBOX_URL.'img/xbox-light-small.png',//Menu icon
		'skin' => 'pink',// Skins: blue, lightblue, green, teal, pink, purple, bluepurple, yellow, orange'
		'layout' => 'boxed',//wide
		'header' => array(
			'icon' => '<img src="'.XBOX_URL.'img/xbox-light.png"/>',
			'desc' => 'Customize here your Theme',
		),
		'capability' => 'edit_published_posts'
	);
	$xbox = xbox_new_admin_page( $options );
	$xbox->add_main_tab( array(
		'name' => 'Main tab',
		'id' => 'main-tab',
		'items' => array(
			'general' => '<i class="xbox-icon xbox-icon-gear"></i>General',
			'data-to-import' => '<i class="xbox-icon xbox-icon-download"></i>Data to import',
			'theme-compatibility' => '<i class="xbox-icon xbox-icon-desktop"></i>Theme Compatibility',
		),
	));
		/*******************/
		/***** GENERAL *****/
		/*******************/
		$xbox->open_tab_item('general');
			$xbox->add_field(array(
				'id' => 'search-results',
				'name' => 'Search results',
				'type' => 'number',
				'default' => 60,
				'grid' => '4-of-8',
				'options' => array(
						'unit' => 'videos / results'
					),
				'attributes' => array(
						'min' => 1,
						'max' => 120,
						'step' => 1
					),
				'desc' => 'Choose the number of videos displayed for each search (6 - 120)',
			));

			$xbox->add_field(array(
				'name' => 'Enable Auto-import',
				'id' => 'amvg-enable-auto-import',
				'type' => 'switcher',
				'default' => 'on',
				'grid' => '4-of-8',
				'desc' => 'Enable auto-import features (Don\'t forget to set auto-import option to Enabled for any saved feed you want)',
			));

			$xbox->open_mixed_field(array('id' => 'displayed-when:switch:amvg-enable-auto-import:on:auto-import-settings', 'name' => 'Auto import settings'));
				$xbox->add_field(array(
					'id' => 'auto-import-amount',
					'name' => 'Amount of videos to import',
					'type' => 'number',
					'default' => 10,
					'grid' => '4-of-8',
					'options' => array(
							'unit' => 'videos / auto-import'
						),
					'attributes' => array(
						'min' => 1,
						'max' => 50,
						'step' => 1
					),
					'desc' => 'Choose how many videos to import (1 - 50)',
				));
				$xbox->add_field(array(
					'name' => 'Frequency',
					'id' => 'amvg-auto-import-frequency',
					'type' => 'select',
					'desc' => 'Choose how often to import videos',
					'default' => 'twicedaily',
					'items' => array(
						'hourly' => 'Every 1 hour',
						'every_six_hours' => 'Every 6 hours',
						'twicedaily' => 'Every 12 hours',
						'daily' => 'Every 24 hours'
					),
					'grid' => '4-of-8-last'
				));
				$xbox->add_field(array(
					'name' => 'Server Cron',
					'id' => 'auto-import-server-cron',
					'type' => 'text',
					'desc' => 'Copy this command and <a href="https://www.wp-script.com/setup-server-cron-job-wordpress/" target="_blank">setup your Server Cron job</a>',
					'default' => 'wget -qO- ' . site_url( '/wp-cron.php' ) . ' &> /dev/null'
				));
			$xbox->close_mixed_field();

			$xbox->add_field(array(
				'id' => 'default-status',
				'name' => 'Default Status',
				'type' => 'radio',
				'default' => 'publish',
				'items' => array(
					'draft' => 'Draft',
					'publish' => 'Publish'
				),
				'desc' => 'Choose the status of the imported videos'
			));
			
			$xbox->open_mixed_field(array('name' => 'Proxy'));
			$xbox->add_field(array(
				'id' => 'proxy-ip',
				'name' => 'IP Adress',
				'type' => 'text',
				'grid' => '2-of-8',
				'desc' => 'Enter a valid Proxy IP',
			));
			$xbox->add_field(array(
				'id' => 'proxy-port',
				'name' => 'Port',
				'type' => 'text',
				'desc' => 'Enter a valid Proxy Port',
				'options' => array(
					'unit' => 'PORT'
				),
				'grid' => '4-of-8-last'
			));				
		$xbox->close_mixed_field();

		$xbox->close_tab_item('general');

		/****************/
		/***** DATA *****/
		/****************/
		$xbox->open_tab_item('data-to-import');
			$xbox->add_field(array(
				'name' => 'Title',
				'id' => 'import-title',
				'type' => 'switcher',
				'default' => 'on',
				'desc' => 'Check if you want to import videos title'
			));
			$xbox->add_field(array(
				'name' => 'Main thumb file',
				'id' => 'import-thumb',
				'type' => 'switcher',
				'default' => 'on',
				'desc' => 'Check if you want to download main thumb files (the thumb url will be saved in all cases)'
			));
			$xbox->add_field(array(
				'name' => 'Description',
				'id' => 'import-description',
				'type' => 'switcher',
				'default' => 'on',
				'desc' => 'Check if you want to import videos description'
			));
			$xbox->add_field(array(
				'name' => 'Tags',
				'id' => 'import-tags',
				'type' => 'switcher',
				'default' => 'on',
				'desc' => 'Check if you want to import videos tags'
			));
			$xbox->add_field(array(
				'name' => 'Actors',
				'id' => 'import-actors',
				'type' => 'switcher',
				'default' => 'on',
				'desc' => 'Check if you want to import videos actors'
			));
		$xbox->close_tab_item('data-to-import');

		/*******************************/
		/***** THEME COMPATIBILITY *****/
		/*******************************/
		$xbox->open_tab_item('theme-compatibility');

			$xbox->add_tab( array(
				'name' => 'Theme compatibility tabs',
				'id' => 'theme-compatibility-tabs',
				'items' => array(
					'player-in-content' => 'Player in content',
					'custom-fields' => 'Custom fields',
					'custom-post-type' => 'Custom post type'
				),
			));

			/* Player in content */
			$xbox->open_tab_item('player-in-content');
			$xbox->add_field(array(
				'id' => 'player-in-content',
				'name' => 'Player in content',
				'type' => 'switcher',
				'default' => 'off',
				'desc' => 'Check if you want to display the video player in the content',
				'grid' => '2-of-8',
			));

			//if on
			$xbox->open_mixed_field(array('id'=> 'displayed-when:switch:player-in-content:on:player-settings', 'name' => 'Player position'));

				$xbox->add_field(array(
					'id' 		=> 'player-position',
					'type' 		=> 'radio',
					'default' 	=> 'before',
					'items' 	=> array(
						'before' 	=> 'Before the content',
						'after' 	=> 'After the content'
					),
					'desc' 		=> 'Choose where to display the video player in the content',
					'grid' 		=> '4-of-8',
				));

				$xbox->close_mixed_field();

			$xbox->close_tab_item('player-in-content');
			
			/* Custom Fields */
			$xbox->open_tab_item('custom-fields');
				$xbox->add_field(array(
					'id' => 'custom-thumbnail',
					'name' => 'Thumbnail',
					'type' => 'text',
					'default' => 'thumb',
					'grid' => '3-of-6',
				));

				$xbox->add_field(array(
					'id' => 'custom-embed-player',
					'name' => 'Embed player',
					'type' => 'text',
					'default' => 'embed',
					'grid' => '3-of-6',
				));

				$xbox->add_field(array(
					'id' => 'custom-video-url',
					'name' => 'Video URL',
					'type' => 'text',
					'default' => 'video_url',
					'grid' => '3-of-6',
				));

				$xbox->add_field(array(
					'id' => 'custom-duration',
					'name' => 'Duration',
					'type' => 'text',
					'default' => 'duration',
					'grid' => '3-of-6',
				));

				$xbox->add_field(array(
					'id' => 'custom-tracking-url',
					'name' => 'Tracking URL',
					'type' => 'text',
					'default' => 'tracking_url',
					'grid' => '3-of-6',
				));
			$xbox->close_tab_item('custom-fields');

			/* Custom post type */
			$xbox->open_tab_item('custom-post-type');
				$xbox->add_field(array(
					'id' => 'custom-video-post-type',
					'name' => 'Video custom post type name',
					'type' => 'text',
					'default' => 'post',
					'desc' => 'Set the video custom post type used by your theme',
					'grid' => '3-of-6',
				));
				$xbox->add_field(array(
					'id' => 'custom-video-categories',
					'name' => 'Video custom categories',
					'type' => 'text',
					'default' => 'category',
					'desc' => 'Set the video categories used by your theme',
					'grid' => '3-of-6',
				));
				$xbox->add_field(array(
					'id' => 'custom-video-tags',
					'name' => 'Video custom tags',
					'type' => 'text',
					'default' => 'post_tag',
					'desc' => 'Set the video tags used by your theme',
					'grid' => '3-of-6',
				));
			$xbox->close_tab_item('custom-post-type');			
			$xbox->close_tab('theme-compatibility-tabs');

		$xbox->close_tab_item('theme-compatibility');

		
	$xbox->close_tab('main-tab');
}