import styles from './Label.module.css'
import { forwardRef, type LabelHTMLAttributes, type ReactNode } from 'react'

interface LabelProps extends LabelHTMLAttributes<HTMLLabelElement> {
  required?: boolean
  children?: ReactNode
  className?: string
}

export const Label = forwardRef<HTMLLabelElement, LabelProps>(
  ({ required, children, className, ...rest }, ref) => {
    return (
      <label ref={ref} className={`${styles.label} ${className ?? ''}`} {...rest}>
        {children}
        {required && <span className={styles.asterisk}>*</span>}
      </label>
    )
  },
)
Label.displayName = 'Label'
