@yourgoods/ui-smart 0.46.1 → 0.46.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,799 @@
1
+ import { defineComponent as ie, ref as x, reactive as ee, watch as J, computed as V, toRefs as ce, createElementBlock as I, openBlock as E, createElementVNode as B, createCommentVNode as D, toDisplayString as te, createVNode as $, unref as u, isRef as ae, withCtx as Y, createTextVNode as ne, Fragment as Fe, createBlock as q, resolveDynamicComponent as he, onMounted as Re } from "vue";
2
+ import { T as ve, c as $e, u as ze, a as We, P as Te, b as He } from "./useRateLimitToast-CclSktkZ.js";
3
+ import { C as R, _ as _e, B as qe, p as _, g as je } from "./index-CsonpLgW.js";
4
+ import { PInput as K, IconMailMd as pe, PButton as se, IconEyeMd as Me, IconEyeClosedMd as be, PDialog as Ge, PTopBar as Ye, IconCrossMd as Je } from "@profeat/ui-kit";
5
+ const Ke = { class: "dialogDefaultContainerInsideContent" }, Qe = { class: "dialogDefaultContainerTextHint" }, Xe = {
6
+ key: 0,
7
+ class: "input-wrapper"
8
+ }, Ze = {
9
+ key: 1,
10
+ class: "input-wrapper"
11
+ }, et = {
12
+ key: 2,
13
+ class: "input-wrapper"
14
+ }, tt = { key: 3 }, at = /* @__PURE__ */ ie({
15
+ __name: "AddNewEmailContent",
16
+ props: {
17
+ email: {},
18
+ oldEmail: {},
19
+ hintText: { default: "" },
20
+ emailError: { default: "" },
21
+ codeError: { default: "" },
22
+ rateLimitText: { default: "" },
23
+ showEmail: { type: Boolean, default: !0 },
24
+ isFinalLimit: { type: Boolean },
25
+ isNotMatchCode: { type: Boolean },
26
+ loading: { type: Boolean }
27
+ },
28
+ emits: ["update:email", "update:code", "edit", "on-match-code", "on-match-code-error", "on-send-code", "on-send-code-again", "on-clear-code-error"],
29
+ setup(j, { emit: W }) {
30
+ const v = j, s = W, m = x(!1), e = x(""), n = ee({
31
+ emailModel: v.email || "",
32
+ codeModel: "",
33
+ touched: { email: !1, code: !1 }
34
+ });
35
+ J(
36
+ () => n.emailModel,
37
+ (p) => {
38
+ s("update:email", p);
39
+ }
40
+ ), J(
41
+ () => n.codeModel,
42
+ (p) => s("update:code", p)
43
+ );
44
+ const g = (p) => {
45
+ n.touched[p] = !0;
46
+ }, d = (p) => n.touched[p] = !1, r = () => {
47
+ e.value = "", d("email");
48
+ }, h = V(() => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(n.emailModel.trim())), U = V(() => !h.value || !!e.value), L = async () => {
49
+ var p;
50
+ try {
51
+ if (g("email"), !h.value) {
52
+ e.value = "Это не похоже на e-mail";
53
+ return;
54
+ }
55
+ const a = await $e(n.emailModel), { data: i } = a.data;
56
+ if (!(((p = i.data[0]) == null ? void 0 : p.available) ?? !1)) {
57
+ e.value = "Такой email уже используется";
58
+ return;
59
+ }
60
+ e.value = "", s("on-send-code", {
61
+ email: n.emailModel,
62
+ prevEmail: v.oldEmail,
63
+ offLoading: !0
64
+ }), m.value = !0;
65
+ } catch (a) {
66
+ console.error("Неизвестная ошибка при проверке доступности email:", a), e.value = "Это не похоже на e-mail";
67
+ }
68
+ };
69
+ let A = "";
70
+ const w = (p) => {
71
+ s("on-clear-code-error");
72
+ const a = p.target;
73
+ let i = a.value.replace(/\D/g, "");
74
+ i.length > 4 && (i = i.slice(0, 4)), a.value = i, n.codeModel = i, i.length === 4 && i !== A && (A = i, s("on-match-code", { email: n.emailModel, code: i }));
75
+ }, c = () => {
76
+ s("on-send-code-again", { email: n.emailModel });
77
+ }, b = V(() => {
78
+ if (e.value) return e.value;
79
+ if (n.touched.email) {
80
+ if (!n.emailModel.trim()) return "Введите e-mail";
81
+ if (!h.value) return "Это не похоже на e-mail";
82
+ }
83
+ return v.emailError || "";
84
+ }), T = V(() => v.isNotMatchCode ? "Неверный код" : n.touched.code ? F.value.trim() ? v.codeError ?? null : "Введите код" : ""), { emailModel: P, codeModel: F } = ce(n);
85
+ return (p, a) => {
86
+ const i = ve;
87
+ return E(), I("div", Ke, [
88
+ B("div", Qe, te(m.value ? "Введите код подтверждения" : p.hintText), 1),
89
+ p.showEmail ? (E(), I("div", Xe, [
90
+ $(u(K), {
91
+ modelValue: u(P),
92
+ "onUpdate:modelValue": a[0] || (a[0] = (C) => ae(P) ? P.value = C : null),
93
+ size: "large",
94
+ "text-size": "medium",
95
+ label: "Почта",
96
+ type: "email",
97
+ error: b.value,
98
+ onBlur: a[1] || (a[1] = (C) => g("email")),
99
+ onInput: r
100
+ }, null, 8, ["modelValue", "error"]),
101
+ $(u(pe), {
102
+ class: "icon-locked",
103
+ onClick: a[2] || (a[2] = (C) => p.$emit("edit", "email"))
104
+ })
105
+ ])) : D("", !0),
106
+ m.value ? D("", !0) : (E(), I("div", Ze, [
107
+ $(u(se), {
108
+ style: { width: "100%" },
109
+ disabled: U.value,
110
+ onClick: L
111
+ }, {
112
+ default: Y(() => a[5] || (a[5] = [
113
+ ne(" Отправить код ")
114
+ ])),
115
+ _: 1,
116
+ __: [5]
117
+ }, 8, ["disabled"])
118
+ ])),
119
+ m.value ? (E(), I("div", et, [
120
+ $(u(K), {
121
+ modelValue: u(F),
122
+ "onUpdate:modelValue": a[3] || (a[3] = (C) => ae(F) ? F.value = C : null),
123
+ size: "large",
124
+ "text-size": "medium",
125
+ label: "Код",
126
+ type: "text",
127
+ error: T.value,
128
+ onInput: w,
129
+ onBlur: a[4] || (a[4] = (C) => g("code"))
130
+ }, null, 8, ["modelValue", "error"])
131
+ ])) : D("", !0),
132
+ !p.loading && m.value ? (E(), I("div", tt, [
133
+ $(i, {
134
+ loading: p.loading,
135
+ "rate-limit-text": p.rateLimitText,
136
+ "is-final-limit": p.isFinalLimit,
137
+ "on-send-again": c
138
+ }, null, 8, ["loading", "rate-limit-text", "is-final-limit"])
139
+ ])) : D("", !0)
140
+ ]);
141
+ };
142
+ }
143
+ }), lt = { class: "dialogDefaultContainer" }, ot = { class: "dialogDefaultContainerInsideContent" }, it = { class: "input-wrapper" }, nt = { class: "input-wrapper" }, st = { style: { width: "100%", display: "flex" } }, dt = {
144
+ key: 0,
145
+ class: "dialogDefaultContainer"
146
+ }, rt = { class: "dialogDefaultContainerInsideContent" }, ut = { style: { "margin-top": "12px" } }, Ve = 8, mt = /* @__PURE__ */ ie({
147
+ __name: "AddNewPasswordContent",
148
+ props: {
149
+ modelValue: { type: Boolean },
150
+ title: { default: "Установка пароля" },
151
+ hintText: { default: "" },
152
+ emailSessionId: {}
153
+ },
154
+ emits: ["update:modelValue", "submit", "close", "update-user"],
155
+ setup(j, { emit: W }) {
156
+ const v = W, s = x(!1), m = x(""), e = x(""), n = ee({
157
+ newPassword: !1,
158
+ newPasswordConfirm: !1
159
+ }), g = x(R.NEW), d = x(!1), r = x(!1), h = V(() => d.value ? "text" : "password"), U = V(() => r.value ? "text" : "password"), L = () => {
160
+ d.value = !d.value;
161
+ }, A = () => {
162
+ r.value = !r.value;
163
+ }, w = V(() => n.newPassword ? m.value.trim() ? m.value.trim().length < Ve ? `Пароль слишком короткий. Введите хотя бы ${Ve} символов` : "" : "Введите пароль" : ""), c = V(() => n.newPasswordConfirm ? e.value.trim() ? e.value !== m.value ? "Пароли не совпадают" : "" : "Повторите пароль" : ""), b = V(() => !!(w.value || c.value)), T = V(() => s.value || !m.value.trim() || !e.value.trim() ? !0 : b.value), P = () => {
164
+ v("update:modelValue", !1), v("close");
165
+ }, F = async () => {
166
+ v("update-user", m.value);
167
+ };
168
+ return (p, a) => (E(), I(Fe, null, [
169
+ B("div", lt, [
170
+ B("div", ot, [
171
+ a[7] || (a[7] = B("div", { class: "dialogDefaultContainerTextHint" }, te("Установите новый пароль для защиты аккаунта. Пароль должен содержать не менее 8 символов."), -1)),
172
+ B("div", it, [
173
+ $(u(K), {
174
+ modelValue: m.value,
175
+ "onUpdate:modelValue": a[0] || (a[0] = (i) => m.value = i),
176
+ size: "large",
177
+ "text-size": "medium",
178
+ label: "Новый пароль",
179
+ type: h.value,
180
+ error: w.value,
181
+ onBlur: a[1] || (a[1] = () => n.newPassword = !0),
182
+ onInput: a[2] || (a[2] = () => n.newPassword = !0)
183
+ }, null, 8, ["modelValue", "type", "error"]),
184
+ (E(), q(he(d.value ? u(Me) : u(be)), {
185
+ class: "icon-locked",
186
+ onClick: L
187
+ }))
188
+ ]),
189
+ B("div", nt, [
190
+ $(u(K), {
191
+ modelValue: e.value,
192
+ "onUpdate:modelValue": a[3] || (a[3] = (i) => e.value = i),
193
+ size: "large",
194
+ "text-size": "medium",
195
+ label: "Повторите новый пароль",
196
+ type: U.value,
197
+ error: c.value,
198
+ onBlur: a[4] || (a[4] = () => n.newPasswordConfirm = !0),
199
+ onInput: a[5] || (a[5] = () => n.newPasswordConfirm = !0)
200
+ }, null, 8, ["modelValue", "type", "error"]),
201
+ (E(), q(he(r.value ? u(Me) : u(be)), {
202
+ class: "icon-locked",
203
+ onClick: A
204
+ }))
205
+ ]),
206
+ B("div", st, [
207
+ $(u(se), {
208
+ style: { width: "100%" },
209
+ disabled: T.value,
210
+ onClick: F
211
+ }, {
212
+ default: Y(() => a[6] || (a[6] = [
213
+ ne(te("Сохранить"))
214
+ ])),
215
+ _: 1,
216
+ __: [6]
217
+ }, 8, ["disabled"])
218
+ ])
219
+ ])
220
+ ]),
221
+ g.value === u(R).COMPLETED ? (E(), I("div", dt, [
222
+ B("div", rt, [
223
+ a[9] || (a[9] = B("p", null, "Пароль успешно установлен", -1)),
224
+ B("div", ut, [
225
+ $(u(se), {
226
+ style: { width: "100%" },
227
+ onClick: P
228
+ }, {
229
+ default: Y(() => a[8] || (a[8] = [
230
+ ne("Закрыть")
231
+ ])),
232
+ _: 1,
233
+ __: [8]
234
+ })
235
+ ])
236
+ ])
237
+ ])) : D("", !0)
238
+ ], 64));
239
+ }
240
+ }), ct = { class: "dialogDefaultContainerInsideContent" }, vt = { class: "dialogDefaultContainerTextHint" }, pt = {
241
+ key: 0,
242
+ class: "input-wrapper"
243
+ }, ft = {
244
+ key: 1,
245
+ class: "input-wrapper"
246
+ }, Et = /* @__PURE__ */ ie({
247
+ __name: "OldEmailContent",
248
+ props: {
249
+ email: {},
250
+ code: {},
251
+ hintText: { default: "" },
252
+ emailError: { default: "" },
253
+ codeError: { default: "" },
254
+ rateLimitText: { default: "" },
255
+ showEmail: { type: Boolean, default: !0 },
256
+ showCode: { type: Boolean, default: !0 },
257
+ isFinalLimit: { type: Boolean },
258
+ isNotMatchCode: { type: Boolean, default: !1 },
259
+ loading: { type: Boolean }
260
+ },
261
+ emits: ["update:email", "update:code", "edit", "on-match-code", "on-match-code-error", "on-send-code-again", "on-clear-code-error"],
262
+ setup(j, { emit: W }) {
263
+ const v = j, s = W, m = ee({
264
+ touched: {
265
+ email: !1,
266
+ code: !1
267
+ },
268
+ emailModel: v.email,
269
+ codeModel: v.code
270
+ });
271
+ J(
272
+ () => m.emailModel,
273
+ (w) => s("update:email", w)
274
+ ), J(
275
+ () => m.codeModel,
276
+ (w) => s("update:code", w)
277
+ );
278
+ const e = (w) => {
279
+ m.touched[w] = !0;
280
+ }, n = x(""), g = (w) => {
281
+ s("on-clear-code-error");
282
+ const c = w.target;
283
+ let b = ((c == null ? void 0 : c.value) ?? "").replace(/\D/g, "");
284
+ b.length > 4 && (b = b.slice(0, 4)), h.value = b, c && c.value !== b && (c.value = b), b.length === 4 && b !== n.value && (n.value = b, s("on-match-code", { email: r.value, code: b }));
285
+ }, d = () => {
286
+ s("on-send-code-again", { email: r.value });
287
+ }, { emailModel: r, codeModel: h, touched: U } = ce(m), L = V(() => U.value.email && !r.value.trim() ? "Введите e-mail" : v.emailError), A = V(() => v.isNotMatchCode ? "Неверный код" : U.value.code ? h.value.trim() ? v.codeError ?? null : "Введите код" : "");
288
+ return (w, c) => {
289
+ const b = ve;
290
+ return E(), I("div", ct, [
291
+ B("div", vt, te(w.hintText), 1),
292
+ w.showEmail ? (E(), I("div", pt, [
293
+ $(u(K), {
294
+ modelValue: u(r),
295
+ "onUpdate:modelValue": c[0] || (c[0] = (T) => ae(r) ? r.value = T : null),
296
+ size: "large",
297
+ "text-size": "medium",
298
+ label: "Почта",
299
+ type: "email",
300
+ error: L.value,
301
+ disabled: !0,
302
+ onBlur: c[1] || (c[1] = (T) => e("email")),
303
+ onInput: c[2] || (c[2] = (T) => e("email"))
304
+ }, null, 8, ["modelValue", "error"]),
305
+ $(u(pe), {
306
+ class: "icon-locked",
307
+ onClick: c[3] || (c[3] = (T) => w.$emit("edit", "email"))
308
+ })
309
+ ])) : D("", !0),
310
+ w.showCode ? (E(), I("div", ft, [
311
+ $(u(K), {
312
+ modelValue: u(h),
313
+ "onUpdate:modelValue": c[4] || (c[4] = (T) => ae(h) ? h.value = T : null),
314
+ size: "large",
315
+ "text-size": "medium",
316
+ label: "Код",
317
+ type: "text",
318
+ error: A.value,
319
+ onInput: g,
320
+ onBlur: c[5] || (c[5] = (T) => e("code"))
321
+ }, null, 8, ["modelValue", "error"])
322
+ ])) : D("", !0),
323
+ $(b, {
324
+ loading: w.loading,
325
+ "rate-limit-text": w.rateLimitText,
326
+ "is-final-limit": w.isFinalLimit,
327
+ "on-send-again": d
328
+ }, null, 8, ["loading", "rate-limit-text", "is-final-limit"])
329
+ ]);
330
+ };
331
+ }
332
+ }), wt = /* @__PURE__ */ _e(Et, [["__scopeId", "data-v-5e561fbe"]]), Ct = { class: "dialogDefaultContainerInsideContent" }, yt = { class: "dialogDefaultContainerTextHint" }, gt = {
333
+ key: 0,
334
+ class: "input-wrapper"
335
+ }, ht = {
336
+ key: 1,
337
+ class: "input-wrapper"
338
+ }, Tt = {
339
+ key: 2,
340
+ class: "input-wrapper"
341
+ }, Mt = { key: 3 }, bt = /* @__PURE__ */ ie({
342
+ __name: "NewEmailContent",
343
+ props: {
344
+ email: {},
345
+ oldEmail: {},
346
+ hintText: { default: "" },
347
+ emailError: { default: "" },
348
+ codeError: { default: "" },
349
+ rateLimitText: { default: "" },
350
+ showEmail: { type: Boolean, default: !0 },
351
+ isFinalLimit: { type: Boolean, default: !1 },
352
+ isNotMatchCode: { type: Boolean, default: !1 },
353
+ loading: { type: Boolean }
354
+ },
355
+ emits: ["update:email", "update:code", "edit", "on-match-code", "on-match-code-error", "on-send-code", "on-send-code-again", "on-clear-code-error"],
356
+ setup(j, { emit: W }) {
357
+ const v = j, s = W, m = x(!1), e = x(""), n = ee({
358
+ touched: { email: !1, code: !1 },
359
+ emailModel: "",
360
+ codeModel: ""
361
+ });
362
+ J(
363
+ () => n.emailModel,
364
+ (a) => {
365
+ s("update:email", a);
366
+ }
367
+ ), J(
368
+ () => n.codeModel,
369
+ (a) => s("update:code", a)
370
+ );
371
+ const g = (a) => n.touched[a] = !0, d = (a) => n.touched[a] = !1, r = () => {
372
+ e.value = "", d("email");
373
+ }, h = V(() => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(n.emailModel.trim())), U = V(() => !h.value || !!e.value), L = async () => {
374
+ var a;
375
+ try {
376
+ if (g("email"), !h.value) {
377
+ e.value = "Это не похоже на e-mail";
378
+ return;
379
+ }
380
+ const i = await $e(n.emailModel), { data: C } = i.data;
381
+ if (!(((a = C.data[0]) == null ? void 0 : a.available) ?? !1)) {
382
+ e.value = "Такой email уже используется";
383
+ return;
384
+ }
385
+ e.value = "", s("on-send-code", { email: n.emailModel, prevEmail: v.oldEmail, offLoading: !0 }), m.value = !0;
386
+ } catch (i) {
387
+ console.error("Неизвестная ошибка при проверке доступности email:", i), e.value = "Это не похоже на e-mail";
388
+ }
389
+ };
390
+ let A = "";
391
+ const w = (a) => {
392
+ s("on-clear-code-error");
393
+ const i = a.target;
394
+ let C = i.value.replace(/\D/g, "");
395
+ C.length > 4 && (C = C.slice(0, 4), i.value = C), n.codeModel = C, C.length === 4 && C !== A && (A = C, s("on-match-code", { email: n.emailModel, code: C }));
396
+ }, c = () => {
397
+ s("on-send-code-again", { email: n.emailModel });
398
+ }, { emailModel: b, codeModel: T, touched: P } = ce(n), F = V(() => {
399
+ if (e.value) return e.value;
400
+ if (n.touched.email) {
401
+ if (!n.emailModel.trim()) return "Введите e-mail";
402
+ if (!h.value) return "Это не похоже на e-mail";
403
+ }
404
+ return v.emailError || "";
405
+ }), p = V(() => v.isNotMatchCode ? "Неверный код" : P.value.code ? T.value.trim() ? v.codeError ?? null : "Введите код" : "");
406
+ return (a, i) => {
407
+ const C = ve;
408
+ return E(), I("div", Ct, [
409
+ B("div", yt, te(m.value ? "Введите код подтверждения" : a.hintText), 1),
410
+ a.showEmail ? (E(), I("div", gt, [
411
+ $(u(K), {
412
+ modelValue: u(b),
413
+ "onUpdate:modelValue": i[0] || (i[0] = (z) => ae(b) ? b.value = z : null),
414
+ size: "large",
415
+ "text-size": "medium",
416
+ label: "Почта",
417
+ type: "email",
418
+ error: F.value,
419
+ onBlur: i[1] || (i[1] = (z) => g("email")),
420
+ onInput: r
421
+ }, null, 8, ["modelValue", "error"]),
422
+ $(u(pe), {
423
+ class: "icon-locked",
424
+ onClick: i[2] || (i[2] = (z) => a.$emit("edit", "email"))
425
+ })
426
+ ])) : D("", !0),
427
+ m.value ? D("", !0) : (E(), I("div", ht, [
428
+ $(u(se), {
429
+ style: { width: "100%" },
430
+ disabled: U.value,
431
+ onClick: L
432
+ }, {
433
+ default: Y(() => i[5] || (i[5] = [
434
+ ne(" Отправить код ")
435
+ ])),
436
+ _: 1,
437
+ __: [5]
438
+ }, 8, ["disabled"])
439
+ ])),
440
+ m.value ? (E(), I("div", Tt, [
441
+ $(u(K), {
442
+ modelValue: u(T),
443
+ "onUpdate:modelValue": i[3] || (i[3] = (z) => ae(T) ? T.value = z : null),
444
+ size: "large",
445
+ "text-size": "medium",
446
+ label: "Код",
447
+ type: "text",
448
+ error: p.value,
449
+ onInput: w,
450
+ onBlur: i[4] || (i[4] = (z) => g("code"))
451
+ }, null, 8, ["modelValue", "error"])
452
+ ])) : D("", !0),
453
+ m.value ? (E(), I("div", Mt, [
454
+ $(C, {
455
+ loading: a.loading,
456
+ "rate-limit-text": a.rateLimitText,
457
+ "is-final-limit": a.isFinalLimit,
458
+ "on-send-again": c
459
+ }, null, 8, ["loading", "rate-limit-text", "is-final-limit"])
460
+ ])) : D("", !0)
461
+ ]);
462
+ };
463
+ }
464
+ }), Vt = { class: "text-center w-full" }, xt = { class: "dialogTitle" }, $t = {
465
+ key: 0,
466
+ class: "dialogDefaultContainer"
467
+ }, kt = {
468
+ key: 1,
469
+ class: "dialogDefaultContainer"
470
+ }, xe = 3, Pt = /* @__PURE__ */ ie({
471
+ __name: "ProfileEmailDialog",
472
+ props: {
473
+ modelValue: { type: Boolean },
474
+ title: { default: "Смена почты" },
475
+ hintText: { default: "Чтобы продолжить, введите код подтверждения" },
476
+ initialEmail: { default: "" },
477
+ throttler: {},
478
+ provider: {},
479
+ mode: {}
480
+ },
481
+ emits: ["update:modelValue", "submit-email", "edit", "close", "notify", "clean-input-errors", "on-update-jwt", "update-email-field", "on-password-error", "on-toast"],
482
+ setup(j, { emit: W }) {
483
+ const v = j, s = W, m = x(v.modelValue), e = ee({
484
+ oldEmail: v.initialEmail,
485
+ newEmail: "",
486
+ code: "",
487
+ addEmail: "",
488
+ addCode: ""
489
+ }), n = ee({ email: !1, code: !1 }), g = x(R.OLD), d = x(null), r = x(!1), h = x(!1), U = x(!1), L = x(qe.VERIFY_EMAIL), A = V(() => L.value === "password-flow"), w = V(() => p.value ? v.title : A.value ? "Добавление пароля" : "Добавление почты"), { startTimer: c, remainingSeconds: b, isAvailableForSendAgain: T, totalRateAttempts: P, currentRateAttempt: F } = We(), { isEditFlow: p, getFlow: a } = ze(x(v.mode ?? "edit")), { showRateLimitToast: i } = He(s), C = V(() => n.email && !e.oldEmail.trim() ? "Введите e-mail" : ""), z = V(() => n.code && !e.code.trim() ? "Введите код" : ""), de = V(() => T.value ? "Повторить" : `${b.value}`), G = x(xe), ke = V(() => G.value === 0), Ie = (l) => new Promise((t) => setTimeout(t, l));
490
+ J(
491
+ () => v.modelValue,
492
+ (l) => m.value = l
493
+ ), J(m, (l) => s("update:modelValue", l));
494
+ const re = () => {
495
+ s("close"), m.value = !1;
496
+ }, fe = (l) => s("edit", l);
497
+ async function Ee(l, t = !1) {
498
+ var o;
499
+ try {
500
+ const M = (o = (await _("/users/profile/check-throttler", { method: "email", email: l, isInvite: t })).data) == null ? void 0 : o.data;
501
+ return M ? (await Ie(1e3), M.restTimeSec > 0 ? (c(M.restTimeSec), T.value = !1, P.value = M.attempts.total ?? P.value, F.value = (M.attempts.total ?? 0) - (M.attempts.available ?? 0), G.value = M.attempts.available ?? G.value) : T.value = !0, M) : null;
502
+ } catch {
503
+ return null;
504
+ }
505
+ }
506
+ async function ue(l = "email") {
507
+ var o;
508
+ return ((o = (await je("/users/profile/session/get-edit-session", { params: { field: l } })).data) == null ? void 0 : o.data) ?? null;
509
+ }
510
+ async function Se(l = "email") {
511
+ try {
512
+ const t = await ue(l);
513
+ d.value = (t == null ? void 0 : t.sessionId) ?? d.value, g.value = (t == null ? void 0 : t.step) ?? g.value, e.oldEmail = (t == null ? void 0 : t.oldValue) ?? e.oldEmail, t != null && t.sessionId || await we(l);
514
+ } catch {
515
+ await we(l);
516
+ }
517
+ }
518
+ async function we(l = "email") {
519
+ var t;
520
+ try {
521
+ const o = await _("/users/profile/session/create-if-not-exists", { field: l, oldValue: v.initialEmail }), f = ((t = o.data) == null ? void 0 : t.data) ?? o.data;
522
+ d.value = (f == null ? void 0 : f.sessionId) ?? d.value, g.value = (f == null ? void 0 : f.step) ?? g.value, e.oldEmail = (f == null ? void 0 : f.oldValue) ?? e.oldEmail, e.newEmail = (f == null ? void 0 : f.newValue) ?? e.newEmail;
523
+ } catch {
524
+ }
525
+ }
526
+ async function le({ value: l, offLoading: t = !0 }) {
527
+ var o;
528
+ try {
529
+ r.value = !0;
530
+ const f = l ?? e.addEmail, M = await _(
531
+ "/users/profile/email/contact/send-code",
532
+ {
533
+ sessionId: d.value,
534
+ email: f,
535
+ value: f,
536
+ oldValue: e.oldEmail,
537
+ provider: v.provider
538
+ }
539
+ // { headers: { 'x-only-sms': 'true' } }
540
+ );
541
+ if (M.status === 403 && ((o = M.data) != null && o.tooManyRequests)) {
542
+ const S = M.data.tooManyRequests;
543
+ return S.restTimeSec > 0 ? (c(S.restTimeSec), P.value = S.attempts.total ?? P.value, F.value = (S.attempts.total ?? 0) - (S.attempts.available ?? 0), G.value = S.attempts.available ?? G.value) : T.value = !0, M;
544
+ }
545
+ return await Ee(l ?? e.oldEmail), M;
546
+ } catch (f) {
547
+ throw console.error(f), f;
548
+ } finally {
549
+ t && (r.value = !1);
550
+ }
551
+ }
552
+ const Ce = async (l, t) => {
553
+ var o, f, M, S, N, H, oe, k, Q;
554
+ if (!e.oldEmail && t === R.OLD) throw new Error("oldEmail пустой — модель потерялась");
555
+ try {
556
+ r.value = !0;
557
+ const y = await ue();
558
+ if (d.value = (y == null ? void 0 : y.sessionId) ?? d.value, g.value = (y == null ? void 0 : y.step) ?? g.value, e.oldEmail = (y == null ? void 0 : y.oldValue) ?? e.oldEmail, e.newEmail = (y == null ? void 0 : y.newValue) ?? e.newEmail, !d.value) throw new Error("Нет sessionId для match");
559
+ const O = await _("/users/profile/change/email/match-code", {
560
+ email: t === R.NEW ? e.newEmail : e.oldEmail,
561
+ sessionId: d.value,
562
+ code: l,
563
+ step: t
564
+ }), X = ((o = O.data) == null ? void 0 : o.nextStep) ?? ((M = (f = O.data) == null ? void 0 : f.data) == null ? void 0 : M.nextStep) ?? null, Ue = ((N = (S = O.data) == null ? void 0 : S.data) == null ? void 0 : N.rateLimit) ?? ((H = O.data) == null ? void 0 : H.rateLimit) ?? null, Ae = O.data.data.success ?? O.data.success;
565
+ if (i(Ue), !Ae) {
566
+ h.value = !0;
567
+ return;
568
+ }
569
+ if (X) {
570
+ if (g.value = X, g.value === R.NEW) {
571
+ const Z = await ue();
572
+ e.oldEmail = (Z == null ? void 0 : Z.oldValue) ?? e.oldEmail, e.newEmail = (Z == null ? void 0 : Z.newValue) ?? e.newEmail, e.code = "";
573
+ }
574
+ g.value === R.COMPLETED && (e.code = "", s("submit-email", { email: e.addEmail, code: l }), s("on-toast", { color: "success", text: "E-mail изменён" }), s("on-update-jwt", "email", "edit", e.newEmail), d.value = null, s("close"));
575
+ }
576
+ return O;
577
+ } catch (y) {
578
+ const O = (k = (oe = y == null ? void 0 : y.response) == null ? void 0 : oe.data) == null ? void 0 : k.rateLimit, X = (Q = y == null ? void 0 : y.response) == null ? void 0 : Q.data.statusCode;
579
+ if (console.error("rate-limit debug error: ", y), X === 429 && O) {
580
+ console.debug("rate-limit debug status and exists rateLimit: ", O), i(O), h.value = !0;
581
+ return;
582
+ }
583
+ throw y;
584
+ } finally {
585
+ r.value = !1;
586
+ }
587
+ }, Be = async () => {
588
+ try {
589
+ const l = await _("/users/profile/bind/email/cancel", {
590
+ sessionId: d.value
591
+ });
592
+ if ((l.data.data ?? l.data).success) {
593
+ s("close");
594
+ return;
595
+ }
596
+ } catch (l) {
597
+ console.error(l);
598
+ }
599
+ };
600
+ async function Le({ code: l }) {
601
+ await Ce(l, R.OLD);
602
+ }
603
+ function ye(l) {
604
+ }
605
+ async function Pe({ code: l }) {
606
+ await Ce(l, R.NEW);
607
+ }
608
+ const ge = async ({
609
+ value: l,
610
+ field: t = "email",
611
+ offLoading: o = !0
612
+ }) => {
613
+ var f;
614
+ try {
615
+ if (r.value = !0, !d.value) throw new Error("Bind-сессия не найдена. Создайте её через createBindSession.");
616
+ const M = l ?? e.addEmail, S = await _(`/users/profile/bind/contact/send-code/${t}`, {
617
+ sessionId: d.value,
618
+ email: M,
619
+ provider: v.provider
620
+ }), N = (f = S.data) == null ? void 0 : f.tooManyRequests;
621
+ if (S.status === 403 && N) {
622
+ N.restTimeSec > 0 ? (c(N.restTimeSec), P.value = N.attempts.total ?? P.value, F.value = (N.attempts.total ?? 0) - (N.attempts.available ?? 0), G.value = N.attempts.available ?? xe) : T.value = !0;
623
+ return;
624
+ }
625
+ const H = await Ee(M);
626
+ return H && H.restTimeSec > 0 ? c(H.restTimeSec) : T.value = !0, S;
627
+ } finally {
628
+ o && (r.value = !1);
629
+ }
630
+ }, De = async () => {
631
+ var l, t, o, f, M, S, N, H, oe;
632
+ try {
633
+ if (!d.value) {
634
+ const X = await me();
635
+ d.value = X.sessionId ?? d.value;
636
+ }
637
+ const k = await _("/users/profile/bind/email/match-code", {
638
+ email: e.addEmail,
639
+ sessionId: d.value,
640
+ code: e.addCode
641
+ }), Q = ((l = k.data) == null ? void 0 : l.nextStep) ?? ((o = (t = k.data) == null ? void 0 : t.data) == null ? void 0 : o.nextStep);
642
+ L.value = Q ?? L.value;
643
+ const y = ((M = (f = k.data) == null ? void 0 : f.data) == null ? void 0 : M.rateLimit) ?? ((S = k.data) == null ? void 0 : S.rateLimit) ?? null, O = k.data.data.success ?? k.data.success;
644
+ if (i(y), !O) {
645
+ U.value = !0;
646
+ return;
647
+ }
648
+ } catch (k) {
649
+ const Q = (H = (N = k == null ? void 0 : k.response) == null ? void 0 : N.data) == null ? void 0 : H.rateLimit;
650
+ if (((oe = k == null ? void 0 : k.response) == null ? void 0 : oe.status) === 429 && Q) {
651
+ i(Q), h.value = !0;
652
+ return;
653
+ }
654
+ throw k;
655
+ }
656
+ }, Ne = async () => {
657
+ }, Oe = async (l) => {
658
+ if (!d.value) {
659
+ const t = await me();
660
+ d.value = t.sessionId ?? d.value;
661
+ }
662
+ r.value = !0;
663
+ try {
664
+ await _("/users/profile/bind/email/password/set", { sessionId: d.value, newPassword: l }), L.value = R.COMPLETED, s("on-toast", { color: "success", text: "E-mail успешно привязан к аккаунту" }), s("update-email-field", e.addEmail), s("submit-email", { email: e.addEmail, code: e.addCode }), s("on-update-jwt", "email", "bind", e.addEmail), s("close");
665
+ } finally {
666
+ r.value = !1;
667
+ }
668
+ }, me = async () => {
669
+ r.value = !0;
670
+ try {
671
+ const l = await _("/users/profile/bind/email/init", { email: "" }), t = l.data.data ?? l.data;
672
+ return L.value = t.step ?? L.value, d.value = t.sessionId ?? d.value, t;
673
+ } finally {
674
+ r.value = !1;
675
+ }
676
+ };
677
+ return Re(async () => {
678
+ r.value = !0;
679
+ const l = await a("email");
680
+ if (v.mode === "bind" && l === "bind") {
681
+ await me(), r.value = !1;
682
+ return;
683
+ }
684
+ await Se(), e.oldEmail && await le({ value: e.oldEmail }), r.value = !1;
685
+ }), (l, t) => (E(), q(u(Ge), {
686
+ modelValue: m.value,
687
+ "onUpdate:modelValue": [
688
+ t[18] || (t[18] = (o) => m.value = o),
689
+ re
690
+ ],
691
+ width: "small",
692
+ "auto-height": !0,
693
+ "close-on-click-outside": !0,
694
+ "onClick:outside": re
695
+ }, {
696
+ header: Y(() => [
697
+ B("div", Vt, [
698
+ $(u(Ye), {
699
+ "slot-left": !1,
700
+ size: "small",
701
+ borded: !0,
702
+ "no-padding": !1
703
+ }, {
704
+ title: Y(() => [
705
+ B("span", xt, te(w.value), 1)
706
+ ]),
707
+ "right-button": Y(() => [
708
+ $(u(Je), {
709
+ class: "cross",
710
+ onClick: re
711
+ })
712
+ ]),
713
+ _: 1
714
+ })
715
+ ])
716
+ ]),
717
+ default: Y(() => [
718
+ B("div", null, [
719
+ u(p) ? (E(), I("div", $t, [
720
+ r.value ? (E(), q(Te, { key: 0 })) : D("", !0),
721
+ g.value === u(R).OLD ? (E(), q(wt, {
722
+ key: 1,
723
+ email: e.oldEmail,
724
+ "onUpdate:email": t[0] || (t[0] = (o) => e.oldEmail = o),
725
+ code: e.code,
726
+ "onUpdate:code": t[1] || (t[1] = (o) => e.code = o),
727
+ "hint-text": l.hintText,
728
+ "email-error": C.value,
729
+ "code-error": z.value,
730
+ "rate-limit-text": de.value,
731
+ "is-final-limit": G.value === 0,
732
+ "is-not-match-code": h.value,
733
+ loading: r.value,
734
+ onEdit: fe,
735
+ onOnMatchCode: Le,
736
+ onOnMatchCodeError: ye,
737
+ onSendCode: t[2] || (t[2] = (o) => le({ value: e.oldEmail })),
738
+ onOnSendCodeAgain: t[3] || (t[3] = (o) => le({ value: e.oldEmail })),
739
+ onOnClearCodeError: t[4] || (t[4] = (o) => h.value = !1)
740
+ }, null, 8, ["email", "code", "hint-text", "email-error", "code-error", "rate-limit-text", "is-final-limit", "is-not-match-code", "loading"])) : g.value === u(R).NEW ? (E(), q(bt, {
741
+ key: 2,
742
+ email: e.newEmail,
743
+ "onUpdate:email": t[5] || (t[5] = (o) => e.newEmail = o),
744
+ oldEmail: e.oldEmail,
745
+ "onUpdate:oldEmail": t[6] || (t[6] = (o) => e.oldEmail = o),
746
+ code: e.code,
747
+ "onUpdate:code": t[7] || (t[7] = (o) => e.code = o),
748
+ "hint-text": "Введите новый адрес вашей почты",
749
+ "email-error": C.value,
750
+ "code-error": z.value,
751
+ "rate-limit-text": de.value,
752
+ "is-final-limit": G.value === 0,
753
+ "is-not-match-code": h.value,
754
+ loading: r.value,
755
+ onEdit: fe,
756
+ onOnMatchCode: Pe,
757
+ onOnMatchCodeError: ye,
758
+ onOnSendCode: t[8] || (t[8] = (o) => le({ value: e.newEmail })),
759
+ onOnSendCodeAgain: t[9] || (t[9] = (o) => le({ value: e.newEmail })),
760
+ onOnClearCodeError: t[10] || (t[10] = (o) => h.value = !1)
761
+ }, null, 8, ["email", "oldEmail", "code", "email-error", "code-error", "rate-limit-text", "is-final-limit", "is-not-match-code", "loading"])) : D("", !0)
762
+ ])) : (E(), I("div", kt, [
763
+ r.value ? (E(), q(Te, { key: 0 })) : D("", !0),
764
+ A.value ? (E(), q(mt, {
765
+ key: 2,
766
+ "model-value": m.value,
767
+ "email-session-id": d.value,
768
+ "onUpdate:modelValue": t[17] || (t[17] = (o) => s("update:modelValue", o)),
769
+ onUpdateUser: Oe,
770
+ onClose: Be
771
+ }, null, 8, ["model-value", "email-session-id"])) : (E(), q(at, {
772
+ key: 1,
773
+ email: e.addEmail,
774
+ "onUpdate:email": t[11] || (t[11] = (o) => e.addEmail = o),
775
+ oldEmail: e.addEmail,
776
+ "onUpdate:oldEmail": t[12] || (t[12] = (o) => e.addEmail = o),
777
+ code: e.addCode,
778
+ "onUpdate:code": t[13] || (t[13] = (o) => e.addCode = o),
779
+ "hint-text": u(p) ? l.hintText : "Чтобы продолжить, введите новый адрес вашей почты",
780
+ "rate-limit-text": de.value,
781
+ "is-final-limit": ke.value,
782
+ "is-not-match-code": U.value,
783
+ loading: r.value,
784
+ onOnSendCode: t[14] || (t[14] = (o) => ge({ value: e.addEmail, field: "email" })),
785
+ onOnSendCodeAgain: t[15] || (t[15] = (o) => ge({ value: e.addEmail, field: "email" })),
786
+ onOnMatchCode: De,
787
+ onOnMatchCodeError: Ne,
788
+ onOnClearCodeError: t[16] || (t[16] = (o) => U.value = !1)
789
+ }, null, 8, ["email", "oldEmail", "code", "hint-text", "rate-limit-text", "is-final-limit", "is-not-match-code", "loading"]))
790
+ ]))
791
+ ])
792
+ ]),
793
+ _: 1
794
+ }, 8, ["modelValue"]));
795
+ }
796
+ });
797
+ export {
798
+ Pt as default
799
+ };