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 } import { getTemplatesFromConfigs } from '@/config/assistants' // Get all community templates from shared config function getCommunityTemplates(): CommunityTemplate[] { return getTemplatesFromConfigs() } 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 */}
) }