@everymatrix/lottery-ticket 0.0.3

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 (49) hide show
  1. package/dist/cjs/index-fc097c03.js +1250 -0
  2. package/dist/cjs/index.cjs.js +2 -0
  3. package/dist/cjs/loader.cjs.js +21 -0
  4. package/dist/cjs/lottery-ticket.cjs.entry.js +147 -0
  5. package/dist/cjs/lottery-ticket.cjs.js +19 -0
  6. package/dist/collection/collection-manifest.json +12 -0
  7. package/dist/collection/components/lottery-ticket/lottery-ticket.css +193 -0
  8. package/dist/collection/components/lottery-ticket/lottery-ticket.js +384 -0
  9. package/dist/collection/components/lottery-ticket/lottery-ticket.types.js +1 -0
  10. package/dist/collection/index.js +1 -0
  11. package/dist/collection/utils/locale.utils.js +28 -0
  12. package/dist/collection/utils/utils.js +0 -0
  13. package/dist/components/index.d.ts +22 -0
  14. package/dist/components/index.js +2 -0
  15. package/dist/components/lottery-ticket.d.ts +11 -0
  16. package/dist/components/lottery-ticket.js +175 -0
  17. package/dist/esm/index-84f8a38a.js +1224 -0
  18. package/dist/esm/index.js +1 -0
  19. package/dist/esm/loader.js +17 -0
  20. package/dist/esm/lottery-ticket.entry.js +143 -0
  21. package/dist/esm/lottery-ticket.js +17 -0
  22. package/dist/esm/polyfills/core-js.js +11 -0
  23. package/dist/esm/polyfills/css-shim.js +1 -0
  24. package/dist/esm/polyfills/dom.js +79 -0
  25. package/dist/esm/polyfills/es5-html-element.js +1 -0
  26. package/dist/esm/polyfills/index.js +34 -0
  27. package/dist/esm/polyfills/system.js +6 -0
  28. package/dist/index.cjs.js +1 -0
  29. package/dist/index.js +1 -0
  30. package/dist/lottery-ticket/index.esm.js +0 -0
  31. package/dist/lottery-ticket/lottery-ticket.esm.js +1 -0
  32. package/dist/lottery-ticket/p-7ea3fc34.entry.js +1 -0
  33. package/dist/lottery-ticket/p-b69ccce7.js +2 -0
  34. package/dist/stencil.config.js +22 -0
  35. package/dist/types/Users/user/workspace/everymatrix/widgets-stencil/packages/lottery-ticket/.stencil/packages/lottery-ticket/stencil.config.d.ts +2 -0
  36. package/dist/types/components/lottery-ticket/lottery-ticket.d.ts +61 -0
  37. package/dist/types/components/lottery-ticket/lottery-ticket.types.d.ts +49 -0
  38. package/dist/types/components.d.ts +113 -0
  39. package/dist/types/index.d.ts +1 -0
  40. package/dist/types/stencil-public-runtime.d.ts +1565 -0
  41. package/dist/types/utils/locale.utils.d.ts +1 -0
  42. package/dist/types/utils/utils.d.ts +0 -0
  43. package/loader/cdn.js +3 -0
  44. package/loader/index.cjs.js +3 -0
  45. package/loader/index.d.ts +12 -0
  46. package/loader/index.es2017.js +3 -0
  47. package/loader/index.js +4 -0
  48. package/loader/package.json +10 -0
  49. package/package.json +19 -0
@@ -0,0 +1,384 @@
1
+ import { Component, h, Prop, State, Event, Listen, Watch } from '@stencil/core';
2
+ import { translate } from '../../utils/locale.utils';
3
+ import '@everymatrix/lottery-grid';
4
+ export class LotteryTicket {
5
+ constructor() {
6
+ /**
7
+ * Number of grids of a ticket
8
+ */
9
+ this.numberOfGrids = 1;
10
+ /**
11
+ * Option to have the ticket registered for multiple draws
12
+ */
13
+ this.multipleDraws = true;
14
+ /**
15
+ * Shows the reset button
16
+ */
17
+ this.resetButton = false;
18
+ /**
19
+ * Shows the auto-pick button
20
+ */
21
+ this.autoPick = false;
22
+ /**
23
+ * Language
24
+ */
25
+ this.language = 'en';
26
+ this.multiplier = false;
27
+ this.numberOfDraws = 1;
28
+ this.isLoading = true;
29
+ this.hasErrors = false;
30
+ this.ticketDone = false;
31
+ }
32
+ connectedCallback() {
33
+ let url = new URL(`${this.endpoint}/games/${this.gameId}`);
34
+ fetch(url.href)
35
+ .then((response) => {
36
+ if (response.ok) {
37
+ return response.json();
38
+ }
39
+ else {
40
+ // Throw error
41
+ this.hasErrors = true;
42
+ }
43
+ })
44
+ .then((data) => {
45
+ this.isLoading = false;
46
+ this.gameData = data;
47
+ this.grids = [...Array(data.rules.boards.length).keys()];
48
+ })
49
+ .catch((err) => {
50
+ this.isLoading = false;
51
+ this.hasErrors = true;
52
+ console.error('Error!', err);
53
+ });
54
+ }
55
+ multiplierChangeHandler(e) {
56
+ this.multiplier = e.target ? e.target.checked : false;
57
+ this.multiplierChange.emit(this.multiplier);
58
+ }
59
+ drawsChangeHandler(event) {
60
+ this.ticket = Object.assign(Object.assign({}, this.ticket), { draws: event });
61
+ this.ticketCompleted.emit(this.ticket);
62
+ }
63
+ gridFilledHandler(event) {
64
+ this.ticket = Object.assign(Object.assign({}, event.detail), { draws: this.numberOfDraws });
65
+ this.ticketDone = true;
66
+ this.ticketCompleted.emit(this.ticket);
67
+ }
68
+ toggleAutoSelection() {
69
+ this.ticketDone = true;
70
+ this.autoSelection.emit(this.ticketId);
71
+ }
72
+ toggleResetSelection() {
73
+ this.ticketDone = false;
74
+ this.resetSelection.emit(this.ticketId);
75
+ }
76
+ changeStake(event) {
77
+ this.stakeChange.emit({
78
+ ticketId: this.ticketId,
79
+ stake: event.target.value
80
+ });
81
+ }
82
+ render() {
83
+ if (this.isLoading) {
84
+ return (h("div", null,
85
+ h("p", null, translate('loading', this.language))));
86
+ }
87
+ else {
88
+ if (this.hasErrors) {
89
+ return (h("div", null,
90
+ h("p", null, translate('error', this.language))));
91
+ }
92
+ else {
93
+ const { rules } = this.gameData;
94
+ return (h("div", { class: "TicketContainer" },
95
+ h("p", null, this.gameData.name),
96
+ this.resetButton && this.ticketDone &&
97
+ h("a", { class: "ResetButton", onClick: () => this.toggleResetSelection() }, translate('resetButton', this.language)),
98
+ this.autoPick && !this.ticketDone &&
99
+ h("a", { class: "AutoButton", onClick: () => this.toggleAutoSelection() }, translate('autoButton', this.language)),
100
+ this.grids.map((item, index) => h("div", { class: "TicketGridBullets" },
101
+ h("p", { class: "TicketGridTitle" },
102
+ translate('grid', this.language),
103
+ " ",
104
+ item),
105
+ h("lottery-grid", { "grid-index": index, "maximum-allowed": rules.boards[index].maximumAllowed, "minimum-allowed": rules.boards[index].minimumAllowed, "total-numbers": rules.boards[index].totalNumbers, selectable: true, "reset-button": true, "auto-pick": true, "game-id": this.gameId, "ticket-id": this.ticketId, language: this.language }))),
106
+ rules.multiplier &&
107
+ h("div", null,
108
+ h("label", { class: "Toggle" },
109
+ h("label", { class: "Label" },
110
+ translate('multiplier', this.language),
111
+ ": "),
112
+ h("input", { class: "ToggleCheckbox", type: "checkbox", onInput: (e) => this.multiplierChangeHandler(e) }),
113
+ h("div", { class: "ToggleSwitch" }))),
114
+ this.multipleDraws &&
115
+ h("div", { class: "TicketDraws" },
116
+ h("label", { class: "Label" },
117
+ translate('numberOfDraws', this.language),
118
+ ": "),
119
+ h("div", { class: "NumberInput" },
120
+ h("button", { onClick: () => this.numberOfDraws > 1 ? this.numberOfDraws-- : this.numberOfDraws = 1, class: "Minus" }, "-"),
121
+ h("input", { class: "InputDefault", min: "1", value: this.numberOfDraws, type: "number" }),
122
+ h("button", { onClick: () => this.numberOfDraws++, class: "Plus" }, "+"))),
123
+ h("label", { class: "Label" },
124
+ translate('wagerPerDraw', this.language),
125
+ ": "),
126
+ h("div", { class: "WagerInput" }, rules.stakes.length > 1 ? h("div", null,
127
+ h("select", { class: "InputDefault", onChange: (event) => this.changeStake(event) }, rules.stakes.map((item) => h("option", { value: item.amount },
128
+ item.amount,
129
+ " ",
130
+ item.currency)))) : h("div", null,
131
+ h("input", { min: "1", value: rules.stakes[0].amount, type: "number", disabled: true }),
132
+ h("p", { class: "WagerInputTitle" }, rules.stakes[0].currency)))));
133
+ }
134
+ }
135
+ }
136
+ static get is() { return "lottery-ticket"; }
137
+ static get encapsulation() { return "shadow"; }
138
+ static get originalStyleUrls() { return {
139
+ "$": ["lottery-ticket.scss"]
140
+ }; }
141
+ static get styleUrls() { return {
142
+ "$": ["lottery-ticket.css"]
143
+ }; }
144
+ static get properties() { return {
145
+ "endpoint": {
146
+ "type": "string",
147
+ "mutable": false,
148
+ "complexType": {
149
+ "original": "string",
150
+ "resolved": "string",
151
+ "references": {}
152
+ },
153
+ "required": false,
154
+ "optional": false,
155
+ "docs": {
156
+ "tags": [],
157
+ "text": "NorWAy endpoint"
158
+ },
159
+ "attribute": "endpoint",
160
+ "reflect": false
161
+ },
162
+ "gameId": {
163
+ "type": "string",
164
+ "mutable": false,
165
+ "complexType": {
166
+ "original": "string",
167
+ "resolved": "string",
168
+ "references": {}
169
+ },
170
+ "required": false,
171
+ "optional": false,
172
+ "docs": {
173
+ "tags": [],
174
+ "text": "Game ID"
175
+ },
176
+ "attribute": "game-id",
177
+ "reflect": false
178
+ },
179
+ "numberOfGrids": {
180
+ "type": "number",
181
+ "mutable": false,
182
+ "complexType": {
183
+ "original": "number",
184
+ "resolved": "number",
185
+ "references": {}
186
+ },
187
+ "required": false,
188
+ "optional": false,
189
+ "docs": {
190
+ "tags": [],
191
+ "text": "Number of grids of a ticket"
192
+ },
193
+ "attribute": "number-of-grids",
194
+ "reflect": false,
195
+ "defaultValue": "1"
196
+ },
197
+ "multipleDraws": {
198
+ "type": "boolean",
199
+ "mutable": false,
200
+ "complexType": {
201
+ "original": "boolean",
202
+ "resolved": "boolean",
203
+ "references": {}
204
+ },
205
+ "required": false,
206
+ "optional": false,
207
+ "docs": {
208
+ "tags": [],
209
+ "text": "Option to have the ticket registered for multiple draws"
210
+ },
211
+ "attribute": "multiple-draws",
212
+ "reflect": false,
213
+ "defaultValue": "true"
214
+ },
215
+ "ticketId": {
216
+ "type": "number",
217
+ "mutable": false,
218
+ "complexType": {
219
+ "original": "number",
220
+ "resolved": "number",
221
+ "references": {}
222
+ },
223
+ "required": false,
224
+ "optional": false,
225
+ "docs": {
226
+ "tags": [],
227
+ "text": "Ticket ID"
228
+ },
229
+ "attribute": "ticket-id",
230
+ "reflect": false
231
+ },
232
+ "resetButton": {
233
+ "type": "boolean",
234
+ "mutable": false,
235
+ "complexType": {
236
+ "original": "boolean",
237
+ "resolved": "boolean",
238
+ "references": {}
239
+ },
240
+ "required": false,
241
+ "optional": false,
242
+ "docs": {
243
+ "tags": [],
244
+ "text": "Shows the reset button"
245
+ },
246
+ "attribute": "reset-button",
247
+ "reflect": false,
248
+ "defaultValue": "false"
249
+ },
250
+ "autoPick": {
251
+ "type": "boolean",
252
+ "mutable": false,
253
+ "complexType": {
254
+ "original": "boolean",
255
+ "resolved": "boolean",
256
+ "references": {}
257
+ },
258
+ "required": false,
259
+ "optional": false,
260
+ "docs": {
261
+ "tags": [],
262
+ "text": "Shows the auto-pick button"
263
+ },
264
+ "attribute": "auto-pick",
265
+ "reflect": false,
266
+ "defaultValue": "false"
267
+ },
268
+ "language": {
269
+ "type": "string",
270
+ "mutable": false,
271
+ "complexType": {
272
+ "original": "string",
273
+ "resolved": "string",
274
+ "references": {}
275
+ },
276
+ "required": false,
277
+ "optional": false,
278
+ "docs": {
279
+ "tags": [],
280
+ "text": "Language"
281
+ },
282
+ "attribute": "language",
283
+ "reflect": false,
284
+ "defaultValue": "'en'"
285
+ }
286
+ }; }
287
+ static get states() { return {
288
+ "multiplier": {},
289
+ "numberOfDraws": {},
290
+ "isLoading": {},
291
+ "hasErrors": {},
292
+ "ticketDone": {}
293
+ }; }
294
+ static get events() { return [{
295
+ "method": "ticketCompleted",
296
+ "name": "ticketCompleted",
297
+ "bubbles": true,
298
+ "cancelable": true,
299
+ "composed": true,
300
+ "docs": {
301
+ "tags": [{
302
+ "name": "TODO",
303
+ "text": "including ts type"
304
+ }],
305
+ "text": ""
306
+ },
307
+ "complexType": {
308
+ "original": "any",
309
+ "resolved": "any",
310
+ "references": {}
311
+ }
312
+ }, {
313
+ "method": "autoSelection",
314
+ "name": "autoSelection",
315
+ "bubbles": true,
316
+ "cancelable": true,
317
+ "composed": true,
318
+ "docs": {
319
+ "tags": [],
320
+ "text": ""
321
+ },
322
+ "complexType": {
323
+ "original": "any",
324
+ "resolved": "any",
325
+ "references": {}
326
+ }
327
+ }, {
328
+ "method": "resetSelection",
329
+ "name": "resetSelection",
330
+ "bubbles": true,
331
+ "cancelable": true,
332
+ "composed": true,
333
+ "docs": {
334
+ "tags": [],
335
+ "text": ""
336
+ },
337
+ "complexType": {
338
+ "original": "any",
339
+ "resolved": "any",
340
+ "references": {}
341
+ }
342
+ }, {
343
+ "method": "stakeChange",
344
+ "name": "stakeChange",
345
+ "bubbles": true,
346
+ "cancelable": true,
347
+ "composed": true,
348
+ "docs": {
349
+ "tags": [],
350
+ "text": ""
351
+ },
352
+ "complexType": {
353
+ "original": "any",
354
+ "resolved": "any",
355
+ "references": {}
356
+ }
357
+ }, {
358
+ "method": "multiplierChange",
359
+ "name": "multiplierChange",
360
+ "bubbles": true,
361
+ "cancelable": true,
362
+ "composed": true,
363
+ "docs": {
364
+ "tags": [],
365
+ "text": ""
366
+ },
367
+ "complexType": {
368
+ "original": "any",
369
+ "resolved": "any",
370
+ "references": {}
371
+ }
372
+ }]; }
373
+ static get watchers() { return [{
374
+ "propName": "numberOfDraws",
375
+ "methodName": "drawsChangeHandler"
376
+ }]; }
377
+ static get listeners() { return [{
378
+ "name": "gridFilled",
379
+ "method": "gridFilledHandler",
380
+ "target": undefined,
381
+ "capture": false,
382
+ "passive": false
383
+ }]; }
384
+ }
@@ -0,0 +1 @@
1
+ export * from './components';
@@ -0,0 +1,28 @@
1
+ const DEFAULT_LANGUAGE = 'en';
2
+ const SUPPORTED_LANGUAGES = ['ro', 'en'];
3
+ const TRANSLATIONS = {
4
+ en: {
5
+ loading: 'Loading, please wait ...',
6
+ error: 'It was an error while trying to fetch the data',
7
+ grid: 'Grid',
8
+ multiplier: 'Multiplier',
9
+ numberOfDraws: 'Number of draws',
10
+ wagerPerDraw: 'Wager per draw',
11
+ resetButton: 'Reset',
12
+ autoButton: 'I feel lucky'
13
+ },
14
+ ro: {
15
+ loading: 'Se incarca, va rugam asteptati ...',
16
+ error: 'A fost o eroare in timp ce asteptam datele',
17
+ grid: 'Grid',
18
+ multiplier: 'Multiplicator',
19
+ numberOfDraws: 'Numarul de extrageri',
20
+ wagerPerDraw: 'Pariul per extragere',
21
+ resetButton: 'Reseteaza',
22
+ autoButton: 'Ma simt norocos'
23
+ },
24
+ };
25
+ export const translate = (key, customLang) => {
26
+ const lang = customLang;
27
+ return TRANSLATIONS[lang !== undefined && SUPPORTED_LANGUAGES.includes(lang) ? lang : DEFAULT_LANGUAGE][key];
28
+ };
File without changes
@@ -0,0 +1,22 @@
1
+ /* LotteryTicket custom elements */
2
+ export { LotteryTicket as LotteryTicket } from '../types/components/lottery-ticket/lottery-ticket';
3
+
4
+ /**
5
+ * Used to manually set the base path where assets can be found.
6
+ * If the script is used as "module", it's recommended to use "import.meta.url",
7
+ * such as "setAssetPath(import.meta.url)". Other options include
8
+ * "setAssetPath(document.currentScript.src)", or using a bundler's replace plugin to
9
+ * dynamically set the path at build time, such as "setAssetPath(process.env.ASSET_PATH)".
10
+ * But do note that this configuration depends on how your script is bundled, or lack of
11
+ * bundling, and where your assets can be loaded from. Additionally custom bundling
12
+ * will have to ensure the static assets are copied to its build directory.
13
+ */
14
+ export declare const setAssetPath: (path: string) => void;
15
+
16
+ export interface SetPlatformOptions {
17
+ raf?: (c: FrameRequestCallback) => number;
18
+ ael?: (el: EventTarget, eventName: string, listener: EventListenerOrEventListenerObject, options: boolean | AddEventListenerOptions) => void;
19
+ rel?: (el: EventTarget, eventName: string, listener: EventListenerOrEventListenerObject, options: boolean | AddEventListenerOptions) => void;
20
+ }
21
+ export declare const setPlatformOptions: (opts: SetPlatformOptions) => void;
22
+ export * from '../types';
@@ -0,0 +1,2 @@
1
+ export { setAssetPath, setPlatformOptions } from '@stencil/core/internal/client';
2
+ export { LotteryTicket, defineCustomElement as defineCustomElementLotteryTicket } from './lottery-ticket.js';
@@ -0,0 +1,11 @@
1
+ import type { Components, JSX } from "../types/components";
2
+
3
+ interface LotteryTicket extends Components.LotteryTicket, HTMLElement {}
4
+ export const LotteryTicket: {
5
+ prototype: LotteryTicket;
6
+ new (): LotteryTicket;
7
+ };
8
+ /**
9
+ * Used to define this component and all nested components recursively.
10
+ */
11
+ export const defineCustomElement: () => void;
@@ -0,0 +1,175 @@
1
+ import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
2
+ import '@everymatrix/lottery-grid';
3
+
4
+ const DEFAULT_LANGUAGE = 'en';
5
+ const SUPPORTED_LANGUAGES = ['ro', 'en'];
6
+ const TRANSLATIONS = {
7
+ en: {
8
+ loading: 'Loading, please wait ...',
9
+ error: 'It was an error while trying to fetch the data',
10
+ grid: 'Grid',
11
+ multiplier: 'Multiplier',
12
+ numberOfDraws: 'Number of draws',
13
+ wagerPerDraw: 'Wager per draw',
14
+ resetButton: 'Reset',
15
+ autoButton: 'I feel lucky'
16
+ },
17
+ ro: {
18
+ loading: 'Se incarca, va rugam asteptati ...',
19
+ error: 'A fost o eroare in timp ce asteptam datele',
20
+ grid: 'Grid',
21
+ multiplier: 'Multiplicator',
22
+ numberOfDraws: 'Numarul de extrageri',
23
+ wagerPerDraw: 'Pariul per extragere',
24
+ resetButton: 'Reseteaza',
25
+ autoButton: 'Ma simt norocos'
26
+ },
27
+ };
28
+ const translate = (key, customLang) => {
29
+ const lang = customLang;
30
+ return TRANSLATIONS[lang !== undefined && SUPPORTED_LANGUAGES.includes(lang) ? lang : DEFAULT_LANGUAGE][key];
31
+ };
32
+
33
+ const lotteryTicketCss = "@import url(\"https://fonts.googleapis.com/css2?family=Roboto:wght@100&display=swap\");:host{display:block;font-family:\"Roboto\", sans-serif}.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;background-color:transparent;border:none;align-items:center;justify-content:center;height:20px;margin:0;position:relative}.NumberInput button:after{display:inline-block;position:absolute;transform:translate(-50%, -50%) rotate(180deg);width:30px;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:block;border-radius:4px;padding:8px 25px;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:block;border-radius:4px;padding:8px 25px;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}";
34
+
35
+ const LotteryTicket$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
36
+ constructor() {
37
+ super();
38
+ this.__registerHost();
39
+ this.__attachShadow();
40
+ this.ticketCompleted = createEvent(this, "ticketCompleted", 7);
41
+ this.autoSelection = createEvent(this, "autoSelection", 7);
42
+ this.resetSelection = createEvent(this, "resetSelection", 7);
43
+ this.stakeChange = createEvent(this, "stakeChange", 7);
44
+ this.multiplierChange = createEvent(this, "multiplierChange", 7);
45
+ /**
46
+ * Number of grids of a ticket
47
+ */
48
+ this.numberOfGrids = 1;
49
+ /**
50
+ * Option to have the ticket registered for multiple draws
51
+ */
52
+ this.multipleDraws = true;
53
+ /**
54
+ * Shows the reset button
55
+ */
56
+ this.resetButton = false;
57
+ /**
58
+ * Shows the auto-pick button
59
+ */
60
+ this.autoPick = false;
61
+ /**
62
+ * Language
63
+ */
64
+ this.language = 'en';
65
+ this.multiplier = false;
66
+ this.numberOfDraws = 1;
67
+ this.isLoading = true;
68
+ this.hasErrors = false;
69
+ this.ticketDone = false;
70
+ }
71
+ connectedCallback() {
72
+ let url = new URL(`${this.endpoint}/games/${this.gameId}`);
73
+ fetch(url.href)
74
+ .then((response) => {
75
+ if (response.ok) {
76
+ return response.json();
77
+ }
78
+ else {
79
+ // Throw error
80
+ this.hasErrors = true;
81
+ }
82
+ })
83
+ .then((data) => {
84
+ this.isLoading = false;
85
+ this.gameData = data;
86
+ this.grids = [...Array(data.rules.boards.length).keys()];
87
+ })
88
+ .catch((err) => {
89
+ this.isLoading = false;
90
+ this.hasErrors = true;
91
+ console.error('Error!', err);
92
+ });
93
+ }
94
+ multiplierChangeHandler(e) {
95
+ this.multiplier = e.target ? e.target.checked : false;
96
+ this.multiplierChange.emit(this.multiplier);
97
+ }
98
+ drawsChangeHandler(event) {
99
+ this.ticket = Object.assign(Object.assign({}, this.ticket), { draws: event });
100
+ this.ticketCompleted.emit(this.ticket);
101
+ }
102
+ gridFilledHandler(event) {
103
+ this.ticket = Object.assign(Object.assign({}, event.detail), { draws: this.numberOfDraws });
104
+ this.ticketDone = true;
105
+ this.ticketCompleted.emit(this.ticket);
106
+ }
107
+ toggleAutoSelection() {
108
+ this.ticketDone = true;
109
+ this.autoSelection.emit(this.ticketId);
110
+ }
111
+ toggleResetSelection() {
112
+ this.ticketDone = false;
113
+ this.resetSelection.emit(this.ticketId);
114
+ }
115
+ changeStake(event) {
116
+ this.stakeChange.emit({
117
+ ticketId: this.ticketId,
118
+ stake: event.target.value
119
+ });
120
+ }
121
+ render() {
122
+ if (this.isLoading) {
123
+ return (h("div", null, h("p", null, translate('loading', this.language))));
124
+ }
125
+ else {
126
+ if (this.hasErrors) {
127
+ return (h("div", null, h("p", null, translate('error', this.language))));
128
+ }
129
+ else {
130
+ const { rules } = this.gameData;
131
+ return (h("div", { class: "TicketContainer" }, h("p", null, this.gameData.name), this.resetButton && this.ticketDone &&
132
+ h("a", { class: "ResetButton", onClick: () => this.toggleResetSelection() }, translate('resetButton', this.language)), this.autoPick && !this.ticketDone &&
133
+ h("a", { class: "AutoButton", onClick: () => this.toggleAutoSelection() }, translate('autoButton', this.language)), this.grids.map((item, index) => h("div", { class: "TicketGridBullets" }, h("p", { class: "TicketGridTitle" }, translate('grid', this.language), " ", item), h("lottery-grid", { "grid-index": index, "maximum-allowed": rules.boards[index].maximumAllowed, "minimum-allowed": rules.boards[index].minimumAllowed, "total-numbers": rules.boards[index].totalNumbers, selectable: true, "reset-button": true, "auto-pick": true, "game-id": this.gameId, "ticket-id": this.ticketId, language: this.language }))), rules.multiplier &&
134
+ h("div", null, h("label", { class: "Toggle" }, h("label", { class: "Label" }, translate('multiplier', this.language), ": "), h("input", { class: "ToggleCheckbox", type: "checkbox", onInput: (e) => this.multiplierChangeHandler(e) }), h("div", { class: "ToggleSwitch" }))), this.multipleDraws &&
135
+ h("div", { class: "TicketDraws" }, h("label", { class: "Label" }, translate('numberOfDraws', this.language), ": "), h("div", { class: "NumberInput" }, h("button", { onClick: () => this.numberOfDraws > 1 ? this.numberOfDraws-- : this.numberOfDraws = 1, class: "Minus" }, "-"), h("input", { class: "InputDefault", min: "1", value: this.numberOfDraws, type: "number" }), h("button", { onClick: () => this.numberOfDraws++, class: "Plus" }, "+"))), h("label", { class: "Label" }, translate('wagerPerDraw', this.language), ": "), h("div", { class: "WagerInput" }, rules.stakes.length > 1 ? h("div", null, h("select", { class: "InputDefault", onChange: (event) => this.changeStake(event) }, rules.stakes.map((item) => h("option", { value: item.amount }, item.amount, " ", item.currency)))) : h("div", null, h("input", { min: "1", value: rules.stakes[0].amount, type: "number", disabled: true }), h("p", { class: "WagerInputTitle" }, rules.stakes[0].currency)))));
136
+ }
137
+ }
138
+ }
139
+ static get watchers() { return {
140
+ "numberOfDraws": ["drawsChangeHandler"]
141
+ }; }
142
+ static get style() { return lotteryTicketCss; }
143
+ }, [1, "lottery-ticket", {
144
+ "endpoint": [1],
145
+ "gameId": [1, "game-id"],
146
+ "numberOfGrids": [2, "number-of-grids"],
147
+ "multipleDraws": [4, "multiple-draws"],
148
+ "ticketId": [2, "ticket-id"],
149
+ "resetButton": [4, "reset-button"],
150
+ "autoPick": [4, "auto-pick"],
151
+ "language": [1],
152
+ "multiplier": [32],
153
+ "numberOfDraws": [32],
154
+ "isLoading": [32],
155
+ "hasErrors": [32],
156
+ "ticketDone": [32]
157
+ }, [[0, "gridFilled", "gridFilledHandler"]]]);
158
+ function defineCustomElement$1() {
159
+ if (typeof customElements === "undefined") {
160
+ return;
161
+ }
162
+ const components = ["lottery-ticket"];
163
+ components.forEach(tagName => { switch (tagName) {
164
+ case "lottery-ticket":
165
+ if (!customElements.get(tagName)) {
166
+ customElements.define(tagName, LotteryTicket$1);
167
+ }
168
+ break;
169
+ } });
170
+ }
171
+
172
+ const LotteryTicket = LotteryTicket$1;
173
+ const defineCustomElement = defineCustomElement$1;
174
+
175
+ export { LotteryTicket, defineCustomElement };