import 'package:flutter/material.dart';
import '../widgets/dialog_actions.dart';

class ImportResultDialog extends StatelessWidget {
  final String fileName;
  final int processedRows;
  final int createdCount;
  final int invalidRows;
  final List<String> invalidRowIndices;
  final Map<String, String> invalidRowReasons;
  final VoidCallback onClose;

  const ImportResultDialog({
    super.key,
    required this.fileName,
    required this.processedRows,
    required this.createdCount,
    required this.invalidRows,
    required this.invalidRowIndices,
    required this.invalidRowReasons,
    required this.onClose,
  });

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      title: const Text('파일 처리 결과'),
      content: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text('파일명: $fileName'),
          const SizedBox(height: 8),
          Text('처리된 행: $processedRows개'),
          Text('생성된 이벤트: $createdCount개'),
          if (invalidRows > 0) ...[
            const SizedBox(height: 8),
            Text('유효하지 않은 행: $invalidRows개', style: const TextStyle(color: Colors.red)),
            if (invalidRowIndices.isNotEmpty)
              Text(
                '실패 행(최대 10개 미리보기): ${invalidRowIndices.take(10).join(', ')}',
                style: const TextStyle(fontSize: 12, color: Colors.redAccent),
              ),
            if (invalidRowReasons.isNotEmpty) ...[
              const SizedBox(height: 6),
              const Text('실패 사유(일부):', style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600)),
              ...invalidRowReasons.entries.take(5).map(
                (e) => Text('행 ${e.key}: ${e.value}', style: const TextStyle(fontSize: 12, color: Colors.redAccent)),
              ),
              if (invalidRowReasons.length > 5)
                Text('... 외 ${invalidRowReasons.length - 5}건', style: const TextStyle(fontSize: 12, color: Colors.redAccent)),
            ],
          ],
        ],
      ),
      actions: DialogActions.confirm(
        onCancel: onClose,
        onConfirm: onClose,
        confirmText: '닫기',
      ),
    );
  }
}
