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