const require_rolldown_runtime = require('../../../../../../_virtual/rolldown_runtime.js');
const require_metadata$1 = require('./metadata.js');
const require_matchesEntirely$1 = require('./helpers/matchesEntirely.js');
const require_formatNationalNumberUsingFormat$1 = require('./helpers/formatNationalNumberUsingFormat.js');
const require_getIddPrefix$1 = require('./helpers/getIddPrefix.js');
const require_RFC3966$1 = require('./helpers/RFC3966.js');

//#region ../../node_modules/.pnpm/libphonenumber-js@1.11.3/node_modules/libphonenumber-js/build/format.js
var require_format = /* @__PURE__ */ require_rolldown_runtime.__commonJS({ "../../node_modules/.pnpm/libphonenumber-js@1.11.3/node_modules/libphonenumber-js/build/format.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 });
	exports.chooseFormatForNumber = chooseFormatForNumber;
	exports["default"] = formatNumber;
	var _matchesEntirely = _interopRequireDefault(require_matchesEntirely$1.require_matchesEntirely());
	var _formatNationalNumberUsingFormat = _interopRequireDefault(require_formatNationalNumberUsingFormat$1.require_formatNationalNumberUsingFormat());
	var _metadata = _interopRequireWildcard(require_metadata$1.require_metadata());
	var _getIddPrefix = _interopRequireDefault(require_getIddPrefix$1.require_getIddPrefix());
	var _RFC = require_RFC3966$1.require_RFC3966();
	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 ownKeys(object, enumerableOnly) {
		var keys = Object.keys(object);
		if (Object.getOwnPropertySymbols) {
			var symbols = Object.getOwnPropertySymbols(object);
			enumerableOnly && (symbols = symbols.filter(function(sym) {
				return Object.getOwnPropertyDescriptor(object, sym).enumerable;
			})), keys.push.apply(keys, symbols);
		}
		return keys;
	}
	function _objectSpread(target) {
		for (var i = 1; i < arguments.length; i++) {
			var source = null != arguments[i] ? arguments[i] : {};
			i % 2 ? ownKeys(Object(source), !0).forEach(function(key) {
				_defineProperty(target, key, source[key]);
			}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
				Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
			});
		}
		return target;
	}
	function _defineProperty(obj, key, value) {
		if (key in obj) Object.defineProperty(obj, key, {
			value,
			enumerable: true,
			configurable: true,
			writable: true
		});
		else obj[key] = value;
		return obj;
	}
	var DEFAULT_OPTIONS = { formatExtension: function formatExtension(formattedNumber, extension, metadata) {
		return "".concat(formattedNumber).concat(metadata.ext()).concat(extension);
	} };
	/**
	* Formats a phone number.
	*
	* format(phoneNumberInstance, 'INTERNATIONAL', { ..., v2: true }, metadata)
	* format(phoneNumberInstance, 'NATIONAL', { ..., v2: true }, metadata)
	*
	* format({ phone: '8005553535', country: 'RU' }, 'INTERNATIONAL', { ... }, metadata)
	* format({ phone: '8005553535', country: 'RU' }, 'NATIONAL', undefined, metadata)
	*
	* @param  {object|PhoneNumber} input — If `options.v2: true` flag is passed, the `input` should be a `PhoneNumber` instance. Otherwise, it should be an object of shape `{ phone: '...', country: '...' }`.
	* @param  {string} format
	* @param  {object} [options]
	* @param  {object} metadata
	* @return {string}
	*/
	function formatNumber(input, format, options, metadata) {
		if (options) options = _objectSpread(_objectSpread({}, DEFAULT_OPTIONS), options);
		else options = DEFAULT_OPTIONS;
		metadata = new _metadata["default"](metadata);
		if (input.country && input.country !== "001") {
			if (!metadata.hasCountry(input.country)) throw new Error("Unknown country: ".concat(input.country));
			metadata.country(input.country);
		} else if (input.countryCallingCode) metadata.selectNumberingPlan(input.countryCallingCode);
		else return input.phone || "";
		var countryCallingCode = metadata.countryCallingCode();
		var nationalNumber = options.v2 ? input.nationalNumber : input.phone;
		var number;
		switch (format) {
			case "NATIONAL":
				if (!nationalNumber) return "";
				number = formatNationalNumber(nationalNumber, input.carrierCode, "NATIONAL", metadata, options);
				return addExtension(number, input.ext, metadata, options.formatExtension);
			case "INTERNATIONAL":
				if (!nationalNumber) return "+".concat(countryCallingCode);
				number = formatNationalNumber(nationalNumber, null, "INTERNATIONAL", metadata, options);
				number = "+".concat(countryCallingCode, " ").concat(number);
				return addExtension(number, input.ext, metadata, options.formatExtension);
			case "E.164": return "+".concat(countryCallingCode).concat(nationalNumber);
			case "RFC3966": return (0, _RFC.formatRFC3966)({
				number: "+".concat(countryCallingCode).concat(nationalNumber),
				ext: input.ext
			});
			case "IDD":
				if (!options.fromCountry) return;
				return addExtension(formatIDD(nationalNumber, input.carrierCode, countryCallingCode, options.fromCountry, metadata), input.ext, metadata, options.formatExtension);
			default: throw new Error("Unknown \"format\" argument passed to \"formatNumber()\": \"".concat(format, "\""));
		}
	}
	function formatNationalNumber(number, carrierCode, formatAs, metadata, options) {
		var format = chooseFormatForNumber(metadata.formats(), number);
		if (!format) return number;
		return (0, _formatNationalNumberUsingFormat["default"])(number, format, {
			useInternationalFormat: formatAs === "INTERNATIONAL",
			withNationalPrefix: format.nationalPrefixIsOptionalWhenFormattingInNationalFormat() && options && options.nationalPrefix === false ? false : true,
			carrierCode,
			metadata
		});
	}
	function chooseFormatForNumber(availableFormats, nationalNnumber) {
		for (var _iterator = _createForOfIteratorHelperLoose(availableFormats), _step; !(_step = _iterator()).done;) {
			var format = _step.value;
			if (format.leadingDigitsPatterns().length > 0) {
				var lastLeadingDigitsPattern = format.leadingDigitsPatterns()[format.leadingDigitsPatterns().length - 1];
				if (nationalNnumber.search(lastLeadingDigitsPattern) !== 0) continue;
			}
			if ((0, _matchesEntirely["default"])(nationalNnumber, format.pattern())) return format;
		}
	}
	function addExtension(formattedNumber, ext, metadata, formatExtension) {
		return ext ? formatExtension(formattedNumber, ext, metadata) : formattedNumber;
	}
	function formatIDD(nationalNumber, carrierCode, countryCallingCode, fromCountry, metadata) {
		if ((0, _metadata.getCountryCallingCode)(fromCountry, metadata.metadata) === countryCallingCode) {
			var formattedNumber = formatNationalNumber(nationalNumber, carrierCode, "NATIONAL", metadata);
			if (countryCallingCode === "1") return countryCallingCode + " " + formattedNumber;
			return formattedNumber;
		}
		var iddPrefix = (0, _getIddPrefix["default"])(fromCountry, void 0, metadata.metadata);
		if (iddPrefix) return "".concat(iddPrefix, " ").concat(countryCallingCode, " ").concat(formatNationalNumber(nationalNumber, null, "INTERNATIONAL", metadata));
	}
}) });

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