import { appBasePath } from "@agent-native/core/client/api-path"; import { useT } from "@agent-native/core/client/i18n"; import { IconArrowLeft, IconCheck, IconCopy, IconExternalLink, } from "@tabler/icons-react"; import { useEffect, useMemo, useState } from "react"; import { Link, useLocation } from "react-router"; import { Button } from "@/components/ui/button"; import enMessages from "@/i18n/en-US"; export function meta() { return [{ title: enMessages.bugReportRoute.donePageTitle }]; } function absoluteAppUrl(path: string) { if (typeof window === "undefined") return path; return new URL(`${appBasePath()}${path}`, window.location.origin).toString(); } function targetOrigin(returnUrl: string | null) { if (!returnUrl) return "*"; try { return new URL(returnUrl).origin; } catch { return "*"; } } export default function BugReportDoneRoute() { const t = useT(); const location = useLocation(); const [copied, setCopied] = useState(false); const params = useMemo( () => new URLSearchParams(location.search), [location.search], ); const recordingId = params.get("recordingId")?.trim() || null; const returnUrl = params.get("returnUrl")?.trim() || null; const recordingUrl = recordingId ? absoluteAppUrl(`/r/${encodeURIComponent(recordingId)}`) : null; const embedUrl = recordingId ? absoluteAppUrl(`/embed/${encodeURIComponent(recordingId)}`) : null; const agentContextUrl = recordingId ? absoluteAppUrl( `/api/agent-context.json?id=${encodeURIComponent(recordingId)}`, ) : null; useEffect(() => { if (!recordingId || !recordingUrl) return; const message = { type: "agent-native.clips.bug-report.submitted", recordingId, recordingUrl, embedUrl, agentContextUrl, }; const origin = targetOrigin(returnUrl); window.opener?.postMessage(message, origin); if (window.parent && window.parent !== window) { window.parent.postMessage(message, origin); } }, [agentContextUrl, embedUrl, recordingId, recordingUrl, returnUrl]); const copyRecordingUrl = async () => { if (!recordingUrl) return; await navigator.clipboard.writeText(recordingUrl); setCopied(true); window.setTimeout(() => setCopied(false), 1800); }; return (

{recordingId ? t("bugReportRoute.doneTitle") : t("bugReportRoute.missingRecording")}

{t("bugReportRoute.doneDescription")}

{recordingUrl ? (
{returnUrl ? ( ) : null}
) : null}
); }