{{-- resources/views/superadmin/proactive/command/templates.blade.php --}} @extends('layouts.superadmin') @section('title', 'ProActive — قوالب القيادة') @section('page-title', 'قوالب القيادة (Templates)') @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|manual|auto|system $search = trim((string)($search ?? $q('search',''))); if(!in_array($view,['cards','table'],true)) $view='cards'; if(!in_array($scope,['all','manual','auto','system'],true)) $scope='all'; // items: templates list (Collection/Paginator/array) // Expected fields (مرن): id, title, body, category, scope, channel, variables_json, is_active, created_at, updated_at, usage_count $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), 'manual' => (int)($manualCount ?? 0), 'auto' => (int)($autoCount ?? 0), 'system' => (int)($systemCount ?? 0), ]; $rCommand = safe_route('superadmin.proactive.command', [], true, url('/superadmin/proactive/command')); $rTemplates = safe_route('superadmin.proactive.templates', [], 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,$rTemplates){ $url = $rTemplates.'?'.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('manual','يدوي', (int)($stats['manual'] ?? 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'), $scopeBtn('auto','تلقائي', (int)($stats['auto'] ?? 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('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'), ]; $scopeBadge = function($s) use ($chip){ $s = (string)$s; if($s==='manual') return $chip('border-cyan-400/25 bg-cyan-500/10 text-cyan-100'); if($s==='auto') return $chip('border-emerald-400/25 bg-emerald-500/10 text-emerald-100'); if($s==='system') return $chip('border-fuchsia-400/25 bg-fuchsia-500/10 text-fuchsia-100'); return $chip('border-white/10 bg-white/5 text-white/70'); }; $activeBadge = 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=140){ $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
{{-- HERO --}}
ProActive • قوالب القيادة

القوالب — Templates

قوالب جاهزة تُستخدم فورًا: تذكير، تنبيه، قرار، طلب إثبات، تصعيد… مع متغيرات ذكية مثل {leader} {date} {time} {platform} {title}

إجمالي: {{ (int)($stats['total'] ?? 0) }} نشط: {{ (int)($stats['active'] ?? 0) }} يدوي: {{ (int)($stats['manual'] ?? 0) }} تلقائي: {{ (int)($stats['auto'] ?? 0) }} نظام: {{ (int)($stats['system'] ?? 0) }}
{{-- FILTER --}}
تصفير
* التصنيف: {{ $scope }}.
{{-- SCOPES --}}
@foreach($scopes as $s) {{ $s['label'] }} ({{ (int)$s['count'] }}) @endforeach
{{-- HINTS --}}
متغيرات جاهزة
{leader} {date} {time} {platform} {title} {link} {reason}
* الاستبدال الفعلي يتم في الكنترول/الخدمة. هنا فقط عرض واضح للقوالب.
{{-- LIST --}} @if($hasItems) @if($view === 'cards')
@foreach($items as $t) @php $id = (int)getv($t,'id', 0); $title = (string)getv($t,'title', '— بدون عنوان —'); $body = (string)getv($t,'body', getv($t,'message','')); $cat = (string)getv($t,'category', getv($t,'type','general')); $sc = (string)getv($t,'scope', 'manual'); // manual|auto|system $ch = (string)getv($t,'channel', getv($t,'send_via','push')); $vars = (string)getv($t,'variables_json', getv($t,'variables','')); $active = (int)getv($t,'is_active', 1) === 1; $usage = (int)getv($t,'usage_count', 0); $created= (string)getv($t,'created_at', ''); $updated= (string)getv($t,'updated_at', ''); $preview= $short($body, 180); @endphp
{{ $title }}
تصنيف: {{ $cat }} • قناة: {{ $ch }}
{{ strtoupper($sc) }} {{ $active ? 'نشط' : 'معطّل' }}
المحتوى
{{ $preview !== '' ? $preview : '— بدون نص —' }}
ID: {{ $id }} استخدام: {{ $usage }} @if($vars !== '') Vars @endif
{{ $created }} {{ $updated }}
@endforeach
@else
جدول القوالب
عرض سريع — التفاصيل الكاملة في قاعدة البيانات/الكنترول.
@foreach($items as $t) @php $title = (string)getv($t,'title','—'); $cat = (string)getv($t,'category', getv($t,'type','general')); $sc = (string)getv($t,'scope','manual'); $ch = (string)getv($t,'channel', getv($t,'send_via','push')); $active = (int)getv($t,'is_active',1) === 1; $usage = (int)getv($t,'usage_count',0); $updated= (string)getv($t,'updated_at',''); @endphp @endforeach
العنوان تصنيف Scope قناة الحالة استخدام آخر تحديث
{{ $title }} {{ $cat }} {{ strtoupper($sc) }} {{ $ch }} {{ $active ? 'نشط' : 'معطّل' }} {{ $usage }} {{ $updated }}
@if(isset($items) && method_exists($items,'links'))
{{ $items->links() }}
@endif
@endif @else
لا يوجد قوالب ضمن هذا الفلتر
جرّب تغيّر Scope أو كلمة البحث.
@endif
@endsection