import f from "./index-metadata.js";
import u from "./index-getNumberType.js";
function l(e, t) {
  var r = typeof Symbol < "u" && e[Symbol.iterator] || e["@@iterator"];
  if (r) return (r = r.call(e)).next.bind(r);
  if (Array.isArray(e) || (r = y(e)) || t) {
    r && (e = r);
    var n = 0;
    return function() {
      return n >= e.length ? { done: !0 } : { done: !1, value: e[n++] };
    };
  }
  throw new TypeError(`Invalid attempt to iterate non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`);
}
function y(e, t) {
  if (e) {
    if (typeof e == "string") return a(e, t);
    var r = Object.prototype.toString.call(e).slice(8, -1);
    if (r === "Object" && e.constructor && (r = e.constructor.name), r === "Map" || r === "Set") return Array.from(e);
    if (r === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)) return a(e, t);
  }
}
function a(e, t) {
  (t == null || t > e.length) && (t = e.length);
  for (var r = 0, n = new Array(t); r < t; r++)
    n[r] = e[r];
  return n;
}
function p(e, t, r) {
  r = new f(r);
  for (var n = l(e), o; !(o = n()).done; ) {
    var i = o.value;
    if (r.country(i), r.leadingDigits()) {
      if (t && t.search(r.leadingDigits()) === 0)
        return i;
    } else if (u({
      phone: t,
      country: i
    }, void 0, r.metadata))
      return i;
  }
}
export {
  p as default
};
