<?php

$is_for_firsttime = get_option ( ESSB3_FIRST_TIME_NAME );
if ($is_for_firsttime) {
	if ($is_for_firsttime == 'true') {
		include (ESSB3_PLUGIN_ROOT . 'lib/admin/essb-first-time.php');
		return;
	}
}

if (!defined('ESSB3_CACHED_COUNTERS')) {
	define('ESSB3_CACHED_COUNTERS', true);
	if (!class_exists('ESSBCachedCounters')) {
		include_once(ESSB3_PLUGIN_ROOT . 'lib/core/share-counters/essb-cached-counters.php');
	}
}

global $essb_navigation_tabs, $essb_sidebar_sections, $essb_section_options;
global $essb_admin_options, $essb_options;
$essb_admin_options = get_option ( ESSB3_OPTIONS_NAME );
global $essb_networks;
$essb_networks = get_option ( ESSB3_NETWORK_LIST );
// if (! is_array ( $essb_networks )) {
$essb_networks = essb_available_social_networks ();

$purchase_code = ESSBOptionValuesHelper::options_value ( $essb_admin_options, 'purchase_code' );
// }

// print_r($essb_o;

// reset plugin settings to default
$reset_settings = isset ( $_REQUEST ['reset_settings'] ) ? $_REQUEST ['reset_settings'] : '';
if ($reset_settings == 'true') {
	$essb_admin_options = array ();
	$essb_options = array ();
	
	$default_options = ' ';
	
	$options_base = ESSB_Manager::convert_ready_made_option ( $default_options );
	// print_r($options_base);
	if ($options_base) {
		$essb_options = $options_base;
		$essb_admin_options = $options_base;
	}
	update_option ( ESSB3_OPTIONS_NAME, $essb_admin_options );
}

$dismiss_welcome = isset($_REQUEST['dismiss-welcome']) ? $_REQUEST['dismiss-welcome'] : '';
if ($dismiss_welcome == 'true') {
	$essb_options['disable_welcome'] = 'true';
	update_option ( ESSB3_OPTIONS_NAME, $essb_options );
}

$full_counter_update = isset($_REQUEST['essb_clear_cached_counters']) ? $_REQUEST['essb_clear_cached_counters'] : '';
if ($full_counter_update == 'true') {
	delete_post_meta_by_key('essb_cache_expire');
}

global $essb_admin_options_fanscounter;
$essb_admin_options_fanscounter = get_option ( ESSB3_OPTIONS_NAME_FANSCOUNTER );

if (! is_array ( $essb_admin_options_fanscounter )) {
	if (! class_exists ( 'ESSBSocialFollowersCounterHelper' )) {
		include_once (ESSB3_PLUGIN_ROOT . 'lib/modules/social-followers-counter/essb-social-followers-counter-helper.php');
	}
	
	$essb_admin_options_fanscounter = ESSBSocialFollowersCounterHelper::create_default_options_from_structure ( ESSBSocialFollowersCounterHelper::options_structure () );
	update_option ( ESSB3_OPTIONS_NAME_FANSCOUNTER, $essb_admin_options_fanscounter );
}

// print "options are:";
// print_r($essb_admin_options);

if (count ( $essb_navigation_tabs ) > 0) {
	
	$tab_1 = key ( $essb_navigation_tabs );
}

if ($tab_1 == '') {
	$tab_1 = "social";
}

global $current_tab;
$current_tab = (empty ( $_GET ['tab'] )) ? $tab_1 : sanitize_text_field ( urldecode ( $_GET ['tab'] ) );
$purge_cache = isset ( $_REQUEST ['purge-cache'] ) ? $_REQUEST ['purge-cache'] : '';
$rebuild_resource = isset ( $_REQUEST ['rebuild-resource'] ) ? $_REQUEST ['rebuild-resource'] : '';

$dismiss_addon = isset ( $_REQUEST ['dismiss'] ) ? $_REQUEST ['dismiss'] : '';
if ($dismiss_addon == "true") {
	$dismiss_addon = isset ( $_REQUEST ['addon'] ) ? $_REQUEST ['addon'] : '';
	$addons = ESSBAddonsHelper::get_instance ();
	
	$addons->dismiss_addon_notice ( $dismiss_addon );
}

$active_settings_page = isset ( $_REQUEST ['page'] ) ? $_REQUEST ['page'] : '';
if (strpos ( $active_settings_page, 'essb_redirect_' ) !== false) {
	$options_page = str_replace ( 'essb_redirect_', '', $active_settings_page );
	// print $options_page;
	// print admin_url ( 'admin.php?page=essb_options&tab=' . $options_page );
	if ($options_page != '') {
		$current_tab = $options_page;
	}
}


$tabs = $essb_navigation_tabs;
$section = $essb_sidebar_sections [$current_tab];
$options = $essb_section_options [$current_tab];

// cache is running
$general_cache_active = ESSBOptionValuesHelper::options_bool_value ( $essb_admin_options, 'essb_cache' );
$general_cache_active_static = ESSBOptionValuesHelper::options_bool_value ( $essb_admin_options, 'essb_cache_static' );
$general_cache_active_static_js = ESSBOptionValuesHelper::options_bool_value ( $essb_admin_options, 'essb_cache_static_js' );
$general_cache_mode = ESSBOptionValuesHelper::options_value ( $essb_admin_options, 'essb_cache_mode' );
$is_cache_active = false;

$general_precompiled_resources = ESSBOptionValuesHelper::options_bool_value ( $essb_admin_options, 'precompiled_resources' );

$display_cache_mode = "";
if ($general_cache_active) {
	if ($general_cache_mode == "full") {
		$display_cache_mode = __("Cache button render and dynamic resources", "essb");
	} else if ($general_cache_mode == "resource") {
		$display_cache_mode = __("Cache only dynamic resources", "essb");
	} else {
		$display_cache_mode = __("Cache only button render", "essb");
	}
	$is_cache_active = true;
}

if ($general_cache_active_static || $general_cache_active_static_js) {
	if ($display_cache_mode != '') {
		$display_cache_mode .= ", ";
	}
	$display_cache_mode .= __("Combine into sigle file all plugin static CSS files", "essb");
	$is_cache_active = true;
}

?>
<!--  sweet alerts -->
<script src="<?php echo ESSB3_PLUGIN_URL?>/assets/admin/sweetalert.min.js"></script> 
<link rel="stylesheet" type="text/css" href="<?php echo ESSB3_PLUGIN_URL?>/assets/admin/sweetalert.css">
<!--  code mirror include -->


<link rel=stylesheet
	href="<?php echo ESSB3_PLUGIN_URL?>/assets/admin/codemirror/codemirror.css">
<script
	src="<?php echo ESSB3_PLUGIN_URL?>/assets/admin/codemirror/codemirror.js"></script>
<script
	src="<?php echo ESSB3_PLUGIN_URL?>/assets/admin/codemirror/mode/xml/xml.js"></script>
<script
	src="<?php echo ESSB3_PLUGIN_URL?>/assets/admin/codemirror/mode/javascript/javascript.js"></script>
<script
	src="<?php echo ESSB3_PLUGIN_URL?>/assets/admin/codemirror/mode/css/css.js"></script>
<script
	src="<?php echo ESSB3_PLUGIN_URL?>/assets/admin/codemirror/mode/htmlmixed/htmlmixed.js"></script>
<script
	src="<?php echo ESSB3_PLUGIN_URL?>/assets/admin/codemirror/addon/edit/matchbrackets.js"></script>
<script
	src="<?php echo ESSB3_PLUGIN_URL?>/assets/admin/codemirror/addon/edit/closebrackets.js"></script>
<script
	src="<?php echo ESSB3_PLUGIN_URL?>/assets/admin/codemirror/addon/edit/matchtags.js"></script>
<script
	src="<?php echo ESSB3_PLUGIN_URL?>/assets/admin/codemirror/addon/edit/closetag.js"></script>
<script
	src="<?php echo ESSB3_PLUGIN_URL?>/assets/admin/codemirror/addon/fold/foldcode.js"></script>
<script
	src="<?php echo ESSB3_PLUGIN_URL?>/assets/admin/codemirror/addon/fold/foldgutter.js"></script>
<script
	src="<?php echo ESSB3_PLUGIN_URL?>/assets/admin/codemirror/addon/fold/indent-fold.js"></script>
<script
	src="<?php echo ESSB3_PLUGIN_URL?>/assets/admin/codemirror/addon/fold/xml-fold.js"></script>
<script
	src="<?php echo ESSB3_PLUGIN_URL?>/assets/admin/codemirror/addon/fold/brace-fold.js"></script>
<script
	src="<?php echo ESSB3_PLUGIN_URL?>/assets/admin/codemirror/addon/fold/comment-fold.js"></script>
<div class="wrap essb-settings-wrap">

<?php

// admin check for activation

if (class_exists ( 'ESSBAdminActivate' )) {
	
	$dismissactivate = isset ( $_REQUEST ['dismissactivate'] ) ? $_REQUEST ['dismissactivate'] : '';
	if ($dismissactivate == "true") {
		ESSBAdminActivate::dismiss_notice ();
	} else {
		if (! ESSBAdminActivate::is_activated () && ESSBAdminActivate::should_display_notice ()) {
			ESSBAdminActivate::notice_activate ();
		}
	}
	
	ESSBAdminActivate::notice_manager();
	
	$deactivate_appscreo = essb_options_bool_value('deactivate_appscreo');
	if (!$deactivate_appscreo) {
		ESSBAdminActivate::notice_new_addons();
	}
}

if (class_exists('ESSBAddonsHelper')) {
	$essb_addons = ESSBAddonsHelper::get_instance ();
	$essb_addons->get_new_addons();
}

// @since 3.2.4
// Twitter Counter Recovery
if (ESSBTwitterCounterRecovery::recovery_called ()) {
	ESSBTwitterCounterRecovery::recovery_start ();
}

/*if (ESSB3_ADDONS_ACTIVE && class_exists ( 'ESSBAddonsHelper' )) {
	$addons = ESSBAddonsHelper::get_instance ();
	$new_addons = $addons->get_new_addons ();
	
	foreach ( $new_addons as $key => $data ) {
		$all_addons_button = '<a href="' . admin_url ( "admin.php?page=essb_addons" ) . '"  text="' . __ ( 'Extensions', 'essb' ) . '" class="status_button float_right" style="margin-right: 5px;"><i class="fa fa-gear"></i>&nbsp;' . __ ( 'View list of all extensions', 'essb' ) . '</a>';
		
		$dismiss_url = esc_url_raw ( add_query_arg ( array ('dismiss' => 'true', 'addon' => $key ), admin_url ( "admin.php?page=essb_options" ) ) );
		
		$dismiss_addons_button = '<a href="' . $dismiss_url . '"  text="' . __ ( 'Extensions', 'essb' ) . '" class="status_button float_right" style="margin-right: 5px;"><i class="fa fa-close"></i>&nbsp;' . __ ( 'Dismiss', 'essb' ) . '</a>';
		//printf ( '<div class="essb-information-box fade"><div class="icon orange"><i class="fa fa-cube"></i></div><div class="inner">New add-on for Easy Social Share Buttons for WordPress is available: <a href="%2$s" target="_blank"><b>%1$s</b></a> %4$s%3$s</div></div>', $data ['title'], $data ['url'], $all_addons_button, $dismiss_addons_button );
		ESSBOptionsFramework::draw_hint(__('New addon available!', 'essb'), sprintf('New add-on for Easy Social Share Buttons for WordPress is available: <a href="%2$s" target="_blank"><b>%1$s</b></a> %4$s%3$s', $data ['title'], $data ['url'], $all_addons_button, $dismiss_addons_button), 'fa fa-cube', 'status essb-status-addon');
	}
}*/

$cache_plugin_message = "";
if (ESSBCacheDetector::is_cache_plugin_detected ()) {
	$cache_plugin_message = __(" Cache plugin detected running on site: ", "essb") . ESSBCacheDetector::cache_plugin_name ();
}

$backup = isset ( $_REQUEST ['backup'] ) ? $_REQUEST ['backup'] : '';
$settings_update = isset ( $_REQUEST ['settings-updated'] ) ? $_REQUEST ['settings-updated'] : '';
if ($settings_update == "true") {
	// printf('<div class="updated" style="padding: 10px;">%1$s</div>', __('Easy
	// Social Share Buttons options are saved!', 'essb'));
	//printf ( '<div class="essb-information-box"><div class="icon"><i class="fa fa-info-circle"></i></div><div class="inner"><b>%1$s</b></div></div>', __ ( 'Easy Social Share Buttons options are saved!' . $cache_plugin_message, 'essb' ) );
	ESSBOptionsFramework::draw_hint(__('Options are saved!', 'essb'), 'Your new setup is ready to use. If you use cache plugin (example: W3 Total Cache, WP Super Cache, WP Rocket) or optimization plugin (example: Autoptimize, BWP Minify) it is highly recommended to clear cache or you may not see the changes. '.$cache_plugin_message, 'fa fa-info-circle', 'status essb-status-update');
	
}
$settings_imported = isset ( $_REQUEST ['settings-imported'] ) ? $_REQUEST ['settings-imported'] : '';
if ($settings_imported == "true") {
	// printf('<div class="updated" style="padding: 10px;">%1$s</div>', __('Easy
	// Social Share Buttons options are saved!', 'essb'));
	//printf ( '<div class="essb-information-box"><div class="icon"><i class="fa fa-info-circle"></i></div><div class="inner">%1$s</div></div>', __ ( 'Easy Social Share Buttons options are imported!' . $cache_plugin_message, 'essb' ) );
	ESSBOptionsFramework::draw_hint(__('Options are imported!', 'essb'), 'If you use cache plugin (example: W3 Total Cache, WP Super Cache, WP Rocket) or optimization plugin (example: Autoptimize, BWP Minify) it is highly recommended to clear cache or you may not see the changes. '.$cache_plugin_message, 'fa fa-info-circle', 'status');
	
}
if ($reset_settings == 'true') {
	//printf ( '<div class="essb-information-box"><div class="icon"><i class="fa fa-gear"></i></div><div class="inner">%1$s</div></div>', __ ( 'Plugin settings are restored to default.' . $cache_plugin_message, 'essb' ) );
	ESSBOptionsFramework::draw_hint(__('Options are reset to default!', 'essb'), 'If you use cache plugin (example: W3 Total Cache, WP Super Cache, WP Rocket) or optimization plugin (example: Autoptimize, BWP Minify) it is highly recommended to clear cache or you may not see the changes. '.$cache_plugin_message, 'fa fa-info-circle', 'status');
	
}

if ($is_cache_active) {
	$cache_clear_address = esc_url_raw ( add_query_arg ( array ('purge-cache' => 'true' ), essb_get_current_page_url () ) );
	
	//printf ( '<div class="essb-information-box"><div class="icon blue"><i class="fa fa-database"></i></div><div class="inner">%1$s: <b>%2$s</b><a href="%3$s" class="button float_right">%4$s</a></div></div>', __ ( 'Easy Social Share Buttons cache is running:', 'essb' ), $display_cache_mode, $cache_clear_address, __ ( 'Purge Cache', 'essb' ) );
	$dismiss_addons_button = '<a href="' . $cache_clear_address . '"  text="' . __ ( 'Purge Cache', 'essb' ) . '" class="status_button float_right" style="margin-right: 5px;"><i class="fa fa-close"></i>&nbsp;' . __ ( 'Purge Cache', 'essb' ) . '</a>';
	ESSBOptionsFramework::draw_hint(__('Plugin Cache is Running!', 'essb'), sprintf('%2$s %1$s', $dismiss_addons_button, $display_cache_mode), 'fa fa-database', 'status');
	
}

if ($general_precompiled_resources) {
	$cache_clear_address = esc_url_raw ( add_query_arg ( array ('rebuild-resource' => 'true' ), essb_get_current_page_url () ) );
	
	//printf ( '<div class="essb-information-box"><div class="icon blue"><i class="fa fa-history"></i></div><div class="inner"><b>%1$s</b><a href="%2$s" class="button float_right">%3$s</a></div></div>', __ ( 'Easy Social Share Buttons is using precompiled static resources', 'essb' ), $cache_clear_address, __ ( 'Rebuild resources', 'essb' ) );
		$dismiss_addons_button = '<a href="' . $cache_clear_address . '"  text="' . __ ( 'Rebuild Resources', 'essb' ) . '" class="status_button float_right" style="margin-right: 5px;"><i class="fa fa-close"></i>&nbsp;' . __ ( 'Rebuild Resources', 'essb' ) . '</a>';
		ESSBOptionsFramework::draw_hint(__('Precompiled Resource Mode is Active!', 'essb'), sprintf('In precompiled mode plugin will load default setup into single static files that will run on entire site. %1$s', $dismiss_addons_button), 'fa fa-history', 'status');
}

if ($backup == 'true') {
	//printf ( '<div class="essb-information-box"><div class="icon"><i class="fa fa-gear"></i></div><div class="inner">%1$s</div></div>', __ ( 'Backup of your current settings is generated. Copy generated configuration string and save it on your computer. You can use it to restore settings or transfer them to other site.', 'essb' ) );
	ESSBOptionsFramework::draw_hint(__('Backup is ready!', 'essb'), 'Backup of your current settings is generated. Copy generated configuration string and save it on your computer. You can use it to restore settings or transfer them to other site.', 'fa fa-gear', 'status');
	
}

if ($purge_cache == 'true') {
	if (class_exists ( 'ESSBDynamicCache' )) {
		ESSBDynamicCache::flush ();
	}
	if (function_exists ( 'purge_essb_cache_static_cache' )) {
		purge_essb_cache_static_cache ();
	}
	//printf ( '<div class="essb-information-box"><div class="icon"><i class="fa fa-info-circle"></i></div><div class="inner">%1$s</div></div>', __ ( 'Easy Social Share Buttons for WordPress Cache is purged!', 'essb' ) );
	ESSBOptionsFramework::draw_hint(__('Cache is Cleared!', 'essb'), 'Build in cache of plugin is fully cleared!', 'fa fa-info-circle', 'status');
		
}

if ($rebuild_resource == "true") {
	if (class_exists ( 'ESSBPrecompiledResources' )) {
		ESSBPrecompiledResources::flush ();
	}
}

if ($current_tab == "analytics") {
	$settings_url = esc_url_raw ( get_admin_url () . 'admin.php?page=essb_options&tab=social&section=sharing&subsection=sharing-6' );
	if (! essb_options_bool_value('stats_active')) {
		printf ( '<div class="essb-information-box"><div class="icon orange"><i class="fa fa-info-circle"></i></div><div class="inner">%1$s<a href="%2$s" class="button float_right">%3$s</a></div></div>', __ ( 'Statistics function in not activated!', 'essb' ), $settings_url, __ ( 'Click here to go to settings and activte it', 'essb' ) );
	}
}

if (function_exists('essb3_apply_readymade_style')) {
	essb3_apply_readymade_style();
}
?>




	<div class="essb-tabs">
		<div class="essb-tabs-title">
			<div class="essb-tabs-version">
				<div class="essb-logo essb-logo32"></div>
				<div class="essb-text-afterlogo">
					<h3>Easy Social Share Buttons for WordPress</h3>
					<p class="essb-tabs-control">
						Version <strong><?php echo ESSB3_VERSION;?></strong>. &nbsp;<strong><a
							href="<?php echo admin_url ("admin.php?page=essb_about"); ?>" class="essb-tab-button">What's new in this version</a></strong>&nbsp;&nbsp;<strong><a
							href="http://codecanyon.net/item/easy-social-share-buttons-for-wordpress/6394476?ref=appscreo"
							target="_blank" class="essb-tab-button">Plugin Homepage</a></strong>&nbsp;&nbsp;<strong><a
							href="http://codecanyon.net/item/easy-social-share-buttons-for-wordpress/6394476?ref=appscreo"
							target="_blank" class="essb-tab-button" id="essb-check-forupdate">Check for update</a></strong>
					</p>
					
				</div>
			</div>
			<div class="essb-title-panel-buttons">
	<?php if (ESSB3_ADDONS_ACTIVE) { ?>
		<?php echo '<a href="'.admin_url ("admin.php?page=essb_addons").'"  text="' . __ ( 'Extensions', 'essb' ) . '" class="essb-btn essb-btn-orange" style="margin-right: 5px;"><i class="fa fa-gear"></i>&nbsp;' . __ ( 'Extensions', 'essb' ) . '</a>'; ?>
	<?php  } ?>
	<?php echo '<a href="'.admin_url ("admin.php?page=essb_redirect_quick&tab=quick").'"  text="' . __ ( 'Quick Setup Wizard', 'essb' ) . '" class="essb-btn essb-btn-red" style="margin-right: 5px;"><i class="fa fa-bolt"></i>&nbsp;' . __ ( 'Quick Setup Wizard', 'essb' ) . '</a>'; ?>
	<?php echo '<a href="'.admin_url ("admin.php?page=essb_redirect_readymade&tab=readymade").'"  text="' . __ ( 'Ready Made Styles', 'essb' ) . '" class="essb-btn essb-btn-green" style="margin-right: 5px;"><i class="fa fa-bolt"></i>&nbsp;' . __ ( 'Apply Ready Made Styles', 'essb' ) . '</a>'; ?>
	<?php echo '<a href="http://support.creoworx.com" target="_blank" text="' . __ ( 'Need Help? Click here to visit our support center', 'essb' ) . '" class="essb-btn essb-btn-light float_right"><i class="fa fa-question"></i>&nbsp;' . __ ( 'Get Support', 'essb' ) . '</a>'; ?>
	</div>
		</div>
		<ul>
    <?php
				$is_first = true;
				$tab_has_nomenu = false;
				foreach ( $tabs as $name => $label ) {
					$tab_sections = isset ( $essb_sidebar_sections [$name] ) ? $essb_sidebar_sections [$name] : array ();
					//print_r($tab_sections);
					$hidden_tab = isset ( $tab_sections ['hide_in_navigation'] ) ? $tab_sections ['hide_in_navigation'] : false;
					if ($hidden_tab) {
						continue;
					}
					
					$icon = isset ( $tab_sections ['icon'] ) ? $tab_sections ['icon'] : '';
					$align = isset($tab_sections['align']) ? $tab_sections['align'] : '';
					
					$options_handler = ($is_first) ? "essb_options" : 'essb_redirect_' . $name;
					echo '<li '.($align == 'right' ? 'class="tab-right"' : '').'><a href="' . admin_url ( 'admin.php?page=' . $options_handler . '&tab=' . $name ) . '" class="essb-nav-tab ';
					if ($current_tab == $name)
						echo 'active';
					echo '" title="'.$label.'">' . ($icon != '' ? '<i class="' . $icon . '"></i>' : '') . '<span>'.$label . '</span></a></li>';
					$is_first = false;
					
					if ($current_tab == $name) {
						$tab_has_nomenu = isset ( $tab_sections ['hide_menu'] ) ? $tab_sections ['hide_menu'] : false;
					}
				}
				
				?>
    </ul>

	</div>

	
	<?php
	
	if ($current_tab != 'analytics' && $current_tab != 'shortcode' && $current_tab != 'status' && $current_tab != 'welcome') {
		ESSBOptionsInterface::draw_form_start (false, '', $tab_has_nomenu);
		
		ESSBOptionsInterface::draw_sidebar ( $section ['fields'] );
		ESSBOptionsInterface::draw_header ( $section ['title'], $section ['hide_update_button'], $section ['wizard_tab'] );
		ESSBOptionsInterface::draw_content ( $options );
		
		ESSBOptionsInterface::draw_form_end ();
		
		ESSBOptionsFramework::register_color_selector ();
		
		?>					
		
		<?php
	} else if ($current_tab == 'analytics') {
		include_once ESSB3_PLUGIN_ROOT . 'lib/modules/social-share-analytics/essb-social-share-analytics-backend-view.php';
	} else if ($current_tab == "shortcode") {
		include_once ESSB3_PLUGIN_ROOT . 'lib/admin/essb-settings-shortcode-generator.php';
	}
	else if ($current_tab == 'status') {
		include_once ESSB3_PLUGIN_ROOT . 'lib/admin/essb-settings-system-status.php';
		
	}
	else if ($current_tab == 'welcome') {
		include_once ESSB3_PLUGIN_ROOT . 'lib/admin/admin-options/essb-welcome.php';
	}
	?>
	
</div>

<?php 

if (!essb_options_bool_value('deactivate_ajaxsubmit')) {

?>

<style type="text/css">
.preloader {
  position: fixed;
  width: 64px;
  height: 64px;
  border: 6px solid #fff;
  border-radius: 100%;
}
.preloader:before,
.preloader:after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  margin: -0.2rem 0 0 -0.2rem;
  border-bottom: 6px solid #fff;
  border-radius: 10px;
  -webkit-transform-origin: 3px center;
}
.preloader:before {
/* hour hand */
  width: 30%;
  -webkit-animation: hour 10s linear infinite;
}
.preloader:after {
/* minute hand */
  width: 40%;
  background-color: #2085e6;
  -webkit-animation: minute 1s linear infinite;
}
@-webkit-keyframes hour {
  100% {
    -webkit-transform: rotate(360deg);
  }
}
@-webkit-keyframes minute {
  100% {
    -webkit-transform: rotate(360deg);
  }
}
/* for demo purposes only — not required */
.preloader {
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
}

.preloader-holder {
	position: fixed;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  top: 0;
  left: 0;
}

.preloader-message {
	position: fixed;
	font-size: 32px;
	line-height: 32px;
	font-family: 'Open Sans', sans-serif;
	font-weight: bold;
	top: calc(50% + 56px);
	bottom: 0;
	left: 0;
	margin: 0;
	text-align: center;
	margin: auto;
	width: 400px;
	right: 0;
	color: #fff;
}

.preloader-holder { display: none; }
.sweet-alert h2 {
	letter-spacing: -0.5px;
	color: #303133;
	font-size: 24px;
	font-weight: 700;
}

.sweet-alert p {
	font-size: 14px;
	color: #303133;
	font-weight: 400;
}

.sweet-alert button {
	font-size: 14px;
	font-weight: 700;
}

.sweet-overlay { 
background-color: rgba(0, 0, 0, 0.7);
}
</style>

<div class="preloader-holder">
<div class="preloader"></div>
<div class="preloader-message">Please Wait a Moment ...</div>
</div>
<script type="text/javascript">

	// assign ajax submit on form
jQuery(document).ready(function($){
	if ($('#essb-btn-update').length && $('#essb_options_form').length) {
		$('#essb-btn-update').off('click').click(function(e) {
			$('.preloader-holder').fadeIn(100);
			var frmSettings = $('#essb_options_form');

			frmSettings.submit(function (e) {
				if (typeof(essb_disable_ajax_submit) == "undefined") essb_disable_ajax_submit = false;
				
				if (!essb_disable_ajax_submit) {
					$.ajax({
			            type: frmSettings.attr('method'),
			            url: frmSettings.attr('action'),
			            data: frmSettings.serialize(),
			            success: function (data) {
			                $('.preloader-holder').fadeOut(400);
			                swal("Your settings are saved!", "Your new setup is ready to use. If you use cache plugin (example: W3 Total Cache, WP Super Cache, WP Rocket) or optimization plugin (example: Autoptimize, BWP Minify) it is highly recommended to clear cache or you may not see the changes.", "success")
			            }
			        });

			        e.preventDefault();
				}
			    });
		});
	}

	if ($('#essb-check-forupdate').length) {
		$('#essb-check-forupdate').click(function(e) {
			e.preventDefault();

			$('.preloader-holder').fadeIn(100);
			var plugin_is_activated = <?php if (ESSBActivationManager::isActivated()) { echo 'true'; } else { echo 'false'; }?>;
			var version_api = '<?php echo ESSBActivationManager::getApiUrl('api')?>version.php'; 
			$.ajax({
				type: "GET",
		        url: version_api,
		        data: {},
		        success: function (data) {
		        	$('.preloader-holder').fadeOut(400);
	                console.log(data);
	                if (typeof(data) == "string")
	                	data = JSON.parse(data);
	                
	                var code = data['code'] || '';
	                var version = data['version'] || '';

	                if (code == '200') {
	                	$.ajax({
	    		            type: "POST",
	    		            url: "<?php echo admin_url("admin-ajax.php");?>",
	    		            data: { 'action': 'essb_process_activation', 'activation_state': 'version_check', 'version': version},
	    		            success: function (data) {
	    		            	console.log(data);
	    		            	 if (typeof(data) == "string")
	    			                	data = JSON.parse(data);

	 			                var code = data['code'] || '';
	 			                if (code != '') {
		 			                if (plugin_is_activated) {
		 			                	swal("New version " + code + " is available!", "Visit updates screen to proceed with plugin update", "success");
		 			                }
		 			                else {
	 			                		swal("New version " + code + " is available!", "Activate plugin to unlock automatic updates", "success");
		 			                }
	 			                }
	 			                else {
	 			                	swal("", "You are running latest version of plugin!", "");
	 			                }
	    		            }
	                	});
	                }
		        },
		        error: function() {
		        	$('.preloader-holder').fadeOut(400);
		        	swal("Connection Error!", "A problem occured when connection to update server. Please try again later or check the what is new page for our latest release", "error");
		        }
			});
		});
	}
});
	
</script>
<?php } ?>