import { reactive as H, computed as K, watch as E, onMounted as Q, toRefs as X, defineComponent as Y, resolveComponent as x, openBlock as u, createElementBlock as h, normalizeClass as p, unref as c, createVNode as Z, isRef as ee, createBlock as ae, Fragment as se, renderList as te, createElementVNode as M, toDisplayString as ne } from "vue";
import { u as ie, b as ce } from "./layer-select-Ba4IEiWY.js";
import { c as W } from "./vendor-D4icwOYu.js";
import { e as oe, _ as re } from "./utils-B4smQbM-.js";
import "ant-design-vue";
import "@mapgis/webclient-common";
const le = {
  /**
   * @description 底图列表
   */
  basemapList: {
    type: Array,
    default: () => []
  },
  /**
   * @description 索引底图标识，与底图列表中其中一项的id保持一致，始终添加在最上面
   */
  indexBasemapId: {
    type: String,
    default: ""
  },
  /**
   * @description 是否为单底图模式
   */
  singleMode: {
    type: Boolean,
    default: !1
  },
  /**
   * @description 是否显示底图
   */
  show: {
    type: Boolean,
    default: !0
  }
}, me = {}, pe = (r, v) => {
  const { zondy: y, map: d } = ie(), { LayerType: t } = y.enum, {
    ArcGISMapImageLayer: g,
    ArcGISTileLayer: f,
    Cesium3DTilesCacheLayer: k,
    IGSFeatureLayer: b,
    IGSMapImageLayer: B,
    IGSSceneLayer: _,
    IGSTileLayer: C,
    IGSVectorTileLayer: w,
    M3DModelCacheLayer: I,
    TerrainCacheLayer: S,
    GeoJSONLayer: o,
    WFSLayer: G,
    WMSLayer: D,
    WMTSLayer: R,
    WebTileLayer: A
  } = y.layer, i = H({
    // 底图列表
    basemapList: r.basemapList,
    // 索引底图id
    indexBasemapId: r.indexBasemapId,
    // 是否为单底图模式
    singleMode: r.singleMode,
    // 是否显示底图
    show: r.show,
    // 当前添加底图的空间坐标参考系
    wkid: void 0
  });
  let l = {};
  const F = K(() => !i.basemapList.filter((e) => e.visible).length);
  E(
    () => i.show,
    (a) => {
      N(a);
    }
  ), E(
    () => i.wkid,
    (a) => {
      V(a);
    }
  ), Q(() => {
    j();
  });
  function N(a) {
    a ? L() : d.basemap = void 0;
  }
  function V(a) {
    const { basemapList: e } = i;
    e.forEach((n) => {
      const { spatialReference: s } = n;
      n.disabled = a ? s.wkid !== a : !1;
    });
  }
  function O(a) {
    var e;
    i.show && (a.disabled || (i.wkid || (i.wkid = (e = a.spatialReference) == null ? void 0 : e.wkid), i.singleMode ? J(a) : a.select = !a.select, a.select ? T(a) : P(a)));
  }
  function z() {
    return W(i.basemapList);
  }
  function j() {
    const { basemapList: a, show: e } = i;
    if (!e)
      return;
    a.filter((s) => s.select && s.visible).forEach((s) => {
      var m;
      i.wkid || (i.wkid = (m = s.spatialReference) == null ? void 0 : m.wkid), T(s, !1);
    }), L();
  }
  function T(a, e = !0) {
    const { children: n } = a, s = [];
    n && n.forEach((m) => {
      const q = U(m);
      s.push(q);
    }), l[a.id] = s, e && L();
  }
  function J(a) {
    const { basemapList: e } = i;
    e.forEach((n) => {
      n.id === a.id ? n.select = !n.select : n.select = !1;
    }), l = {};
  }
  function L() {
    const { Basemap: a, Collection: e } = y, n = $();
    if (d.basemap = void 0, n.length > 0) {
      const s = new a({
        baseLayers: new e(n)
      });
      d.basemap = s;
    } else
      i.wkid = void 0;
  }
  function P(a) {
    delete l[a.id], L();
  }
  function U(a) {
    const e = W(a), { type: n } = e;
    let s;
    switch (n) {
      case t.ArcGISMapImage:
        s = new g(e);
        break;
      case t.ArcGISTile:
        s = new f(e);
        break;
      case t.IGSFeature:
        s = new b(e);
        break;
      case t.IGSMapImage:
        s = new B(e);
        break;
      case t.IGSScene:
        s = new _(e);
        break;
      case t.IGSTile:
        s = new C(e);
        break;
      case t.IGSVectorTile:
        s = new w(e);
        break;
      case t.M3DModelCache:
        s = new I(e);
        break;
      case t.WFS:
        s = new G(e);
        break;
      case t.WMS:
        s = new D(e);
        break;
      case t.WMTS:
        s = new R(e);
        break;
      case t.webTile:
        s = new A(e);
        break;
      case t.GeoJSON:
        s = new o(e);
        break;
      case t.terrain:
        s = new S(e);
        break;
      case t.cesium3DTilesModelCache:
        s = new k(e);
        break;
    }
    return s;
  }
  function $() {
    const { indexBasemapId: a } = i;
    let e = [];
    Object.keys(l).forEach((s) => {
      a !== s && l[s].forEach((m) => {
        e.push(m);
      });
    });
    const n = l[a];
    return n && (e = [...e, ...n]), e;
  }
  return { ...X(i), showEmptyImage: F, emptyImage: oe, handleBasemapItemClick: O, getBasemapList: z };
}, de = ["onClick"], fe = ["src"], ue = /* @__PURE__ */ Y({
  name: "MapgisBasemapManager",
  __name: "basemap-manager",
  props: le,
  emits: me,
  setup(r, { expose: v, emit: y }) {
    const d = r, t = ce("basemap-manager"), { basemapList: g, show: f, showEmptyImage: k, emptyImage: b, handleBasemapItemClick: B, getBasemapList: _ } = pe(
      d
    );
    return v({
      getBasemapList: _
    }), (C, w) => {
      const I = x("mapgis-ui-switch-panel"), S = x("a-empty");
      return u(), h("div", {
        class: p([c(t).b()])
      }, [
        Z(I, {
          checked: c(f),
          "onUpdate:checked": w[0] || (w[0] = (o) => ee(f) ? f.value = o : null),
          size: "small",
          label: "显示底图"
        }, null, 8, ["checked"]),
        c(k) ? (u(), ae(S, {
          key: 0,
          image: c(b)(),
          description: "",
          class: p([c(t).em("empty", "image")])
        }, null, 8, ["image", "class"])) : (u(), h("div", {
          key: 1,
          class: p(c(t).e("basemap-wrapper"))
        }, [
          (u(!0), h(se, null, te(c(g), (o) => (u(), h("div", {
            class: p([
              c(t).e("basemap-item"),
              o.select && c(t).em("basemap-item", "select"),
              o.disabled && c(t).em("basemap-item", "disabled"),
              o.visible ? "" : c(t).em("basemap-item", "invisible")
            ]),
            key: o.id,
            onClick: (G) => c(B)(o)
          }, [
            M("div", {
              class: p(c(t).em("basemap-item", "image"))
            }, [
              M("img", {
                src: o.image || c(b)()
              }, null, 8, fe)
            ], 2),
            M("div", {
              class: p(c(t).em("basemap-item", "name"))
            }, ne(o.name), 3)
          ], 10, de))), 128))
        ], 2))
      ], 2);
    };
  }
}), ke = /* @__PURE__ */ re(ue, [["__scopeId", "data-v-7d9ea270"]]);
export {
  ke as B,
  le as a,
  me as b,
  pe as u
};
