title(self::clean($finalTitle)) ->body(self::clean($finalBody)) ->success(), 'success' ); } /** * Custom info notification. */ public static function info(string $title, string $body, ?string $formalTitle = null, ?string $formalBody = null): Notification { $finalTitle = self::getMessage($title, $formalTitle ?? $title); $finalBody = self::getMessage($body, $formalBody ?? $body); return self::applyStyle( self::make() ->title(self::clean($finalTitle)) ->body(self::clean($finalBody)) ->info(), 'info' ); } /** * Custom warning notification. */ public static function warning(string $title, string $body, ?string $formalTitle = null, ?string $formalBody = null): Notification { $finalTitle = self::getMessage($title, $formalTitle ?? $title); $finalBody = self::getMessage($body, $formalBody ?? $body); return self::applyStyle( self::make() ->title(self::clean($finalTitle)) ->body(self::clean($finalBody)) ->warning(), 'warning' ); } /** * Custom danger notification. */ public static function danger(string $title, string $body, ?string $formalTitle = null, ?string $formalBody = null): Notification { $finalTitle = self::getMessage($title, $formalTitle ?? $title); $finalBody = self::getMessage($body, $formalBody ?? $body); return self::applyStyle( self::make() ->title(self::clean($finalTitle)) ->body(self::clean($finalBody)) ->danger(), 'danger' ); } /** * Apply the user's selected style to the notification. */ protected static function applyStyle(Notification $notification, string $status): Notification { $isCheerful = self::getNotifStyle() === NotifStyle::Cheerful; if ($isCheerful) { $notification ->duration(6000) ->icon(match ($status) { 'success' => 'heroicon-o-sparkles', 'danger' => 'heroicon-o-fire', 'warning' => 'heroicon-o-bolt', 'info' => 'heroicon-o-megaphone', default => null, }); } else { $notification ->icon(null) ->duration(4000); } return $notification; } /** * Get the current user's notification style preference. */ public static function getNotifStyle(): NotifStyle { try { /** @var User|null $user */ $user = Auth::user(); return $user?->settings?->notif_style ?? NotifStyle::Cheerful; } catch (\Throwable $e) { return NotifStyle::Cheerful; } } /** * Get message based on the user's notification style preference. */ public static function getMessage(string $cheerful, string $formal): string { return self::getNotifStyle() === NotifStyle::Cheerful ? $cheerful : $formal; } /** * Strip emojis if the notification style is formal. */ public static function clean(string $text): string { if (self::getNotifStyle() === NotifStyle::Formal) { // Comprehensive regex to remove emojis and symbols $regex = '/[\x{1F600}-\x{1F64F}\x{1F300}-\x{1F5FF}\x{1F680}-\x{1F6FF}\x{2600}-\x{26FF}\x{2700}-\x{27BF}\x{1F900}-\x{1F9FF}\x{1F1E0}-\x{1F1FF}]/u'; return trim(preg_replace($regex, '', $text)); } return $text; } }