'use client' import { AlertCircleIcon, CheckIcon, ScissorsIcon } from 'lucide-react' import { useEffect, useMemo, useRef, useState } from 'react' import type { SpeechCutSaveResponse, SpeechCutStatusResponse, SpeechCutSuggestionResponse, } from '@/app/(campaign)/campanha/(app)/comunicacao/acervo/cortar/types' import { Alert, AlertDescription } from '@/components/ui/Alert' import { Button } from '@/components/ui/button' import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from '@/components/ui/dialog' import { Field, FieldLabel } from '@/components/ui/field' import { Input } from '@/components/ui/input' import { Spinner } from '@/components/ui/Spinner' import { Textarea } from '@/components/ui/textarea' import { postCampaignJson } from '@/lib/campaignJsonRequest' import { SPEECH_CUT_GENERIC_ERROR_MESSAGE, type SpeechCutRequest } from '@/lib/schemas/speechCut' import { formatSpeechClock, formatSpeechSpan } from '@/lib/speechClock' import { buildSpeechCutFallbackMetadata, SPEECH_CUT_DESCRIPTION_MAX_LENGTH, SPEECH_CUT_TITLE_MAX_LENGTH, speechCutStepStates, type SpeechCutStep, type SpeechCutViewModel, } from '@/lib/speechCut' import { MIN_EXCERPT_SECONDS, type ExcerptRange } from '@/lib/speechExcerptSelection' import { cn } from '@/lib/utils' const SAVE_ENDPOINT = '/campanha/comunicacao/acervo/cortar' const STATUS_ENDPOINT = `${SAVE_ENDPOINT}/status` const SUGGESTION_ENDPOINT = `${SAVE_ENDPOINT}/sugestao` const POLL_INTERVAL_MS = 1500 type CutPhase = 'form' | 'running' | 'failed' type SpeechCutDialogProps = { open: boolean onOpenChange: (open: boolean) => void speechId: number speechType: string | null dateLabel: string summary: string | null range: ExcerptRange onPublished: (cut: SpeechCutViewModel) => void } const StepMark = ({ state }: { state: 'done' | 'current' | 'queued' }) => state === 'done' ? (