<?php

/**
 * Class deprecated. Pending remove from the core package as soon as we are sure that there is no
 * developer referring to functions inside it
 * 
 * @author appscreo
 *
 */

class ESSBOptionsInterface {
	
	public static function draw_form_start($custom = false, $group = '', $without_menu = false) {
		global $_REQUEST, $current_tab, $essb_options;
		
		$active_section = isset($_REQUEST['section']) ? $_REQUEST['section'] : '';
		$active_subsection = isset($_REQUEST['subsection']) ? $_REQUEST['subsection'] : '';
		
		$active_section = sanitize_text_field($active_section);
		$active_subsection = sanitize_text_field($active_subsection);
		
		$admin_template = '';

		echo '<script type="text/javascript">var loadedEditorControls = {};</script>';
		echo '<form id="essb_options_form" enctype="multipart/form-data" method="post" action="">';
		if ($custom && !empty($group)) {
			settings_fields( $group );
			wp_nonce_field( 'essb_setup', 'essb_token' );
			echo '<input type="hidden" name="essb_salt" value="'.sanitize_text_field(essb_admin_setting_token()).'"/>';
		}
		else {
			echo '<input type="hidden" name="action" value="update"/>';
			echo '<input type="hidden" name="option_page" value="essb_settings_group"/>';
			wp_nonce_field( 'essb_setup', 'essb_token' );
			echo '<input type="hidden" name="essb_salt" value="'.sanitize_text_field(essb_admin_setting_token()).'"/>';
				
		}
		echo '<input id="section" name="section" type="hidden" value="'.sanitize_text_field($active_section).'"/>';
		echo '<input id="subsection" name="subsection" type="hidden" value="'.sanitize_text_field($active_subsection).'"/>';
		echo '<input id="tab" name="tab" type="hidden" value="'.sanitize_text_field($current_tab).'"/>';
		echo '<div class="essb-options '.$admin_template.' '.($without_menu ? "essb-options-nomenu":'').'" id="essb-options">';
	}
	
	public static function draw_header5($title = '', $hide_update_button = false, $wizard_tab = false, $custom_code = '') {
		if ($hide_update_button) {
			echo '<div class="essb-options-header" id="essb-options-header">
			<a href="#" text="Back to top" class="essb-btn essb-btn-light essb-button-backtotop" id="essb-btn-backtotop">' . esc_html__ ( 'Back To Top', 'essb' ) . '</a>
				
			</div>';
			
			echo '<div class="essb-options-title">
			' . $title . '
			</div>';
			
		
		}
		else {
			$update_button_text = esc_html__('Update Settings', 'essb');
			$next_prev_buttons = "";
			if ($wizard_tab) {
				$update_button_text = esc_html__('Save Settings', 'essb');
				$next_prev_buttons = '<a name="prevbutton" id="prevbutton" class="essb-btn essb-wizard-prev">< Previous</a>&nbsp;<a name="nextbutton" id="nextbutton" class="essb-btn essb-wizard-next">Next ></a>&nbsp;&nbsp;&nbsp;';
			}
				
			echo '<div class="essb-options-header" id="essb-options-header">
			'.$custom_code.'
			<input type="Submit" name="Submit" value="' . $update_button_text . '" class="essb-btn essb-btn-red" id="essb-btn-update" />
			<a href="#" text="Back to top" class="essb-btn essb-btn-light essb-button-backtotop" id="essb-btn-backtotop"><i class="fa fa-arrow-up"></i> ' . esc_html__ ( 'Back To Top', 'essb' ) . '</a>
			'.$next_prev_buttons.'
			</div>';
			
			echo '<div class="essb-options-title">
			' . $title . '<span class="essb-options-subtitle"></span>
			</div>';
			
		}
		
	}
	
	public static function draw_header($title = '', $hide_update_button = false, $wizard_tab = false) {
		if ($hide_update_button) {
			echo '<div class="essb-options-header" id="essb-options-header">
			<div class="essb-options-title">
			' . $title . '
			</div>
			<a href="#" text="Back to top" class="essb-btn essb-btn-light essb-button-backtotop">' . esc_html__ ( 'Back To Top', 'essb' ) . '</a>
			
			</div>';
		
		} 
		else {
			$update_button_text = esc_html__('Update Settings', 'essb');
			$next_prev_buttons = "";
			if ($wizard_tab) {
				$update_button_text = esc_html__('Save Settings', 'essb');
				$next_prev_buttons = '<a name="prevbutton" id="prevbutton" class="essb-btn essb-wizard-prev">< Previous</a>&nbsp;<a name="nextbutton" id="nextbutton" class="essb-btn essb-wizard-next">Next ></a>&nbsp;&nbsp;&nbsp;';
			}
			else {
				if (!essb_options_bool_value('deactivate_ajaxsubmit')) {
					$next_prev_buttons = '<a name="search-button" id="essb-search-button" class="essb-btn essb-wizard-prev"><i class="fa fa-search"></i> '.esc_html__('Search Options', 'essb').'</a>';
				}
			}
			
			echo '<div class="essb-options-header" id="essb-options-header">
				<div class="essb-options-title">
			  	' . $title . '<span class="essb-options-subtitle"></span>
				</div>		
				<a href="#" text="Back to top" class="essb-btn essb-btn-light essb-button-backtotop"><i class="fa fa-arrow-up"></i> ' . esc_html__ ( 'Back To Top', 'essb' ) . '</a>
				'.$next_prev_buttons.'
				<input type="Submit" name="Submit" value="' . $update_button_text . '" class="essb-btn essb-btn-red" id="essb-btn-update" />				
			</div>';
		}
	}
	
	public static function draw_sidebar($options = array()) {
		
		echo '<div class="essb-options-sidebar" id="essb-options-sidebar">';

		echo '<ul class="essb-options-group-menu" id="sticky-navigation">';
		
		foreach ($options as $single) {
			$type = $single['type'];
			$field_id = isset($single['field_id']) ? $single['field_id'] : '';
			$title = isset($single['title']) ? $single['title'] : '';
			$sub_menuaction = isset($single['action']) ? $single['action'] : '';
			$default_child = isset($single['default_child']) ? $single['default_child'] : '';
			$icon = isset($single['icon']) ? $single['icon'] : '';
			
			$level2 = isset($single['level2']) ? $single['level2'] : '';
			
			if ($icon == 'default') {
				$icon = 'gear';
			}
			
			if ($level2 == 'true') {
				$icon = 'circle essb-navigation-small-icon';
			}
			
			if ($icon != '') {
				if (strpos($icon, 'ti-') !== false ) {
					$icon = sprintf('<i class="essb-sidebar-icon %1$s"></i>', $icon);
				}
				else {
					$icon = sprintf('<i class="essb-sidebar-icon fa fa-%1$s"></i>', $icon);
				}
			}
			
			$css_class = "";
			switch ($type) {
				case "menu_item":
					$css_class = "essb-menu-item";
					
					if ($sub_menuaction == "activate_first") {
						$css_class .= " essb-activate-first";
					}
					break;
				case "sub_menu_item":
					$css_class = "essb-submenu-item";
					
					if ($sub_menuaction == 'menu') {
						$css_class .= " essb-submenu-menuitem";
					}
					
					if ($level2 == 'true') {
						$css_class .= " level2";
					}
					
					if ($level2 != 'title') {
						$css_class .= ' essb-submenu-with-action';
					}
					if ($level2 == 'title') {
						$css_class .= ' essb-submenu-title';
					}
					
					break;
				case "heading":
					$css_class = "essb-title";
					break;
				default:
					$css_class = "essb-menu-item";
					break;
			}
			
			printf('<li class="%1$s essb-menuid-%2$s" data-menu="%2$s" data-activate-child="%4$s" id="essb-menu-%2$s"><a href="#">%5$s%3$s</a></li>', $css_class, $field_id, $title, $default_child, $icon);
		}
		
		echo '</ul>';
		
		echo '</div>';
		
	}
	
	public static function draw_content($options = array(), $custom = false, $user_settings = array()) {
		echo '<div class="essb-options-container" style="min-height: 840px;">';
				
		foreach($options as $section => $fields) {
			printf('<div id="essb-container-%1$s" class="essb-data-container">',$section);
									
			echo '<div class="essb-flex-grid">';
			$section_options = $fields;
			
			ESSBOptionsFramework::reset_row_status();
			
			foreach ($section_options as $option) {
				ESSBOptionsFramework::draw_options_field($option, $custom, $user_settings);
			}
			
			echo '</div>';
			
			echo '</div>';
		}
		
		echo '</div>';
	}	
	
	public static function draw_form_end() {
		echo '</div>';
		echo '</form>';
	}
	
}

?>