<!DOCTYPE html>
<html>
<head>
    <title>Generator Diplome PDF</title>
</head>
<body>
    <h2>Generator Diplome – Configurare</h2>

    <form id="form-preview" action="preview.php" method="post" target="_blank">
        <label>Template PDF:</label><br>
        <select name="template" required>
            <?php
            foreach (glob("templates/*.pdf") as $pdf) {
                $name = basename($pdf);
                echo "<option value=\"$name\">$name</option>";
            }
            ?>
        </select><br><br>

        <label>Coordonata X pentru nume (0–297 mm):</label><br>
        <input type="number" name="x" value="0" step="1" required><br><br>

        <label>Coordonata Y pentru nume (0–210 mm):</label><br>
        <input type="number" name="y" value="100" step="1" required><br><br>

        <button type="submit">🔍 Vezi preview</button>
    </form>

    <hr>

    <form action="process.php" method="post" enctype="multipart/form-data">
        <input type="hidden" name="template" value="">
        <input type="hidden" name="x" value="">
        <input type="hidden" name="y" value="">

        <label>Încarcă Excel (.xlsx):</label><br>
        <input type="file" name="excel_file" accept=".xlsx" required><br><br>

        <button type="submit">🚀 Generează Diplome</button>
    </form>

    <script>
    // Copiază automat valorile de coordonate și template în ambele formulare
    const syncFields = () => {
        const template = document.querySelector('select[name="template"]').value;
        const x = document.querySelector('input[name="x"]').value;
        const y = document.querySelector('input[name="y"]').value;
        document.querySelectorAll('form')[1].template.value = template;
        document.querySelectorAll('form')[1].x.value = x;
        document.querySelectorAll('form')[1].y.value = y;
    };
    document.querySelectorAll('form')[0].addEventListener('submit', syncFields);
    </script>
</body>
</html>
