/* eslint-disable @typescript-eslint/no-explicit-any */
import { createElement } from 'react';
import { TailwindPlayCommonParams } from '@/TailwindPlay/Fields/types.js';
import { extractHusarData } from '@/TailwindPlay/shared/extract.js';
import { isValidHtmlComponent } from '@/TailwindPlay/shared/constants.js';
import { isVoidElement } from '@/TailwindPlay/Fields/shared';

export const FieldBoolean: React.FC<TailwindPlayCommonParams> = (props) => {
  const { v, attributes } = extractHusarData(props);
  const tag = isValidHtmlComponent(attributes);
  if (isVoidElement(tag)) {
    // For void elements, use value/defaultValue instead of children
    return createElement(tag, { ...attributes, defaultValue: !!v });
  }
  return createElement(tag, { ...attributes }, !!v);
};
