<?php
/**
 * Dashboard management.
 *
 * @package automation-web-platform
 */

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

/**
 * WAWP Dashboard Class
 * Handles the main React dashboard container and user count optimization.
 */
class WAWP_Dashboard {
	/**
	 * Singleton instance.
	 *
	 * @var WAWP_Dashboard
	 */
	private static $instance = null;

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

		return self::$instance;
	}

	/**
	 * Render the React dashboard root element.
	 * Handled by WAWP_Menu now, but kept for backward compatibility if needed.
	 */
	public function render_page() {
		echo '<div id="wawp-dashboard-root"></div>';
	}

	/**
	 * Get dashboard data for React.
	 *
	 * @return array Dashboard data.
	 */
	public function get_dashboard_data() {
		$user_data                  = wawp_get_user_data();
		$connector                  = WAWP_Connector();
		$woocommerce_installed      = class_exists( 'WooCommerce' );
		$wc_subscriptions_installed = class_exists( 'WC_Subscriptions' );
		$wcs_installed              = $wc_subscriptions_installed || file_exists( WP_PLUGIN_DIR . '/woocommerce-subscriptions/woocommerce-subscriptions.php' );
		$icons_url                  = WAWP_PLUGIN_URL . 'assets/icons/';
		$is_guest                   = false;

		$is_pro = false;
		if ( ! empty( $user_data['is_lifetime'] ) ) {
			$is_pro = true;
		} elseif ( ! empty( $user_data['subscriptions'] ) && is_array( $user_data['subscriptions'] ) ) {
			foreach ( $user_data['subscriptions'] as $sub ) {
				if ( ! empty( $sub['status'] ) && 'active' === $sub['status'] ) {
					$is_pro = true;
					break;
				}
			}
		}

		$data = array(
			'isGuest'   => $is_guest,
			'stats'     => self::get_snapshot_stats(),
			'wooStatus' => array(
				'active'    => $woocommerce_installed,
				'installed' => $woocommerce_installed || file_exists( WP_PLUGIN_DIR . '/woocommerce/woocommerce.php' ),
			),
			'icons'     => array(
				'baseUrl'    => WAWP_PLUGIN_URL . 'assets/img/',
				'successGif' => WAWP_PLUGIN_URL . 'assets/img/success.gif',
				'errorGif'   => WAWP_PLUGIN_URL . 'assets/img/error.gif',
			),
			'features'  => array(
				'trackingIds'    => array(
					'enabled' => (bool) WAWP()->get_wawp_setting( WAWP_Settings_Registry::TRACKING_IDS_ENABLED, 1 ),
					'option'  => WAWP_Settings_Registry::TRACKING_IDS_ENABLED,
					'allowed' => true,
				),
				'emailTracking'  => array(
					'enabled' => (bool) WAWP()->get_wawp_setting( WAWP_Settings_Registry::EMAIL_TRACKING_ENABLED, 0 ),
					'option'  => WAWP_Settings_Registry::EMAIL_TRACKING_ENABLED,
					'allowed' => wawp_is_feature_allowed( 'activity_log', $user_data ),
				),
				'systemInfo'     => array(
					'enabled' => (bool) WAWP()->get_wawp_setting( WAWP_Settings_Registry::SYSTEM_INFO_ENABLED, 1 ),
					'option'  => WAWP_Settings_Registry::SYSTEM_INFO_ENABLED,
					'allowed' => wawp_is_feature_allowed( 'system_information', $user_data ),
				),
				'chatWidget'     => array(
					'enabled' => (bool) WAWP()->get_wawp_setting( WAWP_Settings_Registry::CHAT_WIDGET_ENABLED, 1 ),
					'option'  => WAWP_Settings_Registry::CHAT_WIDGET_ENABLED,
					'allowed' => wawp_is_feature_allowed( 'whatsapp_chat_button', $user_data ),
				),
				'notifications'  => array(
					'enabled' => (bool) WAWP()->get_wawp_setting( WAWP_Settings_Registry::NOTIFICATIONS_ENABLED, 1 ),
					'option'  => WAWP_Settings_Registry::NOTIFICATIONS_ENABLED,
					'allowed' => wawp_is_feature_allowed( 'advanced_notifications', $user_data ),
				),
				'activityHub'    => array(
					'enabled' => (bool) WAWP()->get_wawp_setting( WAWP_Settings_Registry::UNIFIED_LOG_ENABLED, 1 ),
					'option'  => WAWP_Settings_Registry::UNIFIED_LOG_ENABLED,
					'allowed' => wawp_is_feature_allowed( 'activity_log', $user_data ),
				),
				'countryCode'    => array(
					'enabled' => (bool) WAWP()->get_wawp_setting( WAWP_Settings_Registry::COUNTRYCODE_ENABLED, 1 ),
					'option'  => WAWP_Settings_Registry::COUNTRYCODE_ENABLED,
					'allowed' => wawp_is_feature_allowed( 'countrycode_cache', $user_data ),
				),
				'otpLogin'       => array(
					'enabled' => (bool) WAWP()->get_wawp_setting( WAWP_Settings_Registry::PASSWORDLESS_LOGIN_ENABLED, 1 ),
					'option'  => WAWP_Settings_Registry::PASSWORDLESS_LOGIN_ENABLED,
					'allowed' => wawp_is_feature_allowed( 'login_with_otp', $user_data ),
				),
				'signupOtp'      => array(
					'enabled' => (bool) WAWP()->get_wawp_setting( WAWP_Settings_Registry::SIGNUP_ENABLED, 1 ),
					'option'  => WAWP_Settings_Registry::SIGNUP_ENABLED,
					'allowed' => wawp_is_feature_allowed( 'registration_form_builder', $user_data ),
				),
				'checkoutOtp'    => array(
					'enabled' => (bool) WAWP()->get_wawp_setting( WAWP_Settings_Registry::CHECKOUT_OTP_ENABLED, 1 ) && $woocommerce_installed,
					'option'  => WAWP_Settings_Registry::CHECKOUT_OTP_ENABLED,
					'allowed' => wawp_is_feature_allowed( 'checkout_verification', $user_data ),
					'error'   => ! $woocommerce_installed ? esc_html__( 'WooCommerce plugin not active', 'automation-web-platform' ) : '',
				),
				'customPages'    => array(
					'enabled' => (bool) WAWP()->get_wawp_setting( WAWP_Settings_Registry::CUSTOM_PAGES_ENABLED, 1 ),
					'option'  => WAWP_Settings_Registry::CUSTOM_PAGES_ENABLED,
					'allowed' => wawp_is_feature_allowed( 'authentication_pages', $user_data ),
				),
				'recaptcha'      => array(
					'enabled' => (bool) WAWP()->get_wawp_setting( WAWP_Settings_Registry::GOOGLE_RECAPTCHA_ENABLED, 0 ),
					'option'  => WAWP_Settings_Registry::GOOGLE_RECAPTCHA_ENABLED,
					'allowed' => wawp_is_feature_allowed( 'google_recaptcha', $user_data ),
				),
				'abandonedCarts' => array(
					'enabled' => (bool) WAWP()->get_wawp_setting( WAWP_Settings_Registry::ABANDONED_CARTS_ENABLED, 0 ),
					'option'  => WAWP_Settings_Registry::ABANDONED_CARTS_ENABLED,
					'allowed' => wawp_is_feature_allowed( 'abandoned_cart_recovery', $user_data ),
				),
				'campaigns'      => array(
					'enabled' => (bool) WAWP()->get_wawp_setting( WAWP_Settings_Registry::CAMPAIGNS_ENABLED, 0 ),
					'option'  => WAWP_Settings_Registry::CAMPAIGNS_ENABLED,
					'allowed' => wawp_is_feature_allowed( 'segmented_notifications', $user_data ),
				),
				'multilang'      => array(
					'enabled' => (bool) WAWP()->get_wawp_setting( WAWP_Settings_Registry::MULTILANG_ENABLED, 0 ),
					'option'  => WAWP_Settings_Registry::MULTILANG_ENABLED,
					'allowed' => wawp_is_feature_allowed( 'multilingual_support', $user_data ),
				),
				'subNotifs'      => array(
					'enabled'    => (bool) WAWP()->get_wawp_setting( WAWP_Settings_Registry::SUB_NOTIFS_ENABLED, 0 ) && $wc_subscriptions_installed,
					'option'     => WAWP_Settings_Registry::SUB_NOTIFS_ENABLED,
					'allowed'    => wawp_is_feature_allowed( 'subscription_alerts', $user_data ),
					'error'      => ! $wc_subscriptions_installed ? esc_html__( 'WooCommerce Subscriptions plugin not active', 'automation-web-platform' ) : '',
					'pluginLink' => ! $wc_subscriptions_installed ? ( $wcs_installed ? admin_url( 'plugins.php?action=activate&plugin=woocommerce-subscriptions/woocommerce-subscriptions.php&_wpnonce=' . wp_create_nonce( 'activate-plugin_woocommerce-subscriptions/woocommerce-subscriptions.php' ) ) : admin_url( 'plugins.php' ) ) : '',
				),
				'emailTemplates' => array(
					'enabled' => (bool) WAWP()->get_wawp_setting( WAWP_Settings_Registry::EMAIL_TEMPLATES_ENABLED, 0 ),
					'option'  => WAWP_Settings_Registry::EMAIL_TEMPLATES_ENABLED,
					'allowed' => wawp_is_feature_allowed( 'email_templates', $user_data ),
				),
			),
			'urls'      => array(
				'usersAdmin'     => admin_url( 'users.php' ),
				'systemInfo'     => admin_url( 'admin.php?page=' . WAWP_MAIN_MENU_SLUG . '&wawp_section=system_info' ),
				'chatWidget'     => admin_url( 'admin.php?page=wawp&wawp_section=chat_widget' ),
				'notifications'  => admin_url( 'admin.php?page=wawp&wawp_section=notifications' ),
				'abandonedCarts' => admin_url( 'admin.php?page=' . WAWP_MAIN_MENU_SLUG . '&wawp_section=notifications' ),
				'campaigns'      => admin_url( 'admin.php?page=wawp&wawp_section=campaigns' ),
				'otpLogin'       => admin_url( 'admin.php?page=wawp&wawp_section=otp_messages&tab=tab-otp-login' ),
				'registration'   => admin_url( 'admin.php?page=wawp&wawp_section=otp_messages&tab=tab-signup' ),
				'checkout'       => admin_url( 'admin.php?page=wawp&wawp_section=otp_messages&tab=tab-checkout' ),
				'pages'          => admin_url( 'admin.php?page=wawp&wawp_section=otp_messages&tab=tab-login-signup-pages' ),
				'recaptcha'      => admin_url( 'admin.php?page=wawp&wawp_section=recaptcha' ),
				'phoneField'     => admin_url( 'admin.php?page=wawp&wawp_section=country-code' ),
				'pricing'        => 'https://wawp.net//',
				'wooActivate'    => admin_url( 'plugins.php?action=activate&plugin=woocommerce/woocommerce.php&_wpnonce=' . wp_create_nonce( 'activate-plugin_woocommerce/woocommerce.php' ) ),
				'wooInstall'     => admin_url( 'update.php?action=install-plugin&plugin=woocommerce&_wpnonce=' . wp_create_nonce( 'install-plugin_woocommerce' ) ),
			),
			'i18n'      => array(
				'success'                           => esc_html__( 'Option updated successfully.', 'automation-web-platform' ),
				'errorClose'                        => esc_html__( 'Close', 'automation-web-platform' ),
				'done'                              => esc_html__( 'Done', 'automation-web-platform' ),
				'proVersion'                        => esc_html__( 'Pro', 'automation-web-platform' ),
				'freeVersion'                       => esc_html__( 'Free', 'automation-web-platform' ),
				'labelVersion'                      => esc_html__( 'Version', 'automation-web-platform' ),
				'pageTitle'                         => esc_html__( 'Dashboard', 'automation-web-platform' ),
				'pageSubtitle'                      => esc_html__( 'Manage your automated workflows, track delivery performance, and monitor system health in one centralized location.', 'automation-web-platform' ),
				'successTitle'                      => esc_html__( 'Success', 'automation-web-platform' ),
				'errorTitle'                        => esc_html__( 'Error', 'automation-web-platform' ),
				'allUsers'                          => esc_html__( 'All Users', 'automation-web-platform' ),
				'allUsersSub'                       => esc_html__( 'Total WordPress accounts.', 'automation-web-platform' ),
				'badgeDb'                           => esc_html__( 'DB', 'automation-web-platform' ),
				'btnSettings'                       => esc_html__( 'Settings', 'automation-web-platform' ),
				'badgeConnect'                      => esc_html__( 'Connect', 'automation-web-platform' ),
				'badgeSecurity'                     => esc_html__( 'Security', 'automation-web-platform' ),
				'sectionEngagementDesc'             => __( 'Advanced communication tools to increase customer life-time value.', 'automation-web-platform' ),
				'sectionAuthDesc'                   => __( 'Secure and streamline your user onboarding with WhatsApp-powered identity flows.', 'automation-web-platform' ),
				'viewAllUsers'                      => esc_html__( 'View All Users', 'automation-web-platform' ),
				'snapshotTitle'                     => esc_html__( 'WordPress Users — Snapshot', 'automation-web-platform' ),
				'snapshotSubtitle'                  => esc_html__( 'Overview of phone numbers and verification status.', 'automation-web-platform' ),
				'emailTemplates'                    => esc_html__( 'Email Templates', 'automation-web-platform' ),
				'emailTemplatesDesc'                => __( 'Design professional, high-converting email templates using a drag-and-drop builder to elevate your brand communication and engagement.', 'automation-web-platform' ),
				'btnActivate'                       => esc_html__( 'Activate it first', 'automation-web-platform' ),
				'btnUpgrade'                        => esc_html__( 'Upgrade', 'automation-web-platform' ),
				'phoneAdded'                        => esc_html__( 'Phone Numbers Added', 'automation-web-platform' ),
				'phoneAddedSub'                     => esc_html__( 'Users with saved phone numbers.', 'automation-web-platform' ),
				'verifiedLabel'                     => esc_html__( 'Completed Verification', 'automation-web-platform' ),
				'verifiedSub'                       => esc_html__( 'Accounts successfully verified.', 'automation-web-platform' ),
				'badgeAll'                          => esc_html__( 'All', 'automation-web-platform' ),
				'badgeVerified'                     => esc_html__( 'Verified', 'automation-web-platform' ),
				'sectionCore'                       => esc_html__( 'Core', 'automation-web-platform' ),
				'sectionEngagement'                 => __( 'Engagement & Retention', 'automation-web-platform' ),
				'sectionAuth'                       => __( 'Authentication & User Management', 'automation-web-platform' ),
				'featTrackingTitle'                 => esc_html__( 'Unique Message IDs', 'automation-web-platform' ),
				'featTrackingDesc'                  => __( 'Assign a unique tracking ID to every message sent for easy identification, better deliverability, and precise activity tracing.', 'automation-web-platform' ),
				'featEmailTrackingTitle'            => esc_html__( 'Email Open Tracking', 'automation-web-platform' ),
				'featEmailTrackingDesc'             => esc_html__( 'Track when users open your emails using a transparent tracking pixel. Must be enabled with user consent.', 'automation-web-platform' ),
				'featSysInfoTitle'                  => esc_html__( 'System Information', 'automation-web-platform' ),
				'featSysInfoDesc'                   => esc_html__( 'Monitor your server health and WordPress environment in real-time to ensure seamless performance for all automation tasks.', 'automation-web-platform' ),
				'featChatTitle'                     => esc_html__( 'WhatsApp Chat Button', 'automation-web-platform' ),
				'featChatDesc'                      => __( 'Engage visitors instantly by adding a floating WhatsApp button, turning casual site traffic into high-converting sales conversations.', 'automation-web-platform' ),
				'featNotifTitle'                    => esc_html__( 'Automated Notifications', 'automation-web-platform' ),
				'featNotifDesc'                     => esc_html__( 'Schedule and trigger automated alerts based on specific events to keep your customers informed and engaged without lifting a finger.', 'automation-web-platform' ),
				'featAbandonTitle'                  => esc_html__( 'Abandoned Cart Recovery', 'automation-web-platform' ),
				'featAbandonDesc'                   => esc_html__( 'Recover lost revenue automatically by sending timely WhatsApp reminders to shoppers who leave items in their cart without checking out.', 'automation-web-platform' ),
				'featCampaignTitle'                 => esc_html__( 'Bulk Campaigns', 'automation-web-platform' ),
				'featCampaignDesc'                  => esc_html__( 'Send high-impact bulk broadcasts and segmented campaigns to thousands of customers simultaneously with full performance tracking.', 'automation-web-platform' ),
				'featMultiTitle'                    => esc_html__( 'Multilingual Notifications', 'automation-web-platform' ),
				'featMultiDesc'                     => __( 'Deliver personalized messages in your customers’ native languages automatically, ensuring your brand resonates across global markets.', 'automation-web-platform' ),
				'multilingualAutomations'           => esc_html__( 'Multilingual Automations', 'automation-web-platform' ),
				'multilingualAutomationsDesc'       => esc_html__( 'Deliver notification templates automatically in the customer\'s preferred language.', 'automation-web-platform' ),
				'activateMultilingualSupport'       => esc_html__( 'Activate Multilingual Support', 'automation-web-platform' ),
				'activateMultilingualSupportDesc'   => esc_html__( 'Enable translations and localization across notifications.', 'automation-web-platform' ),
				'addTranslationLanguage'            => esc_html__( 'Add Translation Language', 'automation-web-platform' ),
				'featSubTitle'                      => esc_html__( 'WooCommerce Subscriptions', 'automation-web-platform' ),
				'featSubDesc'                       => __( 'Keep subscribers informed with automated alerts for renewal reminders, status changes, and failed payments to reduce churn.', 'automation-web-platform' ),
				'featCountryTitle'                  => esc_html__( 'Country Code Management', 'automation-web-platform' ),
				'featCountryDesc'                   => esc_html__( 'Automatically detect and validate user country codes during registration and checkout to ensure 100% accurate global messaging.', 'automation-web-platform' ),
				'featRecaptchaTitle'                => esc_html__( 'reCAPTCHA Protection', 'automation-web-platform' ),
				'featRecaptchaDesc'                 => esc_html__( 'Protect your site from bots and spam with advanced integration on all your critical forms.', 'automation-web-platform' ),
				'featLoginTitle'                    => esc_html__( 'Passwordless Login', 'automation-web-platform' ),
				'featLoginDesc'                     => esc_html__( 'Increase security and user convenience by allowing customers to log in via WhatsApp OTP instead of passwords.', 'automation-web-platform' ),
				'featSignupTitle'                   => esc_html__( 'Advanced Registration', 'automation-web-platform' ),
				'featSignupDesc'                    => esc_html__( 'Streamline user registration with a high-converting form builder and real-time phone verification.', 'automation-web-platform' ),
				'featCheckoutTitle'                 => esc_html__( 'Checkout Verification', 'automation-web-platform' ),
				'featCheckoutDesc'                  => esc_html__( 'Reduce fake orders and abandoned checkouts by verifying customer phone numbers during the payment process.', 'automation-web-platform' ),
				'featPagesTitle'                    => esc_html__( 'Custom Auth Pages', 'automation-web-platform' ),
				'featPagesDesc'                     => __( 'Design beautiful, fully branded login and registration pages that offer a seamless experience for your members.', 'automation-web-platform' ),
				'dashboard'                         => esc_html__( 'Dashboard', 'automation-web-platform' ),
				'userJourney'                       => esc_html__( 'User Journey', 'automation-web-platform' ),
				'general'                           => esc_html__( 'General', 'automation-web-platform' ),
				'generalSettings'                   => esc_html__( 'General Settings', 'automation-web-platform' ),
				'messagingTools'                    => esc_html__( 'Messaging Tools', 'automation-web-platform' ),
				'subscription'                      => esc_html__( 'Subscription', 'automation-web-platform' ),
				'systemInfo'                        => esc_html__( 'System Status', 'automation-web-platform' ),
				'phoneField'                        => esc_html__( 'Phone Field', 'automation-web-platform' ),
				'countryCode'                       => esc_html__( 'Country Code', 'automation-web-platform' ),
				'authPages'                         => esc_html__( 'Auth Pages', 'automation-web-platform' ),
				'recaptcha'                         => esc_html__( 'Google reCAPTCHA', 'automation-web-platform' ),
				'ordersStatus'                      => __( 'Orders & status', 'automation-web-platform' ),
				'senderSettings'                    => esc_html__( 'Sender Settings', 'automation-web-platform' ),
				'waWeb'                             => esc_html__( 'WhatsApp Web', 'automation-web-platform' ),
				'metaApi'                           => esc_html__( 'Meta API', 'automation-web-platform' ),
				'smtpServer'                        => esc_html__( 'SMTP Server', 'automation-web-platform' ),
				'firebaseOtp'                       => esc_html__( 'Firebase OTP', 'automation-web-platform' ),
				'Otp'                               => esc_html__( 'OTP', 'automation-web-platform' ),
				'blockManager'                      => esc_html__( 'Block Manager', 'automation-web-platform' ),
				'activityHub'                       => esc_html__( 'Activity Hub', 'automation-web-platform' ),
				'abandonedCartsTitle'               => esc_html__( 'Abandoned Carts', 'automation-web-platform' ),
				'sessions'                          => esc_html__( 'Sessions', 'automation-web-platform' ),
				'cartSettings'                      => esc_html__( 'Settings', 'automation-web-platform' ),
				'acartSettings'                     => esc_html__( 'ACart Settings', 'automation-web-platform' ),
				'engagement'                        => esc_html__( 'Engagement', 'automation-web-platform' ),
				'whatsappChat'                      => esc_html__( 'WhatsApp Chat', 'automation-web-platform' ),
				'automatedNotif'                    => esc_html__( 'Automated Notif', 'automation-web-platform' ),
				'bulkCampaigns'                     => esc_html__( 'Bulk Campaigns', 'automation-web-platform' ),
				'authentications'                   => esc_html__( 'Authentications', 'automation-web-platform' ),
				'passwordlessLogin'                 => esc_html__( 'Passwordless Login', 'automation-web-platform' ),
				'registrationForm'                  => esc_html__( 'Registration Form', 'automation-web-platform' ),
				'checkoutVerif'                     => esc_html__( 'Checkout Verification', 'automation-web-platform' ),
				'resources'                         => esc_html__( 'Resources', 'automation-web-platform' ),
				'setupWizard'                       => esc_html__( 'Setup Wizard', 'automation-web-platform' ),
				'documentation'                     => esc_html__( 'Documentation', 'automation-web-platform' ),
				'placeholders'                      => esc_html__( 'Placeholders', 'automation-web-platform' ),
				'community'                         => esc_html__( 'Community', 'automation-web-platform' ),
				'shortcodes'                        => esc_html__( 'Shortcodes', 'automation-web-platform' ),
				'search'                            => esc_html__( 'Search features...', 'automation-web-platform' ),
				'askAi'                             => esc_html__( 'Ask AI', 'automation-web-platform' ),
				'aiAssistantTitle'                  => esc_html__( 'Wawp Co-Pilot', 'automation-web-platform' ),
				'aiWelcomeMessage'                  => esc_html__( 'Hello! I am your Wawp AI Guide. I have access to your current settings, system status, and configurations. How can I help you optimize your automation today?', 'automation-web-platform' ),
				'aiAssistantSubtitle'               => esc_html__( 'Live Context-Aware Assistant', 'automation-web-platform' ),
				'aiChatHistory'                     => esc_html__( 'Chat History', 'automation-web-platform' ),
				'aiChatHistoryDesc'                 => esc_html__( 'Access and manage your past AI conversations.', 'automation-web-platform' ),
				'aiSettings'                        => esc_html__( 'AI Settings', 'automation-web-platform' ),
				'aiSettingsCenter'                  => esc_html__( 'AI Settings Center', 'automation-web-platform' ),
				'aiSettingsCenterDesc'              => esc_html__( 'Integrate next-generation AI agents and high-performance models.', 'automation-web-platform' ),
				'aiExitToChat'                      => esc_html__( 'Exit to Chat', 'automation-web-platform' ),
				'aiInitializingCenter'              => esc_html__( 'Initializing AI Center...', 'automation-web-platform' ),
				'aiLegacyFreeModeActive'            => esc_html__( 'Legacy Free Mode Active', 'automation-web-platform' ),
				'aiLegacyFreeModeDesc'              => esc_html__( 'You are currently using shared resources. For GPT-5.5 performance and extended reasoning, connect a premium provider.', 'automation-web-platform' ),
				'aiQuickSet'                        => esc_html__( 'Quick Set:', 'automation-web-platform' ),
				'aiInfrastructure'                  => esc_html__( 'AI INFRASTRUCTURE', 'automation-web-platform' ),
				'aiEliteProviders'                  => esc_html__( 'ELITE PROVIDERS', 'automation-web-platform' ),
				'aiApiKey'                          => esc_html__( 'API Key', 'automation-web-platform' ),
				'aiPreferredModel'                  => esc_html__( 'Preferred Model', 'automation-web-platform' ),
				'aiTestConnectionDesc'              => esc_html__( 'Test connection with the provided credentials.', 'automation-web-platform' ),
				'aiTestConnectionBtn'               => esc_html__( 'Test Connection', 'automation-web-platform' ),
				'aiSecurityProtocol'                => esc_html__( 'AI Security Protocol', 'automation-web-platform' ),
				'aiSecurityProtocolDesc'            => esc_html__( 'Standard encryption at rest. Keys never leave your WordPress environment. 100% direct server-to-provider communication.', 'automation-web-platform' ),
				'aiSaveConfiguration'               => esc_html__( 'Save Configuration', 'automation-web-platform' ),
				'aiEngineSynced'                    => esc_html__( 'Engine Synced', 'automation-web-platform' ),
				'aiSyncFailure'                     => esc_html__( 'Sync Failure', 'automation-web-platform' ),
				'aiNoChats'                         => esc_html__( 'No previous chats.', 'automation-web-platform' ),
				'searchTitle'                       => esc_html__( 'Global OmniSearch', 'automation-web-platform' ),
				'searchSubtitle'                    => esc_html__( 'Search users, orders, and features', 'automation-web-platform' ),
				'searchPlaceholder'                 => esc_html__( 'Search users, orders, products, features...', 'automation-web-platform' ),
				'filterSources'                     => esc_html__( 'Filter Sources', 'automation-web-platform' ),
				'recentSearches'                    => esc_html__( 'Recent Searches', 'automation-web-platform' ),
				'searchResults'                     => esc_html__( 'Search Results', 'automation-web-platform' ),
				'noResultsFound'                    => esc_html__( 'No results found for', 'automation-web-platform' ),
				'toSelect'                          => esc_html__( 'to select', 'automation-web-platform' ),
				'toNavigate'                        => esc_html__( 'to navigate', 'automation-web-platform' ),
				'quickSearch'                       => esc_html__( 'Quick Search', 'automation-web-platform' ),
				'matches'                           => esc_html__( 'Matches', 'automation-web-platform' ),
				'searchMore'                        => esc_html__( 'more', 'automation-web-platform' ),
				'directSettingsLinks'               => esc_html__( 'Direct Settings Links', 'automation-web-platform' ),
				'tryTogglingFilters'                => esc_html__( 'Try toggling filters or checking your keywords.', 'automation-web-platform' ),
				'sourcePlugin'                      => esc_html__( 'Wawp Plugin', 'automation-web-platform' ),
				'sourceUsers'                       => esc_html__( 'Users', 'automation-web-platform' ),
				'sourceOrders'                      => esc_html__( 'Orders', 'automation-web-platform' ),
				'sourceProducts'                    => esc_html__( 'Products', 'automation-web-platform' ),
				'sourceSubscriptions'               => esc_html__( 'Subscriptions', 'automation-web-platform' ),
				'sourceCoupons'                     => esc_html__( 'Coupons', 'automation-web-platform' ),
				'sourceCampaigns'                   => esc_html__( 'Campaigns', 'automation-web-platform' ),
				'sourceRules'                       => esc_html__( 'Rules', 'automation-web-platform' ),
				'sourcePosts'                       => esc_html__( 'Posts', 'automation-web-platform' ),
				'sourcePages'                       => esc_html__( 'Pages', 'automation-web-platform' ),
				'sourceMedia'                       => esc_html__( 'Media', 'automation-web-platform' ),
				'sourceCategories'                  => esc_html__( 'Categories', 'automation-web-platform' ),
				'groupPlugin'                       => __( 'Wawp Pages & Settings', 'automation-web-platform' ),
				'groupUsers'                        => esc_html__( 'Registered Users', 'automation-web-platform' ),
				'groupOrders'                       => esc_html__( 'WooCommerce Orders', 'automation-web-platform' ),
				'groupProducts'                     => esc_html__( 'WooCommerce Products', 'automation-web-platform' ),
				'groupSubscriptions'                => esc_html__( 'WooCommerce Subscriptions', 'automation-web-platform' ),
				'groupCoupons'                      => esc_html__( 'WooCommerce Coupons', 'automation-web-platform' ),
				'groupCampaigns'                    => esc_html__( 'Broadcast Campaigns', 'automation-web-platform' ),
				'groupRules'                        => esc_html__( 'Notification Rules', 'automation-web-platform' ),
				'groupPosts'                        => esc_html__( 'WordPress Posts', 'automation-web-platform' ),
				'groupPages'                        => esc_html__( 'WordPress Pages', 'automation-web-platform' ),
				'groupMedia'                        => esc_html__( 'Media Library', 'automation-web-platform' ),
				'groupCategories'                   => __( 'Categories & Tags', 'automation-web-platform' ),
				'searchAll'                         => esc_html__( 'All', 'automation-web-platform' ),
				'searchClear'                       => esc_html__( 'Clear', 'automation-web-platform' ),
				'omniSearchDiscovery'               => esc_html__( 'OmniSearch Discovery', 'automation-web-platform' ),
				'omniSearchDiscoveryDesc'           => esc_html__( 'Search across your entire platform, commerce, and users in real-time.', 'automation-web-platform' ),
				'senderSettingsDesc'                => esc_html__( 'Manage WhatsApp, Email, and Meta API sending instances.', 'automation-web-platform' ),
				'waWebDesc'                         => esc_html__( 'Connect and manage WhatsApp Web automation instances.', 'automation-web-platform' ),
				'metaApiDesc'                       => esc_html__( 'Official WhatsApp Business API integration via Meta.', 'automation-web-platform' ),
				'smtpServerDesc'                    => esc_html__( 'Configure custom SMTP or mail servers for email notifications.', 'automation-web-platform' ),
				'firebaseOtpDesc'                   => esc_html__( 'Configure Firebase for secure SMS/OTP authentication.', 'automation-web-platform' ),
				'subscriptionDesc'                  => esc_html__( 'Manage your plan and license status.', 'automation-web-platform' ),
				'blockManagerDesc'                  => esc_html__( 'Manage blocked numbers and spam prevention rules.', 'automation-web-platform' ),
				'wooMissingTitle'                   => esc_html__( 'WooCommerce Required', 'automation-web-platform' ),
				'wooMissingNotice'                  => esc_html__( 'To enable Order Notifications and Checkout Verification, WooCommerce must be installed and active.', 'automation-web-platform' ),
				'wooActivate'                       => esc_html__( 'Activate WooCommerce', 'automation-web-platform' ),
				'wooInstall'                        => esc_html__( 'Install WooCommerce', 'automation-web-platform' ),
				'badgeRequired'                     => esc_html__( 'Required', 'automation-web-platform' ),
				'waOfflineTitle'                    => esc_html__( 'WhatsApp is Disconnected', 'automation-web-platform' ),
				'waOfflineNotice'                   => esc_html__( 'WhatsApp is enabled but offline. Connect your number to start using WhatsApp features.', 'automation-web-platform' ),
				'waOfflineBtn'                      => esc_html__( 'Connect Number', 'automation-web-platform' ),
				'badgeOffline'                      => esc_html__( 'Offline', 'automation-web-platform' ),
				'firebasePendingTitle'              => esc_html__( 'Firebase SMS Pending Setup', 'automation-web-platform' ),
				'firebasePendingNotice'             => esc_html__( 'Firebase SMS is enabled but not configured. Complete setup to start sending SMS.', 'automation-web-platform' ),
				'firebasePendingBtn'                => esc_html__( 'Configure Firebase', 'automation-web-platform' ),
				'badgeSetupRequired'                => esc_html__( 'Setup Required', 'automation-web-platform' ),
				'smtpPendingTitle'                  => esc_html__( 'SMTP Server Pending Setup', 'automation-web-platform' ),
				'smtpPendingNotice'                 => esc_html__( 'SMTP is enabled but no active mail server is configured. Set up SMTP to send emails.', 'automation-web-platform' ),
				'smtpPendingBtn'                    => esc_html__( 'Configure SMTP', 'automation-web-platform' ),
				'badgeUpdate'                       => esc_html__( 'Update', 'automation-web-platform' ),
				'systemCronTitle'                   => esc_html__( 'Automated Tasks Need Attention', 'automation-web-platform' ),
				'systemCronNotice'                  => esc_html__( 'A problem was detected with the scheduled tasks (Cron) system. Please visit the System Infrastructure page and use the "Auto Fix" button to ensure automation works correctly.', 'automation-web-platform' ),
				'systemRepairBtn'                   => __( 'View Details & Repair', 'automation-web-platform' ),
				'badgeIssueFound'                   => esc_html__( 'Issue Found', 'automation-web-platform' ),
				'systemDbTitle'                     => esc_html__( 'Database Tables Need Attention', 'automation-web-platform' ),
				'systemDbNotice'                    => esc_html__( 'Missing or corrupted database tables were detected. Please visit the System Infrastructure page and use the "Auto Fix" button to avoid data loss or feature failure.', 'automation-web-platform' ),
				'blockedTitle'                      => esc_html__( 'Site Blocked', 'automation-web-platform' ),
				// translators: %s: site domain name.
				'blockedDesc'                       => esc_html__( 'This domain (%s) has been blocked for violating our Terms of Service.', 'automation-web-platform' ),
				'blockedSuspended'                  => esc_html__( 'All automation and messaging features are suspended. Please review our usage policies or contact our support team.', 'automation-web-platform' ),
				'btnTerms'                          => esc_html__( 'Terms of Services', 'automation-web-platform' ),
				'btnContactSupport'                 => esc_html__( 'Contact Wawp Support', 'automation-web-platform' ),
				'prohibitedActivities'              => esc_html__( 'Prohibited Activities', 'automation-web-platform' ),
				'prohibitedDesc'                    => esc_html__( 'We prohibit spamming, scamming, unauthorized bulk messaging, and unlicensed distribution. If you believe this is a mistake, contact our billing/security team.', 'automation-web-platform' ),
				'overloadTitle'                     => esc_html__( 'Site Limit Reached', 'automation-web-platform' ),
				'overloadDesc'                      => esc_html__( 'Your free account allows using this plugin on one site only. This site has exceeded that limit.', 'automation-web-platform' ),
				'overloadSwitch'                    => esc_html__( 'To use the plugin here, either upgrade to a paid plan or switch to the free WordPress.org version which has no site restrictions.', 'automation-web-platform' ),
				'btnFreeVersion'                    => esc_html__( 'Use Free Version (WordPress.org)', 'automation-web-platform' ),
				'whyHappening'                      => esc_html__( 'Why is this happening?', 'automation-web-platform' ),
				'overloadReason'                    => esc_html__( 'Your Wawp account is on the Free Plan, which supports activation on 1 site. All admin sections of this plugin are locked until the site limit is resolved.', 'automation-web-platform' ),
				'proRequiredTitle'                  => esc_html__( 'Pro Subscription Required', 'automation-web-platform' ),
				'proRequiredDesc'                   => esc_html__( 'This feature is exclusively available for active Pro Subscription plans.', 'automation-web-platform' ),
				'proRequiredExpired'                => esc_html__( 'Your current subscription is Free or has expired. Upgrade your plan today to unlock this and many other premium automation features.', 'automation-web-platform' ),
				'btnManageSubscription'             => esc_html__( 'Manage Subscription', 'automation-web-platform' ),
				'proIncluded'                       => esc_html__( 'What is included in Pro?', 'automation-web-platform' ),
				'proIncludedDesc'                   => esc_html__( 'Access to premium sending channels (Meta API, Firebase OTP), Bulk Broadcast Campaigns, Abandoned Cart recovery automation, Real-time Activity Logs, drag-and-drop Email Builder, and priority support.', 'automation-web-platform' ),
				'notActiveTitle'                    => esc_html__( 'Site Not Active', 'automation-web-platform' ),
				'notActiveDesc'                     => esc_html__( 'This site is inactive or you have no active subscription. Check our plans to activate more sites.', 'automation-web-platform' ),
				'checkProhibitedUses'               => esc_html__( 'Check Prohibited Uses at:', 'automation-web-platform' ),
				'btnPricing'                        => esc_html__( 'Pricing', 'automation-web-platform' ),
				// Global Personalization Dialog Keys (Available for Notifications, Campaigns, and Chat).
				'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'          => __( 'WooCommerce Items & Products', 'automation-web-platform' ),
				'woocommerceBillingShipping'        => __( 'WooCommerce Billing & Shipping', 'automation-web-platform' ),
				'woocommerceSubscriptions'          => esc_html__( 'WooCommerce Subscriptions', 'automation-web-platform' ),
				// Global AI QA Spam Checker Keys.
				'antiBanCompliance'                 => __( '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'                 => __( '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'                       => __( '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'               => __( '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' ),
				'videoPlaceholder'                  => esc_html__( 'Video Placeholder', 'automation-web-platform' ),
				'pdfDocumentPreview'                => esc_html__( 'PDF Document Preview', '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' ),
				'greetingsLabel'                    => esc_html__( 'Greetings', 'automation-web-platform' ),
				'smartGreetingsLabel'               => esc_html__( 'Smart Greetings', 'automation-web-platform' ),
				'noImageLabel'                      => esc_html__( 'No Image', 'automation-web-platform' ),
				'noImageDesc'                       => esc_html__( 'Text-only', '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' ),
				'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' ),
				// translators: %s: Search query.
				'noResultsForLang'                  => esc_html__( 'No results found for "%s"', 'automation-web-platform' ),
				'cancel'                            => esc_html__( 'Cancel', 'automation-web-platform' ),
				'failedFetchTemplates'              => esc_html__( 'Failed to fetch templates', 'automation-web-platform' ),
				'connectionError'                   => esc_html__( 'Connection error', 'automation-web-platform' ),
				'failedLoadTemplate'                => esc_html__( 'Failed to load template', 'automation-web-platform' ),
				'confirmDeleteTemplate'             => esc_html__( 'Are you sure you want to delete this template?', 'automation-web-platform' ),
				'templateDeleted'                   => esc_html__( 'Template deleted', 'automation-web-platform' ),
				'deleteFailed'                      => esc_html__( 'Delete failed', 'automation-web-platform' ),
				'pleaseEnterTemplateName'           => esc_html__( 'Please enter a template name', 'automation-web-platform' ),
				'templateSavedSuccess'              => esc_html__( 'Template saved successfully', 'automation-web-platform' ),
				'saveFailed'                        => esc_html__( 'Save failed', 'automation-web-platform' ),
				'recipientEmailRequired'            => esc_html__( 'Recipient email address is required', 'automation-web-platform' ),
				'testEmailSent'                     => esc_html__( 'Test email sent', 'automation-web-platform' ),
				'failedSendTestEmail'               => esc_html__( 'Failed to send test email', 'automation-web-platform' ),
				'templateExportedSuccess'           => esc_html__( 'Template exported successfully', 'automation-web-platform' ),
				'templateImportedSuccess'           => esc_html__( 'Template imported successfully', 'automation-web-platform' ),
				'invalidTemplateFormat'             => esc_html__( 'Invalid template file format', 'automation-web-platform' ),
				'errorReadingTemplateFile'          => esc_html__( 'Error reading template file: ', 'automation-web-platform' ),
				'emailTemplatesTitle'               => esc_html__( 'Email Templates', 'automation-web-platform' ),
				'emailTemplatesSectionDesc'         => esc_html__( 'Manage your reusable email designs', 'automation-web-platform' ),
				'savingLabel'                       => esc_html__( 'Saving...', 'automation-web-platform' ),
				'saveChangesLabel'                  => esc_html__( 'Save Changes', 'automation-web-platform' ),
				'savedEmailDesignsTitle'            => esc_html__( 'Saved Email Designs', 'automation-web-platform' ),
				'savedEmailDesignsDesc'             => esc_html__( 'A library of your custom email templates ready for campaign use.', 'automation-web-platform' ),
				'importLabel'                       => esc_html__( 'Import', 'automation-web-platform' ),
				'newTemplateLabel'                  => esc_html__( 'New Template', 'automation-web-platform' ),
				'syncingTemplates'                  => esc_html__( 'Syncing your templates...', 'automation-web-platform' ),
				'noTemplatesYet'                    => esc_html__( 'No templates yet', 'automation-web-platform' ),
				'clickNewTemplateToStart'           => esc_html__( 'Click the "New Template" button to get started.', 'automation-web-platform' ),
				// translators: %s: Template update date.
				'updatedLabel'                      => esc_html__( 'Updated %s', 'automation-web-platform' ),
				'exportTemplateLabel'               => esc_html__( 'Export Template', 'automation-web-platform' ),
				'deleteBtnLabel'                    => esc_html__( 'Delete', 'automation-web-platform' ),
				'editTemplateLabel'                 => esc_html__( 'Edit Template', 'automation-web-platform' ),
				'emailDomainSuggestionsTitle'       => esc_html__( 'Email Domain Suggestions', 'automation-web-platform' ),
				'emailDomainSuggestionsDesc'        => esc_html__( 'Manage the list of domains shown in the email autocomplete suggestions across your forms.', 'automation-web-platform' ),
				'emailDomainsPlaceholder'           => esc_html__( 'gmail.com, yahoo.com, outlook.com...', 'automation-web-platform' ),
				'emailDomainsNote'                  => esc_html__( 'Note: Separate domains with commas. These will appear as suggestions when users start typing their email.', 'automation-web-platform' ),
				// Consolidated Firebase & WhatsApp unified settings page keys.
				'firebase_sms_auth_title'           => esc_html__( 'Firebase SMS Authentication', 'automation-web-platform' ),
				'firebase_sms_auth_desc'            => esc_html__( 'Sends secure verification codes globally via Google Firebase SMS gateway. Highly recommended for robust and global phone verification.', 'automation-web-platform' ),
				'firebase_sms_external_desc'        => esc_html__( 'Firebase SMS messages are handled externally. To modify templates or manage costs, please visit your Firebase control panel.', 'automation-web-platform' ),
				'firebase_tpl_label'                => esc_html__( 'Manage Firebase SMS Templates', 'automation-web-platform' ),
				'open_firebase_console'             => esc_html__( 'Open Firebase Console', 'automation-web-platform' ),
				'firebase_active_ready'             => esc_html__( 'Firebase Account found. System is ready to route messages through Google gateway.', 'automation-web-platform' ),
				'firebase_config_missing_error'     => __( '<b>Firebase is not configured!</b> Please visit the Firebase Settings tab first.', 'automation-web-platform' ),
				'whatsapp_web_auth_title'           => esc_html__( 'WhatsApp Web Authentication', 'automation-web-platform' ),
				'whatsapp_web_auth_desc'            => esc_html__( 'Users will see the login field with WhatsApp/Phone by default. Highly recommended for mobile-first audiences.', 'automation-web-platform' ),
				'email_magic_link_title'            => esc_html__( 'Email Magic Link Login', 'automation-web-platform' ),
				'email_magic_link_desc'             => esc_html__( 'Users receive a secure, one-click authorization link directly to their inbox. Highly recommended for a passwordless, hassle-free desktop experience.', 'automation-web-platform' ),
				'checkout_active'                   => esc_html__( 'Checkout verification is active', 'automation-web-platform' ),
				// translators: %s: Verification method name (e.g. WhatsApp Web Authentication).
				'checkout_method_status'            => __( 'Secure payment flow is enabled. Users are required to verify via %s before completing their order.', 'automation-web-platform' ),
				'auth_portal_active'                => esc_html__( 'Authentication portal is active', 'automation-web-platform' ),
				// translators: %s: Verification method name (e.g. WhatsApp Web Authentication).
				'auth_method_status'                => __( 'Passwordless authentication is enabled. Users authenticate and access their accounts via %s by default.', 'automation-web-platform' ),
				'ab_verification_active'            => esc_html__( 'Recovery verification is active', 'automation-web-platform' ),
				// translators: %s: Verification method name (e.g. WhatsApp Web Authentication).
				'ab_verification_method_status'     => __( 'Secure recovery process is enabled. Shoppers verify their identity via %s before retrieving their abandoned carts.', 'automation-web-platform' ),
				'signup_active'                     => esc_html__( 'User registration portal is active', 'automation-web-platform' ),
				'signup_inactive'                   => esc_html__( 'User registration portal is disabled', 'automation-web-platform' ),
				// translators: %s: Verification method name (e.g. WhatsApp Web Authentication).
				'signup_method'                     => __( 'Advanced customer registration is enabled. New users verify their accounts via %s before completing signup.', 'automation-web-platform' ),
				'chooseWaSender'                    => esc_html__( 'Choose WhatsApp Sender', 'automation-web-platform' ),
				'chooseWaSenderDesc'                => esc_html__( 'Select the WhatsApp number that will be used to send messages for this feature.', 'automation-web-platform' ),
				'preferredChannel'                  => esc_html__( 'Preferred Verification Channel', 'automation-web-platform' ),
				'msg_config_label'                  => esc_html__( 'Message Configuration', 'automation-web-platform' ),
				'force_lang_label'                  => esc_html__( 'Force Language', 'automation-web-platform' ),
				'enable_custom_footer_label'        => esc_html__( 'Enable Custom Footer', 'automation-web-platform' ),
				'list_ui_label'                     => esc_html__( 'List Interface Design', 'automation-web-platform' ),
				// Setup Wizard translations.
				'wizardStep2Title'                  => esc_html__( 'Account Linked', 'automation-web-platform' ),
				'wizardStep3Title'                  => __( 'Sync & Channels', 'automation-web-platform' ),
				'wizardStep4Title'                  => esc_html__( 'Final Diagnostics', 'automation-web-platform' ),
				'wizardStep5Title'                  => esc_html__( 'Choose Configuration Path', 'automation-web-platform' ),
				'wizardStep6Title'                  => esc_html__( 'Congratulations! Setup Finalized', 'automation-web-platform' ),
				'wizardStep2Desc'                   => esc_html__( 'Your Wawp account is successfully connected.', 'automation-web-platform' ),
				'wizardStep3Desc'                   => esc_html__( 'Ensure your whatsapp and email channels are performing optimally.', 'automation-web-platform' ),
				'wizardStep4Desc'                   => esc_html__( 'Verify system database and cron jobs status before launch.', 'automation-web-platform' ),
				'wizardStep5Desc'                   => esc_html__( 'Select how you would like to set up Wawp: migrate, configure new or start empty.', 'automation-web-platform' ),
				'wizardStep6Desc'                   => esc_html__( 'Your Wawp dashboard is ready to go and send.', 'automation-web-platform' ),
				// translators: %1$d: Current wizard step, %2$d: Total wizard steps.
				'wizardStepsProgress'               => esc_html__( 'Step %1$d of %2$d', 'automation-web-platform' ),
				'wizardSetupFast'                   => esc_html__( 'Designed to get you ready for sending in less than a minute', 'automation-web-platform' ),
				'wizardActiveConnection'            => esc_html__( 'Active Connection', 'automation-web-platform' ),
				'wizardSyncStatus'                  => esc_html__( 'Sync Status', 'automation-web-platform' ),
				'wizardRefreshing'                  => esc_html__( 'Refreshing...', 'automation-web-platform' ),
				'wizardDisconnect'                  => esc_html__( 'Disconnect', 'automation-web-platform' ),
				'wizardFullAccountSettings'         => esc_html__( 'Go to Full Account Settings', 'automation-web-platform' ),
				'wizardWhatsAppWebGateway'          => esc_html__( 'WhatsApp Web Gateway', 'automation-web-platform' ),
				'wizardWhatsAppWebGatewayDesc'      => esc_html__( 'Connect your personal WhatsApp number to send automated orders notifications and customer messages.', 'automation-web-platform' ),
				'wizardWhatsAppStatusOnline'        => esc_html__( 'Online', 'automation-web-platform' ),
				'wizardWhatsAppStatusScan'          => esc_html__( 'Scan QR', 'automation-web-platform' ),
				'wizardWhatsAppStatusOffline'       => esc_html__( 'Offline', 'automation-web-platform' ),
				'wizardNoWhatsAppConnected'         => esc_html__( 'No connected WhatsApp numbers', 'automation-web-platform' ),
				'wizardConnectNewNumber'            => esc_html__( 'Connect New Number', 'automation-web-platform' ),
				'wizardAdvancedWhatsAppWebSettings' => esc_html__( 'Advanced WhatsApp Web Settings', 'automation-web-platform' ),
				'wizardWordPressEmailSMTP'          => esc_html__( 'WordPress Email SMTP', 'automation-web-platform' ),
				'wizardWordPressEmailSMTPDesc'      => esc_html__( 'Configure and set the default WordPress PHP Mailer as the active automatic sender for your emails.', 'automation-web-platform' ),
				'wizardActiveConfigured'            => __( 'Active & Configured', 'automation-web-platform' ),
				'wizardActiveConfiguredDesc'        => esc_html__( 'The default WordPress PHPMailer is currently set as your active email sender.', 'automation-web-platform' ),
				'wizardMailerInactive'              => esc_html__( 'WordPress Mailer Inactive', 'automation-web-platform' ),
				'wizardMailerInactiveDesc'          => esc_html__( 'The default mailer has not been registered or set as default yet.', 'automation-web-platform' ),
				'wizardEnableMailer'                => esc_html__( 'Enable WordPress default mailer', 'automation-web-platform' ),
				'wizardAdvancedSMTP'                => esc_html__( 'Advanced SMTP Settings', 'automation-web-platform' ),
				'wizardCheckingSettings'            => esc_html__( 'Finalizing Site Setup...', 'automation-web-platform' ),
				'wizardVerifyingDatabase'           => esc_html__( 'Verifying database and cloud sync...', 'automation-web-platform' ),
				'wizardSystemCheckedIssues'         => esc_html__( 'System Checked - Issues Detected', 'automation-web-platform' ),
				'wizardSystemCheckedIssuesDesc'     => esc_html__( 'We detected some setup issues. Please click the auto-fix button below to resolve them instantly.', 'automation-web-platform' ),
				'wizardEverythingReady'             => esc_html__( 'Everything is Ready!', 'automation-web-platform' ),
				'wizardEverythingReadyDesc'         => esc_html__( 'Wawp is now active and monitoring your site.', 'automation-web-platform' ),
				'wizardDatabase'                    => esc_html__( 'Database', 'automation-web-platform' ),
				'wizardDatabaseConnected'           => esc_html__( 'CONNECTED', 'automation-web-platform' ),
				'wizardDatabaseIssues'              => esc_html__( 'ISSUES', 'automation-web-platform' ),
				'wizardCronJobs'                    => esc_html__( 'Cron Jobs', 'automation-web-platform' ),
				'wizardCronScheduled'               => esc_html__( 'SCHEDULED', 'automation-web-platform' ),
				'wizardCronIssues'                  => esc_html__( 'ISSUES', 'automation-web-platform' ),
				'wizardWhatsApp'                    => esc_html__( 'WhatsApp', 'automation-web-platform' ),
				'wizardWhatsAppStable'              => esc_html__( 'STABLE', 'automation-web-platform' ),
				'wizardWhatsAppOffline'             => esc_html__( 'OFFLINE', 'automation-web-platform' ),
				'wizardAutoFixIssues'               => esc_html__( 'Auto Fix Issues', 'automation-web-platform' ),
				'wizardViewDetailedSystemInfo'      => esc_html__( 'View Detailed System Info', 'automation-web-platform' ),
				'wizardPathChoose'                  => esc_html__( 'Choose Configuration Path', 'automation-web-platform' ),
				'wizardPathChooseDesc'              => esc_html__( 'Select how you would like to set up Wawp: migrate your existing legacy configurations or start clean.', 'automation-web-platform' ),
				'wizardMigrateTitle'                => esc_html__( 'Migrate from Previous Version', 'automation-web-platform' ),
				'wizardMigrateDesc'                 => esc_html__( 'Sync users and automatically migrate legacy signup forms and notification rules.', 'automation-web-platform' ),
				'wizardConfigureNewTitle'           => esc_html__( 'Configure as New', 'automation-web-platform' ),
				'wizardConfigureNewDesc'            => esc_html__( 'Start with a clean sheet without copying any previous settings to start fresh.', 'automation-web-platform' ),
				'wizardStartScratchTitle'           => esc_html__( 'Start from Scratch', 'automation-web-platform' ),
				'wizardStartScratchDesc'            => esc_html__( 'Start with a clean slate to manually configure all channels and options.', 'automation-web-platform' ),
				'wizardGoToNotifications'           => esc_html__( 'Go to Automated Notifications Page', 'automation-web-platform' ),
				'wizardMigrationChecklist'          => esc_html__( 'Migration Checklist', 'automation-web-platform' ),
				'wizardSyncUsers'                   => esc_html__( 'Sync Users Data', 'automation-web-platform' ),
				'wizardLegacyDataMigration'         => esc_html__( 'Legacy Data Migration', 'automation-web-platform' ),
				'wizardNotificationsMigration'      => esc_html__( 'System Notifications Migration', 'automation-web-platform' ),
				'wizardChecklistSuccess'            => esc_html__( 'Success', 'automation-web-platform' ),
				'wizardChecklistFailed'             => esc_html__( 'Failed', 'automation-web-platform' ),
				'wizardChecklistMigrating'          => esc_html__( 'Migrating...', 'automation-web-platform' ),
				'wizardChecklistPending'            => esc_html__( 'Pending', 'automation-web-platform' ),
				'wizardStartMigrationBtn'           => esc_html__( 'Start Data Migration', 'automation-web-platform' ),
				'wizardAllMigratedSuccess'          => esc_html__( 'All systems migrated successfully!', 'automation-web-platform' ),
				'wizardAdvancedChecklist'           => esc_html__( 'Advanced Setup Checklist', 'automation-web-platform' ),
				'wizardImportDefaultTemplates'      => esc_html__( 'Import Default Email SMTP Templates', 'automation-web-platform' ),
				'wizardImportDefaultTemplatesDesc'  => esc_html__( 'Preload rich predefined email templates from wawp-email-templates.json', 'automation-web-platform' ),
				'wizardConfigureEnglishNotifs'      => esc_html__( 'Configure Custom English Automated Notifications', 'automation-web-platform' ),
				'wizardConfigureEnglishNotifsDesc'  => __( 'WhatsApp Web & Email alerts for users and admin (Login, Register & WooCommerce)', 'automation-web-platform' ),
				'wizardStartImportBtn'              => __( 'Start Importing Default Channels & Setup', 'automation-web-platform' ),
				'wizardImportedSuccess'             => esc_html__( 'Congratulations! Predefined configurations have been imported successfully!', 'automation-web-platform' ),
				'wizardImportedSuccessDesc'         => esc_html__( 'Login, signup, and WooCommerce order processing triggers are now fully active and ready to send.', 'automation-web-platform' ),
				'wizardSuccessTitle'                => esc_html__( 'You are on the first step of success! 🎉', 'automation-web-platform' ),
				'wizardSuccessDesc'                 => esc_html__( 'Congratulations! Site setup is successfully finalized. Your site is now fully equipped to automate smart notifications and engage your customers.', 'automation-web-platform' ),
				'wizardGoToDashboard'               => esc_html__( 'Go to Dashboard', 'automation-web-platform' ),
				'wizardHelpText'                    => esc_html__( 'If you need any help, please visit help.wawp.net/en', 'automation-web-platform' ),
				'wizardPrevious'                    => esc_html__( 'Previous', 'automation-web-platform' ),
				'wizardNextStep'                    => esc_html__( 'Next Step', 'automation-web-platform' ),
				'toastImportSuccess'                => esc_html__( 'All configurations imported successfully!', 'automation-web-platform' ),
				'toastImportFailed'                 => esc_html__( 'Failed to import automated notifications.', 'automation-web-platform' ),
				'toastImportError'                  => esc_html__( 'An unexpected error occurred during notifications import.', 'automation-web-platform' ),
				'toastMailerEnabled'                => esc_html__( 'WordPress Mailer enabled successfully', 'automation-web-platform' ),
				'toastRepairSuccess'                => esc_html__( 'System issues repaired successfully', 'automation-web-platform' ),
				'toastRepairFailed'                 => esc_html__( 'Auto-repair failed', 'automation-web-platform' ),
				'toastRepairError'                  => esc_html__( 'An error occurred during auto-repair', 'automation-web-platform' ),
				'wizardGetStartedForFree'           => esc_html__( 'Get Started for Free', 'automation-web-platform' ),
				'wizardGetStartedForFreeDesc'       => esc_html__( 'Connect your WordPress site with WAWP to unlock premium automation features.', 'automation-web-platform' ),
				'wizardConnectYourAccount'          => esc_html__( 'Connect Your Account', 'automation-web-platform' ),
				'wizardConnectYourAccountDesc'      => esc_html__( 'Securely authenticate with Wawp to unlock synchronization.', 'automation-web-platform' ),
				'wizardAuthenticateNow'             => esc_html__( 'Authenticate Now', 'automation-web-platform' ),
				'wizardContinueSetup'               => esc_html__( 'Continue Setup', 'automation-web-platform' ),
				'wizardNeedNewAccount'              => esc_html__( 'Need a new account?', 'automation-web-platform' ),
				'wizardCreateAccount'               => esc_html__( 'Create account', 'automation-web-platform' ),
				'wizardTerms'                       => esc_html__( 'Terms', 'automation-web-platform' ),
				'wizardPrivacy'                     => esc_html__( 'Privacy', 'automation-web-platform' ),
				'featWhatsAppWebSender'             => esc_html__( 'WhatsApp Web Sender', 'automation-web-platform' ),
				'featWhatsAppWebSenderDesc'         => esc_html__( 'Direct message dispatch', 'automation-web-platform' ),
				'featEmailSmtpTemplates'            => __( 'Email SMTP & Templates', 'automation-web-platform' ),
				'featEmailSmtpTemplatesDesc'        => esc_html__( 'Secure email delivery', 'automation-web-platform' ),
				'featWhatsAppChatButton'            => esc_html__( 'WhatsApp Chat Button', 'automation-web-platform' ),
				'featWhatsAppChatButtonDesc'        => esc_html__( 'Direct floating widget', 'automation-web-platform' ),
				'featRegistrationBuilder'           => esc_html__( 'Registration Builder', 'automation-web-platform' ),
				'featRegistrationBuilderDesc'       => esc_html__( 'Custom signup forms', 'automation-web-platform' ),
				'featPasswordlessOtpLogin'          => esc_html__( 'Passwordless Login', 'automation-web-platform' ),
				'featPasswordlessOtpLoginDesc'      => esc_html__( 'Secured authentication', 'automation-web-platform' ),
				'featSystemDiagnostics'             => esc_html__( 'System Status', 'automation-web-platform' ),
				'featSystemDiagnosticsDesc'         => esc_html__( 'Real-time performance', 'automation-web-platform' ),
				'featSenderManagement'              => esc_html__( 'Sender Management', 'automation-web-platform' ),
				'featSenderManagementDesc'          => esc_html__( 'Connect multiple channels', 'automation-web-platform' ),
				'featFreeMessageQuota'              => esc_html__( 'Free Message Quota', 'automation-web-platform' ),
				'featFreeMessageQuotaDesc'          => esc_html__( 'Start sending instantly', 'automation-web-platform' ),
				'featCloudSynchronization'          => esc_html__( 'Cloud Synchronization', 'automation-web-platform' ),
				'featCloudSynchronizationDesc'      => esc_html__( 'Secure data mirroring', 'automation-web-platform' ),
				'featPhoneFieldFormatting'          => esc_html__( 'Phone Field Formatting', 'automation-web-platform' ),
				'featPhoneFieldFormattingDesc'      => esc_html__( 'Automatic country codes', 'automation-web-platform' ),
				'featOrderAlertsSetup'              => __( 'Order Alerts & Setup', 'automation-web-platform' ),
				'featOrderAlertsSetupDesc'          => esc_html__( 'Instant status updates', 'automation-web-platform' ),
				'featRealtimeEntryLogs'             => esc_html__( 'Real-time Entry Logs', 'automation-web-platform' ),
				'featRealtimeEntryLogsDesc'         => esc_html__( 'Monitor message status', 'automation-web-platform' ),
			),
		);

		$data['features'] = apply_filters( 'wawp_dashboard_features', $data['features'], $user_data );

		return $data;
	}

	/**
	 * Canonical snapshot stats for the Dashboard.
	 * Uses wawp_user_info table (accurate) + transient caching.
	 */
	public static function get_snapshot_stats() {
		global $wpdb;
		$user_info_table = WAWP()->user_manager->get_table_name();

		$total_wp_users = wp_cache_get( 'wawp_total_users', 'wawp_dashboard' );
		if ( false === $total_wp_users ) {
			$total_wp_users = get_transient( 'wawp_total_users' );
			if ( false === $total_wp_users ) {
				global $wpdb;
				$total_wp_users = (int) WAWP()->db->get_results_cached( $wpdb->prepare( 'SELECT COUNT(ID) as total FROM %i', $wpdb->users ), 'wawp_total_wp_users', 'wawp_dashboard', HOUR_IN_SECONDS )[0]['total'] ?? 0;
				set_transient( 'wawp_total_users', $total_wp_users, HOUR_IN_SECONDS );
			}
			wp_cache_set( 'wawp_total_users', $total_wp_users, 'wawp_dashboard', HOUR_IN_SECONDS );
		}

		$info_stats = wp_cache_get( 'wawp_userinfo_stats', 'wawp_dashboard' );
		if ( false === $info_stats ) {
			$info_stats = get_transient( 'wawp_userinfo_stats' );
			if ( false === $info_stats ) {
				global $wpdb;
				if ( ! $user_info_table ) {
					$info_stats = array(
						'total_rows'       => 0,
						'users_with_phone' => 0,
						'verified'         => 0,
						'not_verified'     => 0,
					);
				} else {
					$results    = WAWP()->db->get_results_cached( $wpdb->prepare( "SELECT COUNT(*) as total_rows, SUM(CASE WHEN phone <> '' AND phone <> 'N/A' THEN 1 ELSE 0 END) as users_with_phone, SUM(CASE WHEN whatsapp_verified = 'Verified' THEN 1 ELSE 0 END) as verified FROM %i", $user_info_table ), 'wawp_user_info_summary', 'wawp_dashboard', 5 * MINUTE_IN_SECONDS );
					$info_stats = ! empty( $results ) ? (array) $results[0] : null;
					if ( $info_stats ) {
						$info_stats['not_verified'] = (int) ( $info_stats['users_with_phone'] ?? 0 ) - (int) ( $info_stats['verified'] ?? 0 );
					} else {
						$info_stats = array(
							'total_rows'       => 0,
							'users_with_phone' => 0,
							'verified'         => 0,
							'not_verified'     => 0,
						);
					}
				}
				set_transient( 'wawp_userinfo_stats', $info_stats, 5 * MINUTE_IN_SECONDS );
			}
			wp_cache_set( 'wawp_userinfo_stats', $info_stats, 'wawp_dashboard', 5 * MINUTE_IN_SECONDS );
		}

		$users_with_phone = (int) $info_stats['users_with_phone'];
		$total_verified   = (int) $info_stats['verified'];
		$percent_verified = $users_with_phone > 0 ? ( $total_verified / $users_with_phone ) * 100 : 0;
		$percent_added    = $total_wp_users > 0 ? ( $users_with_phone / $total_wp_users ) * 100 : 0;

		return array(
			'totalWpUsers'    => $total_wp_users,
			'usersWithPhone'  => $users_with_phone,
			'verified'        => $total_verified,
			'percentAdded'    => number_format( $percent_added, 0 ) . '%',
			'percentVerified' => number_format( $percent_verified, 0 ) . '%',
		);
	}
}
