/**
 * tdesign v0.46.4
 * (c) 2022 tdesign
 * @license MIT
 */

import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import pick from 'lodash/pick';
import TransferList from './components/transfer-list.js';
import TransferOperations from './components/transfer-operations.js';
import mixins from '../utils/mixins.js';
import getConfigReceiverMixins from '../config-provider/config-receiver.js';
import props from './props.js';
import { TRANSFER_NAME, getTransferData, filterTransferData, getDataValues, getTransferListOption } from './utils.js';
import { emitEvent } from '../utils/event.js';
import '../_chunks/dep-a4bd011a.js';
import '@babel/runtime/helpers/typeof';
import '../pagination/index.js';
import '../pagination/pagination.js';
import 'tdesign-icons-vue';
import '../input-number/index.js';
import '@vue/composition-api';
import '../input-number/input-number.js';
import '../button/index.js';
import '../button/button.js';
import '../loading/index.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/set-style.js';
import '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import '../utils/dom.js';
import 'vue';
import 'raf';
import 'lodash/isString';
import '../utils/easing.js';
import '../utils/render-tnode.js';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../utils/transfer-dom.js';
import '../loading/props.js';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import './style/css.js';
import '../loading/type.js';
import '../loading/plugin.js';
import '../config.js';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../config-provider/type.js';
import '../button/props.js';
import '../utils/ripple.js';
import '../button/type.js';
import '../input/index.js';
import '../input/input.js';
import '../utils/helper.js';
import '../input/props.js';
import '../input/input-group.js';
import '../utils/map-props.js';
import '../input/type.js';
import '../input-number/props.js';
import '../input-number/useInputNumber.js';
import '../hooks/useCommonClassName.js';
import '../config-provider/useConfig.js';
import '../hooks/useVModel.js';
import '../_common/js/input-number/number.js';
import 'lodash/isNumber';
import '../_common/js/input-number/large-number.js';
import '../_common/js/log/log.js';
import '../_common/js/log/index.js';
import '../hooks/useFormDisabled.js';
import '../hooks/useGlobalIcon.js';
import '../hooks/useConfig.js';
import '../input-number/type.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 '../hooks/useDefaultValue.js';
import '../hooks/tnode.js';
import 'lodash/isEmpty';
import '../hooks/render-tnode.js';
import 'lodash/isObject';
import '../select/props.js';
import '../popup/index.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../popup/props.js';
import '../popup/container.js';
import '../popup/type.js';
import '../tag/index.js';
import '../tag/tag.js';
import '../tag/props.js';
import '../tag/check-tag.js';
import '../tag/check-tag-props.js';
import '../tag/type.js';
import '../select-input/index.js';
import '../select-input/select-input.js';
import '../select-input/props.js';
import '../select-input/useSingle.js';
import '../select-input/useMultiple.js';
import '../tag-input/index.js';
import '../tag-input/tag-input.js';
import '../tag-input/props.js';
import '../tag-input/hooks/useTagScroll.js';
import '../tag-input/useTagList.js';
import '../tag-input/hooks/useHover.js';
import '../tag-input/hooks/useDragSorter.js';
import '../tag-input/type.js';
import '../select-input/useOverlayInnerStyle.js';
import '../select-input/type.js';
import '../common-components/fake-arrow.js';
import '../select/option.js';
import '../select/option-props.js';
import '../checkbox/index.js';
import '../checkbox/group.js';
import 'lodash/intersection';
import '../checkbox/checkbox.js';
import '../checkbox/props.js';
import '../checkbox/checkbox-group-props.js';
import '../checkbox/type.js';
import '../hooks/useLazyLoad.js';
import '../_common/js/utils/observe.js';
import '../select/util.js';
import '../select/select-panel.js';
import '../hooks/useVirtualScroll.js';
import '../select/hooks/useSelectOptions.js';
import '../select/optionGroup.js';
import '../select/option-group-props.js';
import '../select/type.js';
import '../input-adornment/index.js';
import '../input-adornment/input-adornment.js';
import '../input-adornment/props.js';
import '../input-adornment/type.js';
import '../pagination/props.js';
import '../pagination/type.js';
import './components/transfer-search.js';

var SOURCE = "source";
var TARGET = "target";
var _Transfer = mixins(getConfigReceiverMixins("transfer")).extend({
  name: TRANSFER_NAME,
  components: {
    TransferList: TransferList,
    TransferOperations: TransferOperations
  },
  model: {
    prop: "value",
    event: "change"
  },
  props: props,
  data: function data() {
    return {
      SOURCE: SOURCE,
      TARGET: TARGET,
      formDisabled: void 0
    };
  },
  computed: {
    tDisabled: function tDisabled() {
      return this.formDisabled || this.disabled;
    },
    isTreeMode: function isTreeMode() {
      var treeSlot = this.$scopedSlots.tree;
      return typeof treeSlot === "function";
    },
    leftButtonDisabled: function leftButtonDisabled() {
      return this.direction === "right";
    },
    rightButtonDisabled: function rightButtonDisabled() {
      return this.direction === "left";
    },
    transferData: function transferData() {
      return getTransferData(this.data, this.keys, this.isTreeMode);
    },
    sourceList: function sourceList() {
      return filterTransferData(this.transferData, this.value, false, this.isTreeMode);
    },
    targetList: function targetList() {
      return filterTransferData(this.transferData, this.value, true, this.isTreeMode);
    },
    checkedValue: function checkedValue() {
      var _ref;

      return _ref = {}, _defineProperty(_ref, SOURCE, getDataValues(this.sourceList, this.checked, {
        isTreeMode: this.isTreeMode
      })), _defineProperty(_ref, TARGET, getDataValues(this.targetList, this.checked, {
        isTreeMode: this.isTreeMode
      })), _ref;
    },
    hasFooter: function hasFooter() {
      return !!this.$scopedSlots.footer || !!this.footer;
    },
    showPagination: function showPagination() {
      return !!this.pagination && !this.$scopedSlots.content;
    },
    showSearch: function showSearch() {
      return !!this.search;
    },
    footerOption: function footerOption() {
      var footer = this.footer || "";
      return getTransferListOption(footer);
    },
    emptyOption: function emptyOption() {
      return getTransferListOption(this.empty);
    },
    searchOption: function searchOption() {
      return getTransferListOption(this.search);
    },
    checkAllOption: function checkAllOption() {
      return getTransferListOption(this.showCheckAll);
    },
    disabledOption: function disabledOption() {
      return getTransferListOption(this.tDisabled);
    },
    titleOption: function titleOption() {
      return getTransferListOption(this.title);
    },
    paginationOption: function paginationOption() {
      return getTransferListOption(this.pagination);
    }
  },
  methods: {
    transferTo: function transferTo(toDirection) {
      var oldTargetValue = JSON.parse(JSON.stringify(this.value));
      var newTargetValue;
      var checkedValue = toDirection === TARGET ? this.checkedValue[SOURCE] : this.checkedValue[TARGET];

      if (toDirection === SOURCE) {
        newTargetValue = oldTargetValue.filter(function (v) {
          return !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);
      var params = {
        type: toDirection,
        movedValue: checkedValue
      };
      emitEvent(this, "change", newTargetValue, params);
    },
    transferToRight: function transferToRight() {
      this.transferTo(TARGET);
    },
    transferToLeft: function transferToLeft() {
      this.transferTo(SOURCE);
    },
    handleCheckedChange: function handleCheckedChange(val, listType) {
      var sourceChecked = listType === SOURCE ? val : this.checkedValue[SOURCE];
      var targetChecked = listType === TARGET ? val : this.checkedValue[TARGET];
      var checked = [].concat(_toConsumableArray(sourceChecked), _toConsumableArray(targetChecked));
      var event = {
        checked: checked,
        sourceChecked: sourceChecked,
        targetChecked: targetChecked,
        type: listType
      };
      this.$emit("update:checked", checked);
      emitEvent(this, "checked-change", event);
    },
    filterMethod: function filterMethod(transferList, targetValueList, needMatch) {
      return transferList.filter(function (item) {
        var isMatch = targetValueList.indexOf(item.value) > -1;
        return needMatch ? isMatch : !isMatch;
      });
    },
    handleScroll: function handleScroll(e, listType) {
      var target = e.target;
      var bottomDistance = target.scrollHeight - target.scrollTop - target.clientHeight;
      var event = {
        e: e,
        bottomDistance: bottomDistance,
        type: listType
      };
      emitEvent(this, "scroll", event);
    },
    handleSearch: function handleSearch(e) {
      emitEvent(this, "search", e);
    },
    handlePageChange: function handlePageChange(pageInfo, listType) {
      emitEvent(this, "page-change", pageInfo, {
        type: listType
      });
    },
    renderTransferList: function renderTransferList(listType) {
      var _this = this;

      var h = this.$createElement;
      var 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": function checkedChange(val) {
            return _this.handleCheckedChange(val, listType);
          },
          "scroll": function scroll($event) {
            return _this.handleScroll($event, listType);
          },
          "search": this.handleSearch,
          "pageChange": function pageChange(pageInfo) {
            return _this.handlePageChange(pageInfo, listType);
          }
        },
        "scopedSlots": scopedSlots
      });
    }
  },
  render: function render() {
    var h = arguments[0];
    return h("div", {
      "class": [this.componentName, this.showSearch ? "".concat(this.componentName, "__search") : "", this.hasFooter ? "".concat(this.componentName, "__footer") : "", this.showPagination ? "".concat(this.componentName, "__pagination") : "", this.isTreeMode ? "".concat(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
