@yourgoods/ui-smart 0.3.0 → 0.5.0

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