"use client"; import type { HierarchicalContentNode } from '@/types/syllabus'; import { Folder, FileText, ChevronRight, Dot, Sparkles, Loader2 } from 'lucide-react'; import { cn } from '@/lib/utils'; import { Button } from '@/components/ui/button'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog"; import React, { useState } from 'react'; import { explainTopic } from '@/ai/flows/explain-topic-flow'; interface HierarchicalContentDisplayProps { nodes: HierarchicalContentNode[]; level?: number; } const NodeDisplay: React.FC<{ node: HierarchicalContentNode; level: number }> = ({ node, level }) => { const hasChildren = node.children && node.children.length > 0; const [isAlertOpen, setIsAlertOpen] = useState(false); const [alertContent, setAlertContent] = useState(''); const [alertTitle, setAlertTitle] = useState(''); const [isLoadingExplanation, setIsLoadingExplanation] = useState(false); let paddingLeft; switch (level) { case 0: paddingLeft = 'pl-0'; break; case 1: paddingLeft = 'pl-4'; break; case 2: paddingLeft = 'pl-8'; break; case 3: paddingLeft = 'pl-12'; break; case 4: paddingLeft = 'pl-16'; break; default: paddingLeft = 'pl-20'; } const handleExplainClick = async (topic: string) => { setAlertTitle(`Explanation for: ${topic}`); setAlertContent(''); setIsLoadingExplanation(true); setIsAlertOpen(true); try { const result = await explainTopic({ topicText: topic }); setAlertContent(result.explanation); } catch (error) { console.error("Error generating explanation:", error); setAlertContent('Sorry, I could not generate an explanation for this topic at the moment.'); } finally { setIsLoadingExplanation(false); } }; return (
  • {hasChildren ? ( ) : ( )} {node.isCode ? ( {node.text} ) : ( {node.text} )}
    {hasChildren && ( )} {alertTitle} {isLoadingExplanation ? (
    Generating explanation...
    ) : (
    {alertContent}
    )}
    setIsAlertOpen(false)}>Close
  • ); }; export function HierarchicalContentDisplay({ nodes, level = 0 }: HierarchicalContentDisplayProps) { if (!nodes || nodes.length === 0) { return null; } return ( ); }