import "../../../../../node_modules/element-plus/es/index.mjs";
/* empty css                                                             */
/* empty css                                                                  */
import "../../../../../node_modules/element-plus/theme-chalk/el-tooltip.css.mjs";
/* empty css                                                                */
/* empty css                                                                 */
/* empty css                                                                  */
/* empty css                                                                   */
/* empty css                                                                      */
import { useCssVars, inject, ref, computed, resolveComponent, createElementBlock, openBlock, createElementVNode, createVNode, normalizeClass, unref, withModifiers, withCtx, withDirectives, vShow, createBlock, renderSlot, createTextVNode, toDisplayString, createCommentVNode, Fragment, renderList, nextTick } from "vue";
import Add from "./Add.vue2.mjs";
/* empty css          */
import _export_sfc from "../../../../../_virtual/_plugin-vue_export-helper.mjs";
import { ElPopconfirm } from "../../../../../node_modules/element-plus/es/components/popconfirm/index.mjs";
import { ElButton } from "../../../../../node_modules/element-plus/es/components/button/index.mjs";
import { ElInput } from "../../../../../node_modules/element-plus/es/components/input/index.mjs";
import ClickOutside from "../../../../../node_modules/element-plus/es/directives/click-outside/index.mjs";
import { ElText } from "../../../../../node_modules/element-plus/es/components/text/index.mjs";
import { ElIcon } from "../../../../../node_modules/element-plus/es/components/icon/index.mjs";
import { ElTooltip } from "../../../../../node_modules/element-plus/es/components/tooltip/index.mjs";
const _hoisted_1 = { class: "node-box" };
const _hoisted_2 = { class: "node-header" };
const _hoisted_3 = { class: "head" };
const _hoisted_4 = { class: "node-content" };
const _sfc_main = {
  __name: "Node",
  props: {
    icon: String,
    node: Object,
    color: String,
    readOnly: {
      type: Boolean,
      default: false
    },
    close: {
      type: Boolean,
      default: true
    }
  },
  emits: ["addNode", "delNode", "activeNode"],
  setup(__props, { emit: __emit }) {
    useCssVars((_ctx) => ({
      "77a51cb7": __props.color
    }));
    const _inject = inject("flowDesign", {
      readOnly: ref(false),
      nodesError: ref({})
    });
    const $emits = __emit;
    const $props = __props;
    const errorInfo = computed(() => _inject.nodesError.value[$props.node.id]);
    const _readOnly = computed(() => {
      var _a;
      return ((_a = _inject.readOnly) == null ? void 0 : _a.value) || $props.readOnly;
    });
    const showInput = ref(false);
    const inputRef = ref();
    const onShowInput = () => {
      if (_readOnly.value) return;
      showInput.value = true;
      nextTick(() => {
        var _a;
        (_a = inputRef.value) == null ? void 0 : _a.focus();
      });
    };
    const onClickOutside = () => {
      if (showInput.value) {
        showInput.value = false;
      }
    };
    const activeNode = () => {
      if (_readOnly.value) return;
      $emits("activeNode", $props.node);
    };
    const addNode = (type) => {
      $emits("addNode", type, $props.node);
    };
    const delNode = () => {
      $emits("delNode", $props.node);
    };
    return (_ctx, _cache) => {
      var _a;
      const _component_el_button = ElButton;
      const _component_el_popconfirm = ElPopconfirm;
      const _component_el_input = ElInput;
      const _component_EditPen = resolveComponent("EditPen");
      const _component_el_icon = ElIcon;
      const _component_el_text = ElText;
      const _component_svg_icon = resolveComponent("svg-icon");
      const _component_WarnTriangleFilled = resolveComponent("WarnTriangleFilled");
      const _component_el_tooltip = ElTooltip;
      return openBlock(), createElementBlock("div", _hoisted_1, [
        createElementVNode("div", {
          onClick: activeNode,
          class: normalizeClass(["node", { "error-node": ((_a = unref(errorInfo)) == null ? void 0 : _a.length) && !unref(_readOnly) }])
        }, [
          createElementVNode("div", _hoisted_2, [
            createElementVNode("span", {
              onClick: _cache[0] || (_cache[0] = withModifiers(() => {
              }, ["stop"]))
            }, [
              createVNode(_component_el_popconfirm, {
                title: "您确定要删除该节点吗？",
                width: "200",
                "hide-after": 0,
                placement: "right-start",
                onConfirm: delNode
              }, {
                reference: withCtx(() => [
                  withDirectives(createVNode(_component_el_button, {
                    class: "node-close",
                    plain: "",
                    circle: "",
                    icon: "CircleClose",
                    size: "small",
                    type: "danger"
                  }, null, 512), [
                    [vShow, __props.close && !unref(_readOnly)]
                  ])
                ]),
                _: 1
              })
            ]),
            createElementVNode("div", _hoisted_3, [
              unref(showInput) ? (openBlock(), createElementBlock("div", {
                key: 0,
                onClick: _cache[2] || (_cache[2] = withModifiers(() => {
                }, ["stop"]))
              }, [
                withDirectives(createVNode(_component_el_input, {
                  ref_key: "inputRef",
                  ref: inputRef,
                  onBlur: onClickOutside,
                  maxlength: "30",
                  modelValue: __props.node.name,
                  "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => __props.node.name = $event)
                }, null, 8, ["modelValue"]), [
                  [unref(ClickOutside), onClickOutside]
                ])
              ])) : (openBlock(), createBlock(_component_el_text, {
                key: 1,
                tag: "b",
                truncated: "",
                onClick: withModifiers(onShowInput, ["stop"])
              }, {
                default: withCtx(() => [
                  createTextVNode(toDisplayString(__props.node.name) + " ", 1),
                  createVNode(_component_el_icon, null, {
                    default: withCtx(() => [
                      createVNode(_component_EditPen)
                    ]),
                    _: 1
                  })
                ]),
                _: 1
              })),
              renderSlot(_ctx.$slots, "icon", {}, () => [
                __props.icon ? (openBlock(), createBlock(_component_svg_icon, {
                  key: 0,
                  size: 30,
                  color: "node-icon",
                  name: __props.icon
                }, null, 8, ["name"])) : createCommentVNode("", true)
              ], true)
            ]),
            createVNode(_component_el_tooltip, { placement: "top-start" }, {
              content: withCtx(() => [
                (openBlock(true), createElementBlock(Fragment, null, renderList(unref(errorInfo), (err) => {
                  return openBlock(), createElementBlock("div", {
                    key: err.id
                  }, toDisplayString(err.message), 1);
                }), 128))
              ]),
              default: withCtx(() => {
                var _a2;
                return [
                  withDirectives(createVNode(_component_el_icon, {
                    class: "warn-icon",
                    size: 20
                  }, {
                    default: withCtx(() => [
                      createVNode(_component_WarnTriangleFilled, {
                        onClick: _cache[3] || (_cache[3] = withModifiers(() => {
                        }, ["stop"]))
                      })
                    ]),
                    _: 1
                  }, 512), [
                    [vShow, ((_a2 = unref(errorInfo)) == null ? void 0 : _a2.length) && !unref(_readOnly)]
                  ])
                ];
              }),
              _: 1
            })
          ]),
          createElementVNode("div", _hoisted_4, [
            renderSlot(_ctx.$slots, "default", {}, void 0, true)
          ])
        ], 2),
        createVNode(Add, { onAddNode: addNode })
      ]);
    };
  }
};
const Node = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-45d7e9c1"]]);
export {
  Node as default
};
