<div class="d-flex justify-content-between align-items-center mb-4">
    <h4 class="mb-0"><i class="fas fa-envelope me-2"></i><?= lang('comm.email_log') ?></h4>
</div>
<div class="card"><div class="card-body">
    <table id="email-log-table" class="table table-striped table-hover w-100"
           data-url="/communications/api/email-log/datatable"
           data-columns='<?= json_encode([
               ["data"=>"id","title"=>"#","width"=>"50px"],
               ["data"=>"to_address","title"=>"To"],
               ["data"=>"subject","title"=>"Subject"],
               ["data"=>"status","title"=>"Status"],
               ["data"=>"sent_at","title"=>"Sent"],
               ["data"=>"created_at","title"=>"Created"]
           ]) ?>'>
        <thead><tr><th>#</th><th>To</th><th>Subject</th><th>Status</th><th>Sent</th><th>Created</th></tr></thead>
    </table>
</div></div>

<?php $__view->push('scripts') ?>
<script>
$(function(){
    DataTableHelper.init('email-log-table', {
        columnDefs: [
            { targets: 2, render: function(d){ return d ? d.substring(0,50)+(d.length>50?'...':'') : '-'; }},
            { targets: 3, render: function(d){
                var map = {queued:'warning',sent:'info',delivered:'success',bounced:'danger',failed:'danger'};
                return '<span class="badge bg-'+(map[d]||'secondary')+'">'+d+'</span>';
            }},
            { targets: [4,5], render: function(d){ return d ? new Date(d).toLocaleString() : '-'; }}
        ]
    });
});
</script>
<?php $__view->endPush() ?>