const require_rolldown_runtime = require('../../../../../../../_virtual/rolldown_runtime.js');
const require_ParseError$1 = require('../ParseError.js');
const require_extractPhoneContext$1 = require('./extractPhoneContext.js');

//#region ../../node_modules/.pnpm/libphonenumber-js@1.11.3/node_modules/libphonenumber-js/build/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js
var require_extractFormattedPhoneNumberFromPossibleRfc3966NumberUri = /* @__PURE__ */ require_rolldown_runtime.__commonJS({ "../../node_modules/.pnpm/libphonenumber-js@1.11.3/node_modules/libphonenumber-js/build/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.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["default"] = extractFormattedPhoneNumberFromPossibleRfc3966NumberUri;
	var _extractPhoneContext = _interopRequireWildcard(require_extractPhoneContext$1.require_extractPhoneContext());
	var _ParseError = _interopRequireDefault(require_ParseError$1.require_ParseError());
	function _interopRequireDefault(obj) {
		return obj && obj.__esModule ? obj : { "default": obj };
	}
	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;
	}
	/**
	* @param  {string} numberToParse
	* @param  {string} nationalNumber
	* @return {}
	*/
	function extractFormattedPhoneNumberFromPossibleRfc3966NumberUri(numberToParse, _ref) {
		var extractFormattedPhoneNumber = _ref.extractFormattedPhoneNumber;
		var phoneContext = (0, _extractPhoneContext["default"])(numberToParse);
		if (!(0, _extractPhoneContext.isPhoneContextValid)(phoneContext)) throw new _ParseError["default"]("NOT_A_NUMBER");
		var phoneNumberString;
		if (phoneContext === null) phoneNumberString = extractFormattedPhoneNumber(numberToParse) || "";
		else {
			phoneNumberString = "";
			if (phoneContext.charAt(0) === _extractPhoneContext.PLUS_SIGN) phoneNumberString += phoneContext;
			var indexOfRfc3966Prefix = numberToParse.indexOf(_extractPhoneContext.RFC3966_PREFIX_);
			var indexOfNationalNumber;
			/* istanbul ignore else */
			if (indexOfRfc3966Prefix >= 0) indexOfNationalNumber = indexOfRfc3966Prefix + _extractPhoneContext.RFC3966_PREFIX_.length;
			else indexOfNationalNumber = 0;
			var indexOfPhoneContext = numberToParse.indexOf(_extractPhoneContext.RFC3966_PHONE_CONTEXT_);
			phoneNumberString += numberToParse.substring(indexOfNationalNumber, indexOfPhoneContext);
		}
		var indexOfIsdn = phoneNumberString.indexOf(_extractPhoneContext.RFC3966_ISDN_SUBADDRESS_);
		if (indexOfIsdn > 0) phoneNumberString = phoneNumberString.substring(0, indexOfIsdn);
		if (phoneNumberString !== "") return phoneNumberString;
	}
}) });

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