<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<link href="<?php echo base_url('assets/css/datatables/dataTables.bootstrap.css') ?>" rel="stylesheet">

<section class="content-header">
    <h1><i class="fa fa-check-square-o"></i> <?php echo $page_title ?> <small><?php echo lang('list') ?></small></h1>
    <ol class="breadcrumb">
        <li><a href="<?php echo site_url('admin') ?>"><i class="fa fa-dashboard"></i> Dashboard</a></li>
        <li class="active"><?php echo lang('to_do_list') ?></li>
    </ol>
</section>

<section class="content">

<div class="box box-primary">
    <div class="box-header with-border">
        <h3 class="box-title"><i class="fa fa-check-square-o"></i> <?php echo lang('to_do_list') ?></h3>
        <div class="box-tools pull-right">
            <?php if(check_user_role(17)==1): ?>
            <a href="<?php echo site_url('admin/to_do_list/add') ?>" class="btn btn-primary btn-sm">
                <i class="fa fa-plus"></i> <?php echo lang('add_new') ?>
            </a>
            <?php endif; ?>
        </div>
    </div>
    <div class="box-body no-padding">
        <table id="example1" class="table table-hover" style="margin:0">
            <thead>
                <tr>
                    <th style="width:36px">#</th>
                    <th style="width:110px">Data</th>
                    <th>Título</th>
                    <th>Descrição</th>
                    <th style="width:120px">Ações</th>
                </tr>
            </thead>
            <tbody>
            <?php if(isset($lists)): $i=1; foreach($lists as $new):
                $vencido = strtotime($new->date) < strtotime(date('Y-m-d'));
                $hoje    = date('Y-m-d') === $new->date;
            ?>
            <tr class="<?php echo $hoje ? 'success' : ($vencido ? 'danger' : '') ?>">
                <td><?php echo $i++ ?></td>
                <td style="vertical-align:middle;white-space:nowrap">
                    <i class="fa fa-calendar-o text-muted" style="margin-right:5px"></i>
                    <small style="color:<?php echo $vencido&&!$hoje?'#c62828':'#555' ?>"><?php echo date_convert($new->date) ?></small>
                    <?php if($hoje): ?>
                    <span class="label label-success" style="font-size:9px;margin-left:3px">Hoje</span>
                    <?php elseif($vencido): ?>
                    <span class="label label-danger" style="font-size:9px;margin-left:3px">Vencido</span>
                    <?php endif; ?>
                </td>
                <td style="vertical-align:middle"><strong><?php echo htmlspecialchars($new->title) ?></strong></td>
                <td style="vertical-align:middle">
                    <small class="text-muted"><?php echo htmlspecialchars(mb_substr($new->description ?? '', 0, 80)) ?><?php echo mb_strlen($new->description ?? '') > 80 ? '...' : '' ?></small>
                </td>
                <td style="vertical-align:middle;white-space:nowrap">
                    <?php if(check_user_role(19)==1): ?>
                    <a href="<?php echo site_url('admin/to_do_list/view_to_do/'.$new->id) ?>" class="btn btn-xs btn-default" title="Ver"><i class="fa fa-eye"></i></a>
                    <?php endif; ?>
                    <?php if(check_user_role(18)==1): ?>
                    <a href="<?php echo site_url('admin/to_do_list/edit/'.$new->id) ?>" class="btn btn-xs btn-warning" title="Editar"><i class="fa fa-pencil"></i></a>
                    <?php endif; ?>
                    <?php if(check_user_role(20)==1): ?>
                    <a href="<?php echo site_url('admin/to_do_list/delete/'.$new->id) ?>" class="btn btn-xs btn-danger" onclick="return confirm('<?php echo lang('are_you_sure') ?>')" title="Excluir"><i class="fa fa-trash"></i></a>
                    <?php endif; ?>
                </td>
            </tr>
            <?php endforeach; endif; ?>
            </tbody>
        </table>
    </div>
</div>

</section>

<script src="<?php echo base_url('assets/js/plugins/datatables/jquery.dataTables.js') ?>"></script>
<script src="<?php echo base_url('assets/js/plugins/datatables/dataTables.bootstrap.js') ?>"></script>
<script>
$(function() {
    $('#example1').dataTable({
        order: [[1,'asc']],
        pageLength: 25,
        language: { url: '//cdn.datatables.net/plug-ins/1.10.21/i18n/Portuguese-Brasil.json' }
    });
});
</script>
