'use strict';

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

var vue = require('vue');
require('../../../hooks/index.js');
var index$2 = require('../../checkbox/index.js');
var index$3 = require('../../input/index.js');
var iconsVue = require('@element-plus/icons-vue');
var index$4 = require('../../tree/index.js');
var transferPanel = require('./transfer-panel.js');
require('./composables/index.js');
var pluginVue_exportHelper = require('../../../../_virtual/plugin-vue_export-helper.js');
var usePropsAlias = require('./composables/use-props-alias.js');
var index = require('../../../hooks/use-locale/index.js');
var index$1 = require('../../../hooks/use-namespace/index.js');
var useCheck = require('./composables/use-check.js');

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

exports["default"] = TransferLeftPanel;
//# sourceMappingURL=transfer-left-plane.js.map
