var q = Object.defineProperty;
var _ = (e, t, s) => t in e ? q(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
var v = (e, t, s) => (_(e, typeof t != "symbol" ? t + "" : t, s), s);
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 s = P("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 h("div", {
      class: `${this.ns.b()}`
    }, [e.length > 0 && e.map((t) => {
      const s = t.sequenceFlowName.startsWith("驳回") || t.sequenceFlowName.startsWith("取消"), o = t.sequenceFlowName.startsWith("保存") || t.sequenceFlowName.startsWith("关闭") || t.sequenceFlowName.startsWith("保存并关闭");
      return h("div", {
        key: t.sequenceFlowId,
        class: [this.ns.e("item"), o ? this.ns.em("item", "plain") : "", s ? this.ns.em("item", "reject") : ""]
      }, [h("i-button", {
        attrs: {
          title: t.sequenceFlowName
        },
        on: {
          click: (i) => this.handleClick(t, i)
        }
      }, [t.sequenceFlowName || ""])]);
    })]);
  }
});
function x(e, t) {
  var i, a;
  const s = [];
  e.source.columnType === "GROUPGRIDCOLUMN" && e.children.forEach((n) => {
    s.push(x(n, t));
  });
  const o = {
    title: e.title,
    width: e.source.widthUnit === "STAR" ? void 0 : e.width,
    minWidth: e.width,
    align: ((i = e.source.align) == null ? void 0 : i.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 ee(e) {
  const t = e.model, s = [], o = t.columns.map((i) => x(i, e));
  return t.children.forEach((i) => {
    const a = o.find((n) => n.key === i.codeName);
    a && s.push(a);
  }), e.singleSelect || s.splice(0, 0, { type: "selection", width: 60 }), s;
}
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 s(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 i(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: s, onDbRowClick: o, onSelectionChange: i, onSortChange: a };
}
function ne(e) {
  function t(i) {
    !i || i === e.curPage || (e.curPage = i, e.load());
  }
  function s(i) {
    !i || i === e.size || (e.size = i, e.curPage === 1 && e.load());
  }
  function o() {
    e.curPage = 1, e.load();
  }
  return { onPageChange: t, onPageSizeChange: s, onPageReset: o };
}
const se = 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(), s = P("grid"), o = K(t, e.modelData, e.context, e.params), [i] = 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((F) => F.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, D = 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 !== D && (G(), D = m);
      }), b.observe(g.value)));
    }), J(() => {
      b && b.disconnect();
    });
    const L = S(() => [{
      hiddenRow: !0
    }, ...o.items]), y = P("grid-field-column"), W = P("collaborative-satisfaction-grid"), k = C([]), j = S(() => {
      const r = [...i.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: F
          }) => {
            const N = I.value[F - 1];
            return h("div", {
              class: [y.b()],
              style: y.cssVarBlock({
                "justify-content": "flex-end"
              })
            }, [h("span", {
              class: y.e("text")
            }, [(N == null ? void 0 : N[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: s,
      columns: i,
      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: W,
      tableColumns: j
    };
  },
  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: i
      }) => {
        const a = this.c.rows[i - 1];
        if (o.hiddenRow)
          return h("span", {
            style: "word-break: break-word;white-space: pre-wrap;"
          }, ["隐藏行的列隐藏行的列隐藏行的列隐藏行的列隐藏行的列隐藏行的列隐藏行的列隐藏行的列隐藏行的列隐藏行的列隐藏行的列隐藏行的列"]);
        if (a)
          return h(this.c.providers[s].component, {
            props: {
              controller: this.c.columns[s],
              row: a
            },
            key: o.srfkey + s
          });
      };
    }), 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 ie {
  constructor() {
    v(this, "component", "IndexView");
  }
}
const re = new Q(import.meta.url);
class ae extends X {
  async execAction(t, s, o, i, a) {
    const n = "/ibzsy/xtmydcphzdc";
    return ibiz.net.request(n, {
      method: "post",
      data: i,
      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 ie()
    ), e.component(
      "CollaborativeSatisfactionGrid",
      se
    ), ibiz.register.control.register(
      "CUSTOM_CollaborativeSatisfactionGrid",
      new ce()
    ), ibiz.register.uiAction.register(
      "DEUIACTION_CollaborativeSatisfactionPort",
      new le()
    );
  }
};
export {
  Ce as default
};
