import React, { useState, useEffect, Fragment } from 'react'; import { fetchAgentJourneyDetail } from '../../service/agent-analytics/agent-analytics.service'; import type { IJourneyDetail } from '../../service/agent-analytics/agent-analytics.interface'; import { formatNumber, formatIntentScore } from './helpers'; import { getSentimentLabel, getSentimentBadgeTone, } from './journeyDetailModal.utils'; interface JourneyDetailModalProps { fingerprint: string | null; onClose: () => void; } const BADGE_TONE_CLASSES: Record = { success: 'bg-green-100 text-green-800', critical: 'bg-red-100 text-red-800', info: 'bg-blue-100 text-blue-800', attention: 'bg-yellow-100 text-yellow-800', }; const JourneyDetailModal = ({ fingerprint, onClose, }: JourneyDetailModalProps): JSX.Element | null => { const [detail, setDetail] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { if (!fingerprint) return; setLoading(true); setError(null); fetchAgentJourneyDetail(fingerprint) .then(d => { setDetail(d); setLoading(false); }) .catch(e => { setError(e.message); setLoading(false); }); }, [fingerprint]); if (!fingerprint) return null; return (
{/* Backdrop */}
{/* Modal */}
{/* Header */}

Conversation Detail

{fingerprint.length > 40 ? fingerprint.slice(0, 40) + '...' : fingerprint}

{loading && (

Loading conversation...

)} {error && (

{error}

)} {detail && !loading && (
{/* Metadata */}

Duration

{formatNumber(detail.duration_minutes, 1)} min

Language

{detail.language || '-'}

Outcome

{detail.outcome || '-'}

Intent Score

{formatIntentScore(detail.purchase_intent_score)}

{/* Summary */} {detail.summary && (

Summary

{detail.summary}

)} {/* Messages Timeline */}

Messages ({(detail.messages || []).length})

{(detail.messages || []).map((m, i) => (
{m.user_message && (

{m.user_message}

)} {m.ai_response && (

{m.ai_response}

{(m.products_shown || []).length > 0 && (
{m.products_shown.map((p, j) => ( {p.image_url && ( {p.name )} {p.name || p.sku || ''} ))}
)} {m.conversation_stage && (

Stage: {m.conversation_stage}

)}
)}
))}
{/* Product Journey */} {(detail.product_journey || []).length > 0 && (

Product Journey

{detail.product_journey.map((pj, i) => (
{pj.image_url && ( {pj.name )} {pj.product_url ? ( {pj.product || pj.name || pj.sku || '-'} ) : ( {pj.product || pj.name || pj.sku || '-'} )}
{pj.recommended && ( Recommended )} {pj.clicked && ( Clicked )} {pj.carted && ( Added to cart )}
))}
)} {/* Stage Progression */} {(detail.stage_progression || []).length > 0 && (

Stage Progression

{detail.stage_progression.map((s, i) => ( {i > 0 && ( {'\u2192'} )} {s} ))}
)} {/* Sentiment Progression */} {(detail.sentiment_progression || []).length > 0 && (

Sentiment Progression

{detail.sentiment_progression.map((s, i) => { const label = getSentimentLabel(s); const tone = getSentimentBadgeTone(label); return ( {i > 0 && ( {'\u2192'} )} {label} ); })}
)} {/* Clicked / Added to Cart Products */} {((detail.clicked_products || []).length > 0 || (detail.carted_products || []).length > 0) && (
{(detail.clicked_products || []).length > 0 && (

Clicked Products

{detail.clicked_products.map((product, index) => ( {product.image_url && ( {product.name )} {product.name || product.sku} ))}
)} {(detail.carted_products || []).length > 0 && (

Added to Cart

{detail.carted_products.map((product, index) => ( {product.image_url && ( {product.name )} {product.name || product.sku} ))}
)}
)} {/* Extra info */}

Clicks

{detail.product_clicks || 0}

Add to Cart

{detail.add_to_cart_count || 0}

Likes

{detail.liked_messages_count || 0}

Dislikes

{detail.disliked_messages_count || 0}

)}
); }; export default JourneyDetailModal;