// src/features/flyer/BulkImportSummary.tsx
import React from 'react';
import { CheckCircleIcon } from '../../components/icons/CheckCircleIcon';
import { ExclamationTriangleIcon } from '../../components/icons/ExclamationTriangleIcon';
import { InformationCircleIcon } from '../../components/icons/InformationCircleIcon';

interface BulkImportSummaryProps {
  summary: {
    processed: string[];
    skipped: string[];
    errors: { fileName: string; message: string }[];
  };
  onDismiss: () => void;
}

export const BulkImportSummary: React.FC<BulkImportSummaryProps> = ({ summary, onDismiss }) => {
    const hasContent = summary.processed.length > 0 || summary.skipped.length > 0 || summary.errors.length > 0;

  return (
    <div className="p-6 bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 min-h-[400px] flex flex-col">
        <div className="flex justify-between items-start mb-4">
            <div>
                <h2 className="text-xl font-bold text-gray-800 dark:text-white">Bulk Import Report</h2>
                <p className="text-sm text-gray-500 dark:text-gray-400">
                    {`Processed: ${summary.processed.length}, Skipped: ${summary.skipped.length}, Errors: ${summary.errors.length}`}
                </p>
            </div>
            <button
                onClick={onDismiss}
                className="text-sm bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 rounded-md px-3 py-1"
                aria-label="Dismiss summary"
            >
                Close
            </button>
        </div>

        {hasContent ? (
            <div className="space-y-4 grow overflow-y-auto">
                 {summary.processed.length > 0 && (
                    <div>
                        <h4 className="text-md font-semibold flex items-center mb-2 text-green-700 dark:text-green-400">
                            <CheckCircleIcon className="w-5 h-5 mr-2" />
                            Successfully Processed ({summary.processed.length})
                        </h4>
                        <ul className="text-sm list-disc pl-6 space-y-1 bg-gray-50 dark:bg-gray-800/50 p-3 rounded-md">
                            {summary.processed.map((item, index) => <li key={index} className="text-gray-700 dark:text-gray-300">{item}</li>)}
                        </ul>
                    </div>
                 )}
                 {summary.skipped.length > 0 && (
                    <div>
                        <h4 className="text-md font-semibold flex items-center mb-2 text-blue-700 dark:text-blue-400">
                            <InformationCircleIcon className="w-5 h-5 mr-2" />
                            Skipped Duplicates ({summary.skipped.length})
                        </h4>
                        <ul className="text-sm list-disc pl-6 space-y-1 bg-gray-50 dark:bg-gray-800/50 p-3 rounded-md">
                            {summary.skipped.map((item, index) => <li key={index} className="text-gray-700 dark:text-gray-300">{item}</li>)}
                        </ul>
                    </div>
                 )}
                 {summary.errors.length > 0 && (
                     <div>
                        <h4 className="text-md font-semibold flex items-center mb-2 text-red-700 dark:text-red-400">
                            <ExclamationTriangleIcon className="w-5 h-5 mr-2" />
                            Errors ({summary.errors.length})
                        </h4>
                        <ul className="text-sm list-disc pl-6 space-y-2 bg-gray-50 dark:bg-gray-800/50 p-3 rounded-md">
                            {summary.errors.map((err, index) => (
                                <li key={index} className="text-red-800 dark:text-red-300">
                                    <strong>{err.fileName}:</strong> {err.message}
                                </li>
                            ))}
                        </ul>
                    </div>
                 )}
            </div>
        ) : (
            <div className="grow flex flex-col justify-center items-center text-center">
                 <InformationCircleIcon className="w-12 h-12 text-gray-400 mb-4" />
                 <p className="text-gray-600 dark:text-gray-400">No new files were found to process.</p>
            </div>
        )}
    </div>
  );
};