@everymatrix/lottery-draw-results 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 (47) hide show
  1. package/dist/cjs/index-03778cb9.js +1147 -0
  2. package/dist/cjs/index.cjs.js +2 -0
  3. package/dist/cjs/loader.cjs.js +21 -0
  4. package/dist/cjs/lottery-draw-results.cjs.entry.js +179 -0
  5. package/dist/cjs/lottery-draw-results.cjs.js +19 -0
  6. package/dist/collection/collection-manifest.json +12 -0
  7. package/dist/collection/components/lottery-draw-results/lottery-draw-results.css +148 -0
  8. package/dist/collection/components/lottery-draw-results/lottery-draw-results.js +365 -0
  9. package/dist/collection/index.js +1 -0
  10. package/dist/collection/utils/locale.utils.js +30 -0
  11. package/dist/collection/utils/utils.js +3 -0
  12. package/dist/components/index.d.ts +22 -0
  13. package/dist/components/index.js +2 -0
  14. package/dist/components/lottery-draw-results.d.ts +11 -0
  15. package/dist/components/lottery-draw-results.js +209 -0
  16. package/dist/esm/index-17920f23.js +1122 -0
  17. package/dist/esm/index.js +1 -0
  18. package/dist/esm/loader.js +17 -0
  19. package/dist/esm/lottery-draw-results.entry.js +175 -0
  20. package/dist/esm/lottery-draw-results.js +17 -0
  21. package/dist/esm/polyfills/core-js.js +11 -0
  22. package/dist/esm/polyfills/css-shim.js +1 -0
  23. package/dist/esm/polyfills/dom.js +79 -0
  24. package/dist/esm/polyfills/es5-html-element.js +1 -0
  25. package/dist/esm/polyfills/index.js +34 -0
  26. package/dist/esm/polyfills/system.js +6 -0
  27. package/dist/index.cjs.js +1 -0
  28. package/dist/index.js +1 -0
  29. package/dist/lottery-draw-results/index.esm.js +0 -0
  30. package/dist/lottery-draw-results/lottery-draw-results.esm.js +1 -0
  31. package/dist/lottery-draw-results/p-62092f31.js +2 -0
  32. package/dist/lottery-draw-results/p-c6628b24.entry.js +1 -0
  33. package/dist/stencil.config.js +22 -0
  34. package/dist/types/Users/user/workspace/everymatrix/widgets-stencil/packages/lottery-draw-results/.stencil/packages/lottery-draw-results/stencil.config.d.ts +2 -0
  35. package/dist/types/components/lottery-draw-results/lottery-draw-results.d.ts +44 -0
  36. package/dist/types/components.d.ts +87 -0
  37. package/dist/types/index.d.ts +1 -0
  38. package/dist/types/stencil-public-runtime.d.ts +1565 -0
  39. package/dist/types/utils/locale.utils.d.ts +1 -0
  40. package/dist/types/utils/utils.d.ts +1 -0
  41. package/loader/cdn.js +3 -0
  42. package/loader/index.cjs.js +3 -0
  43. package/loader/index.d.ts +12 -0
  44. package/loader/index.es2017.js +3 -0
  45. package/loader/index.js +4 -0
  46. package/loader/package.json +10 -0
  47. package/package.json +19 -0
@@ -0,0 +1,365 @@
1
+ import { Component, Prop, h, State } from '@stencil/core';
2
+ import { translate } from '../../utils/locale.utils';
3
+ import '@everymatrix/lottery-grid';
4
+ const DEFAULT_VALUES = {
5
+ gamename: 'Chrono',
6
+ gamedate: '24/09/2022',
7
+ state: 'Processing',
8
+ amount: 304444,
9
+ ticketid: '6963444',
10
+ selection: '[5, 6, 7, 8, 9]',
11
+ multiplier: 4.5,
12
+ resultstatus: 'Processing',
13
+ drawstatus: 'Won',
14
+ drawamount: 1022,
15
+ drawid: '54545555',
16
+ drawdate: '24/09/2032'
17
+ };
18
+ export class LotteryDrawResults {
19
+ constructor() {
20
+ /**
21
+ * Language of the widget
22
+ */
23
+ this.language = 'en';
24
+ /**
25
+ * Shows only the last draw
26
+ */
27
+ this.drawMode = false;
28
+ this.gameName = '';
29
+ this.multiplier = 5.434;
30
+ this.ticketData = {};
31
+ this.isLoading = true;
32
+ this.drawResults = [];
33
+ this.rules = {};
34
+ this.toggleDrawer = [false];
35
+ this.hasErrors = false;
36
+ this.errorText = '';
37
+ this.changeBox = (index) => {
38
+ this.toggleDrawer = this.toggleDrawer.map((item, itemIndex) => {
39
+ if (itemIndex == index) {
40
+ return !item;
41
+ }
42
+ return item;
43
+ });
44
+ if (index >= this.toggleDrawer.length) {
45
+ this.toggleDrawer.push(true);
46
+ }
47
+ };
48
+ }
49
+ connectedCallback() {
50
+ let promises = [];
51
+ promises.push(this.getGameData());
52
+ if (this.playerId) {
53
+ promises.push(this.getTicketData());
54
+ }
55
+ if (this.drawId) {
56
+ promises.push(this.getDrawData());
57
+ }
58
+ Promise.all(promises)
59
+ .then(() => {
60
+ this.isLoading = false;
61
+ });
62
+ }
63
+ getDrawData() {
64
+ return new Promise((resolve, reject) => {
65
+ let url = new URL(`${this.endpoint}/games/${this.gameId}/draws/${this.drawId}`);
66
+ fetch(url.href)
67
+ .then((response) => {
68
+ // @TODO EXCEPTIONS
69
+ return response.json();
70
+ })
71
+ .then((data) => {
72
+ this.drawData = data;
73
+ resolve(true);
74
+ })
75
+ .catch((err) => {
76
+ reject(err);
77
+ });
78
+ });
79
+ }
80
+ getGameData() {
81
+ return new Promise((resolve, reject) => {
82
+ let url = new URL(`${this.endpoint}/games/${this.gameId}`);
83
+ fetch(url.href)
84
+ .then((response) => {
85
+ return response.json();
86
+ })
87
+ .then((data) => {
88
+ this.rules = {
89
+ maximumAllowed: data.rules.boards[0].maximumAllowed,
90
+ totalNumbers: data.rules.boards[0].totalNumbers
91
+ };
92
+ resolve(true);
93
+ })
94
+ .catch((err) => {
95
+ this.isLoading = false;
96
+ this.hasErrors = true;
97
+ this.errorText = err;
98
+ reject(err);
99
+ });
100
+ });
101
+ }
102
+ getTicketData() {
103
+ return new Promise((resolve, reject) => {
104
+ let url = new URL(`${this.endpoint}/tickets/player/${this.playerId}`);
105
+ fetch(url.href)
106
+ .then((response) => {
107
+ return response.json();
108
+ })
109
+ .then((data) => {
110
+ this.ticketData = data.length === 0 ? DEFAULT_VALUES : data[1];
111
+ this.drawResults = this.ticketData.drawResults.map((item) => item);
112
+ this.selection = this.ticketData.selection[0].join(',');
113
+ resolve(true);
114
+ })
115
+ .catch((err) => {
116
+ reject(err);
117
+ });
118
+ });
119
+ }
120
+ render() {
121
+ var _a, _b, _c, _d, _e, _f;
122
+ if (this.isLoading) {
123
+ return (h("p", null, "Loading, please wait ..."));
124
+ }
125
+ else if (this.hasErrors) {
126
+ h("p", null, this.errorText);
127
+ }
128
+ else {
129
+ return (h("section", { class: "DrawResultsSection" }, !this.drawMode ?
130
+ h("div", { class: "DrawResultsArea" },
131
+ h("div", { class: "TicketInfo" },
132
+ h("div", { class: "TicketGameName" },
133
+ translate('drawName', this.language),
134
+ ": ",
135
+ h("span", null, this.gameName)),
136
+ h("div", { class: "TicketDate" },
137
+ "Ticket Purchase Date: ",
138
+ h("span", null, (_a = this.ticketData) === null || _a === void 0 ? void 0 : _a.createdAt.slice(0, 10))),
139
+ h("div", { class: "TicketStatus" },
140
+ "Status: ",
141
+ h("span", null, (_b = this.ticketData) === null || _b === void 0 ? void 0 : _b.state))),
142
+ h("div", { class: "DrawResultsBody" },
143
+ h("div", { class: "TicketIdContainer" },
144
+ h("p", null,
145
+ "Ticket id: ",
146
+ h("span", null, (_c = this.ticketData) === null || _c === void 0 ? void 0 : _c.id))),
147
+ h("div", { class: "TicketAmountContainer" },
148
+ h("p", null,
149
+ "Ticket amount: ",
150
+ h("span", null, (_d = this.ticketData) === null || _d === void 0 ? void 0 : _d.amount))),
151
+ h("div", { class: "DrawNumbersGrid" },
152
+ h("p", null,
153
+ translate('drawNumbersGridTicket', this.language),
154
+ ":"),
155
+ h("div", { class: "BulletContainer" },
156
+ h("lottery-grid", { "maximum-allowed": this.rules.maximumAllowed, "total-numbers": this.rules.totalNumbers, "selected-numbers": this.selection, selectable: false, "display-selected": true, language: this.language }))),
157
+ h("div", { class: "DrawMultipler" },
158
+ h("label", { class: "Label" },
159
+ "Multiplier: ",
160
+ h("span", null, JSON.stringify((_e = this.ticketData) === null || _e === void 0 ? void 0 : _e.multiplier)))),
161
+ h("div", { class: "NumberOfDrawsContainer" },
162
+ h("p", null,
163
+ translate('numberOfDraws', this.language),
164
+ ": ", (_f = this.ticketData) === null || _f === void 0 ? void 0 :
165
+ _f.drawCount),
166
+ h("div", { class: "DrawTicketsContainer" }, this.drawResults.map((item, index) => h("div", { class: "ExpandableBoxes" },
167
+ h("div", { class: this.toggleDrawer[index] ? 'ExpandableBox ShowBox' : 'ExpandableBox', onClick: () => this.changeBox(index) },
168
+ h("div", { class: "TicketResultContainer" },
169
+ h("p", null,
170
+ translate('ticketResult', this.language),
171
+ ": ",
172
+ item.status)),
173
+ item.state == 'won' &&
174
+ h("div", { class: "AmountWonContainer" },
175
+ h("p", null,
176
+ translate('amountWon', this.language),
177
+ ": ",
178
+ Number(item.amount).toLocaleString('en'),
179
+ " ",
180
+ item.currency)),
181
+ h("div", { class: "DrawIdContainer" },
182
+ h("p", null,
183
+ translate('drawId', this.language),
184
+ ": ",
185
+ item.drawId)),
186
+ h("div", { class: "DrawDateContainer" },
187
+ h("p", null,
188
+ translate('drawDate', this.language),
189
+ ": ",
190
+ item.updatedAt.slice(0, 10),
191
+ " | ",
192
+ item.updatedAt.slice(11, 19))),
193
+ h("div", { class: "DrawNumbersGrid" }),
194
+ h("div", { class: "DrawMultipler" },
195
+ h("label", { class: "Label" },
196
+ "Multiplier: ",
197
+ item.multiplier)))))))))
198
+ :
199
+ h("div", { class: "DrawResultsArea" }, this.drawData &&
200
+ h("div", null,
201
+ h("div", { class: "DrawResultsHeader" },
202
+ h("span", null,
203
+ translate('drawId', this.language),
204
+ ": ",
205
+ this.drawData.id),
206
+ h("span", null,
207
+ translate('drawDate', this.language),
208
+ ": ",
209
+ this.drawData.date.slice(0, 10))),
210
+ h("div", { class: "DrawResultsBody" },
211
+ h("div", { class: "DrawNumbersGrid" },
212
+ h("p", null,
213
+ translate('drawNumbersGridDraw', this.language),
214
+ ":"),
215
+ h("div", { class: "BulletContainer" },
216
+ h("lottery-grid", { "maximum-allowed": this.rules.maximumAllowed, "total-numbers": this.rules.totalNumbers, selectedNumbers: this.drawData.winningNumbers.join(','), "display-selected": true, selectable: false, language: this.language })),
217
+ h("div", { class: "DrawMultipler" },
218
+ h("label", { class: "Label" },
219
+ "Multiplier: ",
220
+ this.multiplier))))))));
221
+ }
222
+ }
223
+ static get is() { return "lottery-draw-results"; }
224
+ static get encapsulation() { return "shadow"; }
225
+ static get originalStyleUrls() { return {
226
+ "$": ["lottery-draw-results.scss"]
227
+ }; }
228
+ static get styleUrls() { return {
229
+ "$": ["lottery-draw-results.css"]
230
+ }; }
231
+ static get properties() { return {
232
+ "endpoint": {
233
+ "type": "string",
234
+ "mutable": false,
235
+ "complexType": {
236
+ "original": "string",
237
+ "resolved": "string",
238
+ "references": {}
239
+ },
240
+ "required": false,
241
+ "optional": false,
242
+ "docs": {
243
+ "tags": [],
244
+ "text": "Endpoint URL for the source of data"
245
+ },
246
+ "attribute": "endpoint",
247
+ "reflect": false
248
+ },
249
+ "gameId": {
250
+ "type": "string",
251
+ "mutable": false,
252
+ "complexType": {
253
+ "original": "string",
254
+ "resolved": "string",
255
+ "references": {}
256
+ },
257
+ "required": false,
258
+ "optional": false,
259
+ "docs": {
260
+ "tags": [],
261
+ "text": "GameID of the lottery game"
262
+ },
263
+ "attribute": "game-id",
264
+ "reflect": false
265
+ },
266
+ "language": {
267
+ "type": "string",
268
+ "mutable": false,
269
+ "complexType": {
270
+ "original": "string",
271
+ "resolved": "string",
272
+ "references": {}
273
+ },
274
+ "required": false,
275
+ "optional": false,
276
+ "docs": {
277
+ "tags": [],
278
+ "text": "Language of the widget"
279
+ },
280
+ "attribute": "language",
281
+ "reflect": false,
282
+ "defaultValue": "'en'"
283
+ },
284
+ "playerId": {
285
+ "type": "string",
286
+ "mutable": false,
287
+ "complexType": {
288
+ "original": "string",
289
+ "resolved": "string",
290
+ "references": {}
291
+ },
292
+ "required": false,
293
+ "optional": false,
294
+ "docs": {
295
+ "tags": [],
296
+ "text": "Player ID"
297
+ },
298
+ "attribute": "player-id",
299
+ "reflect": false
300
+ },
301
+ "drawMode": {
302
+ "type": "boolean",
303
+ "mutable": false,
304
+ "complexType": {
305
+ "original": "boolean",
306
+ "resolved": "boolean",
307
+ "references": {}
308
+ },
309
+ "required": false,
310
+ "optional": false,
311
+ "docs": {
312
+ "tags": [],
313
+ "text": "Shows only the last draw"
314
+ },
315
+ "attribute": "draw-mode",
316
+ "reflect": false,
317
+ "defaultValue": "false"
318
+ },
319
+ "drawId": {
320
+ "type": "string",
321
+ "mutable": false,
322
+ "complexType": {
323
+ "original": "string",
324
+ "resolved": "string",
325
+ "references": {}
326
+ },
327
+ "required": false,
328
+ "optional": false,
329
+ "docs": {
330
+ "tags": [],
331
+ "text": "Shows results for a specific drawID (option)"
332
+ },
333
+ "attribute": "draw-id",
334
+ "reflect": false
335
+ },
336
+ "gameName": {
337
+ "type": "string",
338
+ "mutable": false,
339
+ "complexType": {
340
+ "original": "string",
341
+ "resolved": "string",
342
+ "references": {}
343
+ },
344
+ "required": false,
345
+ "optional": false,
346
+ "docs": {
347
+ "tags": [],
348
+ "text": ""
349
+ },
350
+ "attribute": "game-name",
351
+ "reflect": false,
352
+ "defaultValue": "''"
353
+ }
354
+ }; }
355
+ static get states() { return {
356
+ "multiplier": {},
357
+ "ticketData": {},
358
+ "isLoading": {},
359
+ "drawResults": {},
360
+ "rules": {},
361
+ "toggleDrawer": {},
362
+ "hasErrors": {},
363
+ "errorText": {}
364
+ }; }
365
+ }
@@ -0,0 +1 @@
1
+ export * from './components';
@@ -0,0 +1,30 @@
1
+ const DEFAULT_LANGUAGE = 'en';
2
+ const SUPPORTED_LANGUAGES = ['ro', 'en'];
3
+ const TRANSLATIONS = {
4
+ en: {
5
+ drawResultsHeader: 'Last draw results',
6
+ drawId: 'Draw ID',
7
+ drawName: 'Game name',
8
+ drawDate: 'Draw Date',
9
+ drawNumbersGridDraw: 'Draw numbers Grid A',
10
+ drawNumbersGridTicket: 'Draw numbers Grid B',
11
+ ticketResult: 'Ticket result',
12
+ amountWon: 'Amount won',
13
+ numberOfDraws: 'Number of draws'
14
+ },
15
+ ro: {
16
+ drawResultsHeader: 'Ultimele rezultate extragere',
17
+ drawId: 'Id extragere',
18
+ drawName: 'Numele jocului',
19
+ drawDate: 'Data extragerii',
20
+ drawNumbersGridDraw: 'Numerele extrase Grid A',
21
+ drawNumbersGridTicket: 'Numerele extrase Grid B',
22
+ ticketResult: 'Rezultatul biletului',
23
+ amountWon: 'Suma castigata',
24
+ numberOfDraws: 'Numarul de extrageri'
25
+ },
26
+ };
27
+ export const translate = (key, customLang) => {
28
+ const lang = customLang;
29
+ return TRANSLATIONS[lang !== undefined && SUPPORTED_LANGUAGES.includes(lang) ? lang : DEFAULT_LANGUAGE][key];
30
+ };
@@ -0,0 +1,3 @@
1
+ export function format(first, middle, last) {
2
+ return ((first || '') + (middle ? ` ${middle}` : '') + (last ? ` ${last}` : ''));
3
+ }
@@ -0,0 +1,22 @@
1
+ /* LotteryDrawResults custom elements */
2
+ export { LotteryDrawResults as LotteryDrawResults } from '../types/components/lottery-draw-results/lottery-draw-results';
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 { LotteryDrawResults, defineCustomElement as defineCustomElementLotteryDrawResults } from './lottery-draw-results.js';
@@ -0,0 +1,11 @@
1
+ import type { Components, JSX } from "../types/components";
2
+
3
+ interface LotteryDrawResults extends Components.LotteryDrawResults, HTMLElement {}
4
+ export const LotteryDrawResults: {
5
+ prototype: LotteryDrawResults;
6
+ new (): LotteryDrawResults;
7
+ };
8
+ /**
9
+ * Used to define this component and all nested components recursively.
10
+ */
11
+ export const defineCustomElement: () => void;
@@ -0,0 +1,209 @@
1
+ import { proxyCustomElement, HTMLElement, 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
+ drawResultsHeader: 'Last draw results',
9
+ drawId: 'Draw ID',
10
+ drawName: 'Game name',
11
+ drawDate: 'Draw Date',
12
+ drawNumbersGridDraw: 'Draw numbers Grid A',
13
+ drawNumbersGridTicket: 'Draw numbers Grid B',
14
+ ticketResult: 'Ticket result',
15
+ amountWon: 'Amount won',
16
+ numberOfDraws: 'Number of draws'
17
+ },
18
+ ro: {
19
+ drawResultsHeader: 'Ultimele rezultate extragere',
20
+ drawId: 'Id extragere',
21
+ drawName: 'Numele jocului',
22
+ drawDate: 'Data extragerii',
23
+ drawNumbersGridDraw: 'Numerele extrase Grid A',
24
+ drawNumbersGridTicket: 'Numerele extrase Grid B',
25
+ ticketResult: 'Rezultatul biletului',
26
+ amountWon: 'Suma castigata',
27
+ numberOfDraws: 'Numarul de extrageri'
28
+ },
29
+ };
30
+ const translate = (key, customLang) => {
31
+ const lang = customLang;
32
+ return TRANSLATIONS[lang !== undefined && SUPPORTED_LANGUAGES.includes(lang) ? lang : DEFAULT_LANGUAGE][key];
33
+ };
34
+
35
+ const lotteryDrawResultsCss = "@import url(\"https://fonts.googleapis.com/css2?family=Roboto:wght@100&display=swap\");:host{display:block;font-family:\"Roboto\", sans-serif}.TicketInfo{display:flex;flex-direction:row;gap:15px;background-color:#009993;color:#fff;padding:12px;font-size:14px}.DrawResultsSection{max-width:500px;margin:0 auto;margin:0px auto 10px;border-radius:4px}.DrawResultsHeader{display:flex;justify-content:space-between;padding:10px 20px;background-color:#009993;color:#fff;font-size:14px}.DrawResultsHeader h4{text-transform:uppercase;font-weight:400;margin:0}.DrawMultipler label{display:block;margin:15px 0}.DrawResultsBody{padding:0 20px}.DrawResultsBody .DrawNumbersGrid{font-size:14px}.DrawResultsBody .NumberOfDrawsContainer{display:table;width:100%}.Toggle{cursor:pointer;display:inline-block}.ToggleSwitch{display:inline-block;background:#ccc;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%, #eee 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:#56c080}.ToggleCheckbox:checked+.ToggleSwitch:before{left:38px}.ToggleCheckbox{position:absolute;visibility:hidden}.Label{margin-right:5px;position:relative;top:2px}.DrawTicketsContainer{margin:30px auto}.ExpandableBoxes{position:relative}.ExpandableBox{width:100%;height:100%;max-height:100px;float:left;margin:0 0 20px 0;border:1px solid #009993;border-radius:4px;padding:10px;box-sizing:border-box;-webkit-transition:all 0.6s ease-in-out;-moz-transition:all 0.6s ease-in-out;-o-transition:all 0.6s ease-in-out;-ms-transition:all 0.6s ease-in-out;transition:all 0.6s ease-in-out;overflow:hidden}.ExpandableBox.ShowBox{max-height:400px;margin:0px 0px 20p 0px}.ExpandableBox.HideBox{width:0;height:0;overflow:hidden;border:none;padding:0;margin:0;opacity:0}";
36
+
37
+ const DEFAULT_VALUES = {
38
+ gamename: 'Chrono',
39
+ gamedate: '24/09/2022',
40
+ state: 'Processing',
41
+ amount: 304444,
42
+ ticketid: '6963444',
43
+ selection: '[5, 6, 7, 8, 9]',
44
+ multiplier: 4.5,
45
+ resultstatus: 'Processing',
46
+ drawstatus: 'Won',
47
+ drawamount: 1022,
48
+ drawid: '54545555',
49
+ drawdate: '24/09/2032'
50
+ };
51
+ const LotteryDrawResults$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
52
+ constructor() {
53
+ super();
54
+ this.__registerHost();
55
+ this.__attachShadow();
56
+ /**
57
+ * Language of the widget
58
+ */
59
+ this.language = 'en';
60
+ /**
61
+ * Shows only the last draw
62
+ */
63
+ this.drawMode = false;
64
+ this.gameName = '';
65
+ this.multiplier = 5.434;
66
+ this.ticketData = {};
67
+ this.isLoading = true;
68
+ this.drawResults = [];
69
+ this.rules = {};
70
+ this.toggleDrawer = [false];
71
+ this.hasErrors = false;
72
+ this.errorText = '';
73
+ this.changeBox = (index) => {
74
+ this.toggleDrawer = this.toggleDrawer.map((item, itemIndex) => {
75
+ if (itemIndex == index) {
76
+ return !item;
77
+ }
78
+ return item;
79
+ });
80
+ if (index >= this.toggleDrawer.length) {
81
+ this.toggleDrawer.push(true);
82
+ }
83
+ };
84
+ }
85
+ connectedCallback() {
86
+ let promises = [];
87
+ promises.push(this.getGameData());
88
+ if (this.playerId) {
89
+ promises.push(this.getTicketData());
90
+ }
91
+ if (this.drawId) {
92
+ promises.push(this.getDrawData());
93
+ }
94
+ Promise.all(promises)
95
+ .then(() => {
96
+ this.isLoading = false;
97
+ });
98
+ }
99
+ getDrawData() {
100
+ return new Promise((resolve, reject) => {
101
+ let url = new URL(`${this.endpoint}/games/${this.gameId}/draws/${this.drawId}`);
102
+ fetch(url.href)
103
+ .then((response) => {
104
+ // @TODO EXCEPTIONS
105
+ return response.json();
106
+ })
107
+ .then((data) => {
108
+ this.drawData = data;
109
+ resolve(true);
110
+ })
111
+ .catch((err) => {
112
+ reject(err);
113
+ });
114
+ });
115
+ }
116
+ getGameData() {
117
+ return new Promise((resolve, reject) => {
118
+ let url = new URL(`${this.endpoint}/games/${this.gameId}`);
119
+ fetch(url.href)
120
+ .then((response) => {
121
+ return response.json();
122
+ })
123
+ .then((data) => {
124
+ this.rules = {
125
+ maximumAllowed: data.rules.boards[0].maximumAllowed,
126
+ totalNumbers: data.rules.boards[0].totalNumbers
127
+ };
128
+ resolve(true);
129
+ })
130
+ .catch((err) => {
131
+ this.isLoading = false;
132
+ this.hasErrors = true;
133
+ this.errorText = err;
134
+ reject(err);
135
+ });
136
+ });
137
+ }
138
+ getTicketData() {
139
+ return new Promise((resolve, reject) => {
140
+ let url = new URL(`${this.endpoint}/tickets/player/${this.playerId}`);
141
+ fetch(url.href)
142
+ .then((response) => {
143
+ return response.json();
144
+ })
145
+ .then((data) => {
146
+ this.ticketData = data.length === 0 ? DEFAULT_VALUES : data[1];
147
+ this.drawResults = this.ticketData.drawResults.map((item) => item);
148
+ this.selection = this.ticketData.selection[0].join(',');
149
+ resolve(true);
150
+ })
151
+ .catch((err) => {
152
+ reject(err);
153
+ });
154
+ });
155
+ }
156
+ render() {
157
+ var _a, _b, _c, _d, _e, _f;
158
+ if (this.isLoading) {
159
+ return (h("p", null, "Loading, please wait ..."));
160
+ }
161
+ else if (this.hasErrors) {
162
+ h("p", null, this.errorText);
163
+ }
164
+ else {
165
+ return (h("section", { class: "DrawResultsSection" }, !this.drawMode ?
166
+ h("div", { class: "DrawResultsArea" }, h("div", { class: "TicketInfo" }, h("div", { class: "TicketGameName" }, translate('drawName', this.language), ": ", h("span", null, this.gameName)), h("div", { class: "TicketDate" }, "Ticket Purchase Date: ", h("span", null, (_a = this.ticketData) === null || _a === void 0 ? void 0 : _a.createdAt.slice(0, 10))), h("div", { class: "TicketStatus" }, "Status: ", h("span", null, (_b = this.ticketData) === null || _b === void 0 ? void 0 : _b.state))), h("div", { class: "DrawResultsBody" }, h("div", { class: "TicketIdContainer" }, h("p", null, "Ticket id: ", h("span", null, (_c = this.ticketData) === null || _c === void 0 ? void 0 : _c.id))), h("div", { class: "TicketAmountContainer" }, h("p", null, "Ticket amount: ", h("span", null, (_d = this.ticketData) === null || _d === void 0 ? void 0 : _d.amount))), h("div", { class: "DrawNumbersGrid" }, h("p", null, translate('drawNumbersGridTicket', this.language), ":"), h("div", { class: "BulletContainer" }, h("lottery-grid", { "maximum-allowed": this.rules.maximumAllowed, "total-numbers": this.rules.totalNumbers, "selected-numbers": this.selection, selectable: false, "display-selected": true, language: this.language }))), h("div", { class: "DrawMultipler" }, h("label", { class: "Label" }, "Multiplier: ", h("span", null, JSON.stringify((_e = this.ticketData) === null || _e === void 0 ? void 0 : _e.multiplier)))), h("div", { class: "NumberOfDrawsContainer" }, h("p", null, translate('numberOfDraws', this.language), ": ", (_f = this.ticketData) === null || _f === void 0 ? void 0 :
167
+ _f.drawCount), h("div", { class: "DrawTicketsContainer" }, this.drawResults.map((item, index) => h("div", { class: "ExpandableBoxes" }, h("div", { class: this.toggleDrawer[index] ? 'ExpandableBox ShowBox' : 'ExpandableBox', onClick: () => this.changeBox(index) }, h("div", { class: "TicketResultContainer" }, h("p", null, translate('ticketResult', this.language), ": ", item.status)), item.state == 'won' &&
168
+ h("div", { class: "AmountWonContainer" }, h("p", null, translate('amountWon', this.language), ": ", Number(item.amount).toLocaleString('en'), " ", item.currency)), h("div", { class: "DrawIdContainer" }, h("p", null, translate('drawId', this.language), ": ", item.drawId)), h("div", { class: "DrawDateContainer" }, h("p", null, translate('drawDate', this.language), ": ", item.updatedAt.slice(0, 10), " | ", item.updatedAt.slice(11, 19))), h("div", { class: "DrawNumbersGrid" }), h("div", { class: "DrawMultipler" }, h("label", { class: "Label" }, "Multiplier: ", item.multiplier)))))))))
169
+ :
170
+ h("div", { class: "DrawResultsArea" }, this.drawData &&
171
+ h("div", null, h("div", { class: "DrawResultsHeader" }, h("span", null, translate('drawId', this.language), ": ", this.drawData.id), h("span", null, translate('drawDate', this.language), ": ", this.drawData.date.slice(0, 10))), h("div", { class: "DrawResultsBody" }, h("div", { class: "DrawNumbersGrid" }, h("p", null, translate('drawNumbersGridDraw', this.language), ":"), h("div", { class: "BulletContainer" }, h("lottery-grid", { "maximum-allowed": this.rules.maximumAllowed, "total-numbers": this.rules.totalNumbers, selectedNumbers: this.drawData.winningNumbers.join(','), "display-selected": true, selectable: false, language: this.language })), h("div", { class: "DrawMultipler" }, h("label", { class: "Label" }, "Multiplier: ", this.multiplier))))))));
172
+ }
173
+ }
174
+ static get style() { return lotteryDrawResultsCss; }
175
+ }, [1, "lottery-draw-results", {
176
+ "endpoint": [1],
177
+ "gameId": [1, "game-id"],
178
+ "language": [1],
179
+ "playerId": [1, "player-id"],
180
+ "drawMode": [4, "draw-mode"],
181
+ "drawId": [1, "draw-id"],
182
+ "gameName": [1, "game-name"],
183
+ "multiplier": [32],
184
+ "ticketData": [32],
185
+ "isLoading": [32],
186
+ "drawResults": [32],
187
+ "rules": [32],
188
+ "toggleDrawer": [32],
189
+ "hasErrors": [32],
190
+ "errorText": [32]
191
+ }]);
192
+ function defineCustomElement$1() {
193
+ if (typeof customElements === "undefined") {
194
+ return;
195
+ }
196
+ const components = ["lottery-draw-results"];
197
+ components.forEach(tagName => { switch (tagName) {
198
+ case "lottery-draw-results":
199
+ if (!customElements.get(tagName)) {
200
+ customElements.define(tagName, LotteryDrawResults$1);
201
+ }
202
+ break;
203
+ } });
204
+ }
205
+
206
+ const LotteryDrawResults = LotteryDrawResults$1;
207
+ const defineCustomElement = defineCustomElement$1;
208
+
209
+ export { LotteryDrawResults, defineCustomElement };