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