import * as React from 'react'
import { cn } from '@/lib/utils'

/**
 * FieldLabel / FieldHint / FieldError — typography primitives для form fields.
 * Замена @nstart/ui (без логики, чистые atomic spans/divs).
 *
 * <p>Per handoff: label = text-body (13/400), hint/error = text-cell (12.5).
 */

export type FieldLabelProps = React.LabelHTMLAttributes<HTMLLabelElement> & {
  required?: boolean
}

export const FieldLabel = React.forwardRef<HTMLLabelElement, FieldLabelProps>(
  function FieldLabel({ className, required, children, ...props }, ref) {
    return (
      <label
        ref={ref}
        className={cn(
          'inline-flex items-baseline gap-0.5 text-body font-medium text-ink',
          className,
        )}
        {...props}
      >
        {children}
        {required && (
          <span aria-hidden="true" className="text-pink">
            *
          </span>
        )}
      </label>
    )
  },
)

export function FieldHint({ className, ...props }: React.HTMLAttributes<HTMLParagraphElement>) {
  return <p className={cn('text-cell text-mute', className)} {...props} />
}

export function FieldError({ className, ...props }: React.HTMLAttributes<HTMLParagraphElement>) {
  return (
    <p
      role="alert"
      className={cn('text-cell text-pink', className)}
      {...props}
    />
  )
}
