'use strict';

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

var vue = require('vue');
var lodash = require('lodash');
require('../../../hooks/index.js');
var Icons = require('@element-plus/icons-vue');
var transfer = require('./transfer.js');
var transferLeftPlane = require('./transfer-left-plane.js');
var pluginVue_exportHelper = require('../../../../_virtual/plugin-vue_export-helper.js');
var index = require('../../../hooks/use-locale/index.js');
var index$1 = require('../../../hooks/use-namespace/index.js');

const __default__ = vue.defineComponent({
  name: "ElUnidirectionalTransfer"
});
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...__default__,
  props: transfer.UnidirectionalTransferProps,
  emits: transfer.UnidirectionalTransferEmits,
  setup(__props, { expose, emit }) {
    const props = __props;
    const leftPanel = vue.ref();
    const { t } = index.useLocale();
    const ns = index$1.useNamespace("unidirectionalTransfer");
    const propsValueMap = vue.computed(() => {
      return Object.assign({}, transfer.DEFAULT_PROPS, props.props);
    });
    let checkedData = {};
    const getCheckableData = (data) => {
      data.forEach((transferDataItem) => {
        if (!transferDataItem[propsValueMap.value.children] || !transferDataItem[propsValueMap.value.children].length) {
          if (!transferDataItem[propsValueMap.value.disabled]) {
            checkedData[transferDataItem[propsValueMap.value.key]] = transferDataItem;
          }
        } else {
          getCheckableData(transferDataItem[propsValueMap.value.children]);
        }
      });
      return checkedData;
    };
    const checkableData = vue.computed(() => {
      checkedData = {};
      return getCheckableData(props.data);
    });
    const removeChecked = (key) => {
      var _a, _b;
      if (!((_a = leftPanel.value) == null ? void 0 : _a.getNodeData(key))) {
        update(props.modelValue.filter((item) => item !== key));
        return;
      }
      (_b = leftPanel.value) == null ? void 0 : _b.removeChecked(key);
    };
    const panelFilterPlaceholder = vue.computed(() => props.filterPlaceholder || t("el.transfer.filterPlaceholder"));
    let emitValue = [...props.modelValue];
    let firstCheck = false;
    const initModelValue = [...props.modelValue];
    function update(key) {
      if (!firstCheck) {
        const nonexistent = Array.from(/* @__PURE__ */ new Set([...initModelValue, ...props.modelValue])).filter((item) => !key.includes(item));
        emit("change-nonexistent", nonexistent);
      }
      firstCheck = true;
      emitValue = key;
      emit("update:modelValue", key);
      emit("change", key);
    }
    vue.watch(() => props.data, () => {
      firstCheck = false;
    });
    vue.onMounted(() => {
      var _a;
      props.modelValue && leftPanel.value && ((_a = leftPanel.value) == null ? void 0 : _a.setChecked(props.modelValue));
    });
    vue.watch(() => props.modelValue, (keys, oldValue) => {
      var _a;
      if (!lodash.isEqual(keys, oldValue) && !lodash.isEqual(keys, emitValue)) {
        (_a = leftPanel.value) == null ? void 0 : _a.setChecked(keys);
      }
    });
    function setChecked(key) {
      var _a;
      (_a = leftPanel.value) == null ? void 0 : _a.setChecked(key);
    }
    expose({
      setChecked
    });
    return (_ctx, _cache) => {
      const _component_el_icon = vue.resolveComponent("el-icon");
      return vue.openBlock(), vue.createElementBlock("div", {
        class: vue.normalizeClass(vue.unref(ns).b())
      }, [
        vue.createVNode(transferLeftPlane["default"], {
          ref_key: "leftPanel",
          ref: leftPanel,
          data: props.data,
          placeholder: vue.unref(panelFilterPlaceholder),
          filterable: _ctx.filterable,
          "filter-method": _ctx.filterMethod,
          props: props.props,
          "render-content": props.renderContent,
          "model-value": props.modelValue,
          onChange: update
        }, null, 8, ["data", "placeholder", "filterable", "filter-method", "props", "render-content", "model-value"]),
        vue.createElementVNode("div", {
          class: vue.normalizeClass(vue.unref(ns).b("panel"))
        }, [
          vue.createElementVNode("p", {
            class: vue.normalizeClass(vue.unref(ns).be("panel", "header"))
          }, [
            vue.renderSlot(_ctx.$slots, "searchContent", {
              length: _ctx.modelValue.length
            }, () => [
              vue.createElementVNode("span", null, vue.toDisplayString(vue.unref(t)("el.transfer.hasChecked")) + "\uFF08" + vue.toDisplayString(_ctx.modelValue.length) + "\uFF09", 1)
            ])
          ], 2),
          vue.createElementVNode("div", {
            class: vue.normalizeClass(vue.unref(ns).be("panel", "body"))
          }, [
            vue.createElementVNode("div", {
              class: vue.normalizeClass(vue.unref(ns).be("panel", "container"))
            }, [
              (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(_ctx.modelValue, (item, index) => {
                return vue.openBlock(), vue.createElementBlock("div", {
                  key: index,
                  class: vue.normalizeClass(vue.unref(ns).be("panel", "list"))
                }, [
                  vue.renderSlot(_ctx.$slots, "reftPanelContent", {
                    key: item,
                    data: vue.unref(checkableData)[item]
                  }, () => {
                    var _a;
                    return [
                      vue.createElementVNode("div", null, vue.toDisplayString(((_a = vue.unref(checkableData)[item]) == null ? void 0 : _a[vue.unref(propsValueMap).label]) || ""), 1)
                    ];
                  }),
                  vue.createVNode(_component_el_icon, {
                    size: "12",
                    onClick: ($event) => removeChecked(item)
                  }, {
                    default: vue.withCtx(() => [
                      vue.createVNode(vue.unref(Icons.Close))
                    ]),
                    _: 2
                  }, 1032, ["onClick"])
                ], 2);
              }), 128))
            ], 2)
          ], 2)
        ], 2)
      ], 2);
    };
  }
});
var Transfer = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "/home/kimihiro/workfiles/dingdandao/element-plus/packages/components/unidirectionalTransfer/src/transfer.vue"]]);

exports["default"] = Transfer;
//# sourceMappingURL=transfer2.js.map
