'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var iconsVue = require('@element-plus/icons-vue');
var index = require('../../checkbox/index.js');
var index$1 = require('../../radio/index.js');
var index$2 = require('../../icon/index.js');
require('../../../hooks/index.js');
var dshNodeContent = require('./dsh-node-content.js');
var types = require('./types.js');
var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
var index$3 = require('../../../hooks/use-namespace/index.js');

const _sfc_main = vue.defineComponent({
  name: "ElDshCascaderNode",
  components: {
    ElCheckbox: index.ElCheckbox,
    ElRadio: index$1.ElRadio,
    ElDshNodeContent: dshNodeContent["default"],
    ElIcon: index$2.ElIcon,
    Check: iconsVue.Check,
    Loading: iconsVue.Loading,
    ArrowRight: iconsVue.ArrowRight
  },
  props: {
    node: {
      type: Object,
      required: true
    },
    menuId: String,
    onlyThis: {
      type: Boolean,
      default: true
    }
  },
  emits: ["expand"],
  setup(props, { emit }) {
    var _a;
    const panel = vue.inject(types.DSH_CASCADER_PANEL_INJECTION_KEY);
    const ns = index$3.useNamespace("dsh-cascader-node");
    const isHoverMenu = vue.computed(() => panel.isHoverMenu);
    const multiple = vue.computed(() => panel.config.multiple);
    const checkStrictly = vue.computed(() => panel.config.checkStrictly);
    const checkedNodeId = vue.computed(() => {
      var _a2;
      return (_a2 = panel.checkedNodes[0]) == null ? void 0 : _a2.uid;
    });
    const DshIsDisabled = vue.computed(() => props.node.DshIsDisabled);
    const DshIsLeaf = vue.computed(() => props.node.DshIsLeaf);
    const expandable = vue.computed(() => checkStrictly.value && !DshIsLeaf.value || !DshIsDisabled.value);
    const inExpandingPath = vue.computed(() => isInPath(panel.expandingNode));
    const inCheckedPath = vue.computed(() => checkStrictly.value && panel.checkedNodes.some(isInPath));
    const propsValue = (_a = props.node.config.value) != null ? _a : "value";
    const isInPath = (node) => {
      var _a2;
      const { level, uid } = props.node;
      return ((_a2 = node == null ? void 0 : node.pathNodes[level - 1]) == null ? void 0 : _a2.uid) === uid;
    };
    const doExpand = () => {
      if (inExpandingPath.value)
        return;
      panel.expandNode(props.node);
    };
    const doCheck = (checked) => {
      const { node } = props;
      if (checked === node.checked)
        return;
      panel.handleCheckChange(node, checked);
    };
    const onlyCheck = () => {
      const { node } = props;
      panel.checkedNodes.forEach((item) => item.doCheck(false));
      panel.handleCheckChange(node, false);
      panel.onlyThisConfirm(node.value);
    };
    const doLoad = () => {
      panel.lazyLoad(props.node, () => {
        if (!DshIsLeaf.value)
          doExpand();
      });
    };
    const handleHoverExpand = (e) => {
      if (!isHoverMenu.value)
        return;
      handleExpand();
      !DshIsLeaf.value && emit("expand", e);
    };
    const handleExpand = () => {
      const { node } = props;
      if (!expandable.value || node.loading)
        return;
      node.loaded ? doExpand() : doLoad();
    };
    const handleClick = (node) => {
      if (node.data[propsValue] === "cascader-all" || isHoverMenu.value) {
        handleSelectCheck(!node.checked);
        return;
      }
      if (DshIsLeaf.value && !DshIsDisabled.value && !checkStrictly.value && !multiple.value) {
        handleCheck(true);
      } else {
        handleExpand();
      }
    };
    const handleSelectCheck = (checked) => {
      if (props.node.data[propsValue] === "cascader-all") {
        panel.checkedAll(checked);
      }
      if (checkStrictly.value) {
        doCheck(checked);
        if (props.node.loaded) {
          doExpand();
        }
      } else {
        handleCheck(checked);
      }
    };
    const handleCheck = (checked) => {
      if (!props.node.loaded) {
        doLoad();
      } else {
        doCheck(checked);
        !checkStrictly.value && doExpand();
      }
    };
    return {
      panel,
      isHoverMenu,
      multiple,
      checkStrictly,
      checkedNodeId,
      DshIsDisabled,
      DshIsLeaf,
      expandable,
      inExpandingPath,
      inCheckedPath,
      ns,
      handleHoverExpand,
      handleExpand,
      handleClick,
      handleCheck,
      handleSelectCheck,
      onlyCheck
    };
  }
});
const _hoisted_1 = ["id", "aria-haspopup", "aria-owns", "aria-expanded", "tabindex"];
const _hoisted_2 = /* @__PURE__ */ vue.createElementVNode("span", null, null, -1);
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  const _component_el_checkbox = vue.resolveComponent("el-checkbox");
  const _component_el_radio = vue.resolveComponent("el-radio");
  const _component_check = vue.resolveComponent("check");
  const _component_el_icon = vue.resolveComponent("el-icon");
  const _component_el_dsh_node_content = vue.resolveComponent("el-dsh-node-content");
  const _component_loading = vue.resolveComponent("loading");
  const _component_arrow_right = vue.resolveComponent("arrow-right");
  return vue.openBlock(), vue.createElementBlock("li", {
    id: `${_ctx.menuId}-${_ctx.node.uid}`,
    role: "menuitem",
    "aria-haspopup": !_ctx.DshIsLeaf,
    "aria-owns": _ctx.DshIsLeaf ? null : _ctx.menuId,
    "aria-expanded": _ctx.inExpandingPath,
    tabindex: _ctx.expandable ? -1 : void 0,
    class: vue.normalizeClass([
      _ctx.ns.b(),
      _ctx.ns.is("selectable", _ctx.checkStrictly),
      _ctx.ns.is("active", _ctx.node.checked),
      _ctx.ns.is("disabled", !_ctx.expandable),
      !_ctx.node.DshIsLeaf && _ctx.inExpandingPath && "in-active-path",
      _ctx.inCheckedPath && "in-checked-path"
    ]),
    onMouseenter: _cache[2] || (_cache[2] = (...args) => _ctx.handleHoverExpand && _ctx.handleHoverExpand(...args)),
    onFocus: _cache[3] || (_cache[3] = (...args) => _ctx.handleHoverExpand && _ctx.handleHoverExpand(...args)),
    onClick: _cache[4] || (_cache[4] = ($event) => _ctx.handleClick(_ctx.node))
  }, [
    vue.createCommentVNode(" prefix "),
    _ctx.multiple ? (vue.openBlock(), vue.createBlock(_component_el_checkbox, {
      key: 0,
      "model-value": _ctx.node.checked,
      indeterminate: _ctx.node.indeterminate,
      disabled: _ctx.DshIsDisabled,
      onClick: _cache[0] || (_cache[0] = vue.withModifiers(() => {
      }, ["stop"])),
      "onUpdate:modelValue": _ctx.handleSelectCheck
    }, null, 8, ["model-value", "indeterminate", "disabled", "onUpdate:modelValue"])) : _ctx.checkStrictly ? (vue.openBlock(), vue.createBlock(_component_el_radio, {
      key: 1,
      "model-value": _ctx.checkedNodeId,
      label: _ctx.node.uid,
      disabled: _ctx.DshIsDisabled,
      "onUpdate:modelValue": _ctx.handleSelectCheck,
      onClick: _cache[1] || (_cache[1] = vue.withModifiers(() => {
      }, ["stop"]))
    }, {
      default: vue.withCtx(() => [
        vue.createCommentVNode("\n        Add an empty element to avoid render label,\n        do not use empty fragment here for https://github.com/vuejs/vue-next/pull/2485\n      "),
        _hoisted_2
      ]),
      _: 1
    }, 8, ["model-value", "label", "disabled", "onUpdate:modelValue"])) : _ctx.DshIsLeaf && _ctx.node.checked ? (vue.openBlock(), vue.createBlock(_component_el_icon, {
      key: 2,
      class: vue.normalizeClass(_ctx.ns.e("prefix"))
    }, {
      default: vue.withCtx(() => [
        vue.createVNode(_component_check)
      ]),
      _: 1
    }, 8, ["class"])) : vue.createCommentVNode("v-if", true),
    vue.createCommentVNode(" content "),
    vue.createVNode(_component_el_dsh_node_content, {
      "only-check": _ctx.onlyCheck,
      node: _ctx.node
    }, null, 8, ["only-check", "node"]),
    vue.createCommentVNode(" postfix "),
    !_ctx.DshIsLeaf ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 3 }, [
      _ctx.node.loading ? (vue.openBlock(), vue.createBlock(_component_el_icon, {
        key: 0,
        class: vue.normalizeClass([_ctx.ns.is("loading"), _ctx.ns.e("postfix")])
      }, {
        default: vue.withCtx(() => [
          vue.createVNode(_component_loading)
        ]),
        _: 1
      }, 8, ["class"])) : (vue.openBlock(), vue.createBlock(_component_el_icon, {
        key: 1,
        class: vue.normalizeClass(["arrow-right", _ctx.ns.e("postfix")])
      }, {
        default: vue.withCtx(() => [
          vue.createVNode(_component_arrow_right)
        ]),
        _: 1
      }, 8, ["class"]))
    ], 64)) : vue.createCommentVNode("v-if", true)
  ], 42, _hoisted_1);
}
var ElDshCascaderNode = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["render", _sfc_render], ["__file", "D:\\project\\work\\code-monkey-ui\\packages\\components\\dsh-cascader-panel\\src\\node.vue"]]);

exports["default"] = ElDshCascaderNode;
//# sourceMappingURL=node2.js.map
