/**
 * tdesign v0.39.1-alpha.1
 * (c) 2022 tdesign
 * @license MIT
 */

'use strict';

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

var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var pick = require('lodash/pick');
var config = require('../config.js');
var transfer_components_transferList = require('./components/transfer-list.js');
var transfer_components_transferOperations = require('./components/transfer-operations.js');
var utils_mixins = require('../utils/mixins.js');
var configProvider_configReceiver = require('../config-provider/config-receiver.js');
var transfer_props = require('./props.js');
var transfer_utils = require('./utils.js');
var utils_event = require('../utils/event.js');
require('../_chunks/dep-33ee4bce.js');
require('@babel/runtime/helpers/typeof');
require('../pagination/index.js');
require('../pagination/pagination.js');
require('tdesign-icons-vue');
require('../input-number/index.js');
require('../input-number/input-number.js');
require('@babel/runtime/helpers/asyncToGenerator');
require('@babel/runtime/regenerator');
require('vue');
require('../button/index.js');
require('../button/button.js');
require('../utils/classnames.js');
require('../loading/index.js');
require('../loading/loading.js');
require('../loading/icon/gradient.js');
require('../_common/js/loading/circle-adapter.js');
require('../_common/js/utils/set-style.js');
require('../_common/js/utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('../utils/dom.js');
require('raf');
require('lodash/isString');
require('../utils/easing.js');
require('../utils/render-tnode.js');
require('lodash/isObject');
require('../utils/transfer-dom.js');
require('../loading/props.js');
require('../utils/withInstall.js');
require('lodash/capitalize');
require('../loading/plugin.js');
require('../button/props.js');
require('../utils/ripple.js');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../input/index.js');
require('../input/addon.js');
require('../input/input.js');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/helper.js');
require('../input/props.js');
require('../input/input-group.js');
require('../utils/map-props.js');
require('../input-number/props.js');
require('../select/index.js');
require('../select/select.js');
require('lodash/isFunction');
require('lodash/debounce');
require('lodash/get');
require('lodash/set');
require('../popup/index.js');
require('../popup/popup.js');
require('@popperjs/core');
require('../popup/props.js');
require('../popup/container.js');
require('../tag/index.js');
require('../tag/tag.js');
require('../tag/props.js');
require('../tag/check-tag.js');
require('../tag/check-tag-props.js');
require('../common-components/fake-arrow.js');
require('../select/option.js');
require('../select/option-props.js');
require('../checkbox/index.js');
require('../checkbox/group.js');
require('lodash/intersection');
require('../checkbox/checkbox.js');
require('../checkbox/props.js');
require('../checkbox/checkbox-group-props.js');
require('../select/props.js');
require('../select/optionGroup.js');
require('../select/option-group-props.js');
require('../pagination/props.js');
require('./components/transfer-search.js');
require('lodash/cloneDeep');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var pick__default = /*#__PURE__*/_interopDefaultLegacy(pick);

var SOURCE = "source";
var TARGET = "target";
var _Transfer = utils_mixins["default"](configProvider_configReceiver["default"]("transfer")).extend({
  name: transfer_utils.TRANSFER_NAME,
  components: {
    TransferList: transfer_components_transferList["default"],
    TransferOperations: transfer_components_transferOperations["default"]
  },
  model: {
    prop: "value",
    event: "change"
  },
  props: transfer_props["default"],
  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 transfer_utils.getTransferData(this.data, this.keys, this.isTreeMode);
    },
    sourceList: function sourceList() {
      return transfer_utils.filterTransferData(this.transferData, this.value, false, this.isTreeMode);
    },
    targetList: function targetList() {
      return transfer_utils.filterTransferData(this.transferData, this.value, true, this.isTreeMode);
    },
    checkedValue: function checkedValue() {
      var _ref;

      return _ref = {}, _defineProperty__default["default"](_ref, SOURCE, transfer_utils.getDataValues(this.sourceList, this.checked, {
        isTreeMode: this.isTreeMode
      })), _defineProperty__default["default"](_ref, TARGET, transfer_utils.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 transfer_utils.getTransferListOption(footer);
    },
    emptyOption: function emptyOption() {
      return transfer_utils.getTransferListOption(this.empty);
    },
    searchOption: function searchOption() {
      return transfer_utils.getTransferListOption(this.search);
    },
    checkAllOption: function checkAllOption() {
      return transfer_utils.getTransferListOption(this.showCheckAll);
    },
    disabledOption: function disabledOption() {
      return transfer_utils.getTransferListOption(this.tDisabled);
    },
    titleOption: function titleOption() {
      return transfer_utils.getTransferListOption(this.title);
    },
    paginationOption: function paginationOption() {
      return transfer_utils.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 = transfer_utils.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
      };
      utils_event.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__default["default"](sourceChecked), _toConsumableArray__default["default"](targetChecked));
      var event = {
        checked: checked,
        sourceChecked: sourceChecked,
        targetChecked: targetChecked,
        type: listType
      };
      this.$emit("update:checked", checked);
      utils_event.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
      };
      utils_event.emitEvent(this, "scroll", event);
    },
    handleSearch: function handleSearch(e) {
      utils_event.emitEvent(this, "search", e);
    },
    handlePageChange: function handlePageChange(pageInfo, listType) {
      utils_event.emitEvent(this, "page-change", pageInfo, {
        type: listType
      });
    },
    renderTransferList: function renderTransferList(listType) {
      var _this = this;

      var h = this.$createElement;
      var scopedSlots = pick__default["default"](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": ["".concat(config.prefix, "-transfer"), this.showSearch ? "".concat(config.prefix, "-transfer__search") : "", this.hasFooter ? "".concat(config.prefix, "-transfer__footer") : "", this.showPagination ? "".concat(config.prefix, "-transfer__pagination") : "", this.isTreeMode ? "".concat(config.prefix, "-transfer--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)]);
  }
});

exports["default"] = _Transfer;
//# sourceMappingURL=transfer.js.map
