import * as React from "react";
import * as TooltipPrimitive from "@radix-ui/react-tooltip";

import { cn } from "../lib/utils";

const TooltipProvider = TooltipPrimitive.Provider;

const Tooltip = TooltipPrimitive.Root;

const TooltipTrigger = React.forwardRef<
  React.ElementRef<typeof TooltipPrimitive.Trigger>,
  React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Trigger>
>(({ className, ...prop }, ref) => (
  <TooltipPrimitive.Trigger
    ref={ref}
    className={cn(
      "tw-figr-font-secondary tw-figr-text-desktop-caption-accent",
      className
    )}
    {...prop}
  />
));

const TooltipContent = React.forwardRef<
  React.ElementRef<typeof TooltipPrimitive.Content>,
  React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
>(({ className, sideOffset = 4, ...props }, ref) => (
  <TooltipPrimitive.Content
    ref={ref}
    sideOffset={sideOffset}
    className={cn(
      "tw-figr-z-50 tw-figr-overflow-hidden tw-figr-rounded-m tw-figr-border tw-figr-border-neutral-200 tw-figr-bg-base-white tw-figr-px-sm tw-figr-py-xs tw-figr-font-secondary tw-figr-text-xs tw-figr-text-neutral-700 tw-figr-shadow-md tw-figr-animate-in tw-figr-fade-in-0 tw-figr-zoom-in-95 data-[state=closed]:tw-figr-animate-out data-[state=closed]:tw-figr-fade-out-0 data-[state=closed]:tw-figr-zoom-out-95 data-[side=bottom]:tw-figr-slide-in-from-top-2 data-[side=left]:tw-figr-slide-in-from-right-2 data-[side=right]:tw-figr-slide-in-from-left-2 data-[side=top]:tw-figr-slide-in-from-bottom-2",
      className
    )}
    {...props}
  />
));
TooltipContent.displayName = TooltipPrimitive.Content.displayName;

export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
