'use client' import React, { forwardRef, cloneElement, isValidElement } from 'react' /** * Props for FormControlLabel component (MUI-compatible) */ export interface FormControlLabelProps extends Omit, 'onChange'> { testId?: string /** The control element (Checkbox, Radio, Switch) */ control: React.ReactElement /** The label text or element */ label: React.ReactNode /** Whether the control is disabled */ disabled?: boolean /** Whether the label should appear after the control */ labelPlacement?: 'end' | 'start' | 'top' | 'bottom' /** Value for form submission */ value?: unknown /** MUI sx prop for styling compatibility */ sx?: Record } /** * FormControlLabel - A wrapper for form controls with labels (MUI-compatible) * * @example * ```tsx * } * label="Remember me" * /> * ``` */ export const FormControlLabel = forwardRef( ( { control, label, disabled = false, labelPlacement = 'end', testId, className = '', sx, ...props }, ref ) => { // Clone the control element to inject disabled prop if needed const controlElement = isValidElement(control) ? cloneElement(control, { ...(control.props as Record), disabled: disabled || (control.props as Record).disabled, } as Partial) : control const renderLabel = () => ( {label} ) return ( ) } ) FormControlLabel.displayName = 'FormControlLabel'