<?php
/**
 * @author       mtc.
 * @author       Florin Radica <florin.radica@mtcmedia.co.uk>
 * @description  This file is used with AJAX to retrieve the list of states for a particular country.
 *               If country has no states, an empty array is retrieved.
 */

$path="../../../";
require_once $path .'core/includes/header.inc.php';

use Mtc\Core\Models\CountryState;

$ajax = isset($_REQUEST['ajax']) ? true : false;
$country_code = isset($_REQUEST['country_code']) ? $_REQUEST['country_code'] : '';

$state_list = CountryState::getCountryStateList();

if (isset($_REQUEST['ajax'])) {
    if (isset($state_list[$country_code])) {
        echo json_encode($state_list[$country_code]);
    } else {
        echo '{}';
    }
}
