import { defineComponent as w, ref as C, watch as $, computed as B, createElementBlock as r, openBlock as l, createVNode as u, createBlock as m, unref as t, withCtx as f, createCommentVNode as b, createElementVNode as s, normalizeStyle as U, Transition as x, Fragment as h, renderList as L } from "vue";
import { useUser as R, useStorage as y, useRooms as M } from "./composables-BAZQlC3e.js";
import { UiLayer as N, AuthCredentials as P, AuthLogin as S, UserPanel as V, UserProfile as A, UserRooms as E, ChatPrivateList as j } from "./components.js";
import z from "./RoomButton-CZtN5Sk1.js";
const F = { class: "flex flex-col items-center w-full" }, H = {
  key: 1,
  class: "flex flex-col"
}, I = { class: "p-4 flex flex-col items-stretch gap-4" }, T = { class: "flex flex-col items-stretch bg-light-900 dark-bg-dark-500 p-2 rounded-xl" }, q = {
  key: 0,
  class: "i-la-angle-down"
}, D = {
  key: 1,
  class: "i-la-angle-up"
}, G = { class: "flex flex-col items-stretch bg-light-900 dark-bg-dark-500 p-2 rounded-xl" }, J = {
  key: 0,
  class: "i-la-angle-down"
}, K = {
  key: 1,
  class: "i-la-angle-up"
}, te = /* @__PURE__ */ w({
  __name: "UserHome",
  emits: ["user", "room", "close", "chat", "browse"],
  setup(O, { emit: Q }) {
    const { user: n } = R();
    function k() {
      n.db.get("safe").get("saved").put(!0);
    }
    const p = C(!1);
    $(() => n.is, () => {
      n.db.get("safe").get("saved").on((i) => p.value = i);
    }, { immediate: !0 });
    const d = y("showChats", !0), a = y("showRooms", !0), c = B(() => M(n.pub));
    return (i, e) => (l(), r("div", F, [
      u(t(N), {
        open: t(n).is && !p.value,
        "close-button": "",
        onClose: e[1] || (e[1] = (o) => k())
      }, {
        default: f(() => [
          p.value ? b("", !0) : (l(), m(t(P), { key: 0 }, {
            default: f(() => [
              s("button", {
                class: "button mx-8 justify-center",
                onClick: e[0] || (e[0] = (o) => k())
              }, e[8] || (e[8] = [
                s("div", { class: "i-la-check" }, null, -1),
                s("div", { class: "ml-2" }, "I've stored my key securely", -1)
              ]))
            ]),
            _: 1
          }))
        ]),
        _: 1
      }, 8, ["open"]),
      t(n).is ? (l(), r("div", H, [
        u(t(V), {
          onBrowse: e[2] || (e[2] = (o) => {
            i.$emit("browse", o), i.$emit("close");
          })
        }),
        s("div", I, [
          u(t(A)),
          s("button", {
            class: "p-2 rounded-xl font-bold text-lg shadow-md",
            style: U({ backgroundColor: t(n).color }),
            onClick: e[3] || (e[3] = (o) => {
              i.$emit("user", t(n).pub), i.$emit("close");
            })
          }, " My public profile", 4),
          e[13] || (e[13] = s("hr", { class: "w-full" }, null, -1)),
          u(t(E), {
            onBrowse: e[4] || (e[4] = (o) => i.$emit("room", o))
          }),
          s("div", T, [
            s("button", {
              class: "items-center w-full flex px-2 pb-2",
              onClick: e[5] || (e[5] = (o) => a.value = !t(a))
            }, [
              e[9] || (e[9] = s("div", { class: "font-bold text-lg" }, "My favourite rooms", -1)),
              e[10] || (e[10] = s("div", { class: "flex-1" }, null, -1)),
              t(a) ? (l(), r("div", q)) : (l(), r("div", D))
            ]),
            u(x, {
              name: "fade",
              mode: "out-in"
            }, {
              default: f(() => {
                var o, g;
                return [
                  t(a) ? (l(), r("div", {
                    class: "flex flex-col gap-4",
                    key: t(n).pub
                  }, [
                    (l(!0), r(h, null, L((g = (o = c.value) == null ? void 0 : o.rooms) == null ? void 0 : g.value, (W, v) => (l(), m(z, {
                      key: v,
                      pub: v,
                      onBrowse: (X) => i.$emit("room", v),
                      panel: !1
                    }, null, 8, ["pub", "onBrowse"]))), 128))
                  ])) : b("", !0)
                ];
              }),
              _: 1
            })
          ]),
          s("div", G, [
            s("button", {
              class: "items-center w-full flex px-2 pb-2",
              onClick: e[6] || (e[6] = (o) => d.value = !t(d))
            }, [
              e[11] || (e[11] = s("div", { class: "font-bold text-lg" }, "My chats", -1)),
              e[12] || (e[12] = s("div", { class: "flex-1" }, null, -1)),
              t(d) ? (l(), r("div", J)) : (l(), r("div", K))
            ]),
            u(x, {
              name: "fade",
              mode: "out-in"
            }, {
              default: f(() => [
                t(d) ? (l(), m(t(j), {
                  key: 0,
                  onChat: e[7] || (e[7] = (o) => i.$emit("chat", o))
                })) : b("", !0)
              ]),
              _: 1
            })
          ])
        ])
      ])) : (l(), m(t(S), { key: 0 }))
    ]));
  }
});
export {
  te as default
};
//# sourceMappingURL=UserHome-DuzuV30R.js.map
