<?php

defined( 'ABSPATH' ) || exit;
// Track block usage
if ( function_exists( 'ezhp_track_block_usage' ) ) {
    ezhp_track_block_usage( 'moon-phase', $attributes );
}
// Sanitize inputs
$ezhp_language = sanitize_text_field( $attributes['language'] ?? 'en' );
$ezhp_image_size = absint( $attributes['imageSize'] ?? 100 );
$ezhp_api_key = sanitize_text_field( get_option( 'ezhp_horoscope_activation_guid', '' ) );
// RTL languages
$ezhp_rtl_languages = array(
    'ar',
    'he',
    'ur',
    'fa'
);
$ezhp_is_rtl = in_array( $ezhp_language, $ezhp_rtl_languages, true );
// CTA attributes
$ezhp_is_rest = defined( 'REST_REQUEST' ) && REST_REQUEST;
$ezhp_cta_enabled = false;
if ( $ezhp_is_rest ) {
    $ezhp_cta_enabled = !empty( $attributes['ctaEnabled'] );
}
$ezhp_cta_text = sanitize_text_field( $attributes['ctaText'] ?? '' );
$ezhp_cta_image_url = esc_url( $attributes['ctaImageUrl'] ?? '' );
$ezhp_cta_image_alt = sanitize_text_field( $attributes['ctaImageAlt'] ?? '' );
$ezhp_cta_url = esc_url( $attributes['ctaUrl'] ?? '' );
$ezhp_cta_link_type = sanitize_text_field( $attributes['ctaLinkType'] ?? 'button' );
$ezhp_cta_link_text = sanitize_text_field( $attributes['ctaLinkText'] ?? '' );
$ezhp_cta_image_clickable = !empty( $attributes['ctaImageClickable'] );
$ezhp_cta_element_id = sanitize_html_class( $attributes['ctaElementId'] ?? '' );
$ezhp_allowed_html = array(
    'div'    => array(
        'class'                    => array(),
        'style'                    => array(),
        'dir'                      => array(),
        'data-language'            => array(),
        'data-apikey'              => array(),
        'data-cta-enabled'         => array(),
        'data-cta-text'            => array(),
        'data-cta-image-url'       => array(),
        'data-cta-image-alt'       => array(),
        'data-cta-url'             => array(),
        'data-cta-link-type'       => array(),
        'data-cta-link-text'       => array(),
        'data-cta-image-clickable' => array(),
        'data-cta-element-id'      => array(),
    ),
    'img'    => array(
        'src'   => array(),
        'alt'   => array(),
        'class' => array(),
        'style' => array(),
    ),
    'p'      => array(
        'class' => array(),
    ),
    'span'   => array(
        'class' => array(),
    ),
    'select' => array(
        'class'      => array(),
        'aria-label' => array(),
    ),
    'option' => array(
        'value' => array(),
    ),
    'strong' => array(),
);
// Moon phase image attributes
$ezhp_moon_images = array(
    'new moon'        => $attributes['newMoonImage'] ?? '',
    'waxing crescent' => $attributes['waxingCrescentImage'] ?? '',
    'first quarter'   => $attributes['firstQuarterImage'] ?? '',
    'waxing gibbous'  => $attributes['waxingGibbousImage'] ?? '',
    'full moon'       => $attributes['fullMoonImage'] ?? '',
    'waning gibbous'  => $attributes['waningGibbousImage'] ?? '',
    'last quarter'    => $attributes['lastQuarterImage'] ?? '',
    'waning crescent' => $attributes['waningCrescentImage'] ?? '',
);
// Default bundled images fallback
$ezhp_default_images = array(
    'new moon'        => plugins_url( 'assets/images/moon-phases/new-moon.png', dirname( __FILE__, 3 ) ),
    'waxing crescent' => plugins_url( 'assets/images/moon-phases/waxing-crescent.png', dirname( __FILE__, 3 ) ),
    'first quarter'   => plugins_url( 'assets/images/moon-phases/first-quarter.png', dirname( __FILE__, 3 ) ),
    'waxing gibbous'  => plugins_url( 'assets/images/moon-phases/waxing-gibbous.png', dirname( __FILE__, 3 ) ),
    'full moon'       => plugins_url( 'assets/images/moon-phases/full-moon.png', dirname( __FILE__, 3 ) ),
    'waning gibbous'  => plugins_url( 'assets/images/moon-phases/waning-gibbous.png', dirname( __FILE__, 3 ) ),
    'last quarter'    => plugins_url( 'assets/images/moon-phases/last-quarter.png', dirname( __FILE__, 3 ) ),
    'waning crescent' => plugins_url( 'assets/images/moon-phases/waning-crescent.png', dirname( __FILE__, 3 ) ),
);
// Emoji fallbacks
$ezhp_emoji_fallbacks = array(
    'new moon'        => '🌑',
    'waxing crescent' => '🌒',
    'first quarter'   => '🌓',
    'waxing gibbous'  => '🌔',
    'full moon'       => '🌕',
    'waning gibbous'  => '🌖',
    'last quarter'    => '🌗',
    'waning crescent' => '🌘',
);
// Zodiac signs with emojis
$ezhp_zodiac_signs = array(
    'aries'       => '♈',
    'taurus'      => '♉',
    'gemini'      => '♊',
    'cancer'      => '♋',
    'leo'         => '♌',
    'virgo'       => '♍',
    'libra'       => '♎',
    'scorpio'     => '♏',
    'sagittarius' => '♐',
    'capricorn'   => '♑',
    'aquarius'    => '♒',
    'pisces'      => '♓',
);
// Zodiac translations
$ezhp_zodiac_translations = array(
    'en' => array(
        'aries'       => 'Aries',
        'taurus'      => 'Taurus',
        'gemini'      => 'Gemini',
        'cancer'      => 'Cancer',
        'leo'         => 'Leo',
        'virgo'       => 'Virgo',
        'libra'       => 'Libra',
        'scorpio'     => 'Scorpio',
        'sagittarius' => 'Sagittarius',
        'capricorn'   => 'Capricorn',
        'aquarius'    => 'Aquarius',
        'pisces'      => 'Pisces',
    ),
    'fr' => array(
        'aries'       => 'Bélier',
        'taurus'      => 'Taureau',
        'gemini'      => 'Gémeaux',
        'cancer'      => 'Cancer',
        'leo'         => 'Lion',
        'virgo'       => 'Vierge',
        'libra'       => 'Balance',
        'scorpio'     => 'Scorpion',
        'sagittarius' => 'Sagittaire',
        'capricorn'   => 'Capricorne',
        'aquarius'    => 'Verseau',
        'pisces'      => 'Poissons',
    ),
    'it' => array(
        'aries'       => 'Ariete',
        'taurus'      => 'Toro',
        'gemini'      => 'Gemelli',
        'cancer'      => 'Cancro',
        'leo'         => 'Leone',
        'virgo'       => 'Vergine',
        'libra'       => 'Bilancia',
        'scorpio'     => 'Scorpione',
        'sagittarius' => 'Sagittario',
        'capricorn'   => 'Capricorno',
        'aquarius'    => 'Acquario',
        'pisces'      => 'Pesci',
    ),
    'de' => array(
        'aries'       => 'Widder',
        'taurus'      => 'Stier',
        'gemini'      => 'Zwillinge',
        'cancer'      => 'Krebs',
        'leo'         => 'Löwe',
        'virgo'       => 'Jungfrau',
        'libra'       => 'Waage',
        'scorpio'     => 'Skorpion',
        'sagittarius' => 'Schütze',
        'capricorn'   => 'Steinbock',
        'aquarius'    => 'Wassermann',
        'pisces'      => 'Fische',
    ),
    'es' => array(
        'aries'       => 'Aries',
        'taurus'      => 'Tauro',
        'gemini'      => 'Géminis',
        'cancer'      => 'Cáncer',
        'leo'         => 'Leo',
        'virgo'       => 'Virgo',
        'libra'       => 'Libra',
        'scorpio'     => 'Escorpio',
        'sagittarius' => 'Sagitario',
        'capricorn'   => 'Capricornio',
        'aquarius'    => 'Acuario',
        'pisces'      => 'Piscis',
    ),
    'ar' => array(
        'aries'       => 'الحمل',
        'taurus'      => 'الثور',
        'gemini'      => 'الجوزاء',
        'cancer'      => 'السرطان',
        'leo'         => 'الأسد',
        'virgo'       => 'العذراء',
        'libra'       => 'الميزان',
        'scorpio'     => 'العقرب',
        'sagittarius' => 'القوس',
        'capricorn'   => 'الجدي',
        'aquarius'    => 'الدلو',
        'pisces'      => 'الحوت',
    ),
    'bn' => array(
        'aries'       => 'মেষ',
        'taurus'      => 'বৃষ',
        'gemini'      => 'মিথুন',
        'cancer'      => 'কর্কট',
        'leo'         => 'সিংহ',
        'virgo'       => 'কন্যা',
        'libra'       => 'তুলা',
        'scorpio'     => 'বৃশ্চিক',
        'sagittarius' => 'ধনু',
        'capricorn'   => 'মকর',
        'aquarius'    => 'কুম্ভ',
        'pisces'      => 'মীন',
    ),
    'cs' => array(
        'aries'       => 'Beran',
        'taurus'      => 'Býk',
        'gemini'      => 'Blíženci',
        'cancer'      => 'Rak',
        'leo'         => 'Lev',
        'virgo'       => 'Panna',
        'libra'       => 'Váhy',
        'scorpio'     => 'Štír',
        'sagittarius' => 'Střelec',
        'capricorn'   => 'Kozoroh',
        'aquarius'    => 'Vodnář',
        'pisces'      => 'Ryby',
    ),
    'da' => array(
        'aries'       => 'Vædderen',
        'taurus'      => 'Tyren',
        'gemini'      => 'Tvillingerne',
        'cancer'      => 'Krebsen',
        'leo'         => 'Løven',
        'virgo'       => 'Jomfruen',
        'libra'       => 'Vægten',
        'scorpio'     => 'Skorpionen',
        'sagittarius' => 'Skytten',
        'capricorn'   => 'Stenbukken',
        'aquarius'    => 'Vandmanden',
        'pisces'      => 'Fiskene',
    ),
    'el' => array(
        'aries'       => 'Κριός',
        'taurus'      => 'Ταύρος',
        'gemini'      => 'Δίδυμοι',
        'cancer'      => 'Καρκίνος',
        'leo'         => 'Λέων',
        'virgo'       => 'Παρθένος',
        'libra'       => 'Ζυγός',
        'scorpio'     => 'Σκορπιός',
        'sagittarius' => 'Τοξότης',
        'capricorn'   => 'Αιγόκερως',
        'aquarius'    => 'Υδροχόος',
        'pisces'      => 'Ιχθύες',
    ),
    'et' => array(
        'aries'       => 'Jäär',
        'taurus'      => 'Sõnn',
        'gemini'      => 'Kaksikud',
        'cancer'      => 'Vähk',
        'leo'         => 'Lõvi',
        'virgo'       => 'Neitsi',
        'libra'       => 'Kaalud',
        'scorpio'     => 'Skorpion',
        'sagittarius' => 'Ambur',
        'capricorn'   => 'Kaljukits',
        'aquarius'    => 'Veevalaja',
        'pisces'      => 'Kalad',
    ),
    'eu' => array(
        'aries'       => 'Aharia',
        'taurus'      => 'Zezena',
        'gemini'      => 'Bikiak',
        'cancer'      => 'Karramarroa',
        'leo'         => 'Lehoia',
        'virgo'       => 'Birjina',
        'libra'       => 'Balantza',
        'scorpio'     => 'Eskorpioia',
        'sagittarius' => 'Sagitario',
        'capricorn'   => 'Capricornio',
        'aquarius'    => 'Akuarioa',
        'pisces'      => 'Arrainak',
    ),
    'fa' => array(
        'aries'       => 'حمل',
        'taurus'      => 'ثور',
        'gemini'      => 'جوزا',
        'cancer'      => 'سرطان',
        'leo'         => 'اسد',
        'virgo'       => 'سنبله',
        'libra'       => 'میزان',
        'scorpio'     => 'عقرب',
        'sagittarius' => 'قوس',
        'capricorn'   => 'جدی',
        'aquarius'    => 'دلو',
        'pisces'      => 'حوت',
    ),
    'fi' => array(
        'aries'       => 'Oinas',
        'taurus'      => 'Härkä',
        'gemini'      => 'Kaksoset',
        'cancer'      => 'Rapu',
        'leo'         => 'Leijona',
        'virgo'       => 'Neitsyt',
        'libra'       => 'Vaaka',
        'scorpio'     => 'Skorpioni',
        'sagittarius' => 'Jousimies',
        'capricorn'   => 'Kauris',
        'aquarius'    => 'Vesimies',
        'pisces'      => 'Kalat',
    ),
    'he' => array(
        'aries'       => 'טלה',
        'taurus'      => 'שור',
        'gemini'      => 'תאומים',
        'cancer'      => 'סרטן',
        'leo'         => 'אריה',
        'virgo'       => 'בתולה',
        'libra'       => 'מאזניים',
        'scorpio'     => 'עקרב',
        'sagittarius' => 'קשת',
        'capricorn'   => 'גדי',
        'aquarius'    => 'דלי',
        'pisces'      => 'דגים',
    ),
    'hi' => array(
        'aries'       => 'मेष',
        'taurus'      => 'वृषभ',
        'gemini'      => 'मिथुन',
        'cancer'      => 'कर्क',
        'leo'         => 'सिंह',
        'virgo'       => 'कन्या',
        'libra'       => 'तुला',
        'scorpio'     => 'वृश्चिक',
        'sagittarius' => 'धनु',
        'capricorn'   => 'मकर',
        'aquarius'    => 'कुम्भ',
        'pisces'      => 'मीन',
    ),
    'hu' => array(
        'aries'       => 'Kos',
        'taurus'      => 'Bika',
        'gemini'      => 'Ikrek',
        'cancer'      => 'Rák',
        'leo'         => 'Oroszlán',
        'virgo'       => 'Szűz',
        'libra'       => 'Mérleg',
        'scorpio'     => 'Skorpió',
        'sagittarius' => 'Nyilas',
        'capricorn'   => 'Bak',
        'aquarius'    => 'Vízöntő',
        'pisces'      => 'Halak',
    ),
    'id' => array(
        'aries'       => 'Aries',
        'taurus'      => 'Taurus',
        'gemini'      => 'Gemini',
        'cancer'      => 'Cancer',
        'leo'         => 'Leo',
        'virgo'       => 'Virgo',
        'libra'       => 'Libra',
        'scorpio'     => 'Scorpio',
        'sagittarius' => 'Sagitarius',
        'capricorn'   => 'Capricorn',
        'aquarius'    => 'Aquarius',
        'pisces'      => 'Pisces',
    ),
    'ja' => array(
        'aries'       => '牡羊座',
        'taurus'      => '牡牛座',
        'gemini'      => '双子座',
        'cancer'      => '蟹座',
        'leo'         => '獅子座',
        'virgo'       => '乙女座',
        'libra'       => '天秤座',
        'scorpio'     => '蠍座',
        'sagittarius' => '射手座',
        'capricorn'   => '山羊座',
        'aquarius'    => '水瓶座',
        'pisces'      => '魚座',
    ),
    'ko' => array(
        'aries'       => '양자리',
        'taurus'      => '황소자리',
        'gemini'      => '쌍둥이자리',
        'cancer'      => '게자리',
        'leo'         => '사자자리',
        'virgo'       => '처녀자리',
        'libra'       => '천칭자리',
        'scorpio'     => '전갈자리',
        'sagittarius' => '궁수자리',
        'capricorn'   => '염소자리',
        'aquarius'    => '물병자리',
        'pisces'      => '물고기자리',
    ),
    'lt' => array(
        'aries'       => 'Avinas',
        'taurus'      => 'Jautis',
        'gemini'      => 'Dvyniai',
        'cancer'      => 'Vėžys',
        'leo'         => 'Liūtas',
        'virgo'       => 'Mergelė',
        'libra'       => 'Svarstyklės',
        'scorpio'     => 'Skorpionas',
        'sagittarius' => 'Šaulys',
        'capricorn'   => 'Ožiaragis',
        'aquarius'    => 'Vandenis',
        'pisces'      => 'Žuvys',
    ),
    'lv' => array(
        'aries'       => 'Auns',
        'taurus'      => 'Vērsis',
        'gemini'      => 'Dvīņi',
        'cancer'      => 'Vēzis',
        'leo'         => 'Lauva',
        'virgo'       => 'Jaunava',
        'libra'       => 'Svari',
        'scorpio'     => 'Skorpions',
        'sagittarius' => 'Strēlnieks',
        'capricorn'   => 'Mežāzis',
        'aquarius'    => 'Ūdensvīrs',
        'pisces'      => 'Zivis',
    ),
    'ms' => array(
        'aries'       => 'Aries',
        'taurus'      => 'Taurus',
        'gemini'      => 'Gemini',
        'cancer'      => 'Kanser',
        'leo'         => 'Leo',
        'virgo'       => 'Virgo',
        'libra'       => 'Libra',
        'scorpio'     => 'Skorpio',
        'sagittarius' => 'Sagitarius',
        'capricorn'   => 'Kaprikorn',
        'aquarius'    => 'Akuarius',
        'pisces'      => 'Pisces',
    ),
    'nb' => array(
        'aries'       => 'Væren',
        'taurus'      => 'Tyren',
        'gemini'      => 'Tvillingene',
        'cancer'      => 'Krepsen',
        'leo'         => 'Løven',
        'virgo'       => 'Jomfruen',
        'libra'       => 'Vekten',
        'scorpio'     => 'Skorpionen',
        'sagittarius' => 'Skytten',
        'capricorn'   => 'Steinbukken',
        'aquarius'    => 'Vannmannen',
        'pisces'      => 'Fiskene',
    ),
    'nl' => array(
        'aries'       => 'Ram',
        'taurus'      => 'Stier',
        'gemini'      => 'Tweelingen',
        'cancer'      => 'Kreeft',
        'leo'         => 'Leeuw',
        'virgo'       => 'Maagd',
        'libra'       => 'Weegschaal',
        'scorpio'     => 'Schorpioen',
        'sagittarius' => 'Boogschutter',
        'capricorn'   => 'Steenbok',
        'aquarius'    => 'Waterman',
        'pisces'      => 'Vissen',
    ),
    'pl' => array(
        'aries'       => 'Baran',
        'taurus'      => 'Byk',
        'gemini'      => 'Bliźnięta',
        'cancer'      => 'Rak',
        'leo'         => 'Lew',
        'virgo'       => 'Panna',
        'libra'       => 'Waga',
        'scorpio'     => 'Skorpion',
        'sagittarius' => 'Strzelec',
        'capricorn'   => 'Koziorożec',
        'aquarius'    => 'Wodnik',
        'pisces'      => 'Ryby',
    ),
    'pt' => array(
        'aries'       => 'Áries',
        'taurus'      => 'Touro',
        'gemini'      => 'Gémeos',
        'cancer'      => 'Caranguejo',
        'leo'         => 'Leão',
        'virgo'       => 'Virgem',
        'libra'       => 'Balança',
        'scorpio'     => 'Escorpião',
        'sagittarius' => 'Sagitário',
        'capricorn'   => 'Capricórnio',
        'aquarius'    => 'Aquário',
        'pisces'      => 'Peixes',
    ),
    'ro' => array(
        'aries'       => 'Berbec',
        'taurus'      => 'Taur',
        'gemini'      => 'Gemeni',
        'cancer'      => 'Rac',
        'leo'         => 'Leu',
        'virgo'       => 'Fecioară',
        'libra'       => 'Balanță',
        'scorpio'     => 'Scorpion',
        'sagittarius' => 'Săgetător',
        'capricorn'   => 'Capricorn',
        'aquarius'    => 'Vărsător',
        'pisces'      => 'Pești',
    ),
    'ru' => array(
        'aries'       => 'Овен',
        'taurus'      => 'Телец',
        'gemini'      => 'Близнецы',
        'cancer'      => 'Рак',
        'leo'         => 'Лев',
        'virgo'       => 'Дева',
        'libra'       => 'Весы',
        'scorpio'     => 'Скорпион',
        'sagittarius' => 'Стрелец',
        'capricorn'   => 'Козерог',
        'aquarius'    => 'Водолей',
        'pisces'      => 'Рыбы',
    ),
    'sq' => array(
        'aries'       => 'Dashi',
        'taurus'      => 'Demi',
        'gemini'      => 'Binjakët',
        'cancer'      => 'Gaforrja',
        'leo'         => 'Luani',
        'virgo'       => 'Virgjëresha',
        'libra'       => 'Peshorja',
        'scorpio'     => 'Akrepi',
        'sagittarius' => 'Shigjetari',
        'capricorn'   => 'Bricjapi',
        'aquarius'    => 'Ujori',
        'pisces'      => 'Peshqit',
    ),
    'sv' => array(
        'aries'       => 'Väduren',
        'taurus'      => 'Oxen',
        'gemini'      => 'Tvillingarna',
        'cancer'      => 'Kräftan',
        'leo'         => 'Lejonet',
        'virgo'       => 'Jungfrun',
        'libra'       => 'Vågen',
        'scorpio'     => 'Skorpionen',
        'sagittarius' => 'Skytten',
        'capricorn'   => 'Stenbocken',
        'aquarius'    => 'Vattumannen',
        'pisces'      => 'Fiskarna',
    ),
    'th' => array(
        'aries'       => 'ราศีเมษ',
        'taurus'      => 'ราศีพฤษภ',
        'gemini'      => 'ราศีเมถุน',
        'cancer'      => 'ราศีกรกฎ',
        'leo'         => 'ราศีสิงห์',
        'virgo'       => 'ราศีกันย์',
        'libra'       => 'ราศีตุลย์',
        'scorpio'     => 'ราศีพิจิก',
        'sagittarius' => 'ราศีธนู',
        'capricorn'   => 'ราศีมังกร',
        'aquarius'    => 'ราศีกุมภ์',
        'pisces'      => 'ราศีมีน',
    ),
    'tl' => array(
        'aries'       => 'Aries',
        'taurus'      => 'Taurus',
        'gemini'      => 'Gemini',
        'cancer'      => 'Cancer',
        'leo'         => 'Leo',
        'virgo'       => 'Virgo',
        'libra'       => 'Libra',
        'scorpio'     => 'Scorpio',
        'sagittarius' => 'Sagittarius',
        'capricorn'   => 'Capricorn',
        'aquarius'    => 'Aquarius',
        'pisces'      => 'Pisces',
    ),
    'tr' => array(
        'aries'       => 'Koç',
        'taurus'      => 'Boğa',
        'gemini'      => 'İkizler',
        'cancer'      => 'Yengeç',
        'leo'         => 'Aslan',
        'virgo'       => 'Başak',
        'libra'       => 'Terazi',
        'scorpio'     => 'Akrep',
        'sagittarius' => 'Yay',
        'capricorn'   => 'Oğlak',
        'aquarius'    => 'Kova',
        'pisces'      => 'Balık',
    ),
    'uk' => array(
        'aries'       => 'Овен',
        'taurus'      => 'Телець',
        'gemini'      => 'Близнюки',
        'cancer'      => 'Рак',
        'leo'         => 'Лев',
        'virgo'       => 'Діва',
        'libra'       => 'Терези',
        'scorpio'     => 'Скорпіон',
        'sagittarius' => 'Стрілець',
        'capricorn'   => 'Козеріг',
        'aquarius'    => 'Водолій',
        'pisces'      => 'Риби',
    ),
    'ur' => array(
        'aries'       => 'برج حمل',
        'taurus'      => 'برج ثور',
        'gemini'      => 'برج جوزا',
        'cancer'      => 'برج سرطان',
        'leo'         => 'برج اسد',
        'virgo'       => 'برج سنبلہ',
        'libra'       => 'برج میزان',
        'scorpio'     => 'برج عقرب',
        'sagittarius' => 'برج قوس',
        'capricorn'   => 'برج جدی',
        'aquarius'    => 'برج دلو',
        'pisces'      => 'برج حوت',
    ),
    'eo' => array(
        'aries'       => 'Ŝafo',
        'taurus'      => 'Taŭro',
        'gemini'      => 'Ĝemeloj',
        'cancer'      => 'Kankro',
        'leo'         => 'Leono',
        'virgo'       => 'Virgulino',
        'libra'       => 'Pesilo',
        'scorpio'     => 'Skorpio',
        'sagittarius' => 'Sagitario',
        'capricorn'   => 'Kaprikorno',
        'aquarius'    => 'Akvario',
        'pisces'      => 'Fiŝoj',
    ),
    'ga' => array(
        'aries'       => 'An Reithe',
        'taurus'      => 'An Tarbh',
        'gemini'      => 'Na Cúpla',
        'cancer'      => 'An Portán',
        'leo'         => 'An Leon',
        'virgo'       => 'An Mhaighdean',
        'libra'       => 'An Mheá',
        'scorpio'     => 'An Scairp',
        'sagittarius' => 'An Saighdeoir',
        'capricorn'   => 'An Gabhar',
        'aquarius'    => 'An tUisceadóir',
        'pisces'      => 'Na hÉisc',
    ),
    'gl' => array(
        'aries'       => 'Aries',
        'taurus'      => 'Tauro',
        'gemini'      => 'Xémini',
        'cancer'      => 'Cancro',
        'leo'         => 'Leo',
        'virgo'       => 'Virgo',
        'libra'       => 'Libra',
        'scorpio'     => 'Escorpión',
        'sagittarius' => 'Saxitario',
        'capricorn'   => 'Capricornio',
        'aquarius'    => 'Acuario',
        'pisces'      => 'Piscis',
    ),
    'az' => array(
        'aries'       => 'Qoç',
        'taurus'      => 'Buğa',
        'gemini'      => 'Əkizlər',
        'cancer'      => 'Xərçəng',
        'leo'         => 'Şir',
        'virgo'       => 'Qız',
        'libra'       => 'Tərəzi',
        'scorpio'     => 'Əqrəb',
        'sagittarius' => 'Oxatan',
        'capricorn'   => 'Oğlaq',
        'aquarius'    => 'Dolça',
        'pisces'      => 'Balıqlar',
    ),
    'bg' => array(
        'aries'       => 'Овен',
        'taurus'      => 'Телец',
        'gemini'      => 'Близнаци',
        'cancer'      => 'Рак',
        'leo'         => 'Лъв',
        'virgo'       => 'Дева',
        'libra'       => 'Везни',
        'scorpio'     => 'Скорпион',
        'sagittarius' => 'Стрелец',
        'capricorn'   => 'Козирог',
        'aquarius'    => 'Водолей',
        'pisces'      => 'Риби',
    ),
    'ca' => array(
        'aries'       => 'Àries',
        'taurus'      => 'Taure',
        'gemini'      => 'Bessons',
        'cancer'      => 'Cranc',
        'leo'         => 'Lleó',
        'virgo'       => 'Verge',
        'libra'       => 'Balança',
        'scorpio'     => 'Escorpí',
        'sagittarius' => 'Sagitari',
        'capricorn'   => 'Capricorn',
        'aquarius'    => 'Aquari',
        'pisces'      => 'Peixos',
    ),
    'sk' => array(
        'aries'       => 'Baran',
        'taurus'      => 'Býk',
        'gemini'      => 'Blíženci',
        'cancer'      => 'Rak',
        'leo'         => 'Lev',
        'virgo'       => 'Panna',
        'libra'       => 'Váhy',
        'scorpio'     => 'Škorpión',
        'sagittarius' => 'Strelec',
        'capricorn'   => 'Kozorožec',
        'aquarius'    => 'Vodnár',
        'pisces'      => 'Ryby',
    ),
    'sl' => array(
        'aries'       => 'Oven',
        'taurus'      => 'Bik',
        'gemini'      => 'Dvojčka',
        'cancer'      => 'Rak',
        'leo'         => 'Lev',
        'virgo'       => 'Devica',
        'libra'       => 'Tehtnica',
        'scorpio'     => 'Škorpijon',
        'sagittarius' => 'Strelec',
        'capricorn'   => 'Kozorog',
        'aquarius'    => 'Vodnar',
        'pisces'      => 'Ribi',
    ),
    'zh' => array(
        'aries'       => '白羊座',
        'taurus'      => '金牛座',
        'gemini'      => '双子座',
        'cancer'      => '巨蟹座',
        'leo'         => '狮子座',
        'virgo'       => '处女座',
        'libra'       => '天秤座',
        'scorpio'     => '天蝎座',
        'sagittarius' => '射手座',
        'capricorn'   => '摩羯座',
        'aquarius'    => '水瓶座',
        'pisces'      => '双鱼座',
    ),
);
// "Select your sign" translations
$ezhp_select_translations = array(
    'en' => 'Select your sign',
    'fr' => 'Sélectionnez votre signe',
    'it' => 'Seleziona il tuo segno',
    'de' => 'Wählen Sie Ihr Zeichen',
    'es' => 'Selecciona tu signo',
    'ar' => 'اختر برجك',
    'bn' => 'আপনার রাশি নির্বাচন করুন',
    'cs' => 'Vyberte své znamení',
    'da' => 'Vælg dit tegn',
    'el' => 'Επιλέξτε το ζώδιό σας',
    'et' => 'Valige oma märk',
    'eu' => 'Hautatu zure zeinua',
    'fa' => 'برج خود را انتخاب کنید',
    'fi' => 'Valitse merkkisi',
    'he' => 'בחר את המזל שלך',
    'hi' => 'अपनी राशि चुनें',
    'hu' => 'Válaszd ki a jegyedet',
    'id' => 'Pilih tanda Anda',
    'ja' => 'あなたの星座を選択してください',
    'ko' => '당신의 별자리를 선택하세요',
    'lt' => 'Pasirinkite savo ženklą',
    'lv' => 'Izvēlieties savu zīmi',
    'ms' => 'Pilih tanda anda',
    'nb' => 'Velg ditt tegn',
    'nl' => 'Selecteer uw teken',
    'pl' => 'Wybierz swój znak',
    'pt' => 'Selecione seu signo',
    'ro' => 'Selectați semnul dvs',
    'ru' => 'Выберите свой знак',
    'sq' => 'Zgjidhni shenjën tuaj',
    'sv' => 'Välj ditt tecken',
    'th' => 'เลือกราศีของคุณ',
    'tl' => 'Piliin ang iyong tanda',
    'tr' => 'Burcunuzu seçin',
    'uk' => 'Виберіть свій знак',
    'ur' => 'اپنا برج منتخب کریں',
    'eo' => 'Elektu vian signon',
    'ga' => 'Roghnaigh do chomhartha',
    'gl' => 'Selecciona o teu signo',
    'az' => 'Bürcünüzü seçin',
    'bg' => 'Изберете вашия знак',
    'ca' => 'Selecciona el teu signe',
    'sk' => 'Vyberte si svoje znamenie',
    'sl' => 'Izberite svoj znak',
    'zh' => '选择你的星座',
);
// Build cache key
$ezhp_cache_key = 'ezhp_moon_phase_' . md5( $ezhp_language . '_' . $ezhp_image_size . '_' . wp_json_encode( $ezhp_moon_images ) . '_' . (( $ezhp_cta_enabled ? '1' : '0' )) . '_' . $ezhp_cta_text . '_' . $ezhp_cta_url );
// Don't use cache in editor (REST API context)
$ezhp_is_rest = defined( 'REST_REQUEST' ) && REST_REQUEST;
// Try cached data (only on frontend)
if ( !$ezhp_is_rest ) {
    $ezhp_cached = get_transient( $ezhp_cache_key );
    if ( $ezhp_cached && !str_contains( $ezhp_cached, 'error' ) ) {
        echo wp_kses( $ezhp_cached, $ezhp_allowed_html );
        return;
    }
}
// Fetch moon phase from API
$ezhp_api_url = sprintf( 'https://api.ezhoroscope.com/api/Astrology/moon-phase-in-zodiac?apikey=%s&lang=%s', rawurlencode( $ezhp_api_key ), rawurlencode( $ezhp_language ) );
$ezhp_response = wp_remote_get( $ezhp_api_url, array(
    'timeout' => 20,
    'headers' => array(
        'Accept' => 'application/json',
    ),
) );
if ( is_wp_error( $ezhp_response ) ) {
    echo '<div class="ez-moon-phase-error">' . esc_html__( 'Unable to retrieve moon phase at this time.', 'ez-horoscope' ) . '</div>';
    return;
}
$ezhp_body = wp_remote_retrieve_body( $ezhp_response );
$ezhp_data = json_decode( $ezhp_body, true );
if ( empty( $ezhp_data ) || !isset( $ezhp_data['lunarPhase'] ) ) {
    echo '<div class="ez-moon-phase-error">' . esc_html__( 'No moon phase data available.', 'ez-horoscope' ) . '</div>';
    return;
}
$ezhp_lunar_phase_full = $ezhp_data['lunarPhase'];
$ezhp_lunar_phase_english = $ezhp_data['englishLunarPhase'] ?? $ezhp_lunar_phase_full;
// Parse moon phase name from string like "Full Moon and is a Hunter's Moon (Super Moon) in Aries"
$ezhp_phase_patterns = array(
    'new moon'        => '/\\bnew moon\\b/i',
    'waxing crescent' => '/\\bwaxing crescent\\b/i',
    'first quarter'   => '/\\bfirst quarter\\b/i',
    'waxing gibbous'  => '/\\bwaxing gibbous\\b/i',
    'full moon'       => '/\\bfull moon\\b/i',
    'waning gibbous'  => '/\\bwaning gibbous\\b/i',
    'last quarter'    => '/\\blast quarter\\b/i',
    'waning crescent' => '/\\bwaning crescent\\b/i',
);
$ezhp_detected_phase = 'full moon';
// Default fallback
foreach ( $ezhp_phase_patterns as $ezhp_phase_key => $ezhp_pattern ) {
    if ( preg_match( $ezhp_pattern, $ezhp_lunar_phase_english ) ) {
        $ezhp_detected_phase = $ezhp_phase_key;
        break;
    }
}
// Determine image to display
$ezhp_moon_image_url = '';
if ( !empty( $ezhp_moon_images[$ezhp_detected_phase] ) ) {
    $ezhp_moon_image_url = $ezhp_moon_images[$ezhp_detected_phase];
} elseif ( !empty( $ezhp_default_images[$ezhp_detected_phase] ) ) {
    $ezhp_moon_image_url = $ezhp_default_images[$ezhp_detected_phase];
}
// Get translations for current language
$ezhp_zodiac_labels = $ezhp_zodiac_translations[$ezhp_language] ?? $ezhp_zodiac_translations['en'];
$ezhp_select_label = $ezhp_select_translations[$ezhp_language] ?? $ezhp_select_translations['en'];
// Build output with CTA data attributes
$ezhp_output = '<div class="ez-moon-phase-widget"';
if ( $ezhp_is_rtl ) {
    $ezhp_output .= ' dir="rtl"';
}
$ezhp_output .= ' data-language="' . esc_attr( $ezhp_language ) . '"';
$ezhp_output .= ' data-apikey="' . esc_attr( $ezhp_api_key ) . '"';
$ezhp_output .= ' data-cta-enabled="' . (( $ezhp_cta_enabled ? 'true' : 'false' )) . '"';
$ezhp_output .= ' data-cta-text="' . esc_attr( $ezhp_cta_text ) . '"';
$ezhp_output .= ' data-cta-image-url="' . esc_attr( $ezhp_cta_image_url ) . '"';
$ezhp_output .= ' data-cta-image-alt="' . esc_attr( $ezhp_cta_image_alt ) . '"';
$ezhp_output .= ' data-cta-url="' . esc_attr( $ezhp_cta_url ) . '"';
$ezhp_output .= ' data-cta-link-type="' . esc_attr( $ezhp_cta_link_type ) . '"';
$ezhp_output .= ' data-cta-link-text="' . esc_attr( $ezhp_cta_link_text ) . '"';
$ezhp_output .= ' data-cta-image-clickable="' . (( $ezhp_cta_image_clickable ? 'true' : 'false' )) . '"';
$ezhp_output .= ' data-cta-element-id="' . esc_attr( $ezhp_cta_element_id ) . '"';
$ezhp_output .= '>';
// Moon phase display
$ezhp_output .= '<div class="ez-moon-phase-display">';
if ( !empty( $ezhp_moon_image_url ) ) {
    $ezhp_output .= '<img src="' . esc_url( $ezhp_moon_image_url ) . '" alt="' . esc_attr( ucwords( $ezhp_detected_phase ) ) . '" class="ez-moon-phase-image" style="width:' . esc_attr( $ezhp_image_size ) . 'px;height:' . esc_attr( $ezhp_image_size ) . 'px;">';
} else {
    $ezhp_output .= '<span class="ez-moon-phase-emoji">' . esc_html( $ezhp_emoji_fallbacks[$ezhp_detected_phase] ) . '</span>';
}
$ezhp_output .= '<p class="ez-moon-phase-text">' . esc_html( $ezhp_lunar_phase_full ) . '</p>';
$ezhp_output .= '</div>';
// Zodiac dropdown
$ezhp_output .= '<div class="ez-moon-phase-zodiac-select">';
$ezhp_output .= '<select class="ez-moon-zodiac-dropdown" aria-label="' . esc_attr( $ezhp_select_label ) . '">';
$ezhp_output .= '<option value="">' . esc_html( $ezhp_select_label ) . '</option>';
foreach ( $ezhp_zodiac_signs as $ezhp_sign_key => $ezhp_sign_emoji ) {
    $ezhp_sign_label = $ezhp_zodiac_labels[$ezhp_sign_key] ?? ucfirst( $ezhp_sign_key );
    $ezhp_output .= '<option value="' . esc_attr( $ezhp_sign_key ) . '">' . esc_html( $ezhp_sign_emoji . ' ' . $ezhp_sign_label ) . '</option>';
}
$ezhp_output .= '</select>';
$ezhp_output .= '</div>';
// Moon content container (populated via AJAX)
$ezhp_output .= '<div class="ez-moon-content-container">';
$ezhp_output .= '<div class="ez-moon-content-result"></div>';
$ezhp_output .= '</div>';
$ezhp_output .= '</div>';
// Cache successful response
if ( !empty( $ezhp_lunar_phase_full ) ) {
    set_transient( $ezhp_cache_key, $ezhp_output, HOUR_IN_SECONDS );
}
echo wp_kses( $ezhp_output, $ezhp_allowed_html );