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