<div class="card-block">
    <h2 class="card-title">Listagem de Check list</h2>
    <div align="right">
        <button data-toggle="modal" data-target="#adicionarCheckList" class="btn btn-s-md btn-success"><i
                    class="fa fa-user-plus fa-2x"></i> Adicionar
        </button>
    </div>
</div>

<?php foreach ($checkslists as $r) { ?>
    <div class="card">
        <div class="card-header">
            <a class="btn-minimize" style="font-size: larger" data-perform="card-collapse">
                <i class="ti-minus"></i> <?php echo $r->ID_CHECKLIST . ' - ' . strtoupper($r->DS_DESCRICAO) . ' - ' . $r->DS_CRITICIDADE . ' - ' . $r->DS_VEICULOS ?>
            </a>
            <div class="card-actions">
                <a id="btnAdicionarItemCheckList" data-toggle="modal" checkList_id="<?php echo $r->ID_CHECKLIST ?>"
                   data-target="#adicionarItemCheckList" class="btn btn-success btn-circle"><i
                            class="fa fa-plus"></i></a>
                <button class="btn btn-info btn-circle"><i class="fa fa-pencil"></i></button>
                <button checklist="<?php echo $r->ID_CHECKLIST ?>" data-toggle="modal"
                   data-target="#modalExluirItem" class="btn btn-danger btn-circle" <?php empty($r->ITENS_CHECKLIST)?"disabled":""?> ><i
                            class="fa fa-trash-o"></i></button>
                <a class="btn-close"><i class="ti-close"></i></a>
            </div>
        </div>
        <div class="card-block collapse" aria-expanded="true">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-block">
                        <div class="table-responsive">
                            <table class="table full-color-table full-success-table hover-table">
                                <thead>
                                <tr align="center">
                                    <th>#</th>
                                    <th>Descrição</th>
                                    <th>Utilizado</th>
                                    <th>Prioridade</th>
                                    <th>Ações</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php if ($r->ITENS_CHECKLIST) { ?>
                                    <?php foreach ($r->ITENS_CHECKLIST as $i) { ?>
                                        <tr>
                                            <td><?php echo $i->ID_ITEM_CHECKLIST ?></td>
                                            <td><?php echo $i->DESCRICAO_ITEM ?></td>
                                            <td><?php echo $i->DS_PRIORIADE_ITEM ?></td>
                                            <td>
                                                <select class="selectpicker m-b-20 m-r-10" data-style="btn-primary">
                                                    <option data-tokens="ketchup mustard"><?php echo $i->DS_CRITICIDADE ?></option>
                                                    <option data-tokens="ketchup mustard">Alta</option>
                                                    <option data-tokens="ketchup mustard">Média</option>
                                                    <option data-tokens="ketchup mustard">Baixa</option>
                                                </select>

                                            </td>
                                            <td align="center">
                                                <button class="btn btn-secondary btn-circle"
                                                   checklistItem="<?php echo $i->ID_ITEM_CHECKLIST ?>"
                                                   data-toggle="modal" data-target="#modalExluirItem"><i
                                                            class="fa fa-trash"></i> </button>
                                            </td>
                                        </tr>
                                    <?php }
                                } else { ?>
                                    <tr align="center">
                                        <td colspan="5">Nenhum Registro Encontrado !!!</td>
                                    </tr>
                                <?php } ?>

                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
<?php } ?>

<?php $this->load->view("sistema/modais/checklists/adicionarCheckListModal"); ?>
<?php $this->load->view("sistema/modais/checklists/adicionarItensCheckListModal"); ?>
<?php $this->load->view("sistema/modais/exluirItemGerericosModal"); ?>


<script type="text/javascript">
    $(document).on('click', 'a', function (event) {
        $('#idCheckList').val($(this).attr('checkList_id'));
    });

    $(document).on('click', 'button', function (event) {
        if ($(this).attr('checklist')) {
            $('#idItemExcluir').val($(this).attr('checklist'));
            $("#excluirItem").attr("action", "<?php echo base_url() ?>checklists/excluirCheckList");
        }
        if ($(this).attr('checklistItem')) {
            $('#idItemExcluir').val($(this).attr('checklistItem'));
            $("#excluirItem").attr("action", "<?php echo base_url() ?>checklists/excluirItem");
        }
    });

</script>

