from reportlab.lib.pagesizes import A4
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib import colors

def gerar_pdf_similares_teoboat():
    caminho = '/home/magdalena/eee/grupos/grupo-9/Estudo_de_Similares_Teoboat_Grupo_9.pdf'
    doc = SimpleDocTemplate(caminho, pagesize=A4, rightMargin=36, leftMargin=36, topMargin=36, bottomMargin=36)
    styles = getSampleStyleSheet()

    title_style = ParagraphStyle(
        'DocTitle',
        parent=styles['Heading1'],
        fontSize=16,
        leading=20,
        textColor=colors.HexColor('#0f2d4a'),
        spaceAfter=4
    )
    subtitle_style = ParagraphStyle(
        'DocSub',
        parent=styles['Normal'],
        fontSize=9.5,
        leading=13,
        textColor=colors.HexColor('#555555'),
        spaceAfter=12
    )
    h2_style = ParagraphStyle(
        'H2',
        parent=styles['Heading2'],
        fontSize=11.5,
        leading=15,
        textColor=colors.HexColor('#1b4b72'),
        spaceBefore=8,
        spaceAfter=4
    )
    body_style = ParagraphStyle(
        'Body',
        parent=styles['Normal'],
        fontSize=9,
        leading=13,
        textColor=colors.HexColor('#222222'),
        spaceAfter=5
    )
    cell_style = ParagraphStyle(
        'Cell',
        parent=styles['Normal'],
        fontSize=8,
        leading=10.5,
        textColor=colors.HexColor('#222222')
    )
    cell_head = ParagraphStyle(
        'CellH',
        parent=styles['Normal'],
        fontSize=8,
        leading=10.5,
        fontName='Helvetica-Bold',
        textColor=colors.white
    )

    story = []
    story.append(Paragraph("ESTUDO DE EMBARCAÇÕES SIMILARES &bull; TEOBOAT (GRUPO 9)", title_style))
    story.append(Paragraph("Análise Paramétrica de Mini-Dinghy, Trainers e Veleiros Infantis &bull; EEE / BRANA Projetos Navais", subtitle_style))
    story.append(Spacer(1, 4))

    story.append(Paragraph("1. Objetivo e Critérios de Similaridade", h2_style))
    story.append(Paragraph("O presente estudo levanta embarcações consagradas de porte ultra-compacto (LOA entre 1,90 m e 2,50 m) para ancorar as decisões de projeto do <b>Teoboat</b>: dimensões principais, deslocamento leve, estabilidade inicial, plano vélico seguro e insubmersibilidade.", body_style))
    story.append(Spacer(1, 4))

    story.append(Paragraph("2. Tabela Paramétrica Comparativa de Similares", h2_style))
    t_data = [
        [Paragraph(h, cell_head) for h in ["Embarcação", "LOA (m)", "BOA (m)", "Calado (m)", "Peso Casco", "Área Vélica", "Material / Conceito"]],
        [Paragraph("<b>Teoboat (Grupo 9)</b>", cell_style), Paragraph("1,90", cell_style), Paragraph("0,98", cell_style), Paragraph("0,14 / 0,25", cell_style), Paragraph("15 kg (20 kg pronto)", cell_style), Paragraph("2,00 m²", cell_style), Paragraph("Compensado naval 4 mm / Biquilha / Colar", cell_style)],
        [Paragraph("<b>Cockleshell Pram 7'</b>", cell_style), Paragraph("2,13", cell_style), Paragraph("1,05", cell_style), Paragraph("0,11 / 0,60", cell_style), Paragraph("20 kg", cell_style), Paragraph("2,50 m²", cell_style), Paragraph("Compensado naval 4 mm / Stitch-and-glue", cell_style)],
        [Paragraph("<b>Optimist</b>", cell_style), Paragraph("2,31", cell_style), Paragraph("1,13", cell_style), Paragraph("0,13 / 0,84", cell_style), Paragraph("35 kg", cell_style), Paragraph("3,30 m²", cell_style), Paragraph("Fibra de vidro / Bolina central / Sprit-sail", cell_style)],
        [Paragraph("<b>Walker Bay 8 RID</b>", cell_style), Paragraph("2,51", cell_style), Paragraph("1,32", cell_style), Paragraph("0,15 / 0,65", cell_style), Paragraph("32 kg + tubo", cell_style), Paragraph("3,60 m²", cell_style), Paragraph("Casco rígido + Colar inflável perimetral", cell_style)],
        [Paragraph("<b>Naples Sabot / El Toro</b>", cell_style), Paragraph("2,44", cell_style), Paragraph("1,14", cell_style), Paragraph("0,12 / 0,75", cell_style), Paragraph("38 kg", cell_style), Paragraph("3,50 m²", cell_style), Paragraph("Compensado naval ou PRFV / Catboat pram", cell_style)],
        [Paragraph("<b>PDRacer (Puddle Duck)</b>", cell_style), Paragraph("2,44", cell_style), Paragraph("1,22", cell_style), Paragraph("0,10 / 0,70", cell_style), Paragraph("25 kg", cell_style), Paragraph("3,00 m²", cell_style), Paragraph("Compensado naval / Caixa aberta / Fundo chato", cell_style)]
    ]
    t_tab = Table(t_data, colWidths=[110, 45, 45, 60, 80, 65, 125])
    t_tab.setStyle(TableStyle([
        ('BACKGROUND', (0,0), (-1,0), colors.HexColor('#0f2d4a')),
        ('GRID', (0,0), (-1,-1), 0.5, colors.HexColor('#cccccc')),
        ('ROWBACKGROUNDS', (0,1), (-1,-1), [colors.white, colors.HexColor('#f8f9fa')]),
        ('TOPPADDING', (0,0), (-1,-1), 4),
        ('BOTTOMPADDING', (0,0), (-1,-1), 4),
    ]))
    story.append(t_tab)
    story.append(Spacer(1, 6))

    story.append(Paragraph("3. Análise dos Similares e Lições para o Teoboat", h2_style))
    notas = [
        "&bull; <b>Walker Bay 8 com Colar RID (Referência em Estabilidade Passiva):</b> O Walker Bay prova que a adição de um colar perimetral em embarcação rígida pequena multiplica a estabilidade de reserva e evita emborcamento acidental. O Teoboat adota essa mesma lógica com seu colar de 100-120 mm em espuma de célula fechada.",
        "&bull; <b>Cockleshell Pram 7' (Referência de Leveza Construtiva):</b> Mostra a viabilidade de construir um barco de ~20 kg com compensado naval de 4 mm pelo método Costure e Cole (Stitch-and-Glue), facilmente transportável no teto do carro por apenas um adulto.",
        "&bull; <b>Diferenciais do Teoboat frente ao Optimist:</b> O Optimist pesa 35 kg, tem retranca rígida perigosa e exige bolina central que divide o cockpit. O Teoboat reduz o comprimento para 1,90 m, o peso para 20 kg pronto, adota biquilhas (cockpit 100% livre) e vela sem retranca com área dócil de 2,00 m²."
    ]
    for n in notas:
        story.append(Paragraph(n, body_style))

    doc.build(story)
    print("PDF Estudo de Similares Teoboat gerado com sucesso!")

gerar_pdf_similares_teoboat()
