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