var q = Object.defineProperty;
var $ = (s, n, e) => n in s ? q(s, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[n] = e;
var P = (s, n, e) => ($(s, typeof n != "symbol" ? n + "" : n, e), e);
import { ListPortletController as w, AppMenuPortletController as F } from "@ibiz-template/controller";
import { ListPortletModel as T, AppMenuPortletModel as R } from "@ibiz-template/model";
import { useNamespace as k, useListController as E } from "@ibiz-template/vue-util";
import { PluginStaticResource as N, safeRedirect as L, AppFuncCommand as U } from "@ibiz-template/runtime";
import { defineComponent as D, ref as f, getCurrentInstance as C, onMounted as x, h as t, watch as j, onUnmounted as B } from "vue";
import { CounterService as G } from "@ibiz-template/service";
const d = new N(import.meta.url), J = D({
  name: "AppPortalListPortlet",
  props: {
    modelData: {
      type: T,
      required: !0
    },
    controller: {
      type: w,
      required: !0
    }
  },
  setup(s) {
    const n = k("app-portal-list-portlet"), e = f([]), p = Array.from({
      length: 4
    }).map((c, i) => d.dir(`/assets/img/app-portal-list-${i}.svg`)), l = C();
    if (l && s.modelData.list) {
      const c = E(l.proxy, s.modelData.list, s.controller.context);
      x(() => {
        c.nerve.self.evt.on("mounted", async () => {
          const i = await c.load(), g = window.Environment || {};
          e.value = i.slice(0, g.portalNum || 4);
        });
      });
    }
    return {
      ns: n,
      appPortalList: e,
      appPortalImgList: p,
      openPage: (c) => {
        c && L(c, {
          type: "_blank"
        });
      }
    };
  },
  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("i-tooltip", {
      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 H {
  constructor() {
    P(this, "component", J);
  }
  async createController(n, e, p) {
    const l = new w(
      n,
      e,
      p
    );
    return await l.init(), l;
  }
}
const A = D({
  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 = "未分类", m = f([]), c = f([]), i = f(!1), g = (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;
          }), m.value = Object.keys(r).map((a) => ({
            name: a,
            items: r[a]
          }));
        }
      });
    }, S = () => {
      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 && (g == null || g.$Notice.success({
          title: "成功",
          desc: "保存成功"
        }), b());
      })), i.value = !i.value;
    };
    j(() => s.isShowDrawer, (o) => {
      o && b();
    });
    const h = (o) => {
      o && ibiz.net.get(`/appfuncs/${o}/getfuncurl`).then((r) => {
        r.ok && r.data && r.data.url && L(r.data.url, {
          type: "_blank"
        });
      });
    }, v = (o, r) => {
      var a;
      i.value && ((a = o.dataTransfer) == null || a.setData("originIndex", r.toString()));
    }, z = (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], y = c.value[r];
          c.value.splice(a, 1, y), c.value.splice(r, 1, u);
        }
      }
    }, I = (o, r, a, u) => {
      if (o.stopPropagation(), r.ispersonal = +!r.ispersonal, u === "remove")
        c.value.splice(a, 1);
      else if (u === "change") {
        const y = c.value.findIndex((O) => O.pssysappfuncid === r.pssysappfuncid);
        y === -1 ? c.value.push(r) : c.value.splice(y, 1);
      }
    };
    return () => t("div", {
      class: [e.b(), s.isShowDrawer ? e.m("show") : ""],
      style: {
        marginTop: s.isShowDrawer ? "0" : "-100vh"
      }
    }, [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("i-button", {
      on: {
        click: S
      }
    }, [i.value ? "保存" : "配置"]), t("i-button", {
      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: () => h(o.pssysappfuncid),
        dragstart: (a) => v(a, r),
        dragover: z,
        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) => I(a, o, r, "remove")
      }
    }, [t("i-icon", {
      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("i-tooltip", {
      attrs: {
        content: o.tip,
        disabled: !o.tip
      }
    }, [t("div", {
      class: e.be("group-item", "text")
    }, [o.pssysappfuncname])])]))])]), m.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: () => h(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) => I(u, a, r, "change")
      }
    }, [a.ispersonal ? t("i-icon", {
      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("i-tooltip", {
      attrs: {
        content: a.tip,
        disabled: !a.tip
      }
    }, [t("div", {
      class: e.be("group-item", "text")
    }, [a.pssysappfuncname])])]))])]))])]);
  }
}), K = D({
  name: "FuncPortalListPortlet",
  components: {
    FuncDrawer: A
  },
  props: {
    modelData: {
      type: T,
      required: !0
    },
    controller: {
      type: w,
      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"), m = f([]), c = C();
    let i = null;
    c && s.modelData.list && (i = E(c.proxy, s.modelData.list, s.controller.context), x(() => {
      i == null || i.nerve.self.evt.on("mounted", async () => {
        if (i) {
          const h = await i.load();
          m.value = h;
        }
      });
    }));
    const g = (h) => {
      h && ibiz.net.get(`/appfuncs/${h}/getfuncurl`).then((v) => {
        v.ok && v.data && v.data.url && L(v.data.url, {
          type: "_blank"
        });
      });
    }, b = f(!1);
    return {
      ns: n,
      quickEntryImg: e,
      editorImg: p,
      placeholderImg: l,
      funcPortalList: m,
      openPage: g,
      isShowDrawer: b,
      isShowDrawerChange: async () => {
        if (b.value = !1, i) {
          const h = await i.load();
          m.value = h;
        }
      }
    };
  },
  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("i-tooltip", {
      attrs: {
        content: s.tip,
        disabled: !s.tip
      }
    }, [t("div", {
      class: this.ns.be("item", "text")
    }, [s.pssysappfuncname])])]))]), t(A, {
      attrs: {
        isShowDrawer: this.isShowDrawer
      },
      on: {
        "on-close": this.isShowDrawerChange
      }
    })]);
  }
});
class Q {
  constructor() {
    P(this, "component", K);
  }
  async createController(n, e, p) {
    const l = new w(
      n,
      e,
      p
    );
    return await l.init(), l;
  }
}
const V = D({
  name: "TodoAppMenuPortlet",
  props: {
    modelData: {
      type: R,
      required: !0
    },
    controller: {
      type: F,
      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 G.getCounterByRef(i), p.onChange((g) => {
          l.value = g;
        });
      }), 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(U.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("i-tooltip", {
      attrs: {
        content: n.source.tooltip,
        disabled: !n.source.tooltip
      }
    }, [t("div", {
      class: this.ns.be("item-right", "text")
    }, [n.label])])])]))]);
  }
});
class W {
  constructor() {
    P(this, "component", V);
  }
  async createController(n, e, p) {
    const l = new F(
      n,
      e,
      p
    );
    return await l.init(), l;
  }
}
const ot = {
  mateUrl: import.meta.url,
  install(s) {
    d.loadStyle(["/style.css"]), ibiz.register.portletPart.register(
      "PORTLET_CUSTOM_AppPortalList",
      new H()
    ), ibiz.register.portletPart.register(
      "PORTLET_CUSTOM_FuncPortalList",
      new Q()
    ), ibiz.register.portletPart.register(
      "PORTLET_CUSTOM_TodoAppMenu",
      new W()
    );
  }
};
export {
  ot as default
};
