import { useEffect, useMemo, useRef, useState } from 'react'; import type { FC } from 'react'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faPhoneArrowDown, faPhoneArrowUp, faPhoneXmark, faPlay, faPause, faMagnifyingGlass, } from '@fortawesome/pro-duotone-svg-icons'; const SearchLg: FC<{ className?: string }> = ({ className }) => ; import { Table, TableCard } from '@/components/application/table/table'; import { Badge } from '@/components/base/badges/badges'; import { Button } from '@/components/base/buttons/button'; import { Input } from '@/components/base/input/input'; import { Select } from '@/components/base/select/select'; import { TopBar } from '@/components/layout/top-bar'; import { ClickToCallButton } from '@/components/call-desk/click-to-call-button'; import { formatShortDate, formatPhone } from '@/lib/format'; import { computeSlaStatus } from '@/lib/scoring'; import { cx } from '@/utils/cx'; import { useData } from '@/providers/data-provider'; import { PaginationCardDefault } from '@/components/application/pagination/pagination'; import type { Call, CallDirection, CallDisposition } from '@/types/entities'; type FilterKey = 'all' | 'inbound' | 'outbound' | 'missed'; const filterItems = [ { id: 'all' as const, label: 'All Calls' }, { id: 'inbound' as const, label: 'Inbound' }, { id: 'outbound' as const, label: 'Outbound' }, { id: 'missed' as const, label: 'Missed' }, ]; const dispositionConfig: Record = { APPOINTMENT_BOOKED: { label: 'Appt Booked', color: 'success' }, FOLLOW_UP_SCHEDULED: { label: 'Follow-up', color: 'brand' }, INFO_PROVIDED: { label: 'Info Provided', color: 'blue-light' }, NO_ANSWER: { label: 'No Answer', color: 'warning' }, WRONG_NUMBER: { label: 'Wrong Number', color: 'gray' }, CALLBACK_REQUESTED: { label: 'Callback', color: 'brand' }, }; const formatDuration = (seconds: number | null): string => { if (seconds === null || seconds === 0) return '\u2014'; if (seconds < 60) return `${seconds}s`; const mins = Math.floor(seconds / 60); const secs = seconds % 60; return secs > 0 ? `${mins}m ${secs}s` : `${mins}m`; }; const formatPhoneDisplay = (call: Call): string => { if (call.callerNumber && call.callerNumber.length > 0) { return formatPhone(call.callerNumber[0]); } return '\u2014'; }; const DirectionIcon: FC<{ direction: CallDirection | null; status: Call['callStatus'] }> = ({ direction, status }) => { if (status === 'MISSED') { return ; } if (direction === 'OUTBOUND') { return ; } return ; }; const getCallSla = (call: Call): { percent: number; status: 'low' | 'medium' | 'high' | 'critical' } | null => { if (call.sla == null) return null; const percent = Math.round(call.sla); return { percent, status: computeSlaStatus(percent) }; }; const RecordingPlayer: FC<{ url: string }> = ({ url }) => { const audioRef = useRef(null); const [isPlaying, setIsPlaying] = useState(false); const togglePlay = () => { const audio = audioRef.current; if (!audio) return; if (isPlaying) { audio.pause(); setIsPlaying(false); } else { audio.play().catch(() => setIsPlaying(false)); setIsPlaying(true); } }; const handleEnded = () => setIsPlaying(false); return ( <>