<?php
require_once 'inc/local_estoque.php';

// print_r($local_estoque);
?>

    <div class="block">
      <div class="content controls">
        <div class="form-row">
          <div class="col-md-12">
            <label>Lista de Endereços</label>
          
            <div class="table-responsive">
            <table class="table table-stripped code-sortable itens-1-n" id="local_estoque" data-n="<?= count($local_estoque['itens']); ?>" data-order-by="0">
              <thead>
                <tr>
                  <th width="20%">Endereço</th>
                  <th width="30%">Descrição</th>
                  <th width="30%">Prioridade</th>
                  <th width="05%">Saldo</th>
                  
                  <th width="3%" class="text-center no-sort">Ativo</th>
                  <th width="3%" class="text-center no-sort">Excluir</th>
                </tr>
              </thead>
              <tbody>
                <?php
                for($i = 0; $i < count($local_estoque['itens']); $i++) {
                  $item = $local_estoque['itens'][$i];
                ?>
                <tr  class="settrcalculo">
                  <td><input type="text" name="local_estoque[itens][<?= $i; ?>][id]" class="form-control"  value="<?= sgcws_attr($item['id']); ?>" /></td>
                  <td><input type="text" name="local_estoque[itens][<?= $i; ?>][ds_endereco]" class="form-control" value="<?= sgcws_attr($item['ds_endereco']); ?>" /></td>
                  <td><input type="text" name="local_estoque[itens][<?= $i; ?>][ds_prioridade]" class="form-control" value="<?= sgcws_attr($item['ds_prioridade']); ?>" /></td>
                  <td></td>

                  <td class="text-center"><input required type="checkbox" name="local_estoque[itens][<?= $i; ?>][st_ativo]" class="form-control" <?= sgcws_attr($item['st_ativo']) ? 'checked' : ''; ?> /></td>
                  
                  <td class="text-center"><a class="item-delete" href="#"><span class="fa fa-trash"></span></a></td>
                </tr>
                <?php
                }
                // uma linha separada para um item novo
                $item = local_enderecos_create();
                ?>
                <tr  class="settrcalculo">
                  <td><input type="text" name="local_estoque[itens][<?= $i; ?>][id]" class="form-control"  value="<?= sgcws_attr($item['id']); ?>" /></td>
                  <td><input type="text" name="local_estoque[itens][<?= $i; ?>][ds_endereco]" class="form-control"  value="<?= sgcws_attr($item['ds_endereco']); ?>" /></td>
                  <td><input type="text" name="local_estoque[itens][<?= $i; ?>][ds_prioridade]" class="form-control"  value="<?= sgcws_attr($item['ds_prioridade']); ?>" /></td>
                  <td></td>

                  <td class="text-center"><input required type="checkbox" name="local_estoque[itens][<?= $i; ?>][st_ativo]" class="form-control" <?= sgcws_attr($item['st_ativo']) ? 'checked' : ''; ?> /></td>
                 
                  <td class="text-center"><a class="item-delete" href="#"><span class="fa fa-trash"></span></a></td>
                </tr>
              </tbody>
            </table>
            </div>
            <p>
              <a href="#" class="item-add pull-right" data-target="#local_estoque"><span class="fa fa-plus-circle"></span> Novo item</a>
            </p>
          </div>
        </div>
      </div> <!-- controls -->
    </div> <!-- block -->
