/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

import { h as helper } from '../../../chunks/helper.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _typeof from '@babel/runtime/helpers/typeof';
import mixins from '../../../utils/mixins.js';
import { Pagination } from '../../pagination/index.js';
import { Checkbox, CheckboxGroup } from '../../checkbox/index.js';
import { getLeafCount, getDataValues, findTopNode } from '../utils.js';
import Ripple from '../../../utils/ripple.js';
import LSearch from './transfer-search.js';
import { renderLNodeJSXDefault } from '../../../utils/render-node.js';
import { getClassPrefixMixins, getKeepAnimationMixins } from '../../config-provider/config-receiver.js';
import '../../../chunks/_commonjsHelpers.js';
import 'vue';
import '../../pagination/pagination.js';
import '@ldesign/icons-vue';
import '../../input-number/index.js';
import '../../input-number/input-number.js';
import '@vue/composition-api';
import '../../button/index.js';
import '../../button/button.js';
import '../../loading/index.js';
import '../../loading/loading.js';
import '../../loading/icon/gradient.js';
import '../../../chunks/defineProperty-28395935.js';
import '../../../chunks/set-style.js';
import '../../../chunks/helper2.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/slicedToArray';
import '../../../config.js';
import '../../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../../utils/easing.js';
import '../../../utils/transfer-dom.js';
import '../../loading/props.js';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import 'lodash/mergeWith';
import 'lodash';
import '../../config-provider/context.js';
import '../../../chunks/zh_CN.js';
import '../../config-provider/type.js';
import '../../../utils/with-install.js';
import '../../loading/style/css.js';
import '../../loading/type.js';
import '../../loading/plugin.js';
import '../../button/props.js';
import '../../button/style/css.js';
import '../../button/type.js';
import '../../input/index.js';
import '../../input/input.js';
import '../../../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../../../utils/event.js';
import '../../input/props.js';
import '../../input/group.js';
import '../../../utils/map-props.js';
import '../../input/style/css.js';
import '../../input/type.js';
import '../../input-number/props.js';
import '../../input-number/hooks/use-input-number.js';
import '../../../chunks/isObjectLike-2443c6ff.js';
import '../../../chunks/_commonjsHelpers-ea2bee21.js';
import '../../../chunks/isArray-b0f0e351.js';
import '../../../chunks/log.js';
import '../../../hooks/use-common-classname.js';
import '../../config-provider/useConfig.js';
import '../../../hooks/use-vmodel.js';
import '../../../hooks/use-form-disabled.js';
import '../../../hooks/use-global-icon.js';
import '../../../hooks/use-config.js';
import '../../input-number/style/css.js';
import '../../input-number/type.js';
import '../../select/index.js';
import '../../select/select.js';
import 'lodash/isFunction';
import 'lodash/debounce';
import 'lodash/get';
import 'lodash/cloneDeep';
import 'lodash/isArray';
import '../../../hooks/use-default-value.js';
import '../../../hooks/lnode.js';
import 'lodash/isEmpty';
import '../../../hooks/render-lnode.js';
import 'lodash/isObject';
import '../../select/props.js';
import '../../popup/index.js';
import '../../popup/popup.js';
import '@popperjs/core';
import '../../popup/props.js';
import '../../popup/container.js';
import '../../popup/style/css.js';
import '../../popup/type.js';
import '../../tag/index.js';
import '../../tag/tag.js';
import '../../tag/props.js';
import '../../tag/check-tag.js';
import '../../tag/style/css.js';
import '../../tag/type.js';
import '../../select-input/index.js';
import '../../select-input/select-input.js';
import '../../select-input/props.js';
import '../../select-input/hooks/use-single.js';
import 'lodash/pick';
import '../../select-input/hooks/use-multiple.js';
import '../../select-input/hooks/use-overlay-innerstyle.js';
import '../../select-input/style/css.js';
import '../../select-input/type.js';
import '../../common/fake-arrow.js';
import '../../select/option.js';
import '../../../hooks/use-lazy-load.js';
import '../../../chunks/observe.js';
import '../../select/utils.js';
import '../../checkbox/group.js';
import 'lodash/intersection';
import '../../checkbox/checkbox.js';
import '../../checkbox/props.js';
import '../../checkbox/style/css.js';
import '../../checkbox/type.js';
import '../../select/select-panel.js';
import '../../../hooks/use-virtual-scroll.js';
import '../../select/hooks/use-select-options.js';
import '../../select/option-group.js';
import '../../select/style/css.js';
import '../../select/type.js';
import '../../input-adornment/index.js';
import '../../input-adornment/input-adornment.js';
import '../../input-adornment/props.js';
import '../../input-adornment/style/css.js';
import '../../input-adornment/type.js';
import '../../pagination/props.js';
import '../../pagination/style/css.js';
import '../../pagination/type.js';

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 classPrefixMixins = getClassPrefixMixins("transfer");
var keepAnimationMixins = getKeepAnimationMixins();
var TransferList = mixins(keepAnimationMixins, classPrefixMixins).extend({
  name: "LTransferList",
  components: {
    LSearch: LSearch,
    LCheckbox: Checkbox,
    LCheckboxGroup: CheckboxGroup,
    LPagination: Pagination
  },
  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() {
      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(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 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 = 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 = renderLNodeJSXDefault(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("l-checkbox-group", {
        "attrs": {
          "value": this.checkedValue
        },
        "on": {
          "change": this.handleCheckedChange
        }
      }, [this.curPageData.map(function (item, index) {
        return h("l-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)
        }, [renderLNodeJSXDefault(_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
        }
      }, [renderLNodeJSXDefault(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")
      }, [renderLNodeJSXDefault(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 renderLNodeJSXDefault(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("l-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("l-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("l-pagination", helper([{}, {
      "props": this.paginationProps
    }, {
      "on": {
        "change": this.handlePaginationChange
      }
    }]))]), this.renderFooter()]);
  }
});

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