import * as React from "react"
import { Slot } from "@radix-ui/react-slot"
import { cva, type VariantProps } from "class-variance-authority"

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

const imageVariants = cva(
  "inline-block overflow-hidden rounded-md transition-all",
  {
    variants: {
      variant: {
        default: "",
        rounded: "rounded-md",
        circle: "rounded-full",
        soft: "rounded-xl",
        square: "rounded-none",
      },
      size: {
        sm: "w-10 h-10",
        md: "w-20 h-20",
        lg: "w-40 h-40",
        full: "w-full h-full",

        rectSm: "w-[120px] h-[60px]",
        rectMd: "w-[180px] h-[90px]",
        rectLg: "w-[240px] h-[120px]",
      },
    },
    defaultVariants: {
      variant: "default",
      size: "md",
    },
  }
)

function Image({
  className,
  variant,
  size,
  asChild = false,
  alt,
  ...props
}: React.ImgHTMLAttributes<HTMLImageElement> &
  VariantProps<typeof imageVariants> & {
    asChild?: boolean
  }) {
  const Comp = asChild ? Slot : "img"

  return (
    <Comp
      data-slot="image"
      alt={alt}
      className={cn(imageVariants({ variant, size, className }))}
      {...props}
    />
  )
}

export { Image, imageVariants }
