<?php
require_once __DIR__ . '/../../../config/database.php';
require_once __DIR__ . '/../../../lib/auth.php';
require_once __DIR__ . '/../../../lib/csrf.php';

if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

requireLogin();

$pageTitle = 'Soil Test Analysis Report';
$siteName = 'Crop Management Platform';
$activeItem = 'Soil Analysis';

include __DIR__ . '/../../../layouts/header.php';
include __DIR__ . '/../../../layouts/navbar.php';
?>

<div id="layoutSidenav">
    <div id="layoutSidenav_nav">
        <?php include __DIR__ . '/../../../layouts/sidebar.php'; ?>
    </div>
    <div id="layoutSidenav_content">
        <main>
            <div class="container-fluid px-4">
                <h1 class="mt-4"><?= htmlspecialchars($pageTitle, ENT_QUOTES, 'UTF-8') ?></h1>
                <ol class="breadcrumb mb-4"><!-- TODO: render breadcrumbs dynamically --></ol>

                <div class="row">
                    <div class="container">
                        <h3 id="forms-example">Soil Test Details</h3>
                        <p class="text-muted">Complete the soil test form and submit.</p>

                        <!-- Client Details Form Component -->
                        <?php include __DIR__ . '/../../../components/clientDetailsForm.php'; ?>

                        <!-- New Client Modal Component -->
                        <?php include __DIR__ . '/../../../components/newClientModal.php'; ?>

                        <form method="post" action="/controllers/soilTestSubmit.php" id="SoilcsvForm" class="needs-validation" novalidate>
                            <input type="hidden" name="csrf_token" value="<?php echo generateCsrfToken(); ?>">

                            <?php // Soil Analysis Form Component ?>
                            <?php include __DIR__ . '/../../../components/soilAnalysisForm.php'; ?>

                            <button form="SoilcsvForm" type="submit" name="SoilcsvForm" class="btn btn-success">Submit</button>
                        </form>

                        <hr />

                        <div class="card">
                            <div class="card-body">
                                <h5 class="card-title">Excel/CSV Upload</h5>
                                <p class="card-text">Download a CSV of this form for easy filling or upload a filled form to pre-populate.</p>
                                <div class="input-group mt-3">
                                    <input type="file" class="form-control border-success" id="upload" accept=".csv">
                                    <button class="btn btn-success" type="button" id="download">Download</button>
                                </div>
                            </div>
                        </div>

                        <?php // include __DIR__ . '/../../../controllers/soilTestSubmit.php'; ?>

                        <!-- old modX placeholders: [[!clientDetailsFORM]], [[!soilformSubmit]], [[!newClientDetails]] -->

                    </div>
                </div>
            </div>
        </main>

    </div>
</div>

<?php include __DIR__ . '/../../../layouts/footer.php'; ?>
