<?php if(isset($_GET["sucesso"])){ ?>					
   <div style="margin-top: 15px" class="alert alert-success" role="alert">
      O <?= ($tipo == "1") ? 'cliente' : 'fornecedor' ?> foi atualizado com sucesso.
   </div>                         
<?php } ?>

<div class="row" <?= (!isset($_GET["sucesso"]) ? 'style="padding-top: 15px"' : '') ?>>
                            <div class="col-xl-8">
                                <div class="card mb-4">
                                    <div class="card-header">
                                        <i class="bi-clipboard-data"></i>
                                        Dados do <?= ($tipo == "1") ? 'Cliente' : 'Fornecedor' ?>
                                    </div>
                                    <div class="card-body">
                                    
                                    <form id="cadastro_cliente_fornecedor" nome="cadastro_cliente_fornecedor" action="atualizar_cliente_fornecedor_action.php" method="post" class="form-card">
                                    
                                    <div class="row justify-content-between text-left">
                                       <div class="form-group col-sm-6 flex-column d-flex">
                                         <label style="padding-left: 5px" class="form-control-label">Nome/Fantasia<span class="text-danger"> *</span></label>
                                         <input onkeyup="atualizar_info_lado()" value="<?= $fantasia ?>" onBlur="this.value = this.value.toUpperCase();" required type="text" id="fantasia" name="fantasia" placeholder="">
                                       </div>
                                    
                                       <div class="form-group col-sm-6 flex-column d-flex">
                                         <label style="padding-left: 5px" class="form-control-label">Raz&atilde;o Social</label>
                                         <input onkeyup="atualizar_info_lado()" value="<?= $razao_social ?>" onBlur="this.value = this.value.toUpperCase();" type="text" id="razao_social" name="razao_social" placeholder="">
                                       </div>
                                    </div>
                    
                                    <div class="row justify-content-between text-left">
                                       <div class="form-group col-sm-6 flex-column d-flex">
                                         <label style="padding-left: 5px" class="form-control-label">CPF/CNPJ<span class="text-danger"> *</span></label>
                                         <input onkeyup="atualizar_info_lado()" value="<?= $cpf_cnpj ?>" onBlur="this.value = this.value.toUpperCase();" required type="text" id="cpf_cnpj" name="cpf_cnpj" placeholder="">
                                       </div>
                                       
                                       <div class="form-group col-sm-6 flex-column d-flex">
                                          <label style="padding-left: 5px" class="form-control-label">E-Mail<span class="text-danger"> *</span></label>
                                          <input onkeyup="atualizar_info_lado()" value="<?= $email ?>" onBlur="this.value = this.value.toLowerCase();" required type="text" id="email" name="email" placeholder="">
                                       </div>
                                    </div>
                                    
                                    <div class="row justify-content-between text-left">
                                       <div class="form-group col-sm-6 flex-column d-flex">
                                         <label style="padding-left: 5px" class="form-control-label">Telefone<span class="text-danger"> *</span></label>
                                         <input onkeyup="atualizar_info_lado()" value="<?= $telefone ?>" required type="text" id="telefone" name="telefone" placeholder="">
                                       </div>
                                       <div class="form-group col-sm-6 flex-column d-flex">
                                         <label style="padding-left: 5px" class="form-control-label">Respons&aacute;vel</label>
                                         <input onkeyup="atualizar_info_lado()" value="<?= $responsavel ?>" onBlur="this.value = this.value.toUpperCase();" type="text" id="responsavel" name="responsavel" placeholder="">
                                       </div>
                                    </div>
                                       
                                    <div class="row justify-content-between text-left">
                                       <div class="form-group col-sm-6 flex-column d-flex">
                                         <label style="padding-left: 5px" class="form-control-label">Telefone Respons&aacute;vel</label>
                                         <input onkeyup="atualizar_info_lado()" value="<?= $telefone_responsavel ?>" onBlur="this.value = this.value.toUpperCase();" type="text" id="telefone_responsavel" name="telefone_responsavel" placeholder="">
                                       </div>
                                       
                                       <div class="form-group col-sm-6 flex-column d-flex">
                                         <label style="padding-left: 5px" class="form-control-label">Endere&ccedil;o<span class="text-danger"> *</span></label>
                                         <input onkeyup="atualizar_info_lado()" value="<?= $endereco ?>" onBlur="this.value = this.value.toUpperCase();" required type="text" id="endereco" name="endereco" placeholder="">
                                       </div>
                                    </div>   
                                    
                                    <div class="row justify-content-between text-left">
                                       <div class="form-group col-sm-6 flex-column d-flex">
                                         <label style="padding-left: 5px" class="form-control-label">Setor<span class="text-danger"> *</span></label>
                                         <input onkeyup="atualizar_info_lado()" value="<?= $setor ?>" onBlur="this.value = this.value.toUpperCase();" required type="text" id="setor" name="setor" placeholder="">
                                       </div>  
                                       <div class="form-group col-sm-6 flex-column d-flex">
                                         <label style="padding-left: 5px" class="form-control-label">Cidade<span class="text-danger"> *</span></label>
                                         <input onkeyup="atualizar_info_lado()" value="<?= $cidade ?>" onBlur="this.value = this.value.toUpperCase();" required type="text" id="cidade" name="cidade" placeholder="">
                                       </div>
                                    </div>
                                    
                                    <div class="row justify-content-between text-left">   
                                       <div class="form-group col-sm-6 flex-column d-flex">
                                         <label style="padding-left: 5px" class="form-control-label">Estado<span class="text-danger"> *</span></label>
                                         <input onkeyup="atualizar_info_lado()" value="<?= $estado ?>" onBlur="this.value = this.value.toUpperCase();" required type="text" id="estado" name="estado" placeholder="">
                                       </div>
                                       <div class="form-group col-sm-6 flex-column d-flex">
                                         <label style="padding-left: 5px" class="form-control-label">CEP</label>
                                         <input onkeyup="atualizar_info_lado()" value="<?= $cep ?>" onBlur="this.value = this.value.toUpperCase();" type="text" id="cep" name="cep" placeholder="">
                                       </div>
                                    </div>   
                                       
                                    <div class="row justify-content-between text-left">
                                       <div class="form-group col-12 flex-column d-flex">
                                          <label style="padding-left: 5px" class="form-control-label">Informaçoes Adicionais<span class="text-danger"> *</span></label>
                                          <textarea onkeyup="atualizar_info_lado()" required class="form-control" name="info" id="info" rows="3"><?= $info ?></textarea>
                                       </div>
                                    </div>
                                    
                                    <div class="row justify-content-between text-left">
                                       <div class="form-group col-12 flex-column d-flex">
                                          <table style="margin-top: 7px; margin-bottom: 7px">
                                          <tr><td width="2%"><input class="form-check-input" type="checkbox" <?= (($ambos == "3") ? ' checked ' : '') ?> $ambos  name="ambos" value="" id="ambos"></td>
                                          <td>
										  <label style="padding-left: 5px" class="form-control-label"><?= (($tipo == "1") ? 'Este cliente tamb&eacute;m &eacute; fornecedor?' : 'Este fornecedor tamb&eacute;m &eacute; cliente?') ?></label></td></tr></table>
                                          

                                       </div>
                                    </div>
                                       
                                    
                                    <div class="row justify-content-between text-left">
                                       <div class="form-group col-sm-6 flex-column d-flex">
                                         <label style="padding-left: 5px" class="form-control-label">Data de Cadastro<span class="text-danger"> *</span></label>
                                         <input required type="text" disabled="disabled" id="data_cadastro" value="<?= $data_cadastro ?>" name="data_cadastro" placeholder="">
                                       </div>
                                       <div class="form-group col-sm-6 flex-column d-flex">
                                           <label style="padding-left: 5px" class="form-control-label">Usu&aacute;rio Cadastro<span 
                                              class="text-danger"> *</span></label>
                                         <input required type="text" disabled="disabled" id="usuario_cadastro" 
                                              value="<?= obterNomeUsuarioId($usuario_cadastro) ?>" name="usuario_cadastro" placeholder="">
                                       </div>
                                    </div>
                                    
                                    <div class="row justify-content-end">
                                       <div class="form-group col-12 flex-column d-flex">
                                          <div class="btn-group" role="group">
                                            
                                            <?php if(Permissao::podeAlterar($_SESSION["nivel_acesso"])){ ?>
                                              <button type="submit" name="gravar" style="margin-right: 8px; width: 180px" 
                                              class="btn-secondary">Atualizar Dados</button>
                                            <?php } ?>
                                            
                                            <?php if(Permissao::podeExcluir($_SESSION["nivel_acesso"])){ ?>
                                              <button type="button" <?= ($usuario == "admin" ? 'disabled="disabled"' : '') ?> 
                                              onclick="excluir_registro('<?= $id_cliente_fornecedor ?>', '<?= $fantasia ?>')" name="excluir" 
                                              style="width: 180px" class="btn-secondary">Excluir <?= ($tipo == "1") ? 'Cliente' : 'Fornecedor' ?></button>
                                            <?php } ?> 
                                          
                                          </div>
                                          <input name="id_cliente_fornecedor" type="hidden" id="id_cliente_fornecedor" value="<?= $id_cliente_fornecedor ?>">
                                          <input name="foto" type="hidden" id="foto" value="<?= $foto_cliente_fornecedor ?>">
                                          <input name="tipo" type="hidden" id="tipo" value="<?= $tipo ?>">
                                       </div>
                                    </div>
                                    
                                    </form>
                                    
                                    </div>
                                </div>
                            </div>
                            <div class="col-xl-4">
                                <div class="card mb-4">
                                    <div class="card-header">
                                        <i class="bi-file-earmark-person"></i>
                                        Foto (Opcional)
                                    </div>
                                    <div class="card-body">
                                    
                                    <div style="background-image: url('imagens/fundo_fotos.jpg'); background-repeat: repeat-x; text-align:center" class="image_area">
								      <form method="post">
									    <label for="upload_image">
										   <img width="150px" src="<?= $foto ?>" id="uploaded_image" class="rounded-circle" style="width:200;" />
									     <div class="overlay">
											<div class="text">Click para trocar a imagem</div>
										  </div>
										<input type="file" name="image" class="image" id="upload_image" style="display:none" />
									    </label>
								      </form>
							        </div>
                                    
                                    <table width="100%">
                                      <tr>
                                        <td align="center"><span id="foto_cliente_fornecedor"></span></td>
                                      </tr>
                                      <tr>  
                                        <td align="center"><span id="foto_fantasia_cliente_fornecedor"><b><?= $fantasia ?></b></span></td>
                                      </tr>
                                      <tr>
                                        <td align="center"><span id="foto_cidade_estado_cliente_fornecedor"><?= $cidade . ' - ' . $estado ?></span></td>
                                      </tr>
                                      <tr>
                                        <td style="padding-top: 15px" align="center"><span id="foto_info_cliente_fornecedor"><?= $info ?></span></td>
                                      </tr>
                                    </table>
                                    
                                    </div>
                                </div>
                            </div>
                        </div>