import React, { useState, useMemo } from 'react'; import * as Dialog from '@radix-ui/react-dialog'; import { useTemplateStore } from '@/stores/template-store'; import { LayoutGrid, MessageSquare, Settings, FileText, Bot, Workflow, X } from 'lucide-react'; import { useDesignStore } from '@/stores/design-store'; import MermaidDiagram from '@/components/ui/mermaid-diagram'; const TemplateSelector = () => { const { getTemplates, showTemplateSelector, setShowTemplateSelector } = useTemplateStore(); const templates = getTemplates(); const { designs, setCurrentDesign, createNewDesign } = useDesignStore(); const [selectedTags, setSelectedTags] = useState([]); // Get all unique tags from templates const allTags = useMemo(() => { const tagSet = new Set(); templates.forEach(template => { template.tags?.forEach(tag => tagSet.add(tag)); }); return Array.from(tagSet).sort(); }, [templates]); // Filter templates based on selected tags const filteredTemplates = useMemo(() => { if (selectedTags.length === 0) return templates; return templates.filter(template => selectedTags.some(selectedTag => template.tags?.includes(selectedTag)) ); }, [templates, selectedTags]); if (!showTemplateSelector) { return null; } const toggleTag = (tag: string) => { setSelectedTags(prev => prev.includes(tag) ? prev.filter(t => t !== tag) : [...prev, tag] ); }; const clearAllTags = () => { setSelectedTags([]); }; const handleSelectTemplate = (template: any) => { const newDesign = { id: Math.random().toString(36).substring(2, 15), name: template.title, description: template.description, type: template.type, data: template.data, createdAt: new Date(), updatedAt: new Date(), lastModified: 'now', } createNewDesign(newDesign); setCurrentDesign(newDesign); setShowTemplateSelector(false); } return (
{/* Header with Blank Design CTA */}
Choose a template Start with architecture pattern templates or create from scratch.
{/* Tag Filters */}

Filter by tags:

{selectedTags.length > 0 && ( )}
{allTags.map((tag) => ( ))}
{selectedTags.length > 0 && (
Showing {filteredTemplates.length} of {templates.length} templates
)}
{/* Templates Grid */}
{filteredTemplates.map((template) => { const getTemplateIcon = () => { if (template.title.includes('Service')) return ; if (template.title.includes('Business Workflow')) return ; if (template.title.includes('Payment')) return ; if (template.title.includes('E-commerce') || template.title.includes('Checkout')) return ; if (template.title.includes('Banking')) return ; if (template.title.includes('Subscription')) return ; return ; }; return (
{/* Diagram Section */}
{template.mermaid ? ( ) : ( No preview )}
{/* Content Section */}

{template.title}

{template.description}

{/* Tags */} {template.tags && template.tags.length > 0 && (
{template.tags.slice(0, 3).map((tag) => ( {tag} ))} {template.tags.length > 3 && ( +{template.tags.length - 3} )}
)} {/* Button at bottom */}
); })}
); }; export default TemplateSelector;