<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<section class="content-header">
    <h1><i class="fa fa-tags"></i> Categorias Financeiras</h1>
</section>
<section class="content">
<div class="row">
    <div class="col-md-7">
        <div class="box box-primary">
            <div class="box-header"><h3 class="box-title">Categorias Cadastradas</h3></div>
            <div class="box-body no-padding">
                <table class="table table-hover">
                    <thead><tr><th>Categoria</th><th>Tipo</th><th>Ação</th></tr></thead>
                    <tbody>
                    <?php foreach($categorias as $cat): ?>
                    <tr>
                        <td><?php echo htmlspecialchars($cat->nome)?></td>
                        <td><span class="label label-<?php echo $cat->tipo==='receber'?'success':($cat->tipo==='pagar'?'danger':'info')?>"><?php echo $cat->tipo?></span></td>
                        <td>
                            <button class="btn btn-warning btn-xs btn-edit-cat" data-id="<?php echo $cat->id?>" data-nome="<?php echo htmlspecialchars($cat->nome)?>" data-tipo="<?php echo $cat->tipo?>">
                                <i class="fa fa-pencil"></i>
                            </button>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <div class="col-md-5">
        <div class="box box-success">
            <div class="box-header"><h3 class="box-title" id="cat-title">Nova Categoria</h3></div>
            <form method="post" action="<?php echo site_url('admin/financeiro/categorias')?>">
            <div class="box-body">
                <input type="hidden" name="id" id="cat-id" value="0">
                <div class="form-group">
                    <label>Nome</label>
                    <input type="text" name="nome" id="cat-nome" class="form-control" required>
                </div>
                <div class="form-group">
                    <label>Tipo</label>
                    <select name="tipo" id="cat-tipo" class="form-control">
                        <option value="receber">Receita</option>
                        <option value="pagar">Despesa</option>
                        <option value="ambos">Ambos</option>
                    </select>
                </div>
                <input type="hidden" name="submitted" value="1">
            </div>
            <div class="box-footer">
                <button type="submit" class="btn btn-success"><i class="fa fa-save"></i> Salvar</button>
            </div>
            </form>
        </div>
    </div>
</div>
</section>
<script>
$(function(){
    $('.btn-edit-cat').on('click',function(){
        $('#cat-id').val($(this).data('id'));
        $('#cat-nome').val($(this).data('nome'));
        $('#cat-tipo').val($(this).data('tipo'));
        $('#cat-title').text('Editar Categoria');
    });
});
</script>
