const require_rolldown_runtime = require('../../../../../../../_virtual/rolldown_runtime.js');
const require_metadata$1 = require('../metadata.js');
const require_parseDigits$1 = require('../helpers/parseDigits.js');
const require_isValid$1 = require('../isValid.js');
const require_format$1 = require('../format.js');
const require_getCountryByCallingCode$1 = require('../helpers/getCountryByCallingCode.js');
const require_util$1 = require('./util.js');
const require_matchPhoneNumberStringAgainstPhoneNumber$1 = require('./matchPhoneNumberStringAgainstPhoneNumber.js');

//#region ../../node_modules/.pnpm/libphonenumber-js@1.11.3/node_modules/libphonenumber-js/build/findNumbers/Leniency.js
var require_Leniency = /* @__PURE__ */ require_rolldown_runtime.__commonJS({ "../../node_modules/.pnpm/libphonenumber-js@1.11.3/node_modules/libphonenumber-js/build/findNumbers/Leniency.js": ((exports) => {
	Object.defineProperty(exports, "__esModule", { value: true });
	exports.containsMoreThanOneSlashInNationalNumber = containsMoreThanOneSlashInNationalNumber;
	_interopRequireDefault(require_isValid$1.require_isValid());
	var _parseDigits = _interopRequireDefault(require_parseDigits$1.require_parseDigits());
	var _matchPhoneNumberStringAgainstPhoneNumber = _interopRequireDefault(require_matchPhoneNumberStringAgainstPhoneNumber$1.require_matchPhoneNumberStringAgainstPhoneNumber());
	var _metadata2 = _interopRequireDefault(require_metadata$1.require_metadata());
	var _getCountryByCallingCode = _interopRequireDefault(require_getCountryByCallingCode$1.require_getCountryByCallingCode());
	var _format = require_format$1.require_format();
	require_util$1.require_util();
	function _interopRequireDefault(obj) {
		return obj && obj.__esModule ? obj : { "default": obj };
	}
	/**
	* Leniency when finding potential phone numbers in text segments
	* The levels here are ordered in increasing strictness.
	*/
	var _default = {
		POSSIBLE: function POSSIBLE(phoneNumber, _ref) {
			_ref.candidate;
			_ref.metadata;
			return true;
		},
		VALID: function VALID(phoneNumber, _ref2) {
			var candidate = _ref2.candidate;
			_ref2.defaultCountry;
			var metadata = _ref2.metadata;
			if (!phoneNumber.isValid() || !containsOnlyValidXChars(phoneNumber, candidate, metadata)) return false;
			return true;
		},
		STRICT_GROUPING: function STRICT_GROUPING(phoneNumber, _ref3) {
			var candidate = _ref3.candidate, defaultCountry = _ref3.defaultCountry, metadata = _ref3.metadata, regExpCache = _ref3.regExpCache;
			if (!phoneNumber.isValid() || !containsOnlyValidXChars(phoneNumber, candidate, metadata) || containsMoreThanOneSlashInNationalNumber(phoneNumber, candidate) || !isNationalPrefixPresentIfRequired(phoneNumber, {
				defaultCountry,
				metadata
			})) return false;
			return checkNumberGroupingIsValid(phoneNumber, candidate, metadata, allNumberGroupsRemainGrouped, regExpCache);
		},
		EXACT_GROUPING: function EXACT_GROUPING(phoneNumber, _ref4) {
			var candidate = _ref4.candidate, defaultCountry = _ref4.defaultCountry, metadata = _ref4.metadata, regExpCache = _ref4.regExpCache;
			if (!phoneNumber.isValid() || !containsOnlyValidXChars(phoneNumber, candidate, metadata) || containsMoreThanOneSlashInNationalNumber(phoneNumber, candidate) || !isNationalPrefixPresentIfRequired(phoneNumber, {
				defaultCountry,
				metadata
			})) return false;
			return checkNumberGroupingIsValid(phoneNumber, candidate, metadata, allNumberGroupsAreExactlyPresent, regExpCache);
		}
	};
	exports["default"] = _default;
	function containsOnlyValidXChars(phoneNumber, candidate, metadata) {
		for (var index = 0; index < candidate.length - 1; index++) {
			var charAtIndex = candidate.charAt(index);
			if (charAtIndex === "x" || charAtIndex === "X") {
				var charAtNextIndex = candidate.charAt(index + 1);
				if (charAtNextIndex === "x" || charAtNextIndex === "X") {
					index++;
					if ((0, _matchPhoneNumberStringAgainstPhoneNumber["default"])(candidate.substring(index), phoneNumber, metadata) !== "NSN_MATCH") return false;
				} else {
					var ext = (0, _parseDigits["default"])(candidate.substring(index));
					if (ext) {
						if (phoneNumber.ext !== ext) return false;
					} else if (phoneNumber.ext) return false;
				}
			}
		}
		return true;
	}
	function isNationalPrefixPresentIfRequired(phoneNumber, _ref5) {
		var defaultCountry = _ref5.defaultCountry, _metadata = _ref5.metadata;
		if (phoneNumber.__countryCallingCodeSource !== "FROM_DEFAULT_COUNTRY") return true;
		var metadata = new _metadata2["default"](_metadata);
		metadata.selectNumberingPlan(phoneNumber.countryCallingCode);
		phoneNumber.country || (0, _getCountryByCallingCode["default"])(phoneNumber.countryCallingCode, {
			nationalNumber: phoneNumber.nationalNumber,
			defaultCountry,
			metadata
		});
		var nationalNumber = phoneNumber.nationalNumber;
		var format = (0, _format.chooseFormatForNumber)(metadata.numberingPlan.formats(), nationalNumber);
		if (format.nationalPrefixFormattingRule()) {
			if (metadata.numberingPlan.nationalPrefixIsOptionalWhenFormattingInNationalFormat()) return true;
			if (!format.usesNationalPrefix()) return true;
			return Boolean(phoneNumber.nationalPrefix);
		}
		return true;
	}
	function containsMoreThanOneSlashInNationalNumber(phoneNumber, candidate) {
		var firstSlashInBodyIndex = candidate.indexOf("/");
		if (firstSlashInBodyIndex < 0) return false;
		var secondSlashInBodyIndex = candidate.indexOf("/", firstSlashInBodyIndex + 1);
		if (secondSlashInBodyIndex < 0) return false;
		if ((phoneNumber.__countryCallingCodeSource === "FROM_NUMBER_WITH_PLUS_SIGN" || phoneNumber.__countryCallingCodeSource === "FROM_NUMBER_WITHOUT_PLUS_SIGN") && (0, _parseDigits["default"])(candidate.substring(0, firstSlashInBodyIndex)) === phoneNumber.countryCallingCode) return candidate.slice(secondSlashInBodyIndex + 1).indexOf("/") >= 0;
		return true;
	}
	function checkNumberGroupingIsValid(number, candidate, metadata, checkGroups, regExpCache) {
		throw new Error("This part of code hasn't been ported");
	}
	function allNumberGroupsAreExactlyPresent(metadata, number, normalizedCandidate, formattedNumberGroups) {
		throw new Error("This part of code hasn't been ported");
	}
	function allNumberGroupsRemainGrouped(metadata, number, normalizedCandidate, formattedNumberGroups) {
		throw new Error("This part of code hasn't been ported");
	}
}) });

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