/**
 * tdesign v0.32.0
 * (c) 2021 tdesign
 * @license MIT
 */

import { h as helper } from '../../_chunks/dep-42d5c87e.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _typeof from '@babel/runtime/helpers/typeof';
import Vue from 'vue';
import { prefix } from '../../config.js';
import { Pagination } from '../../pagination/index.js';
import { Checkbox, CheckboxGroup } from '../../checkbox/index.js';
import { getLeefCount, getDataValues, findTopNode } from '../utils.js';
import Ripple from '../../utils/ripple.js';
import Search from './transfer-search.js';
import { renderTNodeJSXDefault } from '../../utils/render-tnode.js';
import '../../pagination/pagination.js';
import 'tdesign-icons-vue';
import '../../utils/mixins.js';
import '../../config-provider/config-receiver.js';
import '../../config-provider/zh_CN_config.js';
import '../../config-provider/type.js';
import '../../input-number/index.js';
import '../../input-number/input-number.js';
import '@babel/runtime/helpers/asyncToGenerator';
import '@babel/runtime/regenerator';
import '../../utils/event.js';
import '../../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/camelCase';
import '../../button/index.js';
import '../../button/button.js';
import '../../utils/classnames.js';
import '../../loading/index.js';
import '../../loading/loading.js';
import '../../loading/icon/gradient.js';
import '../../utils/set-style.js';
import '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../utils/easing.js';
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 '../../button/props.js';
import '../../button/type.js';
import '../../input-number/props.js';
import '../../utils/map-props.js';
import '../../input-number/type.js';
import '../../select/index.js';
import '../../select/select.js';
import '@babel/runtime/helpers/toConsumableArray';
import 'lodash/isFunction';
import 'lodash/debounce';
import 'lodash/get';
import 'lodash/set';
import '../../popup/index.js';
import '../../popup/popup.js';
import '@popperjs/core';
import '../../_chunks/dep-1db5c91c.js';
import '../../popup/props.js';
import '../../popup/type.js';
import '../../input/index.js';
import '../../input/addon.js';
import '../../input/input.js';
import '../../input/props.js';
import '../../input/input-group.js';
import '../../input/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 '../../common-components/fake-arrow.js';
import '../../select/option.js';
import '../../select/option-props.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 '../../select/props.js';
import '../../select/optionGroup.js';
import '../../select/option-group-props.js';
import '../../select/type.js';
import '../../pagination/props.js';
import '../../pagination/type.js';
import 'lodash/cloneDeep';

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(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 TransferList = Vue.extend({
  name: "TTransferList",
  components: {
    Search: Search,
    TCheckbox: Checkbox,
    TCheckboxGroup: CheckboxGroup
  },
  directives: {
    ripple: Ripple
  },
  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() {
      return this.pagination.current || this.defaultCurrent || this.pagination.defaultCurrent;
    },
    pageSize: function pageSize() {
      return this.pagination.pageSize || this.defaultPageSize || this.pagination.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(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 getLeefCount(this.dataSource);
    }
  },
  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 = 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 = 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 = findTopNode(this);
      var defaultNode = h(CheckboxGroup, {
        "attrs": {
          "value": this.checkedValue
        },
        "on": {
          "change": this.handleCheckedChange
        }
      }, [this.curPageData.map(function (item, index) {
        return h(Checkbox, {
          "attrs": {
            "disabled": _this3.disabled || item.disabled,
            "value": item.value
          },
          "class": ["".concat(prefix, "-transfer__list-item")],
          "key": item.key,
          "directives": [{
            name: "ripple",
            value: true
          }],
          "props": _objectSpread({}, _this3.checkboxProps)
        }, [renderTNodeJSXDefault(_this3, "transferItem", {
          defaultNode: h("span", [item.label]),
          params: {
            data: item.data,
            index: index,
            type: _this3.listType
          }
        })]);
      })]);
      return h("div", {
        "class": "".concat(prefix, "-transfer__list-content narrow-scrollbar"),
        "on": {
          "scroll": this.scroll
        }
      }, [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(prefix, "-transfer__empty")
      }, [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(prefix, "-transfer__footer")
      }, [this.footer]) : null;
      return renderTNodeJSXDefault(this, "footer", {
        defaultNode: defaultNode,
        params: {
          type: this.listType
        }
      });
    }
  },
  render: function render() {
    var _this4 = this;

    var h = arguments[0];
    return h("div", {
      "class": "".concat(prefix, "-transfer__list ").concat(prefix, "-transfer__list-").concat(this.listType)
    }, [h("div", {
      "class": "".concat(prefix, "-transfer__list-header")
    }, [h("div", [this.checkAll && h(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(prefix, "-transfer__list-body"), this.search ? "".concat(prefix, "-transfer__list--with-search") : ""]
    }, [this.search && h("search", {
      "attrs": {
        "searchValue": this.filterValue,
        "placeholder": this.t(this.global.placeholder),
        "disabled": this.disabled,
        "search": this.search
      },
      "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(prefix, "-transfer__list-pagination")
    }, [h(Pagination, helper([{}, {
      "props": this.paginationProps
    }, {
      "on": {
        "change": this.handlePaginationChange
      }
    }]))]), this.renderFooter()]);
  }
});

export { TransferList as default };
//# sourceMappingURL=transfer-list.js.map
