const require_rolldown_runtime = require('../../../../../../_virtual/rolldown_runtime.js');
const require_isObject$1 = require('./helpers/isObject.js');
const require_metadata$1 = require('./metadata.js');
const require_PhoneNumber$1 = require('./PhoneNumber.js');
const require_getCountryByNationalNumber$1 = require('./helpers/getCountryByNationalNumber.js');
const require_getCountryByCallingCode$1 = require('./helpers/getCountryByCallingCode.js');
const require_AsYouTypeState$1 = require('./AsYouTypeState.js');
const require_AsYouTypeFormatter$1 = require('./AsYouTypeFormatter.js');
const require_AsYouTypeParser$1 = require('./AsYouTypeParser.js');

//#region ../../node_modules/.pnpm/libphonenumber-js@1.11.3/node_modules/libphonenumber-js/build/AsYouType.js
var require_AsYouType = /* @__PURE__ */ require_rolldown_runtime.__commonJS({ "../../node_modules/.pnpm/libphonenumber-js@1.11.3/node_modules/libphonenumber-js/build/AsYouType.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 });
	var _metadata = _interopRequireDefault(require_metadata$1.require_metadata());
	var _PhoneNumber = _interopRequireDefault(require_PhoneNumber$1.require_PhoneNumber());
	var _AsYouTypeState = _interopRequireDefault(require_AsYouTypeState$1.require_AsYouTypeState());
	var _AsYouTypeFormatter = _interopRequireWildcard(require_AsYouTypeFormatter$1.require_AsYouTypeFormatter());
	var _AsYouTypeParser = _interopRequireWildcard(require_AsYouTypeParser$1.require_AsYouTypeParser());
	var _getCountryByCallingCode = _interopRequireDefault(require_getCountryByCallingCode$1.require_getCountryByCallingCode());
	var _getCountryByNationalNumber = _interopRequireDefault(require_getCountryByNationalNumber$1.require_getCountryByNationalNumber());
	var _isObject = _interopRequireDefault(require_isObject$1.require_isObject());
	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 _interopRequireDefault(obj) {
		return obj && obj.__esModule ? obj : { "default": obj };
	}
	function _slicedToArray(arr, i) {
		return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
	}
	function _nonIterableRest() {
		throw new TypeError("Invalid attempt to destructure 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 _iterableToArrayLimit(arr, i) {
		var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
		if (_i == null) return;
		var _arr = [];
		var _n = true;
		var _d = false;
		var _s, _e;
		try {
			for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
				_arr.push(_s.value);
				if (i && _arr.length === i) break;
			}
		} catch (err) {
			_d = true;
			_e = err;
		} finally {
			try {
				if (!_n && _i["return"] != null) _i["return"]();
			} finally {
				if (_d) throw _e;
			}
		}
		return _arr;
	}
	function _arrayWithHoles(arr) {
		if (Array.isArray(arr)) return arr;
	}
	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 USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
	var AsYouType = /* @__PURE__ */ function() {
		/**
		* @param {(string|object)?} [optionsOrDefaultCountry] - The default country used for parsing non-international phone numbers. Can also be an `options` object.
		* @param {Object} metadata
		*/
		function AsYouType$1(optionsOrDefaultCountry, metadata) {
			_classCallCheck(this, AsYouType$1);
			this.metadata = new _metadata["default"](metadata);
			var _this$getCountryAndCa2 = _slicedToArray(this.getCountryAndCallingCode(optionsOrDefaultCountry), 2), defaultCountry = _this$getCountryAndCa2[0], defaultCallingCode = _this$getCountryAndCa2[1];
			this.defaultCountry = defaultCountry;
			this.defaultCallingCode = defaultCallingCode;
			this.reset();
		}
		_createClass(AsYouType$1, [
			{
				key: "getCountryAndCallingCode",
				value: function getCountryAndCallingCode(optionsOrDefaultCountry) {
					var defaultCountry;
					var defaultCallingCode;
					if (optionsOrDefaultCountry) if ((0, _isObject["default"])(optionsOrDefaultCountry)) {
						defaultCountry = optionsOrDefaultCountry.defaultCountry;
						defaultCallingCode = optionsOrDefaultCountry.defaultCallingCode;
					} else defaultCountry = optionsOrDefaultCountry;
					if (defaultCountry && !this.metadata.hasCountry(defaultCountry)) defaultCountry = void 0;
					if (defaultCallingCode) {
						/* istanbul ignore if */
						if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
							if (this.metadata.isNonGeographicCallingCode(defaultCallingCode)) defaultCountry = "001";
						}
					}
					return [defaultCountry, defaultCallingCode];
				}
			},
			{
				key: "input",
				value: function input(text) {
					var _this$parser$input = this.parser.input(text, this.state), digits = _this$parser$input.digits;
					if (_this$parser$input.justLeadingPlus) this.formattedOutput = "+";
					else if (digits) {
						this.determineTheCountryIfNeeded();
						if (this.state.nationalSignificantNumber) this.formatter.narrowDownMatchingFormats(this.state);
						var formattedNationalNumber;
						if (this.metadata.hasSelectedNumberingPlan()) formattedNationalNumber = this.formatter.format(digits, this.state);
						if (formattedNationalNumber === void 0) {
							if (this.parser.reExtractNationalSignificantNumber(this.state)) {
								this.determineTheCountryIfNeeded();
								var nationalDigits = this.state.getNationalDigits();
								if (nationalDigits) formattedNationalNumber = this.formatter.format(nationalDigits, this.state);
							}
						}
						this.formattedOutput = formattedNationalNumber ? this.getFullNumber(formattedNationalNumber) : this.getNonFormattedNumber();
					}
					return this.formattedOutput;
				}
			},
			{
				key: "reset",
				value: function reset() {
					var _this = this;
					this.state = new _AsYouTypeState["default"]({
						onCountryChange: function onCountryChange(country) {
							_this.country = country;
						},
						onCallingCodeChange: function onCallingCodeChange(callingCode, country) {
							_this.metadata.selectNumberingPlan(country, callingCode);
							_this.formatter.reset(_this.metadata.numberingPlan, _this.state);
							_this.parser.reset(_this.metadata.numberingPlan);
						}
					});
					this.formatter = new _AsYouTypeFormatter["default"]({
						state: this.state,
						metadata: this.metadata
					});
					this.parser = new _AsYouTypeParser["default"]({
						defaultCountry: this.defaultCountry,
						defaultCallingCode: this.defaultCallingCode,
						metadata: this.metadata,
						state: this.state,
						onNationalSignificantNumberChange: function onNationalSignificantNumberChange() {
							_this.determineTheCountryIfNeeded();
							_this.formatter.reset(_this.metadata.numberingPlan, _this.state);
						}
					});
					this.state.reset({
						country: this.defaultCountry,
						callingCode: this.defaultCallingCode
					});
					this.formattedOutput = "";
					return this;
				}
			},
			{
				key: "isInternational",
				value: function isInternational() {
					return this.state.international;
				}
			},
			{
				key: "getCallingCode",
				value: function getCallingCode() {
					if (this.isInternational()) return this.state.callingCode;
				}
			},
			{
				key: "getCountryCallingCode",
				value: function getCountryCallingCode() {
					return this.getCallingCode();
				}
			},
			{
				key: "getCountry",
				value: function getCountry() {
					if (this.state.digits) return this._getCountry();
				}
			},
			{
				key: "_getCountry",
				value: function _getCountry() {
					var country = this.state.country;
					/* istanbul ignore if */
					if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
						if (country === "001") return;
					}
					return country;
				}
			},
			{
				key: "determineTheCountryIfNeeded",
				value: function determineTheCountryIfNeeded() {
					if (!this.state.country || this.isCountryCallingCodeAmbiguous()) this.determineTheCountry();
				}
			},
			{
				key: "getFullNumber",
				value: function getFullNumber(formattedNationalNumber) {
					var _this2 = this;
					if (this.isInternational()) {
						var prefix = function prefix$1(text) {
							return _this2.formatter.getInternationalPrefixBeforeCountryCallingCode(_this2.state, { spacing: text ? true : false }) + text;
						};
						var callingCode = this.state.callingCode;
						if (!callingCode) return prefix("".concat(this.state.getDigitsWithoutInternationalPrefix()));
						if (!formattedNationalNumber) return prefix(callingCode);
						return prefix("".concat(callingCode, " ").concat(formattedNationalNumber));
					}
					return formattedNationalNumber;
				}
			},
			{
				key: "getNonFormattedNationalNumberWithPrefix",
				value: function getNonFormattedNationalNumberWithPrefix() {
					var _this$state = this.state, nationalSignificantNumber = _this$state.nationalSignificantNumber, complexPrefixBeforeNationalSignificantNumber = _this$state.complexPrefixBeforeNationalSignificantNumber, nationalPrefix = _this$state.nationalPrefix;
					var number = nationalSignificantNumber;
					var prefix = complexPrefixBeforeNationalSignificantNumber || nationalPrefix;
					if (prefix) number = prefix + number;
					return number;
				}
			},
			{
				key: "getNonFormattedNumber",
				value: function getNonFormattedNumber() {
					var nationalSignificantNumberMatchesInput = this.state.nationalSignificantNumberMatchesInput;
					return this.getFullNumber(nationalSignificantNumberMatchesInput ? this.getNonFormattedNationalNumberWithPrefix() : this.state.getNationalDigits());
				}
			},
			{
				key: "getNonFormattedTemplate",
				value: function getNonFormattedTemplate() {
					var number = this.getNonFormattedNumber();
					if (number) return number.replace(/[\+\d]/g, _AsYouTypeFormatter.DIGIT_PLACEHOLDER);
				}
			},
			{
				key: "isCountryCallingCodeAmbiguous",
				value: function isCountryCallingCodeAmbiguous() {
					var callingCode = this.state.callingCode;
					var countryCodes = this.metadata.getCountryCodesForCallingCode(callingCode);
					return countryCodes && countryCodes.length > 1;
				}
			},
			{
				key: "determineTheCountry",
				value: function determineTheCountry() {
					this.state.setCountry((0, _getCountryByCallingCode["default"])(this.isInternational() ? this.state.callingCode : this.defaultCallingCode, {
						nationalNumber: this.state.nationalSignificantNumber,
						defaultCountry: this.defaultCountry,
						metadata: this.metadata
					}));
				}
			},
			{
				key: "getNumberValue",
				value: function getNumberValue() {
					var _this$state2 = this.state, digits = _this$state2.digits, callingCode = _this$state2.callingCode, country = _this$state2.country, nationalSignificantNumber = _this$state2.nationalSignificantNumber;
					if (!digits) return;
					if (this.isInternational()) if (callingCode) return "+" + callingCode + nationalSignificantNumber;
					else return "+" + digits;
					else if (country || callingCode) return "+" + (country ? this.metadata.countryCallingCode() : callingCode) + nationalSignificantNumber;
				}
			},
			{
				key: "getNumber",
				value: function getNumber() {
					var _this$state3 = this.state, nationalSignificantNumber = _this$state3.nationalSignificantNumber, carrierCode = _this$state3.carrierCode, callingCode = _this$state3.callingCode;
					var country = this._getCountry();
					if (!nationalSignificantNumber) return;
					if (!country && !callingCode) return;
					if (country) {
						if (country === this.defaultCountry) {
							var metadata = new _metadata["default"](this.metadata.metadata);
							metadata.selectNumberingPlan(country);
							var _callingCode = metadata.numberingPlan.callingCode();
							var ambiguousCountries = this.metadata.getCountryCodesForCallingCode(_callingCode);
							if (ambiguousCountries.length > 1) {
								var exactCountry = (0, _getCountryByNationalNumber["default"])(nationalSignificantNumber, {
									countries: ambiguousCountries,
									defaultCountry: this.defaultCountry,
									metadata: this.metadata.metadata
								});
								if (exactCountry) country = exactCountry;
							}
						}
					}
					var phoneNumber = new _PhoneNumber["default"](country || callingCode, nationalSignificantNumber, this.metadata.metadata);
					if (carrierCode) phoneNumber.carrierCode = carrierCode;
					return phoneNumber;
				}
			},
			{
				key: "isPossible",
				value: function isPossible() {
					var phoneNumber = this.getNumber();
					if (!phoneNumber) return false;
					return phoneNumber.isPossible();
				}
			},
			{
				key: "isValid",
				value: function isValid() {
					var phoneNumber = this.getNumber();
					if (!phoneNumber) return false;
					return phoneNumber.isValid();
				}
			},
			{
				key: "getNationalNumber",
				value: function getNationalNumber() {
					return this.state.nationalSignificantNumber;
				}
			},
			{
				key: "getChars",
				value: function getChars() {
					return (this.state.international ? "+" : "") + this.state.digits;
				}
			},
			{
				key: "getTemplate",
				value: function getTemplate() {
					return this.formatter.getTemplate(this.state) || this.getNonFormattedTemplate() || "";
				}
			}
		]);
		return AsYouType$1;
	}();
	exports["default"] = AsYouType;
}) });

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