/**
   * lit-table
   *
   * Copyright (c) TanStack
   *
   * This source code is licensed under the MIT license found in the
   * LICENSE.md file in the root directory of this source tree.
   *
   * @license MIT
   */
import { createTable } from '@tanstack/table-core';
export * from '@tanstack/table-core';

function flexRender(Comp, props) {
  if (!Comp) return null;
  if (typeof Comp === 'function') {
    return Comp(props);
  }
  return Comp;
}
class TableController {
  tableInstance = null;
  _tableState = null;
  constructor(host) {
    (this.host = host).addController(this);
  }
  table(options) {
    if (!this.tableInstance) {
      const resolvedOptions = {
        state: {},
        onStateChange: () => {},
        // noop
        renderFallbackValue: null,
        ...options
      };
      this.tableInstance = createTable(resolvedOptions);
      this._tableState = {
        ...this.tableInstance.initialState,
        ...options.state
      };
    }
    this.tableInstance.setOptions(prev => ({
      ...prev,
      ...options,
      state: {
        ...this._tableState,
        ...options.state
      },
      onStateChange: updater => {
        this._tableState = updater(this._tableState);
        this.host.requestUpdate();
        options.onStateChange == null || options.onStateChange(updater);
      }
    }));
    return this.tableInstance;
  }
  hostDisconnected() {}
}

export { TableController, flexRender };
//# sourceMappingURL=index.mjs.map
