@yourgoods/ui-smart 0.28.0 → 0.30.0

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