'use client';

import { useRouter } from 'next/navigation';
import {
  Download,
  Eye,
  MoreVertical,
  PlayCircle,
  RotateCcw,
  Ticket,
  Trash2,
} from 'lucide-react';

import { Button } from '@/components/ui/button';
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuSeparator,
  DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import type { UploadListItem } from '@/types';

interface UploadActionsMenuProps {
  upload: UploadListItem;
  onViewVideo: (upload: UploadListItem) => void;
}

export function UploadActionsMenu({
  upload,
  onViewVideo,
}: UploadActionsMenuProps) {
  const router = useRouter();

  return (
    <DropdownMenu>
      <DropdownMenuTrigger asChild>
        <Button
          type="button"
          variant="ghost"
          size="icon"
          className="size-8"
          onClick={(event) => event.stopPropagation()}
        >
          <MoreVertical className="size-4" />
          <span className="sr-only">Open actions</span>
        </Button>
      </DropdownMenuTrigger>
      <DropdownMenuContent align="end">
        {upload.raw_video_url ? (
          <DropdownMenuItem
            onClick={(event) => {
              event.stopPropagation();
              onViewVideo(upload);
            }}
          >
            <PlayCircle className="size-4" />
            View Video
          </DropdownMenuItem>
        ) : null}
        <DropdownMenuItem>
          <Eye /> View Details
        </DropdownMenuItem>
        <DropdownMenuItem>
          <RotateCcw /> Retry Analysis
        </DropdownMenuItem>
        <DropdownMenuItem
          disabled={!upload.ticket_id}
          onClick={(event) => {
            event.stopPropagation();
            if (upload.ticket_id) {
              router.push(`/ticket/${upload.ticket_id}`);
            }
          }}
        >
          <Ticket /> Open Ticket
        </DropdownMenuItem>
        <DropdownMenuSeparator />
        <DropdownMenuItem variant="destructive">
          <Trash2 /> Delete
        </DropdownMenuItem>
      </DropdownMenuContent>
    </DropdownMenu>
  );
}
