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

'use strict';

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

var helper = require('../../../chunks/helper.js');
var utils_mixins = require('../../../utils/mixins.js');
var components_pagination_index = require('../../pagination/index.js');
var components_checkbox_index = require('../../checkbox/index.js');
var components_transfer_utils = require('../utils.js');
var utils_ripple = require('../../../utils/ripple.js');
var utils_renderNode = require('../../../utils/render-node.js');
var components_configProvider_configReceiver = require('../../config-provider/config-receiver.js');
var components_transfer_components_transferSearch = require('./transfer-search.js');
require('vue');
require('../../../utils/with-install.js');
require('lodash');
require('../../../config.js');
require('../../../utils/map-props.js');
require('../../pagination/pagination.js');
require('@ldesign/icons-vue');
require('../../input-number/index.js');
require('../../input-number/input-number.js');
require('@vue/composition-api');
require('../../button/index.js');
require('../../button/button.js');
require('../../loading/index.js');
require('../../loading/loading.js');
require('../../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../../chunks/log.js');
require('../../../chunks/_commonjsHelpers-2e6815bd.js');
require('../../../utils/easing.js');
require('../../../utils/transfer-dom.js');
require('../../loading/props.js');
require('../../loading/icon/gradient.js');
require('../../../chunks/defineProperty-838e4192.js');
require('../../../chunks/set-style.js');
require('../../../chunks/helper2.js');
require('lodash/mergeWith');
require('../../config-provider/context.js');
require('../../../chunks/zh_CN.js');
require('../../loading/plugin.js');
require('../../button/props.js');
require('../../input/index.js');
require('../../input/input.js');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../../utils/helper.js');
require('../../../utils/event.js');
require('../../input/props.js');
require('../../input/group.js');
require('../../../hooks/use-global-icon.js');
require('../../config-provider/useConfig.js');
require('../../input-number/props.js');
require('../../input-number/hooks/use-input-number.js');
require('../../../chunks/isObjectLike-c22c7e3b.js');
require('../../../chunks/isArray-cd7357b9.js');
require('../../../chunks/isNumber-c4eb560e.js');
require('../../../hooks/use-common-classname.js');
require('../../../hooks/use-vmodel.js');
require('../../../hooks/use-form-disabled.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('lodash/isObject');
require('../../../hooks/use-default-value.js');
require('../../../hooks/lnode.js');
require('lodash/isEmpty');
require('../../../hooks/render-lnode.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('../../select-input/index.js');
require('../../select-input/select-input.js');
require('../../select-input/props.js');
require('../../select-input/hooks/use-single.js');
require('lodash/pick');
require('../../../hooks/use-config.js');
require('../../select-input/hooks/use-multiple.js');
require('../../tag-input/index.js');
require('../../tag-input/tag-input.js');
require('../../tag-input/props.js');
require('../../tag-input/hooks/use-tag-scroll.js');
require('../../tag-input/hooks/use-tag-list.js');
require('../../tag-input/hooks/use-hover.js');
require('../../tag-input/hooks/use-drag-sorter.js');
require('../../select-input/hooks/use-overlay-innerstyle.js');
require('../../common/fake-arrow.js');
require('../../select/option.js');
require('../../../hooks/use-lazy-load.js');
require('../../../chunks/observe.js');
require('../../select/utils.js');
require('../../select/props.js');
require('../../checkbox/group.js');
require('lodash/intersection');
require('../../checkbox/checkbox.js');
require('../../checkbox/props.js');
require('../../select/select-panel.js');
require('../../../hooks/use-virtual-scroll.js');
require('../../select/hooks/use-select-options.js');
require('../../select/option-group.js');
require('../../input-adornment/index.js');
require('../../input-adornment/input-adornment.js');
require('../../input-adornment/props.js');
require('../../pagination/props.js');

const classPrefixMixins = components_configProvider_configReceiver.getClassPrefixMixins("transfer");
const keepAnimationMixins = components_configProvider_configReceiver.getKeepAnimationMixins();
var TransferList = utils_mixins["default"](keepAnimationMixins, classPrefixMixins).extend({
  name: "LTransferList",
  components: {
    LSearch: components_transfer_components_transferSearch["default"],
    LCheckbox: components_checkbox_index.Checkbox,
    LCheckboxGroup: components_checkbox_index.CheckboxGroup,
    LPagination: components_pagination_index.Pagination
  },
  directives: {
    ripple: utils_ripple["default"]
  },
  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 components_transfer_utils.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 = components_transfer_utils.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 = utils_renderNode.renderLNodeJSXDefault(this, "title", {
        defaultNode,
        params: {
          type: this.listType
        }
      });
      return h("span", [titleNode]);
    },
    renderContent() {
      const h = this.$createElement;
      const rootNode = components_transfer_utils.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
        }
      }, [utils_renderNode.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
        }
      }, [utils_renderNode.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`
      }, [utils_renderNode.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 utils_renderNode.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.helper([{}, {
      "props": this.paginationProps
    }, {
      "on": {
        "change": this.handlePaginationChange
      }
    }]))]), this.renderFooter()]);
  }
});

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