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_tabela_cotas_teoboat():
    caminho = '/home/magdalena/eee/grupos/grupo-9/Tabela_de_Cotas_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.5,
        leading=11,
        textColor=colors.HexColor('#222222')
    )
    cell_head = ParagraphStyle(
        'CellH',
        parent=styles['Normal'],
        fontSize=8.5,
        leading=11,
        fontName='Helvetica-Bold',
        textColor=colors.white
    )

    story = []
    story.append(Paragraph("TABELA DE COTAS (OFFSETS) &bull; TEOBOAT (GRUPO 9)", title_style))
    story.append(Paragraph("Miniembarcação Infantil a Vela (1,90 m) &bull; Projetistas: Karina Menezes, Monique, Carolina Sapucaia, Danrley e Sidnei &bull; EEE / BRANA", subtitle_style))
    story.append(Spacer(1, 4))

    story.append(Paragraph("1. Dados Principais e Convenções Geométricas", h2_style))
    t_info = [
        [Paragraph(h, cell_head) for h in ["Parâmetro", "Valor", "Convenção Técnica"]],
        [Paragraph("Comprimento Total (LOA)", cell_style), Paragraph("1.900,0 mm (1,90 m)", cell_style), Paragraph("Origem X = 0 no espelho de popa (Baliza 1)", cell_style)],
        [Paragraph("Boca Máxima (BOA)", cell_style), Paragraph("980,0 mm (0,98 m)", cell_style), Paragraph("Meia-boca máxima de 490 mm na Baliza 5 (meia-nau)", cell_style)],
        [Paragraph("Pontal a Meia-Nau (D)", cell_style), Paragraph("360,0 mm (0,36 m)", cell_style), Paragraph("Altura do fundo até a borda na Baliza 5", cell_style)],
        [Paragraph("Linha de Base (BL)", cell_style), Paragraph("Z = 0,0 mm", cell_style), Paragraph("Ponto mais baixo do fundo na Baliza 5", cell_style)],
        [Paragraph("Método Construtivo", cell_style), Paragraph("Costure e Cole (Stitch-and-Glue)", cell_style), Paragraph("Compensado naval 4 mm com quina viva (Hard Chine)", cell_style)]
    ]
    t_tab_info = Table(t_info, colWidths=[140, 110, 270])
    t_tab_info.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_info)
    story.append(Spacer(1, 6))

    story.append(Paragraph("2. Tabela de Cotas Oficial Brana (7 Colunas em mm)", h2_style))
    story.append(Paragraph("Meias-bocas medidas da linha de centro; alturas medidas acima da linha de base (Z = 0 mm no ponto mais baixo da quilha na B5):", body_style))

    t_cotas = [
        [Paragraph(h, cell_head) for h in ["Baliza", "X (mm)", "MB Borda (sheer_hb)", "MB Quina (chine_hb)", "Alt. Borda (sheer_ht)", "Alt. Quina (chine_ht)", "Alt. Quilha (keel_ht)"]],
        [Paragraph("B1 (Popa)", cell_style), Paragraph("0,0", cell_style), Paragraph("360,0", cell_style), Paragraph("320,0", cell_style), Paragraph("400,0", cell_style), Paragraph("180,0", cell_style), Paragraph("80,0", cell_style)],
        [Paragraph("B2", cell_style), Paragraph("237,5", cell_style), Paragraph("430,0", cell_style), Paragraph("390,0", cell_style), Paragraph("380,0", cell_style), Paragraph("150,0", cell_style), Paragraph("40,0", cell_style)],
        [Paragraph("B3", cell_style), Paragraph("475,0", cell_style), Paragraph("470,0", cell_style), Paragraph("435,0", cell_style), Paragraph("365,0", cell_style), Paragraph("130,0", cell_style), Paragraph("15,0", cell_style)],
        [Paragraph("B4", cell_style), Paragraph("712,5", cell_style), Paragraph("485,0", cell_style), Paragraph("455,0", cell_style), Paragraph("360,0", cell_style), Paragraph("120,0", cell_style), Paragraph("0,0", cell_style)],
        [Paragraph("B5 (Meio)", cell_style), Paragraph("950,0", cell_style), Paragraph("490,0", cell_style), Paragraph("460,0", cell_style), Paragraph("360,0", cell_style), Paragraph("120,0", cell_style), Paragraph("0,0", cell_style)],
        [Paragraph("B6", cell_style), Paragraph("1.187,5", cell_style), Paragraph("480,0", cell_style), Paragraph("450,0", cell_style), Paragraph("365,0", cell_style), Paragraph("125,0", cell_style), Paragraph("5,0", cell_style)],
        [Paragraph("B7", cell_style), Paragraph("1.425,0", cell_style), Paragraph("445,0", cell_style), Paragraph("410,0", cell_style), Paragraph("380,0", cell_style), Paragraph("140,0", cell_style), Paragraph("30,0", cell_style)],
        [Paragraph("B8", cell_style), Paragraph("1.662,5", cell_style), Paragraph("350,0", cell_style), Paragraph("310,0", cell_style), Paragraph("415,0", cell_style), Paragraph("180,0", cell_style), Paragraph("95,0", cell_style)],
        [Paragraph("B9 (Proa)", cell_style), Paragraph("1.900,0", cell_style), Paragraph("0,0", cell_style), Paragraph("0,0", cell_style), Paragraph("460,0", cell_style), Paragraph("260,0", cell_style), Paragraph("220,0", cell_style)]
    ]
    t_tab_cotas = Table(t_cotas, colWidths=[60, 60, 80, 80, 80, 80, 80])
    t_tab_cotas.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_cotas)
    story.append(Spacer(1, 6))

    story.append(Paragraph("3. Detalhamento das 8 Colunas (Incluindo Meia-Boca do Fundo Chato)", h2_style))
    t_cotas8 = [
        [Paragraph(h, cell_head) for h in ["Baliza", "X (mm)", "Alt. Quilha", "Alt. Quina", "Alt. Borda", "MB Fundo", "MB Quina", "MB Borda"]],
        [Paragraph("B1 (Popa)", cell_style), Paragraph("0,0", cell_style), Paragraph("80,0", cell_style), Paragraph("180,0", cell_style), Paragraph("400,0", cell_style), Paragraph("180,0", cell_style), Paragraph("320,0", cell_style), Paragraph("360,0", cell_style)],
        [Paragraph("B2", cell_style), Paragraph("237,5", cell_style), Paragraph("40,0", cell_style), Paragraph("150,0", cell_style), Paragraph("380,0", cell_style), Paragraph("220,0", cell_style), Paragraph("390,0", cell_style), Paragraph("430,0", cell_style)],
        [Paragraph("B3", cell_style), Paragraph("475,0", cell_style), Paragraph("15,0", cell_style), Paragraph("130,0", cell_style), Paragraph("365,0", cell_style), Paragraph("250,0", cell_style), Paragraph("435,0", cell_style), Paragraph("470,0", cell_style)],
        [Paragraph("B4", cell_style), Paragraph("712,5", cell_style), Paragraph("0,0", cell_style), Paragraph("120,0", cell_style), Paragraph("360,0", cell_style), Paragraph("265,0", cell_style), Paragraph("455,0", cell_style), Paragraph("485,0", cell_style)],
        [Paragraph("B5 (Meio)", cell_style), Paragraph("950,0", cell_style), Paragraph("0,0", cell_style), Paragraph("120,0", cell_style), Paragraph("360,0", cell_style), Paragraph("270,0", cell_style), Paragraph("460,0", cell_style), Paragraph("490,0", cell_style)],
        [Paragraph("B6", cell_style), Paragraph("1.187,5", cell_style), Paragraph("5,0", cell_style), Paragraph("125,0", cell_style), Paragraph("365,0", cell_style), Paragraph("260,0", cell_style), Paragraph("450,0", cell_style), Paragraph("480,0", cell_style)],
        [Paragraph("B7", cell_style), Paragraph("1.425,0", cell_style), Paragraph("30,0", cell_style), Paragraph("140,0", cell_style), Paragraph("380,0", cell_style), Paragraph("230,0", cell_style), Paragraph("410,0", cell_style), Paragraph("445,0", cell_style)],
        [Paragraph("B8", cell_style), Paragraph("1.662,5", cell_style), Paragraph("95,0", cell_style), Paragraph("180,0", cell_style), Paragraph("415,0", cell_style), Paragraph("150,0", cell_style), Paragraph("310,0", cell_style), Paragraph("350,0", cell_style)],
        [Paragraph("B9 (Proa)", cell_style), Paragraph("1.900,0", cell_style), Paragraph("220,0", cell_style), Paragraph("260,0", cell_style), Paragraph("460,0", cell_style), Paragraph("0,0", cell_style), Paragraph("0,0", cell_style), Paragraph("0,0", cell_style)]
    ]
    t_tab_cotas8 = Table(t_cotas8, colWidths=[55, 55, 65, 65, 65, 65, 75, 75])
    t_tab_cotas8.setStyle(TableStyle([
        ('BACKGROUND', (0,0), (-1,0), colors.HexColor('#1b4b72')),
        ('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_cotas8)
    story.append(Spacer(1, 6))

    story.append(Paragraph("4. Notas Construtivas para Traçado e Corte", h2_style))
    notas = [
        "&bull; <b>Espaçamento entre Balizas:</b> Exatos 237,5 mm entre estações consecutivas (1.900 mm / 8 vãos = 237,5 mm).",
        "&bull; <b>Aresta Viva (Chine):</b> A baliza é definida por dois segmentos retos (fundo e costado), permitindo o desenvolvimento direto em painéis planos de compensado naval de 4 mm pelo método Costure e Cole.",
        "&bull; <b>Rocker do Fundo:</b> O fundo possui curvatura suave (rocker), atingindo a cota zero nas balizas 4 e 5, subindo 80 mm na popa e 220 mm na proa para garantir saída limpa e corte dócil de marolas."
    ]
    for n in notas:
        story.append(Paragraph(n, body_style))

    doc.build(story)
    print("PDF Tabela de Cotas Teoboat gerado com sucesso!")

gerar_pdf_tabela_cotas_teoboat()
