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

'use strict';

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

var helper = require('../../_chunks/dep-d7a1e02c.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _typeof = require('@babel/runtime/helpers/typeof');
var utils_mixins = require('../../utils/mixins.js');
var pagination_index = require('../../pagination/index.js');
var checkbox_index = require('../../checkbox/index.js');
var transfer_utils = require('../utils.js');
var utils_ripple = require('../../utils/ripple.js');
var transfer_components_transferSearch = require('./transfer-search.js');
var utils_renderTnode = require('../../utils/render-tnode.js');
var configProvider_configReceiver = require('../../config-provider/config-receiver.js');
require('vue');
require('../../pagination/pagination.js');
require('tdesign-icons-vue');
require('../../input-number/index.js');
require('@vue/composition-api');
require('../../input-number/input-number.js');
require('../../button/index.js');
require('../../button/button.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/toConsumableArray');
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/transfer-dom.js');
require('../../loading/props.js');
require('lodash/camelCase');
require('lodash/kebabCase');
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('../../utils/withInstall.js');
require('lodash/capitalize');
require('../../loading/plugin.js');
require('../../config.js');
require('../../button/props.js');
require('../../input/index.js');
require('../../input/input.js');
require('../../utils/helper.js');
require('../../utils/event.js');
require('../../input/props.js');
require('../../input/input-group.js');
require('../../utils/map-props.js');
require('../../input-number/props.js');
require('../../input-number/useInputNumber.js');
require('../../hooks/useCommonClassName.js');
require('../../config-provider/useConfig.js');
require('../../hooks/useVModel.js');
require('../../_common/js/input-number/number.js');
require('lodash/isNumber');
require('../../_common/js/input-number/large-number.js');
require('../../_common/js/log/log.js');
require('../../hooks/useFormDisabled.js');
require('../../hooks/useGlobalIcon.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('../../hooks/useDefaultValue.js');
require('../../hooks/tnode.js');
require('lodash/isEmpty');
require('../../hooks/render-tnode.js');
require('lodash/isObject');
require('../../select/props.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('../../tag/check-tag-props.js');
require('../../select-input/index.js');
require('../../select-input/select-input.js');
require('../../select-input/props.js');
require('../../select-input/useSingle.js');
require('lodash/pick');
require('../../hooks/useConfig.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-input/hooks/useHover.js');
require('../../tag-input/hooks/useDragSorter.js');
require('../../select-input/useOverlayInnerStyle.js');
require('../../common-components/fake-arrow.js');
require('../../select/option.js');
require('../../select/option-props.js');
require('../../hooks/useLazyLoad.js');
require('../../_common/js/utils/observe.js');
require('../../select/util.js');
require('../../checkbox/group.js');
require('lodash/intersection');
require('../../checkbox/checkbox.js');
require('../../checkbox/props.js');
require('../../checkbox/checkbox-group-props.js');
require('../../select/select-panel.js');
require('../../hooks/useVirtualScroll.js');
require('../../select/hooks/useSelectOptions.js');
require('../../select/optionGroup.js');
require('../../select/option-group-props.js');
require('../../input-adornment/index.js');
require('../../input-adornment/input-adornment.js');
require('../../input-adornment/props.js');
require('../../pagination/props.js');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);

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; }
var classPrefixMixins = configProvider_configReceiver.getClassPrefixMixins("transfer");
var keepAnimationMixins = configProvider_configReceiver.getKeepAnimationMixins();
var TransferList = utils_mixins["default"](keepAnimationMixins, classPrefixMixins).extend({
  name: "TTransferList",
  components: {
    Search: transfer_components_transferSearch["default"],
    TCheckbox: checkbox_index.Checkbox,
    TCheckboxGroup: checkbox_index.CheckboxGroup
  },
  directives: {
    ripple: utils_ripple["default"]
  },
  props: {
    checkboxProps: {
      type: Object,
      "default": function _default() {
        return {};
      }
    },
    dataSource: {
      type: Array,
      "default": function _default() {
        return [];
      }
    },
    listType: {
      type: String,
      "default": "target"
    },
    title: {
      type: [String, Function]
    },
    checkedValue: {
      type: Array,
      "default": function _default() {
        return [];
      }
    },
    disabled: {
      type: Boolean,
      "default": false
    },
    search: {
      type: [Boolean, Object],
      "default": false
    },
    transferItem: Function,
    empty: {
      type: [Function, String]
    },
    pagination: [Boolean, Object],
    footer: [Function, String],
    checkAll: Boolean,
    t: Function,
    global: Object,
    isTreeMode: {
      type: Boolean,
      "default": false
    }
  },
  data: function data() {
    return {
      filterValue: "",
      defaultCurrent: 1,
      defaultPageSize: 0
    };
  },
  computed: {
    currentPage: function currentPage() {
      var _ref, _this$pagination$curr, _this$pagination, _this$pagination2;

      return (_ref = (_this$pagination$curr = (_this$pagination = this.pagination) === null || _this$pagination === void 0 ? void 0 : _this$pagination.current) !== null && _this$pagination$curr !== void 0 ? _this$pagination$curr : this.defaultCurrent) !== null && _ref !== void 0 ? _ref : (_this$pagination2 = this.pagination) === null || _this$pagination2 === void 0 ? void 0 : _this$pagination2.defaultCurrent;
    },
    pageSize: function pageSize() {
      var _ref2, _this$pagination$page, _this$pagination3, _this$pagination4;

      return (_ref2 = (_this$pagination$page = (_this$pagination3 = this.pagination) === null || _this$pagination3 === void 0 ? void 0 : _this$pagination3.pageSize) !== null && _this$pagination$page !== void 0 ? _this$pagination$page : this.defaultPageSize) !== null && _ref2 !== void 0 ? _ref2 : (_this$pagination4 = this.pagination) === null || _this$pagination4 === void 0 ? void 0 : _this$pagination4.defaultPageSize;
    },
    pageTotal: function pageTotal() {
      return this.filteredData && this.filteredData.length || 0;
    },
    filteredData: function filteredData() {
      var _this = this;

      return this.dataSource.filter(function (item) {
        var label = item && item.label.toString();
        return label.toLowerCase().indexOf(_this.filterValue.toLowerCase()) > -1;
      });
    },
    curPageData: function curPageData() {
      var pageData = this.filteredData;
      if (!this.pagination) return pageData;
      if (this.pageSize === 0) return pageData;
      var startIndex = (this.currentPage - 1) * this.pageSize;
      var endIndex = this.currentPage * this.pageSize;
      pageData = pageData.slice(startIndex, endIndex);
      return pageData;
    },
    paginationProps: function paginationProps() {
      var defaultPaginationProps = {
        size: "small",
        theme: "simple",
        totalContent: false,
        pageSizeOptions: []
      };
      return _typeof__default["default"](this.pagination) === "object" ? _objectSpread(_objectSpread(_objectSpread({}, defaultPaginationProps), this.pagination), {}, {
        current: this.currentPage,
        total: this.pageTotal,
        pageSize: this.pageSize
      }) : {};
    },
    hasFooter: function hasFooter() {
      return !!this.$slots["default"];
    },
    indeterminate: function indeterminate() {
      return !this.isAllChecked && this.checkedValue.length > 0;
    },
    isAllChecked: function isAllChecked() {
      var _this2 = this;

      return this.checkedValue.length > 0 && this.dataSource.every(function (item) {
        return item.disabled || _this2.checkedValue.includes(item.value);
      });
    },
    totalCount: function totalCount() {
      return transfer_utils.getLeafCount(this.dataSource);
    }
  },
  watch: {
    totalCount: function totalCount(val) {
      if (val <= (this.currentPage - 1) * this.pageSize) {
        var lastPage = Math.ceil(val / this.pageSize);
        this.defaultCurrent = lastPage;
      }
    }
  },
  methods: {
    handlePaginationChange: function handlePaginationChange(pageInfo) {
      this.$emit("pageChange", pageInfo);
      this.defaultCurrent = pageInfo.current;
      this.defaultPageSize = pageInfo.pageSize;
    },
    handleCheckedChange: function handleCheckedChange(val) {
      this.$emit("checkedChange", val);
    },
    handleCheckedAllChange: function handleCheckedAllChange(checked) {
      if (checked) {
        var allValue = transfer_utils.getDataValues(this.dataSource, [], {
          isTreeMode: this.isTreeMode,
          include: false
        });
        this.handleCheckedChange(allValue);
      } else {
        this.handleCheckedChange([]);
      }
    },
    scroll: function scroll(e) {
      this.$emit("scroll", e);
    },
    handleSearch: function handleSearch(e) {
      var event = {
        query: e.value,
        type: this.listType,
        e: e.e,
        trigger: e.trigger
      };
      this.$emit("search", event);
    },
    renderTitle: function renderTitle() {
      var h = this.$createElement;
      var defaultNode = this.title && typeof this.title === "string" ? h("template", [this.title]) : null;
      var titleNode = utils_renderTnode.renderTNodeJSXDefault(this, "title", {
        defaultNode: defaultNode,
        params: {
          type: this.listType
        }
      });
      return h("span", [titleNode]);
    },
    renderContent: function renderContent() {
      var _this3 = this;

      var h = this.$createElement;
      var rootNode = transfer_utils.findTopNode(this);
      var defaultNode = h(checkbox_index.CheckboxGroup, {
        "attrs": {
          "value": this.checkedValue
        },
        "on": {
          "change": this.handleCheckedChange
        }
      }, [this.curPageData.map(function (item, index) {
        return h(checkbox_index.Checkbox, {
          "attrs": {
            "disabled": _this3.disabled || item.disabled,
            "value": item.value
          },
          "class": ["".concat(_this3.componentName, "__list-item")],
          "key": item.key,
          "directives": [{
            name: "ripple",
            value: _this3.keepAnimation.ripple
          }],
          "props": _objectSpread({}, _this3.checkboxProps)
        }, [utils_renderTnode.renderTNodeJSXDefault(_this3, "transferItem", {
          defaultNode: h("span", [item.label]),
          params: {
            data: item.data,
            index: index,
            type: _this3.listType
          }
        })]);
      })]);
      return h("div", {
        "class": "".concat(this.componentName, "__list-content narrow-scrollbar"),
        "on": {
          "scroll": this.scroll
        }
      }, [utils_renderTnode.renderTNodeJSXDefault(rootNode, "tree", {
        defaultNode: defaultNode,
        params: {
          data: this.curPageData,
          value: this.checkedValue,
          onChange: this.handleCheckedChange
        }
      })]);
    },
    renderEmpty: function renderEmpty() {
      var h = this.$createElement;
      var empty = this.empty || this.t(this.global.empty);
      var defaultNode = typeof empty === "string" ? h("span", [empty]) : null;
      return h("div", {
        "class": "".concat(this.componentName, "__empty")
      }, [utils_renderTnode.renderTNodeJSXDefault(this, "empty", {
        defaultNode: defaultNode,
        params: {
          type: this.listType
        }
      })]);
    },
    renderFooter: function renderFooter() {
      var h = this.$createElement;
      var defaultNode = typeof this.footer === "string" ? h("div", {
        "class": "".concat(this.componentName, "__footer")
      }, [this.footer]) : null;
      return utils_renderTnode.renderTNodeJSXDefault(this, "footer", {
        defaultNode: defaultNode,
        params: {
          type: this.listType
        }
      });
    }
  },
  render: function render() {
    var _this4 = this;

    var h = arguments[0];
    return h("div", {
      "class": "".concat(this.componentName, "__list ").concat(this.componentName, "__list-").concat(this.listType)
    }, [h("div", {
      "class": "".concat(this.componentName, "__list-header")
    }, [h("div", [this.checkAll && h(checkbox_index.Checkbox, {
      "attrs": {
        "disabled": this.disabled || !this.dataSource.length,
        "checked": this.isAllChecked,
        "indeterminate": this.indeterminate
      },
      "on": {
        "change": this.handleCheckedAllChange
      }
    }), h("span", [this.t(this.global.title, {
      checked: this.checkedValue.length,
      total: this.totalCount
    })])]), this.renderTitle()]), h("div", {
      "class": ["".concat(this.componentName, "__list-body"), this.search ? "".concat(this.componentName, "__list--with-search") : ""]
    }, [this.search && h("search", {
      "attrs": {
        "searchValue": this.filterValue,
        "placeholder": this.t(this.global.placeholder),
        "disabled": this.disabled,
        "search": this.search,
        "classPrefix": this.classPrefix
      },
      "on": {
        "change": function change(e) {
          return _this4.filterValue = e;
        },
        "search": this.handleSearch
      }
    }), this.curPageData.length > 0 ? this.renderContent() : this.renderEmpty()]), this.pagination && this.pageSize > 0 && this.pageTotal > 0 && h("div", {
      "class": "".concat(this.componentName, "__list-pagination")
    }, [h(pagination_index.Pagination, helper.helper([{}, {
      "props": this.paginationProps
    }, {
      "on": {
        "change": this.handlePaginationChange
      }
    }]))]), this.renderFooter()]);
  }
});

exports["default"] = TransferList;
//# sourceMappingURL=transfer-list.js.map
