import { COUNTRIES_LIST } from '../../../core/src/utils/country.mjs';

// Attempts to format the number in the following format (XXX) XXX-XXXX.
const formatNumber = async ({ parsePhoneNumber, phoneNumber, country })=>{
    try {
        const parsedPhoneNumber = await Promise.race([
            parsePhoneNumber(phoneNumber, country),
            new Promise((done)=>setTimeout(()=>done(undefined), 10000))
        ]);
        if (!parsedPhoneNumber) {
            return phoneNumber;
        }
        return parsedPhoneNumber.national;
    } catch  {
        return phoneNumber;
    }
};
// Attempts to format the number in the following format +1XXXXXXXXXX.
const formatNumberToIncludeCountryCode = async ({ parsePhoneNumber, phoneNumber, country })=>{
    const code = COUNTRIES_LIST[country];
    const fallbackNumber = `+${code}${phoneNumber}`;
    const fallback = {
        isValid: true,
        number: fallbackNumber
    };
    try {
        const parsedPhoneNumber = await Promise.race([
            parsePhoneNumber(phoneNumber, country),
            new Promise((done)=>setTimeout(()=>done(undefined), 2000))
        ]);
        if (!parsedPhoneNumber) {
            return fallback;
        }
        return parsedPhoneNumber;
    } catch  {
        return fallback;
    }
};

export { formatNumber, formatNumberToIncludeCountryCode };
//# sourceMappingURL=handleParsePhoneNumber.mjs.map
