import s from "./index-stripIddPrefix.js";
import M from "./index-extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js";
import u from "./index-metadata.js";
import { MAX_LENGTH_COUNTRY_CODE as I } from "./index-constants3.js";
function p(r, o, f, i) {
  if (!r)
    return {};
  var n;
  if (r[0] !== "+") {
    var l = s(r, o, f, i);
    if (l && l !== r)
      n = !0, r = "+" + l;
    else {
      if (o || f) {
        var _ = M(r, o, f, i), C = _.countryCallingCode, N = _.number;
        if (C)
          return {
            countryCallingCodeSource: "FROM_NUMBER_WITHOUT_PLUS_SIGN",
            countryCallingCode: C,
            number: N
          };
      }
      return {
        // No need to set it to `UNSPECIFIED`. It can be just `undefined`.
        // countryCallingCodeSource: 'UNSPECIFIED',
        number: r
      };
    }
  }
  if (r[1] === "0")
    return {};
  i = new u(i);
  for (var e = 2; e - 1 <= I && e <= r.length; ) {
    var t = r.slice(1, e);
    if (i.hasCallingCode(t))
      return i.selectNumberingPlan(t), {
        countryCallingCodeSource: n ? "FROM_NUMBER_WITH_IDD" : "FROM_NUMBER_WITH_PLUS_SIGN",
        countryCallingCode: t,
        number: r.slice(e)
      };
    e++;
  }
  return {};
}
export {
  p as default
};
