<?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 = __DIR__ . '/flags/' . $code . '.svg';
		if ( file_exists( $file ) ) {
			$svg = file_get_contents( $file );
			$svg = str_replace( '<svg', '<svg class="volade-flag"', $svg );
			return $svg;
		}
		$file = __DIR__ . '/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( __DIR__ . '/' . $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', 'core-version-switcher-by-volade' ),
			'EN' => __( 'United Kingdom', 'core-version-switcher-by-volade' ),
			'US' => __( 'United States', 'core-version-switcher-by-volade' ),
			'ES' => __( 'Spain', 'core-version-switcher-by-volade' ),
			'PT' => __( 'Portugal', 'core-version-switcher-by-volade' ),
			'DE' => __( 'Germany', 'core-version-switcher-by-volade' ),
			'IT' => __( 'Italy', 'core-version-switcher-by-volade' ),
			'CH' => __( 'Switzerland', 'core-version-switcher-by-volade' ),
			'SE' => __( 'Sweden', 'core-version-switcher-by-volade' ),
			'NO' => __( 'Norway', 'core-version-switcher-by-volade' ),
			'NL' => __( 'Netherlands', 'core-version-switcher-by-volade' ),
			'BE' => __( 'Belgium', 'core-version-switcher-by-volade' ),
			'AT' => __( 'Austria', 'core-version-switcher-by-volade' ),
			'DK' => __( 'Denmark', 'core-version-switcher-by-volade' ),
			'FI' => __( 'Finland', 'core-version-switcher-by-volade' ),
			'PL' => __( 'Poland', 'core-version-switcher-by-volade' ),
			'CZ' => __( 'Czech Republic', 'core-version-switcher-by-volade' ),
			'JP' => __( 'Japan', 'core-version-switcher-by-volade' ),
			'KR' => __( 'South Korea', 'core-version-switcher-by-volade' ),
			'CN' => __( 'China', 'core-version-switcher-by-volade' ),
			'IN' => __( 'India', 'core-version-switcher-by-volade' ),
			'BR' => __( 'Brazil', 'core-version-switcher-by-volade' ),
			'MX' => __( 'Mexico', 'core-version-switcher-by-volade' ),
			'CO' => __( 'Colombia', 'core-version-switcher-by-volade' ),
			'PE' => __( 'Peru', 'core-version-switcher-by-volade' ),
			'CL' => __( 'Chile', 'core-version-switcher-by-volade' ),
			'AR' => __( 'Argentina', 'core-version-switcher-by-volade' ),
			'EG' => __( 'Egypt', 'core-version-switcher-by-volade' ),
			'MA' => __( 'Morocco', 'core-version-switcher-by-volade' ),
			'DZ' => __( 'Algeria', 'core-version-switcher-by-volade' ),
			'TN' => __( 'Tunisia', 'core-version-switcher-by-volade' ),
			'SN' => __( 'Senegal', 'core-version-switcher-by-volade' ),
			'CI' => __( 'Ivory Coast', 'core-version-switcher-by-volade' ),
			'NG' => __( 'Nigeria', 'core-version-switcher-by-volade' ),
			'KE' => __( 'Kenya', 'core-version-switcher-by-volade' ),
			'ZA' => __( 'South Africa', 'core-version-switcher-by-volade' ),
			'TH' => __( 'Thailand', 'core-version-switcher-by-volade' ),
			'VN' => __( 'Vietnam', 'core-version-switcher-by-volade' ),
			'PH' => __( 'Philippines', 'core-version-switcher-by-volade' ),
			'ID' => __( 'Indonesia', 'core-version-switcher-by-volade' ),
			'MY' => __( 'Malaysia', 'core-version-switcher-by-volade' ),
			'SG' => __( 'Singapore', 'core-version-switcher-by-volade' ),
			'AE' => __( 'United Arab Emirates', 'core-version-switcher-by-volade' ),
			'SA' => __( 'Saudi Arabia', 'core-version-switcher-by-volade' ),
			'TR' => __( 'Turkey', 'core-version-switcher-by-volade' ),
			'IL' => __( 'Israel', 'core-version-switcher-by-volade' ),
			'AU' => __( 'Australia', 'core-version-switcher-by-volade' ),
			'NZ' => __( 'New Zealand', 'core-version-switcher-by-volade' ),
			'CA' => __( 'Canada', 'core-version-switcher-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;
	}
}
