/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import { q as f } from "./queryUtils.js";
async function g(t, e) {
  let a;
  return await t.when(() => {
    a = t.map.allLayers.toArray().reduce((s, n) => ((n.type === "feature" || n?.type === "subtype-group") && (s[n.id] = {
      name: n.title,
      supportsUpdate: void 0
    }), s), {});
  }), l(e, a, t);
}
async function w(t, e) {
  let a;
  return await t.when(() => {
    a = t.map.allTables.toArray().reduce((s, n) => (s[n.id] = {
      name: n.title,
      supportsUpdate: void 0
    }, s), {});
  }), l(e, a, t);
}
async function l(t, e, a) {
  const s = {}, n = Object.keys(e);
  for (const i of n)
    try {
      const r = await c(a, i);
      await r.load(), await r.when();
      const o = r.editingEnabled && r.capabilities?.operations.supportsUpdate;
      (!t || t && o) && (s[i] = {
        name: e[i].name,
        supportsUpdate: o
      });
    } catch (r) {
      console.log(r);
      continue;
    }
  return s;
}
async function b(t, e) {
  const a = await c(t, e);
  return a ? await t.whenLayerView(a) : void 0;
}
async function c(t, e) {
  let a = [];
  return await t?.when(() => {
    a = [...t.map.allLayers.toArray(), ...t.map.allTables.toArray()].filter((s) => s.id === e);
  }), a.length > 0 ? a[0] : void 0;
}
async function m(t) {
  const e = t.map.allLayers.filter((s) => s.type === "feature").toArray().map((s) => s);
  let a = [];
  return await t.when(() => {
    a = e.map((s) => t.whenLayerView(s));
  }), await Promise.allSettled(a), e;
}
async function p(t) {
  const e = t.map.allTables.toArray();
  let a = [];
  return await t.when(() => {
    a = e.map((s) => s.load());
  }), await Promise.allSettled(a), e;
}
async function I(t, e, a, s = !1, n = 0) {
  return s && (await u(t, e, a, !1, void 0, n), await new Promise((i) => setTimeout(i, 1e3))), e.highlight(t);
}
async function T(t) {
  const e = y(t);
  return Object.keys(e).reduce((a, s) => {
    const n = e[s];
    return a.push(n.layerView.highlight(n.ids)), a;
  }, []);
}
function y(t) {
  return t.reduce((e, a) => {
    const s = a.layerView, n = s?.layer.id;
    return n && Object.keys(e).indexOf(n) > -1 ? e[n].ids = [.../* @__PURE__ */ new Set([...a.selectedIds, ...e[n].ids])] : n && (e[n] = {
      layerView: s,
      ids: a.selectedIds
    }), a.workflowType === "REFINE" && Object.keys(a.refineInfos).forEach((i) => {
      const r = a.refineInfos[i];
      Object.keys(e).indexOf(i) > -1 && (e[i].ids = [.../* @__PURE__ */ new Set([...r.addIds, ...e[i].ids])], e[i].ids = e[i].ids.filter((o) => r.removeIds.indexOf(o) < 0));
    }), e;
  }, {});
}
async function d(t, e, a) {
  const s = {
    objectIds: t
  };
  e.featureEffect = {
    ...a,
    filter: s
  }, setTimeout(() => {
    e.featureEffect = void 0;
  }, 1300);
}
async function u(t, e, a, s = !0, n, i = 0) {
  const r = await f(t, e.layer), o = { target: r.extent };
  r.count === 1 && e.layer.geometryType === "point" && i && (o.scale = i), await a.goTo(o), s && await d(t, e, n);
}
export {
  m as a,
  p as b,
  b as c,
  g as d,
  u as e,
  w as f,
  c as g,
  I as h,
  y as i,
  T as j
};
