import { useStudio as e } from "../../providers/StudioProvider.js";
import { useWorkspaceConfig as t } from "../../hooks/useConfig.js";
import { useBatchDeleteWorkspaces as n, useDeleteWorkspace as r, useFilterWorkspaces as i, useSetFavouriteWorkspace as a } from "../../hooks/useWorkspaces.js";
import { useComponentOverrides as o } from "../../providers/ComponentOverridesProvider.js";
import { Badge as s } from "../../components/ui/badge.js";
import { Dialog as c, DialogContent as l } from "../../components/ui/dialog.js";
import { Tooltip as u, TooltipContent as d, TooltipProvider as f, TooltipTrigger as p } from "../../components/ui/tooltip.js";
import m from "../../components/lists/ListView.js";
import { useDebounce as h } from "../../hooks/useDebounce.js";
import g from "./components/CreateWorkspace.js";
import { useEffect as _, useState as v } from "react";
import { Fragment as y, jsx as b, jsxs as x } from "react/jsx-runtime";
import { useSearchParams as S } from "react-router-dom";
import { Star as C } from "lucide-react";
//#region src/features/workspaces/Workspaces.tsx
var w = () => {
	let { CreateWorkspace: w, EditWorkspace: T } = o(), ee = w ?? g, E = T ?? g, { router: D } = e(), [O] = S(), [k, A] = v(0), [j, M] = v(10), [N, P] = v("createdAt"), [F, I] = v("ASC"), [L, R] = v(), [z, B] = v({}), V = h(L, 500), [H, U] = v(!1), [W, G] = v(void 0);
	_(() => {
		O.get("create") === "true" && U(!0);
	}, [O]);
	let K = t(), q = i(V, z, N, F, k, j), J = r(), Y = n(), X = a(), Z = (e) => {
		J.mutate(e);
	}, Q = (e) => {
		Y.mutate(e);
	}, te = () => {
		U(!0);
	}, ne = () => {
		U(!1);
	}, re = (e) => {
		D.navigateToWorkspace(e);
	}, ie = (e) => {
		G(e);
	}, $ = () => {
		U(!1), G(void 0);
	};
	return /* @__PURE__ */ x(y, { children: [
		/* @__PURE__ */ b(m, {
			loading: K.isPending || q.isPending,
			error: q.error ?? K.error ?? null,
			items: q.data?.data ?? [],
			totalItems: q.data?.total ?? 0,
			setPage: A,
			setRowsPerPage: M,
			setOrderBy: P,
			setOrder: I,
			setSearchTerm: R,
			setFilters: B,
			orderBy: N,
			order: F,
			searchTerm: L,
			filters: z,
			page: k,
			rowsPerPage: j,
			deleteItem: Z,
			onClick: re,
			handleNew: te,
			handleEdit: ie,
			enableBatchActions: !0,
			batchDelete: Q,
			columns: [
				{
					id: "id",
					label: "ID",
					minWidth: 30,
					format: (e) => e.slice(0, 6)
				},
				{
					id: "title",
					label: "Title",
					minWidth: 100,
					format: (e) => /* @__PURE__ */ b(f, { children: /* @__PURE__ */ x(u, { children: [/* @__PURE__ */ b(p, {
						asChild: !0,
						children: /* @__PURE__ */ b(s, {
							variant: "outline",
							className: "hover:bg-primary/10 cursor-pointer",
							onClick: () => B((t) => ({
								...t,
								className: e
							})),
							children: e.length > 25 ? e.slice(0, 25) + "..." : e
						})
					}), /* @__PURE__ */ b(d, { children: /* @__PURE__ */ b("p", { children: e }) })] }) })
				},
				{
					id: "environments",
					label: "Environments",
					minWidth: 150,
					format: (e) => {
						let t = e;
						return !t || t.length === 0 ? "—" : /* @__PURE__ */ b("div", {
							className: "flex flex-wrap gap-1",
							children: t.map((e) => /* @__PURE__ */ x(s, {
								variant: "secondary",
								children: [e.envName ?? e.remoteEnvironmentId.slice(0, 8), e.type && /* @__PURE__ */ x("span", {
									className: "text-muted-foreground ml-1",
									children: [
										"(",
										e.type,
										")"
									]
								})]
							}, e.remoteEnvironmentId))
						});
					}
				},
				{
					id: "createdAt",
					label: "Date Created",
					minWidth: 100,
					format: (e) => new Date(e).toLocaleDateString()
				}
			],
			filterConfig: {},
			rowActions: [{
				id: "add-favourite",
				label: "Add to favourites",
				icon: /* @__PURE__ */ b(C, { className: "h-4 w-4" }),
				condition: (e) => !e.isFavourite,
				action: (e) => {
					X.mutate({
						id: e.id,
						isFavourite: !0
					});
				}
			}, {
				id: "remove-favourite",
				label: "Remove from favourites",
				icon: /* @__PURE__ */ b(C, { className: "h-4 w-4 fill-current" }),
				condition: (e) => !!e.isFavourite,
				action: (e) => {
					X.mutate({
						id: e.id,
						isFavourite: !1
					});
				}
			}]
		}),
		/* @__PURE__ */ b(c, {
			open: H,
			onOpenChange: U,
			children: /* @__PURE__ */ b(l, {
				className: "max-w-2xl",
				children: /* @__PURE__ */ b(ee, {
					types: K.data ?? [],
					onSuccess: ne
				})
			})
		}),
		/* @__PURE__ */ b(c, {
			open: !!W,
			onOpenChange: (e) => !e && $(),
			children: /* @__PURE__ */ b(l, {
				className: "max-w-2xl",
				children: W && /* @__PURE__ */ b(E, {
					types: K.data ?? [],
					workspace: W,
					onSuccess: $
				})
			})
		})
	] });
};
//#endregion
export { w as default };
