<?php
/**
 * Deactivation Feedback View
 *
 * Renders the modal markup used to collect feedback on plugin deactivation.
 *
 * @package    MOMCS_Sync
 * @subpackage MOMCS_Sync\views\src\common\components
 * @author     miniOrange
 */

declare(strict_types=1);

namespace MOMCS_Sync\Views\Src\Common\Components;

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

/**
 * Class Deactivation_Feedback_View
 */
class Deactivation_Feedback_View {
	/**
	 * Render the feedback modal markup.
	 *
	 * @return void
	 */
	public function render(): void {
		$current_user = wp_get_current_user();
		$email        = $current_user && isset( $current_user->user_email ) ? (string) $current_user->user_email : '';

		?>
		<div id="momcs-deactivation-feedback-modal" class="momcs-deactivation-feedback-modal" aria-hidden="true">
			<div class="momcs-deactivation-feedback-modal__content" role="dialog" aria-modal="true" aria-labelledby="momcs-deactivation-feedback-title">
				<button type="button" class="momcs-deactivation-feedback-close" id="momcs-deactivation-feedback-close" aria-label="<?php echo esc_attr__( 'Close', 'multi-channel-for-woocommerce' ); ?>">&times;</button>

				<div class="momcs-deactivation-feedback-step" id="momcs-deactivation-feedback-step-initial" data-step="initial">
					<h2 id="momcs-deactivation-feedback-title"><?php echo esc_html__( 'Leaving too soon?', 'multi-channel-for-woocommerce' ); ?></h2>
					<p><?php echo esc_html__( 'We would love to improve. Could you spare a moment to tell us why you are deactivating?', 'multi-channel-for-woocommerce' ); ?></p>
					<div class="momcs-deactivation-feedback-actions">
						<button type="button" class="button" id="momcs-deactivation-feedback-stay"><?php echo esc_html__( 'Stay', 'multi-channel-for-woocommerce' ); ?></button>
						<button type="button" class="button button-primary" id="momcs-deactivation-feedback-continue"><?php echo esc_html__( 'Deactivate', 'multi-channel-for-woocommerce' ); ?></button>
					</div>
				</div>

				<div class="momcs-deactivation-feedback-step" id="momcs-deactivation-feedback-step-form" data-step="form" style="display:none;">
					<h2><?php echo esc_html__( 'Why are you deactivating?', 'multi-channel-for-woocommerce' ); ?></h2>
					<form id="momcs-deactivation-feedback-form" class="momcs-deactivation-feedback-form">
						<fieldset class="momcs-deactivation-feedback-reasons">
							<legend class="screen-reader-text"><?php echo esc_html__( 'Deactivation reason', 'multi-channel-for-woocommerce' ); ?></legend>
							<label class="momcs-deactivation-feedback-reason">
								<input type="radio" name="momcs_deactivation_reason" value="temporary" />
								<span><?php echo esc_html__( 'I only needed it temporarily', 'multi-channel-for-woocommerce' ); ?></span>
							</label>
							<label class="momcs-deactivation-feedback-reason">
								<input type="radio" name="momcs_deactivation_reason" value="found_better" />
								<span><?php echo esc_html__( 'I found a better plugin', 'multi-channel-for-woocommerce' ); ?></span>
							</label>
							<label class="momcs-deactivation-feedback-reason">
								<input type="radio" name="momcs_deactivation_reason" value="missing_features" />
								<span><?php echo esc_html__( 'Missing features I need', 'multi-channel-for-woocommerce' ); ?></span>
							</label>
							<label class="momcs-deactivation-feedback-reason">
								<input type="radio" name="momcs_deactivation_reason" value="not_working" />
								<span><?php echo esc_html__( 'It is not working as expected', 'multi-channel-for-woocommerce' ); ?></span>
							</label>
							<label class="momcs-deactivation-feedback-reason">
								<input type="radio" name="momcs_deactivation_reason" value="switching_premium" />
								<span><?php echo esc_html__( 'I am switching to a premium version', 'multi-channel-for-woocommerce' ); ?></span>
							</label>
							<label class="momcs-deactivation-feedback-reason">
								<input type="radio" name="momcs_deactivation_reason" value="other" />
								<span><?php echo esc_html__( 'Other', 'multi-channel-for-woocommerce' ); ?></span>
							</label>
						</fieldset>

						<label for="momcs_deactivation_details"><?php echo esc_html__( 'Additional details (optional)', 'multi-channel-for-woocommerce' ); ?></label>
						<textarea id="momcs_deactivation_details" rows="4" placeholder="<?php echo esc_attr__( 'Tell us more so we can improve.', 'multi-channel-for-woocommerce' ); ?>"></textarea>

						<label for="momcs_deactivation_email" class="momcs-deactivation-feedback-label-margin"><?php echo esc_html__( 'Email (optional)', 'multi-channel-for-woocommerce' ); ?></label>
						<input type="email" id="momcs_deactivation_email" value="<?php echo esc_attr( $email ); ?>" placeholder="<?php echo esc_attr__( 'name@example.com', 'multi-channel-for-woocommerce' ); ?>" />

						<div id="momcs-deactivation-feedback-error" class="momcs-contact-us-alert momcs-contact-us-alert--error" style="display:none;"></div>
						<div id="momcs-deactivation-feedback-success" class="momcs-contact-us-alert momcs-contact-us-alert--success" style="display:none;"></div>

						<div class="momcs-deactivation-feedback-actions">
							<button type="button" class="button" id="momcs-deactivation-feedback-back"><?php echo esc_html__( 'Back', 'multi-channel-for-woocommerce' ); ?></button>
							<button type="submit" class="button button-primary" id="momcs-deactivation-feedback-submit"><?php echo esc_html__( 'Submit & Deactivate', 'multi-channel-for-woocommerce' ); ?></button>
							<button type="button" class="button" id="momcs-deactivation-feedback-skip"><?php echo esc_html__( 'Skip & Deactivate', 'multi-channel-for-woocommerce' ); ?></button>
						</div>
						<div id="momcs-deactivation-feedback-loading" class="momcs-contact-us-loading" style="display:none;"></div>
					</form>
				</div>
			</div>
		</div>
		<?php
	}
}
