<h4 class="mb-4"><i class="fas fa-check-double me-2"></i><?= lang('admin.data_quality') ?></h4>
<div class="row g-3 mb-4">
    <div class="col-md-3"><div class="card border-primary h-100"><div class="card-body"><div class="d-flex justify-content-between"><div><h6 class="text-muted">Active Rules</h6><h3><?= $stats['total_rules'] ?></h3></div><i class="fas fa-ruler fa-2x text-primary opacity-50"></i></div></div></div></div>
    <div class="col-md-3"><div class="card border-warning h-100"><div class="card-body"><div class="d-flex justify-content-between"><div><h6 class="text-muted">Open Issues</h6><h3><?= $stats['open_issues'] ?></h3></div><i class="fas fa-exclamation-triangle fa-2x text-warning opacity-50"></i></div></div></div></div>
    <div class="col-md-3"><div class="card border-danger h-100"><div class="card-body"><div class="d-flex justify-content-between"><div><h6 class="text-muted">Critical</h6><h3><?= $stats['critical_issues'] ?></h3></div><i class="fas fa-fire fa-2x text-danger opacity-50"></i></div></div></div></div>
    <div class="col-md-3"><div class="card border-info h-100"><div class="card-body"><div class="d-flex justify-content-between"><div><h6 class="text-muted">Last Scan</h6><h5><?= $stats['last_scan'] ? format_datetime($stats['last_scan']['started_at']) : 'Never' ?></h5></div><i class="fas fa-search fa-2x text-info opacity-50"></i></div></div></div></div>
</div>
<div class="mb-3"><button class="btn btn-primary" id="btn-scan"><i class="fas fa-search me-1"></i>Run Scan Now</button></div>
<ul class="nav nav-tabs mb-3"><li class="nav-item"><a class="nav-link active" data-bs-toggle="tab" href="#tab-issues">Issues</a></li><li class="nav-item"><a class="nav-link" data-bs-toggle="tab" href="#tab-rules">Rules</a></li></ul>
<div class="tab-content">
    <div class="tab-pane fade show active" id="tab-issues"><div class="card"><div class="card-body">
        <table id="issues-table" class="table table-sm table-striped w-100" data-url="/admin/data-quality/issues/datatable"
               data-columns='[{"data":"rule"},{"data":"entity"},{"data":"field"},{"data":"issue"},{"data":"severity"},{"data":"status"},{"data":"detected"},{"data":"actions","orderable":false}]'>
            <thead><tr><th>Rule</th><th>Entity</th><th>Field</th><th>Issue</th><th>Severity</th><th>Status</th><th>Detected</th><th>Actions</th></tr></thead>
        </table>
    </div></div></div>
    <div class="tab-pane fade" id="tab-rules"><div class="card"><div class="card-body">
        <table id="rules-table" class="table table-sm table-striped w-100" data-url="/admin/data-quality/rules/datatable"
               data-columns='[{"data":"code"},{"data":"name"},{"data":"entity"},{"data":"type"},{"data":"severity"},{"data":"active"}]'>
            <thead><tr><th>Code</th><th>Name</th><th>Entity</th><th>Type</th><th>Severity</th><th>Active</th></tr></thead>
        </table>
    </div></div></div>
</div>
<?php $__view->push('scripts') ?>
<script>
DataTableHelper.init('issues-table');DataTableHelper.init('rules-table',{paging:false});
$('#btn-scan').click(function(){const btn=$(this);btn.prop('disabled',true).html('<i class="fas fa-spinner fa-spin me-1"></i>Scanning...');$.post('/admin/data-quality/scan',{_token:'<?= csrf_token() ?>'},function(r){btn.prop('disabled',false).html('<i class="fas fa-search me-1"></i>Run Scan Now');if(r.success){FormHelper.showToast('success',r.message);DataTableHelper.reload('issues-table');}else FormHelper.showToast('error',r.message);},'json');});
$(document).on('click','.btn-issue-action',function(){$.post('/admin/data-quality/issues/'+$(this).data('id')+'/action',{_token:'<?= csrf_token() ?>',action:$(this).data('action')},function(r){if(r.success){FormHelper.showToast('success',r.message);DataTableHelper.reload('issues-table');}else FormHelper.showToast('error',r.message);},'json');});
</script>
<?php $__view->endPush() ?>