import { c as ee, m as Pe, p as _, h as me, f as j, i as K, k as Se, e as Ce, b as C, d as te, u as ae, o as X, s as De, q as pe, t as Ie } from "./AssetItem-CFsdMEwW.js";
import { o as ke } from "./index-client-DJaMHbvZ.js";
import { v as re, x as $, A as S, y as B, z as J, t as ne, n as b, D as Q, w as Z, I as e, G as i, m as y, o as be, p as he, r as ie, C as oe, M as ge, O as Ve, bz as Ue, by as Y, F as _e, bA as de, Y as $e, E as Be, L as je, T as ue, S as Ae } from "./index-BxjwuJ6T.js";
import { v as we, P as Oe } from "./validation-DaZvZUPL.js";
import { C as Re } from "./App-pmcYlKkW.js";
import { L as ce } from "./Label-DamsCZ57.js";
import { I as fe } from "./Input-BtyPpztB.js";
import { B as Le } from "./ButtonBack-TLkmy8GZ.js";
import { B as Fe } from "./Button-S2OwL6nP.js";
import { e as Ne, i as Te } from "./each-BgMcYdMq.js";
var ze = j('<label class="crtw-font-medium" for="credenzaSelect"> </label>'), qe = j("<option> </option>"), Ge = j("<option> </option>"), He = j('<div><!> <select name="credenzaSelect"><!><!></select></div>');
const Ke = {
  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, Ke);
  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 F = {
    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 = He(), n = $(h);
  {
    var A = (a) => {
      var t = ze(), p = $(t, !0);
      B(t), J(() => X(p, m())), C(a, t);
    };
    K(n, (a) => {
      m() && a(A);
    });
  }
  var k = S(n, 2), N = $(k);
  {
    var o = (a) => {
      var t = qe();
      t.disabled = !0, De(t, "hidden", !0);
      var p = $(t, !0);
      B(t);
      var V = {};
      J(() => {
        pe(t, !c()), X(p, u()), V !== (V = u()) && (t.__value = u());
      }), C(a, t);
    };
    K(N, (a) => {
      u() && a(o);
    });
  }
  var T = S(N);
  return Ne(T, 1, d, Te, (a, t) => {
    var p = Ge(), V = $(p, !0);
    B(p);
    var L = {};
    J(() => {
      pe(p, (Z(c()), e(t), Q(() => c() === e(t).value))), X(V, (e(t), Q(() => e(t).name ?? e(t).value))), L !== (L = (e(t), Q(() => e(t).value))) && (p.value = (p.__value = (e(t), Q(() => e(t).value))) ?? "");
    }), C(a, p);
  }), B(k), B(h), J(() => {
    Se(
      k,
      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"
    ), k.disabled = E();
  }), Ce("change", k, I), C(D, h), ne(F);
}
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 Me = 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 = Me(), I = $(E), F = $(I);
  xe(F, {
    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 = S(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), C(D, E), ne(x);
}
var Ye = j('<span class="crtw-text-red-500">*</span>'), Je = j("First and last name <!>", 1), Qe = j('<span class="crtw-text-red-500">*</span>'), We = j("Email address <!>", 1), Xe = 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: F,
    onBackClick: h,
    shouldShowBackButton: n,
    isEmailChangeDisabled: A,
    isPhoneChangeDisabled: k
  } = E();
  var N = {
    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 = Je(), G = S(ie(P));
          {
            var O = (R) => {
              var se = Ye();
              C(R, se);
            };
            K(G, (R) => {
              I && R(O);
            });
          }
          C(s, P);
        },
        $$slots: { default: !0 }
      });
      var V = S(p, 2);
      fe(V, {
        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 = S(t, 2), z = $(L);
      ce(z, {
        for: "EmailInput",
        children: (s, U) => {
          oe();
          var P = We(), G = S(ie(P));
          {
            var O = (R) => {
              var se = Qe();
              C(R, se);
            };
            K(G, (R) => {
              I && R(O);
            });
          }
          C(s, P);
        },
        $$slots: { default: !0 }
      });
      var le = S(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 M = S(L, 2), W = $(M);
      ce(W, {
        for: "PhoneInput",
        children: (s, U) => {
          oe();
          var P = Ie("Phone number");
          C(s, P);
        },
        $$slots: { default: !0 }
      });
      var f = S(W, 2);
      ye(f, {
        get disabled() {
          return k;
        },
        get phone() {
          return m();
        },
        set phone(s) {
          m(s);
        },
        $$legacy: !0
      }), B(M);
      var l = S(M, 2);
      Fe(l, {
        text: "Update profile",
        get onClick() {
          return F;
        },
        get disabled() {
          return c();
        }
      });
      var g = S(l, 2);
      {
        var w = (s) => {
          var U = Xe(), P = $(U);
          B(U), J(() => X(P, `- ${v() ?? ""}`)), C(s, U);
        };
        K(g, (s) => {
          v() && s(w);
        });
      }
      var H = S(g, 2);
      {
        var q = (s) => {
          var U = Ze(), P = $(U);
          Le(P, {
            get onClick() {
              return h;
            }
          }), B(U), C(s, U);
        };
        K(H, (s) => {
          n && s(q);
        });
      }
      C(o, a);
    },
    $$slots: { default: !0 }
  }), ne(N);
}
function tt(D, r) {
  if (new.target) return ee({ component: tt, ...D });
  re(r, !1);
  const d = () => _e(je, "$configStore", m), u = () => _e(Y, "$forcedPageStore", m), [m, c] = Be();
  var v = this && this.__awaiter || function(f, l, g, w) {
    function H(q) {
      return q instanceof g ? q : new g(function(s) {
        s(q);
      });
    }
    return new (g || (g = Promise))(function(q, s) {
      function U(O) {
        try {
          G(w.next(O));
        } catch (R) {
          s(R);
        }
      }
      function P(O) {
        try {
          G(w.throw(O));
        } catch (R) {
          s(R);
        }
      }
      function G(O) {
        O.done ? q(O.value) : H(O.value).then(U, P);
      }
      G((w = w.apply(f, l || [])).next());
    });
  }, x = y();
  const { updateProfile: E, close: I, toastAlert: F } = ge(Ve);
  let h = y(), n = y(), A = y(), k, N = y(), o = y(), T = y();
  const a = Ue.subscribe((f) => {
    var l, g;
    if (!f) {
      Y.set(null), I();
      return;
    }
    i(n, f.name || ""), i(h, f.email || ""), i(A, f.phone || ""), k = f, i(N, !!(!((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), V = 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({}, k.email !== e(h) ? { email: e(h) } : {}), k.name !== e(n) ? { name: e(n) } : {}), k.phone !== e(A) ? { phone: e(A) } : {}), w = yield E(g);
      Y.set(null), F("Account has been updated successfully. Email or phone should be confirmed by entering one-time code.", "success");
      const H = ge(Ae);
      !(!((f = w?.pending) === null || f === void 0) && f.phone) && !(!((l = w?.pending) === null || l === void 0) && l.email) && (!H || H === ue.UPDATE_PROFILE) && I();
    } catch (g) {
      const w = g?.message || "Error while updating your account details.";
      F(w, "failure"), i(z, w);
    }
    i(t, !1);
  });
  ke(a), be(
    () => (e(p), e(h), e(V), de(x), d(), e(L), e(n), e(t)),
    () => {
      i(p, we(e(h))), i(V, !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(V) || !e(L));
    }
  ), he();
  var M = {
    $set: ae,
    $on: (f, l) => te(r, f, l)
  };
  me();
  {
    let f = $e(() => (d(), Z(Y), u(), Z(ue), e(N), e(o), Q(() => ({
      isExtendedRegistration: d().auth?.extendedRegistration,
      onProfileUpdate: le,
      onBackClick: () => Y.set(null),
      shouldShowBackButton: u() === ue.UPDATE_PROFILE,
      isEmailChangeDisabled: e(N),
      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(V);
      },
      set isEmailInputValid(l) {
        i(V, l);
      },
      $$legacy: !0
    });
  }
  var W = ne(M);
  return c(), W;
}
export {
  tt as default
};
//# sourceMappingURL=UpdateProfile-C-QQjGW6.js.map
