import { Button } from "../ui/button.js";
import { Card, CardContent } from "../ui/card.js";
import { Checkbox } from "../ui/checkbox.js";
import ConfirmDialog_default from "./ConfirmDialog.js";
import DataTableBatchAction_default from "./DataTableBatchAction.js";
import DataTableFilters_default from "./DataTableFilters.js";
import DataTablePagination_default from "./DataTablePagination.js";
import DataTableToolbar_default from "./DataTableToolbar.js";
import { c } from "react/compiler-runtime";
import { useState } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
import { Loader2, Trash2 } from "lucide-react";
function DataList(he) {
	let r = c(89), { data: i, totalItems: a, loading: ge, error: o, page: _e, pageSize: ve, onPageChange: ye, onPageSizeChange: be, searchTerm: xe, onSearchChange: s, filters: l, filterConfig: u, onFiltersChange: d, onRowClick: f, onNew: p, enableBatchActions: Se, batchActions: m, onBatchDelete: h, rowActions: Ce, itemRenderer: we, newButtonLabel: Te } = he, Ee = ge === void 0 ? !1 : ge, g;
	r[0] === l ? g = r[1] : (g = l === void 0 ? {} : l, r[0] = l, r[1] = g);
	let _ = g, v;
	r[2] === u ? v = r[3] : (v = u === void 0 ? {} : u, r[2] = u, r[3] = v);
	let y = v, b = Se === void 0 ? !0 : Se, x;
	r[4] === m ? x = r[5] : (x = m === void 0 ? [] : m, r[4] = m, r[5] = x);
	let De = x, Oe = Ce === void 0 ? [] : Ce, S;
	r[6] === Symbol.for("react.memo_cache_sentinel") ? (S = [], r[6] = S) : S = r[6];
	let [C, w] = useState(S), [T, ke] = useState(!1), E;
	r[7] === Symbol.for("react.memo_cache_sentinel") ? (E = {
		isOpen: !1,
		type: "single"
	}, r[7] = E) : E = r[7];
	let [D, O] = useState(E), k;
	r[8] !== i || r[9] !== C.length ? (k = () => {
		C.length === i.length ? w([]) : w(i.map(_temp));
	}, r[8] = i, r[9] = C.length, r[10] = k) : k = r[10];
	let Ae = k, A;
	r[11] === Symbol.for("react.memo_cache_sentinel") ? (A = (e) => {
		w((t) => t.includes(e) ? t.filter((t) => t !== e) : [...t, e]);
	}, r[11] = A) : A = r[11];
	let je = A, j;
	r[12] === Symbol.for("react.memo_cache_sentinel") ? (j = () => w([]), r[12] = j) : j = r[12];
	let Me = j, M;
	r[13] === O ? M = r[14] : (M = () => {
		O({
			isOpen: !0,
			type: "batch"
		});
	}, r[13] = O, r[14] = M);
	let N = M, P;
	r[15] !== D.itemId || r[16] !== D.type || r[17] !== h || r[18] !== C || r[19] !== O ? (P = async () => {
		D.type === "single" && D.itemId || D.type === "batch" && (await h?.(C), Me()), O({
			isOpen: !1,
			type: "single"
		});
	}, r[15] = D.itemId, r[16] = D.type, r[17] = h, r[18] = C, r[19] = O, r[20] = P) : P = r[20];
	let F = P, I;
	r[21] !== N || r[22] !== h ? (I = h ? [{
		id: "delete",
		label: "Delete Selected",
		icon: /* @__PURE__ */ jsx(Trash2, { className: "mr-2 h-4 w-4" }),
		variant: "destructive",
		action: N
	}] : [], r[21] = N, r[22] = h, r[23] = I) : I = r[23];
	let L;
	r[24] !== De || r[25] !== I ? (L = [...I, ...De], r[24] = De, r[25] = I, r[26] = L) : L = r[26];
	let R = L, z;
	r[27] !== N || r[28] !== C ? (z = (e) => {
		e.id === "delete" ? N() : (e.action(C), Me());
	}, r[27] = N, r[28] = C, r[29] = z) : z = r[29];
	let Ne = z, B;
	r[30] === _ ? B = r[31] : (B = Object.values(_).filter(Boolean), r[30] = _, r[31] = B);
	let Pe = B.length, Fe = [...[], ...Oe], Ie = Fe.length > 0, V;
	r[32] === T ? V = r[33] : (V = () => ke(!T), r[32] = T, r[33] = V);
	let Le = !!d && Object.keys(y).length > 0, Re = !!s, ze = C.length === i.length && i.length > 0, H;
	r[34] !== ze || r[35] !== Ae ? (H = /* @__PURE__ */ jsxs("div", {
		className: "text-sm text-gray-400",
		children: [/* @__PURE__ */ jsx(Checkbox, {
			checked: ze,
			onCheckedChange: Ae,
			"aria-label": "Select all rows",
			className: "mr-4"
		}), "Select All"]
	}), r[34] = ze, r[35] = Ae, r[36] = H) : H = r[36];
	let U;
	r[37] !== R || r[38] !== b || r[39] !== Ne || r[40] !== C.length ? (U = b && /* @__PURE__ */ jsx(DataTableBatchAction_default, {
		selectedCount: C.length,
		batchActions: R,
		onBatchAction: Ne
	}), r[37] = R, r[38] = b, r[39] = Ne, r[40] = C.length, r[41] = U) : U = r[41];
	let W;
	r[42] !== y || r[43] !== _ || r[44] !== T || r[45] !== d ? (W = /* @__PURE__ */ jsx(DataTableFilters_default, {
		filters: _,
		filterConfig: y,
		onFiltersChange: d,
		isOpen: T
	}), r[42] = y, r[43] = _, r[44] = T, r[45] = d, r[46] = W) : W = r[46];
	let G;
	r[47] !== U || r[48] !== W ? (G = /* @__PURE__ */ jsxs("div", { children: [U, W] }), r[47] = U, r[48] = W, r[49] = G) : G = r[49];
	let K;
	r[50] !== Pe || r[51] !== T || r[52] !== Te || r[53] !== p || r[54] !== s || r[55] !== xe || r[56] !== V || r[57] !== Le || r[58] !== Re || r[59] !== H || r[60] !== G ? (K = /* @__PURE__ */ jsxs(DataTableToolbar_default, {
		searchTerm: xe,
		onSearchChange: s,
		onFilterToggle: V,
		onNew: p,
		filterCount: Pe,
		isFilterOpen: T,
		newButtonLabel: Te,
		showFilter: Le,
		showSearch: Re,
		children: [H, G]
	}), r[50] = Pe, r[51] = T, r[52] = Te, r[53] = p, r[54] = s, r[55] = xe, r[56] = V, r[57] = Le, r[58] = Re, r[59] = H, r[60] = G, r[61] = K) : K = r[61];
	let q;
	r[62] === o ? q = r[63] : (q = o && /* @__PURE__ */ jsx(Card, {
		className: "border-destructive/50 bg-destructive/5",
		children: /* @__PURE__ */ jsx(CardContent, {
			className: "p-4",
			children: /* @__PURE__ */ jsxs("p", {
				className: "text-destructive font-medium",
				children: ["Error: ", o.message]
			})
		})
	}), r[62] = o, r[63] = q);
	let Be = Ee ? /* @__PURE__ */ jsx("div", {
		className: "flex items-center justify-center py-8",
		children: /* @__PURE__ */ jsx(Loader2, { className: "h-8 w-8 animate-spin" })
	}) : /* @__PURE__ */ jsx("div", { children: i.length === 0 ? /* @__PURE__ */ jsx("span", { children: "No items found" }) : i.map((n, me) => /* @__PURE__ */ jsxs("div", {
		className: "flex items-center",
		children: [
			b && /* @__PURE__ */ jsx("div", {
				className: "flex items-center justify-center pr-4",
				onClick: _temp2,
				children: /* @__PURE__ */ jsx(Checkbox, {
					checked: C.includes(n.id),
					onCheckedChange: () => je(n.id),
					"aria-label": `Select row ${n.id}`
				})
			}),
			/* @__PURE__ */ jsx(Card, {
				className: "my-2 grow transition-shadow hover:shadow-md",
				children: /* @__PURE__ */ jsx(CardContent, {
					className: "px-6",
					children: /* @__PURE__ */ jsx("div", {
						className: "flex items-center justify-between",
						children: /* @__PURE__ */ jsx("div", {
							className: `flex-1 ${f ? "cursor-pointer" : ""} ${C.includes(n.id) ? "bg-muted/50" : ""}`,
							onClick: f ? () => f(n) : void 0,
							children: /* @__PURE__ */ jsx("div", { children: we && we(n) })
						})
					})
				})
			}, n.id),
			Ie && /* @__PURE__ */ jsx("div", {
				className: "flex items-center justify-center",
				onClick: _temp3,
				children: /* @__PURE__ */ jsx("div", {
					className: "flex items-center justify-center gap-1",
					children: Fe.map((t) => !t.condition || t.condition(n) ? /* @__PURE__ */ jsx(Button, {
						variant: t.variant || "ghost",
						size: "sm",
						onClick: () => void t.action(n),
						disabled: t.disabled?.(n),
						title: t.label,
						className: t.className,
						children: t.icon
					}, t.id) : null)
				})
			})
		]
	}, `data-list-item-${me}`)) }), J;
	r[64] === Be ? J = r[65] : (J = /* @__PURE__ */ jsx("div", {
		className: "space-y-2",
		children: Be
	}), r[64] = Be, r[65] = J);
	let Y;
	r[66] !== ye || r[67] !== be || r[68] !== _e || r[69] !== ve || r[70] !== a ? (Y = /* @__PURE__ */ jsx(DataTablePagination_default, {
		page: _e,
		pageSize: ve,
		totalItems: a,
		onPageChange: ye,
		onPageSizeChange: be
	}), r[66] = ye, r[67] = be, r[68] = _e, r[69] = ve, r[70] = a, r[71] = Y) : Y = r[71];
	let X;
	r[72] !== D || r[73] !== O ? (X = (e) => O({
		...D,
		isOpen: e
	}), r[72] = D, r[73] = O, r[74] = X) : X = r[74];
	let Ve = D.type === "single" ? "Delete Item" : "Delete Items", He = D.type === "single" ? "Are you sure you want to delete this item? This action cannot be undone." : `Are you sure you want to delete ${C.length} items? This action cannot be undone.`, Z;
	r[75] === F ? Z = r[76] : (Z = () => void F(), r[75] = F, r[76] = Z);
	let Q;
	r[77] !== D.isOpen || r[78] !== X || r[79] !== Ve || r[80] !== He || r[81] !== Z ? (Q = /* @__PURE__ */ jsx(ConfirmDialog_default, {
		isOpen: D.isOpen,
		onOpenChange: X,
		title: Ve,
		description: He,
		onConfirm: Z,
		confirmText: "Delete",
		cancelText: "Cancel",
		variant: "destructive"
	}), r[77] = D.isOpen, r[78] = X, r[79] = Ve, r[80] = He, r[81] = Z, r[82] = Q) : Q = r[82];
	let $;
	return r[83] !== K || r[84] !== q || r[85] !== J || r[86] !== Y || r[87] !== Q ? ($ = /* @__PURE__ */ jsxs("div", {
		className: "space-y-4",
		children: [
			K,
			q,
			J,
			Y,
			Q
		]
	}), r[83] = K, r[84] = q, r[85] = J, r[86] = Y, r[87] = Q, r[88] = $) : $ = r[88], $;
}
function _temp3(e) {
	return e.stopPropagation();
}
function _temp2(e) {
	return e.stopPropagation();
}
function _temp(e) {
	return e.id;
}
export { DataList };
