diff --git a/src/components/Componentes/question-birthplace.tsx b/src/components/Componentes/question-birthplace.tsx index ea99112..dfc8f4f 100644 --- a/src/components/Componentes/question-birthplace.tsx +++ b/src/components/Componentes/question-birthplace.tsx @@ -65,30 +65,23 @@ function parseValue(rawValue: unknown): { country: string; city: string } { "ایالات متحده آمریکا (US)", ); - let parts: string[] = []; if (str.includes(",")) { - parts = str.split(",").map((s) => s.trim()); - } else if (str.includes("،")) { - parts = str.split("،").map((s) => s.trim()); - } else if (str.includes(" - ")) { - parts = str.split(" - ").map((s) => s.trim()); + const idx = str.lastIndexOf(","); + const cityPart = str.slice(0, idx).trim(); + const countryPart = str.slice(idx + 1).trim(); + return { city: cityPart, country: countryPart }; } - - if (parts.length >= 2) { - const part0 = parts[0] || ""; - const part1 = parts.slice(1).join(", ").trim(); - - const isPart0Country = isKnownCountry(part0); - const isPart1Country = isKnownCountry(part1); - - if (isPart0Country && !isPart1Country) { - return { country: part0, city: part1 }; - } - if (isPart1Country && !isPart0Country) { - return { country: part1, city: part0 }; - } - // Default standard order: City first, Country second - return { city: part0, country: part1 }; + if (str.includes("،")) { + const idx = str.lastIndexOf("،"); + const cityPart = str.slice(0, idx).trim(); + const countryPart = str.slice(idx + 1).trim(); + return { city: cityPart, country: countryPart }; + } + if (str.includes(" - ")) { + const idx = str.lastIndexOf(" - "); + const cityPart = str.slice(0, idx).trim(); + const countryPart = str.slice(idx + 3).trim(); + return { city: cityPart, country: countryPart }; } if (isKnownCountry(str)) {