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