"use client"

import * as React from "react"
import { Eye } from "lucide-react"

import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/shared/components/ui/dialog"
import { Button } from "@/shared/components/ui/button"
import { FilePreview } from "./file-preview"
import type { FileAttachment } from "../types"

interface FilePreviewDialogProps {
  file: FileAttachment
  trigger?: React.ReactNode
  triggerLabel?: string
  triggerVariant?: "default" | "outline" | "secondary" | "ghost" | "destructive"
  triggerSize?: "default" | "sm" | "lg" | "icon"
}

export function FilePreviewDialog({
  file,
  trigger,
  triggerLabel = "Preview",
  triggerVariant = "outline",
  triggerSize = "sm",
}: FilePreviewDialogProps) {
  return (
    <Dialog>
      <DialogTrigger asChild>
        {trigger ?? (
          <Button type="button" variant={triggerVariant} size={triggerSize}>
            <Eye className={triggerLabel ? "mr-2 h-4 w-4" : "h-4 w-4"} />
            {triggerLabel ? <span>{triggerLabel}</span> : <span className="sr-only">Preview</span>}
          </Button>
        )}
      </DialogTrigger>
      <DialogContent className="max-h-[90vh] max-w-5xl overflow-hidden">
        <DialogHeader>
          <DialogTitle className="truncate">{file.originalName}</DialogTitle>
          <DialogDescription>
            File preview · {file.mimeType}
          </DialogDescription>
        </DialogHeader>
        <div className="max-h-[75vh] overflow-auto">
          <FilePreview file={file} />
        </div>
      </DialogContent>
    </Dialog>
  )
}
