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