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