<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
// ob_start();
?>
<script>
	function wsdesk_mode_select()
	{
		if(document.getElementById('wsdesk_mode_std').checked)
			document.getElementById('wsdesk_lite_mode').style.display="none";
		else
			document.getElementById('wsdesk_lite_mode').style.display="block";
	};
	function wsdesk_mode_select_lite(){
		if(document.getElementById('wsdesk_mode_lite').checked)
			document.getElementById('wsdesk_lite_mode').style.display="block";
		else
			document.getElementById('wsdesk_lite_mode').style.display="none";
	}
	function wsdesk_mode_select_insane()
	{

		document.getElementById('wsdesk_lite_mode').style.display="none";
	};
</script>
<div class="crm-form-element">
	<div class="col-md-3">
		<label for="wsdesk_mode" style="padding-right:1em !important;"><?php esc_html_e( 'WSDesk Mode', 'wsdesk' ); ?></label>
	</div>
	<div class="col-md-9">
		<span class="help-block"><?php esc_html_e( 'Select your WSDesk mode.', 'wsdesk' ); ?></span>
		<span style="vertical-align: middle;">
			<?php
				$wsdesk_mode = eh_crm_get_settingsmeta( '0', 'wsdesk_mode' );
				$standard    = '';
				$lite        = '';
				$display     = 'none';
			switch ( $wsdesk_mode ) {
				case 'standard':
					$standard = 'checked';
					$lite     = '';
					$insane   = '';
					break;
				case 'lite':
					$standard = '';
					$lite     = 'checked';
					$insane   = '';
					$display  = 'block';

					break;
				case 'insane':
					$standard = '';
					$insane   = 'checked';
					$lite     = '';
					$display  = 'none';

					break;
				default:
					$standard = 'checked';
					$lite     = '';
					$insane   = '';
					break;

			}
			?>
			<input type="radio" disabled style="margin-top: 0;" onclick="wsdesk_mode_select();" id="wsdesk_mode_std" class="form-control" name="wsdesk_mode" <?php echo esc_html( $standard ); ?> value="standard"> <?php esc_html_e( 'Standard mode', 'wsdesk' ); ?><br>
			<input type="radio" disabled style="margin-top: 0;" onclick="wsdesk_mode_select_lite();" id="wsdesk_mode_lite" class="form-control" name="wsdesk_mode" <?php echo esc_html( $lite ); ?> value="lite"> <?php esc_html_e( 'Lite mode', 'wsdesk' ); ?><br>

			<input type="radio" disabled style="margin-top: 0;" onclick="wsdesk_mode_select_insane();" id="wsdesk_mode_insane" class="form-control" name="wsdesk_mode" <?php echo esc_html( $insane ); ?> value="insane"> <?php esc_html_e( 'Insane mode', 'wsdesk' ); ?> <span class="glyphicon glyphicon-info-sign" style="color:lightgray;font-size:x-small;vertical-align:baseline;" data-toggle="wsdesk_tooltip" title="<?php esc_html_e( 'Insane Mode enables all the tweaks from Lite Mode along with a number of additional optimizations. Please note, enabling this option may affect some of the functionalities.', 'wsdesk' ); ?>" data-container="body"></span><br><br>
			<span class="crm-divider"></span>
			<span class="help-block"><?php esc_html_e( 'Please note: As the plugin performance is optimized, switching between different modes is no longer necessary. This section will be removed from the plugin settings altogether in the forthcoming update.', 'wsdesk' ); ?></span>
			<div class="wsdesk_lite_mode hide" id="wsdesk_lite_mode" style="display: <?php echo esc_html( $display ); ?>;font-size: 12px;">
			<span style="vertical-align: middle;">
				<?php
					$display_default_status_count = eh_crm_get_settingsmeta( '0', 'display_default_status_count' );
					$enable                       = '';
				switch ( $display_default_status_count ) {
					case 'disable':
						$enable = '';
						break;
					default:
						$enable = 'checked';
						break;
				}
				?>
				&nbsp;
				<input type="checkbox" <?php echo esc_html( $enable ); ?> style="margin-top: 0;" id="display_default_status_count" class="form-control" name="display_default_status_count" value="enable"> <?php esc_html_e( 'Display default status count on primary menu', 'wsdesk' ); ?><br>
			</span>
			<span style="vertical-align: middle;">
				<?php
					$ticket_count_view = eh_crm_get_settingsmeta( '0', 'ticket_count_view' );
					$enable            = '';
				switch ( $ticket_count_view ) {
					case 'ticket_count_view':
						$enable = 'checked';
						break;
					default:
						$enable = '';
						break;
				}
				?>
				&nbsp;
				<input type="checkbox" <?php echo esc_html( $enable ); ?> style="margin-top: 0;" id="<?php echo( 'ticket_count_view' ); ?>" class="form-control" name="ticket_count_view" value="ticket_count_view"> <?php esc_html_e( 'Hide the ticket counts in the tickets dashboard', 'wsdesk' ); ?>
				<br>
			</span>
			<span style="vertical-align: middle;">
				<?php
					$quick_view_tickets = eh_crm_get_settingsmeta( '0', 'quick_view_tickets' );
					$enable             = '';
				switch ( $quick_view_tickets ) {
					case 'enable':
						$enable = 'checked';
						break;
					default:
						$enable = '';
						break;
				}
				?>
				&nbsp;
				<input type="checkbox" <?php echo esc_html( $enable ); ?> style="margin-top: 0;" id="quick_view_tickets" class="form-control" name="quick_view_tickets" value="enable"> <?php esc_html_e( 'Disable quick view option in the tickets dashboard', 'wsdesk' ); ?><br>
			</span>
			<span style="vertical-align: middle;">
				<?php
					$refresh_ticket_page = eh_crm_get_settingsmeta( '0', 'refresh_ticket_page' );
					$enable              = '';
				switch ( $refresh_ticket_page ) {
					case 'enable':
						$enable = 'checked';
						break;
					default:
						$enable = '';
						break;
				}
				?>
				&nbsp;
				<input type="checkbox" <?php echo esc_html( $enable ); ?> style="margin-top: 0;" id="refresh_ticket_page" class="form-control" name="refresh_ticket_page" value="enable"> <?php esc_html_e( 'Disable refresh the tickets dashboard when the ticket tab is closed', 'wsdesk' ); ?><br>
			</span>
			<span class="crm-divider"></span>
			<div class="crm-form-element">
				<div class="col-md-9">
					<label for="auto_create_user" style="padding-right:1em !important;"><?php esc_html_e( 'Limit scheduled triggers execution', 'wsdesk' ); ?></label>
					<span class="help-block"><?php esc_html_e( 'Enable this option to specify a time interval to trigger all scheduled actions.', 'wsdesk' ); ?></span>
					<span style="vertical-align: middle;">
						<?php
						$scheduled_triggers_enable = eh_crm_get_settingsmeta( '0', 'scheduled_triggers_enable' );
						$scheduled_triggers_time   = eh_crm_get_settingsmeta( '0', 'scheduled_triggers_time' );
						if ( empty( $scheduled_triggers_time ) ) {
							$scheduled_triggers_time = 24;
						}
						$auto_create_user = eh_crm_get_settingsmeta( '0', 'scheduled_triggers_enable' );
						$enable           = '';
						switch ( $auto_create_user ) {
							case 'enable':
								$enable = 'checked';
								$upath  = 'block';
								break;
							default:
								$enable = '';
								$upath  = 'none';
								break;
						}
						?>

						<input type="checkbox" <?php echo esc_html( $enable ); ?> style="margin-top: 0;" id="scheduled_triggers_enable" onclick="enable_scheduled_triggers_enable();" class="form-control" name="scheduled_triggers_enable" value="enable"> <?php esc_html_e( 'Enable', 'wsdesk' ); ?></br></br>
						<div id="scheduled_triggers_time_option" style="display: <?php echo esc_html( $upath ); ?>">

							<input type="number" oninput="this.value = !!this.value && Math.abs(this.value) >= 0 ? Math.abs(this.value) : null" min="0" id="scheduled_triggers_time"  value="<?php echo esc_html( $scheduled_triggers_time ); ?>" class="form-control crm-form-element-input">
							<span class="help-block"><?php esc_html_e( ' Enter the time interval to execute the scheduled actions in hours.', 'wsdesk' ); ?></span>
						</div>
					</span>
				</div>
			</div>
		</div>
		</span>
	</div>
</div>

<span class="crm-divider"></span>
<div class="crm-form-element">
	<div class="col-md-3">
		<label for="excerpt_in_auto_suggestion" style="padding-right:1em !important;"><?php esc_html_e( 'Show Excerpt on Auto-Suggestion', 'wsdesk' ); ?></label>
	</div>
	<div class="col-md-9">
		<span class="help-block"><?php esc_html_e( 'Enable this option to show excerpt instead of first sentence of the post while displaying auto-suggestion.', 'wsdesk' ); ?></span>
		<span style="vertical-align: middle;">
		   <?php
			$show_excerpt_in_auto_suggestion = eh_crm_get_settingsmeta( '0', 'show_excerpt_in_auto_suggestion' );
			$enable                          = '';
			switch ( $show_excerpt_in_auto_suggestion ) {
				case 'enable':
					$enable = 'checked';
					break;
				default:
					$enable = '';
					break;
			}
			?>
			<input type="checkbox" <?php echo esc_html( $enable ); ?> style="margin-top: 0;" id="show_excerpt_in_auto_suggestion" class="form-control" name="show_excerpt_in_auto_suggestion" value="enable"> <?php esc_html_e( 'Enable', 'wsdesk' ); ?><br>
		</span>
	</div>
</div>
<span class="crm-divider"></span>
<div class="crm-form-element">
	<div class="col-md-3">
		<label for="auto_assign" style="padding-right:1em !important;"><?php esc_html_e( 'Display Tickets As', 'wsdesk' ); ?></label>
	</div>
	<div class="col-md-9">
		<span class="help-block"><?php esc_html_e( 'Enabling HTML option may lead to security issues. Resolving such issues are out of the scope of WSDesk plugin, hence we do not recommend this option.', 'wsdesk' ); ?></span>
		<span style="vertical-align: middle;">
			<?php
				$tickets_display = eh_crm_get_settingsmeta( '0', 'tickets_display' );
				$text            = '';
				$html            = '';
			switch ( $tickets_display ) {
				case 'text':
					$text = 'checked';
					break;
				default:
					$html = 'checked';
					break;
			}
			?>
			<input type="radio" <?php echo esc_html( $html ); ?> style="margin-top: 0;" id="tickets_display" class="form-control" name="tickets_display" value="html"> <?php esc_html_e( 'HTML', 'wsdesk' ); ?><br>
			<input type="radio" <?php echo esc_html( $text ); ?> style="margin-top: 0;" id="tickets_display" class="form-control" name="tickets_display" value="text"> <?php esc_html_e( 'Text', 'wsdesk' ); ?><br>
		</span>
	</div>
</div>
<span class="crm-divider"></span>
<div class="crm-form-element">
	<div class="col-md-3">
		<label for="auto_create_user" style="padding-right:1em !important;"><?php esc_html_e( 'WSDesk API', 'wsdesk' ); ?></label>
	</div>
	<div class="col-md-9">
		<span class="help-block"><?php esc_html_e( 'Create tickets via API from any website', 'wsdesk' ); ?></span>
		<span style="vertical-align: middle;">
			<?php
				$api_key          = eh_crm_get_settingsmeta( '0', 'api_key' );
				$auto_create_user = eh_crm_get_settingsmeta( '0', 'enable_api' );
			if ( empty( $api_key ) ) {
				$api_key = md5( time() . EH_CRM_MAIN_URL );
			}
				$enable = '';
			switch ( $auto_create_user ) {
				case 'enable':
					$enable = 'checked';
					$upath  = 'block';
					break;
				default:
					$enable = '';
					$upath  = 'none';
					break;
			}
			?>
			<input type="checkbox" <?php echo esc_html( $enable ); ?> style="margin-top: 0;" id="enable_api" onclick="enable_api_click();" class="form-control" name="enable_api" value="enable"> <?php esc_html_e( 'Enable API', 'wsdesk' ); ?><br>
			<div id="api_key" style="display: <?php echo esc_html( $upath ); ?>">
				<span class="help-block"><?php esc_html_e( 'API Key:', 'wsdesk' ); ?> <span class="glyphicon glyphicon-info-sign" style="color:lightgray;font-size:x-small;vertical-align:baseline;" data-toggle="wsdesk_tooltip" title="<?php esc_html_e( 'Please share this API Key only with trusted sources.', 'wsdesk' ); ?>" data-container="body"></span></span>
				<input type="text" id="api_key_textbox" value="<?php echo esc_html( $api_key ); ?>" class="form-control crm-form-element-input">
			</div>
		</span>
	</div>
</div>
<span class="crm-divider"></span>
<div class="crm-form-element">
	<div class="col-md-3">
		<label for="custom-attachment-folder" style="padding-right:1em !important;"><?php esc_html_e( 'Default Deep Link', 'wsdesk' ); ?></label>
	</div>
	<div class="col-md-9">
		<?php
		$default_deep_link = urldecode( stripslashes( eh_crm_get_settingsmeta( '0', 'default_deep_link' ) ) );
		?>
		<span class="help-block"><?php esc_html_e( 'Add a default deep link here', 'wsdesk' ); ?></span>
		<span style="vertical-align: middle;">
			<span class="help-block"><?php esc_html_e( 'Path: ' . esc_url( admin_url() ) . 'admin.php?page=wsdesk_tickets&', 'wsdesk' ); ?></span>
			<input type="text" id="default_deep_link" placeholder="view=all" value='<?php echo esc_html( $default_deep_link ); ?>' class="form-control crm-form-element-input">
		</span>
	</div>
</div>
<span class="crm-divider"></span>
	<div class="crm-form-element">
		<div class="col-md-3">
			<label for="ticket-activity-logs" style="padding-right:1em !important;"><?php esc_html_e( 'Ticket Activity Logs', 'wsdesk' ); ?></label>
			<label for="ticket-activity-logs" class="premium_green_set"><a href="<?php echo esc_url( 'https://elextensions.com/plugin/wsdesk-wordpress-support-desk-plugin/' ); ?>" target="_blank"><sup class="text-success"><?php esc_html_e( '[Premium!]', 'wsdesk' ); ?></sup></a></label>
		</div>
		<div class="col-md-9">
			<span class="help-block"><?php esc_html_e( 'Enable this option to log the activities of the ticket.', 'wsdesk' ); ?></span>
			<span style="vertical-align: middle;">
				<?php
					$wsdesk_activity_log_status = eh_crm_get_settingsmeta( '0', 'wsdesk_activity_log_status' );
					$activity_log_enable        = ( 'enable' === $wsdesk_activity_log_status ) ? 'checked' : '';
					$activity_log_disabled      = ! wsdesk_is_premium() ? 'disabled' : '';
				?>
				<input type="checkbox" <?php echo esc_attr( $activity_log_enable ); ?> <?php echo esc_attr( $activity_log_disabled ); ?> style="margin-top: 0;" id="wsdesk_activity_log" class="form-control" name="wsdesk_activity_log" value="enable"> <?php esc_html_e( 'Enable', 'wsdesk' ); ?><br>
			</span>
		</div>
	</div>
	<span class="crm-divider"></span>
	<div class="crm-form-element">
		<div class="col-md-3">
			<label for="ticket-email-logs" style="padding-right:1em !important;"><?php esc_html_e( 'Email Logs', 'wsdesk' ); ?></label>
			<label for="ticket-email-logs" class="premium_green_set"><a href="<?php echo esc_url( 'https://elextensions.com/plugin/wsdesk-wordpress-support-desk-plugin/' ); ?>" target="_blank"><sup class="text-success"><?php esc_html_e( '[Premium!]', 'wsdesk' ); ?></sup></a></label>
		</div>
		<div class="col-md-9">
			<span class="help-block"><?php esc_html_e( 'Enable this option to log the emails related to the specific ticket.', 'wsdesk' ); ?></span>
			<span style="vertical-align: middle;">
				<?php
					$wsdesk_email_log_status = eh_crm_get_settingsmeta( '0', 'wsdesk_email_log_status' );
					$email_log_enable        = ( 'enable' === $wsdesk_email_log_status ) ? 'checked' : '';
					$email_log_disabled      = ! wsdesk_is_premium() ? 'disabled' : '';
				?>
				<input type="checkbox" <?php echo esc_attr( $email_log_enable ); ?> <?php echo esc_attr( $email_log_disabled ); ?> style="margin-top: 0;" id="wsdesk_email_log" class="form-control" name="wsdesk_email_log" value="enable"> <?php esc_html_e( 'Enable', 'wsdesk' ); ?><br>
			</span>
		</div>
	</div>
	<span class="crm-divider"></span>
<div class="crm-form-element">
	<div class="col-md-3">
		<label for="custom-attachment-folder" style="padding-right:1em !important;"><?php esc_html_e( 'Debug Mode', 'wsdesk' ); ?></label>
	</div>
	<div class="col-md-9">
		<span class="help-block"><?php esc_html_e( 'Enable this option to place debug logs in PHP error log file', 'wsdesk' ); ?></span>
		<span style="vertical-align: middle;">
			<?php
				$wsdesk_debug_status = eh_crm_get_settingsmeta( '0', 'wsdesk_debug_status' );
				$debug_enable        = '';
			switch ( $wsdesk_debug_status ) {
				case 'enable':
					$debug_enable = 'checked';
					break;
				default:
					$debug_enable = '';
					break;
			}
			?>
			<input type="checkbox" <?php echo esc_html( $debug_enable ); ?> style="margin-top: 0;" id="wsdesk_debug_email" class="form-control" name="wsdesk_debug_email" value="enable"> <?php esc_html_e( 'Enable', 'wsdesk' ); ?><br>
		</span>
	</div>
</div>

<span class="crm-divider"></span>
<div class="crm-form-element">
	<div class="col-md-3">
		<label for="custom-attachment-folder" style="padding-right:1em !important;"><?php esc_html_e( 'Powered by WSDesk Tag', 'wsdesk' ); ?></label>
	</div>
	<div class="col-md-9">
		<span class="help-block"><?php esc_html_e( 'Disabling this option will remove Powered by WSDesk Tag from front end and all support E-mails.', 'wsdesk' ); ?></span>
		<span style="vertical-align: middle;">
			<?php
				$wsdesk_powered_by_status = eh_crm_get_settingsmeta( '0', 'wsdesk_powered_by_status' );
			switch ( $wsdesk_powered_by_status ) {
				case 'disable':
					$wsdesk_powered_by_status_checked = '';
					break;
				default:
					$wsdesk_powered_by_status_checked = 'checked';
					break;
			}
			?>
			<input type="checkbox" <?php echo esc_html( $wsdesk_powered_by_status_checked ); ?> style="margin-top: 0;" id="wsdesk_powered_by_status" class="form-control" name="wsdesk_powered_by_status" value="enable"> <?php esc_html_e( 'Enable', 'wsdesk' ); ?><br>
		</span>
	</div>
</div>
<span class="crm-divider"></span>
<div class="crm-form-element">
	<div class="col-md-3">
		<label for="linkify-url" style="padding-right:1em !important;"><?php esc_html_e( 'Convert URLs to Hyperlinks', 'wsdesk' ); ?></label>
	</div>
	<div class="col-md-9">
		<span class="help-block"><?php esc_html_e( 'Enabling this option will convert all URLs in ticket conversation to hyperlinks. (BETA)', 'wsdesk' ); ?></span>
		<span style="vertical-align: middle;">
			<?php
				$linkify_urls = eh_crm_get_settingsmeta( '0', 'linkify_urls' );
			switch ( $linkify_urls ) {
				case 'enable':
					$linkify_urls_checked = 'checked';
					break;
				default:
					$linkify_urls_checked = '';
					break;
			}
			?>
			<input type="checkbox" <?php echo esc_html( $linkify_urls_checked ); ?> style="margin-top: 0;" id="linkify_urls" class="form-control" name="linkify_urls" value="enable"> <?php esc_html_e( 'Enable', 'wsdesk' ); ?><br>
		</span>
	</div>
</div>
<span class="crm-divider"></span>
<div class="crm-form-element">
	<div class="col-md-12">
		<button type="button" id="save_general" class="save_wsdesk_mode btn btn-primary btn-sm"> <span class="glyphicon glyphicon-ok"></span> <?php esc_html_e( 'Save Changes', 'wsdesk' ); ?></button>
	</div>
</div>
<?php
// return ob_get_clean();
