import React from 'react';

interface ChangelogEntry {
  version: string;
  date: string;
  changes: string[];
}

const CHANGELOG: ChangelogEntry[] = [
  {
    version: '0.0.5',
    date: '2024-05-20',
    changes: [
      'Optimized database queries for project loading',
      'Fixed z-index issues in the navigation bar',
      'Added keyboard shortcuts for quick search',
    ],
  },
  {
    version: '0.0.4',
    date: '2024-05-10',
    changes: [
      'Implemented real-time collaboration via WebSockets',
      'Added support for Markdown in project descriptions',
      'Improved error handling for API timeouts',
    ],
  },
  {
    version: '0.0.3',
    date: '2024-04-25',
    changes: [
      'Integrated TanStack Router for type-safe navigation',
      'Added dark mode support via Tailwind CSS',
      'Refactored shared types in @emberclone/shared',
    ],
  },
  {
    version: '0.0.2',
    date: '2024-04-12',
    changes: [
      'Added Projects module for organizing tasks',
      'Implemented Drizzle ORM schema migrations',
      'Added user authentication flow',
    ],
  },
  {
    version: '0.0.1',
    date: '2024-04-01',
    changes: [
      'Initial release of EmberClone',
      'Basic Fastify backend setup',
      'Core React application structure',
    ],
  },
];

interface ChangelogModalProps {
  open: boolean;
  onClose: () => void;
}

export default function ChangelogModal({ open, onClose }: ChangelogModalProps) {
  if (!open) return null;

  return (
    <div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm">
      <div className="bg-white dark:bg-slate-900 w-full max-w-2xl max-h-[80vh] overflow-hidden rounded-xl shadow-2xl flex flex-col border border-slate-200 dark:border-slate-800">
        <div className="p-6 border-b border-slate-200 dark:border-slate-800 flex justify-between items-center">
          <h2 className="text-2xl font-bold text-slate-900 dark:text-white">Changelog</h2>
          <button 
            onClick={onClose}
            className="p-2 hover:bg-slate-100 dark:hover:bg-slate-800 rounded-full transition-colors text-slate-500"
          >
            <svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
            </svg>
          </button>
        </div>

        <div className="p-6 overflow-y-auto space-y-8">
          {CHANGELOG.map((entry) => (
            <div key={entry.version} className="relative pl-8 border-l-2 border-slate-200 dark:border-slate-700">
              <div className="absolute -left-[9px] top-1 w-4 h-4 rounded-full bg-blue-500 border-2 border-white dark:border-slate-900" />
              
              <div className="flex items-baseline gap-3 mb-2">
                <span className="text-lg font-bold text-slate-900 dark:text-white">v{entry.version}</span>
                <span className="text-sm text-slate-500 dark:text-slate-400">{entry.date}</span>
              </div>
              
              <ul className="space-y-2">
                {entry.changes.map((change, idx) => (
                  <li key={idx} className="text-slate-600 dark:text-slate-300 text-sm flex gap-2">
                    <span className="text-blue-500">•</span>
                    {change}
                  </li>
                ))}
              </ul>
            </div>
          ))}
        </div>

        <div className="p-4 border-t border-slate-200 dark:border-slate-800 flex justify-end">
          <button 
            onClick={onClose}
            className="px-4 py-2 bg-slate-900 dark:bg-white text-white dark:text-slate-900 rounded-lg font-medium hover:opacity-90 transition-opacity"
          >
            Close
          </button>
        </div>
      </div>
    </div>
  );
}