{"version":3,"file":"build-raw-value.mjs","names":[],"sources":["../../../../src/components/PhoneInput/build-raw-value/build-raw-value.ts"],"sourcesContent":["import { getMaskDigitCount } from '../format-phone-number/format-phone-number';\nimport { getDigits } from '../get-digits/get-digits';\nimport type { PhoneInputCountryData } from '../phone-data';\n\ninterface BuildRawValueOptions {\n  canAutoDetect: boolean;\n  international: boolean;\n  selectedCountry: PhoneInputCountryData | null;\n  normalizeNationalPrefix?: boolean;\n  forceNationalPrefix?: boolean;\n  preferSelectedCountry?: boolean;\n}\n\nexport function buildRawValue(inputValue: string, options: BuildRawValueOptions): string {\n  const {\n    canAutoDetect,\n    international,\n    selectedCountry,\n    normalizeNationalPrefix = true,\n    forceNationalPrefix = false,\n    preferSelectedCountry = false,\n  } = options;\n  const raw = getDigits(inputValue);\n  const digitsOnly = raw.replace(/^\\+/, '');\n  const startsWithDialCode =\n    !!selectedCountry &&\n    digitsOnly.startsWith(selectedCountry.dialCode) &&\n    (raw.startsWith('+') ||\n      selectedCountry.iso2 !== 'kz' ||\n      digitsOnly.length > getMaskDigitCount(selectedCountry.format));\n  const stripNationalPrefix = (digits: string) =>\n    normalizeNationalPrefix &&\n    selectedCountry?.nationalPrefix &&\n    digits.startsWith(selectedCountry.nationalPrefix) &&\n    (forceNationalPrefix ||\n      selectedCountry.nationalPrefix === '0' ||\n      digits.length > getMaskDigitCount(selectedCountry.format))\n      ? digits.slice(selectedCountry.nationalPrefix.length)\n      : digits;\n\n  if (!international && selectedCountry && !(canAutoDetect && raw.startsWith('+'))) {\n    return `+${selectedCountry.dialCode}${stripNationalPrefix(digitsOnly)}`;\n  }\n\n  if (preferSelectedCountry && selectedCountry && !raw.startsWith('+')) {\n    const nationalDigits =\n      international && startsWithDialCode\n        ? digitsOnly.slice(selectedCountry.dialCode.length)\n        : digitsOnly;\n    return `+${selectedCountry.dialCode}${stripNationalPrefix(nationalDigits)}`;\n  }\n\n  if (canAutoDetect || !selectedCountry) {\n    if (selectedCountry?.nationalPrefix) {\n      if (raw.startsWith(`+${selectedCountry.dialCode}`)) {\n        return `+${selectedCountry.dialCode}${stripNationalPrefix(digitsOnly.slice(selectedCountry.dialCode.length))}`;\n      }\n      if (!raw.startsWith('+') && digitsOnly.startsWith(selectedCountry.nationalPrefix)) {\n        return `+${selectedCountry.dialCode}${stripNationalPrefix(digitsOnly)}`;\n      }\n    }\n    if (\n      selectedCountry &&\n      !raw.startsWith('+') &&\n      digitsOnly.startsWith(selectedCountry.dialCode) &&\n      !startsWithDialCode\n    ) {\n      return `+${selectedCountry.dialCode}${stripNationalPrefix(digitsOnly)}`;\n    }\n    return raw.startsWith('+') ? raw : `+${raw}`;\n  }\n\n  const nationalDigits = startsWithDialCode\n    ? digitsOnly.slice(selectedCountry.dialCode.length)\n    : digitsOnly;\n  return `+${selectedCountry.dialCode}${stripNationalPrefix(nationalDigits)}`;\n}\n"],"mappings":";;;;AAaA,SAAgB,cAAc,YAAoB,SAAuC;CACvF,MAAM,EACJ,eACA,eACA,iBACA,0BAA0B,MAC1B,sBAAsB,OACtB,wBAAwB,UACtB;CACJ,MAAM,MAAM,UAAU,UAAU;CAChC,MAAM,aAAa,IAAI,QAAQ,OAAO,EAAE;CACxC,MAAM,qBACJ,CAAC,CAAC,mBACF,WAAW,WAAW,gBAAgB,QAAQ,MAC7C,IAAI,WAAW,GAAG,KACjB,gBAAgB,SAAS,QACzB,WAAW,SAAS,kBAAkB,gBAAgB,MAAM;CAChE,MAAM,uBAAuB,WAC3B,2BACA,iBAAiB,kBACjB,OAAO,WAAW,gBAAgB,cAAc,MAC/C,uBACC,gBAAgB,mBAAmB,OACnC,OAAO,SAAS,kBAAkB,gBAAgB,MAAM,KACtD,OAAO,MAAM,gBAAgB,eAAe,MAAM,IAClD;CAEN,IAAI,CAAC,iBAAiB,mBAAmB,EAAE,iBAAiB,IAAI,WAAW,GAAG,IAC5E,OAAO,IAAI,gBAAgB,WAAW,oBAAoB,UAAU;CAGtE,IAAI,yBAAyB,mBAAmB,CAAC,IA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