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

$pagina_id = $_GET["id"];
$query = $pdo->query("SELECT * FROM vagas WHERE id = $pagina_id");
$pagina_p_visu = $query->fetchAll(PDO::FETCH_ASSOC);
$total_reg = @count($pagina_p_visu);

$status_atual = $pagina_p_visu[0]['status'];
?>
<script src="tinymce/tinymce.min.js"></script>
<script>
    tinymce.init({
        selector: 'textarea',
        plugins: 'autolink lists link image charmap print preview',
        toolbar: 'undo redo | bold italic | alignleft aligncenter alignright | link image'
    });
</script>

<div class="content-body">
    <div class="container-fluid">
        <div class="page-titles">
            <ol class="breadcrumb">
                <a href="vagas.php" class="btn light btn-dark btn-xs">Voltar</a>
            </ol>
        </div>
        <div class="row">
            <div class="col-xl-12">
                <div class="row">
                    <div class="col-xl-12 col-lg-12">
                        <div class="card">
                            <div class="card-header">
                                <h4 class="card-title">Atualizar empresa</h4>

                            </div>
                            <div class="card-body">
                                <div class="basic-form">
                                    <form action="includes/class_vagas.php?vagas=2&id=<?php echo $pagina_p_visu[0]['id'] ?>" method="post" enctype="multipart/form-data">

                                        <div class="mb-3 row">
                                            <label class="col-sm-3 col-form-label">Empresa</label>
                                            <div class="col-sm-9">

                                                <div class="row align-items-center">
                                                    <div class="col-md-6 my-1">
                                                        <select name="empresa" class="me-sm-2 default-select form-control wide" id="categoria" aria-controls="tabela" class="form-control" required>
                                                            <option value="">Escolha uma:</option>
                                                            <?php
                                                            $query = $pdo->query("SELECT * FROM empresas order by id asc");
                                                            $empresas = $query->fetchAll(PDO::FETCH_ASSOC);
                                                            for ($icate = 0; $icate < @count($empresas); $icate++) {
                                                            ?>
                                                                <option value="<?php echo $empresas[$icate]['id'] ?>" <?php if (empty($pagina_p_visu[0]['razao_social']) || $pagina_p_visu[0]['categoria'] == $empresas[$icate]['id']) echo ' selected'; ?>><?php echo $empresas[$icate]['razao_social'] ?></option>
                                                            <?php } ?>

                                                        </select>
                                                    </div>

                                                    <div class="col-md-6">
                                                        <a href="empresas_add.php" class="btn btn-primary btn-xxs">Adicionar nova empresa</a>
                                                    </div>

                                                </div>

                                            </div>
                                        </div>
                                        <div class="mb-3 row">
                                            <label class="col-sm-3 col-form-label">Categoria</label>
                                            <div class="col-sm-9">

                                                <div class="row align-items-center">
                                                    <div class="col-md-12 my-1">
                                                        <select name="categoria" class="me-sm-2 default-select form-control wide" id="categoria" aria-controls="tabela" class="form-control" required>
                                                            <option value="">Escolha uma:</option>
                                                            <?php
                                                            $query = $pdo->query("SELECT * FROM categorias_vagas order by id asc");
                                                            $categoria = $query->fetchAll(PDO::FETCH_ASSOC);
                                                            for ($icate = 0; $icate < @count($categoria); $icate++) {
                                                            ?>
                                                                <option value="<?php echo $categoria[$icate]['id'] ?>" <?php if (empty($pagina_p_visu[0]['razao_social']) || $pagina_p_visu[0]['categoria'] == $categoria[$icate]['id']) echo ' selected'; ?>><?php echo $categoria[$icate]['nome_cat'] ?></option>
                                                            <?php } ?>

                                                        </select>
                                                    </div>

                                                </div>

                                            </div>
                                        </div>
                                        <div class="mb-3 row">
                                            <label class="col-sm-3 col-form-label">Título da vaga</label>
                                            <div class="col-sm-9">
                                                <input type="text" name="titulo" class="form-control" value="<?php echo $pagina_p_visu[0]['titulo'] ?>" Required>

                                            </div>
                                        </div>
                                        <div class="mb-3 row">
                                            <label class="col-sm-3 col-form-label">Empresa</label>
                                            <div class="col-sm-9">

                                                <div class="row align-items-center">
                                                    <div class="col-md-12 my-1">
                                                        <select name="status" class="me-sm-2 default-select form-control wide" id="inlineFormCustomSelect" Required>
                                                            <option value="">Escolha...</option>
                                                            <option value="Aberta" <?php echo ($status_atual === 'Aberta') ? 'selected' : ''; ?>>Aberta</option>
                                                            <option value="Finalizada" <?php echo ($status_atual === 'Finalizada') ? 'selected' : ''; ?>>Finalizada</option>
                                                            <option value="Cancelada" <?php echo ($status_atual === 'Cancelada') ? 'selected' : ''; ?>>Cancelada</option>
                                                        </select>
                                                    </div>
                                                </div>

                                            </div>
                                        </div>
                                        <div class="mb-3 row">
                                            <label class="col-sm-3 col-form-label">Descrição</label>
                                            <div class="col-sm-9">
                                                <textarea name="descricao" class="form-control" value=""><?php echo $pagina_p_visu[0]['descricao'] ?></textarea>
                                            </div>
                                        </div>

                                        <div class="mb-3 row">
                                            <label class="col-sm-3 col-form-label">Salário</label>
                                            <div class="col-sm-9">
                                                <input type="text" name="salario" class="form-control" value="<?php echo $pagina_p_visu[0]['salario'] ?>">

                                            </div>
                                        </div>
                                        <div class="mb-3 row">
                                            <label class="col-sm-3 col-form-label">Requisitos</label>
                                            <div class="col-sm-9">
                                                <input type="text" name="requisitos" class="form-control" value="<?php echo $pagina_p_visu[0]['requisitos'] ?>">
                                            </div>
                                        </div>

                                        <div class="mb-3 row">
                                            <label class="col-sm-3 col-form-label">Benefícios</label>
                                            <div class="col-sm-9">
                                                <input type="text" name="beneficios" class="form-control" value="<?php echo $pagina_p_visu[0]['beneficios'] ?>">

                                            </div>
                                        </div>
                                        <div class="mb-3 row">
                                            <label class="col-sm-3 col-form-label">Quantidade</label>
                                            <div class="col-sm-9">
                                                <input type="text" name="quantidade" class="form-control" value="<?php echo $pagina_p_visu[0]['quantidade'] ?>">

                                            </div>
                                        </div>






                                        <div class="mb-3 row">
                                            <div class="col-sm-10">
                                                <button type="submit" class="btn btn-primary">Atualizar vaga</button>
                                                <button type="button" id="executar-codigo-btn" onclick="executarCodigo()" class="btn btn-danger">Deletar vaga <span class="btn-icon-end"><i class="fa fa-close"></i></span> </button>
                                                <?php
                                                $pegaid = "includes/class_vagas.php?empresas=3&id=" . $pagina_id . "";

                                                ?>



                                                <script>
                                                    var pegou = "<?php echo $pegaid ?>";


                                                    function executarCodigo() {

                                                        Swal.fire({
                                                            icon: 'warning',
                                                            title: 'Realmente deseja apagar esta vaga?',
                                                            text: 'Este processo é irreversível!',
                                                            showCancelButton: true,
                                                            confirmButtonColor: '#3085d6',
                                                            cancelButtonColor: '#d33',
                                                            confirmButtonText: 'Sim apagar'
                                                        }).then((result) => {
                                                            if (result.value) {
                                                                window.location = pegou;
                                                            }
                                                        })
                                                    }
                                                </script>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>



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

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