<?php
/**
 *  This file contains the whole feedback form to be displayed at the time of deactivation of the plugin.
 *
 * @package object-data-sync-for-salesforce
 */

namespace MoSfSyncSalesforce;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

use MoSfSyncSalesforce\Helper\Plugin_Constants;
use MoSfSyncSalesforce\Services\Utils;

/**
 * Displays the feedback form at the time of plugin deactivation.
 *
 * @return void
 */
function mo_sf_sync_display_feedback_form() {
	if ( isset( $_SERVER['PHP_SELF'] ) && 'plugins.php' !== basename( sanitize_text_field( wp_unslash( $_SERVER['PHP_SELF'] ) ) ) ) {
		return;
	}
	wp_enqueue_style( 'wp-pointer' );
	wp_enqueue_script( 'wp-pointer' );
	wp_enqueue_script( 'utils' );
	wp_enqueue_style( 'mo_sf_sync_admin_plugins_page_style', Utils::mo_sf_sync_get_settings_css_path_url(), array(), Plugin_Constants::VERSION );
	wp_enqueue_script( 'mo-sf-feedback-form-js', Utils::mo_sf_sync_get_feedback_form_js_path_url(), array( 'jquery' ), Plugin_Constants::VERSION, true );

	$feedback_form_config = array(
		'feedback_5' => esc_html__( 'Thank you for appreciating our work', 'object-data-sync-for-salesforce' ),
		'feedback_4' => esc_html__( 'We\'re glad that you are happy with our plugin', 'object-data-sync-for-salesforce' ),
		'feedback_3' => esc_html__( 'Let us know if you need any help', 'object-data-sync-for-salesforce' ),
		'feedback_2' => esc_html__( 'Found any issues ? Let us know and we\'ll fix it ASAP', 'object-data-sync-for-salesforce' ),
		'feedback_1' => esc_html__( 'Not happy with our plugin ? Let us know what went wrong', 'object-data-sync-for-salesforce' ),
	);
	wp_localize_script( 'mo-sf-feedback-form-js', 'feedbackFormConfig', $feedback_form_config );

	?>
	<div id="mo_sf_sync_feedback_modal" class="mo_sf_sync_modal"
		style="width:90%; margin-left:12%; margin-top:5%; text-align:center;">
		<div class="mo_sf_sync_modal-content" style="width:50%;">
			<h3 style="margin: 2%; text-align:center;"><b>
					<?php esc_attr_e( 'Your feedback', 'object-data-sync-for-salesforce' ); ?>
				</b><span class="mo_sf_sync_close" style="cursor: pointer">&times;</span>
			</h3>
			<hr style="width:75%;">
			<form name="f" method="post" action="" id="mo_sf_sync_feedback">
				<?php wp_nonce_field( 'mo_sf_sync_feedback' ); ?>
				<input type="hidden" name="option" value="mo_sf_sync_feedback" />
				<div>
					<p style="margin:2%">
					<h4 style="margin: 2%; text-align:center;">
						<?php esc_attr_e( 'Please help us to improve our plugin by giving your opinion.', 'object-data-sync-for-salesforce' ); ?><br>
					</h4>
					<div id="mo_sf_sync_smi_rate" style="text-align:center">
						<input type="radio" name="rate" id="mo_sf_sync_angry" value="1" />
						<label for="mo_sf_sync_angry">
							<?php
							Utils::mo_sf_sync_render_image(
								'angry.png',
								array(
									'alt'   => 'Angry',
									'class' => 'mo_sf_sync_sm',
								)
							);
							?>
						</label>

						<input type="radio" name="rate" id="mo_sf_sync_sad" value="2" />
						<label for="mo_sf_sync_sad">
							<?php
							Utils::mo_sf_sync_render_image(
								'sad.png',
								array(
									'alt'   => 'Sad',
									'class' => 'mo_sf_sync_sm',
								)
							);
							?>
						</label>


						<input type="radio" name="rate" id="mo_sf_sync_neutral" value="3" />
						<label for="mo_sf_sync_neutral">
							<?php
							Utils::mo_sf_sync_render_image(
								'normal.png',
								array(
									'alt'   => 'Normal',
									'class' => 'mo_sf_sync_sm',
								)
							);
							?>
						</label>

						<input type="radio" name="rate" id="mo_sf_sync_smile" value="4" />
						<label for="mo_sf_sync_smile">
							<?php
							Utils::mo_sf_sync_render_image(
								'smile.png',
								array(
									'alt'   => 'Smile',
									'class' => 'mo_sf_sync_sm',
								)
							);
							?>
						</label>

						<input type="radio" name="rate" id="mo_sf_sync_happy" value="5" checked />
						<label for="mo_sf_sync_happy">
							<?php
							Utils::mo_sf_sync_render_image(
								'happy.png',
								array(
									'alt'   => 'Happy',
									'class' => 'mo_sf_sync_sm',
								)
							);
							?>
						</label>

						<div id="mo_sf_sync_outer" style="visibility:visible"><span id="mo_sf_sync_result">
								<?php esc_attr_e( 'Thank you for appreciating our work', 'object-data-sync-for-salesforce' ); ?>
							</span></div>
					</div><br>
					<hr style="width:75%;">
					<?php
							$user  = wp_get_current_user();
							$email = $user->user_email;
					?>
					<div style="text-align:center;">

						<div style="display:inline-block; width:60%;">
							<input type="email" id="mo_sf_sync_query_mail" name="query_mail"
								style="text-align:center; border:0px solid black; border-style:solid; background:#f0f3f7; width:20vw;border-radius: 6px;"
								placeholder="<?php esc_attr_e( 'Please enter your email address', 'object-data-sync-for-salesforce' ); ?>"
								required value="<?php echo esc_attr( $email ); ?>" readonly="readonly" />

							<input type="radio" name="edit" id="mo_sf_sync_edit" value="" />
							<label for="edit"><img class="mo_sf_sync_editable"
									src="<?php echo esc_url( plugin_dir_url( __FILE__ ) ) . 'images/61456.png'; ?>" />
							</label>

						</div>
						<br><br>
						<textarea id="query_feedback" name="query_feedback" rows="4" style="width: 60%"
							placeholder="<?php esc_attr_e( 'Tell us what happened!', 'object-data-sync-for-salesforce' ); ?>"></textarea>
						<br><br>
						<input type="checkbox" name="get_reply" value="yes" checked>
						<?php esc_attr_e( 'miniOrange representative will reach out to you at the email-address entered above.', 'object-data-sync-for-salesforce' ); ?></input>
					</div>
					<br>

					<div class="mo_sf_sync_modal-footer" style="text-align: center;margin-bottom: 2%">
						<input type="submit" name="miniorange_feedback_submit"
							class="button button-primary button-large"
							value="<?php esc_attr_e( 'Send', 'object-data-sync-for-salesforce' ); ?>" />
						<span width="30%">&nbsp;&nbsp;</span>
						<input type="submit" name="miniorange_feedback_submit" class="button button-primary button-large"
							value="<?php esc_attr_e( 'Skip', 'object-data-sync-for-salesforce' ); ?>"/>
					</div>
				</div>
			</form>
		</div>
	</div>
	<?php
}
