@xsolla/xui-input-payment 0.64.0-pr56.1768440195

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,957 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.tsx
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ InputPayment: () => InputPayment
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+
37
+ // src/InputPayment.tsx
38
+ var import_react4 = __toESM(require("react"));
39
+
40
+ // ../primitives-native/src/Box.tsx
41
+ var import_react_native = require("react-native");
42
+ var import_jsx_runtime = require("react/jsx-runtime");
43
+ var Box = ({
44
+ children,
45
+ onPress,
46
+ onLayout,
47
+ onMoveShouldSetResponder,
48
+ onResponderGrant,
49
+ onResponderMove,
50
+ onResponderRelease,
51
+ onResponderTerminate,
52
+ backgroundColor,
53
+ borderColor,
54
+ borderWidth,
55
+ borderBottomWidth,
56
+ borderBottomColor,
57
+ borderTopWidth,
58
+ borderTopColor,
59
+ borderLeftWidth,
60
+ borderLeftColor,
61
+ borderRightWidth,
62
+ borderRightColor,
63
+ borderRadius,
64
+ borderStyle,
65
+ height,
66
+ padding,
67
+ paddingHorizontal,
68
+ paddingVertical,
69
+ margin,
70
+ marginTop,
71
+ marginBottom,
72
+ marginLeft,
73
+ marginRight,
74
+ flexDirection,
75
+ alignItems,
76
+ justifyContent,
77
+ position,
78
+ top,
79
+ bottom,
80
+ left,
81
+ right,
82
+ width,
83
+ flex,
84
+ overflow,
85
+ zIndex,
86
+ hoverStyle,
87
+ pressStyle,
88
+ style,
89
+ "data-testid": dataTestId,
90
+ testID,
91
+ as,
92
+ src,
93
+ alt,
94
+ ...rest
95
+ }) => {
96
+ const getContainerStyle = (pressed) => ({
97
+ backgroundColor: pressed && pressStyle?.backgroundColor ? pressStyle.backgroundColor : backgroundColor,
98
+ borderColor,
99
+ borderWidth,
100
+ borderBottomWidth,
101
+ borderBottomColor,
102
+ borderTopWidth,
103
+ borderTopColor,
104
+ borderLeftWidth,
105
+ borderLeftColor,
106
+ borderRightWidth,
107
+ borderRightColor,
108
+ borderRadius,
109
+ borderStyle,
110
+ overflow,
111
+ zIndex,
112
+ height,
113
+ width,
114
+ padding,
115
+ paddingHorizontal,
116
+ paddingVertical,
117
+ margin,
118
+ marginTop,
119
+ marginBottom,
120
+ marginLeft,
121
+ marginRight,
122
+ flexDirection,
123
+ alignItems,
124
+ justifyContent,
125
+ position,
126
+ top,
127
+ bottom,
128
+ left,
129
+ right,
130
+ flex,
131
+ ...style
132
+ });
133
+ const finalTestID = dataTestId || testID;
134
+ const {
135
+ role,
136
+ tabIndex,
137
+ onKeyDown,
138
+ onKeyUp,
139
+ "aria-label": _ariaLabel,
140
+ "aria-labelledby": _ariaLabelledBy,
141
+ "aria-current": _ariaCurrent,
142
+ "aria-disabled": _ariaDisabled,
143
+ "aria-live": _ariaLive,
144
+ className,
145
+ "data-testid": _dataTestId,
146
+ ...nativeRest
147
+ } = rest;
148
+ if (as === "img" && src) {
149
+ const imageStyle = {
150
+ width,
151
+ height,
152
+ borderRadius,
153
+ position,
154
+ top,
155
+ bottom,
156
+ left,
157
+ right,
158
+ ...style
159
+ };
160
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
161
+ import_react_native.Image,
162
+ {
163
+ source: { uri: src },
164
+ style: imageStyle,
165
+ testID: finalTestID,
166
+ resizeMode: "cover",
167
+ ...nativeRest
168
+ }
169
+ );
170
+ }
171
+ if (onPress) {
172
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
173
+ import_react_native.Pressable,
174
+ {
175
+ onPress,
176
+ onLayout,
177
+ onMoveShouldSetResponder,
178
+ onResponderGrant,
179
+ onResponderMove,
180
+ onResponderRelease,
181
+ onResponderTerminate,
182
+ style: ({ pressed }) => getContainerStyle(pressed),
183
+ testID: finalTestID,
184
+ ...nativeRest,
185
+ children
186
+ }
187
+ );
188
+ }
189
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
190
+ import_react_native.View,
191
+ {
192
+ style: getContainerStyle(),
193
+ testID: finalTestID,
194
+ onLayout,
195
+ onMoveShouldSetResponder,
196
+ onResponderGrant,
197
+ onResponderMove,
198
+ onResponderRelease,
199
+ onResponderTerminate,
200
+ ...nativeRest,
201
+ children
202
+ }
203
+ );
204
+ };
205
+
206
+ // ../primitives-native/src/Text.tsx
207
+ var import_react_native2 = require("react-native");
208
+ var import_jsx_runtime2 = require("react/jsx-runtime");
209
+ var roleMap = {
210
+ alert: "alert",
211
+ heading: "header",
212
+ button: "button",
213
+ link: "link",
214
+ text: "text"
215
+ };
216
+ var Text = ({
217
+ children,
218
+ color,
219
+ fontSize,
220
+ fontWeight,
221
+ fontFamily,
222
+ id,
223
+ role,
224
+ ...props
225
+ }) => {
226
+ let resolvedFontFamily = fontFamily ? fontFamily.split(",")[0].replace(/['"]/g, "").trim() : void 0;
227
+ if (resolvedFontFamily === "Pilat Wide Bold") {
228
+ resolvedFontFamily = void 0;
229
+ }
230
+ const style = {
231
+ color,
232
+ fontSize: typeof fontSize === "number" ? fontSize : void 0,
233
+ fontWeight,
234
+ fontFamily: resolvedFontFamily,
235
+ textDecorationLine: props.textDecoration
236
+ };
237
+ const accessibilityRole = role ? roleMap[role] : void 0;
238
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.Text, { style, testID: id, accessibilityRole, children });
239
+ };
240
+
241
+ // ../primitives-native/src/Spinner.tsx
242
+ var import_react_native3 = require("react-native");
243
+ var import_jsx_runtime3 = require("react/jsx-runtime");
244
+ var Spinner = ({
245
+ color,
246
+ size,
247
+ role,
248
+ "aria-label": ariaLabel,
249
+ "aria-live": ariaLive,
250
+ "aria-describedby": ariaDescribedBy,
251
+ testID
252
+ }) => {
253
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
254
+ import_react_native3.View,
255
+ {
256
+ accessible: true,
257
+ accessibilityRole: role === "status" ? "none" : void 0,
258
+ accessibilityLabel: ariaLabel,
259
+ accessibilityLiveRegion: ariaLive === "polite" ? "polite" : ariaLive === "assertive" ? "assertive" : "none",
260
+ testID,
261
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
262
+ import_react_native3.ActivityIndicator,
263
+ {
264
+ color,
265
+ size: typeof size === "number" ? size : "small"
266
+ }
267
+ )
268
+ }
269
+ );
270
+ };
271
+ Spinner.displayName = "Spinner";
272
+
273
+ // ../primitives-native/src/Icon.tsx
274
+ var import_react = __toESM(require("react"));
275
+ var import_react_native4 = require("react-native");
276
+ var import_jsx_runtime4 = require("react/jsx-runtime");
277
+
278
+ // ../primitives-native/src/Divider.tsx
279
+ var import_react_native5 = require("react-native");
280
+ var import_jsx_runtime5 = require("react/jsx-runtime");
281
+
282
+ // ../primitives-native/src/Input.tsx
283
+ var import_react2 = require("react");
284
+ var import_react_native6 = require("react-native");
285
+ var import_jsx_runtime6 = require("react/jsx-runtime");
286
+ var keyboardTypeMap = {
287
+ text: "default",
288
+ number: "numeric",
289
+ email: "email-address",
290
+ tel: "phone-pad",
291
+ url: "url",
292
+ decimal: "decimal-pad"
293
+ };
294
+ var inputModeToKeyboardType = {
295
+ none: "default",
296
+ text: "default",
297
+ decimal: "decimal-pad",
298
+ numeric: "number-pad",
299
+ tel: "phone-pad",
300
+ search: "default",
301
+ email: "email-address",
302
+ url: "url"
303
+ };
304
+ var autoCompleteToTextContentType = {
305
+ "one-time-code": "oneTimeCode",
306
+ email: "emailAddress",
307
+ username: "username",
308
+ password: "password",
309
+ "new-password": "newPassword",
310
+ tel: "telephoneNumber",
311
+ "postal-code": "postalCode",
312
+ name: "name"
313
+ };
314
+ var InputPrimitive = (0, import_react2.forwardRef)(
315
+ ({
316
+ value,
317
+ placeholder,
318
+ onChange,
319
+ onChangeText,
320
+ onFocus,
321
+ onBlur,
322
+ onKeyDown,
323
+ disabled,
324
+ secureTextEntry,
325
+ style,
326
+ color,
327
+ fontSize,
328
+ placeholderTextColor,
329
+ maxLength,
330
+ name,
331
+ type,
332
+ inputMode,
333
+ autoComplete,
334
+ id,
335
+ "aria-invalid": ariaInvalid,
336
+ "aria-describedby": ariaDescribedBy,
337
+ "aria-labelledby": ariaLabelledBy,
338
+ "aria-label": ariaLabel,
339
+ "aria-disabled": ariaDisabled,
340
+ "data-testid": dataTestId
341
+ }, ref) => {
342
+ const handleChangeText = (text) => {
343
+ onChangeText?.(text);
344
+ if (onChange) {
345
+ const syntheticEvent = {
346
+ target: { value: text },
347
+ currentTarget: { value: text },
348
+ type: "change",
349
+ nativeEvent: { text },
350
+ preventDefault: () => {
351
+ },
352
+ stopPropagation: () => {
353
+ },
354
+ isTrusted: false
355
+ };
356
+ onChange(syntheticEvent);
357
+ }
358
+ };
359
+ const keyboardType = inputMode ? inputModeToKeyboardType[inputMode] || "default" : type ? keyboardTypeMap[type] || "default" : "default";
360
+ const textContentType = autoComplete ? autoCompleteToTextContentType[autoComplete] : void 0;
361
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
362
+ import_react_native6.TextInput,
363
+ {
364
+ ref,
365
+ value,
366
+ placeholder,
367
+ onChangeText: handleChangeText,
368
+ onFocus,
369
+ onBlur,
370
+ onKeyPress: (e) => {
371
+ if (onKeyDown) {
372
+ onKeyDown({
373
+ key: e.nativeEvent.key,
374
+ preventDefault: () => {
375
+ }
376
+ });
377
+ }
378
+ },
379
+ editable: !disabled,
380
+ secureTextEntry: secureTextEntry || type === "password",
381
+ keyboardType,
382
+ textContentType,
383
+ style: [
384
+ {
385
+ color,
386
+ fontSize: typeof fontSize === "number" ? fontSize : void 0,
387
+ flex: 1,
388
+ padding: 0,
389
+ textAlign: style?.textAlign || "left"
390
+ },
391
+ style
392
+ ],
393
+ placeholderTextColor,
394
+ maxLength,
395
+ testID: dataTestId || id,
396
+ accessibilityLabel: ariaLabel,
397
+ accessibilityHint: ariaDescribedBy,
398
+ accessibilityState: {
399
+ disabled: disabled || ariaDisabled
400
+ },
401
+ accessible: true
402
+ }
403
+ );
404
+ }
405
+ );
406
+ InputPrimitive.displayName = "InputPrimitive";
407
+
408
+ // ../primitives-native/src/TextArea.tsx
409
+ var import_react3 = require("react");
410
+ var import_react_native7 = require("react-native");
411
+ var import_jsx_runtime7 = require("react/jsx-runtime");
412
+ var TextAreaPrimitive = (0, import_react3.forwardRef)(
413
+ ({
414
+ value,
415
+ placeholder,
416
+ onChange,
417
+ onChangeText,
418
+ onFocus,
419
+ onBlur,
420
+ onKeyDown,
421
+ disabled,
422
+ style,
423
+ color,
424
+ fontSize,
425
+ placeholderTextColor,
426
+ maxLength,
427
+ rows,
428
+ id,
429
+ "aria-invalid": ariaInvalid,
430
+ "aria-describedby": ariaDescribedBy,
431
+ "aria-labelledby": ariaLabelledBy,
432
+ "aria-label": ariaLabel,
433
+ "aria-disabled": ariaDisabled,
434
+ "data-testid": dataTestId
435
+ }, ref) => {
436
+ const handleChangeText = (text) => {
437
+ onChangeText?.(text);
438
+ if (onChange) {
439
+ const syntheticEvent = {
440
+ target: { value: text },
441
+ currentTarget: { value: text },
442
+ type: "change",
443
+ nativeEvent: { text },
444
+ preventDefault: () => {
445
+ },
446
+ stopPropagation: () => {
447
+ },
448
+ isTrusted: false
449
+ };
450
+ onChange(syntheticEvent);
451
+ }
452
+ };
453
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
454
+ import_react_native7.TextInput,
455
+ {
456
+ ref,
457
+ value,
458
+ placeholder,
459
+ onChangeText: handleChangeText,
460
+ onFocus,
461
+ onBlur,
462
+ onKeyPress: (e) => {
463
+ if (onKeyDown) {
464
+ onKeyDown({
465
+ key: e.nativeEvent.key,
466
+ preventDefault: () => {
467
+ }
468
+ });
469
+ }
470
+ },
471
+ editable: !disabled,
472
+ multiline: true,
473
+ numberOfLines: rows || 4,
474
+ style: [
475
+ {
476
+ color,
477
+ fontSize: typeof fontSize === "number" ? fontSize : void 0,
478
+ flex: 1,
479
+ padding: 0,
480
+ textAlignVertical: "top",
481
+ textAlign: style?.textAlign || "left"
482
+ },
483
+ style
484
+ ],
485
+ placeholderTextColor,
486
+ maxLength,
487
+ testID: dataTestId || id,
488
+ accessibilityLabel: ariaLabel,
489
+ accessibilityHint: ariaDescribedBy,
490
+ accessibilityState: {
491
+ disabled: disabled || ariaDisabled
492
+ },
493
+ accessible: true
494
+ }
495
+ );
496
+ }
497
+ );
498
+ TextAreaPrimitive.displayName = "TextAreaPrimitive";
499
+
500
+ // src/InputPayment.tsx
501
+ var import_xui_core = require("@xsolla/xui-core");
502
+ var import_xui_icons_payment = require("@xsolla/xui-icons-payment");
503
+ var import_jsx_runtime8 = require("react/jsx-runtime");
504
+ var DEFAULT_POSSIBLE_PAYMENTS = [
505
+ "mastercard",
506
+ "visa",
507
+ "maestro",
508
+ "diners",
509
+ "amex",
510
+ "discover",
511
+ "jcb",
512
+ "unionpay"
513
+ ];
514
+ var paymentIconComponents = {
515
+ visa: import_xui_icons_payment.Visa,
516
+ mastercard: import_xui_icons_payment.Mastercard,
517
+ maestro: import_xui_icons_payment.Maestro,
518
+ amex: import_xui_icons_payment.AmericanExpress,
519
+ diners: import_xui_icons_payment.Dinersclub,
520
+ discover: import_xui_icons_payment.Discover,
521
+ jcb: import_xui_icons_payment.Jcb,
522
+ unionpay: import_xui_icons_payment.Unionpay,
523
+ aura: import_xui_icons_payment.Aura,
524
+ cartesbancaires: import_xui_icons_payment.CartesBancaires,
525
+ cirrus: import_xui_icons_payment.Cirrus,
526
+ dankort: import_xui_icons_payment.Dankort,
527
+ elo: import_xui_icons_payment.Elo,
528
+ hipercard: import_xui_icons_payment.Hipercard,
529
+ mir: import_xui_icons_payment.Mir,
530
+ naranja: import_xui_icons_payment.Naranja,
531
+ paypal: import_xui_icons_payment.Paypal,
532
+ sodexo: import_xui_icons_payment.Sodexo,
533
+ uatp: import_xui_icons_payment.Uatp
534
+ };
535
+ var detectPaymentSystem = (cardNumber) => {
536
+ const cleanNumber = cardNumber.replace(/\s/g, "");
537
+ if (!cleanNumber) return null;
538
+ if (/^1/.test(cleanNumber)) return "uatp";
539
+ if (/^220[0-4]/.test(cleanNumber)) return "mir";
540
+ if (/^3[47]/.test(cleanNumber)) return "amex";
541
+ if (/^3(?:0[0-5]|[68])/.test(cleanNumber)) return "diners";
542
+ if (/^35(?:2[89]|[3-8])/.test(cleanNumber)) return "jcb";
543
+ if (/^(401178|401179|431274|438935|451416|457393|457631|457632|504175|506699|5067[0-9]{2}|509[0-9]{3}|627780|636297|636368|650[0-9]{3}|651[0-9]{3}|655[0-9]{3})/.test(
544
+ cleanNumber
545
+ ))
546
+ return "elo";
547
+ if (/^4/.test(cleanNumber)) return "visa";
548
+ if (/^(606282|637095|637568|637599|637609|637612)/.test(cleanNumber))
549
+ return "hipercard";
550
+ if (/^507860/.test(cleanNumber)) return "aura";
551
+ if (/^5019/.test(cleanNumber)) return "dankort";
552
+ if (/^589562/.test(cleanNumber)) return "naranja";
553
+ if (/^5[1-5]/.test(cleanNumber)) return "mastercard";
554
+ if (cleanNumber.length >= 4 && /^(?:222[1-9]|22[3-9]\d|2[3-6]\d{2}|27[01]\d|2720)/.test(cleanNumber))
555
+ return "mastercard";
556
+ if (/^(?:6011|65|64[4-9])/.test(cleanNumber)) return "discover";
557
+ if (cleanNumber.length >= 6 && /^(?:6221(?:2[6-9]|[3-9]\d)|622[2-8]\d{2}|6229(?:[01]\d|2[0-5]))/.test(cleanNumber))
558
+ return "discover";
559
+ if (/^62/.test(cleanNumber)) return "unionpay";
560
+ if (/^(?:5[06-9]|6)/.test(cleanNumber)) return "maestro";
561
+ return null;
562
+ };
563
+ var CARD_GAP = 4;
564
+ var PaymentIcons = ({ possiblePayments, maxVisible, recognizedPayment, iconHeight }) => {
565
+ const [cyclingIndex, setCyclingIndex] = (0, import_react4.useState)(0);
566
+ const [isTransitioning, setIsTransitioning] = (0, import_react4.useState)(false);
567
+ const [isRecognized, setIsRecognized] = (0, import_react4.useState)(false);
568
+ const scaledCardHeight = iconHeight;
569
+ const scaledCardWidth = Math.round(iconHeight * (4 / 3));
570
+ const scaledGap = CARD_GAP;
571
+ const constantCards = possiblePayments.slice(0, maxVisible - 1);
572
+ const cyclingCards = possiblePayments.slice(maxVisible - 1);
573
+ (0, import_react4.useEffect)(() => {
574
+ if (recognizedPayment) {
575
+ setIsRecognized(true);
576
+ } else {
577
+ const timeout = setTimeout(() => {
578
+ setIsRecognized(false);
579
+ }, 50);
580
+ return () => clearTimeout(timeout);
581
+ }
582
+ }, [recognizedPayment]);
583
+ (0, import_react4.useEffect)(() => {
584
+ if (cyclingCards.length <= 1 || recognizedPayment) return;
585
+ const interval = setInterval(() => {
586
+ setIsTransitioning(true);
587
+ setTimeout(() => {
588
+ setCyclingIndex((prev) => (prev + 1) % cyclingCards.length);
589
+ setIsTransitioning(false);
590
+ }, 150);
591
+ }, 2e3);
592
+ return () => clearInterval(interval);
593
+ }, [cyclingCards.length, recognizedPayment]);
594
+ const paymentLabels = {
595
+ mastercard: "Mastercard",
596
+ visa: "Visa",
597
+ maestro: "Maestro",
598
+ diners: "Diners Club",
599
+ amex: "American Express",
600
+ discover: "Discover",
601
+ jcb: "JCB",
602
+ unionpay: "UnionPay",
603
+ aura: "Aura",
604
+ cartesbancaires: "Cartes Bancaires",
605
+ cirrus: "Cirrus",
606
+ dankort: "Dankort",
607
+ elo: "Elo",
608
+ hipercard: "Hipercard",
609
+ mir: "Mir",
610
+ naranja: "Naranja",
611
+ paypal: "PayPal",
612
+ sodexo: "Sodexo",
613
+ uatp: "UATP"
614
+ };
615
+ const getAriaLabel = () => {
616
+ if (recognizedPayment) {
617
+ return `Recognized payment: ${paymentLabels[recognizedPayment]}`;
618
+ }
619
+ return `Accepted payment cards: ${possiblePayments.map((key) => paymentLabels[key]).join(", ")}`;
620
+ };
621
+ const totalVisibleCards = Math.min(possiblePayments.length, maxVisible);
622
+ const containerWidth = totalVisibleCards * scaledCardWidth + (totalVisibleCards - 1) * scaledGap;
623
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
624
+ Box,
625
+ {
626
+ flexDirection: "row",
627
+ alignItems: "center",
628
+ role: "img",
629
+ "aria-label": getAriaLabel(),
630
+ position: "relative",
631
+ width: containerWidth,
632
+ height: scaledCardHeight,
633
+ style: { overflow: "hidden" },
634
+ children: [
635
+ constantCards.map((key, index) => {
636
+ const IconComponent = paymentIconComponents[key];
637
+ const isRecognizedCard = recognizedPayment === key;
638
+ let translateX = 0;
639
+ let opacity = 1;
640
+ if (isRecognized && recognizedPayment) {
641
+ if (isRecognizedCard) {
642
+ const targetPosition = (totalVisibleCards - 1) * (scaledCardWidth + scaledGap);
643
+ const currentPosition = index * (scaledCardWidth + scaledGap);
644
+ translateX = targetPosition - currentPosition;
645
+ opacity = 1;
646
+ } else {
647
+ translateX = containerWidth;
648
+ opacity = 0;
649
+ }
650
+ }
651
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
652
+ Box,
653
+ {
654
+ position: "absolute",
655
+ left: index * (scaledCardWidth + scaledGap),
656
+ style: {
657
+ transform: import_xui_core.isWeb ? `translateX(${translateX}px)` : void 0,
658
+ opacity,
659
+ ...import_xui_core.isWeb && { transition: "transform 300ms ease-out, opacity 300ms ease-out" }
660
+ },
661
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(IconComponent, { size: scaledCardHeight })
662
+ },
663
+ key
664
+ );
665
+ }),
666
+ cyclingCards.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
667
+ Box,
668
+ {
669
+ position: "absolute",
670
+ left: (maxVisible - 1) * (scaledCardWidth + scaledGap),
671
+ width: scaledCardWidth,
672
+ height: scaledCardHeight,
673
+ children: cyclingCards.map((key, index) => {
674
+ const IconComponent = paymentIconComponents[key];
675
+ const isCurrentCycling = index === cyclingIndex;
676
+ const isRecognizedCard = recognizedPayment === key;
677
+ let translateX = 0;
678
+ let opacity = isCurrentCycling && !isTransitioning ? 1 : 0;
679
+ if (isRecognized && recognizedPayment) {
680
+ if (isRecognizedCard) {
681
+ opacity = 1;
682
+ } else {
683
+ translateX = containerWidth;
684
+ opacity = 0;
685
+ }
686
+ }
687
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
688
+ Box,
689
+ {
690
+ position: "absolute",
691
+ top: 0,
692
+ left: 0,
693
+ style: {
694
+ transform: import_xui_core.isWeb ? `translateX(${translateX}px)` : void 0,
695
+ opacity,
696
+ ...import_xui_core.isWeb && {
697
+ transition: isRecognized ? "transform 300ms ease-out, opacity 300ms ease-out" : "opacity 150ms ease-in-out"
698
+ }
699
+ },
700
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(IconComponent, { size: scaledCardHeight })
701
+ },
702
+ key
703
+ );
704
+ })
705
+ }
706
+ )
707
+ ]
708
+ }
709
+ );
710
+ };
711
+ var InputPayment = (0, import_react4.forwardRef)(
712
+ ({
713
+ value,
714
+ icon,
715
+ placeholder = "Card number",
716
+ onChange,
717
+ onChangeText,
718
+ onKeyDown,
719
+ size = "m",
720
+ name,
721
+ disabled = false,
722
+ errorMessage,
723
+ error,
724
+ possiblePayments = DEFAULT_POSSIBLE_PAYMENTS,
725
+ maxVisiblePossiblePayments = 5,
726
+ recognizedPayment: controlledRecognizedPayment,
727
+ onRecognizedPaymentChange,
728
+ autoDetect = true,
729
+ id: providedId,
730
+ "aria-label": ariaLabel,
731
+ testID,
732
+ ...rest
733
+ }, ref) => {
734
+ const { theme } = (0, import_xui_core.useDesignSystem)();
735
+ const [internalState, setInternalState] = (0, import_react4.useState)(
736
+ "default"
737
+ );
738
+ const [passValue, setPassValue] = (0, import_react4.useState)(value ?? "");
739
+ const [detectedPayment, setDetectedPayment] = (0, import_react4.useState)(null);
740
+ const inputRef = (0, import_react4.useRef)(null);
741
+ const rawId = (0, import_xui_core.useId)();
742
+ const safeId = rawId.replace(/:/g, "");
743
+ const inputId = providedId || `input-payment-${safeId}`;
744
+ const errorId = `${inputId}-error`;
745
+ import_react4.default.useImperativeHandle(
746
+ ref,
747
+ () => inputRef.current,
748
+ []
749
+ );
750
+ (0, import_react4.useEffect)(() => {
751
+ if (value !== void 0) {
752
+ setPassValue(value);
753
+ }
754
+ }, [value]);
755
+ (0, import_react4.useEffect)(() => {
756
+ if (autoDetect && passValue) {
757
+ const detected = detectPaymentSystem(passValue);
758
+ const validDetected = detected && possiblePayments.includes(detected) ? detected : null;
759
+ setDetectedPayment(validDetected);
760
+ onRecognizedPaymentChange?.(validDetected);
761
+ } else if (!passValue) {
762
+ setDetectedPayment(null);
763
+ if (autoDetect) {
764
+ onRecognizedPaymentChange?.(null);
765
+ }
766
+ }
767
+ }, [passValue, autoDetect, onRecognizedPaymentChange, possiblePayments]);
768
+ const isDisable = disabled;
769
+ const isError = !!(errorMessage || error);
770
+ const isFocus = internalState === "focus";
771
+ const displayRecognizedPayment = controlledRecognizedPayment ?? detectedPayment;
772
+ const sizeStyles = theme.sizing.input(size);
773
+ const inputColors = theme.colors.control.input;
774
+ const handleFocus = () => {
775
+ if (!isDisable) {
776
+ setInternalState("focus");
777
+ }
778
+ };
779
+ const handleBlur = () => {
780
+ if (!isDisable) {
781
+ setInternalState("default");
782
+ }
783
+ };
784
+ const handleChange = (e) => {
785
+ const newValue = e.target.value;
786
+ if (onChange) {
787
+ onChange(e);
788
+ }
789
+ if (onChangeText) {
790
+ onChangeText(newValue);
791
+ }
792
+ setPassValue(newValue);
793
+ };
794
+ const handleKeyDown = (e) => {
795
+ if (e.key === "Escape") {
796
+ e.currentTarget.blur();
797
+ }
798
+ if (onKeyDown) {
799
+ onKeyDown(e);
800
+ }
801
+ };
802
+ let backgroundColor = inputColors.bg;
803
+ let borderColor = inputColors.border;
804
+ let outlineColor;
805
+ if (isDisable) {
806
+ backgroundColor = inputColors.bgDisable;
807
+ borderColor = inputColors.borderDisable;
808
+ } else if (isError) {
809
+ outlineColor = theme.colors.border.alert;
810
+ if (isFocus) {
811
+ backgroundColor = theme.colors.control.focus.bg;
812
+ }
813
+ } else if (isFocus) {
814
+ backgroundColor = theme.colors.control.focus.bg;
815
+ outlineColor = theme.colors.border.brand;
816
+ }
817
+ const textColor = isDisable ? inputColors.textDisable : inputColors.text;
818
+ const placeholderColor = inputColors.placeholder;
819
+ const iconColor = inputColors.placeholder;
820
+ const paddingConfig = {
821
+ xl: { vertical: 12, horizontal: 12 },
822
+ l: { vertical: 14, horizontal: 12 },
823
+ m: { vertical: 11, horizontal: 12 },
824
+ s: { vertical: 7, horizontal: 10 },
825
+ xs: { vertical: 7, horizontal: 10 }
826
+ };
827
+ const borderRadiusConfig = {
828
+ xl: 4,
829
+ l: 4,
830
+ m: 2,
831
+ s: 2,
832
+ xs: 2
833
+ };
834
+ const iconSizeConfig = {
835
+ xl: 18,
836
+ l: 18,
837
+ m: 18,
838
+ s: 16,
839
+ xs: 16
840
+ };
841
+ const focusOutlineConfig = {
842
+ xl: { width: 2, offset: -2 },
843
+ l: { width: 2, offset: -2 },
844
+ m: { width: 1, offset: -1 },
845
+ s: { width: 1, offset: -1 },
846
+ xs: { width: 1, offset: -1 }
847
+ };
848
+ const padding = paddingConfig[size];
849
+ const borderRadius = borderRadiusConfig[size];
850
+ const iconSize = iconSizeConfig[size];
851
+ const focusOutline = focusOutlineConfig[size];
852
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(Box, { flexDirection: "column", gap: 8, width: "100%", testID, children: [
853
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
854
+ Box,
855
+ {
856
+ backgroundColor,
857
+ borderColor,
858
+ borderWidth: borderColor !== "transparent" ? 1 : 0,
859
+ borderRadius,
860
+ height: sizeStyles.height,
861
+ paddingVertical: padding.vertical,
862
+ paddingHorizontal: padding.horizontal,
863
+ flexDirection: "row",
864
+ alignItems: "center",
865
+ gap: 10,
866
+ position: "relative",
867
+ style: {
868
+ ...outlineColor ? {
869
+ outline: `${focusOutline.width}px solid ${outlineColor}`,
870
+ outlineOffset: `${focusOutline.offset}px`
871
+ } : {}
872
+ },
873
+ hoverStyle: !isDisable && !isFocus && !isError ? {
874
+ backgroundColor: inputColors.bgHover,
875
+ borderColor: inputColors.borderHover
876
+ } : void 0,
877
+ children: [
878
+ icon && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
879
+ Box,
880
+ {
881
+ alignItems: "center",
882
+ justifyContent: "center",
883
+ role: "img",
884
+ "aria-hidden": "true",
885
+ children: import_react4.default.isValidElement(icon) ? import_react4.default.cloneElement(icon, {
886
+ size: iconSize,
887
+ color: iconColor
888
+ }) : icon
889
+ }
890
+ ),
891
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Box, { flex: 1, height: "100%", justifyContent: "center", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
892
+ InputPrimitive,
893
+ {
894
+ ref: inputRef,
895
+ id: inputId,
896
+ value: passValue,
897
+ name,
898
+ placeholder,
899
+ onChange: handleChange,
900
+ onFocus: handleFocus,
901
+ onBlur: handleBlur,
902
+ onKeyDown: handleKeyDown,
903
+ disabled: isDisable,
904
+ type: "text",
905
+ inputMode: "numeric",
906
+ autoComplete: "off",
907
+ color: textColor,
908
+ fontSize: sizeStyles.fontSize,
909
+ placeholderTextColor: placeholderColor,
910
+ "aria-invalid": isError || void 0,
911
+ "aria-describedby": errorMessage ? errorId : void 0,
912
+ "aria-label": ariaLabel || "Card number",
913
+ "aria-disabled": isDisable || void 0,
914
+ "data-testid": "input-payment__field",
915
+ ...rest
916
+ }
917
+ ) }),
918
+ possiblePayments.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
919
+ Box,
920
+ {
921
+ alignItems: "center",
922
+ justifyContent: "center",
923
+ "data-testid": "input-payment__card-icons",
924
+ style: { overflow: "hidden" },
925
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
926
+ PaymentIcons,
927
+ {
928
+ possiblePayments,
929
+ maxVisible: maxVisiblePossiblePayments,
930
+ recognizedPayment: displayRecognizedPayment,
931
+ iconHeight: iconSize
932
+ }
933
+ )
934
+ }
935
+ )
936
+ ]
937
+ }
938
+ ),
939
+ errorMessage && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
940
+ Text,
941
+ {
942
+ id: errorId,
943
+ role: "alert",
944
+ color: theme.colors.content.alert.primary,
945
+ fontSize: sizeStyles.fontSize - 2,
946
+ children: errorMessage
947
+ }
948
+ )
949
+ ] });
950
+ }
951
+ );
952
+ InputPayment.displayName = "InputPayment";
953
+ // Annotate the CommonJS export names for ESM import in node:
954
+ 0 && (module.exports = {
955
+ InputPayment
956
+ });
957
+ //# sourceMappingURL=index.js.map