'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'); 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'; } }; 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-stone-700 bg-stone-200' : 'text-green-700 bg-green-100'; } return 'text-yellow-700 bg-yellow-100'; }; 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 bg-white border border-stone-200 rounded-xl text-stone-900 placeholder:text-stone-400 focus:outline-none focus:ring-2 focus:ring-stone-400" />
{/* 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()}
))}
)}
); };