/**
 * Web Component wrapper for AITable (hand-crafted WC adapter).
 * Custom element: <hf-ai-table>
 *
 * Wraps the React component with AIInteractionProvider so the
 * useAIInteraction() hook has context outside of AIMessage.
 *
 * @generated by scripts/generate-wc-components.ts
 * DO NOT EDIT MANUALLY
 */

import React from 'react';
import { AIInteractionProvider, AITable } from '../components';
import {
  BaseCompoundWC,
  camelToKebab,
  dispatchEvent,
  installPropAccessors,
  type PropDefs,
  registerWC,
} from './_shared';

const PROP_DEFS: PropDefs = {
  schema: 'json',
};

class AITableWC extends BaseCompoundWC {
  get propDefs() {
    return PROP_DEFS;
  }

  static get observedAttributes() {
    return Object.keys(PROP_DEFS).map(camelToKebab);
  }

  protected _renderReact(): React.ReactElement {
    const props = this._readAllProps();
    const schema = props.schema as Record<string, unknown> | undefined;

    // Null guard: return empty fragment until schema is provided
    if (!schema || typeof schema !== 'object' || !schema.id) {
      return React.createElement(React.Fragment);
    }

    return React.createElement(
      AIInteractionProvider,
      {
        onInteraction: (event: unknown) =>
          dispatchEvent(this, 'interaction', event),
      },
      React.createElement(AITable, {
        schema: schema as import('../components/AITable').TableBlockSchema,
      }),
    );
  }
}

installPropAccessors(AITableWC, PROP_DEFS);
registerWC('hf-ai-table', AITableWC);

export { AITableWC };
export default AITableWC;
