import { useState } from "react"; import { Edit, Info, Loader2, Play, Rocket } from "lucide-react"; import { PersonaAvatar } from "../../../../components/personas/PersonaAvatar"; import { Button } from "../../../../components/ui/button"; import { Card } from "../../../../components/ui/card"; import { cn } from "../../../../lib/utils"; import { UnassignedLabel, isUnassignedLabel } from "../../../../lib/displayValue" export type PracticeReviewQuestion = { id: string; questionText: string; voicePrompt: string; sampleAnswerVoicePrompt: string; tips?: string; }; export type PracticeReviewMetadataItem = { label: string; value: string; }; export type PracticeSequentialReviewProps = { practiceTitle: string; thumbnailUrl?: string | null; thumbnailKind?: "image" | "video" | "vimeo" | "gradient"; persona?: { name: string; avatar: string } | null; metadata?: PracticeReviewMetadataItem[]; parentLink?: string | null; guidanceText: string; questions: PracticeReviewQuestion[]; saving?: boolean; saveError?: string | null; canPublish?: boolean; showMissingParentWarning?: boolean; showUnlinkedBanner?: boolean; onEditContext?: () => void; onEditQuestions?: () => void; onBack: () => void; onSaveDraft: () => void; onPublish: () => void; publishLabel?: string; publishingLabel?: string; sectionTitle?: string; sectionSubtitle?: string; }; function audioFileLabel(url: string, fallback: string): string { const trimmed = url.trim(); if (!trimmed) return fallback; try { const path = new URL(trimmed).pathname.split("/").filter(Boolean).pop(); if (path) return decodeURIComponent(path); } catch { // fall through } const seg = trimmed.split("/").filter(Boolean).pop(); return seg && seg.length < 64 ? seg : fallback; } export function ReviewAudioPlayer({ src, label, className, }: { src: string; label: string; className?: string; }) { const [playing, setPlaying] = useState(false); const fileName = audioFileLabel(src, label); if (!src.trim()) { return (

No audio URL provided

); } return (
{[3, 5, 4, 7, 5, 8, 4, 6, 5, 4, 6, 4].map((h, i) => ( ))}
{fileName}
{src}
); } function formatQuestionIndex(index: number): string { return String(index + 1).padStart(2, "0"); } export function PracticeSequentialReview({ practiceTitle, thumbnailUrl, thumbnailKind = "gradient", persona = null, metadata = [], parentLink = null, guidanceText, questions, saving = false, saveError = null, canPublish = true, showMissingParentWarning = false, showUnlinkedBanner = false, onEditContext, onEditQuestions, onBack, onSaveDraft, onPublish, publishLabel = "Publish Now", publishingLabel = "Publishing…", sectionTitle = "Create Practice Questions", sectionSubtitle = "Define the dialogue flow and interactions for this scenario.", }: PracticeSequentialReviewProps) { const filledQuestions = questions.filter( (q) => q.questionText.trim() || q.voicePrompt.trim() || q.sampleAnswerVoicePrompt.trim(), ); return (
{sectionTitle ? (

{sectionTitle}

{sectionSubtitle ? (

{sectionSubtitle}

) : null}
) : null} {showUnlinkedBanner && parentLink === "Not attached to any course, module, or lesson" ? (

Not attached yet

This practice will be saved without course, module, or lesson links. Attach locations later from the practice editor.

) : null} {showMissingParentWarning && !canPublish ? (

Missing parent for the API

Open Add Practice from a course, module, or lesson so parent IDs are in the URL.

) : null}

Basic Information

{onEditContext ? ( ) : null}
{thumbnailKind === "video" && thumbnailUrl ? (
Tips / Guidance

{isUnassignedLabel(guidanceText) ? : guidanceText}

Questions

{filledQuestions.length}
{filledQuestions.map((question, index) => (
{formatQuestionIndex(index)}

Text prompt

{question.questionText.trim() || }

{question.voicePrompt.trim() ? (

Voice prompt

) : null}
))}

Answers

{filledQuestions.length}
{onEditQuestions ? ( ) : null}
{filledQuestions.map((question, index) => (
{formatQuestionIndex(index)} {question.sampleAnswerVoicePrompt.trim() ? (

Voice prompt

) : (

)}
))}
{saveError ? (

{saveError}

) : null}
); }