/**
 * ldesign v0.3.13
 * (c) 2023 ldesign
 * @license MIT
 */

'use strict';

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

var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var pick = require('lodash/pick');
var isFunction = require('lodash/isFunction');
var hooks_useVModel = require('../hooks/useVModel.js');
var hooks_useDefaultValue = require('../hooks/useDefaultValue.js');
var form_hooks = require('../form/hooks.js');
var hooks_useConfig = require('../hooks/useConfig.js');
var transfer_props = require('./props.js');
var transfer_utils = require('./utils.js');
var transfer_components_transferOperations = require('./components/transfer-operations.js');
var transfer_components_transferList = require('./components/transfer-list.js');
require('lodash/kebabCase');
require('../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('lodash/isString');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('lodash/isArray');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-f4db2590.js');
require('dayjs');
require('lodash/isUndefined');
require('../utils/event.js');
require('../utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('lodash/camelCase');
require('lodash/isNull');
require('lodash/isNumber');
require('@ldesign/icons-vue-next');
require('../button/index.js');
require('../utils/withInstall.js');
require('../button/button.js');
require('../loading/index.js');
require('../loading/directive.js');
require('../loading/plugin.js');
require('../utils/dom.js');
require('../utils/easing.js');
require('../loading/loading.js');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isObject');
require('../hooks/useTeleport.js');
require('../loading/props.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('../hooks/useRipple.js');
require('../utils/set-style.js');
require('../hooks/useKeepAnimation.js');
require('../hooks/tnode.js');
require('../button/props.js');
require('../hooks/useGlobalIcon.js');
require('../pagination/index.js');
require('../pagination/pagination.js');
require('lodash/isNaN');
require('../input-number/index.js');
require('../input-number/input-number.js');
require('../input/index.js');
require('../input/input.js');
require('../input/props.js');
require('../input/useInput.js');
require('../form/const.js');
require('../input/useLengthLimit.js');
require('../_common/js/log/log.js');
require('../input/useInputEventHandler.js');
require('../input/useInputWidth.js');
require('../input/input-group.js');
require('../input/input-group-props.js');
require('../input-number/props.js');
require('../input-number/useInputNumber.js');
require('../hooks/useCommonClassName.js');
require('../_common/js/input-number/number.js');
require('lodash/isNil');
require('../_common/js/input-number/large-number.js');
require('../select/index.js');
require('../select/select.js');
require('lodash/debounce');
require('lodash/get');
require('lodash/intersection');
require('../common-components/fake-arrow.js');
require('../select-input/index.js');
require('../select-input/select-input.js');
require('../popup/index.js');
require('../popup/popup.js');
require('@popperjs/core');
require('../popup/props.js');
require('../popup/container.js');
require('../hooks/useResizeObserver.js');
require('../select-input/props.js');
require('../select-input/useSingle.js');
require('../select-input/useMultiple.js');
require('../tag-input/index.js');
require('../tag-input/tag-input.js');
require('../tag-input/props.js');
require('../tag-input/hooks/useTagScroll.js');
require('../tag-input/useTagList.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('../tag-input/hooks/useHover.js');
require('../tag-input/hooks/useDragSorter.js');
require('../select-input/useOverlayInnerStyle.js');
require('../select/props.js');
require('../select/select-panel.js');
require('lodash/omit');
require('../select/option.js');
require('../checkbox/index.js');
require('../checkbox/checkbox.js');
require('../checkbox/props.js');
require('../checkbox/constants.js');
require('../checkbox/group.js');
require('../hooks/slot.js');
require('../checkbox/checkbox-group-props.js');
require('../select/option-props.js');
require('../select/helper.js');
require('../select/optionGroup.js');
require('../select/option-group-props.js');
require('../select/hooks/usePanelVirtualScroll.js');
require('../hooks/useVirtualScroll.js');
require('../select/hooks/useSelectOptions.js');
require('../input-adornment/index.js');
require('../input-adornment/input-adornment.js');
require('../input-adornment/props.js');
require('../pagination/props.js');
require('../pagination/usePaginationClasses.js');
require('../pagination/useMoreAction.js');
require('../pagination/pagination-mini.js');
require('../pagination/pagination-mini-props.js');
require('./components/transfer-search.js');

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

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

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _isSlot(s) {
  return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !vue.isVNode(s);
}
var SOURCE = "source";
var TARGET = "target";
var _Transfer = vue.defineComponent({
  name: transfer_utils.TRANSFER_NAME,
  props: _objectSpread({}, transfer_props["default"]),
  setup: function setup(props2, _ref) {
    var slots = _ref.slots;
    var disabled = form_hooks.useFormDisabled();
    var classPrefix = hooks_useConfig.usePrefixClass();
    var _toRefs = vue.toRefs(props2),
      value = _toRefs.value,
      modelValue = _toRefs.modelValue,
      checked = _toRefs.checked;
    var _useVModel = hooks_useVModel["default"](value, modelValue, props2.defaultValue, props2.onChange),
      _useVModel2 = _slicedToArray__default["default"](_useVModel, 2),
      innerValue = _useVModel2[0],
      setInnerValue = _useVModel2[1];
    var _useDefaultValue = hooks_useDefaultValue["default"](checked, props2.defaultChecked, props2.onCheckedChange, "checked"),
      _useDefaultValue2 = _slicedToArray__default["default"](_useDefaultValue, 1),
      innerChecked = _useDefaultValue2[0];
    var valueList = vue.computed(function () {
      return innerValue.value;
    });
    var isTreeMode = vue.computed(function () {
      var treeSlot = slots.tree;
      return isFunction__default["default"](treeSlot);
    });
    var leftButtonDisabled = vue.computed(function () {
      return props2.direction === "right";
    });
    var rightButtonDisabled = vue.computed(function () {
      return props2.direction === "left";
    });
    var transferData = vue.computed(function () {
      return transfer_utils.getTransferData(props2.data, props2.keys, isTreeMode.value);
    });
    var sourceList = vue.computed(function () {
      return transfer_utils.filterTransferData(transferData.value, valueList.value, false, isTreeMode.value);
    });
    var targetList = vue.computed(function () {
      return transfer_utils.filterTransferData(transferData.value, valueList.value, true, isTreeMode.value);
    });
    var checkedValue = vue.computed(function () {
      var _ref2;
      return _ref2 = {}, _defineProperty__default["default"](_ref2, SOURCE, transfer_utils.getDataValues(sourceList.value, innerChecked.value, {
        isTreeMode: isTreeMode.value
      })), _defineProperty__default["default"](_ref2, TARGET, transfer_utils.getDataValues(targetList.value, innerChecked.value, {
        isTreeMode: isTreeMode.value
      })), _ref2;
    });
    var hasFooter = vue.computed(function () {
      return !!slots.footer || !!props2.footer;
    });
    var showPagination = vue.computed(function () {
      return !!props2.pagination && !slots.content;
    });
    var showSearch = vue.computed(function () {
      return !!props2.search;
    });
    var footerOption = vue.computed(function () {
      var footer = props2.footer || "";
      return transfer_utils.getTransferListOption(footer);
    });
    var emptyOption = vue.computed(function () {
      return transfer_utils.getTransferListOption(props2.empty);
    });
    var searchOption = vue.computed(function () {
      return transfer_utils.getTransferListOption(props2.search);
    });
    var checkAllOption = vue.computed(function () {
      return transfer_utils.getTransferListOption(props2.showCheckAll);
    });
    var disabledOption = vue.computed(function () {
      return transfer_utils.getTransferListOption(disabled.value);
    });
    var titleOption = vue.computed(function () {
      return transfer_utils.getTransferListOption(props2.title);
    });
    var paginationOption = vue.computed(function () {
      return transfer_utils.getTransferListOption(props2.pagination);
    });
    var handleCheckedChange = function handleCheckedChange(val, listType) {
      var _props2$onCheckedChan;
      var sourceChecked = listType === SOURCE ? val : checkedValue.value[SOURCE];
      var targetChecked = listType === TARGET ? val : checkedValue.value[TARGET];
      var checked2 = [].concat(_toConsumableArray__default["default"](sourceChecked), _toConsumableArray__default["default"](targetChecked));
      var event = {
        checked: checked2,
        sourceChecked: sourceChecked,
        targetChecked: targetChecked,
        type: listType
      };
      innerChecked.value = checked2;
      (_props2$onCheckedChan = props2.onCheckedChange) === null || _props2$onCheckedChan === void 0 ? void 0 : _props2$onCheckedChan.call(props2, event);
    };
    var transferTo = function transferTo(toDirection) {
      var oldTargetValue = JSON.parse(JSON.stringify(valueList.value));
      var newTargetValue;
      var selfCheckedValue = toDirection === TARGET ? checkedValue.value[SOURCE] : checkedValue.value[TARGET];
      if (toDirection === SOURCE) {
        newTargetValue = oldTargetValue.filter(function (v) {
          return !selfCheckedValue.includes(v);
        });
      } else if (props2.targetSort === "original") {
        newTargetValue = transfer_utils.getDataValues(transferData.value, oldTargetValue.concat(selfCheckedValue), {
          isTreeMode: isTreeMode.value
        });
      } else if (props2.targetSort === "unshift") {
        newTargetValue = selfCheckedValue.concat(oldTargetValue);
      } else {
        newTargetValue = oldTargetValue.concat(selfCheckedValue);
      }
      handleCheckedChange([], toDirection === SOURCE ? TARGET : SOURCE);
      var params = {
        type: toDirection,
        movedValue: selfCheckedValue
      };
      setInnerValue(newTargetValue, params);
    };
    var transferToRight = function transferToRight() {
      transferTo(TARGET);
    };
    var transferToLeft = function transferToLeft() {
      transferTo(SOURCE);
    };
    var handleScroll = function handleScroll(e, listType) {
      var _props2$onScroll;
      var target = e.target;
      var bottomDistance = target.scrollHeight - target.scrollTop - target.clientHeight;
      var event = {
        e: e,
        bottomDistance: bottomDistance,
        type: listType
      };
      (_props2$onScroll = props2.onScroll) === null || _props2$onScroll === void 0 ? void 0 : _props2$onScroll.call(props2, event);
    };
    var handleSearch = function handleSearch(e) {
      var _props2$onSearch;
      (_props2$onSearch = props2.onSearch) === null || _props2$onSearch === void 0 ? void 0 : _props2$onSearch.call(props2, e);
    };
    var handlePageChange = function handlePageChange(pageInfo, listType) {
      var _props2$onPageChange;
      (_props2$onPageChange = props2.onPageChange) === null || _props2$onPageChange === void 0 ? void 0 : _props2$onPageChange.call(props2, pageInfo, {
        type: listType
      });
    };
    var renderTransferList = function renderTransferList(listType) {
      var scopedSlots = pick__default["default"](slots, ["title", "empty", "footer", "operation", "transferItem", "default", "tree"]);
      return vue.createVNode(transfer_components_transferList["default"], {
        "checkboxProps": props2.checkboxProps,
        "transferItem": props2.transferItem,
        "list-type": listType,
        "title": titleOption.value[listType],
        "data-source": listType === SOURCE ? sourceList.value : targetList.value,
        "checked-value": checkedValue.value[listType],
        "disabled": disabledOption.value[listType],
        "search": searchOption.value[listType],
        "pagination": paginationOption.value[listType],
        "check-all": checkAllOption.value[listType],
        "footer": footerOption.value[listType],
        "empty": emptyOption.value[listType],
        "onCheckedChange": function onCheckedChange($event) {
          return handleCheckedChange($event, listType);
        },
        "onScroll": function onScroll($event) {
          return handleScroll($event, listType);
        },
        "onSearch": handleSearch,
        "onPageChange": function onPageChange($event) {
          return handlePageChange($event, listType);
        },
        "isTreeMode": isTreeMode.value
      }, _isSlot(scopedSlots) ? scopedSlots : {
        "default": function _default() {
          return [scopedSlots];
        }
      });
    };
    return function () {
      return vue.createVNode("div", {
        "class": ["".concat(classPrefix.value, "-transfer"), showSearch.value ? "".concat(classPrefix.value, "-transfer__search") : "", hasFooter.value ? "".concat(classPrefix.value, "-transfer__footer") : "", showPagination.value ? "".concat(classPrefix.value, "-transfer__pagination") : "", isTreeMode.value ? "".concat(classPrefix.value, "-transfer--with-tree") : ""]
      }, [renderTransferList(SOURCE), vue.createVNode(transfer_components_transferOperations["default"], {
        "leftDisabled": disabledOption.value[TARGET] || leftButtonDisabled.value || checkedValue.value[TARGET].length === 0,
        "rightDisabled": disabledOption.value[SOURCE] || rightButtonDisabled.value || checkedValue.value[SOURCE].length === 0,
        "operation": props2.operation,
        "onMoveToRight": transferToRight,
        "onMoveToLeft": transferToLeft
      }, {
        operation: slots.operation
      }), renderTransferList(TARGET)]);
    };
  }
});

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