import { ChatFileCard } from "./ChatFileCard";
import { ChatCodeFilePreview } from "./ChatCodeFilePreview";
import type { ChatFile } from "@paperclipai/shared";

interface ChatFilePreviewProps {
  file: ChatFile;
  contentPath: string;
}

export function ChatFilePreview({ file, contentPath }: ChatFilePreviewProps) {
  if (file.category === "image") {
    return (
      <div className="flex flex-col gap-1">
        <a href={contentPath} target="_blank" rel="noreferrer" className="block w-fit">
          <img
            src={contentPath}
            alt={file.originalFilename}
            loading="lazy"
            className="max-h-[300px] rounded-lg object-contain"
          />
        </a>
        {/* Always show card below image for download button */}
        <ChatFileCard file={file} contentPath={contentPath} />
      </div>
    );
  }

  if (file.category === "code") {
    return <ChatCodeFilePreview file={file} contentPath={contentPath} />;
  }

  // For all non-image, non-code types (document, other): render the file card with download
  return <ChatFileCard file={file} contentPath={contentPath} />;
}
