const require_rolldown_runtime = require('../../../../../../_virtual/rolldown_runtime.js');
const require_constants$1 = require('./constants.js');
const require_parseDigits$1 = require('./helpers/parseDigits.js');
const require_applyInternationalSeparatorStyle$1 = require('./helpers/applyInternationalSeparatorStyle.js');
const require_formatNationalNumberUsingFormat$1 = require('./helpers/formatNationalNumberUsingFormat.js');
const require_AsYouTypeFormatter_util$1 = require('./AsYouTypeFormatter.util.js');
const require_AsYouTypeFormatter_complete$1 = require('./AsYouTypeFormatter.complete.js');
const require_AsYouTypeFormatter_PatternMatcher$1 = require('./AsYouTypeFormatter.PatternMatcher.js');

//#region ../../node_modules/.pnpm/libphonenumber-js@1.11.3/node_modules/libphonenumber-js/build/AsYouTypeFormatter.js
var require_AsYouTypeFormatter = /* @__PURE__ */ require_rolldown_runtime.__commonJS({ "../../node_modules/.pnpm/libphonenumber-js@1.11.3/node_modules/libphonenumber-js/build/AsYouTypeFormatter.js": ((exports) => {
	function _typeof(obj) {
		"@babel/helpers - typeof";
		return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj$1) {
			return typeof obj$1;
		} : function(obj$1) {
			return obj$1 && "function" == typeof Symbol && obj$1.constructor === Symbol && obj$1 !== Symbol.prototype ? "symbol" : typeof obj$1;
		}, _typeof(obj);
	}
	Object.defineProperty(exports, "__esModule", { value: true });
	Object.defineProperty(exports, "DIGIT_PLACEHOLDER", {
		enumerable: true,
		get: function get() {
			return _AsYouTypeFormatterUtil.DIGIT_PLACEHOLDER;
		}
	});
	var _AsYouTypeFormatterUtil = require_AsYouTypeFormatter_util$1.require_AsYouTypeFormatter_util();
	var _AsYouTypeFormatterComplete = _interopRequireWildcard(require_AsYouTypeFormatter_complete$1.require_AsYouTypeFormatter_complete());
	var _AsYouTypeFormatterPatternMatcher = _interopRequireDefault(require_AsYouTypeFormatter_PatternMatcher$1.require_AsYouTypeFormatter_PatternMatcher());
	var _parseDigits = _interopRequireDefault(require_parseDigits$1.require_parseDigits());
	var _formatNationalNumberUsingFormat = require_formatNationalNumberUsingFormat$1.require_formatNationalNumberUsingFormat();
	var _constants = require_constants$1.require_constants();
	var _applyInternationalSeparatorStyle = _interopRequireDefault(require_applyInternationalSeparatorStyle$1.require_applyInternationalSeparatorStyle());
	function _interopRequireDefault(obj) {
		return obj && obj.__esModule ? obj : { "default": obj };
	}
	function _getRequireWildcardCache(nodeInterop) {
		if (typeof WeakMap !== "function") return null;
		var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
		var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
		return (_getRequireWildcardCache = function _getRequireWildcardCache$1(nodeInterop$1) {
			return nodeInterop$1 ? cacheNodeInterop : cacheBabelInterop;
		})(nodeInterop);
	}
	function _interopRequireWildcard(obj, nodeInterop) {
		if (!nodeInterop && obj && obj.__esModule) return obj;
		if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") return { "default": obj };
		var cache = _getRequireWildcardCache(nodeInterop);
		if (cache && cache.has(obj)) return cache.get(obj);
		var newObj = {};
		var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
		for (var key in obj) if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
			var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
			if (desc && (desc.get || desc.set)) Object.defineProperty(newObj, key, desc);
			else newObj[key] = obj[key];
		}
		newObj["default"] = obj;
		if (cache) cache.set(obj, newObj);
		return newObj;
	}
	function _createForOfIteratorHelperLoose(o, allowArrayLike) {
		var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
		if (it) return (it = it.call(o)).next.bind(it);
		if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
			if (it) o = it;
			var i = 0;
			return function() {
				if (i >= o.length) return { done: true };
				return {
					done: false,
					value: o[i++]
				};
			};
		}
		throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
	}
	function _unsupportedIterableToArray(o, minLen) {
		if (!o) return;
		if (typeof o === "string") return _arrayLikeToArray(o, minLen);
		var n = Object.prototype.toString.call(o).slice(8, -1);
		if (n === "Object" && o.constructor) n = o.constructor.name;
		if (n === "Map" || n === "Set") return Array.from(o);
		if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
	}
	function _arrayLikeToArray(arr, len) {
		if (len == null || len > arr.length) len = arr.length;
		for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
		return arr2;
	}
	function _classCallCheck(instance, Constructor) {
		if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
	}
	function _defineProperties(target, props) {
		for (var i = 0; i < props.length; i++) {
			var descriptor = props[i];
			descriptor.enumerable = descriptor.enumerable || false;
			descriptor.configurable = true;
			if ("value" in descriptor) descriptor.writable = true;
			Object.defineProperty(target, descriptor.key, descriptor);
		}
	}
	function _createClass(Constructor, protoProps, staticProps) {
		if (protoProps) _defineProperties(Constructor.prototype, protoProps);
		if (staticProps) _defineProperties(Constructor, staticProps);
		Object.defineProperty(Constructor, "prototype", { writable: false });
		return Constructor;
	}
	var DUMMY_DIGIT = "9";
	var LONGEST_DUMMY_PHONE_NUMBER = (0, _AsYouTypeFormatterUtil.repeat)(DUMMY_DIGIT, 15);
	var NATIONAL_PREFIX_SEPARATORS_PATTERN = /[- ]/;
	var SUPPORT_LEGACY_FORMATTING_PATTERNS = true;
	var CREATE_CHARACTER_CLASS_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && function() {
		return /\[([^\[\]])*\]/g;
	};
	var CREATE_STANDALONE_DIGIT_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && function() {
		return /\d(?=[^,}][^,}])/g;
	};
	var NON_ALTERING_FORMAT_REG_EXP = /* @__PURE__ */ new RegExp("[" + _constants.VALID_PUNCTUATION + "]*\\$1[" + _constants.VALID_PUNCTUATION + "]*(\\$\\d[" + _constants.VALID_PUNCTUATION + "]*)*$");
	var MIN_LEADING_DIGITS_LENGTH = 3;
	var AsYouTypeFormatter = /* @__PURE__ */ function() {
		function AsYouTypeFormatter$1(_ref) {
			_ref.state;
			var metadata = _ref.metadata;
			_classCallCheck(this, AsYouTypeFormatter$1);
			this.metadata = metadata;
			this.resetFormat();
		}
		_createClass(AsYouTypeFormatter$1, [
			{
				key: "resetFormat",
				value: function resetFormat() {
					this.chosenFormat = void 0;
					this.template = void 0;
					this.nationalNumberTemplate = void 0;
					this.populatedNationalNumberTemplate = void 0;
					this.populatedNationalNumberTemplatePosition = -1;
				}
			},
			{
				key: "reset",
				value: function reset(numberingPlan, state) {
					this.resetFormat();
					if (numberingPlan) {
						this.isNANP = numberingPlan.callingCode() === "1";
						this.matchingFormats = numberingPlan.formats();
						if (state.nationalSignificantNumber) this.narrowDownMatchingFormats(state);
					} else {
						this.isNANP = void 0;
						this.matchingFormats = [];
					}
				}
			},
			{
				key: "format",
				value: function format(nextDigits, state) {
					var _this = this;
					if ((0, _AsYouTypeFormatterComplete.canFormatCompleteNumber)(state.nationalSignificantNumber, this.metadata)) for (var _iterator = _createForOfIteratorHelperLoose(this.matchingFormats), _step; !(_step = _iterator()).done;) {
						var format$1 = _step.value;
						var formattedCompleteNumber = (0, _AsYouTypeFormatterComplete["default"])(state, format$1, {
							metadata: this.metadata,
							shouldTryNationalPrefixFormattingRule: function shouldTryNationalPrefixFormattingRule(format$2) {
								return _this.shouldTryNationalPrefixFormattingRule(format$2, {
									international: state.international,
									nationalPrefix: state.nationalPrefix
								});
							},
							getSeparatorAfterNationalPrefix: function getSeparatorAfterNationalPrefix(format$2) {
								return _this.getSeparatorAfterNationalPrefix(format$2);
							}
						});
						if (formattedCompleteNumber) {
							this.resetFormat();
							this.chosenFormat = format$1;
							this.setNationalNumberTemplate(formattedCompleteNumber.replace(/\d/g, _AsYouTypeFormatterUtil.DIGIT_PLACEHOLDER), state);
							this.populatedNationalNumberTemplate = formattedCompleteNumber;
							this.populatedNationalNumberTemplatePosition = this.template.lastIndexOf(_AsYouTypeFormatterUtil.DIGIT_PLACEHOLDER);
							return formattedCompleteNumber;
						}
					}
					return this.formatNationalNumberWithNextDigits(nextDigits, state);
				}
			},
			{
				key: "formatNationalNumberWithNextDigits",
				value: function formatNationalNumberWithNextDigits(nextDigits, state) {
					var previouslyChosenFormat = this.chosenFormat;
					var newlyChosenFormat = this.chooseFormat(state);
					if (newlyChosenFormat) if (newlyChosenFormat === previouslyChosenFormat) return this.formatNextNationalNumberDigits(nextDigits);
					else return this.formatNextNationalNumberDigits(state.getNationalDigits());
				}
			},
			{
				key: "narrowDownMatchingFormats",
				value: function narrowDownMatchingFormats(_ref2) {
					var _this2 = this;
					var nationalSignificantNumber = _ref2.nationalSignificantNumber, nationalPrefix = _ref2.nationalPrefix, international = _ref2.international;
					var leadingDigits = nationalSignificantNumber;
					var leadingDigitsPatternIndex = leadingDigits.length - MIN_LEADING_DIGITS_LENGTH;
					if (leadingDigitsPatternIndex < 0) leadingDigitsPatternIndex = 0;
					this.matchingFormats = this.matchingFormats.filter(function(format) {
						return _this2.formatSuits(format, international, nationalPrefix) && _this2.formatMatches(format, leadingDigits, leadingDigitsPatternIndex);
					});
					if (this.chosenFormat && this.matchingFormats.indexOf(this.chosenFormat) === -1) this.resetFormat();
				}
			},
			{
				key: "formatSuits",
				value: function formatSuits(format, international, nationalPrefix) {
					if (nationalPrefix && !format.usesNationalPrefix() && !format.nationalPrefixIsOptionalWhenFormattingInNationalFormat()) return false;
					if (!international && !nationalPrefix && format.nationalPrefixIsMandatoryWhenFormattingInNationalFormat()) return false;
					return true;
				}
			},
			{
				key: "formatMatches",
				value: function formatMatches(format, leadingDigits, leadingDigitsPatternIndex) {
					var leadingDigitsPatternsCount = format.leadingDigitsPatterns().length;
					if (leadingDigitsPatternsCount === 0) return true;
					leadingDigitsPatternIndex = Math.min(leadingDigitsPatternIndex, leadingDigitsPatternsCount - 1);
					var leadingDigitsPattern = format.leadingDigitsPatterns()[leadingDigitsPatternIndex];
					if (leadingDigits.length < MIN_LEADING_DIGITS_LENGTH) try {
						return new _AsYouTypeFormatterPatternMatcher["default"](leadingDigitsPattern).match(leadingDigits, { allowOverflow: true }) !== void 0;
					} catch (error) {
						console.error(error);
						return true;
					}
					return new RegExp("^(".concat(leadingDigitsPattern, ")")).test(leadingDigits);
				}
			},
			{
				key: "getFormatFormat",
				value: function getFormatFormat(format, international) {
					return international ? format.internationalFormat() : format.format();
				}
			},
			{
				key: "chooseFormat",
				value: function chooseFormat(state) {
					var _this3 = this;
					var _loop = function _loop$1() {
						var format = _step2.value;
						if (_this3.chosenFormat === format) return "break";
						/* istanbul ignore if */
						if (!NON_ALTERING_FORMAT_REG_EXP.test(_this3.getFormatFormat(format, state.international))) return "continue";
						if (!_this3.createTemplateForFormat(format, state)) {
							_this3.matchingFormats = _this3.matchingFormats.filter(function(_) {
								return _ !== format;
							});
							return "continue";
						}
						_this3.chosenFormat = format;
						return "break";
					};
					/* istanbul ignore next */
					for (var _iterator2 = _createForOfIteratorHelperLoose(this.matchingFormats.slice()), _step2; !(_step2 = _iterator2()).done;) {
						var _ret = _loop();
						if (_ret === "break") break;
						if (_ret === "continue") continue;
					}
					if (!this.chosenFormat) this.resetFormat();
					return this.chosenFormat;
				}
			},
			{
				key: "createTemplateForFormat",
				value: function createTemplateForFormat(format, state) {
					/* istanbul ignore if */
					if (SUPPORT_LEGACY_FORMATTING_PATTERNS && format.pattern().indexOf("|") >= 0) return;
					var template = this.getTemplateForFormat(format, state);
					if (template) {
						this.setNationalNumberTemplate(template, state);
						return true;
					}
				}
			},
			{
				key: "getSeparatorAfterNationalPrefix",
				value: function getSeparatorAfterNationalPrefix(format) {
					if (this.isNANP) return " ";
					if (format && format.nationalPrefixFormattingRule() && NATIONAL_PREFIX_SEPARATORS_PATTERN.test(format.nationalPrefixFormattingRule())) return " ";
					return "";
				}
			},
			{
				key: "getInternationalPrefixBeforeCountryCallingCode",
				value: function getInternationalPrefixBeforeCountryCallingCode(_ref3, options) {
					var IDDPrefix = _ref3.IDDPrefix, missingPlus = _ref3.missingPlus;
					if (IDDPrefix) return options && options.spacing === false ? IDDPrefix : IDDPrefix + " ";
					if (missingPlus) return "";
					return "+";
				}
			},
			{
				key: "getTemplate",
				value: function getTemplate(state) {
					if (!this.template) return;
					var index = -1;
					var i = 0;
					var internationalPrefix = state.international ? this.getInternationalPrefixBeforeCountryCallingCode(state, { spacing: false }) : "";
					while (i < internationalPrefix.length + state.getDigitsWithoutInternationalPrefix().length) {
						index = this.template.indexOf(_AsYouTypeFormatterUtil.DIGIT_PLACEHOLDER, index + 1);
						i++;
					}
					return (0, _AsYouTypeFormatterUtil.cutAndStripNonPairedParens)(this.template, index + 1);
				}
			},
			{
				key: "setNationalNumberTemplate",
				value: function setNationalNumberTemplate(template, state) {
					this.nationalNumberTemplate = template;
					this.populatedNationalNumberTemplate = template;
					this.populatedNationalNumberTemplatePosition = -1;
					if (state.international) this.template = this.getInternationalPrefixBeforeCountryCallingCode(state).replace(/[\d\+]/g, _AsYouTypeFormatterUtil.DIGIT_PLACEHOLDER) + (0, _AsYouTypeFormatterUtil.repeat)(_AsYouTypeFormatterUtil.DIGIT_PLACEHOLDER, state.callingCode.length) + " " + template;
					else this.template = template;
				}
			},
			{
				key: "getTemplateForFormat",
				value: function getTemplateForFormat(format, _ref4) {
					var nationalSignificantNumber = _ref4.nationalSignificantNumber, international = _ref4.international, nationalPrefix = _ref4.nationalPrefix, complexPrefixBeforeNationalSignificantNumber = _ref4.complexPrefixBeforeNationalSignificantNumber;
					var pattern = format.pattern();
					/* istanbul ignore else */
					if (SUPPORT_LEGACY_FORMATTING_PATTERNS) pattern = pattern.replace(CREATE_CHARACTER_CLASS_PATTERN(), "\\d").replace(CREATE_STANDALONE_DIGIT_PATTERN(), "\\d");
					var digits = LONGEST_DUMMY_PHONE_NUMBER.match(pattern)[0];
					if (nationalSignificantNumber.length > digits.length) return;
					var strictPattern = /* @__PURE__ */ new RegExp("^" + pattern + "$");
					var nationalNumberDummyDigits = nationalSignificantNumber.replace(/\d/g, DUMMY_DIGIT);
					if (strictPattern.test(nationalNumberDummyDigits)) digits = nationalNumberDummyDigits;
					var numberFormat = this.getFormatFormat(format, international);
					var nationalPrefixIncludedInTemplate;
					if (this.shouldTryNationalPrefixFormattingRule(format, {
						international,
						nationalPrefix
					})) {
						var numberFormatWithNationalPrefix = numberFormat.replace(_formatNationalNumberUsingFormat.FIRST_GROUP_PATTERN, format.nationalPrefixFormattingRule());
						/* istanbul ignore else */
						if ((0, _parseDigits["default"])(format.nationalPrefixFormattingRule()) === (nationalPrefix || "") + (0, _parseDigits["default"])("$1")) {
							numberFormat = numberFormatWithNationalPrefix;
							nationalPrefixIncludedInTemplate = true;
							if (nationalPrefix) {
								var i = nationalPrefix.length;
								while (i > 0) {
									numberFormat = numberFormat.replace(/\d/, _AsYouTypeFormatterUtil.DIGIT_PLACEHOLDER);
									i--;
								}
							}
						}
					}
					var template = digits.replace(new RegExp(pattern), numberFormat).replace(new RegExp(DUMMY_DIGIT, "g"), _AsYouTypeFormatterUtil.DIGIT_PLACEHOLDER);
					if (!nationalPrefixIncludedInTemplate) {
						if (complexPrefixBeforeNationalSignificantNumber) template = (0, _AsYouTypeFormatterUtil.repeat)(_AsYouTypeFormatterUtil.DIGIT_PLACEHOLDER, complexPrefixBeforeNationalSignificantNumber.length) + " " + template;
						else if (nationalPrefix) template = (0, _AsYouTypeFormatterUtil.repeat)(_AsYouTypeFormatterUtil.DIGIT_PLACEHOLDER, nationalPrefix.length) + this.getSeparatorAfterNationalPrefix(format) + template;
					}
					if (international) template = (0, _applyInternationalSeparatorStyle["default"])(template);
					return template;
				}
			},
			{
				key: "formatNextNationalNumberDigits",
				value: function formatNextNationalNumberDigits(digits) {
					var result = (0, _AsYouTypeFormatterUtil.populateTemplateWithDigits)(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition, digits);
					if (!result) {
						this.resetFormat();
						return;
					}
					this.populatedNationalNumberTemplate = result[0];
					this.populatedNationalNumberTemplatePosition = result[1];
					return (0, _AsYouTypeFormatterUtil.cutAndStripNonPairedParens)(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1);
				}
			},
			{
				key: "shouldTryNationalPrefixFormattingRule",
				value: function shouldTryNationalPrefixFormattingRule(format, _ref5) {
					var international = _ref5.international, nationalPrefix = _ref5.nationalPrefix;
					if (format.nationalPrefixFormattingRule()) {
						var usesNationalPrefix = format.usesNationalPrefix();
						if (usesNationalPrefix && nationalPrefix || !usesNationalPrefix && !international) return true;
					}
				}
			}
		]);
		return AsYouTypeFormatter$1;
	}();
	exports["default"] = AsYouTypeFormatter;
}) });

//#endregion
Object.defineProperty(exports, 'default', {
  enumerable: true,
  get: function () {
    return require_AsYouTypeFormatter();
  }
});