import { showContextMenu as e } from "../contextMenu/index.js";
import { injectState as t } from "./keys.js";
import n from "./BaseCellComponent.js";
import { computed as r, createBlock as i, createElementBlock as a, defineComponent as o, normalizeClass as s, openBlock as c, ref as l, resolveDynamicComponent as u, toDisplayString as d } from "vue";
import { tapIf as f } from "@milaboratories/helpers";
var p = ["^data-row-index"], m = {
	key: 0,
	class: "control-cell"
}, h = /* @__PURE__ */ o({
	__name: "TdCell",
	props: { cell: {} },
	setup(o) {
		let h = o, g = t(), _ = r(() => h.cell.column.valueType), v = (e) => {
			f(g.settings.value.onUpdatedRow, (t) => {
				let n = h.cell.row, r = {
					...n.dataRow,
					[h.cell.id]: e
				};
				t({
					...n,
					dataRow: r
				});
			});
		}, y = (e) => {
			e.metaKey && g.selectRow(h.cell.row.primaryKey);
		}, b = (t, n) => {
			if (t.type === "contextmenu") t.preventDefault();
			else return;
			let r = g.settings ?? {}, i = [], { onSelectedRows: a, onSelectedColumns: o } = r.value, s = g.data.selectedRows.has(n.primaryKey);
			a && a.length && (s ? i.push({
				text: "Deselect row",
				cb() {
					g.data.selectedRows.delete(h.cell.row.primaryKey);
				}
			}) : i.push({
				text: "Select row",
				cb() {
					g.selectRow(h.cell.row.primaryKey);
				}
			})), o && o.length && (i.push({
				text: "Select column",
				cb() {
					g.selectColumn(h.cell.column.id);
				}
			}), i.push({
				text: "Unselect column",
				cb() {
					g.unselectColumn(h.cell.column.id);
				}
			})), i.length && e(t, i);
		}, x = l(), S = r(() => h.cell.column.component ? h.cell.column.component() : void 0);
		return (e, t) => (c(), a("div", {
			ref_key: "cellRef",
			ref: x,
			class: s(["td-cell", { [o.cell.class]: !0 }]),
			"^data-row-index": o.cell.row.index,
			onClick: y,
			onContextmenu: t[0] ||= (e) => b(e, o.cell.row)
		}, [o.cell.control ? (c(), a("div", m, d(o.cell.row.index), 1)) : S.value ? (c(), i(u(S.value), {
			key: 1,
			"model-value": o.cell.value,
			"onUpdate:modelValue": v
		}, null, 8, ["model-value"])) : (c(), i(n, {
			key: 2,
			"model-value": o.cell.value,
			"value-type": _.value,
			editable: o.cell.column.editable,
			"onUpdate:modelValue": v
		}, null, 8, [
			"model-value",
			"value-type",
			"editable"
		]))], 42, p));
	}
});
export { h as default };

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