<?php
/**
 * Pixelio Cart Abandon Recovery More - Support Page
 *
 * This file handles the support page in the WordPress admin for the
 * Pixelio Cart Abandon Recovery More plugin. It provides:
 * - FAQ section
 * - Documentation links
 * - Support ticket submission form
 *
 * Features:
 * - Sends support emails with user-provided information
 * - Handles GDPR opt-in for temporary access
 * - Includes accordion UI for better UX
 *
 * @package PixelioCartAbandonRecoveryMore
 * @subpackage Admin
 * @since 1.0.0
 */

use PixelioCartAbandonRecoveryMore\Admin\Views\Reusable\Pixelio_Cart_Abandon_Recovery_More_Header;
use PixelioCartAbandonRecoveryMore\Admin\Views\Reusable\Pixelio_Cart_Abandon_Recovery_More_Overlay;
use PixelioCartAbandonRecoveryMore\Admin\Wrapper\Pixelio_Cart_Abandon_Recovery_More_Wordpress_Wrapper;
use PixelioCartAbandonRecoveryMore\Includes\Utils\Pixelio_Cart_Abandon_Recovery_More_Util;

if ( ! defined( 'ABSPATH' ) ) exit;
$pixelio_cart_abandon_recovery_more_mail_sent = false;
if ( isset( $_POST['pixelio-cart-abandon-recovery-more-email-contact'] ) &&
	isset( $_POST['pixelio-cart-abandon-recovery-more-issue'] ) && isset( $_POST['pixelio-cart-abandon-recovery-more-issue-description'] )
	&& isset( $_POST['pixelio-cart-abandon-recovery-more-issue-page'] ) &&
	isset( $_POST['pixelio-cart-abandon-recovery-more-rgpd-access'] ) &&  isset( $_POST['pixelio_cart_abandon_recovery_more_nonce'] )
	&& wp_verify_nonce(
		sanitize_text_field( wp_unslash( $_POST['pixelio_cart_abandon_recovery_more_nonce'] ) ),
		'pixelio_cart_abandon_recovery_more_action'
	)) {
	$pixelio_cart_abandon_recovery_more_mail_sent = wp_mail(
		'contact@pixelio.be',
		// phpcs:ignore WordPress.Security.NonceVerification.Missing -- safe admin-only GET check for plugin page slug.
		sanitize_text_field( wp_unslash( $_POST['pixelio-cart-abandon-recovery-more-issue'] ) ),
		// phpcs:ignore WordPress.Security.NonceVerification.Missing -- safe admin-only GET check for plugin page slug.
		sanitize_text_field( wp_unslash( $_POST['pixelio-cart-abandon-recovery-more-issue-description'] ) ) . ' ' .
		// phpcs:ignore WordPress.Security.NonceVerification.Missing -- safe admin-only GET check for plugin page slug.
		sanitize_text_field( wp_unslash( $_POST['pixelio-cart-abandon-recovery-more-issue-page'] ) ) . ' ' .
		// phpcs:ignore WordPress.Security.NonceVerification.Missing -- safe admin-only GET check for plugin page slug.
		sanitize_text_field( wp_unslash( $_POST['pixelio-cart-abandon-recovery-more-email-contact'] ) )
		// phpcs:ignore WordPress.Security.NonceVerification.Missing -- safe admin-only GET check for plugin page slug.
		. ' ' . sanitize_text_field( wp_unslash( $_POST['pixelio-cart-abandon-recovery-more-rgpd-access'] ) )
	);
}

?>
<div class="pixelio-cart-abandon-recovery-more-accordion-item pixelio-cart-abandon-recovery-more-hide-it">
	<button class="pixelio-cart-abandon-recovery-more-accordion-header">
	</button>
	<div class="pixelio-cart-abandon-recovery-more-accordion-body">
		<p></p>
	</div>
</div>
<?php
$pixelio_util = new Pixelio_Cart_Abandon_Recovery_More_Util(new Pixelio_Cart_Abandon_Recovery_More_Wordpress_Wrapper());
$pixelio_cart_abandon_recovery_more_header = new Pixelio_Cart_Abandon_Recovery_More_Header($pixelio_util);
$pixelio_cart_abandon_recovery_more_header->pixelio_cart_abandon_recovery_more_get_views();
?>
<div id="pixelio-cart-abandon-recovery-more-page-body">

	<div id="pixelio-cart-abandon-recovery-more-right-sidebar">
		<div
			class="pixelio-cart-abandon-recovery-more-page-section  pixelio-cart-abandon-recovery-more-page-section-container"
			id="pixelio-cart-abandon-recovery-more-faq-input-section">

			<div id="pixelio-cart-abandon-recovery-more-page-section-faq">

				<div class="pixelio-cart-abandon-recovery-more-card">

					<h3 class="pixelio-cart-abandon-recovery-more-accordion-section-subtitle "><?php esc_html_e( 'Frequently asked question', 'rivio-ai-cart-recovery-marketing-email-automation' ); ?></h3>

					<div id="pixelio-cart-abandon-recovery-more-accordion">


					</div>
				</div>
				<div class="pixelio-cart-abandon-recovery-more-card">
					<h3 class="pixelio-cart-abandon-recovery-more-accordion-section-subtitle "><?php esc_html_e( 'Documentations', 'rivio-ai-cart-recovery-marketing-email-automation' ); ?></h3>
					<p><?php esc_html_e( 'The documentation is accessible directly on our website. ', 'rivio-ai-cart-recovery-marketing-email-automation' ); ?></p>
					<a href="https://www.rivio.be/rivio-documentation/"
						class="pixelio-cart-abandon-recovery-more-input-button"><?php esc_html_e( 'Go to the documentation. ', 'rivio-ai-cart-recovery-marketing-email-automation' ); ?></a>
				</div>
				<div class="pixelio-cart-abandon-recovery-more-card">
					<h3 class="pixelio-cart-abandon-recovery-more-accordion-section-subtitle "><?php esc_html_e( 'Support form', 'rivio-ai-cart-recovery-marketing-email-automation' ); ?></h3>
					<p><?php esc_html_e( 'If none of the resources below have been able to assist you, feel free to submit your question below. To help us assist you better, we recommend enabling the creation of a temporary user below for the duration of your ticket resolution. Once you mark the issue as resolved, the system will automatically remove our access.', 'rivio-ai-cart-recovery-marketing-email-automation' ); ?></p>
					<?php if ( $pixelio_cart_abandon_recovery_more_mail_sent ) { ?>
						<p><?php esc_html_e( 'Mail has been sent successfully', 'rivio-ai-cart-recovery-marketing-email-automation' ); ?></p>
					<?php } else { ?>
						<form class="pixelio-contact-form" action="" method="POST" class="pixelio-contact-form">
							<!-- Issue Title -->
							<label class="pixelio-cart-abandon-recovery-more-input-label "
									for="issue"><?php esc_html_e( 'Where can we contact you back ?', 'rivio-ai-cart-recovery-marketing-email-automation' ); ?></label>

							<input type="text"
									class="pixelio-cart-abandon-recovery-more-input-text pixelio-cart-abandon-recovery-more-input-support-form"
									id="pixelio-cart-abandon-recovery-more-email-contact"
									name="pixelio-cart-abandon-recovery-more-email-contact" placeholder="Your email"
									required>
							<label class="pixelio-cart-abandon-recovery-more-input-label "
									for="issue"><?php esc_html_e( 'What is your issue?', 'rivio-ai-cart-recovery-marketing-email-automation' ); ?></label>

							<input type="text"
									class="pixelio-cart-abandon-recovery-more-input-text pixelio-cart-abandon-recovery-more-input-support-form"
									id="pixelio-cart-abandon-recovery-more-issue"
									name="pixelio-cart-abandon-recovery-more-issue"
									placeholder="Briefly describe your issue"
									required>


							<!-- Issue Description -->
							<div class="form-group">
								<label class="pixelio-cart-abandon-recovery-more-input-label" for="description">
									<?php esc_html_e( 'Describe it as much as you can', 'rivio-ai-cart-recovery-marketing-email-automation' ); ?>
								</label>
								<textarea
									class="pixelio-cart-abandon-recovery-more-input-support-form pixelio-cart-abandon-recovery-more-input-text"
									id="pixelio-cart-abandon-recovery-more-issue-description"
									name="pixelio-cart-abandon-recovery-more-issue-description"
									placeholder="Provide detailed information about your issue" required></textarea>
							</div>

							<!-- Page where it happened -->
							<div class="form-group">
								<label
									for="page"> <?php esc_html_e( 'On which page did it happen?', 'rivio-ai-cart-recovery-marketing-email-automation' ); ?></label>
								<input type="text" id="pixelio-cart-abandon-recovery-more-issue-page"
										class="pixelio-cart-abandon-recovery-more-input-text pixelio-cart-abandon-recovery-more-input-support-form"
										name="pixelio-cart-abandon-recovery-more-issue-page"
										placeholder="e.g., https://yourwebsite.com/specific-page" required>
							</div>

							<!-- Allow remote access -->
							<div class="pixelio-cart-abandon-recovery-more-opt-in-checkbox-container">
								<label class="pixelio-cart-abandon-recovery-more-checkbox-wrapper">
								<?php wp_nonce_field(
									'pixelio_cart_abandon_recovery_more_action',
									'pixelio_cart_abandon_recovery_more_nonce'
								);
								?><input type="checkbox" id="pixelio-cart-abandon-recovery-more-rgpd-access"
											class="pixelio-cart-abandon-recovery-more-opt-in-checkbox"
											name="pixelio-cart-abandon-recovery-more-rgpd-access">
									<div
										class="pixelio-cart-abandon-recovery-more-slider pixelio-cart-abandon-recovery-more-slider-not-pro pixelio-cart-abandon-recovery-more-checkbox-round "
										data-clicked_on="pixelio-cart-abandon-recovery-more-rgpd-access"></div>
								</label>
								<?php esc_html_e( 'I agree to be contacted back about this issue.', 'rivio-ai-cart-recovery-marketing-email-automation' ); ?>
							</div>

							<!-- Submit Button -->
							<div class="form-submit ">
								<button type="submit" class="pixelio-cart-abandon-recovery-more-input-button"
										id="pixelio-cart-abandon-recovery-more-faq-input-button"> <?php esc_html_e( 'Submit', 'rivio-ai-cart-recovery-marketing-email-automation' ); ?>
								</button>
							</div>
						</form>
					<?php } ?>
				</div>
			</div>
		</div>
	</div>
</div>
</div>
