var W = Object.defineProperty;
var q = (e, t, s) => t in e ? W(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
var G = (e, t, s) => (q(e, typeof t != "symbol" ? t + "" : t, s), s);
import { GridModel as B, ModelUtil as $ } from "@ibiz-template/model";
import { defineComponent as x, h as d, ref as C, computed as v, getCurrentInstance as _, watch as T, onUnmounted as V } from "vue";
import { useNamespace as S, useGridController as J } from "@ibiz-template/vue-util";
import { PluginStaticResource as K } from "@ibiz-template/runtime";
const Q = x({
  name: "WFToolbar",
  props: {
    wfLinks: {
      type: Array,
      required: !0
    }
  },
  setup(e, {
    emit: t
  }) {
    const s = S("wf-toolbar"), o = async (a, n) => {
      t("wf-link-click", a, n);
    };
    return {
      ns: s,
      handleClick: async (a, n) => {
        setTimeout(() => {
          o(a, n);
        }, 30);
      }
    };
  },
  render() {
    const e = this.wfLinks || [];
    return d("div", {
      class: `${this.ns.b()}`
    }, [e.length > 0 && e.map((t) => {
      const s = t.sequenceFlowName.startsWith("驳回") || t.sequenceFlowName.startsWith("取消");
      return d("div", {
        key: t.sequenceFlowId,
        class: [this.ns.e("item"), s ? this.ns.em("item", "reject") : ""]
      }, [d("i-button", {
        attrs: {
          title: t.sequenceFlowName
        },
        on: {
          click: (o) => this.handleClick(t, o)
        }
      }, [t.sequenceFlowName || ""])]);
    })]);
  }
});
function z(e, t) {
  var r, a;
  const s = [];
  e.source.columnType === "GROUPGRIDCOLUMN" && e.children.forEach((n) => {
    s.push(z(n, t));
  });
  const o = {
    title: e.title,
    width: e.source.widthUnit === "STAR" ? void 0 : e.width,
    minWidth: e.width,
    align: ((r = e.source.align) == null ? void 0 : r.toLowerCase()) || "center",
    slot: e.codeName,
    key: e.codeName,
    fieldName: e.deFieldName,
    ellipsis: !0,
    tooltip: !1,
    // todo 表格提示用title
    resizable: !0,
    sortable: !t.noSort && e.source.enableSort ? "custom" : !1,
    columnType: e.source.columnType,
    userParams: e.source.userParams,
    className: (a = e.source.getCellPSSysCss()) == null ? void 0 : a.cssName
  };
  return s.length > 0 && Object.assign(o, { children: s }), o;
}
function X(e) {
  const t = e.model, s = [], o = t.columns.map((r) => z(r, e));
  return t.children.forEach((r) => {
    const a = o.find((n) => n.key === r.codeName);
    a && s.push(a);
  }), e.singleSelect || s.splice(0, 0, { type: "selection", width: 60 }), s;
}
function Y(e) {
  const t = C([]);
  return e.nerve.self.evt.on("created", () => {
    t.value = X(e);
  }), [v(() => {
    const o = [...t.value];
    if (!o.find((n) => !n.width)) {
      let n = o.length - 1;
      o[n].key === "rowEdit" && (n -= 1), o[n] = {
        ...o[n],
        width: void 0
      };
    }
    const a = o.find((n) => n.columnType === "UAGRIDCOLUMN");
    if (a) {
      const n = a.userParams;
      n && n.fixed === "true" && (a.fixed = "right");
    }
    return o;
  }), t];
}
function Z(e) {
  const t = (n) => e.items.find((u) => u.srfkey === n.srfkey);
  function s(n) {
    const u = t(n);
    if (e.singleSelect) {
      const h = e.selectedData.find(
        (g) => g.srfkey === n.srfkey
      );
      e.onSelectionChange(h ? [] : [u]);
    }
    e.onRowClick(u);
  }
  function o(n) {
    e.onDbRowClick(t(n));
  }
  function r(n) {
    if (!e.singleSelect) {
      const u = [];
      n.forEach((h) => {
        const g = t(h);
        g && u.push(g);
      }), e.onSelectionChange(u);
    }
  }
  function a(n) {
    const { column: u, order: h } = n, g = h === "asc" || h === "desc" ? h : void 0;
    e.setSort(u.fieldName, g), e.load();
  }
  return { onRowClick: s, onDbRowClick: o, onSelectionChange: r, onSortChange: a };
}
function ee(e) {
  function t(r) {
    !r || r === e.curPage || (e.curPage = r, e.load());
  }
  function s(r) {
    !r || r === e.size || (e.size = r, e.curPage === 1 && e.load());
  }
  function o() {
    e.curPage = 1, e.load();
  }
  return { onPageChange: t, onPageSizeChange: s, onPageReset: o };
}
const te = x({
  props: {
    modelData: B,
    context: {
      type: Object,
      required: !0
    },
    params: {
      type: Object,
      default: () => ({})
    },
    /**
     * 表格行数据默认激活模式
     * - 0 不激活
     * - 1 单击激活
     * - 2 双击激活(默认值)
     *
     * @type {(number | 0 | 1 | 2)}
     */
    gridRowActiveMode: {
      type: Number,
      default: 2
    },
    modal: {
      type: Object
    }
  },
  setup(e) {
    const {
      proxy: t
    } = _(), s = S("grid"), o = J(t, e.modelData, e.context, e.params), [r] = Y(o), {
      onRowClick: a,
      onDbRowClick: n,
      onSelectionChange: u,
      onSortChange: h
    } = Z(o), {
      onPageChange: g,
      onPageReset: O,
      onPageSizeChange: U
    } = ee(o), M = v(() => {
      var l, c;
      const i = (c = (l = e.modelData) == null ? void 0 : l.source.getPSControlParam()) == null ? void 0 : c.ctrlParams;
      return (i == null ? void 0 : i.HIGHLIGHT) !== "false";
    });
    let p = null;
    const H = (i, l) => {
      p != null && window.clearTimeout(p), p = window.setTimeout(() => {
        const c = t.$refs.grid;
        c && (o.selectedData.find((I) => I.srfkey === i.srfkey) && c.clearCurrentRow(), c.toggleSelect && c.toggleSelect(l)), a(i);
      }, 300);
    }, E = (i) => {
      p != null && window.clearTimeout(p);
      const l = t.$refs.grid;
      l && (o.selectedData.find((f) => f.srfkey === i.srfkey) || l.clearCurrentRow()), n(i);
    }, w = C(0), m = C(null), P = C(null);
    let b = null, F = 0;
    const N = () => {
      var i;
      if (m.value && ((i = e.modal) == null ? void 0 : i.mode) !== "EMBED")
        if (o.model.source.enablePagingBar && P.value) {
          const l = P.value.$el, c = l.offsetHeight + parseFloat(window.getComputedStyle(l).paddingTop);
          w.value = m.value.offsetHeight - c;
        } else
          w.value = m.value.offsetHeight;
      o.model.source.height > 0 && (w.value = o.model.source.height);
    };
    T(m, (i, l) => {
      i && i !== l && (N(), window.ResizeObserver && m.value && (b = new ResizeObserver((c) => {
        const f = c[0].contentRect.height;
        f !== F && (N(), F = f);
      }), b.observe(m.value)));
    }), V(() => {
      b && b.disconnect();
    });
    const j = v(() => [{
      hiddenRow: !0
    }, ...o.items]), y = S("grid-field-column"), L = S("collaborative-satisfaction-grid"), k = C([]), A = v(() => {
      const i = [...r.value];
      return i.splice(1, 0, ...k.value), i;
    }), R = C([]);
    return T(() => o.items, () => {
      k.value = [], R.value = [], Array.isArray(o.items) && (k.value = o.items.map((i) => {
        const l = i.bpjbm, c = i.type;
        return {
          title: l,
          width: 120,
          minWidth: 120,
          align: "right",
          key: c,
          ellipsis: !0,
          tooltip: !1,
          resizable: !0,
          render: (f, {
            index: I
          }) => {
            const D = R.value[I - 1];
            return d("div", {
              class: [y.b()],
              style: y.cssVarBlock({
                "justify-content": "flex-end"
              })
            }, [d("span", {
              class: y.e("text")
            }, [(D == null ? void 0 : D[c]) || ""])]);
          }
        };
      }), R.value = o.items.map((i) => {
        try {
          const l = JSON.parse(i.pjdbs || "[]");
          if (Array.isArray(l) && l.length) {
            const c = {};
            return l.forEach((f) => {
              c[f.type] = f.value || "";
            }), c;
          }
        } catch (l) {
          ibiz.log.error(`${i.pjdbs} 解析错误`);
        }
        return {};
      }));
    }), {
      c: o,
      ns: s,
      columns: r,
      tableData: j,
      onDbRowClick: n,
      onUIRowClick: H,
      onUIDbRowClick: E,
      onSelectionChange: u,
      onSortChange: h,
      onPageChange: g,
      onPageSizeChange: U,
      onPageReset: O,
      tableHeight: w,
      gridRef: m,
      girdPaginationRef: P,
      highlight: M,
      ns2: y,
      ns3: L,
      tableColumns: A
    };
  },
  render() {
    if (!this.c.complete)
      return;
    const e = {};
    return this.c.model.columns.forEach((t) => {
      if (t.source.columnType === "GROUPGRIDCOLUMN")
        return;
      const s = t.codeName;
      e[s] = ({
        row: o,
        index: r
      }) => {
        const a = this.c.rows[r - 1];
        if (o.hiddenRow)
          return d("span", {
            style: "word-break: break-word;white-space: pre-wrap;"
          }, ["隐藏行的列隐藏行的列隐藏行的列隐藏行的列隐藏行的列隐藏行的列隐藏行的列隐藏行的列隐藏行的列隐藏行的列隐藏行的列隐藏行的列"]);
        if (a)
          return d(this.c.providers[s].component, {
            props: {
              controller: this.c.columns[s],
              row: a
            },
            key: o.srfkey + s
          });
      };
    }), d("control-layout", {
      attrs: {
        modelData: this.c.model
      }
    }, [d("div", {
      ref: "gridRef",
      class: [this.ns.b(), this.ns.is("show-header", !this.c.model.source.hideHeader), this.ns.is("enable-page", this.c.model.source.enablePagingBar), this.ns3.b()]
    }, [d("i-table", {
      ref: "grid",
      attrs: {
        height: this.tableHeight,
        "show-header": !this.c.model.source.hideHeader,
        "highlight-row": this.c.singleSelect && this.highlight,
        data: this.tableData,
        columns: this.tableColumns,
        "row-class-name": (t) => t.hiddenRow ? "hidden-row" : ""
      },
      class: this.ns.b("content"),
      on: {
        "on-row-click": this.onUIRowClick,
        "on-row-dblclick": this.onUIDbRowClick,
        "on-selection-change": this.onSelectionChange,
        "on-sort-change": this.onSortChange
      },
      scopedSlots: e
    }), this.c.model.source.enablePagingBar && d("app-grid-pagination", {
      ref: "girdPaginationRef",
      attrs: {
        total: this.c.total,
        curPage: this.c.curPage,
        size: this.c.size
      },
      on: {
        change: this.onPageChange,
        "page-size-change": this.onPageSizeChange,
        "page-reset": this.onPageReset
      }
    })])]);
  }
});
class oe {
  constructor() {
    G(this, "component", "IndexView");
  }
}
const ne = new K(import.meta.url);
class se {
  constructor() {
    G(this, "component", "CollaborativeSatisfactionGrid");
  }
}
const ue = {
  mateUrl: import.meta.url,
  install(e) {
    $.getModelService().then((t) => {
      t.app.userParams.autoWidth === "true" && document.getElementsByClassName("app")[0].classList.add("auto-width");
    }), ne.loadStyle(["/style.css"]), e.component("WfToolbar", Q), ibiz.config.enableDataInfoBar = !1, ibiz.config.gridEditShowMode = "all", ibiz.register.view.register(
      "VIEW_CUSTOM_GsIndexCSS",
      new oe()
    ), e.component(
      "CollaborativeSatisfactionGrid",
      te
    ), ibiz.register.control.register(
      "CUSTOM_CollaborativeSatisfactionGrid",
      new se()
    );
  }
};
export {
  ue as default
};
