import { useState } from 'react' import { FileText, Clock, CheckCircle2, ArrowUpRight, Star, AlertTriangle, Loader2, RefreshCw, Info } from 'lucide-react' import { aiSessionsApi } from '@/api' import { toast } from '@/lib/toast' import type { SessionDocumentation } from '@/types/ai-session' interface SessionDocViewProps { documentation: SessionDocumentation onRate?: (rating: number) => void currentRating?: number | null psaPushStatus?: string | null psaPushError?: string | null memberMappingWarning?: string | null sessionId?: string ticketId?: string | null } export function SessionDocView({ documentation, onRate, currentRating, psaPushStatus, psaPushError, memberMappingWarning, sessionId, ticketId, }: SessionDocViewProps) { const [retrying, setRetrying] = useState(false) const [currentPushStatus, setCurrentPushStatus] = useState(psaPushStatus) const [currentPushError, setCurrentPushError] = useState(psaPushError) const handleRetry = async () => { if (!sessionId) return setRetrying(true) try { const result = await aiSessionsApi.retryPsaPush(sessionId) setCurrentPushStatus(result.psa_push_status) setCurrentPushError(result.psa_push_error) if (result.psa_push_status === 'sent') { toast.success('Documentation pushed to ticket successfully') } } catch { toast.error('Retry failed') } finally { setRetrying(false) } } return (
{/* PSA Push Status */} {currentPushStatus && currentPushStatus !== 'no_psa' && (
{currentPushStatus === 'sent' && ( <> Documentation pushed to ticket {ticketId ? `#${ticketId}` : ''} )} {currentPushStatus === 'pending_retry' && ( <> Documentation queued for push — will sync shortly )} {currentPushStatus === 'failed' && ( <>
Failed to push to ticket{currentPushError ? ` — ${currentPushError}` : ''}
)}
)} {/* Member mapping warning */} {memberMappingWarning && (
Time entry was not created — {memberMappingWarning} Session timing is included in the ticket note.
)} {/* Header */}

Session Documentation

{documentation.problem_summary}

{documentation.problem_domain && ( {documentation.problem_domain} )} {documentation.duration_display && ( {documentation.duration_display} )} {documentation.total_steps} steps
{/* Outcome */} {(documentation.resolution_summary || documentation.escalation_reason) && (
{documentation.resolution_summary ? ( ) : ( )} {documentation.resolution_summary ? 'Resolved' : 'Escalated'}

{documentation.resolution_summary || documentation.escalation_reason}

)} {/* Intake summary */}

Original intake

{documentation.intake_summary}

{/* Diagnostic steps */}

Diagnostic trail

{documentation.diagnostic_steps.map((step) => (
{step.step_number}

{step.description}

{step.engineer_response && (

→ {step.engineer_response}

)} {step.outcome && (

Outcome: {step.outcome}

)}
))}
{/* Follow-up recommendations */} {documentation.follow_up_recommendations.length > 0 && (

Follow-up

)} {/* Rating */} {onRate && (

How helpful was this session?

{[1, 2, 3, 4, 5].map((star) => ( ))}
)}
) }