/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

import pick from 'lodash/pick';
import mixins from '../../utils/mixins.js';
import getConfigReceiverMixins from '../config-provider/config-receiver.js';
import TransferList from './components/transfer-list.js';
import TransferOperations from './components/transfer-operations.js';
import props from './props.js';
import { TRANSFER_NAME, getTransferData, filterTransferData, getDataValues, getTransferListOption } from './utils.js';
import { emitEvent } from '../../utils/event.js';
import 'vue';
import 'lodash/mergeWith';
import 'lodash';
import '../config-provider/context.js';
import '../../_chunks/dep-def4c2ce.js';
import '../../_chunks/dep-29915b8e.js';
import '../pagination/index.js';
import '../../utils/with-install.js';
import '../../config.js';
import '../../utils/map-props.js';
import '../pagination/pagination.js';
import '@ldesign/icons-vue';
import '../input-number/index.js';
import '../input-number/input-number.js';
import '@vue/composition-api';
import '../button/index.js';
import '../button/button.js';
import '../loading/index.js';
import '../loading/loading.js';
import '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../_chunks/dep-70c789e5.js';
import '../../_chunks/dep-5210251b.js';
import '../../utils/easing.js';
import '../../utils/render-node.js';
import '../../utils/transfer-dom.js';
import '../loading/props.js';
import '../loading/icon/gradient.js';
import '../../_chunks/dep-eb467ddf.js';
import '../../_chunks/dep-cf772670.js';
import '../../_chunks/dep-47d77fc8.js';
import '../loading/plugin.js';
import '../../utils/ripple.js';
import '../button/props.js';
import '../input/index.js';
import '../input/input.js';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../../utils/helper.js';
import '../input/props.js';
import '../input/group.js';
import '../../hooks/use-global-icon.js';
import '../config-provider/useConfig.js';
import '../input-number/props.js';
import '../input-number/hooks/use-input-number.js';
import '../../_chunks/dep-24cf4e98.js';
import '../../_chunks/dep-48540ab4.js';
import '../../_chunks/dep-a9f96abb.js';
import '../../hooks/use-common-classname.js';
import '../../hooks/use-vmodel.js';
import '../../hooks/use-form-disabled.js';
import '../select/index.js';
import '../select/select.js';
import 'lodash/isFunction';
import 'lodash/debounce';
import 'lodash/get';
import 'lodash/cloneDeep';
import 'lodash/isArray';
import 'lodash/isObject';
import '../../hooks/use-default-value.js';
import '../../hooks/lnode.js';
import 'lodash/isEmpty';
import '../../hooks/render-lnode.js';
import '../popup/index.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../popup/props.js';
import '../popup/container.js';
import '../tag/index.js';
import '../tag/tag.js';
import '../tag/props.js';
import '../tag/check-tag.js';
import '../select-input/index.js';
import '../select-input/select-input.js';
import '../select-input/props.js';
import '../select-input/hooks/use-single.js';
import '../../hooks/use-config.js';
import '../select-input/hooks/use-multiple.js';
import '../tag-input/index.js';
import '../tag-input/tag-input.js';
import '../tag-input/props.js';
import '../tag-input/hooks/use-tag-scroll.js';
import '../tag-input/hooks/use-tag-list.js';
import '../tag-input/hooks/use-hover.js';
import '../tag-input/hooks/use-drag-sorter.js';
import '../select-input/hooks/use-overlay-innerstyle.js';
import '../common/fake-arrow.js';
import '../select/option.js';
import '../checkbox/index.js';
import '../checkbox/group.js';
import 'lodash/intersection';
import '../checkbox/checkbox.js';
import '../checkbox/props.js';
import '../../hooks/use-lazy-load.js';
import '../../_chunks/dep-356f585c.js';
import '../select/utils.js';
import '../select/props.js';
import '../select/select-panel.js';
import '../../hooks/use-virtual-scroll.js';
import '../select/hooks/use-select-options.js';
import '../select/option-group.js';
import '../input-adornment/index.js';
import '../input-adornment/input-adornment.js';
import '../input-adornment/props.js';
import '../pagination/props.js';
import './components/transfer-search.js';

const SOURCE = "source";
const TARGET = "target";
var _Transfer = mixins(getConfigReceiverMixins("transfer")).extend({
  name: TRANSFER_NAME,
  components: {
    TransferList,
    TransferOperations
  },
  model: {
    prop: "value",
    event: "change"
  },
  props,
  data() {
    return {
      SOURCE,
      TARGET,
      formDisabled: void 0
    };
  },
  computed: {
    tDisabled() {
      return this.formDisabled || this.disabled;
    },
    isTreeMode() {
      const treeSlot = this.$scopedSlots.tree;
      return typeof treeSlot === "function";
    },
    leftButtonDisabled() {
      return this.direction === "right";
    },
    rightButtonDisabled() {
      return this.direction === "left";
    },
    transferData() {
      return getTransferData(this.data, this.keys, this.isTreeMode);
    },
    sourceList() {
      return filterTransferData(this.transferData, this.value, false, this.isTreeMode);
    },
    targetList() {
      return filterTransferData(this.transferData, this.value, true, this.isTreeMode);
    },
    checkedValue() {
      return {
        [SOURCE]: getDataValues(this.sourceList, this.checked, {
          isTreeMode: this.isTreeMode
        }),
        [TARGET]: getDataValues(this.targetList, this.checked, {
          isTreeMode: this.isTreeMode
        })
      };
    },
    hasFooter() {
      return !!this.$scopedSlots.footer || !!this.footer;
    },
    showPagination() {
      return !!this.pagination && !this.$scopedSlots.content;
    },
    showSearch() {
      return !!this.search;
    },
    footerOption() {
      const footer = this.footer || "";
      return getTransferListOption(footer);
    },
    emptyOption() {
      return getTransferListOption(this.empty);
    },
    searchOption() {
      return getTransferListOption(this.search);
    },
    checkAllOption() {
      return getTransferListOption(this.showCheckAll);
    },
    disabledOption() {
      return getTransferListOption(this.tDisabled);
    },
    titleOption() {
      return getTransferListOption(this.title);
    },
    paginationOption() {
      return getTransferListOption(this.pagination);
    }
  },
  methods: {
    transferTo(toDirection) {
      const oldTargetValue = JSON.parse(JSON.stringify(this.value));
      let newTargetValue;
      const checkedValue = toDirection === TARGET ? this.checkedValue[SOURCE] : this.checkedValue[TARGET];
      if (toDirection === SOURCE) {
        newTargetValue = oldTargetValue.filter(v => !checkedValue.includes(v));
      } else if (this.targetSort === "original") {
        newTargetValue = getDataValues(this.transferData, oldTargetValue.concat(checkedValue), {
          isTreeMode: this.isTreeMode
        });
      } else if (this.targetSort === "unshift") {
        newTargetValue = checkedValue.concat(oldTargetValue);
      } else {
        newTargetValue = oldTargetValue.concat(checkedValue);
      }
      this.handleCheckedChange([], toDirection === SOURCE ? TARGET : SOURCE);
      const params = {
        type: toDirection,
        movedValue: checkedValue
      };
      emitEvent(this, "change", newTargetValue, params);
    },
    transferToRight() {
      this.transferTo(TARGET);
    },
    transferToLeft() {
      this.transferTo(SOURCE);
    },
    handleCheckedChange(val, listType) {
      const sourceChecked = listType === SOURCE ? val : this.checkedValue[SOURCE];
      const targetChecked = listType === TARGET ? val : this.checkedValue[TARGET];
      const checked = [...sourceChecked, ...targetChecked];
      const event = {
        checked,
        sourceChecked,
        targetChecked,
        type: listType
      };
      this.$emit("update:checked", checked);
      emitEvent(this, "checked-change", event);
    },
    filterMethod(transferList, targetValueList, needMatch) {
      return transferList.filter(item => {
        const isMatch = targetValueList.includes(item.value);
        return needMatch ? isMatch : !isMatch;
      });
    },
    handleScroll(e, listType) {
      const target = e.target;
      const bottomDistance = target.scrollHeight - target.scrollTop - target.clientHeight;
      const event = {
        e,
        bottomDistance,
        type: listType
      };
      emitEvent(this, "scroll", event);
    },
    handleSearch(e) {
      emitEvent(this, "search", e);
    },
    handlePageChange(pageInfo, listType) {
      emitEvent(this, "page-change", pageInfo, {
        type: listType
      });
    },
    renderTransferList(listType) {
      const h = this.$createElement;
      const scopedSlots = pick(this.$scopedSlots, ["title", "empty", "footer", "operation", "transferItem", "default"]);
      return h("transfer-list", {
        "attrs": {
          "checkboxProps": this.checkboxProps,
          "transferItem": this.transferItem,
          "list-type": listType,
          "title": this.titleOption[listType],
          "data-source": listType === SOURCE ? this.sourceList : this.targetList,
          "checked-value": this.checkedValue[listType],
          "disabled": this.disabledOption[listType],
          "search": this.searchOption[listType],
          "pagination": this.paginationOption[listType],
          "check-all": this.checkAllOption[listType],
          "footer": this.footerOption[listType],
          "empty": this.emptyOption[listType],
          "t": this.t,
          "global": this.global,
          "isTreeMode": this.isTreeMode
        },
        "on": {
          "checkedChange": val => this.handleCheckedChange(val, listType),
          "scroll": $event => this.handleScroll($event, listType),
          "search": this.handleSearch,
          "pageChange": pageInfo => this.handlePageChange(pageInfo, listType)
        },
        "scopedSlots": scopedSlots
      });
    }
  },
  render() {
    const h = arguments[0];
    return h("div", {
      "class": [this.componentName, this.showSearch ? `${this.componentName}__search` : "", this.hasFooter ? `${this.componentName}__footer` : "", this.showPagination ? `${this.componentName}__pagination` : "", this.isTreeMode ? `${this.componentName}--with-tree` : ""]
    }, [this.renderTransferList(SOURCE), h("transfer-operations", {
      "attrs": {
        "left-disabled": this.disabledOption[TARGET] || this.leftButtonDisabled || this.checkedValue[TARGET].length === 0,
        "right-disabled": this.disabledOption[SOURCE] || this.rightButtonDisabled || this.checkedValue[SOURCE].length === 0,
        "operation": this.operation
      },
      "on": {
        "moveToRight": this.transferToRight,
        "moveToLeft": this.transferToLeft
      },
      "scopedSlots": {
        operation: this.$scopedSlots.operation
      }
    }), this.renderTransferList(TARGET)]);
  }
});

export { _Transfer as default };
//# sourceMappingURL=transfer.js.map
