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

'use strict';

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

var pick = require('lodash/pick');
var utils_mixins = require('../../utils/mixins.js');
var components_configProvider_configReceiver = require('../config-provider/config-receiver.js');
var components_transfer_components_transferList = require('./components/transfer-list.js');
var components_transfer_components_transferOperations = require('./components/transfer-operations.js');
var components_transfer_props = require('./props.js');
var components_transfer_utils = require('./utils.js');
var utils_event = require('../../utils/event.js');
require('vue');
require('lodash/mergeWith');
require('lodash');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');
require('../../chunks/helper.js');
require('../pagination/index.js');
require('../../utils/with-install.js');
require('../../config.js');
require('../../utils/map-props.js');
require('../pagination/pagination.js');
require('@ldesign/icons-vue');
require('../input-number/index.js');
require('../input-number/input-number.js');
require('@vue/composition-api');
require('../button/index.js');
require('../button/button.js');
require('../loading/index.js');
require('../loading/loading.js');
require('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../chunks/log.js');
require('../../chunks/_commonjsHelpers-2e6815bd.js');
require('../../utils/easing.js');
require('../../utils/render-node.js');
require('../../utils/transfer-dom.js');
require('../loading/props.js');
require('../loading/icon/gradient.js');
require('../../chunks/defineProperty-838e4192.js');
require('../../chunks/set-style.js');
require('../../chunks/helper2.js');
require('../loading/plugin.js');
require('../../utils/ripple.js');
require('../button/props.js');
require('../input/index.js');
require('../input/input.js');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../utils/helper.js');
require('../input/props.js');
require('../input/group.js');
require('../../hooks/use-global-icon.js');
require('../config-provider/useConfig.js');
require('../input-number/props.js');
require('../input-number/hooks/use-input-number.js');
require('../../chunks/isObjectLike-c22c7e3b.js');
require('../../chunks/isArray-cd7357b9.js');
require('../../chunks/isNumber-c4eb560e.js');
require('../../hooks/use-common-classname.js');
require('../../hooks/use-vmodel.js');
require('../../hooks/use-form-disabled.js');
require('../select/index.js');
require('../select/select.js');
require('lodash/isFunction');
require('lodash/debounce');
require('lodash/get');
require('lodash/cloneDeep');
require('lodash/isArray');
require('lodash/isObject');
require('../../hooks/use-default-value.js');
require('../../hooks/lnode.js');
require('lodash/isEmpty');
require('../../hooks/render-lnode.js');
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('../select-input/index.js');
require('../select-input/select-input.js');
require('../select-input/props.js');
require('../select-input/hooks/use-single.js');
require('../../hooks/use-config.js');
require('../select-input/hooks/use-multiple.js');
require('../tag-input/index.js');
require('../tag-input/tag-input.js');
require('../tag-input/props.js');
require('../tag-input/hooks/use-tag-scroll.js');
require('../tag-input/hooks/use-tag-list.js');
require('../tag-input/hooks/use-hover.js');
require('../tag-input/hooks/use-drag-sorter.js');
require('../select-input/hooks/use-overlay-innerstyle.js');
require('../common/fake-arrow.js');
require('../select/option.js');
require('../checkbox/index.js');
require('../checkbox/group.js');
require('lodash/intersection');
require('../checkbox/checkbox.js');
require('../checkbox/props.js');
require('../../hooks/use-lazy-load.js');
require('../../chunks/observe.js');
require('../select/utils.js');
require('../select/props.js');
require('../select/select-panel.js');
require('../../hooks/use-virtual-scroll.js');
require('../select/hooks/use-select-options.js');
require('../select/option-group.js');
require('../input-adornment/index.js');
require('../input-adornment/input-adornment.js');
require('../input-adornment/props.js');
require('../pagination/props.js');
require('./components/transfer-search.js');

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

var pick__default = /*#__PURE__*/_interopDefaultLegacy(pick);

const SOURCE = "source";
const TARGET = "target";
var _Transfer = utils_mixins["default"](components_configProvider_configReceiver["default"]("transfer")).extend({
  name: components_transfer_utils.TRANSFER_NAME,
  components: {
    TransferList: components_transfer_components_transferList["default"],
    TransferOperations: components_transfer_components_transferOperations["default"]
  },
  model: {
    prop: "value",
    event: "change"
  },
  props: components_transfer_props["default"],
  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 components_transfer_utils.getTransferData(this.data, this.keys, this.isTreeMode);
    },
    sourceList() {
      return components_transfer_utils.filterTransferData(this.transferData, this.value, false, this.isTreeMode);
    },
    targetList() {
      return components_transfer_utils.filterTransferData(this.transferData, this.value, true, this.isTreeMode);
    },
    checkedValue() {
      return {
        [SOURCE]: components_transfer_utils.getDataValues(this.sourceList, this.checked, {
          isTreeMode: this.isTreeMode
        }),
        [TARGET]: components_transfer_utils.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 components_transfer_utils.getTransferListOption(footer);
    },
    emptyOption() {
      return components_transfer_utils.getTransferListOption(this.empty);
    },
    searchOption() {
      return components_transfer_utils.getTransferListOption(this.search);
    },
    checkAllOption() {
      return components_transfer_utils.getTransferListOption(this.showCheckAll);
    },
    disabledOption() {
      return components_transfer_utils.getTransferListOption(this.tDisabled);
    },
    titleOption() {
      return components_transfer_utils.getTransferListOption(this.title);
    },
    paginationOption() {
      return components_transfer_utils.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 = components_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);
      const params = {
        type: toDirection,
        movedValue: checkedValue
      };
      utils_event.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);
      utils_event.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
      };
      utils_event.emitEvent(this, "scroll", event);
    },
    handleSearch(e) {
      utils_event.emitEvent(this, "search", e);
    },
    handlePageChange(pageInfo, listType) {
      utils_event.emitEvent(this, "page-change", pageInfo, {
        type: listType
      });
    },
    renderTransferList(listType) {
      const h = this.$createElement;
      const 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": 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)]);
  }
});

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