<x-filament-panels::page>
    @if ($this::canViewImportWorkflow())
        {{ $this->form }}

        @if ($precheckRowCount !== null)
            <x-filament::section>
                <x-slot name="heading">
                    {{ __('dberp.data_import.precheck_summary_heading') }}
                </x-slot>

                <dl class="grid gap-3 text-sm sm:grid-cols-2">
                    <div>
                        <dt class="font-medium text-gray-700 dark:text-gray-300">{{ __('dberp.fields.import_type') }}</dt>
                        <dd class="mt-1 text-gray-600 dark:text-gray-400">{{ $precheckImportType }}</dd>
                    </div>
                    <div>
                        <dt class="font-medium text-gray-700 dark:text-gray-300">{{ __('dberp.fields.source_filename') }}</dt>
                        <dd class="mt-1 text-gray-600 dark:text-gray-400">{{ $precheckFilename }}</dd>
                    </div>
                    <div>
                        <dt class="font-medium text-gray-700 dark:text-gray-300">{{ __('dberp.fields.total_rows') }}</dt>
                        <dd class="mt-1 text-gray-600 dark:text-gray-400">{{ $precheckRowCount }}</dd>
                    </div>
                    @if ($precheckValidatedRowCount !== null)
                        <div>
                            <dt class="font-medium text-gray-700 dark:text-gray-300">{{ __('dberp.data_import.validated_rows') }}</dt>
                            <dd class="mt-1 text-gray-600 dark:text-gray-400">{{ $precheckValidatedRowCount }}</dd>
                        </div>
                    @endif
                    @if ($precheckFailedRowCount !== null && $precheckFailedRowCount > 0)
                        <div>
                            <dt class="font-medium text-gray-700 dark:text-gray-300">{{ __('dberp.data_import.failed_rows') }}</dt>
                            <dd class="mt-1 text-danger-600 dark:text-danger-400">{{ $precheckFailedRowCount }}</dd>
                        </div>
                    @endif
                    @if ($precheckBatchStatus !== null)
                        <div>
                            <dt class="font-medium text-gray-700 dark:text-gray-300">{{ __('dberp.fields.batch_status') }}</dt>
                            <dd class="mt-1 text-gray-600 dark:text-gray-400">
                                {{ \App\Business\DataImport\Enums\DataImportBatchStatus::from($precheckBatchStatus)->label() }}
                            </dd>
                        </div>
                    @endif
                </dl>

                @if ($precheckErrorMessages !== [])
                    <div class="mt-4">
                        <p class="text-sm font-medium text-gray-700 dark:text-gray-300">
                            {{ __('dberp.data_import.row_error_heading') }}
                        </p>
                        <ul class="mt-2 list-disc space-y-1 ps-5 text-sm text-danger-600 dark:text-danger-400">
                            @foreach (array_slice($precheckErrorMessages, 0, 20) as $message)
                                <li>{{ $message }}</li>
                            @endforeach
                        </ul>
                    </div>
                @endif

                <p class="mt-4 text-sm text-gray-500 dark:text-gray-400">
                    @if ($this->canExecuteCurrentBatch())
                        {{ __('dberp.data_import.precheck_ready_for_execute_notice') }}
                    @elseif ($precheckBatchId !== null)
                        {{ __('dberp.data_import.precheck_no_write_notice') }}
                    @else
                        {{ __('dberp.data_import.precheck_file_only_notice') }}
                    @endif
                </p>

                @if ($precheckBatchId !== null && $this::canViewBatchHistory())
                    <p class="mt-2 text-sm text-gray-500 dark:text-gray-400">
                        {{ __('dberp.data_import.precheck_batch_history_hint') }}
                    </p>
                @endif
            </x-filament::section>
        @endif

        <x-filament::section collapsible collapsed>
            <x-slot name="heading">
                {{ __('dberp.data_import.skeleton.supported_types_heading') }}
            </x-slot>

            <ul class="list-disc space-y-1 ps-5 text-sm text-gray-700 dark:text-gray-300">
                @foreach ($this->firstStageImportTypes() as $type)
                    <li>{{ $type['label'] }}</li>
                @endforeach
            </ul>

            <div class="mt-4">
                <p class="text-sm font-medium text-gray-700 dark:text-gray-300">
                    {{ __('dberp.data_import.skeleton.recommended_order_heading') }}
                </p>
                <p class="mt-1 text-sm text-gray-600 dark:text-gray-400">
                    {{ __('dberp.data_import.skeleton.recommended_order_body') }}
                </p>
            </div>
        </x-filament::section>
    @endif

    @if ($this::canViewBatchHistory())
        <x-filament::section>
            <x-slot name="heading">
                {{ __('dberp.data_import.skeleton.batch_history_heading') }}
            </x-slot>

            <p class="mb-4 text-sm text-gray-600 dark:text-gray-400">
                {{ __('dberp.data_import.skeleton.batch_history_description') }}
            </p>

            {{ $this->table }}
        </x-filament::section>
    @endif
</x-filament-panels::page>
