var X = Object.defineProperty;
var Z = (e, t, l) => t in e ? X(e, t, { enumerable: !0, configurable: !0, writable: !0, value: l }) : e[t] = l;
var _ = (e, t, l) => Z(e, typeof t != "symbol" ? t + "" : t, l);
import { defineComponent as ee, ref as L, computed as O, watch as K, resolveDirective as te, withDirectives as P, openBlock as f, createElementBlock as b, useUser as ne, useNewGift as ie, useGuests as le, useProject as se, toRef as re, useProjects as oe, useColor as ae, useGun as ue, reactive as Q, resolveComponent as ce, createBaseVNode as m, unref as s, createBlock as w, withCtx as I, toDisplayString as S, Fragment as F, renderList as D, createVNode as z, mergeProps as pe, vModelSelect as de, vModelText as me, createTextVNode as fe, createCommentVNode as V, normalizeStyle as H } from "./composables-Ci32s3jE.js";
import { AccountBadge as T, AuthForm as ve, ProjectCard as he, RoomButton as ge } from "./components.js";
import { currencies as be } from "./currencies-BZwbRKMz.js";
/**
 * Vue Number Format 3.34.1
 * (c) 2021-2023 Dipak Sarkar <hello@dipaksarkar.in> (https://dipaksarkar.in/)
 * @license MIT
 */
var U = { prefix: "", suffix: "", separator: ",", decimal: ".", precision: 2, minimumFractionDigits: null, prefill: !0, reverseFill: !1, min: null, max: null, nullValue: "" };
function xe(e) {
  return t = 0, l = e, o = 20, Math.max(t, Math.min(l, o));
  var t, l, o;
}
class A {
  constructor(t) {
    _(this, "options");
    _(this, "input");
    _(this, "number");
    _(this, "isClean");
    _(this, "preSurRegExp");
    _(this, "numberRegExp");
    _(this, "cleanRegExp");
    _(this, "negativeRegExp");
    this.options = Object.assign(J(U), t);
    const { prefix: l, suffix: o, decimal: u, reverseFill: n } = this.options;
    this.input = "", this.number = "", this.isClean = !n;
    const r = l.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"), i = o.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
    this.preSurRegExp = new RegExp(`${r}|${i}`, "g"), this.numberRegExp = new RegExp(`[^0-9\\${u}]+`, "gi"), this.cleanRegExp = new RegExp("[^0-9]+", "gi"), this.negativeRegExp = new RegExp("[^0-9\\-]+", "gi");
  }
  isNull() {
    return !this.numberOnly(this.isClean ? this.cleanRegExp : this.negativeRegExp);
  }
  clean(t = !1) {
    return this.isClean = t, this;
  }
  sign() {
    if (this.input === null || this.input === void 0) return "";
    const t = this.input.toString().indexOf("-") >= 0;
    return this.isClean ? t && this.realNumber() > 0 ? "-" : "" : t ? "-" : "";
  }
  toFixed() {
    const t = Math.pow(10, this.options.precision);
    return (parseFloat(this.numberOnly(/\D+/g)) / t || 0).toFixed(xe(this.options.precision));
  }
  toNumber(t) {
    return Number(t);
  }
  numberOnly(t) {
    var l;
    return (l = this.input) == null ? void 0 : l.toString().replace(this.preSurRegExp, "").replace(t || this.numberRegExp, "");
  }
  isNegative() {
    return this.sign() === "-";
  }
  numbers() {
    const { reverseFill: t, decimal: l } = this.options;
    return t ? this.number = this.toFixed().replace(".", l) : typeof this.input == "number" ? this.number = this.parts(this.input.toString().replace("-", ""), ".").join(l) : isNaN(this.toNumber(this.input)) ? this.number = this.parts(this.numberOnly()).join(l) : this.number = this.parts(this.input.replace("-", ""), ".").join(l), this.number;
  }
  unformatNumber() {
    return this.numbers().toString().replace(this.options.decimal, ".");
  }
  realNumber() {
    return parseFloat(this.unformatNumber());
  }
  parts(t, l) {
    const { precision: o, minimumFractionDigits: u, decimal: n } = this.options;
    let r = t.toString().split(l || n);
    if (r.length > 1 && (r[0] = this.toNumber(r[0]) || 0, r[1] = r.slice(1, r.length).join(""), r = r.slice(0, 2)), this.isClean) {
      const i = this.toNumber(r.join(".")).toFixed(o), d = this.toNumber(i), c = d.toFixed(u);
      r = u >= 0 && d.toString().length < c.length ? c.toString().split(".") : d.toString().split(".");
    }
    return r.slice(0, 2);
  }
  addSeparator() {
    const { decimal: t, separator: l } = this.options, o = this.numbers().split(t);
    return o[0] = o[0].toString().replace(/(\d)(?=(?:\d{3})+\b)/gm, `$1${l}`), o.join(t);
  }
  format(t) {
    this.input = t;
    const { reverseFill: l, nullValue: o, prefix: u, suffix: n } = this.options;
    return this.isNull() && !l ? o : this.sign() + u + this.addSeparator() + n;
  }
  unformat(t) {
    this.input = t;
    const { reverseFill: l, nullValue: o } = this.options, u = this.realNumber(), n = this.unformatNumber();
    return this.isNull() || l && u === 0 ? o : this.sign() + n;
  }
}
const q = "-";
function J(e) {
  return JSON.parse(JSON.stringify(e));
}
function G(e) {
  return new CustomEvent(e, { bubbles: !0, cancelable: !0, detail: { facade: !0 } });
}
function R(e) {
  const t = e instanceof HTMLInputElement ? e : e.querySelector("input");
  if (!t) throw new Error("number directive requires an input element");
  return t;
}
function Y(e, t) {
  const l = () => {
    e.setSelectionRange(t, t);
  };
  l(), setTimeout(l, 1);
}
function j(e, t, { emit: l = !0, force: o = !1, clean: u = !1 } = {}) {
  var h;
  const { options: n, oldValue: r } = e, { reverseFill: i, max: d, min: c } = n, v = ((h = t == null ? void 0 : t.props) == null ? void 0 : h.value) || e.value;
  if (o || r !== v) {
    const E = new A(n).clean(u && !i);
    let k = E.format(v), x = E.clean(!i).unformat(v);
    return u && (Number(d) === d && Number(x) > d ? (k = E.format(d), x = d.toString()) : Number(c) === c && Number(x) < c && (k = E.format(c), x = c.toString())), e.oldValue = k, e.unmasked = x, e.value !== k && (e.value = k), l && e.dispatchEvent(G("input"));
  }
}
var ye = { beforeMount: (e, { value: t, modifiers: l }, o) => {
  var d;
  e = R(e);
  const u = Object.assign(J(U), t, l), { reverseFill: n, precision: r, decimal: i } = u;
  e.options = u, e.setAttribute("inputmode", "numeric"), n && e.value ? (e.value = parseFloat(new A({ ...u, reverseFill: !1 }).unformat(e.value)).toFixed(r), (d = o == null ? void 0 : o.props) != null && d.value && (o.props.value = e.value)) : e.value && !isNaN(Number(e.value)) && (e.value = e.value.replace(".", i)), j(e, o, { force: u.prefill, clean: !0, emit: !1 });
}, mounted: (e) => {
  const t = (e = R(e)).parentElement || e, l = (n) => {
    n.target === e && function(r) {
      const { target: i, detail: d } = r;
      if (d != null && d.facade) return !1;
      r.stopPropagation();
      let c = i.value.length;
      const { oldValue: v, options: h } = i;
      i.selectionEnd && (c = i.value.length - i.selectionEnd), j(i, null, { clean: !h.precision, emit: !1 }), h.suffix && (c = Math.max(c, h.suffix.length)), c = i.value.length - c, h.prefix && (c = Math.max(c, h.prefix.length)), Y(i, c), v !== i.value && i.dispatchEvent(G("input"));
    }(n);
  }, o = (n) => {
    n.target === e && function(r) {
      const { target: i } = r, { oldValue: d } = i;
      j(i, null, { force: !0, clean: !0, emit: !1 }), d !== i.value && i.dispatchEvent(G("input"));
    }(n);
  }, u = (n) => {
    n.target === e && function(r, i) {
      const { options: d } = i, { prefix: c, suffix: v, decimal: h, min: E, separator: k } = d, { key: x } = r, $ = new RegExp(`${c}|${v}`, "g"), C = i.value.replace($, ""), B = E === void 0 || Number(E) < 0 || Number(E) !== E;
      if (x === h) C.includes(h) ? r.preventDefault() : C || (i.value = "0" + h, i.dispatchEvent(new Event("input")));
      else if (x !== q || B) {
        if (x === "Backspace") {
          const g = i.selectionEnd || 0, p = i.value.slice(g - 1, g), N = i.value.slice(g - 2, g);
          let a = i.value.length - g;
          [c, q, k].includes(p) && (r.preventDefault(), i.value = p === k ? i.value.replace(N, "") : i.value.replace(new RegExp(`[${c}${q}]`, "g"), ""), a = Math.max(a, v.length), a = i.value.length - a, a = Math.max(a, c.length), Y(i, a), i.dispatchEvent(new Event("input")));
        }
      } else r.preventDefault();
    }(n, e);
  };
  t.addEventListener("input", l, !0), t.addEventListener("blur", o, !0), t.addEventListener("keydown", u, !0), e.cleanup = () => {
    t.removeEventListener("input", l, !0), t.removeEventListener("blur", o, !0), t.removeEventListener("keydown", u, !0);
  };
}, updated: (e, { value: t, oldValue: l, modifiers: o }, u) => {
  if (e = R(e), t !== l) {
    const n = e.options;
    e.options = Object.assign(n, t, o), j(e, u, { force: !0, clean: !1, emit: !1 });
  } else j(e, u, { emit: !1 });
}, unmounted: (e) => {
  R(e).cleanup();
} };
const y = J(U);
var W = ee({ name: "VueNumber", directives: { number: ye }, props: { modelValue: { type: [String, Number], required: !0 }, nullValue: { type: [Number, String], default: y.nullValue }, masked: Boolean, readonly: Boolean, disabled: Boolean, reverseFill: { type: Boolean, default: y.reverseFill }, prefill: { type: Boolean, default: y.prefill }, precision: { type: Number, default: () => y.precision }, minimumFractionDigits: { type: Number, default: () => y.minimumFractionDigits }, decimal: { type: String, default: () => y.decimal }, min: { type: Number, default: () => y.min }, max: { type: Number, default: () => y.max }, separator: { type: String, default: () => y.separator }, prefix: { type: String, default: () => y.prefix }, suffix: { type: String, default: () => y.suffix } }, emits: ["update:model-value", "input:model-value"], setup(e, { emit: t }) {
  const l = L(e.modelValue), o = L(!1), u = L(""), n = O(() => ({ ...e })), r = new A(n.value), i = O(() => e.masked ? r.format(l.value) : u.value), d = () => {
    t("update:model-value", i.value);
  };
  return K(() => e.modelValue, (c) => {
    const v = r.format(c);
    v !== l.value && (l.value = v);
  }), { config: n, maskedValue: l, unmaskedValue: u, input: (c) => {
    const { target: v } = c;
    l.value = v.value, u.value = v.unmasked, o.value = !0, t("input:model-value", i.value);
  }, blur: () => {
    o.value && i.value !== e.modelValue && d();
  }, change: d };
} });
const Ee = ["value", "readonly", "disabled"];
W.render = function(e, t, l, o, u, n) {
  const r = te("number");
  return P((f(), b("input", { type: "text", autocomplete: "off", value: e.maskedValue, readonly: e.readonly, disabled: e.disabled, class: "v-number vue-number-format", onChange: t[0] || (t[0] = (...i) => e.change && e.change(...i)), onInput: t[1] || (t[1] = (...i) => e.input && e.input(...i)), onBlur: t[2] || (t[2] = (...i) => e.blur && e.blur(...i)) }, null, 40, Ee)), [[r, e.config]]);
}, W.__file = "src/component.vue";
const ke = { class: "flex flex-col max-w-140" }, _e = {
  class: "grid p-4 gap-2 items-center",
  style: { "grid-template-columns": "1fr 10fr" }
}, Ne = /* @__PURE__ */ m("div", { class: "p-2 text-right" }, "FROM", -1), we = { class: "flex-1" }, Se = /* @__PURE__ */ m("div", { class: "p-2 text-right" }, "TO ", -1), Fe = /* @__PURE__ */ m("div", { class: "flex-1" }, null, -1), je = {
  key: 1,
  class: "flex flex-col"
}, Ce = { class: "font-bold" }, Ve = { class: "flex flex-wrap gap-3" }, Re = /* @__PURE__ */ m("div", { class: "p-2 text-right" }, "WALLET", -1), Oe = /* @__PURE__ */ m("div", { class: "p-2 text-right" }, "Quantity", -1), $e = /* @__PURE__ */ m("div", { class: "p-2 text-right" }, "Quality", -1), Be = ["value"], Me = /* @__PURE__ */ m("div", { class: "p-2 text-right self-start" }, "Wish ", -1), Le = { class: "p-2 text-right" }, De = {
  key: 0,
  class: "w-full"
}, Te = {
  key: 1,
  class: "flex flex-wrap gap-1"
}, qe = ["onClick"], Pe = { class: "font-bold" }, Ge = /* @__PURE__ */ m("div", { class: "p-2 text-right" }, "ROOM", -1), We = {
  key: 2,
  class: "flex"
}, Ue = { class: "overflow-scroll font-mono text-xs m-4 opacity-50 break-all col-span-2" }, He = {
  __name: "GiftForm",
  props: {
    gift: {
      type: Object,
      default: () => ({})
    }
  },
  emits: ["sent", "update:gift"],
  setup(e, { emit: t }) {
    const l = {
      decimal: ".",
      separator: " ",
      prefix: "",
      precision: 2,
      masked: !1
    }, o = e, { user: u } = ne(), { gift: n, cleanGift: r, propose: i, proposed: d, hash: c, valid: v } = ie(o.gift), { guests: h, count: E } = le(), { project: k } = se(re(n, "project")), { projects: x } = oe(), $ = ae();
    K(() => n.wallet, (g) => {
      g && (n.ql = g.currency);
    });
    const C = O(() => {
      const g = ue(), p = Q({});
      return Object.keys(h).forEach((N) => {
        g.user(N).get("wallets").on((a, M) => {
          p[N] = h[N];
        });
      }), p;
    }), B = O(() => {
      const g = Q({});
      return Object.keys(x).forEach((p) => {
        p.includes(n.to) && (g[p] = x[p]);
      }), g;
    });
    return (g, p) => {
      const N = ce("gift-wallets");
      return f(), b("div", ke, [
        m("div", _e, [
          Ne,
          m("div", we, [
            s(u).pub ? (f(), w(s(T), {
              key: 0,
              pub: s(u).pub
            }, null, 8, ["pub"])) : (f(), w(s(ve), { key: 1 }))
          ]),
          Se,
          s(n).to ? (f(), w(s(T), {
            key: 0,
            pub: s(n).to
          }, {
            default: I(() => [
              Fe,
              m("div", {
                class: "i-la-times mr-2",
                onClick: p[0] || (p[0] = (a) => {
                  s(n).to = "", s(n).wallet = null;
                })
              })
            ]),
            _: 1
          }, 8, ["pub"])) : (f(), b("div", je, [
            m("div", Ce, "USER SELECT OF " + S(Object.keys(C.value).length), 1),
            m("div", Ve, [
              (f(!0), b(F, null, D(s(h), (a) => (f(), w(s(T), {
                key: a,
                pub: a.pub,
                onClick: (M) => s(n).to = a.pub
              }, null, 8, ["pub", "onClick"]))), 128))
            ])
          ])),
          s(n).to ? (f(), b(F, { key: 2 }, [
            Re,
            (f(), w(N, {
              key: s(n).to,
              pub: s(n).to,
              "active-wallet": s(n).wallet,
              onWallet: p[1] || (p[1] = (a) => s(n).wallet = a),
              onClear: p[2] || (p[2] = (a) => s(n).wallet = null)
            }, null, 8, ["pub", "active-wallet"])),
            s(n).wallet ? (f(), b(F, { key: 0 }, [
              Oe,
              z(s(W), pe({
                modelValue: s(n).qn,
                "onUpdate:modelValue": p[3] || (p[3] = (a) => s(n).qn = a)
              }, l, { placeholder: "Quantity" }), null, 16, ["modelValue"]),
              $e,
              P(m("select", {
                class: "rounded-xl dark-bg-dark-100 p-2",
                "onUpdate:modelValue": p[4] || (p[4] = (a) => s(n).ql = a),
                placeholder: "Your account currency"
              }, [
                (f(!0), b(F, null, D(s(be), (a) => (f(), b("option", {
                  key: a,
                  value: a
                }, S(a), 9, Be))), 128))
              ], 512), [
                [de, s(n).ql]
              ]),
              Me,
              P(m("textarea", {
                class: "p-2",
                "onUpdate:modelValue": p[5] || (p[5] = (a) => s(n).wish = a),
                placeholder: "Wish"
              }, null, 512), [
                [me, s(n).wish]
              ]),
              m("div", Le, [
                fe("PROJECT "),
                s(n).project ? V("", !0) : (f(), b("div", De, "SELECT"))
              ]),
              s(n).project ? (f(), w(s(he), {
                key: 0,
                project: s(k),
                path: s(n).project
              }, {
                default: I(() => [
                  m("div", {
                    class: "i-la-times",
                    onClick: p[6] || (p[6] = (a) => s(n).project = null)
                  })
                ]),
                _: 1
              }, 8, ["project", "path"])) : (f(), b("div", Te, [
                (f(!0), b(F, null, D(B.value, (a, M) => (f(), b("div", {
                  class: "p-2 rounded-xl cursor-pointer",
                  key: M,
                  style: H({ backgroundColor: a.color }),
                  onClick: (Ae) => s(n).project = a.path
                }, [
                  m("div", Pe, S(a.title), 1)
                ], 12, qe))), 128))
              ])),
              Ge,
              z(s(ge)),
              s(v) ? (f(), b("div", We, [
                m("button", {
                  class: "button w-full justify-center",
                  onClick: p[7] || (p[7] = (a) => {
                    s(i)(), g.$emit("sent", s(c));
                  })
                }, "Propose")
              ])) : V("", !0),
              m("pre", Ue, S(s(r)), 1),
              m("div", {
                class: "font-mono text-xs col-span-2 text-center rounded-lg m-2 transition",
                style: H({ backgroundColor: s($).hex(s(c) || "") })
              }, S(s(c)), 5)
            ], 64)) : V("", !0)
          ], 64)) : V("", !0)
        ])
      ]);
    };
  }
};
export {
  He as default
};
//# sourceMappingURL=GiftForm-CkAL1BWR.js.map
