<?php
/**
 * Flow Builder.
 *
 * @package automation-web-platform
 */

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

if ( ! defined( 'WAWP_NOTIF_CRON_HOOK' ) ) {
	define( 'WAWP_NOTIF_CRON_HOOK', 'wawp_notif_send_scheduled_notification_action' );
}

/**
 * Class WAWP_Flow_Builder
 */
class WAWP_Flow_Builder {
	use WAWP_Flow_Logic;
	use WAWP_WordPress_Triggers;
	use WAWP_Woocommerce_Triggers;
	use WAWP_Subscription_Triggers;
	use WAWP_Abandoned_Cart_Triggers;

	/**
	 * Database manager.
	 *
	 * @var WAWP_Database_Manager
	 */
	private $wawp_db_manager;

	/**
	 * Singleton instance.
	 *
	 * @var WAWP_Flow_Builder|null
	 */
	private static $instance = null;

	/**
	 * Get singleton instance.
	 *
	 * @return WAWP_Flow_Builder
	 */
	public static function get_instance() {
		if ( null === self::$instance ) {
			self::$instance = new self();
		}

		return self::$instance;
	}

	/**
	 * Constructor.
	 */
	public function __construct() {
		if ( class_exists( 'WAWP_Database_Manager' ) ) {
			$this->wawp_db_manager = WAWP()->db;
		}

		$this->init_hooks();
	}

	/**
	 * Initialize hooks.
	 */
	private function init_hooks() {
		// WordPress Core Triggers.
		add_action( 'wp_login', array( $this, 'handle_user_login_trigger' ), 20, 2 );
		add_action( 'user_register', array( $this, 'handle_user_signup_trigger' ), 20, 1 );

		// WooCommerce Triggers.
		if ( class_exists( 'WooCommerce' ) ) {
			add_action( 'woocommerce_order_status_changed', array( $this, 'handle_order_status_change' ), 10, 4 );
			add_action( 'woocommerce_new_customer_note', array( $this, 'handle_new_customer_note_trigger' ), 20, 1 );

			// Pending payment / early status hooks processing.
			add_action( 'woocommerce_checkout_order_processed', array( $this, 'process_pending_order_notifications' ), 20, 1 );
			add_action( 'woocommerce_new_order', array( $this, 'process_pending_order_notifications' ), 20, 1 );
			add_action( 'woocommerce_update_order', array( $this, 'process_pending_order_notifications' ), 20, 1 );

			// Manual Status Notifications.
			add_action( 'woocommerce_order_action_send_order_details', array( $this, 'handle_wc_manual_status_notify' ), 10, 1 );
			add_action( 'woocommerce_order_action_resend_new_order_notification', array( $this, 'handle_wc_manual_status_notify' ), 10, 1 );

			// Subscriptions.
			if ( class_exists( 'WC_Subscriptions' ) && $this->is_subscription_notifs_active() ) {
				add_action( 'woocommerce_subscription_status_updated', array( $this, 'handle_subscription_status_updated' ), 20, 3 );
				add_action( 'woocommerce_subscription_renewal_payment_complete', array( $this, 'handle_subscription_renewal_complete' ), 20, 2 );
			}
		}

		// Abandoned Cart Triggers.
		add_action( 'wawp_abandoned_cart_trigger', array( $this, 'handle_abandoned_cart_trigger' ), 10, 2 );

		// Cron Handlers.
		add_action( WAWP_NOTIF_CRON_HOOK, array( $this, 'process_scheduled_notification' ), 10, 1 );
	}

	/**
	 * Render settings page.
	 */
	public function render_settings_page() {
		echo '<div id="wawp-dashboard-root"></div>';
	}

	/**
	 * Fallback for missing method to prevent fatal errors if cron fires.
	 *
	 * @param array $args Cron arguments.
	 */
	public function process_scheduled_notification( $args ) {
		if ( empty( $args['rule_id'] ) || empty( $args['lang_code'] ) ) {
			return;
		}

		$rule = $this->get_rule( $args['rule_id'], $args['lang_code'] );
		if ( ! $rule || empty( $rule['enabled'] ) ) {
			return;
		}

		$this->perform_delivery( $rule, $args['replacements'] ?? array(), $args['recipient'] ?? array(), $args['log_base'] ?? '', $args['related_id'] ?? null );
	}

	/**
	 * Get data for React UI.
	 *
	 * @return array
	 */
	public function get_react_settings_data() {
		static $cached_result = null;
		if ( null !== $cached_result ) {
			return $cached_result;
		}

		global $wpdb;
		$settings              = $this->get_settings();
		$available_triggers    = $this->get_available_triggers();
		$meta_templates_for_js = class_exists( 'WAWP_Meta_Sender' ) ? WAWP_Meta_Sender::get_meta_templates_grouped() : array();
		$all_wc_countries      = array();

		if ( class_exists( 'WC_Countries' ) ) {
			$wc_countries     = new WC_Countries();
			$all_wc_countries = $wc_countries->get_allowed_countries();
		}

		$all_gateways = array();
		if ( class_exists( 'WC_Payment_Gateways' ) ) {
			$gateway_objects = WC()->payment_gateways()->payment_gateways();
			foreach ( $gateway_objects as $gateway ) {
				$all_gateways[ $gateway->id ] = $gateway->get_title();
			}
		}

		$online_instances = array();
		if ( class_exists( 'WAWP_Instance_Manager' ) ) {
			$online_instances = WAWP()->instance_manager->get_online_instances_cached();
		}

		$email_templates = WAWP()->db->get_results_cached(
			$wpdb->prepare( 'SELECT id, name FROM %i', $wpdb->prefix . 'wawp_email_templates' ),
			'wawp_email_templates_id_name',
			'wawp_notif'
		);

		$result = array(
			'settings'              => $settings,
			'availableTriggers'     => $available_triggers,
			'metaTemplates'         => $meta_templates_for_js,
			'placeholders'          => $this->get_available_placeholders(),
			'placeholderGroups'     => $this->get_grouped_placeholders(),
			'onlineInstances'       => $online_instances,
			'wcCountries'           => $all_wc_countries,
			'paymentGateways'       => $all_gateways,
			'emailTemplates'        => $email_templates,
			'isPro'                 => $this->is_pro_user(),
			'isMultiLangActive'     => $this->is_multi_lang_active(),
			'iconBaseUrl'           => WAWP_PLUGIN_URL . 'assets/icons/',
			'nonceSearchProducts'   => wp_create_nonce( 'wawp_search_products_nonce' ),
			'nonceSearchCategories' => wp_create_nonce( 'wawp_search_products_nonce' ),
			'availableTranslations' => ( function () {
				if ( ! function_exists( 'wp_get_available_translations' ) ) {
					require_once ABSPATH . 'wp-admin/includes/translation-install.php';
				}

				return wp_get_available_translations();
			} )(),
			'wpAdmins'              => ( function () {
				return array_map(
					function ( $user ) {
						$phone = WAWP()->user_manager->get_user_phone( $user->ID );

						return array(
							'ID'           => $user->ID,
							'display_name' => $user->display_name,
							'user_email'   => $user->user_email,
							'wa_number'    => $phone,
							'wa_verified'  => WAWP()->user_manager->get_verification_status( $user->ID, 'whatsapp' ),
						);
					},
					get_users( array( 'role' => 'administrator' ) )
				);
			} )(),
			'wpRoles'               => ( function () {
				$roles  = wp_roles()->roles;
				$result = array();
				foreach ( $roles as $key => $role ) {
					$result[] = array(
						'id'    => $key,
						'label' => translate_user_role( $role['name'] ),
					);
				}

				return $result;
			} )(),
			'i18n'                  => array(
				'pageTitle'                              => esc_html__( 'Notifications Builder', 'automation-web-platform' ),
				'pageSubtitle'                           => esc_html__( 'Unlimited notification options.', 'automation-web-platform' ),
				'addLanguage'                            => esc_html__( 'Add language', 'automation-web-platform' ),
				'newNotification'                        => esc_html__( 'New Notification', 'automation-web-platform' ),
				'saveSettings'                           => esc_html__( 'Save Settings', 'automation-web-platform' ),
				'duplicate'                              => esc_html__( 'Duplicate', 'automation-web-platform' ),
				'remove'                                 => esc_html__( 'Remove', 'automation-web-platform' ),
				'edit'                                   => esc_html__( 'Edit', 'automation-web-platform' ),
				'main'                                   => esc_html__( 'Main', 'automation-web-platform' ),
				'triggers'                               => esc_html__( 'Triggers', 'automation-web-platform' ),
				'targeting'                              => esc_html__( 'Targeting', 'automation-web-platform' ),
				'design'                                 => esc_html__( 'Design', 'automation-web-platform' ),
				'timing'                                 => esc_html__( 'Timing', 'automation-web-platform' ),
				'test'                                   => esc_html__( 'Test', 'automation-web-platform' ),
				'finish'                                 => esc_html__( 'Finish', 'automation-web-platform' ),
				'whatsapp'                               => esc_html__( 'WhatsApp', 'automation-web-platform' ),
				'email'                                  => esc_html__( 'Email', 'automation-web-platform' ),
				'userCopy'                               => esc_html__( 'User Copy', 'automation-web-platform' ),
				'adminCopy'                              => esc_html__( 'Admin Copy', 'automation-web-platform' ),
				'defaultWhatsAppMessage'                 => esc_html__( 'Hello {user_name}, welcome to {sitename}!', 'automation-web-platform' ),
				'defaultEmailSubject'                    => esc_html__( 'Notification from {sitename}', 'automation-web-platform' ),
				'defaultEmailBody'                       => esc_html__( "Hello {user_name},\n\nThis is a notification regarding your account on {sitename}.", 'automation-web-platform' ),
				'editAutomationRule'                     => esc_html__( 'Edit Automation Rule', 'automation-web-platform' ),
				'configureNotifFlow'                     => esc_html__( 'Configure your notification flow', 'automation-web-platform' ),
				'stepTrigger'                            => esc_html__( 'Trigger', 'automation-web-platform' ),
				'stepChannels'                           => esc_html__( 'Channels', 'automation-web-platform' ),
				'stepRecipients'                         => esc_html__( 'Recipients', 'automation-web-platform' ),
				'stepMedia'                              => esc_html__( 'Media', 'automation-web-platform' ),
				'stepMessage'                            => esc_html__( 'Message', 'automation-web-platform' ),
				'stepFilters'                            => esc_html__( 'Filters', 'automation-web-platform' ),
				'stepSimulator'                          => esc_html__( 'Simulator', 'automation-web-platform' ),
				'titleStep1'                             => esc_html__( 'Trigger & Automation Timing', 'automation-web-platform' ),
				'titleStep2'                             => esc_html__( 'Customer Delivery Channels', 'automation-web-platform' ),
				'titleStep3'                             => esc_html__( 'Configure Recipients', 'automation-web-platform' ),
				'titleStep4'                             => esc_html__( 'Header Media Settings', 'automation-web-platform' ),
				'titleStep5'                             => esc_html__( 'Message Content', 'automation-web-platform' ),
				'titleStep6'                             => esc_html__( 'Audience Targeting Rules', 'automation-web-platform' ),
				'titleStep7'                             => esc_html__( 'Simulation Engine', 'automation-web-platform' ),
				'descStep1'                              => esc_html__( 'Choose the event category and the specific action that triggers this rule.', 'automation-web-platform' ),
				'descStep2'                              => esc_html__( 'Select which channels to use for sending customer notifications.', 'automation-web-platform' ),
				'descStep3'                              => esc_html__( 'Define who should receive these notifications.', 'automation-web-platform' ),
				'descStep4'                              => esc_html__( 'Make your message standout with a header image.', 'automation-web-platform' ),
				'descStep5'                              => esc_html__( 'Write professional messages for each channel.', 'automation-web-platform' ),
				'descStep6'                              => esc_html__( 'Add specific conditions to filter your audience.', 'automation-web-platform' ),
				'descStep7'                              => esc_html__( 'Test your configuration using a real site context.', 'automation-web-platform' ),
				'eventCategory'                          => esc_html__( 'Event Category', 'automation-web-platform' ),
				'wordpressDesc'                          => esc_html__( 'Core system events', 'automation-web-platform' ),
				'woocommerceDescActive'                  => esc_html__( 'Store & orders', 'automation-web-platform' ),
				'woocommerceDescInactive'                => esc_html__( 'Requires WooCommerce plugin to be installed and active', 'automation-web-platform' ),
				'subscriptionsLabel'                     => esc_html__( 'Subscriptions', 'automation-web-platform' ),
				'subscriptionsDescActive'                => esc_html__( 'Recurring payments', 'automation-web-platform' ),
				'subscriptionsDescNoWoo'                 => esc_html__( 'Requires WooCommerce plugin active first', 'automation-web-platform' ),
				'subscriptionsDescInactive'              => esc_html__( 'Requires WooCommerce Subscriptions plugin to be active and Subscription Notifications enabled', 'automation-web-platform' ),
				'wawpAbandonedCartLabel'                 => esc_html__( 'Wawp Abandoned Cart', 'automation-web-platform' ),
				'wawpAbandonedCartDescActive'            => esc_html__( 'Abandoned Cart recovery', 'automation-web-platform' ),
				'wawpAbandonedCartDescInactive'          => esc_html__( 'Requires Abandoned Carts feature to be enabled in Dashboard', 'automation-web-platform' ),
				'eventAction'                            => esc_html__( 'Event Action', 'automation-web-platform' ),
				'executionSchedule'                      => esc_html__( 'Execution Schedule', 'automation-web-platform' ),
				'executeImmediately'                     => esc_html__( 'Execute Immediately', 'automation-web-platform' ),
				'executeWithDelay'                       => esc_html__( 'Execute with Delay', 'automation-web-platform' ),
				'delayValue'                             => esc_html__( 'Delay Value', 'automation-web-platform' ),
				'delayMins'                              => esc_html__( 'Mins', 'automation-web-platform' ),
				'delayHours'                             => esc_html__( 'Hours', 'automation-web-platform' ),
				'delayDays'                              => esc_html__( 'Days', 'automation-web-platform' ),
				'whatsappNotif'                          => esc_html__( 'WhatsApp Notification', 'automation-web-platform' ),
				'whatsappNotifDesc'                      => esc_html__( 'System will send automated alerts and updates to the user\'s phone number.', 'automation-web-platform' ),
				'prefDeliveryMethod'                     => esc_html__( 'Preferred Delivery Method', 'automation-web-platform' ),
				'wawpInstanceDesc'                       => esc_html__( 'Personal Account', 'automation-web-platform' ),
				'metaCloudDesc'                          => esc_html__( 'Paid subscription required to unlock', 'automation-web-platform' ),
				'emailSmtpTitle'                         => esc_html__( 'Email SMTP (Site)', 'automation-web-platform' ),
				'emailSmtpDesc'                          => esc_html__( 'Notifications will be delivered through your website\'s active SMTP server.', 'automation-web-platform' ),
				'enableInternalAdmin'                    => esc_html__( '1. Enable Internal Admin Channels', 'automation-web-platform' ),
				'whatsappAlert'                          => esc_html__( 'WhatsApp Alert', 'automation-web-platform' ),
				'emailAlert'                             => esc_html__( 'Email Alert', 'automation-web-platform' ),
				'selectStaffMembers'                     => esc_html__( 'Select Staff Members to Notify', 'automation-web-platform' ),
				'selectStaffMembersDesc'                 => esc_html__( 'Who in your team should get these critical internal alerts?', 'automation-web-platform' ),
				'wordpressLabel'                         => esc_html__( 'WordPress', 'automation-web-platform' ),
				'woocommerceLabel'                       => esc_html__( 'WooCommerce', 'automation-web-platform' ),
				'whatsappMarketingLabel'                 => esc_html__( 'WhatsApp Marketing', 'automation-web-platform' ),
				'whatsappMetaLabel'                      => esc_html__( 'WhatsApp Meta API', 'automation-web-platform' ),
				'adminWhatsappLabel'                     => esc_html__( 'Admin WhatsApp', 'automation-web-platform' ),
				'templateLabel'                          => esc_html__( 'Template', 'automation-web-platform' ),
				'sessionLabel'                           => esc_html__( 'Session', 'automation-web-platform' ),
				'freeLabel'                              => esc_html__( 'Free', 'automation-web-platform' ),
				'metaApiLabel'                           => esc_html__( 'Meta API', 'automation-web-platform' ),
				'whatsappWebLabel'                       => esc_html__( 'WhatsApp Web', 'automation-web-platform' ),
				'targetTemplateLabel'                    => esc_html__( 'Target Template', 'automation-web-platform' ),
				'chooseMetaTemplatePlaceholder'          => esc_html__( 'Choose a Meta template...', 'automation-web-platform' ),
				'metaTemplateNotice'                     => esc_html__( 'Approved templates are required for business-initiated conversations.', 'automation-web-platform' ),
				'messagePreviewLabel'                    => esc_html__( 'Message Preview', 'automation-web-platform' ),
				'liveDemoLabel'                          => esc_html__( 'Live Demo', 'automation-web-platform' ),
				'simulationNotice'                       => esc_html__( 'Simulation: Actual content uses production data.', 'automation-web-platform' ),
				'greetingsLabel'                         => esc_html__( 'Greetings', 'automation-web-platform' ),
				'personalizeLabel'                       => esc_html__( 'Personalize', 'automation-web-platform' ),
				'emojiLabel'                             => esc_html__( 'Emoji', 'automation-web-platform' ),
				'helpLabel'                              => esc_html__( 'Help', 'automation-web-platform' ),
				'aiLabel'                                => esc_html__( 'AI', 'automation-web-platform' ),
				'smartGreetingsLabel'                    => esc_html__( 'Smart Greetings', 'automation-web-platform' ),
				'allToolsLabel'                          => esc_html__( 'All Tools', 'automation-web-platform' ),
				'charsLabel'                             => esc_html__( 'CHARS', 'automation-web-platform' ),
				'typeSessionMessagePlaceholder'          => esc_html__( 'Type session message...', 'automation-web-platform' ),
				'enterWhatsAppMessageContentPlaceholder' => esc_html__( 'Enter WhatsApp message content...', 'automation-web-platform' ),
				'displayHeaderImage'                     => esc_html__( 'Display Header Image', 'automation-web-platform' ),
				'noImageLabel'                           => esc_html__( 'No Image', 'automation-web-platform' ),
				'noImageDesc'                            => esc_html__( 'Text-only', 'automation-web-platform' ),
				'featuredImageLabel'                     => esc_html__( 'Featured Image', 'automation-web-platform' ),
				'featuredImageDesc'                      => esc_html__( 'Use WP Post image', 'automation-web-platform' ),
				'customImageLabel'                       => esc_html__( 'Custom Image', 'automation-web-platform' ),
				'customImageDesc'                        => esc_html__( 'Custom Media URL', 'automation-web-platform' ),
				'dynamicProductLabel'                    => esc_html__( 'Dynamic Product', 'automation-web-platform' ),
				'dynamicProductDesc'                     => esc_html__( 'WooCommerce products', 'automation-web-platform' ),
				'mediaUrlDirectLink'                     => esc_html__( 'Media URL (Direct Link)', 'automation-web-platform' ),
				'customerEmailLabel'                     => esc_html__( 'Customer Email', 'automation-web-platform' ),
				'subjectLabel'                           => esc_html__( 'Subject', 'automation-web-platform' ),
				'selectTemplateLabel'                    => esc_html__( 'Select Template', 'automation-web-platform' ),
				'chooseEmailTemplate'                    => esc_html__( 'Choose email template...', 'automation-web-platform' ),
				'internalAlertsLabel'                    => esc_html__( 'Internal Alerts', 'automation-web-platform' ),
				'adminEmailLabel'                        => esc_html__( 'Admin Email', 'automation-web-platform' ),
				'adminEmailSubject'                      => esc_html__( 'Admin Email Subject', 'automation-web-platform' ),
				'automationTriggerCond'                  => esc_html__( 'Automation Trigger Conditions', 'automation-web-platform' ),
				'onlyExecuteIfCond'                      => esc_html__( 'Only execute this rule if the following conditions are met.', 'automation-web-platform' ),
				'countrySpecificLabel'                   => esc_html__( 'Country Specific', 'automation-web-platform' ),
				'productTargetingLabel'                  => esc_html__( 'Product Targeting', 'automation-web-platform' ),
				'categoryLogicLabel'                     => esc_html__( 'Category Logic', 'automation-web-platform' ),
				'paymentMethodLabel'                     => esc_html__( 'Payment Method', 'automation-web-platform' ),
				'audienceTargetingPro'                   => esc_html__( 'Audience Targeting requires Pro Plan', 'automation-web-platform' ),
				'audienceTargetingProDesc'               => esc_html__( 'Advanced targeting rules (Country targeting, Product targeting, Category logic, and Payment targeting) are only available for paid subscription accounts.', 'automation-web-platform' ),
				'upgradePlanBtn'                         => esc_html__( 'Upgrade Plan', 'automation-web-platform' ),
				'whitelistCountry'                       => esc_html__( 'WHITELIST (Only send if...)', 'automation-web-platform' ),
				'blocklistCountry'                       => esc_html__( 'BLOCKLIST (Do NOT send if...)', 'automation-web-platform' ),
				'allowedProducts'                        => esc_html__( 'ALLOWED PRODUCTS (IDs)', 'automation-web-platform' ),
				'restrictedProducts'                     => esc_html__( 'RESTRICTED PRODUCTS (IDs)', 'automation-web-platform' ),
				'searchProductsPlaceholder'              => esc_html__( 'Search products by name or SKU...', 'automation-web-platform' ),
				'allowedCategories'                      => esc_html__( 'ALLOWED CATEGORIES (IDs)', 'automation-web-platform' ),
				'restrictedCategories'                   => esc_html__( 'RESTRICTED CATEGORIES (IDs)', 'automation-web-platform' ),
				'searchCategoriesPlaceholder'            => esc_html__( 'Search categories...', 'automation-web-platform' ),
				'allowedPaymentGateways'                 => esc_html__( 'ALLOWED PAYMENT GATEWAYS', 'automation-web-platform' ),
				'selectedLabel'                          => esc_html__( 'Selected:', 'automation-web-platform' ),
				'allWord'                                => esc_html__( 'All', 'automation-web-platform' ),
				'activeRuleSimulator'                    => esc_html__( 'Active Rule Simulator', 'automation-web-platform' ),
				'testConfigLiveContext'                  => esc_html__( 'Test your configuration across User & Admin copies using live site contexts (Orders/Users).', 'automation-web-platform' ),
				'selectTargetStaffSimulation'            => esc_html__( 'Select target staff for simulation...', 'automation-web-platform' ),
				'deployingSimulation'                    => esc_html__( 'Deploying Simulation...', 'automation-web-platform' ),
				'fireTestNotif'                          => esc_html__( 'Fire Test Notification', 'automation-web-platform' ),
				'pleaseSelectStaffTest'                  => esc_html__( 'Please select a team member for the test.', 'automation-web-platform' ),
				'backBtn'                                => esc_html__( 'Back', 'automation-web-platform' ),
				'discardBtn'                             => esc_html__( 'Discard', 'automation-web-platform' ),
				'continueToStep'                         => esc_html__( 'Continue to Step', 'automation-web-platform' ),
				'applyTransformation'                    => esc_html__( 'Apply Transformation', 'automation-web-platform' ),
				'wawpInstance'                           => esc_html__( 'Wawp Instance', 'automation-web-platform' ),
				'metaCloudAPI'                           => esc_html__( 'Meta Cloud API', 'automation-web-platform' ),
				'officialAPIDesc'                        => esc_html__( 'Official API', 'automation-web-platform' ),
				'mediaUrlLabel'                          => esc_html__( 'Media URL', 'automation-web-platform' ),
				'activeTriggerAutomations'               => esc_html__( 'Active Trigger Automations', 'automation-web-platform' ),
				'rulesGroupedDesc'                       => esc_html__( 'Rules are grouped by feature for easier management.', 'automation-web-platform' ),
				'wordpressCoreEvents'                    => esc_html__( 'WordPress Core Events', 'automation-web-platform' ),
				'woocommerceStoreAlerts'                 => esc_html__( 'WooCommerce Store Alerts', 'automation-web-platform' ),
				'customerSubscriptions'                  => esc_html__( 'Customer Subscriptions', 'automation-web-platform' ),
				'wawpAbandonedCartGroup'                 => esc_html__( 'Wawp Abandoned Cart', 'automation-web-platform' ),
				'otherIntegrations'                      => esc_html__( 'Other Integrations', 'automation-web-platform' ),
				'pausedBadge'                            => esc_html__( 'Paused', 'automation-web-platform' ),
				'user'                                   => esc_html__( 'User', 'automation-web-platform' ),
				'admins'                                 => esc_html__( 'Admins', 'automation-web-platform' ),
				'both'                                   => esc_html__( 'Both', 'automation-web-platform' ),
				'instantTiming'                          => esc_html__( 'Instant', 'automation-web-platform' ),
				'noNotifsConfigured'                     => esc_html__( 'No Notifications Configured', 'automation-web-platform' ),
				'startByAddingTrigger'                   => esc_html__( 'Start by adding your first trigger above to automate your store.', 'automation-web-platform' ),
				'addLanguageTitle'                       => esc_html__( 'Add New Language', 'automation-web-platform' ),
				'addLanguageDesc'                        => esc_html__( 'Select the language you want to translate your notifications to.', 'automation-web-platform' ),
				'searchLanguageLabel'                    => esc_html__( 'Search Language', 'automation-web-platform' ),
				'searchLanguagePlaceholder'              => esc_html__( 'Search for a language...', 'automation-web-platform' ),
				'cancel'                                 => esc_html__( 'Cancel', 'automation-web-platform' ),
				'enableInternalAdminChannels'            => esc_html__( '1. Enable Internal Admin Channels', 'automation-web-platform' ),
				'selectStaffToNotify'                    => esc_html__( 'Select Staff Members to Notify', 'automation-web-platform' ),
				'selectStaffToNotifyDesc'                => esc_html__( 'Who in your team should get these critical internal alerts?', 'automation-web-platform' ),
				'audienceTargetingProTitle'              => esc_html__( 'Audience Targeting requires Pro Plan', 'automation-web-platform' ),
				'upgradePlan'                            => esc_html__( 'Upgrade Plan', 'automation-web-platform' ),
				'descUserLogin'                          => esc_html__( 'Sent automatically when a user logs into your site.', 'automation-web-platform' ),
				'descUserSignup'                         => esc_html__( 'Sent automatically when a new user registers on your site.', 'automation-web-platform' ),
				'descWcOrderNoteAdded'                   => esc_html__( 'Sent when a new customer note is added to an order.', 'automation-web-platform' ),
				'descWcStatusPrefix'                     => esc_html__( 'Sent when an order status is updated to {status}.', 'automation-web-platform' ),
				'descWcSubStatusPrefix'                  => esc_html__( 'Sent when a subscription is marked as {status}.', 'automation-web-platform' ),
				'descWcSubRenewal'                       => esc_html__( 'Sent when a subscription renewal payment is successfully processed.', 'automation-web-platform' ),
				'descWcSubNote'                          => esc_html__( 'Sent when a note is added to a subscription by an administrator.', 'automation-web-platform' ),
				'descTriggerFallback'                    => esc_html__( 'This notification triggers on the {event} event.', 'automation-web-platform' ),
				// Personalization Dialog Keys.
				'personalizationTitle'                   => esc_html__( 'Personalization', 'automation-web-platform' ),
				'personalizationDesc'                    => esc_html__( 'Insert dynamic variables to customize your message for each recipient', 'automation-web-platform' ),
				'searchVariablesPlaceholder'             => esc_html__( 'Search variables...', 'automation-web-platform' ),
				'noVariablesFound'                       => esc_html__( 'No variables found for your search.', 'automation-web-platform' ),
				'generalSiteVariables'                   => esc_html__( 'General Site Variables', 'automation-web-platform' ),
				'wordpressUserAccounts'                  => esc_html__( 'WordPress User Accounts', 'automation-web-platform' ),
				'woocommerceOrderDetails'                => esc_html__( 'WooCommerce Order Details', 'automation-web-platform' ),
				'woocommerceItemsProducts'               => esc_html__( 'WooCommerce Items & Products', 'automation-web-platform' ),
				'woocommerceBillingShipping'             => esc_html__( 'WooCommerce Billing & Shipping', 'automation-web-platform' ),
				'woocommerceSubscriptions'               => esc_html__( 'WooCommerce Subscriptions', 'automation-web-platform' ),
				// AI QA Spam Checker Keys.
				'antiBanCompliance'                      => esc_html__( 'Anti-Ban & Compliance', 'automation-web-platform' ),
				'bannedTerminology'                      => esc_html__( 'Banned terminology', 'automation-web-platform' ),
				// translators: %s: The specific filter violation.
				'strictFilterViolation'                  => esc_html__( 'Strict filter violation: %s', 'automation-web-platform' ),
				'optOutInteraction'                      => esc_html__( 'Opt-out (Interaction)', 'automation-web-platform' ),
				'addOptOutNotice'                        => esc_html__( 'Add "Reply STOP to unsubscribe" to build sender reputation.', 'automation-web-platform' ),
				'linkPlacement'                          => esc_html__( 'Link placement', 'automation-web-platform' ),
				'linkPlacementNotice'                    => esc_html__( 'URL detected at message start ({linkIdx}). Higher risk of automatic flag.', 'automation-web-platform' ),
				'clickbaitDetection'                     => esc_html__( 'Clickbait detection', 'automation-web-platform' ),
				// translators: %s: List of urgency terms.
				'avoidUrgencyTerms'                      => esc_html__( 'Avoid urgency terms like: %s', 'automation-web-platform' ),
				'structureHumanity'                      => esc_html__( 'Structure & Humanity', 'automation-web-platform' ),
				'optimalLength'                          => esc_html__( 'Optimal length (250-700)', 'automation-web-platform' ),
				'currentLengthNotice'                    => esc_html__( 'Current: {length} chars. Best for mobile is 250-700.', 'automation-web-platform' ),
				'readabilityComplexity'                  => esc_html__( 'Readability complexity', 'automation-web-platform' ),
				'complexSentencesNotice'                 => esc_html__( 'Complex sentences (Avg {avg} words). Break into smaller lines.', 'automation-web-platform' ),
				'visualStructure'                        => esc_html__( 'Visual structure (White space)', 'automation-web-platform' ),
				'solidTextBlockNotice'                   => esc_html__( 'Solid text block detected. Add double line breaks between paragraphs.', 'automation-web-platform' ),
				'richContent'                            => esc_html__( 'Rich content (Emojis & Formatting)', 'automation-web-platform' ),
				'addEmojisNotice'                        => esc_html__( 'Add a few emojis to look more like a human interaction.', 'automation-web-platform' ),
				'useBoldNotice'                          => esc_html__( 'Use *bold* for highlights to improve skimmability.', 'automation-web-platform' ),
				'engagementTechnical'                    => esc_html__( 'Engagement & Technical', 'automation-web-platform' ),
				'personalizationIntensity'               => esc_html__( 'Personalization intensity', 'automation-web-platform' ),
				'staticContentNotice'                    => esc_html__( 'Static content detected. Use variables to personalize every message.', 'automation-web-platform' ),
				'interactionHook'                        => esc_html__( 'Interaction hook (CTA)', 'automation-web-platform' ),
				'missingCtaNotice'                       => esc_html__( 'Missing call-to-action or trailing question.', 'automation-web-platform' ),
				'contentDiversity'                       => esc_html__( 'Content diversity (SpinTax)', 'automation-web-platform' ),
				'optionalSpintaxNotice'                  => esc_html__( "Optional: Use '{hi|hello}' to vary message delivery.", 'automation-web-platform' ),
				'brandSignature'                         => esc_html__( 'Brand signature', 'automation-web-platform' ),
				'missingSignatureNotice'                 => esc_html__( 'Missing brand name or site signature at message end.', 'automation-web-platform' ),
				'linkLengthRatio'                        => esc_html__( 'Link vs Length ratio', 'automation-web-platform' ),
				'sendingLinksTinyMsgNotice'              => esc_html__( 'Sending links in tiny messages is a high spam signal.', 'automation-web-platform' ),
				'otpUxStrategy'                          => esc_html__( 'OTP UX Strategy', 'automation-web-platform' ),
				'directnessCodeNotice'                   => esc_html__( 'Directness: Code should be the very first thing read.', 'automation-web-platform' ),
				'comprehensiveAiDiagnostic'              => esc_html__( 'Wawp Comprehensive AI Diagnostic • Anti-Ban Active', 'automation-web-platform' ),
				'passedResultText'                       => esc_html__( 'PASSED', 'automation-web-platform' ),
				'failedResultText'                       => esc_html__( 'FAILED', 'automation-web-platform' ),
				'analysisDurationLabel'                  => esc_html__( 'Analysis', 'automation-web-platform' ),
				'successLabel'                           => esc_html__( 'Success', 'automation-web-platform' ),
				'issuesFoundLabel'                       => esc_html__( 'Issues Found', 'automation-web-platform' ),
				'whitelistCountriesLabel'                => esc_html__( 'WHITELIST (Only send if...)', 'automation-web-platform' ),
				'blocklistCountriesLabel'                => esc_html__( 'BLOCKLIST (Do NOT send if...)', 'automation-web-platform' ),
				'allowedProductsLabel'                   => esc_html__( 'ALLOWED PRODUCTS (IDs)', 'automation-web-platform' ),
				'restrictedProductsLabel'                => esc_html__( 'RESTRICTED PRODUCTS (IDs)', 'automation-web-platform' ),
				'allowedCategoriesLabel'                 => esc_html__( 'ALLOWED CATEGORIES (IDs)', 'automation-web-platform' ),
				'restrictedCategoriesLabel'              => esc_html__( 'RESTRICTED CATEGORIES (IDs)', 'automation-web-platform' ),
				'selectItemsPlaceholder'                 => esc_html__( 'Select items...', 'automation-web-platform' ),
				'searchSelectPlaceholder'                => esc_html__( 'Search...', 'automation-web-platform' ),
				'selectAllLabel'                         => esc_html__( 'Select All', 'automation-web-platform' ),
				'deselectAllLabel'                       => esc_html__( 'Deselect All', 'automation-web-platform' ),
				'noItemsFoundLabel'                      => esc_html__( 'No items found.', 'automation-web-platform' ),
				'moreLabel'                              => esc_html__( 'more', 'automation-web-platform' ),
				// translators: %s: Search query.
				'noResultsForLang'                       => esc_html__( 'No results found for "%s"', 'automation-web-platform' ),
				// translators: %s: Sent count.
				'sentCount'                              => esc_html__( '%s sent', 'automation-web-platform' ),
			),
		);

		$cached_result = $result;
		return $result;
	}
}
