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

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

add_filter( 'adde-options', 'adde_options_page' );
/**
 * This function is a adde-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 adde_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="ADDE-options-tab">
				<div v-cloak>
					<ul class="list-inline">
						<li class="active"><a href="admin.php?page=adde-options">' . esc_html__( 'Options', 'adde' ) . '</a></li>
					</ul>
				</div>
			</div>';
	$output .= $options_table;
	$output .= '</div>';
	$output .= WPSCORE()->display_footer( false );
	$output .= '</div></div>';
	return $output;

}

add_action( 'xbox_init', 'adde_options' );

/**
 * This function is a xbox_init action callback to define all the plugin Xbox options.
 *
 * @return void
 */
function adde_options() {
	$options = array(
		'id'         => 'ADDE-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-adblocker-detector-general'] = '<i class="xbox-icon xbox-icon-gear"></i>' . esc_html__( 'General', 'adde' );
	$items['wps-adblocker-detector-content'] = '<i class="xbox-icon xbox-icon-edit"></i>' . esc_html__( 'Content', 'adde' );

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

	/**
	 * GENERAL
	 */
	$xbox->open_tab_item( 'wps-adblocker-detector-general' );
		$xbox->add_field(
			array(
				'name'    => esc_html__( 'Dev mode for admin', 'adde' ),
				'id'      => 'adblocker-detector-dev-mode',
				'type'    => 'switcher',
				'default' => 'off',
				'grid'    => '2-of-8',
				'desc'    => esc_html__( 'This option allows you to see the adblocker detector popup even if you don\'t have an adblocker extension. Useful to make tests.', 'adde' ),
			)
		);

		$xbox->add_field(
			array(
				'name'    => esc_html__( 'Dark mode', 'adde' ),
				'id'      => 'adblocker-detector-dark-mode',
				'type'    => 'switcher',
				'default' => 'off',
				'grid'    => '2-of-8',
				'desc'    => esc_html__( 'Turn your adblocker detector popup into dark mode.', 'adde' ),
			)
		);

		$xbox->add_field(
			array(
				'id'      => 'refresh-button-color',
				'name'    => esc_html__( 'Refresh button color', 'adde' ),
				'type'    => 'colorpicker',
				'default' => '#d10d12',
				'desc'    => esc_html__( 'Choose the color of the Refresh button.', 'adde' ),
				'grid'    => '2-of-8',
			)
		);

		$xbox->add_field(
			array(
				'name'    => esc_html__( 'Display Close button', 'adde' ),
				'id'      => 'display-adblocker-detector-close-button',
				'type'    => 'switcher',
				'default' => 'on',
				'grid'    => '2-of-8',
				'desc'    => esc_html__( 'Display a Close button to allow visitors which use an adblocker extension to navigate on your site.', 'adde' ),
			)
		);

		$xbox->open_mixed_field(
			array(
				'id'   => 'displayed-when:switch:display-adblocker-detector-close-button:on:close-button-color-settings',
				'name' => esc_html__(
					'Close button color',
					'adde'
				),
			)
		);
			$xbox->add_field(
				array(
					'id'      => 'close-button-color',
					'name'    => '',
					'type'    => 'colorpicker',
					'default' => '#777777',
					'desc'    => esc_html__( 'Choose the color of the Close button.', 'adde' ),
					'grid'    => '2-of-8',
				)
			);
		$xbox->close_mixed_field();
	$xbox->close_tab_item( 'wps-adblocker-detector-general' );

	/**
	 * CONTENT
	 */
	$xbox->open_tab_item( 'wps-adblocker-detector-content' );
		$xbox->add_field(
			array(
				'id'      => 'adblocker-detector-title',
				'name'    => esc_html__( 'Title', 'adde' ),
				'type'    => 'text',
				'default' => 'Adblocker detected!',
				'grid'    => '8-of-8 last',
				'desc'    => esc_html__( 'Set a title at the top of the adblocker-detector popup.', 'adde' ),
			)
		);

		$xbox->add_field(
			array(
				'id'      => 'adblocker-detector-description',
				'name'    => esc_html__( 'Description', 'adde' ),
				'type'    => 'textarea',
				'default' => 'We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.',
				'grid'    => '8-of-8 last',
				'desc'    => esc_html__( 'Set a description in your adblocker detector popup.', 'adde' ),
			)
		);

		$xbox->open_mixed_field( array( 'name' => esc_html__( 'Buttons text', 'adde' ) ) );
			$xbox->add_field(
				array(
					'id'      => 'adblocker-detector-refresh-button-text',
					'name'    => esc_html__( 'Refresh button', 'adde' ),
					'type'    => 'text',
					'default' => 'Refresh',
					'desc'    => esc_html__( 'Set the text for the "Refresh" button.', 'adde' ),
					'grid'    => '4-of-8',
				)
			);
			$xbox->add_field(
				array(
					'id'      => 'adblocker-detector-close-button-text',
					'name'    => esc_html__( 'Close button', 'adde' ),
					'type'    => 'text',
					'default' => 'Close',
					'desc'    => esc_html__( 'Set the text for the "Close" button.', 'adde' ),
					'grid'    => '4-of-8 last',
				)
			);
		$xbox->close_mixed_field();
	$xbox->close_tab_item( 'wps-adblocker-detector-content' );
	$xbox->close_tab( 'main-tab' );
}
