<?php 
// Check if redirected after successful form submission
$show_download = isset($_GET['download']) && $_GET['download'] == 'success';
?>
<?php include 'includes/header.php'; ?>

<!-- Page Header -->
<section class="py-5 text-white" style="background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);">
    <div class="container py-3 text-center">
        <h1 class="outfit fw-bold display-4">Download Catalogue</h1>
        <p class="mb-0 text-white-50">Get access to our complete product directory, codes, and pricing models.</p>
    </div>
</section>

<section class="py-5 bg-white">
    <div class="container py-4">
        <div class="row justify-content-center">
            <div class="col-lg-6 col-md-8">
                
                <?php if ($show_download): ?>
                    <!-- Success Download State -->
                    <div class="card border-0 shadow-lg p-5 rounded-4 text-center bg-light">
                        <div class="text-success fs-1 mb-4"><i class="fa-solid fa-circle-check"></i></div>
                        <h3 class="outfit fw-bold text-dark mb-2">Thank You!</h3>
                        <p class="text-secondary small mb-4">Your request has been registered. The catalogue download should begin automatically. If it doesn't, click the button below.</p>
                        
                        <a href="assets/docs/veluno_catalogue_2026.pdf" download class="btn btn-primary px-5 py-3 rounded-pill fw-bold w-100 mb-3">
                            <i class="fa-solid fa-file-arrow-down me-2"></i> Download Catalogue PDF
                        </a>
                        
                        <a href="products.php" class="btn btn-outline-primary px-5 py-2.5 rounded-pill fw-bold w-100">
                            Browse Products Online
                        </a>
                    </div>
                    
                    <!-- Auto trigger download on load -->
                    <script>
                        window.onload = function() {
                            const link = document.createElement('a');
                            link.href = 'assets/docs/veluno_catalogue_2026.pdf';
                            link.download = 'veluno_catalogue_2026.pdf';
                            document.body.appendChild(link);
                            link.click();
                            document.body.removeChild(link);
                        };
                    </script>

                <?php else: ?>
                    <!-- Lead Capture Form State -->
                    <div class="card border-0 shadow-lg p-4 p-md-5 rounded-4 bg-light">
                        <div class="text-center mb-4">
                            <div class="text-primary fs-1 mb-2"><i class="fa-solid fa-file-pdf"></i></div>
                            <h3 class="outfit fw-bold text-dark mb-1">Access Catalogue</h3>
                            <p class="small text-secondary mb-0">Please fill out this quick form to download the catalog.</p>
                        </div>
                        
                        <form action="send-enquiry.php" method="POST" class="needs-validation" novalidate>
                            <input type="hidden" name="form_type" value="catalogue_download">
                            
                            <div class="mb-3">
                                <label class="form-label small fw-semibold text-secondary">Your Name *</label>
                                <input type="text" class="form-control bg-white" name="name" required placeholder="E.g., Anil Gupta">
                                <div class="invalid-feedback">Please enter your name.</div>
                            </div>
                            
                            <div class="mb-3">
                                <label class="form-label small fw-semibold text-secondary">Mobile Number *</label>
                                <input type="tel" class="form-control bg-white" name="phone" pattern="[0-9]{10}" required placeholder="10-digit mobile number">
                                <div class="invalid-feedback">Please enter your 10-digit mobile number.</div>
                            </div>
                            
                            <div class="mb-4">
                                <label class="form-label small fw-semibold text-secondary">Email Address *</label>
                                <input type="email" class="form-control bg-white" name="email" required placeholder="E.g., anil@hardware.com">
                                <div class="invalid-feedback">Please enter a valid email address.</div>
                            </div>
                            
                            <button type="submit" class="btn btn-primary w-100 py-3 fw-bold rounded-3">
                                <i class="fa-solid fa-file-arrow-down me-1"></i> Submit & Download PDF
                            </button>
                        </form>
                        
                        <div class="text-center mt-3">
                            <span class="small text-secondary"><i class="fa-solid fa-lock me-1"></i> We never share your data.</span>
                        </div>
                    </div>
                <?php endif; ?>

            </div>
        </div>
    </div>
</section>

<?php include 'includes/footer.php'; ?>
