/**
 * Web Component wrapper for AIChart (hand-crafted WC adapter).
 * Custom element: <hf-ai-chart>
 *
 * Wraps the React component with AIInteractionProvider so the
 * useAIInteraction() hook has context outside of AIMessage.
 * Sets display:block in connectedCallback so ResponsiveContainer can measure.
 *
 * @generated by scripts/generate-wc-components.ts
 * DO NOT EDIT MANUALLY
 */

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

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

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

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

  connectedCallback() {
    // Ensure the custom element is a block-level element so
    // Recharts' ResponsiveContainer can measure its dimensions.
    this.style.display = 'block';
    super.connectedCallback();
  }

  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(AIChart, {
        schema: schema as import('../components/AIChart').ChartBlockSchema,
      }),
    );
  }
}

installPropAccessors(AIChartWC, PROP_DEFS);
registerWC('hf-ai-chart', AIChartWC);

export { AIChartWC };
export default AIChartWC;
