<?php
/* -------------------------------------------------------------------------- */
/*                                CONFIGURATION                               */
/* -------------------------------------------------------------------------- */
date_default_timezone_set("Australia/Hobart");

error_reporting(E_ALL);
ini_set('display_errors', '0');
ini_set('log_errors', '1');

require_once 'connection.php';
include_once "dompdf/vendor/autoload.php";

use Dompdf\Dompdf;
use Dompdf\Options;

if (session_status() !== PHP_SESSION_ACTIVE) session_start();
if (empty($_SESSION['csrf'])) $_SESSION['csrf'] = bin2hex(random_bytes(16));
$csrf = $_SESSION['csrf'];

#$enquiry_date = date("l dS M 'y");
$drg = $_GET['drg'] ?? '';

if (!empty($_GET['drg'])) {
    include "table.php";
}

/* New: toggle PDF mode */
$asPdf = isset($_GET['pdf']);

/* If we are about to generate a PDF, start buffering the HTML now */
if ($asPdf) {
    ob_start();
}
?>

<!doctype html>
<html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title><?= htmlspecialchars($drg) ?> - Site Drafting</title>
        <link rel="shortcut icon" href="images/blueprint.ico" type="image/x-icon">
        <link href="css/bootstrap.css" rel="stylesheet">
        <link href="css/blueprint.css" rel="stylesheet">
        <link href="css/print.css" rel="stylesheet" media="print">

        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">

        <!-- jQuery first, then Popper.js, then Bootstrap JS -->
        <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
        <script type="text/javascript" src="https://use.fontawesome.com/1e2844bb90.js"></script>
        <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js" integrity="sha256-T0Vest3yCU7pafRw9r+settMBX6JkKN06dqBnpQ8d30=" crossorigin="anonymous"></script>

	</head>

    <body style="background-color:#fff !important;">

        <?php if (!$asPdf): ?>
        <nav class="navbar bg-brown-dark brown-light border-bottom border-body d-print-none" data-bs-theme="dark">
            <div class="container-fluid">
                <a class="navbar-brand brown-light" href="dashboard.php">
                    <img src="images/blueprint-logo-light.png" alt="Logo" width="30" height="24" class="d-inline-block align-text-top">
                    Modulos Design
                </a>
                <div class="ms-auto d-flex gap-2">
                    <a href="dashboard.php" class="btn btn-sm btn-outline-light"><i class="bi bi-grid-fill"></i> Dashboard</a>
                    <?php if (!empty($drg)): ?><a href="client-brief.php?drg=<?= (int)$drg ?>" class="btn btn-sm btn-outline-light"><i class="bi bi-person-fill"></i> Client Brief</a><?php endif; ?>
                </div>
            </div>
        </nav>
        <?php endif; ?>

		<div class="container border border-3 border-dark vh-100">
			<div class="row mt-2">
				<div class="col align-self-start">
					<p class="mb-0"><?= htmlspecialchars(($firstname ?? '') . ' ' . ($lastname ?? '')) ?> - <?= htmlspecialchars($client_mobile ?? '') ?></p>
					<p class="mb-0"><?= htmlspecialchars($site_address ?? '') ?></p>
				</div>
				<div class="col-2 align-self-end text-end">
					<h1 class="mb-0 fw-bold"><?= htmlspecialchars($drg) ?></h1>
				</div>
			</div>
			<hr class="">
			<div class="row">
				<div class="col">
				</div>
            </div>
		</div>
	</body>
</html>