<div class="d-flex justify-content-between align-items-center mb-4">
    <h4 class="mb-0"><i class="fas fa-bullhorn me-2"></i><?= lang('comm.bulk_communications') ?></h4>
    <?php if (Gate::can('notifications.bulk')): ?>
    <a href="/communications/bulk/create" class="btn btn-primary"><i class="fas fa-plus me-1"></i><?= lang('comm.create_bulk') ?></a>
    <?php endif; ?>
</div>
<div class="card"><div class="card-body">
    <table id="bulk-table" class="table table-striped table-hover w-100"
           data-url="/communications/api/bulk/datatable"
           data-columns='<?= json_encode([
               ["data"=>"id","title"=>"#","width"=>"50px"],
               ["data"=>"campaign_name","title"=>"Campaign"],
               ["data"=>"channel_name","title"=>"Channel"],
               ["data"=>"total_recipients","title"=>"Recipients"],
               ["data"=>"status","title"=>"Status"],
               ["data"=>"created_at","title"=>"Created"],
               ["data"=>"id","title"=>"Actions","orderable"=>false,"searchable"=>false]
           ]) ?>'>
        <thead><tr><th>#</th><th>Campaign</th><th>Channel</th><th>Recipients</th><th>Status</th><th>Created</th><th>Actions</th></tr></thead>
    </table>
</div></div>

<?php $__view->push('scripts') ?>
<script>
$(function(){
    DataTableHelper.init('bulk-table', {
        columnDefs: [
            { targets: 3, render: function(d){ return '<span class="badge bg-primary">'+d+'</span>'; }},
            { targets: 4, render: function(d){
                var map = {draft:'secondary',scheduled:'info',sending:'warning',completed:'success',paused:'warning',cancelled:'danger'};
                return '<span class="badge bg-'+(map[d]||'secondary')+'">'+d+'</span>';
            }},
            { targets: 5, render: function(d){ return d ? new Date(d).toLocaleString() : ''; }},
            { targets: 6, render: function(d){ return '<a href="/communications/bulk/'+d+'" class="btn btn-outline-primary btn-sm"><i class="fas fa-eye"></i></a>'; }}
        ]
    });
});
</script>
<?php $__view->endPush() ?>