<div class="d-flex justify-content-between align-items-center mb-4">
    <h4 class="mb-0"><i class="fas fa-bolt me-2"></i><?= lang('comm.triggers') ?></h4>
    <?php if (Gate::can('notifications.send')): ?>
    <a href="/communications/triggers/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="triggers-table" class="table table-striped table-hover w-100"
           data-url="/communications/api/triggers/datatable"
           data-columns='<?= json_encode([
               ["data"=>"id","title"=>"#","width"=>"50px"],
               ["data"=>"trigger_code","title"=>"Code"],
               ["data"=>"trigger_name_en","title"=>"Name"],
               ["data"=>"module","title"=>"Module"],
               ["data"=>"event_type","title"=>"Event"],
               ["data"=>"template_name","title"=>"Template"],
               ["data"=>"is_active","title"=>"Active"],
               ["data"=>"id","title"=>"Actions","orderable"=>false,"searchable"=>false]
           ]) ?>'>
        <thead><tr><th>#</th><th>Code</th><th>Name</th><th>Module</th><th>Event</th><th>Template</th><th>Active</th><th>Actions</th></tr></thead>
    </table>
</div></div>

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