import { cn } from "@/lib/utils";
import { Button } from "@/ui";
import { useSortable } from "@dnd-kit/sortable";
import { GripVerticalIcon } from "lucide-react";

export interface DataTableRowDragHandleCellProps {
  rowId: string;
  className?: string;
}

export const DataTableRowDragHandleCell = ({
  rowId,
  className,
}: DataTableRowDragHandleCellProps) => {
  const { attributes, listeners, isDragging } = useSortable({
    id: rowId,
  });

  return (
    <Button
      onClick={(event) => {
        event.preventDefault();
        return;
      }}
      size='icon'
      variant='link'
      className={cn(
        isDragging ? "cursor-grabbing" : "cursor-grab",
        "w-4 h-4 mt-2 text-ring hover:text-muted-foreground",
        className
      )}
      {...attributes}
      {...listeners}
    >
      <GripVerticalIcon className='w-4 h-4' />
      <span className='sr-only'>Mover fila</span>
    </Button>
  );
};
