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