<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<style>
.detail-grid { display:grid; grid-template-columns:1fr 1fr; gap:0; }
.detail-item { padding:10px 16px; border-bottom:1px solid #f0f2f5; }
.detail-item.full { grid-column:1/-1; }
.detail-item .dl { font-size:10px; font-weight:700; color:#aaa; text-transform:uppercase; letter-spacing:.5px; display:block; margin-bottom:3px; }
.detail-item .dv { font-size:13px; color:#222; }
@media(max-width:767px){ .detail-grid{grid-template-columns:1fr} .detail-item.full{grid-column:1} }
</style>

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

<section class="content">
<div class="box box-primary">
    <div class="box-header with-border" style="background:linear-gradient(135deg,#1e3a5f,#2e75b6);border-radius:10px 10px 0 0">
        <h3 class="box-title" style="color:#fff"><i class="fa fa-check-square-o"></i> <?php echo htmlspecialchars($list->title ?? '') ?></h3>
    </div>
    <div class="box-body no-padding">
        <div class="detail-grid">
            <div class="detail-item">
                <span class="dl"><?php echo lang('name') ?></span>
                <span class="dv"><?php echo htmlspecialchars($list->title ?? '—') ?></span>
            </div>
            <div class="detail-item">
                <span class="dl"><?php echo lang('notification_date') ?></span>
                <span class="dv"><i class="fa fa-calendar-o"></i> <?php echo date_convert($list->date ?? '') ?></span>
            </div>
            <div class="detail-item full">
                <span class="dl"><?php echo lang('description') ?></span>
                <span class="dv" style="white-space:pre-wrap"><?php echo $list->description ?? '—' ?></span>
            </div>

            <?php
            // Campos personalizados
            $CI = get_instance();
            if(!empty($fields)):
                foreach($fields as $doc):
                    $result = $CI->db->query("SELECT * FROM rel_form_custom_fields WHERE custom_field_id='".$doc->id."' AND table_id='".$list->id."' AND form='".$doc->form."'")->row();
                    $reply = $result->reply ?? '';
            ?>
            <div class="detail-item">
                <span class="dl"><?php echo htmlspecialchars($doc->name) ?></span>
                <span class="dv">
                    <?php if($doc->field_type == 6 && !empty($reply)): ?>
                    <a href="<?php echo $reply ?>" target="_blank"><?php echo $reply ?></a>
                    <?php elseif($doc->field_type == 7 && !empty($reply)): ?>
                    <a href="mailto:<?php echo $reply ?>"><?php echo $reply ?></a>
                    <?php elseif($doc->field_type == 2 || $doc->field_type == 3 || $doc->field_type == 4): ?>
                    <?php
                        $values = explode(',', $doc->values ?? '');
                        $matched = '';
                        foreach($values as $val) if(trim($val) == $reply) $matched = trim($val);
                        echo htmlspecialchars($matched ?: '—');
                    ?>
                    <?php else: ?>
                    <?php echo htmlspecialchars($reply ?: '—') ?>
                    <?php endif; ?>
                </span>
            </div>
            <?php endforeach; endif; ?>
        </div>
    </div>
    <div class="box-footer">
        <a href="<?php echo site_url('admin/to_do_list') ?>" class="btn btn-default btn-sm"><i class="fa fa-arrow-left"></i> Voltar</a>
        <?php if(check_user_role(18)==1): ?>
        <a href="<?php echo site_url('admin/to_do_list/edit/'.$list->id) ?>" class="btn btn-warning btn-sm"><i class="fa fa-pencil"></i> Editar</a>
        <?php endif; ?>
    </div>
</div>
</section>
