<?php require_once("includes/topo.php");  ?>

<div class="content-body">
    <div class="container-fluid">
        <div class="row">
            <div class="col-xl-12">
                <div class="row">


                    <div class="col-lg-12">

                        <div class="card">
                            <div class="card-header">
                                <h4 class="card-title">Vagas</h4>
                                <a href="vagas_add.php" class="btn btn-primary btn-sm">Adicionar nova vaga</a>
                            </div>
                            <div class="card-body">
                                <div class="table-responsive">
                                    <table class="table table-responsive-md">
                                        <thead>
                                            <tr>
                                                <th style="width:50px;">
                                                    <div class="form-check custom-checkbox checkbox-success check-lg me-3">
                                                        <input type="checkbox" class="form-check-input" id="checkAll" required="">
                                                        <label class="form-check-label" for="checkAll"></label>
                                                    </div>
                                                </th>
                                                <th><strong>ID</strong></th>
                                                <th><strong>Nome</strong></th>
                                                <th><strong>Empresa</strong></th>
                                                <th><strong>Inscritos</strong></th>
                                                <th><strong>Status</strong></th>
                                                <th><strong></strong></th>
                                            </tr>
                                        </thead>
                                        <tbody>


                                            <?php
                                            //VAGAS
                                            $query = $pdo->query("SELECT * FROM vagas order by id desc");
                                            $vagas = $query->fetchAll(PDO::FETCH_ASSOC);
                                            for ($i = 0; $i < @count($vagas); $i++) {
                                                foreach ($vagas[$i] as $key => $value) {
                                                }

                                                $idempresa = $vagas[$i]['empresa'];
                                                $idvaga = $vagas[$i]['empresa'];

                                                $queryEmpresa = $pdo->query("SELECT * FROM empresas where id = $idempresa");
                                                $empresa = $queryEmpresa->fetchAll(PDO::FETCH_ASSOC);

                                                $query = $pdo->query("SELECT * FROM candidaturas WHERE vaga = $idvaga");
                                                $vagasPega = $query->fetchAll(PDO::FETCH_ASSOC);
                                                $total_vagas = @count($vagasPega);

                                            ?>
                                                <tr>
                                                    <td>
                                                        <div class="form-check custom-checkbox checkbox-success check-lg me-3">
                                                            <input type="checkbox" class="form-check-input" id="customCheckBox2" required="">
                                                            <label class="form-check-label" for="customCheckBox2"></label>
                                                        </div>
                                                    </td>
                                                    <td><strong><?php echo $vagas[$i]['id'] ?></strong></td>
                                                    <td>
                                                        <div class="d-flex align-items-center">
                                                            <a href="vagas_update.php?id=<?php echo $vagas[$i]['id'] ?>">
                                                                <span class="w-space-no"><?php echo $vagas[$i]['titulo'] ?></span>
                                                            </a>
                                                        </div>
                                                    </td>
                                                    <td><?php echo $empresa[0]['razao_social'] ?></td>
                                                    <td>
                                                        Total inscritos: <?php echo $total_vagas ?> <a href="candidaturas.php?id=<?php echo $vagas[$i]['id'] ?>" class="btn btn-primary btn-xs">Visualizar</a>
                                                    </td>
                                                    <td>
                                                        <div class="d-flex align-items-center"><i class="fa fa-circle text-success me-1"></i> Ativo</div>
                                                    </td>
                                                    <td>
                                                        <div class="d-flex">
                                                            <a href="vagas_update.php?id=<?php echo $vagas[$i]['id'] ?>" class="btn btn-primary shadow btn-xs sharp me-1"><i class="fa fa-pencil"></i></a>
                                                        </div>
                                                    </td>
                                                </tr>

                                            <?php } ?>



                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>





                </div>
            </div>

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

<?php require_once("includes/rodape.php"); ?>



<?php if (!empty($_GET['status']) == "ok") { ?>
    <script>
        window.onload = function() {
            swal({
                title: 'Sucesso',
                text: ("Empresa criada com sucesso!"),
                type: 'success',
                confirmButtonText: 'Fechar'
            })
        };
    </script>
<?php } ?>

<?php if (!empty($_GET['apagou']) == "ok") { ?>
    <script>
        window.onload = function() {
            swal({
                title: 'Empresa apagada!',
                text: ("Empresa apagada com sucesso!"),
                type: 'success',
                confirmButtonText: 'Fechar'
            })
        };
    </script>
<?php } ?>