import React from 'react';
import * as TooltipPrimitive from '@radix-ui/react-tooltip';
import { cn } from './utils';

/**
 * CustomTooltipContent — Tooltip com portal e seta estilo sidebar/assistente.
 *
 * Substitui os componentes `SidebarTooltipContent` e `AssistantTooltipContent`
 * que eram definidos inline em `sidebar.tsx` e `xertica-assistant.tsx`.
 *
 * @example
 * ```tsx
 * import { Tooltip, TooltipTrigger } from '../ui/tooltip';
 * import { CustomTooltipContent } from '../shared/CustomTooltipContent';
 *
 * <Tooltip>
 *   <TooltipTrigger asChild><Button>Hover me</Button></TooltipTrigger>
 *   <CustomTooltipContent side="right">Minha dica</CustomTooltipContent>
 * </Tooltip>
 * ```
 */
export function CustomTooltipContent({
  className,
  sideOffset = 0,
  children,
  ...props
}: React.ComponentProps<typeof TooltipPrimitive.Content>) {
  return (
    <TooltipPrimitive.Portal>
      <TooltipPrimitive.Content
        data-slot="tooltip-content"
        sideOffset={sideOffset}
        className={cn(
          'bg-popover text-popover-foreground shadow-lg animate-in fade-in-0 zoom-in-95',
          'data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95',
          'data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2',
          'data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
          'z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance',
          className
        )}
        {...props}
      >
        {children}
        <TooltipPrimitive.Arrow className="fill-popover z-50 drop-shadow-sm" width={8} height={4} />
      </TooltipPrimitive.Content>
    </TooltipPrimitive.Portal>
  );
}
