<?php
defined( 'ABSPATH' ) || exit; // Exit if accessed directly

//It displays the save button and related messages
function eos_dp_save_button(){
	$extra_class = '';
	$warning = '';
	$permalink_structure = get_option( 'permalink_structure' );
	$permalinks_label = __( 'the actual permalinks structure is not supported');
	if( '' === $permalink_structure ){
		$permalinks_label = __( 'the permalinks are set as plain','eos-dp' );
	}
	elseif( '/archives/%post_id%' === $permalink_structure ){
		$permalinks_label = __( 'the permalinks are set as numeric','eos-dp' );
	}
	if( false === strpos( basename( $permalink_structure ),'%postname%' ) && !in_array( $_GET['page'],array( 'eos_dp_admin','eos_dp_admin_url','eos_dp_url' ) ) ){
			$extra_class = ' eos-no-events';
			$warning = '<div style="background:#fff;color:#000;padding:10px;margin-bottom:10px;border-left:4px solid  #dc3232">'.sprintf( __( "You can't save because %s",'eos-dp' ),$permalinks_label );
			$warning .= '<p><a class="button" target="_blank" href="'.admin_url( 'options-permalink.php' ).'">'.__( 'Change Permalinks Structure','eos-dp' ).'</a></p>';
			$warning .= '</div>';
	}
	$dir = is_rtl() ? 'left' : 'right';
	$antiDir = is_rtl() ? 'right' : 'left';
	$page = isset( $_GET['page'] ) ? $_GET['page'] : '';
	?>
	<div class="eos-dp-btn-wrp" style="margin-top:40px">
		<?php echo $warning; ?>
		<input type="submit" name="submit" class="eos-dp-save-<?php echo esc_attr( $page );echo $extra_class; ?> button button-primary submit-dp-opts" data-backup="false" value="<?php _e( 'Save all changes','eos-dp' ); ?>"  />
		<?php eos_dp_ajax_loader_img(); ?>
		<div style="margin-<?php echo $dir; ?>:30px">
			<div class="eos-hidden eos-dp-opts-msg eos-dp-opts-msg_success msg_response" style="padding:10px;margin:10px;border-left:4px solid #00a32a;background:#fff">
				<span><?php echo __( 'Options saved.','eos-dp' ); ?></span>
			</div>
			<div class="eos-dp-opts-msg_failed eos-dp-opts-msg eos-hidden msg_response" style="padding:10px;margin:10px;border-left:4px solid #d63638;background:#fff">
				<span><?php echo __( 'Something went wrong, maybe you need to refresh the page and try again, but you will lose all your changes','eos-dp' ); ?></span>
			</div>
			<div class="eos-dp-opts-msg_warning eos-dp-opts-msg eos-hidden msg_response" style="padding:10px;margin:10px;border-left:4px solid #dba617;background:#fff">
				<span></span>
			</div>
			<div class="eos-dp-opts-response_msg eos-dp-opts-msg eos-hidden msg_response" style="height:100vh;overflow-y:auto;padding:10px;position:fixed;top:40px;background:#fff">
				<p><button id="fdp-response-popup-close" type="button" class="notice-dismiss"></button></p>
				<div></div>
				<p><img id="fdp-response-screenshot" class="eos-hidden" src="" /></p>
				<p>
					<?php wp_nonce_field( 'eos_dp_pro_remove_test', 'eos_dp_pro_remove_test' ); ?>
					<span id="fdp-remove-from-report" class="button"><?php esc_html_e( 'Discard','eos-dp-pro' ); ?></span>
					<span id="fdp-test-close" class="button"><?php esc_html_e( 'Close','eos-dp-pro' ); ?></span>
					<a id="fdp-see-all-gtmetrix-tests" class="button fdp-see-all-tests eos-hidden" href="<?php echo admin_url( '/admin.php?page=eos_dp_report&tool=gtmetrix' ); ?>" target="_fdp_gtmetrix_report"><?php esc_html_e( 'See all tests','eos-dp-pro' ); ?></a>
					<a id="fdp-see-all-gpsi-tests" class="button fdp-see-all-tests eos-hidden" href="<?php echo admin_url( '/admin.php?page=eos_dp_report&tool=gpsi' ); ?>" target="_fdp_gpsi_report"><?php esc_html_e( 'See all tests','eos-dp-pro' ); ?></a>
				</p>
			</div>
		</div>
	</div>
	<?php do_action( 'fdp_after_save_button' );
	if( function_exists( 'get_user_locale' ) ){
		$locale = get_user_locale();
		if( $locale ){
			$locA = explode( '_',$locale );
			if( isset( $locA[0] ) && !in_array( $locA[0],array( 'en','it' ) ) ){
			?>
			<div id="eos-dp-translate" class="eos-dp-margin-top-48">
				<p><?php printf( __( 'Click %shere%s if you want to translate Freesoul Deactivate Plugins in your language.','eos-dp' ),'<a href="https://translate.wordpress.org/projects/wp-plugins/freesoul-deactivate-plugins/stable/'.esc_attr( $locA[0] ).'/default/" rel="noopener" target="_blank">','</a>' ); ?></p>
			</div>
			<?php
			}
		}
	}
	?>
	<div id="eos-dp-popup" style="display:none;z-index:9999999999;background:#fff;padding:20px;position:fixed;<?php echo $antiDir; ?>:50%;-o-transform:translateX(-50%);-ms-transform:translateX(-50%);-moz-transform:translateX(-50%);-webkit-transform:translateX(-50%);transform:translateX(-50%);top:50px;width:800px;height:auto;max-width:80%;box-sizing:border-box;max-height:80vh;overflow-y:auto">
		<div id="eos-dp-popup-top" style="<?php echo $dir; ?>:0;position:absolute;top:0">
			<span id="eos-dp-popup-close" class="hover dashicons dashicons-no-alt" style="padding:10px;font-size:24px" title="<?php _e( 'Close','eos-dp' ); ?>"></span>
		</div>
		<h3><?php printf( __( 'The %spage%s was checked simulating a user who is not logged in.','eos-dp' ),'<a id="eos-dp-popup-page-link" href="#" target="_blank">','</a>' ); ?></h3>
		<div id="eos-dp-popup-txt"></div>
	</div>
	<?php
	do_action( 'eos_dp_after_footer' );
	eos_dp_pro_version_notice();
}
