<?php
/**
 * The admin-specific functionality of the plugin.
 *
 * @package    Cloudi7_ID_Card_Generator
 * @subpackage Cloudi7_ID_Card_Generator/admin
 */

// Prevent direct access.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Class Cloudi7_ICG_Admin
 *
 * Defines admin-side hooks for enqueuing styles / scripts and
 * registering admin menu pages. Feature methods will be added here
 * in subsequent development phases.
 */
class Cloudi7_ICG_Admin {

	/**
	 * The plugin version.
	 *
	 * @var string $version
	 */
	private $version;

	/**
	 * Initialize the class and set its properties.
	 *
	 * @param string $version The current version of the plugin.
	 */
	public function __construct( $version ) {
		$this->version = $version;

		// Database schema check/update during admin initialization
		$db_version = get_option( 'cloudi7_icg_version', '0.0.0' );
		if ( version_compare( $db_version, $this->version, '<' ) ) {
			if ( ! class_exists( 'Cloudi7_ICG_Activator' ) ) {
				require_once Cloudi7_ICG_PLUGIN_DIR . 'includes/class-cloudi7-icg-activator.php';
			}
			Cloudi7_ICG_Activator::activate();
			update_option( 'cloudi7_icg_version', $this->version );
		}
	}

	/**
	 * Register the stylesheets for the admin area.
	 *
	 * Hooked to: admin_enqueue_scripts
	 *
	 * @return void
	 */
	public function enqueue_styles() {
		wp_enqueue_style(
			'cloudi7-icg-admin',
			Cloudi7_ICG_PLUGIN_URL . 'assets/css/cloudi7-icg-admin.css',
			array(),
			$this->version,
			'all'
		);

		wp_enqueue_style(
			'cloudi7-icg-dashboard',
			Cloudi7_ICG_PLUGIN_URL . 'assets/css/admin-dashboard.css',
			array(),
			$this->version,
			'all'
		);

		wp_enqueue_style(
			'cloudi7-icg-card',
			Cloudi7_ICG_PLUGIN_URL . 'assets/css/card.css',
			array(),
			$this->version,
			'all'
		);

		wp_enqueue_style(
			'cloudi7-icg-admin-form',
			Cloudi7_ICG_PLUGIN_URL . 'assets/css/admin-form.css',
			array(),
			$this->version,
			'all'
		);

		wp_enqueue_style(
			'cloudi7-icg-card-preview',
			Cloudi7_ICG_PLUGIN_URL . 'assets/css/card-preview.css',
			array(),
			$this->version,
			'all'
		);

		wp_enqueue_style(
			'cloudi7-icg-card-design',
			Cloudi7_ICG_PLUGIN_URL . 'assets/css/card-design.css',
			array(),
			$this->version,
			'all'
		);

		wp_enqueue_style(
			'cloudi7-icg-admin-settings',
			Cloudi7_ICG_PLUGIN_URL . 'assets/css/admin-settings.css',
			array(),
			$this->version,
			'all'
		);

		// Template Specific Styles
		$cloudi7_icg_skin = get_option( 'cloudi7_icg_template_skin', 'modern' );
		wp_enqueue_style(
			'cloudi7-icg-template-style',
			Cloudi7_ICG_PLUGIN_URL . 'templates/' . $cloudi7_icg_skin . '/style.css',
			array( 'cloudi7-icg-card' ),
			$this->version,
			'all'
		);
	}

	/**
	 * Register the JavaScript for the admin area.
	 *
	 * Hooked to: admin_enqueue_scripts
	 *
	 * @return void
	 */
	public function enqueue_scripts() {
		// Enqueue WordPress media uploader.
		wp_enqueue_media();

		wp_enqueue_script(
			'cloudi7-icg-html2canvas',
			Cloudi7_ICG_PLUGIN_URL . 'assets/js/libs/html2canvas.min.js',
			array(),
			'1.4.1',
			true
		);

		wp_enqueue_script(
			'cloudi7-icg-admin',
			Cloudi7_ICG_PLUGIN_URL . 'assets/js/cloudi7-icg-admin.js',
			array( 'jquery' ),
			$this->version,
			true
		);

		wp_enqueue_script(
			'cloudi7-icg-card-actions',
			Cloudi7_ICG_PLUGIN_URL . 'assets/js/cloudi7-icg-public.js',
			array( 'jquery', 'cloudi7-icg-html2canvas' ),
			$this->version,
			true
		);

		// Localize script for AJAX or common variables if needed later.
		wp_localize_script( 'cloudi7-icg-admin', 'cloudi7_icg_vars', array(
			'nonce' => wp_create_nonce( 'cloudi7_icg_admin_nonce' ),
		));
	}

	/**
	 * Register the admin menu and submenus.
	 *
	 * Registers the top-level "ID Card Generator" menu and its associated submenus.
	 *
	 * @return void
	 */
	public function add_menu_pages() {
		add_menu_page(
			esc_html__( 'ID Card Generator', 'cloudi7-id-card-generator' ),
			esc_html__( 'ID Card Generator', 'cloudi7-id-card-generator' ),
			'manage_options',
			'cloudi7-icg-dashboard',
			array( $this, 'display_dashboard' ),
			'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyMCAyMCI+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTE4IDNoLTJDMTYuOSAzIDE2IDMuOSAxNiA1djEwYzAgMS4xLjkgMiAyIDJoMmMxLjEgMCAyLS45IDItMlY1YzAtMS4xLS45LTItMi0yem0wIDEySDRWNWgxNHYxMHpNMCA3aDRWNUgwVjd6bTAgNEg0VjlIMFYxMXptMCA0SDR2LTJIMFYxNXoiLz48L3N2Zz4=',
			99
		);

		add_submenu_page(
			'cloudi7-icg-dashboard',
			esc_html__( 'Dashboard', 'cloudi7-id-card-generator' ),
			esc_html__( 'Dashboard', 'cloudi7-id-card-generator' ),
			'manage_options',
			'cloudi7-icg-dashboard',
			array( $this, 'display_dashboard' )
		);

		add_submenu_page(
			'cloudi7-icg-dashboard',
			esc_html__( 'Create ID Card', 'cloudi7-id-card-generator' ),
			esc_html__( 'Create ID Card', 'cloudi7-id-card-generator' ),
			'manage_options',
			'cloudi7-icg-create-card',
			array( $this, 'display_create_card' )
		);

		add_submenu_page(
			'cloudi7-icg-dashboard',
			esc_html__( 'All ID Cards', 'cloudi7-id-card-generator' ),
			esc_html__( 'All ID Cards', 'cloudi7-id-card-generator' ),
			'manage_options',
			'cloudi7-icg-all-cards',
			array( $this, 'display_all_cards' )
		);

		add_submenu_page(
			'cloudi7-icg-dashboard',
			esc_html__( 'Settings', 'cloudi7-id-card-generator' ),
			esc_html__( 'Settings', 'cloudi7-id-card-generator' ),
			'manage_options',
			'cloudi7-icg-settings',
			array( $this, 'display_settings' )
		);

		add_submenu_page(
			'cloudi7-icg-dashboard',
			esc_html__( 'Applications', 'cloudi7-id-card-generator' ),
			esc_html__( 'Applications', 'cloudi7-id-card-generator' ) . ' <span class="awaiting-mod count-' . $this->get_pending_apps_count() . '"><span class="pending-count">' . $this->get_pending_apps_count() . '</span></span>',
			'manage_options',
			'cloudi7-icg-apps',
			array( $this, 'display_applications' )
		);

		add_submenu_page(
			'cloudi7-icg-dashboard',
			esc_html__( 'Templates', 'cloudi7-id-card-generator' ),
			esc_html__( 'Templates', 'cloudi7-id-card-generator' ),
			'manage_options',
			'cloudi7-icg-templates',
			array( $this, 'display_templates' )
		);
	}

	/**
	 * Handle form submissions and actions before page rendering.
	 *
	 * Listens for POST and GET requests related to card management and settings
	 * and delegates them to the appropriate processing methods.
	 *
	 * @return void
	 */
	public function handle_actions() {
		if ( ! isset( $_REQUEST['page'] ) || strpos( sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ), 'cloudi7-icg-' ) !== 0 ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
			return;
		}

		if ( isset( $_POST['cloudi7_icg_save_card'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
			$this->process_save_card();
		}

		if ( isset( $_POST['cloudi7_icg_save_settings'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
			$this->process_save_settings();
		}

		if ( isset( $_POST['cloudi7_icg_save_template'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
			$this->process_save_template();
		}

		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		if ( isset( $_GET['action'] ) && 'delete' === sanitize_text_field( wp_unslash( $_GET['action'] ) ) && isset( $_GET['id'] ) ) {
			$this->process_delete_card();
		}

		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		if ( isset( $_GET['action'] ) && 'approve_app' === sanitize_text_field( wp_unslash( $_GET['action'] ) ) && isset( $_GET['id'] ) ) {
			$this->process_approve_application();
		}

		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		if ( isset( $_GET['action'] ) && 'reject_app' === sanitize_text_field( wp_unslash( $_GET['action'] ) ) && isset( $_GET['id'] ) ) {
			$this->process_reject_application();
		}

		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		if ( isset( $_GET['action'] ) && 'delete_app' === sanitize_text_field( wp_unslash( $_GET['action'] ) ) && isset( $_GET['id'] ) ) {
			$this->process_delete_application();
		}

		// Suppress admin footer when viewing/previewing a card as requested
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		if ( isset( $_GET['page'] ) && 'cloudi7-icg-all-cards' === sanitize_text_field( wp_unslash( $_GET['page'] ) ) && isset( $_GET['action'] ) && 'view' === sanitize_text_field( wp_unslash( $_GET['action'] ) ) ) {
			add_filter( 'admin_footer_text', '__return_empty_string', 999 );
			add_filter( 'update_footer', '__return_empty_string', 999 );
		}
	}

	/**
	 * Display the Dashboard page.
	 *
	 * Renders the dashboard with card statistics and quick links.
	 *
	 * @return void
	 */
	public function display_dashboard() {
		global $wpdb;
		$cloudi7_icg_table_name = $wpdb->prefix . 'cloudi7_icg_cards';
		
		// Fetch statistics
		$cloudi7_icg_cache_key = 'cloudi7_icg_data_total_cards';
		$cloudi7_icg_total_cards = wp_cache_get( $cloudi7_icg_cache_key );
		if ( false === $cloudi7_icg_total_cards ) {
			// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
			$cloudi7_icg_total_cards = $wpdb->get_var( "SELECT COUNT(id) FROM {$wpdb->prefix}cloudi7_icg_cards" );
			wp_cache_set( $cloudi7_icg_cache_key, $cloudi7_icg_total_cards );
		}
		$cloudi7_icg_cache_key = 'cloudi7_icg_data_recent_cards';
		$cloudi7_icg_recent_cards = wp_cache_get( $cloudi7_icg_cache_key );
		if ( false === $cloudi7_icg_recent_cards ) {
			// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
			$cloudi7_icg_recent_cards = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}cloudi7_icg_cards ORDER BY created_at DESC LIMIT 5" );
			wp_cache_set( $cloudi7_icg_cache_key, $cloudi7_icg_recent_cards );
		}
		
		// Organization type counts
		$cloudi7_icg_cache_key = 'cloudi7_icg_data_org_counts';
		$cloudi7_icg_org_counts_raw = wp_cache_get( $cloudi7_icg_cache_key );
		if ( false === $cloudi7_icg_org_counts_raw ) {
			// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
			$cloudi7_icg_org_counts_raw = $wpdb->get_results( "SELECT organization_type, COUNT(*) as count FROM {$wpdb->prefix}cloudi7_icg_cards GROUP BY organization_type" );
			wp_cache_set( $cloudi7_icg_cache_key, $cloudi7_icg_org_counts_raw );
		}
		$cloudi7_icg_org_counts = array();
		foreach ( $cloudi7_icg_org_counts_raw as $cloudi7_icg_row ) {
			$cloudi7_icg_org_counts[ $cloudi7_icg_row->organization_type ] = $cloudi7_icg_row->count;
		}

		include Cloudi7_ICG_PLUGIN_DIR . 'admin/views/dashboard.php';
	}

	/**
	 * Display the Create/Edit Card page.
	 *
	 * Fetches existing card data if an 'id' is provided in the URL.
	 *
	 * @return void
	 */
	public function display_create_card() {
		global $wpdb;
		$cloudi7_icg_card = null;

		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		if ( isset( $_GET['id'] ) ) {
			$cloudi7_icg_id = intval( $_GET['id'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
			$cloudi7_icg_table_name = $wpdb->prefix . 'cloudi7_icg_cards';
			$cloudi7_icg_cache_key = 'cloudi7_icg_data_card_' . $cloudi7_icg_id;
			$cloudi7_icg_card = wp_cache_get( $cloudi7_icg_cache_key );
			if ( false === $cloudi7_icg_card ) {
				// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
				$cloudi7_icg_card = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}cloudi7_icg_cards WHERE id = %d", $cloudi7_icg_id ) );
				wp_cache_set( $cloudi7_icg_cache_key, $cloudi7_icg_card );
			}
		}

		include_once Cloudi7_ICG_PLUGIN_DIR . 'admin/views/edit-card.php';
	}

	/**
	 * Display the All Cards list page.
	 *
	 * Fetches all cards from the database and displays the list view.
	 * Also handles the 'view' action to show individual card previews.
	 *
	 * @return void
	 */
	public function display_all_cards() {
		global $wpdb;
		$cloudi7_icg_table_name = $wpdb->prefix . 'cloudi7_icg_cards';

		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		if ( isset( $_GET['action'] ) && 'view' === $_GET['action'] && isset( $_GET['id'] ) ) {
			$cloudi7_icg_id = intval( $_GET['id'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
			$cloudi7_icg_cache_key = 'cloudi7_icg_data_card_preview_' . $cloudi7_icg_id;
			$cloudi7_icg_card = wp_cache_get( $cloudi7_icg_cache_key );
			if ( false === $cloudi7_icg_card ) {
				// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
				$cloudi7_icg_card = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}cloudi7_icg_cards WHERE id = %d", $cloudi7_icg_id ) );
				wp_cache_set( $cloudi7_icg_cache_key, $cloudi7_icg_card );
			}
			if ( $cloudi7_icg_card ) {
				include_once Cloudi7_ICG_PLUGIN_DIR . 'admin/views/preview-card.php';
				return;
			}
		}

		// Pagination logic
		$cloudi7_icg_per_page     = 20;
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$cloudi7_icg_current_page = isset( $_GET['paged'] ) ? max( 1, intval( $_GET['paged'] ) ) : 1;
		$cloudi7_icg_offset       = ( $cloudi7_icg_current_page - 1 ) * $cloudi7_icg_per_page;
		
		$cloudi7_icg_cache_key = 'cloudi7_icg_data_total_items_cards';
		$cloudi7_icg_total_items = wp_cache_get( $cloudi7_icg_cache_key );
		if ( false === $cloudi7_icg_total_items ) {
			// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
			$cloudi7_icg_total_items = $wpdb->get_var( "SELECT COUNT(id) FROM {$wpdb->prefix}cloudi7_icg_cards" );
			wp_cache_set( $cloudi7_icg_cache_key, $cloudi7_icg_total_items );
		}
		$cloudi7_icg_total_pages = ceil( $cloudi7_icg_total_items / $cloudi7_icg_per_page );

		$cloudi7_icg_cache_key = 'cloudi7_icg_data_cards_list_p' . $cloudi7_icg_current_page;
		$cloudi7_icg_cards = wp_cache_get( $cloudi7_icg_cache_key );
		if ( false === $cloudi7_icg_cards ) {
			// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
			$cloudi7_icg_cards = $wpdb->get_results( $wpdb->prepare( 
				"SELECT * FROM {$wpdb->prefix}cloudi7_icg_cards ORDER BY created_at DESC LIMIT %d OFFSET %d", 
				$cloudi7_icg_per_page, 
				$cloudi7_icg_offset 
			) );
			wp_cache_set( $cloudi7_icg_cache_key, $cloudi7_icg_cards );
		}

		include_once Cloudi7_ICG_PLUGIN_DIR . 'admin/views/list-cards.php';
	}

	/**
	 * Display the Settings page.
	 *
	 * @return void
	 */
	public function display_settings() {
		include_once Cloudi7_ICG_PLUGIN_DIR . 'admin/views/settings.php';
	}

	/**
	 * Display the Templates page.
	 *
	 * @return void
	 */
	public function display_templates() {
		include_once Cloudi7_ICG_PLUGIN_DIR . 'admin/views/templates.php';
	}

	/**
	 * Display the Applications page.
	 *
	 * @return void
	 */
	public function display_applications() {
		global $wpdb;
		$cloudi7_icg_table_name = $wpdb->prefix . 'cloudi7_icg_applications';

		// Pagination logic
		$cloudi7_icg_per_page     = 20;
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$cloudi7_icg_current_page = isset( $_GET['paged'] ) ? max( 1, intval( $_GET['paged'] ) ) : 1;
		$cloudi7_icg_offset       = ( $cloudi7_icg_current_page - 1 ) * $cloudi7_icg_per_page;
		
		$cloudi7_icg_cache_key = 'cloudi7_icg_data_total_items_apps';
		$cloudi7_icg_total_items = wp_cache_get( $cloudi7_icg_cache_key );
		if ( false === $cloudi7_icg_total_items ) {
			// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
			$cloudi7_icg_total_items = $wpdb->get_var( "SELECT COUNT(id) FROM {$wpdb->prefix}cloudi7_icg_applications" );
			wp_cache_set( $cloudi7_icg_cache_key, $cloudi7_icg_total_items );
		}
		$cloudi7_icg_total_pages = ceil( $cloudi7_icg_total_items / $cloudi7_icg_per_page );

		$cloudi7_icg_cache_key = 'cloudi7_icg_data_apps_list_p' . $cloudi7_icg_current_page;
		$cloudi7_icg_apps = wp_cache_get( $cloudi7_icg_cache_key );
		if ( false === $cloudi7_icg_apps ) {
			// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
			$cloudi7_icg_apps = $wpdb->get_results( $wpdb->prepare( 
				"SELECT * FROM {$wpdb->prefix}cloudi7_icg_applications ORDER BY created_at DESC LIMIT %d OFFSET %d", 
				$cloudi7_icg_per_page, 
				$cloudi7_icg_offset 
			) );
			wp_cache_set( $cloudi7_icg_cache_key, $cloudi7_icg_apps );
		}

		include_once Cloudi7_ICG_PLUGIN_DIR . 'admin/views/applications.php';
	}

	/**
	 * Process saving/updating a card.
	 *
	 * Handles form submission, validation, sanitization, and database persistence.
	 * Also triggers QR code generation for the card.
	 *
	 * @return void
	 */
	private function process_save_card() {
		if ( ! isset( $_POST['cloudi7_icg_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['cloudi7_icg_nonce'] ) ), 'cloudi7_icg_action' ) ) {
			wp_die( esc_html__( 'Security check failed', 'cloudi7-id-card-generator' ) );
		}

		if ( ! current_user_can( 'manage_options' ) ) {
			wp_die( esc_html__( 'You do not have permission to perform this action.', 'cloudi7-id-card-generator' ) );
		}

		global $wpdb;
		$cloudi7_icg_table_name = $wpdb->prefix . 'cloudi7_icg_cards';

		$cloudi7_icg_id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0;
		
		$cloudi7_icg_data = array(
			'name'              => isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '',
			'photo'             => isset( $_POST['photo'] ) ? esc_url_raw( wp_unslash( $_POST['photo'] ) ) : '',
			'organization_type' => isset( $_POST['organization_type'] ) ? sanitize_text_field( wp_unslash( $_POST['organization_type'] ) ) : '',
			'email'             => isset( $_POST['email'] ) ? sanitize_email( wp_unslash( $_POST['email'] ) ) : '',
			'phone'             => isset( $_POST['phone'] ) ? sanitize_text_field( wp_unslash( $_POST['phone'] ) ) : '',
			'dob'               => isset( $_POST['dob'] ) ? sanitize_text_field( wp_unslash( $_POST['dob'] ) ) : '',
			'gov_id'            => isset( $_POST['gov_id'] ) ? sanitize_text_field( wp_unslash( $_POST['gov_id'] ) ) : '',
			'parent_name'       => isset( $_POST['parent_name'] ) ? sanitize_text_field( wp_unslash( $_POST['parent_name'] ) ) : '',
			'parent_phone'      => isset( $_POST['parent_phone'] ) ? sanitize_text_field( wp_unslash( $_POST['parent_phone'] ) ) : '',
			'blood_group'       => isset( $_POST['blood_group'] ) ? sanitize_text_field( wp_unslash( $_POST['blood_group'] ) ) : '',
			'address'           => isset( $_POST['address'] ) ? sanitize_textarea_field( wp_unslash( $_POST['address'] ) ) : '',
			'issue_date'        => isset( $_POST['issue_date'] ) ? sanitize_text_field( wp_unslash( $_POST['issue_date'] ) ) : '',
			'expiry_date'       => isset( $_POST['expiry_date'] ) ? sanitize_text_field( wp_unslash( $_POST['expiry_date'] ) ) : '',
		);

		// Handle extra_data and Validation
		$cloudi7_icg_extra_data = array();
		$cloudi7_icg_org_type = $cloudi7_icg_data['organization_type'];

		if ( 'School' === $cloudi7_icg_org_type ) {
			if ( empty( $_POST['school_class'] ) ) {
				wp_die( esc_html__( 'Class / Grade is required for School ID cards.', 'cloudi7-id-card-generator' ) );
			}
			$cloudi7_icg_extra_data['class']                = sanitize_text_field( wp_unslash( $_POST['school_class'] ) );
			$cloudi7_icg_extra_data['blood_group']          = isset( $_POST['school_blood_group'] ) ? sanitize_text_field( wp_unslash( $_POST['school_blood_group'] ) ) : '';
			$cloudi7_icg_extra_data['father_guardian_name'] = isset( $_POST['school_father_guardian_name'] ) ? sanitize_text_field( wp_unslash( $_POST['school_father_guardian_name'] ) ) : '';
			
			// Also sync core columns if applicable (legacy/convenience)
			$cloudi7_icg_data['class'] = $cloudi7_icg_extra_data['class'];
		} elseif ( 'Corporate' === $cloudi7_icg_org_type ) {
			$cloudi7_icg_extra_data['department']    = isset( $_POST['corp_department'] ) ? sanitize_text_field( wp_unslash( $_POST['corp_department'] ) ) : '';
			$cloudi7_icg_extra_data['designation']   = isset( $_POST['corp_designation'] ) ? sanitize_text_field( wp_unslash( $_POST['corp_designation'] ) ) : '';
			$cloudi7_icg_extra_data['employee_id']   = isset( $_POST['corp_employee_id'] ) ? sanitize_text_field( wp_unslash( $_POST['corp_employee_id'] ) ) : '';
			
			$cloudi7_icg_data['department']  = $cloudi7_icg_extra_data['department'];
			$cloudi7_icg_data['designation'] = $cloudi7_icg_extra_data['designation'];
		} elseif ( 'Event' === $cloudi7_icg_org_type ) {
			$cloudi7_icg_extra_data['event_name']   = isset( $_POST['event_name'] ) ? sanitize_text_field( wp_unslash( $_POST['event_name'] ) ) : '';
			$cloudi7_icg_extra_data['role']         = isset( $_POST['event_role'] ) ? sanitize_text_field( wp_unslash( $_POST['event_role'] ) ) : '';
			$cloudi7_icg_extra_data['organization'] = isset( $_POST['event_organization'] ) ? sanitize_text_field( wp_unslash( $_POST['event_organization'] ) ) : '';
		} elseif ( 'Club' === $cloudi7_icg_org_type ) {
			$cloudi7_icg_extra_data['membership_id'] = isset( $_POST['club_member_id'] ) ? sanitize_text_field( wp_unslash( $_POST['club_member_id'] ) ) : '';
			$cloudi7_icg_extra_data['role']          = isset( $_POST['club_role'] ) ? sanitize_text_field( wp_unslash( $_POST['club_role'] ) ) : '';
			$cloudi7_icg_extra_data['join_date']    = isset( $_POST['club_join_date'] ) ? sanitize_text_field( wp_unslash( $_POST['club_join_date'] ) ) : '';
		} elseif ( 'Custom' === $cloudi7_icg_org_type ) {
			$cloudi7_icg_extra_data['department']    = isset( $_POST['custom_department'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_department'] ) ) : '';
			$cloudi7_icg_extra_data['role']          = isset( $_POST['custom_role'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_role'] ) ) : '';
			$cloudi7_icg_extra_data['notes']         = isset( $_POST['custom_notes'] ) ? sanitize_textarea_field( wp_unslash( $_POST['custom_notes'] ) ) : '';
		}
		
		// Capture Global Custom Fields
		if ( isset( $_POST['custom_field_1'] ) ) {
			$cloudi7_icg_extra_data['custom_field_1'] = sanitize_text_field( wp_unslash( $_POST['custom_field_1'] ) );
		}
		if ( isset( $_POST['custom_field_2'] ) ) {
			$cloudi7_icg_extra_data['custom_field_2'] = sanitize_text_field( wp_unslash( $_POST['custom_field_2'] ) );
		}
		if ( isset( $_POST['custom_field_3'] ) ) {
			$cloudi7_icg_extra_data['custom_field_3'] = sanitize_text_field( wp_unslash( $_POST['custom_field_3'] ) );
		}
		
		$cloudi7_icg_data['extra_data'] = wp_json_encode( $cloudi7_icg_extra_data );

		$cloudi7_icg_id_number = '';

		if ( $cloudi7_icg_id ) {
			// Get existing ID number for update
			$cloudi7_icg_cache_key = 'cloudi7_icg_data_card_id_num_' . $cloudi7_icg_id;
			$cloudi7_icg_existing_card = wp_cache_get( $cloudi7_icg_cache_key );
			if ( false === $cloudi7_icg_existing_card ) {
				// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
				$cloudi7_icg_existing_card = $wpdb->get_row( $wpdb->prepare( "SELECT id_number FROM {$wpdb->prefix}cloudi7_icg_cards WHERE id = %d", $cloudi7_icg_id ) );
				wp_cache_set( $cloudi7_icg_cache_key, $cloudi7_icg_existing_card );
			}
			if ( $cloudi7_icg_existing_card ) {
				$cloudi7_icg_id_number = $cloudi7_icg_existing_card->id_number;
			}
			// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
			$wpdb->update( $cloudi7_icg_table_name, $cloudi7_icg_data, array( 'id' => $cloudi7_icg_id ) );
			$cloudi7_icg_message = 'updated';
		} else {
			$cloudi7_icg_id_number = Cloudi7_ICG_ID_Generator::generate_id();
			$cloudi7_icg_data['id_number'] = $cloudi7_icg_id_number;
			// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
			$wpdb->insert( $cloudi7_icg_table_name, $cloudi7_icg_data );
			$cloudi7_icg_id = $wpdb->insert_id;
			$cloudi7_icg_message = 'created';
		}

		// Generate/Update QR Code
		if ( ! empty( $cloudi7_icg_id_number ) ) {
			$this->generate_id_qr_code( $cloudi7_icg_id_number );
		}

		wp_cache_delete( 'cloudi7_icg_data_total_cards' );
		wp_cache_delete( 'cloudi7_icg_data_recent_cards' );
		wp_cache_delete( 'cloudi7_icg_data_org_counts' );
		wp_cache_delete( 'cloudi7_icg_data_total_items_cards' );
		wp_cache_delete( 'cloudi7_icg_data_card_' . $cloudi7_icg_id );
		wp_cache_delete( 'cloudi7_icg_data_card_preview_' . $cloudi7_icg_id );
		wp_cache_delete( 'cloudi7_icg_data_last_id_number' );

		wp_safe_redirect( esc_url( admin_url( 'admin.php?page=cloudi7-icg-all-cards&message=' . sanitize_text_field( $cloudi7_icg_message ) ) ) );
		exit;
	}

	/**
	 * Process saving settings.
	 *
	 * Handles the submission of the settings form, updating plugin options.
	 *
	 * @return void
	 */
	private function process_save_settings() {
		if ( ! isset( $_POST['cloudi7_icg_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['cloudi7_icg_nonce'] ) ), 'cloudi7_icg_action' ) ) {
			wp_die( esc_html__( 'Security check failed', 'cloudi7-id-card-generator' ) );
		}

		if ( ! current_user_can( 'manage_options' ) ) {
			wp_die( esc_html__( 'You do not have permission to perform this action.', 'cloudi7-id-card-generator' ) );
		}

		$cloudi7_icg_options = array(
			'cloudi7_icg_org_logo'      => isset( $_POST['cloudi7_icg_org_logo'] ) ? esc_url_raw( wp_unslash( $_POST['cloudi7_icg_org_logo'] ) ) : '',
			'cloudi7_icg_org_signature' => isset( $_POST['cloudi7_icg_org_signature'] ) ? esc_url_raw( wp_unslash( $_POST['cloudi7_icg_org_signature'] ) ) : '',
			'cloudi7_icg_org_name'      => isset( $_POST['cloudi7_icg_org_name'] ) ? sanitize_text_field( wp_unslash( $_POST['cloudi7_icg_org_name'] ) ) : '',
			'cloudi7_icg_org_address' => isset( $_POST['cloudi7_icg_org_address'] ) ? sanitize_textarea_field( wp_unslash( $_POST['cloudi7_icg_org_address'] ) ) : '',
			'cloudi7_icg_org_phone'   => isset( $_POST['cloudi7_icg_org_phone'] ) ? sanitize_text_field( wp_unslash( $_POST['cloudi7_icg_org_phone'] ) ) : '',
			'cloudi7_icg_org_email'   => isset( $_POST['cloudi7_icg_org_email'] ) ? sanitize_email( wp_unslash( $_POST['cloudi7_icg_org_email'] ) ) : '',
			'cloudi7_icg_org_website' => isset( $_POST['cloudi7_icg_org_website'] ) ? esc_url_raw( wp_unslash( $_POST['cloudi7_icg_org_website'] ) ) : '',
			'cloudi7_icg_org_terms'   => isset( $_POST['cloudi7_icg_org_terms'] ) ? sanitize_textarea_field( wp_unslash( $_POST['cloudi7_icg_org_terms'] ) ) : '',
			'cloudi7_icg_org_type'    => isset( $_POST['cloudi7_icg_org_type'] ) ? sanitize_text_field( wp_unslash( $_POST['cloudi7_icg_org_type'] ) ) : 'School',
			'cloudi7_icg_orientation' => isset( $_POST['cloudi7_icg_orientation'] ) ? sanitize_text_field( wp_unslash( $_POST['cloudi7_icg_orientation'] ) ) : 'horizontal',
			'cloudi7_icg_back_text'   => isset( $_POST['cloudi7_icg_back_text'] ) ? sanitize_textarea_field( wp_unslash( $_POST['cloudi7_icg_back_text'] ) ) : '',
			'cloudi7_icg_custom_field_1_label' => isset( $_POST['cloudi7_icg_custom_field_1_label'] ) ? sanitize_text_field( wp_unslash( $_POST['cloudi7_icg_custom_field_1_label'] ) ) : '',
			'cloudi7_icg_custom_field_2_label' => isset( $_POST['cloudi7_icg_custom_field_2_label'] ) ? sanitize_text_field( wp_unslash( $_POST['cloudi7_icg_custom_field_2_label'] ) ) : '',
			'cloudi7_icg_custom_field_3_label' => isset( $_POST['cloudi7_icg_custom_field_3_label'] ) ? sanitize_text_field( wp_unslash( $_POST['cloudi7_icg_custom_field_3_label'] ) ) : '',
		);

		foreach ( $cloudi7_icg_options as $cloudi7_icg_key => $cloudi7_icg_value ) {
			update_option( $cloudi7_icg_key, $cloudi7_icg_value );
		}

		wp_safe_redirect( esc_url( admin_url( 'admin.php?page=cloudi7-icg-settings&message=updated' ) ) );
		exit;
	}

	/**
	 * Process deleting a card.
	 *
	 * Handles removal of a card from the database and its associated QR code file.
	 *
	 * @return void
	 */
	private function process_delete_card() {
		if ( ! isset( $_GET['cloudi7_icg_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['cloudi7_icg_nonce'] ) ), 'cloudi7_icg_action' ) ) {
			wp_die( esc_html__( 'Security check failed', 'cloudi7-id-card-generator' ) );
		}

		if ( ! current_user_can( 'manage_options' ) ) {
			wp_die( esc_html__( 'You do not have permission to perform this action.', 'cloudi7-id-card-generator' ) );
		}

		global $wpdb;
		$cloudi7_icg_id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0;
		$cloudi7_icg_table_name = $wpdb->prefix . 'cloudi7_icg_cards';

		if ( $cloudi7_icg_id ) {
			// Get ID number to delete QR code
			$cloudi7_icg_cache_key = 'cloudi7_icg_data_card_id_num_del_' . $cloudi7_icg_id;
			$cloudi7_icg_card = wp_cache_get( $cloudi7_icg_cache_key );
			if ( false === $cloudi7_icg_card ) {
				// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
				$cloudi7_icg_card = $wpdb->get_row( $wpdb->prepare( "SELECT id_number FROM {$wpdb->prefix}cloudi7_icg_cards WHERE id = %d", $cloudi7_icg_id ) );
				wp_cache_set( $cloudi7_icg_cache_key, $cloudi7_icg_card );
			}
			
			if ( $cloudi7_icg_card ) {
				$cloudi7_icg_upload_dir = wp_upload_dir();
				$cloudi7_icg_qr_file = $cloudi7_icg_upload_dir['basedir'] . '/cloudi7-icg-qrcodes/' . $cloudi7_icg_card->id_number . '.png';
				if ( file_exists( $cloudi7_icg_qr_file ) ) {
					wp_delete_file( $cloudi7_icg_qr_file );
				}
				
				// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
				$wpdb->delete( $cloudi7_icg_table_name, array( 'id' => $cloudi7_icg_id ) );
				wp_cache_delete( 'cloudi7_icg_data_total_cards' );
				wp_cache_delete( 'cloudi7_icg_data_recent_cards' );
				wp_cache_delete( 'cloudi7_icg_data_org_counts' );
				wp_cache_delete( 'cloudi7_icg_data_total_items_cards' );
				wp_cache_delete( 'cloudi7_icg_data_card_' . $cloudi7_icg_id );
				wp_cache_delete( 'cloudi7_icg_data_card_id_num_del_' . $cloudi7_icg_id );
				wp_cache_delete( 'cloudi7_icg_data_card_preview_' . $cloudi7_icg_id );
			}
		}

		wp_safe_redirect( esc_url( admin_url( 'admin.php?page=cloudi7-icg-all-cards&message=deleted' ) ) );
		exit;
	}

	/**
	 * Generate QR Code for an ID Card.
	 *
	 * Creates a QR code image linking to the verification URL and saves it
	 * to the plugin's upload directory.
	 *
	 * @param string $id_number The ID number to generate QR for.
	 * @return void
	 */
	private function generate_id_qr_code( $id_number ) {
		$cloudi7_icg_upload_dir = wp_upload_dir();
		$cloudi7_icg_qr_dir = $cloudi7_icg_upload_dir['basedir'] . '/cloudi7-icg-qrcodes';
		$cloudi7_icg_qr_file = $cloudi7_icg_qr_dir . '/' . $id_number . '.png';

		// Ensure directory exists
		if ( ! file_exists( $cloudi7_icg_qr_dir ) ) {
			wp_mkdir_p( $cloudi7_icg_qr_dir );
		}

		if ( ! class_exists( 'QRCode' ) ) {
			require_once Cloudi7_ICG_PLUGIN_DIR . 'includes/libs/qrcode/qrcode.php';
		}

		// Site URL for verification - specifically answering: "current website url/verify"
		$cloudi7_icg_verify_url = add_query_arg( 'verify_id', $id_number, home_url( '/verify/' ) );
		
		try {
			$cloudi7_icg_qr = new QRCode( $cloudi7_icg_verify_url );
			$cloudi7_icg_image = $cloudi7_icg_qr->render_image();
			if ( $cloudi7_icg_image ) {
				imagepng( $cloudi7_icg_image, $cloudi7_icg_qr_file );
				imagedestroy( $cloudi7_icg_image );
			}
		} catch ( Exception $cloudi7_icg_e ) {
			// Error logging could be added here for production debugging
			// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
			error_log( 'Cloudi7_ICG QR Error: ' . $cloudi7_icg_e->getMessage() );
		}
	}

	/**
	 * Process template selection saving.
	 *
	 * @return void
	 */
	private function process_save_template() {
		if ( ! isset( $_POST['cloudi7_icg_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['cloudi7_icg_nonce'] ) ), 'cloudi7_icg_action' ) ) {
			wp_die( esc_html__( 'Security check failed', 'cloudi7-id-card-generator' ) );
		}

		if ( ! current_user_can( 'manage_options' ) ) {
			wp_die( esc_html__( 'You do not have permission to perform this action.', 'cloudi7-id-card-generator' ) );
		}

		$cloudi7_icg_skin = isset( $_POST['cloudi7_icg_template_skin'] ) ? sanitize_text_field( wp_unslash( $_POST['cloudi7_icg_template_skin'] ) ) : 'modern';
		update_option( 'cloudi7_icg_template_skin', $cloudi7_icg_skin );

		wp_safe_redirect( esc_url( admin_url( 'admin.php?page=cloudi7-icg-templates&message=updated' ) ) );
		exit;
	}

	/**
	 * Process approving an application.
	 *
	 * Converts the application into a card.
	 *
	 * @return void
	 */
	private function process_approve_application() {
		if ( ! isset( $_GET['cloudi7_icg_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['cloudi7_icg_nonce'] ) ), 'cloudi7_icg_action' ) ) {
			wp_die( esc_html__( 'Security check failed', 'cloudi7-id-card-generator' ) );
		}

		if ( ! current_user_can( 'manage_options' ) ) {
			wp_die( esc_html__( 'You do not have permission to perform this action.', 'cloudi7-id-card-generator' ) );
		}

		global $wpdb;
		$cloudi7_icg_id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0;
		$cloudi7_icg_table_apps  = $wpdb->prefix . 'cloudi7_icg_applications';
		$cloudi7_icg_table_cards = $wpdb->prefix . 'cloudi7_icg_cards';

		$cloudi7_icg_cache_key = 'cloudi7_icg_data_app_' . $cloudi7_icg_id;
		$cloudi7_icg_app = wp_cache_get( $cloudi7_icg_cache_key );
		if ( false === $cloudi7_icg_app ) {
			// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
			$cloudi7_icg_app = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}cloudi7_icg_applications WHERE id = %d", $cloudi7_icg_id ) );
			wp_cache_set( $cloudi7_icg_cache_key, $cloudi7_icg_app );
		}
		if ( $cloudi7_icg_app && 'pending' === $cloudi7_icg_app->status ) {
			$cloudi7_icg_org_details = json_decode( $cloudi7_icg_app->org_details, true );
			$cloudi7_icg_id_number = Cloudi7_ICG_ID_Generator::generate_id();
			
			$cloudi7_icg_data = array(
				'id_number'         => $cloudi7_icg_id_number,
				'name'              => $cloudi7_icg_app->name,
				'email'             => $cloudi7_icg_app->email,
				'phone'             => $cloudi7_icg_app->phone,
				'photo'             => $cloudi7_icg_app->photo,
				'organization_type' => $cloudi7_icg_app->org_type,
				'dob'               => $cloudi7_icg_app->dob,
				'gov_id'            => $cloudi7_icg_app->gov_id,
				'parent_name'       => $cloudi7_icg_app->parent_name,
				'parent_phone'      => $cloudi7_icg_app->parent_phone,
				'blood_group'       => $cloudi7_icg_app->blood_group,
				'extra_data'        => wp_json_encode( $cloudi7_icg_org_details ),
				'issue_date'        => gmdate( 'Y-m-d' ),
				'created_at'        => current_time( 'mysql' ),
			);

			// Sync some fields for convenience if they exist in org_details
			if ( isset( $cloudi7_icg_org_details['class'] ) ) $cloudi7_icg_data['class'] = $cloudi7_icg_org_details['class'];
			if ( isset( $cloudi7_icg_org_details['department'] ) ) $cloudi7_icg_data['department'] = $cloudi7_icg_org_details['department'];
			if ( isset( $cloudi7_icg_org_details['designation'] ) ) $cloudi7_icg_data['designation'] = $cloudi7_icg_org_details['designation'];

			// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
			$wpdb->insert( $cloudi7_icg_table_cards, $cloudi7_icg_data );
			// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
			$wpdb->update( $cloudi7_icg_table_apps, array( 'status' => 'approved' ), array( 'id' => $cloudi7_icg_id ) );

			// Generate QR Code
			$this->generate_id_qr_code( $cloudi7_icg_data['id_number'] );

			wp_cache_delete( 'cloudi7_icg_data_total_cards' );
			wp_cache_delete( 'cloudi7_icg_data_recent_cards' );
			wp_cache_delete( 'cloudi7_icg_data_org_counts' );
			wp_cache_delete( 'cloudi7_icg_data_total_items_cards' );
			wp_cache_delete( 'cloudi7_icg_data_total_items_apps' );
			wp_cache_delete( 'cloudi7_icg_data_pending_apps_count' );
			wp_cache_delete( 'cloudi7_icg_data_app_' . $cloudi7_icg_id );
			wp_cache_delete( 'cloudi7_icg_data_last_id_number' );

			wp_safe_redirect( esc_url( admin_url( 'admin.php?page=cloudi7-icg-apps&message=approved' ) ) );
			exit;
		}
	}

	/**
	 * Process rejecting an application.
	 *
	 * @return void
	 */
	private function process_reject_application() {
		if ( ! isset( $_GET['cloudi7_icg_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['cloudi7_icg_nonce'] ) ), 'cloudi7_icg_action' ) ) {
			wp_die( esc_html__( 'Security check failed', 'cloudi7-id-card-generator' ) );
		}

		global $wpdb;
		$cloudi7_icg_id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0;
		$cloudi7_icg_table_name = $wpdb->prefix . 'cloudi7_icg_applications';

		// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
		$wpdb->update( $cloudi7_icg_table_name, array( 'status' => 'rejected' ), array( 'id' => $cloudi7_icg_id ) );
		wp_cache_delete( 'cloudi7_icg_data_pending_apps_count' );
		wp_cache_delete( 'cloudi7_icg_data_app_' . $cloudi7_icg_id );
		wp_cache_delete( 'cloudi7_icg_data_total_items_apps' );
		wp_safe_redirect( esc_url( admin_url( 'admin.php?page=cloudi7-icg-apps&message=rejected' ) ) );
		exit;
	}

	/**
	 * Process deleting an application.
	 *
	 * @return void
	 */
	private function process_delete_application() {
		if ( ! isset( $_GET['cloudi7_icg_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['cloudi7_icg_nonce'] ) ), 'cloudi7_icg_action' ) ) {
			wp_die( esc_html__( 'Security check failed', 'cloudi7-id-card-generator' ) );
		}

		global $wpdb;
		$cloudi7_icg_id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0;
		$cloudi7_icg_table_name = $wpdb->prefix . 'cloudi7_icg_applications';

		// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
		$wpdb->delete( $cloudi7_icg_table_name, array( 'id' => $cloudi7_icg_id ) );
		wp_cache_delete( 'cloudi7_icg_data_pending_apps_count' );
		wp_cache_delete( 'cloudi7_icg_data_app_' . $cloudi7_icg_id );
		wp_cache_delete( 'cloudi7_icg_data_total_items_apps' );
		wp_safe_redirect( esc_url( admin_url( 'admin.php?page=cloudi7-icg-apps&message=deleted' ) ) );
		exit;
	}

	/**
	 * Get count of pending applications.
	 *
	 * @return int
	 */
	private function get_pending_apps_count() {
		global $wpdb;
		$cloudi7_icg_table_name = $wpdb->prefix . 'cloudi7_icg_applications';
		$cloudi7_icg_cache_key = 'cloudi7_icg_data_pending_apps_count';
		$cloudi7_icg_data = wp_cache_get( $cloudi7_icg_cache_key );
		if ( false === $cloudi7_icg_data ) {
			// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
			$cloudi7_icg_data = (int) $wpdb->get_var( "SELECT COUNT(id) FROM {$wpdb->prefix}cloudi7_icg_applications WHERE status = 'pending'" );
			wp_cache_set( $cloudi7_icg_cache_key, $cloudi7_icg_data );
		}
		return $cloudi7_icg_data;
	}
	/**
	 * Customize the admin footer text.
	 *
	 * @param string $text The default footer text.
	 * @return string The customized footer text.
	 */
	public function admin_footer_text( $text ) {
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		if ( isset( $_GET['page'] ) && strpos( sanitize_text_field( wp_unslash( $_GET['page'] ) ), 'cloudi7-icg-' ) === 0 ) {
			return sprintf(
				/* translators: %1$s: Plugin site URL */
				wp_kses_post( __( 'Version 1.0.0 | By <a href="%1$s" target="_blank">CLOUDi7</a> | <a href="%1$s" target="_blank">Visit plugin site</a>', 'cloudi7-id-card-generator' ) ),
				'https://www.cloudi7.com'
			);
		}
		return $text;
	}

	/**
	 * Customize the admin footer version.
	 *
	 * @param string $text The default footer version text.
	 * @return string The customized version text.
	 */
	public function update_footer( $text ) {
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		if ( isset( $_GET['page'] ) && strpos( sanitize_text_field( wp_unslash( $_GET['page'] ) ), 'cloudi7-icg-' ) === 0 ) {
			return '';
		}
		return $text;
	}
}
