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