Files

107 lines
3.9 KiB
PHP

@use('Namu\WireChat\Facades\WireChat')
@php
$isSameAsNext = ($message?->sendable_id === $nextMessage?->sendable_id) && ($message?->sendable_type === $nextMessage?->sendable_type);
$isNotSameAsNext = !$isSameAsNext;
$isSameAsPrevious = ($message?->sendable_id === $previousMessage?->sendable_id) && ($message?->sendable_type === $previousMessage?->sendable_type);
$isNotSameAsPrevious = !$isSameAsPrevious;
@endphp
<div
{{-- We use style here to make it easy for dynamic and safe injection --}}
@style([
'background-color:var(--wc-brand-primary)' => $belongsToAuth==true
])
@class([
'flex flex-wrap max-w-fit text-[15px] border border-gray-200/40 dark:border-none rounded-xl p-2.5 flex flex-col text-black bg-[#f6f6f8fb]',
'text-white' => $belongsToAuth, // Background color for messages sent by the authenticated user
'bg-[var(--wc-light-secondary)] dark:bg-[var(--wc-dark-secondary)] dark:text-white' => !$belongsToAuth,
// Message styles based on position and ownership
// RIGHT
// First message on RIGHT
'rounded-br-md rounded-tr-2xl' => ($isSameAsNext && $isNotSameAsPrevious && $belongsToAuth),
// Middle message on RIGHT
'rounded-r-md' => ($isSameAsPrevious && $belongsToAuth),
// Standalone message RIGHT
'rounded-br-xl rounded-r-xl' => ($isNotSameAsPrevious && $isNotSameAsNext && $belongsToAuth),
// Last Message on RIGHT
'rounded-br-2xl' => ($isNotSameAsNext && $belongsToAuth),
// LEFT
// First message on LEFT
'rounded-bl-md rounded-tl-2xl' => ($isSameAsNext && $isNotSameAsPrevious && !$belongsToAuth),
// Middle message on LEFT
'rounded-l-md' => ($isSameAsPrevious && !$belongsToAuth),
// Standalone message LEFT
'rounded-bl-xl rounded-l-xl' => ($isNotSameAsPrevious && $isNotSameAsNext && !$belongsToAuth),
// Last message on LEFT
'rounded-bl-2xl' => ($isNotSameAsNext && !$belongsToAuth),
])
>
@if (!$belongsToAuth && $isGroup)
<div
@class([
'shrink-0 font-medium text-black',
// Hide avatar if the next message is from the same user
'hidden' => $isSameAsPrevious
])>
{{ $message?->sendable?->display_name }}
</div>
@endif
@php
// Check if the body is a valid internal URL so a href link can be rendered
$appUrl = rtrim(config('app.url'), '/');
$body = trim($message?->body ?? '');
$isInternalUrl = false;
if (filter_var($body, FILTER_VALIDATE_URL)) {
$isInternalUrl = str_starts_with($body, $appUrl);
}
// Check if body is a transaction statement URL (matches all localized slugs, e.g. /en/statement/123 or /nl/transactie-bewijs/123)
$transactionShowPattern = '#^' . preg_quote($appUrl, '#') . '/[a-z]{2}/[a-z\-]+/(\d+)$#';
$isTransactionLink = preg_match($transactionShowPattern, $body, $transactionMatches);
$transactionLinkId = $isTransactionLink ? $transactionMatches[1] : null;
@endphp
@if ($isTransactionLink && !$attachment)
<a href="{{ $body }}" class="underline text-sm md:text-base dark:text-white block py-1">
{{ __('View transaction') }} #{{ $transactionLinkId }}
</a>
@elseif ($isTransactionLink && $attachment)
{{-- Link already rendered inside the image/QR partial --}}
@else
<pre class="whitespace-pre-line break-all tracking-normal text-sm md:text-base dark:text-white lg:tracking-normal"
style="font-family: inherit;">
@if ($isInternalUrl)
<a href="{{ $body }}" class="underline">
{{ $body }}
</a>
@else
{{ $body }}
@endif
</pre>
@endif
{{-- Display the created time based on different conditions --}}
<span
@class(['text-[11px] ml-auto ', 'text-gray-700 dark:text-gray-300' => !$belongsToAuth,'text-gray-100' => $belongsToAuth])>
@php
// If the message was created today, show only the time (e.g., 1:00 AM)
echo $message?->created_at->format('H:i');
@endphp
</span>
</div>