<?php
/**
 * General Settings Page
 *
 * @package SimpleCalendar/Admin
 */
namespace SimpleCalendar\Admin\Pages;

use SimpleCalendar\Abstracts\Admin_Page;

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

/**
 * General settings.
 *
 * Handles the plugin general settings and outputs the markup the settings page.
 *
 * @since 3.0.0
 */
class Advanced extends Admin_Page
{
	/**
	 * Constructor.
	 *
	 * @since 3.0.0
	 */
	public function __construct()
	{
		$this->id = 'advanced';
		$this->option_group = 'settings';
		$this->label = __('Advanced', 'google-calendar-events');
		//$this->description  = __( 'Advanced settings.', 'google-calendar-events' );
		$this->sections = $this->add_sections();
		$this->fields = $this->add_fields();
	}

	/**
	 * Add sections.
	 *
	 * @since  3.0.0
	 *
	 * @return array
	 */
	public function add_sections()
	{
		return apply_filters('simcal_add_' . $this->option_group . '_' . $this->id . '_sections', [
			'assets' => [
				'title' => __('Styles', 'google-calendar-events'),
				'description' =>
					'<div class="simcal-text-sm simcal-font-poppins simcal-font-normal simcal-text-sc_grey-100 simcal-mt-[5px] ">' .
					__('Manage front end assets that handle the calendars appearance.', 'google-calendar-events') .
					'</div>',
			],
			'optimisation' => [
				'title' => __('Optimisation', 'google-calendar-events'),
				'description' =>
					'<div class="simcal-text-sm simcal-font-poppins simcal-font-normal simcal-text-sc_grey-100 simcal-mt-[5px] ">' .
					__('Manage front end styles & scripts loading behavior.', 'google-calendar-events') .
					'</div>',
			],
			'installation' => [
				'title' => __('Installation', 'google-calendar-events'),
				'description' =>
					'<div class="simcal-text-sm simcal-font-poppins simcal-font-normal simcal-text-sc_grey-100 simcal-mt-[5px] ">' .
					__('Manage your data (plugin settings and saved calendars).', 'google-calendar-events') .
					'</div>',
			],
		]);
	}

	/**
	 * Add fields.
	 *
	 * @since  3.0.0
	 *
	 * @return array
	 */
	public function add_fields()
	{
		$fields = [];
		$this->values = get_option('simple-calendar_' . $this->option_group . '_' . $this->id);

		foreach ($this->sections as $section => $a):
			if ('assets' == $section) {
				$fields[$section] = [
					'disable_css' => [
						'title' => __('Disable CSS', 'google-calendar-events'),
						'tooltip' => __(
							'If ticked, this option will prevent all front end stylesheets to load. This also includes all add-on stylesheets.',
							'google-calendar-events'
						),
						'type' => 'checkbox',
						'name' => 'simple-calendar_' . $this->option_group . '_' . $this->id . '[' . $section . '][disable_css]',
						'id' => 'simple-calendar-' . $this->option_group . '-' . $this->id . '-' . $section . '-disable-css',
						'value' => $this->get_option_value($section, 'disable_css'),
					],
				];
			} elseif ('optimisation' == $section) {
				$fields[$section] = [
					'disable_lazy_loading' => [
						'title' => __('Disable Lazy Loading', 'google-calendar-events'),
						'tooltip' => __(
							'By default, calendar scripts and styles only load on pages that contain calendars or calendar shortcodes for improved performance. When this option is checked (disabled), scripts and styles will load on all pages (old behavior).',
							'google-calendar-events'
						),
						'type' => 'checkbox',
						'name' =>
							'simple-calendar_' . $this->option_group . '_' . $this->id . '[' . $section . '][disable_lazy_loading]',
						'id' =>
							'simple-calendar-' . $this->option_group . '-' . $this->id . '-' . $section . '-disable-lazy-loading',
						'value' => $this->get_option_value($section, 'disable_lazy_loading'),
					],
				];
			} elseif ('installation' == $section) {
				$fields[$section] = [
					'delete_settings' => [
						'title' => __('Delete settings', 'google-calendar-events'),
						'tooltip' => __(
							'Tick this option if you want to wipe this plugin settings from database when uninstalling.',
							'google-calendar-events'
						),
						'type' => 'checkbox',
						'name' =>
							'simple-calendar_' . $this->option_group . '_' . $this->id . '[' . $section . '][delete_settings]',
						'id' => 'simple-calendar-' . $this->option_group . '-' . $this->id . '-' . $section . '-delete-settings',
						'value' => $this->get_option_value($section, 'delete_settings'),
					],
					'erase_data' => [
						'title' => __('Erase calendar data', 'google-calendar-events'),
						'tooltip' => __(
							'By default your data will be retained in database even after uninstall. Tick this option if you want to delete all your calendar data when uninstalling.',
							'google-calendar-events'
						),
						'type' => 'checkbox',
						'name' => 'simple-calendar_' . $this->option_group . '_' . $this->id . '[' . $section . '][erase_data]',
						'id' => 'simple-calendar_' . $this->option_group . '_' . $this->id . '-delete-data',
						'value' => $this->get_option_value($section, 'erase_data'),
					],
				];
			}
		endforeach;

		return apply_filters('simcal_add_' . $this->option_group . '_' . $this->id . '_fields', $fields);
	}
}
