<?php
include '../config.php';
include '../configuracao/modelo.php';

$tabela_alvo = $_GET['tabela'] ?? '';

// Busca as configurações da tabela
$stmt = $mysqli->prepare("SELECT tabela_campo_1, tabela_campo_2, tabela_campo_3 FROM tabela WHERE tabela_nome = ?");
$stmt->bind_param("s", $tabela_alvo);
$stmt->execute();
$stmt->bind_result($tc1, $tc2, $tc3);
$stmt->fetch();
$stmt->close();
?>

<style>
    .tg-config { border-collapse: collapse; margin: 20px auto; width: 80%; font-family: Arial, sans-serif; }
    .tg-config td { background-color: #fdf6e3; border: 1px solid #93a1a1; padding: 15px; }
    .tg-config th { background-color: #657b83; color: #fdf6e3; padding: 10px; }
    .input-full { width: 100%; padding: 8px; box-sizing: border-box; }
    .btn-save { background-color: #2ecc71; color: white; padding: 10px; border: none; cursor: pointer; width: 100%; }
</style>

<div class="tg-wrap">
    <form action="executa.php" method="GET">
        <input type="hidden" name="acao" value="configurar_tabela">
        <input type="hidden" name="tabela" value="<?php echo htmlspecialchars($tabela_alvo); ?>">
        
        <table class="tg-config">
            <thead>
                <tr><th colspan="2">Configurar Parâmetros da Tabela: <?php echo htmlspecialchars($tabela_alvo); ?></th></tr>
            </thead>
            <tbody>
                <tr>
                    <td><strong>Parâmetro 1 (tabela_campo_1):</strong></td>
                    <td><input type="text" name="vlr_tc1" class="input-full" value="<?php echo htmlspecialchars($tc1); ?>"></td>
                </tr>
                <tr>
                    <td><strong>Parâmetro 2 (tabela_campo_2):</strong></td>
                    <td><input type="text" name="vlr_tc2" class="input-full" value="<?php echo htmlspecialchars($tc2); ?>"></td>
                </tr>
                <tr>
                    <td><strong>Parâmetro 3 (tabela_campo_3):</strong></td>
                    <td><input type="text" name="vlr_tc3" class="input-full" value="<?php echo htmlspecialchars($tc3); ?>"></td>
                </tr>
                <tr>
                    <td colspan="2"><input type="submit" value="Salvar Parâmetros" class="btn-save"></td>
                </tr>
            </tbody>
        </table>
    </form>
</div>