<?php
/**
 * Volade i18n — Traductions multilingues + drapeaux SVG
 *
 * @package Volade\SDK
 * @license GPL-2.0-or-later
 */

trait Volade_I18n {

    private $countries = array();

    public function get_flag_svg( $country_code ) {
        $code = strtolower( $country_code );
        $file = dirname( __FILE__ ) . '/flags/' . $code . '.svg';
        if ( file_exists( $file ) ) {
            $svg = file_get_contents( $file );
            $svg = str_replace( '<svg', '<svg class="volade-flag"', $svg );
            return $svg;
        }
        $file = dirname( __FILE__ ) . '/flags/_default.svg';
        if ( file_exists( $file ) ) {
            return file_get_contents( $file );
        }
        return '<span class="volade-flag-missing">' . strtoupper( $code ) . '</span>';
    }

    public function get_flag_url( $country_code ) {
        $code = strtolower( $country_code );
        $file = 'flags/' . $code . '.svg';
        if ( file_exists( dirname( __FILE__ ) . '/' . $file ) ) {
            $url = $this->get_url() . 'flags/' . $code . '.svg';
            return esc_url( $url );
        }
        return '';
    }

    public function get_country_name( $country_code ) {
        $names = $this->get_country_names();
        $code = strtoupper( $country_code );
        return isset( $names[ $code ] ) ? $names[ $code ] : $code;
    }

    public function get_country_names() {
        return array(
            'FR' => __( 'France', 'php-compatibility-checker-by-volade' ),
            'EN' => __( 'United Kingdom', 'php-compatibility-checker-by-volade' ),
            'US' => __( 'United States', 'php-compatibility-checker-by-volade' ),
            'ES' => __( 'Spain', 'php-compatibility-checker-by-volade' ),
            'PT' => __( 'Portugal', 'php-compatibility-checker-by-volade' ),
            'DE' => __( 'Germany', 'php-compatibility-checker-by-volade' ),
            'IT' => __( 'Italy', 'php-compatibility-checker-by-volade' ),
            'CH' => __( 'Switzerland', 'php-compatibility-checker-by-volade' ),
            'SE' => __( 'Sweden', 'php-compatibility-checker-by-volade' ),
            'NO' => __( 'Norway', 'php-compatibility-checker-by-volade' ),
            'NL' => __( 'Netherlands', 'php-compatibility-checker-by-volade' ),
            'BE' => __( 'Belgium', 'php-compatibility-checker-by-volade' ),
            'AT' => __( 'Austria', 'php-compatibility-checker-by-volade' ),
            'DK' => __( 'Denmark', 'php-compatibility-checker-by-volade' ),
            'FI' => __( 'Finland', 'php-compatibility-checker-by-volade' ),
            'PL' => __( 'Poland', 'php-compatibility-checker-by-volade' ),
            'CZ' => __( 'Czech Republic', 'php-compatibility-checker-by-volade' ),
            'JP' => __( 'Japan', 'php-compatibility-checker-by-volade' ),
            'KR' => __( 'South Korea', 'php-compatibility-checker-by-volade' ),
            'CN' => __( 'China', 'php-compatibility-checker-by-volade' ),
            'IN' => __( 'India', 'php-compatibility-checker-by-volade' ),
            'BR' => __( 'Brazil', 'php-compatibility-checker-by-volade' ),
            'MX' => __( 'Mexico', 'php-compatibility-checker-by-volade' ),
            'CO' => __( 'Colombia', 'php-compatibility-checker-by-volade' ),
            'PE' => __( 'Peru', 'php-compatibility-checker-by-volade' ),
            'CL' => __( 'Chile', 'php-compatibility-checker-by-volade' ),
            'AR' => __( 'Argentina', 'php-compatibility-checker-by-volade' ),
            'EG' => __( 'Egypt', 'php-compatibility-checker-by-volade' ),
            'MA' => __( 'Morocco', 'php-compatibility-checker-by-volade' ),
            'DZ' => __( 'Algeria', 'php-compatibility-checker-by-volade' ),
            'TN' => __( 'Tunisia', 'php-compatibility-checker-by-volade' ),
            'SN' => __( 'Senegal', 'php-compatibility-checker-by-volade' ),
            'CI' => __( 'Ivory Coast', 'php-compatibility-checker-by-volade' ),
            'NG' => __( 'Nigeria', 'php-compatibility-checker-by-volade' ),
            'KE' => __( 'Kenya', 'php-compatibility-checker-by-volade' ),
            'ZA' => __( 'South Africa', 'php-compatibility-checker-by-volade' ),
            'TH' => __( 'Thailand', 'php-compatibility-checker-by-volade' ),
            'VN' => __( 'Vietnam', 'php-compatibility-checker-by-volade' ),
            'PH' => __( 'Philippines', 'php-compatibility-checker-by-volade' ),
            'ID' => __( 'Indonesia', 'php-compatibility-checker-by-volade' ),
            'MY' => __( 'Malaysia', 'php-compatibility-checker-by-volade' ),
            'SG' => __( 'Singapore', 'php-compatibility-checker-by-volade' ),
            'AE' => __( 'United Arab Emirates', 'php-compatibility-checker-by-volade' ),
            'SA' => __( 'Saudi Arabia', 'php-compatibility-checker-by-volade' ),
            'TR' => __( 'Turkey', 'php-compatibility-checker-by-volade' ),
            'IL' => __( 'Israel', 'php-compatibility-checker-by-volade' ),
            'AU' => __( 'Australia', 'php-compatibility-checker-by-volade' ),
            'NZ' => __( 'New Zealand', 'php-compatibility-checker-by-volade' ),
            'CA' => __( 'Canada', 'php-compatibility-checker-by-volade' ),
        );
    }

    public function get_locale() {
        return determine_locale();
    }

    public function get_available_locales() {
        return array( 'en_US', 'fr_FR', 'es_ES', 'de_DE', 'pt_BR', 'it_IT' );
    }

    public function get_locale_label( $locale ) {
        $labels = array(
            'en_US' => 'English (US)',
            'fr_FR' => 'Français (France)',
            'es_ES' => 'Español (España)',
            'de_DE' => 'Deutsch (Deutschland)',
            'pt_BR' => 'Português (Brasil)',
            'it_IT' => 'Italiano (Italia)',
        );
        return isset( $labels[ $locale ] ) ? $labels[ $locale ] : $locale;
    }
}
