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

import { h as helper } from '../../../chunks/helper.js';
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 { renderLNodeJSXDefault } from '../../../utils/render-node.js';
import { getClassPrefixMixins, getKeepAnimationMixins } from '../../config-provider/config-receiver.js';
import LSearch from './transfer-search.js';
import '../../../chunks/_commonjsHelpers.js';
import 'vue';
import '../../../utils/with-install.js';
import 'lodash';
import '../../../config.js';
import '../../../utils/map-props.js';
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 '../../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../../chunks/index.js';
import '../../../chunks/log.js';
import '../../../chunks/_commonjsHelpers-2e6815bd.js';
import '../../../utils/easing.js';
import '../../../utils/transfer-dom.js';
import '../../loading/props.js';
import '../../loading/icon/gradient.js';
import '../../../chunks/defineProperty-838e4192.js';
import '../../../chunks/set-style.js';
import '../../../chunks/helper2.js';
import 'lodash/mergeWith';
import '../../config-provider/context.js';
import '../../../chunks/zh_CN.js';
import '../../config-provider/type.js';
import '../../loading/style';
import '../../loading/type.js';
import '../../loading/plugin.js';
import '../../button/props.js';
import '../../button/style';
import '../../button/type.js';
import '../../input/index.js';
import '../../input/input.js';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../../../utils/helper.js';
import '../../../utils/event.js';
import '../../input/props.js';
import '../../input/group.js';
import '../../input/style';
import '../../input/type.js';
import '../../../hooks/use-global-icon.js';
import '../../../hooks/use-config.js';
import '../../config-provider/useConfig.js';
import '../../input-number/props.js';
import '../../input-number/hooks/use-input-number.js';
import '../../../chunks/isObjectLike-c22c7e3b.js';
import '../../../chunks/isArray-cd7357b9.js';
import '../../../chunks/isNumber-c4eb560e.js';
import '../../../hooks/use-common-classname.js';
import '../../../hooks/use-vmodel.js';
import '../../../hooks/use-form-disabled.js';
import '../../input-number/style';
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 'lodash/isObject';
import '../../../hooks/use-default-value.js';
import '../../../hooks/lnode.js';
import 'lodash/isEmpty';
import '../../../hooks/render-lnode.js';
import '../../popup/index.js';
import '../../popup/popup.js';
import '@popperjs/core';
import '../../popup/props.js';
import '../../popup/container.js';
import '../../popup/style';
import '../../popup/type.js';
import '../../tag/index.js';
import '../../tag/tag.js';
import '../../tag/props.js';
import '../../tag/check-tag.js';
import '../../tag/style';
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 '../../tag-input/index.js';
import '../../tag-input/tag-input.js';
import '../../tag-input/props.js';
import '../../tag-input/hooks/use-tag-scroll.js';
import '../../tag-input/hooks/use-tag-list.js';
import '../../tag-input/hooks/use-hover.js';
import '../../tag-input/hooks/use-drag-sorter.js';
import '../../tag-input/style';
import '../../tag-input/type.js';
import '../../select-input/hooks/use-overlay-innerstyle.js';
import '../../select-input/style';
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 '../../select/props.js';
import '../../checkbox/group.js';
import 'lodash/intersection';
import '../../checkbox/checkbox.js';
import '../../checkbox/props.js';
import '../../checkbox/style';
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';
import '../../select/type.js';
import '../../input-adornment/index.js';
import '../../input-adornment/input-adornment.js';
import '../../input-adornment/props.js';
import '../../input-adornment/style';
import '../../input-adornment/type.js';
import '../../pagination/props.js';
import '../../pagination/style';
import '../../pagination/type.js';

const classPrefixMixins = getClassPrefixMixins("transfer");
const keepAnimationMixins = getKeepAnimationMixins();
var TransferList = mixins(keepAnimationMixins, classPrefixMixins).extend({
  name: "LTransferList",
  components: {
    LSearch,
    LCheckbox: Checkbox,
    LCheckboxGroup: CheckboxGroup,
    LPagination: Pagination
  },
  directives: {
    ripple: Ripple
  },
  props: {
    checkboxProps: {
      type: Object,
      default: () => ({})
    },
    dataSource: {
      type: Array,
      default() {
        return [];
      }
    },
    listType: {
      type: String,
      default: "target"
    },
    title: {
      type: [String, Function]
    },
    checkedValue: {
      type: Array,
      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() {
    return {
      filterValue: "",
      defaultCurrent: 1,
      defaultPageSize: 0
    };
  },
  computed: {
    currentPage() {
      var _this$pagination, _this$pagination2;
      return ((_this$pagination = this.pagination) === null || _this$pagination === void 0 ? void 0 : _this$pagination.current) ?? this.defaultCurrent ?? ((_this$pagination2 = this.pagination) === null || _this$pagination2 === void 0 ? void 0 : _this$pagination2.defaultCurrent);
    },
    pageSize() {
      var _this$pagination3, _this$pagination4;
      return ((_this$pagination3 = this.pagination) === null || _this$pagination3 === void 0 ? void 0 : _this$pagination3.pageSize) ?? this.defaultPageSize ?? ((_this$pagination4 = this.pagination) === null || _this$pagination4 === void 0 ? void 0 : _this$pagination4.defaultPageSize);
    },
    pageTotal() {
      return this.filteredData && this.filteredData.length || 0;
    },
    filteredData() {
      return this.dataSource.filter(item => {
        const label = item && item.label.toString();
        return label.toLowerCase().includes(this.filterValue.toLowerCase());
      });
    },
    curPageData() {
      let pageData = this.filteredData;
      if (!this.pagination) return pageData;
      if (this.pageSize === 0) return pageData;
      const startIndex = (this.currentPage - 1) * this.pageSize;
      const endIndex = this.currentPage * this.pageSize;
      pageData = pageData.slice(startIndex, endIndex);
      return pageData;
    },
    paginationProps() {
      const defaultPaginationProps = {
        size: "small",
        theme: "simple",
        totalContent: false,
        pageSizeOptions: []
      };
      return typeof this.pagination === "object" ? {
        ...defaultPaginationProps,
        ...this.pagination,
        current: this.currentPage,
        total: this.pageTotal,
        pageSize: this.pageSize
      } : {};
    },
    hasFooter() {
      return !!this.$slots.default;
    },
    indeterminate() {
      return !this.isAllChecked && this.checkedValue.length > 0;
    },
    isAllChecked() {
      return this.checkedValue.length > 0 && this.dataSource.every(item => item.disabled || this.checkedValue.includes(item.value));
    },
    totalCount() {
      return getLeafCount(this.dataSource);
    }
  },
  watch: {
    totalCount(val) {
      if (val <= (this.currentPage - 1) * this.pageSize) {
        const lastPage = Math.ceil(val / this.pageSize);
        this.defaultCurrent = lastPage;
      }
    }
  },
  methods: {
    handlePaginationChange(pageInfo) {
      this.$emit("pageChange", pageInfo);
      this.defaultCurrent = pageInfo.current;
      this.defaultPageSize = pageInfo.pageSize;
    },
    handleCheckedChange(val) {
      this.$emit("checkedChange", val);
    },
    handleCheckedAllChange(checked) {
      if (checked) {
        const allValue = getDataValues(this.dataSource, [], {
          isTreeMode: this.isTreeMode,
          include: false
        });
        this.handleCheckedChange(allValue);
      } else {
        this.handleCheckedChange([]);
      }
    },
    scroll(e) {
      this.$emit("scroll", e);
    },
    handleSearch(e) {
      const event = {
        query: e.value,
        type: this.listType,
        e: e.e,
        trigger: e.trigger
      };
      this.$emit("search", event);
    },
    renderTitle() {
      const h = this.$createElement;
      const defaultNode = this.title && typeof this.title === "string" ? h("template", [this.title]) : null;
      const titleNode = renderLNodeJSXDefault(this, "title", {
        defaultNode,
        params: {
          type: this.listType
        }
      });
      return h("span", [titleNode]);
    },
    renderContent() {
      const h = this.$createElement;
      const rootNode = findTopNode(this);
      const defaultNode = h("l-checkbox-group", {
        "attrs": {
          "value": this.checkedValue
        },
        "on": {
          "change": this.handleCheckedChange
        }
      }, [this.curPageData.map((item, index) => h("l-checkbox", {
        "attrs": {
          "disabled": this.disabled || item.disabled,
          "value": item.value
        },
        "class": [`${this.componentName}__list-item`],
        "key": item.key,
        "directives": [{
          name: "ripple",
          value: this.keepAnimation.ripple
        }],
        "props": {
          ...this.checkboxProps
        }
      }, [renderLNodeJSXDefault(this, "transferItem", {
        defaultNode: h("span", [item.label]),
        params: {
          data: item.data,
          index,
          type: this.listType
        }
      })]))]);
      return h("div", {
        "class": `${this.componentName}__list-content narrow-scrollbar`,
        "on": {
          "scroll": this.scroll
        }
      }, [renderLNodeJSXDefault(rootNode, "tree", {
        defaultNode,
        params: {
          data: this.curPageData,
          value: this.checkedValue,
          onChange: this.handleCheckedChange
        }
      })]);
    },
    renderEmpty() {
      const h = this.$createElement;
      const empty = this.empty || this.t(this.global.empty);
      const defaultNode = typeof empty === "string" ? h("span", [empty]) : null;
      return h("div", {
        "class": `${this.componentName}__empty`
      }, [renderLNodeJSXDefault(this, "empty", {
        defaultNode,
        params: {
          type: this.listType
        }
      })]);
    },
    renderFooter() {
      const h = this.$createElement;
      const defaultNode = typeof this.footer === "string" ? h("div", {
        "class": `${this.componentName}__footer`
      }, [this.footer]) : null;
      return renderLNodeJSXDefault(this, "footer", {
        defaultNode,
        params: {
          type: this.listType
        }
      });
    }
  },
  render() {
    const h = arguments[0];
    return h("div", {
      "class": `${this.componentName}__list ${this.componentName}__list-${this.listType}`
    }, [h("div", {
      "class": `${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": [`${this.componentName}__list-body`, this.search ? `${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": e => this.filterValue = e,
        "search": this.handleSearch
      }
    }), this.curPageData.length > 0 ? this.renderContent() : this.renderEmpty()]), this.pagination && this.pageSize > 0 && this.pageTotal > 0 && h("div", {
      "class": `${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
