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

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