import { defineComponent, ref, reactive, nextTick, toRefs, watch, openBlock, createElementBlock, normalizeClass, unref, createElementVNode, createVNode, isRef, withCtx, createTextVNode, toDisplayString, createBlock, createCommentVNode } from 'vue';
import '../../../hooks/index.mjs';
import { ElCheckbox } from '../../checkbox/index.mjs';
import { ElInput } from '../../input/index.mjs';
import { Search } from '@element-plus/icons-vue';
import { ElTree } from '../../tree/index.mjs';
import { transferPanelProps, transferPanelEmits } from './transfer-panel.mjs';
import './composables/index.mjs';
import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
import { usePropsAlias } from './composables/use-props-alias.mjs';
import { useLocale } from '../../../hooks/use-locale/index.mjs';
import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
import { useCheck } from './composables/use-check.mjs';

const __default__ = defineComponent({
  name: "ElTransferPanel"
});
const _sfc_main = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: transferPanelProps,
  emits: transferPanelEmits,
  setup(__props, { expose, emit }) {
    const props = __props;
    const propsAlias = usePropsAlias(props);
    const tree = ref();
    const { t } = useLocale();
    const ns = useNamespace("unidirectionalTransfer");
    const panelState = reactive({
      checked: [],
      allChecked: false,
      query: ""
    });
    const { isIndeterminate, checkedSummary, checkableData } = useCheck(props, panelState);
    const handleCheckChange = function() {
      var _a;
      const checkedNodes = (_a = tree.value) == null ? void 0 : _a.getCheckedNodes(true);
      panelState.checked = checkedNodes.map((item) => item[propsAlias.value.key]);
      emit("checked-change", checkedNodes);
      emit("change", panelState.checked);
    };
    const handleAllCheckedChange = (value) => {
      var _a;
      panelState.checked = value ? checkableData.value.map((item) => item[propsAlias.value.key]) : [];
      (_a = tree.value) == null ? void 0 : _a.setCheckedKeys(panelState.checked);
      emit("checked-change", checkableData.value);
      emit("change", panelState.checked);
    };
    const filterNodeMethod = function(value, data, node) {
      if (typeof props.filterMethod === "function") {
        return props.filterMethod(value, data, node);
      } else {
        const label = String(data[propsAlias.value.label] || data[propsAlias.value.key]);
        return label.toLowerCase().includes(panelState.query.toLowerCase());
      }
    };
    const setChecked = function(keys) {
      var _a;
      panelState.checked = keys;
      (_a = tree.value) == null ? void 0 : _a.setCheckedKeys(keys);
    };
    const removeChecked = function(key) {
      var _a;
      (_a = tree.value) == null ? void 0 : _a.setChecked(key, false);
      nextTick(() => {
        handleCheckChange();
      });
    };
    const { checked, allChecked, query } = toRefs(panelState);
    watch(() => query.value, () => {
      var _a;
      (_a = tree.value) == null ? void 0 : _a.filter();
    });
    expose({
      setChecked,
      removeChecked
    });
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", {
        class: normalizeClass(unref(ns).b("panel"))
      }, [
        createElementVNode("p", {
          class: normalizeClass(unref(ns).be("panel", "header"))
        }, [
          createVNode(unref(ElCheckbox), {
            modelValue: unref(allChecked),
            "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(allChecked) ? allChecked.value = $event : null),
            indeterminate: unref(isIndeterminate),
            "validate-event": false,
            onChange: handleAllCheckedChange
          }, {
            default: withCtx(() => [
              createTextVNode(toDisplayString(unref(t)("el.transfer.all")) + " ", 1),
              createElementVNode("span", null, toDisplayString(unref(checkedSummary)), 1)
            ]),
            _: 1
          }, 8, ["modelValue", "indeterminate"])
        ], 2),
        createElementVNode("div", {
          class: normalizeClass([unref(ns).be("panel", "body"), unref(ns).be("panel", "body-left")])
        }, [
          _ctx.filterable ? (openBlock(), createBlock(unref(ElInput), {
            key: 0,
            modelValue: unref(query),
            "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => isRef(query) ? query.value = $event : null),
            class: normalizeClass(unref(ns).be("panel", "filter")),
            size: "default",
            placeholder: _ctx.placeholder,
            icon: unref(Search),
            clearable: "",
            "validate-event": false
          }, null, 8, ["modelValue", "class", "placeholder", "icon"])) : createCommentVNode("v-if", true),
          createVNode(unref(ElTree), {
            ref_key: "tree",
            ref: tree,
            modelValue: unref(checked),
            "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => isRef(checked) ? checked.value = $event : null),
            data: _ctx.data,
            "show-checkbox": "",
            "node-key": unref(propsAlias).key,
            props: unref(propsAlias),
            "filter-node-method": filterNodeMethod,
            onCheck: handleCheckChange
          }, null, 8, ["modelValue", "data", "node-key", "props"])
        ], 2)
      ], 2);
    };
  }
});
var TransferLeftPanel = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "/Users/judai/code/d-element-plus/packages/components/unidirectionalTransfer/src/transfer-left-plane.vue"]]);

export { TransferLeftPanel as default };
//# sourceMappingURL=transfer-left-plane.mjs.map
