import type { ReactNode } from "react";
import { View } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { SafeAreaScrollView } from "@/components/safe-area-scroll-view";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { Text } from "@/components/ui/text";
import { cn } from "@/lib/utils";
const fixture = {
location: {
authorization: "When In Use",
lastLocation: {
latitude: 37.33182,
longitude: -122.03118,
accuracyMeters: 12.4,
speedMps: 0.4,
},
},
recompute: {
lastReason: "manual",
lastTime: new Date("2024-05-21T09:32:00Z"),
elapsedMs: 482,
fetchFailed: false,
error: null as string | null,
},
winner: {
title: "Glass Now online",
subtitle: "Connected to iPhone",
type: "INFO",
bucket: "RIGHT_NOW",
priority: 0.8,
ttlSec: 86400,
poiType: "CAFE",
startsAt: 1767717000,
id: "demo:welcome",
},
feed: [
{
id: "demo:welcome",
title: "Glass Now online",
subtitle: "Connected to iPhone",
type: "INFO",
bucket: "RIGHT_NOW",
priority: 0.8,
ttlSec: 86400,
},
{
id: "cal:demo:1767717000",
title: "Team Sync",
subtitle: "",
type: "CALENDAR_EVENT",
bucket: "FYI",
priority: 0.7,
ttlSec: 5400,
},
{
id: "demo:next",
title: "Next: Calendar",
subtitle: "Then Weather + POI",
type: "INFO",
bucket: "FYI",
priority: 0.4,
ttlSec: 86400,
},
{
id: "music:now:demo",
title: "Midnight City",
subtitle: "M83 - Hurry Up, We're Dreaming",
type: "NOW_PLAYING",
bucket: "FYI",
priority: 0.35,
ttlSec: 30,
},
],
nowPlaying: {
auth: "Authorized",
title: "Midnight City",
artist: "M83",
album: "Hurry Up, We're Dreaming",
playbackStatus: "playing",
},
weatherDiagnostics: {
provider: "WeatherKit",
last_fetch: "2024-05-21 09:30:14",
alerts: "0",
conditions: "mostly_clear_day",
},
calendarDiagnostics: {
events_upcoming: "3",
next_event: "Team Sync - 10:30",
},
test: {
note: "Test actions are not available in the React Native client.",
},
};
const formatTime = (date: Date | null) => {
if (!date) {
return "--";
}
return date.toLocaleTimeString();
};
const formatSpeed = (speedMps: number) => {
if (speedMps < 0) {
return "--";
}
return `${speedMps.toFixed(1)} m/s`;
};
const formatLatLon = (value: number) => value.toFixed(5);
const formatPriority = (value: number) => value.toFixed(2);
export default function OrchestratorScreen() {
const insets = useSafeAreaInsets();
return (
Orchestrator
Context engine status and diagnostics.
);
}
function ValueRow({ label, value }: { label: ReactNode; value: ReactNode }) {
return (
{typeof label === "string" ? (
{label}
) : (
label
)}
{typeof value === "string" || typeof value === "number" ? (
{value}
) : (
value
)}
);
}
function LocationSection() {
const { authorization, lastLocation } = fixture.location;
return (
Location
{lastLocation ? (
<>
{`${formatLatLon(lastLocation.latitude)}, ${formatLatLon(lastLocation.longitude)}`}
}
/>
>
) : (
No location yet
)}
);
}
function RecomputeSection() {
const { lastReason, lastTime, elapsedMs, fetchFailed, error } =
fixture.recompute;
return (
Recompute
{error ? (
{error}
) : null}
);
}
function WinnerSection() {
const winner = fixture.winner;
return (
Winner
{winner ? (
{winner.title}
{winner.subtitle ?? "No description"}
{winner.type}
{winner.poiType ? (
) : null}
{winner.startsAt ? (
) : null}
{winner.id}
}
/>
) : (
No winner yet
)}
);
}
function FeedSection() {
const feed = fixture.feed;
return (
Feed
{feed.length === 0 ? (
No feed items yet
) : (
{feed.map((item, i) => (
{item.title}
{item.subtitle || "No description"}
{`bucket ${item.bucket} | prio ${formatPriority(item.priority)} | ttl ${item.ttlSec}s`}
{item.type}
))}
)}
);
}
function NowPlayingSection() {
const { auth, title, artist, album, playbackStatus } = fixture.nowPlaying;
const subtitle = [artist, album].filter(Boolean).join(" | ") || "Apple Music";
return (
Now Playing
{title ? (
<>
{title}
{subtitle}
{playbackStatus}
>
) : (
{auth === "Authorized" ? "Nothing playing" : "Not authorized"}
)}
);
}
function DiagnosticsSection({
title,
entries,
}: {
title: string;
entries: Record;
}) {
const keys = Object.keys(entries).sort();
return (
{title}
{keys.map((key) => (
{entries[key]}
}
/>
))}
);
}
function TestSection() {
return (
Test
{fixture.test.note}
);
}