hemfixarna-web-components 0.3.1 → 0.9.2

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 (156) hide show
  1. package/dist/cjs/hemfixarna-address_16.cjs.entry.js +1753 -0
  2. package/dist/cjs/hemfixarna-address_16.cjs.entry.js.map +1 -0
  3. package/dist/cjs/hemfixarna-components.cjs.js +28 -0
  4. package/dist/cjs/hemfixarna-components.cjs.js.map +1 -0
  5. package/dist/cjs/index-d9e286dc.js +1652 -0
  6. package/dist/cjs/index-d9e286dc.js.map +1 -0
  7. package/dist/cjs/index.cjs.js +4 -0
  8. package/dist/cjs/index.cjs.js.map +1 -0
  9. package/dist/cjs/loader.cjs.js +24 -0
  10. package/dist/cjs/loader.cjs.js.map +1 -0
  11. package/dist/collection/assets/back.svg +3 -0
  12. package/dist/collection/assets/cart.svg +10 -0
  13. package/dist/collection/assets/checked.svg +10 -0
  14. package/dist/collection/assets/close.svg +5 -0
  15. package/dist/collection/assets/copy.png +0 -0
  16. package/dist/collection/assets/date.svg +6 -0
  17. package/dist/collection/assets/down.svg +3 -0
  18. package/dist/collection/assets/hemfixarna.svg +11 -0
  19. package/dist/collection/assets/info.svg +5 -0
  20. package/dist/collection/assets/minus.svg +4 -0
  21. package/dist/collection/assets/plus.svg +5 -0
  22. package/dist/collection/collection-manifest.json +27 -0
  23. package/dist/collection/components/hemfixarna-address/hemfixarna-address.js +67 -0
  24. package/dist/collection/components/hemfixarna-address/hemfixarna-address.js.map +1 -0
  25. package/dist/collection/components/hemfixarna-box/hemfixarna-box.js +97 -0
  26. package/dist/collection/components/hemfixarna-box/hemfixarna-box.js.map +1 -0
  27. package/dist/{hemfixarna-components/hemfixarna-breadcrumbs.entry.js → collection/components/hemfixarna-breadcrumbs/hemfixarna-breadcrumbs.js} +46 -11
  28. package/dist/collection/components/hemfixarna-breadcrumbs/hemfixarna-breadcrumbs.js.map +1 -0
  29. package/dist/collection/components/hemfixarna-byggmax/hemfixarna-byggmax.css +0 -0
  30. package/dist/collection/components/hemfixarna-byggmax/hemfixarna-byggmax.js +50 -0
  31. package/dist/collection/components/hemfixarna-byggmax/hemfixarna-byggmax.js.map +1 -0
  32. package/dist/collection/components/hemfixarna-cart/hemfixarna-cart.js +41 -0
  33. package/dist/collection/components/hemfixarna-cart/hemfixarna-cart.js.map +1 -0
  34. package/dist/collection/components/hemfixarna-category.tsx/hemfixarna-category.js +18 -0
  35. package/dist/collection/components/hemfixarna-category.tsx/hemfixarna-category.js.map +1 -0
  36. package/dist/collection/components/hemfixarna-checkout/hemfixarna-checkout.js +92 -0
  37. package/dist/collection/components/hemfixarna-checkout/hemfixarna-checkout.js.map +1 -0
  38. package/dist/collection/components/hemfixarna-component/hemfixarna-component.js +221 -0
  39. package/dist/collection/components/hemfixarna-component/hemfixarna-component.js.map +1 -0
  40. package/dist/collection/components/hemfixarna-component/hemfixarna.css +752 -0
  41. package/dist/collection/components/hemfixarna-demo/hemfixarna-demo.css +118 -0
  42. package/dist/collection/components/hemfixarna-demo/hemfixarna-demo.js +76 -0
  43. package/dist/collection/components/hemfixarna-demo/hemfixarna-demo.js.map +1 -0
  44. package/dist/collection/components/hemfixarna-getuser/hemfixarna-getuser.js +84 -0
  45. package/dist/collection/components/hemfixarna-getuser/hemfixarna-getuser.js.map +1 -0
  46. package/dist/{hemfixarna-components/hemfixarna-info.entry.js → collection/components/hemfixarna-info/hemfixarna-info.js} +27 -11
  47. package/dist/collection/components/hemfixarna-info/hemfixarna-info.js.map +1 -0
  48. package/dist/collection/components/hemfixarna-order/hemfixarna-order.js +50 -0
  49. package/dist/collection/components/hemfixarna-order/hemfixarna-order.js.map +1 -0
  50. package/dist/collection/components/hemfixarna-orderrows/hemfixarna-orderrows.js +80 -0
  51. package/dist/collection/components/hemfixarna-orderrows/hemfixarna-orderrows.js.map +1 -0
  52. package/dist/{hemfixarna-components/hemfixarna-product.entry.js → collection/components/hemfixarna-product/hemfixarna-product.js} +15 -16
  53. package/dist/collection/components/hemfixarna-product/hemfixarna-product.js.map +1 -0
  54. package/dist/collection/components/hemfixarna-service/hemfixarna-service.js +18 -0
  55. package/dist/collection/components/hemfixarna-service/hemfixarna-service.js.map +1 -0
  56. package/dist/collection/components/hemfixarna-start/hemfixarna-start.js +41 -0
  57. package/dist/collection/components/hemfixarna-start/hemfixarna-start.js.map +1 -0
  58. package/dist/collection/index.js +2 -0
  59. package/dist/collection/index.js.map +1 -0
  60. package/dist/collection/store/index.js +25 -0
  61. package/dist/collection/store/index.js.map +1 -0
  62. package/dist/{hemfixarna-components/index-2bf8566c.js → collection/types/index.js} +3 -6
  63. package/dist/collection/types/index.js.map +1 -0
  64. package/dist/collection/utils/api.js +41 -0
  65. package/dist/collection/utils/api.js.map +1 -0
  66. package/dist/{hemfixarna-components/calc-a9ece205.js → collection/utils/calc.js} +36 -6
  67. package/dist/collection/utils/calc.js.map +1 -0
  68. package/dist/collection/utils/creditSafe.js +18 -0
  69. package/dist/collection/utils/creditSafe.js.map +1 -0
  70. package/dist/collection/utils/felixFunctions.js +189 -0
  71. package/dist/collection/utils/felixFunctions.js.map +1 -0
  72. package/dist/collection/utils/form.js +7 -0
  73. package/dist/collection/utils/form.js.map +1 -0
  74. package/dist/esm/hemfixarna-address_16.entry.js +1734 -0
  75. package/dist/esm/hemfixarna-address_16.entry.js.map +1 -0
  76. package/dist/esm/hemfixarna-components.js +23 -0
  77. package/dist/esm/hemfixarna-components.js.map +1 -0
  78. package/dist/esm/index-ca1aada9.js +1621 -0
  79. package/dist/esm/index-ca1aada9.js.map +1 -0
  80. package/dist/esm/index.js +3 -0
  81. package/dist/esm/index.js.map +1 -0
  82. package/dist/esm/loader.js +20 -0
  83. package/dist/esm/loader.js.map +1 -0
  84. package/dist/esm/polyfills/core-js.js +11 -0
  85. package/dist/esm/polyfills/css-shim.js +1 -0
  86. package/dist/esm/polyfills/dom.js +79 -0
  87. package/dist/esm/polyfills/es5-html-element.js +1 -0
  88. package/dist/esm/polyfills/index.js +34 -0
  89. package/dist/esm/polyfills/system.js +6 -0
  90. package/dist/hemfixarna-components/hemfixarna-components.esm.js +1 -162
  91. package/dist/hemfixarna-components/hemfixarna-components.esm.js.map +1 -1
  92. package/dist/hemfixarna-components/index.esm.js +0 -1
  93. package/dist/hemfixarna-components/index.esm.js.map +1 -1
  94. package/dist/hemfixarna-components/p-8829e98e.js +3 -0
  95. package/dist/hemfixarna-components/p-8829e98e.js.map +1 -0
  96. package/dist/hemfixarna-components/p-c05e2af1.entry.js +2 -0
  97. package/dist/hemfixarna-components/p-c05e2af1.entry.js.map +1 -0
  98. package/dist/index.cjs.js +1 -0
  99. package/dist/index.js +1 -0
  100. package/dist/types/components/hemfixarna-address/hemfixarna-address.d.ts +1 -0
  101. package/dist/types/components/hemfixarna-cart/hemfixarna-cart.d.ts +1 -9
  102. package/dist/types/components/hemfixarna-checkout/hemfixarna-checkout.d.ts +3 -1
  103. package/dist/types/components/hemfixarna-getuser/hemfixarna-getuser.d.ts +1 -1
  104. package/dist/types/components/hemfixarna-order/hemfixarna-order.d.ts +3 -0
  105. package/dist/types/components/hemfixarna-orderrows/hemfixarna-orderrows.d.ts +8 -0
  106. package/dist/types/components.d.ts +19 -0
  107. package/dist/types/store/index.d.ts +2 -6
  108. package/dist/types/types/index.d.ts +18 -7
  109. package/dist/types/utils/api.d.ts +20 -2
  110. package/dist/types/utils/calc.d.ts +5 -1
  111. package/dist/types/utils/creditSafe.d.ts +3 -0
  112. package/dist/types/utils/form.d.ts +2 -0
  113. package/package.json +2 -1
  114. package/dist/hemfixarna-components/api-3228fe30.js +0 -28
  115. package/dist/hemfixarna-components/api-3228fe30.js.map +0 -1
  116. package/dist/hemfixarna-components/app-globals-0f993ce5.js +0 -5
  117. package/dist/hemfixarna-components/app-globals-0f993ce5.js.map +0 -1
  118. package/dist/hemfixarna-components/calc-a9ece205.js.map +0 -1
  119. package/dist/hemfixarna-components/css-shim-62d2171c.js +0 -6
  120. package/dist/hemfixarna-components/css-shim-62d2171c.js.map +0 -1
  121. package/dist/hemfixarna-components/dom-46a68c9b.js +0 -75
  122. package/dist/hemfixarna-components/dom-46a68c9b.js.map +0 -1
  123. package/dist/hemfixarna-components/hemfixarna-address.entry.js +0 -52
  124. package/dist/hemfixarna-components/hemfixarna-address.entry.js.map +0 -1
  125. package/dist/hemfixarna-components/hemfixarna-box.entry.js +0 -35
  126. package/dist/hemfixarna-components/hemfixarna-box.entry.js.map +0 -1
  127. package/dist/hemfixarna-components/hemfixarna-breadcrumbs.entry.js.map +0 -1
  128. package/dist/hemfixarna-components/hemfixarna-byggmax.entry.js +0 -20
  129. package/dist/hemfixarna-components/hemfixarna-byggmax.entry.js.map +0 -1
  130. package/dist/hemfixarna-components/hemfixarna-cart.entry.js +0 -82
  131. package/dist/hemfixarna-components/hemfixarna-cart.entry.js.map +0 -1
  132. package/dist/hemfixarna-components/hemfixarna-category.entry.js +0 -21
  133. package/dist/hemfixarna-components/hemfixarna-category.entry.js.map +0 -1
  134. package/dist/hemfixarna-components/hemfixarna-checkout.entry.js +0 -54
  135. package/dist/hemfixarna-components/hemfixarna-checkout.entry.js.map +0 -1
  136. package/dist/hemfixarna-components/hemfixarna-component.entry.js +0 -133
  137. package/dist/hemfixarna-components/hemfixarna-component.entry.js.map +0 -1
  138. package/dist/hemfixarna-components/hemfixarna-demo.entry.js +0 -65
  139. package/dist/hemfixarna-components/hemfixarna-demo.entry.js.map +0 -1
  140. package/dist/hemfixarna-components/hemfixarna-getuser.entry.js +0 -410
  141. package/dist/hemfixarna-components/hemfixarna-getuser.entry.js.map +0 -1
  142. package/dist/hemfixarna-components/hemfixarna-info.entry.js.map +0 -1
  143. package/dist/hemfixarna-components/hemfixarna-order.entry.js +0 -24
  144. package/dist/hemfixarna-components/hemfixarna-order.entry.js.map +0 -1
  145. package/dist/hemfixarna-components/hemfixarna-product.entry.js.map +0 -1
  146. package/dist/hemfixarna-components/hemfixarna-service.entry.js +0 -21
  147. package/dist/hemfixarna-components/hemfixarna-service.entry.js.map +0 -1
  148. package/dist/hemfixarna-components/hemfixarna-start.entry.js +0 -18
  149. package/dist/hemfixarna-components/hemfixarna-start.entry.js.map +0 -1
  150. package/dist/hemfixarna-components/index-2bf8566c.js.map +0 -1
  151. package/dist/hemfixarna-components/index-59ed730c.js +0 -3397
  152. package/dist/hemfixarna-components/index-59ed730c.js.map +0 -1
  153. package/dist/hemfixarna-components/index-75ed3bb8.js +0 -216
  154. package/dist/hemfixarna-components/index-75ed3bb8.js.map +0 -1
  155. package/dist/hemfixarna-components/shadow-css-05e0c1f4.js +0 -389
  156. package/dist/hemfixarna-components/shadow-css-05e0c1f4.js.map +0 -1
@@ -0,0 +1,1753 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const index = require('./index-d9e286dc.js');
6
+
7
+ const appendToMap = (map, propName, value) => {
8
+ const items = map.get(propName);
9
+ if (!items) {
10
+ map.set(propName, [value]);
11
+ }
12
+ else if (!items.includes(value)) {
13
+ items.push(value);
14
+ }
15
+ };
16
+ const debounce = (fn, ms) => {
17
+ let timeoutId;
18
+ return (...args) => {
19
+ if (timeoutId) {
20
+ clearTimeout(timeoutId);
21
+ }
22
+ timeoutId = setTimeout(() => {
23
+ timeoutId = 0;
24
+ fn(...args);
25
+ }, ms);
26
+ };
27
+ };
28
+
29
+ /**
30
+ * Check if a possible element isConnected.
31
+ * The property might not be there, so we check for it.
32
+ *
33
+ * We want it to return true if isConnected is not a property,
34
+ * otherwise we would remove these elements and would not update.
35
+ *
36
+ * Better leak in Edge than to be useless.
37
+ */
38
+ const isConnected = (maybeElement) => !('isConnected' in maybeElement) || maybeElement.isConnected;
39
+ const cleanupElements = debounce((map) => {
40
+ for (let key of map.keys()) {
41
+ map.set(key, map.get(key).filter(isConnected));
42
+ }
43
+ }, 2000);
44
+ const stencilSubscription = () => {
45
+ if (typeof index.getRenderingRef !== 'function') {
46
+ // If we are not in a stencil project, we do nothing.
47
+ // This function is not really exported by @stencil/core.
48
+ return {};
49
+ }
50
+ const elmsToUpdate = new Map();
51
+ return {
52
+ dispose: () => elmsToUpdate.clear(),
53
+ get: (propName) => {
54
+ const elm = index.getRenderingRef();
55
+ if (elm) {
56
+ appendToMap(elmsToUpdate, propName, elm);
57
+ }
58
+ },
59
+ set: (propName) => {
60
+ const elements = elmsToUpdate.get(propName);
61
+ if (elements) {
62
+ elmsToUpdate.set(propName, elements.filter(index.forceUpdate));
63
+ }
64
+ cleanupElements(elmsToUpdate);
65
+ },
66
+ reset: () => {
67
+ elmsToUpdate.forEach((elms) => elms.forEach(index.forceUpdate));
68
+ cleanupElements(elmsToUpdate);
69
+ },
70
+ };
71
+ };
72
+
73
+ const unwrap = (val) => (typeof val === 'function' ? val() : val);
74
+ const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) => {
75
+ const unwrappedState = unwrap(defaultState);
76
+ let states = new Map(Object.entries(unwrappedState !== null && unwrappedState !== void 0 ? unwrappedState : {}));
77
+ const handlers = {
78
+ dispose: [],
79
+ get: [],
80
+ set: [],
81
+ reset: [],
82
+ };
83
+ const reset = () => {
84
+ var _a;
85
+ // When resetting the state, the default state may be a function - unwrap it to invoke it.
86
+ // otherwise, the state won't be properly reset
87
+ states = new Map(Object.entries((_a = unwrap(defaultState)) !== null && _a !== void 0 ? _a : {}));
88
+ handlers.reset.forEach((cb) => cb());
89
+ };
90
+ const dispose = () => {
91
+ // Call first dispose as resetting the state would
92
+ // cause less updates ;)
93
+ handlers.dispose.forEach((cb) => cb());
94
+ reset();
95
+ };
96
+ const get = (propName) => {
97
+ handlers.get.forEach((cb) => cb(propName));
98
+ return states.get(propName);
99
+ };
100
+ const set = (propName, value) => {
101
+ const oldValue = states.get(propName);
102
+ if (shouldUpdate(value, oldValue, propName)) {
103
+ states.set(propName, value);
104
+ handlers.set.forEach((cb) => cb(propName, value, oldValue));
105
+ }
106
+ };
107
+ const state = (typeof Proxy === 'undefined'
108
+ ? {}
109
+ : new Proxy(unwrappedState, {
110
+ get(_, propName) {
111
+ return get(propName);
112
+ },
113
+ ownKeys(_) {
114
+ return Array.from(states.keys());
115
+ },
116
+ getOwnPropertyDescriptor() {
117
+ return {
118
+ enumerable: true,
119
+ configurable: true,
120
+ };
121
+ },
122
+ has(_, propName) {
123
+ return states.has(propName);
124
+ },
125
+ set(_, propName, value) {
126
+ set(propName, value);
127
+ return true;
128
+ },
129
+ }));
130
+ const on = (eventName, callback) => {
131
+ handlers[eventName].push(callback);
132
+ return () => {
133
+ removeFromArray(handlers[eventName], callback);
134
+ };
135
+ };
136
+ const onChange = (propName, cb) => {
137
+ const unSet = on('set', (key, newValue) => {
138
+ if (key === propName) {
139
+ cb(newValue);
140
+ }
141
+ });
142
+ // We need to unwrap the defaultState because it might be a function.
143
+ // Otherwise we might not be sending the right reset value.
144
+ const unReset = on('reset', () => cb(unwrap(defaultState)[propName]));
145
+ return () => {
146
+ unSet();
147
+ unReset();
148
+ };
149
+ };
150
+ const use = (...subscriptions) => {
151
+ const unsubs = subscriptions.reduce((unsubs, subscription) => {
152
+ if (subscription.set) {
153
+ unsubs.push(on('set', subscription.set));
154
+ }
155
+ if (subscription.get) {
156
+ unsubs.push(on('get', subscription.get));
157
+ }
158
+ if (subscription.reset) {
159
+ unsubs.push(on('reset', subscription.reset));
160
+ }
161
+ if (subscription.dispose) {
162
+ unsubs.push(on('dispose', subscription.dispose));
163
+ }
164
+ return unsubs;
165
+ }, []);
166
+ return () => unsubs.forEach((unsub) => unsub());
167
+ };
168
+ const forceUpdate = (key) => {
169
+ const oldValue = states.get(key);
170
+ handlers.set.forEach((cb) => cb(key, oldValue, oldValue));
171
+ };
172
+ return {
173
+ state,
174
+ get,
175
+ set,
176
+ on,
177
+ onChange,
178
+ use,
179
+ dispose,
180
+ reset,
181
+ forceUpdate,
182
+ };
183
+ };
184
+ const removeFromArray = (array, item) => {
185
+ const index = array.indexOf(item);
186
+ if (index >= 0) {
187
+ array[index] = array[array.length - 1];
188
+ array.length--;
189
+ }
190
+ };
191
+
192
+ const createStore = (defaultState, shouldUpdate) => {
193
+ const map = createObservableMap(defaultState, shouldUpdate);
194
+ map.use(stencilSubscription());
195
+ return map;
196
+ };
197
+
198
+ const { state, onChange, } = createStore({
199
+ step: 1,
200
+ checkoutStep: 1,
201
+ checkoutEdit: false,
202
+ selectedCategory: null,
203
+ selectedService: null,
204
+ selectedProduct: null,
205
+ cart: [],
206
+ business: 'undefined',
207
+ options: null,
208
+ rut: true,
209
+ rot: true,
210
+ token: null,
211
+ user: null,
212
+ modal: null,
213
+ });
214
+ onChange('cart', cart => {
215
+ window.sessionStorage.setItem(`hemfixarna-${state.business}-cart`, JSON.stringify(cart));
216
+ });
217
+ onChange('user', user => {
218
+ window.sessionStorage.setItem(`hemfixarna-${state.business}-user`, JSON.stringify(user));
219
+ });
220
+
221
+ const hideField = (field) => {
222
+ return field.split(' ').reduce((acc, curr) => {
223
+ return curr.length < 2 ? curr : acc + curr.slice(0, 1) + '*'.repeat(curr.length - 2) + curr.slice(curr.length - 1, curr.length) + ' ';
224
+ }, '');
225
+ };
226
+
227
+ const HemfixarnaAddress = class {
228
+ constructor(hostRef) {
229
+ index.registerInstance(this, hostRef);
230
+ this.handleSubmit = (e) => {
231
+ e.preventDefault();
232
+ const streetValid = this.street.length > 0;
233
+ if (!streetValid) {
234
+ this.streetError = 'Ange en gatuadress';
235
+ }
236
+ const zipValid = this.zip.length > 0;
237
+ if (!zipValid) {
238
+ this.zipError = 'Ange ett postnummer';
239
+ }
240
+ const townValid = this.town.length > 0;
241
+ if (!townValid) {
242
+ this.townError = 'Ange en ort';
243
+ }
244
+ if (streetValid && zipValid && townValid) {
245
+ state.user = Object.assign(Object.assign({}, state.user), { street: this.street, zip: this.zip, town: this.town });
246
+ state.checkoutStep = 2;
247
+ state.checkoutEdit = false;
248
+ }
249
+ };
250
+ this.handleChangeStreet = (e) => {
251
+ this.streetError = null;
252
+ this.street = this.street === state.user.street ? '' : e.target.value;
253
+ };
254
+ this.handleChangeZip = (e) => {
255
+ this.zipError = null;
256
+ this.zip = this.zip === state.user.zip ? '' : e.target.value;
257
+ };
258
+ this.handleChangeTown = (e) => {
259
+ this.townError = null;
260
+ this.town = this.town === state.user.town ? '' : e.target.value;
261
+ };
262
+ this.render = () => {
263
+ return (index.h("form", { class: "hemfixarna_address", onSubmit: e => this.handleSubmit(e) }, index.h("div", null, index.h("input", { class: `${this.street.length ? 'input_active' : ''}`, onInput: this.handleChangeStreet, type: "text", name: "street", value: this.street === state.user.street ? hideField(this.street) : this.street }), index.h("label", { htmlFor: "street" }, "Gatuaddress ")), this.streetError && index.h("span", null, this.streetError), index.h("div", null, index.h("input", { class: `${this.zip.length ? 'input_active' : ''}`, onInput: this.handleChangeZip, type: "tel", name: "zip", value: this.zip === state.user.zip ? hideField(this.zip) : this.zip }), index.h("label", { htmlFor: "zip" }, "Postnummer ")), this.zipError && index.h("span", null, this.zipError), index.h("div", null, index.h("input", { class: `${this.town.length ? 'input_active' : ''}`, onInput: this.handleChangeTown, type: "text", name: "town", value: this.town === state.user.town ? hideField(this.town) : this.town }), index.h("label", { htmlFor: "town" }, "Ort ")), this.townError && index.h("span", null, this.townError), index.h("input", { type: "submit", value: "Forts\u00E4tt och Boka" })));
264
+ };
265
+ this.street = '';
266
+ this.streetError = null;
267
+ this.zip = '';
268
+ this.zipError = null;
269
+ this.town = '';
270
+ this.townError = null;
271
+ }
272
+ componentWillLoad() {
273
+ if (state.user) {
274
+ this.street = state.user.street;
275
+ this.zip = state.user.zip;
276
+ this.town = state.user.town;
277
+ }
278
+ }
279
+ };
280
+
281
+ const getRutPrice = (price) => {
282
+ return Math.ceil(price / 2);
283
+ };
284
+ const getRotPrice = (price) => {
285
+ return Math.ceil(price * 0.7);
286
+ };
287
+ const getProductPrice = (product, price, amount = 1) => {
288
+ if (product.rot && state.rot) {
289
+ return getRotPrice((price || product.price) * amount);
290
+ }
291
+ else if (product.rut && state.rut) {
292
+ return getRutPrice((price || product.price) * amount);
293
+ }
294
+ else {
295
+ return (price || product.price) * amount;
296
+ }
297
+ };
298
+ const getProductPriceWithRotAndRut = (product) => {
299
+ if (product.rot) {
300
+ return getRotPrice(product.price);
301
+ }
302
+ else if (product.rut && state.rut) {
303
+ return getRutPrice(product.price);
304
+ }
305
+ else {
306
+ return product.price;
307
+ }
308
+ };
309
+ const getPartPrice = (part, product, amount = 1) => {
310
+ if (product.rot && state.rot) {
311
+ return getRotPrice(part.price * amount);
312
+ }
313
+ else if (product.rut && state.rut) {
314
+ return getRutPrice(part.price * amount);
315
+ }
316
+ else {
317
+ return part.price * amount;
318
+ }
319
+ };
320
+ const getStartFee = () => {
321
+ if (!state.cart)
322
+ return { rut: 0, rot: 0 };
323
+ const hasRut = state.cart.some(item => item.rut && item.start_fee);
324
+ const hasRot = state.cart.some(item => item.rot && item.start_fee);
325
+ const rutPrice = state.rut ? getRutPrice(state.options.start_fee) : state.options.start_fee * 1;
326
+ const rotPrice = state.rot ? getRotPrice(state.options.start_fee) : state.options.start_fee * 1;
327
+ if (hasRut && hasRot) {
328
+ return { rut: rutPrice, rot: rotPrice, length: 2 };
329
+ }
330
+ else if (hasRut) {
331
+ return { rut: rutPrice, rot: 0, length: 1 };
332
+ }
333
+ else if (hasRot) {
334
+ return { rut: 0, rot: rotPrice, length: 1 };
335
+ }
336
+ else {
337
+ return { rut: 0, rot: 0, length: 0 };
338
+ }
339
+ };
340
+ const getItemPrice = (item) => {
341
+ const partsPrice = item.parts.reduce((acc, curr) => {
342
+ return acc + curr.price * curr.amount;
343
+ }, 0);
344
+ return getProductPrice(item, item.price * item.amount + partsPrice);
345
+ };
346
+ const calculateRot = () => {
347
+ const totalWithRot = state.cart.reduce((acc, curr) => {
348
+ return curr.rot ? acc + getItemPrice(curr) : acc;
349
+ }, 0) + getStartFee().rot;
350
+ const totalWithoutRot = state.cart.reduce((acc, curr) => {
351
+ const partsPrice = curr.parts.reduce((acc, curr) => {
352
+ return acc + curr.price * curr.amount;
353
+ }, 0);
354
+ return curr.rot ? acc + curr.price * curr.amount + partsPrice : acc;
355
+ }, 0) + Number(state.options.start_fee);
356
+ return totalWithoutRot - totalWithRot;
357
+ };
358
+ const calculateRut = () => {
359
+ const totalWithRut = state.cart.reduce((acc, curr) => {
360
+ return curr.rut ? acc + getItemPrice(curr) : acc;
361
+ }, 0) + getStartFee().rut;
362
+ const totalWithoutRut = state.cart.reduce((acc, curr) => {
363
+ const partsPrice = curr.parts.reduce((acc, curr) => {
364
+ return acc + curr.price * curr.amount;
365
+ }, 0);
366
+ return curr.rut ? acc + curr.price * curr.amount + partsPrice : acc;
367
+ }, 0) + Number(state.options.start_fee);
368
+ return totalWithoutRut - totalWithRut;
369
+ };
370
+ const getTotalPrice = () => {
371
+ return state.cart.reduce((acc, curr) => acc + getItemPrice(curr), 0) + getStartFee().rot + getStartFee().rut;
372
+ };
373
+
374
+ const HemfixarnaBox = class {
375
+ constructor(hostRef) {
376
+ index.registerInstance(this, hostRef);
377
+ this.post = undefined;
378
+ this.icon = undefined;
379
+ this.postTitle = undefined;
380
+ }
381
+ setTaxonomy(taxonomy) {
382
+ if (taxonomy) {
383
+ if ((taxonomy === null || taxonomy === void 0 ? void 0 : taxonomy.taxonomy) === 'service_cat') {
384
+ state.selectedCategory = taxonomy;
385
+ state.step = 2;
386
+ }
387
+ else if ((taxonomy === null || taxonomy === void 0 ? void 0 : taxonomy.post_type) === 'service') {
388
+ state.selectedService = taxonomy;
389
+ state.step = 3;
390
+ }
391
+ else if ((taxonomy === null || taxonomy === void 0 ? void 0 : taxonomy.post_type) === 'ikea_product') {
392
+ state.selectedProduct = taxonomy;
393
+ state.step = 4;
394
+ }
395
+ }
396
+ }
397
+ render() {
398
+ return (index.h("li", { onClick: () => this.setTaxonomy(this.post) }, this.post.icon && index.h("img", { class: "hemfixarna_logo", height: 82, src: this.icon, alt: this.postTitle }), index.h("div", null, index.h("p", null, this.postTitle), state.step === 3 && index.h("p", { class: "price" }, "Fr\u00E5n ", getProductPrice(this.post), "kr"))));
399
+ }
400
+ };
401
+
402
+ const HemfixarnaBreadcrumbs = class {
403
+ constructor(hostRef) {
404
+ index.registerInstance(this, hostRef);
405
+ this.tree = undefined;
406
+ this.closeModal = undefined;
407
+ }
408
+ getCartLength() {
409
+ return state.cart.reduce((acc, curr) => acc + curr.amount, 0);
410
+ }
411
+ handleCartClick() {
412
+ var _a;
413
+ if ((_a = state.cart) === null || _a === void 0 ? void 0 : _a.length) {
414
+ state.step = 5;
415
+ }
416
+ }
417
+ handleHomePageClick() {
418
+ state.step = 1;
419
+ setTimeout(() => {
420
+ state.selectedCategory = null;
421
+ state.selectedProduct = null;
422
+ state.selectedService = null;
423
+ }, 200);
424
+ }
425
+ render() {
426
+ const logo = index.getAssetPath(`./assets/hemfixarna.svg`);
427
+ const close = index.getAssetPath(`./assets/close.svg`);
428
+ const cart = index.getAssetPath(`./assets/cart.svg`);
429
+ const back = index.getAssetPath(`./assets/back.svg`);
430
+ return (index.h("div", null, index.h("div", { class: "hemfixarna_crumbs" }, index.h("div", { class: "hemfixarna_crumbs--links" }, index.h("img", { onClick: () => this.handleHomePageClick(), src: logo, width: 110 }), index.h("img", { onClick: () => this.closeModal(), class: "close", src: close, width: 32 }), index.h("div", null, index.h("button", { onClick: () => this.handleHomePageClick() }, "Alla tj\u00E4nster"))), index.h("div", { onClick: () => this.handleCartClick(), class: `cart ${this.getCartLength() > 0 ? 'cart_active' : ''}` }, index.h("img", { src: cart, width: 24 }), index.h("span", null, this.getCartLength()))), [3, 4].includes(state.step) && (index.h("button", { class: "hemfixarna_crumbs--back", onClick: () => {
431
+ state.step = state.step === 4 ? 3 : 2;
432
+ } }, index.h("img", { width: 24, src: back, alt: "back arrow" }), index.h("span", null, "Se allt ", state.step === 4 ? state.selectedService.post_title : state.selectedCategory.name)))));
433
+ }
434
+ };
435
+
436
+ var Business;
437
+ (function (Business) {
438
+ Business["byggmax"] = "byggmax";
439
+ })(Business || (Business = {}));
440
+ var TopCategory;
441
+ (function (TopCategory) {
442
+ TopCategory["byggmax"] = "category/bygg";
443
+ })(TopCategory || (TopCategory = {}));
444
+
445
+ const hemfixarnaByggmaxCss = "";
446
+
447
+ const MyComponent$1 = class {
448
+ constructor(hostRef) {
449
+ index.registerInstance(this, hostRef);
450
+ this.tree = null;
451
+ this.slug = undefined;
452
+ }
453
+ render() {
454
+ return index.h("hemfixarna-component", { slug: this.slug, business: Business.byggmax, topCategory: TopCategory.byggmax });
455
+ }
456
+ };
457
+ MyComponent$1.style = hemfixarnaByggmaxCss;
458
+
459
+ const HemfixarnaCart = class {
460
+ constructor(hostRef) {
461
+ index.registerInstance(this, hostRef);
462
+ this.tree = undefined;
463
+ }
464
+ render() {
465
+ const back = index.getAssetPath(`./assets/back.svg`);
466
+ return (index.h("div", { class: "hemfixarna_cart" }, index.h("div", { class: "hemfixarna_cart--left" }, index.h("h2", null, state.checkoutStep === 2 && !state.checkoutEdit && (index.h("button", { onClick: () => {
467
+ state.checkoutStep = 1;
468
+ } }, index.h("img", { width: 24, src: back, alt: "back arrow" }))), "Din bokning"), index.h("hemfixarna-orderrows", { tree: this.tree })), index.h("div", { class: "hemfixarna_cart--right" }, index.h("h2", null, state.checkoutStep === 2 && !state.checkoutEdit && (index.h("button", { onClick: () => {
469
+ state.checkoutStep = 1;
470
+ } }, index.h("img", { width: 24, src: back, alt: "back arrow" }))), "Dina uppgifter"), index.h("hemfixarna-checkout", null), index.h("hemfixarna-info", null))));
471
+ }
472
+ };
473
+
474
+ const HemfixarnaCategory = class {
475
+ constructor(hostRef) {
476
+ index.registerInstance(this, hostRef);
477
+ }
478
+ setSelectedService(service) {
479
+ state.selectedService = service;
480
+ state.step = 3;
481
+ }
482
+ render() {
483
+ return (index.h("div", null, index.h("h2", null, state.selectedCategory.name), index.h("div", { class: "hemfixarna_categories--wrapper" }, index.h("div", null, index.h("ul", { class: "hemfixarna_categories" }, state.selectedCategory.services
484
+ .sort((a, b) => (a.post_title < b.post_title ? -1 : 1))
485
+ .map(s => {
486
+ var _a;
487
+ return (index.h("hemfixarna-box", { post: s, icon: (_a = s.icon.url) !== null && _a !== void 0 ? _a : s.icon, postTitle: s.post_title }));
488
+ }))), index.h("hemfixarna-info", { list: state.options.trust }))));
489
+ }
490
+ };
491
+
492
+ const base = `${"http://hemfixare.se.test"}/wp-json/headless` ;
493
+ const getTaxonomy = async (endpoint) => {
494
+ if (!endpoint) {
495
+ return;
496
+ }
497
+ const type = endpoint.split('/')[0];
498
+ const slug = endpoint.split('/')[1];
499
+ try {
500
+ const res = await fetch(`${base}/${type}/${slug}`);
501
+ return await res.json();
502
+ }
503
+ catch (error) {
504
+ console.log(error);
505
+ }
506
+ };
507
+ const getOptions = async () => {
508
+ try {
509
+ const res = await fetch(`${base}/webcoptions`);
510
+ return (await res.json());
511
+ }
512
+ catch (error) {
513
+ console.log(error);
514
+ }
515
+ };
516
+ const postOrder = async (data) => {
517
+ try {
518
+ const res = await fetch(`${base}/weborder`, {
519
+ method: 'POST',
520
+ body: JSON.stringify(data),
521
+ headers: {
522
+ 'Content-Type': 'application/json',
523
+ },
524
+ });
525
+ return (await res.json());
526
+ }
527
+ catch (error) {
528
+ console.log(error);
529
+ }
530
+ };
531
+
532
+ const HemfixarnaCheckout = class {
533
+ constructor(hostRef) {
534
+ index.registerInstance(this, hostRef);
535
+ this.handleChangeDate = (e) => {
536
+ this.dateError = null;
537
+ this.date = e.target.value;
538
+ };
539
+ this.handleChangeTerms = () => {
540
+ this.generalError = null;
541
+ };
542
+ this.sendOrder = async () => {
543
+ // Test order post (remove later)
544
+ const order = {
545
+ name: state.user.firstName + ' ' + state.user.lastName,
546
+ customer: state.business,
547
+ phone: state.user.phone,
548
+ social_security_number: state.user.ssn,
549
+ email: state.user.email,
550
+ address: `${state.user.street} | ${state.user.zip} | ${state.user.town}`,
551
+ earliest_visit_date: this.date,
552
+ order_items: JSON.stringify(state.cart.map(item => `${item.amount}st ${item.name} ${getProductPrice(item, item.price, item.amount)}kr ${item.parts.length ? `| ${item.parts.map(part => `${part.amount}st ${part.name} ${getPartPrice(part, item, part.amount)}kr`).join(' | ')} ` : ''} ${item.rot && state.rot ? '(med rot)' : state.rut && item.rut ? '(med rut)' : '(utan rut/rot)'}`)),
553
+ start_fee: `${getStartFee().rut > 0 ? `Rut: ${getStartFee().rut}kr` : 'Rut: 0'} ` + `${getStartFee().rot > 0 ? `Rot: ${getStartFee().rot}kr` : 'Rot: 0'}`,
554
+ total: getTotalPrice(),
555
+ };
556
+ try {
557
+ const { data: orderConfirm, status } = await postOrder(order);
558
+ if (orderConfirm && status && status === 200) {
559
+ state.step = 6;
560
+ }
561
+ else {
562
+ this.generalError = 'Något gick fel, försök igen senare';
563
+ }
564
+ }
565
+ catch (_) {
566
+ this.generalError = 'Något gick fel, försök igen senare';
567
+ }
568
+ };
569
+ this.handleSubmit = (e) => {
570
+ e.preventDefault();
571
+ this.generalError = null;
572
+ const validDate = this.date.length > 0;
573
+ if (!validDate) {
574
+ this.dateError = 'Ange ett giltigt datum';
575
+ }
576
+ const checkBoxes = Array.from(this.el.querySelectorAll('input[type="checkbox"]'));
577
+ const notValidTerms = checkBoxes.find(i => !i.checked);
578
+ if (notValidTerms) {
579
+ this.generalError = 'Du måste godkänna villkoren';
580
+ }
581
+ if (validDate && !notValidTerms) {
582
+ this.sendOrder();
583
+ }
584
+ };
585
+ this.render = () => {
586
+ const dateLogo = index.getAssetPath(`./assets/date.svg`);
587
+ const down = index.getAssetPath(`./assets/down.svg`);
588
+ if (state.checkoutEdit) {
589
+ return index.h("hemfixarna-address", null);
590
+ }
591
+ else if (state.checkoutStep === 1) {
592
+ return index.h("hemfixarna-getuser", null);
593
+ }
594
+ else if (state.checkoutStep === 2) {
595
+ return (index.h("div", { class: "mb-2" }, index.h("div", { class: "hemfixarna_addressinfo" }, index.h("div", null, index.h("p", null, hideField(state.user.firstName)), index.h("p", null, hideField(state.user.lastName)), index.h("p", null, state.user.email), index.h("p", null, state.user.phone)), index.h("div", null, index.h("p", null, hideField(state.user.street)), index.h("p", null, hideField(state.user.zip)), index.h("p", null, hideField(state.user.town))), index.h("button", { onClick: () => (state.checkoutEdit = true) }, "Beh\u00F6ver du \u00E4ndra adressen?")), index.h("form", { onSubmit: e => this.handleSubmit(e) }, index.h("div", null, index.h("img", { src: dateLogo, width: 24 }), index.h("input", { class: `${this.date.length ? 'input_active' : ''}`, min: new Date().toISOString().split('T')[0], onChange: e => this.handleChangeDate(e), type: "date", name: "date", value: this.date }), index.h("label", { htmlFor: "date" }, "Tidigaste datum f\u00F6r hembes\u00F6k"), index.h("img", { src: down, width: 24 })), this.dateError && index.h("span", null, this.dateError), index.h("label", { class: "hemfixarna_checkbox" }, index.h("input", { onChange: () => this.handleChangeTerms(), type: "checkbox" }), index.h("span", { innerHTML: state.options.terms })), state.cart
596
+ .filter(i => i.terms_checkout && i.terms_show_checkbox)
597
+ .map(item => (index.h(index.Fragment, null, index.h("label", { class: "hemfixarna_checkbox" }, index.h("input", { onChange: () => this.handleChangeTerms(), type: "checkbox" }), index.h("span", null, item.terms_checkout))))), this.generalError && index.h("span", null, this.generalError), index.h("input", { type: "submit", value: "Slutf\u00F6r Bokning" }))));
598
+ }
599
+ };
600
+ this.date = '';
601
+ this.dateError = null;
602
+ this.generalError = null;
603
+ }
604
+ componentWillLoad() {
605
+ if (Boolean(state.user && state.user.street)) {
606
+ state.checkoutStep = 2;
607
+ }
608
+ }
609
+ get el() { return index.getElement(this); }
610
+ };
611
+
612
+ const hemfixarnaCss = "@import url(\"https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600&display=swap\"); *{box-sizing:border-box}:host{font-family:\"Inter\", sans-serif}:host .mb-2{margin-bottom:2rem}:host form{display:flex;flex-direction:column;gap:1rem}:host form img{position:absolute;top:50%;transform:translateY(-50%);pointer-events:none}:host form img:first-of-type{left:1rem}:host form img:last-of-type{right:1rem}:host form span{margin-top:-0.5rem;color:#ec6632}:host form p{text-align:center}:host form p{margin:0}:host form div{position:relative}:host form div label{pointer-events:none;position:absolute;left:1rem;top:50%;transform:translateY(-50%);background:#fff;padding:0.25rem;transition:0.2s all cubic-bezier(0.465, 0.183, 0.153, 0.946)}:host form div input{padding:1rem;width:100%;font-size:1rem;border:1px solid #fcd9c9}:host form div input:focus~label,:host form div .input_active~label{top:0;transform:translateY(-50%);background:linear-gradient(180deg, #fffaf2 50%, #fff 50%)}:host h1{font-size:24px;font-weight:400;line-height:32px;letter-spacing:-3%;text-align:left;margin:0 0 0.5rem}:host h2{margin:0 0 1.5rem;font-weight:700;font-size:20px;line-height:28px;letter-spacing:-3%}:host p{font-size:16px;font-weight:400;line-height:24px;letter-spacing:-3%}:host .hemfixarna{width:100%;}:host .hemfixarna .switch{position:relative;display:inline-block;width:40px;height:20px}:host .hemfixarna .switch input{opacity:0;width:0;height:0}:host .hemfixarna .slider{position:absolute;cursor:pointer;top:0;left:0;right:0;bottom:0;background-color:#ccc;-webkit-transition:0.4s;transition:0.4s;border-radius:34px}:host .hemfixarna .slider:before{position:absolute;content:\"\";height:18px;width:18px;left:2px;bottom:1px;background-color:white;-webkit-transition:0.4s;transition:0.4s;border-radius:50%}:host .hemfixarna input:checked+.slider{background-color:#fcd9c9}:host .hemfixarna input:focus+.slider{box-shadow:0 0 1px #fcd9c9}:host .hemfixarna input:checked+.slider:before{-webkit-transform:translateX(18px);-ms-transform:translateX(18px);transform:translateX(18px);background:#ec6632}:host .hemfixarna_checkbox{display:grid;grid-template-columns:2.5rem auto;font-size:16px;font-weight:400;line-height:24px;letter-spacing:-3%}:host .hemfixarna_checkbox>span{transform:translateY(6px)}:host .hemfixarna_checkbox span,:host .hemfixarna_checkbox span p{color:#474444;font-size:14px}:host .hemfixarna_checkbox p{text-align:left}:host .hemfixarna_info{display:flex;flex-direction:column;gap:1.5rem;padding:2rem;box-shadow:0px 4px 8px 0px rgba(0, 0, 0, 0.0392156863);border-radius:0.25rem;border:1px solid #fcd9c9}:host .hemfixarna_info h2{margin:0}@media (min-width: 769px){:host .hemfixarna_info{position:sticky;top:0}}:host .hemfixarna_infomodal{position:absolute;top:40%;left:50%;transform:translate(-50%, -50%);width:100%;max-width:80%;background:#fffaf2;border:1px solid #fcd9c9;padding:2rem;z-index:99;border-radius:0.25rem;box-shadow:0px 4px 8px 0px rgba(0, 0, 0, 0.0392156863);display:flex;flex-direction:column;gap:1rem}:host .hemfixarna_infomodal button{background:#ec6632;color:#fff;border-radius:60px;font-size:16px;padding:0.5rem 1rem}:host .hemfixarna_addressinfo{padding:1rem 1rem 4rem;border:1px solid #fcd9c9;position:relative;margin-bottom:2rem;display:grid;grid-template-columns:1fr 1fr;gap:0.5rem}:host .hemfixarna_addressinfo button{position:absolute;bottom:1rem;right:1rem;font-weight:500;text-underline-offset:2px;text-decoration:underline}:host .hemfixarna_part{background:#fff;box-shadow:0px 4px 8px 0px rgba(0, 0, 0, 0.0392156863);display:grid;padding:1rem;grid-template-columns:auto 75px}:host .hemfixarna_counter{display:flex;align-items:center}:host .hemfixarna_counter span{padding:0 0.5rem}:host .hemfixarna_counter img{cursor:pointer}:host .hemfixarna_counter img:not(.disabled):hover{transition:0.1s all cubic-bezier(0.465, 0.183, 0.153, 0.946);filter:brightness(1.02);transform:scale(1.01);box-shadow:0px 8px 16px 2px rgba(0, 0, 0, 0.0392156863)}:host .hemfixarna_terms{font-size:14px}:host .hemfixarna_terms a{color:inherit}:host .hemfixarna_logo{height:4rem}:host .hemfixarna_box{padding:1rem;display:flex;align-items:center;justify-content:space-between;background:#fffaf2;border:1px solid #fcd9c9;width:100%;box-sizing:border-box;border-radius:0.25rem;gap:1rem 0.5rem}:host .hemfixarna_box>div{display:grid;gap:0.5rem}:host .hemfixarna_btn,:host .hemfixarna_buy,:host .hemfixarna input[type=submit]{border:none;border-radius:60px;font-weight:600;letter-spacing:0.5px;line-height:20px;box-shadow:0px 4px 8px 0px rgba(0, 0, 0, 0.0392156863)}:host .hemfixarna_btn:not(.disabled):hover,:host .hemfixarna_buy:not(.disabled):hover,:host .hemfixarna input[type=submit]:not(.disabled):hover{transition:0.1s all cubic-bezier(0.465, 0.183, 0.153, 0.946);filter:brightness(1.02);transform:scale(1.01);box-shadow:0px 8px 16px 2px rgba(0, 0, 0, 0.0392156863)}:host .hemfixarna_btn{font-size:14px;background:#c84e18;color:#fff;padding:1rem 2rem;white-space:nowrap;position:relative}:host .hemfixarna_btn span{position:absolute;background:#fff;border-radius:100%;width:24px;height:24px;display:flex;justify-content:center;align-items:center;font-weight:600;font-size:13px;line-height:11px;top:-0.5rem;right:-0.75rem}:host .hemfixarna_btn span{background:#25a710;color:#fff;right:0 !important}:host .hemfixarna_buy,:host .hemfixarna input[type=submit]{font-size:21px;background:#25a710;color:#fff;padding:1rem 1.5rem}:host .hemfixarna .disabled{opacity:0.5;cursor:default}:host .hemfixarna_modal{position:fixed;background:#fffaf2;border:1px solid #fcd9c9;border-radius:0.25rem;top:50%;left:50%;z-index:1000;transition:0.1s all cubic-bezier(0.465, 0.183, 0.153, 0.946);transform:translate(-50%, -50%) scale(0.7);opacity:0;height:92%;width:92%;max-width:920px;display:flex;flex-direction:column;gap:0.5rem}:host .hemfixarna_modal--open{opacity:1;transform:translate(-50%, -50%) scale(1)}:host .hemfixarna_backdrop{z-index:999;position:fixed;background:#474444;top:0;left:0;bottom:0;right:0;opacity:0;transition:transform 0.1s cubic-bezier(0.465, 0.183, 0.153, 0.946), opacity 0.1s cubic-bezier(0.465, 0.183, 0.153, 0.946)}:host .hemfixarna_backdrop--open{opacity:0.3}:host .hemfixarna_order{position:absolute;top:-1px;left:-1px;right:-1px;bottom:-1px;background-repeat:no-repeat !important;background-size:cover !important;background-position:center !important;display:grid;grid-template-columns:1fr 1fr;padding:3rem 2rem 4rem}@media (max-width: 768px){:host .hemfixarna_order{grid-template-columns:1fr;grid-template-rows:0 auto}}:host .hemfixarna_order>div:last-of-type{background:#fffaf2;padding:2rem;display:flex;flex-direction:column;max-height:100%;overflow:auto}:host .hemfixarna_order img{cursor:pointer}:host .hemfixarna_order button{margin:1rem 0;padding:0;text-decoration:underline;text-underline-offset:2px;font-size:14px;font-weight:600}:host .hemfixarna_cart{display:grid;grid-template-columns:1fr 1fr;gap:2rem}@media (max-width: 768px){:host .hemfixarna_cart{grid-template-columns:1fr;gap:0}}:host .hemfixarna_cart--right h2,:host .hemfixarna_cart--left h2{display:flex;align-items:center}:host .hemfixarna_cart--right h2 img,:host .hemfixarna_cart--left h2 img{margin-top:0.2rem}@media (min-width: 769px){:host .hemfixarna_cart--left h2 button{display:none}}@media (max-width: 768px){:host .hemfixarna_cart--right h2 button{display:none}}:host .hemfixarna_cart--startfee{display:flex;justify-content:space-between}:host .hemfixarna_cart--rutrot{display:flex;justify-content:space-between}:host .hemfixarna_cart--rutrot div{display:flex;gap:1rem;align-items:center}:host .hemfixarna_cart--additional{display:flex;flex-direction:column;gap:1rem;padding:1rem;border-top:1px solid #fcd9c9}:host .hemfixarna_cart--additional p{font-size:14px}:host .hemfixarna_cart--additional strong{text-decoration:underline;text-underline-offset:2px;cursor:pointer;position:relative}:host .hemfixarna_cart--additional strong img{position:absolute;top:50%;transform:translateY(-50%);right:-1.5rem}:host .hemfixarna_cart--price{border-top:1px solid #fcd9c9;padding:1rem;display:flex;justify-content:space-between}:host .hemfixarna_cart--price h3{margin:0}:host .hemfixarna_cart--item{display:flex;flex-direction:column;gap:0.5rem;padding:1rem 0;border-top:1px solid #fcd9c9}:host .hemfixarna_cart--item>div{display:flex;justify-content:space-between}:host .hemfixarna_cart--item>div>div{display:flex;align-items:center;gap:1rem}:host .hemfixarna_cart--item>div button{color:#ec6632}:host .hemfixarna_categories{display:grid;gap:1.5rem}:host .hemfixarna_categories--wrapper{gap:2rem;display:grid;grid-template-columns:1fr 1fr}@media (max-width: 768px){:host .hemfixarna_categories--wrapper{grid-template-columns:1fr}}:host .hemfixarna_categories li{position:relative;background:#fff;border-radius:0.25rem;min-height:132px;padding:1.5rem;box-shadow:0px 4px 8px 0px rgba(0, 0, 0, 0.0392156863);display:flex;align-items:center;gap:1.5rem;cursor:pointer}:host .hemfixarna_categories li:hover{transition:0.1s all cubic-bezier(0.465, 0.183, 0.153, 0.946);filter:brightness(1.02);transform:scale(1.01);box-shadow:0px 8px 16px 2px rgba(0, 0, 0, 0.0392156863)}:host .hemfixarna_categories li>button{height:100%;width:100%}:host .hemfixarna_categories li .price{font-weight:700}:host .hemfixarna_content{height:100%;overflow:auto;padding:0 2rem 4rem}:host .hemfixarna_content--5{padding-top:1rem}:host .hemfixarna_crumbs{position:relative;padding:1rem 1.5rem;border-bottom:1px solid #fcd9c9;display:flex;justify-content:space-between}:host .hemfixarna_crumbs--back{padding:1rem 1.5rem 0.5rem;display:flex;align-items:center;gap:0.5rem;box-shadow:none !important}:host .hemfixarna_crumbs--back:hover{transition:0.1s all cubic-bezier(0.465, 0.183, 0.153, 0.946);filter:brightness(1.02);transform:scale(1.01);box-shadow:0px 8px 16px 2px rgba(0, 0, 0, 0.0392156863)}:host .hemfixarna_crumbs img{cursor:pointer}:host .hemfixarna_crumbs .close{position:absolute;right:-1rem;top:-1rem;z-index:9}:host .hemfixarna_crumbs .cart{padding-left:1rem;position:relative}:host .hemfixarna_crumbs .cart img{cursor:inherit}:host .hemfixarna_crumbs .cart span{position:absolute;background:#fff;border-radius:100%;width:24px;height:24px;display:flex;justify-content:center;align-items:center;font-weight:600;font-size:13px;line-height:11px;top:-0.5rem;right:-0.75rem}:host .hemfixarna_crumbs .cart_active{cursor:pointer}:host .hemfixarna_crumbs .cart_active span{background:#25a710;color:#fff}:host .hemfixarna_crumbs--links{display:flex;align-items:center;gap:1rem;overflow:auto}@media (min-width: 769px){:host .hemfixarna_crumbs--links{-ms-overflow-style:none}:host .hemfixarna_crumbs--links::-webkit-scrollbar{display:none}:host .hemfixarna_crumbs--links::-webkit-scrollbar-button{display:none}}:host .hemfixarna_crumbs button{white-space:nowrap;background:#f1ded6;border-radius:4rem;padding:0.75rem 1rem;font-size:12px;font-weight:600;letter-spacing:0.3px;box-shadow:none !important}:host .hemfixarna_crumbs button:not(.active):hover{transition:0.1s all cubic-bezier(0.465, 0.183, 0.153, 0.946);filter:brightness(1.02);transform:scale(1.01);box-shadow:0px 8px 16px 2px rgba(0, 0, 0, 0.0392156863)}:host .hemfixarna_crumbs .active{background:#fffaf2;cursor:default}:host .hemfixarna_features{gap:0.75rem !important}:host .hemfixarna_features li{display:flex;gap:1rem;align-items:center}:host .hemfixarna_address{margin-bottom:1rem}:host .hemfixarna_product{display:grid;gap:1rem}:host .hemfixarna_product--link{font-weight:700;color:#474444;text-underline-offset:0.25rem}:host .hemfixarna_product--left{gap:2rem}:host .hemfixarna_product--right{gap:2rem}:host .hemfixarna_product--price{margin-top:0.25rem;font-weight:700}:host .hemfixarna_product--total{text-align:center;margin:-1rem 0;font-size:21px;line-height:28px}:host .hemfixarna_product--item{background:#fff;padding:1rem;display:grid;grid-template-columns:auto 75px;box-shadow:0px 4px 8px 0px rgba(0, 0, 0, 0.0392156863)}:host .hemfixarna_product--grid{display:grid;grid-template-columns:1fr 1fr;gap:2rem}@media (max-width: 768px){:host .hemfixarna_product--grid{grid-template-columns:1fr}}:host .hemfixarna_product--grid>div{display:flex;flex-direction:column}:host .hemfixarna_product--grid ul{display:flex;flex-direction:column;gap:0.5rem}:host .hemfixarna_product p{margin:0}:host .hemfixarna_product--top{display:flex;gap:2rem}:host .hemfixarna_product--top>div{width:100%}:host .hemfixarna_product--top>div h1{max-width:80%}@media (max-width: 768px){:host .hemfixarna_product--top>div h1{max-width:100%}}:host .hemfixarna_product--top h4{margin-bottom:0.5rem}:host h5,:host p{margin:0}:host input[type=submit]{cursor:pointer}:host input[type=date]~label{left:3.5rem}:host input[type=date]{border:1px solid #fcd9c9;padding-left:4rem}:host input[type=checkbox]{height:1.125rem;width:1.125rem;border:1px solid #fcd9c9}:host input[type=checkbox]:checked{background:red}:host input[type=date]::-webkit-calendar-picker-indicator{background:transparent;bottom:0;color:transparent;cursor:pointer;height:auto;left:0;position:absolute;right:0;top:0;width:auto}:host button,:host a{cursor:pointer;background:none;border:none}:host ul{list-style:none;margin:0;padding:0}";
613
+
614
+ const HemfixarnaComponent = class {
615
+ constructor(hostRef) {
616
+ index.registerInstance(this, hostRef);
617
+ this.modal = false;
618
+ this.showModal = false;
619
+ this.tree = null;
620
+ this.product = null;
621
+ this.slug = undefined;
622
+ this.business = undefined;
623
+ this.topCategory = undefined;
624
+ }
625
+ async fetchNewTaxonomy(newValue) {
626
+ state.selectedCategory = null;
627
+ state.selectedProduct = null;
628
+ state.selectedService = null;
629
+ const res = await getTaxonomy(newValue);
630
+ if ((res === null || res === void 0 ? void 0 : res.code) === 'not_found' || (res === null || res === void 0 ? void 0 : res.code) === 'rest_no_route') {
631
+ console.log('taxonomy not found');
632
+ }
633
+ else if (res) {
634
+ this.setTaxonomy(res);
635
+ if ((res === null || res === void 0 ? void 0 : res.post_type) === 'ikea_product') {
636
+ this.product = res;
637
+ }
638
+ }
639
+ }
640
+ async componentWillLoad() {
641
+ state.business = this.business;
642
+ const cart = window.sessionStorage.getItem(`hemfixarna-${this.business}-cart`);
643
+ if (cart) {
644
+ state.cart = JSON.parse(cart);
645
+ }
646
+ const user = window.sessionStorage.getItem(`hemfixarna-${this.business}-user`);
647
+ if (user) {
648
+ state.user = JSON.parse(user);
649
+ }
650
+ const tree = await getTaxonomy(this.topCategory);
651
+ if ((tree === null || tree === void 0 ? void 0 : tree.code) === 'not_found') {
652
+ console.warn('tree not found');
653
+ }
654
+ else if (tree) {
655
+ this.tree = tree;
656
+ }
657
+ if (this.slug) {
658
+ const res = await getTaxonomy(this.slug);
659
+ if ((res === null || res === void 0 ? void 0 : res.code) === 'not_found') {
660
+ console.log('taxonomy not found');
661
+ }
662
+ else if (res) {
663
+ this.setTaxonomy(res);
664
+ }
665
+ }
666
+ const options = await getOptions();
667
+ state.options = options;
668
+ }
669
+ setTaxonomy(taxonomy) {
670
+ if (taxonomy) {
671
+ if ((taxonomy === null || taxonomy === void 0 ? void 0 : taxonomy.taxonomy) === 'service_cat') {
672
+ state.selectedCategory = taxonomy;
673
+ state.step = 2;
674
+ }
675
+ else if ((taxonomy === null || taxonomy === void 0 ? void 0 : taxonomy.post_type) === 'service') {
676
+ state.selectedService = taxonomy;
677
+ state.selectedCategory = this.tree.sub_cats.find(c => c.services.find(s => s.ID === taxonomy.ID));
678
+ state.step = 3;
679
+ }
680
+ else if ((taxonomy === null || taxonomy === void 0 ? void 0 : taxonomy.post_type) === 'ikea_product') {
681
+ state.selectedProduct = taxonomy;
682
+ state.selectedService = this.tree.sub_cats
683
+ .map(c => c.services)
684
+ .flat()
685
+ .find(s => s.products.find(p => p.ID === state.selectedProduct.ID));
686
+ state.selectedCategory = this.tree.sub_cats.find(c => c.services.find(s => s.ID === state.selectedService.ID));
687
+ state.step = 4;
688
+ }
689
+ }
690
+ }
691
+ // Open close modal && click outside event
692
+ openModal() {
693
+ this.modal = true;
694
+ setTimeout(() => {
695
+ this.showModal = true;
696
+ }, 50);
697
+ }
698
+ closeModal() {
699
+ this.showModal = false;
700
+ setTimeout(() => {
701
+ this.modal = false;
702
+ }, 200);
703
+ }
704
+ handleClick(e) {
705
+ const el = this.el.shadowRoot.querySelector('.hemfixarna_modal');
706
+ if (el) {
707
+ const isClickInside = el.contains(e.composedPath()[0]);
708
+ if (!isClickInside) {
709
+ this.closeModal();
710
+ }
711
+ }
712
+ const infomodal = this.el.shadowRoot.querySelector('.hemfixarna_infomodal');
713
+ if (infomodal) {
714
+ const isClickInside = infomodal.contains(e.composedPath()[0]);
715
+ if (!isClickInside) {
716
+ state.modal = null;
717
+ }
718
+ }
719
+ }
720
+ getCartLength() {
721
+ return state.cart.reduce((acc, curr) => acc + curr.amount, 0);
722
+ }
723
+ render() {
724
+ var _a, _b;
725
+ const logo = index.getAssetPath(`./assets/hemfixarna.svg`);
726
+ return (index.h("div", { class: "hemfixarna" }, index.h("div", { class: "hemfixarna_box" }, index.h("div", null, index.h("div", null, index.h("p", null, ((_a = this.product) === null || _a === void 0 ? void 0 : _a.post_title) || (index.h("span", null, "Montering/Installation p\u00E5 plats - ", index.h("strong", null, "se priser h\u00E4r"))), this.product && ((_b = this.slug) === null || _b === void 0 ? void 0 : _b.includes('product')) ? (index.h("span", null, ' från', " ", index.h("strong", null, getProductPriceWithRotAndRut(this.product), "kr"))) : null)), index.h("img", { src: logo, width: 104 })), index.h("button", { onClick: () => this.openModal(), class: "hemfixarna_btn" }, "Till montering", this.getCartLength() > 0 && index.h("span", null, this.getCartLength()))), this.modal && (index.h("div", null, index.h("div", { class: `hemfixarna_modal ${this.showModal ? 'hemfixarna_modal--open' : ''}` }, state.modal && (index.h("div", { class: "hemfixarna_infomodal" }, index.h("h2", null, state.modal.title), state.modal.text.map((t) => (index.h("p", null, t))), index.h("div", null, index.h("button", { onClick: () => (state.modal = null) }, "St\u00E4ng")))), this.tree && index.h("hemfixarna-breadcrumbs", { closeModal: () => this.closeModal(), tree: this.tree }), index.h("div", { class: `hemfixarna_content hemfixarna_content--${state.step}` }, state.step === 1 && this.tree && index.h("hemfixarna-start", { tree: this.tree }), state.step === 2 && state.selectedCategory && index.h("hemfixarna-category", null), state.step === 3 && state.selectedService && index.h("hemfixarna-service", null), state.step === 4 && state.selectedProduct && index.h("hemfixarna-product", null), state.step === 5 && index.h("hemfixarna-cart", { tree: this.tree }), state.step === 6 && index.h("hemfixarna-order", { tree: this.tree }))), index.h("div", { class: `hemfixarna_backdrop ${this.showModal ? 'hemfixarna_backdrop--open' : ''}` })))));
727
+ }
728
+ static get assetsDirs() { return ["assets"]; }
729
+ get el() { return index.getElement(this); }
730
+ static get watchers() { return {
731
+ "slug": ["fetchNewTaxonomy"]
732
+ }; }
733
+ };
734
+ HemfixarnaComponent.style = hemfixarnaCss;
735
+
736
+ const hemfixarnaDemoCss = "@import url(\"https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600&display=swap\"); :host{font-family:\"Inter\", sans-serif}:host .hemfixarna_example{margin-bottom:1rem;background:#000;padding:1rem;color:#fff;display:flex;justify-content:space-between;cursor:pointer;max-width:500px;box-sizing:border-box;position:relative}:host .hemfixarna_example--tooltip{background:#000;top:-3rem;font-size:16px;left:40%;color:white;padding:0.5rem;position:absolute;opacity:0}:host .hemfixarna_example--tooltip::after{content:\"\";position:absolute;top:100%;left:50%;margin-left:-5px;border-width:5px;border-style:solid;border-color:#000 transparent transparent transparent}:host .hemfixarna_example:hover .hemfixarna_example--tooltip{opacity:1}:host .hemfixarna_example p{font-size:14px}:host .hemfixarna_example img{filter:invert(1)}:host .hemfixarna_install{display:grid;gap:0.5rem;margin-top:1rem}:host .hemfixarna_categories{max-height:100%;overflow:auto;position:relative}:host .hemfixarna_categories--label{display:flex;align-items:center;justify-content:space-between;padding:0.5rem}:host .hemfixarna_categories--label button{background:#3f3a92;border:none;font-weight:600;padding:0.2rem 0.6rem;border-radius:10px;margin-right:0.5rem;color:#ece8e8}:host .hemfixarna_categories--label button:active{transform:scale(0.95)}:host .hemfixarna_categories--label--big{font-weight:600;background:#9f9da9}:host p{margin:0}:host span{color:darkolivegreen;font-size:10px}:host button{cursor:pointer}:host>div{display:grid;gap:2rem;width:100%;grid-template-columns:1fr 1fr;height:100vh;place-items:center;overflow:hidden;padding:1rem 2rem;box-sizing:border-box}:host>div>*{width:100%}:host>div>div{max-width:500px}:host>div ul{margin:0;padding:0;list-style:none}:host>div ul ul{background:#000;gap:1px;display:grid}:host>div ul li{padding-left:1rem;background:#fff}";
737
+
738
+ const MyComponent = class {
739
+ constructor(hostRef) {
740
+ index.registerInstance(this, hostRef);
741
+ this.cdnLink = '<script type="module" src="https://cdn.jsdelivr.net/npm//hemfixarna-web-components@latest/dist/hemfixarna-components/hemfixarna-components.esm.js"></script>';
742
+ this.selectedSlug = undefined;
743
+ this.tooltipText = 'Kopiera till urklipp';
744
+ this.tree = null;
745
+ }
746
+ getTopLevelCategory() {
747
+ switch ("byggmax") {
748
+ case Business.byggmax:
749
+ return TopCategory.byggmax;
750
+ default:
751
+ return '';
752
+ }
753
+ }
754
+ async componentWillLoad() {
755
+ const tree = await getTaxonomy(this.getTopLevelCategory());
756
+ if ((tree === null || tree === void 0 ? void 0 : tree.code) === 'not_found') {
757
+ console.warn('tree not found');
758
+ }
759
+ else if (tree) {
760
+ this.tree = tree;
761
+ }
762
+ }
763
+ getExample() {
764
+ return `<hemfixarna-${"byggmax"}${this.selectedSlug ? ` slug="${this.selectedSlug}" ` : ''}></hemfixarna-${"byggmax"}>`;
765
+ }
766
+ copyExample() {
767
+ navigator.clipboard.writeText(this.getExample());
768
+ this.tooltipText = 'Snippet kopierad';
769
+ setTimeout(() => {
770
+ this.tooltipText = 'Kopiera till urklipp';
771
+ }, 2000);
772
+ }
773
+ copyCdn() {
774
+ navigator.clipboard.writeText(this.cdnLink);
775
+ this.tooltipText = 'Text kopierad';
776
+ setTimeout(() => {
777
+ this.tooltipText = 'Kopiera till urklipp';
778
+ }, 2000);
779
+ }
780
+ copyNpmInstall() {
781
+ navigator.clipboard.writeText('npm i hemfixarna-web-components');
782
+ this.tooltipText = 'Text kopierad';
783
+ setTimeout(() => {
784
+ this.tooltipText = 'Kopiera till urklipp';
785
+ }, 2000);
786
+ }
787
+ render() {
788
+ const copy = index.getAssetPath(`./assets/copy.png`);
789
+ return (index.h("div", null, index.h("div", null, index.h("div", { onClick: () => this.copyExample(), class: "hemfixarna_example" }, index.h("p", null, this.getExample()), index.h("img", { src: copy, height: 20 }), index.h("span", { class: "hemfixarna_example--tooltip" }, this.tooltipText)), "byggmax" === Business.byggmax && index.h("hemfixarna-byggmax", { slug: this.selectedSlug }), index.h("div", { class: "hemfixarna_install" }, index.h("div", null, index.h("a", { target: "_blank", href: "https://www.npmjs.com/package/hemfixarna-web-components" }, "Install with npm")), index.h("div", { onClick: () => this.copyNpmInstall(), class: "hemfixarna_example" }, index.h("p", null, "npm i hemfixarna-web-components"), index.h("span", { class: "hemfixarna_example--tooltip" }, this.tooltipText), index.h("img", { src: copy, height: 20 })), index.h("p", null, "Or use cdn"), index.h("div", { onClick: () => this.copyCdn(), class: "hemfixarna_example" }, index.h("p", null, this.cdnLink), index.h("span", { class: "hemfixarna_example--tooltip" }, this.tooltipText), index.h("img", { src: copy, height: 20 })))), index.h("ul", { class: "hemfixarna_categories" }, this.tree.sub_cats.map(c => (index.h("li", null, index.h("div", { class: "hemfixarna_categories--label hemfixarna_categories--label--big" }, index.h("div", null, index.h("p", null, c.name), index.h("span", null, `category/${c.slug}`)), index.h("div", null, index.h("button", { onClick: () => navigator.clipboard.writeText(`category/${c.slug}`) }, "Kopiera slug"), index.h("button", { onClick: () => (this.selectedSlug = `category/${c.slug}`) }, "Ladda kategori"))), index.h("ul", null, c.services.map(sc => (index.h("li", null, index.h("div", { class: "hemfixarna_categories--label" }, index.h("div", null, index.h("p", null, sc.post_title), index.h("span", null, `service/${sc.post_name}`)), index.h("div", null, index.h("button", { onClick: () => navigator.clipboard.writeText(`service/${sc.post_name}`) }, "Kopiera slug"), index.h("button", { onClick: () => (this.selectedSlug = `service/${sc.post_name}`) }, "Ladda kategori"))), index.h("ul", null, sc.products.map(sc => (index.h("li", null, index.h("div", { class: "hemfixarna_categories--label" }, index.h("div", null, index.h("p", null, sc.post_title), index.h("span", null, `product/${sc.post_name}`)), index.h("div", null, index.h("button", { onClick: () => navigator.clipboard.writeText(`product/${sc.post_name}`) }, "Kopiera slug"), index.h("button", { onClick: () => (this.selectedSlug = `product/${sc.post_name}`) }, "Ladda kategori")))))))))))))))));
790
+ }
791
+ };
792
+ MyComponent.style = hemfixarnaDemoCss;
793
+
794
+ // src/errors.ts
795
+ var PersonnummerError = class extends Error {
796
+ constructor() {
797
+ super("Invalid swedish personal identity number");
798
+ }
799
+ };
800
+
801
+ // src/utils.ts
802
+ var compareAsc = (dateLeft, dateRight) => {
803
+ const diff = dateLeft.getTime() - dateRight.getTime();
804
+ return diff < 0 ? -1 : diff > 0 ? 1 : diff;
805
+ };
806
+ var diffInYears = (dateLeft, dateRight) => {
807
+ const sign = compareAsc(dateLeft, dateRight);
808
+ const yearDiff = Math.abs(dateLeft.getFullYear() - dateRight.getFullYear());
809
+ dateLeft.setFullYear(dateLeft.getFullYear() - sign * yearDiff);
810
+ const isLastYearNotFull = compareAsc(dateLeft, dateRight) === -sign;
811
+ const result = sign * (yearDiff - +isLastYearNotFull);
812
+ return result === 0 ? 0 : result;
813
+ };
814
+ var luhn = (str) => {
815
+ let sum = 0;
816
+ str += "";
817
+ for (let i = 0, l = str.length; i < l; i++) {
818
+ let v = parseInt(str[i]);
819
+ v *= 2 - i % 2;
820
+ if (v > 9) {
821
+ v -= 9;
822
+ }
823
+ sum += v;
824
+ }
825
+ return Math.ceil(sum / 10) * 10 - sum;
826
+ };
827
+ var testDate = (year, month, day) => {
828
+ month -= 1;
829
+ const date = new Date(year, month, day);
830
+ return !(date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day);
831
+ };
832
+
833
+ // src/index.ts
834
+ var Personnummer = class {
835
+ /**
836
+ * Personnummer constructor.
837
+ *
838
+ * @param {string} pin
839
+ * @param {object} options
840
+ */
841
+ constructor(pin, options) {
842
+ /**
843
+ * Personnummer century.
844
+ *
845
+ * @var {string}
846
+ */
847
+ this._century = "";
848
+ /**
849
+ * Personnummer full year.
850
+ *
851
+ * @var {string}
852
+ */
853
+ this._fullYear = "";
854
+ /**
855
+ * Personnummer year.
856
+ *
857
+ * @var {string}
858
+ */
859
+ this._year = "";
860
+ /**
861
+ * Personnummer month.
862
+ *
863
+ * @var {string}
864
+ */
865
+ this._month = "";
866
+ /**
867
+ * Personnummer day.
868
+ *
869
+ * @var {string}
870
+ */
871
+ this._day = "";
872
+ /**
873
+ * Personnummer seperator.
874
+ *
875
+ * @var {string}
876
+ */
877
+ this._sep = "";
878
+ /**
879
+ * Personnumer first three of the last four numbers.
880
+ *
881
+ * @var {string}
882
+ */
883
+ this._num = "";
884
+ /**
885
+ * The last number of the personnummer.
886
+ *
887
+ * @var {string}
888
+ */
889
+ this._check = "";
890
+ this.parse(pin, {
891
+ allowCoordinationNumber: true,
892
+ allowInterimNumber: false,
893
+ ...options
894
+ });
895
+ }
896
+ /**
897
+ * Get century.
898
+ *
899
+ * @return {string}
900
+ */
901
+ get century() {
902
+ return this._century;
903
+ }
904
+ /**
905
+ * Get age.
906
+ *
907
+ * @return {string}
908
+ */
909
+ get fullYear() {
910
+ return this._fullYear;
911
+ }
912
+ /**
913
+ * Get age.
914
+ *
915
+ * @return {string}
916
+ */
917
+ get year() {
918
+ return this._year;
919
+ }
920
+ /**
921
+ * Get month.
922
+ *
923
+ * @return {string}
924
+ */
925
+ get month() {
926
+ return this._month;
927
+ }
928
+ /**
929
+ * Get day.
930
+ *
931
+ * @return {string}
932
+ */
933
+ get day() {
934
+ return this._day;
935
+ }
936
+ /**
937
+ * Get sep.
938
+ *
939
+ * @return {string}
940
+ */
941
+ get sep() {
942
+ return this._sep;
943
+ }
944
+ /**
945
+ * Get num.
946
+ *
947
+ * @return {string}
948
+ */
949
+ get num() {
950
+ return this._num;
951
+ }
952
+ /**
953
+ * Get check.
954
+ *
955
+ * @return {string}
956
+ */
957
+ get check() {
958
+ return this._check;
959
+ }
960
+ /**
961
+ * Parse personnummer.
962
+ *
963
+ * @param {string} pin
964
+ * @param {object} options
965
+ *
966
+ * @return {Personnummer}
967
+ */
968
+ static parse(pin, options) {
969
+ return new Personnummer(pin, options);
970
+ }
971
+ /**
972
+ * Validate a Swedish personal identity number.
973
+ *
974
+ * @param {string} str
975
+ * @param {object} options
976
+ *
977
+ * @return {boolean}
978
+ */
979
+ static valid(pin, options) {
980
+ try {
981
+ Personnummer.parse(pin, options);
982
+ return true;
983
+ } catch (e) {
984
+ return false;
985
+ }
986
+ }
987
+ /**
988
+ * Parse personnummer and set class properties.
989
+ *
990
+ * @param {string} pin
991
+ * @param {object} options
992
+ */
993
+ parse(pin, options) {
994
+ if (pin.length < 10 || pin.length > 13) {
995
+ throw new PersonnummerError();
996
+ }
997
+ const reg = /^(\d{2}){0,1}(\d{2})(\d{2})(\d{2})([+-]?)((?!000)\d{3}|[TRSUWXJKLMN]\d{2})(\d)$/;
998
+ const match = reg.exec(pin);
999
+ if (!match) {
1000
+ throw new PersonnummerError();
1001
+ }
1002
+ const century = match[1];
1003
+ const year = match[2];
1004
+ const month = match[3];
1005
+ const day = match[4];
1006
+ const sep = match[5];
1007
+ const num = match[6];
1008
+ const check = match[7];
1009
+ if (typeof century === "undefined" || !century.length) {
1010
+ const d = /* @__PURE__ */ new Date();
1011
+ let baseYear = 0;
1012
+ if (sep === "+") {
1013
+ this._sep = "+";
1014
+ baseYear = d.getFullYear() - 100;
1015
+ } else {
1016
+ this._sep = "-";
1017
+ baseYear = d.getFullYear();
1018
+ }
1019
+ this._century = ("" + (baseYear - (baseYear - parseInt(year)) % 100)).substr(0, 2);
1020
+ } else {
1021
+ this._century = century;
1022
+ if ((/* @__PURE__ */ new Date()).getFullYear() - parseInt(century + year, 10) < 100) {
1023
+ this._sep = "-";
1024
+ } else {
1025
+ this._sep = "+";
1026
+ }
1027
+ }
1028
+ this._year = year;
1029
+ this._fullYear = this._century + year;
1030
+ this._month = month;
1031
+ this._day = day;
1032
+ this._num = num;
1033
+ this._check = check;
1034
+ if (!this.valid()) {
1035
+ throw new PersonnummerError();
1036
+ }
1037
+ if (!(options == null ? void 0 : options.allowCoordinationNumber) && this.isCoordinationNumber()) {
1038
+ throw new PersonnummerError();
1039
+ }
1040
+ if (!(options == null ? void 0 : options.allowInterimNumber) && this.isInterimNumber()) {
1041
+ throw new PersonnummerError();
1042
+ }
1043
+ }
1044
+ /**
1045
+ * Validate a Swedish personal identity number.
1046
+ *
1047
+ * @return {boolean}
1048
+ */
1049
+ valid() {
1050
+ const valid = luhn(
1051
+ this.year + this.month + this.day + this.num.replace(/[TRSUWXJKLMN]/, "1")
1052
+ ) === +this.check && !!this.check;
1053
+ if (valid && testDate(parseInt(this.century + this.year), +this.month, +this.day)) {
1054
+ return valid;
1055
+ }
1056
+ return valid && testDate(parseInt(this.century + this.year), +this.month, +this.day - 60);
1057
+ }
1058
+ /**
1059
+ * Format a Swedish personal identity number as one of the official formats,
1060
+ * A long format or a short format.
1061
+ *
1062
+ * If the input number could not be parsed a empty string will be returned.
1063
+ *
1064
+ * @param {boolean} longFormat
1065
+ *
1066
+ * @return {string}
1067
+ */
1068
+ format(longFormat = false) {
1069
+ if (longFormat) {
1070
+ return `${this.century}${this.year}${this.month}${this.day}${this.num}${this.check}`;
1071
+ }
1072
+ return `${this.year}${this.month}${this.day}${this.sep}${this.num}${this.check}`;
1073
+ }
1074
+ /**
1075
+ * Get age from a Swedish personal identity number.
1076
+ *
1077
+ * @return {number}
1078
+ */
1079
+ getAge() {
1080
+ const date = this.getDate();
1081
+ return diffInYears(new Date(Date.now()), date);
1082
+ }
1083
+ /**
1084
+ * Get date from a Swedish personal identity number.
1085
+ *
1086
+ * @return {Date}
1087
+ */
1088
+ getDate() {
1089
+ let ageDay = +this.day;
1090
+ if (this.isCoordinationNumber()) {
1091
+ ageDay -= 60;
1092
+ }
1093
+ const ageDate = this.century + this.year + "-" + this.month + "-" + (ageDay < 10 ? "0" + ageDay : ageDay);
1094
+ return new Date(ageDate);
1095
+ }
1096
+ /**
1097
+ * Check if a Swedish personal identity number is a interim number or not.
1098
+ *
1099
+ * @return {boolean}
1100
+ */
1101
+ isInterimNumber() {
1102
+ return /[TRSUWXJKLMN]/.test(this.num[0]);
1103
+ }
1104
+ /**
1105
+ * Check if a Swedish personal identity number is a coordination number or not.
1106
+ *
1107
+ * @return {boolean}
1108
+ */
1109
+ isCoordinationNumber() {
1110
+ return testDate(
1111
+ parseInt(this.century + this.year),
1112
+ +this.month,
1113
+ +this.day - 60
1114
+ );
1115
+ }
1116
+ /**
1117
+ * Check if a Swedish personal identity number is for a female.
1118
+ *
1119
+ * @return {boolean}
1120
+ */
1121
+ isFemale() {
1122
+ return !this.isMale();
1123
+ }
1124
+ /**
1125
+ * Check if a Swedish personal identity number is for a male.
1126
+ *
1127
+ * @return {boolean}
1128
+ */
1129
+ isMale() {
1130
+ const sexDigit = parseInt(this.num.substr(-1));
1131
+ return sexDigit % 2 === 1;
1132
+ }
1133
+ };
1134
+ var src_default = Personnummer;
1135
+
1136
+ function createCommonjsModule(fn, basedir, module) {
1137
+ return module = {
1138
+ path: basedir,
1139
+ exports: {},
1140
+ require: function (path, base) {
1141
+ return commonjsRequire();
1142
+ }
1143
+ }, fn(module, module.exports), module.exports;
1144
+ }
1145
+
1146
+ function commonjsRequire () {
1147
+ throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
1148
+ }
1149
+
1150
+ var utf8 = createCommonjsModule(function (module, exports) {
1151
+ // tslint:disable:no-bitwise
1152
+ Object.defineProperty(exports, "__esModule", { value: true });
1153
+ exports.utf8 = void 0;
1154
+ exports.utf8 = {
1155
+ encode: encode,
1156
+ decode: decode,
1157
+ };
1158
+ function encode(unicodeText) {
1159
+ unicodeText = unicodeText.replace(/\r\n/g, "\n");
1160
+ var result = "";
1161
+ for (var i = 0; i < unicodeText.length; i++) {
1162
+ var char = unicodeText.charCodeAt(i);
1163
+ if (char < 128) {
1164
+ result += String.fromCharCode(char);
1165
+ }
1166
+ else if (char > 127 && char < 2048) {
1167
+ result += String.fromCharCode((char >> 6) | 192);
1168
+ result += String.fromCharCode((char & 63) | 128);
1169
+ }
1170
+ else {
1171
+ result += String.fromCharCode((char >> 12) | 224);
1172
+ result += String.fromCharCode(((char >> 6) & 63) | 128);
1173
+ result += String.fromCharCode((char & 63) | 128);
1174
+ }
1175
+ }
1176
+ return result;
1177
+ }
1178
+ function decode(utf8Text) {
1179
+ var result = "";
1180
+ var i = 0;
1181
+ var char1 = 0;
1182
+ var char2 = 0;
1183
+ var char3 = 0;
1184
+ while (i < utf8Text.length) {
1185
+ char1 = utf8Text.charCodeAt(i);
1186
+ if (char1 < 128) {
1187
+ result += String.fromCharCode(char1);
1188
+ i++;
1189
+ }
1190
+ else if (char1 > 191 && char1 < 224) {
1191
+ char2 = utf8Text.charCodeAt(i + 1);
1192
+ result += String.fromCharCode(((char1 & 31) << 6) | (char2 & 63));
1193
+ i += 2;
1194
+ }
1195
+ else {
1196
+ char2 = utf8Text.charCodeAt(i + 1);
1197
+ char3 = utf8Text.charCodeAt(i + 2);
1198
+ result += String.fromCharCode(((char1 & 15) << 12) | ((char2 & 63) << 6) | (char3 & 63));
1199
+ i += 3;
1200
+ }
1201
+ }
1202
+ return result;
1203
+ }
1204
+ });
1205
+
1206
+ var md5 = createCommonjsModule(function (module, exports) {
1207
+ // tslint:disable:no-bitwise
1208
+ Object.defineProperty(exports, "__esModule", { value: true });
1209
+ exports.generate = void 0;
1210
+
1211
+ function generate(unicodeText) {
1212
+ var x = [];
1213
+ var k;
1214
+ var AA;
1215
+ var BB;
1216
+ var CC;
1217
+ var DD;
1218
+ var a;
1219
+ var b;
1220
+ var c;
1221
+ var d;
1222
+ var S11 = 7;
1223
+ var S12 = 12;
1224
+ var S13 = 17;
1225
+ var S14 = 22;
1226
+ var S21 = 5;
1227
+ var S22 = 9;
1228
+ var S23 = 14;
1229
+ var S24 = 20;
1230
+ var S31 = 4;
1231
+ var S32 = 11;
1232
+ var S33 = 16;
1233
+ var S34 = 23;
1234
+ var S41 = 6;
1235
+ var S42 = 10;
1236
+ var S43 = 15;
1237
+ var S44 = 21;
1238
+ var utf8Text = utf8.utf8.encode(unicodeText);
1239
+ x = convertToWordArray(utf8Text);
1240
+ a = 0x67452301;
1241
+ b = 0xefcdab89;
1242
+ c = 0x98badcfe;
1243
+ d = 0x10325476;
1244
+ for (k = 0; k < x.length; k += 16) {
1245
+ AA = a;
1246
+ BB = b;
1247
+ CC = c;
1248
+ DD = d;
1249
+ a = FF(a, b, c, d, x[k + 0], S11, 0xd76aa478);
1250
+ d = FF(d, a, b, c, x[k + 1], S12, 0xe8c7b756);
1251
+ c = FF(c, d, a, b, x[k + 2], S13, 0x242070db);
1252
+ b = FF(b, c, d, a, x[k + 3], S14, 0xc1bdceee);
1253
+ a = FF(a, b, c, d, x[k + 4], S11, 0xf57c0faf);
1254
+ d = FF(d, a, b, c, x[k + 5], S12, 0x4787c62a);
1255
+ c = FF(c, d, a, b, x[k + 6], S13, 0xa8304613);
1256
+ b = FF(b, c, d, a, x[k + 7], S14, 0xfd469501);
1257
+ a = FF(a, b, c, d, x[k + 8], S11, 0x698098d8);
1258
+ d = FF(d, a, b, c, x[k + 9], S12, 0x8b44f7af);
1259
+ c = FF(c, d, a, b, x[k + 10], S13, 0xffff5bb1);
1260
+ b = FF(b, c, d, a, x[k + 11], S14, 0x895cd7be);
1261
+ a = FF(a, b, c, d, x[k + 12], S11, 0x6b901122);
1262
+ d = FF(d, a, b, c, x[k + 13], S12, 0xfd987193);
1263
+ c = FF(c, d, a, b, x[k + 14], S13, 0xa679438e);
1264
+ b = FF(b, c, d, a, x[k + 15], S14, 0x49b40821);
1265
+ a = GG(a, b, c, d, x[k + 1], S21, 0xf61e2562);
1266
+ d = GG(d, a, b, c, x[k + 6], S22, 0xc040b340);
1267
+ c = GG(c, d, a, b, x[k + 11], S23, 0x265e5a51);
1268
+ b = GG(b, c, d, a, x[k + 0], S24, 0xe9b6c7aa);
1269
+ a = GG(a, b, c, d, x[k + 5], S21, 0xd62f105d);
1270
+ d = GG(d, a, b, c, x[k + 10], S22, 0x2441453);
1271
+ c = GG(c, d, a, b, x[k + 15], S23, 0xd8a1e681);
1272
+ b = GG(b, c, d, a, x[k + 4], S24, 0xe7d3fbc8);
1273
+ a = GG(a, b, c, d, x[k + 9], S21, 0x21e1cde6);
1274
+ d = GG(d, a, b, c, x[k + 14], S22, 0xc33707d6);
1275
+ c = GG(c, d, a, b, x[k + 3], S23, 0xf4d50d87);
1276
+ b = GG(b, c, d, a, x[k + 8], S24, 0x455a14ed);
1277
+ a = GG(a, b, c, d, x[k + 13], S21, 0xa9e3e905);
1278
+ d = GG(d, a, b, c, x[k + 2], S22, 0xfcefa3f8);
1279
+ c = GG(c, d, a, b, x[k + 7], S23, 0x676f02d9);
1280
+ b = GG(b, c, d, a, x[k + 12], S24, 0x8d2a4c8a);
1281
+ a = HH(a, b, c, d, x[k + 5], S31, 0xfffa3942);
1282
+ d = HH(d, a, b, c, x[k + 8], S32, 0x8771f681);
1283
+ c = HH(c, d, a, b, x[k + 11], S33, 0x6d9d6122);
1284
+ b = HH(b, c, d, a, x[k + 14], S34, 0xfde5380c);
1285
+ a = HH(a, b, c, d, x[k + 1], S31, 0xa4beea44);
1286
+ d = HH(d, a, b, c, x[k + 4], S32, 0x4bdecfa9);
1287
+ c = HH(c, d, a, b, x[k + 7], S33, 0xf6bb4b60);
1288
+ b = HH(b, c, d, a, x[k + 10], S34, 0xbebfbc70);
1289
+ a = HH(a, b, c, d, x[k + 13], S31, 0x289b7ec6);
1290
+ d = HH(d, a, b, c, x[k + 0], S32, 0xeaa127fa);
1291
+ c = HH(c, d, a, b, x[k + 3], S33, 0xd4ef3085);
1292
+ b = HH(b, c, d, a, x[k + 6], S34, 0x4881d05);
1293
+ a = HH(a, b, c, d, x[k + 9], S31, 0xd9d4d039);
1294
+ d = HH(d, a, b, c, x[k + 12], S32, 0xe6db99e5);
1295
+ c = HH(c, d, a, b, x[k + 15], S33, 0x1fa27cf8);
1296
+ b = HH(b, c, d, a, x[k + 2], S34, 0xc4ac5665);
1297
+ a = II(a, b, c, d, x[k + 0], S41, 0xf4292244);
1298
+ d = II(d, a, b, c, x[k + 7], S42, 0x432aff97);
1299
+ c = II(c, d, a, b, x[k + 14], S43, 0xab9423a7);
1300
+ b = II(b, c, d, a, x[k + 5], S44, 0xfc93a039);
1301
+ a = II(a, b, c, d, x[k + 12], S41, 0x655b59c3);
1302
+ d = II(d, a, b, c, x[k + 3], S42, 0x8f0ccc92);
1303
+ c = II(c, d, a, b, x[k + 10], S43, 0xffeff47d);
1304
+ b = II(b, c, d, a, x[k + 1], S44, 0x85845dd1);
1305
+ a = II(a, b, c, d, x[k + 8], S41, 0x6fa87e4f);
1306
+ d = II(d, a, b, c, x[k + 15], S42, 0xfe2ce6e0);
1307
+ c = II(c, d, a, b, x[k + 6], S43, 0xa3014314);
1308
+ b = II(b, c, d, a, x[k + 13], S44, 0x4e0811a1);
1309
+ a = II(a, b, c, d, x[k + 4], S41, 0xf7537e82);
1310
+ d = II(d, a, b, c, x[k + 11], S42, 0xbd3af235);
1311
+ c = II(c, d, a, b, x[k + 2], S43, 0x2ad7d2bb);
1312
+ b = II(b, c, d, a, x[k + 9], S44, 0xeb86d391);
1313
+ a = addUnsigned(a, AA);
1314
+ b = addUnsigned(b, BB);
1315
+ c = addUnsigned(c, CC);
1316
+ d = addUnsigned(d, DD);
1317
+ }
1318
+ return wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d);
1319
+ }
1320
+ exports.generate = generate;
1321
+ function rotateLeft(lValue, iShiftBits) {
1322
+ return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits));
1323
+ }
1324
+ function addUnsigned(lX, lY) {
1325
+ var lX4;
1326
+ var lY4;
1327
+ var lX8;
1328
+ var lY8;
1329
+ var lResult;
1330
+ lX8 = lX & 0x80000000;
1331
+ lY8 = lY & 0x80000000;
1332
+ lX4 = lX & 0x40000000;
1333
+ lY4 = lY & 0x40000000;
1334
+ lResult = (lX & 0x3fffffff) + (lY & 0x3fffffff);
1335
+ if (lX4 & lY4) {
1336
+ return lResult ^ 0x80000000 ^ lX8 ^ lY8;
1337
+ }
1338
+ if (lX4 | lY4) {
1339
+ if (lResult & 0x40000000) {
1340
+ return lResult ^ 0xc0000000 ^ lX8 ^ lY8;
1341
+ }
1342
+ else {
1343
+ return lResult ^ 0x40000000 ^ lX8 ^ lY8;
1344
+ }
1345
+ }
1346
+ else {
1347
+ return lResult ^ lX8 ^ lY8;
1348
+ }
1349
+ }
1350
+ function F(x, y, z) {
1351
+ return (x & y) | (~x & z);
1352
+ }
1353
+ function G(x, y, z) {
1354
+ return (x & z) | (y & ~z);
1355
+ }
1356
+ function H(x, y, z) {
1357
+ return x ^ y ^ z;
1358
+ }
1359
+ function I(x, y, z) {
1360
+ return y ^ (x | ~z);
1361
+ }
1362
+ function FF(a, b, c, d, x, s, ac) {
1363
+ a = addUnsigned(a, addUnsigned(addUnsigned(F(b, c, d), x), ac));
1364
+ return addUnsigned(rotateLeft(a, s), b);
1365
+ }
1366
+ function GG(a, b, c, d, x, s, ac) {
1367
+ a = addUnsigned(a, addUnsigned(addUnsigned(G(b, c, d), x), ac));
1368
+ return addUnsigned(rotateLeft(a, s), b);
1369
+ }
1370
+ function HH(a, b, c, d, x, s, ac) {
1371
+ a = addUnsigned(a, addUnsigned(addUnsigned(H(b, c, d), x), ac));
1372
+ return addUnsigned(rotateLeft(a, s), b);
1373
+ }
1374
+ function II(a, b, c, d, x, s, ac) {
1375
+ a = addUnsigned(a, addUnsigned(addUnsigned(I(b, c, d), x), ac));
1376
+ return addUnsigned(rotateLeft(a, s), b);
1377
+ }
1378
+ function convertToWordArray(value) {
1379
+ var lWordCount;
1380
+ var lMessageLength = value.length;
1381
+ var lNumberOfWordsTemp1 = lMessageLength + 8;
1382
+ var lNumberOfWordsTemp2 = (lNumberOfWordsTemp1 - (lNumberOfWordsTemp1 % 64)) / 64;
1383
+ var lNumberOfWords = (lNumberOfWordsTemp2 + 1) * 16;
1384
+ var lWordArray = Array(lNumberOfWords - 1);
1385
+ var lBytePosition = 0;
1386
+ var lByteCount = 0;
1387
+ while (lByteCount < lMessageLength) {
1388
+ lWordCount = (lByteCount - (lByteCount % 4)) / 4;
1389
+ lBytePosition = (lByteCount % 4) * 8;
1390
+ lWordArray[lWordCount] =
1391
+ lWordArray[lWordCount] | (value.charCodeAt(lByteCount) << lBytePosition);
1392
+ lByteCount++;
1393
+ }
1394
+ lWordCount = (lByteCount - (lByteCount % 4)) / 4;
1395
+ lBytePosition = (lByteCount % 4) * 8;
1396
+ lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
1397
+ lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
1398
+ lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
1399
+ return lWordArray;
1400
+ }
1401
+ function wordToHex(lValue) {
1402
+ var wordToHexValue = "";
1403
+ var wordToHexValueTemp = "";
1404
+ var lByte;
1405
+ var lCount;
1406
+ for (lCount = 0; lCount <= 3; lCount++) {
1407
+ lByte = (lValue >>> (lCount * 8)) & 255;
1408
+ wordToHexValueTemp = "0" + lByte.toString(16);
1409
+ wordToHexValue =
1410
+ wordToHexValue + wordToHexValueTemp.substr(wordToHexValueTemp.length - 2, 2);
1411
+ }
1412
+ return wordToHexValue;
1413
+ }
1414
+ });
1415
+
1416
+ var lib = createCommonjsModule(function (module, exports) {
1417
+ Object.defineProperty(exports, "__esModule", { value: true });
1418
+ exports.MD5 = exports.generate = void 0;
1419
+
1420
+ var md5_2 = md5;
1421
+ Object.defineProperty(exports, "generate", { enumerable: true, get: function () { return md5_2.generate; } });
1422
+ exports.MD5 = {
1423
+ generate: md5.generate,
1424
+ };
1425
+ });
1426
+
1427
+ const apiSearch = async (query) => {
1428
+ var _a;
1429
+ const res = await fetch((_a = "https://hemfixare-lookup-dev.vercel.app/api") !== null && _a !== void 0 ? _a : 'https://hemfixare-lookup.vercel.app/api', {
1430
+ method: 'POST',
1431
+ headers: {
1432
+ 'Content-Type': 'application/json',
1433
+ },
1434
+ body: JSON.stringify({
1435
+ query,
1436
+ hash: lib.MD5.generate(String.fromCharCode(83, 101, 67, 82, 101, 116) + query),
1437
+ }),
1438
+ });
1439
+ const data = await res.json();
1440
+ return data;
1441
+ };
1442
+
1443
+ const HemfixarnaGetuser = class {
1444
+ constructor(hostRef) {
1445
+ index.registerInstance(this, hostRef);
1446
+ this.handleChangeEmail = (e) => {
1447
+ this.emailError = null;
1448
+ this.email = e.target.value;
1449
+ };
1450
+ this.handleChangePhone = (e) => {
1451
+ this.phoneError = null;
1452
+ this.phone = e.target.value;
1453
+ };
1454
+ this.handleChangessn = (e) => {
1455
+ this.ssnError = null;
1456
+ this.ssn = e.target.value;
1457
+ };
1458
+ this.handleSubmit = async (e) => {
1459
+ e.preventDefault();
1460
+ 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,}))$/);
1461
+ const validEmail = emailRegex.test(this.email);
1462
+ if (!validEmail) {
1463
+ this.emailError = 'Ange en giltig e-postadress';
1464
+ }
1465
+ const validPhone = this.phone.length > 6;
1466
+ if (!validPhone) {
1467
+ this.phoneError = 'Ange ett giltigt telefonnummer';
1468
+ }
1469
+ const validssn = src_default.valid(this.ssn);
1470
+ if (!validssn) {
1471
+ this.ssnError = 'Ange ett giltigt personnummer';
1472
+ }
1473
+ else if (validssn) {
1474
+ const pn = src_default.parse(this.ssn).format(true);
1475
+ this.ssn = [pn.slice(0, 8), '-', pn.slice(8)].join('');
1476
+ }
1477
+ if (validEmail && validPhone && validssn) {
1478
+ try {
1479
+ const user = await apiSearch(this.ssn);
1480
+ if (user) {
1481
+ state.checkoutStep = 2;
1482
+ state.user = Object.assign(Object.assign({}, user), { email: this.email, phone: this.phone, ssn: this.ssn });
1483
+ }
1484
+ else {
1485
+ this.ssnError = 'Vi kunde tyvärr inte hitta en address med ditt angivna personnummer';
1486
+ }
1487
+ }
1488
+ catch (e) {
1489
+ this.ssnError = 'Vi kunde tyvärr inte hitta en address med ditt angivna personnummer';
1490
+ console.log(e);
1491
+ }
1492
+ }
1493
+ };
1494
+ this.render = () => {
1495
+ return (index.h("form", { class: "mb-2", onSubmit: e => this.handleSubmit(e) }, index.h("div", null, index.h("input", { class: `${this.email.length ? 'input_active' : ''}`, onChange: e => this.handleChangeEmail(e), type: "email", name: "email", value: this.email }), index.h("label", { htmlFor: "email" }, "E-post ")), this.emailError && index.h("span", null, this.emailError), index.h("div", null, index.h("input", { class: `${this.phone.length ? 'input_active' : ''}`, onChange: e => this.handleChangePhone(e), type: "tel", name: "phone", value: this.phone }), index.h("label", { htmlFor: "phone" }, "Mobiltelefon ")), this.phoneError && index.h("span", null, this.phoneError), index.h("div", null, index.h("input", { class: `${this.ssn.length ? 'input_active' : ''}`, onChange: e => this.handleChangessn(e), type: "tel", name: "ssn", value: this.ssn }), index.h("label", { htmlFor: "phone" }, "Personnummer*")), this.ssnError && index.h("span", null, this.ssnError), index.h("input", { type: "submit", value: "Forts\u00E4tt och Boka*" }), index.h("p", null, "*Vi h\u00E4mtar din adress")));
1496
+ };
1497
+ this.email = '';
1498
+ this.emailError = null;
1499
+ this.phone = '';
1500
+ this.phoneError = null;
1501
+ this.ssn = '';
1502
+ this.ssnError = null;
1503
+ }
1504
+ componentWillLoad() {
1505
+ if (state.user) {
1506
+ this.email = state.user.email;
1507
+ this.phone = state.user.phone;
1508
+ this.ssn = state.user.ssn;
1509
+ }
1510
+ }
1511
+ };
1512
+
1513
+ const HemfixarnaInfo = class {
1514
+ constructor(hostRef) {
1515
+ index.registerInstance(this, hostRef);
1516
+ this.logo = index.getAssetPath(`./assets/hemfixarna.svg`);
1517
+ this.checkoutList = [
1518
+ { trust_badge: 'Efter att du fyllt i formuläret blir du kontaktad av en Hemfixare för bokning av tid.' },
1519
+ { trust_badge: 'När jobbet är klart kommer du få en faktura med RUT/ROT-avdrag.' },
1520
+ ];
1521
+ this.list = null;
1522
+ }
1523
+ getList() {
1524
+ return this.list ? this.list : this.checkoutList;
1525
+ }
1526
+ render() {
1527
+ const checked = index.getAssetPath(`./assets/checked.svg`);
1528
+ return (index.h("div", { class: "hemfixarna_info" }, state.step < 5 ? (index.h(index.Fragment, null, index.h("h2", null, "Vilka \u00E4r Hemfixarna?"), index.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."))) : (index.h("h2", null, "Vad h\u00E4nder nu?")), index.h("ul", { class: "hemfixarna_features" }, this.getList().map(l => (index.h("li", { key: l.trust_badge }, index.h("img", { src: checked, alt: "checked" }), index.h("p", null, l.trust_badge))))), index.h("img", { src: this.logo, width: 200, alt: "hemfixarna" }), index.h("a", { class: "hemfixarna_product--link", target: "_blank", href: state.options.link.url }, state.options.link.title)));
1529
+ }
1530
+ };
1531
+
1532
+ const HemfixarnaOrder = class {
1533
+ constructor(hostRef) {
1534
+ index.registerInstance(this, hostRef);
1535
+ this.render = () => {
1536
+ return (index.h("div", { style: { background: `url(${state.options.thank_you_image})` }, class: "hemfixarna_order" }, index.h("div", null), index.h("div", null, index.h("h2", null, "Tack f\u00F6r din bokning"), index.h("hemfixarna-orderrows", { tree: this.tree, cart: false }), index.h("span", { onClick: () => this.resetShop() }, index.h("button", null, "G\u00F6r en ny bokning")), index.h("hemfixarna-info", { list: [
1537
+ { trust_badge: 'Du kommer bli kontaktad av en Hemfixare för bokning av tid.' },
1538
+ { trust_badge: 'När jobbet är klart kommer du få en faktura med RUT/ROT-avdrag.' },
1539
+ ] }))));
1540
+ };
1541
+ this.tree = undefined;
1542
+ }
1543
+ resetShop() {
1544
+ state.step = 1;
1545
+ state.cart = [];
1546
+ state.selectedCategory = null;
1547
+ state.selectedService = null;
1548
+ state.selectedProduct = null;
1549
+ state.checkoutStep = 1;
1550
+ }
1551
+ disconnectedCallback() {
1552
+ this.resetShop();
1553
+ }
1554
+ };
1555
+
1556
+ const HemfixarnaOrderrows = class {
1557
+ constructor(hostRef) {
1558
+ index.registerInstance(this, hostRef);
1559
+ this.cart = true;
1560
+ this.tree = undefined;
1561
+ }
1562
+ goToProduct(id) {
1563
+ const services = this.tree.sub_cats.map((c) => c.services).flat();
1564
+ const products = services.map((s) => s.products).flat();
1565
+ const product = products.find((p) => p.ID === id);
1566
+ const service = services.find((s) => s.products.find((p) => p.ID === id));
1567
+ const category = this.tree.sub_cats.find((c) => c.services.find((s) => s.products.find((p) => p.ID === id)));
1568
+ state.selectedCategory = category;
1569
+ state.selectedService = service;
1570
+ state.selectedProduct = product;
1571
+ state.step = 4;
1572
+ }
1573
+ openMontering() {
1574
+ state.modal = {
1575
+ title: 'Monteringsavgift',
1576
+ text: [
1577
+ 'Monteringsavgiften är en fast avgift som läggs på din beställning. Avgiften täcker kostnader för att montera produkterna du beställer.',
1578
+ 'Monteringsavgiften debiteras per påbörjat nytt uppdrag. Om du bokar ett uppdrag som både innehåller RUT- och ROT-avdrag så kommer uppdraget att delas upp och således kommer två monteringsavgifter att debiteras och två fakturor att utställas.',
1579
+ ],
1580
+ };
1581
+ }
1582
+ render() {
1583
+ const info = index.getAssetPath(`./assets/info.svg`);
1584
+ return (index.h(index.Fragment, null, index.h("ul", { class: "hemfixarna_cart--items" }, state.cart.map(item => {
1585
+ var _a;
1586
+ return (index.h("li", { class: "hemfixarna_cart--item" }, index.h("div", null, index.h("div", null, item.icon && index.h("img", { width: 30, src: (_a = item.icon.url) !== null && _a !== void 0 ? _a : item.icon, alt: item.name }), index.h("p", null, index.h("strong", null, item.amount, "x "), item.name)), this.cart && index.h("button", { onClick: () => this.goToProduct(item.id) }, "\u00C4ndra")), index.h("p", null, index.h("strong", null, getProductPrice(item, item.price, item.amount), "kr")), item.parts.length > 0 && (index.h("ul", null, item.parts.map(part => (index.h("li", null, index.h("p", null, index.h("strong", null, part.amount, "x "), part.name), index.h("p", null, index.h("strong", null, getPartPrice(part, item, part.amount), "kr")))))))));
1587
+ })), index.h("div", { class: "hemfixarna_cart--additional" }, getStartFee().length > 0 && (index.h("div", { class: "hemfixarna_cart--startfee" }, index.h("p", null, getStartFee().length, "x", ' ', index.h("strong", { onClick: () => this.openMontering() }, "Monteringsavgift", index.h("img", { height: 16, src: info, alt: "info monteringsavgift" }))), index.h("p", null, getStartFee().rot + getStartFee().rut, "kr"))), state.cart.find((item) => item.rot) && (index.h("div", { class: "hemfixarna_cart--rutrot" }, index.h("div", null, this.cart && (index.h("label", { class: "switch" }, index.h("input", { checked: state.rot, onChange: () => (state.rot = !state.rot), type: "checkbox" }), index.h("span", { class: "slider" }))), index.h("p", null, "ROT-avdrag")), index.h("p", null, "(-", state.rot ? calculateRot() : 0, "kr)"))), state.cart.find((item) => item.rut) && (index.h("div", { class: "hemfixarna_cart--rutrot" }, index.h("div", null, index.h("label", { class: "switch" }, index.h("input", { onChange: () => (state.rut = !state.rut), checked: state.rut, type: "checkbox" }), index.h("span", { class: "slider" })), index.h("p", null, "RUT-avdrag")), index.h("p", null, "(-", state.rut ? calculateRut() : 0, "kr)")))), index.h("div", { class: "hemfixarna_cart--price" }, index.h("h2", null, "Totalbelopp: "), index.h("h2", null, getTotalPrice(), "kr"))));
1588
+ }
1589
+ };
1590
+
1591
+ const HemfixarnaProduct = class {
1592
+ constructor(hostRef) {
1593
+ index.registerInstance(this, hostRef);
1594
+ this.amount = 0;
1595
+ }
1596
+ addProduct() {
1597
+ const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);
1598
+ if (productInCart) {
1599
+ productInCart.amount++;
1600
+ state.cart = [...state.cart];
1601
+ }
1602
+ else {
1603
+ state.cart = [
1604
+ ...state.cart,
1605
+ {
1606
+ id: state.selectedProduct.ID,
1607
+ rut: state.selectedProduct.rut,
1608
+ rot: state.selectedProduct.rot,
1609
+ amount: 1,
1610
+ parts: [],
1611
+ price: state.selectedProduct.price,
1612
+ name: state.selectedProduct.post_title,
1613
+ start_fee: !state.selectedProduct.start_fee,
1614
+ terms_checkout: state.selectedProduct.terms_checkout,
1615
+ terms_show_checkbox: state.selectedProduct.terms_show_checkbox,
1616
+ icon: state.selectedProduct.icon,
1617
+ },
1618
+ ];
1619
+ }
1620
+ }
1621
+ removeProduct() {
1622
+ const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);
1623
+ if (productInCart && productInCart.amount > 1) {
1624
+ productInCart.amount--;
1625
+ state.cart = [...state.cart];
1626
+ }
1627
+ else {
1628
+ state.cart = state.cart.filter(p => p.id !== state.selectedProduct.ID);
1629
+ }
1630
+ }
1631
+ //Handle cart and parts
1632
+ addPart(part) {
1633
+ const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);
1634
+ if (productInCart) {
1635
+ const partInCart = productInCart.parts.find(sp => sp.id === part.ID);
1636
+ if (partInCart) {
1637
+ partInCart.amount++;
1638
+ productInCart.parts = [...productInCart.parts];
1639
+ }
1640
+ else {
1641
+ productInCart.parts = [...productInCart.parts, { id: part.ID, amount: 1, price: part.price, name: part.post_title }];
1642
+ }
1643
+ state.cart = [...state.cart.filter(p => p.id !== productInCart.id), productInCart];
1644
+ }
1645
+ }
1646
+ removePart(part) {
1647
+ const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);
1648
+ if (productInCart) {
1649
+ const partInCart = productInCart.parts.find(sp => sp.id === part.ID);
1650
+ if (partInCart && partInCart.amount > 1) {
1651
+ partInCart.amount--;
1652
+ productInCart.parts = [...productInCart.parts];
1653
+ }
1654
+ else {
1655
+ productInCart.parts = productInCart.parts.filter(sp => sp.id !== part.ID);
1656
+ }
1657
+ state.cart = [...state.cart.filter(p => p.id !== productInCart.id), productInCart];
1658
+ }
1659
+ }
1660
+ goToCart() {
1661
+ const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);
1662
+ if (productInCart) {
1663
+ state.step = 5;
1664
+ }
1665
+ }
1666
+ getAmount() {
1667
+ var _a;
1668
+ return ((_a = state.cart.find(p => p.id === state.selectedProduct.ID)) === null || _a === void 0 ? void 0 : _a.amount) || 0;
1669
+ }
1670
+ getPartAmount(partId) {
1671
+ var _a;
1672
+ const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);
1673
+ 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;
1674
+ }
1675
+ getTotalPrice() {
1676
+ let price = 0;
1677
+ const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);
1678
+ if (productInCart) {
1679
+ const partsPrice = productInCart.parts.reduce((acc, curr) => {
1680
+ const part = state.selectedProduct.parts.find(p => p.ID === curr.id);
1681
+ if (part) {
1682
+ return acc + part.price * curr.amount;
1683
+ }
1684
+ return acc;
1685
+ }, 0);
1686
+ price = state.selectedProduct.price * productInCart.amount + partsPrice;
1687
+ }
1688
+ else {
1689
+ price = state.selectedProduct.price;
1690
+ }
1691
+ return getProductPrice(state.selectedProduct, price);
1692
+ }
1693
+ render() {
1694
+ var _a, _b, _c;
1695
+ const checked = index.getAssetPath(`./assets/checked.svg`);
1696
+ const plus = index.getAssetPath(`./assets/plus.svg`);
1697
+ const minus = index.getAssetPath(`./assets/minus.svg`);
1698
+ return (index.h("div", { class: "hemfixarna_product" }, index.h("div", { class: "hemfixarna_product--top" }, state.selectedProduct.icon && (index.h("img", { width: 80, src: (_a = state.selectedProduct.icon.url) !== null && _a !== void 0 ? _a : state.selectedProduct.icon, alt: state.selectedProduct.post_title })), index.h("div", null, index.h("h1", null, state.selectedProduct.post_title), index.h("h2", null, "Fr\u00E5n: ", getProductPrice(state.selectedProduct), " kr"))), index.h("div", { class: "hemfixarna_product--grid" }, index.h("div", { class: "hemfixarna_product--left" }, ((_b = state.selectedProduct.list) === null || _b === void 0 ? void 0 : _b.length) && (index.h("ul", { class: "hemfixarna_features" }, state.selectedProduct.list.map(l => (index.h("li", { key: l.bullet }, index.h("img", { src: checked, alt: "checked" }), index.h("p", null, l.bullet)))))), index.h("p", { class: "hemfixarna_terms" }, index.h("strong", null, "OBS! "), index.h("span", { innerHTML: state.selectedProduct.terms }))), index.h("div", { class: "hemfixarna_product--right" }, index.h("ul", null, index.h("li", { class: "hemfixarna_product--item" }, index.h("div", null, index.h("p", null, "Antal ", state.selectedProduct.post_title), index.h("p", { class: "hemfixarna_product--price" }, getProductPrice(state.selectedProduct), "kr/st")), index.h("div", { class: "hemfixarna_counter" }, index.h("img", { class: `${this.getAmount() === 0 ? 'disabled' : ''}`, src: minus, onClick: () => this.removeProduct() }), index.h("span", null, this.getAmount()), index.h("img", { src: plus, onClick: () => this.addProduct() }))), ((_c = state.selectedProduct.parts) === null || _c === void 0 ? void 0 : _c.length) &&
1699
+ state.selectedProduct.parts.map(p => (index.h("li", { class: "hemfixarna_part" }, index.h("div", null, index.h("p", null, p.post_title), index.h("p", { class: "hemfixarna_product--price" }, getPartPrice(p, state.selectedProduct), "kr/st")), index.h("div", { class: "hemfixarna_counter" }, index.h("img", { class: `${this.getPartAmount(p.ID) === 0 ? 'disabled' : ''}`, src: minus, onClick: () => this.removePart(p) }), index.h("span", null, this.getPartAmount(p.ID)), index.h("img", { class: `${this.getAmount() === 0 ? 'disabled' : ''}`, src: plus, onClick: () => this.addPart(p) })))))), index.h("h4", { class: "hemfixarna_product--total" }, "Totalt ", this.getTotalPrice(), " kr"), index.h("button", { onClick: () => this.goToCart(), class: `hemfixarna_buy ${this.getAmount() === 0 ? 'disabled' : ''}` }, "Boka"), state.options && index.h("hemfixarna-info", { list: state.options.trust })))));
1700
+ }
1701
+ };
1702
+
1703
+ const HemfixarnaService = class {
1704
+ constructor(hostRef) {
1705
+ index.registerInstance(this, hostRef);
1706
+ }
1707
+ setSelectedProduct(product) {
1708
+ state.selectedProduct = product;
1709
+ state.step = 4;
1710
+ }
1711
+ render() {
1712
+ return (index.h("div", null, index.h("h2", null, state.selectedService.post_title), index.h("div", { class: "hemfixarna_categories--wrapper" }, index.h("div", null, index.h("ul", { class: "hemfixarna_categories" }, state.selectedService.products
1713
+ .sort((a, b) => (a.post_title < b.post_title ? -1 : 1))
1714
+ .map(p => {
1715
+ var _a;
1716
+ return (index.h("hemfixarna-box", { post: p, icon: (_a = p.icon.url) !== null && _a !== void 0 ? _a : p.icon, postTitle: p.post_title }));
1717
+ }))), index.h("hemfixarna-info", { list: state.options.trust }))));
1718
+ }
1719
+ };
1720
+
1721
+ const HemfixarnaGrid = class {
1722
+ constructor(hostRef) {
1723
+ index.registerInstance(this, hostRef);
1724
+ this.tree = undefined;
1725
+ }
1726
+ render() {
1727
+ return (index.h("div", null, index.h("h2", null, "Alla tj\u00E4nster"), index.h("div", { class: "hemfixarna_categories--wrapper" }, index.h("ul", { class: "hemfixarna_categories" }, this.tree.sub_cats
1728
+ .sort((a, b) => (a.name < b.name ? -1 : 1))
1729
+ .map(c => {
1730
+ var _a;
1731
+ return (index.h("hemfixarna-box", { post: c, icon: (_a = c.icon.url) !== null && _a !== void 0 ? _a : c.icon, postTitle: c.name }));
1732
+ })), index.h("hemfixarna-info", { list: state.options.trust }))));
1733
+ }
1734
+ };
1735
+
1736
+ exports.hemfixarna_address = HemfixarnaAddress;
1737
+ exports.hemfixarna_box = HemfixarnaBox;
1738
+ exports.hemfixarna_breadcrumbs = HemfixarnaBreadcrumbs;
1739
+ exports.hemfixarna_byggmax = MyComponent$1;
1740
+ exports.hemfixarna_cart = HemfixarnaCart;
1741
+ exports.hemfixarna_category = HemfixarnaCategory;
1742
+ exports.hemfixarna_checkout = HemfixarnaCheckout;
1743
+ exports.hemfixarna_component = HemfixarnaComponent;
1744
+ exports.hemfixarna_demo = MyComponent;
1745
+ exports.hemfixarna_getuser = HemfixarnaGetuser;
1746
+ exports.hemfixarna_info = HemfixarnaInfo;
1747
+ exports.hemfixarna_order = HemfixarnaOrder;
1748
+ exports.hemfixarna_orderrows = HemfixarnaOrderrows;
1749
+ exports.hemfixarna_product = HemfixarnaProduct;
1750
+ exports.hemfixarna_service = HemfixarnaService;
1751
+ exports.hemfixarna_start = HemfixarnaGrid;
1752
+
1753
+ //# sourceMappingURL=hemfixarna-address_16.cjs.entry.js.map