import { useStudio as e } from "../../providers/StudioProvider.js";
import { useBatchDeleteWorkflows as t, useDeleteWorkflow as n, useFilterWorkflows as r } from "../../hooks/useWorkflows.js";
import { useFilterWorkspaces as i } from "../../hooks/useWorkspaces.js";
import { Badge as a } from "../../components/ui/badge.js";
import { Tooltip as o, TooltipContent as s, TooltipProvider as c, TooltipTrigger as l } from "../../components/ui/tooltip.js";
import u from "../../components/lists/ListView.js";
import { useDebounce as d } from "../../hooks/useDebounce.js";
import { useMemo as f, useState as p } from "react";
import { jsx as m, jsxs as h } from "react/jsx-runtime";
//#region src/features/runs/Runs.tsx
var g = {
	completed: "bg-green-50 text-green-900 border-green-200",
	failed: "bg-destructive/10 text-destructive border-destructive/20",
	canceled: "bg-orange-50 text-orange-900 border-orange-200",
	running: "bg-blue-50 text-blue-900 border-blue-200",
	paused: "bg-yellow-50 text-yellow-900 border-yellow-200",
	pending: "bg-muted text-muted-foreground border-border"
}, _ = ({ defaultFilters: _ = {} }) => {
	let { router: v } = e(), [y, b] = p(0), [x, S] = p(10), [C, w] = p("createdAt"), [T, E] = p("DESC"), [D, O] = p(), [k, A] = p(_), j = r(d(D, 500), {
		...k,
		parentId: null
	}, C, T, y, x), M = i(void 0, {}, "title", "ASC", 0, 100), N = n(), P = t(), F = f(() => {
		let e = /* @__PURE__ */ new Map();
		for (let t of M.data?.data ?? []) e.set(t.id, t.title);
		return e;
	}, [M.data]), I = f(() => (M.data?.data ?? []).map((e) => ({
		label: e.title,
		value: e.id
	})), [M.data]), L = f(() => {
		let e = /* @__PURE__ */ new Set();
		for (let t of j.data?.data ?? []) t.alias && e.add(t.alias);
		return Array.from(e).sort();
	}, [j.data]);
	return /* @__PURE__ */ m(u, {
		loading: j.isPending,
		error: j.error ?? null,
		items: j.data?.data ?? [],
		totalItems: j.data?.total ?? 0,
		setPage: b,
		setRowsPerPage: S,
		setOrderBy: w,
		setOrder: E,
		setSearchTerm: O,
		setFilters: A,
		orderBy: C,
		order: T,
		searchTerm: D,
		filters: k,
		page: y,
		rowsPerPage: x,
		deleteItem: (e) => {
			N.mutate(e);
		},
		onClick: (e) => {
			v.navigateToWorkflow(e);
		},
		enableBatchActions: !0,
		batchDelete: (e) => {
			P.mutate(e);
		},
		columns: [
			{
				id: "run",
				label: "Run",
				minWidth: 60,
				format: (e) => {
					let t = e;
					return t == null ? "—" : `#${t}`;
				}
			},
			{
				id: "workspaceId",
				label: "Workspace",
				minWidth: 120,
				format: (e) => {
					let t = e;
					return /* @__PURE__ */ m(a, {
						variant: "outline",
						className: "hover:bg-primary/10 cursor-pointer",
						onClick: (e) => {
							e.stopPropagation(), A((e) => ({
								...e,
								workspaceId: t
							}));
						},
						children: F.get(t) ?? t.slice(0, 8)
					});
				}
			},
			{
				id: "alias",
				label: "Type",
				minWidth: 100,
				format: (e) => {
					let t = e;
					return /* @__PURE__ */ m(a, {
						variant: "outline",
						className: "hover:bg-primary/10 cursor-pointer",
						onClick: (e) => {
							e.stopPropagation(), A((e) => ({
								...e,
								alias: t
							}));
						},
						children: t
					});
				}
			},
			{
				id: "title",
				label: "Title",
				minWidth: 150,
				format: (e) => {
					let t = e;
					return t ? /* @__PURE__ */ m(c, { children: /* @__PURE__ */ h(o, { children: [/* @__PURE__ */ m(l, {
						asChild: !0,
						children: /* @__PURE__ */ m("span", { children: t.length > 40 ? t.slice(0, 40) + "..." : t })
					}), t.length > 40 && /* @__PURE__ */ m(s, { children: /* @__PURE__ */ m("p", { children: t }) })] }) }) : "—";
				}
			},
			{
				id: "status",
				label: "Status",
				minWidth: 100,
				format: (e) => {
					let t = e;
					return /* @__PURE__ */ m(a, {
						className: `rounded-full border px-2 py-1 text-xs whitespace-nowrap ${g[t] || "bg-muted text-muted-foreground border-border"}`,
						children: t
					});
				}
			},
			{
				id: "createdAt",
				label: "Date Created",
				minWidth: 100,
				format: (e) => new Date(e).toLocaleDateString()
			}
		],
		filterConfig: {
			status: [
				"pending",
				"running",
				"paused",
				"completed",
				"failed",
				"canceled"
			],
			workspaceId: I,
			alias: L
		}
	});
};
//#endregion
export { _ as default };
