import { getClassNames } from '@websolutespa/bom-core'; import { FormControl, useControl } from '@websolutespa/bom-mixer-forms'; import { useLabel } from '@websolutespa/bom-mixer-hooks'; import { ChangeEvent, FocusEvent, useId, useState } from 'react'; import { Button } from '../components'; import { Checkbox, Field, FieldProps, Label } from '../forms'; import { FieldError } from './field-error'; type FieldConsentProps = { control: FormControl; }; export function FieldConsent({ control }: FieldConsentProps & FieldProps) { const uid = useId(); const label = useLabel(); const uniqueName = `${control.name}-${uid}`; const uniqueNameTrue = `${uniqueName}-true`; const uniqueNameFalse = `${uniqueName}-false`; const [state, setValue, setTouched] = useControl(control); const onSelect = (value: boolean) => { // console.log('value', value); setValue(value); }; const [focus, setFocus] = useState(false); const onTrueChange = (event: ChangeEvent) => { onSelect(true); }; const onTrueBlur = (_: FocusEvent) => { setTouched(); setFocus(false); }; const onTrueFocus = (_: FocusEvent) => { setFocus(true); }; const onFalseChange = (event: ChangeEvent) => { onSelect(false); }; const onFalseBlur = (_: FocusEvent) => { setTouched(); setFocus(false); }; const onFalseFocus = (_: FocusEvent) => { setFocus(true); }; const detail = control.customData?.detail; const [active, setActive] = useState(false); const controlLabel = control.label && label(control.label); return ( state.flags.hidden ? ( ) : ( 0 })} padding="1em 0" borderBottom="1px solid var(--color-neutral-200)">
{controlLabel && ( )} {detail && ( <>   {active && (

)} )}

) ); }