import { CountryCode } from "libphonenumber-js";
import { Country } from "@/components/ui/PhoneInput/types";
import countryOptionsDataMap from "@/components/ui/PhoneInput/utils/countryOptionsDataMap";
import getPhoneMask from "@/components/ui/PhoneInput/utils/getPhoneMask";

type InitialDataFromValue = {
    country: Country;
    format: ReturnType<typeof getPhoneMask>;
};

const getInitialDataFromValue = (
    initialCountryCode: string
): InitialDataFromValue => {
    return {
        country: countryOptionsDataMap[initialCountryCode],
        format: getPhoneMask(initialCountryCode as CountryCode),
    };
};

export default getInitialDataFromValue;
