import * as React from "react"
import * as RadioGroupPrimitive from "@radix-ui/react-radio-group"
import { Circle } from "lucide-react"

import { cn } from "@/lib/utils"

const RadioGroup = React.forwardRef<
  React.ElementRef<typeof RadioGroupPrimitive.Root>,
  React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root>
>(({ className, ...props }, ref) => {
  return (
    <RadioGroupPrimitive.Root
      className={cn("smx-grid smx-gap-2", className)}
      {...props}
      ref={ref}
    />
  )
})
RadioGroup.displayName = RadioGroupPrimitive.Root.displayName

const RadioGroupItem = React.forwardRef<
  React.ElementRef<typeof RadioGroupPrimitive.Item>,
  React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>
>(({ className, ...props }, ref) => {
  return (
    <RadioGroupPrimitive.Item
      ref={ref}
      className={cn(
        "smx-aspect-square smx-h-4 smx-w-4 smx-rounded-full smx-border smx-border-primary smx-text-primary smx-ring-offset-background focus:smx-outline-none focus-visible:smx-ring-2 focus-visible:smx-ring-ring focus-visible:smx-ring-offset-2 disabled:smx-cursor-not-allowed disabled:smx-opacity-50",
        className
      )}
      {...props}
    >
      <RadioGroupPrimitive.Indicator className="smx-flex smx-items-center smx-justify-center">
        <Circle className="smx-h-2.5 smx-w-2.5 smx-fill-current smx-text-current" />
      </RadioGroupPrimitive.Indicator>
    </RadioGroupPrimitive.Item>
  )
})
RadioGroupItem.displayName = RadioGroupPrimitive.Item.displayName

export { RadioGroup, RadioGroupItem }
