'use client'; import React, { useState } from 'react'; import { motion } from 'framer-motion'; import { Plus, Edit, Trash2, Search, Grid, List, Globe, Github, RefreshCw } from 'lucide-react'; // Editor is now a separate page at /editor interface Project { id: string; title: string; description: string; content?: string; category: string; difficulty?: string; tags?: string[]; featured: boolean; published: boolean; github?: string; live?: string; image?: string; createdAt: string; updatedAt: string; analytics?: { views: number; likes: number; shares: number; }; performance?: { lighthouse: number; }; } interface ProjectManagerProps { projects: Project[]; onProjectsChange: () => void; } export const ProjectManager: React.FC = ({ projects, onProjectsChange }) => { const [viewMode, setViewMode] = useState<'grid' | 'list'>('grid'); const [searchTerm, setSearchTerm] = useState(''); const [selectedCategory, setSelectedCategory] = useState('all'); // Editor is now a separate page - no modal state needed const categories = ['all', 'Web Development', 'Full-Stack', 'Web Application', 'Mobile App', 'Design']; // Filter projects const filteredProjects = projects.filter((project) => { const matchesSearch = project.title.toLowerCase().includes(searchTerm.toLowerCase()) || project.description.toLowerCase().includes(searchTerm.toLowerCase()) || project.tags?.some(tag => tag.toLowerCase().includes(searchTerm.toLowerCase())); const matchesCategory = selectedCategory === 'all' || project.category === selectedCategory; return matchesSearch && matchesCategory; }); const openEditor = (project?: Project) => { // Simple navigation to editor - let the editor handle auth if (project) { window.location.href = `/editor?id=${project.id}`; } else { window.location.href = '/editor'; } }; // closeEditor removed - editor is now separate page // saveProject removed - editor is now separate page const deleteProject = async (projectId: string) => { if (!confirm('Are you sure you want to delete this project?')) return; try { await fetch(`/api/projects/${projectId}`, { method: 'DELETE', headers: { 'x-admin-request': 'true' } }); onProjectsChange(); } catch (error) { console.error('Error deleting project:', error); } }; const getStatusColor = (project: Project) => { if (project.published) { return project.featured ? 'text-purple-400 bg-purple-500/20' : 'text-green-400 bg-green-500/20'; } return 'text-yellow-400 bg-yellow-500/20'; }; const getStatusText = (project: Project) => { if (project.published) { return project.featured ? 'Featured' : 'Published'; } return 'Draft'; }; return (
{/* Header */}

Project Management

{projects.length} projects • {projects.filter(p => p.published).length} published

{/* Filters and View Toggle */}
{/* Search */}
setSearchTerm(e.target.value)} className="w-full pl-10 pr-4 py-3 admin-glass-light border border-white/30 rounded-xl text-white placeholder-white/50 focus:outline-none focus:ring-2 focus:ring-blue-500" />
{/* Category Filter */} {/* View Toggle */}
{/* Projects Grid/List */} {viewMode === 'grid' ? (
{filteredProjects.map((project) => ( {/* Project Header */}

{project.title}

{project.category}

{/* Project Content */}

{project.description}

{/* Tags */} {project.tags && project.tags.length > 0 && (
{project.tags.slice(0, 3).map((tag) => ( {tag} ))} {project.tags.length > 3 && ( +{project.tags.length - 3} )}
)} {/* Status and Links */}
{getStatusText(project)}
{project.github && ( )} {project.live && ( )}
{/* Analytics */}

{project.analytics?.views || 0}

Views

{project.analytics?.likes || 0}

Likes

{project.performance?.lighthouse || 90}

Score

))}
) : (
{filteredProjects.map((project) => (

{project.title}

{project.category}

{getStatusText(project)}
{project.analytics?.views || 0} views {new Date(project.updatedAt).toLocaleDateString()}
))}
)} {/* Editor is now a separate page at /editor */}
); };