"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, DialogDescription, 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 [partsPanelLoading, setPartsPanelLoading] = useState(true) const [partsPanelVisible, setPartsPanelVisible] = useState(true) const isMobile = useIsMobile() // Reset error state when manual URL changes useEffect(() => { if (isOpen) { setPdfError(false) setIsLoading(true) setPartsPanelLoading(true) setPartsPanelVisible(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) } const showPartsPanelWithData = showPartsPanel && (partsPanelLoading || partsPanelVisible) const canToggleParts = partsPanelLoading || partsPanelVisible const partsToggleLabel = partsPanelLoading ? "Checking Parts..." : partsPanelVisible ? showPartsPanel ? "Hide Parts" : "Show Parts" : "Parts Unavailable" // 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.

) : (