@extends('layouts.site')

@section('title', 'Live Chat Support — ' . config('app.name'))

@section('content')
{{-- Hero Section --}}
<div class="bg-gradient-to-r from-green-800 to-green-900 shadow-lg" style="background: linear-gradient(to right, #1a4731, #0f2819);">
    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
        <div class="flex items-center gap-6">
            <div class="hidden md:flex w-20 h-20 rounded-xl shadow-lg bg-white/10 items-center justify-center flex-shrink-0">
                <i class="fas fa-headset text-white text-3xl"></i>
            </div>
            <div>
                <h1 class="text-3xl md:text-4xl font-serif font-bold text-white">Live Chat Support</h1>
                <p class="text-green-200 mt-2">Start a conversation with our support team.</p>
            </div>
        </div>
    </div>
</div>

{{-- Breadcrumb --}}
<div class="bg-gray-50 border-b border-gray-200">
    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-3">
        <nav class="flex items-center space-x-2 text-sm text-gray-600" aria-label="Breadcrumb">
            <a href="{{ url('/') }}" class="hover:text-green-600 transition flex items-center">
                <i class="fas fa-home mr-1"></i>Home
            </a>
            <i class="fas fa-chevron-right text-gray-400 text-xs"></i>
            <span class="text-gray-900 font-medium">Live Chat Support</span>
        </nav>
    </div>
</div>

<div class="bg-gray-50 py-12 px-4">
    <div class="max-w-lg w-full">
        {{-- Header --}}
        <div class="text-center mb-8">
            <div class="w-16 h-16 rounded-full flex items-center justify-center mx-auto mb-4" style="background-color: #1a4731;">
                <i class="fas fa-headset text-white text-2xl"></i>
            </div>
            <h1 class="text-2xl font-bold text-gray-900">SSHIA Live Support</h1>
            <p class="text-gray-500 mt-1">Start a conversation with our support team</p>
        </div>

        @if(session('success'))
            <div class="mb-4 p-4 bg-green-100 border border-green-400 text-green-700 rounded-lg flex items-center gap-2">
                <i class="fas fa-check-circle"></i> {{ session('success') }}
            </div>
        @endif

        {{-- Chat Form --}}
        <div class="bg-white rounded-2xl shadow-lg border border-gray-200 overflow-hidden">
            <div class="px-6 py-5 border-b border-gray-100" style="background-color: #1a4731;">
                <div class="flex items-center gap-3">
                    <div class="w-10 h-10 rounded-full bg-white/20 flex items-center justify-center">
                        <i class="fas fa-comments text-white"></i>
                    </div>
                    <div>
                        <p class="text-white font-semibold">Start a Chat</p>
                        <p class="text-green-200 text-xs">We typically reply within minutes</p>
                    </div>
                </div>
            </div>

            <form action="{{ route('chat.public.create') }}" method="POST" class="p-6 space-y-4">
                @csrf

                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <div>
                        <label for="visitor_name" class="block text-sm font-medium text-gray-700 mb-1">
                            Your Name <span class="text-gray-400 text-xs">(optional)</span>
                        </label>
                        <input type="text" id="visitor_name" name="visitor_name"
                            value="{{ old('visitor_name', $name) }}"
                            placeholder="John Doe"
                            class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-green-500">
                    </div>
                    <div>
                        <label for="visitor_email" class="block text-sm font-medium text-gray-700 mb-1">
                            Your Email <span class="text-gray-400 text-xs">(optional)</span>
                        </label>
                        <input type="email" id="visitor_email" name="visitor_email"
                            value="{{ old('visitor_email', $email) }}"
                            placeholder="john@example.com"
                            class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-green-500">
                    </div>
                </div>

                @if($categories->count() > 0)
                    <div>
                        <label for="category_id" class="block text-sm font-medium text-gray-700 mb-1">
                            Topic <span class="text-gray-400 text-xs">(optional)</span>
                        </label>
                        <select id="category_id" name="category_id"
                            class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-green-500">
                            <option value="">Select a topic...</option>
                            @foreach($categories as $category)
                                <option value="{{ $category->id }}" {{ old('category_id') == $category->id ? 'selected' : '' }}>
                                    {{ $category->name }}
                                </option>
                            @endforeach
                        </select>
                    </div>
                @endif

                <div>
                    <label for="initial_message" class="block text-sm font-medium text-gray-700 mb-1">
                        How can we help you? <span class="text-red-500">*</span>
                    </label>
                    <textarea id="initial_message" name="initial_message" rows="4" required
                        placeholder="Describe your question or issue..."
                        class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-green-500 resize-none @error('initial_message') border-red-400 @enderror">{{ old('initial_message', $message) }}</textarea>
                    @error('initial_message')<p class="mt-1 text-xs text-red-600">{{ $message }}</p>@enderror
                </div>

                <button type="submit"
                    class="w-full py-3 text-white font-semibold rounded-lg transition hover:opacity-90"
                    style="background-color: #1a4731;">
                    <i class="fas fa-paper-plane mr-2"></i> Start Chat
                </button>
            </form>
        </div>

        <p class="text-center text-xs text-gray-400 mt-4">
            By starting a chat, you agree to our privacy policy. Your conversation may be recorded for quality purposes.
        </p>
    </div>
</div>
@endsection
