// https://ui.shadcn.com/docs/components/label

import * as LabelPrimitive from '@radix-ui/react-label'
import { Slot } from '@radix-ui/react-slot'
import { cva, type VariantProps } from 'class-variance-authority'
import type * as React from 'react'
import { cn } from '../../utils/cn'
import { typographyVariants } from '../Typography'

const labelVariants = cva('flex gap-1 items-center', {
  variants: {
    size: {
      default: typographyVariants({
        variant: 'body-semi-s',
        color: 'muted',
      }),
      sm: typographyVariants({ variant: 'body-semi-xs', color: 'muted' }),
      xs: typographyVariants({ variant: 'body-semi-xs', color: 'muted' }),
    },
  },
  defaultVariants: {
    size: 'default',
  },
})

type LabelProps = React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
  VariantProps<typeof labelVariants> & {
    asChild?: boolean
    ref?: React.Ref<React.ElementRef<typeof LabelPrimitive.Root>>
  }

const Label = ({ className, size, asChild, ref, ...props }: LabelProps) => {
  const Comp = asChild ? Slot : LabelPrimitive.Root
  return (
    <Comp
      ref={ref}
      className={cn(labelVariants({ size }), className)}
      {...props}
    />
  )
}
Label.displayName = LabelPrimitive.Root.displayName

export { Label, labelVariants }
