<?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">Empresas</h4>
                                <a href="empresas_add.php" class="btn btn-primary btn-sm">Adicionar empresa</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>Criado em</strong></th>
                                                <th><strong>Status</strong></th>
                                                <th><strong></strong></th>
                                            </tr>
                                        </thead>
                                        <tbody>


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

                                            ?>
                                                <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 $empresas[$i]['id'] ?></strong></td>
                                                    <td>
                                                        <div class="d-flex align-items-center">
                                                            <a href="empresas_update.php?id=<?php echo $empresas[$i]['id'] ?>">
                                                                <img src="images/gerais/<?php echo $empresas[$i]['logo'] ?>" class="rounded-lg me-2" width="24" alt="">
                                                                <span class="w-space-no"><?php echo $empresas[$i]['razao_social'] ?></span>
                                                            </a>
                                                        </div>
                                                    </td>
                                                    <td><?php // echo $empresas[$i]['criado_em'] 
                                                        ?></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="empresas_update.php?id=<?php echo $empresas[$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 } ?>