/**
 * Web Component wrapper for AIToolCall (hand-crafted WC adapter).
 * Custom element: <hf-ai-tool-call>
 *
 * Provides JSON prop parsing for `toolPart` and a null guard
 * so the component doesn't crash before Vue sets the prop.
 *
 * @generated by scripts/generate-wc-components.ts
 * DO NOT EDIT MANUALLY
 */

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

const PROP_DEFS: PropDefs = {
  toolPart: 'json',
  defaultOpen: 'boolean',
  open: 'boolean',
};

class AIToolCallWC 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 toolPart = props.toolPart as Record<string, unknown> | undefined;

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

    return React.createElement(AIToolCall, {
      toolPart: toolPart as import('../components/AIToolCall').ToolCallPart,
      defaultOpen: (props.defaultOpen as boolean) ?? false,
      open: props.open as boolean | undefined,
      onOpenChange: (open: boolean) => dispatchEvent(this, 'open-change', open),
    });
  }
}

installPropAccessors(AIToolCallWC, PROP_DEFS);
registerWC('hf-ai-tool-call', AIToolCallWC);

export { AIToolCallWC };
export default AIToolCallWC;
