import { useActionQuery } from "@agent-native/core/client/hooks"; import { cn } from "../lib/utils"; import { ActionQueryError } from "./action-query-error"; import { Badge } from "./ui/badge"; import { Skeleton } from "./ui/skeleton"; export function appAvailabilityLabel(value?: string) { switch (value) { case "all-apps": return "Inherited by all apps"; case "selected-granted": return "Granted to this app"; case "selected-not-granted": return "Not granted"; case "selected-no-app": return "Select app"; case "path-not-managed": return "Not managed"; default: return "Checking"; } } export function appLayerState(layer: any): { label: string; className: string; } { if (layer.effective) { return { label: "Wins", className: "border-green-500/30 bg-green-500/10 text-green-700", }; } if (layer.overridden) { return { label: "Overridden", className: "border-amber-500/30 bg-amber-500/10 text-amber-700", }; } return { label: "Missing", className: "text-muted-foreground", }; } export function formatResourceTimestamp(value?: number | null): string { if (!value) return "not present"; return new Date(value).toLocaleString(); } export function AppResourceEffectiveStack({ appId, resource, }: { appId: string; resource: any; }) { const query = useActionQuery( "get-workspace-resource-effective-context", { resourceId: resource.id, appId }, { enabled: !!resource.id }, ); const { data: context, isLoading } = query; const layers = ((context as any)?.layers ?? []) as any[]; const active = (context as any)?.effectiveResource; const availability = (context as any)?.availability; if (isLoading && !context) { return (