<?php $render('header', ['loggedUser'=>$loggedUser, 'title'=>$titlePage]); ?>
<?=$render('sidebar', [
  'loggedUser'=>$loggedUser, 
  'pageActive'=>$pageActive,
  'permissions'=>$permissions
]);?>

<!-- Content System -->
<div class="content-wrapper">
  <div class="pages">
    
    <h3>Editar Cliente</h3>
    <div class="users">
      <!-- Message -->

      <?php if(!empty($error)): ?>
        <div class="alert <?=$error['alertType'];?>" role="alert">
          <?php echo $error['msg']; ?>
        </div>
      <?php endif; ?>

      <!-- /Message -->
      <form method="POST" action="<?=$base;?>/updateclient" id="form_validator">        
        <div class="oculted">
          <span>
            <i>
              <div>
                <input type="hidden" name="type_view" value="edit">
                <input type="hidden" name="id" value="<?= $form['id']; ?>" >
              </div>
            </i>
          </span>
        </div>
        <!-- Dados do usuário -->
        <div class="client-data">
          <h4>Dados do Cliente</h4>
          <div class="form-row">
            <div class="form-group col-md-1">
                <label for="inputStatus">Status</label>
                <select class="form-control" name="status">
                  <option value="1" <?= ($form['status'] == 1)?'selected':''; ?> >Ativo</option>
                  <option value="2" <?= ($form['status'] != 1)?'selected':''; ?> >Inativo</option>
                </select>
            </div>

            <div class="form-group col-md-1">
              <label for="inputClassification">Classificação</label>
              <select class="form-control" name="classification" id="inputClassification">
                  <option value="GOLD" <?= ($form['classification'] == 'GOLD' )?'selected':''; ?> >GOLD</option>
                  <option value="MASTER" <?= ($form['classification'] == 'MASTER' )?'selected':''; ?> >MASTER</option>
                  <option value="CLASSIC" <?= ($form['classification'] == 'CLASSIC' )?'selected':''; ?> >CLASSIC</option>
                  <option value="PRATA" <?= ($form['classification'] == 'PRATA' )?'selected':''; ?> >PRATA</option>
                  <option value="BRONZE" <?= ($form['classification'] == 'BRONZE' )?'selected':''; ?> >BRONZE</option>
              </select>
            </div>

              <div class="form-group col-md-1">
                <label for="inputTypeClient">Tipo (*)</label>
                <select class="form-control" name="type" id="inputTypeClient" required>
                    <option value="1" <?= ($form['type'] == 1)?'selected':''; ?> >PF</option>
                    <option value="2" <?= ($form['type'] == 2)?'selected':''; ?> >PJ</option>
                </select>
              </div>

              <div class="form-group col-md-2">
                <label for="inputRg">RG</label>
                <input type="text" class="form-control" <?= ($form['type'] == 2)?'disabled':''; ?> id="inputRg" name="rg" placeholder="0000000" value="<?php echo (!empty($form))?$form['rg']:''; ?>">
            </div>

            <div class="form-group col-md-2" id="add_cpf_cnpj">
                <label for="inputCpfCnpj">CPF / CNPJ (*)</label>
                <input type="text" class="form-control" id="cnpj" name="cnpj" placeholder="00.000.000/0000-00" value="<?php echo (!empty($form))?$form['cnpj']:''; ?>">
                <input type="text" class="form-control" id="cpf" name="cpf" placeholder="000.000.000-00" value="<?php echo (!empty($form))?$form['cpf']:''; ?>">
            </div>

            <div class="form-group col-md-2" id="validate_birth_date">
                <label for="inputBirtDate">Data de nascimento</label>
                <input type="text" class="form-control" <?= ($form['type'] == 2)?'disabled':''; ?> id="inputBirtDate" name="birthdate" placeholder="00/00/0000" value="<?php echo (!empty($form))?$form['birth_date']:''; ?>">
            </div>

            <div class="form-group col-md-3" id="validate_name">
                <label for="inputName">Nome / Razão Social (*)</label>
                <input type="text" class="form-control" id="inputName" name="name" data-rules="required" required placeholder="Fazenda Flor do Dia" value="<?php echo (!empty($form))?$form['name']:''; ?>">
              </div>
              
          </div>

          <div class="form-row">

            <div class="form-group col-md-2" id="validade_email">
                <label for="inputEmail">E-mail</label>
                <input type="email" class="form-control" id="inputEmail" name="email" data-rules="email" placeholder="email@dominio.com.br" value="<?php echo (!empty($form))?$form['email']:''; ?>">
            </div>

            <div class="form-group col-md-1">
                <label for="inputCep">CEP</label>
                <input type="text" class="form-control" id="inputCep" name="cep" placeholder="00000-000" value="<?php echo (!empty($form))?$form['cep']:''; ?>">
            </div>

              <div class="form-group col-md-2">
                <label for="inputPublicPlace">Logradouro</label>
                <input type="text" class="form-control" id="inputPublicPlace" name="public_place" placeholder="Av. Novo Mundo" value="<?php echo (!empty($form))?$form['public_place']:''; ?>">
            </div>

            <div class="form-group col-md-1">
                <label for="inputState">Estado (*)</label>
                <select class="form-control" name="state" id="inputState">
                  <?php foreach($states as $state): ?>
                    <option value="<?php echo $state['uf']; ?>" <?php echo (!empty($form) && $form['state'] == $state['uf'])?'selected':'' ?> ><?php echo $state['uf']; ?></option>
                  <?php endforeach; ?>
                </select>
            </div>

            <div class="form-group col-md-2">
                <label for="inputCity">Cidade (*)</label>
                <select name="city" class="form-control" required id="inputCity">
                  <option value="<?=$form['city'];?>"><?=$form['city_name'];?></option>
                </select>
                <div class="errorc"></div>
            </div>

            <div class="form-group col-md-2">
                <label for="inputFirstPhone">Fone Celular</label>
                <input type="text" class="form-control" id="inputFirstPhone" data-rules="phonecel" name="first_phone" placeholder="(00) 00000-0000" value="<?php echo (!empty($form))?$form['first_phone']:''; ?>">
            </div>

            <div class="form-group col-md-2">
                <label for="inputSecondPhone">Fone Fixo</label>
                <input type="text" class="form-control" id="inputSecondPhone" data-rules="phonefix" name="second_phone" placeholder="(00) 0000-0000" value="<?php echo (!empty($form))?$form['second_phone']:''; ?>">
            </div>

          </div>

          <div class="form-row">

            <div class="form-group col-md-2">
              <label for="inputCategory">Categoria</label>

              <select name="category" class="form-control" id="inputCategory">
                <option <?= ($form['category'] == '3')?'selected':''; ?> value="3">Ambos</option>
                <option <?= ($form['category'] == '1')?'selected':''; ?> value="1">Genética</option>
                <option <?= ($form['category'] == '2')?'selected':''; ?> value="2">Insumos</option> 
              </select>
            </div>

            <div class="form-group col-md-2">
              <label for="inputSalesman">Vendedor Responsável</label>

              <select name="salesman" class="form-control" id="inputSalesman">
                <option value="" >Selecionar</option>
                <?php foreach($salesman as $item): ?>
                  <option value="<?= $item['id']; ?>" <?= ($form['id_salesman'] == $item['id'])?'selected':'' ?> ><?= $item['name']; ?></option>
                <?php endforeach; ?>
              </select>
            </div>

            <div class="form-group col-md-5">
                <label for="inputNote">Observação</label>
                <textarea class="form-control" id="inputNote" rows="8" name="note" placeholder="Observação sobre o Cliente..."><?= (!empty($form))?$form['note']:''; ?></textarea>
            </div>
              
          </div>
            
        </div>
        
        <!-- Dados do Comprador -->
        <div class="buyer-data">
          <h4>Dados do Comprador</h4>
          <div class="form-group">
              <div class="form-check">
                <input class="form-check-input" type="checkbox" id="gridCheck">
                <label class="form-check-label" for="gridCheck">
                  O próprio
                </label>
              </div>
          </div>

            <div class="form-row">
              <div class="form-group col-md-3">
                <label for="inputBuyerName">Nome</label>
                <input type="text" class="form-control" id="inputBuyerName" name="buyer_name" placeholder="Nome do Comprador" value="<?php echo (!empty($form))?$form['buyer']:''; ?>">
            </div>

            <div class="form-group col-md-3">
                <label for="inputBuyerPhone">Celular/fixo</label>
                <input type="text" class="form-control" name="buyer_phone" placeholder="(00) 00000-0000" value="<?php echo (!empty($form))?$form['buyer_phone']:''; ?>">
            </div>  

            <div class="form-group col-md-3">
                <label for="inputBuyerEmail">E-mail</label>
                <input type="email" class="form-control" id="inputBuyerEmail" name="buyer_email" placeholder="email@dominio.com.br" value="<?php echo (!empty($form))?$form['buyer_email']:''; ?>">
            </div>  

            <div class="form-group col-md-3" id="validate_buyer_birth_date">
                <label for="inputBuyerBirtDate">Data de nascimento</label>
                <input type="text" class="form-control" id="inputBuyerBirtDate" name="buyer_birthdate" placeholder="00/00/0000" value="<?php echo (!empty($form))?$form['buyer_birth_date']:''; ?>">
            </div>  
            </div>
          
        </div>
        
        <div class="button">
            <button type="submit" class="btn btn-success">Salvar</button>
            <a href="<?=$base;?>/clients" class="btn btn-info">Voltar</a>
        </div>
        
      </form>
    </div>
    <script src="<?=$base; ?>/assets/js/clients.js"></script>
  </div>  		
</div>
<!-- /.content-system -->

<?=$render('footer');?>