<?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 Vendedor</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;?>/updatesalesman" 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 Vendedor</h4>
          <div class="form-row">
            <div class="form-group col-md-1">
                <label for="inputStatus">Status</label>
                <select class="form-control" name="status">
                  <option <?= ($form['status'] == 1)?'selected':''; ?> value="1" >Ativo</option>
                  <option <?= ($form['status'] != 1)?'selected':''; ?> value="2" >Inativo</option>
                </select>
              </div>

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

            <div class="form-group col-md-2" id="validate_cpf_cnpj">
                <label for="inputCpfCnpj">CPF / CNPJ</label>
                <input type="text" class="form-control" id="cnpj" data-rules="cnpj" name="cnpj" placeholder="00.000.000/0000-00" value="<?= $form['cnpj']; ?>">
                <input type="text" class="form-control" id="cpf" data-rules="cpf" name="cpf" placeholder="000.000.000-00" value="<?= $form['cpf']; ?>">
                <div class="val_salesman"></div>
            </div>

            <div class="form-group col-md-4" id="validate_name">
                <label for="inputName">Nome (*)</label>
                <input type="text" class="form-control" id="inputName" data-rules="required" name="name"  placeholder="Vendedor xyz" value="<?= $form['name']; ?>">
              </div>        

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

            <div class="form-group col-md-2">
                <label for="inputSecondPhone">Celular 02</label>
                <input type="text" class="form-control" id="inputFirstPhone" data-rules="phonecel" name="second_phone" placeholder="(00) 00000-0000" value="<?= $form['second_phone']; ?>">
            </div>              
          </div>

            <div class="form-row">
              <div class="form-group col-md-3" id="validade_email">
                  <label for="inputEmail">E-mail</label>
                  <input type="email" class="form-control" id="inputEmail" data-rules="email" name="email" placeholder="email@dominio.com.br" value="<?= $form['email']; ?>">
              </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" id="inputBirtDate" name="birthdate" placeholder="00/00/0000" value="<?= $form['birth_date']; ?>">
              </div>

              <div class="form-group col-md-3">
                  <label for="data_bank">Dados bancários</label>
                  <textarea class="form-control" id="data_bank" rows="8" name="data_bank" placeholder="Informações bancárias do Vendedor..."><?= $form['bank_data']; ?></textarea>
              </div>

              <div class="form-group col-md-4">
                  <label for="inputNote">OBS</label>
                  <textarea class="form-control" id="inputNote" rows="8" name="note" placeholder="Observação sobre o Vendedor..."><?= $form['note']; ?></textarea>
              </div>
            </div>

            <div class="form-row coluns-2">

              <div>
                <h4>Região de atuação</h4>
                <div class="form-row">

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

                  <div class="form-group col-md-4">
                      <label for="inputCity">Cidade</label>
                      <select name="city" class="form-control"  id="inputCity">
                        
                      </select>           
                  </div>

                  <div class="form-group add_are">
                    <label></label>
                    <a href="#" id="add_are" class="btn btn-primary">adicionar</a>
                  </div>                  
                </div>

                <div class="form-row">
                  <div class="form-group col-md-6">
                      <label for="operational_area">Região de atuação</label>
                      <textarea class="form-control" id="operational_area" rows="8" name="operational_area" placeholder="Região de atuação..."><?= $form['operational_area']; ?></textarea>
                  </div>
                </div>

              </div>

              <div>
                <h4>% Comissão</h4>
                <div class="form-row">
                  <div class="form-group col-md-6">
                    <label for="inputState">fornecedor</label>
                    <select class="form-control" name="provider" id="inputProvider">
                      <option value="">selecionar</option>
                      <?php foreach($providers as $provider): ?>
                        <option value="<?= $provider['id']; ?>"><?= $provider['company_name']; ?></option>
                      <?php endforeach; ?>
                    </select>
                  </div>

                  <div class="form-group col-md-2">
                    <label>Comisão</label>
                    <input type="text" name="comission_percent" id="ss_comission" class="form-control">
                  </div>

                  <div class="form-group col-md-1" style="display: flex; align-items: end;">
                    <span class="btn btn-primary" id="save_comission">salvar</span>
                  </div>

                </div>

                <div class="form-row">
                  <div class="form-group col-md-10">
                      <label for="comission_values">Comissões Cadastradas</label>
                      <textarea class="form-control" id="comission_values" rows="8" name="comission_values" placeholder="Região de atuação..."><?= $comission; ?></textarea>
                  </div>
                </div>

              </div>

            </div>                  
        </div>

        <div class="button">
          <button type="submit" class="btn btn-success">Salvar</button>
          <a href="<?=$base;?>/salesman" class="btn btn-info">Voltar</a>
        </div>
        
      </form>
    </div>

    <div class="message-add" id="show-msg-add"></div>

    <script src="<?=$base;?>/assets/js/salesman.js"></script>
  </div>  		
</div>
<!-- /.content-system -->

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