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

$pagina_id = $_GET["id"];
$query = $pdo->query("SELECT * FROM empresas WHERE id = $pagina_id");
$pagina_p_visu = $query->fetchAll(PDO::FETCH_ASSOC);
$total_reg = @count($pagina_p_visu);
?>
<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="empresas.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_empresas.php?empresas=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">Razão Social</label>
                                            <div class="col-sm-9">
                                                <input type="text" name="razao_social" class="form-control" value="<?php echo $pagina_p_visu[0]['razao_social'] ?>" Required>

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

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

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

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

                                            </div>
                                        </div>

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

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

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

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

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

                                            </div>
                                        </div>
                                        <div class="mb-3 row">
                                            <label class="col-sm-3 col-form-label">Inscrição estadual</label>
                                            <div class="col-sm-9">
                                                <input type="text" name="inscricao_estadual" class="form-control" value="<?php echo $pagina_p_visu[0]['inscricao_estadual'] ?>">

                                            </div>
                                        </div>
                                        <div class="mb-3 row">
                                            <label class="col-sm-3 col-form-label">Inscrição municipal</label>
                                            <div class="col-sm-9">
                                                <input type="text" name="inscricao_municipal" class="form-control" value="<?php echo $pagina_p_visu[0]['inscricao_municipal'] ?>">

                                            </div>
                                        </div>

                                        <div class="mb-3 row">
                                            <label class="col-sm-3 col-form-label">Logo</label>
                                            <div class="col-sm-9">
                                                <img src="images/gerais/<?php echo $pagina_p_visu[0]['logo'] ?>" class="rounded-lg me-2" width="60" alt="">
                                                <input class="form-control" name="logo" type="file" id="formFile">
                                            </div>
                                        </div>






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

                                                ?>



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


                                                    function executarCodigo() {

                                                        Swal.fire({
                                                            icon: 'warning',
                                                            title: 'Realmente deseja apagar esta empresa?',
                                                            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");  ?>