From 5f71c3e250533022b4effb3d5ba19d82f1599276 Mon Sep 17 00:00:00 2001 From: Friederich Loheide Date: Sun, 27 Sep 2026 20:10:35 +0000 Subject: [PATCH 1/2] =?UTF-8?q?Nachrichten=201.1.0:=20Schnittstelle=20f?= =?UTF-8?q?=C3=BCr=20die=20App,=20Verbindung=20pr=C3=BCfen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - /api/v1/chat: config, Gruppenchats, verlassen, bearbeiten, löschen, Reaktionen, „Gibt es Neues?“, „schreibt …“, GIFs, Echtzeit-Anmeldung und Anhänge mit Token - Anhang-Adressen zeigen bei API-Aufrufen auf die API (Token statt Sitzung) - Backend: „Echtzeit prüfen“ und „GIPHY prüfen“ melden sofort, ob die Zugangsdaten stimmen - README: Schritt-für-Schritt-Einrichtung für pusher.com und GIPHY Co-Authored-By: Claude Opus 5.5 (1M context) --- README.md | 49 ++++++++++++++--- plugin.json | 2 +- routes/api.php | 25 ++++++--- src/Filament/Pages/ChatSettings.php | 16 ++++++ src/Gifs.php | 28 ++++++++++ .../Controllers/ConversationController.php | 13 +++++ src/Presenter.php | 8 ++- src/Realtime.php | 52 +++++++++++++++---- tests/ChatTest.php | 40 ++++++++++++++ 9 files changed, 207 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 025dbf9..8521d5c 100644 --- a/README.md +++ b/README.md @@ -35,17 +35,52 @@ Voraussetzung: Inhaus **0.39.0** oder neuer. ## Echtzeit (optional) Ohne Einrichtung fragt der Chat alle 3 Sekunden (im Hintergrund seltener) nach Neuem – das läuft auf jedem Webspace. -Für sofortige Zustellung einen Pusher-kompatiblen Dienst eintragen: +Für sofortige Zustellung braucht es einen Pusher-kompatiblen Dienst. Über ihn geht nur das Signal „es gibt Neues“, +nie Nachrichteninhalte. Auf einem reinen Webspace (ohne dauerhaft laufende Prozesse) ist **pusher.com** der +einfachste Weg: -- **pusher.com**: App anlegen, App-ID, Key, Secret und Cluster eintragen, Server leer lassen. -- **Laravel Reverb / Soketi** (eigener Server): App-ID, Key, Secret, Server (z. B. `ws.example.org`), Port (443). - Der Server muss vom Browser (WebSocket) und vom Portal (HTTP) aus erreichbar sein. +1. Kostenloses Konto unter anlegen („Channels“, Sandbox-Tarif: + 200 000 Signale/Tag, 100 gleichzeitige Verbindungen – für die meisten Häuser genug). +2. „Create app“: Name z. B. „Inhaus“, Cluster **eu** (Server in der EU), Frontend „Vanilla JS“, Backend „Laravel“. +3. Unter „App Keys“ stehen `app_id`, `key`, `secret` und `cluster`. +4. Im Backend unter **Portal → Nachrichten → Echtzeit** einschalten, App-ID, Key, Secret und Cluster (`eu`) + eintragen, **Server leer lassen**, speichern. +5. Oben auf **„Echtzeit prüfen“** klicken – „Verbindung steht“ heißt: fertig. + +Alternativ ein eigener Server mit **Laravel Reverb** oder **Soketi**: App-ID, Key, Secret, Server +(z. B. `ws.example.org`) und Port (443) eintragen. Der Server muss vom Browser bzw. der App (WebSocket) und +vom Portal (HTTP) aus erreichbar sein. Die Inhaus-App nutzt dieselbe Einrichtung automatisch. + +## GIPHY (optional) + +Die eigene GIF-Sammlung (Backend → Chat-GIFs) funktioniert ohne Einrichtung. Für die Suche bei GIPHY: + +1. Unter anmelden, „Create an App“ → **API** (nicht SDK) wählen. +2. Den angezeigten API-Key im Backend unter **Portal → Nachrichten → GIFs** eintragen und speichern. +3. Oben auf **„GIPHY prüfen“** klicken. + +Ein neuer Schlüssel ist ein Beta-Schlüssel (100 Abrufe pro Stunde); für mehr bei GIPHY ein „Production“-Upgrade +beantragen. Suchbegriffe gehen dabei an GIPHY, die GIFs lädt der Browser von dort. ## Schnittstelle für die App -Unter `/api/v1/chat/…` (Token nötig): `GET conversations`, `POST direct {user_id}`, -`GET conversations/{id}/messages?vor=`, `POST conversations/{id}/messages {body, gif_url, reply_to, files[]}`, -`POST conversations/{id}/read {message_id}`, `GET unread`. +Unter `/api/v1/chat/…` (Token nötig), dieselben Regeln wie im Portal: + +| Methode | Pfad | Zweck | +|---|---|---| +| GET | `config` | eigene Person, `can_create_groups`, `giphy`, `realtime` (ohne Secret), `reactions`, `max_upload_mb` | +| GET | `conversations` | Gesprächsliste | +| POST | `direct {user_id}` / `groups {name, members[]}` | Direktnachricht öffnen / Gruppenchat anlegen (Recht nötig) | +| DELETE | `conversations/{id}` | Gespräch verlassen | +| GET | `conversations/{id}/messages?vor=` | 40 Nachrichten, ältere mit `vor` | +| POST | `conversations/{id}/messages {body, gif_url, reply_to, files[]}` | senden (JSON oder multipart) | +| POST | `conversations/{id}/read {message_id}` / `typing` | gelesen / „schreibt …“ | +| PUT / DELETE | `messages/{id}` | bearbeiten / löschen | +| POST | `messages/{id}/reaction {emoji}` | Reaktion umschalten | +| GET | `updates?seit=&offen=&nach=` | „Gibt es Neues?“ – wie im Portal | +| GET | `unread`, `gifs?q=` | ungelesene Nachrichten, GIF-Suche | +| POST | `realtime/auth {socket_id, channel_name}` | Anmeldung am privaten Echtzeit-Kanal | +| GET | `attachments/{id}` | Anhang (Adressen in den Antworten zeigen bei API-Aufrufen hierher) | ## Entwicklung diff --git a/plugin.json b/plugin.json index 81fb46e..615196f 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "slug": "chat", "name": "Nachrichten", - "version": "1.0.0", + "version": "1.1.0", "description": "Direktnachrichten und Gruppenchats im Portal – mit Anhängen, Bildern, GIFs (eigene Sammlung und optional GIPHY), Emojis, Reaktionen, Antworten und Gelesen-Status. Gruppen anlegen nur mit Recht; auf Wunsch Echtzeit über einen Pusher-kompatiblen Dienst.", "author": "Loheide", "namespace": "Inhaus\\Plugins\\Chat\\", diff --git a/routes/api.php b/routes/api.php index 4efc554..53eef4b 100644 --- a/routes/api.php +++ b/routes/api.php @@ -5,11 +5,22 @@ use Inhaus\Plugins\Chat\Http\Controllers\ConversationController; use Inhaus\Plugins\Chat\Http\Controllers\MessageController; // /api/v1/chat … für die Inhaus-App (Token nötig) – dieselben Regeln wie im Portal -Route::prefix('chat')->group(function () { - Route::get('/conversations', [ConversationController::class, 'index']); - Route::post('/direct', [ConversationController::class, 'direct'])->middleware('throttle:30,1'); - Route::get('/conversations/{conversation}/messages', [MessageController::class, 'index']); - Route::post('/conversations/{conversation}/messages', [MessageController::class, 'store'])->middleware('throttle:60,1'); - Route::post('/conversations/{conversation}/read', [MessageController::class, 'read']); - Route::get('/unread', [MessageController::class, 'unread']); +Route::prefix('chat')->name('chat.app.')->group(function () { + Route::get('/config', [ConversationController::class, 'config'])->name('config'); + Route::get('/conversations', [ConversationController::class, 'index'])->name('conversations'); + Route::post('/direct', [ConversationController::class, 'direct'])->middleware('throttle:30,1')->name('direct'); + Route::post('/groups', [ConversationController::class, 'createGroup'])->middleware('throttle:10,1')->name('groups'); + Route::delete('/conversations/{conversation}', [ConversationController::class, 'leave'])->name('leave'); + Route::get('/conversations/{conversation}/messages', [MessageController::class, 'index'])->name('messages'); + Route::post('/conversations/{conversation}/messages', [MessageController::class, 'store'])->middleware('throttle:60,1')->name('send'); + Route::post('/conversations/{conversation}/read', [MessageController::class, 'read'])->name('read'); + Route::post('/conversations/{conversation}/typing', [MessageController::class, 'typing'])->middleware('throttle:60,1')->name('typing'); + Route::put('/messages/{message}', [MessageController::class, 'update'])->name('edit'); + Route::delete('/messages/{message}', [MessageController::class, 'destroy'])->name('delete'); + Route::post('/messages/{message}/reaction', [MessageController::class, 'react'])->middleware('throttle:60,1')->name('react'); + Route::get('/updates', [MessageController::class, 'updates'])->middleware('throttle:120,1')->name('updates'); + Route::get('/unread', [MessageController::class, 'unread'])->name('unread'); + Route::get('/gifs', [MessageController::class, 'gifs'])->middleware('throttle:60,1')->name('gifs'); + Route::post('/realtime/auth', [MessageController::class, 'realtimeAuth'])->middleware('throttle:30,1')->name('realtime'); + Route::get('/attachments/{attachment}', [MessageController::class, 'attachment'])->name('attachment'); }); diff --git a/src/Filament/Pages/ChatSettings.php b/src/Filament/Pages/ChatSettings.php index 9ad1ab5..c235ae1 100644 --- a/src/Filament/Pages/ChatSettings.php +++ b/src/Filament/Pages/ChatSettings.php @@ -18,6 +18,8 @@ use Filament\Schemas\Schema; use Filament\Support\Icons\Heroicon; use Illuminate\Support\Facades\Crypt; use Illuminate\Validation\ValidationException; +use Inhaus\Plugins\Chat\Gifs; +use Inhaus\Plugins\Chat\Realtime; use UnitEnum; /** @@ -138,9 +140,23 @@ class ChatSettings extends Page Notification::make()->success()->title('Gespeichert')->send(); } + /** + * @param array{ok: bool, message: string} $result + */ + private function report(array $result): void + { + Notification::make()->{$result['ok'] ? 'success' : 'danger'}()->title($result['ok'] ? 'Verbindung steht' : 'Das klappt noch nicht')->body($result['message'])->send(); + } + protected function getHeaderActions(): array { return [ + Action::make('checkRealtime')->label('Echtzeit prüfen')->color('gray')->icon(Heroicon::OutlinedSignal) + ->visible(fn () => app(Realtime::class)->enabled()) + ->action(fn () => $this->report(app(Realtime::class)->check())), + Action::make('checkGiphy')->label('GIPHY prüfen')->color('gray')->icon(Heroicon::OutlinedGif) + ->visible(fn () => app(Gifs::class)->giphyEnabled()) + ->action(fn () => $this->report(app(Gifs::class)->checkGiphy())), Action::make('forgetGiphy')->label('GIPHY ausschalten')->color('gray') ->visible(fn () => filled(app(Settings::class)->get('chat.giphy_key'))) ->requiresConfirmation() diff --git a/src/Gifs.php b/src/Gifs.php index 779c090..9104637 100644 --- a/src/Gifs.php +++ b/src/Gifs.php @@ -56,6 +56,34 @@ class Gifs return $path === '' ? Storage::disk(self::DISK)->url(self::FOLDER) : Storage::disk(self::DISK)->url($path); } + /** + * Schlüssel prüfen (Backend) – ein Abruf der Trends. + * + * @return array{ok: bool, message: string} + */ + public function checkGiphy(): array + { + if (! $this->giphyEnabled()) { + return ['ok' => false, 'message' => 'Es ist kein GIPHY-Schlüssel gespeichert.']; + } + + try { + $response = Http::timeout(5)->acceptJson()->get('https://api.giphy.com/v1/gifs/trending', [ + 'api_key' => Crypt::decryptString((string) $this->settings->get('chat.giphy_key')), + 'limit' => 1, + ]); + } catch (Throwable $e) { + return ['ok' => false, 'message' => 'GIPHY ist nicht erreichbar: '.mb_substr($e->getMessage(), 0, 160)]; + } + + return match (true) { + $response->successful() => ['ok' => true, 'message' => 'Der Schlüssel funktioniert – die GIF-Suche im Chat findet jetzt auch GIPHY.'], + in_array($response->status(), [401, 403], true) => ['ok' => false, 'message' => 'GIPHY lehnt den Schlüssel ab – bitte prüfen.'], + $response->status() === 429 => ['ok' => false, 'message' => 'Der Schlüssel funktioniert, das Kontingent ist aber gerade aufgebraucht (Beta-Schlüssel: 100 Abrufe pro Stunde).'], + default => ['ok' => false, 'message' => 'Unerwartete Antwort von GIPHY (HTTP '.$response->status().').'], + }; + } + /** * @return list> */ diff --git a/src/Http/Controllers/ConversationController.php b/src/Http/Controllers/ConversationController.php index b1b4021..2cce3f6 100644 --- a/src/Http/Controllers/ConversationController.php +++ b/src/Http/Controllers/ConversationController.php @@ -44,6 +44,19 @@ class ConversationController extends Controller ]); } + /** Einstellungen für die App (entspricht den Seitendaten im Portal) */ + public function config(Request $request, Gifs $gifs, Realtime $realtime): JsonResponse + { + return response()->json([ + 'me' => Presenter::person($request->user()), + 'can_create_groups' => $request->user()->can('chat.groups.create'), + 'giphy' => $gifs->giphyEnabled(), + 'realtime' => $realtime->clientConfig(), + 'reactions' => Reaction::EMOJIS, + 'max_upload_mb' => (int) app(Settings::class)->get('chat.max_upload_mb', 25), + ]); + } + public function index(Request $request): JsonResponse { return response()->json(['conversations' => $this->list($request->user())]); diff --git a/src/Presenter.php b/src/Presenter.php index 25a8964..958ab96 100644 --- a/src/Presenter.php +++ b/src/Presenter.php @@ -14,6 +14,12 @@ class Presenter /** * @return array */ + /** Die App lädt Anhänge mit ihrem Token über die API, der Browser über die Sitzung */ + public static function attachmentUrl(Attachment $attachment): string + { + return request()->is('api/*') ? route('chat.app.attachment', $attachment) : route('chat.attachment', $attachment); + } + public static function person(?User $user): ?array { return $user ? ['id' => $user->id, 'name' => $user->name, 'first_name' => $user->first_name, 'initials' => $user->initials, 'avatar_url' => $user->avatarUrl(96), 'job_title' => $user->job_title] : null; @@ -100,7 +106,7 @@ class Presenter 'image' => $a->isImage(), 'width' => $a->width, 'height' => $a->height, - 'url' => route('chat.attachment', $a), + 'url' => self::attachmentUrl($a), ])->all(), 'reactions' => $m->reactions->groupBy('emoji')->map(fn ($group, $emoji) => [ 'emoji' => $emoji, diff --git a/src/Realtime.php b/src/Realtime.php index 2f5b038..538d964 100644 --- a/src/Realtime.php +++ b/src/Realtime.php @@ -77,6 +77,32 @@ class Realtime return ['auth' => $this->settings->get('chat.realtime.key').':'.hash_hmac('sha256', $socketId.':'.$channel, $this->secret())]; } + /** + * Verbindung prüfen (Backend): fragt beim Dienst die offenen Kanäle ab – klappt das, + * stimmen Server, App-ID, Key und Secret. + * + * @return array{ok: bool, message: string} + */ + public function check(): array + { + if (! $this->enabled()) { + return ['ok' => false, 'message' => 'Echtzeit ist nicht eingeschaltet oder unvollständig eingerichtet.']; + } + + try { + $response = Http::timeout(5)->acceptJson()->get($this->signedUrl('GET', '/apps/'.$this->settings->get('chat.realtime.app_id').'/channels')); + } catch (Throwable $e) { + return ['ok' => false, 'message' => 'Der Dienst ist nicht erreichbar: '.mb_substr($e->getMessage(), 0, 160)]; + } + + return match (true) { + $response->successful() => ['ok' => true, 'message' => 'Verbindung steht – Nachrichten kommen jetzt sofort an.'], + in_array($response->status(), [401, 403], true) => ['ok' => false, 'message' => 'Der Dienst lehnt die Anmeldung ab – bitte Key und Secret prüfen.'], + $response->status() === 404 => ['ok' => false, 'message' => 'Diese App-ID kennt der Dienst nicht.'], + default => ['ok' => false, 'message' => 'Unerwartete Antwort des Dienstes (HTTP '.$response->status().').'], + }; + } + /** * @param list $channels * @param array $data @@ -84,24 +110,30 @@ class Realtime private function trigger(array $channels, string $event, array $data): void { $body = json_encode(['name' => $event, 'channels' => $channels, 'data' => json_encode($data)]); - $path = '/apps/'.$this->settings->get('chat.realtime.app_id').'/events'; - $query = [ - 'auth_key' => (string) $this->settings->get('chat.realtime.key'), - 'auth_timestamp' => (string) time(), - 'auth_version' => '1.0', - 'body_md5' => md5($body), - ]; - ksort($query); - $query['auth_signature'] = hash_hmac('sha256', "POST\n{$path}\n".http_build_query($query), $this->secret()); try { - Http::timeout(3)->withBody($body, 'application/json')->post($this->baseUrl().$path.'?'.http_build_query($query)); + Http::timeout(3)->withBody($body, 'application/json')->post($this->signedUrl('POST', '/apps/'.$this->settings->get('chat.realtime.app_id').'/events', $body)); } catch (Throwable $e) { // Echtzeit ist nur eine Beschleunigung – die Oberfläche fragt ohnehin regelmäßig nach report($e); } } + /** Adresse mit Signatur nach dem Pusher-HTTP-Protokoll */ + private function signedUrl(string $method, string $path, ?string $body = null): string + { + $query = [ + 'auth_key' => (string) $this->settings->get('chat.realtime.key'), + 'auth_timestamp' => (string) time(), + 'auth_version' => '1.0', + ...($body === null ? [] : ['body_md5' => md5($body)]), + ]; + ksort($query); + $query['auth_signature'] = hash_hmac('sha256', "{$method}\n{$path}\n".http_build_query($query), $this->secret()); + + return $this->baseUrl().$path.'?'.http_build_query($query); + } + private function baseUrl(): string { $scheme = $this->settings->get('chat.realtime.scheme') ?: 'https'; diff --git a/tests/ChatTest.php b/tests/ChatTest.php index 0759276..214a7c3 100644 --- a/tests/ChatTest.php +++ b/tests/ChatTest.php @@ -13,10 +13,12 @@ use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Storage; use Inertia\Testing\AssertableInertia as Assert; +use Inhaus\Plugins\Chat\Gifs; use Inhaus\Plugins\Chat\Models\Conversation; use Inhaus\Plugins\Chat\Models\Gif; use Inhaus\Plugins\Chat\Models\Message; use Inhaus\Plugins\Chat\Realtime; +use Laravel\Sanctum\Sanctum; use Tests\TestCase; /** @@ -206,4 +208,42 @@ class ChatTest extends TestCase ->assertOk()->assertJsonPath('auth', 'k:'.hash_hmac('sha256', '123.456:'.Realtime::channel($ada->id), 's3cret')); $this->actingAs($ada)->postJson('/chat/api/echtzeit/anmelden', ['socket_id' => '123.456', 'channel_name' => Realtime::channel($bob->id)])->assertForbidden(); } + + public function test_connection_checks_for_realtime_and_giphy(): void + { + $realtime = app(Realtime::class); + $this->assertFalse($realtime->check()['ok']); + + app(Settings::class)->setMany(['chat.realtime.enabled' => true, 'chat.realtime.app_id' => '42', 'chat.realtime.key' => 'k', 'chat.realtime.secret' => Crypt::encryptString('s3cret'), 'chat.realtime.host' => 'ws.example.org']); + Http::fake(['ws.example.org/apps/42/channels*' => Http::sequence()->push(['channels' => []])->push(['error' => 'Invalid signature'], 401)]); + $this->assertTrue($realtime->check()['ok']); + $this->assertStringContainsString('Key und Secret', $realtime->check()['message']); + Http::assertSent(fn ($r) => $r->method() === 'GET' && str_contains($r->url(), 'auth_signature=') && ! str_contains($r->url(), 'body_md5')); + + $gifs = app(Gifs::class); + $this->assertFalse($gifs->checkGiphy()['ok']); + app(Settings::class)->set('chat.giphy_key', Crypt::encryptString('gk')); + Http::fake(['api.giphy.com/*' => Http::sequence()->push(['data' => []])->push(['message' => 'Unauthorized'], 401)]); + $this->assertTrue($gifs->checkGiphy()['ok']); + $this->assertFalse($gifs->checkGiphy()['ok']); + } + + public function test_app_api_with_token(): void + { + [$ada, $bob] = User::factory()->count(2)->create()->all(); + Sanctum::actingAs($ada); + + $this->getJson('/api/v1/chat/config')->assertOk()->assertJsonPath('me.id', $ada->id)->assertJsonPath('realtime', null)->assertJsonPath('can_create_groups', false); + $id = $this->postJson('/api/v1/chat/direct', ['user_id' => $bob->id])->assertOk()->json('id'); + $url = $this->post("/api/v1/chat/conversations/{$id}/messages", ['body' => 'Hallo aus der App', 'files' => [UploadedFile::fake()->image('foto.jpg', 40, 40)]], ['Accept' => 'application/json']) + ->assertCreated()->json('message.attachments.0.url'); + $this->assertStringContainsString('/api/v1/chat/attachments/', $url); + $this->get($url)->assertOk(); + + $this->getJson('/api/v1/chat/updates?offen='.$id)->assertOk()->assertJsonPath('messages.0.body', 'Hallo aus der App'); + $this->getJson('/api/v1/chat/conversations')->assertJsonPath('conversations.0.person.id', $bob->id); + + Sanctum::actingAs(User::factory()->create()); + $this->get($url)->assertNotFound(); + } } From 7a4832001fee0f222c15c3d7af26488545e1a63a Mon Sep 17 00:00:00 2001 From: Friederich Loheide Date: Tue, 29 Sep 2026 05:37:41 +0000 Subject: [PATCH 2/2] =?UTF-8?q?Nachrichten=201.2.0:=20Nutzt=20die=20Vorlag?= =?UTF-8?q?e=20=E2=80=9Ef=C3=BCllt=20den=20Bildschirm=E2=80=9C=20(ab=20Inh?= =?UTF-8?q?aus=200.50=20ohne=20Fu=C3=9Fzeile)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 (1M context) --- dist/pages/Index.js | 2 +- plugin.json | 2 +- resources/js/pages/Index.vue | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/pages/Index.js b/dist/pages/Index.js index 3a1b260..e846944 100644 --- a/dist/pages/Index.js +++ b/dist/pages/Index.js @@ -1,2 +1,2 @@ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["../chunks/pusher-DXDYBH7H.js","../chunks/rolldown-runtime-CbXtAM7H.js"])))=>i.map(i=>d[i]); -import{n as e}from"../chunks/rolldown-runtime-CbXtAM7H.js";import{t}from"../chunks/createLucideIcon-CYyWUN7r.js";import{Fragment as n,computed as r,createBlock as i,createCommentVNode as a,createElementBlock as o,createElementVNode as s,createTextVNode as c,createVNode as l,mergeModels as u,nextTick as d,normalizeClass as f,normalizeStyle as p,onBeforeUnmount as m,onMounted as h,openBlock as g,ref as _,renderList as v,renderSlot as y,resolveDynamicComponent as b,toDisplayString as x,unref as S,useModel as C,vModelText as w,watch as T,withCtx as E,withDirectives as D,withKeys as O,withModifiers as k}from"vue";import{AppLayout as A,Button as j,Dialog as M,DialogContent as N,DialogDescription as P,DialogFooter as F,DialogHeader as I,DialogTitle as L,FileIcon as R,Input as z,Label as B,PersonAvatar as V,Switch as ee,http as H,toast as U}from"@inhaus/ui";var te=t({name:`arrow-down`,size:24,node:[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]}),ne=t({name:`arrow-left`,size:24,node:[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]}),re=t({name:`bell-off`,size:24,node:[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742`,key:`178tsu`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05`,key:`1hqiys`}]]}),W=t({name:`corner-up-left`,size:24,node:[[`path`,{d:`M20 20v-7a4 4 0 0 0-4-4H4`,key:`1nkjon`}],[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}]]}),G=t({name:`crown`,size:24,node:[[`path`,{d:`M11.562 3.266a.5.5 0 0 1 .876 0L15.39 8.87a1 1 0 0 0 1.516.294L21.183 5.5a.5.5 0 0 1 .798.519l-2.834 10.246a1 1 0 0 1-.956.734H5.81a1 1 0 0 1-.957-.734L2.02 6.02a.5.5 0 0 1 .798-.519l4.276 3.664a1 1 0 0 0 1.516-.294z`,key:`1vdc57`}],[`path`,{d:`M5 21h14`,key:`11awu3`}]]}),ie=t({name:`download`,size:24,node:[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]}),ae=t({name:`eye-off`,size:24,node:[[`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`,key:`ct8e1f`}],[`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`,key:`151rxh`}],[`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`,key:`13bj9a`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]}),oe=t({name:`face-slightly-smiling-plus`,size:24,node:[[`path`,{d:`M13.267 2.08a10 10 0 108.653 8.653`,key:`1wbpyh`}],[`path`,{d:`M15 10V9`,key:`4dkmfx`}],[`path`,{d:`M16 5h6`,key:`1vod17`}],[`path`,{d:`M16.472 15a6 6 0 01-8.943 0`,key:`7qomzy`}],[`path`,{d:`M19 2v6`,key:`4bpg5p`}],[`path`,{d:`M9 10V9`,key:`1lazqi`}]],aliases:[`smile-plus`]}),se=t({name:`face-slightly-smiling`,size:24,node:[[`path`,{d:`M15 10V9`,key:`4dkmfx`}],[`path`,{d:`M16.472 15a6 6 0 01-8.943 0`,key:`7qomzy`}],[`path`,{d:`M9 10V9`,key:`1lazqi`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]],aliases:[`smile`]}),ce=t({name:`file`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}]]}),le=t({name:`image`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]}),ue=t({name:`info`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]}),K=t({name:`loader-circle`,size:24,node:[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]],aliases:[`loader-2`]}),de=t({name:`log-out`,size:24,node:[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]}),fe=t({name:`message-square-plus`,size:24,node:[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M12 8v6`,key:`1ib9pf`}],[`path`,{d:`M9 11h6`,key:`1fldmi`}]]}),pe=t({name:`messages-square`,size:24,node:[[`path`,{d:`M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z`,key:`1n2ejm`}],[`path`,{d:`M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1`,key:`1qfcsi`}]]}),me=t({name:`paperclip`,size:24,node:[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]}),he=t({name:`pencil`,size:24,node:[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]}),q=t({name:`search`,size:24,node:[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]}),ge=t({name:`send-horizontal`,size:24,node:[[`path`,{d:`M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z`,key:`117uat`}],[`path`,{d:`M6 12h16`,key:`s4cdu5`}]],aliases:[`send-horizonal`]}),_e=t({name:`trash`,size:24,node:[[`path`,{d:`M10 11v6`,key:`nco0om`}],[`path`,{d:`M14 11v6`,key:`outv1u`}],[`path`,{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6`,key:`miytrc`}],[`path`,{d:`M3 6h18`,key:`d0wm0j`}],[`path`,{d:`M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`,key:`e791ji`}]],aliases:[`trash-2`]}),ve=t({name:`upload`,size:24,node:[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]}),ye=t({name:`user-minus`,size:24,node:[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`22`,x2:`16`,y1:`11`,y2:`11`,key:`1shjgl`}]]}),be=t({name:`user-plus`,size:24,node:[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`19`,x2:`19`,y1:`8`,y2:`14`,key:`1bvyxn`}],[`line`,{x1:`22`,x2:`16`,y1:`11`,y2:`11`,key:`1shjgl`}]]}),xe=t({name:`users`,size:24,node:[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]}),Se=t({name:`users-round`,size:24,node:[[`path`,{d:`M18 21a8 8 0 0 0-16 0`,key:`3ypg7q`}],[`circle`,{cx:`10`,cy:`8`,r:`5`,key:`o932ke`}],[`path`,{d:`M22 20c0-3.37-2-6.5-4-8a5 5 0 0 0-.45-8.3`,key:`10s06x`}]],aliases:[`users-2`]}),J=t({name:`x`,size:24,node:[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]}),Y=`/chat/api`,X={conversations:()=>H.get(`${Y}/gespraeche`),direct:e=>H.post(`${Y}/direkt`,{user_id:e}),createGroup:(e,t)=>H.post(`${Y}/gruppen`,{name:e,members:t}),updateConversation:(e,t)=>H.put(`${Y}/gespraeche/${e}`,t),leave:e=>H.delete(`${Y}/gespraeche/${e}`),addMembers:(e,t)=>H.post(`${Y}/gespraeche/${e}/mitglieder`,{members:t}),removeMember:(e,t)=>H.delete(`${Y}/gespraeche/${e}/mitglieder/${t}`),setAdmin:(e,t,n)=>H.put(`${Y}/gespraeche/${e}/mitglieder/${t}`,{admin:n}),messages:(e,t)=>H.get(`${Y}/gespraeche/${e}/nachrichten${t?`?vor=${t}`:``}`),send(e,{body:t,gifUrl:n,replyTo:r,files:i}){let a=new FormData;return t&&a.append(`body`,t),n&&a.append(`gif_url`,n),r&&a.append(`reply_to`,r),(i??[]).forEach(e=>a.append(`files[]`,e)),H.post(`${Y}/gespraeche/${e}/nachrichten`,a)},edit:(e,t)=>H.put(`${Y}/nachrichten/${e}`,{body:t}),remove:e=>H.delete(`${Y}/nachrichten/${e}`),react:(e,t)=>H.post(`${Y}/nachrichten/${e}/reaktion`,{emoji:t}),read:(e,t)=>H.post(`${Y}/gespraeche/${e}/gelesen`,{message_id:t}),typing:e=>H.post(`${Y}/gespraeche/${e}/tippt`),updates:e=>H.get(`${Y}/neues?${new URLSearchParams(Object.entries(e).filter(([,e])=>e!=null))}`),unread:()=>H.get(`${Y}/ungelesen`),gifs:e=>H.get(`${Y}/gifs?q=${encodeURIComponent(e??``)}`),people:e=>H.get(`/personen/suche?q=${encodeURIComponent(e)}`)};function Z(e){window.dispatchEvent(new CustomEvent(`inhaus-chat:unread`,{detail:e}))}var Ce={class:`ih:grid ih:gap-2`},we={key:0,class:`ih:flex ih:flex-wrap ih:gap-1.5`},Te=[`aria-label`,`onClick`],Ee={class:`ih:relative`},De=[`autofocus`,`placeholder`],Oe={key:1,class:`ih:max-h-64 ih:overflow-y-auto ih:rounded-md ih:border ih:bg-popover ih:p-1`,role:`listbox`},ke=[`aria-selected`],Ae=[`onClick`,`onMouseenter`],je={class:`ih:min-w-0 ih:flex-1`},Me={class:`ih:block ih:truncate ih:font-medium`},Ne={key:0,class:`ih:block ih:truncate ih:text-xs ih:text-muted-foreground`},Pe={key:2,class:`ih:px-1 ih:text-[13px] ih:text-muted-foreground`},Fe={__name:`PeopleSelect`,props:u({multiple:{type:Boolean,default:!1},exclude:{type:Array,default:()=>[]},placeholder:{type:String,default:`Name oder E-Mail eingeben …`},autofocus:{type:Boolean,default:!1}},{modelValue:{type:Array,default:()=>[]},modelModifiers:{}}),emits:u([`pick`],[`update:modelValue`]),setup(e,{emit:t}){let r=e,i=t,u=C(e,`modelValue`),d=_(``),p=_([]),m=_(0),h=_(!1),y;T(d,e=>{if(clearTimeout(y),e.trim().length<2){p.value=[];return}y=setTimeout(async()=>{h.value=!0;try{let t=[...r.exclude,...u.value.map(e=>e.id)];p.value=(await X.people(e.trim())).people.filter(e=>!t.includes(e.id)),m.value=0}finally{h.value=!1}},200)});function b(e){e&&(i(`pick`,e),r.multiple&&(u.value=[...u.value,e]),d.value=``,p.value=[])}let E=e=>u.value=u.value.filter(t=>t.id!==e.id);return(t,r)=>(g(),o(`div`,Ce,[e.multiple&&u.value.length?(g(),o(`div`,we,[(g(!0),o(n,null,v(u.value,e=>(g(),o(`span`,{key:e.id,class:`ih:inline-flex ih:items-center ih:gap-1.5 ih:rounded-full ih:border ih:bg-card ih:py-0.5 ih:pr-1 ih:pl-0.5 ih:text-[13px]`},[l(S(V),{person:e,class:`ih:size-6 ih:text-[10px]`},null,8,[`person`]),c(` `+x(e.name)+` `,1),s(`button`,{type:`button`,class:`ih:rounded-full ih:p-0.5 ih:text-muted-foreground ih:hover:bg-muted ih:hover:text-foreground`,"aria-label":`${e.name} entfernen`,onClick:t=>E(e)},[l(S(J),{class:`ih:size-3.5`})],8,Te)]))),128))])):a(``,!0),s(`div`,Ee,[l(S(q),{class:`ih:pointer-events-none ih:absolute ih:top-1/2 ih:left-2.5 ih:size-4 ih:-translate-y-1/2 ih:text-muted-foreground`}),D(s(`input`,{"onUpdate:modelValue":r[0]||=e=>d.value=e,type:`search`,autocomplete:`off`,autofocus:e.autofocus,placeholder:e.placeholder,"aria-label":`Person suchen`,class:`ih:h-10 ih:w-full ih:rounded-md ih:border ih:border-input ih:bg-card ih:pr-3 ih:pl-8 ih:text-sm ih:shadow-xs ih:focus-visible:ring-3 ih:focus-visible:ring-ring/30 ih:focus-visible:outline-none`,onKeydown:[r[1]||=O(k(e=>m.value=Math.min(p.value.length-1,m.value+1),[`prevent`]),[`down`]),r[2]||=O(k(e=>m.value=Math.max(0,m.value-1),[`prevent`]),[`up`]),r[3]||=O(k(e=>b(p.value[m.value]),[`prevent`]),[`enter`])]},null,40,De),[[w,d.value]])]),p.value.length?(g(),o(`ul`,Oe,[(g(!0),o(n,null,v(p.value,(e,t)=>(g(),o(`li`,{key:e.id,role:`option`,"aria-selected":t===m.value},[s(`button`,{type:`button`,class:f([`ih:flex ih:w-full ih:items-center ih:gap-2.5 ih:rounded ih:px-2 ih:py-1.5 ih:text-left ih:text-sm`,t===m.value?`ih:bg-accent`:`ih:hover:bg-accent/60`]),onClick:t=>b(e),onMouseenter:e=>m.value=t},[l(S(V),{person:e,class:`ih:size-7 ih:text-[11px]`},null,8,[`person`]),s(`span`,je,[s(`span`,Me,x(e.name),1),e.job_title||e.department?(g(),o(`span`,Ne,x([e.job_title,e.department].filter(Boolean).join(` · `)),1)):a(``,!0)])],42,Ae)],8,ke))),128))])):d.value.trim().length>=2&&!h.value?(g(),o(`p`,Pe,`Niemand gefunden.`)):a(``,!0)]))}},Ie={class:`ih:grid ih:gap-5`},Le={class:`ih:flex ih:items-center ih:justify-between ih:gap-3 ih:text-sm`},Re={key:1,class:`ih:grid ih:gap-2`},ze={class:`ih:-mx-2 ih:grid`},Be={class:`ih:min-w-0 ih:flex-1 ih:text-sm`},Ve={class:`ih:font-medium`},He={key:0,class:`ih:text-muted-foreground`},Ue={key:1,class:`ih:ml-1.5 ih:inline-flex ih:items-center ih:gap-0.5 ih:text-xs ih:text-brand-text`},We=[`title`,`aria-label`,`onClick`],Ge=[`aria-label`,`onClick`],Ke={key:0,class:`ih:grid ih:gap-2 ih:rounded-md ih:border ih:p-3`},qe={class:`ih:flex ih:items-center ih:gap-1.5 ih:text-sm ih:font-medium`},Je={__name:`ConversationInfo`,props:u({conversation:{type:Object,required:!0},me:{type:Object,required:!0}},{open:{type:Boolean,default:!1},openModifiers:{}}),emits:u([`updated`,`left`],[`update:open`]),setup(e,{emit:t}){let u=e,d=C(e,`open`),f=t,p=r(()=>u.conversation.type===`group`),m=_(``),h=_([]),y=_(!1);T(d,e=>{e&&(m.value=u.conversation.name,h.value=[])});async function w(e,t){y.value=!0;try{let n=await e();f(`updated`,n.conversations),t&&U.success(t)}catch(e){U.error(e.message)}finally{y.value=!1}}let D=()=>w(()=>X.updateConversation(u.conversation.id,{name:m.value.trim()}),`Gruppe umbenannt`),O=e=>w(()=>X.updateConversation(u.conversation.id,{muted:e}),e?`Stummgeschaltet – keine Benachrichtigungen mehr`:`Benachrichtigungen wieder an`),A=()=>w(()=>X.addMembers(u.conversation.id,h.value.map(e=>e.id)),`Hinzugefügt`).then(()=>h.value=[]),F=e=>window.confirm(`${e.name} aus der Gruppe entfernen?`)&&w(()=>X.removeMember(u.conversation.id,e.id)),R=e=>w(()=>X.setAdmin(u.conversation.id,e.id,!e.admin));async function B(){window.confirm(p.value?`Gruppe verlassen? Sie sehen die Nachrichten danach nicht mehr.`:`Gespräch aus Ihrer Liste entfernen? Mit der nächsten Nachricht erscheint es wieder.`)&&(await w(()=>X.leave(u.conversation.id)),d.value=!1,f(`left`))}return(t,r)=>(g(),i(S(M),{open:d.value,"onUpdate:open":r[2]||=e=>d.value=e},{default:E(()=>[l(S(N),{class:`ih:max-h-[85dvh] ih:overflow-y-auto ih:sm:max-w-lg`},{default:E(()=>[l(S(I),null,{default:E(()=>[l(S(L),null,{default:E(()=>[c(x(e.conversation.name),1)]),_:1}),l(S(P),null,{default:E(()=>[c(x(p.value?`Gruppe mit ${e.conversation.members.length} Mitgliedern`:`Direktnachricht`),1)]),_:1})]),_:1}),s(`div`,Ie,[p.value&&e.conversation.is_admin?(g(),o(`form`,{key:0,class:`ih:flex ih:gap-2`,onSubmit:k(D,[`prevent`])},[l(S(z),{modelValue:m.value,"onUpdate:modelValue":r[0]||=e=>m.value=e,maxlength:`100`,"aria-label":`Name der Gruppe`},null,8,[`modelValue`]),l(S(j),{type:`submit`,variant:`outline`,disabled:y.value||!m.value.trim()||m.value.trim()===e.conversation.name},{default:E(()=>[...r[3]||=[c(`Umbenennen`,-1)]]),_:1},8,[`disabled`])],32)):a(``,!0),s(`label`,Le,[r[4]||=s(`span`,null,[s(`span`,{class:`ih:font-medium`},`Stummschalten`),s(`span`,{class:`ih:block ih:text-xs ih:text-muted-foreground`},`Keine Glocke und kein Push für dieses Gespräch.`)],-1),l(S(ee),{"model-value":e.conversation.muted,disabled:y.value,"onUpdate:modelValue":O},null,8,[`model-value`,`disabled`])]),p.value?(g(),o(`section`,Re,[r[7]||=s(`h3`,{class:`ih:text-sm ih:font-semibold`},`Mitglieder`,-1),s(`ul`,ze,[(g(!0),o(n,null,v(e.conversation.members,t=>(g(),o(`li`,{key:t.id,class:`ih:flex ih:items-center ih:gap-3 ih:rounded-md ih:px-2 ih:py-1.5 ih:hover:bg-muted/60`},[l(S(V),{person:t,class:`ih:size-8 ih:text-[11px]`},null,8,[`person`]),s(`span`,Be,[s(`span`,Ve,x(t.name),1),t.id===e.me.id?(g(),o(`span`,He,` (Sie)`)):a(``,!0),t.admin?(g(),o(`span`,Ue,[l(S(G),{class:`ih:size-3`}),r[5]||=c(` Admin`,-1)])):a(``,!0)]),e.conversation.is_admin&&t.id!==e.me.id?(g(),o(n,{key:0},[s(`button`,{type:`button`,class:`ih:rounded ih:p-1.5 ih:text-muted-foreground ih:hover:bg-accent ih:hover:text-foreground`,title:t.admin?`Admin-Rechte entziehen`:`Zum Admin machen`,"aria-label":t.admin?`${t.name}: Admin-Rechte entziehen`:`${t.name} zum Admin machen`,onClick:e=>R(t)},[l(S(G),{class:`ih:size-4`})],8,We),s(`button`,{type:`button`,class:`ih:rounded ih:p-1.5 ih:text-muted-foreground ih:hover:bg-accent ih:hover:text-destructive`,"aria-label":`${t.name} entfernen`,onClick:e=>F(t)},[l(S(ye),{class:`ih:size-4`})],8,Ge)],64)):a(``,!0)]))),128))]),e.conversation.is_admin?(g(),o(`div`,Ke,[s(`span`,qe,[l(S(be),{class:`ih:size-4`}),r[6]||=c(` Personen hinzufügen`,-1)]),l(Fe,{modelValue:h.value,"onUpdate:modelValue":r[1]||=e=>h.value=e,multiple:``,exclude:e.conversation.members.map(e=>e.id)},null,8,[`modelValue`,`exclude`]),h.value.length?(g(),i(S(j),{key:0,size:`sm`,class:`ih:justify-self-start`,disabled:y.value,onClick:A},{default:E(()=>[y.value?(g(),i(S(K),{key:0,class:`ih:animate-spin`})):a(``,!0),c(` `+x(h.value.length)+` hinzufügen`,1)]),_:1},8,[`disabled`])):a(``,!0)])):a(``,!0)])):a(``,!0),l(S(j),{variant:`outline`,class:`ih:justify-self-start ih:text-destructive ih:hover:text-destructive`,disabled:y.value,onClick:B},{default:E(()=>[(g(),i(b(p.value?S(de):S(ae)))),c(` `+x(p.value?`Gruppe verlassen`:`Aus der Liste entfernen`),1)]),_:1},8,[`disabled`])])]),_:1})]),_:1},8,[`open`]))}},Ye={__name:`ChatAvatar`,props:{conversation:{type:Object,required:!0},size:{type:String,default:`ih:size-10`}},setup(e){return(t,n)=>e.conversation.person?(g(),i(S(V),{key:0,person:e.conversation.person,class:f(e.size)},null,8,[`person`,`class`])):(g(),o(`span`,{key:1,class:f([`ih:grid ih:shrink-0 ih:place-items-center ih:rounded-full ih:bg-brand-soft ih:text-brand-text`,e.size]),"aria-hidden":`true`},[l(S(xe),{class:`ih:size-[45%]`})],2))}},Xe=new Intl.DateTimeFormat(`de-DE`,{hour:`2-digit`,minute:`2-digit`}),Ze=new Intl.DateTimeFormat(`de-DE`,{weekday:`short`}),Qe=new Intl.DateTimeFormat(`de-DE`,{day:`2-digit`,month:`2-digit`,year:`2-digit`}),$e=new Intl.DateTimeFormat(`de-DE`,{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`}),Q=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime();function et(e){if(!e)return``;let t=new Date(e),n=(Q(new Date)-Q(t))/864e5;return n===0?Xe.format(t):n===1?`Gestern`:n<7?Ze.format(t):Qe.format(t)}var tt=e=>Xe.format(new Date(e));function nt(e){let t=new Date(e),n=(Q(new Date)-Q(t))/864e5;return n===0?`Heute`:n===1?`Gestern`:$e.format(t)}var $=(e,t)=>Q(new Date(e))===Q(new Date(t));function rt(e){return e<1024?`${e} B`:e<1048576?`${Math.round(e/1024)} KB`:`${(e/1024/1024).toFixed(1).replace(`.`,`,`)} MB`}function it(e){let t=[],n=/(https?:\/\/[^\s<>"']+[^\s<>"'.,;:!?)\]])/g,r=0;for(let i of e.matchAll(n))i.index>r&&t.push({text:e.slice(r,i.index)}),t.push({text:i[0],href:i[0]}),r=i.index+i[0].length;return r!!e&&/^(\p{Extended_Pictographic}|\p{Emoji_Component}|‍|️|\s){1,12}$/u.test(e)&&[...e.replace(/\s/g,``)].length<=8,ot={class:`ih:flex ih:h-full ih:min-h-0 ih:flex-col`},st={class:`ih:flex ih:items-center ih:gap-2 ih:border-b ih:p-3`},ct={class:`ih:border-b ih:p-3`},lt={class:`ih:relative`},ut={class:`ih:min-h-0 ih:flex-1 ih:overflow-y-auto`,"aria-label":`Gespräche`},dt=[`aria-current`,`onClick`],ft={class:`ih:min-w-0 ih:flex-1`},pt={class:`ih:flex ih:items-baseline ih:gap-2`},mt={class:`ih:shrink-0 ih:text-[11px] ih:text-muted-foreground ih:tabular-nums`},ht={class:`ih:flex ih:items-center ih:gap-2`},gt=[`aria-label`],_t={key:0,class:`ih:p-6 ih:text-center ih:text-sm ih:text-muted-foreground`},vt={__name:`ConversationList`,props:{conversations:{type:Array,required:!0},activeId:{type:Number,default:null},canCreateGroups:{type:Boolean,default:!1}},emits:[`open`,`new-chat`,`new-group`],setup(e,{emit:t}){let c=e,u=t,d=_(``),p=r(()=>{let e=d.value.trim().toLowerCase();return e?c.conversations.filter(t=>[t.name,...t.members.map(e=>e.name)].join(` `).toLowerCase().includes(e)):c.conversations});return(t,r)=>(g(),o(`div`,ot,[s(`div`,st,[r[3]||=s(`h1`,{class:`ih:flex-1 ih:text-lg ih:font-semibold ih:tracking-tight`},`Nachrichten`,-1),e.canCreateGroups?(g(),i(S(j),{key:0,variant:`ghost`,size:`icon`,title:`Neue Gruppe`,"aria-label":`Neue Gruppe`,onClick:r[0]||=e=>u(`new-group`)},{default:E(()=>[l(S(Se))]),_:1})):a(``,!0),l(S(j),{size:`icon`,title:`Neue Nachricht`,"aria-label":`Neue Nachricht`,onClick:r[1]||=e=>u(`new-chat`)},{default:E(()=>[l(S(fe))]),_:1})]),s(`div`,ct,[s(`div`,lt,[l(S(q),{class:`ih:pointer-events-none ih:absolute ih:top-1/2 ih:left-2.5 ih:size-4 ih:-translate-y-1/2 ih:text-muted-foreground`}),D(s(`input`,{"onUpdate:modelValue":r[2]||=e=>d.value=e,type:`search`,placeholder:`Gespräche durchsuchen`,"aria-label":`Gespräche durchsuchen`,class:`ih:h-9 ih:w-full ih:rounded-md ih:bg-muted ih:pr-3 ih:pl-8 ih:text-sm ih:focus-visible:ring-3 ih:focus-visible:ring-ring/30 ih:focus-visible:outline-none`},null,512),[[w,d.value]])])]),s(`ul`,ut,[(g(!0),o(n,null,v(p.value,t=>(g(),o(`li`,{key:t.id},[s(`button`,{type:`button`,class:f([`ih:flex ih:w-full ih:items-center ih:gap-3 ih:px-3 ih:py-2.5 ih:text-left ih:transition-colors`,t.id===e.activeId?`ih:bg-brand-soft`:`ih:hover:bg-accent/60`]),"aria-current":t.id===e.activeId?`true`:void 0,onClick:e=>u(`open`,t.id)},[l(Ye,{conversation:t,size:`ih:size-11`},null,8,[`conversation`]),s(`span`,ft,[s(`span`,pt,[s(`span`,{class:f([`ih:min-w-0 ih:flex-1 ih:truncate ih:text-sm`,t.unread?`ih:font-semibold`:`ih:font-medium`])},x(t.name),3),s(`span`,mt,x(S(et)(t.last_message_at)),1)]),s(`span`,ht,[s(`span`,{class:f([`ih:min-w-0 ih:flex-1 ih:truncate ih:text-[13px]`,t.unread?`ih:text-foreground`:`ih:text-muted-foreground`])},x(t.preview??(t.type===`group`?`${t.members.length} Mitglieder`:`Noch keine Nachrichten`)),3),t.muted?(g(),i(S(re),{key:0,class:`ih:size-3.5 ih:shrink-0 ih:text-muted-foreground`,"aria-label":`Stummgeschaltet`})):a(``,!0),t.unread?(g(),o(`span`,{key:1,class:`ih:grid ih:h-5 ih:min-w-5 ih:shrink-0 ih:place-items-center ih:rounded-full ih:bg-brand ih:px-1.5 ih:text-[11px] ih:font-semibold ih:text-brand-foreground ih:tabular-nums`,"aria-label":`${t.unread} ungelesen`},x(t.unread>99?`99+`:t.unread),9,gt)):a(``,!0)])])],10,dt)]))),128)),p.value.length?a(``,!0):(g(),o(`li`,_t,x(d.value?`Nichts gefunden.`:`Noch keine Gespräche. Oben rechts eine neue Nachricht beginnen.`),1))])]))}},yt={class:`ih:grid ih:gap-4`},bt={key:0,class:`ih:grid ih:gap-1.5`},xt={class:`ih:grid ih:gap-1.5`},St={key:1,class:`ih:flex ih:items-center ih:gap-2 ih:text-sm ih:text-muted-foreground`},Ct={__name:`NewChatDialog`,props:u({group:{type:Boolean,default:!1},me:{type:Object,required:!0}},{open:{type:Boolean,default:!1},openModifiers:{}}),emits:u([`created`],[`update:open`]),setup(e,{emit:t}){let n=e,r=C(e,`open`),u=t,d=_(``),f=_([]),p=_(!1);T(r,e=>{e&&(d.value=``,f.value=[])});async function m(e){if(!n.group){p.value=!0;try{let t=await X.direct(e.id);r.value=!1,u(`created`,t)}catch(e){U.error(e.message)}finally{p.value=!1}}}async function h(){p.value=!0;try{let e=await X.createGroup(d.value.trim(),f.value.map(e=>e.id));r.value=!1,u(`created`,e)}catch(e){U.error(e.message)}finally{p.value=!1}}return(t,n)=>(g(),i(S(M),{open:r.value,"onUpdate:open":n[3]||=e=>r.value=e},{default:E(()=>[l(S(N),{class:`ih:sm:max-w-md`},{default:E(()=>[l(S(I),null,{default:E(()=>[l(S(L),null,{default:E(()=>[c(x(e.group?`Neue Gruppe`:`Neue Nachricht`),1)]),_:1}),l(S(P),null,{default:E(()=>[c(x(e.group?`Name und Mitglieder wählen – Sie verwalten die Gruppe.`:`An wen möchten Sie schreiben?`),1)]),_:1})]),_:1}),s(`div`,yt,[e.group?(g(),o(`div`,bt,[l(S(B),{for:`chat-group-name`},{default:E(()=>[...n[4]||=[c(`Name der Gruppe`,-1)]]),_:1}),l(S(z),{id:`chat-group-name`,modelValue:d.value,"onUpdate:modelValue":n[0]||=e=>d.value=e,maxlength:`100`,placeholder:`z. B. Station 3 – Frühdienst`},null,8,[`modelValue`])])):a(``,!0),s(`div`,xt,[e.group?(g(),i(S(B),{key:0},{default:E(()=>[...n[5]||=[c(`Mitglieder`,-1)]]),_:1})):a(``,!0),l(Fe,{modelValue:f.value,"onUpdate:modelValue":n[1]||=e=>f.value=e,multiple:e.group,exclude:[e.me.id],autofocus:``,onPick:m},null,8,[`modelValue`,`multiple`,`exclude`])]),p.value&&!e.group?(g(),o(`p`,St,[l(S(K),{class:`ih:size-4 ih:animate-spin`}),n[6]||=c(` Gespräch wird geöffnet …`,-1)])):a(``,!0)]),e.group?(g(),i(S(F),{key:0},{default:E(()=>[l(S(j),{variant:`ghost`,onClick:n[2]||=e=>r.value=!1},{default:E(()=>[...n[7]||=[c(`Abbrechen`,-1)]]),_:1}),l(S(j),{disabled:p.value||!d.value.trim()||!f.value.length,onClick:h},{default:E(()=>[p.value?(g(),i(S(K),{key:0,class:`ih:animate-spin`})):a(``,!0),n[8]||=c(` Gruppe erstellen `,-1)]),_:1},8,[`disabled`])]),_:1})):a(``,!0)]),_:1})]),_:1},8,[`open`]))}},wt=[{label:`Smileys`,icon:`😀`,emojis:`😀 😃 😄 😁 😆 😅 🤣 😂 🙂 🙃 😉 😊 😇 🥰 😍 🤩 😘 😗 😚 😋 😛 😜 🤪 😝 🤗 🤭 🤫 🤔 🤐 🤨 😐 😑 😶 😏 😒 🙄 😬 😌 😔 😪 😴 😷 🤒 🤕 🤢 🤧 🥵 🥶 🥴 😵 🤯 🤠 🥳 😎 🤓 🧐 😕 😟 🙁 😮 😯 😲 😳 🥺 😦 😧 😨 😰 😥 😢 😭 😱 😖 😣 😞 😓 😩 😫 🥱 😤 😡 😠 🤬`.split(` `)},{label:`Gesten`,icon:`👍`,emojis:`👍 👎 👌 🤌 ✌️ 🤞 🤟 🤘 🤙 👈 👉 👆 👇 ☝️ ✋ 🤚 🖐️ 🖖 👋 👏 🙌 👐 🤲 🤝 🙏 ✍️ 💪 🦾 👀 🧠 🫶 ❤️ 🧡 💛 💚 💙 💜 🖤 🤍 🤎 💔 ❣️ 💕 💞 💓 💗 💖 💘 💯 ✨ ⭐ 🌟 💥 🔥 🎉 🎊`.split(` `)},{label:`Menschen`,icon:`🧑`,emojis:`👶 🧒 👦 👧 🧑 👱 👨 🧔 👩 🧓 👴 👵 🙋 🙆 🙅 🤷 🤦 🙇 💁 🧑‍⚕️ 🧑‍🍳 🧑‍🔧 🧑‍🏫 🧑‍💻 🧑‍💼 🧑‍🔬 🧑‍🎨 🧑‍🚒 👮 🕵️ 💂 👷 🤴 👸 🧙 🧚 🦸 🏃 🚶 🧘 🏋️ 🚴 🤸 👯 💃 🕺 👪 🧑‍🤝‍🧑`.split(` `)},{label:`Natur`,icon:`🌿`,emojis:`🐶 🐱 🐭 🐹 🐰 🦊 🐻 🐼 🐨 🐯 🦁 🐮 🐷 🐸 🐵 🐔 🐧 🐦 🦆 🦉 🐴 🦄 🐝 🐞 🦋 🐢 🐍 🐙 🐠 🐬 🐳 🌵 🎄 🌲 🌳 🌴 🌱 🌿 🍀 🍁 🍂 🌷 🌹 🌻 🌼 🌸 🌞 🌝 🌙 ⭐ ☀️ 🌤️ ⛅ 🌧️ ⛈️ ❄️ ☃️ 🌈 🌊`.split(` `)},{label:`Essen`,icon:`🍕`,emojis:`🍏 🍎 🍐 🍊 🍋 🍌 🍉 🍇 🍓 🫐 🍒 🍑 🥭 🍍 🥥 🥝 🍅 🥑 🥦 🥕 🌽 🥔 🥐 🥖 🥨 🧀 🥚 🍳 🥞 🥓 🍔 🍟 🍕 🌭 🥪 🌮 🥗 🍝 🍜 🍲 🍣 🍰 🎂 🧁 🍩 🍪 🍫 🍬 🍭 🍦 ☕ 🍵 🧃 🥤 🍺 🍻 🥂 🍷`.split(` `)},{label:`Aktivitäten`,icon:`⚽`,emojis:`⚽ 🏀 🏈 ⚾ 🎾 🏐 🏓 🏸 🥅 ⛳ 🎣 🎽 🎿 ⛸️ 🥇 🥈 🥉 🏆 🏅 🎗️ 🎫 🎟️ 🎭 🎨 🎬 🎤 🎧 🎼 🎹 🥁 🎷 🎺 🎸 🎻 🎲 🧩 🎯 🎳 🎮 🎰`.split(` `)},{label:`Dinge`,icon:`💡`,emojis:`⌚ 📱 💻 ⌨️ 🖥️ 🖨️ 🖱️ 💾 📷 📞 ☎️ 📺 ⏰ ⏳ 💡 🔦 🕯️ 💰 💳 🧾 ✉️ 📧 📨 📦 📝 📁 📂 📅 📆 📌 📎 ✂️ 🔒 🔑 🔨 🛠️ 🧰 🩺 💊 💉 🩹 🧯 🛒 🎁 🎈 🏠 🏥 🏫 🚗 🚌 🚲 ✈️ 🚀 🕐`.split(` `)},{label:`Symbole`,icon:`✅`,emojis:`✅ ☑️ ✔️ ❌ ❎ ➕ ➖ ❓ ❗ ‼️ ⁉️ 💤 ⚠️ 🚫 ⛔ 🔴 🟠 🟡 🟢 🔵 🟣 ⚫ ⚪ 🔶 🔷 ▶️ ⏸️ ⏹️ 🔄 🔁 🆗 🆕 🆒 🆘 ℹ️ 🔔 🔕 📣 💬 💭 🗯️ ♻️ ⬆️ ⬇️ ⬅️ ➡️`.split(` `)}],Tt={class:`ih:flex ih:border-b ih:px-1`,role:`tablist`,"aria-label":`Emoji-Gruppen`},Et=[`aria-selected`,`title`,`onClick`],Dt=[`aria-label`],Ot=[`aria-label`,`onClick`],kt={__name:`EmojiPicker`,emits:[`pick`],setup(e,{emit:t}){let r=t,i=_(0);return(e,t)=>(g(),o(`div`,null,[s(`div`,Tt,[(g(!0),o(n,null,v(S(wt),(e,t)=>(g(),o(`button`,{key:e.label,type:`button`,role:`tab`,"aria-selected":i.value===t,title:e.label,class:f([`ih:grid ih:size-9 ih:place-items-center ih:text-lg ih:transition-opacity`,i.value===t?`ih:border-b-2 ih:border-brand`:`ih:opacity-60 ih:hover:opacity-100`]),onClick:e=>i.value=t},x(e.icon),11,Et))),128))]),s(`div`,{class:`ih:grid ih:max-h-60 ih:grid-cols-8 ih:gap-0.5 ih:overflow-y-auto ih:p-2`,role:`tabpanel`,"aria-label":S(wt)[i.value].label},[(g(!0),o(n,null,v(S(wt)[i.value].emojis,e=>(g(),o(`button`,{key:e,type:`button`,class:`ih:grid ih:aspect-square ih:place-items-center ih:rounded ih:text-xl ih:hover:bg-accent`,"aria-label":e,onClick:t=>r(`pick`,e)},x(e),9,Ot))),128))],8,Dt)]))}},At={class:`ih:border-b ih:p-2`},jt={class:`ih:relative`},Mt={class:`ih:max-h-72 ih:overflow-y-auto ih:p-2`},Nt={key:0,class:`ih:grid ih:place-items-center ih:py-8`},Pt={key:1,class:`ih:columns-2 ih:gap-1.5`},Ft=[`title`,`onClick`],It=[`src`,`alt`],Lt={key:2,class:`ih:py-6 ih:text-center ih:text-sm ih:text-muted-foreground`},Rt={key:0,class:`ih:border-t ih:px-3 ih:py-1.5 ih:text-[10px] ih:text-muted-foreground`},zt={__name:`GifPicker`,emits:[`pick`],setup(e,{emit:t}){let r=t,i=_(``),c=_([]),u=_(!1),d=_(!1),f;async function m(){d.value=!0;try{let e=await X.gifs(i.value);c.value=e.gifs,u.value=e.giphy}finally{d.value=!1}}return T(i,()=>{clearTimeout(f),f=setTimeout(m,300)}),h(m),(e,t)=>(g(),o(`div`,null,[s(`div`,At,[s(`div`,jt,[l(S(q),{class:`ih:pointer-events-none ih:absolute ih:top-1/2 ih:left-2.5 ih:size-4 ih:-translate-y-1/2 ih:text-muted-foreground`}),D(s(`input`,{"onUpdate:modelValue":t[0]||=e=>i.value=e,type:`search`,placeholder:`GIFs suchen`,"aria-label":`GIFs suchen`,autofocus:``,class:`ih:h-9 ih:w-full ih:rounded-md ih:bg-muted ih:pr-3 ih:pl-8 ih:text-sm ih:focus-visible:outline-none`},null,512),[[w,i.value]])])]),s(`div`,Mt,[d.value&&!c.value.length?(g(),o(`div`,Nt,[l(S(K),{class:`ih:size-5 ih:animate-spin ih:text-muted-foreground`})])):c.value.length?(g(),o(`div`,Pt,[(g(!0),o(n,null,v(c.value,e=>(g(),o(`button`,{key:e.url,type:`button`,class:`ih:mb-1.5 ih:block ih:w-full ih:overflow-hidden ih:rounded ih:bg-muted ih:hover:ring-2 ih:hover:ring-brand`,title:e.title,onClick:t=>r(`pick`,e)},[s(`img`,{src:e.preview,alt:e.title,loading:`lazy`,class:`ih:block ih:w-full`,style:p(e.width&&e.height?{aspectRatio:`${e.width} / ${e.height}`}:{})},null,12,It)],8,Ft))),128))])):(g(),o(`p`,Lt,x(i.value?`Keine GIFs gefunden.`:`Noch keine GIFs in der Sammlung.`),1))]),u.value?(g(),o(`p`,Rt,`Mit Suche über GIPHY – Suchbegriffe gehen an GIPHY.`)):a(``,!0)]))}},Bt={__name:`Popup`,emits:[`close`],setup(e,{emit:t}){let n=t,r=_(null),i=e=>r.value&&!r.value.contains(e.target)&&!e.target.closest?.(`[data-popup-toggle]`)&&n(`close`),a=e=>e.key===`Escape`&&n(`close`);return h(()=>{document.addEventListener(`pointerdown`,i),document.addEventListener(`keydown`,a)}),m(()=>{document.removeEventListener(`pointerdown`,i),document.removeEventListener(`keydown`,a)}),(e,t)=>(g(),o(`div`,{ref_key:`root`,ref:r,class:`ih:absolute ih:bottom-full ih:left-0 ih:z-30 ih:mb-2 ih:w-[min(22rem,calc(100vw-2rem))] ih:overflow-hidden ih:rounded-lg ih:border ih:bg-popover ih:text-popover-foreground ih:shadow-lg`,role:`dialog`},[y(e.$slots,`default`)],512))}},Vt={class:`ih:border-t ih:bg-card ih:p-3`},Ht={key:0,class:`ih:mb-2 ih:flex ih:items-start ih:gap-2 ih:rounded-md ih:border-l-3 ih:border-brand ih:bg-muted ih:px-3 ih:py-1.5 ih:text-[13px]`},Ut={class:`ih:min-w-0 ih:flex-1`},Wt={class:`ih:block ih:font-semibold`},Gt={key:0,class:`ih:line-clamp-1 ih:text-muted-foreground`},Kt={key:1,class:`ih:mb-2 ih:flex ih:gap-2 ih:overflow-x-auto ih:pb-1`},qt=[`src`,`alt`],Jt={key:1,class:`ih:flex ih:h-16 ih:w-36 ih:items-center ih:gap-2 ih:rounded-md ih:border ih:bg-muted ih:px-2 ih:text-xs`},Yt={class:`ih:min-w-0`},Xt={class:`ih:block ih:truncate ih:font-medium`},Zt=[`aria-label`,`onClick`],Qt={class:`ih:relative ih:flex ih:items-end ih:gap-1`},$t=[`aria-expanded`],en=[`aria-expanded`],tn=[`placeholder`],nn=[`disabled`,`aria-label`],rn={class:`ih:mt-1.5 ih:hidden ih:text-[11px] ih:text-muted-foreground ih:sm:block`},an={__name:`Composer`,props:{replyTo:{type:Object,default:null},editing:{type:Object,default:null},maxUploadMb:{type:Number,default:25},sending:{type:Boolean,default:!1}},emits:[`send`,`save-edit`,`cancel`,`typing`],setup(e,{expose:t,emit:u}){let p=e,m=u,h=_(``),y=_([]),b=_(null),C=_(null),O=_(null),k=r(()=>!p.sending&&(h.value.trim()||y.value.length));T(()=>p.editing,e=>{h.value=e?.body??``,d(A)}),T(()=>p.replyTo,e=>e&&d(A));function A(){b.value?.focus(),j()}function j(){let e=b.value;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,180)}px`)}let M=0;function N(){j(),Date.now()-M>3e3&&h.value.trim()&&(M=Date.now(),m(`typing`))}function P(e){for(let t of e){if(t.size>p.maxUploadMb*1024*1024){U.error(`„${t.name}“ ist größer als ${p.maxUploadMb} MB.`);continue}if(y.value.length>=10){U.error(`Höchstens 10 Dateien je Nachricht.`);break}y.value.push({file:t,url:t.type.startsWith(`image/`)?URL.createObjectURL(t):null})}A()}function F(e){let t=[...e.clipboardData?.files??[]];t.length&&(e.preventDefault(),P(t))}function I(e){let[t]=y.value.splice(e,1);t?.url&&URL.revokeObjectURL(t.url)}function L(){if(p.editing){h.value.trim()&&m(`save-edit`,h.value.trim());return}k.value&&(m(`send`,{body:h.value,files:y.value.map(e=>e.file)}),y.value.forEach(e=>e.url&&URL.revokeObjectURL(e.url)),y.value=[],h.value=``,d(j))}function R(e){e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),L()),e.key===`Escape`&&(p.editing||p.replyTo)&&m(`cancel`)}function z(e){let t=b.value,n=t?.selectionStart??h.value.length,r=t?.selectionEnd??h.value.length;h.value=h.value.slice(0,n)+e+h.value.slice(r),d(()=>{t?.focus(),t?.setSelectionRange(n+e.length,n+e.length)})}function B(e){O.value=null,m(`send`,{gifUrl:e.url})}let V=e=>O.value=O.value===e?null:e;return t({addFiles:P,focus:A}),(t,r)=>(g(),o(`div`,Vt,[e.replyTo||e.editing?(g(),o(`div`,Ht,[e.editing?(g(),i(S(he),{key:0,class:`ih:mt-0.5 ih:size-3.5 ih:shrink-0 ih:text-brand-text`})):a(``,!0),s(`span`,Ut,[s(`span`,Wt,x(e.editing?`Nachricht bearbeiten`:`Antwort an ${e.replyTo.user?.name??``}`),1),e.replyTo?(g(),o(`span`,Gt,x(e.replyTo.body||(e.replyTo.gif_url?`GIF`:`Datei`)),1)):a(``,!0)]),s(`button`,{type:`button`,class:`ih:rounded ih:p-0.5 ih:text-muted-foreground ih:hover:text-foreground`,"aria-label":`Abbrechen`,onClick:r[0]||=e=>m(`cancel`)},[l(S(J),{class:`ih:size-4`})])])):a(``,!0),y.value.length?(g(),o(`ul`,Kt,[(g(!0),o(n,null,v(y.value,(e,t)=>(g(),o(`li`,{key:t,class:`ih:relative ih:shrink-0`},[e.url?(g(),o(`img`,{key:0,src:e.url,alt:e.file.name,class:`ih:size-16 ih:rounded-md ih:border ih:object-cover`},null,8,qt)):(g(),o(`span`,Jt,[l(S(ce),{class:`ih:size-5 ih:shrink-0 ih:text-muted-foreground`}),s(`span`,Yt,[s(`span`,Xt,x(e.file.name),1),c(x(S(rt)(e.file.size)),1)])])),s(`button`,{type:`button`,class:`ih:absolute ih:-top-1.5 ih:-right-1.5 ih:grid ih:size-5 ih:place-items-center ih:rounded-full ih:bg-foreground ih:text-background`,"aria-label":`${e.file.name} entfernen`,onClick:e=>I(t)},[l(S(J),{class:`ih:size-3`})],8,Zt)]))),128))])):a(``,!0),s(`div`,Qt,[O.value===`emoji`?(g(),i(Bt,{key:0,onClose:r[1]||=e=>O.value=null},{default:E(()=>[l(kt,{onPick:z})]),_:1})):a(``,!0),O.value===`gif`?(g(),i(Bt,{key:1,onClose:r[2]||=e=>O.value=null},{default:E(()=>[l(zt,{onPick:B})]),_:1})):a(``,!0),e.editing?a(``,!0):(g(),o(n,{key:2},[s(`button`,{type:`button`,"data-popup-toggle":``,class:f([`ih:grid ih:size-10 ih:shrink-0 ih:place-items-center ih:rounded-full ih:text-muted-foreground ih:hover:bg-muted ih:hover:text-foreground`,{"ih:bg-muted ih:text-foreground":O.value===`emoji`}]),"aria-label":`Emoji einfügen`,"aria-expanded":O.value===`emoji`,onClick:r[3]||=e=>V(`emoji`)},[l(S(se),{class:`ih:size-5`})],10,$t),s(`button`,{type:`button`,"data-popup-toggle":``,class:f([`ih:grid ih:h-10 ih:shrink-0 ih:place-items-center ih:rounded-full ih:px-2 ih:text-xs ih:font-bold ih:text-muted-foreground ih:hover:bg-muted ih:hover:text-foreground`,{"ih:bg-muted ih:text-foreground":O.value===`gif`}]),"aria-label":`GIF senden`,"aria-expanded":O.value===`gif`,onClick:r[4]||=e=>V(`gif`)},`GIF`,10,en),s(`button`,{type:`button`,class:`ih:grid ih:size-10 ih:shrink-0 ih:place-items-center ih:rounded-full ih:text-muted-foreground ih:hover:bg-muted ih:hover:text-foreground`,"aria-label":`Datei anhängen`,onClick:r[5]||=e=>C.value?.click()},[l(S(me),{class:`ih:size-5`})]),s(`input`,{ref_key:`fileInput`,ref:C,type:`file`,multiple:``,class:`ih:hidden`,onChange:r[6]||=e=>{P([...e.target.files]),e.target.value=``}},null,544)],64)),D(s(`textarea`,{ref_key:`input`,ref:b,"onUpdate:modelValue":r[7]||=e=>h.value=e,rows:`1`,maxlength:`5000`,placeholder:e.editing?`Nachricht bearbeiten`:`Nachricht schreiben`,"aria-label":`Nachricht`,class:`ih:max-h-[180px] ih:min-h-10 ih:flex-1 ih:resize-none ih:rounded-2xl ih:border ih:border-input ih:bg-background ih:px-4 ih:py-2 ih:text-[15px] ih:leading-snug ih:focus-visible:ring-3 ih:focus-visible:ring-ring/30 ih:focus-visible:outline-none`,onInput:N,onKeydown:R,onPaste:F},null,40,tn),[[w,h.value]]),s(`button`,{type:`button`,class:`ih:grid ih:size-10 ih:shrink-0 ih:place-items-center ih:rounded-full ih:bg-brand ih:text-brand-foreground ih:transition-opacity ih:disabled:opacity-40`,disabled:e.editing?!h.value.trim():!k.value,"aria-label":e.editing?`Speichern`:`Senden`,onClick:L},[e.sending?(g(),i(S(K),{key:0,class:`ih:size-5 ih:animate-spin`})):(g(),i(S(ge),{key:1,class:`ih:size-5`}))],8,nn)]),s(`p`,rn,[r[8]||=s(`kbd`,{class:`ih:font-sans`},`Enter`,-1),r[9]||=c(` senden · `,-1),r[10]||=s(`kbd`,{class:`ih:font-sans`},`Umschalt + Enter`,-1),r[11]||=c(` neue Zeile · Bilder lassen sich auch einfügen oder hierher ziehen `,-1),l(S(le),{class:`ih:inline ih:size-3`})])]))}},on={key:0,class:`ih:my-3 ih:text-center`},sn={class:`ih:inline-block ih:rounded-full ih:bg-muted ih:px-3 ih:py-1 ih:text-xs ih:text-muted-foreground`},cn=[`id`],ln={key:0,class:`ih:w-8 ih:shrink-0`},un={key:0,class:`ih:mb-0.5 ih:px-3 ih:text-xs ih:font-medium ih:text-muted-foreground`},dn={key:0,class:`ih:rounded-2xl ih:border ih:border-dashed ih:px-3 ih:py-2 ih:text-sm ih:text-muted-foreground ih:italic`},fn={class:`ih:block ih:font-semibold`},pn={class:`ih:line-clamp-2 ih:opacity-80`},mn=[`src`],hn=[`href`,`title`],gn=[`src`,`alt`],_n=[`href`],vn={class:`ih:min-w-0 ih:flex-1`},yn={class:`ih:block ih:truncate ih:text-sm ih:font-medium`},bn={class:`ih:block ih:text-xs ih:opacity-75`},xn=[`href`],Sn={key:2,class:`ih:flex ih:shrink-0 ih:items-center ih:opacity-0 ih:transition-opacity ih:group-hover:opacity-100 ih:focus-within:opacity-100 ih:[@media(hover:none)]:opacity-100`},Cn={class:`ih:group/react ih:relative`},wn={type:`button`,class:`ih:grid ih:size-7 ih:place-items-center ih:rounded-full ih:text-muted-foreground ih:hover:bg-muted`,"aria-label":`Reagieren`},Tn=[`aria-label`,`onClick`],En={key:1,class:`ih:relative ih:z-10 ih:-mt-1.5 ih:flex ih:flex-wrap ih:gap-1 ih:px-2`},Dn=[`aria-pressed`,`aria-label`,`onClick`],On={class:`ih:text-sm`},kn={class:`ih:mt-0.5 ih:px-1 ih:text-[11px] ih:text-muted-foreground ih:tabular-nums`},An={__name:`MessageBubble`,props:{message:{type:Object,required:!0},showAuthor:{type:Boolean,default:!0},showAvatar:{type:Boolean,default:!0},group:{type:Boolean,default:!1},reactions:{type:Array,required:!0},read:{type:Boolean,default:!1}},emits:[`react`,`reply`,`edit`,`delete`,`jump`],setup(e,{emit:t}){let u=e,d=t,m=r(()=>u.message),h=r(()=>!m.value.attachments.length&&!m.value.reply_to&&at(m.value.body)),_=r(()=>m.value.attachments.filter(e=>e.image)),y=r(()=>m.value.attachments.filter(e=>!e.image));return(t,r)=>m.value.kind===`system`?(g(),o(`div`,on,[s(`span`,sn,x(m.value.body),1)])):(g(),o(`div`,{key:1,id:`nachricht-${m.value.id}`,class:f([`ih:group ih:flex ih:items-end ih:gap-2`,[m.value.mine?`ih:flex-row-reverse`:``,e.showAuthor?`ih:mt-3`:`ih:mt-0.5`]])},[e.group&&!m.value.mine?(g(),o(`div`,ln,[e.showAvatar&&m.value.user?(g(),i(S(V),{key:0,person:m.value.user,class:`ih:size-8 ih:text-[11px]`},null,8,[`person`])):a(``,!0)])):a(``,!0),s(`div`,{class:f([`ih:flex ih:max-w-[min(34rem,80%)] ih:min-w-0 ih:flex-col`,m.value.mine?`ih:items-end`:`ih:items-start`])},[e.group&&!m.value.mine&&e.showAuthor?(g(),o(`span`,un,x(m.value.user?.name??`Gelöschtes Konto`),1)):a(``,!0),s(`div`,{class:f([`ih:relative ih:flex ih:items-center ih:gap-1`,m.value.mine?`ih:flex-row-reverse`:``])},[m.value.deleted?(g(),o(`div`,dn,`Nachricht gelöscht`)):(g(),o(`div`,{key:1,class:f([`ih:min-w-0 ih:overflow-hidden ih:text-[15px] ih:leading-snug`,h.value||m.value.kind===`gif`?``:[m.value.mine?`ih:rounded-2xl ih:rounded-br-md ih:bg-brand ih:text-brand-foreground`:`ih:rounded-2xl ih:rounded-bl-md ih:border ih:bg-card`,_.value.length&&!m.value.body?``:`ih:px-3 ih:py-2`]])},[m.value.reply_to?(g(),o(`button`,{key:0,type:`button`,class:f([`ih:mb-1.5 ih:block ih:w-full ih:rounded-md ih:border-l-3 ih:px-2 ih:py-1 ih:text-left ih:text-[13px]`,m.value.mine?`ih:border-white/60 ih:bg-white/15`:`ih:border-brand ih:bg-muted`]),onClick:r[0]||=e=>d(`jump`,m.value.reply_to.id)},[s(`span`,fn,x(m.value.reply_to.name),1),s(`span`,pn,x(m.value.reply_to.text),1)],2)):a(``,!0),m.value.kind===`gif`?(g(),o(`img`,{key:1,src:m.value.gif_url,alt:`GIF`,loading:`lazy`,class:`ih:max-h-60 ih:rounded-2xl`},null,8,mn)):a(``,!0),_.value.length?(g(),o(`div`,{key:2,class:f([`ih:grid ih:gap-0.5`,_.value.length>1?`ih:grid-cols-2`:``])},[(g(!0),o(n,null,v(_.value,e=>(g(),o(`a`,{key:e.id,href:e.url,target:`_blank`,rel:`noopener`,class:`ih:block ih:overflow-hidden ih:bg-muted`,title:e.name},[s(`img`,{src:e.url,alt:e.name,loading:`lazy`,class:`ih:block ih:max-h-72 ih:w-full ih:object-cover`,style:p(e.width?{aspectRatio:`${e.width} / ${e.height}`}:{})},null,12,gn)],8,hn))),128))],2)):a(``,!0),(g(!0),o(n,null,v(y.value,e=>(g(),o(`a`,{key:e.id,href:e.url,class:f([`ih:my-1 ih:flex ih:items-center ih:gap-2.5 ih:rounded-lg ih:p-2 ih:no-underline`,m.value.mine?`ih:bg-white/15 ih:hover:bg-white/25`:`ih:bg-muted ih:hover:bg-accent`])},[l(S(R),{extension:e.name.split(`.`).pop(),class:`ih:shrink-0`},null,8,[`extension`]),s(`span`,vn,[s(`span`,yn,x(e.name),1),s(`span`,bn,x(S(rt)(e.size)),1)]),l(S(ie),{class:`ih:size-4 ih:shrink-0 ih:opacity-75`})],10,_n))),128)),m.value.body?(g(),o(`p`,{key:3,class:f([`ih:break-words ih:whitespace-pre-wrap`,[h.value?`ih:text-4xl ih:leading-tight`:``,_.value.length?`ih:px-3 ih:py-2`:``]])},[(g(!0),o(n,null,v(S(it)(m.value.body),(e,t)=>(g(),o(n,{key:t},[e.href?(g(),o(`a`,{key:0,href:e.href,target:`_blank`,rel:`noopener noreferrer`,class:`ih:underline ih:underline-offset-2`},x(e.text),9,xn)):(g(),o(n,{key:1},[c(x(e.text),1)],64))],64))),128))],2)):a(``,!0)],2)),m.value.deleted?a(``,!0):(g(),o(`div`,Sn,[s(`div`,Cn,[s(`button`,wn,[l(S(oe),{class:`ih:size-4`})]),s(`div`,{class:f([`ih:absolute ih:bottom-full ih:z-20 ih:hidden ih:gap-0.5 ih:rounded-full ih:border ih:bg-popover ih:p-1 ih:shadow-md ih:group-focus-within/react:flex ih:group-hover/react:flex`,m.value.mine?`ih:right-0`:`ih:left-0`])},[(g(!0),o(n,null,v(e.reactions,e=>(g(),o(`button`,{key:e,type:`button`,class:`ih:grid ih:size-8 ih:place-items-center ih:rounded-full ih:text-lg ih:hover:bg-accent`,"aria-label":`Mit ${e} reagieren`,onClick:t=>d(`react`,e)},x(e),9,Tn))),128))],2)]),s(`button`,{type:`button`,class:`ih:grid ih:size-7 ih:place-items-center ih:rounded-full ih:text-muted-foreground ih:hover:bg-muted`,"aria-label":`Antworten`,onClick:r[1]||=e=>d(`reply`)},[l(S(W),{class:`ih:size-4`})]),m.value.mine?(g(),o(n,{key:0},[m.value.body&&m.value.kind===`text`?(g(),o(`button`,{key:0,type:`button`,class:`ih:grid ih:size-7 ih:place-items-center ih:rounded-full ih:text-muted-foreground ih:hover:bg-muted`,"aria-label":`Bearbeiten`,onClick:r[2]||=e=>d(`edit`)},[l(S(he),{class:`ih:size-4`})])):a(``,!0),s(`button`,{type:`button`,class:`ih:grid ih:size-7 ih:place-items-center ih:rounded-full ih:text-muted-foreground ih:hover:bg-muted ih:hover:text-destructive`,"aria-label":`Löschen`,onClick:r[3]||=e=>d(`delete`)},[l(S(_e),{class:`ih:size-4`})])],64)):a(``,!0)]))],2),m.value.reactions.length?(g(),o(`div`,En,[(g(!0),o(n,null,v(m.value.reactions,e=>(g(),o(`button`,{key:e.emoji,type:`button`,class:f([`ih:flex ih:items-center ih:gap-1 ih:rounded-full ih:border ih:px-1.5 ih:text-xs ih:shadow-xs ih:tabular-nums`,e.mine?`ih:border-brand ih:bg-brand-soft`:`ih:bg-card`]),"aria-pressed":e.mine,"aria-label":`${e.emoji} ${e.count}`,onClick:t=>d(`react`,e.emoji)},[s(`span`,On,x(e.emoji),1),c(x(e.count>1?e.count:``),1)],10,Dn))),128))])):a(``,!0),s(`span`,kn,[c(x(S(tt)(m.value.created_at)),1),m.value.edited?(g(),o(n,{key:0},[c(` · bearbeitet`)],64)):a(``,!0),m.value.mine&&e.read?(g(),o(n,{key:1},[c(` · gelesen`)],64)):a(``,!0)])],2)],10,cn))}},jn=[`aria-label`],Mn={class:`ih:flex ih:items-center ih:gap-3 ih:border-b ih:px-3 ih:py-2.5`},Nn={class:`ih:min-w-0 ih:flex-1`},Pn={class:`ih:flex ih:items-center ih:gap-1.5 ih:truncate ih:font-semibold`},Fn=[`href`],In={key:1,class:`ih:truncate`},Ln=[`aria-label`],Rn={key:0,class:`ih:grid ih:h-full ih:place-items-center`},zn={key:0,class:`ih:flex ih:justify-center ih:py-2`},Bn={key:1,class:`ih:py-10 ih:text-center ih:text-sm ih:text-muted-foreground`},Vn={key:0,class:`ih:my-4 ih:flex ih:justify-center`},Hn={class:`ih:rounded-full ih:bg-card ih:px-3 ih:py-1 ih:text-xs ih:font-medium ih:text-muted-foreground ih:shadow-xs`},Un={key:1,class:`ih:my-3 ih:flex ih:items-center ih:gap-3 ih:text-xs ih:font-semibold ih:text-brand-text`},Wn={key:1,class:`ih:pointer-events-none ih:absolute ih:inset-2 ih:z-20 ih:grid ih:place-items-center ih:rounded-xl ih:border-2 ih:border-dashed ih:border-brand ih:bg-brand-soft/80 ih:text-brand-text`},Gn={class:`ih:flex ih:items-center ih:gap-2 ih:font-medium`},Kn={__name:`Thread`,props:{conversation:{type:Object,required:!0},me:{type:Object,required:!0},reactions:{type:Array,required:!0},maxUploadMb:{type:Number,default:25},typing:{type:Array,default:()=>[]}},emits:[`back`,`info`,`changed`,`read`],setup(e,{expose:t,emit:u}){let p=e,m=u,y=_([]),b=_(!1),C=_(!0),w=_(!1),E=_(!1),D=_(null),O=_(null),A=_(null),j=_(null),M=_(!0),N=_(0),P=_(!1),F=_(null),I=r(()=>p.conversation.type===`group`),L=()=>y.value.at(-1)?.id??0,R=r(()=>[...y.value].reverse().find(e=>e.mine&&!e.deleted&&e.kind!==`system`)?.id);async function z(){C.value=!0,y.value=[],D.value=O.value=null;try{let e=await X.messages(p.conversation.id);y.value=e.messages,b.value=e.more;let t=p.conversation.last_read_id??0;F.value=p.conversation.unread?e.messages.find(e=>e.id>t&&!e.mine&&e.kind!==`system`)?.id??null:null}finally{C.value=!1,await d(),V(F.value?document.getElementById(`nachricht-${F.value}`):null),W(),j.value?.focus()}}async function B(){if(!b.value||w.value||!y.value.length)return;w.value=!0;let e=A.value,t=e.scrollHeight;try{let n=await X.messages(p.conversation.id,y.value[0].id);y.value=[...n.messages,...y.value],b.value=n.more,await d(),e.scrollTop=e.scrollHeight-t}finally{w.value=!1}}function V(e){let t=A.value;t&&(e?e.scrollIntoView({block:`center`}):t.scrollTop=t.scrollHeight,N.value=0)}function ee(){let e=A.value;M.value=e.scrollHeight-e.scrollTop-e.clientHeight<80,M.value&&(N.value=0,W()),e.scrollTop<120&&B()}let H;function W(){clearTimeout(H),H=setTimeout(async()=>{if(![...y.value].reverse().find(e=>!e.mine)||document.visibilityState!==`visible`||!M.value||!p.conversation.unread)return;let e=await X.read(p.conversation.id,L());m(`read`,{id:p.conversation.id,unread:e.unread})},400)}async function G(e){let t=e.filter(e=>e.conversation_id===p.conversation.id);if(!t.length)return;let n=new Map(y.value.map(e=>[e.id,e])),r=0;for(let e of t)n.has(e.id)?Object.assign(n.get(e.id),e):e.id>L()&&(y.value.push(e),r+=+!e.mine);if(!r)return;let i=M.value;await d(),i?(V(),W()):N.value+=r}async function ie(e){E.value=!0;try{let{message:t}=await X.send(p.conversation.id,{...e,replyTo:D.value?.id});D.value=null,y.value.some(e=>e.id===t.id)||y.value.push(t),await d(),V(),m(`changed`)}catch(e){U.error(e.message)}finally{E.value=!1}}async function ae(e){let t=O.value;try{await X.edit(t.id,e),Object.assign(t,{body:e,edited:!0}),O.value=null}catch(e){U.error(e.message)}}async function oe(e){window.confirm(`Nachricht für alle löschen?`)&&(await X.remove(e.id),Object.assign(e,{deleted:!0,body:null,gif_url:null,attachments:[],reactions:[]}),m(`changed`))}async function se(e,t){let n=e.reactions.find(e=>e.emoji===t);n?.mine?(n.count--,n.mine=!1,e.reactions=e.reactions.filter(e=>e.count>0)):n?(n.count++,n.mine=!0):e.reactions.push({emoji:t,count:1,mine:!0}),await X.react(e.id,t).catch(e=>U.error(e.message))}function ce(e){let t=document.getElementById(`nachricht-${e}`);t&&(t.scrollIntoView({block:`center`,behavior:`smooth`}),t.classList.add(`ih:animate-pulse`),setTimeout(()=>t.classList.remove(`ih:animate-pulse`),1500))}function le(e){P.value=!1;let t=[...e.dataTransfer?.files??[]];t.length&&j.value?.addFiles(t)}let de=(e,t)=>{let n=y.value[t-1];return!n||n.kind===`system`||n.user?.id!==e.user?.id||!$(n.created_at,e.created_at)||new Date(e.created_at)-new Date(n.created_at)>3e5},fe=(e,t)=>{let n=y.value[t+1];return!n||n.kind===`system`||n.user?.id!==e.user?.id||!$(n.created_at,e.created_at)},pe=r(()=>p.typing.length?`${p.typing.join(`, `)} ${p.typing.length===1?`schreibt`:`schreiben`} …`:I.value?p.conversation.members.map(e=>e.first_name||e.name).join(`, `):p.conversation.person?.job_title??``);return T(()=>p.conversation.id,z),h(z),t({merge:G,lastId:L}),(t,r)=>(g(),o(`section`,{class:`ih:relative ih:flex ih:h-full ih:min-h-0 ih:flex-col`,"aria-label":`Gespräch mit ${e.conversation.name}`,onDragover:r[5]||=k(e=>P.value=!0,[`prevent`]),onDragleave:r[6]||=k(e=>P.value=!1,[`self`]),onDrop:k(le,[`prevent`])},[s(`header`,Mn,[s(`button`,{type:`button`,class:`ih:grid ih:size-9 ih:place-items-center ih:rounded-md ih:text-muted-foreground ih:hover:bg-accent ih:lg:hidden`,"aria-label":`Zurück zur Übersicht`,onClick:r[0]||=e=>m(`back`)},[l(S(ne),{class:`ih:size-5`})]),l(Ye,{conversation:e.conversation},null,8,[`conversation`]),s(`div`,Nn,[s(`h2`,Pn,[e.conversation.person?(g(),o(`a`,{key:0,href:`/personen/${e.conversation.person.id}`,class:`ih:truncate ih:hover:underline`},x(e.conversation.name),9,Fn)):(g(),o(`span`,In,x(e.conversation.name),1)),e.conversation.muted?(g(),i(S(re),{key:2,class:`ih:size-3.5 ih:shrink-0 ih:text-muted-foreground`,"aria-label":`Stummgeschaltet`})):a(``,!0)]),s(`p`,{class:f([`ih:truncate ih:text-xs`,e.typing.length?`ih:text-brand-text`:`ih:text-muted-foreground`]),"aria-live":`polite`},x(pe.value),3)]),s(`button`,{type:`button`,class:`ih:grid ih:size-9 ih:place-items-center ih:rounded-md ih:text-muted-foreground ih:hover:bg-accent`,"aria-label":I.value?`Gruppe: Mitglieder und Einstellungen`:`Einstellungen zum Gespräch`,onClick:r[1]||=e=>m(`info`)},[l(S(ue),{class:`ih:size-5`})],8,Ln)]),s(`div`,{ref_key:`scroller`,ref:A,class:`ih:min-h-0 ih:flex-1 ih:overflow-y-auto ih:bg-muted/30 ih:px-3 ih:py-4 ih:sm:px-5`,role:`log`,"aria-live":`polite`,"aria-relevant":`additions`,onScrollPassive:ee},[C.value?(g(),o(`div`,Rn,[l(S(K),{class:`ih:size-6 ih:animate-spin ih:text-muted-foreground`})])):(g(),o(n,{key:1},[w.value?(g(),o(`div`,zn,[l(S(K),{class:`ih:size-4 ih:animate-spin ih:text-muted-foreground`})])):a(``,!0),y.value.length?a(``,!0):(g(),o(`p`,Bn,`Schreiben Sie die erste Nachricht.`)),(g(!0),o(n,null,v(y.value,(t,i)=>(g(),o(n,{key:t.id},[i===0||!S($)(y.value[i-1].created_at,t.created_at)?(g(),o(`div`,Vn,[s(`span`,Hn,x(S(nt)(t.created_at)),1)])):a(``,!0),t.id===F.value?(g(),o(`div`,Un,[...r[7]||=[s(`span`,{class:`ih:h-px ih:flex-1 ih:bg-brand/40`},null,-1),c(`Neu`,-1),s(`span`,{class:`ih:h-px ih:flex-1 ih:bg-brand/40`},null,-1)]])):a(``,!0),l(An,{message:t,group:I.value,"show-author":de(t,i),"show-avatar":fe(t,i),reactions:e.reactions,read:t.id===R.value&&!!e.conversation.others_read_id&&e.conversation.others_read_id>=t.id,onReact:e=>se(t,e),onReply:e=>{D.value=t,O.value=null},onEdit:e=>{O.value=t,D.value=null},onDelete:e=>oe(t),onJump:ce},null,8,[`message`,`group`,`show-author`,`show-avatar`,`reactions`,`read`,`onReact`,`onReply`,`onEdit`,`onDelete`])],64))),128))],64))],544),N.value?(g(),o(`button`,{key:0,type:`button`,class:`ih:absolute ih:bottom-28 ih:left-1/2 ih:z-10 ih:flex ih:-translate-x-1/2 ih:items-center ih:gap-1.5 ih:rounded-full ih:bg-brand ih:px-3 ih:py-1.5 ih:text-xs ih:font-medium ih:text-brand-foreground ih:shadow-lg`,onClick:r[2]||=e=>{V(),W()}},[l(S(te),{class:`ih:size-3.5`}),c(` `+x(N.value)+` `+x(N.value===1?`neue Nachricht`:`neue Nachrichten`),1)])):a(``,!0),l(an,{ref_key:`composer`,ref:j,"reply-to":D.value,editing:O.value,sending:E.value,"max-upload-mb":e.maxUploadMb,onSend:ie,onSaveEdit:ae,onCancel:r[3]||=e=>{D.value=null,O.value=null},onTyping:r[4]||=t=>S(X).typing(e.conversation.id).catch(()=>{})},null,8,[`reply-to`,`editing`,`sending`,`max-upload-mb`]),P.value?(g(),o(`div`,Wn,[s(`span`,Gn,[l(S(ve),{class:`ih:size-5`}),r[8]||=c(` Dateien hier ablegen`,-1)])])):a(``,!0)],40,jn))}},qn=`modulepreload`,Jn=function(e,t){return new URL(e,t).href},Yn={},Xn=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=Jn(t,n),t=s(t),t in Yn)return;Yn[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:qn,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})};function Zn({realtime:t,userId:n,openId:r,lastId:i,onUpdate:a}){let o=null,s=null,c=!1,l=!1,u=null,d=()=>{let e=document.visibilityState===`visible`;return u?.connection?.state===`connected`?e?2e4:6e4:e?document.hasFocus()?3e3:6e3:3e4};async function f(){if(!(c||l)){c=!0,clearTimeout(s);try{let e=await X.updates({seit:o,offen:r(),nach:i()});o=e.cursor,a(e)}catch{}finally{c=!1,l||(s=setTimeout(f,d()))}}}let p=()=>document.visibilityState===`visible`&&f();return document.addEventListener(`visibilitychange`,p),window.addEventListener(`focus`,p),t&&Xn(async()=>{let{default:t}=await import(`../chunks/pusher-DXDYBH7H.js`).then(t=>e(t.default,1));return{default:t}},__vite__mapDeps([0,1]),import.meta.url).then(({default:e})=>{l||(u=new e(t.key,{cluster:t.cluster,...t.host?{wsHost:t.host,wsPort:t.port,wssPort:t.port,forceTLS:t.tls,enabledTransports:[`ws`,`wss`]}:{},channelAuthorization:{endpoint:`/chat/api/echtzeit/anmelden`,headers:{"X-XSRF-TOKEN":decodeURIComponent(document.cookie.match(/(?:^|; )XSRF-TOKEN=([^;]*)/)?.[1]??``),Accept:`application/json`}}}),u.subscribe(`private-chat-user-${n}`).bind(`update`,()=>f()))}).catch(()=>{}),f(),{now:f,reset(){o=null,f()},stop(){l=!0,clearTimeout(s),document.removeEventListener(`visibilitychange`,p),window.removeEventListener(`focus`,p),u?.disconnect()}}}var Qn={class:`ih:-mx-4 ih:-my-6 ih:flex ih:h-[calc(100dvh-4rem)] ih:overflow-hidden ih:border-y ih:bg-card ih:lg:mx-0 ih:lg:my-0 ih:lg:h-[calc(100dvh-8.5rem)] ih:lg:rounded-xl ih:lg:border ih:lg:shadow-xs`},$n={key:1,class:`ih:grid ih:h-full ih:place-items-center ih:p-8 ih:text-center`},er={__name:`Index`,props:{me:{type:Object,required:!0},conversations:{type:Array,required:!0},activeId:{type:Number,default:null},canCreateGroups:{type:Boolean,default:!1},realtime:{type:Object,default:null},reactions:{type:Array,required:!0},maxUploadMb:{type:Number,default:25}},setup(e){let t=e,n=_(t.conversations),c=_(t.activeId),u=_([]),d=_(null),p=_(null),v=_(!1),y=r(()=>n.value.find(e=>e.id===c.value)??null);function b(e,t=!0){c.value=e,u.value=[],t&&location.pathname!==`/chat/${e??``}`.replace(/\/$/,``)&&history.pushState({chat:e},``,e?`/chat/${e}`:`/chat`),w?.now()}let x=()=>b(Number(location.pathname.split(`/`)[2])||null,!1);function C(e){e&&(n.value=e,Z(e.reduce((e,t)=>e+(t.muted?0:t.unread),0)))}let w=null;h(()=>{window.addEventListener(`popstate`,x),w=Zn({realtime:t.realtime,userId:t.me.id,openId:()=>c.value,lastId:()=>d.value?.lastId()??0,onUpdate(e){C(e.conversations),u.value=e.typing??[],d.value?.merge(e.messages??[]),Z(e.unread)}})}),m(()=>{window.removeEventListener(`popstate`,x),w?.stop()});function T(e){C(e.conversations),b(e.id)}async function D(){C((await X.conversations()).conversations)}function O({id:e,unread:t}){let r=n.value.find(t=>t.id===e);r&&(r.unread=0),Z(t)}return(t,r)=>(g(),i(S(A),{title:`Nachrichten`},{default:E(()=>[s(`div`,Qn,[s(`aside`,{class:f([`ih:w-full ih:shrink-0 ih:border-r ih:lg:block ih:lg:w-80 ih:xl:w-96`,y.value?`ih:hidden`:`ih:block`])},[l(vt,{conversations:n.value,"active-id":c.value,"can-create-groups":e.canCreateGroups,onOpen:b,onNewChat:r[0]||=e=>p.value=`chat`,onNewGroup:r[1]||=e=>p.value=`group`},null,8,[`conversations`,`active-id`,`can-create-groups`])],2),s(`main`,{class:f([`ih:min-w-0 ih:flex-1 ih:lg:block`,y.value?`ih:block`:`ih:hidden`])},[y.value?(g(),i(Kn,{key:0,ref_key:`thread`,ref:d,conversation:y.value,me:e.me,reactions:e.reactions,typing:u.value,"max-upload-mb":e.maxUploadMb,onBack:r[2]||=e=>b(null),onInfo:r[3]||=e=>v.value=!0,onChanged:D,onRead:O},null,8,[`conversation`,`me`,`reactions`,`typing`,`max-upload-mb`])):(g(),o(`div`,$n,[s(`div`,null,[l(S(pe),{class:`ih:mx-auto ih:size-12 ih:text-muted-foreground/60`,"stroke-width":1.5}),r[7]||=s(`p`,{class:`ih:mt-3 ih:font-medium`},`Wählen Sie ein Gespräch`,-1),r[8]||=s(`p`,{class:`ih:mt-1 ih:text-sm ih:text-muted-foreground`},`oder beginnen Sie eine neue Nachricht.`,-1)])]))],2)]),l(Ct,{open:p.value!==null,group:p.value===`group`,me:e.me,"onUpdate:open":r[4]||=e=>!e&&(p.value=null),onCreated:T},null,8,[`open`,`group`,`me`]),y.value?(g(),i(Je,{key:0,open:v.value,"onUpdate:open":r[5]||=e=>v.value=e,conversation:y.value,me:e.me,onUpdated:C,onLeft:r[6]||=e=>b(null)},null,8,[`open`,`conversation`,`me`])):a(``,!0)]),_:1}))}};export{er as default}; \ No newline at end of file +import{n as e}from"../chunks/rolldown-runtime-CbXtAM7H.js";import{t}from"../chunks/createLucideIcon-CYyWUN7r.js";import{Fragment as n,computed as r,createBlock as i,createCommentVNode as a,createElementBlock as o,createElementVNode as s,createTextVNode as c,createVNode as l,mergeModels as u,nextTick as d,normalizeClass as f,normalizeStyle as p,onBeforeUnmount as m,onMounted as h,openBlock as g,ref as _,renderList as v,renderSlot as y,resolveDynamicComponent as b,toDisplayString as x,unref as S,useModel as C,vModelText as w,watch as T,withCtx as E,withDirectives as D,withKeys as O,withModifiers as k}from"vue";import{AppLayout as A,Button as j,Dialog as M,DialogContent as N,DialogDescription as P,DialogFooter as F,DialogHeader as I,DialogTitle as L,FileIcon as R,Input as z,Label as B,PersonAvatar as V,Switch as ee,http as H,toast as U}from"@inhaus/ui";var te=t({name:`arrow-down`,size:24,node:[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]}),ne=t({name:`arrow-left`,size:24,node:[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]}),re=t({name:`bell-off`,size:24,node:[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742`,key:`178tsu`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05`,key:`1hqiys`}]]}),W=t({name:`corner-up-left`,size:24,node:[[`path`,{d:`M20 20v-7a4 4 0 0 0-4-4H4`,key:`1nkjon`}],[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}]]}),G=t({name:`crown`,size:24,node:[[`path`,{d:`M11.562 3.266a.5.5 0 0 1 .876 0L15.39 8.87a1 1 0 0 0 1.516.294L21.183 5.5a.5.5 0 0 1 .798.519l-2.834 10.246a1 1 0 0 1-.956.734H5.81a1 1 0 0 1-.957-.734L2.02 6.02a.5.5 0 0 1 .798-.519l4.276 3.664a1 1 0 0 0 1.516-.294z`,key:`1vdc57`}],[`path`,{d:`M5 21h14`,key:`11awu3`}]]}),ie=t({name:`download`,size:24,node:[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]}),ae=t({name:`eye-off`,size:24,node:[[`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`,key:`ct8e1f`}],[`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`,key:`151rxh`}],[`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`,key:`13bj9a`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]}),oe=t({name:`face-slightly-smiling-plus`,size:24,node:[[`path`,{d:`M13.267 2.08a10 10 0 108.653 8.653`,key:`1wbpyh`}],[`path`,{d:`M15 10V9`,key:`4dkmfx`}],[`path`,{d:`M16 5h6`,key:`1vod17`}],[`path`,{d:`M16.472 15a6 6 0 01-8.943 0`,key:`7qomzy`}],[`path`,{d:`M19 2v6`,key:`4bpg5p`}],[`path`,{d:`M9 10V9`,key:`1lazqi`}]],aliases:[`smile-plus`]}),se=t({name:`face-slightly-smiling`,size:24,node:[[`path`,{d:`M15 10V9`,key:`4dkmfx`}],[`path`,{d:`M16.472 15a6 6 0 01-8.943 0`,key:`7qomzy`}],[`path`,{d:`M9 10V9`,key:`1lazqi`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]],aliases:[`smile`]}),ce=t({name:`file`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}]]}),le=t({name:`image`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]}),ue=t({name:`info`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]}),K=t({name:`loader-circle`,size:24,node:[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]],aliases:[`loader-2`]}),de=t({name:`log-out`,size:24,node:[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]}),fe=t({name:`message-square-plus`,size:24,node:[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M12 8v6`,key:`1ib9pf`}],[`path`,{d:`M9 11h6`,key:`1fldmi`}]]}),pe=t({name:`messages-square`,size:24,node:[[`path`,{d:`M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z`,key:`1n2ejm`}],[`path`,{d:`M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1`,key:`1qfcsi`}]]}),me=t({name:`paperclip`,size:24,node:[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]}),he=t({name:`pencil`,size:24,node:[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]}),q=t({name:`search`,size:24,node:[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]}),ge=t({name:`send-horizontal`,size:24,node:[[`path`,{d:`M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z`,key:`117uat`}],[`path`,{d:`M6 12h16`,key:`s4cdu5`}]],aliases:[`send-horizonal`]}),_e=t({name:`trash`,size:24,node:[[`path`,{d:`M10 11v6`,key:`nco0om`}],[`path`,{d:`M14 11v6`,key:`outv1u`}],[`path`,{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6`,key:`miytrc`}],[`path`,{d:`M3 6h18`,key:`d0wm0j`}],[`path`,{d:`M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`,key:`e791ji`}]],aliases:[`trash-2`]}),ve=t({name:`upload`,size:24,node:[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]}),ye=t({name:`user-minus`,size:24,node:[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`22`,x2:`16`,y1:`11`,y2:`11`,key:`1shjgl`}]]}),be=t({name:`user-plus`,size:24,node:[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`19`,x2:`19`,y1:`8`,y2:`14`,key:`1bvyxn`}],[`line`,{x1:`22`,x2:`16`,y1:`11`,y2:`11`,key:`1shjgl`}]]}),xe=t({name:`users`,size:24,node:[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]}),Se=t({name:`users-round`,size:24,node:[[`path`,{d:`M18 21a8 8 0 0 0-16 0`,key:`3ypg7q`}],[`circle`,{cx:`10`,cy:`8`,r:`5`,key:`o932ke`}],[`path`,{d:`M22 20c0-3.37-2-6.5-4-8a5 5 0 0 0-.45-8.3`,key:`10s06x`}]],aliases:[`users-2`]}),J=t({name:`x`,size:24,node:[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]}),Y=`/chat/api`,X={conversations:()=>H.get(`${Y}/gespraeche`),direct:e=>H.post(`${Y}/direkt`,{user_id:e}),createGroup:(e,t)=>H.post(`${Y}/gruppen`,{name:e,members:t}),updateConversation:(e,t)=>H.put(`${Y}/gespraeche/${e}`,t),leave:e=>H.delete(`${Y}/gespraeche/${e}`),addMembers:(e,t)=>H.post(`${Y}/gespraeche/${e}/mitglieder`,{members:t}),removeMember:(e,t)=>H.delete(`${Y}/gespraeche/${e}/mitglieder/${t}`),setAdmin:(e,t,n)=>H.put(`${Y}/gespraeche/${e}/mitglieder/${t}`,{admin:n}),messages:(e,t)=>H.get(`${Y}/gespraeche/${e}/nachrichten${t?`?vor=${t}`:``}`),send(e,{body:t,gifUrl:n,replyTo:r,files:i}){let a=new FormData;return t&&a.append(`body`,t),n&&a.append(`gif_url`,n),r&&a.append(`reply_to`,r),(i??[]).forEach(e=>a.append(`files[]`,e)),H.post(`${Y}/gespraeche/${e}/nachrichten`,a)},edit:(e,t)=>H.put(`${Y}/nachrichten/${e}`,{body:t}),remove:e=>H.delete(`${Y}/nachrichten/${e}`),react:(e,t)=>H.post(`${Y}/nachrichten/${e}/reaktion`,{emoji:t}),read:(e,t)=>H.post(`${Y}/gespraeche/${e}/gelesen`,{message_id:t}),typing:e=>H.post(`${Y}/gespraeche/${e}/tippt`),updates:e=>H.get(`${Y}/neues?${new URLSearchParams(Object.entries(e).filter(([,e])=>e!=null))}`),unread:()=>H.get(`${Y}/ungelesen`),gifs:e=>H.get(`${Y}/gifs?q=${encodeURIComponent(e??``)}`),people:e=>H.get(`/personen/suche?q=${encodeURIComponent(e)}`)};function Z(e){window.dispatchEvent(new CustomEvent(`inhaus-chat:unread`,{detail:e}))}var Ce={class:`ih:grid ih:gap-2`},we={key:0,class:`ih:flex ih:flex-wrap ih:gap-1.5`},Te=[`aria-label`,`onClick`],Ee={class:`ih:relative`},De=[`autofocus`,`placeholder`],Oe={key:1,class:`ih:max-h-64 ih:overflow-y-auto ih:rounded-md ih:border ih:bg-popover ih:p-1`,role:`listbox`},ke=[`aria-selected`],Ae=[`onClick`,`onMouseenter`],je={class:`ih:min-w-0 ih:flex-1`},Me={class:`ih:block ih:truncate ih:font-medium`},Ne={key:0,class:`ih:block ih:truncate ih:text-xs ih:text-muted-foreground`},Pe={key:2,class:`ih:px-1 ih:text-[13px] ih:text-muted-foreground`},Fe={__name:`PeopleSelect`,props:u({multiple:{type:Boolean,default:!1},exclude:{type:Array,default:()=>[]},placeholder:{type:String,default:`Name oder E-Mail eingeben …`},autofocus:{type:Boolean,default:!1}},{modelValue:{type:Array,default:()=>[]},modelModifiers:{}}),emits:u([`pick`],[`update:modelValue`]),setup(e,{emit:t}){let r=e,i=t,u=C(e,`modelValue`),d=_(``),p=_([]),m=_(0),h=_(!1),y;T(d,e=>{if(clearTimeout(y),e.trim().length<2){p.value=[];return}y=setTimeout(async()=>{h.value=!0;try{let t=[...r.exclude,...u.value.map(e=>e.id)];p.value=(await X.people(e.trim())).people.filter(e=>!t.includes(e.id)),m.value=0}finally{h.value=!1}},200)});function b(e){e&&(i(`pick`,e),r.multiple&&(u.value=[...u.value,e]),d.value=``,p.value=[])}let E=e=>u.value=u.value.filter(t=>t.id!==e.id);return(t,r)=>(g(),o(`div`,Ce,[e.multiple&&u.value.length?(g(),o(`div`,we,[(g(!0),o(n,null,v(u.value,e=>(g(),o(`span`,{key:e.id,class:`ih:inline-flex ih:items-center ih:gap-1.5 ih:rounded-full ih:border ih:bg-card ih:py-0.5 ih:pr-1 ih:pl-0.5 ih:text-[13px]`},[l(S(V),{person:e,class:`ih:size-6 ih:text-[10px]`},null,8,[`person`]),c(` `+x(e.name)+` `,1),s(`button`,{type:`button`,class:`ih:rounded-full ih:p-0.5 ih:text-muted-foreground ih:hover:bg-muted ih:hover:text-foreground`,"aria-label":`${e.name} entfernen`,onClick:t=>E(e)},[l(S(J),{class:`ih:size-3.5`})],8,Te)]))),128))])):a(``,!0),s(`div`,Ee,[l(S(q),{class:`ih:pointer-events-none ih:absolute ih:top-1/2 ih:left-2.5 ih:size-4 ih:-translate-y-1/2 ih:text-muted-foreground`}),D(s(`input`,{"onUpdate:modelValue":r[0]||=e=>d.value=e,type:`search`,autocomplete:`off`,autofocus:e.autofocus,placeholder:e.placeholder,"aria-label":`Person suchen`,class:`ih:h-10 ih:w-full ih:rounded-md ih:border ih:border-input ih:bg-card ih:pr-3 ih:pl-8 ih:text-sm ih:shadow-xs ih:focus-visible:ring-3 ih:focus-visible:ring-ring/30 ih:focus-visible:outline-none`,onKeydown:[r[1]||=O(k(e=>m.value=Math.min(p.value.length-1,m.value+1),[`prevent`]),[`down`]),r[2]||=O(k(e=>m.value=Math.max(0,m.value-1),[`prevent`]),[`up`]),r[3]||=O(k(e=>b(p.value[m.value]),[`prevent`]),[`enter`])]},null,40,De),[[w,d.value]])]),p.value.length?(g(),o(`ul`,Oe,[(g(!0),o(n,null,v(p.value,(e,t)=>(g(),o(`li`,{key:e.id,role:`option`,"aria-selected":t===m.value},[s(`button`,{type:`button`,class:f([`ih:flex ih:w-full ih:items-center ih:gap-2.5 ih:rounded ih:px-2 ih:py-1.5 ih:text-left ih:text-sm`,t===m.value?`ih:bg-accent`:`ih:hover:bg-accent/60`]),onClick:t=>b(e),onMouseenter:e=>m.value=t},[l(S(V),{person:e,class:`ih:size-7 ih:text-[11px]`},null,8,[`person`]),s(`span`,je,[s(`span`,Me,x(e.name),1),e.job_title||e.department?(g(),o(`span`,Ne,x([e.job_title,e.department].filter(Boolean).join(` · `)),1)):a(``,!0)])],42,Ae)],8,ke))),128))])):d.value.trim().length>=2&&!h.value?(g(),o(`p`,Pe,`Niemand gefunden.`)):a(``,!0)]))}},Ie={class:`ih:grid ih:gap-5`},Le={class:`ih:flex ih:items-center ih:justify-between ih:gap-3 ih:text-sm`},Re={key:1,class:`ih:grid ih:gap-2`},ze={class:`ih:-mx-2 ih:grid`},Be={class:`ih:min-w-0 ih:flex-1 ih:text-sm`},Ve={class:`ih:font-medium`},He={key:0,class:`ih:text-muted-foreground`},Ue={key:1,class:`ih:ml-1.5 ih:inline-flex ih:items-center ih:gap-0.5 ih:text-xs ih:text-brand-text`},We=[`title`,`aria-label`,`onClick`],Ge=[`aria-label`,`onClick`],Ke={key:0,class:`ih:grid ih:gap-2 ih:rounded-md ih:border ih:p-3`},qe={class:`ih:flex ih:items-center ih:gap-1.5 ih:text-sm ih:font-medium`},Je={__name:`ConversationInfo`,props:u({conversation:{type:Object,required:!0},me:{type:Object,required:!0}},{open:{type:Boolean,default:!1},openModifiers:{}}),emits:u([`updated`,`left`],[`update:open`]),setup(e,{emit:t}){let u=e,d=C(e,`open`),f=t,p=r(()=>u.conversation.type===`group`),m=_(``),h=_([]),y=_(!1);T(d,e=>{e&&(m.value=u.conversation.name,h.value=[])});async function w(e,t){y.value=!0;try{let n=await e();f(`updated`,n.conversations),t&&U.success(t)}catch(e){U.error(e.message)}finally{y.value=!1}}let D=()=>w(()=>X.updateConversation(u.conversation.id,{name:m.value.trim()}),`Gruppe umbenannt`),O=e=>w(()=>X.updateConversation(u.conversation.id,{muted:e}),e?`Stummgeschaltet – keine Benachrichtigungen mehr`:`Benachrichtigungen wieder an`),A=()=>w(()=>X.addMembers(u.conversation.id,h.value.map(e=>e.id)),`Hinzugefügt`).then(()=>h.value=[]),F=e=>window.confirm(`${e.name} aus der Gruppe entfernen?`)&&w(()=>X.removeMember(u.conversation.id,e.id)),R=e=>w(()=>X.setAdmin(u.conversation.id,e.id,!e.admin));async function B(){window.confirm(p.value?`Gruppe verlassen? Sie sehen die Nachrichten danach nicht mehr.`:`Gespräch aus Ihrer Liste entfernen? Mit der nächsten Nachricht erscheint es wieder.`)&&(await w(()=>X.leave(u.conversation.id)),d.value=!1,f(`left`))}return(t,r)=>(g(),i(S(M),{open:d.value,"onUpdate:open":r[2]||=e=>d.value=e},{default:E(()=>[l(S(N),{class:`ih:max-h-[85dvh] ih:overflow-y-auto ih:sm:max-w-lg`},{default:E(()=>[l(S(I),null,{default:E(()=>[l(S(L),null,{default:E(()=>[c(x(e.conversation.name),1)]),_:1}),l(S(P),null,{default:E(()=>[c(x(p.value?`Gruppe mit ${e.conversation.members.length} Mitgliedern`:`Direktnachricht`),1)]),_:1})]),_:1}),s(`div`,Ie,[p.value&&e.conversation.is_admin?(g(),o(`form`,{key:0,class:`ih:flex ih:gap-2`,onSubmit:k(D,[`prevent`])},[l(S(z),{modelValue:m.value,"onUpdate:modelValue":r[0]||=e=>m.value=e,maxlength:`100`,"aria-label":`Name der Gruppe`},null,8,[`modelValue`]),l(S(j),{type:`submit`,variant:`outline`,disabled:y.value||!m.value.trim()||m.value.trim()===e.conversation.name},{default:E(()=>[...r[3]||=[c(`Umbenennen`,-1)]]),_:1},8,[`disabled`])],32)):a(``,!0),s(`label`,Le,[r[4]||=s(`span`,null,[s(`span`,{class:`ih:font-medium`},`Stummschalten`),s(`span`,{class:`ih:block ih:text-xs ih:text-muted-foreground`},`Keine Glocke und kein Push für dieses Gespräch.`)],-1),l(S(ee),{"model-value":e.conversation.muted,disabled:y.value,"onUpdate:modelValue":O},null,8,[`model-value`,`disabled`])]),p.value?(g(),o(`section`,Re,[r[7]||=s(`h3`,{class:`ih:text-sm ih:font-semibold`},`Mitglieder`,-1),s(`ul`,ze,[(g(!0),o(n,null,v(e.conversation.members,t=>(g(),o(`li`,{key:t.id,class:`ih:flex ih:items-center ih:gap-3 ih:rounded-md ih:px-2 ih:py-1.5 ih:hover:bg-muted/60`},[l(S(V),{person:t,class:`ih:size-8 ih:text-[11px]`},null,8,[`person`]),s(`span`,Be,[s(`span`,Ve,x(t.name),1),t.id===e.me.id?(g(),o(`span`,He,` (Sie)`)):a(``,!0),t.admin?(g(),o(`span`,Ue,[l(S(G),{class:`ih:size-3`}),r[5]||=c(` Admin`,-1)])):a(``,!0)]),e.conversation.is_admin&&t.id!==e.me.id?(g(),o(n,{key:0},[s(`button`,{type:`button`,class:`ih:rounded ih:p-1.5 ih:text-muted-foreground ih:hover:bg-accent ih:hover:text-foreground`,title:t.admin?`Admin-Rechte entziehen`:`Zum Admin machen`,"aria-label":t.admin?`${t.name}: Admin-Rechte entziehen`:`${t.name} zum Admin machen`,onClick:e=>R(t)},[l(S(G),{class:`ih:size-4`})],8,We),s(`button`,{type:`button`,class:`ih:rounded ih:p-1.5 ih:text-muted-foreground ih:hover:bg-accent ih:hover:text-destructive`,"aria-label":`${t.name} entfernen`,onClick:e=>F(t)},[l(S(ye),{class:`ih:size-4`})],8,Ge)],64)):a(``,!0)]))),128))]),e.conversation.is_admin?(g(),o(`div`,Ke,[s(`span`,qe,[l(S(be),{class:`ih:size-4`}),r[6]||=c(` Personen hinzufügen`,-1)]),l(Fe,{modelValue:h.value,"onUpdate:modelValue":r[1]||=e=>h.value=e,multiple:``,exclude:e.conversation.members.map(e=>e.id)},null,8,[`modelValue`,`exclude`]),h.value.length?(g(),i(S(j),{key:0,size:`sm`,class:`ih:justify-self-start`,disabled:y.value,onClick:A},{default:E(()=>[y.value?(g(),i(S(K),{key:0,class:`ih:animate-spin`})):a(``,!0),c(` `+x(h.value.length)+` hinzufügen`,1)]),_:1},8,[`disabled`])):a(``,!0)])):a(``,!0)])):a(``,!0),l(S(j),{variant:`outline`,class:`ih:justify-self-start ih:text-destructive ih:hover:text-destructive`,disabled:y.value,onClick:B},{default:E(()=>[(g(),i(b(p.value?S(de):S(ae)))),c(` `+x(p.value?`Gruppe verlassen`:`Aus der Liste entfernen`),1)]),_:1},8,[`disabled`])])]),_:1})]),_:1},8,[`open`]))}},Ye={__name:`ChatAvatar`,props:{conversation:{type:Object,required:!0},size:{type:String,default:`ih:size-10`}},setup(e){return(t,n)=>e.conversation.person?(g(),i(S(V),{key:0,person:e.conversation.person,class:f(e.size)},null,8,[`person`,`class`])):(g(),o(`span`,{key:1,class:f([`ih:grid ih:shrink-0 ih:place-items-center ih:rounded-full ih:bg-brand-soft ih:text-brand-text`,e.size]),"aria-hidden":`true`},[l(S(xe),{class:`ih:size-[45%]`})],2))}},Xe=new Intl.DateTimeFormat(`de-DE`,{hour:`2-digit`,minute:`2-digit`}),Ze=new Intl.DateTimeFormat(`de-DE`,{weekday:`short`}),Qe=new Intl.DateTimeFormat(`de-DE`,{day:`2-digit`,month:`2-digit`,year:`2-digit`}),$e=new Intl.DateTimeFormat(`de-DE`,{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`}),Q=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime();function et(e){if(!e)return``;let t=new Date(e),n=(Q(new Date)-Q(t))/864e5;return n===0?Xe.format(t):n===1?`Gestern`:n<7?Ze.format(t):Qe.format(t)}var tt=e=>Xe.format(new Date(e));function nt(e){let t=new Date(e),n=(Q(new Date)-Q(t))/864e5;return n===0?`Heute`:n===1?`Gestern`:$e.format(t)}var $=(e,t)=>Q(new Date(e))===Q(new Date(t));function rt(e){return e<1024?`${e} B`:e<1048576?`${Math.round(e/1024)} KB`:`${(e/1024/1024).toFixed(1).replace(`.`,`,`)} MB`}function it(e){let t=[],n=/(https?:\/\/[^\s<>"']+[^\s<>"'.,;:!?)\]])/g,r=0;for(let i of e.matchAll(n))i.index>r&&t.push({text:e.slice(r,i.index)}),t.push({text:i[0],href:i[0]}),r=i.index+i[0].length;return r!!e&&/^(\p{Extended_Pictographic}|\p{Emoji_Component}|‍|️|\s){1,12}$/u.test(e)&&[...e.replace(/\s/g,``)].length<=8,ot={class:`ih:flex ih:h-full ih:min-h-0 ih:flex-col`},st={class:`ih:flex ih:items-center ih:gap-2 ih:border-b ih:p-3`},ct={class:`ih:border-b ih:p-3`},lt={class:`ih:relative`},ut={class:`ih:min-h-0 ih:flex-1 ih:overflow-y-auto`,"aria-label":`Gespräche`},dt=[`aria-current`,`onClick`],ft={class:`ih:min-w-0 ih:flex-1`},pt={class:`ih:flex ih:items-baseline ih:gap-2`},mt={class:`ih:shrink-0 ih:text-[11px] ih:text-muted-foreground ih:tabular-nums`},ht={class:`ih:flex ih:items-center ih:gap-2`},gt=[`aria-label`],_t={key:0,class:`ih:p-6 ih:text-center ih:text-sm ih:text-muted-foreground`},vt={__name:`ConversationList`,props:{conversations:{type:Array,required:!0},activeId:{type:Number,default:null},canCreateGroups:{type:Boolean,default:!1}},emits:[`open`,`new-chat`,`new-group`],setup(e,{emit:t}){let c=e,u=t,d=_(``),p=r(()=>{let e=d.value.trim().toLowerCase();return e?c.conversations.filter(t=>[t.name,...t.members.map(e=>e.name)].join(` `).toLowerCase().includes(e)):c.conversations});return(t,r)=>(g(),o(`div`,ot,[s(`div`,st,[r[3]||=s(`h1`,{class:`ih:flex-1 ih:text-lg ih:font-semibold ih:tracking-tight`},`Nachrichten`,-1),e.canCreateGroups?(g(),i(S(j),{key:0,variant:`ghost`,size:`icon`,title:`Neue Gruppe`,"aria-label":`Neue Gruppe`,onClick:r[0]||=e=>u(`new-group`)},{default:E(()=>[l(S(Se))]),_:1})):a(``,!0),l(S(j),{size:`icon`,title:`Neue Nachricht`,"aria-label":`Neue Nachricht`,onClick:r[1]||=e=>u(`new-chat`)},{default:E(()=>[l(S(fe))]),_:1})]),s(`div`,ct,[s(`div`,lt,[l(S(q),{class:`ih:pointer-events-none ih:absolute ih:top-1/2 ih:left-2.5 ih:size-4 ih:-translate-y-1/2 ih:text-muted-foreground`}),D(s(`input`,{"onUpdate:modelValue":r[2]||=e=>d.value=e,type:`search`,placeholder:`Gespräche durchsuchen`,"aria-label":`Gespräche durchsuchen`,class:`ih:h-9 ih:w-full ih:rounded-md ih:bg-muted ih:pr-3 ih:pl-8 ih:text-sm ih:focus-visible:ring-3 ih:focus-visible:ring-ring/30 ih:focus-visible:outline-none`},null,512),[[w,d.value]])])]),s(`ul`,ut,[(g(!0),o(n,null,v(p.value,t=>(g(),o(`li`,{key:t.id},[s(`button`,{type:`button`,class:f([`ih:flex ih:w-full ih:items-center ih:gap-3 ih:px-3 ih:py-2.5 ih:text-left ih:transition-colors`,t.id===e.activeId?`ih:bg-brand-soft`:`ih:hover:bg-accent/60`]),"aria-current":t.id===e.activeId?`true`:void 0,onClick:e=>u(`open`,t.id)},[l(Ye,{conversation:t,size:`ih:size-11`},null,8,[`conversation`]),s(`span`,ft,[s(`span`,pt,[s(`span`,{class:f([`ih:min-w-0 ih:flex-1 ih:truncate ih:text-sm`,t.unread?`ih:font-semibold`:`ih:font-medium`])},x(t.name),3),s(`span`,mt,x(S(et)(t.last_message_at)),1)]),s(`span`,ht,[s(`span`,{class:f([`ih:min-w-0 ih:flex-1 ih:truncate ih:text-[13px]`,t.unread?`ih:text-foreground`:`ih:text-muted-foreground`])},x(t.preview??(t.type===`group`?`${t.members.length} Mitglieder`:`Noch keine Nachrichten`)),3),t.muted?(g(),i(S(re),{key:0,class:`ih:size-3.5 ih:shrink-0 ih:text-muted-foreground`,"aria-label":`Stummgeschaltet`})):a(``,!0),t.unread?(g(),o(`span`,{key:1,class:`ih:grid ih:h-5 ih:min-w-5 ih:shrink-0 ih:place-items-center ih:rounded-full ih:bg-brand ih:px-1.5 ih:text-[11px] ih:font-semibold ih:text-brand-foreground ih:tabular-nums`,"aria-label":`${t.unread} ungelesen`},x(t.unread>99?`99+`:t.unread),9,gt)):a(``,!0)])])],10,dt)]))),128)),p.value.length?a(``,!0):(g(),o(`li`,_t,x(d.value?`Nichts gefunden.`:`Noch keine Gespräche. Oben rechts eine neue Nachricht beginnen.`),1))])]))}},yt={class:`ih:grid ih:gap-4`},bt={key:0,class:`ih:grid ih:gap-1.5`},xt={class:`ih:grid ih:gap-1.5`},St={key:1,class:`ih:flex ih:items-center ih:gap-2 ih:text-sm ih:text-muted-foreground`},Ct={__name:`NewChatDialog`,props:u({group:{type:Boolean,default:!1},me:{type:Object,required:!0}},{open:{type:Boolean,default:!1},openModifiers:{}}),emits:u([`created`],[`update:open`]),setup(e,{emit:t}){let n=e,r=C(e,`open`),u=t,d=_(``),f=_([]),p=_(!1);T(r,e=>{e&&(d.value=``,f.value=[])});async function m(e){if(!n.group){p.value=!0;try{let t=await X.direct(e.id);r.value=!1,u(`created`,t)}catch(e){U.error(e.message)}finally{p.value=!1}}}async function h(){p.value=!0;try{let e=await X.createGroup(d.value.trim(),f.value.map(e=>e.id));r.value=!1,u(`created`,e)}catch(e){U.error(e.message)}finally{p.value=!1}}return(t,n)=>(g(),i(S(M),{open:r.value,"onUpdate:open":n[3]||=e=>r.value=e},{default:E(()=>[l(S(N),{class:`ih:sm:max-w-md`},{default:E(()=>[l(S(I),null,{default:E(()=>[l(S(L),null,{default:E(()=>[c(x(e.group?`Neue Gruppe`:`Neue Nachricht`),1)]),_:1}),l(S(P),null,{default:E(()=>[c(x(e.group?`Name und Mitglieder wählen – Sie verwalten die Gruppe.`:`An wen möchten Sie schreiben?`),1)]),_:1})]),_:1}),s(`div`,yt,[e.group?(g(),o(`div`,bt,[l(S(B),{for:`chat-group-name`},{default:E(()=>[...n[4]||=[c(`Name der Gruppe`,-1)]]),_:1}),l(S(z),{id:`chat-group-name`,modelValue:d.value,"onUpdate:modelValue":n[0]||=e=>d.value=e,maxlength:`100`,placeholder:`z. B. Station 3 – Frühdienst`},null,8,[`modelValue`])])):a(``,!0),s(`div`,xt,[e.group?(g(),i(S(B),{key:0},{default:E(()=>[...n[5]||=[c(`Mitglieder`,-1)]]),_:1})):a(``,!0),l(Fe,{modelValue:f.value,"onUpdate:modelValue":n[1]||=e=>f.value=e,multiple:e.group,exclude:[e.me.id],autofocus:``,onPick:m},null,8,[`modelValue`,`multiple`,`exclude`])]),p.value&&!e.group?(g(),o(`p`,St,[l(S(K),{class:`ih:size-4 ih:animate-spin`}),n[6]||=c(` Gespräch wird geöffnet …`,-1)])):a(``,!0)]),e.group?(g(),i(S(F),{key:0},{default:E(()=>[l(S(j),{variant:`ghost`,onClick:n[2]||=e=>r.value=!1},{default:E(()=>[...n[7]||=[c(`Abbrechen`,-1)]]),_:1}),l(S(j),{disabled:p.value||!d.value.trim()||!f.value.length,onClick:h},{default:E(()=>[p.value?(g(),i(S(K),{key:0,class:`ih:animate-spin`})):a(``,!0),n[8]||=c(` Gruppe erstellen `,-1)]),_:1},8,[`disabled`])]),_:1})):a(``,!0)]),_:1})]),_:1},8,[`open`]))}},wt=[{label:`Smileys`,icon:`😀`,emojis:`😀 😃 😄 😁 😆 😅 🤣 😂 🙂 🙃 😉 😊 😇 🥰 😍 🤩 😘 😗 😚 😋 😛 😜 🤪 😝 🤗 🤭 🤫 🤔 🤐 🤨 😐 😑 😶 😏 😒 🙄 😬 😌 😔 😪 😴 😷 🤒 🤕 🤢 🤧 🥵 🥶 🥴 😵 🤯 🤠 🥳 😎 🤓 🧐 😕 😟 🙁 😮 😯 😲 😳 🥺 😦 😧 😨 😰 😥 😢 😭 😱 😖 😣 😞 😓 😩 😫 🥱 😤 😡 😠 🤬`.split(` `)},{label:`Gesten`,icon:`👍`,emojis:`👍 👎 👌 🤌 ✌️ 🤞 🤟 🤘 🤙 👈 👉 👆 👇 ☝️ ✋ 🤚 🖐️ 🖖 👋 👏 🙌 👐 🤲 🤝 🙏 ✍️ 💪 🦾 👀 🧠 🫶 ❤️ 🧡 💛 💚 💙 💜 🖤 🤍 🤎 💔 ❣️ 💕 💞 💓 💗 💖 💘 💯 ✨ ⭐ 🌟 💥 🔥 🎉 🎊`.split(` `)},{label:`Menschen`,icon:`🧑`,emojis:`👶 🧒 👦 👧 🧑 👱 👨 🧔 👩 🧓 👴 👵 🙋 🙆 🙅 🤷 🤦 🙇 💁 🧑‍⚕️ 🧑‍🍳 🧑‍🔧 🧑‍🏫 🧑‍💻 🧑‍💼 🧑‍🔬 🧑‍🎨 🧑‍🚒 👮 🕵️ 💂 👷 🤴 👸 🧙 🧚 🦸 🏃 🚶 🧘 🏋️ 🚴 🤸 👯 💃 🕺 👪 🧑‍🤝‍🧑`.split(` `)},{label:`Natur`,icon:`🌿`,emojis:`🐶 🐱 🐭 🐹 🐰 🦊 🐻 🐼 🐨 🐯 🦁 🐮 🐷 🐸 🐵 🐔 🐧 🐦 🦆 🦉 🐴 🦄 🐝 🐞 🦋 🐢 🐍 🐙 🐠 🐬 🐳 🌵 🎄 🌲 🌳 🌴 🌱 🌿 🍀 🍁 🍂 🌷 🌹 🌻 🌼 🌸 🌞 🌝 🌙 ⭐ ☀️ 🌤️ ⛅ 🌧️ ⛈️ ❄️ ☃️ 🌈 🌊`.split(` `)},{label:`Essen`,icon:`🍕`,emojis:`🍏 🍎 🍐 🍊 🍋 🍌 🍉 🍇 🍓 🫐 🍒 🍑 🥭 🍍 🥥 🥝 🍅 🥑 🥦 🥕 🌽 🥔 🥐 🥖 🥨 🧀 🥚 🍳 🥞 🥓 🍔 🍟 🍕 🌭 🥪 🌮 🥗 🍝 🍜 🍲 🍣 🍰 🎂 🧁 🍩 🍪 🍫 🍬 🍭 🍦 ☕ 🍵 🧃 🥤 🍺 🍻 🥂 🍷`.split(` `)},{label:`Aktivitäten`,icon:`⚽`,emojis:`⚽ 🏀 🏈 ⚾ 🎾 🏐 🏓 🏸 🥅 ⛳ 🎣 🎽 🎿 ⛸️ 🥇 🥈 🥉 🏆 🏅 🎗️ 🎫 🎟️ 🎭 🎨 🎬 🎤 🎧 🎼 🎹 🥁 🎷 🎺 🎸 🎻 🎲 🧩 🎯 🎳 🎮 🎰`.split(` `)},{label:`Dinge`,icon:`💡`,emojis:`⌚ 📱 💻 ⌨️ 🖥️ 🖨️ 🖱️ 💾 📷 📞 ☎️ 📺 ⏰ ⏳ 💡 🔦 🕯️ 💰 💳 🧾 ✉️ 📧 📨 📦 📝 📁 📂 📅 📆 📌 📎 ✂️ 🔒 🔑 🔨 🛠️ 🧰 🩺 💊 💉 🩹 🧯 🛒 🎁 🎈 🏠 🏥 🏫 🚗 🚌 🚲 ✈️ 🚀 🕐`.split(` `)},{label:`Symbole`,icon:`✅`,emojis:`✅ ☑️ ✔️ ❌ ❎ ➕ ➖ ❓ ❗ ‼️ ⁉️ 💤 ⚠️ 🚫 ⛔ 🔴 🟠 🟡 🟢 🔵 🟣 ⚫ ⚪ 🔶 🔷 ▶️ ⏸️ ⏹️ 🔄 🔁 🆗 🆕 🆒 🆘 ℹ️ 🔔 🔕 📣 💬 💭 🗯️ ♻️ ⬆️ ⬇️ ⬅️ ➡️`.split(` `)}],Tt={class:`ih:flex ih:border-b ih:px-1`,role:`tablist`,"aria-label":`Emoji-Gruppen`},Et=[`aria-selected`,`title`,`onClick`],Dt=[`aria-label`],Ot=[`aria-label`,`onClick`],kt={__name:`EmojiPicker`,emits:[`pick`],setup(e,{emit:t}){let r=t,i=_(0);return(e,t)=>(g(),o(`div`,null,[s(`div`,Tt,[(g(!0),o(n,null,v(S(wt),(e,t)=>(g(),o(`button`,{key:e.label,type:`button`,role:`tab`,"aria-selected":i.value===t,title:e.label,class:f([`ih:grid ih:size-9 ih:place-items-center ih:text-lg ih:transition-opacity`,i.value===t?`ih:border-b-2 ih:border-brand`:`ih:opacity-60 ih:hover:opacity-100`]),onClick:e=>i.value=t},x(e.icon),11,Et))),128))]),s(`div`,{class:`ih:grid ih:max-h-60 ih:grid-cols-8 ih:gap-0.5 ih:overflow-y-auto ih:p-2`,role:`tabpanel`,"aria-label":S(wt)[i.value].label},[(g(!0),o(n,null,v(S(wt)[i.value].emojis,e=>(g(),o(`button`,{key:e,type:`button`,class:`ih:grid ih:aspect-square ih:place-items-center ih:rounded ih:text-xl ih:hover:bg-accent`,"aria-label":e,onClick:t=>r(`pick`,e)},x(e),9,Ot))),128))],8,Dt)]))}},At={class:`ih:border-b ih:p-2`},jt={class:`ih:relative`},Mt={class:`ih:max-h-72 ih:overflow-y-auto ih:p-2`},Nt={key:0,class:`ih:grid ih:place-items-center ih:py-8`},Pt={key:1,class:`ih:columns-2 ih:gap-1.5`},Ft=[`title`,`onClick`],It=[`src`,`alt`],Lt={key:2,class:`ih:py-6 ih:text-center ih:text-sm ih:text-muted-foreground`},Rt={key:0,class:`ih:border-t ih:px-3 ih:py-1.5 ih:text-[10px] ih:text-muted-foreground`},zt={__name:`GifPicker`,emits:[`pick`],setup(e,{emit:t}){let r=t,i=_(``),c=_([]),u=_(!1),d=_(!1),f;async function m(){d.value=!0;try{let e=await X.gifs(i.value);c.value=e.gifs,u.value=e.giphy}finally{d.value=!1}}return T(i,()=>{clearTimeout(f),f=setTimeout(m,300)}),h(m),(e,t)=>(g(),o(`div`,null,[s(`div`,At,[s(`div`,jt,[l(S(q),{class:`ih:pointer-events-none ih:absolute ih:top-1/2 ih:left-2.5 ih:size-4 ih:-translate-y-1/2 ih:text-muted-foreground`}),D(s(`input`,{"onUpdate:modelValue":t[0]||=e=>i.value=e,type:`search`,placeholder:`GIFs suchen`,"aria-label":`GIFs suchen`,autofocus:``,class:`ih:h-9 ih:w-full ih:rounded-md ih:bg-muted ih:pr-3 ih:pl-8 ih:text-sm ih:focus-visible:outline-none`},null,512),[[w,i.value]])])]),s(`div`,Mt,[d.value&&!c.value.length?(g(),o(`div`,Nt,[l(S(K),{class:`ih:size-5 ih:animate-spin ih:text-muted-foreground`})])):c.value.length?(g(),o(`div`,Pt,[(g(!0),o(n,null,v(c.value,e=>(g(),o(`button`,{key:e.url,type:`button`,class:`ih:mb-1.5 ih:block ih:w-full ih:overflow-hidden ih:rounded ih:bg-muted ih:hover:ring-2 ih:hover:ring-brand`,title:e.title,onClick:t=>r(`pick`,e)},[s(`img`,{src:e.preview,alt:e.title,loading:`lazy`,class:`ih:block ih:w-full`,style:p(e.width&&e.height?{aspectRatio:`${e.width} / ${e.height}`}:{})},null,12,It)],8,Ft))),128))])):(g(),o(`p`,Lt,x(i.value?`Keine GIFs gefunden.`:`Noch keine GIFs in der Sammlung.`),1))]),u.value?(g(),o(`p`,Rt,`Mit Suche über GIPHY – Suchbegriffe gehen an GIPHY.`)):a(``,!0)]))}},Bt={__name:`Popup`,emits:[`close`],setup(e,{emit:t}){let n=t,r=_(null),i=e=>r.value&&!r.value.contains(e.target)&&!e.target.closest?.(`[data-popup-toggle]`)&&n(`close`),a=e=>e.key===`Escape`&&n(`close`);return h(()=>{document.addEventListener(`pointerdown`,i),document.addEventListener(`keydown`,a)}),m(()=>{document.removeEventListener(`pointerdown`,i),document.removeEventListener(`keydown`,a)}),(e,t)=>(g(),o(`div`,{ref_key:`root`,ref:r,class:`ih:absolute ih:bottom-full ih:left-0 ih:z-30 ih:mb-2 ih:w-[min(22rem,calc(100vw-2rem))] ih:overflow-hidden ih:rounded-lg ih:border ih:bg-popover ih:text-popover-foreground ih:shadow-lg`,role:`dialog`},[y(e.$slots,`default`)],512))}},Vt={class:`ih:border-t ih:bg-card ih:p-3`},Ht={key:0,class:`ih:mb-2 ih:flex ih:items-start ih:gap-2 ih:rounded-md ih:border-l-3 ih:border-brand ih:bg-muted ih:px-3 ih:py-1.5 ih:text-[13px]`},Ut={class:`ih:min-w-0 ih:flex-1`},Wt={class:`ih:block ih:font-semibold`},Gt={key:0,class:`ih:line-clamp-1 ih:text-muted-foreground`},Kt={key:1,class:`ih:mb-2 ih:flex ih:gap-2 ih:overflow-x-auto ih:pb-1`},qt=[`src`,`alt`],Jt={key:1,class:`ih:flex ih:h-16 ih:w-36 ih:items-center ih:gap-2 ih:rounded-md ih:border ih:bg-muted ih:px-2 ih:text-xs`},Yt={class:`ih:min-w-0`},Xt={class:`ih:block ih:truncate ih:font-medium`},Zt=[`aria-label`,`onClick`],Qt={class:`ih:relative ih:flex ih:items-end ih:gap-1`},$t=[`aria-expanded`],en=[`aria-expanded`],tn=[`placeholder`],nn=[`disabled`,`aria-label`],rn={class:`ih:mt-1.5 ih:hidden ih:text-[11px] ih:text-muted-foreground ih:sm:block`},an={__name:`Composer`,props:{replyTo:{type:Object,default:null},editing:{type:Object,default:null},maxUploadMb:{type:Number,default:25},sending:{type:Boolean,default:!1}},emits:[`send`,`save-edit`,`cancel`,`typing`],setup(e,{expose:t,emit:u}){let p=e,m=u,h=_(``),y=_([]),b=_(null),C=_(null),O=_(null),k=r(()=>!p.sending&&(h.value.trim()||y.value.length));T(()=>p.editing,e=>{h.value=e?.body??``,d(A)}),T(()=>p.replyTo,e=>e&&d(A));function A(){b.value?.focus(),j()}function j(){let e=b.value;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,180)}px`)}let M=0;function N(){j(),Date.now()-M>3e3&&h.value.trim()&&(M=Date.now(),m(`typing`))}function P(e){for(let t of e){if(t.size>p.maxUploadMb*1024*1024){U.error(`„${t.name}“ ist größer als ${p.maxUploadMb} MB.`);continue}if(y.value.length>=10){U.error(`Höchstens 10 Dateien je Nachricht.`);break}y.value.push({file:t,url:t.type.startsWith(`image/`)?URL.createObjectURL(t):null})}A()}function F(e){let t=[...e.clipboardData?.files??[]];t.length&&(e.preventDefault(),P(t))}function I(e){let[t]=y.value.splice(e,1);t?.url&&URL.revokeObjectURL(t.url)}function L(){if(p.editing){h.value.trim()&&m(`save-edit`,h.value.trim());return}k.value&&(m(`send`,{body:h.value,files:y.value.map(e=>e.file)}),y.value.forEach(e=>e.url&&URL.revokeObjectURL(e.url)),y.value=[],h.value=``,d(j))}function R(e){e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),L()),e.key===`Escape`&&(p.editing||p.replyTo)&&m(`cancel`)}function z(e){let t=b.value,n=t?.selectionStart??h.value.length,r=t?.selectionEnd??h.value.length;h.value=h.value.slice(0,n)+e+h.value.slice(r),d(()=>{t?.focus(),t?.setSelectionRange(n+e.length,n+e.length)})}function B(e){O.value=null,m(`send`,{gifUrl:e.url})}let V=e=>O.value=O.value===e?null:e;return t({addFiles:P,focus:A}),(t,r)=>(g(),o(`div`,Vt,[e.replyTo||e.editing?(g(),o(`div`,Ht,[e.editing?(g(),i(S(he),{key:0,class:`ih:mt-0.5 ih:size-3.5 ih:shrink-0 ih:text-brand-text`})):a(``,!0),s(`span`,Ut,[s(`span`,Wt,x(e.editing?`Nachricht bearbeiten`:`Antwort an ${e.replyTo.user?.name??``}`),1),e.replyTo?(g(),o(`span`,Gt,x(e.replyTo.body||(e.replyTo.gif_url?`GIF`:`Datei`)),1)):a(``,!0)]),s(`button`,{type:`button`,class:`ih:rounded ih:p-0.5 ih:text-muted-foreground ih:hover:text-foreground`,"aria-label":`Abbrechen`,onClick:r[0]||=e=>m(`cancel`)},[l(S(J),{class:`ih:size-4`})])])):a(``,!0),y.value.length?(g(),o(`ul`,Kt,[(g(!0),o(n,null,v(y.value,(e,t)=>(g(),o(`li`,{key:t,class:`ih:relative ih:shrink-0`},[e.url?(g(),o(`img`,{key:0,src:e.url,alt:e.file.name,class:`ih:size-16 ih:rounded-md ih:border ih:object-cover`},null,8,qt)):(g(),o(`span`,Jt,[l(S(ce),{class:`ih:size-5 ih:shrink-0 ih:text-muted-foreground`}),s(`span`,Yt,[s(`span`,Xt,x(e.file.name),1),c(x(S(rt)(e.file.size)),1)])])),s(`button`,{type:`button`,class:`ih:absolute ih:-top-1.5 ih:-right-1.5 ih:grid ih:size-5 ih:place-items-center ih:rounded-full ih:bg-foreground ih:text-background`,"aria-label":`${e.file.name} entfernen`,onClick:e=>I(t)},[l(S(J),{class:`ih:size-3`})],8,Zt)]))),128))])):a(``,!0),s(`div`,Qt,[O.value===`emoji`?(g(),i(Bt,{key:0,onClose:r[1]||=e=>O.value=null},{default:E(()=>[l(kt,{onPick:z})]),_:1})):a(``,!0),O.value===`gif`?(g(),i(Bt,{key:1,onClose:r[2]||=e=>O.value=null},{default:E(()=>[l(zt,{onPick:B})]),_:1})):a(``,!0),e.editing?a(``,!0):(g(),o(n,{key:2},[s(`button`,{type:`button`,"data-popup-toggle":``,class:f([`ih:grid ih:size-10 ih:shrink-0 ih:place-items-center ih:rounded-full ih:text-muted-foreground ih:hover:bg-muted ih:hover:text-foreground`,{"ih:bg-muted ih:text-foreground":O.value===`emoji`}]),"aria-label":`Emoji einfügen`,"aria-expanded":O.value===`emoji`,onClick:r[3]||=e=>V(`emoji`)},[l(S(se),{class:`ih:size-5`})],10,$t),s(`button`,{type:`button`,"data-popup-toggle":``,class:f([`ih:grid ih:h-10 ih:shrink-0 ih:place-items-center ih:rounded-full ih:px-2 ih:text-xs ih:font-bold ih:text-muted-foreground ih:hover:bg-muted ih:hover:text-foreground`,{"ih:bg-muted ih:text-foreground":O.value===`gif`}]),"aria-label":`GIF senden`,"aria-expanded":O.value===`gif`,onClick:r[4]||=e=>V(`gif`)},`GIF`,10,en),s(`button`,{type:`button`,class:`ih:grid ih:size-10 ih:shrink-0 ih:place-items-center ih:rounded-full ih:text-muted-foreground ih:hover:bg-muted ih:hover:text-foreground`,"aria-label":`Datei anhängen`,onClick:r[5]||=e=>C.value?.click()},[l(S(me),{class:`ih:size-5`})]),s(`input`,{ref_key:`fileInput`,ref:C,type:`file`,multiple:``,class:`ih:hidden`,onChange:r[6]||=e=>{P([...e.target.files]),e.target.value=``}},null,544)],64)),D(s(`textarea`,{ref_key:`input`,ref:b,"onUpdate:modelValue":r[7]||=e=>h.value=e,rows:`1`,maxlength:`5000`,placeholder:e.editing?`Nachricht bearbeiten`:`Nachricht schreiben`,"aria-label":`Nachricht`,class:`ih:max-h-[180px] ih:min-h-10 ih:flex-1 ih:resize-none ih:rounded-2xl ih:border ih:border-input ih:bg-background ih:px-4 ih:py-2 ih:text-[15px] ih:leading-snug ih:focus-visible:ring-3 ih:focus-visible:ring-ring/30 ih:focus-visible:outline-none`,onInput:N,onKeydown:R,onPaste:F},null,40,tn),[[w,h.value]]),s(`button`,{type:`button`,class:`ih:grid ih:size-10 ih:shrink-0 ih:place-items-center ih:rounded-full ih:bg-brand ih:text-brand-foreground ih:transition-opacity ih:disabled:opacity-40`,disabled:e.editing?!h.value.trim():!k.value,"aria-label":e.editing?`Speichern`:`Senden`,onClick:L},[e.sending?(g(),i(S(K),{key:0,class:`ih:size-5 ih:animate-spin`})):(g(),i(S(ge),{key:1,class:`ih:size-5`}))],8,nn)]),s(`p`,rn,[r[8]||=s(`kbd`,{class:`ih:font-sans`},`Enter`,-1),r[9]||=c(` senden · `,-1),r[10]||=s(`kbd`,{class:`ih:font-sans`},`Umschalt + Enter`,-1),r[11]||=c(` neue Zeile · Bilder lassen sich auch einfügen oder hierher ziehen `,-1),l(S(le),{class:`ih:inline ih:size-3`})])]))}},on={key:0,class:`ih:my-3 ih:text-center`},sn={class:`ih:inline-block ih:rounded-full ih:bg-muted ih:px-3 ih:py-1 ih:text-xs ih:text-muted-foreground`},cn=[`id`],ln={key:0,class:`ih:w-8 ih:shrink-0`},un={key:0,class:`ih:mb-0.5 ih:px-3 ih:text-xs ih:font-medium ih:text-muted-foreground`},dn={key:0,class:`ih:rounded-2xl ih:border ih:border-dashed ih:px-3 ih:py-2 ih:text-sm ih:text-muted-foreground ih:italic`},fn={class:`ih:block ih:font-semibold`},pn={class:`ih:line-clamp-2 ih:opacity-80`},mn=[`src`],hn=[`href`,`title`],gn=[`src`,`alt`],_n=[`href`],vn={class:`ih:min-w-0 ih:flex-1`},yn={class:`ih:block ih:truncate ih:text-sm ih:font-medium`},bn={class:`ih:block ih:text-xs ih:opacity-75`},xn=[`href`],Sn={key:2,class:`ih:flex ih:shrink-0 ih:items-center ih:opacity-0 ih:transition-opacity ih:group-hover:opacity-100 ih:focus-within:opacity-100 ih:[@media(hover:none)]:opacity-100`},Cn={class:`ih:group/react ih:relative`},wn={type:`button`,class:`ih:grid ih:size-7 ih:place-items-center ih:rounded-full ih:text-muted-foreground ih:hover:bg-muted`,"aria-label":`Reagieren`},Tn=[`aria-label`,`onClick`],En={key:1,class:`ih:relative ih:z-10 ih:-mt-1.5 ih:flex ih:flex-wrap ih:gap-1 ih:px-2`},Dn=[`aria-pressed`,`aria-label`,`onClick`],On={class:`ih:text-sm`},kn={class:`ih:mt-0.5 ih:px-1 ih:text-[11px] ih:text-muted-foreground ih:tabular-nums`},An={__name:`MessageBubble`,props:{message:{type:Object,required:!0},showAuthor:{type:Boolean,default:!0},showAvatar:{type:Boolean,default:!0},group:{type:Boolean,default:!1},reactions:{type:Array,required:!0},read:{type:Boolean,default:!1}},emits:[`react`,`reply`,`edit`,`delete`,`jump`],setup(e,{emit:t}){let u=e,d=t,m=r(()=>u.message),h=r(()=>!m.value.attachments.length&&!m.value.reply_to&&at(m.value.body)),_=r(()=>m.value.attachments.filter(e=>e.image)),y=r(()=>m.value.attachments.filter(e=>!e.image));return(t,r)=>m.value.kind===`system`?(g(),o(`div`,on,[s(`span`,sn,x(m.value.body),1)])):(g(),o(`div`,{key:1,id:`nachricht-${m.value.id}`,class:f([`ih:group ih:flex ih:items-end ih:gap-2`,[m.value.mine?`ih:flex-row-reverse`:``,e.showAuthor?`ih:mt-3`:`ih:mt-0.5`]])},[e.group&&!m.value.mine?(g(),o(`div`,ln,[e.showAvatar&&m.value.user?(g(),i(S(V),{key:0,person:m.value.user,class:`ih:size-8 ih:text-[11px]`},null,8,[`person`])):a(``,!0)])):a(``,!0),s(`div`,{class:f([`ih:flex ih:max-w-[min(34rem,80%)] ih:min-w-0 ih:flex-col`,m.value.mine?`ih:items-end`:`ih:items-start`])},[e.group&&!m.value.mine&&e.showAuthor?(g(),o(`span`,un,x(m.value.user?.name??`Gelöschtes Konto`),1)):a(``,!0),s(`div`,{class:f([`ih:relative ih:flex ih:items-center ih:gap-1`,m.value.mine?`ih:flex-row-reverse`:``])},[m.value.deleted?(g(),o(`div`,dn,`Nachricht gelöscht`)):(g(),o(`div`,{key:1,class:f([`ih:min-w-0 ih:overflow-hidden ih:text-[15px] ih:leading-snug`,h.value||m.value.kind===`gif`?``:[m.value.mine?`ih:rounded-2xl ih:rounded-br-md ih:bg-brand ih:text-brand-foreground`:`ih:rounded-2xl ih:rounded-bl-md ih:border ih:bg-card`,_.value.length&&!m.value.body?``:`ih:px-3 ih:py-2`]])},[m.value.reply_to?(g(),o(`button`,{key:0,type:`button`,class:f([`ih:mb-1.5 ih:block ih:w-full ih:rounded-md ih:border-l-3 ih:px-2 ih:py-1 ih:text-left ih:text-[13px]`,m.value.mine?`ih:border-white/60 ih:bg-white/15`:`ih:border-brand ih:bg-muted`]),onClick:r[0]||=e=>d(`jump`,m.value.reply_to.id)},[s(`span`,fn,x(m.value.reply_to.name),1),s(`span`,pn,x(m.value.reply_to.text),1)],2)):a(``,!0),m.value.kind===`gif`?(g(),o(`img`,{key:1,src:m.value.gif_url,alt:`GIF`,loading:`lazy`,class:`ih:max-h-60 ih:rounded-2xl`},null,8,mn)):a(``,!0),_.value.length?(g(),o(`div`,{key:2,class:f([`ih:grid ih:gap-0.5`,_.value.length>1?`ih:grid-cols-2`:``])},[(g(!0),o(n,null,v(_.value,e=>(g(),o(`a`,{key:e.id,href:e.url,target:`_blank`,rel:`noopener`,class:`ih:block ih:overflow-hidden ih:bg-muted`,title:e.name},[s(`img`,{src:e.url,alt:e.name,loading:`lazy`,class:`ih:block ih:max-h-72 ih:w-full ih:object-cover`,style:p(e.width?{aspectRatio:`${e.width} / ${e.height}`}:{})},null,12,gn)],8,hn))),128))],2)):a(``,!0),(g(!0),o(n,null,v(y.value,e=>(g(),o(`a`,{key:e.id,href:e.url,class:f([`ih:my-1 ih:flex ih:items-center ih:gap-2.5 ih:rounded-lg ih:p-2 ih:no-underline`,m.value.mine?`ih:bg-white/15 ih:hover:bg-white/25`:`ih:bg-muted ih:hover:bg-accent`])},[l(S(R),{extension:e.name.split(`.`).pop(),class:`ih:shrink-0`},null,8,[`extension`]),s(`span`,vn,[s(`span`,yn,x(e.name),1),s(`span`,bn,x(S(rt)(e.size)),1)]),l(S(ie),{class:`ih:size-4 ih:shrink-0 ih:opacity-75`})],10,_n))),128)),m.value.body?(g(),o(`p`,{key:3,class:f([`ih:break-words ih:whitespace-pre-wrap`,[h.value?`ih:text-4xl ih:leading-tight`:``,_.value.length?`ih:px-3 ih:py-2`:``]])},[(g(!0),o(n,null,v(S(it)(m.value.body),(e,t)=>(g(),o(n,{key:t},[e.href?(g(),o(`a`,{key:0,href:e.href,target:`_blank`,rel:`noopener noreferrer`,class:`ih:underline ih:underline-offset-2`},x(e.text),9,xn)):(g(),o(n,{key:1},[c(x(e.text),1)],64))],64))),128))],2)):a(``,!0)],2)),m.value.deleted?a(``,!0):(g(),o(`div`,Sn,[s(`div`,Cn,[s(`button`,wn,[l(S(oe),{class:`ih:size-4`})]),s(`div`,{class:f([`ih:absolute ih:bottom-full ih:z-20 ih:hidden ih:gap-0.5 ih:rounded-full ih:border ih:bg-popover ih:p-1 ih:shadow-md ih:group-focus-within/react:flex ih:group-hover/react:flex`,m.value.mine?`ih:right-0`:`ih:left-0`])},[(g(!0),o(n,null,v(e.reactions,e=>(g(),o(`button`,{key:e,type:`button`,class:`ih:grid ih:size-8 ih:place-items-center ih:rounded-full ih:text-lg ih:hover:bg-accent`,"aria-label":`Mit ${e} reagieren`,onClick:t=>d(`react`,e)},x(e),9,Tn))),128))],2)]),s(`button`,{type:`button`,class:`ih:grid ih:size-7 ih:place-items-center ih:rounded-full ih:text-muted-foreground ih:hover:bg-muted`,"aria-label":`Antworten`,onClick:r[1]||=e=>d(`reply`)},[l(S(W),{class:`ih:size-4`})]),m.value.mine?(g(),o(n,{key:0},[m.value.body&&m.value.kind===`text`?(g(),o(`button`,{key:0,type:`button`,class:`ih:grid ih:size-7 ih:place-items-center ih:rounded-full ih:text-muted-foreground ih:hover:bg-muted`,"aria-label":`Bearbeiten`,onClick:r[2]||=e=>d(`edit`)},[l(S(he),{class:`ih:size-4`})])):a(``,!0),s(`button`,{type:`button`,class:`ih:grid ih:size-7 ih:place-items-center ih:rounded-full ih:text-muted-foreground ih:hover:bg-muted ih:hover:text-destructive`,"aria-label":`Löschen`,onClick:r[3]||=e=>d(`delete`)},[l(S(_e),{class:`ih:size-4`})])],64)):a(``,!0)]))],2),m.value.reactions.length?(g(),o(`div`,En,[(g(!0),o(n,null,v(m.value.reactions,e=>(g(),o(`button`,{key:e.emoji,type:`button`,class:f([`ih:flex ih:items-center ih:gap-1 ih:rounded-full ih:border ih:px-1.5 ih:text-xs ih:shadow-xs ih:tabular-nums`,e.mine?`ih:border-brand ih:bg-brand-soft`:`ih:bg-card`]),"aria-pressed":e.mine,"aria-label":`${e.emoji} ${e.count}`,onClick:t=>d(`react`,e.emoji)},[s(`span`,On,x(e.emoji),1),c(x(e.count>1?e.count:``),1)],10,Dn))),128))])):a(``,!0),s(`span`,kn,[c(x(S(tt)(m.value.created_at)),1),m.value.edited?(g(),o(n,{key:0},[c(` · bearbeitet`)],64)):a(``,!0),m.value.mine&&e.read?(g(),o(n,{key:1},[c(` · gelesen`)],64)):a(``,!0)])],2)],10,cn))}},jn=[`aria-label`],Mn={class:`ih:flex ih:items-center ih:gap-3 ih:border-b ih:px-3 ih:py-2.5`},Nn={class:`ih:min-w-0 ih:flex-1`},Pn={class:`ih:flex ih:items-center ih:gap-1.5 ih:truncate ih:font-semibold`},Fn=[`href`],In={key:1,class:`ih:truncate`},Ln=[`aria-label`],Rn={key:0,class:`ih:grid ih:h-full ih:place-items-center`},zn={key:0,class:`ih:flex ih:justify-center ih:py-2`},Bn={key:1,class:`ih:py-10 ih:text-center ih:text-sm ih:text-muted-foreground`},Vn={key:0,class:`ih:my-4 ih:flex ih:justify-center`},Hn={class:`ih:rounded-full ih:bg-card ih:px-3 ih:py-1 ih:text-xs ih:font-medium ih:text-muted-foreground ih:shadow-xs`},Un={key:1,class:`ih:my-3 ih:flex ih:items-center ih:gap-3 ih:text-xs ih:font-semibold ih:text-brand-text`},Wn={key:1,class:`ih:pointer-events-none ih:absolute ih:inset-2 ih:z-20 ih:grid ih:place-items-center ih:rounded-xl ih:border-2 ih:border-dashed ih:border-brand ih:bg-brand-soft/80 ih:text-brand-text`},Gn={class:`ih:flex ih:items-center ih:gap-2 ih:font-medium`},Kn={__name:`Thread`,props:{conversation:{type:Object,required:!0},me:{type:Object,required:!0},reactions:{type:Array,required:!0},maxUploadMb:{type:Number,default:25},typing:{type:Array,default:()=>[]}},emits:[`back`,`info`,`changed`,`read`],setup(e,{expose:t,emit:u}){let p=e,m=u,y=_([]),b=_(!1),C=_(!0),w=_(!1),E=_(!1),D=_(null),O=_(null),A=_(null),j=_(null),M=_(!0),N=_(0),P=_(!1),F=_(null),I=r(()=>p.conversation.type===`group`),L=()=>y.value.at(-1)?.id??0,R=r(()=>[...y.value].reverse().find(e=>e.mine&&!e.deleted&&e.kind!==`system`)?.id);async function z(){C.value=!0,y.value=[],D.value=O.value=null;try{let e=await X.messages(p.conversation.id);y.value=e.messages,b.value=e.more;let t=p.conversation.last_read_id??0;F.value=p.conversation.unread?e.messages.find(e=>e.id>t&&!e.mine&&e.kind!==`system`)?.id??null:null}finally{C.value=!1,await d(),V(F.value?document.getElementById(`nachricht-${F.value}`):null),W(),j.value?.focus()}}async function B(){if(!b.value||w.value||!y.value.length)return;w.value=!0;let e=A.value,t=e.scrollHeight;try{let n=await X.messages(p.conversation.id,y.value[0].id);y.value=[...n.messages,...y.value],b.value=n.more,await d(),e.scrollTop=e.scrollHeight-t}finally{w.value=!1}}function V(e){let t=A.value;t&&(e?e.scrollIntoView({block:`center`}):t.scrollTop=t.scrollHeight,N.value=0)}function ee(){let e=A.value;M.value=e.scrollHeight-e.scrollTop-e.clientHeight<80,M.value&&(N.value=0,W()),e.scrollTop<120&&B()}let H;function W(){clearTimeout(H),H=setTimeout(async()=>{if(![...y.value].reverse().find(e=>!e.mine)||document.visibilityState!==`visible`||!M.value||!p.conversation.unread)return;let e=await X.read(p.conversation.id,L());m(`read`,{id:p.conversation.id,unread:e.unread})},400)}async function G(e){let t=e.filter(e=>e.conversation_id===p.conversation.id);if(!t.length)return;let n=new Map(y.value.map(e=>[e.id,e])),r=0;for(let e of t)n.has(e.id)?Object.assign(n.get(e.id),e):e.id>L()&&(y.value.push(e),r+=+!e.mine);if(!r)return;let i=M.value;await d(),i?(V(),W()):N.value+=r}async function ie(e){E.value=!0;try{let{message:t}=await X.send(p.conversation.id,{...e,replyTo:D.value?.id});D.value=null,y.value.some(e=>e.id===t.id)||y.value.push(t),await d(),V(),m(`changed`)}catch(e){U.error(e.message)}finally{E.value=!1}}async function ae(e){let t=O.value;try{await X.edit(t.id,e),Object.assign(t,{body:e,edited:!0}),O.value=null}catch(e){U.error(e.message)}}async function oe(e){window.confirm(`Nachricht für alle löschen?`)&&(await X.remove(e.id),Object.assign(e,{deleted:!0,body:null,gif_url:null,attachments:[],reactions:[]}),m(`changed`))}async function se(e,t){let n=e.reactions.find(e=>e.emoji===t);n?.mine?(n.count--,n.mine=!1,e.reactions=e.reactions.filter(e=>e.count>0)):n?(n.count++,n.mine=!0):e.reactions.push({emoji:t,count:1,mine:!0}),await X.react(e.id,t).catch(e=>U.error(e.message))}function ce(e){let t=document.getElementById(`nachricht-${e}`);t&&(t.scrollIntoView({block:`center`,behavior:`smooth`}),t.classList.add(`ih:animate-pulse`),setTimeout(()=>t.classList.remove(`ih:animate-pulse`),1500))}function le(e){P.value=!1;let t=[...e.dataTransfer?.files??[]];t.length&&j.value?.addFiles(t)}let de=(e,t)=>{let n=y.value[t-1];return!n||n.kind===`system`||n.user?.id!==e.user?.id||!$(n.created_at,e.created_at)||new Date(e.created_at)-new Date(n.created_at)>3e5},fe=(e,t)=>{let n=y.value[t+1];return!n||n.kind===`system`||n.user?.id!==e.user?.id||!$(n.created_at,e.created_at)},pe=r(()=>p.typing.length?`${p.typing.join(`, `)} ${p.typing.length===1?`schreibt`:`schreiben`} …`:I.value?p.conversation.members.map(e=>e.first_name||e.name).join(`, `):p.conversation.person?.job_title??``);return T(()=>p.conversation.id,z),h(z),t({merge:G,lastId:L}),(t,r)=>(g(),o(`section`,{class:`ih:relative ih:flex ih:h-full ih:min-h-0 ih:flex-col`,"aria-label":`Gespräch mit ${e.conversation.name}`,onDragover:r[5]||=k(e=>P.value=!0,[`prevent`]),onDragleave:r[6]||=k(e=>P.value=!1,[`self`]),onDrop:k(le,[`prevent`])},[s(`header`,Mn,[s(`button`,{type:`button`,class:`ih:grid ih:size-9 ih:place-items-center ih:rounded-md ih:text-muted-foreground ih:hover:bg-accent ih:lg:hidden`,"aria-label":`Zurück zur Übersicht`,onClick:r[0]||=e=>m(`back`)},[l(S(ne),{class:`ih:size-5`})]),l(Ye,{conversation:e.conversation},null,8,[`conversation`]),s(`div`,Nn,[s(`h2`,Pn,[e.conversation.person?(g(),o(`a`,{key:0,href:`/personen/${e.conversation.person.id}`,class:`ih:truncate ih:hover:underline`},x(e.conversation.name),9,Fn)):(g(),o(`span`,In,x(e.conversation.name),1)),e.conversation.muted?(g(),i(S(re),{key:2,class:`ih:size-3.5 ih:shrink-0 ih:text-muted-foreground`,"aria-label":`Stummgeschaltet`})):a(``,!0)]),s(`p`,{class:f([`ih:truncate ih:text-xs`,e.typing.length?`ih:text-brand-text`:`ih:text-muted-foreground`]),"aria-live":`polite`},x(pe.value),3)]),s(`button`,{type:`button`,class:`ih:grid ih:size-9 ih:place-items-center ih:rounded-md ih:text-muted-foreground ih:hover:bg-accent`,"aria-label":I.value?`Gruppe: Mitglieder und Einstellungen`:`Einstellungen zum Gespräch`,onClick:r[1]||=e=>m(`info`)},[l(S(ue),{class:`ih:size-5`})],8,Ln)]),s(`div`,{ref_key:`scroller`,ref:A,class:`ih:min-h-0 ih:flex-1 ih:overflow-y-auto ih:bg-muted/30 ih:px-3 ih:py-4 ih:sm:px-5`,role:`log`,"aria-live":`polite`,"aria-relevant":`additions`,onScrollPassive:ee},[C.value?(g(),o(`div`,Rn,[l(S(K),{class:`ih:size-6 ih:animate-spin ih:text-muted-foreground`})])):(g(),o(n,{key:1},[w.value?(g(),o(`div`,zn,[l(S(K),{class:`ih:size-4 ih:animate-spin ih:text-muted-foreground`})])):a(``,!0),y.value.length?a(``,!0):(g(),o(`p`,Bn,`Schreiben Sie die erste Nachricht.`)),(g(!0),o(n,null,v(y.value,(t,i)=>(g(),o(n,{key:t.id},[i===0||!S($)(y.value[i-1].created_at,t.created_at)?(g(),o(`div`,Vn,[s(`span`,Hn,x(S(nt)(t.created_at)),1)])):a(``,!0),t.id===F.value?(g(),o(`div`,Un,[...r[7]||=[s(`span`,{class:`ih:h-px ih:flex-1 ih:bg-brand/40`},null,-1),c(`Neu`,-1),s(`span`,{class:`ih:h-px ih:flex-1 ih:bg-brand/40`},null,-1)]])):a(``,!0),l(An,{message:t,group:I.value,"show-author":de(t,i),"show-avatar":fe(t,i),reactions:e.reactions,read:t.id===R.value&&!!e.conversation.others_read_id&&e.conversation.others_read_id>=t.id,onReact:e=>se(t,e),onReply:e=>{D.value=t,O.value=null},onEdit:e=>{O.value=t,D.value=null},onDelete:e=>oe(t),onJump:ce},null,8,[`message`,`group`,`show-author`,`show-avatar`,`reactions`,`read`,`onReact`,`onReply`,`onEdit`,`onDelete`])],64))),128))],64))],544),N.value?(g(),o(`button`,{key:0,type:`button`,class:`ih:absolute ih:bottom-28 ih:left-1/2 ih:z-10 ih:flex ih:-translate-x-1/2 ih:items-center ih:gap-1.5 ih:rounded-full ih:bg-brand ih:px-3 ih:py-1.5 ih:text-xs ih:font-medium ih:text-brand-foreground ih:shadow-lg`,onClick:r[2]||=e=>{V(),W()}},[l(S(te),{class:`ih:size-3.5`}),c(` `+x(N.value)+` `+x(N.value===1?`neue Nachricht`:`neue Nachrichten`),1)])):a(``,!0),l(an,{ref_key:`composer`,ref:j,"reply-to":D.value,editing:O.value,sending:E.value,"max-upload-mb":e.maxUploadMb,onSend:ie,onSaveEdit:ae,onCancel:r[3]||=e=>{D.value=null,O.value=null},onTyping:r[4]||=t=>S(X).typing(e.conversation.id).catch(()=>{})},null,8,[`reply-to`,`editing`,`sending`,`max-upload-mb`]),P.value?(g(),o(`div`,Wn,[s(`span`,Gn,[l(S(ve),{class:`ih:size-5`}),r[8]||=c(` Dateien hier ablegen`,-1)])])):a(``,!0)],40,jn))}},qn=`modulepreload`,Jn=function(e,t){return new URL(e,t).href},Yn={},Xn=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=Jn(t,n),t=s(t),t in Yn)return;Yn[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:qn,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})};function Zn({realtime:t,userId:n,openId:r,lastId:i,onUpdate:a}){let o=null,s=null,c=!1,l=!1,u=null,d=()=>{let e=document.visibilityState===`visible`;return u?.connection?.state===`connected`?e?2e4:6e4:e?document.hasFocus()?3e3:6e3:3e4};async function f(){if(!(c||l)){c=!0,clearTimeout(s);try{let e=await X.updates({seit:o,offen:r(),nach:i()});o=e.cursor,a(e)}catch{}finally{c=!1,l||(s=setTimeout(f,d()))}}}let p=()=>document.visibilityState===`visible`&&f();return document.addEventListener(`visibilitychange`,p),window.addEventListener(`focus`,p),t&&Xn(async()=>{let{default:t}=await import(`../chunks/pusher-DXDYBH7H.js`).then(t=>e(t.default,1));return{default:t}},__vite__mapDeps([0,1]),import.meta.url).then(({default:e})=>{l||(u=new e(t.key,{cluster:t.cluster,...t.host?{wsHost:t.host,wsPort:t.port,wssPort:t.port,forceTLS:t.tls,enabledTransports:[`ws`,`wss`]}:{},channelAuthorization:{endpoint:`/chat/api/echtzeit/anmelden`,headers:{"X-XSRF-TOKEN":decodeURIComponent(document.cookie.match(/(?:^|; )XSRF-TOKEN=([^;]*)/)?.[1]??``),Accept:`application/json`}}}),u.subscribe(`private-chat-user-${n}`).bind(`update`,()=>f()))}).catch(()=>{}),f(),{now:f,reset(){o=null,f()},stop(){l=!0,clearTimeout(s),document.removeEventListener(`visibilitychange`,p),window.removeEventListener(`focus`,p),u?.disconnect()}}}var Qn={class:`ih:-mx-4 ih:-my-6 ih:flex ih:h-[calc(100dvh-4rem)] ih:overflow-hidden ih:border-y ih:bg-card ih:lg:mx-0 ih:lg:my-0 ih:lg:h-[calc(100dvh-8.5rem)] ih:lg:rounded-xl ih:lg:border ih:lg:shadow-xs`},$n={key:1,class:`ih:grid ih:h-full ih:place-items-center ih:p-8 ih:text-center`},er={__name:`Index`,props:{me:{type:Object,required:!0},conversations:{type:Array,required:!0},activeId:{type:Number,default:null},canCreateGroups:{type:Boolean,default:!1},realtime:{type:Object,default:null},reactions:{type:Array,required:!0},maxUploadMb:{type:Number,default:25}},setup(e){let t=e,n=_(t.conversations),c=_(t.activeId),u=_([]),d=_(null),p=_(null),v=_(!1),y=r(()=>n.value.find(e=>e.id===c.value)??null);function b(e,t=!0){c.value=e,u.value=[],t&&location.pathname!==`/chat/${e??``}`.replace(/\/$/,``)&&history.pushState({chat:e},``,e?`/chat/${e}`:`/chat`),w?.now()}let x=()=>b(Number(location.pathname.split(`/`)[2])||null,!1);function C(e){e&&(n.value=e,Z(e.reduce((e,t)=>e+(t.muted?0:t.unread),0)))}let w=null;h(()=>{window.addEventListener(`popstate`,x),w=Zn({realtime:t.realtime,userId:t.me.id,openId:()=>c.value,lastId:()=>d.value?.lastId()??0,onUpdate(e){C(e.conversations),u.value=e.typing??[],d.value?.merge(e.messages??[]),Z(e.unread)}})}),m(()=>{window.removeEventListener(`popstate`,x),w?.stop()});function T(e){C(e.conversations),b(e.id)}async function D(){C((await X.conversations()).conversations)}function O({id:e,unread:t}){let r=n.value.find(t=>t.id===e);r&&(r.unread=0),Z(t)}return(t,r)=>(g(),i(S(A),{title:`Nachrichten`,width:`app`,header:!1},{default:E(()=>[s(`div`,Qn,[s(`aside`,{class:f([`ih:w-full ih:shrink-0 ih:border-r ih:lg:block ih:lg:w-80 ih:xl:w-96`,y.value?`ih:hidden`:`ih:block`])},[l(vt,{conversations:n.value,"active-id":c.value,"can-create-groups":e.canCreateGroups,onOpen:b,onNewChat:r[0]||=e=>p.value=`chat`,onNewGroup:r[1]||=e=>p.value=`group`},null,8,[`conversations`,`active-id`,`can-create-groups`])],2),s(`main`,{class:f([`ih:min-w-0 ih:flex-1 ih:lg:block`,y.value?`ih:block`:`ih:hidden`])},[y.value?(g(),i(Kn,{key:0,ref_key:`thread`,ref:d,conversation:y.value,me:e.me,reactions:e.reactions,typing:u.value,"max-upload-mb":e.maxUploadMb,onBack:r[2]||=e=>b(null),onInfo:r[3]||=e=>v.value=!0,onChanged:D,onRead:O},null,8,[`conversation`,`me`,`reactions`,`typing`,`max-upload-mb`])):(g(),o(`div`,$n,[s(`div`,null,[l(S(pe),{class:`ih:mx-auto ih:size-12 ih:text-muted-foreground/60`,"stroke-width":1.5}),r[7]||=s(`p`,{class:`ih:mt-3 ih:font-medium`},`Wählen Sie ein Gespräch`,-1),r[8]||=s(`p`,{class:`ih:mt-1 ih:text-sm ih:text-muted-foreground`},`oder beginnen Sie eine neue Nachricht.`,-1)])]))],2)]),l(Ct,{open:p.value!==null,group:p.value===`group`,me:e.me,"onUpdate:open":r[4]||=e=>!e&&(p.value=null),onCreated:T},null,8,[`open`,`group`,`me`]),y.value?(g(),i(Je,{key:0,open:v.value,"onUpdate:open":r[5]||=e=>v.value=e,conversation:y.value,me:e.me,onUpdated:C,onLeft:r[6]||=e=>b(null)},null,8,[`open`,`conversation`,`me`])):a(``,!0)]),_:1}))}};export{er as default}; \ No newline at end of file diff --git a/plugin.json b/plugin.json index 615196f..7efdcdd 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "slug": "chat", "name": "Nachrichten", - "version": "1.1.0", + "version": "1.2.0", "description": "Direktnachrichten und Gruppenchats im Portal – mit Anhängen, Bildern, GIFs (eigene Sammlung und optional GIPHY), Emojis, Reaktionen, Antworten und Gelesen-Status. Gruppen anlegen nur mit Recht; auf Wunsch Echtzeit über einen Pusher-kompatiblen Dienst.", "author": "Loheide", "namespace": "Inhaus\\Plugins\\Chat\\", diff --git a/resources/js/pages/Index.vue b/resources/js/pages/Index.vue index 02b99bb..fc64097 100644 --- a/resources/js/pages/Index.vue +++ b/resources/js/pages/Index.vue @@ -91,7 +91,7 @@ function onRead({ id, unread }) {