const require_rolldown_runtime = require('../../../../../../_virtual/rolldown_runtime.js');
const require_constants$1 = require('./constants.js');
const require_metadata$1 = require('./metadata.js');
const require_createExtensionPattern$1 = require('./helpers/extension/createExtensionPattern.js');
const require_PhoneNumber$1 = require('./PhoneNumber.js');
const require_parsePhoneNumber$1 = require('./parsePhoneNumber.js');
const require_RegExpCache$1 = require('./findNumbers/RegExpCache.js');
const require_util$1 = require('./findNumbers/util.js');
const require_utf_8$1 = require('./findNumbers/utf-8.js');
const require_Leniency$1 = require('./findNumbers/Leniency.js');
const require_parsePreCandidate$1 = require('./findNumbers/parsePreCandidate.js');
const require_isValidPreCandidate$1 = require('./findNumbers/isValidPreCandidate.js');
const require_isValidCandidate$1 = require('./findNumbers/isValidCandidate.js');

//#region ../../node_modules/.pnpm/libphonenumber-js@1.11.3/node_modules/libphonenumber-js/build/PhoneNumberMatcher.js
var require_PhoneNumberMatcher = /* @__PURE__ */ require_rolldown_runtime.__commonJS({ "../../node_modules/.pnpm/libphonenumber-js@1.11.3/node_modules/libphonenumber-js/build/PhoneNumberMatcher.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 });
	_interopRequireDefault(require_PhoneNumber$1.require_PhoneNumber());
	var _constants = require_constants$1.require_constants();
	var _createExtensionPattern = _interopRequireDefault(require_createExtensionPattern$1.require_createExtensionPattern());
	var _RegExpCache = _interopRequireDefault(require_RegExpCache$1.require_RegExpCache());
	var _util = require_util$1.require_util();
	var _utf = require_utf_8$1.require_utf_8();
	var _Leniency = _interopRequireDefault(require_Leniency$1.require_Leniency());
	var _parsePreCandidate = _interopRequireDefault(require_parsePreCandidate$1.require_parsePreCandidate());
	var _isValidPreCandidate = _interopRequireDefault(require_isValidPreCandidate$1.require_isValidPreCandidate());
	var _isValidCandidate = _interopRequireWildcard(require_isValidCandidate$1.require_isValidCandidate());
	var _metadata = require_metadata$1.require_metadata();
	var _parsePhoneNumber = _interopRequireDefault(require_parsePhoneNumber$1.require_parsePhoneNumber());
	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 _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 USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
	var EXTN_PATTERNS_FOR_MATCHING = (0, _createExtensionPattern["default"])("matching");
	/**
	* Patterns used to extract phone numbers from a larger phone-number-like pattern. These are
	* ordered according to specificity. For example, white-space is last since that is frequently
	* used in numbers, not just to separate two numbers. We have separate patterns since we don't
	* want to break up the phone-number-like text on more than one different kind of symbol at one
	* time, although symbols of the same type (e.g. space) can be safely grouped together.
	*
	* Note that if there is a match, we will always check any text found up to the first match as
	* well.
	*/
	var INNER_MATCHES = [
		"\\/+(.*)/",
		"(\\([^(]*)",
		"(?:".concat(_utf.pZ, "-|-").concat(_utf.pZ, ")").concat(_utf.pZ, "*(.+)"),
		"[‒-―－]".concat(_utf.pZ, "*(.+)"),
		"\\.+".concat(_utf.pZ, "*([^.]+)"),
		"".concat(_utf.pZ, "+(").concat(_utf.PZ, "+)")
	];
	var leadLimit = (0, _util.limit)(0, 2);
	var punctuationLimit = (0, _util.limit)(0, 4);
	var digitBlockLimit = _constants.MAX_LENGTH_FOR_NSN + _constants.MAX_LENGTH_COUNTRY_CODE;
	var blockLimit = (0, _util.limit)(0, digitBlockLimit);
	var punctuation = "[".concat(_constants.VALID_PUNCTUATION, "]") + punctuationLimit;
	var digitSequence = _utf.pNd + (0, _util.limit)(1, digitBlockLimit);
	/**
	* Phone number pattern allowing optional punctuation.
	* The phone number pattern used by `find()`, similar to
	* VALID_PHONE_NUMBER, but with the following differences:
	* <ul>
	*   <li>All captures are limited in order to place an upper bound to the text matched by the
	*       pattern.
	* <ul>
	*   <li>Leading punctuation / plus signs are limited.
	*   <li>Consecutive occurrences of punctuation are limited.
	*   <li>Number of digits is limited.
	* </ul>
	*   <li>No whitespace is allowed at the start or end.
	*   <li>No alpha digits (vanity numbers such as 1-800-SIX-FLAGS) are currently supported.
	* </ul>
	*/
	var PATTERN = "(?:" + _isValidCandidate.LEAD_CLASS + punctuation + ")" + leadLimit + digitSequence + "(?:" + punctuation + digitSequence + ")" + blockLimit + "(?:" + EXTN_PATTERNS_FOR_MATCHING + ")?";
	var UNWANTED_END_CHAR_PATTERN = new RegExp("[^".concat(_utf._pN).concat(_utf._pL, "#]+$"));
	var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1;
	/**
	* A stateful class that finds and extracts telephone numbers from {@linkplain CharSequence text}.
	* Instances can be created using the {@linkplain PhoneNumberUtil#findNumbers factory methods} in
	* {@link PhoneNumberUtil}.
	*
	* <p>Vanity numbers (phone numbers using alphabetic digits such as <tt>1-800-SIX-FLAGS</tt> are
	* not found.
	*
	* <p>This class is not thread-safe.
	*/
	var PhoneNumberMatcher = /* @__PURE__ */ function() {
		/**
		* @param {string} text — the character sequence that we will search, null for no text.
		* @param {'POSSIBLE'|'VALID'|'STRICT_GROUPING'|'EXACT_GROUPING'} [options.leniency] — The leniency to use when evaluating candidate phone numbers. See `source/findNumbers/Leniency.js` for more details.
		* @param {number} [options.maxTries] — The maximum number of invalid numbers to try before giving up on the text. This is to cover degenerate cases where the text has a lot of false positives in it. Must be >= 0.
		*/
		function PhoneNumberMatcher$1() {
			var text = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "";
			var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
			var metadata = arguments.length > 2 ? arguments[2] : void 0;
			_classCallCheck(this, PhoneNumberMatcher$1);
			options = {
				v2: options.v2,
				defaultCallingCode: options.defaultCallingCode,
				defaultCountry: options.defaultCountry && (0, _metadata.isSupportedCountry)(options.defaultCountry, metadata) ? options.defaultCountry : void 0,
				leniency: options.leniency || (options.extended ? "POSSIBLE" : "VALID"),
				maxTries: options.maxTries || MAX_SAFE_INTEGER
			};
			if (!options.leniency) throw new TypeError("`leniency` is required");
			if (options.leniency !== "POSSIBLE" && options.leniency !== "VALID") throw new TypeError("Invalid `leniency`: \"".concat(options.leniency, "\". Supported values: \"POSSIBLE\", \"VALID\"."));
			if (options.maxTries < 0) throw new TypeError("`maxTries` must be `>= 0`");
			this.text = text;
			this.options = options;
			this.metadata = metadata;
			this.leniency = _Leniency["default"][options.leniency];
			if (!this.leniency) throw new TypeError("Unknown leniency: \"".concat(options.leniency, "\""));
			/** The maximum number of retries after matching an invalid number. */
			this.maxTries = options.maxTries;
			this.PATTERN = new RegExp(PATTERN, "ig");
			/** The iteration tristate. */
			this.state = "NOT_READY";
			/** The next index to start searching at. Undefined in {@link State#DONE}. */
			this.searchIndex = 0;
			this.regExpCache = new _RegExpCache["default"](32);
		}
		/**
		* Attempts to find the next subsequence in the searched sequence on or after {@code searchIndex}
		* that represents a phone number. Returns the next match, null if none was found.
		*
		* @param index  the search index to start searching at
		* @return  the phone number match found, null if none can be found
		*/
		_createClass(PhoneNumberMatcher$1, [
			{
				key: "find",
				value: function find() {
					var matches;
					while (this.maxTries > 0 && (matches = this.PATTERN.exec(this.text)) !== null) {
						var candidate = matches[0];
						var offset = matches.index;
						candidate = (0, _parsePreCandidate["default"])(candidate);
						if ((0, _isValidPreCandidate["default"])(candidate, offset, this.text)) {
							var match = this.parseAndVerify(candidate, offset, this.text) || this.extractInnerMatch(candidate, offset, this.text);
							if (match) if (this.options.v2) return {
								startsAt: match.startsAt,
								endsAt: match.endsAt,
								number: match.phoneNumber
							};
							else {
								var phoneNumber = match.phoneNumber;
								var result = {
									startsAt: match.startsAt,
									endsAt: match.endsAt,
									phone: phoneNumber.nationalNumber
								};
								if (phoneNumber.country)
 /* istanbul ignore if */
								if (USE_NON_GEOGRAPHIC_COUNTRY_CODE && country === "001") result.countryCallingCode = phoneNumber.countryCallingCode;
								else result.country = phoneNumber.country;
								else result.countryCallingCode = phoneNumber.countryCallingCode;
								if (phoneNumber.ext) result.ext = phoneNumber.ext;
								return result;
							}
						}
						this.maxTries--;
					}
				}
			},
			{
				key: "extractInnerMatch",
				value: function extractInnerMatch(substring, offset, text) {
					for (var _iterator = _createForOfIteratorHelperLoose(INNER_MATCHES), _step; !(_step = _iterator()).done;) {
						var innerMatchPattern = _step.value;
						var isFirstMatch = true;
						var candidateMatch = void 0;
						var innerMatchRegExp = new RegExp(innerMatchPattern, "g");
						while (this.maxTries > 0 && (candidateMatch = innerMatchRegExp.exec(substring)) !== null) {
							if (isFirstMatch) {
								var _candidate = (0, _util.trimAfterFirstMatch)(UNWANTED_END_CHAR_PATTERN, substring.slice(0, candidateMatch.index));
								var _match = this.parseAndVerify(_candidate, offset, text);
								if (_match) return _match;
								this.maxTries--;
								isFirstMatch = false;
							}
							var candidate = (0, _util.trimAfterFirstMatch)(UNWANTED_END_CHAR_PATTERN, candidateMatch[1]);
							var candidateIndexGuess = substring.indexOf(candidate, candidateMatch.index);
							var match = this.parseAndVerify(candidate, offset + candidateIndexGuess, text);
							if (match) return match;
							this.maxTries--;
						}
					}
				}
			},
			{
				key: "parseAndVerify",
				value: function parseAndVerify(candidate, offset, text) {
					if (!(0, _isValidCandidate["default"])(candidate, offset, text, this.options.leniency)) return;
					var phoneNumber = (0, _parsePhoneNumber["default"])(candidate, {
						extended: true,
						defaultCountry: this.options.defaultCountry,
						defaultCallingCode: this.options.defaultCallingCode
					}, this.metadata);
					if (!phoneNumber) return;
					if (!phoneNumber.isPossible()) return;
					if (this.leniency(phoneNumber, {
						candidate,
						defaultCountry: this.options.defaultCountry,
						metadata: this.metadata,
						regExpCache: this.regExpCache
					})) return {
						startsAt: offset,
						endsAt: offset + candidate.length,
						phoneNumber
					};
				}
			},
			{
				key: "hasNext",
				value: function hasNext() {
					if (this.state === "NOT_READY") {
						this.lastMatch = this.find();
						if (this.lastMatch) this.state = "READY";
						else this.state = "DONE";
					}
					return this.state === "READY";
				}
			},
			{
				key: "next",
				value: function next() {
					if (!this.hasNext()) throw new Error("No next element");
					var result = this.lastMatch;
					this.lastMatch = null;
					this.state = "NOT_READY";
					return result;
				}
			}
		]);
		return PhoneNumberMatcher$1;
	}();
	exports["default"] = PhoneNumberMatcher;
}) });

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