{{-- Sélecteur de client avec logos --}} @php $currentClientId = $currentClientId ?? ''; $currentClientName = $currentClientName ?? null; $currentClientLogo = $currentClientLogo ?? null; $currentClientIsCompany = $currentClientIsCompany ?? null; $currentClientId = $currentClientId !== null ? (string) $currentClientId : ''; $currentClient = $currentClientId !== '' ? $clients->firstWhere('client_id', $currentClientId) : null; if ($currentClientId && !$currentClient && empty($currentClientName) && empty($currentClientLogo)) { $currentClientId = ''; } if ($currentClientId === '') { $currentClient = null; } $resolvedLogo = null; if ($currentClient && $currentClient->client_logo && $currentClient->client_logo !== 'null') { $resolvedLogo = $currentClient->client_logo; } elseif ($currentClientLogo && $currentClientLogo !== 'null') { $resolvedLogo = $currentClientLogo; } $hasLogo = $resolvedLogo !== null; $nameForInitials = $currentClient->client_name ?? $currentClientName; $computeInitials = function (?string $name): string { if (!$name) { return '?'; } $clean = preg_replace('/\s+/', ' ', trim($name)); if ($clean === '') { return '?'; } $letters = ''; foreach (explode(' ', $clean) as $word) { if ($word === '') { continue; } $letters .= mb_strtoupper(mb_substr($word, 0, 1, 'UTF-8'), 'UTF-8'); if (mb_strlen($letters, 'UTF-8') >= 3) { break; } } if ($letters === '') { $letters = mb_strtoupper(mb_substr($clean, 0, 1, 'UTF-8'), 'UTF-8'); } return $letters !== '' ? $letters : '?'; }; $colorFromValue = function ($value): string { if ($value === null || $value === '') { return '#6c757d'; } $hash = crc32(strtolower((string) $value)); return sprintf('#%06X', $hash & 0xFFFFFF); }; $buttonInitials = $hasLogo ? ($currentClient->initials ?? $computeInitials($currentClient->client_name ?? $currentClientName)) : $computeInitials($nameForInitials); $buttonColor = $hasLogo ? '#FFFFFF' : $colorFromValue($currentClient->client_id ?? $nameForInitials); $currentIsCompany = $currentClient->is_company ?? ($currentClientIsCompany ?? null); $displayName = $currentClient->client_name ?? ($currentClientName ?? null); if (!$displayName) { $displayName = 'Aucun client'; } @endphp
{{-- Option "Aucun client" --}}
?
Aucun client
{{-- Options clients actifs --}} @foreach($clients as $client) @php $hasCustomLogo = $client->has_custom_logo && $client->client_logo && $client->client_logo !== 'null'; $escapedName = htmlspecialchars($client->client_name, ENT_QUOTES, 'UTF-8'); $optionInitials = $client->initials ?? $computeInitials($client->client_name); $optionColor = $colorFromValue($client->client_id ?? $client->client_name); @endphp
@if($hasCustomLogo) @else
{{ $optionInitials }}
@endif
{{ $client->client_name }}
@endforeach