import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/**
 * PDF Panel - Embedded sidebar panel for viewing/uploading files
 * Used by HazoDataForm when file_panel_display_mode='sidebar'
 */
import { useState, useEffect } from 'react';
import { LuMaximize2, LuX } from 'react-icons/lu';
import { cn } from '../../utils/cn.js';
import { optional_import } from '../../utils/optional_import.js';
export function PdfPanel({ field_label, file_items, file_access_provider, on_upload, on_file_delete, on_close, on_pop_out, viewer_props, }) {
    // Dynamic import of PdfViewer from hazo_pdf (optional peer dep)
    const [PdfViewerComponent, set_pdf_viewer] = useState(null);
    const [load_error, set_load_error] = useState(false);
    useEffect(() => {
        let cancelled = false;
        optional_import('hazo_pdf')
            .then((mod) => {
            if (cancelled)
                return;
            if (mod.PdfViewer) {
                set_pdf_viewer(() => mod.PdfViewer);
            }
            else {
                set_load_error(true);
            }
        })
            .catch(() => {
            if (!cancelled)
                set_load_error(true);
        });
        return () => { cancelled = true; };
    }, []);
    return (_jsxs("div", { className: cn('cls_pdf_panel', 'h-full flex flex-col border rounded-md bg-background'), children: [_jsxs("div", { className: "flex items-center justify-between px-4 py-2 border-b bg-muted/50 shrink-0", children: [_jsx("span", { className: "text-sm font-medium truncate flex-1 mr-2", children: field_label || 'Files' }), _jsxs("div", { className: "flex items-center gap-1", children: [on_pop_out && (_jsx("button", { type: "button", onClick: on_pop_out, className: "h-7 w-7 inline-flex items-center justify-center rounded-sm text-muted-foreground hover:text-foreground hover:bg-muted transition-colors", title: "Open in full screen", "aria-label": "Maximize", children: _jsx(LuMaximize2, { className: "h-4 w-4" }) })), _jsx("button", { type: "button", onClick: on_close, className: "h-7 w-7 inline-flex items-center justify-center rounded-sm text-muted-foreground hover:text-foreground hover:bg-muted transition-colors", title: "Close panel", "aria-label": "Close", children: _jsx(LuX, { className: "h-4 w-4" }) })] })] }), _jsxs("div", { className: "flex-1 min-h-0", children: [load_error && (_jsx("div", { className: "flex items-center justify-center h-full text-sm text-muted-foreground p-4", children: "hazo_pdf is not installed. Install it to use the PDF panel." })), !load_error && !PdfViewerComponent && (_jsx("div", { className: "flex items-center justify-center h-full text-sm text-muted-foreground", children: "Loading viewer..." })), PdfViewerComponent && (_jsx(PdfViewerComponent, { files: file_items, file_manager: file_access_provider, on_upload: on_upload, on_file_delete: on_file_delete, toolbar_enabled: true, show_save_button: false, direct_upload: true, className: "h-full", ...(viewer_props || {}) }))] })] }));
}
//# sourceMappingURL=pdf_panel.js.map