import { t as e } from "./_plugin-vue_export-helper-B3ysoDQm.js";
import { n as t } from "./sortQueryAdapters-CyYXvnDN.js";
import { n, t as r } from "./wt-icon-btn-BIU9YjS8.js";
import { t as i } from "./useWtTable-D_PxqVHO.js";
import { Fragment as a, computed as o, createBlock as s, createCommentVNode as c, createElementBlock as l, createElementVNode as u, createSlots as d, createTextVNode as f, createVNode as p, defineComponent as m, normalizeClass as h, normalizeStyle as g, onMounted as _, openBlock as v, ref as y, renderList as b, renderSlot as x, resolveComponent as S, toDisplayString as C, toRef as w, unref as T, withCtx as E, withModifiers as D } from "vue";
//#region src/components/wt-tree-table-row/wt-tree-table-row.vue?vue&type=script&setup=true&lang.ts
var O = { class: "wt-tree-table-td__content" }, k = {
	key: 0,
	class: "wt-tree-table-td__icon-wrapper"
}, A = {
	key: 0,
	class: "wt-tree-table-td__actions typo-body-1"
}, j = { class: "wt-tree-table-td__content" }, M = /*#__PURE__*/ e(/* @__PURE__ */ m({
	__name: "wt-tree-table-row",
	props: {
		data: {},
		rowPosition: {},
		childrenProp: {},
		selectable: {
			type: Boolean,
			default: !1
		},
		selectedElements: {},
		dataHeaders: {},
		gridActions: {
			type: Boolean,
			default: !0
		},
		nestingLevel: { default: 0 },
		searchedProp: { default: "searched" }
	},
	emits: ["update:selected", "expanded-collapse"],
	setup(e, { emit: t }) {
		let i = e, p = t, m = y(!0), g = o(() => i.nestingLevel), w = o(() => i.nestingLevel + 1), T = o(() => i.selectedElements.includes(i.data)), D = () => {
			m.value = !1, p("expanded-collapse");
		}, M = (e, t = 0) => {
			if (e[i.searchedProp] && t) return !0;
			if (Array.isArray(e[i.childrenProp])) {
				for (let n of e[i.childrenProp]) if (M(n, t + 1)) return !0;
			}
			return !1;
		};
		return _(() => {
			i.searchedProp && M(i.data) && D();
		}), (t, i) => {
			let o = S("wt-tree-table-row", !0);
			return v(), l(a, null, [u("tr", { class: h([[{ "wt-tree-table-row--alternate": e.rowPosition % 2 }], "wt-tree-table-row"]) }, [(v(!0), l(a, null, b(e.dataHeaders, (o, d) => (v(), l("td", {
				key: d,
				class: "wt-tree-table-td typo-body-1"
			}, [u("div", O, [d ? c("", !0) : (v(), l("div", k, [
				(v(!0), l(a, null, b(g.value, (e) => (v(), l("div", {
					key: e,
					class: "wt-tree-table-row__tree-space"
				}))), 128)),
				e.selectable ? (v(), s(n, {
					key: 0,
					selected: T.value,
					"onUpdate:selected": i[0] ||= (n) => t.$emit("update:selected", {
						data: e.data,
						select: n
					})
				}, null, 8, ["selected"])) : c("", !0),
				e.data[e.childrenProp] ? (v(), s(r, {
					key: 1,
					icon: m.value ? "tree-expand" : "tree-collapse",
					onClick: i[1] ||= (e) => m.value = !m.value
				}, null, 8, ["icon"])) : c("", !0)
			])), x(t.$slots, o.value, {
				index: e.rowPosition,
				item: e.data
			}, () => [f(C(e.data[o.value]), 1)], !0)])]))), 128)), e.gridActions ? (v(), l("td", A, [u("div", j, [x(t.$slots, "actions", {
				index: e.rowPosition,
				item: e.data
			}, void 0, !0)])])) : c("", !0)], 2), m.value ? c("", !0) : (v(!0), l(a, { key: 0 }, b(e.data[e.childrenProp], (n, r) => (v(), s(o, {
				key: r,
				"children-prop": e.childrenProp,
				data: n,
				"data-headers": e.dataHeaders,
				"nesting-level": w.value,
				"row-position": e.rowPosition,
				"searched-prop": e.searchedProp,
				selectable: e.selectable,
				"selected-elements": e.selectedElements,
				onExpandedCollapse: D,
				"onUpdate:selected": i[2] ||= (e) => t.$emit("update:selected", {
					data: e.data,
					select: e.select
				})
			}, d({
				actions: E(({ item: n }) => [x(t.$slots, "actions", {
					index: e.rowPosition,
					item: n
				}, void 0, !0)]),
				_: 2
			}, [b(e.dataHeaders, (n, r) => ({
				name: n.value,
				fn: E(({ item: r }) => [x(t.$slots, n.value, {
					index: e.rowPosition,
					item: r
				}, () => [u("div", null, C(r[n.value]), 1)], !0)])
			}))]), 1032, [
				"children-prop",
				"data",
				"data-headers",
				"nesting-level",
				"row-position",
				"searched-prop",
				"selectable",
				"selected-elements"
			]))), 128))], 64);
		};
	}
}), [["__scopeId", "data-v-8381ad70"]]), N = { class: "wt-tree-table wt-scrollbar" }, P = { class: "wt-tree-table-wrapper" }, F = { class: "wt-tree-table-head" }, I = { class: "wt-tree-table-tr wt-tree-table-tr-head" }, L = ["onClick"], R = { class: "wt-tree-table-th__text" }, z = {
	key: 0,
	class: "wt-tree-table-th__actions"
}, B = { class: "wt-tree-table-th__content" }, V = { class: "wt-tree-table-body" }, H = /*#__PURE__*/ e(/* @__PURE__ */ m({
	__name: "wt-tree-table",
	props: {
		headers: {},
		data: {},
		sortable: {
			type: Boolean,
			default: !1
		},
		selectable: {
			type: Boolean,
			default: !0
		},
		selected: {},
		gridActions: {
			type: Boolean,
			default: !0
		},
		childrenProp: {},
		searchedProp: { default: "searched" }
	},
	emits: ["sort", "update:selected"],
	setup(e, { emit: r }) {
		let m = e, _ = r, y = (e) => e[m.childrenProp] && Array.isArray(e[m.childrenProp]), O = (e) => {
			let t = [], n = (e) => {
				if (e._isSelected) return [e];
				y(e) && e[m.childrenProp].forEach(n);
			};
			return e.forEach(n), t;
		}, k = (e) => {
			let t = [], n = (e) => {
				t.push(e), y(e) && e[m.childrenProp].forEach(n);
			};
			return e.forEach(n), t;
		}, A = o(() => m.selected || O(m.data)), j = o(() => A.value.length === k(m.data).length && k(m.data).length > 0), { tableHeaders: H } = i({ headers: w(m, "headers") }), U = ({ sort: e }) => m.sortable && e !== void 0, W = (e) => {
			if (!U(e)) return;
			let n = t(e.sort);
			_("sort", e, n);
		}, G = (e, t) => {
			e.forEach((e) => {
				e._isSelected = t, y(e) && G(e[m.childrenProp], t);
			});
		}, K = () => {
			m.selected ? _("update:selected", j.value ? [] : [...k(m.data)]) : j.value ? G(m.data, !1) : G(m.data, !0);
		}, q = (e, t) => {
			m.selected ? t ? _("update:selected", [...A.value, e]) : _("update:selected", A.value.filter((t) => t !== e)) : e._isSelected = !e._isSelected;
		};
		return (t, r) => {
			let i = S("wt-icon");
			return v(), l("div", N, [u("table", P, [u("thead", F, [u("tr", I, [(v(!0), l(a, null, b(T(H), (t, a) => (v(), l("th", {
				key: String(a) + t?.sort,
				class: h([[{ "wt-tree-table-th--sortable": U(t) }, `wt-tree-table-th--sort-${t.sort}`], "wt-tree-table-th typo-body-1"]),
				style: g(t.width ? `min-width:${t.width}` : ""),
				onClick: (e) => W(t, a)
			}, [u("div", { class: h(["wt-tree-table-th__content", { "wt-tree-table-th__content--selectable": a === 0 && e.selectable }]) }, [
				a === 0 && e.selectable ? (v(), l("div", {
					key: 0,
					onClick: r[0] ||= D(() => {}, ["stop"])
				}, [p(n, {
					selected: j.value,
					"onUpdate:selected": K
				}, null, 8, ["selected"])])) : c("", !0),
				u("div", R, C(t.text), 1),
				e.sortable ? (v(), s(i, {
					key: 1,
					class: "wt-tree-table-th-sort-arrow wt-tree-table-th-sort-arrow--asc",
					icon: "sort-arrow-up",
					size: "sm"
				})) : c("", !0),
				e.sortable ? (v(), s(i, {
					key: 2,
					class: "wt-tree-table-th-sort-arrow wt-tree-table-th-sort-arrow--desc",
					icon: "sort-arrow-down",
					size: "sm"
				})) : c("", !0)
			], 2)], 14, L))), 128)), e.gridActions ? (v(), l("th", z, [u("div", B, [x(t.$slots, "actions-header", {}, void 0, !0)])])) : c("", !0)])]), u("tbody", V, [(v(!0), l(a, null, b(e.data, (n, i) => (v(), s(M, {
				key: i,
				"row-position": i,
				"data-headers": T(H),
				data: n,
				selectable: e.selectable,
				"children-prop": e.childrenProp,
				"selected-elements": A.value,
				"searched-prop": e.searchedProp,
				"onUpdate:selected": r[1] ||= (e) => q(e.data, e.select)
			}, d({
				actions: E(({ item: e }) => [x(t.$slots, "actions", { item: e }, void 0, !0)]),
				_: 2
			}, [b(T(H), (e, n) => ({
				name: e.value,
				fn: E(({ item: n }) => [x(t.$slots, e.value, {
					index: i,
					item: n
				}, () => [f(C(n[e.value]), 1)], !0)])
			}))]), 1032, [
				"row-position",
				"data-headers",
				"data",
				"selectable",
				"children-prop",
				"selected-elements",
				"searched-prop"
			]))), 128))])])]);
		};
	}
}), [["__scopeId", "data-v-69c5594f"]]);
//#endregion
export { H as default };
