hemfixarna-web-components 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/dist/hemfixarna-components/api-3228fe30.js +28 -0
  2. package/dist/hemfixarna-components/api-3228fe30.js.map +1 -0
  3. package/dist/hemfixarna-components/app-globals-0f993ce5.js.map +1 -1
  4. package/dist/hemfixarna-components/assets/back.svg +3 -0
  5. package/dist/hemfixarna-components/assets/cart.svg +10 -0
  6. package/dist/hemfixarna-components/assets/checked.svg +10 -0
  7. package/dist/hemfixarna-components/assets/close.svg +5 -0
  8. package/dist/hemfixarna-components/assets/date.svg +6 -0
  9. package/dist/hemfixarna-components/assets/down.svg +3 -0
  10. package/dist/hemfixarna-components/assets/info.svg +5 -0
  11. package/dist/hemfixarna-components/assets/minus.svg +4 -0
  12. package/dist/hemfixarna-components/assets/plus.svg +5 -0
  13. package/dist/hemfixarna-components/calc-a9ece205.js +85 -0
  14. package/dist/hemfixarna-components/calc-a9ece205.js.map +1 -0
  15. package/dist/hemfixarna-components/css-shim-62d2171c.js.map +1 -1
  16. package/dist/hemfixarna-components/dom-46a68c9b.js.map +1 -1
  17. package/dist/hemfixarna-components/hemfixarna-address.entry.js +52 -0
  18. package/dist/hemfixarna-components/hemfixarna-address.entry.js.map +1 -0
  19. package/dist/hemfixarna-components/hemfixarna-box.entry.js +35 -0
  20. package/dist/hemfixarna-components/hemfixarna-box.entry.js.map +1 -0
  21. package/dist/hemfixarna-components/hemfixarna-breadcrumbs.entry.js +40 -0
  22. package/dist/hemfixarna-components/hemfixarna-breadcrumbs.entry.js.map +1 -0
  23. package/dist/hemfixarna-components/hemfixarna-byggmax.entry.js +3 -35
  24. package/dist/hemfixarna-components/hemfixarna-byggmax.entry.js.map +1 -1
  25. package/dist/hemfixarna-components/hemfixarna-cart.entry.js +82 -0
  26. package/dist/hemfixarna-components/hemfixarna-cart.entry.js.map +1 -0
  27. package/dist/hemfixarna-components/hemfixarna-category.entry.js +21 -0
  28. package/dist/hemfixarna-components/hemfixarna-category.entry.js.map +1 -0
  29. package/dist/hemfixarna-components/hemfixarna-checkout.entry.js +54 -0
  30. package/dist/hemfixarna-components/hemfixarna-checkout.entry.js.map +1 -0
  31. package/dist/hemfixarna-components/hemfixarna-component.entry.js +133 -0
  32. package/dist/hemfixarna-components/hemfixarna-component.entry.js.map +1 -0
  33. package/dist/hemfixarna-components/hemfixarna-components.esm.js +3 -3
  34. package/dist/hemfixarna-components/hemfixarna-components.esm.js.map +1 -1
  35. package/dist/hemfixarna-components/{my-component.entry.js → hemfixarna-demo.entry.js} +19 -15
  36. package/dist/hemfixarna-components/hemfixarna-demo.entry.js.map +1 -0
  37. package/dist/hemfixarna-components/hemfixarna-getuser.entry.js +410 -0
  38. package/dist/hemfixarna-components/hemfixarna-getuser.entry.js.map +1 -0
  39. package/dist/hemfixarna-components/hemfixarna-info.entry.js +25 -0
  40. package/dist/hemfixarna-components/hemfixarna-info.entry.js.map +1 -0
  41. package/dist/hemfixarna-components/hemfixarna-order.entry.js +24 -0
  42. package/dist/hemfixarna-components/hemfixarna-order.entry.js.map +1 -0
  43. package/dist/hemfixarna-components/hemfixarna-product.entry.js +121 -0
  44. package/dist/hemfixarna-components/hemfixarna-product.entry.js.map +1 -0
  45. package/dist/hemfixarna-components/hemfixarna-service.entry.js +9 -139
  46. package/dist/hemfixarna-components/hemfixarna-service.entry.js.map +1 -1
  47. package/dist/hemfixarna-components/hemfixarna-start.entry.js +18 -0
  48. package/dist/hemfixarna-components/hemfixarna-start.entry.js.map +1 -0
  49. package/dist/hemfixarna-components/index-2bf8566c.js +12 -0
  50. package/dist/hemfixarna-components/index-2bf8566c.js.map +1 -0
  51. package/dist/hemfixarna-components/{index-06272934.js → index-59ed730c.js} +3 -3
  52. package/dist/hemfixarna-components/index-59ed730c.js.map +1 -0
  53. package/dist/hemfixarna-components/index-75ed3bb8.js +216 -0
  54. package/dist/hemfixarna-components/index-75ed3bb8.js.map +1 -0
  55. package/dist/hemfixarna-components/shadow-css-05e0c1f4.js.map +1 -1
  56. package/dist/types/components/hemfixarna-address/hemfixarna-address.d.ts +13 -0
  57. package/dist/types/components/hemfixarna-box/hemfixarna-box.d.ts +8 -0
  58. package/dist/types/components/hemfixarna-breadcrumbs/hemfixarna-breadcrumbs.d.ts +9 -0
  59. package/dist/types/components/hemfixarna-byggmax/hemfixarna-byggmax.d.ts +1 -7
  60. package/dist/types/components/hemfixarna-cart/hemfixarna-cart.d.ts +13 -0
  61. package/dist/types/components/hemfixarna-category.tsx/hemfixarna-category.d.ts +5 -0
  62. package/dist/types/components/hemfixarna-checkout/hemfixarna-checkout.d.ts +10 -0
  63. package/dist/types/components/hemfixarna-component/hemfixarna-component.d.ts +19 -0
  64. package/dist/types/components/{my-component/my-component.d.ts → hemfixarna-demo/hemfixarna-demo.d.ts} +2 -1
  65. package/dist/types/components/hemfixarna-getuser/hemfixarna-getuser.d.ts +14 -0
  66. package/dist/types/components/hemfixarna-info/hemfixarna-info.d.ts +13 -0
  67. package/dist/types/components/hemfixarna-order/hemfixarna-order.d.ts +4 -0
  68. package/dist/types/components/hemfixarna-product/hemfixarna-product.d.ts +13 -0
  69. package/dist/types/components/hemfixarna-service/hemfixarna-service.d.ts +2 -39
  70. package/dist/types/components/hemfixarna-start/hemfixarna-start.d.ts +5 -0
  71. package/dist/types/components.d.ts +189 -21
  72. package/dist/types/store/index.d.ts +26 -0
  73. package/dist/types/types/index.d.ts +41 -1
  74. package/dist/types/utils/api.d.ts +4 -2
  75. package/dist/types/utils/calc.d.ts +18 -0
  76. package/dist/types/utils/felixFunctions.d.ts +21 -0
  77. package/package.json +10 -2
  78. package/dist/hemfixarna-components/api-609888bb.js +0 -18
  79. package/dist/hemfixarna-components/api-609888bb.js.map +0 -1
  80. package/dist/hemfixarna-components/index-06272934.js.map +0 -1
  81. package/dist/hemfixarna-components/my-component.entry.js.map +0 -1
@@ -0,0 +1,410 @@
1
+ import { r as registerInstance, h } from './index-59ed730c.js';
2
+ import { s as state } from './index-75ed3bb8.js';
3
+
4
+ // src/errors.ts
5
+ var PersonnummerError = class extends Error {
6
+ constructor() {
7
+ super("Invalid swedish personal identity number");
8
+ }
9
+ };
10
+
11
+ // src/utils.ts
12
+ var compareAsc = (dateLeft, dateRight) => {
13
+ const diff = dateLeft.getTime() - dateRight.getTime();
14
+ return diff < 0 ? -1 : diff > 0 ? 1 : diff;
15
+ };
16
+ var diffInYears = (dateLeft, dateRight) => {
17
+ const sign = compareAsc(dateLeft, dateRight);
18
+ const yearDiff = Math.abs(dateLeft.getFullYear() - dateRight.getFullYear());
19
+ dateLeft.setFullYear(dateLeft.getFullYear() - sign * yearDiff);
20
+ const isLastYearNotFull = compareAsc(dateLeft, dateRight) === -sign;
21
+ const result = sign * (yearDiff - +isLastYearNotFull);
22
+ return result === 0 ? 0 : result;
23
+ };
24
+ var luhn = (str) => {
25
+ let sum = 0;
26
+ str += "";
27
+ for (let i = 0, l = str.length; i < l; i++) {
28
+ let v = parseInt(str[i]);
29
+ v *= 2 - i % 2;
30
+ if (v > 9) {
31
+ v -= 9;
32
+ }
33
+ sum += v;
34
+ }
35
+ return Math.ceil(sum / 10) * 10 - sum;
36
+ };
37
+ var testDate = (year, month, day) => {
38
+ month -= 1;
39
+ const date = new Date(year, month, day);
40
+ return !(date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day);
41
+ };
42
+
43
+ // src/index.ts
44
+ var Personnummer = class {
45
+ /**
46
+ * Personnummer constructor.
47
+ *
48
+ * @param {string} pin
49
+ * @param {object} options
50
+ */
51
+ constructor(pin, options) {
52
+ /**
53
+ * Personnummer century.
54
+ *
55
+ * @var {string}
56
+ */
57
+ this._century = "";
58
+ /**
59
+ * Personnummer full year.
60
+ *
61
+ * @var {string}
62
+ */
63
+ this._fullYear = "";
64
+ /**
65
+ * Personnummer year.
66
+ *
67
+ * @var {string}
68
+ */
69
+ this._year = "";
70
+ /**
71
+ * Personnummer month.
72
+ *
73
+ * @var {string}
74
+ */
75
+ this._month = "";
76
+ /**
77
+ * Personnummer day.
78
+ *
79
+ * @var {string}
80
+ */
81
+ this._day = "";
82
+ /**
83
+ * Personnummer seperator.
84
+ *
85
+ * @var {string}
86
+ */
87
+ this._sep = "";
88
+ /**
89
+ * Personnumer first three of the last four numbers.
90
+ *
91
+ * @var {string}
92
+ */
93
+ this._num = "";
94
+ /**
95
+ * The last number of the personnummer.
96
+ *
97
+ * @var {string}
98
+ */
99
+ this._check = "";
100
+ this.parse(pin, {
101
+ allowCoordinationNumber: true,
102
+ allowInterimNumber: false,
103
+ ...options
104
+ });
105
+ }
106
+ /**
107
+ * Get century.
108
+ *
109
+ * @return {string}
110
+ */
111
+ get century() {
112
+ return this._century;
113
+ }
114
+ /**
115
+ * Get age.
116
+ *
117
+ * @return {string}
118
+ */
119
+ get fullYear() {
120
+ return this._fullYear;
121
+ }
122
+ /**
123
+ * Get age.
124
+ *
125
+ * @return {string}
126
+ */
127
+ get year() {
128
+ return this._year;
129
+ }
130
+ /**
131
+ * Get month.
132
+ *
133
+ * @return {string}
134
+ */
135
+ get month() {
136
+ return this._month;
137
+ }
138
+ /**
139
+ * Get day.
140
+ *
141
+ * @return {string}
142
+ */
143
+ get day() {
144
+ return this._day;
145
+ }
146
+ /**
147
+ * Get sep.
148
+ *
149
+ * @return {string}
150
+ */
151
+ get sep() {
152
+ return this._sep;
153
+ }
154
+ /**
155
+ * Get num.
156
+ *
157
+ * @return {string}
158
+ */
159
+ get num() {
160
+ return this._num;
161
+ }
162
+ /**
163
+ * Get check.
164
+ *
165
+ * @return {string}
166
+ */
167
+ get check() {
168
+ return this._check;
169
+ }
170
+ /**
171
+ * Parse personnummer.
172
+ *
173
+ * @param {string} pin
174
+ * @param {object} options
175
+ *
176
+ * @return {Personnummer}
177
+ */
178
+ static parse(pin, options) {
179
+ return new Personnummer(pin, options);
180
+ }
181
+ /**
182
+ * Validate a Swedish personal identity number.
183
+ *
184
+ * @param {string} str
185
+ * @param {object} options
186
+ *
187
+ * @return {boolean}
188
+ */
189
+ static valid(pin, options) {
190
+ try {
191
+ Personnummer.parse(pin, options);
192
+ return true;
193
+ } catch (e) {
194
+ return false;
195
+ }
196
+ }
197
+ /**
198
+ * Parse personnummer and set class properties.
199
+ *
200
+ * @param {string} pin
201
+ * @param {object} options
202
+ */
203
+ parse(pin, options) {
204
+ if (pin.length < 10 || pin.length > 13) {
205
+ throw new PersonnummerError();
206
+ }
207
+ const reg = /^(\d{2}){0,1}(\d{2})(\d{2})(\d{2})([+-]?)((?!000)\d{3}|[TRSUWXJKLMN]\d{2})(\d)$/;
208
+ const match = reg.exec(pin);
209
+ if (!match) {
210
+ throw new PersonnummerError();
211
+ }
212
+ const century = match[1];
213
+ const year = match[2];
214
+ const month = match[3];
215
+ const day = match[4];
216
+ const sep = match[5];
217
+ const num = match[6];
218
+ const check = match[7];
219
+ if (typeof century === "undefined" || !century.length) {
220
+ const d = /* @__PURE__ */ new Date();
221
+ let baseYear = 0;
222
+ if (sep === "+") {
223
+ this._sep = "+";
224
+ baseYear = d.getFullYear() - 100;
225
+ } else {
226
+ this._sep = "-";
227
+ baseYear = d.getFullYear();
228
+ }
229
+ this._century = ("" + (baseYear - (baseYear - parseInt(year)) % 100)).substr(0, 2);
230
+ } else {
231
+ this._century = century;
232
+ if ((/* @__PURE__ */ new Date()).getFullYear() - parseInt(century + year, 10) < 100) {
233
+ this._sep = "-";
234
+ } else {
235
+ this._sep = "+";
236
+ }
237
+ }
238
+ this._year = year;
239
+ this._fullYear = this._century + year;
240
+ this._month = month;
241
+ this._day = day;
242
+ this._num = num;
243
+ this._check = check;
244
+ if (!this.valid()) {
245
+ throw new PersonnummerError();
246
+ }
247
+ if (!(options == null ? void 0 : options.allowCoordinationNumber) && this.isCoordinationNumber()) {
248
+ throw new PersonnummerError();
249
+ }
250
+ if (!(options == null ? void 0 : options.allowInterimNumber) && this.isInterimNumber()) {
251
+ throw new PersonnummerError();
252
+ }
253
+ }
254
+ /**
255
+ * Validate a Swedish personal identity number.
256
+ *
257
+ * @return {boolean}
258
+ */
259
+ valid() {
260
+ const valid = luhn(
261
+ this.year + this.month + this.day + this.num.replace(/[TRSUWXJKLMN]/, "1")
262
+ ) === +this.check && !!this.check;
263
+ if (valid && testDate(parseInt(this.century + this.year), +this.month, +this.day)) {
264
+ return valid;
265
+ }
266
+ return valid && testDate(parseInt(this.century + this.year), +this.month, +this.day - 60);
267
+ }
268
+ /**
269
+ * Format a Swedish personal identity number as one of the official formats,
270
+ * A long format or a short format.
271
+ *
272
+ * If the input number could not be parsed a empty string will be returned.
273
+ *
274
+ * @param {boolean} longFormat
275
+ *
276
+ * @return {string}
277
+ */
278
+ format(longFormat = false) {
279
+ if (longFormat) {
280
+ return `${this.century}${this.year}${this.month}${this.day}${this.num}${this.check}`;
281
+ }
282
+ return `${this.year}${this.month}${this.day}${this.sep}${this.num}${this.check}`;
283
+ }
284
+ /**
285
+ * Get age from a Swedish personal identity number.
286
+ *
287
+ * @return {number}
288
+ */
289
+ getAge() {
290
+ const date = this.getDate();
291
+ return diffInYears(new Date(Date.now()), date);
292
+ }
293
+ /**
294
+ * Get date from a Swedish personal identity number.
295
+ *
296
+ * @return {Date}
297
+ */
298
+ getDate() {
299
+ let ageDay = +this.day;
300
+ if (this.isCoordinationNumber()) {
301
+ ageDay -= 60;
302
+ }
303
+ const ageDate = this.century + this.year + "-" + this.month + "-" + (ageDay < 10 ? "0" + ageDay : ageDay);
304
+ return new Date(ageDate);
305
+ }
306
+ /**
307
+ * Check if a Swedish personal identity number is a interim number or not.
308
+ *
309
+ * @return {boolean}
310
+ */
311
+ isInterimNumber() {
312
+ return /[TRSUWXJKLMN]/.test(this.num[0]);
313
+ }
314
+ /**
315
+ * Check if a Swedish personal identity number is a coordination number or not.
316
+ *
317
+ * @return {boolean}
318
+ */
319
+ isCoordinationNumber() {
320
+ return testDate(
321
+ parseInt(this.century + this.year),
322
+ +this.month,
323
+ +this.day - 60
324
+ );
325
+ }
326
+ /**
327
+ * Check if a Swedish personal identity number is for a female.
328
+ *
329
+ * @return {boolean}
330
+ */
331
+ isFemale() {
332
+ return !this.isMale();
333
+ }
334
+ /**
335
+ * Check if a Swedish personal identity number is for a male.
336
+ *
337
+ * @return {boolean}
338
+ */
339
+ isMale() {
340
+ const sexDigit = parseInt(this.num.substr(-1));
341
+ return sexDigit % 2 === 1;
342
+ }
343
+ };
344
+ var src_default = Personnummer;
345
+
346
+ const HemfixarnaGetuser = class {
347
+ constructor(hostRef) {
348
+ registerInstance(this, hostRef);
349
+ this.handleChangeEmail = (e) => {
350
+ this.emailError = null;
351
+ this.email = e.target.value;
352
+ };
353
+ this.handleChangePhone = (e) => {
354
+ this.phoneError = null;
355
+ this.phone = e.target.value;
356
+ };
357
+ this.handleChangessn = (e) => {
358
+ this.ssnError = null;
359
+ this.ssn = e.target.value;
360
+ };
361
+ this.handleSubmit = (e) => {
362
+ e.preventDefault();
363
+ const emailRegex = new RegExp(/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/);
364
+ const validEmail = emailRegex.test(this.email);
365
+ if (!validEmail) {
366
+ this.emailError = 'Ange en giltig e-postadress';
367
+ }
368
+ const validPhone = this.phone.length > 6;
369
+ if (!validPhone) {
370
+ this.phoneError = 'Ange ett giltigt telefonnummer';
371
+ }
372
+ const validssn = src_default.valid(this.ssn);
373
+ if (!validssn) {
374
+ this.ssnError = 'Ange ett giltigt personnummer';
375
+ }
376
+ else if (validssn) {
377
+ const pn = src_default.parse(this.ssn).format(true);
378
+ this.ssn = [pn.slice(0, 8), '-', pn.slice(8)].join('');
379
+ }
380
+ if (validEmail && validPhone && validssn) {
381
+ state.checkoutStep = 2;
382
+ state.user = {
383
+ email: this.email,
384
+ phone: this.phone,
385
+ ssn: this.ssn,
386
+ };
387
+ }
388
+ };
389
+ this.render = () => {
390
+ return (h("form", { class: "mb-2", onSubmit: e => this.handleSubmit(e) }, h("div", null, h("input", { class: `${this.email.length ? 'input_active' : ''}`, onChange: e => this.handleChangeEmail(e), type: "email", name: "email", value: this.email }), h("label", { htmlFor: "email" }, "E-post ")), this.emailError && h("span", null, this.emailError), h("div", null, h("input", { class: `${this.phone.length ? 'input_active' : ''}`, onChange: e => this.handleChangePhone(e), type: "tel", name: "phone", value: this.phone }), h("label", { htmlFor: "phone" }, "Mobiltelefon ")), this.phoneError && h("span", null, this.phoneError), h("div", null, h("input", { class: `${this.ssn.length ? 'input_active' : ''}`, onChange: e => this.handleChangessn(e), type: "tel", name: "ssn", value: this.ssn }), h("label", { htmlFor: "phone" }, "Personnummer*")), this.ssnError && h("span", null, this.ssnError), h("input", { type: "submit", value: "Forts\u00E4tt och Boka*" }), h("p", null, "*Vi h\u00E4mtar din adress")));
391
+ };
392
+ this.email = '';
393
+ this.emailError = null;
394
+ this.phone = '';
395
+ this.phoneError = null;
396
+ this.ssn = '';
397
+ this.ssnError = null;
398
+ }
399
+ componentWillLoad() {
400
+ if (state.user) {
401
+ this.email = state.user.email;
402
+ this.phone = state.user.phone;
403
+ this.ssn = state.user.ssn;
404
+ }
405
+ }
406
+ };
407
+
408
+ export { HemfixarnaGetuser as hemfixarna_getuser };
409
+
410
+ //# sourceMappingURL=hemfixarna-getuser.entry.js.map
@@ -0,0 +1 @@
1
+ {"file":"hemfixarna-getuser.entry.esm.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":[],"sourcesContent":[],"version":3}
@@ -0,0 +1,25 @@
1
+ import { r as registerInstance, g as getAssetPath, h, F as Fragment } from './index-59ed730c.js';
2
+ import { s as state } from './index-75ed3bb8.js';
3
+
4
+ const HemfixarnaInfo = class {
5
+ constructor(hostRef) {
6
+ registerInstance(this, hostRef);
7
+ this.logo = getAssetPath(`./assets/hemfixarna.svg`);
8
+ this.checkoutList = [
9
+ { trust_badge: 'Efter att du fyllt i formuläret blir du kontaktad av en Hemfixare för bokning av tid.' },
10
+ { trust_badge: 'När jobbet är klart kommer du få en faktura med RUT/ROT-avdrag.' },
11
+ ];
12
+ this.list = null;
13
+ }
14
+ getList() {
15
+ return this.list ? this.list : this.checkoutList;
16
+ }
17
+ render() {
18
+ const checked = getAssetPath(`./assets/checked.svg`);
19
+ return (h("div", { class: "hemfixarna_info" }, state.step < 5 ? (h(Fragment, null, h("h2", null, "Vilka \u00E4r Hemfixarna?"), h("p", null, "Vi fixar allt fr\u00E5n kr\u00E5ngliga datorer till montering av m\u00F6bler. Vi finns i hela Sverige och \u00E4r alltid redo att rycka ut."))) : (h("h2", null, "Vad h\u00E4nder nu?")), h("ul", { class: "hemfixarna_features" }, this.getList().map(l => (h("li", { key: l.trust_badge }, h("img", { src: checked, alt: "checked" }), h("p", null, l.trust_badge))))), h("img", { src: this.logo, width: 200, alt: "hemfixarna" }), h("a", { class: "hemfixarna_product--link", target: "_blank", href: state.options.link.url }, state.options.link.title)));
20
+ }
21
+ };
22
+
23
+ export { HemfixarnaInfo as hemfixarna_info };
24
+
25
+ //# sourceMappingURL=hemfixarna-info.entry.js.map
@@ -0,0 +1 @@
1
+ {"file":"hemfixarna-info.entry.esm.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":[],"sourcesContent":[],"version":3}
@@ -0,0 +1,24 @@
1
+ import { r as registerInstance, g as getAssetPath, h } from './index-59ed730c.js';
2
+ import { s as state } from './index-75ed3bb8.js';
3
+
4
+ const HemfixarnaOrder = class {
5
+ constructor(hostRef) {
6
+ registerInstance(this, hostRef);
7
+ this.render = () => {
8
+ const hemfixarna = getAssetPath(`./assets/hemfixarna.svg`);
9
+ return (h("div", { style: { background: `url(${state.options.thank_you_image})` }, class: "hemfixarna_order" }, h("div", null), h("div", null, h("h2", null, "Tack f\u00F6r din bokning"), h("img", { onClick: () => this.resetShop(), src: hemfixarna, width: 200, alt: "hemfixarna" }), h("span", { onClick: () => this.resetShop() }, h("button", null, "Ny bokning")))));
10
+ };
11
+ }
12
+ resetShop() {
13
+ state.step = 1;
14
+ state.cart = [];
15
+ state.selectedCategory = null;
16
+ state.selectedService = null;
17
+ state.selectedProduct = null;
18
+ state.checkoutStep = 1;
19
+ }
20
+ };
21
+
22
+ export { HemfixarnaOrder as hemfixarna_order };
23
+
24
+ //# sourceMappingURL=hemfixarna-order.entry.js.map
@@ -0,0 +1 @@
1
+ {"file":"hemfixarna-order.entry.esm.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":[],"sourcesContent":[],"version":3}
@@ -0,0 +1,121 @@
1
+ import { r as registerInstance, g as getAssetPath, h } from './index-59ed730c.js';
2
+ import { s as state } from './index-75ed3bb8.js';
3
+ import { a as getProductPrice, c as getPartPrice } from './calc-a9ece205.js';
4
+
5
+ const HemfixarnaProduct = class {
6
+ constructor(hostRef) {
7
+ registerInstance(this, hostRef);
8
+ this.amount = 0;
9
+ }
10
+ addProduct() {
11
+ const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);
12
+ if (productInCart) {
13
+ productInCart.amount++;
14
+ state.cart = [...state.cart];
15
+ }
16
+ else {
17
+ state.cart = [
18
+ ...state.cart,
19
+ {
20
+ id: state.selectedProduct.ID,
21
+ rut: state.selectedProduct.rut,
22
+ rot: state.selectedProduct.rot,
23
+ amount: 1,
24
+ parts: [],
25
+ price: state.selectedProduct.price,
26
+ name: state.selectedProduct.post_title,
27
+ start_fee: !state.selectedProduct.start_fee,
28
+ terms_checkout: state.selectedProduct.terms_checkout,
29
+ terms_show_checkbox: state.selectedProduct.terms_show_checkbox,
30
+ icon: state.selectedProduct.icon,
31
+ },
32
+ ];
33
+ }
34
+ }
35
+ removeProduct() {
36
+ const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);
37
+ if (productInCart && productInCart.amount > 1) {
38
+ productInCart.amount--;
39
+ state.cart = [...state.cart];
40
+ }
41
+ else {
42
+ state.cart = state.cart.filter(p => p.id !== state.selectedProduct.ID);
43
+ }
44
+ }
45
+ //Handle cart and parts
46
+ addPart(part) {
47
+ const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);
48
+ if (productInCart) {
49
+ const partInCart = productInCart.parts.find(sp => sp.id === part.ID);
50
+ console.log(partInCart);
51
+ if (partInCart) {
52
+ partInCart.amount++;
53
+ productInCart.parts = [...productInCart.parts];
54
+ }
55
+ else {
56
+ productInCart.parts = [...productInCart.parts, { id: part.ID, amount: 1, price: part.price, name: part.post_title }];
57
+ }
58
+ state.cart = [...state.cart.filter(p => p.id !== productInCart.id), productInCart];
59
+ }
60
+ }
61
+ removePart(part) {
62
+ const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);
63
+ if (productInCart) {
64
+ const partInCart = productInCart.parts.find(sp => sp.id === part.ID);
65
+ if (partInCart && partInCart.amount > 1) {
66
+ partInCart.amount--;
67
+ productInCart.parts = [...productInCart.parts];
68
+ }
69
+ else {
70
+ productInCart.parts = productInCart.parts.filter(sp => sp.id !== part.ID);
71
+ }
72
+ state.cart = [...state.cart.filter(p => p.id !== productInCart.id), productInCart];
73
+ }
74
+ }
75
+ goToCart() {
76
+ const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);
77
+ if (productInCart) {
78
+ state.step = 5;
79
+ }
80
+ }
81
+ getAmount() {
82
+ var _a;
83
+ return ((_a = state.cart.find(p => p.id === state.selectedProduct.ID)) === null || _a === void 0 ? void 0 : _a.amount) || 0;
84
+ }
85
+ getPartAmount(partId) {
86
+ var _a;
87
+ const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);
88
+ return ((_a = productInCart === null || productInCart === void 0 ? void 0 : productInCart.parts.find(sp => sp.id === partId)) === null || _a === void 0 ? void 0 : _a.amount) || 0;
89
+ }
90
+ getTotalPrice() {
91
+ let price = 0;
92
+ const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);
93
+ if (productInCart) {
94
+ const partsPrice = productInCart.parts.reduce((acc, curr) => {
95
+ const part = state.selectedProduct.parts.find(p => p.ID === curr.id);
96
+ if (part) {
97
+ return acc + part.price * curr.amount;
98
+ }
99
+ return acc;
100
+ }, 0);
101
+ price = state.selectedProduct.price * productInCart.amount + partsPrice;
102
+ }
103
+ else {
104
+ price = state.selectedProduct.price;
105
+ }
106
+ return getProductPrice(state.selectedProduct, price);
107
+ }
108
+ render() {
109
+ var _a, _b;
110
+ const checked = getAssetPath(`./assets/checked.svg`);
111
+ const plus = getAssetPath(`./assets/plus.svg`);
112
+ const minus = getAssetPath(`./assets/minus.svg`);
113
+ console.log(state.selectedProduct);
114
+ return (h("div", { class: "hemfixarna_product" }, h("div", { class: "hemfixarna_product--top" }, state.selectedProduct.icon && h("img", { width: 80, src: state.selectedProduct.icon, alt: state.selectedProduct.post_title }), h("div", null, h("h1", null, state.selectedProduct.post_title), h("h2", null, "Fr\u00E5n: ", getProductPrice(state.selectedProduct), " kr"))), h("div", { class: "hemfixarna_product--grid" }, h("div", { class: "hemfixarna_product--left" }, ((_a = state.selectedProduct.list) === null || _a === void 0 ? void 0 : _a.length) && (h("ul", { class: "hemfixarna_features" }, state.selectedProduct.list.map(l => (h("li", { key: l.bullet }, h("img", { src: checked, alt: "checked" }), h("p", null, l.bullet)))))), h("p", { class: "hemfixarna_terms" }, h("strong", null, "OBS! "), h("span", { innerHTML: state.selectedProduct.terms }))), h("div", { class: "hemfixarna_product--right" }, h("ul", null, h("li", { class: "hemfixarna_product--item" }, h("div", null, h("p", null, "Antal ", state.selectedProduct.post_title), h("p", { class: "hemfixarna_product--price" }, getProductPrice(state.selectedProduct), "kr/st")), h("div", { class: "hemfixarna_counter" }, h("img", { class: `${this.getAmount() === 0 ? 'disabled' : ''}`, src: minus, onClick: () => this.removeProduct() }), h("span", null, this.getAmount()), h("img", { src: plus, onClick: () => this.addProduct() }))), ((_b = state.selectedProduct.parts) === null || _b === void 0 ? void 0 : _b.length) &&
115
+ state.selectedProduct.parts.map(p => (h("li", { class: "hemfixarna_part" }, h("div", null, h("p", null, p.post_title), h("p", { class: "hemfixarna_product--price" }, getPartPrice(p, state.selectedProduct), "kr/st")), h("div", { class: "hemfixarna_counter" }, h("img", { class: `${this.getPartAmount(p.ID) === 0 ? 'disabled' : ''}`, src: minus, onClick: () => this.removePart(p) }), h("span", null, this.getPartAmount(p.ID)), h("img", { class: `${this.getAmount() === 0 ? 'disabled' : ''}`, src: plus, onClick: () => this.addPart(p) })))))), h("h4", { class: "hemfixarna_product--total" }, "Totalt ", this.getTotalPrice(), " kr"), h("button", { onClick: () => this.goToCart(), class: `hemfixarna_buy ${this.getAmount() === 0 ? 'disabled' : ''}` }, "Boka"), state.options && h("hemfixarna-info", { list: state.options.trust })))));
116
+ }
117
+ };
118
+
119
+ export { HemfixarnaProduct as hemfixarna_product };
120
+
121
+ //# sourceMappingURL=hemfixarna-product.entry.js.map
@@ -0,0 +1 @@
1
+ {"file":"hemfixarna-product.entry.esm.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":[],"sourcesContent":[],"version":3}