<?php echo Form::model($product, array('route' => array('admin.products.tables.store', $product->id))); ?>

<div class="row">
    <div class="col-sm-8">
        <div class="btn-group" role="group" aria-label="...">
            <button class="btn btn-sm btn-success"  data-target="#product-technical-table"  data-action="table-line-add">
                <i class="fa fa-plus"></i> Linha Simples
            </button>
            <button class="btn btn-sm btn-success" data-target="#product-technical-table"  data-action="table-line-add-title">
                <i class="fa fa-plus"></i> Linha de Título
            </button>
        </div>
        <button class="btn btn-sm btn-success" data-target="#product-technical-table" data-action="table-column-add">
            <i class="fa fa-plus"></i> Coluna
        </button>
        <div class="spacer-15"></div>
        <?php if(!$product->tables->isEmpty()): ?>
        <table class="table" id="product-technical-table">
            <?php foreach($product->tables as $key => $row): ?>
            <?php if($key == 0): ?>
            <tr>
                <td style="border-top: 0"></td>
                <?php for($i = 0 ; $i < count($row) ; $i++): ?>
                <td class="text-center" style="border-top: 0">
                    <a href="#" class="text-red text-center hidde" data-target="#product-technical-table" data-action="table-column-remove">
                        <i class="fa fa-trash bigger-120"></i> Eliminar Coluna
                    </a>
                </td>
                <?php endfor; ?>
            </tr>
            <?php endif; ?>
            <tr>
                <?php foreach($row as $key => $column): ?>
                <?php if($key == 0): ?>
                <?php if($column->th): ?>
                <td class="width-1" style="background: #ddd; font-weight: bold">
                <?php else: ?>
                <td class="width-1">
                <?php endif; ?>
                    <a href="#" class="text-red hidde" data-target="#product-technical-table" data-action="table-line-remove">
                        <i class="fa fa-trash bigger-120 margin-10"></i>
                    </a>
                </td>
                <?php endif; ?>
                
                <?php if($column->th): ?>
                <td style="background: #ddd; font-weight: bold">
                <?php else: ?>
                <td>
                <?php endif; ?>
                    <?php echo Form::hidden('th['.($column->row + 1).']['.($column->column + 1).']', $column->th, array('class' => 'form-control')); ?>

                    <div class="form-group">
                        <?php echo Form::text('content['.($column->row + 1).']['.($column->column + 1).']', $column->content, array('class' => 'form-control')); ?>

                    </div>
                </td>
                <?php endforeach; ?>
            </tr>
            <?php endforeach; ?>
        </table>
        <?php else: ?>
        <table class="table" id="product-technical-table">
            <tr>
                <td style="border-top: 0"></td>
                <td class="text-center" style="border-top: 0">
                    <a href="#" class="text-red text-center hidde" data-target="#product-technical-table" data-action="table-column-remove">
                        <i class="fa fa-trash bigger-120"></i> Eliminar Coluna
                    </a>
                </td>
            </tr>
            <tr>
                <td class="width-1" style="background: #ddd; font-weight: bold">
                    <a href="#" class="text-red hidde" data-target="#product-technical-table" data-action="table-line-remove">
                        <i class="fa fa-trash bigger-120 margin-10"></i>
                    </a>
                </td>
                <td style="background: #ddd; font-weight: bold">
                    <?php echo Form::hidden('th[0][0]', 1, array('class' => 'form-control')); ?>

                    <div class="form-group">
                        <?php echo Form::text('content[0][0]', null, array('class' => 'form-control')); ?>

                    </div>
                </td>
            </tr>
        </table>
        
        <?php endif; ?>
    </div>
</div>
<hr>    
<?php echo Form::submit('Gravar', array('class' => 'btn btn-primary', "data-loading-text" => "A Gravar..."  )); ?>

<?php echo Form::close(); ?>