import { useStudio as e } from "../providers/StudioProvider.js";
import { useWorkspaceConfig as t } from "../hooks/useConfig.js";
import { useWorkspace as n } from "../hooks/useWorkspaces.js";
import { Button as r } from "../components/ui/button.js";
import i from "../components/layout/MainLayout.js";
import a from "../components/feedback/ErrorSnackbar.js";
import o from "../features/workspaces/components/WorkspaceHomePage.js";
import { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime";
import { Link as u, useParams as d } from "react-router-dom";
import { ArrowRight as f, Home as p, Loader2 as m } from "lucide-react";
//#region src/pages/WorkspacePage.tsx
var h = () => {
	let { router: h } = e(), { workspaceId: g } = d(), _ = n(g), v = t(), y = _.data, b = (() => {
		if (!y || !v.data) return;
		let e = v.data.find((e) => e.className === y.className)?.ui;
		return (e?.widgets ?? e?.actions)?.find((e) => e.widget === "start-form");
	})(), x = [
		{
			label: "Dashboard",
			href: h.getDashboard(),
			icon: /* @__PURE__ */ c(p, { className: "h-4 w-4" })
		},
		{
			label: "Workspaces",
			href: h.getWorkspaces()
		},
		{
			label: y?.title ?? "",
			current: !0
		}
	], S = _.isLoading || v.isLoading;
	return /* @__PURE__ */ c(i, {
		breadcrumbsData: x,
		children: /* @__PURE__ */ l(s, { children: [
			/* @__PURE__ */ l("div", {
				className: "mb-4 flex items-center justify-between",
				children: [/* @__PURE__ */ c("h1", {
					className: "text-3xl font-bold tracking-tight",
					children: y?.title ?? ""
				}), g && /* @__PURE__ */ c(r, {
					variant: "outline",
					size: "sm",
					asChild: !0,
					children: /* @__PURE__ */ l(u, {
						to: h.getWorkspaceRuns(g),
						children: ["Runs", /* @__PURE__ */ c(f, { className: "ml-1 h-4 w-4" })]
					})
				})]
			}),
			S ? /* @__PURE__ */ c(m, { className: "h-6 w-6 animate-spin" }) : "",
			/* @__PURE__ */ c(a, { error: _.error }),
			/* @__PURE__ */ c(a, { error: v.error }),
			y && b ? /* @__PURE__ */ c(o, {
				workspace: y,
				action: b
			}) : y && !S ? /* @__PURE__ */ l("div", {
				className: "flex flex-col items-center justify-center py-16",
				children: [/* @__PURE__ */ c("p", {
					className: "text-muted-foreground mb-4",
					children: "No home page configured for this workspace."
				}), g && /* @__PURE__ */ c(r, {
					variant: "default",
					asChild: !0,
					children: /* @__PURE__ */ l(u, {
						to: h.getWorkspaceRuns(g),
						children: ["Go to Runs", /* @__PURE__ */ c(f, { className: "ml-1 h-4 w-4" })]
					})
				})]
			}) : null
		] })
	});
};
//#endregion
export { h as default };
