import addressList from './address.json';

export const getProvince = () => {
    const provinceListUnique = [...new Set(addressList.map((obj) => obj.PROVINCE_NAME))];
    return provinceListUnique.map((province) => ({
        value: province,
        label: province,
    }));
};

export const getCity = (provinceName: string) => {
    const cityList = addressList.filter((address) => address.PROVINCE_NAME === provinceName);
    const cityListUnique = [...new Set(cityList.map((obj) => obj.CITY_NAME))];
    return cityListUnique.map((city) => ({
        value: city,
        label: city,
    }));
};

export const getDistrict = (cityName: string) => {
    const districtList = addressList.filter((address) => address.CITY_NAME === cityName);
    const districtListUnique = [...new Set(districtList.map((obj) => obj.DISTRICT_NAME))];
    return districtListUnique.map((district) => ({
        value: district,
        label: district,
    }));
};

export const getTariff = (districtName: string) => {
    const tariff = addressList.find((address) => address.DISTRICT_NAME === districtName);

    return tariff;
};
