import { defineComponent, ref, watch, resolveDirective, withDirectives, openBlock, createElementBlock, computed, nextTick, resolveComponent, createElementVNode, normalizeClass, unref, Fragment, renderList, createBlock, createVNode, withCtx, createTextVNode, toDisplayString, createCommentVNode, pushScopeId, popScopeId } from "vue";
import { A as fetchImages, w as getDefaultExportFromCjs, v as getAugmentedNamespace, aw as require$$0, ax as require$$3, ay as require$$3$1, az as require$$0$1, aA as require$$0$2, aB as require$$1$2, aC as require$$4, aD as require$$6, aE as require$$7, u as useChartEditStore, aF as Icon, i as icon, Q as PackagesCategoryEnum, aG as componentInstall, f as fetchChartComponent, b as fetchConfigComponent, aH as DragKeyEnum, a1 as JSONStringify, aI as EditCanvasTypeEnum, aJ as loadingStart, c as createComponent, aK as loadingFinish, aL as loadingError, d as goDialog, _ as _export_sfc } from "./index-67bc0910.js";
import { u as useChartLayoutStore, a as ChartModeEnum } from "./chartLayoutStore-de4e7ebb.js";
import { u as usePackagesStore } from "./index-07c60303.js";
import "./index-42e17fe3.js";
function _mergeNamespaces(n, m) {
  for (var i = 0; i < m.length; i++) {
    const e = m[i];
    if (typeof e !== "string" && !Array.isArray(e)) {
      for (const k in e) {
        if (k !== "default" && !(k in n)) {
          const d = Object.getOwnPropertyDescriptor(e, k);
          if (d) {
            Object.defineProperty(n, k, d.get ? d : {
              enumerable: true,
              get: () => e[k]
            });
          }
        }
      }
    }
  }
  return Object.freeze(Object.defineProperty(n, Symbol.toStringTag, { value: "Module" }));
}
const _hoisted_1$1 = {
  class: "list-img",
  alt: "图表图片"
};
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
  __name: "index",
  props: {
    chartConfig: {
      type: Object,
      required: true
    }
  },
  setup(__props) {
    const props = __props;
    const imageInfo = ref("");
    const fetchImageUrl = async () => {
      imageInfo.value = await fetchImages(props.chartConfig);
    };
    watch(
      () => props.chartConfig.key,
      () => fetchImageUrl(),
      {
        immediate: true
      }
    );
    return (_ctx, _cache) => {
      const _directive_lazy = resolveDirective("lazy");
      return withDirectives((openBlock(), createElementBlock("img", _hoisted_1$1, null, 512)), [
        [_directive_lazy, imageInfo.value]
      ]);
    };
  }
});
var ChatCategoryEnum = /* @__PURE__ */ ((ChatCategoryEnum2) => {
  ChatCategoryEnum2["PRIVATE"] = "Private";
  ChatCategoryEnum2["SHARE"] = "Share";
  return ChatCategoryEnum2;
})(ChatCategoryEnum || {});
function last$1(array) {
  var length = array == null ? 0 : array.length;
  return length ? array[length - 1] : void 0;
}
var last_1 = last$1;
const last$2 = /* @__PURE__ */ getDefaultExportFromCjs(last_1);
const last$3 = /* @__PURE__ */ _mergeNamespaces({
  __proto__: null,
  default: last$2
}, [last_1]);
const require$$1$1 = /* @__PURE__ */ getAugmentedNamespace(last$3);
function baseSlice$1(array, start, end) {
  var index2 = -1, length = array.length;
  if (start < 0) {
    start = -start > length ? 0 : length + start;
  }
  end = end > length ? length : end;
  if (end < 0) {
    end += length;
  }
  length = start > end ? 0 : end - start >>> 0;
  start >>>= 0;
  var result = Array(length);
  while (++index2 < length) {
    result[index2] = array[index2 + start];
  }
  return result;
}
var _baseSlice = baseSlice$1;
const _baseSlice$1 = /* @__PURE__ */ getDefaultExportFromCjs(_baseSlice);
const _baseSlice$2 = /* @__PURE__ */ _mergeNamespaces({
  __proto__: null,
  default: _baseSlice$1
}, [_baseSlice]);
const require$$1 = /* @__PURE__ */ getAugmentedNamespace(_baseSlice$2);
var baseGet = require$$0, baseSlice = require$$1;
function parent$1(object, path) {
  return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
}
var _parent = parent$1;
const _parent$1 = /* @__PURE__ */ getDefaultExportFromCjs(_parent);
const _parent$2 = /* @__PURE__ */ _mergeNamespaces({
  __proto__: null,
  default: _parent$1
}, [_parent]);
const require$$2$1 = /* @__PURE__ */ getAugmentedNamespace(_parent$2);
var castPath$1 = require$$3, last = require$$1$1, parent = require$$2$1, toKey = require$$3$1;
function baseUnset$1(object, path) {
  path = castPath$1(path, object);
  object = parent(object, path);
  return object == null || delete object[toKey(last(path))];
}
var _baseUnset = baseUnset$1;
const _baseUnset$1 = /* @__PURE__ */ getDefaultExportFromCjs(_baseUnset);
const _baseUnset$2 = /* @__PURE__ */ _mergeNamespaces({
  __proto__: null,
  default: _baseUnset$1
}, [_baseUnset]);
const require$$2 = /* @__PURE__ */ getAugmentedNamespace(_baseUnset$2);
var isPlainObject = require$$0$1;
function customOmitClone$1(value) {
  return isPlainObject(value) ? void 0 : value;
}
var _customOmitClone = customOmitClone$1;
const _customOmitClone$1 = /* @__PURE__ */ getDefaultExportFromCjs(_customOmitClone);
const _customOmitClone$2 = /* @__PURE__ */ _mergeNamespaces({
  __proto__: null,
  default: _customOmitClone$1
}, [_customOmitClone]);
const require$$5 = /* @__PURE__ */ getAugmentedNamespace(_customOmitClone$2);
var arrayMap = require$$0$2, baseClone = require$$1$2, baseUnset = require$$2, castPath = require$$3, copyObject = require$$4, customOmitClone = require$$5, flatRest = require$$6, getAllKeysIn = require$$7;
var CLONE_DEEP_FLAG = 1, CLONE_FLAT_FLAG = 2, CLONE_SYMBOLS_FLAG = 4;
var omit = flatRest(function(object, paths) {
  var result = {};
  if (object == null) {
    return result;
  }
  var isDeep = false;
  paths = arrayMap(paths, function(path) {
    path = castPath(path, object);
    isDeep || (isDeep = path.length > 1);
    return path;
  });
  copyObject(object, getAllKeysIn(object), result);
  if (isDeep) {
    result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
  }
  var length = paths.length;
  while (length--) {
    baseUnset(result, paths[length]);
  }
  return result;
});
var omit_1 = omit;
const omit$1 = /* @__PURE__ */ getDefaultExportFromCjs(omit_1);
const _withScopeId = (n) => (pushScopeId("data-v-1d77a379"), n = n(), popScopeId(), n);
const _hoisted_1 = { class: "go-content-charts-item-animation-patch" };
const _hoisted_2 = ["onDragstart", "onDragend", "onDblclick", "onClick"];
const _hoisted_3 = {
  class: "list-center go-flex-center go-transition",
  draggable: "true"
};
const _hoisted_4 = {
  class: "list-bottom",
  style: { "text-align": "center" }
};
const _hoisted_5 = {
  key: 0,
  class: "list-model"
};
const _hoisted_6 = ["onClick"];
const _hoisted_7 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ createElementVNode("span", null, "删除", -1));
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  props: {
    menuOptions: {
      type: Array,
      default: () => []
    }
  },
  emits: ["deletePhoto"],
  setup(__props, { emit }) {
    const chartEditStore = useChartEditStore();
    const { TrashIcon } = icon.ionicons5;
    const chartLayoutStore = useChartLayoutStore();
    const contentChartsItemBoxRef = ref();
    const isShowTools = (item) => {
      return !item.disabled && item.package === PackagesCategoryEnum.PHOTOS && item.category === ChatCategoryEnum.PRIVATE;
    };
    const chartMode = computed(() => {
      return chartLayoutStore.getChartType;
    });
    const dragStartHandle = (e, item) => {
      if (item.disabled)
        return;
      componentInstall(item.chartKey, fetchChartComponent(item));
      componentInstall(item.conKey, fetchConfigComponent(item));
      e.dataTransfer.setData(DragKeyEnum.DRAG_KEY, JSONStringify(omit$1(item, ["image"])));
      chartEditStore.setEditCanvas(EditCanvasTypeEnum.IS_CREATE, true);
    };
    const dragendHandle = () => {
      chartEditStore.setEditCanvas(EditCanvasTypeEnum.IS_CREATE, false);
    };
    const dblclickHandle = async (item) => {
      if (item.disabled)
        return;
      try {
        loadingStart();
        componentInstall(item.chartKey, fetchChartComponent(item));
        componentInstall(item.conKey, fetchConfigComponent(item));
        let newComponent = await createComponent(item);
        if (item.redirectComponent) {
          item.dataset && (newComponent.option.dataset = item.dataset);
          newComponent.chartConfig.title = item.title;
          newComponent.chartConfig.chartFrame = item.chartFrame;
        }
        chartEditStore.addComponentList(newComponent, false, true);
        chartEditStore.setTargetSelectChart(newComponent.id);
        loadingFinish();
      } catch (error) {
        loadingError();
        window["$message"].warning(`图表正在研发中, 敬请期待...`);
      }
    };
    const clickHandle = (item) => {
      var _a;
      (_a = item == null ? void 0 : item.configEvents) == null ? void 0 : _a.addHandle(item);
    };
    const deleteHandle = (item, index2) => {
      goDialog({
        message: "是否删除此图片？",
        transformOrigin: "center",
        onPositiveCallback: () => {
          const packagesStore = usePackagesStore();
          emit("deletePhoto", item, index2);
          packagesStore.deletePhotos(item, index2);
        }
      });
    };
    watch(
      () => chartMode.value,
      (newValue) => {
        if (newValue === ChartModeEnum.DOUBLE) {
          nextTick(() => {
            contentChartsItemBoxRef.value.classList.add("miniAnimation");
          });
        }
      }
    );
    return (_ctx, _cache) => {
      const _component_n_ellipsis = resolveComponent("n-ellipsis");
      const _component_n_text = resolveComponent("n-text");
      const _component_n_icon = resolveComponent("n-icon");
      const _component_n_button = resolveComponent("n-button");
      return openBlock(), createElementBlock("div", _hoisted_1, [
        createElementVNode("div", {
          ref_key: "contentChartsItemBoxRef",
          ref: contentChartsItemBoxRef,
          class: normalizeClass(["go-content-charts-item-box", [chartMode.value === unref(ChartModeEnum).DOUBLE ? "double" : "single"]])
        }, [
          (openBlock(true), createElementBlock(Fragment, null, renderList(__props.menuOptions, (item, index2) => {
            return openBlock(), createElementBlock("div", {
              class: "item-box",
              key: item.title,
              draggable: "",
              onDragstart: ($event) => !item.disabled && dragStartHandle($event, item),
              onDragend: ($event) => !item.disabled && dragendHandle,
              onDblclick: ($event) => dblclickHandle(item),
              onClick: ($event) => clickHandle(item)
            }, [
              createElementVNode("div", _hoisted_3, [
                item.icon ? (openBlock(), createBlock(unref(Icon), {
                  key: 0,
                  class: "list-img",
                  icon: item.icon,
                  color: "#999",
                  width: "48"
                }, null, 8, ["icon"])) : (openBlock(), createBlock(unref(_sfc_main$1), {
                  key: 1,
                  class: "list-img",
                  chartConfig: item
                }, null, 8, ["chartConfig"]))
              ]),
              createElementVNode("div", _hoisted_4, [
                createVNode(_component_n_text, {
                  class: "list-bottom-text",
                  depth: "3"
                }, {
                  default: withCtx(() => [
                    createVNode(_component_n_ellipsis, { style: { "max-width": "90%" } }, {
                      default: withCtx(() => [
                        createTextVNode(toDisplayString(item.title), 1)
                      ]),
                      _: 2
                    }, 1024)
                  ]),
                  _: 2
                }, 1024)
              ]),
              item.disabled ? (openBlock(), createElementBlock("div", _hoisted_5)) : createCommentVNode("", true),
              isShowTools(item) ? (openBlock(), createElementBlock("div", {
                key: 1,
                class: "list-tools go-transition",
                onClick: ($event) => deleteHandle(item, index2)
              }, [
                createVNode(_component_n_button, {
                  text: "",
                  type: "default",
                  color: "#ffffff"
                }, {
                  icon: withCtx(() => [
                    createVNode(_component_n_icon, null, {
                      default: withCtx(() => [
                        createVNode(unref(TrashIcon))
                      ]),
                      _: 1
                    })
                  ]),
                  default: withCtx(() => [
                    _hoisted_7
                  ]),
                  _: 1
                })
              ], 8, _hoisted_6)) : createCommentVNode("", true)
            ], 40, _hoisted_2);
          }), 128))
        ], 2)
      ]);
    };
  }
});
const index_vue_vue_type_style_index_0_scoped_1d77a379_lang = "";
const index = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-1d77a379"]]);
export {
  index as default
};
