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