import { type ReactNode, useState } from "react";
import type { Listing } from "@ace/host/protocol";
import { Button, toast, Tooltip, TooltipContent, TooltipTrigger } from "@ace/ui";
import { IconBot, IconMonitor } from "@ace/ui/icons";
import { useDetails } from "./details";
import { host } from "./host";
function AccessToggle({ label, value, live, owner, pending, description, children, onClick }: {
label: string;
value?: boolean;
live?: boolean;
owner: boolean;
pending: boolean;
description: string;
children: ReactNode;
onClick: () => void;
}) {
const state = value === undefined ? "Unknown" : value ? "On" : "Off";
return (
}
/>
{label}: {state}
{description}
{!owner && Only the channel owner can change this.
}
{owner && !live && Waiting for live settings. Older hosts need an Ace update.
}
);
}
export function ChannelAccess({ channel, user }: { channel: Listing; user: string }) {
const { shared, sharedLive, desktop, desktopLive } = useDetails(channel.id);
const [sharing, setSharing] = useState(false);
const [changingDesktop, setChangingDesktop] = useState(false);
const owner = channel.owner === user;
// Render only watch-confirmed values, never an optimistic permission grant.
function share() {
setSharing(true);
host.channel(channel.id, { op: "share", author: user, shared: !shared }).catch(
(error: Error) =>
toast.error("Could not change agent access", { description: error.message }),
).finally(() => setSharing(false));
}
function computer() {
setChangingDesktop(true);
host.channel(channel.id, { op: "desktop", author: user, enabled: !desktop }).catch(
(error: Error) =>
toast.error("Could not change desktop tools access", { description: error.message }),
).finally(() => setChangingDesktop(false));
}
return (
);
}