'use client' import { useState, useEffect } from 'react' import { X, Download, ExternalLink, AlertCircle, ShoppingCart } from 'lucide-react' import { Button } from '@/components/ui/button' import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogClose, } from '@/components/ui/dialog' import { Sheet, SheetContent, SheetHeader, SheetTitle, } from '@/components/ui/sheet' import { PartsPanel } from '@/components/parts-panel' import { useIsMobile } from '@/hooks/use-mobile' interface ManualViewerProps { manualUrl: string filename: string isOpen: boolean onClose: () => void } export function ManualViewer({ manualUrl, filename, isOpen, onClose }: ManualViewerProps) { const [pdfError, setPdfError] = useState(false) const [isLoading, setIsLoading] = useState(true) const [showPartsPanel, setShowPartsPanel] = useState(true) const isMobile = useIsMobile() // Reset error state when manual URL changes useEffect(() => { if (isOpen) { setPdfError(false) setIsLoading(true) } }, [manualUrl, isOpen]) // The URL is already properly encoded in getManualUrl function // Just use it as-is for the iframe src const encodedUrl = manualUrl const handleIframeLoad = () => { setIsLoading(false) } const handleIframeError = () => { setIsLoading(false) setPdfError(true) } // Mobile layout - use Sheet if (isMobile) { return (
{filename.replace(/\.pdf$/i, '')}
{isLoading && !pdfError && (

Loading PDF...

)} {pdfError ? (

Unable to Load PDF

The PDF file could not be loaded. This may be due to file corruption or an encoding issue.

) : (