{{-- Status widget --}}
{{-- Build unified list of fields (static + dynamic) --}}
@php
// Formatter closure: normalize array/json/objects into a readable string
$formatValue = null;
$formatValue = function ($v) use (&$formatValue) {
// null/empty
if ($v === null || $v === '') return '—';
// PHP array
if (is_array($v)) {
$pieces = [];
foreach ($v as $item) {
if (is_array($item)) {
// flatten inner arrays to comma-separated
$pieces[] = implode(', ', array_map(fn($x)=> (is_scalar($x) ? (string)$x : json_encode($x)), $item));
} elseif (is_object($item)) {
if (method_exists($item, 'toArray')) {
$pieces[] = implode(', ', $formatValue($item->toArray()));
} else {
$pieces[] = json_encode($item);
}
} else {
$pieces[] = (string)$item;
}
}
return implode(', ', $pieces);
}
// object
if (is_object($v)) {
if (method_exists($v, 'toArray')) {
return $formatValue($v->toArray());
}
if (method_exists($v, '__toString')) {
return (string)$v;
}
return json_encode($v);
}
// string: try decode JSON arrays/objects
if (is_string($v)) {
$trim = trim($v);
if ($trim === '') return '—';
if ((isset($trim[0]) && ($trim[0] === '[' || $trim[0] === '{'))) {
$decoded = json_decode($trim, true);
if (json_last_error() === JSON_ERROR_NONE) {
return $formatValue($decoded);
}
}
// If the value looks like a PHP serialized string, try to decode (best-effort)
if (str_starts_with($trim, 'a:') || str_starts_with($trim, 'O:') || str_starts_with($trim, 's:')) {
try {
$un = @unserialize($trim);
if ($un !== false && $un !== null) {
return $formatValue($un);
}
} catch (\Throwable $e) {
// ignore
}
}
// default: return as-is
return $v;
}
// fallback for scalars
return (string)$v;
};
$staticFields = [
['label'=>'الاسم', 'value'=>($concours_ext->nom . ' ' . $concours_ext->prenom)],
['label'=>'رقم بطاقة التعريف', 'value'=>$concours_ext->cin],
['label'=>'الهاتف', 'value'=>$concours_ext->tel],
['label'=>'البريد', 'value'=>$concours_ext->email],
['label'=>'العنوان', 'value'=>$concours_ext->adresse],
['label'=>'الولاية', 'value'=>$concours_ext->gouvernorat],
['label'=>'الرمز البريدي', 'value'=>$concours_ext->code_postale],
['label'=>'أنشئ في', 'value'=> optional($concours_ext->created_at)->format('Y-m-d H:i')],
];
$allFields = $staticFields;
if (!empty($dynamic)) {
foreach($dynamic as $d) {
// ensure label/value keys exist
$allFields[] = ['label' => $d['label'] ?? '—', 'value' => $d['value'] ?? null];
}
}
@endphp
{{-- Render fields uniformly --}}
@foreach($allFields as $f)
{{ $f['label'] }}
{!! nl2br(e($formatValue($f['value'] ?? null))) !!}
@endforeach
{{-- Files --}}
@if(!empty($files))
الملفات المرفوعة
{{ count($files) }} ملف
@foreach($files as $f)
{{ $f['original_name'] }}
{{ $f['definition_label'] ?? $f['definition_key'] ?? '' }}
• {{ $f['mime'] ?? '' }}
• {{ number_format($f['size'] ?? 0) }} bytes
@endforeach
@endif