import { defineComponent as x, useChat as g, watch as k, watchDebounced as C, computed as _, useBackground as v, currentRoom as S, openBlock as d, createElementBlock as w, createVNode as s, withCtx as B, unref as t, selectedUser as c, createBlock as N, createCommentVNode as V, createBaseVNode as a, toDisplayString as $, normalizeStyle as z, useWebNotification as A } from "./composables-Ci32s3jE.js";
import { AccountHome as D, UiLayer as E, ChatMessages as R, ChatInput as U } from "./components.js";
const H = { class: "px-4 py-6 flex flex-wrap items-center text-center" }, I = { class: "flex-1 ml-2 font-bold" }, L = { class: "p-4 bg-dark-50 bg-opacity-80 flex gap-2 flex sticky bottom-0" }, O = /* @__PURE__ */ x({
  __name: "ChatRoom",
  props: {
    title: { type: String, default: "Topics" },
    topic: { type: String, default: "general" },
    clickSound: { type: String, default: "audio/safe.mp3" }
  },
  emits: ["account"],
  setup(f, { emit: M }) {
    const u = f;
    let i;
    function m() {
      i || (i = new Audio(u.clickSound), i.volume = 0.1), i.play();
    }
    const { send: b, currentChat: r, sorted: p } = g();
    k(() => u.topic, (l) => {
      r.value = l;
    }, { immediate: !0 }), C(p, (l, n) => {
      if (l.length > n.length) {
        m();
        const e = l.slice(-1)[0], {
          isSupported: o,
          notification: T,
          show: h,
          close: W,
          onClick: j,
          onShow: q,
          onError: F,
          onClose: G
        } = A({
          title: e == null ? void 0 : e.text,
          body: `${e == null ? void 0 : e.timestamp} by ${e == null ? void 0 : e.author}`,
          lang: "en",
          tag: "chat"
        });
        o.value && h();
      }
    }, { deep: !0 });
    const y = _(() => v({ pub: S.pub, size: 1200 }));
    return (l, n) => {
      var e;
      return d(), w("div", {
        class: "flex flex-col overflow-y-scroll",
        style: z([{ flex: "1000 1 auto" }, { ...y.value }])
      }, [
        s(t(E), {
          open: !!((e = t(c)) != null && e.pub),
          onClose: n[0] || (n[0] = (o) => t(c).pub = "")
        }, {
          default: B(() => {
            var o;
            return [
              (o = t(c)) != null && o.pub ? (d(), N(t(D), {
                key: 0,
                pub: t(c).pub
              }, null, 8, ["pub"])) : V("", !0)
            ];
          }),
          _: 1
        }, 8, ["open"]),
        a("div", H, [
          a("div", I, $(t(r)), 1)
        ]),
        s(t(R), { messages: t(p) }, null, 8, ["messages"]),
        a("div", L, [
          s(t(U), {
            class: "flex-auto",
            onSubmit: n[1] || (n[1] = (o) => t(b)(o))
          })
        ])
      ], 4);
    };
  }
});
export {
  O as default
};
//# sourceMappingURL=ChatRoom-BRASdRZ0.js.map
