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_stripIddPrefix$1 = require('./stripIddPrefix.js');
const require_extractCountryCallingCodeFromInternationalNumberWithoutPlusSign$1 = require('./extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js');

//#region ../../node_modules/.pnpm/libphonenumber-js@1.11.3/node_modules/libphonenumber-js/build/helpers/extractCountryCallingCode.js
var require_extractCountryCallingCode = /* @__PURE__ */ require_rolldown_runtime.__commonJS({ "../../node_modules/.pnpm/libphonenumber-js@1.11.3/node_modules/libphonenumber-js/build/helpers/extractCountryCallingCode.js": ((exports) => {
	Object.defineProperty(exports, "__esModule", { value: true });
	exports["default"] = extractCountryCallingCode;
	var _stripIddPrefix = _interopRequireDefault(require_stripIddPrefix$1.require_stripIddPrefix());
	var _extractCountryCallingCodeFromInternationalNumberWithoutPlusSign = _interopRequireDefault(require_extractCountryCallingCodeFromInternationalNumberWithoutPlusSign$1.require_extractCountryCallingCodeFromInternationalNumberWithoutPlusSign());
	var _metadata = _interopRequireDefault(require_metadata$1.require_metadata());
	var _constants = require_constants$1.require_constants();
	function _interopRequireDefault(obj) {
		return obj && obj.__esModule ? obj : { "default": obj };
	}
	/**
	* Converts a phone number digits (possibly with a `+`)
	* into a calling code and the rest phone number digits.
	* The "rest phone number digits" could include
	* a national prefix, carrier code, and national
	* (significant) number.
	* @param  {string} number — Phone number digits (possibly with a `+`).
	* @param  {string} [country] — Default country.
	* @param  {string} [callingCode] — Default calling code (some phone numbering plans are non-geographic).
	* @param  {object} metadata
	* @return {object} `{ countryCallingCodeSource: string?, countryCallingCode: string?, number: string }`
	* @example
	* // Returns `{ countryCallingCode: "1", number: "2133734253" }`.
	* extractCountryCallingCode('2133734253', 'US', null, metadata)
	* extractCountryCallingCode('2133734253', null, '1', metadata)
	* extractCountryCallingCode('+12133734253', null, null, metadata)
	* extractCountryCallingCode('+12133734253', 'RU', null, metadata)
	*/
	function extractCountryCallingCode(number, country, callingCode, metadata) {
		if (!number) return {};
		var isNumberWithIddPrefix;
		if (number[0] !== "+") {
			var numberWithoutIDD = (0, _stripIddPrefix["default"])(number, country, callingCode, metadata);
			if (numberWithoutIDD && numberWithoutIDD !== number) {
				isNumberWithIddPrefix = true;
				number = "+" + numberWithoutIDD;
			} else {
				if (country || callingCode) {
					var _extractCountryCallin = (0, _extractCountryCallingCodeFromInternationalNumberWithoutPlusSign["default"])(number, country, callingCode, metadata), countryCallingCode = _extractCountryCallin.countryCallingCode, shorterNumber = _extractCountryCallin.number;
					if (countryCallingCode) return {
						countryCallingCodeSource: "FROM_NUMBER_WITHOUT_PLUS_SIGN",
						countryCallingCode,
						number: shorterNumber
					};
				}
				return { number };
			}
		}
		if (number[1] === "0") return {};
		metadata = new _metadata["default"](metadata);
		var i = 2;
		while (i - 1 <= _constants.MAX_LENGTH_COUNTRY_CODE && i <= number.length) {
			var _countryCallingCode = number.slice(1, i);
			if (metadata.hasCallingCode(_countryCallingCode)) {
				metadata.selectNumberingPlan(_countryCallingCode);
				return {
					countryCallingCodeSource: isNumberWithIddPrefix ? "FROM_NUMBER_WITH_IDD" : "FROM_NUMBER_WITH_PLUS_SIGN",
					countryCallingCode: _countryCallingCode,
					number: number.slice(i)
				};
			}
			i++;
		}
		return {};
	}
}) });

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