import { Button } from '@/Components/ui/button';
import { Document } from '@/types';
import { Eye } from 'lucide-react';

/**
 * Open the document file in a new tab. The file is streamed by the backend,
 * which checks the authorization on every request.
 */
export default function DocumentViewAction({
    document: documentToView,
}: {
    document: Document;
}) {
    return (
        <a
            href={route('documents.file', { document: documentToView.id })}
            target="_blank"
            rel="noreferrer"
            title="Visualizza"
            onClick={(e) => e.stopPropagation()}
        >
            <Button variant="ghost" className="h-8 w-8 p-0">
                <Eye />
            </Button>
        </a>
    );
}
