<x-filament-panels::page>
    <form wire:submit="preview">
        {{ $this->form }}

        <div class="mt-4 flex gap-3">
            <x-filament::button type="submit">
                Previzualizare
            </x-filament::button>
        </div>
    </form>

    @if($preview && count($preview) > 0)
        <div class="mt-6">
            <h3 class="text-lg font-semibold mb-3">Previzualizare — {{ count($preview) }} elevi găsiți</h3>

            <div class="overflow-x-auto rounded-lg border border-gray-200 dark:border-gray-700">
                <table class="w-full text-sm">
                    <thead class="bg-gray-50 dark:bg-gray-800">
                        <tr>
                            <th class="px-4 py-2 text-left font-medium">#</th>
                            <th class="px-4 py-2 text-left font-medium">Nume</th>
                            <th class="px-4 py-2 text-left font-medium">Prenume</th>
                            <th class="px-4 py-2 text-left font-medium">CNP</th>
                            <th class="px-4 py-2 text-left font-medium">Data nașterii</th>
                            <th class="px-4 py-2 text-left font-medium">Email părinte</th>
                            <th class="px-4 py-2 text-left font-medium">Telefon părinte</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-200 dark:divide-gray-700">
                        @foreach($preview as $index => $row)
                            <tr class="{{ empty($row['nume'] ?? '') || empty($row['prenume'] ?? '') ? 'bg-red-50 dark:bg-red-900/20' : '' }}">
                                <td class="px-4 py-2">{{ $index + 1 }}</td>
                                <td class="px-4 py-2 font-medium">{{ $row['nume'] ?? '—' }}</td>
                                <td class="px-4 py-2">{{ $row['prenume'] ?? '—' }}</td>
                                <td class="px-4 py-2">{{ $row['cnp'] ?? '—' }}</td>
                                <td class="px-4 py-2">{{ $row['data_nasterii'] ?? '—' }}</td>
                                <td class="px-4 py-2">{{ $row['email_parinte'] ?? '—' }}</td>
                                <td class="px-4 py-2">{{ $row['telefon_parinte'] ?? '—' }}</td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>

            <div class="mt-4">
                <x-filament::button wire:click="import" color="success">
                    Importă {{ count($preview) }} elevi
                </x-filament::button>
            </div>
        </div>
    @endif

    @if($imported > 0)
        <div class="mt-4 p-4 bg-green-50 dark:bg-green-900/20 rounded-lg">
            <p class="text-green-700 dark:text-green-400 font-medium">
                ✓ {{ $imported }} elevi importați cu succes
                @if($duplicates > 0), {{ $duplicates }} duplicate sărite @endif
                @if($skipped > 0), {{ $skipped }} rânduri incomplete @endif
            </p>
        </div>
    @endif

    <div class="mt-6 p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg">
        <h4 class="font-semibold text-blue-800 dark:text-blue-300 mb-2">Formate XML acceptate</h4>
        <pre class="text-xs text-blue-700 dark:text-blue-400 overflow-x-auto">&lt;SIIIR_Export&gt;
  &lt;Clasa&gt;
    &lt;Elevi&gt;
      &lt;Elev&gt;
        &lt;Nume&gt;Popescu&lt;/Nume&gt;
        &lt;Prenume&gt;Ion&lt;/Prenume&gt;
        &lt;CNP&gt;5010101123456&lt;/CNP&gt;
        &lt;DataNasterii&gt;2001-01-01&lt;/DataNasterii&gt;
      &lt;/Elev&gt;
    &lt;/Elevi&gt;
  &lt;/Clasa&gt;
&lt;/SIIIR_Export&gt;</pre>
    </div>
</x-filament-panels::page>
