var N = Object.defineProperty;
var _ = (e, n, s) => n in e ? N(e, n, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[n] = s;
var y = (e, n, s) => (_(e, typeof n != "symbol" ? n + "" : n, s), s);
import { PluginStaticResource as $, AppFuncCommand as j } from "@ibiz-template/runtime";
import { ListPortletController as D, AppMenuPortletController as E } from "@ibiz-template/controller";
import { ListPortletModel as F, AppMenuPortletModel as B, DefectModelError as G } from "@ibiz-template/model";
import { useNamespace as T, useListController as R } from "@ibiz-template/vue-util";
import { defineComponent as L, ref as h, getCurrentInstance as k, onMounted as C, h as t, watch as J, onUnmounted as H } from "vue";
import { Tooltip as P, Button as x, Icon as A } from "view-design";
import { CounterService as K } from "@ibiz-template/service";
const v = new $(import.meta.url);
const Q = L({
  name: "AppPortalListPortlet",
  props: {
    modelData: {
      type: F,
      required: !0
    },
    controller: {
      type: D,
      required: !0
    }
  },
  setup(e) {
    const n = T("app-portal-list-portlet"), s = h([]), p = Array.from({
      length: 3
    }).map((c, i) => v.dir(`/assets/img/app-portal-list-${i}.svg`)), l = k();
    if (l && e.modelData.list) {
      const c = R(l.proxy, e.modelData.list, e.controller.context);
      C(() => {
        c.nerve.self.evt.on("mounted", async () => {
          const i = await c.load();
          s.value = i.slice(0, 3);
        });
      });
    }
    return {
      ns: n,
      appPortalList: s,
      appPortalImgList: p,
      openPage: (c) => {
        c && window.open(c);
      }
    };
  },
  render() {
    return t("div", {
      class: this.ns.b()
    }, [this.appPortalList.map((e, n) => t("div", {
      class: [this.ns.b("item"), e.url ? "" : this.ns.bm("item", "disabled")],
      key: e.srfkey,
      on: {
        click: () => this.openPage(e.url)
      }
    }, [t(P, {
      attrs: {
        content: e.tip,
        disabled: !e.tip
      }
    }, [t("div", {
      class: this.ns.be("item", "text")
    }, [e.srfmajortext])]), t("div", {
      class: this.ns.be("item", "icon")
    }, [t("img", {
      attrs: {
        src: this.appPortalImgList[n]
      }
    })])]))]);
  }
});
const O = L({
  name: "FuncDrawer",
  props: {
    isShowDrawer: {
      type: Boolean,
      required: !0,
      default: !1
    }
  },
  emits: {
    "on-close": () => !0
  },
  setup(e, {
    emit: n
  }) {
    var I;
    const s = T("func-drawer"), p = v.dir("/assets/img/placeholder.svg"), l = "\u672A\u5206\u7C7B", g = h([]), c = h([]), i = h(!1), m = (I = k()) == null ? void 0 : I.proxy, b = () => {
      ibiz.net.post("/appfuncs/fetchpersonfuncsetting", {
        page: 0,
        size: 1e3,
        sort: "showorder,asc"
      }).then((a) => {
        if (a.ok && a.data && a.data.length) {
          const r = {};
          c.value = a.data.filter((o) => {
            if (o.ispersonal || (o.ispersonal = 0), !o.pssystemappid)
              r[l] ? r[l].push(o) : r[l] = [o];
            else {
              const u = o.pssystemappname;
              r[u] ? r[u].push(o) : r[u] = [o];
            }
            return o.ispersonal;
          }), g.value = Object.keys(r).map((o) => ({
            name: o,
            items: r[o]
          }));
        }
      });
    }, M = () => {
      i.value && (c.value.forEach((a, r) => {
        a.showorder = r;
      }), ibiz.net.post("/appfuncs/setfuncsetting", {
        setting: JSON.stringify({
          list: c.value
        })
      }).then((a) => {
        a.ok && (m == null || m.$Notice.success({
          title: "\u6210\u529F",
          desc: "\u4FDD\u5B58\u6210\u529F"
        }), b());
      })), i.value = !i.value;
    };
    J(() => e.isShowDrawer, (a) => {
      a && b();
    });
    const d = (a) => {
      a && ibiz.net.get(`/appfuncs/${a}/getfuncurl`).then((r) => {
        r.ok && r.data && r.data.url && window.open(r.data.url);
      });
    }, f = (a, r) => {
      var o;
      i.value && ((o = a.dataTransfer) == null || o.setData("originIndex", r.toString()));
    }, z = (a) => {
      a.preventDefault();
    }, U = (a, r) => {
      if (a.preventDefault(), i.value && a.dataTransfer) {
        const o = Number(a.dataTransfer.getData("originIndex"));
        if (o !== r) {
          const u = c.value[o], w = c.value[r];
          c.value.splice(o, 1, w), c.value.splice(r, 1, u);
        }
      }
    }, S = (a, r, o, u) => {
      if (a.stopPropagation(), r.ispersonal = Number(!r.ispersonal), u === "remove")
        c.value.splice(o, 1);
      else if (u === "change") {
        const w = c.value.findIndex((q) => q.pssysappfuncid === r.pssysappfuncid);
        w === -1 ? c.value.push(r) : c.value.splice(w, 1);
      }
    };
    return () => t("div", {
      class: [s.b(), e.isShowDrawer ? s.m("show") : ""]
    }, [t("div", {
      class: s.b("content")
    }, [t("div", {
      class: s.b("group")
    }, [t("header", {
      class: s.b("group-header")
    }, [t("div", {
      class: s.b("group-header-left")
    }, ["\u5E38\u7528\u5E94\u7528"]), t("div", {
      class: s.b("group-header-right")
    }, [t(x, {
      on: {
        click: M
      }
    }, [i.value ? "\u4FDD\u5B58" : "\u914D\u7F6E"]), t(x, {
      on: {
        click: () => n("on-close")
      }
    }, ["\u8FD4\u56DE"])])]), t("main", {
      class: s.b("group-content")
    }, [c.value.map((a, r) => t("div", {
      class: [s.b("group-item"), a.pssysappfuncid ? "" : s.bm("group-item", "disabled")],
      key: a.pssysappfuncid,
      on: {
        click: () => d(a.pssysappfuncid),
        dragstart: (o) => f(o, r),
        dragover: z,
        drop: (o) => U(o, r)
      },
      attrs: {
        draggable: i.value
      }
    }, [t("div", {
      class: [s.be("group-item", "checkbox"), s.bem("group-item", "checkbox", "remove"), i.value ? s.bem("group-item", "checkbox", "show") : ""],
      on: {
        click: (o) => S(o, a, r, "remove")
      }
    }, [t(A, {
      attrs: {
        type: "md-remove",
        size: 16
      }
    })]), t("div", {
      class: s.be("group-item", "icon")
    }, [t("img", {
      attrs: {
        src: a.icon || p,
        draggable: !1
      }
    })]), t(P, {
      attrs: {
        content: a.tip,
        disabled: !a.tip
      }
    }, [t("div", {
      class: s.be("group-item", "text")
    }, [a.pssysappfuncname])])]))])]), g.value.map((a, r) => t("div", {
      class: s.b("group"),
      key: r
    }, [t("header", {
      class: s.b("group-header")
    }, [a.name]), t("main", {
      class: s.b("group-content")
    }, [a.items.map((o) => t("div", {
      class: [s.b("group-item"), o.pssysappfuncid ? "" : s.bm("group-item", "disabled")],
      key: o.pssysappfuncid,
      on: {
        click: () => d(o.pssysappfuncid)
      }
    }, [t("div", {
      class: [s.be("group-item", "checkbox"), o.ispersonal ? s.bem("group-item", "checkbox", "selected") : "", i.value ? s.bem("group-item", "checkbox", "show") : ""],
      on: {
        click: (u) => S(u, o, r, "change")
      }
    }, [o.ispersonal ? t(A, {
      attrs: {
        type: "md-checkmark",
        size: 16
      }
    }) : null]), t("div", {
      class: s.be("group-item", "icon")
    }, [t("img", {
      attrs: {
        src: o.icon || p,
        draggable: !1
      }
    })]), t(P, {
      attrs: {
        content: o.tip,
        disabled: !o.tip
      }
    }, [t("div", {
      class: s.be("group-item", "text")
    }, [o.pssysappfuncname])])]))])]))])]);
  }
}), V = L({
  name: "FuncPortalListPortlet",
  components: {
    FuncDrawer: O
  },
  props: {
    modelData: {
      type: F,
      required: !0
    },
    controller: {
      type: D,
      required: !0
    }
  },
  setup(e) {
    const n = T("func-portal-list-portlet"), s = v.dir("/assets/img/quick-entry.svg"), p = v.dir("/assets/img/editor.svg"), l = v.dir("/assets/img/placeholder.svg"), g = h([]), c = k();
    let i = null;
    c && e.modelData.list && (i = R(c.proxy, e.modelData.list, e.controller.context), C(() => {
      i == null || i.nerve.self.evt.on("mounted", async () => {
        if (i) {
          const d = await i.load();
          g.value = d;
        }
      });
    }));
    const m = (d) => {
      d && ibiz.net.get(`/appfuncs/${d}/getfuncurl`).then((f) => {
        f.ok && f.data && f.data.url && window.open(f.data.url);
      });
    }, b = h(!1);
    return {
      ns: n,
      quickEntryImg: s,
      editorImg: p,
      placeholderImg: l,
      funcPortalList: g,
      openPage: m,
      isShowDrawer: b,
      isShowDrawerChange: async () => {
        if (b.value = !1, i) {
          const d = await i.load();
          g.value = d;
        }
      }
    };
  },
  render() {
    return t("div", {
      class: this.ns.b()
    }, [t("header", {
      class: this.ns.b("header")
    }, [t("div", {
      class: this.ns.b("header-left")
    }, [t("div", {
      class: this.ns.be("header-left", "icon")
    }, [t("img", {
      attrs: {
        src: this.quickEntryImg
      }
    })]), t("div", {
      class: this.ns.be("header-left", "text")
    }, ["\u5FEB\u901F\u5165\u53E3"])]), t("div", {
      class: this.ns.b("header-right"),
      on: {
        click: () => {
          this.isShowDrawer = !0;
        }
      }
    }, [t("div", {
      class: this.ns.be("header-right", "icon")
    }, [t("img", {
      attrs: {
        src: this.editorImg
      }
    })]), t("div", {
      class: this.ns.be("header-right", "text")
    }, ["\u66F4\u591A"])])]), t("div", {
      class: this.ns.e("divider")
    }), t("main", {
      class: this.ns.b("content")
    }, [this.funcPortalList.map((e) => t("div", {
      class: [this.ns.b("item"), e.pssysappfuncid ? "" : this.ns.bm("item", "disabled")],
      key: e.pssysappfuncid,
      on: {
        click: () => this.openPage(e.pssysappfuncid)
      }
    }, [t("div", {
      class: this.ns.be("item", "icon")
    }, [t("img", {
      attrs: {
        src: e.icon || this.placeholderImg
      }
    })]), t(P, {
      attrs: {
        content: e.tip,
        disabled: !e.tip
      }
    }, [t("div", {
      class: this.ns.be("item", "text")
    }, [e.pssysappfuncname])])]))]), t(O, {
      attrs: {
        isShowDrawer: this.isShowDrawer
      },
      on: {
        "on-close": this.isShowDrawerChange
      }
    })]);
  }
});
const W = L({
  name: "TodoAppMenuPortlet",
  props: {
    modelData: {
      type: B,
      required: !0
    },
    controller: {
      type: E,
      required: !0
    }
  },
  setup(e) {
    const n = T("todo-app-menu-portlet"), s = Array.from({
      length: 5
    }).map((c, i) => v.dir(`/assets/img/todo-app-menu-${i}.svg`));
    let p = null;
    const l = h({});
    if (e.modelData.appMenu) {
      const i = e.modelData.appMenu.source.getPSAppCounterRef();
      i && (C(async () => {
        p = await K.getCounterByRef(i), p.onChange((m) => {
          l.value = m;
        });
      }), H(() => {
        p == null || p.destroy();
      }));
    }
    return {
      ns: n,
      todoImgList: s,
      counter: p,
      counterData: l,
      onClickMenuItem: async (c) => {
        const i = c.source.getPSAppFunc();
        if (i)
          await ibiz.commands.execute(j.TAG, i);
        else if (e.modelData.appMenu)
          throw new G(e.modelData.appMenu.source, "\u672A\u914D\u7F6E\u754C\u9762\u884C\u4E3A");
      }
    };
  },
  render() {
    var e;
    return t("div", {
      class: this.ns.b()
    }, [(e = this.modelData.appMenu) == null ? void 0 : e.items.map((n, s) => t("div", {
      class: [this.ns.b("item"), n.source.getPSAppFunc() ? "" : this.ns.bm("item", "disabled")],
      key: n.id,
      on: {
        click: () => this.onClickMenuItem(n)
      }
    }, [t("div", {
      class: this.ns.b("item-left")
    }, [t("div", {
      class: this.ns.be("item-left", "icon")
    }, [t("img", {
      attrs: {
        src: this.todoImgList[s]
      }
    })])]), t("div", {
      class: this.ns.b("item-right")
    }, [t("div", {
      class: this.ns.be("item-right", "count")
    }, [t("span", {
      class: [(this.counterData[n.counterId] || 0) > 99 ? this.ns.be("item-right", "add") : ""]
    }, [(this.counterData[n.counterId] || 0) > 99 ? 99 : this.counterData[n.counterId] || 0]), t("span", ["\u4EF6"])]), t(P, {
      attrs: {
        content: n.source.tooltip,
        disabled: !n.source.tooltip
      }
    }, [t("div", {
      class: this.ns.be("item-right", "text")
    }, [n.label])])])]))]);
  }
});
class X {
  constructor() {
    y(this, "compName", "PORTLETCUSTOMAppPortalList");
  }
  async createController(n, s, p) {
    const l = new D(
      n,
      s,
      p
    );
    return await l.init(), l;
  }
}
class Y {
  constructor() {
    y(this, "compName", "PORTLETCUSTOMFuncPortalList");
  }
  async createController(n, s, p) {
    const l = new D(
      n,
      s,
      p
    );
    return await l.init(), l;
  }
}
class Z {
  constructor() {
    y(this, "compName", "PORTLETCUSTOMTodoAppMenu");
  }
  async createController(n, s, p) {
    const l = new E(
      n,
      s,
      p
    );
    return await l.init(), l;
  }
}
const ct = {
  mateUrl: import.meta.url,
  install(e) {
    e.component("PORTLETCUSTOMAppPortalList", Q), e.component("PORTLETCUSTOMFuncPortalList", V), e.component("PORTLETCUSTOMTodoAppMenu", W), ibiz.register.portletPart.register(
      "PORTLET_CUSTOM_AppPortalList",
      new X()
    ), ibiz.register.portletPart.register(
      "PORTLET_CUSTOM_FuncPortalList",
      new Y()
    ), ibiz.register.portletPart.register(
      "PORTLET_CUSTOM_TodoAppMenu",
      new Z()
    );
  }
};
export {
  ct as default
};
