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

import React from 'react';
import {
  Sheet,
  SheetBody,
  SheetPopup,
  SheetDescription,
  SheetFooter,
  SheetHeader,
  SheetTitle,
} from '../components/organisms/overlays/Sheet';
import {
  BaseCompoundWC,
  camelToKebab,
  installPropAccessors,
  type PropDefs,
  registerWC,
  portalNode,
  dispatchEvent,
} from './_shared';

const PROP_DEFS: PropDefs = {
  open: 'boolean',
  defaultOpen: 'boolean',
  side: 'string',
  width: 'string',
  showCloseButton: 'boolean',
  disableAnimation: 'boolean',
  modal: 'boolean',
};

class SheetWC 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 triggerSlot = this._getSlot('trigger');
    const titleSlot = this._getSlot('title');
    const descriptionSlot = this._getSlot('description');
    const bodySlot = this._getSlot('body');
    const footerSlot = this._getSlot('footer');
    const iconSlot = this._getSlot('icon');

    const contentChildren: React.ReactElement[] = [];

    const hasHeader = titleSlot || descriptionSlot || iconSlot;
    if (hasHeader) {
      const headerChildren: React.ReactElement[] = [];

      if (titleSlot) {
        headerChildren.push(
          React.createElement(SheetTitle, { key: 'title' }, portalNode(titleSlot)),
        );
      }

      if (descriptionSlot) {
        headerChildren.push(
          React.createElement(
            SheetDescription,
            { key: 'description' },
            portalNode(descriptionSlot),
          ),
        );
      }

      contentChildren.push(
        React.createElement(
          SheetHeader,
          {
            key: 'header',
            icon: iconSlot ? portalNode(iconSlot) : undefined,
          },
          ...headerChildren,
        ),
      );
    }

    if (bodySlot) {
      contentChildren.push(
        React.createElement(SheetBody, { key: 'body' }, portalNode(bodySlot)),
      );
    }

    const defaultSlot = this._getDefaultSlot();
    if (defaultSlot && !bodySlot) {
      contentChildren.push(
        React.createElement(SheetBody, { key: 'default-body' }, portalNode(defaultSlot)),
      );
    }

    if (footerSlot) {
      contentChildren.push(
        React.createElement(SheetFooter, { key: 'footer' }, portalNode(footerSlot)),
      );
    }

    return React.createElement(
      Sheet,
      {
        open: props.open as boolean | undefined,
        defaultOpen: (props.defaultOpen as boolean) || false,
        onOpenChange: (open: boolean) => dispatchEvent(this, 'open-change', open),
        modal: props.modal as boolean | undefined,
        trigger: triggerSlot
          ? React.createElement('span', { style: { display: 'contents' } }, portalNode(triggerSlot))
          : undefined,
      },
      React.createElement(
        SheetPopup,
        {
          side: (props.side as 'top' | 'right' | 'bottom' | 'left') || 'right',
          width: (props.width as 'sm' | 'md' | 'lg' | 'xl' | 'full') || 'md',
          showCloseButton: props.showCloseButton !== false,
          disableAnimation: (props.disableAnimation as boolean) || false,
        },
        ...contentChildren,
      ),
    );
  }
}

installPropAccessors(SheetWC, PROP_DEFS);
registerWC('hf-sheet', SheetWC);

export { SheetWC };
export default SheetWC;
