import { defineComponent, ref, watch, provide, resolveComponent, createBlock, openBlock, withCtx, createElementVNode, normalizeClass, unref, createCommentVNode, createVNode, mergeProps, renderSlot, createSlots, normalizeProps, guardReactiveProps } from 'vue';
import '../../../utils/index.mjs';
import './config/index.mjs';
import './components/header-search.vue.mjs';
import './components/main-table.vue.mjs';
import './components/pagination.vue.mjs';
import { ImenuSwitchType } from './config/header-search.mjs';
import { HEADER_SRARCH_HEIGHT, PAGINATION_HEIGHT, tableProps } from './config/table.mjs';
import { createNamespace } from '../../../utils/create-namespace.mjs';
import _sfc_main$1 from './components/header-search.vue2.mjs';
import _sfc_main$2 from './components/main-table.vue2.mjs';
import _sfc_main$3 from './components/pagination.vue2.mjs';

"use strict";
var _sfc_main = /* @__PURE__ */ defineComponent({
  ...{ name: "LlTable" },
  __name: "table",
  props: tableProps,
  setup(__props) {
    const props = __props;
    const originDataSource = ref();
    const newNaTableptions = ref({
      dataSource: [],
      columns: []
    });
    const contentType = ref(ImenuSwitchType.TABLE);
    const headerSearchHeight = ref(HEADER_SRARCH_HEIGHT);
    const tableRef = ref();
    const bem = createNamespace("table");
    const handleChangeDataSource = (dataSource) => {
      newNaTableptions.value.dataSource = dataSource;
    };
    const handleSwitchMenuChange = (v) => {
      contentType.value = v;
    };
    const handleChangeHeaderSearch = (height) => {
      if (headerSearchHeight.value === height) return;
      headerSearchHeight.value = height;
    };
    watch(
      () => props.tableProps,
      (newValue) => {
        if (newValue) {
          newNaTableptions.value = { ...newValue };
          originDataSource.value = [...newValue.dataSource];
          contentType.value = newNaTableptions.value.contentType;
        }
      },
      {
        deep: true,
        immediate: true
      }
    );
    watch(
      () => [tableRef, headerSearchHeight],
      () => {
        if (tableRef.value) {
          const diffHeight = headerSearchHeight.value + 20 + PAGINATION_HEIGHT + 10;
          tableRef.value.style.height = `calc(100% - ${diffHeight}px)`;
        }
      },
      {
        immediate: true,
        deep: true
      }
    );
    provide("contentType", contentType);
    return (_ctx, _cache) => {
      const _component_a_spin = resolveComponent("a-spin");
      return openBlock(), createBlock(_component_a_spin, {
        spinning: props.loading,
        "wrapper-class-name": "ll-table-spin-wrapper"
      }, {
        default: withCtx(() => [
          createElementVNode(
            "div",
            {
              class: normalizeClass(unref(bem).b())
            },
            [
              createCommentVNode(" \u5934\u90E8seach "),
              createVNode(_sfc_main$1, mergeProps(_ctx.headerSearchProps, {
                "header-search-height": headerSearchHeight.value,
                onChange: handleSwitchMenuChange,
                onChangeHeaderSearch: handleChangeHeaderSearch
              }), {
                header: withCtx(() => [
                  renderSlot(_ctx.$slots, "header")
                ]),
                headerLeft: withCtx(() => [
                  renderSlot(_ctx.$slots, "headerLeft")
                ]),
                headerMiddle: withCtx(() => [
                  renderSlot(_ctx.$slots, "headerMiddle")
                ]),
                headerRight: withCtx(() => [
                  renderSlot(_ctx.$slots, "headerRight")
                ]),
                _: 3
                /* FORWARDED */
              }, 16, ["header-search-height"]),
              createCommentVNode(" slot-content table\u548Ccard\u9ED8\u8BA4table "),
              createElementVNode(
                "div",
                {
                  ref_key: "tableRef",
                  ref: tableRef,
                  class: normalizeClass([
                    unref(bem).m("fixed-height"),
                    !newNaTableptions.value.dataSource.length ? unref(bem).m("empty") : ""
                  ])
                },
                [
                  renderSlot(_ctx.$slots, contentType.value, {}, () => [
                    createVNode(
                      _sfc_main$2,
                      mergeProps(newNaTableptions.value, { onHandleChangeDataSource: handleChangeDataSource }),
                      createSlots({
                        tableHeaderCell: withCtx((slots) => [
                          renderSlot(_ctx.$slots, "tableHeaderCell", normalizeProps(guardReactiveProps(slots)))
                        ]),
                        tableBodyCell: withCtx((slots) => [
                          renderSlot(_ctx.$slots, "tableBodyCell", normalizeProps(guardReactiveProps(slots)))
                        ]),
                        tableOperate: withCtx((slots) => [
                          renderSlot(_ctx.$slots, "tableOperate", normalizeProps(guardReactiveProps(slots)))
                        ]),
                        expandedTitle: withCtx(() => [
                          renderSlot(_ctx.$slots, "expandedTitle")
                        ]),
                        emptyText: withCtx(() => [
                          renderSlot(_ctx.$slots, "emptyText")
                        ]),
                        _: 2
                        /* DYNAMIC */
                      }, [
                        _ctx.$slots.expandedRow ? {
                          name: "expandedRow",
                          fn: withCtx((slots) => [
                            renderSlot(_ctx.$slots, "expandedRow", normalizeProps(guardReactiveProps(slots)))
                          ]),
                          key: "0"
                        } : void 0,
                        _ctx.$slots.customFilterDropdown ? {
                          name: "customFilterDropdown",
                          fn: withCtx((slots) => [
                            renderSlot(_ctx.$slots, "customFilterDropdown", normalizeProps(guardReactiveProps(slots)))
                          ]),
                          key: "1"
                        } : void 0,
                        _ctx.$slots.customFilterIcon ? {
                          name: "customFilterIcon",
                          fn: withCtx((slots) => [
                            renderSlot(_ctx.$slots, "customFilterIcon", normalizeProps(guardReactiveProps(slots)))
                          ]),
                          key: "2"
                        } : void 0,
                        _ctx.$slots.summary ? {
                          name: "summary",
                          fn: withCtx((slots) => [
                            renderSlot(_ctx.$slots, "summary", normalizeProps(guardReactiveProps(slots)))
                          ]),
                          key: "3"
                        } : void 0
                      ]),
                      1040
                      /* FULL_PROPS, DYNAMIC_SLOTS */
                    )
                  ])
                ],
                2
                /* CLASS */
              ),
              createCommentVNode(" \u5E95\u90E8\u5206\u9875 "),
              newNaTableptions.value.dataSource.length && !newNaTableptions.value.hiddenPagination ? (openBlock(), createBlock(
                _sfc_main$3,
                normalizeProps(mergeProps({ key: 0 }, _ctx.paginationProps)),
                null,
                16
                /* FULL_PROPS */
              )) : createCommentVNode("v-if", true)
            ],
            2
            /* CLASS */
          )
        ]),
        _: 3
        /* FORWARDED */
      }, 8, ["spinning"]);
    };
  }
});

export { _sfc_main as default };
//# sourceMappingURL=table.vue2.mjs.map
