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