import { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { motion, AnimatePresence } from 'framer-motion'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { Label } from '@/components/ui/label'; import { Separator } from '@/components/ui/separator'; import { Check, Clock, Users, Info, Flame, Target, TrendingUp, FolderOpen, ArrowLeft } from 'lucide-react'; import { RequestTemplate } from '@/hooks/useCreateRequestForm'; import { Button } from '@/components/ui/button'; interface TemplateSelectionStepProps { templates: RequestTemplate[]; selectedTemplate: RequestTemplate | null; onSelectTemplate: (template: RequestTemplate) => void; adminTemplates?: RequestTemplate[]; } const getPriorityIcon = (priority: string) => { switch (priority) { case 'high': return ; case 'medium': return ; case 'low': return ; default: return ; } }; export function TemplateSelectionStep({ templates, selectedTemplate, onSelectTemplate, adminTemplates = [] }: TemplateSelectionStepProps) { const [viewMode, setViewMode] = useState<'main' | 'admin'>('main'); const navigate = useNavigate(); const handleTemplateClick = (template: RequestTemplate) => { if (template.id === 'admin-templates-category') { setViewMode('admin'); } else { if (viewMode === 'admin') { // If selecting an actual admin template, redirect to dedicated flow navigate(`/create-admin-request/${template.id}`); } else { // Default behavior for standard templates onSelectTemplate(template); } } }; const displayTemplates = viewMode === 'main' ? [ ...templates, { id: 'admin-templates-category', name: 'Admin Templates', description: 'Browse standardized request workflows created by your organization administrators', category: 'Organization', icon: FolderOpen, estimatedTime: 'Variable', commonApprovers: [], suggestedSLA: 0, priority: 'medium', fields: {} } as any ] : adminTemplates; return ( {/* Header Section */}

{viewMode === 'main' ? 'Choose Your Request Type' : 'Organization Templates'}

{viewMode === 'main' ? 'Start with a pre-built template for faster approvals, or create a custom request tailored to your needs.' : 'Select a pre-configured workflow template defined by your organization.'}

{viewMode === 'admin' && (
)} {/* Template Cards Grid */}
{displayTemplates.length === 0 && viewMode === 'admin' ? (

No admin templates available yet.

) : ( displayTemplates.map((template) => { const isComingSoon = template.id === 'existing-template' && viewMode === 'main'; // Only show coming soon for placeholder const isDisabled = isComingSoon; const isCategoryCard = template.id === 'admin-templates-category'; const isCustomCard = template.id === 'custom'; const isSelected = selectedTemplate?.id === template.id; return ( handleTemplateClick(template) : undefined} data-testid={`template-card-${template.id}-clickable`} >
{isSelected && (
)}
{template.name} {isComingSoon && ( Coming Soon )}
{template.category} {getPriorityIcon(template.priority)}

{template.description}

{!isCategoryCard && ( <>
{template.estimatedTime}
{template.commonApprovers?.length || 0} approvers
)} {isCategoryCard && (

Click to browse templates →

)}
); }) )}
{/* Template Details Card */} {selectedTemplate && ( {selectedTemplate.name} - Template Details

{selectedTemplate.suggestedSLA} hours

{getPriorityIcon(selectedTemplate.priority)} {selectedTemplate.priority}

{selectedTemplate.estimatedTime}

{selectedTemplate.commonApprovers?.length > 0 ? ( selectedTemplate.commonApprovers.map((approver, index) => ( {approver} )) ) : ( No specific approvers defined )}
)}
); }