<?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>Adicionar Produto</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;?>/updateproduct" id="form_validator">
        <div class="oculted">
          <span>
            <i>
              <div>
                <input type="hidden" name="id" value="<?= $productInfo['id']; ?>" >
              </div>
            </i>
          </span>
        </div>
        <div class="form-row">
          <div class="form-group col-md-1">
              <label for="">Status</label>
              <select name="status" class="form-control">
                <option <?= ($productInfo['status'] == 1)?'selected':''; ?> value="1" >Ativo</option>
                <option <?= ($productInfo['status'] != 1)?'selected':''; ?> value="2" >Inativo</option>
              </select>
            </div>

            <div class="form-group col-md-5" id="validate_name">
              <label for="">Descrição do produto (*)</label>
              <input type="text" class="form-control" name="name" data-rules="required" value="<?= $productInfo['name']; ?>">
            </div>

            <div class="form-group col-md-4" id="provider">
              <label for="">Fornecedor (*)</label>
              <select name="provider" class="form-control">
                <?php foreach($providers as $provider): ?>
                  <option value="<?= $provider['id'] ?>" <?= ($provider['id'] == $productInfo['id_provider'])?'selected':''; ?> ><?= $provider['company_name']; ?></option>
                <?php endforeach; ?>
              </select>
              <div class="pro_error"></div>
            </div>

            <div class="form-group col-md-2" id="validate_group">
              <label for="">Grupo (*)</label>
              <select name="group" class="form-control">
                <option value="0">Selecionar</option>
                <?php foreach($groups as $group): ?>
                  <option value="<?= $group['id'] ?>" <?= ($group['id'] == $productInfo['id_group'])?'selected':''; ?> ><?= $group['name']; ?></option>
                <?php endforeach; ?>
              </select>
              <div class="gro_error"></div>
            </div>

        </div>

        <div class="form-row">
          <div class="form-group col-md-2" id="validate_unity">
              <label for="">Unidade (*)</label>
              <select name="unity" class="form-control">
                <option value="0">Selecionar</option>
                <?php foreach($units as $unit): ?>
                  <option value="<?= $unit['id'] ?>" <?= ($unit['id'] == $productInfo['id_unity'])?'selected':''; ?> ><?= $unit['name']; ?></option>
                <?php endforeach; ?>
              </select>
              <div class="uni_error"></div>
            </div>

            <div class="form-group col-md-2" id="presentation">
              <label for="">Apresentação (*)</label>
              <select name="presentation" class="form-control">
                <option value="0">Selecionar</option>
                <?php foreach($presentations as $presentation): ?>
                  <option value="<?= $presentation['id'] ?>" <?= ($presentation['id'] == $productInfo['id_presentation'])?'selected':''; ?> ><?= $presentation['name']; ?></option>
                <?php endforeach; ?>
              </select>
              <div class="pre_error"></div>
            </div>

            <div class="form-group col-md-2">
              <label for="">Estoque</label>
              <input type="text" class="form-control" name="amount" readonly id="amount" value="<?= $productInfo['amount']; ?>">
            </div>

            <div class="form-group col-md-2" >
              <label for="">Preço de custo</label>
              <input type="text" class="form-control" name="cost_price" id="cost_price" value="<?= $productInfo['cost_price']; ?>">
            </div>

            <div class="form-group col-md-2" >
              <label for="">Preço de venda</label>
              <input type="text" class="form-control" name="price" id="price" value="<?= $productInfo['price']; ?>">
            </div>

            <div class="form-group col-md-2" >
              <label for="value_comission">% comissão</label>
              <input type="text" class="form-control" name="value_comission" id="value_comission" value="<?= $productInfo['comission_value']; ?>">
            </div>

            <div class="form-group col-md-4">
              <label for="">Observação</label>
              <textarea name="note" class="form-control" rows="6"><?= $productInfo['note']; ?></textarea>
            </div>
        </div> 

        <div class="button">
          <button type="submit" class="btn btn-success">Salvar</button>
          <a href="<?=$base;?>/products" class="btn btn-info">Voltar</a>
        </div>
        
      </form>
    </div>
    <script src="<?=$base;?>/assets/js/products.js"></script>
  </div>  		
</div>
<!-- /.content-system -->

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