<?php
/**
 * This file is part of the Wisewand WordPress plugin.
 *
 * @package Wisewand
 * @since 2.8.0
 * @license GPL-2.0-or-later
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
 */
namespace Wisewand\Config;

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class Supported_Options {

	/**
	 * Get all supported languages
	 *
	 * @return array Language code => array with name, native, flag
	 */
	public static function get_languages() {
		return array(
			'en' => array(
				'name'   => 'English',
				'native' => 'English',
				'flag'   => "\xF0\x9F\x87\xBA\xF0\x9F\x87\xB8",
			),
			'fr' => array(
				'name'   => 'French',
				'native' => "Fran\xC3\xA7ais",
				'flag'   => "\xF0\x9F\x87\xAB\xF0\x9F\x87\xB7",
			),
			'de' => array(
				'name'   => 'German',
				'native' => 'Deutsch',
				'flag'   => "\xF0\x9F\x87\xA9\xF0\x9F\x87\xAA",
			),
			'es' => array(
				'name'   => 'Spanish',
				'native' => "Espa\xC3\xB1ol",
				'flag'   => "\xF0\x9F\x87\xAA\xF0\x9F\x87\xB8",
			),
			'it' => array(
				'name'   => 'Italian',
				'native' => 'Italiano',
				'flag'   => "\xF0\x9F\x87\xAE\xF0\x9F\x87\xB9",
			),
			'nl' => array(
				'name'   => 'Dutch',
				'native' => 'Nederlands',
				'flag'   => "\xF0\x9F\x87\xB3\xF0\x9F\x87\xB1",
			),
			'pl' => array(
				'name'   => 'Polish',
				'native' => 'Polski',
				'flag'   => "\xF0\x9F\x87\xB5\xF0\x9F\x87\xB1",
			),
			'pt' => array(
				'name'   => 'Portuguese',
				'native' => "Portugu\xC3\xAAs",
				'flag'   => "\xF0\x9F\x87\xB5\xF0\x9F\x87\xB9",
			),
			'ro' => array(
				'name'   => 'Romanian',
				'native' => "Rom\xC3\xA2n\xC4\x83",
				'flag'   => "\xF0\x9F\x87\xB7\xF0\x9F\x87\xB4",
			),
		);
	}

	/**
	 * Get language codes only
	 *
	 * @return array
	 */
	public static function get_language_codes() {
		return array_keys( self::get_languages() );
	}

	/**
	 * Get all supported countries
	 *
	 * @return array Country code => array with name, flag
	 */
	public static function get_countries() {
		return array(
			'us' => array(
				'name' => 'United States',
				'flag' => "\xF0\x9F\x87\xBA\xF0\x9F\x87\xB8",
			),
			'gb' => array(
				'name' => 'United Kingdom',
				'flag' => "\xF0\x9F\x87\xAC\xF0\x9F\x87\xA7",
			),
			'fr' => array(
				'name' => 'France',
				'flag' => "\xF0\x9F\x87\xAB\xF0\x9F\x87\xB7",
			),
			'de' => array(
				'name' => 'Germany',
				'flag' => "\xF0\x9F\x87\xA9\xF0\x9F\x87\xAA",
			),
			'es' => array(
				'name' => 'Spain',
				'flag' => "\xF0\x9F\x87\xAA\xF0\x9F\x87\xB8",
			),
			'it' => array(
				'name' => 'Italy',
				'flag' => "\xF0\x9F\x87\xAE\xF0\x9F\x87\xB9",
			),
			'ca' => array(
				'name' => 'Canada',
				'flag' => "\xF0\x9F\x87\xA8\xF0\x9F\x87\xA6",
			),
			'be' => array(
				'name' => 'Belgium',
				'flag' => "\xF0\x9F\x87\xA7\xF0\x9F\x87\xAA",
			),
			'ch' => array(
				'name' => 'Switzerland',
				'flag' => "\xF0\x9F\x87\xA8\xF0\x9F\x87\xAD",
			),
			'nl' => array(
				'name' => 'Netherlands',
				'flag' => "\xF0\x9F\x87\xB3\xF0\x9F\x87\xB1",
			),
			'at' => array(
				'name' => 'Austria',
				'flag' => "\xF0\x9F\x87\xA6\xF0\x9F\x87\xB9",
			),
			'pt' => array(
				'name' => 'Portugal',
				'flag' => "\xF0\x9F\x87\xB5\xF0\x9F\x87\xB9",
			),
			'pl' => array(
				'name' => 'Poland',
				'flag' => "\xF0\x9F\x87\xB5\xF0\x9F\x87\xB1",
			),
			'ro' => array(
				'name' => 'Romania',
				'flag' => "\xF0\x9F\x87\xB7\xF0\x9F\x87\xB4",
			),
			'br' => array(
				'name' => 'Brazil',
				'flag' => "\xF0\x9F\x87\xA7\xF0\x9F\x87\xB7",
			),
			'mx' => array(
				'name' => 'Mexico',
				'flag' => "\xF0\x9F\x87\xB2\xF0\x9F\x87\xBD",
			),
			'ar' => array(
				'name' => 'Argentina',
				'flag' => "\xF0\x9F\x87\xA6\xF0\x9F\x87\xB7",
			),
			'cl' => array(
				'name' => 'Chile',
				'flag' => "\xF0\x9F\x87\xA8\xF0\x9F\x87\xB1",
			),
			'co' => array(
				'name' => 'Colombia',
				'flag' => "\xF0\x9F\x87\xA8\xF0\x9F\x87\xB4",
			),
			'pe' => array(
				'name' => 'Peru',
				'flag' => "\xF0\x9F\x87\xB5\xF0\x9F\x87\xAA",
			),
			'au' => array(
				'name' => 'Australia',
				'flag' => "\xF0\x9F\x87\xA6\xF0\x9F\x87\xBA",
			),
			'za' => array(
				'name' => 'South Africa',
				'flag' => "\xF0\x9F\x87\xBF\xF0\x9F\x87\xA6",
			),
			'in' => array(
				'name' => 'India',
				'flag' => "\xF0\x9F\x87\xAE\xF0\x9F\x87\xB3",
			),
			'ae' => array(
				'name' => 'United Arab Emirates',
				'flag' => "\xF0\x9F\x87\xA6\xF0\x9F\x87\xAA",
			),
			'eg' => array(
				'name' => 'Egypt',
				'flag' => "\xF0\x9F\x87\xAA\xF0\x9F\x87\xAC",
			),
			'ma' => array(
				'name' => 'Morocco',
				'flag' => "\xF0\x9F\x87\xB2\xF0\x9F\x87\xA6",
			),
			'lu' => array(
				'name' => 'Luxembourg',
				'flag' => "\xF0\x9F\x87\xB1\xF0\x9F\x87\xBA",
			),
			'ad' => array(
				'name' => 'Andorra',
				'flag' => "\xF0\x9F\x87\xA6\xF0\x9F\x87\xA9",
			),
		);
	}

	/**
	 * Get content types grouped for optgroup rendering
	 *
	 * @return array Groups with label, icon, and items
	 */
	public static function get_content_types() {
		return array(
			'articles_blog' => array(
				'label' => 'Articles & Blog Posts',
				'icon'  => "\xF0\x9F\x93\x9D",
				'items' => array(
					'articles|blog' => 'Blog Article',
					'articles|news' => 'News Article',
				),
			),
			'affiliate' => array(
				'label' => 'Affiliate & Reviews',
				'icon'  => "\xF0\x9F\x9B\x8D\xEF\xB8\x8F",
				'items' => array(
					'articles|affiliation-product-review'   => 'Product Review',
					'articles|affiliation-compare-products' => 'Compare Products',
					'articles|affiliation-top-product'      => 'Top Products List',
					'articles|affiliation-promo-code-product' => 'Promo Code Product',
				),
			),
			'ecommerce' => array(
				'label' => 'E-commerce Pages',
				'icon'  => "\xF0\x9F\x8F\xAA",
				'items' => array(
					'categorypages|' => 'Category Page',
					'productpages|'  => 'Product Page',
				),
			),
			'special' => array(
				'label' => 'Special Formats',
				'icon'  => "\xF0\x9F\x93\xB1",
				'items' => array(
					'discoverarticles|' => 'Google Discover Article',
				),
			),
		);
	}

	/**
	 * Get SEO markets (language:location_code pairs)
	 *
	 * @return array market value => label
	 */
	public static function get_markets() {
		return array(
			'fr:2250' => "\xF0\x9F\x87\xAB\xF0\x9F\x87\xB7 France (French)",
			'en:2840' => "\xF0\x9F\x87\xBA\xF0\x9F\x87\xB8 United States (English)",
			'en:2826' => "\xF0\x9F\x87\xAC\xF0\x9F\x87\xA7 United Kingdom (English)",
			'en:2124' => "\xF0\x9F\x87\xA8\xF0\x9F\x87\xA6 Canada (English)",
			'fr:2124' => "\xF0\x9F\x87\xA8\xF0\x9F\x87\xA6 Canada (French)",
			'de:2276' => "\xF0\x9F\x87\xA9\xF0\x9F\x87\xAA Germany (German)",
			'de:2040' => "\xF0\x9F\x87\xA6\xF0\x9F\x87\xB9 Austria (German)",
			'de:2756' => "\xF0\x9F\x87\xA8\xF0\x9F\x87\xAD Switzerland (German)",
			'es:2724' => "\xF0\x9F\x87\xAA\xF0\x9F\x87\xB8 Spain (Spanish)",
			'es:2484' => "\xF0\x9F\x87\xB2\xF0\x9F\x87\xBD Mexico (Spanish)",
			'es:2032' => "\xF0\x9F\x87\xA6\xF0\x9F\x87\xB7 Argentina (Spanish)",
			'es:2152' => "\xF0\x9F\x87\xA8\xF0\x9F\x87\xB1 Chile (Spanish)",
			'es:2170' => "\xF0\x9F\x87\xA8\xF0\x9F\x87\xB4 Colombia (Spanish)",
			'es:2604' => "\xF0\x9F\x87\xB5\xF0\x9F\x87\xAA Peru (Spanish)",
			'it:2380' => "\xF0\x9F\x87\xAE\xF0\x9F\x87\xB9 Italy (Italian)",
			'it:2756' => "\xF0\x9F\x87\xA8\xF0\x9F\x87\xAD Switzerland (Italian)",
			'nl:2528' => "\xF0\x9F\x87\xB3\xF0\x9F\x87\xB1 Netherlands (Dutch)",
			'nl:2056' => "\xF0\x9F\x87\xA7\xF0\x9F\x87\xAA Belgium (Dutch)",
			'pl:2616' => "\xF0\x9F\x87\xB5\xF0\x9F\x87\xB1 Poland (Polish)",
			'pt:2620' => "\xF0\x9F\x87\xB5\xF0\x9F\x87\xB9 Portugal (Portuguese)",
			'pt:2076' => "\xF0\x9F\x87\xA7\xF0\x9F\x87\xB7 Brazil (Portuguese)",
			'ro:2642' => "\xF0\x9F\x87\xB7\xF0\x9F\x87\xB4 Romania (Romanian)",
			'en:2036' => "\xF0\x9F\x87\xA6\xF0\x9F\x87\xBA Australia (English)",
			'en:2710' => "\xF0\x9F\x87\xBF\xF0\x9F\x87\xA6 South Africa (English)",
			'en:2356' => "\xF0\x9F\x87\xAE\xF0\x9F\x87\xB3 India (English)",
			'fr:2056' => "\xF0\x9F\x87\xA7\xF0\x9F\x87\xAA Belgium (French)",
			'fr:2756' => "\xF0\x9F\x87\xA8\xF0\x9F\x87\xAD Switzerland (French)",
			'fr:2504' => "\xF0\x9F\x87\xB2\xF0\x9F\x87\xA6 Morocco (French)",
			'fr:2442' => "\xF0\x9F\x87\xB1\xF0\x9F\x87\xBA Luxembourg (French)",
			'fr:2818' => "\xF0\x9F\x87\xAA\xF0\x9F\x87\xAC Egypt (French)",
		);
	}

	/**
	 * Get DataForSEO location code → country code mapping
	 *
	 * @return array location_code => country_code
	 */
	public static function get_location_to_country_map() {
		return array(
			2250 => 'fr',  // France
			2840 => 'us',  // United States
			2826 => 'gb',  // United Kingdom
			2124 => 'ca',  // Canada
			2276 => 'de',  // Germany
			2724 => 'es',  // Spain
			2380 => 'it',  // Italy
			2056 => 'be',  // Belgium
			2756 => 'ch',  // Switzerland
			2040 => 'at',  // Austria
			2036 => 'au',  // Australia
			2076 => 'br',  // Brazil
			2032 => 'ar',  // Argentina
			2152 => 'cl',  // Chile
			2170 => 'co',  // Colombia
			2604 => 'pe',  // Peru
			2484 => 'mx',  // Mexico
			2528 => 'nl',  // Netherlands
			2616 => 'pl',  // Poland
			2620 => 'pt',  // Portugal
			2642 => 'ro',  // Romania
			2710 => 'za',  // South Africa
			2356 => 'in',  // India
			2784 => 'ae',  // United Arab Emirates
			2818 => 'eg',  // Egypt
			2504 => 'ma',  // Morocco
			2442 => 'lu',  // Luxembourg
			2020 => 'ad',  // Andorra
		);
	}

	/**
	 * Get DataForSEO location code → language code mapping
	 *
	 * @return array location_code => language_code
	 */
	public static function get_location_to_language_map() {
		return array(
			2250 => 'fr',  // France
			2840 => 'en',  // United States
			2826 => 'en',  // United Kingdom
			2124 => 'en',  // Canada (English default)
			2276 => 'de',  // Germany
			2724 => 'es',  // Spain
			2380 => 'it',  // Italy
			2056 => 'fr',  // Belgium (French default)
			2756 => 'fr',  // Switzerland (French default)
			2040 => 'de',  // Austria
			2036 => 'en',  // Australia
			2076 => 'pt',  // Brazil
			2032 => 'es',  // Argentina
			2152 => 'es',  // Chile
			2170 => 'es',  // Colombia
			2604 => 'es',  // Peru
			2484 => 'es',  // Mexico
			2528 => 'nl',  // Netherlands
			2616 => 'pl',  // Poland
			2620 => 'pt',  // Portugal
			2642 => 'ro',  // Romania
			2710 => 'en',  // South Africa
			2356 => 'en',  // India
			2784 => 'en',  // United Arab Emirates (English default)
			2818 => 'fr',  // Egypt (French default)
			2504 => 'fr',  // Morocco
			2442 => 'fr',  // Luxembourg
			2020 => 'es',  // Andorra (Spanish default)
		);
	}

	/**
	 * Get valid language/country combinations
	 *
	 * @return array language_code => array of valid country_codes
	 */
	public static function get_valid_language_country_combos() {
		return array(
			'en' => array( 'us', 'gb', 'ca', 'au', 'za', 'in', 'ae' ),
			'fr' => array( 'fr', 'ca', 'be', 'ch', 'ma', 'lu', 'eg', 'ad' ),
			'de' => array( 'de', 'at', 'ch' ),
			'es' => array( 'es', 'mx', 'ar', 'cl', 'co', 'pe', 'ad' ),
			'it' => array( 'it', 'ch' ),
			'nl' => array( 'nl', 'be' ),
			'pl' => array( 'pl' ),
			'pt' => array( 'pt', 'br' ),
			'ro' => array( 'ro' ),
		);
	}

	/**
	 * Get image ratio options
	 *
	 * @return array ratio value => label
	 */
	public static function get_image_ratios() {
		return array(
			'landscape' => 'Landscape',
			'portrait'  => 'Portrait',
			'16:9'      => '16:9',
			'4:3'       => '4:3',
			'1:1'       => '1:1 (Square)',
		);
	}

	/**
	 * Get social network options
	 *
	 * @return array network key => array with label, icon
	 */
	public static function get_social_networks() {
		return array(
			'instagram' => array(
				'label' => 'Instagram',
				'icon'  => "\xF0\x9F\x93\xB8",
			),
			'facebook' => array(
				'label' => 'Facebook',
				'icon'  => "\xF0\x9F\x93\x98",
			),
			'x' => array(
				'label' => 'X (Twitter)',
				'icon'  => "\xF0\x9F\x90\xA6",
			),
			'linkedin' => array(
				'label' => 'LinkedIn',
				'icon'  => "\xF0\x9F\x92\xBC",
			),
		);
	}

	/**
	 * Get WordPress post status options
	 *
	 * @return array status => label
	 */
	public static function get_wordpress_statuses() {
		return array(
			'draft'   => 'Draft',
			'publish' => 'Published',
			'pending' => 'Pending Review',
			'future'  => 'Scheduled',
		);
	}

	/**
	 * Get internal links post status options
	 *
	 * @return array status => label
	 */
	public static function get_internal_links_statuses() {
		return array(
			'draft'   => 'Draft',
			'publish' => 'Published',
			'future'  => 'Scheduled',
		);
	}

	/**
	 * Get all config bundled for wp_localize_script
	 *
	 * @return array
	 */
	public static function get_js_config() {
		$languages = array();
		foreach ( self::get_languages() as $code => $lang ) {
			$languages[ $code ] = array(
				'name'   => $lang['name'],
				'native' => $lang['native'],
				'flag'   => $lang['flag'],
			);
		}

		$countries = array();
		foreach ( self::get_countries() as $code => $country ) {
			$countries[ $code ] = array(
				'name' => $country['name'],
				'flag' => $country['flag'],
			);
		}

		return array(
			'languages'    => $languages,
			'countries'    => $countries,
			'markets'      => self::get_markets(),
			'contentTypes' => self::get_content_types(),
			'imageRatios'  => self::get_image_ratios(),
			'wpStatuses'   => self::get_wordpress_statuses(),
		);
	}
}
