@everymatrix/player-limit-notification-nd 0.0.1

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.
Files changed (61) hide show
  1. package/dist/cjs/app-globals-3a1e7e63.js +5 -0
  2. package/dist/cjs/index-8f6e611d.js +1261 -0
  3. package/dist/cjs/index.cjs.js +10 -0
  4. package/dist/cjs/loader.cjs.js +15 -0
  5. package/dist/cjs/player-limit-notification-nd-c65673d9.js +7505 -0
  6. package/dist/cjs/player-limit-notification-nd.cjs.entry.js +10 -0
  7. package/dist/cjs/player-limit-notification-nd.cjs.js +25 -0
  8. package/dist/collection/collection-manifest.json +12 -0
  9. package/dist/collection/components/player-limit-notification-nd/index.js +1 -0
  10. package/dist/collection/components/player-limit-notification-nd/limitConfig.js +50 -0
  11. package/dist/collection/components/player-limit-notification-nd/player-limit-notification-nd.css +315 -0
  12. package/dist/collection/components/player-limit-notification-nd/player-limit-notification-nd.js +815 -0
  13. package/dist/collection/index.js +1 -0
  14. package/dist/collection/utils/locale.utils.js +131 -0
  15. package/dist/collection/utils/types.js +19 -0
  16. package/dist/collection/utils/utils.js +3 -0
  17. package/dist/esm/app-globals-0f993ce5.js +3 -0
  18. package/dist/esm/index-92f4161f.js +1234 -0
  19. package/dist/esm/index.js +2 -0
  20. package/dist/esm/loader.js +11 -0
  21. package/dist/esm/player-limit-notification-nd-c9cf02e4.js +7503 -0
  22. package/dist/esm/player-limit-notification-nd.entry.js +2 -0
  23. package/dist/esm/player-limit-notification-nd.js +20 -0
  24. package/dist/index.cjs.js +1 -0
  25. package/dist/index.js +1 -0
  26. package/dist/player-limit-notification-nd/app-globals-0f993ce5.js +1 -0
  27. package/dist/player-limit-notification-nd/index-92f4161f.js +2 -0
  28. package/dist/player-limit-notification-nd/index.esm.js +1 -0
  29. package/dist/player-limit-notification-nd/player-limit-notification-nd-c9cf02e4.js +6657 -0
  30. package/dist/player-limit-notification-nd/player-limit-notification-nd.entry.js +1 -0
  31. package/dist/player-limit-notification-nd/player-limit-notification-nd.esm.js +1 -0
  32. package/dist/stencil.config.dev.js +19 -0
  33. package/dist/stencil.config.js +19 -0
  34. package/dist/storybook/main.js +43 -0
  35. package/dist/storybook/preview.js +9 -0
  36. package/dist/types/builds/emfe-widgets/widgets-monorepo/packages/stencil/player-limit-notification-nd/.stencil/libs/common/src/storybook/storybook-utils.d.ts +39 -0
  37. package/dist/types/builds/emfe-widgets/widgets-monorepo/packages/stencil/player-limit-notification-nd/.stencil/packages/stencil/player-limit-notification-nd/stencil.config.d.ts +2 -0
  38. package/dist/types/builds/emfe-widgets/widgets-monorepo/packages/stencil/player-limit-notification-nd/.stencil/packages/stencil/player-limit-notification-nd/stencil.config.dev.d.ts +2 -0
  39. package/dist/types/builds/emfe-widgets/widgets-monorepo/packages/stencil/player-limit-notification-nd/.stencil/packages/stencil/player-limit-notification-nd/storybook/main.d.ts +3 -0
  40. package/dist/types/builds/emfe-widgets/widgets-monorepo/packages/stencil/player-limit-notification-nd/.stencil/packages/stencil/player-limit-notification-nd/storybook/preview.d.ts +70 -0
  41. package/dist/types/builds/emfe-widgets/widgets-monorepo/packages/stencil/player-limit-notification-nd/.stencil/tools/plugins/index.d.ts +4 -0
  42. package/dist/types/builds/emfe-widgets/widgets-monorepo/packages/stencil/player-limit-notification-nd/.stencil/tools/plugins/lazy-load-chunk-plugin.d.ts +12 -0
  43. package/dist/types/builds/emfe-widgets/widgets-monorepo/packages/stencil/player-limit-notification-nd/.stencil/tools/plugins/stencil-clean-deps-plugin.d.ts +5 -0
  44. package/dist/types/builds/emfe-widgets/widgets-monorepo/packages/stencil/player-limit-notification-nd/.stencil/tools/plugins/vite-chunk-plugin.d.ts +6 -0
  45. package/dist/types/builds/emfe-widgets/widgets-monorepo/packages/stencil/player-limit-notification-nd/.stencil/tools/plugins/vite-clean-deps-plugin.d.ts +4 -0
  46. package/dist/types/components/player-limit-notification-nd/index.d.ts +1 -0
  47. package/dist/types/components/player-limit-notification-nd/limitConfig.d.ts +50 -0
  48. package/dist/types/components/player-limit-notification-nd/player-limit-notification-nd.d.ts +71 -0
  49. package/dist/types/components.d.ts +61 -0
  50. package/dist/types/index.d.ts +1 -0
  51. package/dist/types/stencil-public-runtime.d.ts +1674 -0
  52. package/dist/types/utils/locale.utils.d.ts +2 -0
  53. package/dist/types/utils/types.d.ts +69 -0
  54. package/dist/types/utils/utils.d.ts +1 -0
  55. package/loader/cdn.js +1 -0
  56. package/loader/index.cjs.js +1 -0
  57. package/loader/index.d.ts +24 -0
  58. package/loader/index.es2017.js +1 -0
  59. package/loader/index.js +2 -0
  60. package/loader/package.json +11 -0
  61. package/package.json +27 -0
@@ -0,0 +1,815 @@
1
+ import { h, Fragment } from "@stencil/core";
2
+ import { translate, getTranslations } from "../../utils/locale.utils";
3
+ import { setClientStyling, setClientStylingURL, setStreamStyling } from "../../../../../../../../libs/common/src/styling/index";
4
+ import { LimitPeriod, LimitType } from "../../utils/types";
5
+ import { DefaultLimitConfig } from "./limitConfig";
6
+ import "../../../../../../../libs/vaadin-facade/index";
7
+ export class PlayerLimitNotificationNd {
8
+ constructor() {
9
+ this.MATCH_CONFIG_AMOUNT = /^(\w+)\((\w+)\):(\d+)-(\d+)$/;
10
+ this.MATCH_CONFIG_PERIOD = /^(\w+)\((\w+)\):([A-Z\-]+)$/;
11
+ this.defaultPeriods = [LimitPeriod.DAILY, LimitPeriod.WEEKLY, LimitPeriod.MONTHLY];
12
+ this.fetchSkipLimit = () => {
13
+ const url = new URL(`${this.endpoint}/api/pam/v1/player-notifications`);
14
+ url.searchParams.append('createNotificationIfNotFound', 'true');
15
+ this.loading = true;
16
+ fetch(url, {
17
+ headers: {
18
+ 'X-SessionId': this.session,
19
+ 'Content-Type': 'application/json'
20
+ },
21
+ method: 'PATCH',
22
+ body: JSON.stringify({
23
+ type: 1,
24
+ interval: 5,
25
+ ackNotification: true,
26
+ ackNotificationTimestamp: new Date().toISOString()
27
+ })
28
+ })
29
+ .then((res) => {
30
+ if (res.ok) {
31
+ return res.json();
32
+ }
33
+ window.postMessage({
34
+ type: 'WidgetNotification',
35
+ data: {
36
+ type: 'error',
37
+ message: translate('limitNotificationFail', this.language)
38
+ }
39
+ }, window.location.href);
40
+ throw new Error(`Error while skipping the limit setting`);
41
+ })
42
+ .then(() => {
43
+ window.postMessage({
44
+ type: 'WidgetNotification',
45
+ data: {
46
+ type: 'success',
47
+ message: translate('setLimitSuccessful', this.language)
48
+ }
49
+ }, window.location.href);
50
+ window.postMessage({ type: 'SubmitLimitNotificationSuccess' }, window.location.href);
51
+ })
52
+ .catch((error) => {
53
+ console.error(error);
54
+ })
55
+ .finally(() => {
56
+ this.loading = false;
57
+ });
58
+ };
59
+ this.mbSource = undefined;
60
+ this.clientStyling = undefined;
61
+ this.clientStylingUrl = undefined;
62
+ this.session = undefined;
63
+ this.userid = undefined;
64
+ this.language = undefined;
65
+ this.endpoint = undefined;
66
+ this.limitsamount = undefined;
67
+ this.limitsperiods = undefined;
68
+ this.currency = undefined;
69
+ this.customcurrencysymbols = undefined;
70
+ this.translationurl = '';
71
+ this.limitItems = [{}];
72
+ this.limitTypeOptions = [];
73
+ this.skipLimit = false;
74
+ this.loading = false;
75
+ this.confirmPopupVisibility = false;
76
+ }
77
+ get currencySymbolMap() {
78
+ const customSymbols = {};
79
+ const defaultCurrencySymbols = {
80
+ EUR: '€',
81
+ RON: ' lei',
82
+ USD: '$'
83
+ };
84
+ if (this.customcurrencysymbols) {
85
+ this.customcurrencysymbols.split(',').forEach((symbol) => {
86
+ let symbolParts = symbol.split(':');
87
+ customSymbols[symbolParts[0].trim()] = symbolParts[1].trim();
88
+ });
89
+ }
90
+ return Object.assign(Object.assign({}, defaultCurrencySymbols), customSymbols);
91
+ }
92
+ handleClientStylingChange(newValue, oldValue) {
93
+ if (newValue != oldValue) {
94
+ setClientStyling(this.stylingContainer, this.clientStyling);
95
+ }
96
+ }
97
+ handleClientStylingUrlChange(newValue, oldValue) {
98
+ if (newValue != oldValue) {
99
+ setClientStylingURL(this.stylingContainer, this.clientStylingUrl);
100
+ }
101
+ }
102
+ handleMbSourceChange(newValue, oldValue) {
103
+ if (newValue != oldValue) {
104
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
105
+ }
106
+ }
107
+ componentDidLoad() {
108
+ if (this.stylingContainer) {
109
+ if (this.mbSource)
110
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
111
+ if (this.clientStyling)
112
+ setClientStyling(this.stylingContainer, this.clientStyling);
113
+ if (this.clientStylingUrl)
114
+ setClientStylingURL(this.stylingContainer, this.clientStylingUrl);
115
+ }
116
+ }
117
+ async componentWillLoad() {
118
+ if (this.translationurl.length > 2) {
119
+ await getTranslations(this.translationurl);
120
+ }
121
+ await this.parseLimitConfigs();
122
+ }
123
+ eventParamsToTranslationKeys(x) {
124
+ return `dataLayer-${x}`;
125
+ }
126
+ emitGtag(eventName, limitItem) {
127
+ //@ts-ignore
128
+ if (typeof gtag == 'function') {
129
+ //@ts-ignore
130
+ gtag({
131
+ event: eventName,
132
+ limit_category: translate(this.eventParamsToTranslationKeys(limitItem.product.toLowerCase()), this.language) ||
133
+ limitItem.product,
134
+ limit_type: translate(this.eventParamsToTranslationKeys(limitItem.type.toLowerCase())) || limitItem.type,
135
+ limit_period: translate(this.eventParamsToTranslationKeys(limitItem.period), this.language) || limitItem.period,
136
+ limit_amount: limitItem.amount
137
+ });
138
+ }
139
+ }
140
+ disconnectedCallback() {
141
+ this.stylingSubscription && this.stylingSubscription.unsubscribe();
142
+ }
143
+ parsePeriodsConfig(periodItem) {
144
+ const match = periodItem.match(this.MATCH_CONFIG_PERIOD);
145
+ const periodMap = {
146
+ D: 'daily',
147
+ W: 'weekly',
148
+ M: 'monthly',
149
+ N: 'none'
150
+ };
151
+ const periodsOptions = [];
152
+ if (match) {
153
+ const [, , , periodStr] = match;
154
+ periodStr.split('-').forEach((code) => {
155
+ if (periodMap[code]) {
156
+ periodsOptions.push(periodMap[code]);
157
+ }
158
+ else {
159
+ throw new Error(`Unknown period code: ${code}`);
160
+ }
161
+ });
162
+ }
163
+ return periodsOptions;
164
+ }
165
+ async parseLimitConfigs() {
166
+ const amountsArray = this.limitsamount.replace(/\s/g, '').split('|');
167
+ const periodsArray = this.limitsperiods.replace(/\s/g, '').split('|');
168
+ if (amountsArray.length === 0) {
169
+ throw new Error('Please provide a full limits configuration.');
170
+ }
171
+ else if (amountsArray.length !== periodsArray.length) {
172
+ throw new Error('Please make sure that the limit configuration parameters specify the same number of tabs.');
173
+ }
174
+ try {
175
+ for (let i = 0; i < amountsArray.length; i++) {
176
+ const amountSection = amountsArray[i];
177
+ const periodSection = periodsArray[i];
178
+ const amountItems = amountSection.split(',');
179
+ const periodItems = periodSection.split(',');
180
+ amountItems.forEach((item, index) => {
181
+ const match = item.match(this.MATCH_CONFIG_AMOUNT);
182
+ if (match) {
183
+ const periodOptions = this.parsePeriodsConfig(periodItems[index]);
184
+ const [, product, type, min, max] = match;
185
+ const limitTypeObject = {
186
+ type: type,
187
+ product,
188
+ min: parseInt(min, 10),
189
+ max: parseInt(max, 10),
190
+ label: `${DefaultLimitConfig[type].title} - ${product}`,
191
+ periodOptions,
192
+ selectedKey: `${type}-${product}`
193
+ };
194
+ this.limitTypeOptions.push(limitTypeObject);
195
+ }
196
+ });
197
+ }
198
+ }
199
+ catch (error) {
200
+ throw new Error(`Error parsing limit config: ${error}`);
201
+ }
202
+ await this.filterExistingLimits();
203
+ this.limitTypeOptions = [...this.limitTypeOptions];
204
+ }
205
+ async filterExistingLimits() {
206
+ try {
207
+ const { sessionLimit, cumulativeSessionLimits, monetaryLimits } = await this.getLimits16();
208
+ if (sessionLimit) {
209
+ this.limitTypeOptions = this.limitTypeOptions.filter((item) => item.type === LimitType.SESSION_LIMIT);
210
+ }
211
+ const limitsLookup = new Map();
212
+ monetaryLimits.forEach((limit) => {
213
+ var _a;
214
+ const key = `${(_a = limit.products) === null || _a === void 0 ? void 0 : _a[0]}-${limit.type}`.toLowerCase();
215
+ const periods = limitsLookup.get(key) || new Set();
216
+ periods.add(limit.period.toLowerCase());
217
+ limitsLookup.set(key, periods);
218
+ });
219
+ this.limitTypeOptions = this.limitTypeOptions
220
+ .map((option) => {
221
+ const key = `${option.product}-${option.type}`.toLowerCase();
222
+ let existingPeriods = limitsLookup.get(key) || new Set();
223
+ if (option.type === LimitType.CUMULATIVE_SESSION && cumulativeSessionLimits) {
224
+ existingPeriods = new Set(cumulativeSessionLimits.map((item) => item.period.toLowerCase()));
225
+ }
226
+ const filteredPeriodOptions = option.periodOptions.filter((period) => !existingPeriods.has(period));
227
+ return filteredPeriodOptions.length > 0 ? Object.assign(Object.assign({}, option), { periodOptions: filteredPeriodOptions }) : null;
228
+ })
229
+ .filter(Boolean);
230
+ }
231
+ catch (e) {
232
+ console.error('error getting limits', e);
233
+ }
234
+ }
235
+ async getLimits16() {
236
+ const fetchSessionLimits = this.limitTypeOptions.some((limit) => limit.type === LimitType.SESSION_LIMIT || limit.type === LimitType.CUMULATIVE_SESSION);
237
+ const monetaryUrl = new URL(`${this.endpoint}/v1/player/${this.userid}/limits/monetary`);
238
+ const optionsEditLimits = {
239
+ method: 'GET',
240
+ headers: {
241
+ 'X-SessionID': this.session,
242
+ 'Content-Type': 'application/json',
243
+ Accept: 'application/json'
244
+ }
245
+ };
246
+ const res = await fetch(monetaryUrl.href, optionsEditLimits);
247
+ if (res.status >= 300) {
248
+ throw new Error(`An error occured during the fetch request`);
249
+ }
250
+ const limitData = (await res.json());
251
+ const monetaryLimits = (limitData === null || limitData === void 0 ? void 0 : limitData.limits) || [];
252
+ let sessionLimit = null;
253
+ let cumulativeSessionLimits = null;
254
+ if (fetchSessionLimits) {
255
+ const sessionUrl = new URL(`${this.endpoint}/v1/player/${this.userid}/limits/session`);
256
+ const sessionRes = await fetch(sessionUrl.href, optionsEditLimits);
257
+ if (sessionRes.status >= 300) {
258
+ throw new Error(`An error occured during the fetch request`);
259
+ }
260
+ const res = (await sessionRes.json());
261
+ sessionLimit = res === null || res === void 0 ? void 0 : res.sessionLimit;
262
+ cumulativeSessionLimits = res === null || res === void 0 ? void 0 : res.cumulativeSessionLimits;
263
+ }
264
+ return {
265
+ sessionLimit,
266
+ cumulativeSessionLimits,
267
+ monetaryLimits
268
+ };
269
+ }
270
+ handleSelectLimitType(e, item) {
271
+ const selectedKey = e.target.value;
272
+ const selectedOption = this.limitTypeOptions.find((item) => item.selectedKey === selectedKey);
273
+ Object.assign(item, Object.assign(Object.assign({}, selectedOption), { selectedKey, typeErrorMessage: null }));
274
+ // trigger rerender
275
+ this.limitItems = [...this.limitItems];
276
+ if (this.isDisabledPeriod(item, item.period)) {
277
+ // reset duplicate periods
278
+ item.period = null;
279
+ }
280
+ }
281
+ handleSelectLimitPeriod(period, item) {
282
+ Object.assign(item, {
283
+ period,
284
+ periodErrorMessage: null
285
+ });
286
+ this.limitItems = [...this.limitItems];
287
+ }
288
+ isDisabledPeriod(limitItem, period) {
289
+ if (!limitItem.type) {
290
+ return false;
291
+ }
292
+ const otherSameTypeLimits = this.limitItems.filter((item) => item !== limitItem && item.selectedKey === limitItem.selectedKey);
293
+ return otherSameTypeLimits.some((item) => item.period === period);
294
+ }
295
+ validateSave() {
296
+ if (this.skipLimit) {
297
+ return true;
298
+ }
299
+ let canSave = true;
300
+ this.limitItems.forEach((item) => {
301
+ var _a;
302
+ Object.assign(item, {
303
+ amountErrorMessage: null,
304
+ periodErrorMessage: null,
305
+ typeErrorMessage: null
306
+ });
307
+ item.amountErrorMessage = this.getAmountErrorMsg(item);
308
+ if (!item.period && !((_a = item.periodOptions) === null || _a === void 0 ? void 0 : _a.includes(LimitPeriod.NONE))) {
309
+ item.periodErrorMessage = translate('emptyPeriodWarning', this.language);
310
+ }
311
+ if (!item.type) {
312
+ item.typeErrorMessage = translate('emptyLimitTypeWarning', this.language);
313
+ }
314
+ if (item.amountErrorMessage || item.typeErrorMessage || item.periodErrorMessage) {
315
+ canSave = false;
316
+ }
317
+ });
318
+ this.limitItems = [...this.limitItems];
319
+ return canSave;
320
+ }
321
+ handleSaveLimit() {
322
+ var _a, _b, _c;
323
+ const canSave = this.validateSave();
324
+ if (!canSave) {
325
+ return;
326
+ }
327
+ if (this.skipLimit) {
328
+ const hasMultipleItems = this.limitItems.length > 1;
329
+ const hasFirstItemData = typeof ((_a = this.limitItems[0]) === null || _a === void 0 ? void 0 : _a.amount) === 'number' || ((_b = this.limitItems[0]) === null || _b === void 0 ? void 0 : _b.period) || ((_c = this.limitItems[0]) === null || _c === void 0 ? void 0 : _c.type);
330
+ if (hasMultipleItems || hasFirstItemData) {
331
+ this.doubleConfirmSkip();
332
+ }
333
+ else {
334
+ this.fetchSkipLimit();
335
+ }
336
+ return;
337
+ }
338
+ this.fetchUpdateLimit();
339
+ }
340
+ doubleConfirmSkip() {
341
+ this.confirmPopupVisibility = true;
342
+ }
343
+ handleCloseConfirm() {
344
+ this.confirmPopupVisibility = false;
345
+ }
346
+ handleSaveSkip() {
347
+ this.handleCloseConfirm();
348
+ this.fetchSkipLimit();
349
+ }
350
+ async fetchUpdateLimit() {
351
+ this.loading = true;
352
+ const updateLimitCalls = [];
353
+ this.limitItems.forEach((limitItem) => {
354
+ switch (limitItem.type) {
355
+ case 'lugas':
356
+ updateLimitCalls.push(this.createSubmitLimitCall(this.updateLugasCall, limitItem));
357
+ break;
358
+ case 'sessionLimit':
359
+ updateLimitCalls.push(this.createSubmitLimitCall(this.updateSingleSessionLimit16Call, limitItem));
360
+ break;
361
+ case 'cumulativeSession':
362
+ updateLimitCalls.push(this.createSubmitLimitCall(this.updateCumulativeSessionLimit16Call, limitItem));
363
+ break;
364
+ default:
365
+ updateLimitCalls.push(this.createSubmitLimitCall(this.updateMonetaryLimits16Call, limitItem));
366
+ break;
367
+ }
368
+ });
369
+ const results = await Promise.allSettled(updateLimitCalls.map((call) => call()));
370
+ const successful = results.filter((result) => result.status === 'fulfilled');
371
+ const failed = results.filter((result) => result.status === 'rejected');
372
+ this.loading = false;
373
+ if (failed.length === updateLimitCalls.length) {
374
+ window.postMessage({
375
+ type: 'WidgetNotification',
376
+ data: {
377
+ type: 'error',
378
+ message: translate('limitNotificationFail', this.language)
379
+ }
380
+ }, window.location.href);
381
+ return;
382
+ }
383
+ if (successful.length === updateLimitCalls.length) {
384
+ window.postMessage({
385
+ type: 'WidgetNotification',
386
+ data: {
387
+ type: 'success',
388
+ message: translate('setLimitSuccessful', this.language)
389
+ }
390
+ });
391
+ window.postMessage({ type: 'SubmitLimitNotificationSuccess' }, window.location.href);
392
+ return;
393
+ }
394
+ if (failed.length) {
395
+ window.postMessage({
396
+ type: 'WidgetNotification',
397
+ data: {
398
+ type: 'info',
399
+ config: {
400
+ enableHtml: true
401
+ },
402
+ message: translate('partialFailedUpdateLimit', this.language, {
403
+ values: {
404
+ accountLimitPath: `/${this.language}/account/limits`
405
+ }
406
+ })
407
+ }
408
+ }, window.location.href);
409
+ window.postMessage({ type: 'SubmitLimitNotificationSuccess' }, window.location.href);
410
+ }
411
+ }
412
+ createSubmitLimitCall(fetchMethod, limitItem) {
413
+ return async () => {
414
+ try {
415
+ const res = await fetchMethod.bind(this)(limitItem);
416
+ if (res.status >= 300) {
417
+ throw new Error(`An error occured during the fetch request`);
418
+ }
419
+ this.emitGtag('self_limitation_success', limitItem);
420
+ }
421
+ catch (e) {
422
+ console.error('error while updating limit', e);
423
+ throw new Error(`error while updating limit: ${e}`);
424
+ }
425
+ };
426
+ }
427
+ updateLugasCall(limitItem) {
428
+ const url = new URL(`${this.endpoint}/v2/player/${this.userid}/limit/lugas`);
429
+ const method = 'POST';
430
+ const body = {
431
+ amount: limitItem.amount,
432
+ roleLimitAmount: 0,
433
+ softMigration: false,
434
+ keepLimit: false
435
+ };
436
+ let optionsEditLimits = {
437
+ method,
438
+ headers: {
439
+ 'X-SessionID': this.session,
440
+ 'Content-Type': 'application/json',
441
+ Accept: 'application/json'
442
+ },
443
+ body: JSON.stringify(body)
444
+ };
445
+ return fetch(url.href, optionsEditLimits);
446
+ }
447
+ updateSingleSessionLimit16Call(limitItem) {
448
+ const url = new URL(`${this.endpoint}/v1/player/${this.userid}/limits/session/`);
449
+ const method = 'PUT';
450
+ const putBody = { sessionLimit: limitItem.amount, sessionLimitUnit: 'minute' };
451
+ let optionsEditLimits = {
452
+ method,
453
+ headers: {
454
+ 'X-SessionID': this.session,
455
+ 'Content-Type': 'application/json',
456
+ Accept: 'application/json'
457
+ },
458
+ body: JSON.stringify(putBody)
459
+ };
460
+ return fetch(url.href, optionsEditLimits);
461
+ }
462
+ // // daily -> Daily ...
463
+ capitalizeFirst(str) {
464
+ return str[0].toUpperCase() + str.substring(1);
465
+ }
466
+ updateCumulativeSessionLimit16Call(limitItem) {
467
+ const url = new URL(`${this.endpoint}/v1/player/${this.userid}/limits/session/`);
468
+ const method = 'PUT';
469
+ const putBody = {
470
+ cumulativeSessionLimits: [
471
+ {
472
+ period: this.capitalizeFirst(limitItem.period),
473
+ minutes: limitItem.amount
474
+ }
475
+ ]
476
+ };
477
+ let optionsEditLimits = {
478
+ method,
479
+ headers: {
480
+ 'X-SessionID': this.session,
481
+ 'Content-Type': 'application/json',
482
+ Accept: 'application/json'
483
+ },
484
+ body: JSON.stringify(putBody)
485
+ };
486
+ return fetch(url.href, optionsEditLimits);
487
+ }
488
+ updateMonetaryLimits16Call(limitItem) {
489
+ var _a;
490
+ const url = new URL(`${this.endpoint}/v1/player/${this.userid}/limits/monetary/`);
491
+ const body = {
492
+ amount: limitItem.amount,
493
+ currency: this.currency,
494
+ period: this.capitalizeFirst(limitItem.period),
495
+ type: DefaultLimitConfig[limitItem.type].callValue16,
496
+ products: [(_a = limitItem.product) !== null && _a !== void 0 ? _a : 'All'],
497
+ walletTypes: ['Deposit', 'NetDeposit'].includes(DefaultLimitConfig[limitItem.type].callValue16)
498
+ ? ['All']
499
+ : ['RealCash']
500
+ };
501
+ let optionsEditLimits = {
502
+ method: 'POST',
503
+ headers: {
504
+ 'X-SessionID': this.session,
505
+ 'Content-Type': 'application/json',
506
+ Accept: 'application/json'
507
+ },
508
+ body: JSON.stringify(body)
509
+ };
510
+ return fetch(url.href, optionsEditLimits);
511
+ }
512
+ handleBlockInputWheel(e) {
513
+ e.preventDefault();
514
+ }
515
+ handleSkipLimitChange(e) {
516
+ this.skipLimit = e.target.checked;
517
+ }
518
+ handleAddLimit() {
519
+ this.limitItems = [...this.limitItems, {}];
520
+ }
521
+ handleRemoveLimit(limitIndex) {
522
+ this.limitItems.splice(limitIndex, 1);
523
+ this.limitItems = [...this.limitItems];
524
+ }
525
+ handleInputLimitAmount(e, item) {
526
+ const inputAmount = Number(e.target.value);
527
+ if (typeof inputAmount !== 'number' || Number.isNaN(inputAmount)) {
528
+ item.amountErrorMessage = translate('invalidAmount', this.language);
529
+ return;
530
+ }
531
+ const isFloat = !Number.isInteger(inputAmount);
532
+ const rounded = isFloat ? Math.round(inputAmount) : inputAmount;
533
+ item.amount = rounded;
534
+ item.amountErrorMessage = this.getAmountErrorMsg(item);
535
+ this.limitItems = [...this.limitItems];
536
+ }
537
+ getAmountErrorMsg(item) {
538
+ if (typeof item.amount !== 'number' || Number.isNaN(item.amount)) {
539
+ return translate('invalidAmount', this.language);
540
+ }
541
+ let amountErrorMessage = null;
542
+ if (item.amount < item.min) {
543
+ amountErrorMessage = translate('invalidInputMessageLimitMin', this.language, {
544
+ values: {
545
+ minValue: item.min,
546
+ currency: this.currency
547
+ }
548
+ });
549
+ }
550
+ if (item.amount > item.max) {
551
+ amountErrorMessage = translate('invalidInputMessageLimitMax', this.language, {
552
+ values: {
553
+ maxValue: item.max,
554
+ currency: this.currency
555
+ }
556
+ });
557
+ }
558
+ return amountErrorMessage;
559
+ }
560
+ renderPeriodButtons(limitItem) {
561
+ const periodOptions = limitItem.periodOptions || this.defaultPeriods;
562
+ if (periodOptions.includes(LimitPeriod.NONE)) {
563
+ return '';
564
+ }
565
+ return (h(Fragment, null, h("div", { class: "limit-item-period" }, h("label", { class: "limit-period-label" }, translate('selectLimitPeriodLabel', this.language)), h("div", { class: "limit-period-wrapper" }, periodOptions.map((period) => (h("button", { class: `
566
+ limit-period-option
567
+ ${limitItem.period === period ? 'selected' : ''}
568
+ `, disabled: this.isDisabledPeriod(limitItem, period), onClick: () => this.handleSelectLimitPeriod(period, limitItem) }, translate(period, this.language)))))), h("small", { class: "error-message" }, limitItem.periodErrorMessage)));
569
+ }
570
+ render() {
571
+ return (h("div", { key: 'ae3dad7b876e7d9ceb250f234c3e1747fdc889d6', class: "player-limit-modal", ref: (el) => (this.stylingContainer = el) }, h("section", { key: '1c1ff957e5d7fa274e92a5962185e6dcc5ca2472', class: "limit-modal-container" }, h("div", { key: '3043c525a39bf35f91614deadbd808d3bad4758b', class: "limit-modal-title" }, h("h2", { key: '88160571e334767c68269ed6fcb44c467617f4c6' }, translate('limitNotificationTitle', this.language)), h("p", { key: '0cdd7545ef845e0f22d74386df28d9a5e97ec3e5' }, translate('limitNotificationSubTitle', this.language))), h("div", { key: '78119df2f63cca751404d0f749a686336256e6ab', class: `limit-modal-content ${this.skipLimit || this.loading ? 'disable-content' : ''}` }, this.limitItems.map((item, index) => (h("div", { class: "limit-item" }, h("div", { class: "limit-item-type" }, h("label", { class: "type-select-label" }, translate('selectLimitTypeLabel', this.language)), h("div", null, h("vaadin-combo-box", { value: item.selectedKey, items: this.limitTypeOptions, "no-vertical-overlap": true, "item-label-path": "label", "item-value-path": "selectedKey", placeholder: translate('selectLimitTypePlaceholder', this.language), onChange: (e) => this.handleSelectLimitType(e, item) })), h("small", { class: "error-message" }, item.typeErrorMessage)), this.renderPeriodButtons(item), h("div", { class: "limit-item-amount" }, h("div", { class: "amount-input" }, h("label", { class: "amount-input-label" }, translate('limitNotificationAmountLabel', this.language)), h("div", { class: "amount-input-wrapper" }, h("div", { class: "amount-input-content" }, h("input", { class: "amount-input-inner", type: "number", pattern: "[0-9]*", value: item.amount, onWheel: this.handleBlockInputWheel, onInput: (e) => this.handleInputLimitAmount(e, item) }), h("span", { class: "amount-input-suffix" }, h("i", null, this.currencySymbolMap[this.currency]))), h("button", { onClick: () => this.handleRemoveLimit(index), class: "remove-limit-button" }, h("svg", { width: "16", height: "18", viewBox: "0 0 16 18", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, h("path", { d: "M3 18C2.45 18 1.97934 17.8043 1.588 17.413C1.19667 17.0217 1.00067 16.5507 1 16V3C0.71667 3 0.479337 2.904 0.288004 2.712C0.0966702 2.52 0.000670115 2.28267 3.44827e-06 2C-0.000663218 1.71733 0.0953369 1.48 0.288004 1.288C0.48067 1.096 0.718003 1 1 1H5C5 0.716667 5.096 0.479333 5.288 0.288C5.48 0.0966668 5.71734 0.000666667 6 0H10C10.2833 0 10.521 0.0960001 10.713 0.288C10.905 0.48 11.0007 0.717333 11 1H15C15.2833 1 15.521 1.096 15.713 1.288C15.905 1.48 16.0007 1.71733 16 2C15.9993 2.28267 15.9033 2.52033 15.712 2.713C15.5207 2.90567 15.2833 3.00133 15 3V16C15 16.55 14.8043 17.021 14.413 17.413C14.0217 17.805 13.5507 18.0007 13 18H3ZM6 14C6.28334 14 6.521 13.904 6.713 13.712C6.905 13.52 7.00067 13.2827 7 13V6C7 5.71667 6.904 5.47933 6.712 5.288C6.52 5.09667 6.28267 5.00067 6 5C5.71734 4.99933 5.48 5.09533 5.288 5.288C5.096 5.48067 5 5.718 5 6V13C5 13.2833 5.096 13.521 5.288 13.713C5.48 13.905 5.71734 14.0007 6 14ZM10 14C10.2833 14 10.521 13.904 10.713 13.712C10.905 13.52 11.0007 13.2827 11 13V6C11 5.71667 10.904 5.47933 10.712 5.288C10.52 5.09667 10.2827 5.00067 10 5C9.71734 4.99933 9.48 5.09533 9.288 5.288C9.096 5.48067 9 5.718 9 6V13C9 13.2833 9.096 13.521 9.288 13.713C9.48 13.905 9.71734 14.0007 10 14Z" })))))), h("small", { class: "error-message" }, item.amountErrorMessage))))), h("div", { key: '23139e7d1b327533489ce4b3f2e432230a3f7645', class: "checkbox-container" }, h("label", { key: '334c57934771223af2403998ddb20b7536c1a959' }, h("span", { key: '04ccbafd91a90ff474bfabd3337a987a953766b9', class: "custom-checkbox" }, h("input", { key: '734547aa3750a0d12fc1e9056092fce2ea1b957c', disabled: this.loading, onChange: (e) => this.handleSkipLimitChange(e), type: "checkbox", class: "checkbox-original" }), h("span", { key: '63f3ce41d763ad6b16b16aa7b39bc74432a9fd3a', class: "checkbox-custom" })), h("span", { key: 'c8f24246e5335e86a76b1e495d410fe2d2ec30fc', class: "checkbox-label" }, translate('skipLimitLimitDescription', this.language)))), h("div", { key: '41cdf413024f032b4120be47b300d26a413dfd8b', class: "limit-buttons" }, h("button", { key: 'cebe997da3cce9473c5f7519d433b3a646f945e2', class: "add-limit", disabled: this.skipLimit || this.loading, onClick: () => this.handleAddLimit() }, h("svg", { key: '8f4e2b46602dd8ca2a8470d1ca33712a359d7fb5', class: "add-limit-mark", width: "14", height: "14", viewBox: "0 0 14 14", xmlns: "http://www.w3.org/2000/svg" }, h("path", { key: '98f33783a2c5c9a2b26978b657b69a4d0d1cb8cd', d: "M13 8H8V13C8 13.2652 7.89464 13.5196 7.70711 13.7071C7.51957 13.8946 7.26522 14 7 14C6.73478 14 6.48043 13.8946 6.29289 13.7071C6.10536 13.5196 6 13.2652 6 13V8H1C0.734784 8 0.48043 7.89464 0.292893 7.70711C0.105357 7.51957 0 7.26522 0 7C0 6.73478 0.105357 6.48043 0.292893 6.29289C0.48043 6.10536 0.734784 6 1 6H6V1C6 0.734784 6.10536 0.480429 6.29289 0.292893C6.48043 0.105357 6.73478 0 7 0C7.26522 0 7.51957 0.105357 7.70711 0.292893C7.89464 0.480429 8 0.734784 8 1V6H13C13.2652 6 13.5196 6.10536 13.7071 6.29289C13.8946 6.48043 14 6.73478 14 7C14 7.26522 13.8946 7.51957 13.7071 7.70711C13.5196 7.89464 13.2652 8 13 8Z" })), h("span", { key: '46c37e85b147a3870a183ebf5cae1a1a10d4c1af' }, translate('addLimitType', this.language))), h("button", { key: '2284595e04d263234d7fca37549738df3424278b', class: "save-limit", disabled: this.loading, onClick: () => this.handleSaveLimit() }, translate('savePlayerLimit', this.language)))), this.confirmPopupVisibility ? (h("section", { class: "confirm-modal" }, h("div", { class: "confirm-modal-content" }, h("h2", { class: "confirm-modal-title" }, translate('limitNotificationTitle', this.language)), h("p", null, translate('confirmLimitNotification', this.language)), h("div", { class: "confirm-modal-buttons" }, h("button", { class: "confirm-limit-close", onClick: () => this.handleCloseConfirm() }, translate('confirmLimitClose', this.language)), h("button", { class: "confirm-limit-save", onClick: () => this.handleSaveSkip() }, translate('confirmLimitSave', this.language)))))) : null));
572
+ }
573
+ static get is() { return "player-limit-notification-nd"; }
574
+ static get encapsulation() { return "shadow"; }
575
+ static get originalStyleUrls() {
576
+ return {
577
+ "$": ["player-limit-notification-nd.scss"]
578
+ };
579
+ }
580
+ static get styleUrls() {
581
+ return {
582
+ "$": ["player-limit-notification-nd.css"]
583
+ };
584
+ }
585
+ static get properties() {
586
+ return {
587
+ "mbSource": {
588
+ "type": "string",
589
+ "mutable": false,
590
+ "complexType": {
591
+ "original": "string",
592
+ "resolved": "string",
593
+ "references": {}
594
+ },
595
+ "required": false,
596
+ "optional": false,
597
+ "docs": {
598
+ "tags": [],
599
+ "text": ""
600
+ },
601
+ "attribute": "mb-source",
602
+ "reflect": true
603
+ },
604
+ "clientStyling": {
605
+ "type": "string",
606
+ "mutable": false,
607
+ "complexType": {
608
+ "original": "string",
609
+ "resolved": "string",
610
+ "references": {}
611
+ },
612
+ "required": false,
613
+ "optional": false,
614
+ "docs": {
615
+ "tags": [],
616
+ "text": ""
617
+ },
618
+ "attribute": "client-styling",
619
+ "reflect": true
620
+ },
621
+ "clientStylingUrl": {
622
+ "type": "string",
623
+ "mutable": false,
624
+ "complexType": {
625
+ "original": "string",
626
+ "resolved": "string",
627
+ "references": {}
628
+ },
629
+ "required": false,
630
+ "optional": false,
631
+ "docs": {
632
+ "tags": [],
633
+ "text": ""
634
+ },
635
+ "attribute": "client-styling-url",
636
+ "reflect": true
637
+ },
638
+ "session": {
639
+ "type": "string",
640
+ "mutable": false,
641
+ "complexType": {
642
+ "original": "string",
643
+ "resolved": "string",
644
+ "references": {}
645
+ },
646
+ "required": false,
647
+ "optional": false,
648
+ "docs": {
649
+ "tags": [],
650
+ "text": ""
651
+ },
652
+ "attribute": "session",
653
+ "reflect": true
654
+ },
655
+ "userid": {
656
+ "type": "string",
657
+ "mutable": false,
658
+ "complexType": {
659
+ "original": "string",
660
+ "resolved": "string",
661
+ "references": {}
662
+ },
663
+ "required": false,
664
+ "optional": false,
665
+ "docs": {
666
+ "tags": [],
667
+ "text": ""
668
+ },
669
+ "attribute": "userid",
670
+ "reflect": true
671
+ },
672
+ "language": {
673
+ "type": "string",
674
+ "mutable": false,
675
+ "complexType": {
676
+ "original": "string",
677
+ "resolved": "string",
678
+ "references": {}
679
+ },
680
+ "required": false,
681
+ "optional": false,
682
+ "docs": {
683
+ "tags": [],
684
+ "text": ""
685
+ },
686
+ "attribute": "language",
687
+ "reflect": true
688
+ },
689
+ "endpoint": {
690
+ "type": "string",
691
+ "mutable": false,
692
+ "complexType": {
693
+ "original": "string",
694
+ "resolved": "string",
695
+ "references": {}
696
+ },
697
+ "required": false,
698
+ "optional": false,
699
+ "docs": {
700
+ "tags": [],
701
+ "text": ""
702
+ },
703
+ "attribute": "endpoint",
704
+ "reflect": true
705
+ },
706
+ "limitsamount": {
707
+ "type": "string",
708
+ "mutable": false,
709
+ "complexType": {
710
+ "original": "string",
711
+ "resolved": "string",
712
+ "references": {}
713
+ },
714
+ "required": false,
715
+ "optional": false,
716
+ "docs": {
717
+ "tags": [],
718
+ "text": ""
719
+ },
720
+ "attribute": "limitsamount",
721
+ "reflect": true
722
+ },
723
+ "limitsperiods": {
724
+ "type": "string",
725
+ "mutable": false,
726
+ "complexType": {
727
+ "original": "string",
728
+ "resolved": "string",
729
+ "references": {}
730
+ },
731
+ "required": false,
732
+ "optional": false,
733
+ "docs": {
734
+ "tags": [],
735
+ "text": ""
736
+ },
737
+ "attribute": "limitsperiods",
738
+ "reflect": true
739
+ },
740
+ "currency": {
741
+ "type": "string",
742
+ "mutable": false,
743
+ "complexType": {
744
+ "original": "string",
745
+ "resolved": "string",
746
+ "references": {}
747
+ },
748
+ "required": false,
749
+ "optional": false,
750
+ "docs": {
751
+ "tags": [],
752
+ "text": ""
753
+ },
754
+ "attribute": "currency",
755
+ "reflect": true
756
+ },
757
+ "customcurrencysymbols": {
758
+ "type": "string",
759
+ "mutable": false,
760
+ "complexType": {
761
+ "original": "string",
762
+ "resolved": "string",
763
+ "references": {}
764
+ },
765
+ "required": false,
766
+ "optional": false,
767
+ "docs": {
768
+ "tags": [],
769
+ "text": ""
770
+ },
771
+ "attribute": "customcurrencysymbols",
772
+ "reflect": true
773
+ },
774
+ "translationurl": {
775
+ "type": "string",
776
+ "mutable": false,
777
+ "complexType": {
778
+ "original": "string",
779
+ "resolved": "string",
780
+ "references": {}
781
+ },
782
+ "required": false,
783
+ "optional": false,
784
+ "docs": {
785
+ "tags": [],
786
+ "text": ""
787
+ },
788
+ "attribute": "translationurl",
789
+ "reflect": true,
790
+ "defaultValue": "''"
791
+ }
792
+ };
793
+ }
794
+ static get states() {
795
+ return {
796
+ "limitItems": {},
797
+ "limitTypeOptions": {},
798
+ "skipLimit": {},
799
+ "loading": {},
800
+ "confirmPopupVisibility": {}
801
+ };
802
+ }
803
+ static get watchers() {
804
+ return [{
805
+ "propName": "clientStyling",
806
+ "methodName": "handleClientStylingChange"
807
+ }, {
808
+ "propName": "clientStylingUrl",
809
+ "methodName": "handleClientStylingUrlChange"
810
+ }, {
811
+ "propName": "mbSource",
812
+ "methodName": "handleMbSourceChange"
813
+ }];
814
+ }
815
+ }