@php $fallbacks = [ 'admin' => [ 'primary' => '#4f46e5', 'accent' => '#22c55e', ], 'user' => [ 'primary' => '#4663ee', 'accent' => '#17a86a', ], 'merchant' => [ 'primary' => '#16a34a', 'accent' => '#14b8a6', ], 'agent' => [ 'primary' => '#4f46e5', 'accent' => '#f59e0b', ], ]; $normalizeHex = static function (mixed $value, string $fallback): string { $value = strtoupper(trim((string) $value)); return preg_match('/^#[0-9A-F]{6}$/', $value) === 1 ? $value : strtoupper($fallback); }; $rgb = static function (string $hex): string { $hex = ltrim($hex, '#'); return collect(str_split($hex, 2)) ->map(fn (string $value): int => hexdec($value)) ->implode(', '); }; $shade = static function (string $hex, int $percent): string { $hex = ltrim($hex, '#'); $channels = collect(str_split($hex, 2))->map(fn (string $value): int => hexdec($value)); $target = $percent < 0 ? 0 : 255; $factor = abs($percent) / 100; return '#'.$channels ->map(fn (int $channel): string => str_pad(dechex((int) round($channel + (($target - $channel) * $factor))), 2, '0', STR_PAD_LEFT)) ->implode(''); }; $colors = collect($fallbacks)->mapWithKeys(function (array $fallback, string $role) use ($normalizeHex, $rgb, $shade): array { $primary = $role === 'admin' ? $normalizeHex($fallback['primary'], $fallback['primary']) : $normalizeHex(setting("{$role}_role_primary_color", $fallback['primary']), $fallback['primary']); $accent = $role === 'admin' ? $normalizeHex($fallback['accent'], $fallback['accent']) : $normalizeHex(setting("{$role}_role_accent_color", $fallback['accent']), $fallback['accent']); return [ $role => [ 'primary' => $primary, 'primaryRgb' => $rgb($primary), 'primaryHover' => strtoupper($shade($primary, -12)), 'primaryDeep' => strtoupper($shade($primary, -25)), 'primarySoft' => strtoupper($shade($primary, 46)), 'accent' => $accent, 'accentRgb' => $rgb($accent), ], ]; }); @endphp