<?php
require_once __DIR__ . '/vendor/autoload.php'; // dompdf
require_once __DIR__ . '/config/db.php';

use Dompdf\Dompdf;

$student = $_GET['name'] ?? 'Student';
$roll    = $_GET['roll'] ?? '';
$style   = $_GET['style'] ?? 'Visual';
$date    = date('d M Y');

/* -------- CONTENT MAP -------- */
$content = [

    'Visual' => [
        'desc' => 'Learns best using diagrams, visuals, charts, and videos.',
        'plan' => [
            'Use diagrams, flowcharts, and mind maps',
            'Watch concept videos before reading',
            'Highlight important points with colours',
            'Revise using visual notes',
            'Prefer presentations over long text'
        ],
        'do' => [
            'Use images and visual aids',
            'Explain concepts using charts',
            'Allow visual note-taking'
        ],
        'dont' => [
            'Avoid text-only explanations',
            'Do not rush without visuals',
            'Avoid dull, long lectures'
        ]
    ],

    'Practical' => [
        'desc' => 'Learns best by doing, practicing, and hands-on activities.',
        'plan' => [
            'Learn by solving problems',
            'Practice immediately after learning',
            'Use real-life examples',
            'Participate in labs and activities',
            'Learn from mistakes'
        ],
        'do' => [
            'Give hands-on tasks',
            'Encourage experimentation',
            'Allow trial-and-error learning'
        ],
        'dont' => [
            'Avoid theory-only teaching',
            'Do not restrict practice',
            'Avoid long passive sessions'
        ]
    ],

    'Logical' => [
        'desc' => 'Learns best through logic, structure, and step-by-step explanation.',
        'plan' => [
            'Study in a structured order',
            'Understand logic behind concepts',
            'Use formulas and rules',
            'Break problems into steps',
            'Revise using concept maps'
        ],
        'do' => [
            'Explain step-by-step',
            'Provide reasoning',
            'Use structured material'
        ],
        'dont' => [
            'Avoid random explanations',
            'Do not skip steps',
            'Avoid unclear instructions'
        ]
    ],

    'Reflective' => [
        'desc' => 'Learns best by thinking deeply and reflecting quietly.',
        'plan' => [
            'Study alone in quiet environment',
            'Think before answering',
            'Write personal notes',
            'Revise by recalling',
            'Maintain a learning journal'
        ],
        'do' => [
            'Give thinking time',
            'Encourage self-reflection',
            'Allow independent study'
        ],
        'dont' => [
            'Avoid forcing instant answers',
            'Avoid constant group pressure',
            'Avoid interruptions'
        ]
    ]
];

$data = $content[$style] ?? $content['Visual'];

/* -------- HTML DESIGN -------- */
$html = "
<html>
<head>
<style>
body {
    font-family: DejaVu Sans, sans-serif;
    background: #f5f7fb;
    color: #111;
}
.container {
    padding: 30px;
}
.header {
    text-align: center;
    border-bottom: 2px solid #0b8c9f;
    padding-bottom: 15px;
}
.header h1 {
    color: #0b8c9f;
    margin: 0;
}
.section {
    margin-top: 25px;
}
.section h3 {
    color: #0f766e;
    border-left: 5px solid #0b8c9f;
    padding-left: 10px;
}
.box {
    background: #ffffff;
    border-radius: 8px;
    padding: 15px;
    margin-top: 10px;
}
ul {
    margin: 0;
    padding-left: 18px;
}
.footer {
    text-align: center;
    margin-top: 40px;
    font-size: 12px;
    color: #555;
}
.badge {
    display: inline-block;
    background: #0b8c9f;
    color: #fff;
    padding: 6px 12px;
    border-radius: 20px;
    font-weight: bold;
}
</style>
</head>

<body>
<div class='container'>

<div class='header'>
    <h1>RS Learning Lab</h1>
    <p><strong>Learning Style Report</strong></p>
    <p>$student " . ($roll ? "| Roll No: $roll" : "") . "</p>
    <p>Date: $date</p>
</div>

<div class='section'>
    <h3>Identified Learning Style</h3>
    <div class='box'>
        <span class='badge'>$style Learner</span>
        <p>{$data['desc']}</p>
    </div>
</div>

<div class='section'>
    <h3>Personalized Daily Study Plan</h3>
    <div class='box'>
        <ul>
            <li>" . implode("</li><li>", $data['plan']) . "</li>
        </ul>
    </div>
</div>

<div class='section'>
    <h3>How This Student Learns Best</h3>
    <div class='box'>
        <strong>DO</strong>
        <ul>
            <li>" . implode("</li><li>", $data['do']) . "</li>
        </ul>
        <br>
        <strong>DON'T</strong>
        <ul>
            <li>" . implode("</li><li>", $data['dont']) . "</li>
        </ul>
    </div>
</div>

<div class='footer'>
    RS Learning Lab • Learning • Assessment • Certification
</div>

</div>
</body>
</html>
";

/* -------- PDF GENERATE -------- */
$dompdf = new Dompdf();
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream("Learning_Style_Report_$student.pdf", ["Attachment" => true]);
