import "./css/_main.css";
import { h, render } from "preact";
import { useCallback, useEffect, useState } from "preact/hooks";
import { api } from "./base/api.jsx";
import { hiddenRoutes } from "./capabilities.jsx";
import { Icon } from "./base/icons.jsx";
import { dashboardPage } from "./dashboard/dashboard.jsx";
import { tasksPage } from "./tasks/tasks.jsx";
import { taskDetailPage } from "./tasks/task-detail.jsx";
import { skillsPage } from "./skills/skills.jsx";
import { workflowsPage } from "./workflows/workflows.jsx";
import { channelsPage } from "./channels/channels.jsx";
import { curatorsPage } from "./curators/curators.jsx";
import { settingsPage } from "./settings/settings.jsx";
import { logsPage } from "./logs/logs.jsx";
import { capturesPage } from "./captures/captures.jsx";
import { mappingsPage } from "./mappings/mappings.jsx";
import { bindingsPage } from "./bindings/bindings.jsx";
import { ChatPage } from "./chat/chat.jsx";
import { matchRoute, navPath } from "./routing.jsx";
/**
* Routes are declared once here. Adding a section means adding a feature
* folder and one entry -- there is no switch statement to hunt for.
*
* `soon: true` sections are deliberately visible before they are built: a
* greyed, labelled entry tells you the capability exists and is coming, which
* is more honest than hiding it and more useful than a 404.
*/
// section names the capability a route needs, as reported by
// GET /api/capabilities. A route with no section is served in every
// composition. The dashboard is rendered by two different processes -- the
// daemon and the extracted UI service -- and a section the serving process
// cannot back would otherwise render as permanently empty rather than as
// absent (archie-core-8cda.5.4).
//
// A route may also carry:
// nav:false -- addressed by URL but not a navigation entry (a detail page
// reached from its section)
// navPath -- the navigation entry this route keeps current; a parameterised
// route is not itself in the nav, so without this the section it
// belongs to would lose its aria-current highlight
// :name -- one captured path segment, e.g. /tasks/:id
const routes = [
{ path: "/", label: "Dashboard", icon: "dashboard", view: dashboardPage },
{ path: "/chat", label: "Chat", icon: "chat", view: ChatPage, section: "chat" },
{ path: "/tasks", label: "Tasks", icon: "tasks", view: tasksPage },
{ path: "/tasks/:id", label: "Task run", view: taskDetailPage, nav: false, navPath: "/tasks" },
{ path: "/logs", label: "Logs", icon: "logs", view: logsPage, section: "logs" },
{ path: "/captures", label: "Event inspector", icon: "captures", view: capturesPage, section: "captures" },
{ path: "/mappings", label: "Field mappings", icon: "mappings", view: mappingsPage, section: "mappings" },
{ path: "/bindings", label: "Playbook bindings", icon: "bindings", view: bindingsPage, section: "bindings" },
{ path: "/skills", label: "Skills", icon: "skills", view: skillsPage, section: "skills" },
{ path: "/workflows", label: "Workflows", icon: "workflows", view: workflowsPage, section: "workflows" },
{ path: "/curators", label: "Curators", icon: "curators", view: curatorsPage, section: "curators" },
{ path: "/channels", label: "Channels", icon: "channels", view: channelsPage, section: "channels" },
{ path: "/settings", label: "Configuration", icon: "settings", view: settingsPage, section: "settings" },
];
const THEME_KEY = "archie.theme";
function currentTheme() {
return localStorage.getItem(THEME_KEY) || "dark";
}
function applyTheme(theme) {
document.documentElement.dataset.theme = theme;
localStorage.setItem(THEME_KEY, theme);
}
// navEntries lists what gets a navigation item: a detail route (nav:false) is
// addressed by URL but reached from its section, so it is not an entry.
function navEntries(hidden) {
return routes.filter((route) => route.nav !== false && !hidden.includes(route.path));
}
function Topbar({ activePath, hidden, onNavigate, chatOpen, onToggleChat, theme, onToggleTheme }) {
const [searchOpen, setSearchOpen] = useState(false);
const closeSearch = () => setSearchOpen(false);
const onSearchKeyDown = (event) => {
if (event.key === "Escape") {
// preventDefault so the window-level handler (chat drawer close) does not
// also fire: dismissing the search should not dismiss the drawer.
event.preventDefault();
closeSearch();
event.target.blur();
return;
}
if (event.key !== "Enter") return;
// Search jumps between sections. It is deliberately not a data search: the
// sections own their own filtering, and a second search that means
// something different in each place is worse than none.
const query = event.target.value.trim().toLowerCase();
const hit = routes.find(
(route) => route.nav !== false && !route.soon && route.label.toLowerCase().startsWith(query),
);
if (hit) {
onNavigate(hit.path);
event.target.value = "";
closeSearch();
}
};
return (