'use client';

import React from 'react';
import { Button } from 'antd';
import { ArrowLeft, Download, ExternalLink } from 'lucide-react';
import styles from './PrintRouteShell.module.scss';

export type PrintRouteShellProps = {
    title?: string;
    onBack: () => void;
    onDownload?: () => void;
    onOpenInNewTab?: () => void;
    downloadDisabled?: boolean;
    children: React.ReactNode;
};

/**
 * Shell mínimo para rotas `/print` — toolbar + área do viewer, sem chrome ERP.
 */
export function PrintRouteShell({
    title,
    onBack,
    onDownload,
    onOpenInNewTab,
    downloadDisabled,
    children,
}: PrintRouteShellProps) {
    return (
        <div className={styles.shell} data-testid="print-route-shell">
            <header className={styles.toolbar}>
                <div className={styles.toolbarLeft}>
                    <Button
                        icon={<ArrowLeft size={16} />}
                        data-testid="print-route-voltar"
                        onClick={onBack}
                    >
                        Voltar
                    </Button>
                    {title ? <p className={styles.title}>{title}</p> : null}
                </div>
                <div className={styles.toolbarRight}>
                    {onOpenInNewTab ? (
                        <Button
                            icon={<ExternalLink size={16} />}
                            data-testid="print-route-abrir"
                            disabled={downloadDisabled}
                            onClick={onOpenInNewTab}
                        >
                            Abrir em nova aba
                        </Button>
                    ) : null}
                    {onDownload ? (
                        <Button
                            type="primary"
                            icon={<Download size={16} />}
                            data-testid="print-route-baixar"
                            disabled={downloadDisabled}
                            onClick={onDownload}
                        >
                            Baixar PDF
                        </Button>
                    ) : null}
                </div>
            </header>
            <div className={styles.viewer}>{children}</div>
        </div>
    );
}
