var X = Object.defineProperty;
var Z = (t, e, n) => e in t ? X(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 G, computed as O, watch as A, resolveDirective as te, withDirectives as q, openBlock as f, createElementBlock as g, 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 I, resolveComponent as ce, createBaseVNode as p, unref as r, createBlock as _, withCtx as U, toDisplayString as S, Fragment as C, renderList as D, createVNode as W, mergeProps as pe, vModelSelect as me, vModelText as fe, createTextVNode as de, createCommentVNode as j, normalizeStyle as H } from "./composables-61bf5e40.js";
import { AccountBadge as M, AuthForm as he, ProjectCard as ge, RoomButton as ve } from "./components.js";
import { currencies as be } from "./currencies-09ab2985.js";
/**
 * Vue Number Format 3.27.0
 * (c) 2021-2023 Dipak Sarkar <hello@dipaksarkar.in> (https://dipaksarkar.in/)
 * @license MIT
 */
var T = {
  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(T, 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 d = this.toNumber(l.join(".")).toFixed(s), c = this.toNumber(d), m = c.toFixed(o);
      o >= 0 && c.toString().length < m.length ? l = m.toString().split(".") : l = c.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 L(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 V(t, e, { emit: n = !0, force: s = !1, clean: o = !1 } = {}) {
  var w;
  const { options: i, oldValue: l } = t, { reverseFill: d, max: c, 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 && !d);
    let b = h.format(E), x = h.clean(!d).unformat(E);
    return o && (Number(c) === c && Number(x) > c ? (b = h.format(c), x = h.unformat(c)) : 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(L("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), V(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(L("input"));
}
function ke(t) {
  const { target: e, detail: n } = t;
  if (n != null && n.facade)
    return !1;
  const { oldValue: s } = e;
  V(e, null, { force: !0, emit: !1, clean: !0 }), s !== e.value && e.dispatchEvent(L("change"));
}
function Ne(t, e) {
  const { options: n } = e, { prefix: s, suffix: o, decimal: i, min: l, separator: d } = n, { key: c } = t, m = new RegExp(`${s}|${o}`, "g"), E = e.value.replace(m, ""), w = l === void 0 || Number(l) < 0 || Number(l) !== l;
  if (c === i)
    E.includes(i) ? t.preventDefault() : E || (e.value = "0" + i, e.dispatchEvent(new Event("input")));
  else if (c === B && !w)
    t.preventDefault();
  else if (c === "Backspace") {
    const h = e.selectionEnd || 0, b = e.value.slice(h - 1, h), x = e.value.slice(h - 2, h);
    let k = e.value.length - h;
    [s, B, d].includes(b) && (t.preventDefault(), b === d ? e.value = e.value.replace(x, "") : e.value = e.value.replace(new RegExp(`[${s}${B}]`, "g"), ""), k = Math.max(k, o.length), k = e.value.length - k, k = Math.max(k, s.length), z(e, k), e.dispatchEvent(new Event("input")));
  }
}
var we = {
  beforeMount: (t, { value: e, modifiers: n }, s) => {
    var c;
    t = R(t);
    const o = Object.assign(Q(T), e, n), { reverseFill: i, precision: l, decimal: d } = o;
    t.options = o, i && t.value ? (t.value = parseFloat(new J({ ...o, reverseFill: !1 }).unformat(t.value)).toFixed(l), (c = s == null ? void 0 : s.props) != null && c.value && (s.props.value = t.value)) : t.value && !isNaN(Number(t.value)) && (t.value = t.value.replace(".", d)), V(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) => ke(s), t.onkeydown = (s) => Ne(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 ? V(t, o, { force: !0, clean: !0 }) : V(t, o);
  },
  unmounted: (t) => {
    R(t).cleanup();
  }
};
const v = Q(T);
var P = ee({
  name: "VueNumber",
  directives: {
    number: we
  },
  props: {
    modelValue: {
      type: [String, Number],
      required: !0
    },
    nullValue: {
      type: [Number, String],
      required: !1,
      default: v.nullValue
    },
    masked: {
      type: Boolean,
      default: !1
    },
    reverseFill: {
      type: Boolean,
      default: v.reverseFill
    },
    prefill: {
      type: Boolean,
      default: v.prefill
    },
    precision: {
      type: Number,
      default: () => v.precision
    },
    minimumFractionDigits: {
      type: Number,
      default: () => v.minimumFractionDigits
    },
    decimal: {
      type: String,
      default: () => v.decimal
    },
    min: {
      type: Number,
      default: () => v.min
    },
    max: {
      type: Number,
      default: () => v.max
    },
    separator: {
      type: String,
      default: () => v.separator
    },
    prefix: {
      type: String,
      default: () => v.prefix
    },
    suffix: {
      type: String,
      default: () => v.suffix
    }
  },
  emits: ["update:model-value", "input:model-value"],
  setup(t, { emit: e }) {
    const n = G(t.modelValue), s = G(""), o = O(() => ({ ...t })), i = O(() => t.masked ? n.value : s.value), l = (c) => {
      const { target: m } = c;
      n.value = m.value, s.value = m.unmasked, e("input:model-value", i.value);
    }, d = () => {
      e("update:model-value", i.value);
    };
    return A(() => t.modelValue, (c, m) => {
      c !== m && (n.value = c);
    }), {
      config: o,
      maskedValue: n,
      unmaskedValue: s,
      input: l,
      change: d
    };
  }
});
const _e = ["value"];
function Fe(t, e, n, s, o, i) {
  const l = te("number");
  return q((f(), g("input", {
    type: "text",
    autocomplete: "off",
    value: t.maskedValue,
    class: "v-number vue-number-format",
    onChange: e[0] || (e[0] = (...d) => t.change && t.change(...d)),
    onInput: e[1] || (e[1] = (...d) => t.input && t.input(...d))
  }, null, 40, _e)), [
    [l, t.config]
  ]);
}
P.render = Fe;
P.__file = "src/component.vue";
const Se = { class: "flex flex-col max-w-140" }, Ce = {
  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 = ["value"], Pe = /* @__PURE__ */ p("div", { class: "p-2 text-right self-start" }, "Wish ", -1), Ge = { class: "p-2 text-right" }, Ie = {
  key: 0,
  class: "w-full"
}, Ue = {
  key: 1,
  class: "flex flex-wrap gap-1"
}, We = ["onClick"], He = { class: "font-bold" }, Ae = /* @__PURE__ */ p("div", { class: "p-2 text-right" }, "ROOM", -1), Je = {
  key: 2,
  class: "flex"
}, Qe = { class: "overflow-scroll font-mono text-xs m-4 opacity-50 break-all col-span-2" }, et = {
  __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: d, proposed: c, hash: m, valid: E } = ie(n.gift), { guests: w, count: h } = se(), { project: b } = re(oe(i, "project")), { projects: x } = le(), k = ue();
    A(() => i.wallet, (N) => {
      N && (i.ql = N.currency);
    });
    const Y = O(() => {
      const N = ae(), a = I({});
      return Object.keys(w).forEach((F) => {
        N.user(F).get("wallets").on((u, $) => {
          a[F] = w[F];
        });
      }), a;
    }), K = O(() => {
      const N = I({});
      return Object.keys(x).forEach((a) => {
        a.includes(i.to) && (N[a] = x[a]);
      }), N;
    });
    return (N, a) => {
      const F = ce("gift-wallets");
      return f(), g("div", Se, [
        p("div", Ce, [
          Ve,
          p("div", je, [
            r(o).pub ? (f(), _(r(M), {
              key: 0,
              pub: r(o).pub
            }, null, 8, ["pub"])) : (f(), _(r(he), { key: 1 }))
          ]),
          Re,
          r(i).to ? (f(), _(r(M), {
            key: 0,
            pub: r(i).to
          }, {
            default: U(() => [
              Oe,
              p("div", {
                class: "i-la-times mr-2",
                onClick: a[0] || (a[0] = (u) => {
                  r(i).to = "", r(i).wallet = null;
                })
              })
            ]),
            _: 1
          }, 8, ["pub"])) : (f(), g("div", $e, [
            p("div", De, "USER SELECT OF " + S(Object.keys(r(Y)).length), 1),
            p("div", Me, [
              (f(!0), g(C, null, D(r(w), (u) => (f(), _(r(M), {
                key: u,
                pub: u.pub,
                onClick: ($) => r(i).to = u.pub
              }, null, 8, ["pub", "onClick"]))), 128))
            ])
          ])),
          r(i).to ? (f(), g(C, { key: 2 }, [
            Be,
            (f(), _(F, {
              key: r(i).to,
              pub: r(i).to,
              "active-wallet": r(i).wallet,
              onWallet: a[1] || (a[1] = (u) => r(i).wallet = u),
              onClear: a[2] || (a[2] = (u) => r(i).wallet = null)
            }, null, 8, ["pub", "active-wallet"])),
            r(i).wallet ? (f(), g(C, { key: 0 }, [
              qe,
              W(r(P), pe({
                modelValue: r(i).qn,
                "onUpdate:modelValue": a[3] || (a[3] = (u) => r(i).qn = u)
              }, s, { placeholder: "Quantity" }), null, 16, ["modelValue"]),
              Te,
              q(p("select", {
                class: "rounded-xl dark-bg-dark-100 p-2",
                "onUpdate:modelValue": a[4] || (a[4] = (u) => r(i).ql = u),
                placeholder: "Your account currency"
              }, [
                (f(!0), g(C, null, D(r(be), (u) => (f(), g("option", {
                  key: u,
                  value: u
                }, S(u), 9, Le))), 128))
              ], 512), [
                [me, r(i).ql]
              ]),
              Pe,
              q(p("textarea", {
                class: "p-2",
                "onUpdate:modelValue": a[5] || (a[5] = (u) => r(i).wish = u),
                placeholder: "Wish"
              }, null, 512), [
                [fe, r(i).wish]
              ]),
              p("div", Ge, [
                de("PROJECT "),
                r(i).project ? j("", !0) : (f(), g("div", Ie, "SELECT"))
              ]),
              r(i).project ? (f(), _(r(ge), {
                key: 0,
                project: r(b),
                path: r(i).project
              }, {
                default: U(() => [
                  p("div", {
                    class: "i-la-times",
                    onClick: a[6] || (a[6] = (u) => r(i).project = null)
                  })
                ]),
                _: 1
              }, 8, ["project", "path"])) : (f(), g("div", Ue, [
                (f(!0), g(C, null, D(r(K), (u, $) => (f(), g("div", {
                  class: "p-2 rounded-xl cursor-pointer",
                  key: $,
                  style: H({ backgroundColor: u.color }),
                  onClick: (ze) => r(i).project = u.path
                }, [
                  p("div", He, S(u.title), 1)
                ], 12, We))), 128))
              ])),
              Ae,
              W(r(ve)),
              r(E) ? (f(), g("div", Je, [
                p("button", {
                  class: "button w-full justify-center",
                  onClick: a[7] || (a[7] = (u) => {
                    r(d)(), N.$emit("sent", r(m));
                  })
                }, "Propose")
              ])) : j("", !0),
              p("pre", Qe, S(r(l)), 1),
              p("div", {
                class: "font-mono text-xs col-span-2 text-center rounded-lg m-2 transition",
                style: H({ backgroundColor: r(k).hex(r(m) || "") })
              }, S(r(m)), 5)
            ], 64)) : j("", !0)
          ], 64)) : j("", !0)
        ])
      ]);
    };
  }
};
export {
  et as default
};
//# sourceMappingURL=GiftForm-6b94e4b5.js.map
