<?php
/**
 * HappyFenceNG Total Enterprise Security Plugin
 * HAPPYWPRISS is a RazorVue Trademark.
 *
 * @package     HappyFenceNG
 * @developer   Simonluca Scillitani
 * @copyright   2025 RazorVue di Scillitani Simonluca
 * @link        https://razorvue.it
 * @author      RazorVue di Scillitani Simonluca
 * @brand       HappyWPRIss
 * @uri         https://happywPRIss.com
 * @set all
 */

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

/**PHPCS -> code compliance: we put useful comments where needed.. */
class HappyFenceNGVRPRI extends HappyFenceNGAVRoute {

	/**PHPCS -> code compliance: we put useful comments where needed.. */
	public function doRoute() {
		try {

			$nonce_save_settings = wp_create_nonce( 'happyfenceng_PRI_save_settings' );
			$burn                = HappyFenceNGFailFast::setup();

			$params = array(
				'texts'  => array(
					'title'                             => esc_html__( 'Privacy Settings', 'happyfenceng-total-enterprise-security' ),
					'enable_privacy_management_title'   => esc_html__( 'Enable Privacy Management', 'happyfenceng-total-enterprise-security' ),
					'enable_privacy_management_description' => esc_html__( 'Check to show the privacy banner', 'happyfenceng-total-enterprise-security' ),
					'enable_privacy_management_tooltip' => esc_html__( 'When enabling this option the plugin will show the privacy banned based on the options selected below.', 'happyfenceng-total-enterprise-security' ),

					'top_banner_text_title'             => esc_html__( 'Banner Text', 'happyfenceng-total-enterprise-security' ),
					'top_banner_text_description'       => esc_html__( 'Insert the title for your banner', 'happyfenceng-total-enterprise-security' ),
					'top_banner_text_tooltip'           => esc_html__( 'Add a custom title for your pricavy banner', 'happyfenceng-total-enterprise-security' ),

					'privacy_url_title'                 => esc_html__( 'Privacy Policy URL', 'happyfenceng-total-enterprise-security' ),
					'privacy_url_description'           => esc_html__( 'Specify if you have a custom url', 'happyfenceng-total-enterprise-security' ),
					'privacy_url_tooltip'               => esc_html__( 'When not empty, this option specifies the custom page to use for privacy options', 'happyfenceng-total-enterprise-security' ),

					'color_title'                       => esc_html__( 'Background color', 'happyfenceng-total-enterprise-security' ),
					'color_description'                 => esc_html__( 'Choose your preferred color', 'happyfenceng-total-enterprise-security' ),
					'color_tooltip'                     => esc_html__( 'Must be a valid hex #RGB or #RRGGBB color e.g.: #222 or #FFFF', 'happyfenceng-total-enterprise-security' ),

					'text_color_title'                  => esc_html__( 'Text color', 'happyfenceng-total-enterprise-security' ),
					'text_color_description'            => esc_html__( 'Choose your preferred color', 'happyfenceng-total-enterprise-security' ),
					'text_color_tooltip'                => esc_html__( 'Must be a valid hex #RGB or #RRGGBB color e.g.: #222 or #FFFF', 'happyfenceng-total-enterprise-security' ),

					'enable_policy_banner_title'        => esc_html__( 'Enable inline privacy policy', 'happyfenceng-total-enterprise-security' ),
					'enable_policy_banner_description'  => esc_html__( 'Display the default banner', 'happyfenceng-total-enterprise-security' ),
					'enable_policy_banner_tooltip'      => esc_html__( 'When enabled the default inline privacy poup will be used.', 'happyfenceng-total-enterprise-security' ),

					'cookie_url_title'                  => esc_html__( 'Cookie Policy URL', 'happyfenceng-total-enterprise-security' ),
					'cookie_url_description'            => esc_html__( 'Specify a custom url page', 'happyfenceng-total-enterprise-security' ),
					'cookie_url_tooltip'                => esc_html__( 'When not empty, this option specifies the custom page to use for cookies options', 'happyfenceng-total-enterprise-security' ),

					'enable_cookie_banner_title'        => esc_html__( 'Enable inline cookie banner', 'happyfenceng-total-enterprise-security' ),
					'enable_cookie_banner_description'  => esc_html__( 'Display the default banner', 'happyfenceng-total-enterprise-security' ),
					'enable_cookie_banner_tooltip'      => esc_html__( 'When enabled the default inline cookie popup will be used.', 'happyfenceng-total-enterprise-security' ),

					'terms_url_title'                   => esc_html__( 'Terms URL', 'happyfenceng-total-enterprise-security' ),
					'terms_url_description'             => esc_html__( 'Custom page terms URL', 'happyfenceng-total-enterprise-security' ),
					'terms_url_tooltip'                 => esc_html__( 'When not empty, this option specifies the custom page to use for terms options', 'happyfenceng-total-enterprise-security' ),

					'enable_terms_banner_title'         => esc_html__( 'Enable inline terms and conditions', 'happyfenceng-total-enterprise-security' ),
					'enable_terms_banner_description'   => esc_html__( 'Enable default popup', 'happyfenceng-total-enterprise-security' ),
					'enable_terms_banner_tooltip'       => esc_html__( 'When enabled the default inline terms popup will be used.', 'happyfenceng-total-enterprise-security' ),

					'show_manage_link_title'            => esc_html__( 'Manage link visibility', 'happyfenceng-total-enterprise-security' ),
					'show_manage_link_description'      => esc_html__( 'Show link after consent', 'happyfenceng-total-enterprise-security' ),
					'show_manage_link_tooltip'          => esc_html__( 'Show the "Manage cookie preferences" link after consent', 'happyfenceng-total-enterprise-security' ),

					'company_name_title'                => esc_html__( 'Company Name', 'happyfenceng-total-enterprise-security' ),
					'company_name_description'          => esc_html__( 'Add your company name', 'happyfenceng-total-enterprise-security' ),
					'company_name_tooltip'              => esc_html__( 'The Company Name to show in the banners', 'happyfenceng-total-enterprise-security' ),

					'owner_email_title'                 => esc_html__( 'Owner email', 'happyfenceng-total-enterprise-security' ),
					'owner_email_description'           => esc_html__( 'Add your email address', 'happyfenceng-total-enterprise-security' ),
					'owner_email_tooltip'               => esc_html__( 'The email address to show in the banners', 'happyfenceng-total-enterprise-security' ),

					'treatment_location_title'          => esc_html__( 'Treatment Location', 'happyfenceng-total-enterprise-security' ),
					'treatment_location_description'    => esc_html__( 'Add your location name', 'happyfenceng-total-enterprise-security' ),
					'treatment_location_tooltip'        => esc_html__( 'Where you treat user data.', 'happyfenceng-total-enterprise-security' ),

					'privacy_warning'                   => esc_html__( 'Your site does not have a Privacy Policy and you have not selected the Enable Privacy Policy Popup.  Nothing will be showed.', 'happyfenceng-total-enterprise-security' ),
					'cookie_warning'                    => esc_html__( 'Your site does not have a Cookie Policy and you have not selected the Enable Cookie Policy Popup.  Nothing will be showed.', 'happyfenceng-total-enterprise-security' ),
					'terms_warning'                     => esc_html__( 'Your site does not have a Terms Policy and you have not selected the Enable Terms Policy Popup.  Nothing will be showed.', 'happyfenceng-total-enterprise-security' ),

					'feature_requires'                  => esc_html__( 'THIS FEATURE IS FREE', 'happyfenceng-total-enterprise-security' ),
					'save_settings'                     => esc_html__( 'Save Settings', 'happyfenceng-total-enterprise-security' ),
					'settings_saved'                    => esc_html__( 'Settings Saved', 'happyfenceng-total-enterprise-security' ),
					'error_saving_settings'             => esc_html__( 'Error saving settings', 'happyfenceng-total-enterprise-security' ),

				),
				'links'  => array(
					'happyfenceng_logo_url' => esc_url( HAPPYFENCENG_PLUGIN_URL . 'assets/images/happyfenceng-small.png' ),

				),
				'values' => array(
					'enable_privacy_management' => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PRIVACY->enable_privacy_management, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
					'top_banner_text'           => esc_html( HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PRIVACY->top_banner_text, HappyFenceNGPlaceholder::EMPTY_STRING ) ),
					'color'                     => esc_attr( HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PRIVACY->color, HappyFenceNGPrivacyProps::_COLOR ) ),
					'text_color'                => esc_attr( HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PRIVACY->text_color, HappyFenceNGPrivacyProps::_COLOR ) ),
					'privacy_url'               => esc_url_raw( HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PRIVACY->privacy_url, HappyFenceNGPlaceholder::EMPTY_STRING ) ),
					'enable_policy_banner'      => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PRIVACY->enable_policy_banner, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
					'cookie_url'                => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PRIVACY->cookie_url, HappyFenceNGPlaceholder::EMPTY_STRING ),
					'enable_cookie_banner'      => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PRIVACY->enable_cookie_banner, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
					'terms_url'                 => esc_url_raw( HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PRIVACY->terms_url, HappyFenceNGPlaceholder::EMPTY_STRING ) ),
					'enable_terms_banner'       => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PRIVACY->enable_terms_banner, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
					'show_manage_link'          => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PRIVACY->show_manage_link, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
					'company_name'              => esc_attr( HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PRIVACY->company_name, HappyFenceNGPlaceholder::EMPTY_STRING ) ),
					'owner_email'               => esc_attr( HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PRIVACY->owner_email, HappyFenceNGPlaceholder::EMPTY_STRING ) ),
					'treatment_location'        => esc_attr( HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PRIVACY->treatment_location, HappyFenceNGPlaceholder::EMPTY_STRING ) ),
					'privacy_notice_warnings'   => (
													! (
														HappyFenceNGPROC::equals( HappyFenceNGWhoAmI::get_instance()->PRIVACY->enable_policy_banner, true ) ) ||
														(
															( HappyFenceNGPROC::equals( isset( HappyFenceNGWhoAmI::get_instance()->PRIVACY->privacy_url ), true ) &&
															HappyFenceNGPROC::equals( empty( HappyFenceNGWhoAmI::get_instance()->PRIVACY->privacy_url ), false )
														)
													)
												),
					'terms_notice_warnings'     => (
													! (
														HappyFenceNGPROC::equals( HappyFenceNGWhoAmI::get_instance()->PRIVACY->enable_terms_banner, true ) ) ||
														(
															( HappyFenceNGPROC::equals( isset( HappyFenceNGWhoAmI::get_instance()->PRIVACY->terms_url ), true ) &&
															HappyFenceNGPROC::equals( empty( HappyFenceNGWhoAmI::get_instance()->PRIVACY->terms_url ), false )
														)
													)
												),

					'cookie_notice_warnings'    => (
													! (
														HappyFenceNGPROC::equals( HappyFenceNGWhoAmI::get_instance()->PRIVACY->enable_cookie_banner, true ) ) ||
														(
															( HappyFenceNGPROC::equals( isset( HappyFenceNGWhoAmI::get_instance()->PRIVACY->cookie_url ), true ) &&
															HappyFenceNGPROC::equals( empty( HappyFenceNGWhoAmI::get_instance()->PRIVACY->cookie_url ), false )
														)
													)
												),

					'checkbox_on'               => HappyFenceNGPlaceholder::CHECKBOX_ON,
					'checkbox_off'              => HappyFenceNGPlaceholder::CHECKBOX_OFF,
					'nonce'                     => $nonce_save_settings,
					'burnNonce'                 => $burn,
					'feature_enabled'           => true,

				),
			);

			ob_start();
			HappyFenceNGVControl::renderView( $params, 'pri' );
			// phpcs:ignore WordPress.Security.EscapeOutput
			echo ob_get_clean();

		} catch ( Throwable $e ) {
			HappyFenceNGLOGCORE::logcore(
				'HappyFenceNGVRPRI - cannot render UI ' . $e->getMessage(),
				HappyFenceNGSyslogFacility::UI,
				HappyFenceNGSyslogSeverity::ERROR
			);
			ob_end_clean();
			HappyFenceNGCleaner::cleaner_oops();
		}
	}
}
