<?php
/**
 * Regional Compliance Configuration
 * 
 * Defines privacy laws and requirements for different regions
 */

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

class Biscotti_Regions
{

    /**
     * All supported regions with their privacy framework details
     */
    public static function get_regions()
    {
        return [
            // ============================================================
            // EUROPE
            // ============================================================
            'eu' => [
                'name' => __('European Union (GDPR)', 'biscotti-cmp'),
                'short' => 'EU',
                'flag' => '🇪🇺',
                'law' => 'GDPR / DSGVO',
                'law_full' => 'General Data Protection Regulation',
                'authority' => 'National Data Protection Authorities',
                'consent_mode' => 'opt-in', // Explicit consent required BEFORE cookies
                'reject_required' => true,  // Must offer reject option
                'granular_consent' => true, // Per-category consent required
                'cookie_wall_allowed' => false, // Cannot block content without consent
                'legitimate_interest' => true, // Can use for some processing
                'consent_duration_max' => 365, // Max days to store consent
                'gdpr_articles' => ['6', '7', '13', '14'],
                'documents_required' => ['privacy_policy', 'cookie_policy'],
                'countries' => [
                    'AT',
                    'BE',
                    'BG',
                    'HR',
                    'CY',
                    'CZ',
                    'DK',
                    'EE',
                    'FI',
                    'FR',
                    'DE',
                    'GR',
                    'HU',
                    'IE',
                    'IT',
                    'LV',
                    'LT',
                    'LU',
                    'MT',
                    'NL',
                    'PL',
                    'PT',
                    'RO',
                    'SK',
                    'SI',
                    'ES',
                    'SE'
                ],
                'special_rules' => [
                    'DE' => ['informal_language' => false], // German requires formal address
                    'AT' => ['informal_language' => false],
                    'ES' => ['lssi_compliance' => true],    // Spain: LSSI law
                    'FR' => ['cnil_compliance' => true],    // France: CNIL guidelines
                ],
            ],

            'uk' => [
                'name' => __('United Kingdom (UK GDPR)', 'biscotti-cmp'),
                'short' => 'UK',
                'flag' => '🇬🇧',
                'law' => 'UK GDPR + PECR',
                'law_full' => 'UK General Data Protection Regulation + Privacy and Electronic Communications Regulations',
                'authority' => 'Information Commissioner\'s Office (ICO)',
                'consent_mode' => 'opt-in',
                'reject_required' => true,
                'granular_consent' => true,
                'cookie_wall_allowed' => false,
                'legitimate_interest' => true,
                'consent_duration_max' => 365,
                'documents_required' => ['privacy_policy', 'cookie_policy'],
                'countries' => ['GB'],
                'special_rules' => [],
            ],

            'ch' => [
                'name' => __('Switzerland (revFADP)', 'biscotti-cmp'),
                'short' => 'CH',
                'flag' => '🇨🇭',
                'law' => 'revDSG / nDSG',
                'law_full' => 'Revidiertes Datenschutzgesetz',
                'authority' => 'EDÖB',
                'consent_mode' => 'opt-in',
                'reject_required' => true,
                'granular_consent' => true,
                'cookie_wall_allowed' => false,
                'legitimate_interest' => true,
                'consent_duration_max' => 365,
                'documents_required' => ['privacy_policy'],
                'countries' => ['CH'],
                'special_rules' => [],
            ],

            // ============================================================
            // AMERICAS
            // ============================================================
            'us' => [
                'name' => __('United States (CCPA/CPRA)', 'biscotti-cmp'),
                'short' => 'US',
                'flag' => '🇺🇸',
                'law' => 'CCPA / CPRA',
                'law_full' => 'California Consumer Privacy Act / California Privacy Rights Act',
                'authority' => 'California Attorney General / California Privacy Protection Agency',
                'consent_mode' => 'opt-out', // Default: cookies allowed, user can opt-out
                'reject_required' => false,
                'do_not_sell_required' => true, // "Do Not Sell My Personal Information" link required
                'granular_consent' => false,
                'cookie_wall_allowed' => true,
                'legitimate_interest' => true,
                'consent_duration_max' => 365,
                'documents_required' => ['privacy_policy'],
                'countries' => ['US'],
                'state_laws' => [
                    // === AKTIVE GESETZE (2020-2024) ===
                    'CA' => [
                        'law' => 'CCPA/CPRA',
                        'name' => 'California Consumer Privacy Act / California Privacy Rights Act',
                        'effective' => '2020-01-01',
                        'ccpa' => true,
                        'cpra' => true,
                        'consent_mode' => 'opt-out',
                        'do_not_sell' => true,
                        'private_right_of_action' => true,
                    ],
                    'VA' => [
                        'law' => 'VCDPA',
                        'name' => 'Virginia Consumer Data Protection Act',
                        'effective' => '2023-01-01',
                        'vcdpa' => true,
                        'consent_mode' => 'opt-out',
                        'do_not_sell' => true,
                    ],
                    'CO' => [
                        'law' => 'CPA',
                        'name' => 'Colorado Privacy Act',
                        'effective' => '2023-07-01',
                        'cpa' => true,
                        'consent_mode' => 'opt-out',
                        'universal_opt_out' => true,
                    ],
                    'CT' => [
                        'law' => 'CTDPA',
                        'name' => 'Connecticut Data Privacy Act',
                        'effective' => '2023-07-01',
                        'ctdpa' => true,
                        'consent_mode' => 'opt-out',
                    ],
                    'UT' => [
                        'law' => 'UCPA',
                        'name' => 'Utah Consumer Privacy Act',
                        'effective' => '2023-12-31',
                        'ucpa' => true,
                        'consent_mode' => 'opt-out',
                    ],
                    'FL' => [
                        'law' => 'FDBR',
                        'name' => 'Florida Digital Bill of Rights',
                        'effective' => '2024-07-01',
                        'fdbr' => true,
                        'consent_mode' => 'opt-out',
                        'children_protection' => true,
                    ],
                    'OR' => [
                        'law' => 'OCPA',
                        'name' => 'Oregon Consumer Privacy Act',
                        'effective' => '2024-07-01',
                        'ocpa' => true,
                        'consent_mode' => 'opt-out',
                    ],
                    'TX' => [
                        'law' => 'TDPSA',
                        'name' => 'Texas Data Privacy and Security Act',
                        'effective' => '2024-07-01',
                        'tdpsa' => true,
                        'consent_mode' => 'opt-out',
                        'do_not_sell' => true,
                    ],
                    'MT' => [
                        'law' => 'MCDPA',
                        'name' => 'Montana Consumer Data Privacy Act',
                        'effective' => '2024-10-01',
                        'mcdpa' => true,
                        'consent_mode' => 'opt-out',
                    ],
                    // === GESETZE AB 2025 ===
                    'DE' => [
                        'law' => 'DPDPA',
                        'name' => 'Delaware Personal Data Privacy Act',
                        'effective' => '2025-01-01',
                        'dpdpa' => true,
                        'consent_mode' => 'opt-out',
                    ],
                    'IA' => [
                        'law' => 'ICDPA',
                        'name' => 'Iowa Consumer Data Protection Act',
                        'effective' => '2025-01-01',
                        'icdpa' => true,
                        'consent_mode' => 'opt-out',
                    ],
                    'NE' => [
                        'law' => 'NDPA',
                        'name' => 'Nebraska Data Privacy Act',
                        'effective' => '2025-01-01',
                        'ndpa' => true,
                        'consent_mode' => 'opt-out',
                    ],
                    'NH' => [
                        'law' => 'NHPA',
                        'name' => 'New Hampshire Privacy Act',
                        'effective' => '2025-01-01',
                        'nhpa' => true,
                        'consent_mode' => 'opt-out',
                    ],
                    'NJ' => [
                        'law' => 'NJDPL',
                        'name' => 'New Jersey Data Privacy Law',
                        'effective' => '2025-01-15',
                        'njdpl' => true,
                        'consent_mode' => 'opt-out',
                        'minor_consent' => true, // Requires consent for minors 13-17
                    ],
                    'TN' => [
                        'law' => 'TIPA',
                        'name' => 'Tennessee Information Protection Act',
                        'effective' => '2025-07-01',
                        'tipa' => true,
                        'consent_mode' => 'opt-out',
                    ],
                    'MN' => [
                        'law' => 'MCDPA',
                        'name' => 'Minnesota Consumer Data Privacy Act',
                        'effective' => '2025-07-31',
                        'mcdpa_mn' => true,
                        'consent_mode' => 'opt-out',
                    ],
                    'MD' => [
                        'law' => 'MODPA',
                        'name' => 'Maryland Online Data Privacy Act',
                        'effective' => '2025-10-01',
                        'modpa' => true,
                        'consent_mode' => 'opt-out',
                        'sensitive_data_ban' => true, // Complete ban on sale of sensitive data
                    ],
                    // === GESETZE AB 2026 ===
                    'IN' => [
                        'law' => 'INCDPA',
                        'name' => 'Indiana Consumer Data Protection Act',
                        'effective' => '2026-01-01',
                        'incdpa' => true,
                        'consent_mode' => 'opt-out',
                    ],
                    'KY' => [
                        'law' => 'KCDPA',
                        'name' => 'Kentucky Consumer Data Protection Act',
                        'effective' => '2026-01-01',
                        'kcdpa' => true,
                        'consent_mode' => 'opt-out',
                    ],
                    'RI' => [
                        'law' => 'RIDPA',
                        'name' => 'Rhode Island Data Privacy Act',
                        'effective' => '2026-01-01',
                        'ridpa' => true,
                        'consent_mode' => 'opt-out',
                    ],
                ],
                'special_rules' => [
                    'do_not_sell_link' => true,
                    'financial_incentive_notice' => true,
                ],
            ],

            'ca' => [
                'name' => __('Canada (PIPEDA)', 'biscotti-cmp'),
                'short' => 'CA',
                'flag' => '🇨🇦',
                'law' => 'PIPEDA',
                'law_full' => 'Personal Information Protection and Electronic Documents Act',
                'authority' => 'Office of the Privacy Commissioner of Canada',
                'consent_mode' => 'implied', // Implied consent for non-sensitive data
                'reject_required' => false,
                'granular_consent' => false,
                'cookie_wall_allowed' => true,
                'legitimate_interest' => true,
                'consent_duration_max' => 365,
                'documents_required' => ['privacy_policy'],
                'countries' => ['CA'],
                'province_laws' => [
                    'QC' => ['law25' => true], // Quebec Law 25 - stricter, more like GDPR
                    'AB' => ['pipa' => true],
                    'BC' => ['pipa' => true],
                ],
                'special_rules' => [],
            ],

            'br' => [
                'name' => __('Brazil (LGPD)', 'biscotti-cmp'),
                'short' => 'BR',
                'flag' => '🇧🇷',
                'law' => 'LGPD',
                'law_full' => 'Lei Geral de Proteção de Dados',
                'authority' => 'ANPD (Autoridade Nacional de Proteção de Dados)',
                'consent_mode' => 'opt-in',
                'reject_required' => true,
                'granular_consent' => true,
                'cookie_wall_allowed' => false,
                'legitimate_interest' => true,
                'consent_duration_max' => 365,
                'documents_required' => ['privacy_policy', 'cookie_policy'],
                'countries' => ['BR'],
                'special_rules' => [],
            ],

            // ============================================================
            // ASIA-PACIFIC
            // ============================================================
            'au' => [
                'name' => __('Australia (Privacy Act)', 'biscotti-cmp'),
                'short' => 'AU',
                'flag' => '🇦🇺',
                'law' => 'Privacy Act 1988',
                'law_full' => 'Privacy Act 1988 + Australian Privacy Principles',
                'authority' => 'Office of the Australian Information Commissioner (OAIC)',
                'consent_mode' => 'implied',
                'reject_required' => false,
                'granular_consent' => false,
                'cookie_wall_allowed' => true,
                'legitimate_interest' => true,
                'consent_duration_max' => 365,
                'documents_required' => ['privacy_policy'],
                'countries' => ['AU'],
                'special_rules' => [],
            ],

            'nz' => [
                'name' => __('New Zealand (Privacy Act)', 'biscotti-cmp'),
                'short' => 'NZ',
                'flag' => '🇳🇿',
                'law' => 'Privacy Act 2020',
                'law_full' => 'Privacy Act 2020',
                'authority' => 'Office of the Privacy Commissioner',
                'consent_mode' => 'implied',
                'reject_required' => false,
                'granular_consent' => false,
                'cookie_wall_allowed' => true,
                'legitimate_interest' => true,
                'consent_duration_max' => 365,
                'documents_required' => ['privacy_policy'],
                'countries' => ['NZ'],
                'special_rules' => [],
            ],

            'jp' => [
                'name' => __('Japan (APPI)', 'biscotti-cmp'),
                'short' => 'JP',
                'flag' => '🇯🇵',
                'law' => 'APPI',
                'law_full' => 'Act on Protection of Personal Information',
                'authority' => 'Personal Information Protection Commission',
                'consent_mode' => 'opt-in', // For third-party data transfer
                'reject_required' => true,
                'granular_consent' => true,
                'cookie_wall_allowed' => false,
                'legitimate_interest' => false,
                'consent_duration_max' => 365,
                'documents_required' => ['privacy_policy'],
                'countries' => ['JP'],
                'special_rules' => [],
            ],

            'kr' => [
                'name' => __('South Korea (PIPA)', 'biscotti-cmp'),
                'short' => 'KR',
                'flag' => '🇰🇷',
                'law' => 'PIPA',
                'law_full' => 'Personal Information Protection Act',
                'authority' => 'Personal Information Protection Commission (PIPC)',
                'consent_mode' => 'opt-in',
                'reject_required' => true,
                'granular_consent' => true,
                'cookie_wall_allowed' => false,
                'legitimate_interest' => false,
                'consent_duration_max' => 365,
                'documents_required' => ['privacy_policy'],
                'countries' => ['KR'],
                'special_rules' => [],
            ],

            'in' => [
                'name' => __('India (DPDPA)', 'biscotti-cmp'),
                'short' => 'IN',
                'flag' => '🇮🇳',
                'law' => 'DPDPA',
                'law_full' => 'Digital Personal Data Protection Act, 2023',
                'authority' => 'Data Protection Board of India',
                'consent_mode' => 'opt-in',
                'reject_required' => true,
                'granular_consent' => true,
                'cookie_wall_allowed' => false,
                'legitimate_interest' => true,
                'consent_duration_max' => 365,
                'documents_required' => ['privacy_policy'],
                'countries' => ['IN'],
                'special_rules' => [
                    'children_consent_age' => 18,
                    'data_localization' => true,
                ],
            ],

            'th' => [
                'name' => __('Thailand (PDPA)', 'biscotti-cmp'),
                'short' => 'TH',
                'flag' => '🇹🇭',
                'law' => 'PDPA',
                'law_full' => 'Personal Data Protection Act B.E. 2562',
                'authority' => 'Personal Data Protection Committee (PDPC)',
                'consent_mode' => 'opt-in',
                'reject_required' => true,
                'granular_consent' => true,
                'cookie_wall_allowed' => false,
                'legitimate_interest' => true,
                'consent_duration_max' => 365,
                'documents_required' => ['privacy_policy'],
                'countries' => ['TH'],
                'special_rules' => [],
            ],

            'sg' => [
                'name' => __('Singapore (PDPA)', 'biscotti-cmp'),
                'short' => 'SG',
                'flag' => '🇸🇬',
                'law' => 'PDPA',
                'law_full' => 'Personal Data Protection Act 2012',
                'authority' => 'Personal Data Protection Commission (PDPC)',
                'consent_mode' => 'opt-in',
                'reject_required' => true,
                'granular_consent' => false,
                'cookie_wall_allowed' => true,
                'legitimate_interest' => true,
                'consent_duration_max' => 365,
                'documents_required' => ['privacy_policy'],
                'countries' => ['SG'],
                'special_rules' => [
                    'do_not_call_registry' => true,
                ],
            ],

            'cn' => [
                'name' => __('China (PIPL)', 'biscotti-cmp'),
                'short' => 'CN',
                'flag' => '🇨🇳',
                'law' => 'PIPL',
                'law_full' => 'Personal Information Protection Law',
                'authority' => 'Cyberspace Administration of China (CAC)',
                'consent_mode' => 'opt-in',
                'reject_required' => true,
                'granular_consent' => true,
                'cookie_wall_allowed' => false,
                'legitimate_interest' => false,
                'consent_duration_max' => 365,
                'documents_required' => ['privacy_policy'],
                'countries' => ['CN'],
                'special_rules' => [
                    'data_localization' => true,
                    'cross_border_transfer_assessment' => true,
                ],
            ],

            'id' => [
                'name' => __('Indonesia (PDP Law)', 'biscotti-cmp'),
                'short' => 'ID',
                'flag' => '🇮🇩',
                'law' => 'PDP Law',
                'law_full' => 'Personal Data Protection Law (UU PDP)',
                'authority' => 'Ministry of Communication and Information Technology',
                'consent_mode' => 'opt-in',
                'reject_required' => true,
                'granular_consent' => true,
                'cookie_wall_allowed' => false,
                'legitimate_interest' => true,
                'consent_duration_max' => 365,
                'documents_required' => ['privacy_policy'],
                'countries' => ['ID'],
                'special_rules' => [],
            ],

            // ============================================================
            // MIDDLE EAST
            // ============================================================
            'tr' => [
                'name' => __('Turkey (KVKK)', 'biscotti-cmp'),
                'short' => 'TR',
                'flag' => '🇹🇷',
                'law' => 'KVKK',
                'law_full' => 'Kişisel Verilerin Korunması Kanunu (Law No. 6698)',
                'authority' => 'Kişisel Verileri Koruma Kurumu (KVKK)',
                'consent_mode' => 'opt-in',
                'reject_required' => true,
                'granular_consent' => true,
                'cookie_wall_allowed' => false,
                'legitimate_interest' => true,
                'consent_duration_max' => 365,
                'documents_required' => ['privacy_policy'],
                'countries' => ['TR'],
                'special_rules' => [],
            ],

            'ae' => [
                'name' => __('UAE (PDPL)', 'biscotti-cmp'),
                'short' => 'AE',
                'flag' => '🇦🇪',
                'law' => 'PDPL',
                'law_full' => 'Federal Decree-Law No. 45 of 2021 on Personal Data Protection',
                'authority' => 'UAE Data Office',
                'consent_mode' => 'opt-in',
                'reject_required' => true,
                'granular_consent' => false,
                'cookie_wall_allowed' => true,
                'legitimate_interest' => true,
                'consent_duration_max' => 365,
                'documents_required' => ['privacy_policy'],
                'countries' => ['AE'],
                'special_rules' => [],
            ],

            'il' => [
                'name' => __('Israel (PPL)', 'biscotti-cmp'),
                'short' => 'IL',
                'flag' => '🇮🇱',
                'law' => 'PPL',
                'law_full' => 'Protection of Privacy Law, 5741-1981',
                'authority' => 'Privacy Protection Authority (PPA)',
                'consent_mode' => 'opt-in',
                'reject_required' => true,
                'granular_consent' => false,
                'cookie_wall_allowed' => true,
                'legitimate_interest' => true,
                'consent_duration_max' => 365,
                'documents_required' => ['privacy_policy'],
                'countries' => ['IL'],
                'special_rules' => [],
            ],

            // ============================================================
            // AFRICA
            // ============================================================
            'za' => [
                'name' => __('South Africa (POPIA)', 'biscotti-cmp'),
                'short' => 'ZA',
                'flag' => '🇿🇦',
                'law' => 'POPIA',
                'law_full' => 'Protection of Personal Information Act',
                'authority' => 'Information Regulator',
                'consent_mode' => 'opt-in',
                'reject_required' => true,
                'granular_consent' => true,
                'cookie_wall_allowed' => false,
                'legitimate_interest' => true,
                'consent_duration_max' => 365,
                'documents_required' => ['privacy_policy', 'paia_manual'],
                'countries' => ['ZA'],
                'special_rules' => [],
            ],

            'eg' => [
                'name' => __('Egypt (DPL)', 'biscotti-cmp'),
                'short' => 'EG',
                'flag' => '🇪🇬',
                'law' => 'DPL',
                'law_full' => 'Data Protection Law No. 151 of 2020',
                'authority' => 'Data Protection Center',
                'consent_mode' => 'opt-in',
                'reject_required' => true,
                'granular_consent' => false,
                'cookie_wall_allowed' => true,
                'legitimate_interest' => true,
                'consent_duration_max' => 365,
                'documents_required' => ['privacy_policy'],
                'countries' => ['EG'],
                'special_rules' => [],
            ],

            'ke' => [
                'name' => __('Kenya (DPA)', 'biscotti-cmp'),
                'short' => 'KE',
                'flag' => '🇰🇪',
                'law' => 'DPA',
                'law_full' => 'Data Protection Act, 2019',
                'authority' => 'Office of the Data Protection Commissioner',
                'consent_mode' => 'opt-in',
                'reject_required' => true,
                'granular_consent' => true,
                'cookie_wall_allowed' => false,
                'legitimate_interest' => true,
                'consent_duration_max' => 365,
                'documents_required' => ['privacy_policy'],
                'countries' => ['KE'],
                'special_rules' => [],
            ],

            'ng' => [
                'name' => __('Nigeria (NDPR)', 'biscotti-cmp'),
                'short' => 'NG',
                'flag' => '🇳🇬',
                'law' => 'NDPR',
                'law_full' => 'Nigeria Data Protection Regulation / Act 2023',
                'authority' => 'Nigeria Data Protection Commission (NDPC)',
                'consent_mode' => 'opt-in',
                'reject_required' => true,
                'granular_consent' => true,
                'cookie_wall_allowed' => false,
                'legitimate_interest' => true,
                'consent_duration_max' => 365,
                'documents_required' => ['privacy_policy'],
                'countries' => ['NG'],
                'special_rules' => [],
            ],
        ];
    }

    /**
     * Get region by code
     */
    public static function get_region($code)
    {
        $regions = self::get_regions();
        return isset($regions[$code]) ? $regions[$code] : null;
    }

    /**
     * Get region by country code
     */
    public static function get_region_by_country($country_code)
    {
        $regions = self::get_regions();

        foreach ($regions as $region_code => $region) {
            if (in_array($country_code, $region['countries'])) {
                return $region_code;
            }
        }

        // Default to EU for unknown countries (strictest)
        return 'eu';
    }

    /**
     * Check if region requires opt-in consent
     */
    public static function requires_opt_in($region_code)
    {
        $region = self::get_region($region_code);
        return $region && $region['consent_mode'] === 'opt-in';
    }

    /**
     * Check if region requires reject button
     */
    public static function requires_reject($region_code)
    {
        $region = self::get_region($region_code);
        return $region && isset($region['reject_required']) && $region['reject_required'];
    }

    /**
     * Check if region requires "Do Not Sell" link
     */
    public static function requires_do_not_sell($region_code)
    {
        $region = self::get_region($region_code);
        return $region && isset($region['do_not_sell_required']) && $region['do_not_sell_required'];
    }

    /**
     * Get banner configuration for region
     */
    public static function get_banner_config($region_code)
    {
        $region = self::get_region($region_code);

        if (!$region) {
            $region = self::get_region('eu'); // Default to EU
        }

        return [
            'consent_mode' => $region['consent_mode'],
            'show_reject' => $region['reject_required'],
            'show_do_not_sell' => isset($region['do_not_sell_required']) && $region['do_not_sell_required'],
            'granular_consent' => $region['granular_consent'],
            'cookie_wall_allowed' => $region['cookie_wall_allowed'],
        ];
    }

    /**
     * Get all regions for dropdown
     */
    public static function get_regions_for_select()
    {
        $regions = self::get_regions();
        $options = [];

        foreach ($regions as $code => $region) {
            $options[$code] = $region['flag'] . ' ' . $region['name'];
        }

        return $options;
    }

    /**
     * Get document requirements for region
     */
    public static function get_required_documents($region_code)
    {
        $region = self::get_region($region_code);
        return $region ? $region['documents_required'] : ['privacy_policy'];
    }

    /**
     * Get all US state laws
     */
    public static function get_us_state_laws()
    {
        $us = self::get_region('us');
        return $us && isset($us['state_laws']) ? $us['state_laws'] : [];
    }

    /**
     * Get all active US state laws for a given date
     */
    public static function get_active_us_state_laws($date = null)
    {
        $date = $date ?: gmdate('Y-m-d');
        $state_laws = self::get_us_state_laws();
        $active = [];

        foreach ($state_laws as $state => $laws) {
            if (isset($laws['effective']) && $laws['effective'] <= $date) {
                $active[$state] = $laws;
            }
        }
        return $active;
    }

    /**
     * Get US state full name and details
     */
    public static function get_us_state_details($state_code)
    {
        $states = [
            'AL' => 'Alabama',
            'AK' => 'Alaska',
            'AZ' => 'Arizona',
            'AR' => 'Arkansas',
            'CA' => 'California',
            'CO' => 'Colorado',
            'CT' => 'Connecticut',
            'DE' => 'Delaware',
            'FL' => 'Florida',
            'GA' => 'Georgia',
            'HI' => 'Hawaii',
            'ID' => 'Idaho',
            'IL' => 'Illinois',
            'IN' => 'Indiana',
            'IA' => 'Iowa',
            'KS' => 'Kansas',
            'KY' => 'Kentucky',
            'LA' => 'Louisiana',
            'ME' => 'Maine',
            'MD' => 'Maryland',
            'MA' => 'Massachusetts',
            'MI' => 'Michigan',
            'MN' => 'Minnesota',
            'MS' => 'Mississippi',
            'MO' => 'Missouri',
            'MT' => 'Montana',
            'NE' => 'Nebraska',
            'NV' => 'Nevada',
            'NH' => 'New Hampshire',
            'NJ' => 'New Jersey',
            'NM' => 'New Mexico',
            'NY' => 'New York',
            'NC' => 'North Carolina',
            'ND' => 'North Dakota',
            'OH' => 'Ohio',
            'OK' => 'Oklahoma',
            'OR' => 'Oregon',
            'PA' => 'Pennsylvania',
            'RI' => 'Rhode Island',
            'SC' => 'South Carolina',
            'SD' => 'South Dakota',
            'TN' => 'Tennessee',
            'TX' => 'Texas',
            'UT' => 'Utah',
            'VT' => 'Vermont',
            'VA' => 'Virginia',
            'WA' => 'Washington',
            'WV' => 'West Virginia',
            'WI' => 'Wisconsin',
            'WY' => 'Wyoming',
            'DC' => 'District of Columbia'
        ];

        $state_laws = self::get_us_state_laws();
        $law_info = isset($state_laws[$state_code]) ? $state_laws[$state_code] : null;

        return [
            'code' => $state_code,
            'name' => isset($states[$state_code]) ? $states[$state_code] : $state_code,
            'law' => $law_info ? $law_info['law'] : null,
            'law_name' => $law_info && isset($law_info['name']) ? $law_info['name'] : null,
            'effective' => $law_info && isset($law_info['effective']) ? $law_info['effective'] : null,
            'has_law' => !empty($law_info),
        ];
    }

    /**
     * Get US states for dropdown select (only states with privacy laws)
     */
    public static function get_us_states_for_select()
    {
        $state_laws = self::get_us_state_laws();
        $options = [];

        foreach ($state_laws as $code => $law) {
            $details = self::get_us_state_details($code);
            $status = $law['effective'] <= gmdate('Y-m-d') ? '✓' : '⏳';
            $options[$code] = $status . ' ' . $details['name'] . ' (' . $law['law'] . ')';
        }

        return $options;
    }
}
