<?php

namespace FSPoster\App\view;

use FSPoster\App\Providers\DB;
use FSPoster\App\Providers\Helper;

defined( 'ABSPATH' ) or exit;

$cronJobsCode = 'wget -O /dev/null ' . site_url() . '/?fs-poster-cron-job=1 >/dev/null 2>&1';
?>

<div class="fs_setting_item" style="width: 50%;">
	<div class="fs_setting_item_label">
		<div><?php print esc_html__('Auto publish new posts:' , 'fs-poster')?></div>
		<div class="fs_s_help"><?php print esc_html__('When you add a new post, the plugin publishes the post automatically on all active social accounts.' , 'fs-poster')?></div>
	</div>
	<div class="fs_s_input">
		<div class="fs_onoffswitch">
			<input type="checkbox" onautocomplete="off" name="fs_auto_share_new_posts" class="fs_onoffswitch-checkbox" id="fs_auto_share_new_posts"<?php print Helper::getOption('auto_share_new_posts', '1')?' checked':''?>>
			<label class="fs_onoffswitch-label" for="fs_auto_share_new_posts"></label>
		</div>
	</div>
</div>

<div style="display: flex;">
	<div style="width: 50%;">
		<div class="fs_setting_item">
			<div class="fs_setting_item_label">
				<div><?php print esc_html__('Share in background:' , 'fs-poster')?></div>
				<div class="fs_s_help"><?php print esc_html__('Share process runs in the background; therefore, you do not need to wait for the process to complete.' , 'fs-poster')?></div>
			</div>
			<div class="fs_s_input">
				<div class="fs_onoffswitch">
					<input type="checkbox" onautocomplete="off" name="fs_share_on_background" class="fs_onoffswitch-checkbox" id="fs_share_on_background"<?php print Helper::getOption('share_on_background', '1')?' checked':''?> onchange="if(jQuery(this).is(':checked')){ jQuery('#hide_11').fadeIn(fadeSpeed); }else{ jQuery('#hide_11').fadeOut(fadeSpeed); }">
					<label class="fs_onoffswitch-label" for="fs_share_on_background"></label>
				</div>
			</div>
		</div>
	</div>
	<div style="width: 50%;<?php print Helper::getOption('share_on_background', '1') ? '' : 'display: none;'?>" id="hide_11">
		<div class="fs_setting_item">
			<div class="fs_setting_item_label">
				<div><?php print esc_html__('Timer for sharing (min.):' , 'fs-poster')?></div>
				<div class="fs_s_help"><?php print esc_html__('Set a time for sharing the post after creating one. Default is 0 to share immediately' , 'fs-poster')?></div>
			</div>
			<div class="fs_s_input">
				<input type="text" onautocomplete="off" name="fs_share_timer" class="ws_form_element" style="text-align: center; width: 50px;" value="<?php print esc_html(Helper::getOption('share_timer', '0'))?>">
			</div>
		</div>
	</div>
</div>

<div class="fs_setting_item" style="width: 50%;">
	<div class="fs_setting_item_label">
		<div><?php print esc_html__('Keep shared posts log:' , 'fs-poster')?></div>
		<div class="fs_s_help"><?php print esc_html__('If you do not want to keep logs of shared posts, you have to disable this option. <span class="ws_color_warning">Note!</span> If you disable this option, you cannot view your insights.' , 'fs-poster')?></div>
	</div>
	<div class="fs_s_input">
		<div class="fs_onoffswitch">
			<input type="checkbox" onautocomplete="off" name="fs_keep_logs" class="fs_onoffswitch-checkbox" id="fs_keep_logs"<?php print Helper::getOption('keep_logs', '1')?' checked':''?>>
			<label class="fs_onoffswitch-label" for="fs_keep_logs"></label>
		</div>
	</div>
</div>

<div style="display: flex;">
	<div style="width: 50%;">
		<div class="fs_setting_item">
			<div class="fs_setting_item_label">
				<div><?php print esc_html__('Post interval:' , 'fs-poster');?></div>
				<div class="fs_s_help"><?php print esc_html__('Define the interval between publications for each social account to regulate posting speed.' , 'fs-poster');?></div>
			</div>
			<div style="margin-right: 25px;">
				<select name="fs_post_interval" id="fs_post_interval" class="ws_form_element" style="width: 150px;">
					<option value="0"<?php print Helper::getOption('post_interval', '0')=='0'?' selected':''?>>- Immediately</option>
					<option value="5"<?php print Helper::getOption('post_interval', '0')=='5'?' selected':''?>>5 seconds</option>
					<option value="10"<?php print Helper::getOption('post_interval', '0')=='10'?' selected':''?>>10 seconds</option>
					<option value="20"<?php print Helper::getOption('post_interval', '0')=='20'?' selected':''?>>20 seconds</option>
					<option value="30"<?php print Helper::getOption('post_interval', '0')=='30'?' selected':''?>>30 seconds</option>
					<option value="45"<?php print Helper::getOption('post_interval', '0')=='45'?' selected':''?>>45 seconds</option>
					<option value="60"<?php print Helper::getOption('post_interval', '0')=='60'?' selected':''?>>1 minute(s)</option>
					<option value="120"<?php print Helper::getOption('post_interval', '0')=='120'?' selected':''?>>2 minute(s)</option>
					<option value="180"<?php print Helper::getOption('post_interval', '0')=='180'?' selected':''?>>3 minute(s)</option>
					<option value="240"<?php print Helper::getOption('post_interval', '0')=='240'?' selected':''?>>4 minute(s)</option>
					<option value="300"<?php print Helper::getOption('post_interval', '0')=='300'?' selected':''?>>5 minute(s)</option>
					<option value="600"<?php print Helper::getOption('post_interval', '0')=='600'?' selected':''?>>10 minute(s)</option>
					<option value="900"<?php print Helper::getOption('post_interval', '0')=='900'?' selected':''?>>15 minute(s)</option>
					<option value="1200"<?php print Helper::getOption('post_interval', '0')=='1200'?' selected':''?>>20 minute(s)</option>
					<option value="1500"<?php print Helper::getOption('post_interval', '0')=='1500'?' selected':''?>>25 minute(s)</option>
					<option value="1800"<?php print Helper::getOption('post_interval', '0')=='1800'?' selected':''?>>30 minute(s)</option>
					<option value="2400"<?php print Helper::getOption('post_interval', '0')=='2400'?' selected':''?>>40 minute(s)</option>
					<option value="3000"<?php print Helper::getOption('post_interval', '0')=='3000'?' selected':''?>>50 minute(s)</option>
					<option value="3600"<?php print Helper::getOption('post_interval', '0')=='3600'?' selected':''?>>1 hour(s)</option>
					<option value="7200"<?php print Helper::getOption('post_interval', '0')=='7200'?' selected':''?>>2 hour(s)</option>
					<option value="10800"<?php print Helper::getOption('post_interval', '0')=='10800'?' selected':''?>>3 hour(s)</option>
					<option value="18000"<?php print Helper::getOption('post_interval', '0')=='18000'?' selected':''?>>5 hour(s)</option>
				</select>
			</div>
		</div>
	</div>
	<div style="width: 50%;" id="hide_limit_speed_add">
		<div class="fs_setting_item">
			<div class="fs_setting_item_label">
				<div><?php print esc_html__('Use "Post interval" option only same social networks:' , 'fs-poster')?></div>
				<div class="fs_s_help"><?php print esc_html__('Limit posting speed only same social network accounts. ' , 'fs-poster')?></div>
			</div>
			<div class="fs_s_input">
				<div class="fs_onoffswitch">
					<input type="checkbox" onautocomplete="off" name="fs_post_interval_type" class="fs_onoffswitch-checkbox" id="fs_post_interval_type"<?php print Helper::getOption('post_interval_type', '1')?' checked':''?>>
					<label class="fs_onoffswitch-label" for="fs_post_interval_type"></label>
				</div>
			</div>
		</div>
	</div>
</div>

<div class="fs_setting_item" style="width: 50%;">
	<div class="fs_setting_item_label">
		<div><?php print esc_html__('Replace the white spaces in the tags with an underscore:' , 'fs-poster')?></div>
		<div class="fs_s_help"><?php print esc_html__('Enable the option to replace the whitespaces with underscores in keyword of {tags} and {categories} ( e.g., "Sport News" will be transformed to "#sport_news" ). Disable the option to remove the whitespaces in keyword of {tags} and {categories} ( e.g., "Sport News" will be transformed to "#sportnews" ).' , 'fs-poster')?></div>
	</div>
	<div class="fs_s_input">
		<div class="fs_onoffswitch">
			<input type="checkbox" onautocomplete="off" name="fs_replace_whitespaces_with_underscore" class="fs_onoffswitch-checkbox" id="fs_replace_whitespaces_with_underscore"<?php print Helper::getOption('replace_whitespaces_with_underscore', '0')?' checked':''?>>
			<label class="fs_onoffswitch-label" for="fs_replace_whitespaces_with_underscore"></label>
		</div>
	</div>
</div>

<div class="fs_setting_item" style="width: 50%;">
	<div class="fs_setting_item_label">
		<div><?php print esc_html__('Replace WordPress shortcodes to their values:' , 'fs-poster')?></div>
		<div class="fs_s_help"><?php print esc_html__('Enable the option to replace WordPress shortcodes to their values.' , 'fs-poster')?></div>
	</div>
	<div class="fs_s_input">
		<div class="fs_onoffswitch">
			<input type="checkbox" onautocomplete="off" name="fs_replace_wp_shortcodes" class="fs_onoffswitch-checkbox" id="fs_replace_wp_shortcodes"<?php print Helper::getOption('replace_wp_shortcodes', '0')?' checked':''?>>
			<label class="fs_onoffswitch-label" for="fs_replace_wp_shortcodes"></label>
		</div>
	</div>
</div>

<script>
	var fadeSpeed = 0;
	jQuery(document).ready(function()
	{
		if( typeof $ == 'undefined' ) var $ = typeof jQuery == 'undefined' ? null : jQuery;

		$("#save_btn").click(function()
		{
			var data = fsCode.serialize($(".settings_form"));

			fsCode.ajax('settings_share_save' , data , function(result)
			{
				fsCode.toast("<?php print esc_html__('Save successful!' , 'fs-poster')?>" , 'success');
			});
		});

		fadeSpeed = 200;

		$("[data-open-img]").click(function ()
		{
			var imgSrc = $(this).data('open-img');

			fsCode.modal('<div><img src="'+imgSrc+'" style="width: 100%;"></div><div style="border-top: 1px solid #999; text-align: center; padding: 10px; margin-top: 9px;"><button type="button" data-modal-close="true" class="ws_btn ws_bg_danger">Close modal</button></div>' , {'width': '60%'});
		});

		$("#fs_post_interval").change(function()
		{
			if ($(this).val() > 0)
			{
				$("#hide_limit_speed_add").fadeIn(300);
			}
			else
			{
				$("#hide_limit_speed_add").fadeOut(300);
			}
		}).trigger('change');
	});
</script>