import { useState, useEffect } from 'react' import { useNavigate } from 'react-router-dom' import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card' import { Input } from '@/components/ui/input' import { Brain, MessageSquare, Search, TrendingUp, Crown, Bot, Eye, Star, Heart, Users, Award } from 'lucide-react' // Community template interface interface CommunityTemplate { id: string name: string description: string author: string category: string tags: string[] model: string systemPrompt: string temperature: number maxTokens: number isOfficial: boolean createdAt: string icon: string usageCount: number rating: number } // Get all community templates function getCommunityTemplates(): CommunityTemplate[] { return [ { id: 'code-reviewer', name: 'Code Review Expert', description: 'Professional code reviewer for detailed analysis and suggestions. Helps identify bugs, security issues, and performance optimizations.', author: 'EdgeLLM Team', category: 'Developer Tools', tags: ['code review', 'programming', 'debugging'], model: 'Qwen/Qwen3-30B-A3B', systemPrompt: 'You are a senior software engineer. Analyze code for quality, best practices, performance, and security. Provide constructive feedback with specific examples.', temperature: 0.3, maxTokens: 1000, isOfficial: true, createdAt: '2024-01-15', icon: '🔍', usageCount: 1247, rating: 4.8 }, { id: 'writing-tutor', name: 'Writing Assistant', description: 'Helps improve writing with structure suggestions and clarity enhancements. Perfect for essays, articles, and professional documents.', author: 'Community', category: 'Writing', tags: ['writing', 'editing', 'grammar'], model: 'Qwen/Qwen3-30B-A3B', systemPrompt: 'You are a writing tutor. Help improve writing through structure, clarity, grammar, and style suggestions. Provide specific feedback and examples.', temperature: 0.4, maxTokens: 800, isOfficial: false, createdAt: '2024-01-20', icon: '📝', usageCount: 892, rating: 4.6 }, { id: 'creative-writer', name: 'Creative Writing Coach', description: 'Inspires creativity and helps develop compelling stories and characters. Great for fiction writers and storytellers.', author: 'Community', category: 'Writing', tags: ['creative', 'storytelling', 'fiction'], model: 'Qwen/Qwen3-30B-A3B', systemPrompt: 'You are a creative writing coach. Help develop stories, characters, and narrative techniques. Provide encouraging feedback and creative suggestions.', temperature: 0.8, maxTokens: 1000, isOfficial: true, createdAt: '2024-01-30', icon: '✨', usageCount: 634, rating: 4.7 }, { id: 'data-analyst', name: 'Data Analysis Expert', description: 'Helps analyze data patterns, create insights, and generate comprehensive reports with statistical analysis.', author: 'EdgeLLM Team', category: 'Data & Analytics', tags: ['data', 'analytics', 'statistics'], model: 'Qwen/Qwen3-30B-A3B', systemPrompt: 'You are a data analysis expert. Help users understand data patterns, create visualizations, and provide statistical insights.', temperature: 0.2, maxTokens: 1200, isOfficial: true, createdAt: '2024-01-18', icon: '📊', usageCount: 567, rating: 4.9 }, { id: 'language-tutor', name: 'Language Learning Tutor', description: 'Interactive language tutor for vocabulary, grammar, and conversation practice. Supports multiple languages.', author: 'Community', category: 'Education', tags: ['language', 'learning', 'education'], model: 'Qwen/Qwen3-30B-A3B', systemPrompt: 'You are a friendly language tutor. Help users learn languages through interactive exercises, explanations, and conversation practice.', temperature: 0.6, maxTokens: 800, isOfficial: false, createdAt: '2024-01-20', icon: '🌐', usageCount: 423, rating: 4.5 }, { id: 'business-advisor', name: 'Business Strategy Advisor', description: 'Provides strategic business advice, market analysis, and growth recommendations for entrepreneurs and businesses.', author: 'EdgeLLM Team', category: 'Business', tags: ['strategy', 'business', 'consulting'], model: 'Qwen/Qwen3-30B-A3B', systemPrompt: 'You are a business strategy consultant. Provide strategic advice, market insights, and growth recommendations based on business principles.', temperature: 0.4, maxTokens: 1000, isOfficial: true, createdAt: '2024-01-22', icon: '💼', usageCount: 789, rating: 4.7 }, { id: 'research-assistant', name: 'Research Assistant', description: 'Helps with academic and professional research, source analysis, and comprehensive report writing.', author: 'Community', category: 'Research', tags: ['research', 'academic', 'analysis'], model: 'Qwen/Qwen3-30B-A3B', systemPrompt: 'You are a research assistant. Help users conduct thorough research, analyze sources, and organize findings into comprehensive reports.', temperature: 0.3, maxTokens: 1200, isOfficial: false, createdAt: '2024-01-25', icon: '📚', usageCount: 356, rating: 4.4 }, { id: 'math-tutor', name: 'Math & Science Tutor', description: 'Expert tutor for mathematics, physics, chemistry, and other STEM subjects with step-by-step explanations.', author: 'EdgeLLM Team', category: 'Education', tags: ['math', 'science', 'tutoring'], model: 'Qwen/Qwen3-30B-A3B', systemPrompt: 'You are a math and science tutor. Provide clear, step-by-step explanations for mathematical and scientific concepts.', temperature: 0.2, maxTokens: 1000, isOfficial: true, createdAt: '2024-01-28', icon: '🔬', usageCount: 678, rating: 4.8 } ] } export function Templates() { const navigate = useNavigate() const [isOnline, setIsOnline] = useState(false) const [communityTemplates] = useState(getCommunityTemplates()) const [likedTemplates, setLikedTemplates] = useState([]) const [searchQuery, setSearchQuery] = useState('') const [selectedCategory, setSelectedCategory] = useState('All') useEffect(() => { checkSystemStatus() loadLikedTemplates() }, []) const checkSystemStatus = async () => { try { const baseUrl = `${window.location.protocol}//${window.location.host}` const res = await fetch(`${baseUrl}/models`) setIsOnline(res.ok) } catch (error) { setIsOnline(false) } } const loadLikedTemplates = () => { try { const liked = JSON.parse(localStorage.getItem('likedTemplates') || '[]') setLikedTemplates(liked) } catch (error) { console.error('Failed to load liked templates:', error) } } const toggleLikeTemplate = (templateId: string) => { const updatedLiked = likedTemplates.includes(templateId) ? likedTemplates.filter(id => id !== templateId) : [...likedTemplates, templateId] setLikedTemplates(updatedLiked) localStorage.setItem('likedTemplates', JSON.stringify(updatedLiked)) } const useTemplate = (template: CommunityTemplate) => { const assistantConfig = { name: template.name, description: template.description, model: template.model, systemPrompt: template.systemPrompt, temperature: template.temperature, maxTokens: template.maxTokens } localStorage.setItem('loadAssistantConfig', JSON.stringify(assistantConfig)) navigate('/playground') } // Filter templates based on search and category const filteredTemplates = communityTemplates.filter(template => { const matchesSearch = template.name.toLowerCase().includes(searchQuery.toLowerCase()) || template.description.toLowerCase().includes(searchQuery.toLowerCase()) || template.tags.some(tag => tag.toLowerCase().includes(searchQuery.toLowerCase())) const matchesCategory = selectedCategory === 'All' || template.category === selectedCategory return matchesSearch && matchesCategory }) const featuredTemplates = filteredTemplates.filter(t => t.isOfficial) const trendingTemplates = [...filteredTemplates].sort((a, b) => b.usageCount - a.usageCount).slice(0, 6) const categories = ['All', ...Array.from(new Set(communityTemplates.map(t => t.category)))] return (
{/* Header */}

Assistant Templates

{isOnline ? 'Online' : 'Offline'}
{/* Hero Section */}

Explore AI Assistants

Discover, customize and deploy specialized AI assistants. Start with proven templates or build from scratch.

{/* Search Bar */}
setSearchQuery(e.target.value)} className="pl-12 pr-4 py-3 text-lg rounded-full border-2 border-gray-200 focus:border-blue-500" />
{/* Category Filters */}
{categories.map((category) => ( ))}
{/* Featured Section */} {selectedCategory === 'All' && featuredTemplates.length > 0 && (

Featured

Curated by EdgeLLM Team
{featuredTemplates.slice(0, 3).map((template) => ( toggleLikeTemplate(template.id)} onUse={() => useTemplate(template)} featured={true} /> ))}
)} {/* Trending Section */} {selectedCategory === 'All' && (

Trending

Most popular this week
{trendingTemplates.slice(0, 6).map((template) => ( toggleLikeTemplate(template.id)} onUse={() => useTemplate(template)} trending={true} /> ))}
)} {/* All Templates Section */}

{selectedCategory === 'All' ? 'All Templates' : selectedCategory}

{filteredTemplates.length} available
{filteredTemplates.length > 0 ? (
{filteredTemplates.map((template) => ( toggleLikeTemplate(template.id)} onUse={() => useTemplate(template)} /> ))}
) : (

No templates found

Try adjusting your search or category filters

)}
) } // Template Card Component function TemplateCard({ template, isLiked, onLike, onUse, featured = false, trending = false }: { template: CommunityTemplate isLiked: boolean onLike: () => void onUse: () => void featured?: boolean trending?: boolean }) { return ( {featured && (
Featured
)} {trending && (
Trending
)}
{template.icon}
{template.name}

by {template.author}

{template.isOfficial && ( Official )}

{template.description}

{/* Tags */}
{template.tags.slice(0, 3).map((tag) => ( {tag} ))}
{/* Stats */}
{template.usageCount.toLocaleString()}
{template.rating}
{template.category}
{/* Action Button */}
) }