import e from "./PlElementListItem.js";
import { moveElements as t } from "./utils.js";
import { Fragment as n, computed as r, createBlock as i, createCommentVNode as a, createElementBlock as o, createElementVNode as ee, createSlots as s, defineComponent as c, mergeModels as l, normalizeClass as u, openBlock as d, renderList as f, renderSlot as p, shallowRef as m, unref as h, useModel as te, useSlots as ne, watch as re, withCtx as g } from "vue";
import { isFunction as _, shallowHash as v } from "@milaboratories/helpers";
import { useSortable as ie } from "@vueuse/integrations/useSortable";
//#region src/components/PlElementList/PlElementList.vue?vue&type=script&setup=true&lang.ts
var y = /* @__PURE__ */ c({
	__name: "PlElementList",
	props: /* @__PURE__ */ l({
		getItemKey: {
			type: Function,
			default: (e) => JSON.stringify(e)
		},
		itemClass: {
			type: [
				String,
				Array,
				Function
			],
			default: void 0
		},
		itemClassTitle: {
			type: [
				String,
				Array,
				Function
			],
			default: void 0
		},
		itemClassBefore: {
			type: [
				String,
				Array,
				Function
			],
			default: void 0
		},
		itemClassAfter: {
			type: [
				String,
				Array,
				Function
			],
			default: void 0
		},
		itemClassContent: {
			type: [
				String,
				Array,
				Function
			],
			default: void 0
		},
		isActive: {
			type: Function,
			default: void 0
		},
		disableDragging: {
			type: Boolean,
			default: void 0
		},
		isDraggable: {
			type: Function,
			default: void 0
		},
		onDragEnd: {
			type: Function,
			default: void 0
		},
		onSort: {
			type: Function,
			default: void 0
		},
		disableRemoving: {
			type: Boolean,
			default: void 0
		},
		isRemovable: {
			type: Function,
			default: void 0
		},
		onRemove: {
			type: Function,
			default: void 0
		},
		disableExpanding: {
			type: Boolean,
			default: void 0
		},
		isExpandable: {
			type: Function,
			default: void 0
		},
		isExpanded: {
			type: Function,
			default: void 0
		},
		onExpand: {
			type: Function,
			default: void 0
		},
		disableToggling: {
			type: Boolean,
			default: void 0
		},
		isToggable: {
			type: Function,
			default: void 0
		},
		isToggled: {
			type: Function,
			default: void 0
		},
		onToggle: {
			type: Function,
			default: void 0
		},
		disablePinning: {
			type: Boolean,
			default: void 0
		},
		isPinnable: {
			type: Function,
			default: void 0
		},
		isPinned: {
			type: Function,
			default: void 0
		},
		onPin: {
			type: Function,
			default: void 0
		}
	}, {
		items: { required: !0 },
		itemsModifiers: {}
	}),
	emits: /* @__PURE__ */ l(["itemClick"], ["update:items"]),
	setup(c, { emit: l }) {
		let y = te(c, "items"), b = c, x = l, S = ne(), C = r(() => b.disableDragging !== !0), w = r(() => y.value.map((e, t) => [t, e]).filter(([e, t]) => V(t, e))), ae = r(() => w.value.length > 0), T = r(() => y.value.map((e, t) => [t, e]).filter(([e, t]) => !V(t, e))), E = r(() => T.value.length > 0), D = m(), O = m(), k = m(), A = (e) => `${oe.value}-${b.getItemKey(e[1], e[0])}`, j = r(() => w.value.map(A)), M = r(() => T.value.map(A)), oe = r((e) => {
			let t = y.value.map(b.getItemKey);
			if (D.value === void 0) return e ?? v(...t);
			if (t.length !== D.value.length) return v(...t);
			let n = D.value.map(b.getItemKey), r = new Set(n);
			for (let e = 0; e < t.length; e++) if (r.has(t[e]) && n[e] !== t[e]) return v(...t);
			return e ?? v(...t);
		});
		N(ae, O, w, () => 0), N(E, k, T, () => w.value.length);
		function N(e, t, n, r) {
			let i = ie(t, n, {
				handle: "[data-draggable=\"true\"]",
				animation: 150,
				forceFallback: !0,
				fallbackOnBody: !0,
				scrollSensitivity: 80,
				forceAutoScrollFallback: !0,
				onUpdate: (e) => {
					if (e.oldIndex == null || e.newIndex == null) throw Error("Sortable event has no index");
					b.onDragEnd?.(e.oldIndex, e.newIndex) !== !1 && P(r() + e.oldIndex, r() + e.newIndex, !0);
				}
			});
			return re([
				t,
				() => b.disableDragging,
				e
			], ([e, t, n]) => {
				!e || t || !n ? i.stop() : i.start();
			}, { immediate: !0 }), i;
		}
		function P(e, n, r) {
			e !== n && (r && (D.value = t(y.value.slice(), e, n)), b.onSort?.(e, n) !== !1 && (y.value = t(y.value, e, n)));
		}
		function F(e, t) {
			return b.isActive?.(e, t) ?? !1;
		}
		function I(e, t) {
			return b.disableDragging === !0 ? !1 : b.isDraggable?.(e, t) ?? !0;
		}
		function L(e, t) {
			return b.disableRemoving === !0 ? !1 : b.isRemovable?.(e, t) ?? !0;
		}
		function R(e, t) {
			return b.disableToggling === !0 ? !1 : b.isToggable?.(e, t) ?? (_(b.isToggled) || _(b.onToggle));
		}
		function z(e, t) {
			return b.isToggled?.(e, t) ?? !1;
		}
		function B(e, t) {
			return b.disablePinning === !0 ? !1 : b.isPinnable?.(e, t) ?? (_(b.isPinned) || _(b.onPin));
		}
		function V(e, t) {
			return b.isPinned?.(e, t) ?? !1;
		}
		function H(e, t) {
			return b.disableExpanding === !0 ? !1 : b.isExpandable?.(e, t) ?? (_(b.isExpanded) || _(b.onExpand));
		}
		function U(e, t) {
			return b.isExpanded?.(e, t) ?? !1;
		}
		function W(e, t) {
			b.onExpand?.(e, t);
		}
		function G(e, t) {
			b.onToggle?.(e, t);
		}
		function K(e, t) {
			if (t === -1) throw Error("Pinnable item not found");
			let n = w.value.findIndex(([e]) => e === t) !== -1;
			b.onPin?.(e, t) !== !1 && P(t, w.value.length + (n ? 0 : -1), !1);
		}
		function q(e, t) {
			b.onRemove?.(e, t) !== !1 && (y.value = [...y.value.slice(0, t), ...y.value.slice(t + 1)]);
		}
		function J(e) {
			return (t, n) => typeof e == "function" ? e(t, n) : e ?? null;
		}
		let Y = J(b.itemClass), X = J(b.itemClassTitle), Z = J(b.itemClassContent), Q = J(b.itemClassBefore), $ = J(b.itemClassAfter);
		return (t, r) => (d(), o("div", { class: u(t.$style.root) }, [ee("div", {
			ref_key: "pinnedContainerRef",
			ref: O,
			class: u(t.$style.list)
		}, [(d(!0), o(n, null, f(w.value, ([n, r], a) => (d(), i(e, {
			key: j.value[a],
			class: u([t.$style.item, h(Y)(r, n)]),
			titleClass: h(X)(r, n),
			contentClass: h(Z)(r, n),
			beforeClass: h(Q)(r, n),
			afterClass: h($)(r, n),
			index: n,
			item: r,
			showDragHandle: C.value,
			isActive: F(r, n),
			isDraggable: I(r, n),
			isRemovable: L(r, n),
			isToggable: R(r, n),
			isToggled: z(r, n),
			isPinnable: B(r, n),
			isPinned: !0,
			isExpandable: H(r, n),
			isExpanded: U(r, n),
			onClick: (e) => x("itemClick", r),
			onRemove: q,
			onToggle: G,
			onPin: K,
			onExpand: W
		}, s({
			title: g(({ item: e, index: n }) => [p(t.$slots, "item-title", {
				index: n,
				item: e
			})]),
			_: 2
		}, [
			S["item-before"] ? {
				name: "before",
				fn: g(({ item: e, index: n }) => [p(t.$slots, "item-before", {
					index: n,
					item: e
				})]),
				key: "0"
			} : void 0,
			S["item-content"] ? {
				name: "content",
				fn: g(({ item: e, index: n }) => [p(t.$slots, "item-content", {
					index: n,
					item: e
				})]),
				key: "1"
			} : void 0,
			S["item-after"] ? {
				name: "after",
				fn: g(({ item: e, index: n }) => [p(t.$slots, "item-after", {
					index: n,
					item: e
				})]),
				key: "2"
			} : void 0
		]), 1032, [
			"class",
			"titleClass",
			"contentClass",
			"beforeClass",
			"afterClass",
			"index",
			"item",
			"showDragHandle",
			"isActive",
			"isDraggable",
			"isRemovable",
			"isToggable",
			"isToggled",
			"isPinnable",
			"isExpandable",
			"isExpanded",
			"onClick"
		]))), 128))], 2), E.value ? (d(), o("div", {
			key: 0,
			ref_key: "unpinnedContainerRef",
			ref: k,
			class: u(t.$style.list)
		}, [(d(!0), o(n, null, f(T.value, ([n, r], a) => (d(), i(e, {
			key: M.value[a],
			class: u([t.$style.item, h(Y)(r, n)]),
			titleClass: h(X)(r, n),
			contentClass: h(Z)(r, n),
			beforeClass: h(Q)(r, n),
			afterClass: h($)(r, n),
			index: n,
			item: r,
			showDragHandle: C.value,
			isActive: F(r, n),
			isDraggable: I(r, n),
			isRemovable: L(r, n),
			isToggable: R(r, n),
			isToggled: z(r, n),
			isPinnable: B(r, n),
			isPinned: !1,
			isExpandable: H(r, n),
			isExpanded: U(r, n),
			onClick: (e) => x("itemClick", r),
			onRemove: q,
			onToggle: G,
			onPin: K,
			onExpand: W
		}, s({
			title: g(({ item: e, index: n }) => [p(t.$slots, "item-title", {
				index: n,
				item: e
			})]),
			_: 2
		}, [S["item-content"] ? {
			name: "content",
			fn: g(({ item: e, index: n }) => [p(t.$slots, "item-content", {
				index: n,
				item: e
			})]),
			key: "0"
		} : void 0, S["item-after"] ? {
			name: "after",
			fn: g(({ item: e, index: n }) => [p(t.$slots, "item-after", {
				index: n,
				item: e
			})]),
			key: "1"
		} : void 0]), 1032, [
			"class",
			"titleClass",
			"contentClass",
			"beforeClass",
			"afterClass",
			"index",
			"item",
			"showDragHandle",
			"isActive",
			"isDraggable",
			"isRemovable",
			"isToggable",
			"isToggled",
			"isPinnable",
			"isExpandable",
			"isExpanded",
			"onClick"
		]))), 128))], 2)) : a("", !0)], 2));
	}
});
//#endregion
export { y as default };

//# sourceMappingURL=PlElementList.vue2.js.map