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