<?php
require_once("../layouts/members/head.php");

// Set the base URL using paymentapi() once
$baseUrl = "https://" . paymentapi("gateway_Url");
?>

<div class="row">
    <!-- Left: Form + Table (50%) -->
    <div class="col-md-6 mb-2">
        <div class="card text-dark">
            <div class="card-header bg-primary text-white py-2">
                <div class="d-flex align-items-center">
                    <span class="mr-auto"><?= file_name() ?></span>
                </div>
            </div>

            <!-- Table -->
            <div class="table-responsive scroll">
                <table class="table w-100" id="dataTable">
                    <thead>
                        <tr class="bg-secondary">
                            <th>SL No</th>
                            <th>Name</th>
                            <th>Link</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $forms = [
                            "Form-9.pdf",
                            "Form_1_Eng.pdf",
                            "Form-2-English.pdf",
                            "Form_3_Eng.pdf",
                            "Form-4-English.pdf",
                            "Form_5_Eng.pdf",
                            "Form-6-English.pdf",
                            "Form_7_Eng.pdf",
                            "Form_8_Eng.pdf",
                            "11.pdf"
                        ];

                        $titles = [
                            "SELF-DECLARATION FROM THE HEAD OF FAMILY (HOF) FOR SHARING ADDRESS WITH IMMEDIATE FAMILY MEMBER RESIDING AT THE SAME ADDRESS Aadhaar Update Form",
                            "For (a) Resident Indian, or (b) Non-Resident Indian having Proof of Address in India (aged 18 years and above) Aadhaar Update Form",
                            "For Non-Resident Indian having Proof of Address outside India (aged 18 years and above) Aadhaar Update Form",
                            "For (a) Resident Indian child, or (b) Non-Resident Indian child having Proof of Address in India (aged 5 years and above and less than 18 years) Aadhaar Update Form",
                            "For Non-Resident Indian child having Proof of Address outside India (aged 5 years and above and less than 18 years) Aadhaar Update Form",
                            "For (a) Resident Indian child, or (b) Non-Resident Indian child having Proof of Address in India (below 5 years of age) Aadhaar Update Form",
                            "For Non-Resident Indian child having Proof of Address outside India (below 5 years of age) Aadhaar Update Form",
                            "For Resident Foreign National (aged 18 years or above) Aadhaar Update Form",
                            "For Resident Foreign National (aged below 18 years) Aadhaar Update Form",
                            "New Ennrolment Form Aadhaar Update Form"
                        ];

                        foreach ($forms as $index => $file) {
                            $pdfUrl = $baseUrl . "/layouts/members/assets/pdf/aadhaar/" . $file;
                            echo "<tr>
                                <td>" . ($index + 1) . "</td>
                                <td>" . htmlspecialchars($titles[$index]) . "</td>
                                <td>
                                    <a href=\"#\" class=\"preview-link\" data-pdf=\"" . $pdfUrl . "\">
                                        <i class=\"fas fa-link\"></i> Open
                                    </a>
                                </td>
                            </tr>";
                        }
                        ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <!-- Right: PDF Preview Section (50%) -->
    <div class="col-md-6 mb-2" id="pdfPreviewContainer" style="display: none;">
        <div class="card h-100">
            <div class="card-header bg-info text-white py-2">PDF Preview</div>
            <div class="card-body p-2">
                <iframe id="pdfPreview" src="" width="100%" height="800px" style="border:1px solid #ccc;">
                    Your browser does not support iframes.
                </iframe>
            </div>
        </div>
    </div>
</div>

<!-- JS for PDF Preview -->
<script>
    document.addEventListener('DOMContentLoaded', function () {
        const previewLinks = document.querySelectorAll('.preview-link');
        const iframe = document.getElementById('pdfPreview');
        const pdfPreviewContainer = document.getElementById('pdfPreviewContainer');

        previewLinks.forEach(link => {
            link.addEventListener('click', function (e) {
                e.preventDefault();
                const pdfUrl = this.getAttribute('data-pdf');
                pdfPreviewContainer.style.display = 'block';
                iframe.src = pdfUrl;
            });
        });
    });
</script>

<?php
require_once("../layouts/members/foot.php");
data_table('#dataTable');
?>
