<?php
/**
 * Options page.
 *
 * @package DCLM\Admin\Pages
 */

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

add_filter( 'dclm-options', 'dclm_options_page' );
/**
 * This function is a dclm-options filter callback to display WP-Script logo & tabs at the top of the Xbox options page.
 *
 * @param string $options_table - default options HTML string to render the Xbox options in the page.
 * @return $output
 */
function dclm_options_page( $options_table ) {
	$output  = '<div id="wp-script"><div class="content-tabs">';
	$output .= WPSCORE()->display_logo( false );
	$output .= WPSCORE()->display_tabs( false );
	$output .= '
		<div class="tab-content tab-options">
			<div class="tab-pane fade in active" id="DCLM-options-tab">
				<div v-cloak>
					<ul class="list-inline">
						<li class="active"><a href="admin.php?page=dclm-options">' . esc_html__( 'Options', 'dclm' ) . '</a></li>
					</ul>
				</div>
			</div>';
	$output .= $options_table;
	$output .= '</div>';
	$output .= WPSCORE()->display_footer( false );
	$output .= '</div></div>';
	return $output;
}

add_action( 'xbox_init', 'dclm_options' );

/**
 * This function is a xbox_init action callback to define all the plugin Xbox options.
 *
 * @return void
 */
function dclm_options() {
	$options = array(
		'id'         => 'DCLM-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 );

	$items['wps-disclaimer-general']     = '<i class="xbox-icon xbox-icon-gear"></i>' . esc_html__( 'General', 'dclm' );
	$items['wps-disclaimer-content']     = '<i class="xbox-icon xbox-icon-edit"></i>' . esc_html__( 'Content', 'dclm' );
	$items['wps-disclaimer-advertising'] = '<i class="xbox-icon xbox-icon-money"></i>' . esc_html__( 'Advertising', 'dclm' );

	$xbox->add_main_tab(
		array(
			'name'  => 'Main tab',
			'id'    => 'main-tab',
			'items' => $items,
		)
	);

	/**
	 * GENERAL
	 */
		$xbox->open_tab_item( 'wps-disclaimer-general' );
		$xbox->add_field(
			array(
				'name'    => esc_html__( 'Dev mode for admin', 'dclm' ),
				'id'      => 'disclaimer-disable-cookie-admin',
				'type'    => 'switcher',
				'default' => 'off',
				'grid'    => '2-of-8',
				'desc'    => esc_html__( 'This option allows you to continue seeing the disclaimer popup even if you click on "YES".', 'dclm' )
					. '<br>'
					. esc_html__( 'Useful to make tests.', 'dclm' ),
			)
		);

		$xbox->add_field(
			array(
				'name'       => esc_html__( 'Atmosphere', 'wpst' ),
				'id'         => 'disclaimer-atmosphere',
				'type'       => 'image_selector',
				'default'    => 'dark',
				'items'      => array(
					'dark'  => DCLM_URL . 'admin/assets/img/options/dark-atmosphere.jpg',
					'light' => DCLM_URL . 'admin/assets/img/options/light-atmosphere.jpg',
				),
				'items_desc' => array(
					'dark'  => esc_html__( 'Dark', 'wpst' ),
					'light' => esc_html__( 'Light', 'wpst' ),
				),
				'options'    => array(
					'width'   => '160px',
					'in_line' => true,
				),
			)
		);

		$xbox->open_mixed_field( array( 'name' => esc_html__( 'Buttons color', 'dclm' ) ) );
			$xbox->add_field(
				array(
					'id'      => 'yes-button-color',
					'name'    => esc_html__( 'YES button', 'dclm' ),
					'type'    => 'colorpicker',
					'default' => '#7fbf4d',
					'desc'    => esc_html__( 'Choose the color of the YES button.', 'dclm' ),
					'grid'    => '2-of-8',
				)
			);
			$xbox->add_field(
				array(
					'id'      => 'no-button-color',
					'name'    => esc_html__( 'NO button', 'dclm' ),
					'type'    => 'colorpicker',
					'default' => '#999999',
					'desc'    => esc_html__( 'Choose the color of the NO button.', 'dclm' ),
					'grid'    => '2-of-8',
				)
			);
		$xbox->close_mixed_field();

		$xbox->add_field(
			array(
				'name'    => esc_html__( 'Logo', 'dclm' ),
				'id'      => 'logo-disclaimer',
				'type'    => 'switcher',
				'default' => 'off',
				'grid'    => '2-of-8',
				'desc'    => esc_html__( 'Display your logo inside the disclaimer popup.', 'dclm' ),
			)
		);
		$xbox->close_mixed_field();

		$xbox->open_mixed_field(
			array(
				'id'   => 'displayed-when:switch:logo-disclaimer:on:logo-disclaimer-settings',
				'name' => esc_html__(
					'Logo settings',
					'dclm'
				),
			)
		);
			$xbox->add_field(
				array(
					'id'      => 'logo-disclaimer-file',
					'name'    => esc_html__( 'Image logo URL', 'dclm' ),
					'type'    => 'file',
					'grid'    => '3-of-6',
					'options' => array(
						'preview_size' => array(
							'width'  => '100%',
							'height' => 'auto',
						),
					),
				)
			);
			$xbox->add_field(
				array(
					'name'       => esc_html__( 'Width', 'dclm' ),
					'id'         => 'logo-disclaimer-width',
					'type'       => 'number',
					'default'    => 50,
					'attributes' => array(
						'min'       => 1,
						'max'       => 100,
						'step'      => 1,
						'precision' => 0,
					),
					'options'    => array(
						'unit' => esc_html__( '%', 'dclm' ),
					),
					'desc'       => esc_html__( 'Set the logo width (1% - 100%).', 'dclm' ),
					'grid'       => '3-of-6 last',
				)
			);
			$xbox->add_field(
				array(
					'name'       => esc_html__( 'Opacity', 'dclm' ),
					'id'         => 'logo-disclaimer-opacity',
					'type'       => 'number',
					'default'    => 50,
					'attributes' => array(
						'min'       => 1,
						'max'       => 100,
						'step'      => 1,
						'precision' => 0,
					),
					'options'    => array(
						'unit' => esc_html__( '%', 'dclm' ),
					),
					'desc'       => esc_html__( 'Set the logo opacity (1% - 100%).', 'dclm' ),
					'grid'       => '3-of-6',
				)
			);
			$xbox->add_field(
				array(
					'name'    => esc_html__( 'Grayscale', 'dclm' ),
					'id'      => 'logo-disclaimer-grayscale',
					'type'    => 'switcher',
					'default' => 'off',
					'grid'    => '3-of-6 last',
				)
			);
		$xbox->close_mixed_field();

		/**
		 * BACKGROUND
		 */
		$xbox->add_field(
			array(
				'name'    => esc_html__( 'Custom background', 'dclm' ),
				'id'      => 'disclaimer-custom-background',
				'type'    => 'switcher',
				'default' => 'off',
			)
		);
		/* If on */
		$xbox->open_mixed_field(
			array(
				'id'   => 'displayed-when:switch:disclaimer-custom-background:on:disclaimer-background-settings',
				'name' => esc_html__(
					'Background settings',
					'dclm'
				),
			)
		);
			$xbox->add_field(
				array(
					'name'       => esc_html__( 'Blur', 'dclm' ),
					'id'         => 'disclaimer-background-blur',
					'type'       => 'number',
					'default'    => 8,
					'attributes' => array(
						'min'       => 0,
						'max'       => 20,
						'step'      => 1,
						'precision' => 0,
					),
					'options'    => array(
						'unit' => esc_html__( 'px', 'dclm' ),
					),
					'desc'       => esc_html__( 'Set the background blur (0 - 20px).', 'dclm' ),
					'grid'       => '3-of-6',
				)
			);
			$xbox->add_field(
				array(
					'name'    => esc_html__( 'Background color', 'dclm' ),
					'id'      => 'disclaimer-background-color',
					'type'    => 'colorpicker',
					'default' => '#000000',
					'grid'    => '3-of-6 last',
				)
			);
			$xbox->add_field(
				array(
					'name'       => esc_html__( 'Background color opacity', 'dclm' ),
					'id'         => 'disclaimer-background-color-opacity',
					'type'       => 'number',
					'default'    => 80,
					'attributes' => array(
						'min'       => 1,
						'max'       => 100,
						'step'      => 1,
						'precision' => 0,
					),
					'options'    => array(
						'unit' => esc_html__( '%', 'dclm' ),
					),
					'desc'       => esc_html__( 'Set the logo opacity (1% - 100%).', 'dclm' ),
					'grid'       => '3-of-6',
				)
			);
			$xbox->add_field(
				array(
					'name'    => esc_html__( 'Image', 'dclm' ),
					'id'      => 'disclaimer-background-image',
					'type'    => 'file',
					'grid'    => '3-of-6 last',
					'options' => array(
						'preview_size' => array(
							'width'  => '80px',
							'height' => '45px',
						),
					),
				)
			);
			$xbox->add_field(
				array(
					'name'    => esc_html__( 'Repeat', 'dclm' ),
					'id'      => 'disclaimer-background-repeat',
					'type'    => 'select',
					'default' => 'no-repeat',
					'items'   => array(
						'repeat'    => 'Yes',
						'no-repeat' => 'No',
					),
					'grid'    => '3-of-6',
				)
			);
			$xbox->add_field(
				array(
					'name'    => esc_html__( 'Position', 'dclm' ),
					'id'      => 'disclaimer-background-position',
					'type'    => 'select',
					'default' => 'center',
					'items'   => array(
						'bottom' => 'Bottom',
						'center' => 'Center',
						'top'    => 'Top',
					),
					'grid'    => '3-of-6 last',
				)
			);
			$xbox->add_field(
				array(
					'name'    => esc_html__( 'Size', 'dclm' ),
					'id'      => 'disclaimer-background-size',
					'type'    => 'select',
					'default' => 'cover',
					'items'   => array(
						'auto'    => 'Auto',
						'cover'   => 'Cover',
						'contain' => 'Contain',
					),
					'grid'    => '3-of-6',
				)
			);
		$xbox->close_mixed_field();
	$xbox->close_tab_item( 'wps-disclaimer-general' );

	/**
	 * CONTENT
	 */
	$xbox->open_tab_item( 'wps-disclaimer-content' );
		$xbox->add_field(
			array(
				'id'      => 'disclaimer-title',
				'name'    => esc_html__( 'Title', 'dclm' ),
				'type'    => 'text',
				'default' => 'Are you 18 or older?',
				'grid'    => '4-of-8',
				'desc'    => esc_html__( 'Set a title at the top of the disclaimer popup.', 'dclm' ),
			)
		);

		$xbox->open_mixed_field( array( 'name' => esc_html__( 'Buttons text', 'dclm' ) ) );
			$xbox->add_field(
				array(
					'id'      => 'disclaimer-yes-button-text',
					'name'    => esc_html__( 'YES button', 'dclm' ),
					'type'    => 'text',
					'default' => 'Yes',
					'desc'    => esc_html__( 'Set the text for the "YES" button.', 'dclm' ),
					'grid'    => '2-of-8',
				)
			);
			$xbox->add_field(
				array(
					'id'      => 'disclaimer-no-button-text',
					'name'    => esc_html__( 'NO button', 'dclm' ),
					'type'    => 'text',
					'default' => 'No',
					'desc'    => esc_html__( 'Set the text for the "NO" button.', 'dclm' ),
					'grid'    => '2-of-8',
				)
			);
		$xbox->close_mixed_field();

		$xbox->add_field(
			array(
				'id'      => 'disclaimer-description',
				'name'    => esc_html__( 'Description', 'dclm' ),
				'type'    => 'textarea',
				'default' => 'You must verify that you are 18 years of age or older to enter this site.',
				'grid'    => '4-of-8',
				'desc'    => esc_html__( 'Set a description at the bottom of the disclaimer popup.', 'dclm' ),
			)
		);

		$xbox->add_field(
			array(
				'id'      => 'disclaimer-nope-title',
				'name'    => esc_html__( 'Nope title', 'dclm' ),
				'type'    => 'text',
				'default' => 'We\'re sorry!',
				'grid'    => '4-of-8',
				'desc'    => esc_html__( 'Set a title at the top of the disclaimer popup when the visitor choosed "NO".', 'dclm' ),
			)
		);

		$xbox->add_field(
			array(
				'id'      => 'disclaimer-nope-under-title',
				'name'    => esc_html__( 'Nope under title', 'dclm' ),
				'type'    => 'text',
				'default' => 'I hit the wrong button!',
				'grid'    => '4-of-8',
				'desc'    => esc_html__( 'Text under the nope title.', 'dclm' ),
			)
		);
		$xbox->add_field(
			array(
				'id'      => 'disclaimer-nope-button-text',
				'name'    => esc_html__( 'Nope button text', 'dclm' ),
				'type'    => 'text',
				'default' => 'I\'m old enough!',
				'grid'    => '4-of-8',
				'desc'    => esc_html__( 'Text inside the nope button.', 'dclm' ),
			)
		);
		$xbox->add_field(
			array(
				'id'      => 'disclaimer-nope-description',
				'name'    => esc_html__( 'Nope Description', 'dclm' ),
				'type'    => 'textarea',
				'default' => 'You must be 18 years of age or older to enter this site.',
				'grid'    => '4-of-8',
				'desc'    => esc_html__( 'Set a description at the bottom of the disclaimer popup when the visitor choosed "NO".', 'dclm' ),
			)
		);
	$xbox->close_tab_item( 'wps-disclaimer-content' );

	/**
	 * ADVERTISING
	 */
	$xbox->open_tab_item( 'wps-disclaimer-advertising' );
		$xbox->add_field(
			array(
				'id'   => 'disclaimer-redirect-url',
				'name' => esc_html__( 'Redirect URL', 'dclm' ),
				'type' => 'text',
				'grid' => '6-of-6',
				'desc' => 'Set the Redirect URL when the visitor clicks on "YES" button.',
			)
		);
		$xbox->add_field(
			array(
				'name'    => esc_html__( 'Stay on site', 'dclm' ),
				'id'      => 'disclaimer-redirect-stay-on-site',
				'type'    => 'switcher',
				'default' => 'on',
				'grid'    => '2-of-8',
				'desc'    =>
				esc_html__( 'If you enable this option, your visitors will stay on your site and the Redirect Url will be opened as popunder.', 'dclm' ) . '<br>' .
				esc_html__( 'If you disable this option, your visitors will be redirected to the Redirect URL and your site will be opened as a popunder.', 'dclm' ) . '<br>' .
				esc_html__( 'The Redirect URL option must be filled.', 'dclm' ),
			)
		);
	$xbox->close_tab_item( 'wps-disclaimer-advertising' );

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