import { useTranslation } from "react-i18next"; import { Card, CardContent, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import ActivityIndicator from "@/components/indicators/activity-indicator"; import { FaExclamationCircle, FaCopy, FaCheck } from "react-icons/fa"; import { useState } from "react"; import { toast } from "sonner"; import type { OnvifProbeResponse, OnvifRtspCandidate, TestResult, CandidateTestMap, } from "@/types/cameraWizard"; type OnvifProbeResultsProps = { isLoading: boolean; isError: boolean; error?: string; probeResult?: OnvifProbeResponse; onSelectCandidate: (uri: string) => void; onRetry: () => void; selectedUris?: string[]; testCandidate?: (uri: string) => void; candidateTests?: CandidateTestMap; testingCandidates?: Record; }; export default function OnvifProbeResults({ isLoading, isError, error, probeResult, onSelectCandidate, onRetry, selectedUris, testCandidate, candidateTests, testingCandidates, }: OnvifProbeResultsProps) { const { t } = useTranslation(["views/settings"]); const [copiedUri, setCopiedUri] = useState(null); const handleCopyUri = (uri: string) => { navigator.clipboard.writeText(uri); setCopiedUri(uri); toast.success(t("cameraWizard.step1.uriCopied")); setTimeout(() => setCopiedUri(null), 2000); }; if (isLoading) { return (

{t("cameraWizard.step1.probingDevice")}

); } if (isError) { return (

{t("cameraWizard.step1.probeError")}

{error &&

{error}

}
); } if (!probeResult?.success) { return (

{t("cameraWizard.step1.probeNoSuccess")}

{probeResult?.message && (

{probeResult.message}

)}
); } const rtspCandidates = probeResult.rtsp_candidates || []; return (
{t("cameraWizard.step1.deviceInfo")} {probeResult.manufacturer && (
Manufacturer:{" "} {probeResult.manufacturer}
)} {probeResult.model && (
Model:{" "} {probeResult.model}
)} {probeResult.firmware_version && (
Firmware:{" "} {probeResult.firmware_version}
)} {probeResult.profiles_count !== undefined && (
Profiles:{" "} {probeResult.profiles_count}
)} {probeResult.ptz_supported !== undefined && (
PTZ Support:{" "} {probeResult.ptz_supported ? "Yes" : "No"}
)} {probeResult.ptz_supported && probeResult.autotrack_supported && (
Autotrack Support:{" "} Yes
)} {probeResult.ptz_supported && probeResult.presets_count !== undefined && (
Presets:{" "} {probeResult.presets_count}
)}
{rtspCandidates.length > 0 && (

{t("cameraWizard.step1.rtspCandidates")}

{rtspCandidates.map((candidate, idx) => { const isSelected = !!selectedUris?.includes(candidate.uri); const candidateTest = candidateTests?.[candidate.uri]; const isTesting = testingCandidates?.[candidate.uri]; return ( handleCopyUri(candidate.uri)} onUse={() => onSelectCandidate(candidate.uri)} isSelected={isSelected} onTest={() => testCandidate && testCandidate(candidate.uri)} candidateTest={candidateTest} isTesting={isTesting} /> ); })}
)}
); } type CandidateItemProps = { candidate: OnvifRtspCandidate; isTested?: boolean; copiedUri: string | null; onCopy: () => void; onUse: () => void; isSelected?: boolean; onTest?: () => void; candidateTest?: TestResult | { success: false; error: string }; isTesting?: boolean; }; function CandidateItem({ candidate, isTested, copiedUri, onCopy, onUse, isSelected, onTest, candidateTest, isTesting, }: CandidateItemProps) { const { t } = useTranslation(["views/settings"]); const [showFull, setShowFull] = useState(false); // Mask credentials for display const maskUri = (uri: string) => { const match = uri.match(/rtsp:\/\/([^:]+):([^@]+)@(.+)/); if (match) { return `rtsp://${match[1]}:••••@${match[3]}`; } return uri; }; return (
{isTested !== undefined && ( {isTested ? "✓ OK" : "✗ Failed"} )}

setShowFull(!showFull)} title="Click to toggle masked/full view" > {showFull ? candidate.uri : maskUri(candidate.uri)}

{candidateTest && candidateTest.success && (
{candidateTest.resolution && ( {`${t("cameraWizard.testResultLabels.resolution")} ${candidateTest.resolution}`} )} {candidateTest.fps && ( {t("cameraWizard.testResultLabels.fps")} {candidateTest.fps} )} {candidateTest.videoCodec && ( {`${t("cameraWizard.testResultLabels.video")} ${candidateTest.videoCodec}`} )} {candidateTest.audioCodec && ( {`${t("cameraWizard.testResultLabels.audio")} ${candidateTest.audioCodec}`} )}
)}
); }