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