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

import { h as helper } from '../../../chunks/helper.js';
import { defineComponent, ref, computed } from '@vue/composition-api';
import { BaseTableProps, PrimaryTableProps, EnhancedTableProps } from '../props.js';
import useTreeData from '../hooks/useTreeData.js';
import useTreeSelect from '../hooks/useTreeSelect.js';
import _PrimaryTable from './primary-table.js';
import { BASE_TABLE_ALL_EVENTS } from './base-table.js';
import '../../../chunks/_commonjsHelpers.js';
import '@ldesign/icons-vue';
import 'lodash/cloneDeep';
import 'lodash/get';
import '../../../chunks/defineProperty-838e4192.js';
import '../../../chunks/get-5e1abd10.js';
import '../../../chunks/isArray-cd7357b9.js';
import '../../../chunks/isSymbol-a38a5184.js';
import '../../../chunks/isObjectLike-c22c7e3b.js';
import '../../../chunks/_commonjsHelpers-2e6815bd.js';
import '../../../chunks/isFunction-91acade7.js';
import '../../../chunks/log.js';
import '../../../chunks/utils3.js';
import '../../../chunks/isNumber-c4eb560e.js';
import './tr.js';
import 'lodash/isFunction';
import 'lodash/upperFirst';
import 'lodash/isString';
import 'lodash/pick';
import '../../../hooks/use-lazy-load.js';
import '../../../chunks/observe.js';
import '../utils.js';
import 'lodash/isObject';
import '../hooks/useFixed.js';
import 'lodash/debounce';
import '../../../chunks/index.js';
import '../../../chunks/helper2.js';
import '../../../utils/dom.js';
import 'vue';
import 'raf';
import '../../../utils/easing.js';
import '../hooks/useClassName.js';
import '../../config-provider/useConfig.js';
import '../../config-provider/context.js';
import 'lodash';
import '../../../chunks/zh_CN.js';
import '../../config-provider/type.js';
import '../hooks/useRowspanAndColspan.js';
import './ellipsis.js';
import '../../../utils/render-node.js';
import '../../tooltip/index.js';
import '../../../utils/map-props.js';
import '../../../utils/with-install.js';
import '../../../config.js';
import '../../tooltip/tooltip.js';
import '../../popup/props.js';
import '../../popup/popup.js';
import '@popperjs/core';
import '../../../chunks/set-style.js';
import '../../../utils/helper.js';
import 'lodash/camelCase';
import '../../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../../../utils/mixins.js';
import '../../popup/container.js';
import '../../tooltip/props.js';
import '../../tooltip/style/css.js';
import '../../tooltip/type.js';
import '../../../hooks/lnode.js';
import 'lodash/isEmpty';
import 'lodash/kebabCase';
import '../../../hooks/render-lnode.js';
import '../../../hooks/use-global-icon.js';
import '../../../hooks/use-config.js';
import 'lodash/intersection';
import '../../../hooks/use-default-value.js';
import 'lodash/omit';
import '../hooks/useColumnController.js';
import '../../checkbox/index.js';
import '../../checkbox/group.js';
import '../../../utils/event.js';
import '../../checkbox/checkbox.js';
import '../../checkbox/props.js';
import '../../checkbox/style/css.js';
import '../../checkbox/type.js';
import '../../dialog/plugin.js';
import '../../dialog/dialog.js';
import 'lodash/isNumber';
import 'lodash/throttle';
import '../../button/index.js';
import '../../button/button.js';
import '../../loading/index.js';
import '../../loading/loading.js';
import '../../../utils/transfer-dom.js';
import '../../loading/props.js';
import '../../loading/icon/gradient.js';
import '../../loading/style/css.js';
import '../../loading/type.js';
import '../../loading/plugin.js';
import '../../../utils/ripple.js';
import '../../button/props.js';
import '../../button/style/css.js';
import '../../button/type.js';
import '../../../hooks/use-destroy-onclose.js';
import '../../dialog/props.js';
import '../../dialog/mixins/action.js';
import '../../dialog/stack.js';
import '../hooks/useTableHeader.js';
import '../hooks/useMultiHeader.js';
import '../hooks/useRowExpand.js';
import '../hooks/useRowSelect.js';
import '../../radio/index.js';
import '../../radio/radio.js';
import '../../radio/props.js';
import '../../radio/group.js';
import '../../radio/radio-button.js';
import '../../radio/style/css.js';
import '../../radio/type.js';
import '../hooks/useSorter.js';
import './sorter-button.js';
import '../hooks/useFilter.js';
import './filter-controller.js';
import 'lodash/lowerFirst';
import '../../popup/index.js';
import '../../popup/style/css.js';
import '../../popup/type.js';
import '../../input/index.js';
import '../../input/input.js';
import '../../input/props.js';
import '../../input/group.js';
import '../../input/style/css.js';
import '../../input/type.js';
import '../hooks/useDragSort.js';
import 'sortablejs';
import '../hooks/useAsyncLoading.js';
import '../hooks/useEditableCell.js';
import './editable-cell.js';
import 'lodash/set';
import '../../form/model.js';
import '../hooks/useEditableRow.js';
import '../hooks/useStyle.js';
import '../../../hooks/use-common-classname.js';
import '../../../hooks/use-virtual-scroll.js';
import '../../affix/index.js';
import '../../affix/affix.js';
import '../../affix/props.js';
import '../../affix/style/css.js';
import '../../affix/type.js';
import '../hooks/useColumnResize.js';
import '../hooks/usePagination.js';
import '../../pagination/index.js';
import '../../pagination/pagination.js';
import '../../input-number/index.js';
import '../../input-number/input-number.js';
import '../../input-number/props.js';
import '../../input-number/hooks/use-input-number.js';
import '../../../hooks/use-vmodel.js';
import '../../../hooks/use-form-disabled.js';
import '../../input-number/style/css.js';
import '../../input-number/type.js';
import '../../select/index.js';
import '../../select/select.js';
import 'lodash/isArray';
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 '../../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/css.js';
import '../../tag-input/type.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 '../../select/utils.js';
import '../../select/props.js';
import '../../select/select-panel.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';
import '../hooks/useAffix.js';
import './tbody.js';
import './thead.js';
import './tfoot.js';

const PRIMARY_B_EVENTS = ["cell-click", "change", "page-change", "expand-change", "filter-change", "select-change", "sort-change", "data-change", "async-loading-click", "column-change", "column-controller-visible-change", "display-columns-change", "drag-sort", "row-edit", "row-validate", "validate"];
const PRIMARY_ALL_EVENTS = BASE_TABLE_ALL_EVENTS.concat(PRIMARY_B_EVENTS);
var _EnhancedTable = defineComponent({
  name: "LEnhancedTable",
  props: {
    ...BaseTableProps,
    ...PrimaryTableProps,
    ...EnhancedTableProps
  },
  setup(props, context) {
    const enhancedTableRef = ref();
    const {
      store,
      dataSource,
      formatTreeColumn,
      swapData,
      ...treeInstanceFunctions
    } = useTreeData(props, context);
    const treeDataMap = ref(store.value.treeDataMap);
    const {
      tIndeterminateSelectedRowKeys,
      onInnerSelectChange
    } = useTreeSelect(props, treeDataMap);
    const getColumns = columns => {
      const arr = [];
      for (let i = 0, len = columns.length; i < len; i++) {
        var _item$children, _item$children2;
        let item = {
          ...columns[i]
        };
        item = formatTreeColumn(item);
        if ((_item$children = item.children) !== null && _item$children !== void 0 && _item$children.length) item.children = getColumns(item.children);
        if (!item.children || (_item$children2 = item.children) !== null && _item$children2 !== void 0 && _item$children2.length) arr.push(item);
      }
      return arr;
    };
    const tColumns = computed(() => {
      const isTreeData = !props.tree || !Object.keys(props.tree).length;
      return isTreeData ? props.columns : getColumns(props.columns);
    });
    const onDragSortChange = params => {
      var _props$onDragSort;
      if (props.beforeDragSort && !props.beforeDragSort(params)) return;
      swapData({
        current: params.current,
        target: params.target,
        currentIndex: params.currentIndex,
        targetIndex: params.targetIndex
      });
      (_props$onDragSort = props.onDragSort) === null || _props$onDragSort === void 0 ? void 0 : _props$onDragSort.call(props, params);
      context.emit("drag-sort", params);
    };
    return {
      store,
      dataSource,
      tColumns,
      tIndeterminateSelectedRowKeys,
      enhancedTableRef,
      onDragSortChange,
      onInnerSelectChange,
      ...treeInstanceFunctions
    };
  },
  methods: {
    getListener() {
      var _this = this;
      const listeners = {};
      PRIMARY_ALL_EVENTS.forEach(key => {
        listeners[key] = function () {
          for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
            args[_key] = arguments[_key];
          }
          _this.$emit(key, ...args);
          if (key === "display-columns-change") _this.$emit("update:displayColumns", ...args);
        };
      });
      return listeners;
    }
  },
  render() {
    const h = arguments[0];
    const props = {
      ...this.$options.propsData,
      data: this.dataSource,
      columns: this.tColumns,
      indeterminateSelectedRowKeys: this.tIndeterminateSelectedRowKeys,
      disableDataPage: Boolean(this.tree && Object.keys(this.tree).length)
    };
    const on = {
      ...this.getListener(),
      "select-change": this.onInnerSelectChange,
      "drag-sort": this.onDragSortChange
    };
    return h(_PrimaryTable, helper([{
      "ref": "enhancedTableRef",
      "scopedSlots": this.$scopedSlots
    }, {
      "props": props
    }, {}, {
      "on": on
    }, {}, this.$attrs]));
  }
});

export { _EnhancedTable as default };
//# sourceMappingURL=enhanced-table.js.map
