{"version":3,"file":"get-countries.mjs","names":[],"sources":["../../../../src/components/PhoneInput/get-countries/get-countries.ts"],"sourcesContent":["import type { PhoneInputCountryData } from '../phone-data';\n\nexport function getCountries(\n  allCountries: PhoneInputCountryData[],\n  options: {\n    onlyCountries?: string[];\n    excludeCountries?: string[];\n    preferredCountries?: string[];\n  }\n): { countries: PhoneInputCountryData[]; preferredList: PhoneInputCountryData[] } {\n  let filtered = allCountries;\n\n  if (options.onlyCountries && options.onlyCountries.length > 0) {\n    const onlyLower = options.onlyCountries.map((c) => c.toLowerCase());\n    const only = new Set(onlyLower);\n    const orderMap = new Map(onlyLower.map((iso, i) => [iso, i]));\n    filtered = filtered\n      .filter((c) => only.has(c.iso2.toLowerCase()))\n      .sort(\n        (a, b) =>\n          (orderMap.get(a.iso2.toLowerCase()) ?? 0) - (orderMap.get(b.iso2.toLowerCase()) ?? 0)\n      );\n  }\n\n  if (options.excludeCountries && options.excludeCountries.length > 0) {\n    const exclude = new Set(options.excludeCountries.map((c) => c.toLowerCase()));\n    filtered = filtered.filter((c) => !exclude.has(c.iso2.toLowerCase()));\n  }\n\n  let preferredList: PhoneInputCountryData[] = [];\n\n  if (options.preferredCountries && options.preferredCountries.length > 0) {\n    const preferred = options.preferredCountries.map((c) => c.toLowerCase());\n    preferredList = preferred\n      .map((iso) => filtered.find((c) => c.iso2.toLowerCase() === iso))\n      .filter((c): c is PhoneInputCountryData => c !== undefined);\n  }\n\n  return { countries: filtered, preferredList };\n}\n\nexport function filterCountries(\n  countries: PhoneInputCountryData[],\n  search: string,\n  getCountryLabel?: (country: PhoneInputCountryData) => string\n): PhoneInputCountryData[] {\n  if (!search) {\n    return countries;\n  }\n\n  const term = search.toLowerCase().trim().replace(/^\\+/, '');\n\n  return countries.filter((c) => {\n    if (c.name.toLowerCase().includes(term)) {\n      return true;\n    }\n\n    if (getCountryLabel && getCountryLabel(c).toLowerCase().includes(term)) {\n      return true;\n    }\n\n    if (c.dialCode.includes(term)) {\n      return true;\n    }\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