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