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

caminho = '/home/magdalena/eee/grupos/grupo-9/Estudo_Velico_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("ESTUDO VÉLICO CONGELADO &bull; TEOBOAT (GRUPO 9)", title_style))
story.append(Paragraph("Área Vélica Fixada em 2,00 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 do Casco e Geometria da Linha d'Água", h2_style))
t1_data = [
    [Paragraph(h, cell_head) for h in ["Parâmetro", "Símbolo", "Valor de Projeto", "Função Naval / Justificativa"]],
    [Paragraph("Comprimento Total", cell_style), Paragraph("LOA", cell_style), Paragraph("1,900 m", cell_style), Paragraph("Porte compacto para transporte em rack de teto", cell_style)],
    [Paragraph("Linha d'Água", cell_style), Paragraph("LWL", cell_style), Paragraph("1,750 m", cell_style), Paragraph("Deslize progressivo e entrada suave", cell_style)],
    [Paragraph("Boca Máxima", cell_style), Paragraph("BOA", cell_style), Paragraph("0,980 m", cell_style), Paragraph("Relação L/B = 1,94 (altíssima estabilidade inicial)", cell_style)],
    [Paragraph("Pontal a Meio-Nau", cell_style), Paragraph("D", cell_style), Paragraph("0,360 m", cell_style), Paragraph("Borda livre seca e segura para crianças", cell_style)],
    [Paragraph("Deslocamento Total", cell_style), Paragraph("Δ", cell_style), Paragraph("45 a 85 kg", cell_style), Paragraph("Casco (15kg) + Rig (5kg) + Criança (20 a 55kg)", cell_style)]
]
t1 = Table(t1_data, colWidths=[120, 50, 80, 270])
t1.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(t1)
story.append(Spacer(1, 6))

story.append(Paragraph("2. Plano Vélico e Análise do SDR (Sail Area / Displacement Ratio)", h2_style))
story.append(Paragraph("A área vélica foi fixada em <b>2,00 m² (21,5 ft²)</b>, em vela pop-up circular de proa sem retranca rígida. Avaliação da razão SDR por faixa etária/peso:", body_style))
t2_data = [
    [Paragraph(h, cell_head) for h in ["Condição / Tripulante", "Peso Criança", "Deslocamento (m)", "Área Vélica", "SDR (SA/D)", "Comportamento"]],
    [Paragraph("Criança Iniciante (4 anos)", cell_style), Paragraph("20 kg", cell_style), Paragraph("45 kg (99 lb)", cell_style), Paragraph("2,00 m²", cell_style), Paragraph("16,1", cell_style), Paragraph("Dócil e ágil para ventos fracos", cell_style)],
    [Paragraph("Criança Média (6 anos)", cell_style), Paragraph("30 kg", cell_style), Paragraph("55 kg (121 lb)", cell_style), Paragraph("2,00 m²", cell_style), Paragraph("14,1", cell_style), Paragraph("Ponto ótimo de cruzeiro leve", cell_style)],
    [Paragraph("Condição Nominal (7 anos)", cell_style), Paragraph("45 kg", cell_style), Paragraph("75 kg (165 lb)", cell_style), Paragraph("2,00 m²", cell_style), Paragraph("11,4", cell_style), Paragraph("Estável e progressivo", cell_style)],
    [Paragraph("Criança Limite (8 anos)", cell_style), Paragraph("55 kg", cell_style), Paragraph("85 kg (187 lb)", cell_style), Paragraph("2,00 m²", cell_style), Paragraph("10,5", cell_style), Paragraph("Segurança total sem trancos", cell_style)]
]
t2 = Table(t2_data, colWidths=[125, 70, 85, 65, 65, 110])
t2.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(t2)
story.append(Spacer(1, 6))

story.append(Paragraph("3. Equilíbrio de Centros e Ângulo de Dellenbaugh (Brisa de 15 a 17 nós)", h2_style))
t3_data = [
    [Paragraph(h, cell_head) for h in ["Condição de Teste", "Deslocamento", "HA (Braço)", "GM Inicial", "Dellenbaugh", "Diagnóstico de Estabilidade"]],
    [Paragraph("Iniciante (4 anos)", cell_style), Paragraph("45 kg", cell_style), Paragraph("0,95 m", cell_style), Paragraph("1,15 m", cell_style), Paragraph("10,2°", cell_style), Paragraph("Super Stiff (hiper-estável)", cell_style)],
    [Paragraph("Média (6 anos)", cell_style), Paragraph("55 kg", cell_style), Paragraph("0,95 m", cell_style), Paragraph("1,07 m", cell_style), Paragraph("9,0°", cell_style), Paragraph("Navegação praticamente plana", cell_style)],
    [Paragraph("Nominal de Projeto", cell_style), Paragraph("75 kg", cell_style), Paragraph("0,95 m", cell_style), Paragraph("1,02 m", cell_style), Paragraph("6,9°", cell_style), Paragraph("Plataforma firme, sem medo de virar", cell_style)],
    [Paragraph("Limite (55 kg)", cell_style), Paragraph("85 kg", cell_style), Paragraph("0,95 m", cell_style), Paragraph("0,98 m", cell_style), Paragraph("6,4°", cell_style), Paragraph("Estabilidade de forma maciça", cell_style)]
]
t3 = Table(t3_data, colWidths=[110, 70, 65, 65, 70, 140])
t3.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(t3)
story.append(Spacer(1, 6))

story.append(Paragraph("4. Conclusões e Benefícios da Fixação em 2,00 m²", h2_style))
notas = [
    "&bull; <b>Esforço Físico Adequado:</b> Com 2,00 m², a força máxima de tração na escota fica entre 3 e 5 kgf, permitindo que a criança segure o cabo diretamente na mão sem fadiga e alivie a vela instantaneamente em caso de rajada.",
    "&bull; <b>Prevenção de Pitchpoling:</b> O centro de esforço contido elimina o afundamento da proa curta em ventos de popa, mantendo o trim do barco perfeitamente nivelado.",
    "&bull; <b>Estabilidade Pedagógica:</b> O adernamento restrito a 6,4° – 10,2° consolida a proposta da 'bicicleta de rodinhas náutica', eliminando o medo de emborcamento e acelerando o aprendizado da orça, arribada e governo."
]
for n in notas:
    story.append(Paragraph(n, body_style))

doc.build(story)
print("Sucesso!")
