<x-app-layout>
    <x-slot name="header">
        <div class="flex items-center justify-between">
            <div class="flex items-center">
                <a href="{{ route('imports.index') }}" class="text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300 me-4">
                    <i class="fas fa-arrow-left"></i>
                </a>
                <h2 class="text-xl font-bold text-gray-900 dark:text-white">
                    {{ __('Import Details') }}
                </h2>
            </div>
            @if($import->status !== 'completed')
                <form action="{{ route('imports.destroy', $import) }}" method="POST" class="inline">
                    @csrf
                    @method('DELETE')
                    <button type="submit" class="text-red-600 hover:text-red-800">
                        <i class="fas fa-trash me-2"></i>Delete
                    </button>
                </form>
            @endif
        </div>
    </x-slot>

    <div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8">
        <!-- Status Card -->
        <div class="bg-white dark:bg-gray-800 rounded-xl shadow-sm p-6 mb-6">
            <div class="flex items-center justify-between">
                <div class="flex items-center">
                    <div class="w-12 h-12 rounded-lg {{ $import->status === 'completed' ? 'bg-green-100 text-green-600' : ($import->status === 'failed' ? 'bg-red-100 text-red-600' : 'bg-yellow-100 text-yellow-600') }} flex items-center justify-center">
                        <i class="fas fa-{{ $import->status === 'completed' ? 'check' : ($import->status === 'failed' ? 'times' : 'clock') }} text-xl"></i>
                    </div>
                    <div class="ml-4">
                        <p class="font-semibold text-gray-900 dark:text-white">{{ $import->filename }}</p>
                        <p class="text-sm text-gray-500">{{ $import->created_at->format('d M Y, H:i') }}</p>
                    </div>
                </div>
                <x-badge :color="$import->status === 'completed' ? 'green' : ($import->status === 'failed' ? 'red' : 'yellow')" size="lg">
                    {{ ucfirst($import->status) }}
                </x-badge>
            </div>
        </div>

        <!-- Stats -->
        <div class="grid grid-cols-1 sm:grid-cols-4 gap-4 mb-6">
            <x-stat-card
                title="Total Rows"
                :value="$import->total_count ?? 0"
                icon="list"
                color="gray"
            />
            <x-stat-card
                title="Imported"
                :value="$import->processed_count ?? 0"
                icon="check"
                color="green"
            />
            <x-stat-card
                title="Skipped"
                :value="$import->skipped_count ?? 0"
                icon="forward"
                color="yellow"
            />
            <x-stat-card
                title="Errors"
                :value="$import->error_count ?? 0"
                icon="times"
                color="red"
            />
        </div>

        <!-- Error Log -->
        @if($import->errors && count($import->errors) > 0)
            <div class="bg-white dark:bg-gray-800 rounded-xl shadow-sm overflow-hidden">
                <div class="px-6 py-4 border-b border-gray-100 dark:border-gray-700">
                    <h3 class="font-semibold text-gray-900 dark:text-white">Error Log</h3>
                </div>
                <div class="divide-y divide-gray-100 dark:divide-gray-700 max-h-96 overflow-y-auto">
                    @foreach($import->errors as $error)
                        <div class="px-6 py-3 flex items-start">
                            <div class="w-8 h-8 rounded bg-red-100 flex items-center justify-center flex-shrink-0">
                                <span class="text-red-600 text-sm font-medium">{{ $error['row'] ?? '?' }}</span>
                            </div>
                            <p class="ml-3 text-sm text-gray-700 dark:text-gray-300">{{ $error['message'] ?? 'Unknown error' }}</p>
                        </div>
                    @endforeach
                </div>
            </div>
        @endif
    </div>
</x-app-layout>
