import { c as ee, m as Pe, p as _, h as me, f as j, i as J, k as Ce, e as Se, b as S, d as te, u as ae, r as Y, s as De, w as pe, t as Ie, o as ge, n as Ve } from "./AssetItem-BxjLUzNd.js";
import { o as ke } from "./index-client-C5PXnhDi.js";
import { t as re, w as $, z as C, x as B, y as M, r as ne, l as b, C as W, v as Z, E as e, D as i, m as y, n as be, o as he, p as ie, A as oe, J as _e, L as Ue, bu as $e, bt as Q, bv as de, V as Be, I as je, Q as ue, O as Ae } from "./index-BBXAtvZr.js";
import { v as we, P as Oe } from "./validation-DaZvZUPL.js";
import { C as Re } from "./App-BwT5MYkN.js";
import { L as ce } from "./Label-zekiKFxP.js";
import { I as fe } from "./Input-CojPyd3m.js";
import { B as Le } from "./ButtonBack-DvsFRnLL.js";
import { B as Ne } from "./Button-CqLZSfSk.js";
import { e as Fe, i as Te } from "./each-D1jTQ_vC.js";
var ze = j('<label class="crtw-font-medium" for="credenzaSelect"> </label>'), qe = j("<option> </option>"), He = j("<option> </option>"), Ge = j('<div><!> <select name="credenzaSelect"><!><!></select></div>');
const Je = {
  hash: "svelte-1bj3sm8",
  code: ".simple.svelte-1bj3sm8 {background-image:none;padding:0 10px;text-align:center;}.simple.svelte-1bj3sm8:focus {background-image:none;}"
};
function xe(D, r) {
  if (new.target) return ee({ component: xe, ...D });
  re(r, !1), Pe(D, Je);
  let d = _(r, "options", 12), u = _(r, "placeholder", 12, void 0), m = _(r, "label", 12, void 0), c = _(r, "selected", 12, void 0), v = _(r, "onChange", 12, void 0), x = _(r, "simple", 12, !1), E = _(r, "disabled", 12, !1);
  const I = (a) => {
    const t = a.target;
    c() !== void 0 && c(t.value), v() && v()(a);
  };
  var N = {
    get options() {
      return d();
    },
    set options(a) {
      d(a), b();
    },
    get placeholder() {
      return u();
    },
    set placeholder(a) {
      u(a), b();
    },
    get label() {
      return m();
    },
    set label(a) {
      m(a), b();
    },
    get selected() {
      return c();
    },
    set selected(a) {
      c(a), b();
    },
    get onChange() {
      return v();
    },
    set onChange(a) {
      v(a), b();
    },
    get simple() {
      return x();
    },
    set simple(a) {
      x(a), b();
    },
    get disabled() {
      return E();
    },
    set disabled(a) {
      E(a), b();
    },
    $set: ae,
    $on: (a, t) => te(r, a, t)
  };
  me();
  var h = Ge(), n = $(h);
  {
    var A = (a) => {
      var t = ze(), p = $(t, !0);
      B(t), M(() => Y(p, m())), S(a, t);
    };
    J(n, (a) => {
      m() && a(A);
    });
  }
  var V = C(n, 2), F = $(V);
  {
    var o = (a) => {
      var t = qe();
      t.disabled = !0, De(t, "hidden", !0);
      var p = $(t, !0);
      B(t);
      var k = {};
      M(() => {
        pe(t, !c()), Y(p, u()), k !== (k = u()) && (t.__value = u());
      }), S(a, t);
    };
    J(F, (a) => {
      u() && a(o);
    });
  }
  var T = C(F);
  return Fe(T, 1, d, Te, (a, t) => {
    var p = He(), k = $(p, !0);
    B(p);
    var L = {};
    M(() => {
      pe(p, (Z(c()), e(t), W(() => c() === e(t).value))), Y(k, (e(t), W(() => e(t).name ?? e(t).value))), L !== (L = (e(t), W(() => e(t).value))) && (p.value = (p.__value = (e(t), W(() => e(t).value))) ?? "");
    }), S(a, p);
  }), B(V), B(h), M(() => {
    Ce(
      V,
      1,
      `crtw-w-full crtw-h-[53px] crtw-px-5 crtw-appearance-none crtw-text-base crtw-rounded crtw-border crtw-border-gray-300
   crtw-cursor-pointer crtw-text-gray-500 focus:crtw-outline-none focus:crtw-border-blue-900 focus:crtw-text-blue-900
    ${x() ? "simple" : ""}`,
      "svelte-1bj3sm8"
    ), V.disabled = E();
  }), Se("change", V, I), S(D, h), ne(N);
}
const ve = [
  { value: "+1", name: "US/CA +1" },
  { value: "+49", name: "DE +49" },
  { value: "+33", name: "FR +33" },
  { value: "+44", name: "UK +44" },
  { value: "+380", name: "UA +380" },
  { value: "+48", name: "PL +48" },
  { value: "+233", name: "GH +233" }
];
var Ke = j('<div class="crtw-flex crtw-justify-center crtw-flex-row"><div class="crtw-w-40 crtw-mr-0.5"><!></div> <!></div>');
function ye(D, r) {
  if (new.target) return ee({ component: ye, ...D });
  re(r, !1);
  let d = _(r, "phone", 12), u = _(r, "isValid", 12, !0), m = _(r, "disabled", 12, !1), c = y(ve[0].value), v = y();
  if (d()) {
    for (const n of ve)
      if (d().indexOf(n.value) === 0) {
        i(v, parseInt(d().slice(n.value.length))), i(c, n.value);
        break;
      }
  }
  be(
    () => (Z(u()), e(v), e(c)),
    () => {
      u(!e(v) || we(String(e(v)), Oe)), u() && e(c) && e(v) && d(e(c) + String(e(v)).trim());
    }
  ), he();
  var x = {
    get phone() {
      return d();
    },
    set phone(n) {
      d(n), b();
    },
    get isValid() {
      return u();
    },
    set isValid(n) {
      u(n), b();
    },
    get disabled() {
      return m();
    },
    set disabled(n) {
      m(n), b();
    },
    $set: ae,
    $on: (n, A) => te(r, n, A)
  };
  me();
  var E = Ke(), I = $(E), N = $(I);
  xe(N, {
    get options() {
      return ve;
    },
    simple: !0,
    get disabled() {
      return m();
    },
    get selected() {
      return e(c);
    },
    set selected(n) {
      i(c, n);
    },
    $$legacy: !0
  }), B(I);
  var h = C(I, 2);
  return fe(h, {
    type: "number",
    min: "0",
    inputmode: "numeric",
    pattern: "[0-9]*",
    placeholder: "Phone Number",
    name: "phone",
    get disabled() {
      return m();
    },
    get value() {
      return e(v);
    },
    set value(n) {
      i(v, n);
    },
    $$legacy: !0
  }), B(E), S(D, E), ne(x);
}
var Qe = j('<span class="crtw-text-red-500">*</span>'), Me = j("First and last name <!>", 1), We = j('<span class="crtw-text-red-500">*</span>'), Xe = j("Email address <!>", 1), Ye = j('<div class="crtw-text-xs crtw-text-[#990008]"> </div>'), Ze = j('<div class="crtw-text-left crtw-mt-2.5 crtw-w-full"><!></div>'), et = j('<div class="crtw-flex crtw-flex-col"><!> <!></div> <div class="crtw-flex crtw-flex-col"><!> <!></div> <div class="crtw-flex crtw-flex-col"><!> <!></div> <!> <!> <!>', 1);
function Ee(D, r) {
  if (new.target) return ee({ component: Ee, ...D });
  re(r, !1);
  let d = _(r, "name", 12), u = _(r, "email", 12), m = _(r, "phone", 12), c = _(r, "isSubmitDisabled", 12), v = _(r, "error", 12), x = _(r, "isEmailInputValid", 12), E = _(r, "options", 12), {
    isExtendedRegistration: I,
    onProfileUpdate: N,
    onBackClick: h,
    shouldShowBackButton: n,
    isEmailChangeDisabled: A,
    isPhoneChangeDisabled: V
  } = E();
  var F = {
    get name() {
      return d();
    },
    set name(o) {
      d(o), b();
    },
    get email() {
      return u();
    },
    set email(o) {
      u(o), b();
    },
    get phone() {
      return m();
    },
    set phone(o) {
      m(o), b();
    },
    get isSubmitDisabled() {
      return c();
    },
    set isSubmitDisabled(o) {
      c(o), b();
    },
    get error() {
      return v();
    },
    set error(o) {
      v(o), b();
    },
    get isEmailInputValid() {
      return x();
    },
    set isEmailInputValid(o) {
      x(o), b();
    },
    get options() {
      return E();
    },
    set options(o) {
      E(o), b();
    },
    $set: ae,
    $on: (o, T) => te(r, o, T)
  };
  return Re(D, {
    class: "crtw-flex crtw-justify-center crtw-flex-col crtw-gap-2.5",
    children: (o, T) => {
      var a = et(), t = ie(a), p = $(t);
      ce(p, {
        for: "NameInput",
        children: (s, U) => {
          oe();
          var P = Me(), H = C(ie(P));
          {
            var O = (R) => {
              var se = Qe();
              S(R, se);
            };
            J(H, (R) => {
              I && R(O);
            });
          }
          S(s, P);
        },
        $$slots: { default: !0 }
      });
      var k = C(p, 2);
      fe(k, {
        id: "NameInput",
        type: "text",
        placeholder: "First and last name",
        name: "name",
        get required() {
          return I;
        },
        get value() {
          return d();
        },
        set value(s) {
          d(s);
        },
        $$legacy: !0
      }), B(t);
      var L = C(t, 2), z = $(L);
      ce(z, {
        for: "EmailInput",
        children: (s, U) => {
          oe();
          var P = Xe(), H = C(ie(P));
          {
            var O = (R) => {
              var se = We();
              S(R, se);
            };
            J(H, (R) => {
              I && R(O);
            });
          }
          S(s, P);
        },
        $$slots: { default: !0 }
      });
      var le = C(z, 2);
      fe(le, {
        id: "EmailInput",
        type: "email",
        placeholder: "Email address",
        name: "email",
        get disabled() {
          return A;
        },
        get isValid() {
          return x();
        },
        set isValid(s) {
          x(s);
        },
        get value() {
          return u();
        },
        set value(s) {
          u(s);
        },
        $$legacy: !0
      }), B(L);
      var K = C(L, 2), X = $(K);
      ce(X, {
        for: "PhoneInput",
        children: (s, U) => {
          oe();
          var P = Ie("Phone number");
          S(s, P);
        },
        $$slots: { default: !0 }
      });
      var f = C(X, 2);
      ye(f, {
        get disabled() {
          return V;
        },
        get phone() {
          return m();
        },
        set phone(s) {
          m(s);
        },
        $$legacy: !0
      }), B(K);
      var l = C(K, 2);
      Ne(l, {
        text: "Update profile",
        get onClick() {
          return N;
        },
        get disabled() {
          return c();
        }
      });
      var g = C(l, 2);
      {
        var w = (s) => {
          var U = Ye(), P = $(U);
          B(U), M(() => Y(P, `- ${v() ?? ""}`)), S(s, U);
        };
        J(g, (s) => {
          v() && s(w);
        });
      }
      var G = C(g, 2);
      {
        var q = (s) => {
          var U = Ze(), P = $(U);
          Le(P, {
            get onClick() {
              return h;
            }
          }), B(U), S(s, U);
        };
        J(G, (s) => {
          n && s(q);
        });
      }
      S(o, a);
    },
    $$slots: { default: !0 }
  }), ne(F);
}
function tt(D, r) {
  if (new.target) return ee({ component: tt, ...D });
  re(r, !1);
  const d = () => ge(je, "$configStore", m), u = () => ge(Q, "$forcedPageStore", m), [m, c] = Ve();
  var v = this && this.__awaiter || function(f, l, g, w) {
    function G(q) {
      return q instanceof g ? q : new g(function(s) {
        s(q);
      });
    }
    return new (g || (g = Promise))(function(q, s) {
      function U(O) {
        try {
          H(w.next(O));
        } catch (R) {
          s(R);
        }
      }
      function P(O) {
        try {
          H(w.throw(O));
        } catch (R) {
          s(R);
        }
      }
      function H(O) {
        O.done ? q(O.value) : G(O.value).then(U, P);
      }
      H((w = w.apply(f, l || [])).next());
    });
  }, x = y();
  const { updateProfile: E, close: I, toastAlert: N } = _e(Ue);
  let h = y(), n = y(), A = y(), V, F = y(), o = y(), T = y();
  const a = $e.subscribe((f) => {
    var l, g;
    if (!f) {
      Q.set(null), I();
      return;
    }
    i(n, f.name || ""), i(h, f.email || ""), i(A, f.phone || ""), V = f, i(F, !!(!((l = f.pending) === null || l === void 0) && l.email)), i(o, !!(!((g = f.pending) === null || g === void 0) && g.phone));
  });
  let t = y(!1), p = y(!1), k = y(!0), L = y(!0), z = y("");
  const le = () => v(void 0, void 0, void 0, function* () {
    var f, l;
    i(z, ""), i(t, !0);
    try {
      const g = Object.assign(Object.assign(Object.assign({}, V.email !== e(h) ? { email: e(h) } : {}), V.name !== e(n) ? { name: e(n) } : {}), V.phone !== e(A) ? { phone: e(A) } : {}), w = yield E(g);
      Q.set(null), N("Account has been updated successfully. Email or phone should be confirmed by entering one-time code.", "success");
      const G = _e(Ae);
      !(!((f = w?.pending) === null || f === void 0) && f.phone) && !(!((l = w?.pending) === null || l === void 0) && l.email) && (!G || G === ue.UPDATE_PROFILE) && I();
    } catch (g) {
      const w = g?.message || "Error while updating your account details.";
      N(w, "failure"), i(z, w);
    }
    i(t, !1);
  });
  ke(a), be(
    () => (e(p), e(h), e(k), de(x), d(), e(L), e(n), e(t)),
    () => {
      i(p, we(e(h))), i(k, !e(h) || e(p)), !(i(x, d().auth) === null || de(x) === void 0) && de(x).extendedRegistration && i(L, !!e(n)), i(T, e(t) || !e(k) || !e(L));
    }
  ), he();
  var K = {
    $set: ae,
    $on: (f, l) => te(r, f, l)
  };
  me();
  {
    let f = Be(() => (d(), Z(Q), u(), Z(ue), e(F), e(o), W(() => ({
      isExtendedRegistration: d().auth?.extendedRegistration,
      onProfileUpdate: le,
      onBackClick: () => Q.set(null),
      shouldShowBackButton: u() === ue.UPDATE_PROFILE,
      isEmailChangeDisabled: e(F),
      isPhoneChangeDisabled: e(o)
    }))));
    Ee(D, {
      get options() {
        return e(f);
      },
      get error() {
        return e(z);
      },
      set error(l) {
        i(z, l);
      },
      get name() {
        return e(n);
      },
      set name(l) {
        i(n, l);
      },
      get email() {
        return e(h);
      },
      set email(l) {
        i(h, l);
      },
      get phone() {
        return e(A);
      },
      set phone(l) {
        i(A, l);
      },
      get isSubmitDisabled() {
        return e(T);
      },
      set isSubmitDisabled(l) {
        i(T, l);
      },
      get isEmailInputValid() {
        return e(k);
      },
      set isEmailInputValid(l) {
        i(k, l);
      },
      $$legacy: !0
    });
  }
  var X = ne(K);
  return c(), X;
}
export {
  tt as default
};
//# sourceMappingURL=UpdateProfile-D2yrDMwe.js.map
