const require_rolldown_runtime = require('../../../../../../_virtual/rolldown_runtime.js');
const require_isObject$1 = require('./helpers/isObject.js');
const require_semver_compare$1 = require('./tools/semver-compare.js');

//#region ../../node_modules/.pnpm/libphonenumber-js@1.11.3/node_modules/libphonenumber-js/build/metadata.js
var require_metadata = /* @__PURE__ */ require_rolldown_runtime.__commonJS({ "../../node_modules/.pnpm/libphonenumber-js@1.11.3/node_modules/libphonenumber-js/build/metadata.js": ((exports) => {
	Object.defineProperty(exports, "__esModule", { value: true });
	exports.getCountryCallingCode = getCountryCallingCode;
	exports.getExtPrefix = getExtPrefix;
	exports.isSupportedCountry = isSupportedCountry;
	exports.validateMetadata = validateMetadata;
	var _semverCompare = _interopRequireDefault(require_semver_compare$1.require_semver_compare());
	var _isObject = _interopRequireDefault(require_isObject$1.require_isObject());
	function _interopRequireDefault(obj) {
		return obj && obj.__esModule ? obj : { "default": obj };
	}
	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);
	}
	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 V3 = "1.2.0";
	var V4 = "1.7.35";
	var DEFAULT_EXT_PREFIX = " ext. ";
	var CALLING_CODE_REG_EXP = /^\d+$/;
	/**
	* See: https://gitlab.com/catamphetamine/libphonenumber-js/blob/master/METADATA.md
	*/
	var Metadata = /* @__PURE__ */ function() {
		function Metadata$1(metadata) {
			_classCallCheck(this, Metadata$1);
			validateMetadata(metadata);
			this.metadata = metadata;
			setVersion.call(this, metadata);
		}
		_createClass(Metadata$1, [
			{
				key: "getCountries",
				value: function getCountries() {
					return Object.keys(this.metadata.countries).filter(function(_) {
						return _ !== "001";
					});
				}
			},
			{
				key: "getCountryMetadata",
				value: function getCountryMetadata(countryCode) {
					return this.metadata.countries[countryCode];
				}
			},
			{
				key: "nonGeographic",
				value: function nonGeographic() {
					if (this.v1 || this.v2 || this.v3) return;
					return this.metadata.nonGeographic || this.metadata.nonGeographical;
				}
			},
			{
				key: "hasCountry",
				value: function hasCountry(country) {
					return this.getCountryMetadata(country) !== void 0;
				}
			},
			{
				key: "hasCallingCode",
				value: function hasCallingCode(callingCode) {
					if (this.getCountryCodesForCallingCode(callingCode)) return true;
					if (this.nonGeographic()) {
						if (this.nonGeographic()[callingCode]) return true;
					} else {
						var countryCodes = this.countryCallingCodes()[callingCode];
						if (countryCodes && countryCodes.length === 1 && countryCodes[0] === "001") return true;
					}
				}
			},
			{
				key: "isNonGeographicCallingCode",
				value: function isNonGeographicCallingCode(callingCode) {
					if (this.nonGeographic()) return this.nonGeographic()[callingCode] ? true : false;
					else return this.getCountryCodesForCallingCode(callingCode) ? false : true;
				}
			},
			{
				key: "country",
				value: function country(countryCode) {
					return this.selectNumberingPlan(countryCode);
				}
			},
			{
				key: "selectNumberingPlan",
				value: function selectNumberingPlan(countryCode, callingCode) {
					if (countryCode && CALLING_CODE_REG_EXP.test(countryCode)) {
						callingCode = countryCode;
						countryCode = null;
					}
					if (countryCode && countryCode !== "001") {
						if (!this.hasCountry(countryCode)) throw new Error("Unknown country: ".concat(countryCode));
						this.numberingPlan = new NumberingPlan(this.getCountryMetadata(countryCode), this);
					} else if (callingCode) {
						if (!this.hasCallingCode(callingCode)) throw new Error("Unknown calling code: ".concat(callingCode));
						this.numberingPlan = new NumberingPlan(this.getNumberingPlanMetadata(callingCode), this);
					} else this.numberingPlan = void 0;
					return this;
				}
			},
			{
				key: "getCountryCodesForCallingCode",
				value: function getCountryCodesForCallingCode(callingCode) {
					var countryCodes = this.countryCallingCodes()[callingCode];
					if (countryCodes) {
						if (countryCodes.length === 1 && countryCodes[0].length === 3) return;
						return countryCodes;
					}
				}
			},
			{
				key: "getCountryCodeForCallingCode",
				value: function getCountryCodeForCallingCode(callingCode) {
					var countryCodes = this.getCountryCodesForCallingCode(callingCode);
					if (countryCodes) return countryCodes[0];
				}
			},
			{
				key: "getNumberingPlanMetadata",
				value: function getNumberingPlanMetadata(callingCode) {
					var countryCode = this.getCountryCodeForCallingCode(callingCode);
					if (countryCode) return this.getCountryMetadata(countryCode);
					if (this.nonGeographic()) {
						var metadata = this.nonGeographic()[callingCode];
						if (metadata) return metadata;
					} else {
						var countryCodes = this.countryCallingCodes()[callingCode];
						if (countryCodes && countryCodes.length === 1 && countryCodes[0] === "001") return this.metadata.countries["001"];
					}
				}
			},
			{
				key: "countryCallingCode",
				value: function countryCallingCode() {
					return this.numberingPlan.callingCode();
				}
			},
			{
				key: "IDDPrefix",
				value: function IDDPrefix() {
					return this.numberingPlan.IDDPrefix();
				}
			},
			{
				key: "defaultIDDPrefix",
				value: function defaultIDDPrefix() {
					return this.numberingPlan.defaultIDDPrefix();
				}
			},
			{
				key: "nationalNumberPattern",
				value: function nationalNumberPattern() {
					return this.numberingPlan.nationalNumberPattern();
				}
			},
			{
				key: "possibleLengths",
				value: function possibleLengths() {
					return this.numberingPlan.possibleLengths();
				}
			},
			{
				key: "formats",
				value: function formats() {
					return this.numberingPlan.formats();
				}
			},
			{
				key: "nationalPrefixForParsing",
				value: function nationalPrefixForParsing() {
					return this.numberingPlan.nationalPrefixForParsing();
				}
			},
			{
				key: "nationalPrefixTransformRule",
				value: function nationalPrefixTransformRule() {
					return this.numberingPlan.nationalPrefixTransformRule();
				}
			},
			{
				key: "leadingDigits",
				value: function leadingDigits() {
					return this.numberingPlan.leadingDigits();
				}
			},
			{
				key: "hasTypes",
				value: function hasTypes() {
					return this.numberingPlan.hasTypes();
				}
			},
			{
				key: "type",
				value: function type(_type) {
					return this.numberingPlan.type(_type);
				}
			},
			{
				key: "ext",
				value: function ext() {
					return this.numberingPlan.ext();
				}
			},
			{
				key: "countryCallingCodes",
				value: function countryCallingCodes() {
					if (this.v1) return this.metadata.country_phone_code_to_countries;
					return this.metadata.country_calling_codes;
				}
			},
			{
				key: "chooseCountryByCountryCallingCode",
				value: function chooseCountryByCountryCallingCode(callingCode) {
					return this.selectNumberingPlan(callingCode);
				}
			},
			{
				key: "hasSelectedNumberingPlan",
				value: function hasSelectedNumberingPlan() {
					return this.numberingPlan !== void 0;
				}
			}
		]);
		return Metadata$1;
	}();
	exports["default"] = Metadata;
	var NumberingPlan = /* @__PURE__ */ function() {
		function NumberingPlan$1(metadata, globalMetadataObject) {
			_classCallCheck(this, NumberingPlan$1);
			this.globalMetadataObject = globalMetadataObject;
			this.metadata = metadata;
			setVersion.call(this, globalMetadataObject.metadata);
		}
		_createClass(NumberingPlan$1, [
			{
				key: "callingCode",
				value: function callingCode() {
					return this.metadata[0];
				}
			},
			{
				key: "getDefaultCountryMetadataForRegion",
				value: function getDefaultCountryMetadataForRegion() {
					return this.globalMetadataObject.getNumberingPlanMetadata(this.callingCode());
				}
			},
			{
				key: "IDDPrefix",
				value: function IDDPrefix() {
					if (this.v1 || this.v2) return;
					return this.metadata[1];
				}
			},
			{
				key: "defaultIDDPrefix",
				value: function defaultIDDPrefix() {
					if (this.v1 || this.v2) return;
					return this.metadata[12];
				}
			},
			{
				key: "nationalNumberPattern",
				value: function nationalNumberPattern() {
					if (this.v1 || this.v2) return this.metadata[1];
					return this.metadata[2];
				}
			},
			{
				key: "possibleLengths",
				value: function possibleLengths() {
					if (this.v1) return;
					return this.metadata[this.v2 ? 2 : 3];
				}
			},
			{
				key: "_getFormats",
				value: function _getFormats(metadata) {
					return metadata[this.v1 ? 2 : this.v2 ? 3 : 4];
				}
			},
			{
				key: "formats",
				value: function formats() {
					var _this = this;
					return (this._getFormats(this.metadata) || this._getFormats(this.getDefaultCountryMetadataForRegion()) || []).map(function(_) {
						return new Format(_, _this);
					});
				}
			},
			{
				key: "nationalPrefix",
				value: function nationalPrefix() {
					return this.metadata[this.v1 ? 3 : this.v2 ? 4 : 5];
				}
			},
			{
				key: "_getNationalPrefixFormattingRule",
				value: function _getNationalPrefixFormattingRule(metadata) {
					return metadata[this.v1 ? 4 : this.v2 ? 5 : 6];
				}
			},
			{
				key: "nationalPrefixFormattingRule",
				value: function nationalPrefixFormattingRule() {
					return this._getNationalPrefixFormattingRule(this.metadata) || this._getNationalPrefixFormattingRule(this.getDefaultCountryMetadataForRegion());
				}
			},
			{
				key: "_nationalPrefixForParsing",
				value: function _nationalPrefixForParsing() {
					return this.metadata[this.v1 ? 5 : this.v2 ? 6 : 7];
				}
			},
			{
				key: "nationalPrefixForParsing",
				value: function nationalPrefixForParsing() {
					return this._nationalPrefixForParsing() || this.nationalPrefix();
				}
			},
			{
				key: "nationalPrefixTransformRule",
				value: function nationalPrefixTransformRule() {
					return this.metadata[this.v1 ? 6 : this.v2 ? 7 : 8];
				}
			},
			{
				key: "_getNationalPrefixIsOptionalWhenFormatting",
				value: function _getNationalPrefixIsOptionalWhenFormatting() {
					return !!this.metadata[this.v1 ? 7 : this.v2 ? 8 : 9];
				}
			},
			{
				key: "nationalPrefixIsOptionalWhenFormattingInNationalFormat",
				value: function nationalPrefixIsOptionalWhenFormattingInNationalFormat() {
					return this._getNationalPrefixIsOptionalWhenFormatting(this.metadata) || this._getNationalPrefixIsOptionalWhenFormatting(this.getDefaultCountryMetadataForRegion());
				}
			},
			{
				key: "leadingDigits",
				value: function leadingDigits() {
					return this.metadata[this.v1 ? 8 : this.v2 ? 9 : 10];
				}
			},
			{
				key: "types",
				value: function types() {
					return this.metadata[this.v1 ? 9 : this.v2 ? 10 : 11];
				}
			},
			{
				key: "hasTypes",
				value: function hasTypes() {
					/* istanbul ignore next */
					if (this.types() && this.types().length === 0) return false;
					return !!this.types();
				}
			},
			{
				key: "type",
				value: function type(_type2) {
					if (this.hasTypes() && getType(this.types(), _type2)) return new Type(getType(this.types(), _type2), this);
				}
			},
			{
				key: "ext",
				value: function ext() {
					if (this.v1 || this.v2) return DEFAULT_EXT_PREFIX;
					return this.metadata[13] || DEFAULT_EXT_PREFIX;
				}
			}
		]);
		return NumberingPlan$1;
	}();
	var Format = /* @__PURE__ */ function() {
		function Format$1(format, metadata) {
			_classCallCheck(this, Format$1);
			this._format = format;
			this.metadata = metadata;
		}
		_createClass(Format$1, [
			{
				key: "pattern",
				value: function pattern() {
					return this._format[0];
				}
			},
			{
				key: "format",
				value: function format() {
					return this._format[1];
				}
			},
			{
				key: "leadingDigitsPatterns",
				value: function leadingDigitsPatterns() {
					return this._format[2] || [];
				}
			},
			{
				key: "nationalPrefixFormattingRule",
				value: function nationalPrefixFormattingRule() {
					return this._format[3] || this.metadata.nationalPrefixFormattingRule();
				}
			},
			{
				key: "nationalPrefixIsOptionalWhenFormattingInNationalFormat",
				value: function nationalPrefixIsOptionalWhenFormattingInNationalFormat() {
					return !!this._format[4] || this.metadata.nationalPrefixIsOptionalWhenFormattingInNationalFormat();
				}
			},
			{
				key: "nationalPrefixIsMandatoryWhenFormattingInNationalFormat",
				value: function nationalPrefixIsMandatoryWhenFormattingInNationalFormat() {
					return this.usesNationalPrefix() && !this.nationalPrefixIsOptionalWhenFormattingInNationalFormat();
				}
			},
			{
				key: "usesNationalPrefix",
				value: function usesNationalPrefix() {
					return this.nationalPrefixFormattingRule() && !FIRST_GROUP_ONLY_PREFIX_PATTERN.test(this.nationalPrefixFormattingRule()) ? true : false;
				}
			},
			{
				key: "internationalFormat",
				value: function internationalFormat() {
					return this._format[5] || this.format();
				}
			}
		]);
		return Format$1;
	}();
	/**
	* A pattern that is used to determine if the national prefix formatting rule
	* has the first group only, i.e., does not start with the national prefix.
	* Note that the pattern explicitly allows for unbalanced parentheses.
	*/
	var FIRST_GROUP_ONLY_PREFIX_PATTERN = /^\(?\$1\)?$/;
	var Type = /* @__PURE__ */ function() {
		function Type$1(type, metadata) {
			_classCallCheck(this, Type$1);
			this.type = type;
			this.metadata = metadata;
		}
		_createClass(Type$1, [{
			key: "pattern",
			value: function pattern() {
				if (this.metadata.v1) return this.type;
				return this.type[0];
			}
		}, {
			key: "possibleLengths",
			value: function possibleLengths() {
				if (this.metadata.v1) return;
				return this.type[1] || this.metadata.possibleLengths();
			}
		}]);
		return Type$1;
	}();
	function getType(types, type) {
		switch (type) {
			case "FIXED_LINE": return types[0];
			case "MOBILE": return types[1];
			case "TOLL_FREE": return types[2];
			case "PREMIUM_RATE": return types[3];
			case "PERSONAL_NUMBER": return types[4];
			case "VOICEMAIL": return types[5];
			case "UAN": return types[6];
			case "PAGER": return types[7];
			case "VOIP": return types[8];
			case "SHARED_COST": return types[9];
		}
	}
	function validateMetadata(metadata) {
		if (!metadata) throw new Error("[libphonenumber-js] `metadata` argument not passed. Check your arguments.");
		if (!(0, _isObject["default"])(metadata) || !(0, _isObject["default"])(metadata.countries)) throw new Error("[libphonenumber-js] `metadata` argument was passed but it's not a valid metadata. Must be an object having `.countries` child object property. Got ".concat((0, _isObject["default"])(metadata) ? "an object of shape: { " + Object.keys(metadata).join(", ") + " }" : "a " + typeOf(metadata) + ": " + metadata, "."));
	}
	/* istanbul ignore next */
	var typeOf = function typeOf$1(_) {
		return _typeof(_);
	};
	/**
	* Returns extension prefix for a country.
	* @param  {string} country
	* @param  {object} metadata
	* @return {string?}
	* @example
	* // Returns " ext. "
	* getExtPrefix("US")
	*/
	function getExtPrefix(country, metadata) {
		metadata = new Metadata(metadata);
		if (metadata.hasCountry(country)) return metadata.country(country).ext();
		return DEFAULT_EXT_PREFIX;
	}
	/**
	* Returns "country calling code" for a country.
	* Throws an error if the country doesn't exist or isn't supported by this library.
	* @param  {string} country
	* @param  {object} metadata
	* @return {string}
	* @example
	* // Returns "44"
	* getCountryCallingCode("GB")
	*/
	function getCountryCallingCode(country, metadata) {
		metadata = new Metadata(metadata);
		if (metadata.hasCountry(country)) return metadata.country(country).countryCallingCode();
		throw new Error("Unknown country: ".concat(country));
	}
	function isSupportedCountry(country, metadata) {
		return metadata.countries.hasOwnProperty(country);
	}
	function setVersion(metadata) {
		var version = metadata.version;
		if (typeof version === "number") {
			this.v1 = version === 1;
			this.v2 = version === 2;
			this.v3 = version === 3;
			this.v4 = version === 4;
		} else if (!version) this.v1 = true;
		else if ((0, _semverCompare["default"])(version, V3) === -1) this.v2 = true;
		else if ((0, _semverCompare["default"])(version, V4) === -1) this.v3 = true;
		else this.v4 = true;
	}
}) });

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