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