{{-- resources/views/superadmin/proactive/command/rules.blade.php --}} @extends('layouts.superadmin') @section('title', 'ProActive — قواعد القيادة') @section('page-title', 'قواعد القيادة (Rules)') @section('content') @php use Illuminate\Support\Facades\Route; /* ✅ safe_route داخل نفس الـView */ if (!function_exists('safe_route')) { function safe_route(string $name, array $params = [], bool $absolute = true, string $fallback = '#'): string { try { return Route::has($name) ? route($name, $params, $absolute) : $fallback; } catch (\Throwable $e) { return $fallback; } } } /* ✅ getter آمن object/array */ if (!function_exists('getv')) { function getv($src, string $key, $default = null) { if (is_array($src)) return array_key_exists($key,$src) ? $src[$key] : $default; if (is_object($src)) return isset($src->{$key}) ? $src->{$key} : $default; return $default; } } $qs = request()->query(); $q = fn($k,$d=null) => request()->get($k,$d); $view = (string)($view ?? $q('view','cards')); // cards|table $scope = (string)($scope ?? $q('scope','all')); // all|active|paused|system|custom $search = trim((string)($search ?? $q('search',''))); if(!in_array($view,['cards','table'],true)) $view='cards'; if(!in_array($scope,['all','active','paused','system','custom'],true)) $scope='all'; // items: rules list (Collection/Paginator/array) // Expected fields (مرن): // id, title, rule_key, description, level (info|warn|hard), scope (system|custom), // is_enabled, priority, when_json, action_json, created_at, updated_at, hits_7d, hits_30d $items = $items ?? collect(); $stats = $stats ?? [ 'total' => (int)($totalCount ?? (method_exists($items,'total') ? $items->total() : (method_exists($items,'count') ? $items->count() : (is_array($items)?count($items):0)))), 'active' => (int)($activeCount ?? 0), 'paused' => (int)($pausedCount ?? 0), 'system' => (int)($systemCount ?? 0), 'custom' => (int)($customCount ?? 0), ]; $rCommand = safe_route('superadmin.proactive.command', [], true, url('/superadmin/proactive/command')); $rRules = safe_route('superadmin.proactive.rules', [], true, url()->current()); $chip = fn($cls) => "px-2.5 py-1 rounded-xl border text-[11px] font-extrabold $cls"; $scopeBtn = function($key, $label, $count, $activeCls, $idleCls) use ($scope,$qs,$rRules){ $url = $rRules.'?'.http_build_query(array_merge($qs, ['scope'=>$key])); return ['url'=>$url,'cls'=>($scope===$key ? $activeCls : $idleCls),'label'=>$label,'count'=>$count]; }; $scopes = [ $scopeBtn('all','الكل', (int)($stats['total'] ?? 0), 'border-amber-400/40 bg-amber-500/15 text-amber-100', 'border-white/10 bg-white/5 text-white/80 hover:text-white hover:bg-white/10'), $scopeBtn('active','نشط', (int)($stats['active'] ?? 0), 'border-emerald-400/40 bg-emerald-500/15 text-emerald-100', 'border-white/10 bg-white/5 text-white/80 hover:text-white hover:bg-white/10'), $scopeBtn('paused','موقوف', (int)($stats['paused'] ?? 0), 'border-rose-400/40 bg-rose-500/15 text-rose-100', 'border-white/10 bg-white/5 text-white/80 hover:text-white hover:bg-white/10'), $scopeBtn('system','نظام', (int)($stats['system'] ?? 0), 'border-fuchsia-400/40 bg-fuchsia-500/15 text-fuchsia-100', 'border-white/10 bg-white/5 text-white/80 hover:text-white hover:bg-white/10'), $scopeBtn('custom','مخصص', (int)($stats['custom'] ?? 0), 'border-cyan-400/40 bg-cyan-500/15 text-cyan-100', 'border-white/10 bg-white/5 text-white/80 hover:text-white hover:bg-white/10'), ]; $lvlBadge = function($lvl) use ($chip){ $lvl = (string)$lvl; if($lvl==='hard') return $chip('border-rose-400/25 bg-rose-500/10 text-rose-100'); if($lvl==='warn') return $chip('border-amber-400/25 bg-amber-500/10 text-amber-100'); return $chip('border-cyan-400/25 bg-cyan-500/10 text-cyan-100'); // info }; $scopeBadge = function($s) use ($chip){ $s = (string)$s; if($s==='system') return $chip('border-fuchsia-400/25 bg-fuchsia-500/10 text-fuchsia-100'); if($s==='custom') return $chip('border-cyan-400/25 bg-cyan-500/10 text-cyan-100'); return $chip('border-white/10 bg-white/5 text-white/70'); }; $onBadge = function($on) use ($chip){ return $on ? $chip('border-emerald-400/25 bg-emerald-500/10 text-emerald-100') : $chip('border-rose-400/25 bg-rose-500/10 text-rose-100'); }; $short = function($txt,$n=150){ $t = trim((string)$txt); if(mb_strlen($t) <= $n) return $t; return mb_substr($t,0,$n).'…'; }; $hasItems = ($items instanceof \Illuminate\Support\Collection) ? $items->isNotEmpty() : (is_array($items) && count($items)>0); @endphp
القواعد هي “قانون التشغيل”: متى نعتبر تأخير؟ متى نطلب إثبات؟ متى نصعّد؟ وكيف تتصرف المنظومة تلقائيًا.
| العنوان | Key | Level | Scope | الحالة | أولوية | Hits (7d) | آخر تحديث |
|---|---|---|---|---|---|---|---|
| {{ $title }} | {{ $key }} | {{ strtoupper($lvl) }} | {{ strtoupper($sc) }} | {{ $on ? 'مفعل' : 'موقوف' }} | {{ $prio }} | {{ $hits7 }} | {{ $upd }} |