/**
 * Web Component wrapper for Accordion (auto-generated).
 * Custom element: <hf-accordion>
 *
 * @generated by scripts/generate-wc-components.ts
 * DO NOT EDIT MANUALLY
 */

import React from 'react';
import {
  Accordion,
  AccordionContent,
  AccordionItem,
  AccordionTrigger,
} from '../components/molecules/navigation/Accordion';
import {
  BaseCompoundWC,
  camelToKebab,
  installPropAccessors,
  type PropDefs,
  registerWC,
  portalNode,
  dispatchEvent,
} from './_shared';

const PROP_DEFS: PropDefs = {
  items: 'json',
  value: 'json',
  defaultValue: 'json',
  multiple: 'boolean',
};

interface AccordionItemDefinition {
  value: string;
  trigger: string;
}

class AccordionWC 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 items = (props.items as AccordionItemDefinition[]) || [];
    const multiple = (props.multiple as boolean) || false;

    const itemElements: React.ReactElement[] = [];
    for (const item of items) {
      const slotName = 'content-' + item.value;
      const slotContent = this._getSlot(slotName);

      itemElements.push(
        React.createElement(
          AccordionItem,
          {
            key: item.value,
            value: item.value,
          },
          React.createElement(AccordionTrigger, null, item.trigger),
          React.createElement(
            AccordionContent,
            null,
            slotContent ? portalNode(slotContent) : null,
          ),
        ),
      );
    }

    return React.createElement(
      Accordion,
      {
        value: props.value as string[] | undefined,
        defaultValue: (props.defaultValue as string[]) || [],
        onValueChange: (value: (string | number)[]) => dispatchEvent(this, 'value-change', value.map(String)),
        multiple,
      },
      ...itemElements,
    );
  }
}

installPropAccessors(AccordionWC, PROP_DEFS);
registerWC('hf-accordion', AccordionWC);

export { AccordionWC };
export default AccordionWC;
