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