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