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 w = (s, n, e) => (_(s, typeof n != "symbol" ? n + "" : n, e), e);
import { ListPortletController as y, AppMenuPortletController as A } from "@ibiz-template/controller";
import { ListPortletModel as F, AppMenuPortletModel as $ } from "@ibiz-template/model";
import { useNamespace as D, useListController as T } from "@ibiz-template/vue-util";
import { defineComponent as k, ref as f, getCurrentInstance as L, onMounted as C, h as t, watch as R, onUnmounted as N } from "vue";
import { PluginStaticResource as U, AppFuncCommand as j } from "@ibiz-template/runtime";
import { CounterService as B } from "@ibiz-template/service";
const d = new U(import.meta.url), G = k({
  name: "AppPortalListPortlet",
  props: {
    modelData: {
      type: F,
      required: !0
    },
    controller: {
      type: y,
      required: !0
    }
  },
  setup(s) {
    const n = D("app-portal-list-portlet"), e = f([]), p = Array.from({
      length: 4
    }).map((c, i) => d.dir(`/assets/img/app-portal-list-${i}.svg`)), l = L();
    if (l && s.modelData.list) {
      const c = T(l.proxy, s.modelData.list, s.controller.context);
      C(() => {
        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("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 J {
  constructor() {
    w(this, "component", G);
  }
  async createController(n, e, p) {
    const l = new y(
      n,
      e,
      p
    );
    return await l.init(), l;
  }
}
const M = k({
  name: "FuncDrawer",
  props: {
    isShowDrawer: {
      type: Boolean,
      required: !0,
      default: !1
    }
  },
  emits: {
    "on-close": () => !0
  },
  setup(s, {
    emit: n
  }) {
    var S;
    const e = D("func-drawer"), p = d.dir("/assets/img/placeholder.svg"), l = "未分类", h = f([]), c = f([]), i = f(!1), m = (S = L()) == null ? void 0 : S.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;
          }), h.value = Object.keys(r).map((o) => ({
            name: o,
            items: r[o]
          }));
        }
      });
    }, x = () => {
      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: "成功",
          desc: "保存成功"
        }), b());
      })), i.value = !i.value;
    };
    R(() => s.isShowDrawer, (a) => {
      a && b();
    });
    const g = (a) => {
      a && ibiz.net.get(`/appfuncs/${a}/getfuncurl`).then((r) => {
        r.ok && r.data && r.data.url && window.open(r.data.url);
      });
    }, v = (a, r) => {
      var o;
      i.value && ((o = a.dataTransfer) == null || o.setData("originIndex", r.toString()));
    }, E = (a) => {
      a.preventDefault();
    }, z = (a, r) => {
      if (a.preventDefault(), i.value && a.dataTransfer) {
        const o = Number(a.dataTransfer.getData("originIndex"));
        if (o !== r) {
          const u = c.value[o], P = c.value[r];
          c.value.splice(o, 1, P), c.value.splice(r, 1, u);
        }
      }
    }, I = (a, r, o, u) => {
      if (a.stopPropagation(), r.ispersonal = +!r.ispersonal, u === "remove")
        c.value.splice(o, 1);
      else if (u === "change") {
        const P = c.value.findIndex((O) => O.pssysappfuncid === r.pssysappfuncid);
        P === -1 ? c.value.push(r) : c.value.splice(P, 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("i-button", {
      on: {
        click: x
      }
    }, [i.value ? "保存" : "配置"]), t("i-button", {
      on: {
        click: () => n("on-close")
      }
    }, ["返回"])])]), t("main", {
      class: e.b("group-content")
    }, [c.value.map((a, r) => t("div", {
      class: [e.b("group-item"), a.pssysappfuncid ? "" : e.bm("group-item", "disabled")],
      key: a.pssysappfuncid,
      on: {
        click: () => g(a.pssysappfuncid),
        dragstart: (o) => v(o, r),
        dragover: E,
        drop: (o) => z(o, 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: (o) => I(o, a, r, "remove")
      }
    }, [t("i-icon", {
      attrs: {
        type: "md-remove",
        size: 16
      }
    })]), 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])])]))])]), h.value.map((a, r) => t("div", {
      class: e.b("group"),
      key: r
    }, [t("header", {
      class: e.b("group-header")
    }, [a.name]), t("main", {
      class: e.b("group-content")
    }, [a.items.map((o) => t("div", {
      class: [e.b("group-item"), o.pssysappfuncid ? "" : e.bm("group-item", "disabled")],
      key: o.pssysappfuncid,
      on: {
        click: () => g(o.pssysappfuncid)
      }
    }, [t("div", {
      class: [e.be("group-item", "checkbox"), o.ispersonal ? e.bem("group-item", "checkbox", "selected") : "", i.value ? e.bem("group-item", "checkbox", "show") : ""],
      on: {
        click: (u) => I(u, o, r, "change")
      }
    }, [o.ispersonal ? t("i-icon", {
      attrs: {
        type: "md-checkmark",
        size: 16
      }
    }) : null]), 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])])]))])]))])]);
  }
}), H = k({
  name: "FuncPortalListPortlet",
  components: {
    FuncDrawer: M
  },
  props: {
    modelData: {
      type: F,
      required: !0
    },
    controller: {
      type: y,
      required: !0
    }
  },
  setup(s) {
    const n = D("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 = L();
    let i = null;
    c && s.modelData.list && (i = T(c.proxy, s.modelData.list, s.controller.context), C(() => {
      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("i-tooltip", {
      attrs: {
        content: s.tip,
        disabled: !s.tip
      }
    }, [t("div", {
      class: this.ns.be("item", "text")
    }, [s.pssysappfuncname])])]))]), t(M, {
      attrs: {
        isShowDrawer: this.isShowDrawer
      },
      on: {
        "on-close": this.isShowDrawerChange
      }
    })]);
  }
});
class K {
  constructor() {
    w(this, "component", H);
  }
  async createController(n, e, p) {
    const l = new y(
      n,
      e,
      p
    );
    return await l.init(), l;
  }
}
const Q = k({
  name: "TodoAppMenuPortlet",
  props: {
    modelData: {
      type: $,
      required: !0
    },
    controller: {
      type: A,
      required: !0
    }
  },
  setup(s) {
    const n = D("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 && (C(async () => {
        p = await B.getCounterByRef(i), p.onChange((m) => {
          l.value = m;
        });
      }), N(() => {
        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("i-tooltip", {
      attrs: {
        content: n.source.tooltip,
        disabled: !n.source.tooltip
      }
    }, [t("div", {
      class: this.ns.be("item-right", "text")
    }, [n.label])])])]))]);
  }
});
class V {
  constructor() {
    w(this, "component", Q);
  }
  async createController(n, e, p) {
    const l = new A(
      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 J()
    ), ibiz.register.portletPart.register(
      "PORTLET_CUSTOM_FuncPortalList",
      new K()
    ), ibiz.register.portletPart.register(
      "PORTLET_CUSTOM_TodoAppMenu",
      new V()
    );
  }
};
export {
  ot as default
};
