<div class="d-flex justify-content-between align-items-center mb-4">
    <h4 class="mb-0"><i class="fas fa-broadcast-tower me-2"></i><?= lang('comm.channels') ?></h4>
    <?php if (Gate::can('notifications.send')): ?>
    <a href="/communications/channels/create" class="btn btn-primary"><i class="fas fa-plus me-1"></i><?= lang('common.create') ?></a>
    <?php endif; ?>
</div>

<div class="card">
    <div class="card-body">
        <table id="channels-table" class="table table-striped table-hover w-100"
               data-url="/communications/api/channels/datatable"
               data-columns='<?= json_encode([
                   ["data" => "id", "title" => "#", "width" => "50px"],
                   ["data" => "channel_code", "title" => "Code"],
                   ["data" => "name_en", "title" => "Name"],
                   ["data" => "channel_type", "title" => "Type"],
                   ["data" => "provider", "title" => "Provider"],
                   ["data" => "is_active", "title" => "Active"],
                   ["data" => "id", "title" => "Actions", "orderable" => false, "searchable" => false]
               ]) ?>'>
            <thead><tr><th>#</th><th>Code</th><th>Name</th><th>Type</th><th>Provider</th><th>Active</th><th>Actions</th></tr></thead>
        </table>
    </div>
</div>

<?php $__view->push('scripts') ?>
<script>
$(function(){
    DataTableHelper.init('channels-table', {
        columnDefs: [
            { targets: 3, render: function(d){ return '<span class="badge bg-info">'+d+'</span>'; }},
            { targets: 5, render: function(d){ return d == 1 ? '<span class="badge bg-success">Active</span>' : '<span class="badge bg-secondary">Inactive</span>'; }},
            { targets: 6, render: function(d){
                return '<a href="/communications/channels/'+d+'/edit" class="btn btn-outline-primary btn-sm"><i class="fas fa-edit"></i></a>';
            }}
        ]
    });
});
</script>
<?php $__view->endPush() ?>