import * as React from 'react'
import * as AvatarPrimitive from '@radix-ui/react-avatar'
import tw from 'twin.macro'

const Avatar = React.forwardRef<
  React.ElementRef<typeof AvatarPrimitive.Root>,
  React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root>
>((props, ref) => (
  <AvatarPrimitive.Root
    ref={ref}
    tw="relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full"
    {...props}
  />
))
Avatar.displayName = AvatarPrimitive.Root.displayName

const AvatarImage = React.forwardRef<
  React.ElementRef<typeof AvatarPrimitive.Image>,
  React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>
>((props, ref) => (
  <AvatarPrimitive.Image
    ref={ref}
    css={[tw`h-full w-full aspect-[1/1]`]}
    {...props}
  />
))
AvatarImage.displayName = AvatarPrimitive.Image.displayName

const AvatarFallback = React.forwardRef<
  React.ElementRef<typeof AvatarPrimitive.Fallback>,
  React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>
>((props, ref) => (
  <AvatarPrimitive.Fallback
    ref={ref}
    tw="flex h-full w-full items-center justify-center rounded-full bg-slate-100 dark:bg-slate-700"
    {...props}
  />
))
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName

const _Avatar = Avatar

export { _Avatar as Root, AvatarImage as Image, AvatarFallback as Fallback }
