@extends('layouts.app')

@section('title', 'Direct Messages')

@section('content')
<div class="container-fluid px-0 py-0" data-reveal>
    <div class="chat-layout">
        <!-- Sidebar Conversions -->
        <div class="chat-sidebar">
            <div class="chat-header justify-content-between">
                <span class="fw-800 text-white fs-5">Conversations</span>
                <button class="btn-arena btn-ghost btn-icon"><i class="bi bi-pencil-square" style="font-size: 1rem;"></i></button>
            </div>
            <div class="chat-search">
                <input type="text" placeholder="Search conversations...">
            </div>
            <div class="chat-list">
                @foreach($conversations as $c)
                <div class="chat-item {{ $loop->first ? 'active' : '' }}">
                    <div class="chat-avatar-wrap">
                        @if($c['avatar'])
                            <img src="{{ asset($c['avatar']) }}" alt="{{ $c['name'] }}" class="chat-avatar">
                        @else
                            <div class="chat-avatar" style="background: var(--arena-surface-03); display: flex; align-items: center; justify-content: center; font-weight: 800; color: var(--arena-accent);">
                                C
                            </div>
                        @endif
                        @if($c['online'])
                            <span class="badge-dot online" style="position: absolute; bottom: 0; right: 0; border: 2px solid var(--arena-surface-01);"></span>
                        @endif
                    </div>
                    <div class="chat-item-meta">
                        <div class="d-flex justify-content-between align-items-center mb-1">
                            <span class="chat-item-name">{{ $c['name'] }}</span>
                            <span class="fs-xs text-muted">{{ $c['time'] }}</span>
                        </div>
                        <div class="d-flex justify-content-between align-items-center">
                            <span class="chat-item-last">{{ $c['last'] }}</span>
                            @if($c['unread'] > 0)
                                <span class="chat-unread">{{ $c['unread'] }}</span>
                            @endif
                        </div>
                    </div>
                </div>
                @endforeach
            </div>
        </div>

        <!-- Chat thread window -->
        <div class="chat-thread">
            <!-- Active Header -->
            <div class="chat-header justify-content-between">
                <div class="d-flex align-items-center gap-3">
                    <div class="position-relative">
                        <img src="{{ asset('assets/images/generated/players/player-1.webp') }}" alt="User" class="chat-avatar" style="width: 40px; height: 40px;">
                        <span class="badge-dot online" style="position: absolute; bottom: 0; right: 0; border: 2px solid var(--arena-bg);"></span>
                    </div>
                    <div>
                        <span class="fw-700 text-white fs-sm d-block">{{ $conversations[0]['name'] }}</span>
                        <span class="fs-xs text-success">Online Competitor</span>
                    </div>
                </div>
                <div class="d-flex gap-2">
                    <button class="btn-arena btn-ghost btn-icon"><i class="bi bi-telephone"></i></button>
                    <button class="btn-arena btn-ghost btn-icon"><i class="bi bi-three-dots-vertical"></i></button>
                </div>
            </div>

            <!-- Messages lists -->
            <div class="chat-messages" id="chatMessages">
                <!-- Received -->
                <div class="message">
                    <img src="{{ asset('assets/images/generated/players/player-2.webp') }}" alt="Avatar" class="msg-avatar" onerror="this.style.display='none';">
                    <div class="message-bubble">
                        Hey! Are we still practicing on Haven tonight at 20:00?
                    </div>
                </div>

                <!-- Sent -->
                <div class="message own">
                    <div class="message-bubble">
                        Yes, everyone is confirmed. Roster is fully assembled.
                    </div>
                </div>

                <!-- Received -->
                <div class="message">
                    <img src="{{ asset('assets/images/generated/players/player-2.webp') }}" alt="Avatar" class="msg-avatar" onerror="this.style.display='none';">
                    <div class="message-bubble">
                        Awesome! See you in the lobby lobby. GG!
                    </div>
                </div>
            </div>

            <!-- Input area -->
            <div class="chat-input-area">
                <textarea id="chatMessageInput" placeholder="Write your message..."></textarea>
                <button class="btn-arena btn-primary btn-icon" id="chatSendBtn" style="width: 42px; height: 42px; display: flex; align-items: center; justify-content: center;">
                    <i class="bi bi-send-fill" style="font-size: 0.875rem;"></i>
                </button>
            </div>
        </div>
    </div>
</div>
@endsection
