@extends('layouts.seller')

@section('title', 'Litige #' . $dispute->id)

@section('content')
<div class="container mx-auto px-4 py-6">
    <div class="flex justify-between items-center mb-6">
        <h1 class="text-2xl font-bold">Litige #{{ $dispute->id }}</h1>
        <a href="{{ route('seller.disputes.index') }}" class="text-blue-600 hover:underline">&larr; Retour</a>
    </div>

    <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
        <div class="lg:col-span-2 space-y-6">
            <div class="bg-white dark:bg-gray-800 rounded-lg shadow p-6">
                <h2 class="text-lg font-semibold mb-4">{{ $dispute->subject }}</h2>
                <p class="text-gray-600 dark:text-gray-300 mb-4">{{ $dispute->description }}</p>
                <div class="flex gap-4 text-sm text-gray-500">
                    <span>Type: {{ $dispute->type }}</span>
                    <span>Commande: #{{ $dispute->order_id }}</span>
                    <span>Client: {{ $dispute->user->name ?? '-' }}</span>
                </div>
            </div>

            <div class="bg-white dark:bg-gray-800 rounded-lg shadow p-6">
                <h2 class="text-lg font-semibold mb-4">Conversation</h2>
                <div class="space-y-4 max-h-80 overflow-y-auto mb-4">
                    @forelse($dispute->messages as $msg)
                    <div class="p-3 rounded-lg {{ $msg->user_id === auth()->id() ? 'bg-green-50 dark:bg-green-900/20 ml-8' : ($msg->is_admin ? 'bg-blue-50 dark:bg-blue-900/20' : 'bg-gray-50 dark:bg-gray-700 mr-8') }}">
                        <div class="flex justify-between text-xs mb-1">
                            <span class="font-medium">{{ $msg->is_admin ? 'Admin' : ($msg->user_id === auth()->id() ? 'Vous' : 'Client') }}</span>
                            <span class="text-gray-500">{{ $msg->created_at->format('d/m H:i') }}</span>
                        </div>
                        <p class="text-sm">{{ $msg->message }}</p>
                    </div>
                    @empty
                    <p class="text-center text-gray-500">Aucun message</p>
                    @endforelse
                </div>

                @if($dispute->status !== 'closed' && $dispute->status !== 'resolved')
                <form action="{{ route('seller.disputes.message', $dispute) }}" method="POST">
                    @csrf
                    <textarea name="message" class="w-full border rounded-lg px-3 py-2 mb-2" rows="2" placeholder="Votre reponse..." required></textarea>
                    <button type="submit" class="bg-blue-600 text-white px-4 py-2 rounded-lg">Envoyer</button>
                </form>
                @endif
            </div>
        </div>

        <div class="bg-white dark:bg-gray-800 rounded-lg shadow p-6 h-fit">
            <h2 class="text-lg font-semibold mb-4">Informations</h2>
            <div class="space-y-3 text-sm">
                <div class="flex justify-between">
                    <span class="text-gray-500">Statut:</span>
                    <span class="font-medium capitalize">{{ $dispute->status }}</span>
                </div>
                <div class="flex justify-between">
                    <span class="text-gray-500">Priorite:</span>
                    <span class="capitalize">{{ $dispute->priority }}</span>
                </div>
                <div class="flex justify-between">
                    <span class="text-gray-500">Cree le:</span>
                    <span>{{ $dispute->created_at->format('d/m/Y') }}</span>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
