@extends('layouts.app')

@section('title', 'Chat Sessions | SEF Solution')

@section('content')
<div class="admin-page">
    <div class="admin-card">
        <div class="admin-top">
            <div>
                <span class="brand-badge">SEF Solution</span>
                <h1>Visitor Chat Sessions</h1>
                <p>যারা ওয়েবসাইটে ঢুকে চ্যাট করেছে তাদের সব লিস্ট</p>
            </div>
            <div class="top-actions">
                <a href="{{ route('admin.dashboard') }}" class="admin-link">Dashboard</a>
                <a href="{{ route('admin.forms') }}" class="admin-link">Lead Forms</a>
            </div>
        </div>

        <div class="table-wrap">
            <table class="lead-table">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Phone</th>
                        <th>Messages</th>
                        <th>Active Time</th>
                        <th>Return Visitor</th>
                        <th>Lead Status</th>
                        <th>Chat Date</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($sessions as $chat)
                        <tr>
                            <td>{{ $chat->id }}</td>
                            <td>{{ $chat->phone ?: 'N/A' }}</td>
                            <td>{{ $chat->messages_count }}</td>
                            <td>{{ $chat->active_seconds >= 60 ? ceil($chat->active_seconds / 60).'m' : $chat->active_seconds.'s' }}</td>
                            <td>{{ $chat->is_returning ? 'Yes' : 'No' }}</td>
                            <td><span class="status-chip">{{ ucfirst($chat->lead_status ?: 'open') }}</span></td>
                            <td>{{ $chat->last_activity_at?->format('d M Y, h:i A') }}</td>
                            <td><a href="{{ route('admin.chats.show', $chat) }}">Open Chat</a></td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="8" class="empty-state">এখনও কোনো chat session আসেনি।</td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>

        <div class="pagination-wrap">{{ $sessions->links() }}</div>
    </div>
</div>
@endsection
