@everymatrix/lottery-ticket-controller 0.1.6 → 0.1.20

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 (40) hide show
  1. package/dist/cjs/helper-accordion_5.cjs.entry.js +661 -0
  2. package/dist/cjs/{index-95915aab.js → index-dd94b8db.js} +17 -0
  3. package/dist/cjs/loader.cjs.js +2 -2
  4. package/dist/cjs/lottery-ticket-controller.cjs.js +2 -2
  5. package/dist/collection/collection-manifest.json +1 -7
  6. package/dist/collection/components/lottery-ticket-controller/lottery-ticket-controller.js +76 -4
  7. package/dist/collection/utils/locale.utils.js +14 -0
  8. package/dist/components/helper-accordion2.js +38 -4
  9. package/dist/components/lottery-bullet2.js +37 -3
  10. package/dist/components/lottery-grid2.js +43 -4
  11. package/dist/components/lottery-ticket-controller.js +52 -3
  12. package/dist/components/lottery-ticket2.js +0 -1
  13. package/dist/esm/helper-accordion_5.entry.js +653 -0
  14. package/dist/esm/{index-e3877ca0.js → index-74cef6d4.js} +17 -0
  15. package/dist/esm/loader.js +2 -2
  16. package/dist/esm/lottery-ticket-controller.js +2 -2
  17. package/dist/lottery-ticket-controller/lottery-ticket-controller.esm.js +1 -1
  18. package/dist/lottery-ticket-controller/p-72e48800.js +1 -0
  19. package/dist/lottery-ticket-controller/p-88036907.entry.js +1 -0
  20. package/dist/stencil.config.js +0 -3
  21. package/dist/types/components/lottery-ticket-controller/lottery-ticket-controller.d.ts +13 -0
  22. package/dist/types/components.d.ts +16 -0
  23. package/dist/types/utils/locale.utils.d.ts +1 -0
  24. package/package.json +6 -2
  25. package/dist/cjs/helper-accordion.cjs.entry.js +0 -92
  26. package/dist/cjs/lottery-bullet.cjs.entry.js +0 -41
  27. package/dist/cjs/lottery-grid.cjs.entry.js +0 -167
  28. package/dist/cjs/lottery-ticket-controller.cjs.entry.js +0 -69
  29. package/dist/cjs/lottery-ticket.cjs.entry.js +0 -169
  30. package/dist/esm/helper-accordion.entry.js +0 -88
  31. package/dist/esm/lottery-bullet.entry.js +0 -37
  32. package/dist/esm/lottery-grid.entry.js +0 -163
  33. package/dist/esm/lottery-ticket-controller.entry.js +0 -65
  34. package/dist/esm/lottery-ticket.entry.js +0 -165
  35. package/dist/lottery-ticket-controller/p-25f1639a.entry.js +0 -1
  36. package/dist/lottery-ticket-controller/p-3971b8e6.js +0 -1
  37. package/dist/lottery-ticket-controller/p-40d1058f.entry.js +0 -1
  38. package/dist/lottery-ticket-controller/p-dc525e6c.entry.js +0 -1
  39. package/dist/lottery-ticket-controller/p-f08b1b06.entry.js +0 -1
  40. package/dist/lottery-ticket-controller/p-f886ec7e.entry.js +0 -1
@@ -0,0 +1,661 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const index = require('./index-dd94b8db.js');
6
+
7
+ const DEFAULT_LANGUAGE$2 = 'en';
8
+ const SUPPORTED_LANGUAGES$2 = ['ro', 'en'];
9
+ const TRANSLATIONS$2 = {
10
+ en: {
11
+ deleteTicket: 'Delete ticket'
12
+ },
13
+ ro: {
14
+ deleteTicket: 'Sterge biletul'
15
+ },
16
+ };
17
+ const translate$2 = (key, customLang) => {
18
+ const lang = customLang;
19
+ return TRANSLATIONS$2[lang !== undefined && SUPPORTED_LANGUAGES$2.includes(lang) ? lang : DEFAULT_LANGUAGE$2][key];
20
+ };
21
+
22
+ const helperAccordionCss = "@import url(\"https://fonts.googleapis.com/css2?family=Roboto:wght@100&display=swap\");:host{display:block;font-family:\"Roboto\", sans-serif}.Header{border-radius:5px;background:#009993;display:flex;gap:30px;border:1px solid #009993;padding:8px 10px;user-select:none;margin-bottom:1px}.Header:hover{background:#00ABA4}.Header .Title,.Header .Subtitle,.Header .Description{margin:0;font-size:14px;color:#fff;text-transform:capitalize}.Header .Expand{margin-left:auto;color:#FFF;width:17px;height:17px;cursor:pointer;text-align:center;transform:rotate(90deg);font-size:20px;user-select:none}.HeaderTicketHistory{border-radius:4px;background:#F1F1F1;display:flex;gap:30px;border:1px solid #009993;padding:8px 10px;user-select:none;margin-bottom:5px}.HeaderTicketHistory:hover{background:#00ABA4}.HeaderTicketHistory .Title,.HeaderTicketHistory .Subtitle,.HeaderTicketHistory .Description{margin:0;font-size:14px;color:#000}.HeaderTicketHistory .Expand{margin-left:auto;color:#FFF;width:17px;height:17px;cursor:pointer;text-align:center;transform:rotate(90deg);font-size:20px;user-select:none}.Content{border-radius:0 0 4px 4px;background:#fff;border:1px solid #009993;padding:10px 15px;user-select:none;color:#000;margin-bottom:10px}.ActionButton{cursor:pointer;display:inline-block;border-radius:4px;margin:20px 0 10px;text-transform:uppercase;font-size:12px;text-align:center;padding:8px 20px;min-width:80px;background:#FF3D00;border:1px solid #FF3D00;color:#FFF}.ActionButton:hover{background:#FF6536;border:1px solid #FF3D00}";
23
+
24
+ const Accordion = class {
25
+ constructor(hostRef) {
26
+ index.registerInstance(this, hostRef);
27
+ this.accordionEvent = index.createEvent(this, "helperAccordionAction", 7);
28
+ /**
29
+ * Flag for ticket history
30
+ */
31
+ this.ticketHistoryFlag = false;
32
+ /**
33
+ * Title (top header)
34
+ */
35
+ this.headerTitle = '';
36
+ /**
37
+ * SubTitle (top header)
38
+ */
39
+ this.headerSubtitle = '';
40
+ /**
41
+ * Description
42
+ */
43
+ this.description = '';
44
+ /**
45
+ * Enables footer content
46
+ */
47
+ this.footer = false;
48
+ /**
49
+ * Enables footer button for tab deletion
50
+ */
51
+ this.deleteTab = false;
52
+ /**
53
+ * Activates postMessages as events for actions from the widget
54
+ */
55
+ this.postMessage = false;
56
+ /**
57
+ * Name of the event emitter by the action button
58
+ */
59
+ this.eventName = 'helperAccordionAction';
60
+ /**
61
+ * Collapsed
62
+ */
63
+ this.collapsed = true;
64
+ /**
65
+ * Language
66
+ */
67
+ this.language = 'en';
68
+ /**
69
+ * Client custom styling via string
70
+ */
71
+ this.clientStyling = '';
72
+ /**
73
+ * Client custom styling via url content
74
+ */
75
+ this.clientStylingUrlContent = '';
76
+ this.limitStylingAppends = false;
77
+ this.setClientStyling = () => {
78
+ let sheet = document.createElement('style');
79
+ sheet.innerHTML = this.clientStyling;
80
+ this.stylingContainer.prepend(sheet);
81
+ };
82
+ this.setClientStylingURL = () => {
83
+ let cssFile = document.createElement('style');
84
+ setTimeout(() => {
85
+ cssFile.innerHTML = this.clientStylingUrlContent;
86
+ this.stylingContainer.prepend(cssFile);
87
+ }, 1);
88
+ };
89
+ }
90
+ // @TODO fix the `any` type :)
91
+ connectedCallback() {
92
+ this.showContent = !this.collapsed;
93
+ }
94
+ componentDidRender() {
95
+ // start custom styling area
96
+ if (!this.limitStylingAppends && this.stylingContainer) {
97
+ if (this.clientStyling)
98
+ this.setClientStyling();
99
+ if (this.clientStylingUrlContent)
100
+ this.setClientStylingURL();
101
+ this.limitStylingAppends = true;
102
+ }
103
+ // end custom styling area
104
+ }
105
+ toggleContent() {
106
+ this.showContent = !this.showContent;
107
+ }
108
+ deleteAction() {
109
+ if (this.postMessage) {
110
+ // @TODO maybe change the name type, this one sucks
111
+ window.postMessage({ type: this.eventName }, window.location.href);
112
+ }
113
+ this.accordionEvent.emit();
114
+ }
115
+ render() {
116
+ return (index.h("div", { class: "Wrapper", ref: el => this.stylingContainer = el }, index.h("div", { class: this.ticketHistoryFlag === true ? 'HeaderTicketHistory' : 'Header' }, index.h("p", { class: "Title" }, this.headerTitle), index.h("p", { class: "Subtitle" }, this.headerSubtitle), index.h("p", { class: "Subtitle Description" }, this.description), index.h("span", { class: "Expand", onClick: () => this.toggleContent() }, this.showContent ? '<' : '>')), this.showContent &&
117
+ index.h("div", null, index.h("div", { class: "Content" }, index.h("slot", { name: 'accordionContent' }), this.footer && this.showContent &&
118
+ index.h("div", null, this.deleteTab &&
119
+ index.h("span", { class: "ActionButton", onClick: () => this.deleteAction() }, translate$2('deleteTicket', this.language)))))));
120
+ }
121
+ };
122
+ Accordion.style = helperAccordionCss;
123
+
124
+ const lotteryBulletCss = "@import url(\"https://fonts.googleapis.com/css2?family=Roboto:wght@100&display=swap\");:host{display:block;font-family:\"Roboto\", sans-serif}@-webkit-keyframes Circle{0%{-webkit-transform:scale(0.5);transform:scale(0.5)}100%{-webkit-transform:scale(1);transform:scale(1)}}@keyframes Circle{0%{-webkit-transform:scale(0.5);transform:scale(0.5)}100%{-webkit-transform:scale(1);transform:scale(1)}}@-webkit-keyframes hover-rotate{0%{-webkit-transform:scale(1) rotateZ(0);transform:scale(1) rotateZ(0)}50%{-webkit-transform:scale(1.2) rotateZ(180deg);transform:scale(1.22) rotateZ(180deg)}100%{-webkit-transform:scale(1) rotateZ(360deg);transform:scale(1) rotateZ(360deg)}}@keyframes hover-rotate{0%{-webkit-transform:scale(1) rotateZ(0);transform:scale(1) rotateZ(0)}50%{-webkit-transform:scale(1.2) rotateZ(180deg);transform:scale(1.2) rotateZ(180deg)}100%{-webkit-transform:scale(1) rotateZ(360deg);transform:scale(1) rotateZ(360deg)}}@-webkit-keyframes selected-scaleUp{0%{-webkit-transform:scale(0.5);transform:scale(0.5)}100%{-webkit-transform:scale(1.2);transform:scale(1.2)}}@keyframes selected-scaleUp{0%{-webkit-transform:scale(0.5);transform:scale(0.5)}100%{-webkit-transform:scale(1);transform:scale(1)}}.Circle{-webkit-animation:Circle 0.8s cubic-bezier(0.39, 0.575, 0.565, 1) both;animation:Circle 0.8s cubic-bezier(0.39, 0.575, 0.565, 1) both;cursor:pointer;color:#000000;display:block;height:30px;width:30px;margin:0;display:flex;align-items:center;justify-content:center;justify-content:center;align-items:center;border:solid 2px #ffffff;background:radial-gradient(circle at top, white 0%, white 100%);font-weight:bold;border-radius:50%;box-shadow:0 2px 4px 0 rgba(0, 0, 0, 0.5);user-select:none;font-size:16px;line-height:16px;font-weight:600;position:relative}.Circle:hover{-webkit-animation:hover-rotate 0.4s linear both;animation:hover-rotate 0.4s linear both;background:radial-gradient(circle at top, white 0%, #f1f1f1 100%)}.Circle.Selected{-webkit-animation:selected-scaleUp 0.4s cubic-bezier(0.39, 0.575, 0.565, 1) both;animation:selected-scaleUp 0.4s cubic-bezier(0.39, 0.575, 0.565, 1) both;color:#ffffff;background:#9EC258;background:-webkit-radial-gradient(top, #00958f, #004D4A);background:-moz-radial-gradient(top, #00958f, #004D4A);background:radial-gradient(to bottom, #00958f, #004D4A);border:solid 2px #00958f}.Circle.Disabled{-webkit-animation:selected-scaleUp 0.4s cubic-bezier(0.39, 0.575, 0.565, 1) both;animation:selected-scaleUp 0.4s cubic-bezier(0.39, 0.575, 0.565, 1) both;color:#f1f1f1;background:#D4D4D4;border:solid 2px #D4D4D4;cursor:default}.Circle.DisabledSelected{-webkit-animation:selected-scaleUp 0.4s cubic-bezier(0.39, 0.575, 0.565, 1) both;animation:selected-scaleUp 0.4s cubic-bezier(0.39, 0.575, 0.565, 1) both;color:#f1f1f1;background:#9EC258;background:-webkit-radial-gradient(top, #00958f, #004D4A);background:-moz-radial-gradient(top, #00958f, #004D4A);background:radial-gradient(to bottom, #00958f, #004D4A);border:solid 2px #D4D4D4;cursor:default}";
125
+
126
+ const LotteryBullet = class {
127
+ constructor(hostRef) {
128
+ index.registerInstance(this, hostRef);
129
+ this.bulletEvent = index.createEvent(this, "lotteryBulletSelection", 7);
130
+ /**
131
+ * Value of the bullet
132
+ */
133
+ this.value = '0';
134
+ /**
135
+ * Marks if the bullet should be selectable
136
+ */
137
+ this.selectable = true;
138
+ /**
139
+ * Marks if the bullet should be selected
140
+ */
141
+ this.isSelected = false;
142
+ /**
143
+ * Client custom styling via string
144
+ */
145
+ this.clientStyling = '';
146
+ /**
147
+ * Client custom styling via url content
148
+ */
149
+ this.clientStylingUrlContent = '';
150
+ this.limitStylingAppends = false;
151
+ this.select = () => {
152
+ if (this.selectable) {
153
+ this.isSelected = !this.isSelected;
154
+ this.bulletEvent.emit({
155
+ value: this.value,
156
+ selected: this.isSelected
157
+ });
158
+ }
159
+ };
160
+ this.setClientStyling = () => {
161
+ let sheet = document.createElement('style');
162
+ sheet.innerHTML = this.clientStyling;
163
+ this.stylingContainer.prepend(sheet);
164
+ };
165
+ this.setClientStylingURL = () => {
166
+ let cssFile = document.createElement('style');
167
+ setTimeout(() => {
168
+ cssFile.innerHTML = this.clientStylingUrlContent;
169
+ this.stylingContainer.prepend(cssFile);
170
+ }, 1);
171
+ };
172
+ }
173
+ componentDidRender() {
174
+ // start custom styling area
175
+ if (!this.limitStylingAppends && this.stylingContainer) {
176
+ if (this.clientStyling)
177
+ this.setClientStyling();
178
+ if (this.clientStylingUrlContent)
179
+ this.setClientStylingURL();
180
+ this.limitStylingAppends = true;
181
+ }
182
+ // end custom styling area
183
+ }
184
+ render() {
185
+ return (index.h("div", { class: 'Circle ' + (this.selectable ? '' : 'Disabled') + (this.isSelected ? 'Selected' : ''), onClick: () => this.select(), ref: el => this.stylingContainer = el }, this.value));
186
+ }
187
+ };
188
+ LotteryBullet.style = lotteryBulletCss;
189
+
190
+ const lotteryGridCss = "@import url(\"https://fonts.googleapis.com/css2?family=Roboto:wght@100&display=swap\");:host{display:block;font-family:\"Roboto\", sans-serif}.GridContainer{display:flex;flex-direction:column;max-width:1200px}.Grid{margin-top:10px 0 10px 0;display:flex;flex-direction:row;flex-wrap:wrap;gap:20px}.Grid.TicketGrid{gap:5px}";
191
+
192
+ const LotteryGrid = class {
193
+ constructor(hostRef) {
194
+ index.registerInstance(this, hostRef);
195
+ this.gridFilledEvent = index.createEvent(this, "gridFilled", 7);
196
+ this.gridDirtyEvent = index.createEvent(this, "gridDirty", 7);
197
+ /**
198
+ * Number of bullets of grid
199
+ */
200
+ this.totalNumbers = 0;
201
+ /**
202
+ * Number of maximum bullets that can be selected
203
+ */
204
+ this.maximumAllowed = 0;
205
+ /**
206
+ * Minimum allowed of bullets
207
+ */
208
+ this.minimumAllowed = 1;
209
+ /**
210
+ * Allows the user to select numbers on the grid
211
+ */
212
+ this.selectable = true;
213
+ /**
214
+ * Numbers that should be showed as selected on the grid (as a string of those numbers e.g. '1,2,3,4,5,6')
215
+ */
216
+ this.selectedNumbers = '';
217
+ /**
218
+ * Show only selected numbers
219
+ */
220
+ this.displaySelected = false;
221
+ /**
222
+ * Language
223
+ */
224
+ this.language = 'en';
225
+ /**
226
+ * Personalize grid for ticket
227
+ */
228
+ this.gridType = '';
229
+ /**
230
+ * Client custom styling via string
231
+ */
232
+ this.clientStyling = '';
233
+ /**
234
+ * Client custom styling via url content
235
+ */
236
+ this.clientStylingUrlContent = '';
237
+ this.numbers = [];
238
+ this.limitStylingAppends = false;
239
+ this.selectedCounter = 0;
240
+ this.setClientStyling = () => {
241
+ let sheet = document.createElement('style');
242
+ sheet.innerHTML = this.clientStyling;
243
+ this.stylingContainer.prepend(sheet);
244
+ };
245
+ this.setClientStylingURL = () => {
246
+ let cssFile = document.createElement('style');
247
+ setTimeout(() => {
248
+ cssFile.innerHTML = this.clientStylingUrlContent;
249
+ this.stylingContainer.prepend(cssFile);
250
+ }, 1);
251
+ };
252
+ }
253
+ connectedCallback() {
254
+ let selected = [];
255
+ if (this.selectedNumbers.length > 0) {
256
+ selected = this.selectedNumbers.split(',');
257
+ this.selectedCounter = selected.length;
258
+ }
259
+ if (this.displaySelected) {
260
+ selected.forEach((item) => {
261
+ this.numbers.push({
262
+ number: item,
263
+ selected: true,
264
+ selectable: this.selectable
265
+ });
266
+ });
267
+ }
268
+ else {
269
+ [...Array(this.totalNumbers).keys()]
270
+ .map(number => (number + 1).toString())
271
+ .forEach((number) => {
272
+ this.numbers.push({
273
+ number,
274
+ selected: selected.indexOf(number) >= 0 ? true : false,
275
+ selectable: this.selectedCounter == this.maximumAllowed ? false : this.selectable
276
+ });
277
+ });
278
+ }
279
+ }
280
+ componentDidRender() {
281
+ // start custom styling area
282
+ if (!this.limitStylingAppends && this.stylingContainer) {
283
+ if (this.clientStyling)
284
+ this.setClientStyling();
285
+ if (this.clientStylingUrlContent)
286
+ this.setClientStylingURL();
287
+ this.limitStylingAppends = true;
288
+ }
289
+ // end custom styling area
290
+ }
291
+ lotteryBulletSelectionHandler(event) {
292
+ this.numbers = this.numbers.map((item) => {
293
+ if (item.number == event.detail.value) {
294
+ return {
295
+ number: item.number,
296
+ selected: event.detail.selected,
297
+ selectable: item.selectable
298
+ };
299
+ }
300
+ return {
301
+ number: item.number,
302
+ selected: item.selected,
303
+ selectable: item.selectable
304
+ };
305
+ });
306
+ if (event.detail.selected) {
307
+ this.selectedCounter += 1;
308
+ if (this.selectedCounter == this.maximumAllowed) {
309
+ this.numbers = this.numbers.map((item) => {
310
+ return {
311
+ number: item.number,
312
+ selected: item.selected,
313
+ selectable: item.selected ? true : false
314
+ };
315
+ });
316
+ this.gridFilledEvent.emit({
317
+ id: this.ticketId,
318
+ index: this.gridIndex,
319
+ selectedNumbers: this.numbers.filter((item) => item.selected).map((item) => item.number)
320
+ });
321
+ }
322
+ }
323
+ else {
324
+ if (this.selectedCounter == this.maximumAllowed) {
325
+ this.numbers = this.numbers.map((item) => {
326
+ return {
327
+ number: item.number,
328
+ selected: item.selected,
329
+ selectable: true
330
+ };
331
+ });
332
+ this.gridDirtyEvent.emit({
333
+ id: this.ticketId,
334
+ index: this.gridIndex,
335
+ selectedNumbers: this.numbers.filter((item) => item.selected).map((item) => item.number)
336
+ });
337
+ }
338
+ this.selectedCounter -= 1;
339
+ }
340
+ }
341
+ async resetSelectionHandler(event) {
342
+ if (event.detail && event.detail == this.ticketId) {
343
+ this.selectedCounter = 0;
344
+ this.numbers = this.numbers.map((item) => {
345
+ return {
346
+ number: item.number,
347
+ selected: false,
348
+ selectable: this.selectable
349
+ };
350
+ });
351
+ this.gridDirtyEvent.emit({
352
+ id: this.ticketId,
353
+ index: this.gridIndex,
354
+ selectedNumbers: this.numbers.filter((item) => item.selected).map((item) => item.number)
355
+ });
356
+ }
357
+ }
358
+ async autoSelectionHandler(event) {
359
+ if (event.detail && event.detail == this.ticketId) {
360
+ this.resetSelectionHandler(event);
361
+ let array = [...Array(this.totalNumbers).keys()]
362
+ .map(number => number + 1)
363
+ .sort(() => 0.5 - Math.random());
364
+ array = array.slice(0, this.minimumAllowed);
365
+ this.numbers = this.numbers.map((item) => {
366
+ return {
367
+ number: item.number,
368
+ selected: array.indexOf(parseInt(item.number, 10)) >= 0 ? true : false,
369
+ selectable: array.indexOf(parseInt(item.number, 10)) >= 0 ? true : false,
370
+ };
371
+ });
372
+ this.gridFilledEvent.emit({
373
+ id: this.ticketId,
374
+ index: this.gridIndex,
375
+ selectedNumbers: this.numbers.filter((item) => item.selected).map((item) => item.number)
376
+ });
377
+ this.selectedCounter = this.maximumAllowed;
378
+ }
379
+ }
380
+ render() {
381
+ return (index.h("div", { class: "GridContainer", ref: el => this.stylingContainer = el }, index.h("div", { class: this.gridType === 'ticket' ? 'Grid TicketGrid' : 'Grid' }, this.numbers.map((item) => index.h("div", null, index.h("lottery-bullet", { value: item.number, selectable: item.selectable, "is-selected": item.selected, "client-styling": this.clientStyling, "client-styling-url-content": this.clientStylingUrlContent }))))));
382
+ }
383
+ };
384
+ LotteryGrid.style = lotteryGridCss;
385
+
386
+ const DEFAULT_LANGUAGE$1 = 'en';
387
+ const SUPPORTED_LANGUAGES$1 = ['ro', 'en'];
388
+ const TRANSLATIONS$1 = {
389
+ en: {
390
+ loading: 'Loading, please wait ...',
391
+ error: 'It was an error while trying to fetch the data',
392
+ grid: 'Grid',
393
+ multiplier: 'Multiplier',
394
+ numberOfDraws: 'Number of draws',
395
+ wagerPerDraw: 'Wager per draw',
396
+ resetButton: 'Reset',
397
+ autoButton: 'I feel lucky'
398
+ },
399
+ ro: {
400
+ loading: 'Se incarca, va rugam asteptati ...',
401
+ error: 'A fost o eroare in timp ce asteptam datele',
402
+ grid: 'Grid',
403
+ multiplier: 'Multiplicator',
404
+ numberOfDraws: 'Numarul de extrageri',
405
+ wagerPerDraw: 'Pariul per extragere',
406
+ resetButton: 'Reseteaza',
407
+ autoButton: 'Ma simt norocos'
408
+ },
409
+ };
410
+ const translate$1 = (key, customLang) => {
411
+ const lang = customLang;
412
+ return TRANSLATIONS$1[lang !== undefined && SUPPORTED_LANGUAGES$1.includes(lang) ? lang : DEFAULT_LANGUAGE$1][key];
413
+ };
414
+
415
+ const lotteryTicketCss = "@import url(\"https://fonts.googleapis.com/css2?family=Roboto:wght@100&display=swap\");:host{display:block;font-family:\"Roboto\", sans-serif}.TicketTitle{font-size:16px;font-weight:bold}.ButtonContainer{display:flex;justify-content:flex-end}.Toggle{cursor:pointer;margin-top:20px;display:inline-block}.ToggleSwitch{display:inline-block;background:#707070;border-radius:16px;width:58px;height:24px;position:relative;vertical-align:middle;transition:background 0.25s}.ToggleSwitch:before,.ToggleSwitch:after{content:\"\"}.ToggleSwitch:before{display:block;background:linear-gradient(to bottom, #fff 0%, #F1F1F1 100%);border-radius:50%;box-shadow:0 0 0 1px rgba(0, 0, 0, 0.25);width:16px;height:16px;position:absolute;top:4px;left:4px;transition:left 0.25s}.Toggle:hover .ToggleSwitch:before{background:linear-gradient(to bottom, #fff 0%, #fff 100%);box-shadow:0 0 0 1px rgba(0, 0, 0, 0.5)}.ToggleCheckbox:checked+.ToggleSwitch{background:#00ABA4}.ToggleCheckbox:checked+.ToggleSwitch:before{left:38px}.ToggleCheckbox{position:absolute;visibility:hidden}.Label{margin-right:5px;position:relative;top:2px;font-size:14px;font-weight:lighter;color:#000}input[type=number]{-webkit-appearance:textfield;-moz-appearance:textfield;appearance:textfield}input[type=number]::-webkit-inner-spin-button,input[type=number]::-webkit-outer-spin-button{-webkit-appearance:none}.NumberInput,.WagerInput{margin-top:10px;display:inline-flex;align-items:center}.NumberInput,.NumberInput *{box-sizing:border-box}.NumberInput button{cursor:pointer;outline:none;-webkit-appearance:none;border:none;align-items:center;justify-content:center;height:20px;position:relative}.NumberInput button:after{display:inline-block;position:absolute;transform:translate(-50%, -50%) rotate(180deg);align-items:center;text-align:center}.NumberInput button.Plus:after{transform:translate(-50%, -50%) rotate(0deg);width:30px;display:inline-flex;align-items:center;text-align:center}.NumberInput input[type=number],.WagerInput input[type=number]{max-width:50px;display:inline-flex;align-items:center;padding:4px 10px;text-align:center}.NumberInput input[type=number] .WagerInputTitle,.WagerInput input[type=number] .WagerInputTitle{font-size:14px;color:#000;padding:10px}.InputDefault{background-color:#F1F1F1;border-radius:4px;padding:5px;border:solid 1px #D4D4D4;color:#707070}.AutoButton{cursor:pointer;display:inline-block;border-radius:4px;padding:8px 20px;width:max-content;margin:5px 0;border:1px solid #00958f;background:#FFF;color:#000;font-size:12px;transition:all 0.2s linear;text-transform:uppercase;text-align:center;letter-spacing:0}.AutoButton:active{background:#00958f;color:#FFF}.ResetButton{cursor:pointer;display:inline-block;border-radius:4px;padding:8px 20px;width:max-content;margin:5px 0;color:#000;font-size:12px;transition:all 0.2s linear;text-transform:uppercase;text-align:center;letter-spacing:0;background:#FF3D00;border:1px solid #FF3D00;color:#FFF}.ResetButton:hover{background:#FF6536;border:1px solid #FF3D00}.TicketGridBullets{background:#f1f1f1;border-radius:4px;padding:20px;margin-top:5px}.TicketGridBullets .TicketGridTitle{margin-top:0px}.Minus{border-radius:4px;width:30px;height:24px !important;margin-right:10px;color:#FFF;background:#009993}.Plus{border-radius:4px;width:30px;height:24px !important;margin-left:10px;color:#FFF;background:#009993}.SelectWrapper{width:auto;padding:5px;margin:0 auto;border:1px solid #ccc;border-radius:5px;position:relative}.SelectButton,.SelectOptions li{display:flex;align-items:center;cursor:pointer}.SelectButton{display:flex;padding:0 5px;border-radius:7px;align-items:center;justify-content:space-between;font-size:14px}.SelectButton span:first-child{padding-right:10px}.SelectExpand{transition:transform 0.3s linear;font-size:12px}.SelectActive .SelectExpand{transform:rotate(180deg)}.SelectContent{display:none;padding:5px;border-radius:7px}.SelectWrapper.SelectActive .SelectContent{width:100%;display:block;position:absolute;left:0;top:32px;padding:0;border:1px solid #ccc;overflow:hidden;background:#fff}.SelectContent .SelectOptions{max-height:100px;margin:0;overflow-y:auto;padding:0}.SelectContent .SelectOptions .SelectedValue{background-color:#009993;color:#fff}.SelectOptions::-webkit-scrollbar{width:7px}.SelectOptions::-webkit-scrollbar-track{background:#f1f1f1;border-radius:25px}.SelectOptions::-webkit-scrollbar-thumb{background:#ccc;border-radius:25px}.SelectOptions li{height:20px;padding:0 13px;font-size:14px}.SelectOptions li:hover{background:#f2f2f2}";
416
+
417
+ const LotteryTicket = class {
418
+ constructor(hostRef) {
419
+ index.registerInstance(this, hostRef);
420
+ this.ticketCompleted = index.createEvent(this, "ticketCompleted", 7);
421
+ this.autoSelection = index.createEvent(this, "autoSelection", 7);
422
+ this.resetSelection = index.createEvent(this, "resetSelection", 7);
423
+ this.stakeChange = index.createEvent(this, "stakeChange", 7);
424
+ this.multiplierChange = index.createEvent(this, "multiplierChange", 7);
425
+ /**
426
+ * Number of grids of a ticket
427
+ */
428
+ this.numberOfGrids = 1;
429
+ /**
430
+ * Option to have the ticket registered for multiple draws
431
+ */
432
+ this.multipleDraws = true;
433
+ /**
434
+ * Shows the reset button
435
+ */
436
+ this.resetButton = false;
437
+ /**
438
+ * Shows the auto-pick button
439
+ */
440
+ this.autoPick = false;
441
+ /**
442
+ * Language
443
+ */
444
+ this.language = 'en';
445
+ this.multiplier = false;
446
+ this.numberOfDraws = 1;
447
+ this.isLoading = true;
448
+ this.hasErrors = false;
449
+ this.ticketDone = false;
450
+ this.isCustomSelect = false;
451
+ this.amountInfo = {};
452
+ }
453
+ /**
454
+ * @TODO find a better way to implement click outside the custom select, so that we don't have to use the 'data-cluster' attribute on each element
455
+ */
456
+ checkForClickOutside(ev) {
457
+ if (ev.composedPath()[0].getAttribute('data-cluster') !== 'SelectComponent') {
458
+ this.isCustomSelect = false;
459
+ }
460
+ }
461
+ connectedCallback() {
462
+ let url = new URL(`${this.endpoint}/games/${this.gameId}`);
463
+ fetch(url.href)
464
+ .then((response) => {
465
+ if (response.ok) {
466
+ return response.json();
467
+ }
468
+ else {
469
+ // Throw error
470
+ this.hasErrors = true;
471
+ }
472
+ })
473
+ .then((data) => {
474
+ this.isLoading = false;
475
+ this.gameData = data;
476
+ this.grids = [...Array(data.rules.boards.length).keys()];
477
+ this.amountInfo = this.gameData.rules.stakes[0]; // initial value for select
478
+ })
479
+ .catch((err) => {
480
+ this.isLoading = false;
481
+ this.hasErrors = true;
482
+ console.error('Error!', err);
483
+ });
484
+ }
485
+ multiplierChangeHandler(e) {
486
+ this.multiplier = e.target ? e.target.checked : false;
487
+ this.multiplierChange.emit(this.multiplier);
488
+ }
489
+ drawsChangeHandler(event) {
490
+ this.ticket = Object.assign(Object.assign({}, this.ticket), { draws: event });
491
+ this.ticketCompleted.emit(this.ticket);
492
+ }
493
+ gridFilledHandler(event) {
494
+ this.ticket = Object.assign(Object.assign({}, event.detail), { draws: this.numberOfDraws });
495
+ this.ticketDone = true;
496
+ this.ticketCompleted.emit(this.ticket);
497
+ }
498
+ toggleAutoSelection() {
499
+ this.ticketDone = true;
500
+ this.autoSelection.emit(this.ticketId);
501
+ }
502
+ toggleResetSelection() {
503
+ this.ticketDone = false;
504
+ this.resetSelection.emit(this.ticketId);
505
+ }
506
+ changeStake(ticketid, amount) {
507
+ this.stakeChange.emit({
508
+ ticketId: ticketid,
509
+ stake: amount
510
+ });
511
+ }
512
+ toggleClass() {
513
+ this.isCustomSelect = !this.isCustomSelect;
514
+ }
515
+ setDropdownItem(item) {
516
+ this.amountInfo = {
517
+ amount: item.amount,
518
+ currency: item.currency
519
+ };
520
+ this.isCustomSelect = false;
521
+ this.changeStake(this.ticketId, item.amount);
522
+ }
523
+ render() {
524
+ if (this.isLoading) {
525
+ return (index.h("div", null, index.h("p", null, translate$1('loading', this.language))));
526
+ }
527
+ else {
528
+ if (this.hasErrors) {
529
+ return (index.h("div", null, index.h("p", null, translate$1('error', this.language))));
530
+ }
531
+ else {
532
+ const { rules } = this.gameData;
533
+ return (index.h("div", { class: "TicketContainer" }, index.h("p", { class: "TicketTitle" }, this.gameData.name), this.resetButton && this.ticketDone &&
534
+ index.h("div", { class: "ButtonContainer" }, index.h("a", { class: "ResetButton", onClick: () => this.toggleResetSelection() }, translate$1('resetButton', this.language))), this.autoPick && !this.ticketDone &&
535
+ index.h("div", { class: "ButtonContainer" }, index.h("a", { class: "AutoButton", onClick: () => this.toggleAutoSelection() }, translate$1('autoButton', this.language))), this.grids.map((item, index$1) => index.h("div", { class: "TicketGridBullets" }, index.h("p", { class: "TicketGridTitle" }, translate$1('grid', this.language), " ", item), index.h("lottery-grid", { "grid-index": index$1, "maximum-allowed": rules.boards[index$1].maximumAllowed, "minimum-allowed": rules.boards[index$1].minimumAllowed, "total-numbers": rules.boards[index$1].totalNumbers, selectable: true, "reset-button": true, "auto-pick": true, "game-id": this.gameId, "ticket-id": this.ticketId, language: this.language }))), rules.multiplier &&
536
+ index.h("div", null, index.h("label", { class: "Toggle" }, index.h("label", { class: "Label" }, translate$1('multiplier', this.language), ": "), index.h("input", { class: "ToggleCheckbox", type: "checkbox", onInput: (e) => this.multiplierChangeHandler(e) }), index.h("div", { class: "ToggleSwitch" }))), this.multipleDraws &&
537
+ index.h("div", { class: "TicketDraws" }, index.h("label", { class: "Label" }, translate$1('numberOfDraws', this.language), ": "), index.h("div", { class: "NumberInput" }, index.h("button", { onClick: () => this.numberOfDraws > 1 ? this.numberOfDraws-- : this.numberOfDraws = 1, class: "Minus" }, "-"), index.h("input", { class: "InputDefault", min: "1", value: this.numberOfDraws, type: "number" }), index.h("button", { onClick: () => this.numberOfDraws++, class: "Plus" }, "+"))), index.h("div", null, index.h("label", { class: "Label" }, translate$1('wagerPerDraw', this.language), ": "), index.h("div", { class: "WagerInput" }, rules.stakes.length > 1 ?
538
+ (index.h("div", { "data-cluster": "SelectComponent", class: this.isCustomSelect ? "SelectWrapper SelectActive" : "SelectWrapper" }, index.h("div", { "data-cluster": "SelectComponent", class: "SelectButton", onClick: () => this.toggleClass() }, index.h("span", { "data-cluster": "SelectComponent" }, this.amountInfo.amount, " ", this.amountInfo.currency), index.h("span", { "data-cluster": "SelectComponent", class: "SelectExpand" }, "\u25BC")), index.h("div", { "data-cluster": "SelectComponent", class: "SelectContent" }, index.h("ul", { "data-cluster": "SelectComponent", class: "SelectOptions" }, rules.stakes.map((item) => index.h("li", { "data-cluster": "SelectComponent", class: this.amountInfo.amount == item.amount ? 'SelectedValue' : '', value: item.amount, onClick: () => this.setDropdownItem(item) }, item.amount, " ", item.currency)))))) : (index.h("div", null, index.h("input", { min: "1", value: rules.stakes[0].amount, type: "number", disabled: true }), index.h("p", { class: "WagerInputTitle" }, rules.stakes[0].currency)))))));
539
+ }
540
+ }
541
+ }
542
+ static get watchers() { return {
543
+ "numberOfDraws": ["drawsChangeHandler"]
544
+ }; }
545
+ };
546
+ LotteryTicket.style = lotteryTicketCss;
547
+
548
+ const DEFAULT_LANGUAGE = 'en';
549
+ const SUPPORTED_LANGUAGES = ['ro', 'en'];
550
+ const TRANSLATIONS = {
551
+ en: {
552
+ ticket: 'Ticket',
553
+ },
554
+ ro: {
555
+ ticket: 'Bilet',
556
+ },
557
+ };
558
+ const translate = (key, customLang) => {
559
+ const lang = customLang;
560
+ return TRANSLATIONS[lang !== undefined && SUPPORTED_LANGUAGES.includes(lang) ? lang : DEFAULT_LANGUAGE][key];
561
+ };
562
+
563
+ const lotteryTicketControllerCss = ":host{display:block}";
564
+
565
+ const LotteryTicketController = class {
566
+ constructor(hostRef) {
567
+ index.registerInstance(this, hostRef);
568
+ this.deleteTicketEvent = index.createEvent(this, "deleteTicket", 7);
569
+ /**
570
+ * Endpoint URL for the source of data (NorWAy standard)
571
+ */
572
+ this.endpoint = '';
573
+ /**
574
+ * Ticket number
575
+ */
576
+ this.ticketId = 1;
577
+ /**
578
+ * Activates postMessages as events for actions from the widget
579
+ */
580
+ this.postMessage = false;
581
+ /**
582
+ * Name of the event emitter by the action button
583
+ */
584
+ this.eventName = 'deleteTicketAction';
585
+ /**
586
+ * Collapsed
587
+ */
588
+ this.collapsed = true;
589
+ /**
590
+ * Number of grids?
591
+ */
592
+ this.numberOfGrids = 1;
593
+ /**
594
+ * This toggles if the last ticket added should be expanded or not
595
+ */
596
+ this.last = false;
597
+ /**
598
+ * Language
599
+ */
600
+ this.language = 'en';
601
+ /**
602
+ * Shows the auto-pick button
603
+ */
604
+ this.autoPick = false;
605
+ /**
606
+ * Shows the reset button
607
+ */
608
+ this.resetButton = false;
609
+ /**
610
+ * Client custom styling via string
611
+ */
612
+ this.clientStyling = '';
613
+ /**
614
+ * Client custom styling via url content
615
+ */
616
+ this.clientStylingUrlContent = '';
617
+ this.limitStylingAppends = false;
618
+ this.setClientStyling = () => {
619
+ let sheet = document.createElement('style');
620
+ sheet.innerHTML = this.clientStyling;
621
+ this.stylingContainer.prepend(sheet);
622
+ };
623
+ this.setClientStylingURL = () => {
624
+ let cssFile = document.createElement('style');
625
+ setTimeout(() => {
626
+ cssFile.innerHTML = this.clientStylingUrlContent;
627
+ this.stylingContainer.prepend(cssFile);
628
+ }, 1);
629
+ };
630
+ }
631
+ // @TODO fix the `any` type
632
+ helperAccordionActionHandler() {
633
+ if (this.postMessage) {
634
+ window.postMessage({ type: this.eventName }, window.location.href);
635
+ }
636
+ this.deleteTicketEvent.emit({
637
+ ticketId: this.ticketId
638
+ });
639
+ }
640
+ componentDidRender() {
641
+ // start custom styling area
642
+ if (!this.limitStylingAppends && this.stylingContainer) {
643
+ if (this.clientStyling)
644
+ this.setClientStyling();
645
+ if (this.clientStylingUrlContent)
646
+ this.setClientStylingURL();
647
+ this.limitStylingAppends = true;
648
+ }
649
+ // end custom styling area
650
+ }
651
+ render() {
652
+ return (index.h("div", { class: "LotteryTicketControllerContainer", ref: el => this.stylingContainer = el }, index.h("helper-accordion", { "header-title": `${translate('ticket', this.language)} ${this.ticketId}`, "header-subtitle": this.ticketDescription, footer: true, "delete-tab": true, collapsed: !this.last || this.collapsed, language: this.language, "client-styling": this.clientStyling, "client-styling-url-content": this.clientStylingUrlContent }, index.h("div", { slot: "accordionContent" }, index.h("lottery-ticket", { endpoint: this.endpoint, "game-id": this.gameId, "ticket-id": this.ticketId, "number-of-grids": this.numberOfGrids, language: this.language, "reset-button": this.resetButton, "auto-pick": this.autoPick, "client-styling": this.clientStyling, "client-styling-url-content": this.clientStylingUrlContent })))));
653
+ }
654
+ };
655
+ LotteryTicketController.style = lotteryTicketControllerCss;
656
+
657
+ exports.helper_accordion = Accordion;
658
+ exports.lottery_bullet = LotteryBullet;
659
+ exports.lottery_grid = LotteryGrid;
660
+ exports.lottery_ticket = LotteryTicket;
661
+ exports.lottery_ticket_controller = LotteryTicketController;