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