<?php include_once('../../../config.php') ?>

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Sisplan Web | Configuração Whatsapp</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="../dist/css/adminlte.min.css?versao=3.2510.21.1">
  <link rel="stylesheet" href="../plugins/fontawesome-free/css/all.min.css?versao=3.2510.21.1">
  <link href='https://fonts.googleapis.com/css?family=Roboto:400,300,500,600,700,400italic' rel='stylesheet' type='text/css'>
  <link rel="stylesheet" type="text/css" href="../dist/css/dataTables.bootstrap4.min.css?versao=3.2510.21.1" />
  <link href='../dist/css/bootstrap.min.css?versao=3.2510.21.1'>
  <link rel="stylesheet" href="../dist/css/custom.css?versao=3.2510.21.1">
  <link rel="stylesheet" href="../dist/css/sisplan.css?versao=3.2510.21.1">
  <link rel="stylesheet" type="text/css" href="../plugins/datatables-keytable/css/keyTable.bootstrap4.min.css?versao=3.2510.21.1">
  <link rel="stylesheet" type="text/css" href="../dist/css/responsive.bootstrap.min.css?versao=3.2510.21.1">
  <link rel="shortcut icon" href="../favicon.ico">
  <link rel="stylesheet" href="../dist/css/cadastro.css?versao=3.2510.21.1">
  <link rel="stylesheet" href="../plugins/toastr/toastr.min.css?versao=3.2510.21.1">
  <link rel="stylesheet" type="text/css" href="../dist/css/driver.min.css?versao=3.2510.21.1" />
  <link rel="stylesheet" href="../dist/css/jquery-ui.css?versao=3.2510.21.1">
  <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
</head>

<body class="hold-transition sidebar-mini layout-fixed">
  <div class="wrapper">


    <div id="myModal" class="modal" tabindex="-1" role="dialog">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 id="myModalLabel" class="modal-title"></h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            <p id="myModalText"></p>
          </div>
          <div class="modal-footer">
            <button id="btnYes" type="button" class="btn btn-primary">Sim</button>
            <button id="btnNo" type="button" class="btn btn-secondary" data-dismiss="modal">Não</button>
          </div>
        </div>
      </div>
    </div>
    <div class="wrapper">
      <div id="myModal" class="modal" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <h5 id="myModalLabel" class="modal-title"></h5>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <div class="modal-body">
              <p id="myModalText"></p>
            </div>
            <div class="modal-footer">
              <button id="btnYes" type="button" class="btn btn-primary">Sim</button>
              <button id="btnNo" type="button" class="btn btn-secondary" data-dismiss="modal">Não</button>
            </div>
          </div>
        </div>
      </div>
      <div class="content-wrapper">
        <div class="content-header">
          <div class="container-fluid">
            <div class="row mb-2">
              <div class="col-sm-6 flex">
                <h1 class="m-0 text-dark">Configuração WhatsApp - Cadastro</h1>
              </div>
              <div class="col-sm-6">
                <!-- <ol class="breadcrumb float-sm-right">
                  
                  <li class="breadcrumb-item active"><a href="../config_whatsapp">Configuração WhatsApp</a></li>
                  <li class="breadcrumb-item active">Cadastro de Configuração WhatsApp</li>
                </ol> -->
              </div>
            </div>
          </div>
          <div class="row justify-content-center mt-0">
            <div class="col-10 text-center p-0 mt-3 mb-2">
              <div class="row">
                <div class="col-md-12 mx-0">
                  <form id="msform">
                    <div class="form-card" id="formcard1" style="min-height: 400px;">
                      <div class="row d-flex justify-content-center">
                        <div class="card col-10" id="campostour">
                          <div class="card-body">
                            <div class="row">
                              <div class="col-1 ml-2 mt-1">
                              <label data-error="wrong" class="labelGeral" data-success="right" for="cbPadrao">Padrão</label>
                                <div class="form-group form-check col-12 icheck-primary">
                                  <input type="checkbox" value="" class="form-check-input" id="cbPadrao">
                                  <label class="form-check-label ml-2" for="cbPadrao"></label>
                                </div>
                              </div>
                              <div class="col-12 col-lg-2">
                                <label data-error="wrong" class="labelGeral" data-success="right" for="txtId">Id</label>
                                <div class="input-group">
                                  <input type="text" class="input-default focus form-control" disabled readonly aria-describedby="ufError" id="txtId" name="txtId" title="Gerado automaticamente" class="form-control" placeholder="Gerado Automatic.">
                                  <span id="ufError" class="error invalid-feedback" style="display: inline;"></span>
                                </div>
                              </div>
                              <div class="col-12 col-lg-4">
                                <label data-error="wrong" class="labelGeral" data-success="right" for="txtNomeDispositivo">Nome</label>
                                <div class="input-group">
                                  <input type="text" class="input-default focus form-control" aria-describedby="ufError" id="txtNomeDispositivo" name="txtNomeDispositivo" class="form-control" placeholder="Nome">
                                  <span id="ufError" class="error invalid-feedback" style="display: inline;"></span>
                                </div>
                              </div>
                              <div class="col-12 col-lg-4">
                                <label data-error="wrong" class="labelGeral" data-success="right" for="txtTelefone">Telefone</label>
                                <div class="input-s">
                                  <input type="text" class="input-default focus form-control" required aria-describedby="ufError" id="txtTelefone" name="txtTelefone" class="form-control" placeholder="Telefone">
                                  <span id="ufError" class="error invalid-feedback" style="display: inline;"></span>
                                </div>
                              </div>
                              <div class="col-12 col-lg-12">
                                <label data-error="wrong" class="labelGeral" data-success="right" for="txtToken">Token</label>
                                <div class="input-group">
                                  <input type="text" class="input-default focus form-control" required readonly aria-describedby="ufError" id="txtToken" name="txtToken" class="form-control" placeholder="Token">
                                  <div class="input-group-append">
                                    <button class="btn bg-danger" id="btnToken" name="btnToken" data-button="absolute" type="button" title="Gerar Token de conexão">
                                      <i class="m-0 p-0 fas fa-check-circle"></i>
                                    </button>
                                  </div>
                                  <span id="ufError" class="error invalid-feedback" style="display: inline;"></span>
                                </div>
                              </div>
                              <div class="col-sm-12 card-body">
                                <div class="d-flex align-items-center" style="grid-gap: 1rem">
                                  <h5>Conectar Dispositivo</h5>
                                  <button type="button" id="btnConectar" class="btn btn-primary btn-sisp">Conectar</button>
                                </div>
                                <img id="qrcode" class="d-none pt-2 mt-2 " style="background: white; padding: 10px;" src="" alt="qr-code" />
                              </div>
                            </div>
                            <input type="button" name="btnGravar" id="btnGravar" class="btn-sisp action-button" value="Gravar" />
                            <button type="button" name="btnTesteWpp" id="btnTesteWpp" class="btn-sisp bg-gradient-success action-button-previous">Testar Envio</button>
                            <button type="button" id="btnVoltar" class="btn-sisp action-button-previous">Voltar</button>
                          </div>
                        </div>
                      </div>
                    </div>
                  </form>
                </div>
              </div>
            </div>
          </div>
        </div>
        </section>
      </div>
    </div>
  </div>
  <div class="modal fade" id="modalTestaEnvio" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg modal-dialog-centered" style="width: 450px;">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title">Testa Envio WhatsApp:</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          <label data-error="wrong" class="labelGeral" data-success="right" for="txtNumeroEnvio">Número:</label>
          <div class="input-group">
            <input type="text" data-selecionado="false" size="1" class="input-default focus form-control"
              id="txtNumeroEnvio" name="txtNumeroEnvio" placeholder="Número de WhatsApp(Ex.:4700000000)">
            <div class="input-group-append">
              <button class="btn bg-danger" id="btn-limpa-numero" type="button"><i
                  class="m-0 p-0 fas fa-trash"></i></button>
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <button class="btn btn-primary btn-sisp" style="width:270px; margin-left: 7px;"
            id="btnEnviaTeste">Enviar</button>
          <button class="btn bg-gradient-danger btn-sisp" style="width:50px; margin-right: 12px;"
            id="btnFecharTestaEnvio" data-dismiss="modal">Fechar</button>
        </div>
      </div>
    </div>
  </div>

  <?php
  include_once('../../../modais.php');
  ?>
  <aside class="control-sidebar control-sidebar-dark">
  </aside>
  </div>
  <script src="../plugins/jquery/jquery.min.js?versao=3.2510.21.1"></script>
  <script src="../plugins/jquery-ui/jquery-ui.min.js?versao=3.2510.21.1"></script>
  <script type="text/javascript" src="../dist/js/jquery.dataTables.js?versao=3.2510.21.1"></script>
  <script type="text/javascript" src="../dist/js/dataTables.bootstrap4.min.js?versao=3.2510.21.1"></script>
  <script src="../plugins/sweetalert2/sweetalert2.min.js?versao=3.2510.21.1"></script>
  <script src="../plugins/toastr/toastr.min.js?versao=3.2510.21.1"></script>
  <script>
    $.widget.bridge('uibutton', $.ui.button);
  </script>
  <script src="../plugins/bootstrap/js/bootstrap.bundle.min.js?versao=3.2510.21.1"></script>
  <script src="../dist/js/adminlte.min.js?versao=3.2510.21.1"></script>
  <script src="../dist/js/requisicoes.js?versao=3.2510.21.1"></script>
  <script src="../dist/js/cliente/entidade.js?versao=3.2510.21.1"></script>
  <script src="../dist/js/loadingoverlay.min.js?versao=3.2510.21.1"></script>
  <script src="../dist/js/valida_cpf_cnpj.js"></script>
  <script src="../plugins/jquery-validation/jquery.validate.min.js?versao=3.2510.21.1"></script>
  <script src="../dist/js/sisplan.js?versao=3.2510.21.1"></script>
  <script src="../utils/funcoes.js?versao=3.2510.21.1"></script>
  <script src="../utils/cookies.js?versao=3.2510.21.1"></script>
  <script src="../dist/js/jquery.maskMoney.min.js?versao=3.2510.21.1"></script>
  <script src="../dist/js/driver.min.js?versao=3.2510.21.1"></script>
  <script src="../dist/js/dataTables.keyTable2.js?versao=3.2510.21.1"></script>
  <script src="../dist/js/jquery.inputmask.js"></script>
  <script type="text/javascript" src="../config.js?versao=3.2510.21.1"></script>
  <script>
    $(document).ready(async function() {
      if (getCookie('usuario') == "") {
        window.location.href = `${BASE_URI}/login`;
        return;
      }

      let usuario = getCookie('usuario');
      let empresa = getCookie('empresa');

      ipInterno = IP_INTERNO;
      ipExterno = IP_EXTERNO;
      basicAuth = BASIC_AUTH;

      const temAcesso = await temAcessoTela('CONFIG_WHATSAPP');
      if (!temAcesso.resultado) {
        toastrAcesso(temAcesso, BASE_URI);
        return;
      }

      const permissaoUsuarioLogado = await permissaoAcessos('CONFIG_WHATSAPP');
      if (permissaoUsuarioLogado.INCLUI == 'N') {
        await criaMensagemErro("Sem permissão para incluir!", () => {
          window.location.href = `${BASE_URI}/config_whatsapp`
        });
        return;
      }

      sArquivo = `${BASE_URI}/pages/config_whatsapp/cadastro_config_whatsapp/config_whatsapp.js?versao=3.2510.21.1`;
      insereJavaScriptPagina(sArquivo);

      const nomeTela = ('<?php echo basename(__FILE__) ?>').replace('.php', '');
      habilitaCamposObrigatoriosTela(nomeTela);
    });
  </script>
</body>

</html>