import { forwardRef, type InputHTMLAttributes, type ForwardedRef } from 'react' import { getCheckboxProps, getFormLabelProps, getIconProps, splitClassNameProp, } from '@pluralsight/headless-styles' import type { CheckboxOptions } from '@pluralsight/headless-styles/types' import { CheckIcon, IndeterminateIcon } from '@pluralsight/icons' import { useFormControl } from '../context/FormControl.tsx' import { Show } from './Show.tsx' export interface CheckboxProps extends CheckboxOptions, Omit, 'id' | 'name' | 'children'> { children?: string } function CheckboxEl( props: CheckboxProps, forwardedRef: ForwardedRef ) { const { children, indeterminate, ...nativeProps } = props const state = useFormControl() const pandoProps = getCheckboxProps({ classNames: splitClassNameProp(nativeProps.className), indeterminate, ...nativeProps, ...state, }) const { value, ...pandoLabelProps } = getFormLabelProps({ ...state, htmlFor: pandoProps.input.id, value: children ?? '', }) return ( ) } export const Checkbox = forwardRef(CheckboxEl)