<?php
require '../../conexao/conexao.php';
require '../../sessao.php';
require '../../configuacoes.php';

require '../../querys/query-metas.php';

$Metas = new Metas($connectionmysql);

$listagemMetas = $Metas->listarMetas();

//print_r($listagemMetas);

if (isset($_SESSION['message'])) {
    echo "<script>alert('" . $_SESSION['message'] . "');</script>";
    unset($_SESSION['message']); // Limpa a mensagem após exibição
}

$Metas->desativaMeta($connectionmysql);
?>

<!DOCTYPE html>
<html lang="pt-BR">
<head>
    <link rel="icon" href="\KPI\pages/configuracoes/logo-sm.png">
    <link rel="shortcut icon" href="\KPI\pages/configuracoes/logo-sm.png">

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- Bootstrap CSS -->

    <!--Material Icon -->
    <link rel="stylesheet" href="https://cdn.materialdesignicons.com/5.4.55/css/materialdesignicons.min.css">
</head>

<?php $pageTitle = 'Configuração de Metas - Manda Receita'; ?>

<body>

    <div class="container-fluid">
        <div class="row">
            <!-- Menu Lateral -->
            <?php include('../lateral.php'); ?>

            <!-- Conteúdo Principal -->
            <main class="col-md-9 col-lg-10 content">
                <form action="" method="post" enctype="multipart/form-data">
                    <div class="wrapper candidato">
                        <div class="container-fluid">
                            <div class="card-box mt-3">
                                <div class="row">
                                    <div class="col-6 text-left mb-4">
                                        <h4 class="page-title">Configura Metas</h4>

                                    </div>
                                    <div class="col-6 text-right">

                                        <a href="add-metas.php" class="btn btn-light" alt="Incluir Metas" title="Incluir Metas"><i class="mdi mdi-plus"></i> Adicionar Metas</a>


                                    </div>
                                    <div class="col-12" style="margin-top: -15px;">
                                        <hr>
                                    </div>
                                </div>
                                <div class="col-12">
                                    <table class="table table-striped table-bordered dt-responsive nowrap">
                                        <tbody>
                                            <tr>
                                                <th valign="middle" nowrap="nowrap">Metas Cadastradas</th>
                                                <th valign="middle" nowrap="nowrap" style="text-align: center">Ações</th>
                                            </tr>

                                            <?php foreach ($listagemMetas as $itens) { ?>
                                                <tr>
                                                    <td width="87%"><?php echo $itens['nome_meta']; ?></td>
                                                    <td width="13%" align="center" nowrap="nowrap">

                                                        <a href="alteracao_metas.php?id=<?php echo $itens['id']; ?>" class="table-actions link-view" title="Alterar Metas"><i class="mdi mdi mdi-account-edit"></i></a>

                                                        <button onclick="window.location.href='listagem-metas.php?id=<?php echo $itens['id']; ?>';" type="button" class="table-actions link-view excluir-btn" title="Excluir Meta">
                                                            <i class="mdi mdi-delete-forever"></i>
                                                        </button>

                                                    </td>
                                                </tr>
                                            <?php } ?>

                                        </tbody>
                                    </table>

                                </div>
                            </div>
                        </div>
                    </div>
                </form>


            </main>
        </div>
    </div>

    <!-- Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.3/dist/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>

</body>

</html>