@magicfeedback/popup-sdk 1.0.0

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.
package/dist/index.mjs ADDED
@@ -0,0 +1,2251 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+
27
+ // node_modules/@magicfeedback/native/dist/magicfeedback-sdk.browser.js
28
+ var require_magicfeedback_sdk_browser = __commonJS({
29
+ "node_modules/@magicfeedback/native/dist/magicfeedback-sdk.browser.js"(exports, module) {
30
+ "use strict";
31
+ !(function(e, t) {
32
+ "object" == typeof exports && "object" == typeof module ? module.exports = t() : "function" == typeof define && define.amd ? define([], t) : "object" == typeof exports ? exports.magicfeedback = t() : e.magicfeedback = t();
33
+ })(self, (() => {
34
+ return e = { 945: function(e2, t2) {
35
+ var i = "undefined" != typeof self ? self : this, n = (function() {
36
+ function e3() {
37
+ this.fetch = false, this.DOMException = i.DOMException;
38
+ }
39
+ return e3.prototype = i, new e3();
40
+ })();
41
+ !(function(e3) {
42
+ !(function(t3) {
43
+ var i2 = "URLSearchParams" in e3, n2 = "Symbol" in e3 && "iterator" in Symbol, a2 = "FileReader" in e3 && "Blob" in e3 && (function() {
44
+ try {
45
+ return new Blob(), true;
46
+ } catch (e4) {
47
+ return false;
48
+ }
49
+ })(), s = "FormData" in e3, r = "ArrayBuffer" in e3;
50
+ if (r) var o = ["[object Int8Array]", "[object Uint8Array]", "[object Uint8ClampedArray]", "[object Int16Array]", "[object Uint16Array]", "[object Int32Array]", "[object Uint32Array]", "[object Float32Array]", "[object Float64Array]"], l = ArrayBuffer.isView || function(e4) {
51
+ return e4 && o.indexOf(Object.prototype.toString.call(e4)) > -1;
52
+ };
53
+ function d(e4) {
54
+ if ("string" != typeof e4 && (e4 = String(e4)), /[^a-z0-9\-#$%&'*+.^_`|~]/i.test(e4)) throw new TypeError("Invalid character in header field name");
55
+ return e4.toLowerCase();
56
+ }
57
+ function c(e4) {
58
+ return "string" != typeof e4 && (e4 = String(e4)), e4;
59
+ }
60
+ function u(e4) {
61
+ var t4 = { next: function() {
62
+ var t5 = e4.shift();
63
+ return { done: void 0 === t5, value: t5 };
64
+ } };
65
+ return n2 && (t4[Symbol.iterator] = function() {
66
+ return t4;
67
+ }), t4;
68
+ }
69
+ function p(e4) {
70
+ this.map = {}, e4 instanceof p ? e4.forEach((function(e5, t4) {
71
+ this.append(t4, e5);
72
+ }), this) : Array.isArray(e4) ? e4.forEach((function(e5) {
73
+ this.append(e5[0], e5[1]);
74
+ }), this) : e4 && Object.getOwnPropertyNames(e4).forEach((function(t4) {
75
+ this.append(t4, e4[t4]);
76
+ }), this);
77
+ }
78
+ function h(e4) {
79
+ if (e4.bodyUsed) return Promise.reject(new TypeError("Already read"));
80
+ e4.bodyUsed = true;
81
+ }
82
+ function m(e4) {
83
+ return new Promise((function(t4, i3) {
84
+ e4.onload = function() {
85
+ t4(e4.result);
86
+ }, e4.onerror = function() {
87
+ i3(e4.error);
88
+ };
89
+ }));
90
+ }
91
+ function f(e4) {
92
+ var t4 = new FileReader(), i3 = m(t4);
93
+ return t4.readAsArrayBuffer(e4), i3;
94
+ }
95
+ function g(e4) {
96
+ if (e4.slice) return e4.slice(0);
97
+ var t4 = new Uint8Array(e4.byteLength);
98
+ return t4.set(new Uint8Array(e4)), t4.buffer;
99
+ }
100
+ function v() {
101
+ return this.bodyUsed = false, this._initBody = function(e4) {
102
+ var t4;
103
+ this._bodyInit = e4, e4 ? "string" == typeof e4 ? this._bodyText = e4 : a2 && Blob.prototype.isPrototypeOf(e4) ? this._bodyBlob = e4 : s && FormData.prototype.isPrototypeOf(e4) ? this._bodyFormData = e4 : i2 && URLSearchParams.prototype.isPrototypeOf(e4) ? this._bodyText = e4.toString() : r && a2 && (t4 = e4) && DataView.prototype.isPrototypeOf(t4) ? (this._bodyArrayBuffer = g(e4.buffer), this._bodyInit = new Blob([this._bodyArrayBuffer])) : r && (ArrayBuffer.prototype.isPrototypeOf(e4) || l(e4)) ? this._bodyArrayBuffer = g(e4) : this._bodyText = e4 = Object.prototype.toString.call(e4) : this._bodyText = "", this.headers.get("content-type") || ("string" == typeof e4 ? this.headers.set("content-type", "text/plain;charset=UTF-8") : this._bodyBlob && this._bodyBlob.type ? this.headers.set("content-type", this._bodyBlob.type) : i2 && URLSearchParams.prototype.isPrototypeOf(e4) && this.headers.set("content-type", "application/x-www-form-urlencoded;charset=UTF-8"));
104
+ }, a2 && (this.blob = function() {
105
+ var e4 = h(this);
106
+ if (e4) return e4;
107
+ if (this._bodyBlob) return Promise.resolve(this._bodyBlob);
108
+ if (this._bodyArrayBuffer) return Promise.resolve(new Blob([this._bodyArrayBuffer]));
109
+ if (this._bodyFormData) throw new Error("could not read FormData body as blob");
110
+ return Promise.resolve(new Blob([this._bodyText]));
111
+ }, this.arrayBuffer = function() {
112
+ return this._bodyArrayBuffer ? h(this) || Promise.resolve(this._bodyArrayBuffer) : this.blob().then(f);
113
+ }), this.text = function() {
114
+ var e4, t4, i3, n3 = h(this);
115
+ if (n3) return n3;
116
+ if (this._bodyBlob) return e4 = this._bodyBlob, i3 = m(t4 = new FileReader()), t4.readAsText(e4), i3;
117
+ if (this._bodyArrayBuffer) return Promise.resolve((function(e5) {
118
+ for (var t5 = new Uint8Array(e5), i4 = new Array(t5.length), n4 = 0; n4 < t5.length; n4++) i4[n4] = String.fromCharCode(t5[n4]);
119
+ return i4.join("");
120
+ })(this._bodyArrayBuffer));
121
+ if (this._bodyFormData) throw new Error("could not read FormData body as text");
122
+ return Promise.resolve(this._bodyText);
123
+ }, s && (this.formData = function() {
124
+ return this.text().then(b);
125
+ }), this.json = function() {
126
+ return this.text().then(JSON.parse);
127
+ }, this;
128
+ }
129
+ p.prototype.append = function(e4, t4) {
130
+ e4 = d(e4), t4 = c(t4);
131
+ var i3 = this.map[e4];
132
+ this.map[e4] = i3 ? i3 + ", " + t4 : t4;
133
+ }, p.prototype.delete = function(e4) {
134
+ delete this.map[d(e4)];
135
+ }, p.prototype.get = function(e4) {
136
+ return e4 = d(e4), this.has(e4) ? this.map[e4] : null;
137
+ }, p.prototype.has = function(e4) {
138
+ return this.map.hasOwnProperty(d(e4));
139
+ }, p.prototype.set = function(e4, t4) {
140
+ this.map[d(e4)] = c(t4);
141
+ }, p.prototype.forEach = function(e4, t4) {
142
+ for (var i3 in this.map) this.map.hasOwnProperty(i3) && e4.call(t4, this.map[i3], i3, this);
143
+ }, p.prototype.keys = function() {
144
+ var e4 = [];
145
+ return this.forEach((function(t4, i3) {
146
+ e4.push(i3);
147
+ })), u(e4);
148
+ }, p.prototype.values = function() {
149
+ var e4 = [];
150
+ return this.forEach((function(t4) {
151
+ e4.push(t4);
152
+ })), u(e4);
153
+ }, p.prototype.entries = function() {
154
+ var e4 = [];
155
+ return this.forEach((function(t4, i3) {
156
+ e4.push([i3, t4]);
157
+ })), u(e4);
158
+ }, n2 && (p.prototype[Symbol.iterator] = p.prototype.entries);
159
+ var y = ["DELETE", "GET", "HEAD", "OPTIONS", "POST", "PUT"];
160
+ function E(e4, t4) {
161
+ var i3, n3, a3 = (t4 = t4 || {}).body;
162
+ if (e4 instanceof E) {
163
+ if (e4.bodyUsed) throw new TypeError("Already read");
164
+ this.url = e4.url, this.credentials = e4.credentials, t4.headers || (this.headers = new p(e4.headers)), this.method = e4.method, this.mode = e4.mode, this.signal = e4.signal, a3 || null == e4._bodyInit || (a3 = e4._bodyInit, e4.bodyUsed = true);
165
+ } else this.url = String(e4);
166
+ if (this.credentials = t4.credentials || this.credentials || "same-origin", !t4.headers && this.headers || (this.headers = new p(t4.headers)), this.method = (n3 = (i3 = t4.method || this.method || "GET").toUpperCase(), y.indexOf(n3) > -1 ? n3 : i3), this.mode = t4.mode || this.mode || null, this.signal = t4.signal || this.signal, this.referrer = null, ("GET" === this.method || "HEAD" === this.method) && a3) throw new TypeError("Body not allowed for GET or HEAD requests");
167
+ this._initBody(a3);
168
+ }
169
+ function b(e4) {
170
+ var t4 = new FormData();
171
+ return e4.trim().split("&").forEach((function(e5) {
172
+ if (e5) {
173
+ var i3 = e5.split("="), n3 = i3.shift().replace(/\+/g, " "), a3 = i3.join("=").replace(/\+/g, " ");
174
+ t4.append(decodeURIComponent(n3), decodeURIComponent(a3));
175
+ }
176
+ })), t4;
177
+ }
178
+ function A(e4, t4) {
179
+ t4 || (t4 = {}), this.type = "default", this.status = void 0 === t4.status ? 200 : t4.status, this.ok = this.status >= 200 && this.status < 300, this.statusText = "statusText" in t4 ? t4.statusText : "OK", this.headers = new p(t4.headers), this.url = t4.url || "", this._initBody(e4);
180
+ }
181
+ E.prototype.clone = function() {
182
+ return new E(this, { body: this._bodyInit });
183
+ }, v.call(E.prototype), v.call(A.prototype), A.prototype.clone = function() {
184
+ return new A(this._bodyInit, { status: this.status, statusText: this.statusText, headers: new p(this.headers), url: this.url });
185
+ }, A.error = function() {
186
+ var e4 = new A(null, { status: 0, statusText: "" });
187
+ return e4.type = "error", e4;
188
+ };
189
+ var k = [301, 302, 303, 307, 308];
190
+ A.redirect = function(e4, t4) {
191
+ if (-1 === k.indexOf(t4)) throw new RangeError("Invalid status code");
192
+ return new A(null, { status: t4, headers: { location: e4 } });
193
+ }, t3.DOMException = e3.DOMException;
194
+ try {
195
+ new t3.DOMException();
196
+ } catch (e4) {
197
+ t3.DOMException = function(e5, t4) {
198
+ this.message = e5, this.name = t4;
199
+ var i3 = Error(e5);
200
+ this.stack = i3.stack;
201
+ }, t3.DOMException.prototype = Object.create(Error.prototype), t3.DOMException.prototype.constructor = t3.DOMException;
202
+ }
203
+ function C(e4, i3) {
204
+ return new Promise((function(n3, s2) {
205
+ var r2 = new E(e4, i3);
206
+ if (r2.signal && r2.signal.aborted) return s2(new t3.DOMException("Aborted", "AbortError"));
207
+ var o2 = new XMLHttpRequest();
208
+ function l2() {
209
+ o2.abort();
210
+ }
211
+ o2.onload = function() {
212
+ var e5, t4, i4 = { status: o2.status, statusText: o2.statusText, headers: (e5 = o2.getAllResponseHeaders() || "", t4 = new p(), e5.replace(/\r?\n[\t ]+/g, " ").split(/\r?\n/).forEach((function(e6) {
213
+ var i5 = e6.split(":"), n4 = i5.shift().trim();
214
+ if (n4) {
215
+ var a4 = i5.join(":").trim();
216
+ t4.append(n4, a4);
217
+ }
218
+ })), t4) };
219
+ i4.url = "responseURL" in o2 ? o2.responseURL : i4.headers.get("X-Request-URL");
220
+ var a3 = "response" in o2 ? o2.response : o2.responseText;
221
+ n3(new A(a3, i4));
222
+ }, o2.onerror = function() {
223
+ s2(new TypeError("Network request failed"));
224
+ }, o2.ontimeout = function() {
225
+ s2(new TypeError("Network request failed"));
226
+ }, o2.onabort = function() {
227
+ s2(new t3.DOMException("Aborted", "AbortError"));
228
+ }, o2.open(r2.method, r2.url, true), "include" === r2.credentials ? o2.withCredentials = true : "omit" === r2.credentials && (o2.withCredentials = false), "responseType" in o2 && a2 && (o2.responseType = "blob"), r2.headers.forEach((function(e5, t4) {
229
+ o2.setRequestHeader(t4, e5);
230
+ })), r2.signal && (r2.signal.addEventListener("abort", l2), o2.onreadystatechange = function() {
231
+ 4 === o2.readyState && r2.signal.removeEventListener("abort", l2);
232
+ }), o2.send(void 0 === r2._bodyInit ? null : r2._bodyInit);
233
+ }));
234
+ }
235
+ C.polyfill = true, e3.fetch || (e3.fetch = C, e3.Headers = p, e3.Request = E, e3.Response = A), t3.Headers = p, t3.Request = E, t3.Response = A, t3.fetch = C, Object.defineProperty(t3, "__esModule", { value: true });
236
+ })({});
237
+ })(n), n.fetch.ponyfill = true, delete n.fetch.polyfill;
238
+ var a = n;
239
+ (t2 = a.fetch).default = a.fetch, t2.fetch = a.fetch, t2.Headers = a.Headers, t2.Request = a.Request, t2.Response = a.Response, e2.exports = t2;
240
+ }, 317: (e2, t2) => {
241
+ "use strict";
242
+ Object.defineProperty(t2, "__esModule", { value: true }), t2.HOST_API_URL_DEV = t2.HOST_API_URL = void 0, t2.HOST_API_URL = "https://api.deepdots.com/", t2.HOST_API_URL_DEV = "https://api-dev.deepdots.com/";
243
+ }, 156: function(e2, t2, i) {
244
+ "use strict";
245
+ var n = this && this.__importDefault || function(e3) {
246
+ return e3 && e3.__esModule ? e3 : { default: e3 };
247
+ };
248
+ Object.defineProperty(t2, "__esModule", { value: true });
249
+ const a = n(i(927));
250
+ let s = null;
251
+ s || (s = (0, a.default)()), t2.default = s;
252
+ }, 927: function(e2, t2, i) {
253
+ "use strict";
254
+ var n = this && this.__awaiter || function(e3, t3, i2, n2) {
255
+ return new (i2 || (i2 = Promise))((function(a2, s2) {
256
+ function r2(e4) {
257
+ try {
258
+ l2(n2.next(e4));
259
+ } catch (e5) {
260
+ s2(e5);
261
+ }
262
+ }
263
+ function o2(e4) {
264
+ try {
265
+ l2(n2.throw(e4));
266
+ } catch (e5) {
267
+ s2(e5);
268
+ }
269
+ }
270
+ function l2(e4) {
271
+ var t4;
272
+ e4.done ? a2(e4.value) : (t4 = e4.value, t4 instanceof i2 ? t4 : new i2((function(e5) {
273
+ e5(t4);
274
+ }))).then(r2, o2);
275
+ }
276
+ l2((n2 = n2.apply(e3, t3 || [])).next());
277
+ }));
278
+ };
279
+ Object.defineProperty(t2, "__esModule", { value: true });
280
+ const a = i(57), s = i(665), r = i(256), o = i(313), l = i(317);
281
+ t2.default = function() {
282
+ const e3 = new s.Config();
283
+ let t3;
284
+ return { init: function(i2) {
285
+ (null == i2 ? void 0 : i2.debug) && e3.set("debug", null == i2 ? void 0 : i2.debug), e3.set("url", (null == i2 ? void 0 : i2.env) && "dev" === (null == i2 ? void 0 : i2.env) ? l.HOST_API_URL_DEV : l.HOST_API_URL), e3.set("env", null == i2 ? void 0 : i2.env), t3 = new r.Log(e3), t3.log("Initialized Magicfeedback", e3);
286
+ }, send: function(i2, a2, s2, r2 = true, l2, d) {
287
+ return n(this, void 0, void 0, (function* () {
288
+ i2 || t3.err("No appID provided"), a2 || t3.err("No publicKey provided"), s2 || t3.err("No feedback provided"), s2.answers || s2.profile || s2.metrics || s2.metadata || t3.err("No feedback data provided");
289
+ const n2 = e3.get("url"), c = { integration: i2, publicKey: a2, privateKey: d, completed: r2, id: l2, feedback: s2 };
290
+ try {
291
+ const e4 = yield (0, o.sendFeedback)(n2, c, t3);
292
+ return t3.log("sent native feedback"), e4;
293
+ } catch (e4) {
294
+ return t3.err("error native feedback", e4), false;
295
+ }
296
+ }));
297
+ }, form: function(i2, n2) {
298
+ return i2 || t3.err("No appID provided"), n2 || t3.err("No publicKey provided"), new a.Form(e3, i2, n2);
299
+ }, session: function(i2) {
300
+ return i2 || t3.err("No sessionId provided"), new a.Form(e3, i2);
301
+ } };
302
+ };
303
+ }, 79: (e2, t2) => {
304
+ "use strict";
305
+ Object.defineProperty(t2, "__esModule", { value: true }), t2.History = void 0, t2.History = class {
306
+ constructor() {
307
+ this.items = [];
308
+ }
309
+ enqueue(e3) {
310
+ this.items.push(e3);
311
+ }
312
+ dequeue() {
313
+ return this.items.shift();
314
+ }
315
+ rollback() {
316
+ return this.items.pop();
317
+ }
318
+ front() {
319
+ return this.items[0];
320
+ }
321
+ back() {
322
+ return this.items[this.items.length - 1];
323
+ }
324
+ isEmpty() {
325
+ return 0 === this.items.length;
326
+ }
327
+ size() {
328
+ return this.items.length;
329
+ }
330
+ get(e3) {
331
+ return this.items[e3];
332
+ }
333
+ };
334
+ }, 665: (e2, t2) => {
335
+ "use strict";
336
+ Object.defineProperty(t2, "__esModule", { value: true }), t2.Config = void 0, t2.Config = class {
337
+ constructor() {
338
+ this.variables = {}, this.variables.env = "prod", this.variables.debug = false;
339
+ }
340
+ get(e3) {
341
+ return this.variables[e3];
342
+ }
343
+ set(e3, t3) {
344
+ this.variables[e3] = t3;
345
+ }
346
+ };
347
+ }, 57: function(e2, t2, i) {
348
+ "use strict";
349
+ var n = this && this.__awaiter || function(e3, t3, i2, n2) {
350
+ return new (i2 || (i2 = Promise))((function(a2, s2) {
351
+ function r2(e4) {
352
+ try {
353
+ l2(n2.next(e4));
354
+ } catch (e5) {
355
+ s2(e5);
356
+ }
357
+ }
358
+ function o2(e4) {
359
+ try {
360
+ l2(n2.throw(e4));
361
+ } catch (e5) {
362
+ s2(e5);
363
+ }
364
+ }
365
+ function l2(e4) {
366
+ var t4;
367
+ e4.done ? a2(e4.value) : (t4 = e4.value, t4 instanceof i2 ? t4 : new i2((function(e5) {
368
+ e5(t4);
369
+ }))).then(r2, o2);
370
+ }
371
+ l2((n2 = n2.apply(e3, t3 || [])).next());
372
+ }));
373
+ };
374
+ Object.defineProperty(t2, "__esModule", { value: true }), t2.Form = void 0;
375
+ const a = i(558), s = i(256), r = i(313), o = i(213), l = i(217), d = i(700), c = i(591), u = i(79), p = i(636);
376
+ t2.Form = class {
377
+ constructor(e3, t3, i2) {
378
+ this.config = e3, this.log = new s.Log(e3), this.formOptionsConfig = { addButton: true, sendButtonText: "Send", backButtonText: "Back", nextButtonText: "Next", addSuccessScreen: true, getMetaData: true, questionFormat: "standard" }, this.selector = "", this.appId = t3, this.publicKey = i2 || "", this.url = e3.get("url"), this.id = "", this.formData = null, this.feedback = { text: "", answers: [], profile: [], metrics: [], metadata: [] }, this.history = new u.History(), this.graph = new l.PageGraph([]), this.progress = 0, this.total = 0, this.completed = false, this.timeToCompleted = 0;
379
+ }
380
+ generate(e3, t3) {
381
+ var i2, a2, s2, o2, l2, d2, c2;
382
+ return n(this, void 0, void 0, (function* () {
383
+ try {
384
+ this.formOptionsConfig = Object.assign(Object.assign({}, this.formOptionsConfig), t3), this.selector = e3;
385
+ let n2 = this.formData;
386
+ if (void 0 !== this.formData && this.formData || (n2 = "" !== this.publicKey ? yield (0, r.getForm)(this.url, this.appId, this.publicKey, this.log) : yield (0, r.getSessionForm)(this.url, this.appId, this.log)), void 0 === n2 || !n2) throw new Error(`No data for app ${this.appId}`);
387
+ if (null === (i2 = n2.error) || void 0 === i2 ? void 0 : i2.message) throw new Error(n2.error.message);
388
+ if (n2.questions = (null === (a2 = n2.questions) || void 0 === a2 ? void 0 : a2.filter(((e4) => "ACTIVE" === e4.status))) || [], n2.pages = (null === (s2 = n2.pages) || void 0 === s2 ? void 0 : s2.filter(((e4) => "ACTIVE" === e4.status))) || [], null === (o2 = n2.pages) || void 0 === o2 || o2.forEach(((e4) => {
389
+ var t4;
390
+ return e4.integrationQuestions = null === (t4 = e4.integrationQuestions) || void 0 === t4 ? void 0 : t4.filter(((e5) => "ACTIVE" === e5.status));
391
+ })), this.formData = n2, this.formData.savedAt || (this.formData.savedAt = /* @__PURE__ */ new Date(), localStorage.setItem(`magicfeedback-${this.appId}`, JSON.stringify(this.formData))), void 0 === this.formData.questions || !this.formData.questions) throw new Error(`No questions for app ${this.appId}`);
392
+ this.formData.pages && 0 !== (null === (l2 = this.formData.pages) || void 0 === l2 ? void 0 : l2.length) || this.formatPages(), null === (d2 = this.formData.questions) || void 0 === d2 || d2.sort(((e4, t4) => e4.position - t4.position)), this.formData.pages = this.formData.pages.filter(((e4) => {
393
+ var t4;
394
+ return (null === (t4 = e4.integrationQuestions) || void 0 === t4 ? void 0 : t4.length) > 0;
395
+ })), this.formOptionsConfig.getMetaData && this.getMetaData(), (null === (c2 = this.formData.style) || void 0 === c2 ? void 0 : c2.startMessage) ? yield this.generateWelcomeMessage(this.formData.style.startMessage) : this.startForm();
396
+ } catch (e4) {
397
+ return this.log.err(e4), void (this.formOptionsConfig.onLoadedEvent && (yield this.formOptionsConfig.onLoadedEvent({ loading: false, error: e4 })));
398
+ }
399
+ }));
400
+ }
401
+ formatPages() {
402
+ var e3;
403
+ if (this.formData) switch (this.formData.identity) {
404
+ case "MAGICSURVEY":
405
+ this.formData.pages = [], null === (e3 = this.formData.questions) || void 0 === e3 || e3.forEach(((e4) => {
406
+ var t4, i2;
407
+ const n2 = new c.PageRoute(e4.id, e4.ref, c.OperatorType.NOEQUAL, [], c.TransitionType.PAGE, (e4.position + 1).toString(), e4.position.toString()), a2 = new d.Page(e4.position.toString(), e4.position, this.appId, [e4], [n2]);
408
+ null === (i2 = null === (t4 = this.formData) || void 0 === t4 ? void 0 : t4.pages) || void 0 === i2 || i2.push(a2);
409
+ }));
410
+ break;
411
+ case "MAGICFORM":
412
+ const t3 = new d.Page("1", 1, this.appId, this.formData.questions, []);
413
+ this.formData.pages = [t3];
414
+ }
415
+ }
416
+ generateContainer() {
417
+ let e3 = document.getElementById(this.selector);
418
+ if (!e3 && (e3 = document.getElementById("magicfeedback-container-" + this.appId), !e3)) throw new Error(`Element with ID '${this.selector}' not found.`);
419
+ return e3.classList.add("magicfeedback-container"), e3.id = "magicfeedback-container-" + this.appId, e3.innerHTML = "", e3;
420
+ }
421
+ generateForm() {
422
+ var e3, t3, i2, a2;
423
+ return n(this, void 0, void 0, (function* () {
424
+ try {
425
+ if (console.log("Generating form for appId:", this.appId), !this.formData || !this.formData.pages || 0 === this.formData.pages.length) throw new Error("No form data");
426
+ this.graph = new l.PageGraph(this.formData.pages.sort(((e4, t4) => e4.position - t4.position)));
427
+ let n2 = this.generateContainer();
428
+ const s2 = document.createElement("form");
429
+ s2.classList.add("magicfeedback-form"), s2.id = "magicfeedback-" + this.appId, s2.addEventListener("submit", ((e4) => e4.preventDefault()));
430
+ const r2 = document.createElement("div");
431
+ r2.classList.add("magicfeedback-questions"), r2.id = "magicfeedback-questions-" + this.appId;
432
+ const d2 = this.graph.getFirstPage();
433
+ if (!d2) throw new Error("No page found");
434
+ if (this.total = this.graph.findMaxDepth(), d2.elements = (0, o.renderQuestions)(d2.questions, this.formOptionsConfig.questionFormat, null === (e3 = this.formData) || void 0 === e3 ? void 0 : e3.lang[0], null === (t3 = this.formData) || void 0 === t3 ? void 0 : t3.product, (() => this.send())), null === (i2 = d2.elements) || void 0 === i2 || i2.forEach(((e4) => r2.appendChild(e4))), s2.appendChild(r2), this.history.enqueue(d2), n2.appendChild(s2), this.progress = this.total - this.graph.findMaxDepth(d2), this.formOptionsConfig.addButton) {
435
+ const e4 = (0, o.renderActions)(null === (a2 = this.formData) || void 0 === a2 ? void 0 : a2.identity, (() => this.back()), this.formOptionsConfig.sendButtonText, this.formOptionsConfig.backButtonText, this.formOptionsConfig.nextButtonText);
436
+ s2.appendChild(e4);
437
+ }
438
+ this.formOptionsConfig.addButton && s2.addEventListener("submit", ((e4) => {
439
+ e4.preventDefault(), this.send();
440
+ })), this.timeToCompleted = (/* @__PURE__ */ new Date()).getTime() / 1e3, this.formOptionsConfig.onLoadedEvent && (yield this.formOptionsConfig.onLoadedEvent({ loading: false, progress: this.progress, total: this.total, formData: this.formData }));
441
+ } catch (e4) {
442
+ return this.log.err(e4), void (this.formOptionsConfig.onLoadedEvent && this.formOptionsConfig.onLoadedEvent({ loading: false, error: e4 }));
443
+ }
444
+ }));
445
+ }
446
+ startForm() {
447
+ this.generateForm();
448
+ }
449
+ generateWelcomeMessage(e3) {
450
+ return n(this, void 0, void 0, (function* () {
451
+ try {
452
+ const t3 = this.generateContainer(), i2 = (0, o.renderStartMessage)(e3, this.formOptionsConfig.addButton, this.formOptionsConfig.startButtonText, (() => this.startForm()));
453
+ t3.appendChild(i2), this.formOptionsConfig.onLoadedEvent && (yield this.formOptionsConfig.onLoadedEvent({ loading: false, formData: this.formData }));
454
+ } catch (e4) {
455
+ return this.log.err(e4), void (this.formOptionsConfig.onLoadedEvent && this.formOptionsConfig.onLoadedEvent({ loading: false, error: e4 }));
456
+ }
457
+ }));
458
+ }
459
+ getMetaData() {
460
+ this.feedback.metadata.push({ key: "navigator-url", value: [window.location.href] }), this.feedback.metadata.push({ key: "navigator-origin", value: [window.location.origin] }), this.feedback.metadata.push({ key: "navigator-pathname", value: [window.location.pathname] }), this.feedback.metadata.push({ key: "navigator-search", value: [window.location.search] }), this.feedback.metadata.push({ key: "navigator-user", value: [navigator.userAgent] }), this.feedback.metadata.push({ key: "navigator-language", value: [navigator.language] }), this.feedback.metadata.push({ key: "navigator-platform", value: [navigator.platform] }), this.feedback.metadata.push({ key: "navigator-appVersion", value: [navigator.appVersion] }), this.feedback.metadata.push({ key: "navigator-appName", value: [navigator.appName] }), this.feedback.metadata.push({ key: "navigator-product", value: [navigator.product] }), this.feedback.metadata.push({ key: "screen-width", value: [window.screen.width.toString()] }), this.feedback.metadata.push({ key: "screen-height", value: [window.screen.height.toString()] }), this.appId && "" === this.publicKey && this.feedback.metadata.push({ key: "MAGICFEEDBACK_SESSION", value: [this.appId] });
461
+ }
462
+ send(e3, t3, i2) {
463
+ return n(this, void 0, void 0, (function* () {
464
+ const n2 = document.getElementById("magicfeedback-questions-" + this.appId);
465
+ try {
466
+ i2 && (this.feedback.profile = [...this.feedback.profile, ...i2]), t3 && (this.feedback.metrics = [...this.feedback.metrics, ...t3]), e3 && (this.feedback.metadata = [...this.feedback.metadata, ...e3]), this.answer(), this.formOptionsConfig.beforeSubmitEvent && (yield this.formOptionsConfig.beforeSubmitEvent({ loading: true, progress: this.progress, total: this.total }));
467
+ const s2 = this.history.back();
468
+ if (!s2) throw new Error("No page found");
469
+ for (const e4 of s2.questions.filter(((e5) => e5.require && ![a.FEEDBACKAPPANSWERTYPE.CONSENT, a.FEEDBACKAPPANSWERTYPE.INFO_PAGE].includes(e5.type)))) {
470
+ const t4 = e4.assets, i3 = this.feedback.answers.filter(((t5) => t5.key.includes(e4.ref) && !t5.key.includes("extra-option")));
471
+ if (0 === i3.length || i3.find(((e5) => 0 === e5.value.length))) throw this.log.err(`The question ${e4.ref} is required`), new Error("No response");
472
+ if (null == t4 ? void 0 : t4.minOptions) {
473
+ let n3 = [];
474
+ if ((null == t4 ? void 0 : t4.exclusiveAnswers) && (n3 = null == t4 ? void 0 : t4.exclusiveAnswers), !i3[0].value.find(((e5) => n3.includes(e5))) && i3[0].value.length < (null == t4 ? void 0 : t4.minOptions)) throw this.log.err(`The question ${e4.ref} requires at least ${null == t4 ? void 0 : t4.minOptions} options`), new Error("No response");
475
+ }
476
+ }
477
+ const r2 = yield this.pushAnswers(false);
478
+ if (!r2) throw new Error("No response");
479
+ this.id = r2, yield this.processNextQuestion(n2);
480
+ } catch (e4) {
481
+ this.log.err(`An error occurred while submitting the form ${this.appId}:`, e4), this.formOptionsConfig.afterSubmitEvent && (yield this.formOptionsConfig.afterSubmitEvent({ loading: false, progress: this.progress, total: this.total, error: e4 }));
482
+ }
483
+ }));
484
+ }
485
+ answer() {
486
+ const e3 = document.getElementById("magicfeedback-" + this.appId);
487
+ if (!e3) return this.log.err(`Form "${e3}" not found.`), void (this.feedback.answers = []);
488
+ const t3 = this.history.back();
489
+ if (!t3) throw new Error("No page found");
490
+ const i2 = [];
491
+ let n2 = false;
492
+ if (e3.querySelectorAll(".magicfeedback-input").forEach(((e4) => {
493
+ const s2 = t3.questions.find(((t4) => {
494
+ var i3;
495
+ return null === (i3 = e4.name) || void 0 === i3 ? void 0 : i3.includes(t4.ref);
496
+ })), o2 = e4.type, l2 = e4.classList[0], d2 = { key: e4.name, value: [] }, c2 = "magicfeedback-consent" === l2 ? e4.checked.toString() : e4.value;
497
+ if (d2.key && "" !== d2.key) {
498
+ switch (null == s2 ? void 0 : s2.type) {
499
+ case a.FEEDBACKAPPANSWERTYPE.EMAIL:
500
+ case a.FEEDBACKAPPANSWERTYPE.TEXT:
501
+ case a.FEEDBACKAPPANSWERTYPE.LONGTEXT:
502
+ case a.FEEDBACKAPPANSWERTYPE.NUMBER:
503
+ case a.FEEDBACKAPPANSWERTYPE.DATE:
504
+ case a.FEEDBACKAPPANSWERTYPE.CONTACT:
505
+ if ("" !== c2) {
506
+ if ("email" === o2) {
507
+ if (!(0, r.validateEmail)(c2)) {
508
+ this.log.err("Invalid email"), n2 = true;
509
+ break;
510
+ }
511
+ this.feedback.profile.push({ key: "email", value: [c2] });
512
+ }
513
+ d2.value.push(c2);
514
+ }
515
+ break;
516
+ case a.FEEDBACKAPPANSWERTYPE.CONSENT:
517
+ d2.value.push(String(e4.checked));
518
+ break;
519
+ case a.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:
520
+ const t4 = e4.id;
521
+ d2.value.push(`${t4}:${c2}%`);
522
+ break;
523
+ case a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:
524
+ case a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:
525
+ case a.FEEDBACKAPPANSWERTYPE.RATING_STAR:
526
+ case a.FEEDBACKAPPANSWERTYPE.RADIO:
527
+ case a.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:
528
+ case a.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:
529
+ (e4.checked || e4.id.includes("extra-option-")) && d2.value.push(c2);
530
+ break;
531
+ case a.FEEDBACKAPPANSWERTYPE.SELECT:
532
+ d2.value.push(c2);
533
+ break;
534
+ case a.FEEDBACKAPPANSWERTYPE.BOOLEAN:
535
+ case a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:
536
+ e4.checked && d2.value.push(c2);
537
+ break;
538
+ case a.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:
539
+ d2.value.push(c2);
540
+ }
541
+ if ((null == i2 ? void 0 : i2.length) > 0 && (null == i2 ? void 0 : i2.find(((e5) => e5.key === d2.key)))) {
542
+ const e5 = i2.findIndex(((e6) => e6.key === d2.key));
543
+ i2[e5].value = [...i2[e5].value, ...d2.value];
544
+ } else i2.push(d2);
545
+ }
546
+ })), n2) return this.feedback.answers = [], void t3.setAnswer([]);
547
+ try {
548
+ t3.questions.filter(((e4) => e4.type === a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX)).forEach(((e4) => {
549
+ const t4 = e4.ref + "-", n3 = i2.filter(((e5) => e5.key.startsWith(t4)));
550
+ if (0 === n3.length) return;
551
+ const a2 = n3.map(((e5) => ({ key: e5.key.substring(t4.length), value: e5.value }))), s2 = { key: e4.ref, value: [JSON.stringify(a2)] };
552
+ for (const e5 of n3) {
553
+ const t5 = i2.findIndex(((t6) => t6.key === e5.key));
554
+ -1 !== t5 && i2.splice(t5, 1);
555
+ }
556
+ const r2 = i2.findIndex(((t5) => t5.key === e4.ref));
557
+ -1 !== r2 ? i2[r2] = s2 : i2.push(s2);
558
+ }));
559
+ } catch (e4) {
560
+ this.log.err("Error agrupando MULTI_QUESTION_MATRIX", e4);
561
+ }
562
+ this.feedback.answers = i2, t3.setAnswer(i2);
563
+ }
564
+ finish() {
565
+ return n(this, void 0, void 0, (function* () {
566
+ if (this.completed = true, this.timeToCompleted = (/* @__PURE__ */ new Date()).getTime() - this.timeToCompleted, this.feedback.metadata.push({ key: "time-to-complete", value: [this.timeToCompleted.toString()] }), this.formOptionsConfig.addSuccessScreen) {
567
+ const e3 = document.getElementById("magicfeedback-container-" + this.appId);
568
+ e3.childNodes.length > 0 && e3.removeChild(e3.childNodes[0]);
569
+ const t3 = (0, o.renderSuccess)(this.formOptionsConfig.successMessage || "Thank you for your feedback!");
570
+ e3.appendChild(t3);
571
+ }
572
+ this.answer();
573
+ try {
574
+ const e3 = yield this.pushAnswers(true);
575
+ if (!e3) throw this.formOptionsConfig.afterSubmitEvent && (yield this.formOptionsConfig.afterSubmitEvent({ loading: false, progress: this.progress, total: this.total, completed: this.completed, error: `An error occurred while submitting the form ${this.appId}:` })), new Error("An error occurred while submitting the form ${this.appId}:");
576
+ this.id = e3, this.formOptionsConfig.afterSubmitEvent && (yield this.formOptionsConfig.afterSubmitEvent({ response: this.id, loading: false, progress: this.progress, total: this.total, completed: this.completed, error: null }));
577
+ } catch (e3) {
578
+ this.log.err(`An error occurred while submitting the form ${this.appId}:`, e3), this.formOptionsConfig.afterSubmitEvent && (yield this.formOptionsConfig.afterSubmitEvent({ loading: false, progress: this.progress, total: this.total, completed: this.completed, error: e3 }));
579
+ }
580
+ }));
581
+ }
582
+ pushAnswers(e3 = false) {
583
+ return n(this, void 0, void 0, (function* () {
584
+ try {
585
+ const t3 = this.config.get("url"), i2 = { integration: this.appId, publicKey: this.publicKey, feedback: this.feedback, completed: e3 };
586
+ return yield (0, r.sendFeedback)(t3, this.id ? Object.assign(Object.assign({}, i2), { sessionId: this.id }) : i2, this.log);
587
+ } catch (e4) {
588
+ return this.log.err(`An error occurred while submitting the form ${this.appId}:`, e4), "";
589
+ }
590
+ }));
591
+ }
592
+ callFollowUpQuestion(e3) {
593
+ var t3;
594
+ return n(this, void 0, void 0, (function* () {
595
+ if (!(null == e3 ? void 0 : e3.followup)) return null;
596
+ try {
597
+ if (0 === this.feedback.answers.length) throw new Error("No answers provided");
598
+ const i2 = this.config.get("url"), n2 = Object.assign(Object.assign(Object.assign({ answer: null === (t3 = this.feedback.answers.find(((t4) => t4.key === e3.ref))) || void 0 === t3 ? void 0 : t3.value[0] }, "" !== this.publicKey && { publicKey: this.publicKey }), "" === this.publicKey && { campaignSessionId: this.appId }), { sessionId: this.id, question: e3 });
599
+ return yield (0, r.getFollowUpQuestion)(i2, n2, this.log);
600
+ } catch (e4) {
601
+ throw this.log.err(`An error occurred while submitting the form ${this.appId}:`, e4), e4;
602
+ }
603
+ }));
604
+ }
605
+ processNextQuestion(e3) {
606
+ var t3, i2, a2;
607
+ return n(this, void 0, void 0, (function* () {
608
+ const n2 = this.history.back();
609
+ if (!n2) throw new Error("No page found");
610
+ const s2 = n2.getFollowupQuestions();
611
+ if (0 === (null == s2 ? void 0 : s2.length)) return void (yield this.renderNextQuestion(e3, n2));
612
+ const r2 = [];
613
+ for (const e4 of s2) {
614
+ const t4 = n2.questions.find(((t5) => t5.ref === e4));
615
+ if (t4) {
616
+ const e5 = yield this.callFollowUpQuestion(t4);
617
+ e5 && r2.push(e5);
618
+ }
619
+ }
620
+ if (0 === r2.length) return void (yield this.renderNextQuestion(e3, n2));
621
+ const l2 = new d.Page(n2.id, n2.position, this.appId, r2, n2.edges), c2 = new p.PageNode(n2.id, n2.position, n2.edges, l2, r2, true);
622
+ c2.elements = (0, o.renderQuestions)(r2, this.formOptionsConfig.questionFormat, null === (t3 = this.formData) || void 0 === t3 ? void 0 : t3.lang[0], null === (i2 = this.formData) || void 0 === i2 ? void 0 : i2.product, (() => this.send())), this.history.enqueue(c2), this.progress += 0.5, e3.innerHTML = "", null === (a2 = c2.elements) || void 0 === a2 || a2.forEach(((t4) => e3.appendChild(t4))), this.formOptionsConfig.afterSubmitEvent && (yield this.formOptionsConfig.afterSubmitEvent({ response: this.id, loading: false, progress: this.progress, total: this.total, followup: c2.isFollowup, completed: this.completed, error: null }));
623
+ }));
624
+ }
625
+ renderNextQuestion(e3, t3) {
626
+ var i2, s2, r2, l2, d2;
627
+ return n(this, void 0, void 0, (function* () {
628
+ let n2 = this.graph.getNextPage(t3, this.feedback.answers);
629
+ if (!n2) return void this.finish();
630
+ const u2 = n2.edges.filter(((e4) => "PRECONDITIONAL" === e4.typeCondition)).sort(((e4, t4) => e4.position < t4.position ? -1 : e4.position > t4.position ? 1 : 0));
631
+ if ((null == u2 ? void 0 : u2.length) > 0) {
632
+ let t4 = null;
633
+ const r3 = u2.map(((e4) => e4.questionRef));
634
+ for (let e4 = this.history.size() - 1; e4 >= 0; e4--) {
635
+ const n3 = this.history.get(e4);
636
+ if (n3 && (t4 = null === (i2 = n3.answers) || void 0 === i2 ? void 0 : i2.find(((e5) => r3.includes(e5.key))), t4)) break;
637
+ }
638
+ let o2 = !u2.some(((e4) => e4.transition === c.TransitionType.ALLOW));
639
+ if (t4) for (const i3 of u2) {
640
+ let r4 = false;
641
+ const l3 = null === (s2 = this.formData) || void 0 === s2 ? void 0 : s2.questions.find(((e4) => e4.ref === i3.questionRef)), d3 = Array.isArray(t4.value) ? t4.value : [t4.value], u3 = Array.isArray(i3.value) ? i3.value : [i3.value];
642
+ if ((null == l3 ? void 0 : l3.type) === a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX) r4 = this.evaluateMatrixPreconditional(i3, t4);
643
+ else switch (i3.typeOperator) {
644
+ case "EQUAL":
645
+ case "INQ":
646
+ r4 = d3.some(((e4) => u3.includes(e4)));
647
+ break;
648
+ case "NOEQUAL":
649
+ case "NINQ":
650
+ r4 = d3.every(((e4) => !u3.includes(e4)));
651
+ break;
652
+ case "GREATER":
653
+ r4 = d3.some(((e4) => Number(e4) > Number(u3[0])));
654
+ break;
655
+ case "LESS":
656
+ r4 = d3.some(((e4) => Number(e4) < Number(u3[0])));
657
+ break;
658
+ case "GREATEREQUAL":
659
+ r4 = d3.some(((e4) => Number(e4) >= Number(u3[0])));
660
+ break;
661
+ case "LESSEQUAL":
662
+ r4 = d3.some(((e4) => Number(e4) <= Number(u3[0])));
663
+ }
664
+ if (r4) switch (this.feedback.answers = [], i3.transition) {
665
+ case c.TransitionType.NEXT:
666
+ return void (n2 && (yield this.renderNextQuestion(e3, n2)));
667
+ case c.TransitionType.ALLOW:
668
+ o2 = true;
669
+ }
670
+ }
671
+ if (!o2) return this.feedback.answers = [], void (n2 && (yield this.renderNextQuestion(e3, n2)));
672
+ }
673
+ n2.elements = (0, o.renderQuestions)(n2.questions, this.formOptionsConfig.questionFormat, null === (r2 = this.formData) || void 0 === r2 ? void 0 : r2.lang[0], null === (l2 = this.formData) || void 0 === l2 ? void 0 : l2.product, (() => this.send())), e3.innerHTML = "", null === (d2 = n2.elements) || void 0 === d2 || d2.forEach(((t4) => e3.appendChild(t4))), this.history.enqueue(n2), this.progress = this.total - this.graph.findMaxDepth(n2), this.formOptionsConfig.afterSubmitEvent && (yield this.formOptionsConfig.afterSubmitEvent({ response: this.id, loading: false, progress: this.progress, total: this.total, followup: n2.isFollowup, completed: this.completed, error: null }));
674
+ }));
675
+ }
676
+ back() {
677
+ var e3;
678
+ return n(this, void 0, void 0, (function* () {
679
+ if (0 === this.history.size()) return;
680
+ const t3 = document.getElementById("magicfeedback-questions-" + this.appId);
681
+ t3 && t3.childNodes.length > 0 && (t3.innerHTML = ""), this.history.rollback();
682
+ const i2 = this.history.back();
683
+ i2 ? (null === (e3 = i2.elements) || void 0 === e3 || e3.forEach(((e4) => t3.appendChild(e4))), this.progress = this.total - this.graph.findMaxDepth(i2)) : this.progress = this.history.size(), this.formOptionsConfig.onBackEvent && (yield this.formOptionsConfig.onBackEvent({ loading: false, progress: this.progress, followup: (null == i2 ? void 0 : i2.isFollowup) || false, error: i2 ? null : "No page found" }));
684
+ }));
685
+ }
686
+ previewQuestion(e3, t3, i2) {
687
+ var n2, a2;
688
+ const s2 = Array.isArray(t3) ? t3 : [t3];
689
+ if (!s2 || 0 === s2.length) throw new Error("[MagicFeedback] No question provided for preview");
690
+ const r2 = document.getElementById(e3);
691
+ if (!r2) throw new Error(`[MagicFeedback] Element with ID '${e3}' not found.`);
692
+ const { format: l2 = this.formOptionsConfig.questionFormat || "standard", language: d2 = (null === (n2 = this.formData) || void 0 === n2 ? void 0 : n2.lang) && this.formData.lang[0] || "en", product: c2 = (null === (a2 = this.formData) || void 0 === a2 ? void 0 : a2.product) || { customIcons: false }, clearContainer: u2 = true, wrap: p2 = true } = i2 || {};
693
+ u2 && (r2.innerHTML = "");
694
+ let h = [];
695
+ try {
696
+ h = (0, o.renderQuestions)(s2, l2, d2, c2);
697
+ } catch (e4) {
698
+ throw this.log.err(e4), e4;
699
+ }
700
+ let m = r2;
701
+ if (p2) {
702
+ const e4 = document.createElement("div");
703
+ e4.classList.add("magicfeedback-preview-question"), m.appendChild(e4), m = e4;
704
+ }
705
+ return h.forEach(((e4) => m.appendChild(e4))), r2;
706
+ }
707
+ parseMatrixAnswerPre(e3) {
708
+ if (!e3 || !e3.value) return [];
709
+ if (1 === e3.value.length && "string" == typeof e3.value[0] && e3.value[0].trim().startsWith("[")) try {
710
+ const t3 = JSON.parse(e3.value[0]);
711
+ if (Array.isArray(t3)) return t3;
712
+ } catch (e4) {
713
+ return [];
714
+ }
715
+ return Array.isArray(e3.value) && e3.value.length > 0 && "object" == typeof e3.value[0] && null !== e3.value[0] && "key" in e3.value[0] ? e3.value : [];
716
+ }
717
+ evaluateMatrixPreconditional(e3, t3) {
718
+ const i2 = Array.isArray(e3.value) ? e3.value : [e3.value], n2 = new Set(e3.option || []), a2 = this.parseMatrixAnswerPre(t3);
719
+ if (!a2.length) return false;
720
+ const s2 = n2.size > 0 ? a2.filter(((e4) => n2.has(e4.key))) : a2;
721
+ if (!s2.length) return false;
722
+ switch (e3.typeOperator) {
723
+ case "EQUAL":
724
+ case "INQ":
725
+ return s2.some(((e4) => (Array.isArray(e4.value) ? e4.value : [e4.value]).some(((e5) => i2.includes(e5)))));
726
+ case "NOEQUAL":
727
+ case "NINQ":
728
+ return s2.every(((e4) => (Array.isArray(e4.value) ? e4.value : [e4.value]).every(((e5) => !i2.includes(e5)))));
729
+ case "GREATER":
730
+ return s2.some(((e4) => (Array.isArray(e4.value) ? e4.value : [e4.value]).some(((e5) => i2.some(((t4) => Number(e5) > Number(t4)))))));
731
+ case "LESS":
732
+ return s2.some(((e4) => (Array.isArray(e4.value) ? e4.value : [e4.value]).some(((e5) => i2.some(((t4) => Number(e5) < Number(t4)))))));
733
+ case "GREATEREQUAL":
734
+ return s2.some(((e4) => (Array.isArray(e4.value) ? e4.value : [e4.value]).some(((e5) => i2.some(((t4) => Number(e5) >= Number(t4)))))));
735
+ case "LESSEQUAL":
736
+ return s2.some(((e4) => (Array.isArray(e4.value) ? e4.value : [e4.value]).some(((e5) => i2.some(((t4) => Number(e5) <= Number(t4)))))));
737
+ default:
738
+ return false;
739
+ }
740
+ }
741
+ };
742
+ }, 700: (e2, t2) => {
743
+ "use strict";
744
+ Object.defineProperty(t2, "__esModule", { value: true }), t2.Page = void 0, t2.Page = class {
745
+ constructor(e3, t3, i, n, a) {
746
+ this.id = e3, this.position = t3, this.generatedAt = (/* @__PURE__ */ new Date()).toISOString(), this.updatedAt = (/* @__PURE__ */ new Date()).toISOString(), this.status = "ACTIVE", this.integrationId = i, this.integrationQuestions = n, this.integrationPageRoutes = a;
747
+ }
748
+ };
749
+ }, 217: (e2, t2, i) => {
750
+ "use strict";
751
+ Object.defineProperty(t2, "__esModule", { value: true }), t2.PageGraph = void 0;
752
+ const n = i(636), a = i(558), s = i(591);
753
+ t2.PageGraph = class {
754
+ constructor(e3) {
755
+ this.nodes = /* @__PURE__ */ new Map(), this.buildGraph(e3);
756
+ }
757
+ buildGraph(e3) {
758
+ e3.forEach(((e4) => {
759
+ var t3;
760
+ e4.integrationPageRoutes && (e4.integrationPageRoutes = (null === (t3 = e4.integrationPageRoutes) || void 0 === t3 ? void 0 : t3.sort(((e5, t4) => new Date((null == e5 ? void 0 : e5.generatedAt) || "").getTime() - new Date((null == t4 ? void 0 : t4.generatedAt) || "").getTime() ? "DIRECT" === e5.typeCondition ? 1 : -1 : 0))) || []);
761
+ const i2 = new n.PageNode(e4.id, e4.position, e4.integrationPageRoutes || [], e4, e4.integrationQuestions);
762
+ this.nodes.set(i2.id, i2);
763
+ }));
764
+ }
765
+ getNodeById(e3) {
766
+ return this.nodes.get(e3);
767
+ }
768
+ getNextEdgeByDefault(e3) {
769
+ if (!e3) return;
770
+ const t3 = e3.edges.find(((e4) => e4.typeCondition === s.ConditionType.DIRECT));
771
+ if (!t3 || ![s.TransitionType.FINISH, s.TransitionType.REDIRECT].includes(t3.transition)) {
772
+ if (t3 && t3.transitionDestiny) return t3.transitionDestiny;
773
+ for (const t4 of this.nodes.values()) if (t4.position === e3.position + 1) return t4.id;
774
+ }
775
+ }
776
+ getFirstPage() {
777
+ let e3, t3 = Number.MAX_VALUE;
778
+ for (const i2 of this.nodes.values()) i2.position < t3 && (t3 = i2.position, e3 = i2);
779
+ return e3;
780
+ }
781
+ getNextPage(e3, t3) {
782
+ var i2;
783
+ if (!e3) return;
784
+ e3.edges.sort(((e4, t4) => "DIRECT" === e4.typeCondition ? 1 : "DIRECT" === t4.typeCondition ? -1 : 0));
785
+ const n2 = e3.edges.find(((i3) => {
786
+ const n3 = e3.questions.find(((e4) => e4.ref === i3.questionRef)), r = null == t3 ? void 0 : t3.filter(((e4) => e4.key === i3.questionRef));
787
+ if ("DIRECT" === i3.typeCondition) return true;
788
+ if (!r || 0 === r.length) return false;
789
+ if ((null == n3 ? void 0 : n3.type) === a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX) return this.evaluateMatrixCondition(i3, r);
790
+ const o = Array.isArray(i3.value) ? i3.value : [i3.value];
791
+ switch (i3.typeOperator) {
792
+ case s.OperatorType.EQUAL:
793
+ return r.some(((e4) => (Array.isArray(e4.value) ? e4.value : [e4.value]).some(((e5) => o.includes(e5)))));
794
+ case s.OperatorType.NOEQUAL:
795
+ return r.every(((e4) => (Array.isArray(e4.value) ? e4.value : [e4.value]).every(((e5) => !o.includes(e5)))));
796
+ case s.OperatorType.GREATER:
797
+ return r.some(((e4) => (Array.isArray(e4.value) ? e4.value : [e4.value]).some(((e5) => o.some(((t4) => Number(e5) > Number(t4)))))));
798
+ case s.OperatorType.LESS:
799
+ return r.some(((e4) => (Array.isArray(e4.value) ? e4.value : [e4.value]).some(((e5) => o.some(((t4) => Number(e5) < Number(t4)))))));
800
+ case s.OperatorType.GREATEREQUAL:
801
+ return r.some(((e4) => (Array.isArray(e4.value) ? e4.value : [e4.value]).some(((e5) => o.some(((t4) => Number(e5) >= Number(t4)))))));
802
+ case s.OperatorType.LESSEQUAL:
803
+ return r.some(((e4) => (Array.isArray(e4.value) ? e4.value : [e4.value]).some(((e5) => o.some(((t4) => Number(e5) <= Number(t4)))))));
804
+ case s.OperatorType.INQ:
805
+ return r.some(((e4) => (Array.isArray(e4.value) ? e4.value : [e4.value]).some(((e5) => o.includes(e5)))));
806
+ case s.OperatorType.NINQ:
807
+ return r.every(((e4) => (Array.isArray(e4.value) ? e4.value : [e4.value]).every(((e5) => !o.includes(e5)))));
808
+ default:
809
+ return false;
810
+ }
811
+ }));
812
+ if (!n2) {
813
+ const t4 = this.getNextEdgeByDefault(e3);
814
+ if (!t4) return;
815
+ return this.getNodeById(t4);
816
+ }
817
+ switch (n2.transition) {
818
+ case s.TransitionType.PAGE:
819
+ if (!n2.transitionDestiny) return;
820
+ return this.getNodeById(n2.transitionDestiny);
821
+ case s.TransitionType.FINISH:
822
+ return;
823
+ case s.TransitionType.REDIRECT:
824
+ return void (window.location.href = (null === (i2 = n2.transitionDestiny) || void 0 === i2 ? void 0 : i2.includes("?")) ? `${n2.transitionDestiny}&${window.location.search.slice(1)}` : `${n2.transitionDestiny}${window.location.search}`);
825
+ default:
826
+ return;
827
+ }
828
+ }
829
+ findDepth(e3) {
830
+ const t3 = this.getNodeById(e3);
831
+ if (!t3) return 0;
832
+ const i2 = /* @__PURE__ */ new Set();
833
+ return this.DFSUtil(t3, i2, 0);
834
+ }
835
+ findMaxDepth(e3) {
836
+ if (e3 || (e3 = this.getFirstPage()), !e3) return 0;
837
+ const t3 = /* @__PURE__ */ new Set();
838
+ let i2 = 1;
839
+ return i2 = Math.max(i2, this.DFSUtil(e3, t3, i2)), i2;
840
+ }
841
+ DFSUtil(e3, t3, i2) {
842
+ t3.add(e3);
843
+ let n2 = i2;
844
+ const a2 = [...e3.edges.filter(((e4) => e4.typeCondition !== s.ConditionType.PRECONDITIONAL)) || []], r = this.getNextEdgeByDefault(e3);
845
+ if (r) {
846
+ const i3 = this.getNodeById(r);
847
+ i3 && !t3.has(i3) && a2.push(new s.PageRoute(i3.id, "", s.OperatorType.DEFAULT, [""], s.TransitionType.PAGE, i3.id, e3.id));
848
+ }
849
+ for (const e4 of a2) {
850
+ if (!e4.transitionDestiny) continue;
851
+ const a3 = this.getNodeById(e4.transitionDestiny);
852
+ if (a3 && !t3.has(a3)) {
853
+ const e5 = a3.questions.find(((e6) => e6.followup)) ? i2 + 2 : i2 + 1, s2 = new Set(t3), r2 = this.DFSUtil(a3, s2, e5);
854
+ n2 = Math.max(n2, r2);
855
+ }
856
+ }
857
+ return n2;
858
+ }
859
+ parseMatrixAnswer(e3) {
860
+ if (!e3 || !e3.value) return [];
861
+ if (1 === e3.value.length && "string" == typeof e3.value[0] && e3.value[0].trim().startsWith("[")) try {
862
+ const t3 = JSON.parse(e3.value[0]);
863
+ if (Array.isArray(t3)) return t3;
864
+ } catch (e4) {
865
+ return [];
866
+ }
867
+ return Array.isArray(e3.value) && e3.value.length > 0 && "object" == typeof e3.value[0] && null !== e3.value[0] && "key" in e3.value[0] ? e3.value : [];
868
+ }
869
+ evaluateMatrixCondition(e3, t3) {
870
+ const i2 = Array.isArray(e3.value) ? e3.value : [e3.value], n2 = new Set(e3.option || []), a2 = t3[0], r = this.parseMatrixAnswer(a2);
871
+ if (!r.length) return false;
872
+ const o = n2.size > 0 ? r.filter(((e4) => n2.has(e4.key))) : r;
873
+ if (!o.length) return false;
874
+ switch (e3.typeOperator) {
875
+ case s.OperatorType.EQUAL:
876
+ case s.OperatorType.INQ:
877
+ return o.some(((e4) => (Array.isArray(e4.value) ? e4.value : [e4.value]).some(((e5) => i2.includes(e5)))));
878
+ case s.OperatorType.NOEQUAL:
879
+ case s.OperatorType.NINQ:
880
+ return o.every(((e4) => (Array.isArray(e4.value) ? e4.value : [e4.value]).every(((e5) => !i2.includes(e5)))));
881
+ case s.OperatorType.GREATER:
882
+ return o.some(((e4) => (Array.isArray(e4.value) ? e4.value : [e4.value]).some(((e5) => i2.some(((t4) => Number(e5) > Number(t4)))))));
883
+ case s.OperatorType.LESS:
884
+ return o.some(((e4) => (Array.isArray(e4.value) ? e4.value : [e4.value]).some(((e5) => i2.some(((t4) => Number(e5) < Number(t4)))))));
885
+ case s.OperatorType.GREATEREQUAL:
886
+ return o.some(((e4) => (Array.isArray(e4.value) ? e4.value : [e4.value]).some(((e5) => i2.some(((t4) => Number(e5) >= Number(t4)))))));
887
+ case s.OperatorType.LESSEQUAL:
888
+ return o.some(((e4) => (Array.isArray(e4.value) ? e4.value : [e4.value]).some(((e5) => i2.some(((t4) => Number(e5) <= Number(t4)))))));
889
+ default:
890
+ return false;
891
+ }
892
+ }
893
+ };
894
+ }, 636: (e2, t2) => {
895
+ "use strict";
896
+ Object.defineProperty(t2, "__esModule", { value: true }), t2.PageNode = void 0, t2.PageNode = class {
897
+ constructor(e3, t3, i, n, a, s = false) {
898
+ this.answers = [], this.id = e3, this.position = t3, this.edges = i, this.data = n, this.questions = a.sort(((e4, t4) => e4.position - t4.position)), this.elements = [], this.isFollowup = s;
899
+ }
900
+ getFollowupQuestions() {
901
+ return this.questions.filter(((e3) => e3.followup)).map(((e3) => e3.ref));
902
+ }
903
+ getRequiredQuestions() {
904
+ return this.questions.filter(((e3) => e3.require)).map(((e3) => e3.ref));
905
+ }
906
+ setAnswer(e3) {
907
+ this.answers = e3;
908
+ }
909
+ };
910
+ }, 591: (e2, t2) => {
911
+ "use strict";
912
+ var i, n, a, s;
913
+ Object.defineProperty(t2, "__esModule", { value: true }), t2.PageRoute = t2.StatusType = t2.OperatorType = t2.ConditionType = t2.TransitionType = void 0, (s = t2.TransitionType || (t2.TransitionType = {})).PAGE = "PAGE", s.FINISH = "FINISH", s.REDIRECT = "REDIRECT", s.NEXT = "NEXT", s.ALLOW = "ALLOW", (function(e3) {
914
+ e3.LOGICAL = "LOGICAL", e3.DIRECT = "DIRECT", e3.PRECONDITIONAL = "PRECONDITIONAL";
915
+ })(i = t2.ConditionType || (t2.ConditionType = {})), (a = t2.OperatorType || (t2.OperatorType = {})).EQUAL = "EQUAL", a.NOEQUAL = "NOEQUAL", a.GREATER = "GREATER", a.LESS = "LESS", a.GREATEREQUAL = "GREATEREQUAL", a.LESSEQUAL = "LESSEQUAL", a.INQ = "INQ", a.NINQ = "NINQ", a.DEFAULT = "DEFAULT", (function(e3) {
916
+ e3.ACTIVE = "ACTIVE", e3.DEPRECATED = "DEPRECATED", e3.DELETE = "DELETE";
917
+ })(n = t2.StatusType || (t2.StatusType = {})), t2.PageRoute = class {
918
+ constructor(e3, t3, a2, s2, r, o, l, d, c, u) {
919
+ this.id = e3, this.questionRef = t3, this.typeCondition = d || i.LOGICAL, this.typeOperator = a2, this.value = s2 || [], this.transition = r, this.transitionDestiny = o, this.status = n.ACTIVE, this.generatedAt = /* @__PURE__ */ new Date(), this.updatedAt = /* @__PURE__ */ new Date(), this.integrationPageId = l, this.position = c || 0, this.option = u || [];
920
+ }
921
+ };
922
+ }, 558: (e2, t2) => {
923
+ "use strict";
924
+ var i, n;
925
+ Object.defineProperty(t2, "__esModule", { value: true }), t2.QuestionType = t2.FEEDBACKAPPANSWERTYPE = void 0, (n = t2.FEEDBACKAPPANSWERTYPE || (t2.FEEDBACKAPPANSWERTYPE = {})).CONTACT = "CONTACT", n.MULTIPLECHOISE_IMAGE = "MULTIPLECHOISE_IMAGE", n.EMAIL = "EMAIL", n.RATING_STAR = "RATING_STAR", n.RADIO = "RADIO", n.MULTIPLECHOICE = "MULTIPLECHOICE", n.SELECT = "SELECT", n.TEXT = "TEXT", n.LONGTEXT = "LONGTEXT", n.NUMBER = "NUMBER", n.RATING_EMOJI = "RATING_EMOJI", n.RATING_NUMBER = "RATING_NUMBER", n.DATE = "DATE", n.BOOLEAN = "BOOLEAN", n.PASSWORD = "PASSWORD", n.CONSENT = "CONSENT", n.MULTI_QUESTION_MATRIX = "MULTI_QUESTION_MATRIX", n.POINT_SYSTEM = "POINT_SYSTEM", n.PRIORITY_LIST = "PRIORITY_LIST", n.INFO_PAGE = "INFO_PAGE", n.UPLOAD_FILE = "UPLOAD_FILE", n.UPLOAD_IMAGE = "UPLOAD_IMAGE", t2.QuestionType = class {
926
+ }, (function(e3) {
927
+ e3.FORM = "form", e3.DIV = "div";
928
+ })(i || (i = {}));
929
+ }, 857: (e2, t2) => {
930
+ "use strict";
931
+ Object.defineProperty(t2, "__esModule", { value: true }), t2.endpoints = void 0, t2.endpoints = { sdk: { app: (e3, t3) => `sdk/app/${e3}/${t3}`, app_info: (e3, t3) => `sdk/app/${e3}/${t3}/info`, session: (e3) => `sdk/app/session/${e3}/info`, feedback: "sdk/feedback", followUpQuestion: "sdk/followUpQuestion" } };
932
+ }, 784: (e2, t2) => {
933
+ "use strict";
934
+ Object.defineProperty(t2, "__esModule", { value: true }), t2.placeholder = void 0, t2.placeholder = { answer: (e3) => {
935
+ switch (e3) {
936
+ case "en":
937
+ default:
938
+ return "Write your answer here...";
939
+ case "es":
940
+ return "Escribe tu respuesta aqu\xED...";
941
+ case "da":
942
+ return "Skriv dit svar her...";
943
+ case "fi":
944
+ return "Kirjoita vastauksesi t\xE4h\xE4n...";
945
+ case "sv":
946
+ return "Skriv ditt svar h\xE4r...";
947
+ case "no":
948
+ return "Skriv svaret ditt her...";
949
+ case "ar":
950
+ return "\u0627\u0643\u062A\u0628 \u0625\u062C\u0627\u0628\u062A\u0643 \u0647\u0646\u0627...";
951
+ case "bn":
952
+ return "\u098F\u0996\u09BE\u09A8\u09C7 \u0986\u09AA\u09A8\u09BE\u09B0";
953
+ }
954
+ }, number: (e3) => {
955
+ switch (e3) {
956
+ case "en":
957
+ default:
958
+ return "Write your number here...";
959
+ case "es":
960
+ return "Escribe tu n\xFAmero aqu\xED...";
961
+ case "da":
962
+ return "Skriv dit nummer her...";
963
+ case "fi":
964
+ return "Kirjoita numerosi t\xE4h\xE4n...";
965
+ case "sv":
966
+ return "Skriv ditt nummer h\xE4r...";
967
+ case "no":
968
+ return "Skriv nummeret ditt her...";
969
+ case "ar":
970
+ return "\u0627\u0643\u062A\u0628 \u0631\u0642\u0645\u0643 \u0647\u0646\u0627...";
971
+ case "bn":
972
+ return "\u098F\u0996\u09BE\u09A8\u09C7 \u0986\u09AA\u09A8\u09BE\u09B0";
973
+ }
974
+ }, email: (e3) => {
975
+ switch (e3) {
976
+ case "en":
977
+ default:
978
+ return "Write your email here...";
979
+ case "es":
980
+ return "Escribe tu correo electr\xF3nico aqu\xED...";
981
+ case "da":
982
+ return "Skriv din e-mail her...";
983
+ case "fi":
984
+ return "Kirjoita s\xE4hk\xF6postiosoitteesi t\xE4h\xE4n...";
985
+ case "sv":
986
+ return "Skriv din e-post h\xE4r...";
987
+ case "no":
988
+ return "Skriv e-posten din her...";
989
+ case "ar":
990
+ return "\u0627\u0643\u062A\u0628 \u0628\u0631\u064A\u062F\u0643 \u0627\u0644\u0625\u0644\u0643\u062A\u0631\u0648\u0646\u064A \u0647\u0646\u0627...";
991
+ case "bn":
992
+ return "\u098F\u0996\u09BE\u09A8\u09C7 \u0986\u09AA\u09A8\u09BE\u09B0";
993
+ }
994
+ }, date: (e3) => {
995
+ switch (e3) {
996
+ case "en":
997
+ default:
998
+ return "Write your date here...";
999
+ case "es":
1000
+ return "Escribe tu fecha aqu\xED...";
1001
+ case "da":
1002
+ return "Skriv din dato her...";
1003
+ case "fi":
1004
+ return "Kirjoita p\xE4iv\xE4m\xE4\xE4r\xE4si t\xE4h\xE4n...";
1005
+ case "sv":
1006
+ return "Skriv ditt datum h\xE4r...";
1007
+ case "no":
1008
+ return "Skriv datoen din her...";
1009
+ case "ar":
1010
+ return "\u0627\u0643\u062A\u0628 \u062A\u0627\u0631\u064A\u062E\u0643 \u0647\u0646\u0627...";
1011
+ case "bn":
1012
+ return "\u098F\u0996\u09BE\u09A8\u09C7 \u0986\u09AA\u09A8\u09BE\u09B0";
1013
+ }
1014
+ }, password: (e3) => {
1015
+ switch (e3) {
1016
+ case "en":
1017
+ default:
1018
+ return "Write your password here...";
1019
+ case "es":
1020
+ return "Escribe tu contrase\xF1a aqu\xED...";
1021
+ case "da":
1022
+ return "Skriv dit kodeord her...";
1023
+ case "fi":
1024
+ return "Kirjoita salasanasi t\xE4h\xE4n...";
1025
+ case "sv":
1026
+ return "Skriv ditt l\xF6senord h\xE4r...";
1027
+ case "no":
1028
+ return "Skriv passordet ditt her...";
1029
+ case "ar":
1030
+ return "\u0627\u0643\u062A\u0628 \u0643\u0644\u0645\u0629 \u0627\u0644\u0645\u0631\u0648\u0631 \u0627\u0644\u062E\u0627\u0635\u0629 \u0628\u0643 \u0647\u0646\u0627...";
1031
+ case "bn":
1032
+ return "\u098F\u0996\u09BE\u09A8\u09C7 \u0986\u09AA\u09A8\u09BE\u09B0";
1033
+ }
1034
+ }, pointsystemerror: (e3) => {
1035
+ switch (e3) {
1036
+ case "en":
1037
+ default:
1038
+ return "The total points must be 100 %";
1039
+ case "es":
1040
+ return "El total de puntos debe ser 100 %";
1041
+ case "da":
1042
+ return "Samlet antal point skal v\xE6re 100 %";
1043
+ case "fi":
1044
+ return "Kokonaispisteiden on oltava 100 %";
1045
+ case "sv":
1046
+ return "Totala po\xE4ng m\xE5ste vara 100 %";
1047
+ case "no":
1048
+ return "Totalt antall poeng m\xE5 v\xE6re 100 %";
1049
+ case "ar":
1050
+ return "\u064A\u062C\u0628 \u0623\u0646 \u062A\u0643\u0648\u0646 \u0627\u0644\u0646\u0642\u0627\u0637 \u0627\u0644\u0625\u062C\u0645\u0627\u0644\u064A\u0629 100 %";
1051
+ case "bn":
1052
+ return "\u09AE\u09CB\u099F \u09AA\u09AF\u09BC\u09C7\u09A8\u09CD\u099F 100 % \u09B9\u09A4\u09C7 \u09B9\u09AC\u09C7";
1053
+ }
1054
+ } };
1055
+ }, 213: (e2, t2, i) => {
1056
+ "use strict";
1057
+ Object.defineProperty(t2, "__esModule", { value: true }), t2.renderStartMessage = t2.renderSuccess = t2.renderError = t2.renderActions = t2.renderQuestions = void 0;
1058
+ const n = i(558), a = i(784), s = "https://survey-dev.magicfeedback.io/assets/emojis";
1059
+ function r(e3, t3) {
1060
+ return e3 ? "object" == typeof e3 ? e3[t3] || e3.en : e3 : "";
1061
+ }
1062
+ function o(e3, t3, i2, n2, a2, s2 = true, r2 = "ltr", o2 = "row") {
1063
+ const l = document.createElement("div");
1064
+ l.classList.add("magicfeedback-rating-placeholder"), l.style.display = "flex", l.style.flexDirection = o2, l.style.alignItems = "center", l.style.justifyContent = "space-between", l.style.width = a2 ? `calc(100% - (100% / ${t3 + 1}))` : "100%", l.style.marginRight = "auto", s2 && window.innerWidth < 600 && (l.style.flexDirection = "column");
1065
+ const d = document.createElement("span");
1066
+ d.textContent = i2, d.classList.add("magicfeedback-rating-placeholder-value"), d.style.fontSize = "15px", d.style.textAlign = "ltr" === r2 ? "left" : "right", d.style.width = "50%", (s2 && window.innerWidth < 600 || "column" === o2) && (d.textContent = `${e3} = ${i2}`, d.style.width = "100%", d.style.textAlign = "left", d.style.marginBottom = "5px");
1067
+ const c = document.createElement("span");
1068
+ return c.textContent = n2, c.classList.add("magicfeedback-rating-placeholder-value"), c.style.fontSize = "15px", c.style.textAlign = "ltr" === r2 ? "right" : "left", c.style.width = "50%", (s2 && window.innerWidth < 600 || "column" === o2) && (c.textContent = `${t3} = ${n2}`, c.style.width = "100%", c.style.textAlign = "left", c.style.marginBottom = "5px"), "ltr" === r2 ? (i2 && l.appendChild(d), n2 && l.appendChild(c)) : (n2 && l.appendChild(c), i2 && l.appendChild(d)), l;
1069
+ }
1070
+ t2.renderQuestions = function e3(t3, i2 = "standard", l = "en", d = { customIcons: false }, c) {
1071
+ if (!t3) throw new Error("[MagicFeedback] No questions provided");
1072
+ const u = [], { customIcons: p, id: h } = d;
1073
+ return t3.forEach(((m) => {
1074
+ var f, g;
1075
+ if ((null === (g = null === (f = null == m ? void 0 : m.questionType) || void 0 === f ? void 0 : f.conf) || void 0 === g ? void 0 : g.length) > 0) {
1076
+ let t4 = document.createElement("div");
1077
+ t4.classList.add("magicfeedback-div");
1078
+ const n2 = document.createElement("label");
1079
+ n2.setAttribute("for", `magicfeedback-${m.id}`), n2.textContent = r(m.title, l), n2.classList.add("magicfeedback-label"), t4.appendChild(n2), m.questionType.conf.forEach(((e4) => {
1080
+ e4.ref = m.ref, m.assets[e4.id] && (e4.assets = { placeholder: m.assets[e4.id] });
1081
+ })), e3(m.questionType.conf, i2, l, d, c).forEach(((e4) => {
1082
+ t4.appendChild(e4);
1083
+ })), u.push(t4);
1084
+ } else {
1085
+ const e4 = (function(e5, t4, i3, l2, d2) {
1086
+ var c2, u2, p2;
1087
+ let h2, m2, { id: f2, title: g2, type: v, ref: y, require: E, value: b, defaultValue: A, assets: k } = e5, C = document.createElement("div");
1088
+ C.classList.add("magicfeedback-div");
1089
+ const T = window.innerWidth < 600, x = "slim" === t4 ? r(g2, i3) : null == k ? void 0 : k.placeholder, w = (N = y, new URLSearchParams(window.location.search).get(N)), L = (null == k ? void 0 : k.maxCharacters) || 0, P = void 0 !== (null == k ? void 0 : k.randomPosition) && (null == k ? void 0 : k.randomPosition), S = (null == k ? void 0 : k.direction) || "row", O = (null == k ? void 0 : k.order) || "ltr";
1090
+ var N;
1091
+ switch (v) {
1092
+ case n.FEEDBACKAPPANSWERTYPE.TEXT:
1093
+ h2 = document.createElement("input"), h2.type = "text", h2.placeholder = x || a.placeholder.answer(i3 || "en"), w && (h2.value = w), h2.addEventListener("keyup", ((e6) => {
1094
+ e6.preventDefault(), console.log(e6.key, e6), "Enter" === e6.key && d2 && d2();
1095
+ })), m2 = "magicfeedback-text";
1096
+ break;
1097
+ case n.FEEDBACKAPPANSWERTYPE.LONGTEXT:
1098
+ h2 = document.createElement("textarea"), h2.rows = 3, L > 0 && (h2.maxLength = L), h2.placeholder = x || a.placeholder.answer(i3 || "en"), w && (h2.value = w), m2 = "magicfeedback-longtext";
1099
+ break;
1100
+ case n.FEEDBACKAPPANSWERTYPE.NUMBER:
1101
+ h2 = document.createElement("input"), h2.type = "number", h2.placeholder = "slim" === t4 ? r(g2, i3) : a.placeholder.number(i3 || "en"), m2 = "magicfeedback-number", b.length && (b.sort(((e6, t5) => Number(e6) - Number(t5))), h2.max = b[b.length - 1], h2.min = b[0], h2.value = b[0]), w && !isNaN(Number(w)) && (h2.value = w);
1102
+ break;
1103
+ case n.FEEDBACKAPPANSWERTYPE.RADIO:
1104
+ case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:
1105
+ h2 = document.createElement("div"), m2 = "magicfeedback-" + ("MULTIPLECHOICE" === v ? "checkbox" : "radio");
1106
+ let R = b || [];
1107
+ P && (R = R.sort((() => Math.random() - 0.5)));
1108
+ let $ = (null == k ? void 0 : k.exclusiveAnswers) || [];
1109
+ (null == k ? void 0 : k.extraOption) && ($ = $.filter(((e6) => e6 !== k.extraOptionText))), $.length > 0 && (null == $ || $.forEach(((e6) => {
1110
+ R.includes(e6) || R.push(e6);
1111
+ }))), (null == k ? void 0 : k.extraOption) && !R.includes(null == k ? void 0 : k.extraOptionText) && R.push(null == k ? void 0 : k.extraOptionText), R.forEach(((e6, t5) => {
1112
+ const s2 = document.createElement("div");
1113
+ s2.classList.add(`magicfeedback-${"MULTIPLECHOICE" === v ? "checkbox" : "radio"}-container`);
1114
+ const r2 = document.createElement("label"), o2 = document.createElement("input");
1115
+ if (o2.id = `rating-${y}-${t5}`, o2.type = "MULTIPLECHOICE" === v ? "checkbox" : "radio", o2.name = y, o2.value = e6, o2.classList.add(m2), o2.classList.add("magicfeedback-input"), v === n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE && (null == k ? void 0 : k.maxOptions) && (null == k ? void 0 : k.maxOptions) > 0 && o2.addEventListener("change", (() => {
1116
+ document.querySelectorAll(`input[name="${y}"]:checked`).length > (null == k ? void 0 : k.maxOptions) && (o2.checked = false);
1117
+ })), v === n.FEEDBACKAPPANSWERTYPE.RADIO && d2 && (!(null == k ? void 0 : k.extraOptionText) || (null == k ? void 0 : k.extraOptionText) && e6 !== (null == k ? void 0 : k.extraOptionText)) && o2.addEventListener("change", (() => {
1118
+ d2();
1119
+ })), e6 !== A && e6 !== w || (o2.checked = true), r2.textContent = e6, r2.htmlFor = `rating-${y}-${t5}`, o2.addEventListener("change", ((t6) => {
1120
+ const i4 = document.getElementById(`extra-option-${y}`);
1121
+ t6.target.checked && $.includes(e6) ? (console.log("exclusiveAnswers", $, e6), R.forEach(((t7) => {
1122
+ t7 !== e6 && (document.querySelector(`input[value="${t7}"]`).checked = false);
1123
+ })), i4 && (i4.style.display = "none")) : $.forEach(((t7) => {
1124
+ t7 !== e6 && (document.querySelector(`input[value="${t7}"]`).checked = false);
1125
+ })), (null == k ? void 0 : k.extraOption) && e6 === (null == k ? void 0 : k.extraOptionText) && i4 && (i4.style.display = t6.target.checked ? "block" : "none");
1126
+ })), s2.appendChild(o2), s2.appendChild(r2), h2.appendChild(s2), (null == k ? void 0 : k.extraOption) && e6 === (null == k ? void 0 : k.extraOptionText)) {
1127
+ const e7 = document.createElement("input");
1128
+ e7.type = "text", e7.placeholder = (null == k ? void 0 : k.extraOptionPlaceholder) || a.placeholder.answer(i3 || "en"), e7.classList.add("magicfeedback-extra-option"), e7.classList.add("magicfeedback-input"), e7.id = `extra-option-${y}`, e7.name = `extra-option-${y}`, e7.style.display = "none", h2.appendChild(e7);
1129
+ }
1130
+ }));
1131
+ break;
1132
+ case n.FEEDBACKAPPANSWERTYPE.BOOLEAN:
1133
+ h2 = document.createElement("div"), m2 = "magicfeedback-radio";
1134
+ const _ = document.createElement("div");
1135
+ _.classList.add("magicfeedback-boolean-container"), _.style.display = "flex", _.style.flexDirection = "row", _.style.justifyContent = "space-between", _.style.width = "70%", _.style.margin = "auto", ((null == k ? void 0 : k.addIcon) ? ["\u{1F44D}", "\u{1F44E}"] : (function(e6) {
1136
+ switch (e6) {
1137
+ case "es":
1138
+ return ["S\xED", "No"];
1139
+ case "fr":
1140
+ return ["Oui", "Non"];
1141
+ case "de":
1142
+ return ["Ja", "Nein"];
1143
+ case "it":
1144
+ return ["S\xEC", "No"];
1145
+ case "pt":
1146
+ return ["Sim", "N\xE3o"];
1147
+ case "nl":
1148
+ return ["Ja", "Nee"];
1149
+ case "pl":
1150
+ return ["Tak", "Nie"];
1151
+ case "ru":
1152
+ return ["\u0414\u0430", "\u041D\u0435\u0442"];
1153
+ case "ja":
1154
+ return ["\u306F\u3044", "\u3044\u3044\u3048"];
1155
+ case "zh":
1156
+ return ["\u662F", "\u4E0D"];
1157
+ case "ko":
1158
+ return ["\uC608", "\uC544\uB2C8"];
1159
+ case "da":
1160
+ case "sv":
1161
+ return ["Ja", "Nej"];
1162
+ case "fi":
1163
+ return ["Kyll\xE4", "Ei"];
1164
+ case "no":
1165
+ return ["Ja", "Nei"];
1166
+ case "ar":
1167
+ return ["\u0646\u0639\u0645", "\u0644\u0627"];
1168
+ case "bn":
1169
+ return ["\u09B9\u09CD\u09AF\u09BE\u0981", "\u09A8\u09BE"];
1170
+ default:
1171
+ return ["Yes", "No"];
1172
+ }
1173
+ })(i3)).forEach(((e6, t5) => {
1174
+ const i4 = document.createElement("label");
1175
+ i4.classList.add("magicfeedback-boolean-option"), i4.htmlFor = `rating-${y}-${t5}`, i4.style.cursor = "pointer", i4.style.border = "1px solid #000", i4.style.display = "flex", i4.style.justifyContent = "center", i4.style.alignItems = "center", i4.style.margin = "auto", i4.style.padding = "0", i4.style.width = "45%", i4.style.height = "38px";
1176
+ const n2 = document.createElement("label");
1177
+ n2.htmlFor = `rating-${y}-${t5}`, n2.textContent = e6, n2.style.margin = "0", n2.style.padding = "0";
1178
+ const a2 = document.createElement("input");
1179
+ a2.id = `rating-${y}-${t5}`, a2.type = "radio", a2.name = y, a2.value = ["Yes", "No"][t5], a2.classList.add(m2), a2.classList.add("magicfeedback-input"), a2.style.position = "absolute", a2.style.opacity = "0", a2.style.width = "0", a2.style.height = "0", a2.style.margin = "0", a2.addEventListener("change", (() => {
1180
+ d2 && d2();
1181
+ })), w && w.toLowerCase() === a2.value.toLowerCase() && (a2.checked = true), i4.appendChild(a2), i4.appendChild(n2), _.appendChild(i4);
1182
+ })), h2.appendChild(_);
1183
+ break;
1184
+ case n.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:
1185
+ h2 = document.createElement("div"), m2 = "magicfeedback-rating";
1186
+ const F = document.createElement("div");
1187
+ F.classList.add("magicfeedback-rating-container");
1188
+ const M = (null == k ? void 0 : k.max) ? Number(null == k ? void 0 : k.max) : 5, B = (null == k ? void 0 : k.min) ? Number(null == k ? void 0 : k.min) : 1, U = o(B, M, null == k ? void 0 : k.minPlaceholder, null == k ? void 0 : k.maxPlaceholder, null == k ? void 0 : k.extraOption);
1189
+ for (let ce = B; ce <= M; ce++) {
1190
+ const ue = document.createElement("div");
1191
+ ue.classList.add("magicfeedback-rating-option");
1192
+ const pe = document.createElement("label");
1193
+ pe.htmlFor = `rating-${y}-${ce}`, pe.classList.add("magicfeedback-rating-option-label-container");
1194
+ const he = document.createElement("label");
1195
+ he.htmlFor = `rating-${y}-${ce}`, he.textContent = ce.toString();
1196
+ const me = document.createElement("img");
1197
+ if (me.alt = `face-${y}-${ce}`, me.className = `rating-image${ce}`, 0 === B && 10 === M) me.src = `${l2}/${ce}.svg`, me.onerror = () => me.src = `${s}/${ce}.svg`;
1198
+ else if (1 === B && 5 === M) switch (ce) {
1199
+ case 1:
1200
+ me.src = `${l2}/1.svg`, me.onerror = () => me.src = `${s}/1.svg`;
1201
+ break;
1202
+ case 2:
1203
+ me.src = `${l2}/2.svg`, me.onerror = () => me.src = `${s}/2.svg`;
1204
+ break;
1205
+ case 3:
1206
+ me.src = `${l2}/6.svg`, me.onerror = () => me.src = `${s}/6.svg`;
1207
+ break;
1208
+ case 4:
1209
+ me.src = `${l2}/9.svg`, me.onerror = () => me.src = `${s}/9.svg`;
1210
+ break;
1211
+ case 5:
1212
+ me.src = `${l2}/10.svg`, me.onerror = () => me.src = `${s}/10.svg`;
1213
+ }
1214
+ else {
1215
+ const ge = Math.round(10 / (M - B) * (ce - B));
1216
+ me.src = `${l2}/${ge}.svg`, me.onerror = () => me.src = `${s}/${ge}.svg`;
1217
+ }
1218
+ const fe = document.createElement("input");
1219
+ fe.id = `rating-${y}-${ce}`, fe.type = "radio", fe.name = y, fe.value = ce.toString(), fe.classList.add(m2), fe.classList.add("magicfeedback-input"), d2 && fe.addEventListener("change", (() => {
1220
+ d2();
1221
+ })), w && w === fe.value && (fe.checked = true), pe.appendChild(fe), pe.appendChild(me), pe.appendChild(he), ue.appendChild(pe), F.appendChild(ue);
1222
+ }
1223
+ if ((null == k ? void 0 : k.extraOption) && (null == k ? void 0 : k.extraOptionText)) {
1224
+ const ve = document.createElement("div");
1225
+ ve.classList.add("magicfeedback-rating-option");
1226
+ const ye = document.createElement("label");
1227
+ ye.htmlFor = `rating-${y}-extra`, ye.classList.add("magicfeedback-rating-option-label-container");
1228
+ const Ee = document.createElement("label");
1229
+ Ee.htmlFor = `rating-${y}-extra`, Ee.textContent = null == k ? void 0 : k.extraOptionText;
1230
+ const be = document.createElement("img");
1231
+ be.src = "https://magicfeedback-c6458-dev.web.app/assets/question.svg", be.alt = `face-${y}-extra`, be.className = "magicfeedback-rating-image-extra";
1232
+ const Ae = document.createElement("input");
1233
+ Ae.id = `rating-${y}-extra`, Ae.type = "radio", Ae.name = y, Ae.value = "-", Ae.classList.add(m2), Ae.classList.add("magicfeedback-input"), d2 && Ae.addEventListener("change", (() => {
1234
+ d2();
1235
+ })), ye.appendChild(Ae), ye.appendChild(be), ye.appendChild(Ee), ve.appendChild(ye), F.appendChild(ve);
1236
+ }
1237
+ h2.appendChild(U), h2.appendChild(F);
1238
+ break;
1239
+ case n.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:
1240
+ m2 = "magicfeedback-rating-number", h2 = (function(e6, t5, i4, n2, a2, s2, r2, o2) {
1241
+ const l3 = document.createElement("div");
1242
+ l3.classList.add("magicfeedback-rating-number");
1243
+ const d3 = "ltr" === i4 ? n2 : `${n2}-reverse`, c3 = document.createElement("div");
1244
+ c3.classList.add("magicfeedback-rating-number-container"), c3.classList.add(`magicfeedback-rating-number-container-${i4}`), c3.classList.add(`magicfeedback-rating-number-container-${n2}`), c3.style.display = "flex", c3.style.flexDirection = d3, c3.setAttribute("role", "radiogroup"), c3.setAttribute("aria-label", (null == t5 ? void 0 : t5.ariaLabel) || "Rating");
1245
+ const u3 = (null == t5 ? void 0 : t5.max) ? Number(null == t5 ? void 0 : t5.max) : 10, p3 = (null == t5 ? void 0 : t5.min) ? Number(null == t5 ? void 0 : t5.min) : 0, h3 = !(a2 || "column" === n2);
1246
+ for (let i5 = p3; i5 <= u3; i5++) {
1247
+ const a3 = document.createElement("div");
1248
+ a3.classList.add("magicfeedback-rating-number-option"), a3.classList.add(`magicfeedback-rating-number-option-${n2}`);
1249
+ const l4 = document.createElement("label");
1250
+ if (l4.htmlFor = `rating-${e6}-${i5}`, l4.classList.add("magicfeedback-rating-number-option-label-container"), h3 && (l4.style.position = "relative", l4.style.overflow = "visible"), h3) {
1251
+ const e7 = document.createElement("span");
1252
+ e7.classList.add("magicfeedback-rating-number-cap"), e7.classList.add("magicfeedback-rating-placeholder-value"), e7.style.fontSize = "14px", e7.style.whiteSpace = "nowrap", e7.style.wordBreak = "normal", i5 === p3 && (null == t5 ? void 0 : t5.minPlaceholder) ? (e7.textContent = t5.minPlaceholder, e7.dataset.capType = "min") : i5 === u3 && (null == t5 ? void 0 : t5.maxPlaceholder) ? (e7.textContent = t5.maxPlaceholder, e7.dataset.capType = "max") : e7.dataset.capType = "mid", l4.appendChild(e7);
1253
+ }
1254
+ let d4 = i5.toString();
1255
+ h3 || (i5 === p3 && (null == t5 ? void 0 : t5.minPlaceholder) && (d4 += ` = ${null == t5 ? void 0 : t5.minPlaceholder}`), i5 === u3 && (null == t5 ? void 0 : t5.maxPlaceholder) && (d4 += ` = ${null == t5 ? void 0 : t5.maxPlaceholder}`));
1256
+ const m3 = document.createElement("input");
1257
+ m3.id = `rating-${e6}-${i5}`, m3.type = "radio", m3.name = e6, m3.value = i5.toString(), m3.classList.add(s2), m3.classList.add("magicfeedback-input"), m3.setAttribute("aria-label", `${i5}`), r2 && m3.addEventListener("change", (() => r2())), o2 && o2 === m3.value && (m3.checked = true);
1258
+ const f3 = document.createElement("label");
1259
+ f3.htmlFor = `rating-${e6}-${i5}`, f3.textContent = d4, f3.classList.add("magicfeedback-rating-number-value"), l4.appendChild(m3), l4.appendChild(f3), a3.appendChild(l4), c3.appendChild(a3);
1260
+ }
1261
+ if ((null == t5 ? void 0 : t5.extraOption) && (null == t5 ? void 0 : t5.extraOptionText)) {
1262
+ const n3 = document.createElement("div");
1263
+ n3.classList.add("magicfeedback-rating-number-option");
1264
+ const a3 = document.createElement("label");
1265
+ if (a3.htmlFor = `rating-${e6}-extra`, a3.classList.add("magicfeedback-rating-number-option-label-container"), h3 && (a3.style.position = "relative", a3.style.overflow = "visible"), h3) {
1266
+ const e7 = document.createElement("span");
1267
+ e7.classList.add("magicfeedback-rating-number-cap"), e7.dataset.capType = "extra", e7.style.fontSize = "12px", e7.style.whiteSpace = "nowrap", e7.style.wordBreak = "normal", a3.appendChild(e7);
1268
+ }
1269
+ const o3 = document.createElement("input");
1270
+ o3.id = `rating-${e6}-extra`, o3.type = "radio", o3.name = e6, o3.value = "-", o3.classList.add(s2), o3.classList.add("magicfeedback-input"), o3.setAttribute("aria-label", null == t5 ? void 0 : t5.extraOptionText), r2 && o3.addEventListener("change", (() => r2()));
1271
+ const l4 = document.createElement("label");
1272
+ l4.htmlFor = `rating-${e6}-extra`, l4.textContent = null == t5 ? void 0 : t5.extraOptionText, l4.classList.add("magicfeedback-rating-number-value"), a3.appendChild(o3), a3.appendChild(l4), n3.appendChild(a3), "ltr" === i4 ? c3.appendChild(n3) : c3.insertBefore(n3, c3.firstChild);
1273
+ }
1274
+ return l3.appendChild(c3), h3 && requestAnimationFrame((() => {
1275
+ const e7 = Array.from(c3.querySelectorAll(".magicfeedback-rating-number-cap"));
1276
+ if (0 === e7.length) return;
1277
+ let t6 = 0;
1278
+ e7.forEach(((e8) => {
1279
+ var i5;
1280
+ if (null === (i5 = e8.textContent) || void 0 === i5 ? void 0 : i5.trim()) {
1281
+ const i6 = e8.getBoundingClientRect().height || 0;
1282
+ i6 > t6 && (t6 = i6);
1283
+ }
1284
+ })), c3.style.position = "relative", c3.style.paddingTop = `${0 === t6 ? "42" : t6 + 6}px`, e7.forEach(((e8) => {
1285
+ const n3 = e8.getBoundingClientRect().height || 0;
1286
+ console.log(t6, n3, 6), e8.style.position = "absolute", e8.style.top = `-${0 === t6 ? "42" : t6 + n3}px`, e8.style.zIndex = "1", e8.style.pointerEvents = "none", e8.style.padding = "0", e8.style.boxSizing = "border-box", e8.style.whiteSpace = "nowrap", e8.style.wordBreak = "normal", e8.style.maxWidth = "none", e8.style.width = "max-content";
1287
+ const a3 = e8.dataset.capType;
1288
+ "min" === a3 ? ("ltr" === i4 ? (e8.style.left = "10px", e8.style.textAlign = "left") : (e8.style.right = "10px", e8.style.textAlign = "right"), e8.style.transform = "none") : "max" === a3 ? ("ltr" === i4 ? (e8.style.right = "10px", e8.style.textAlign = "right") : (e8.style.left = "10px", e8.style.textAlign = "left"), e8.style.transform = "none") : (e8.style.left = "50%", e8.style.transform = "translateX(-50%)", e8.style.textAlign = "center");
1289
+ })), c3.style.overflow = "visible";
1290
+ })), l3;
1291
+ })(y, k, O, S, T, m2, d2, w);
1292
+ break;
1293
+ case n.FEEDBACKAPPANSWERTYPE.RATING_STAR:
1294
+ h2 = document.createElement("div"), m2 = "magicfeedback-rating-star";
1295
+ const q = (function(e6, t5, i4, n2 = () => {
1296
+ }, a2) {
1297
+ const s2 = "magicfeedback-rating-star-selected", r2 = document.createElement("div");
1298
+ r2.classList.add("magicfeedback-rating-star-container"), r2.style.maxWidth = "300px", r2.style.margin = "auto", r2.dataset.originalSelection = "0";
1299
+ for (let t6 = 1; t6 <= 5; t6++) {
1300
+ const i5 = document.createElement("label");
1301
+ i5.classList.add("magicfeedback-rating-star-option");
1302
+ const o2 = document.createElement("input");
1303
+ o2.id = `rating-${e6}-${t6}`, o2.type = "radio", o2.name = e6, o2.value = t6.toString(), o2.style.position = "absolute", o2.style.opacity = "0", o2.style.width = "0", o2.style.height = "0", o2.classList.add("magicfeedback-input"), a2 && a2 === o2.value && (o2.checked = true), o2.addEventListener("change", (() => {
1304
+ const e7 = r2.querySelectorAll(".rating__star");
1305
+ for (let t7 = 0; t7 < e7.length; t7++) t7 + 1 <= Number(o2.value) ? e7[t7].classList.contains(s2) || e7[t7].classList.add(s2) : e7[t7].classList.contains(s2) && e7[t7].classList.remove(s2);
1306
+ r2.dataset.originalSelection = o2.value, n2 && n2();
1307
+ })), i5.appendChild(o2);
1308
+ const l3 = document.createElement("label");
1309
+ l3.htmlFor = `rating-${e6}-${t6}`, l3.classList.add("rating__star"), l3.textContent = "\u2605", l3.style.fontSize = "40px", l3.style.color = "#CCCCCC", l3.style.cursor = "pointer", l3.addEventListener("mouseenter", (() => {
1310
+ const e7 = r2.querySelectorAll(".rating__star"), i6 = t6 - 1;
1311
+ e7.forEach(((e8, t7) => {
1312
+ t7 <= i6 ? e8.classList.contains(s2) || e8.classList.add(s2) : e8.classList.contains(s2) && e8.classList.remove(s2);
1313
+ }));
1314
+ })), l3.addEventListener("mouseleave", (() => {
1315
+ const e7 = Number(r2.dataset.originalSelection || "0");
1316
+ r2.querySelectorAll(".rating__star").forEach(((t7, i6) => {
1317
+ i6 < e7 ? t7.classList.contains(s2) || t7.classList.add(s2) : t7.classList.contains(s2) && t7.classList.remove(s2);
1318
+ }));
1319
+ })), i5.appendChild(l3), r2.appendChild(i5);
1320
+ }
1321
+ return r2.appendChild(o(1, 5, t5, i4, false, false)), r2;
1322
+ })(y, null == k ? void 0 : k.minPlaceholder, null == k ? void 0 : k.maxPlaceholder, d2, w);
1323
+ h2.appendChild(q);
1324
+ break;
1325
+ case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:
1326
+ let V = function(e6) {
1327
+ try {
1328
+ const { position: t5, url: i4, value: n2 } = e6, a2 = document.createElement("label");
1329
+ a2.classList.add("magicfeedback-multiple-choice-image-option"), a2.style.width = `calc( ${100 / W}% - 10px)`, a2.style.height = `calc( ${100 / K}% - 10px)`, a2.style.margin = "5px";
1330
+ const s2 = document.createElement("label");
1331
+ s2.htmlFor = `rating-${y}-${t5}`, s2.classList.add("magicfeedback-image-option-label-container"), s2.style.display = "flex", s2.style.flexDirection = "column", s2.addEventListener("mouseover", (() => {
1332
+ s2.style.border = "2px solid #000";
1333
+ })), s2.addEventListener("mouseout", (() => {
1334
+ s2.style.border = "none";
1335
+ })), s2.addEventListener("click", (() => {
1336
+ s2.style.border = "2px solid #000";
1337
+ }));
1338
+ const r2 = document.createElement("label");
1339
+ r2.textContent = n2, r2.classList.add("magicfeedback-multiple-choice-image-label");
1340
+ const o2 = document.createElement("input");
1341
+ o2.id = `rating-${y}-${t5}`, o2.type = Y ? "checkbox" : "radio", o2.name = y, o2.value = n2, o2.style.position = "absolute", o2.style.opacity = "0", o2.style.width = "0", o2.style.height = "0", o2.classList.add("magicfeedback-input"), w && w === o2.value && (o2.checked = true), !Y && d2 && o2.addEventListener("change", (() => {
1342
+ console.log("send"), d2();
1343
+ }));
1344
+ const l3 = document.createElement("img");
1345
+ l3.classList.add("magicfeedback-multiple-choice-image-image"), l3.src = i4, l3.style.cursor = "pointer", l3.style.backgroundSize = "cover", l3.style.backgroundPosition = "center", l3.style.width = "100%", l3.style.height = "100%", l3.style.objectFit = "cover", l3.style.margin = "auto", s2.appendChild(o2), s2.appendChild(l3), G && s2.appendChild(r2), a2.appendChild(s2), j.appendChild(a2);
1346
+ } catch (e7) {
1347
+ console.error(e7);
1348
+ }
1349
+ };
1350
+ h2 = document.createElement("div"), m2 = "magicfeedback-multiple-choice-image";
1351
+ const j = document.createElement("div");
1352
+ j.classList.add("magicfeedback-multiple-choice-image-container"), j.style.display = "flex", j.style.flexDirection = "row", j.style.flexWrap = "wrap", j.style.justifyContent = "center";
1353
+ const Q = b.length;
1354
+ let W = 1, K = 1;
1355
+ if (window.innerWidth < 600) W = 1, K = Q;
1356
+ else switch (Q) {
1357
+ case 1:
1358
+ case 2:
1359
+ case 3:
1360
+ W = Q, K = 1;
1361
+ break;
1362
+ case 4:
1363
+ case 5:
1364
+ case 6:
1365
+ K = 2, W = Math.ceil(Q / K);
1366
+ break;
1367
+ case 7:
1368
+ case 8:
1369
+ case 9:
1370
+ K = 3, W = Math.ceil(Q / K);
1371
+ break;
1372
+ default:
1373
+ K = 4, W = Math.ceil(Q / K);
1374
+ }
1375
+ const G = void 0 !== (null == k ? void 0 : k.addTitle) && (null == k ? void 0 : k.addTitle), Y = void 0 !== (null == k ? void 0 : k.multiOption) && (null == k ? void 0 : k.multiOption), H = void 0 !== (null == k ? void 0 : k.extraOption) && (null == k ? void 0 : k.extraOption);
1376
+ P && (b = b.sort((() => Math.random() - 0.5))), b.forEach(((e6) => V(JSON.parse(e6)))), H && (null == k ? void 0 : k.extraOptionValue) && (null == k ? void 0 : k.extraOptionValue.length) > 0 && V(null == k ? void 0 : k.extraOptionValue[0]), h2.appendChild(j);
1377
+ break;
1378
+ case n.FEEDBACKAPPANSWERTYPE.SELECT:
1379
+ h2 = document.createElement("select"), m2 = "magicfeedback-select";
1380
+ const X = document.createElement("option");
1381
+ X.value = "", X.text = "slim" === t4 ? r(g2, i3) : A || "Select an option", X.disabled = true, X.selected = true, h2.appendChild(X), b.forEach(((e6) => {
1382
+ const t5 = document.createElement("option");
1383
+ t5.value = e6, t5.text = e6, h2.appendChild(t5);
1384
+ })), w && b.includes(w) && (h2.value = w), d2 && h2.addEventListener("change", (() => {
1385
+ d2();
1386
+ }));
1387
+ break;
1388
+ case n.FEEDBACKAPPANSWERTYPE.DATE:
1389
+ h2 = document.createElement("input"), h2.type = "date", h2.required = E, h2.placeholder = x || a.placeholder.date(i3 || "en"), m2 = "magicfeedback-date", w && (h2.value = w);
1390
+ break;
1391
+ case n.FEEDBACKAPPANSWERTYPE.CONSENT:
1392
+ h2 = document.createElement("input"), m2 = "magicfeedback-consent", h2.type = "checkbox", h2.id = `magicfeedback-${f2}`, h2.name = y, h2.value = "true", h2.required = E, h2.classList.add("magicfeedback-consent"), h2.classList.add("magicfeedback-input"), w && b.includes(w) && (h2.checked = true), d2 && h2.addEventListener("change", (() => {
1393
+ d2();
1394
+ }));
1395
+ break;
1396
+ case n.FEEDBACKAPPANSWERTYPE.EMAIL:
1397
+ h2 = document.createElement("input"), h2.type = "email", h2.required = E, h2.placeholder = x || "you@example.com", m2 = "magicfeedback-email", w && (h2.value = w);
1398
+ break;
1399
+ case n.FEEDBACKAPPANSWERTYPE.PASSWORD:
1400
+ h2 = document.createElement("input"), h2.type = "password", h2.required = E, h2.placeholder = x || a.placeholder.password(i3 || "en"), m2 = "magicfeedback-password", w && (h2.value = w);
1401
+ break;
1402
+ case n.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:
1403
+ h2 = document.createElement("div"), m2 = "magicfeedback-multi-question-matrix";
1404
+ const z = document.createElement("div");
1405
+ z.classList.add("magicfeedback-multi-question-matrix-container");
1406
+ let J = (null == k ? void 0 : k.options) || [], Z = [...b], ee = [];
1407
+ if (P && (J = null == J ? void 0 : J.sort((() => Math.random() - 0.5)), Z = [...Z].sort((() => Math.random() - 0.5))), (null == k ? void 0 : k.exclusiveAnswers) && (ee = null == k ? void 0 : k.exclusiveAnswers, null == ee || ee.forEach(((e6) => {
1408
+ Z.includes(e6) || Z.push(e6);
1409
+ }))), window.innerWidth < 600) {
1410
+ const ke = document.createElement("div");
1411
+ ke.classList.add("magicfeedback-multi-question-matrix-list"), null == J || J.forEach(((e6) => {
1412
+ const t5 = document.createElement("div");
1413
+ t5.classList.add("magicfeedback-multi-question-matrix-list-item"), t5.style.display = "flex", t5.style.flexDirection = "column", t5.style.alignItems = "flex-start", t5.style.marginBottom = "10px";
1414
+ const i4 = document.createElement("label");
1415
+ i4.classList.add("magicfeedback-multi-question-matrix-label"), i4.style.paddingBottom = "10px", i4.textContent = e6, t5.appendChild(i4), Z.forEach(((i5) => {
1416
+ const n2 = document.createElement("div");
1417
+ n2.classList.add("magicfeedback-radio-container"), n2.style.display = "flex", n2.style.alignItems = "center", n2.style.justifyContent = "flex-start", n2.style.width = "99%", n2.style.margin = "5px auto";
1418
+ const a2 = document.createElement("label"), s2 = document.createElement("input");
1419
+ s2.id = `${y}-${e6}-${i5}`, s2.type = "radio", s2.name = `${y}-${e6}`, s2.value = i5, s2.classList.add("magicfeedback-input"), a2.textContent = i5, a2.htmlFor = `${y}-${e6}-${i5}`, n2.appendChild(s2), n2.appendChild(a2), t5.appendChild(n2);
1420
+ })), ke.appendChild(t5);
1421
+ })), z.appendChild(ke);
1422
+ } else {
1423
+ const Ce = document.createElement("table");
1424
+ Ce.classList.add("magicfeedback-multi-question-matrix-table");
1425
+ const Te = document.createElement("thead");
1426
+ Te.classList.add("magicfeedback-multi-question-matrix-header"), Te.style.paddingBottom = "15px";
1427
+ const xe = document.createElement("tr"), we = document.createElement("th");
1428
+ xe.appendChild(we), Z.forEach(((e6) => {
1429
+ const t5 = document.createElement("th");
1430
+ t5.textContent = e6, xe.appendChild(t5);
1431
+ })), Te.appendChild(xe), Ce.appendChild(Te);
1432
+ const Le = document.createElement("tbody");
1433
+ null == J || J.forEach(((e6) => {
1434
+ const t5 = document.createElement("tr");
1435
+ t5.classList.add("magicfeedback-multi-question-matrix-row-tr");
1436
+ const i4 = document.createElement("td");
1437
+ i4.style.minWidth = "200px";
1438
+ const n2 = document.createElement("label");
1439
+ n2.classList.add("magicfeedback-multi-question-matrix-label"), n2.style.paddingRight = "20px", n2.textContent = e6, i4.appendChild(n2), t5.appendChild(i4), Z.forEach(((i5) => {
1440
+ const n3 = document.createElement("td"), a2 = document.createElement("input");
1441
+ a2.type = "radio", a2.name = `${y}-${e6}`, a2.value = i5, a2.id = `${y}-${e6}-${i5}`, a2.classList.add("magicfeedback-input"), n3.appendChild(a2), t5.appendChild(n3);
1442
+ })), Le.appendChild(t5);
1443
+ })), Ce.appendChild(Le), z.appendChild(Ce);
1444
+ }
1445
+ h2.appendChild(z);
1446
+ break;
1447
+ case n.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:
1448
+ h2 = document.createElement("div"), m2 = "magicfeedback-priority-list";
1449
+ const te = document.createElement("div");
1450
+ te.classList.add("magicfeedback-priority-list-container");
1451
+ const ie = document.createElement("ul");
1452
+ ie.classList.add("magicfeedback-priority-list-list"), P && (b = b.sort((() => Math.random() - 0.5))), b.forEach(((e6, t5) => {
1453
+ const i4 = document.createElement("li");
1454
+ i4.classList.add("magicfeedback-priority-list-item"), i4.style.display = "flex", i4.style.justifyContent = "space-between", i4.style.alignItems = "center", i4.style.margin = "5px";
1455
+ const n2 = document.createElement("input");
1456
+ n2.classList.add("magicfeedback-input-magicfeedback-priority-list"), n2.classList.add("magicfeedback-input"), n2.type = "hidden", n2.id = `priority-list-${y}`, n2.name = y, n2.value = `${t5 + 1}. ${e6}`, i4.appendChild(n2);
1457
+ const a2 = document.createElement("label");
1458
+ a2.classList.add("magicfeedback-priority-list-item-label"), a2.textContent = `${t5 + 1}. ${e6}`, i4.appendChild(a2);
1459
+ const s2 = document.createElement("div");
1460
+ s2.style.display = "flex", s2.style.alignItems = "center", s2.style.justifyContent = "space-between";
1461
+ const r2 = document.createElement("img");
1462
+ r2.classList.add("magicfeedback-priority-list-arrow-up"), r2.src = "https://magicfeedback-c6458-dev.web.app/assets/arrow.svg", r2.style.width = "20px", r2.style.height = "20px", r2.style.cursor = "pointer", r2.style.margin = "0 5px", r2.style.color = "#000", r2.style.visibility = 0 === t5 ? "hidden" : "visible", r2.addEventListener("click", (() => {
1463
+ var t6, s3, l3, d3;
1464
+ const c3 = i4.previousElementSibling;
1465
+ if (c3) {
1466
+ const u3 = Number(null === (t6 = n2.value) || void 0 === t6 ? void 0 : t6.split(".")[0]) - 1;
1467
+ n2.value = `${u3}. ${e6}`, a2.textContent = `${u3}. ${e6}`, r2.style.visibility = 1 === u3 ? "hidden" : "visible", o2.style.visibility = u3 === b.length ? "hidden" : "visible";
1468
+ const p3 = c3.querySelector(".magicfeedback-input-magicfeedback-priority-list"), h3 = c3.querySelector(".magicfeedback-priority-list-item-label"), m3 = c3.querySelector(".magicfeedback-priority-list-arrow-up"), f3 = c3.querySelector(".magicfeedback-priority-list-arrow-down");
1469
+ if (p3 && h3 && m3 && f3) {
1470
+ const e7 = Number(null === (s3 = p3.value) || void 0 === s3 ? void 0 : s3.split(".")[0]) + 1;
1471
+ p3.value = `${e7}.${null === (l3 = h3.textContent) || void 0 === l3 ? void 0 : l3.split(".")[1]}`, h3.textContent = `${e7}.${null === (d3 = h3.textContent) || void 0 === d3 ? void 0 : d3.split(".")[1]}`, m3.style.visibility = 1 === e7 ? "hidden" : "visible", f3.style.visibility = e7 === b.length ? "hidden" : "visible";
1472
+ }
1473
+ ie.insertBefore(i4, c3);
1474
+ }
1475
+ })), s2.appendChild(r2);
1476
+ const o2 = document.createElement("img");
1477
+ o2.classList.add("magicfeedback-priority-list-arrow-down"), o2.src = "https://magicfeedback-c6458-dev.web.app/assets/arrow.svg", o2.style.width = "20px", o2.style.height = "20px", o2.style.cursor = "pointer", o2.style.margin = "0 5px", o2.style.color = "#000", o2.style.transform = "rotate(180deg)", o2.style.visibility = t5 === b.length - 1 ? "hidden" : "visible", o2.addEventListener("click", (() => {
1478
+ var t6, s3, l3;
1479
+ const d3 = i4.nextElementSibling;
1480
+ if (d3) {
1481
+ const c3 = Number(null === (t6 = n2.value) || void 0 === t6 ? void 0 : t6.split(".")[0]) + 1;
1482
+ n2.value = c3.toString(), a2.textContent = `${c3.toString()}. ${e6}`, r2.style.visibility = 1 === c3 ? "hidden" : "visible", o2.style.visibility = c3 === b.length ? "hidden" : "visible";
1483
+ const u3 = d3.querySelector(".magicfeedback-input-magicfeedback-priority-list"), p3 = d3.querySelector(".magicfeedback-priority-list-item-label"), h3 = d3.querySelector(".magicfeedback-priority-list-arrow-up"), m3 = d3.querySelector(".magicfeedback-priority-list-arrow-down");
1484
+ if (u3 && p3 && h3 && m3) {
1485
+ const e7 = Number(u3.value.split(".")[0]) - 1;
1486
+ u3.value = `${e7}.${null === (s3 = p3.textContent) || void 0 === s3 ? void 0 : s3.split(".")[1]}`, p3.textContent = `${e7}.${null === (l3 = p3.textContent) || void 0 === l3 ? void 0 : l3.split(".")[1]}`, h3.style.visibility = 1 === e7 ? "hidden" : "visible", m3.style.visibility = e7 === b.length ? "hidden" : "visible";
1487
+ }
1488
+ ie.insertBefore(d3, i4);
1489
+ }
1490
+ })), s2.appendChild(o2), i4.appendChild(s2), ie.appendChild(i4);
1491
+ })), te.appendChild(ie), h2.appendChild(te);
1492
+ break;
1493
+ case n.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:
1494
+ h2 = document.createElement("div"), m2 = "magicfeedback-point-system";
1495
+ const ne = document.createElement("div");
1496
+ ne.classList.add("magicfeedback-point-system-container");
1497
+ const ae = document.createElement("ul");
1498
+ ae.classList.add("magicfeedback-point-system-list"), ae.style.padding = "0";
1499
+ const se = 100, re = se / b.length, oe = document.createElement("div");
1500
+ oe.classList.add("magicfeedback-error"), oe.textContent = a.placeholder.pointsystemerror(i3 || "en"), oe.style.color = "#C70039", oe.style.fontSize = "14px", oe.style.textAlign = "right", oe.style.width = "100%", oe.style.display = "none";
1501
+ const le = document.createElement("div");
1502
+ le.classList.add("magicfeedback-point-system-total"), le.textContent = "0 / 100 %", le.style.textAlign = "right", le.style.fontSize = "15px", le.style.marginTop = "5px", b.forEach(((e6, t5) => {
1503
+ const i4 = document.createElement("li");
1504
+ i4.classList.add("magicfeedback-point-system-item"), i4.style.display = "flex", i4.style.justifyContent = "space-between", i4.style.alignItems = "center", i4.style.margin = "5px";
1505
+ const n2 = document.createElement("label");
1506
+ n2.textContent = e6, n2.style.fontSize = "15px", i4.appendChild(n2);
1507
+ const a2 = document.createElement("span");
1508
+ a2.classList.add("magicfeedback-point-system-input-container");
1509
+ const s2 = document.createElement("input");
1510
+ s2.name = y, s2.id = `${e6}`, s2.type = "number", s2.min = "0", s2.max = `${se}`, s2.value = "0", s2.classList.add("magicfeedback-input"), s2.style.width = "40px", s2.style.border = "0", s2.style.textAlign = "center", s2.style.margin = "0 5px", s2.autofocus = 0 === t5;
1511
+ const r2 = document.createElement("span");
1512
+ r2.textContent = "%", r2.style.color = "#000", s2.addEventListener("input", (() => {
1513
+ const e7 = ae.querySelectorAll("input");
1514
+ let t6 = 0;
1515
+ e7.forEach(((e8) => {
1516
+ t6 += Number(e8.value);
1517
+ })), t6 > se && (s2.value = `${re}%`, t6 -= Number(s2.value));
1518
+ const i5 = document.getElementById("magicfeedback-submit");
1519
+ i5 && (t6 < 100 ? (le.style.color = "orange", i5.setAttribute("disabled", "true")) : (oe.style.display = "none", le.style.color = "green", i5.removeAttribute("disabled"))), le.textContent = `${t6} / 100 %`;
1520
+ })), s2.addEventListener("focus", (() => {
1521
+ const e7 = document.getElementById("magicfeedback-submit");
1522
+ e7 && (e7.setAttribute("disabled", "true"), e7.addEventListener("pointerover", (() => {
1523
+ const e8 = ae.querySelectorAll("input");
1524
+ let t6 = 0;
1525
+ e8.forEach(((e9) => {
1526
+ t6 += Number(e9.value);
1527
+ })), t6 < 100 && (oe.style.display = "block");
1528
+ })));
1529
+ })), a2.appendChild(s2), a2.appendChild(r2), i4.appendChild(a2), ae.appendChild(i4);
1530
+ })), ne.appendChild(ae), ne.appendChild(le), ne.appendChild(oe), h2.appendChild(ne);
1531
+ break;
1532
+ case n.FEEDBACKAPPANSWERTYPE.INFO_PAGE:
1533
+ h2 = document.createElement("div"), m2 = "magicfeedback-info-page";
1534
+ const de = document.createElement("div");
1535
+ de.classList.add("magicfeedback-info-message"), de.innerHTML = x, h2.appendChild(de);
1536
+ break;
1537
+ case n.FEEDBACKAPPANSWERTYPE.UPLOAD_IMAGE:
1538
+ h2 = document.createElement("input"), h2.type = "file", h2.accept = "image/*", h2.required = E, h2.multiple = (null == k ? void 0 : k.multiple) || false, h2.maxLength = (null == k ? void 0 : k.maxFiles) || 1, m2 = "magicfeedback-upload-image";
1539
+ break;
1540
+ case n.FEEDBACKAPPANSWERTYPE.UPLOAD_FILE:
1541
+ h2 = document.createElement("input"), h2.type = "file", h2.required = E, h2.multiple = (null == k ? void 0 : k.multiple) || false, h2.maxLength = (null == k ? void 0 : k.maxFiles) || 1, m2 = "magicfeedback-upload-file";
1542
+ break;
1543
+ default:
1544
+ return C;
1545
+ }
1546
+ h2.id = `magicfeedback-${f2}`, h2.setAttribute("name", y), h2.classList.add(m2), (void 0 !== A || null !== w) && (h2.value = w || A), ["RADIO", "MULTIPLECHOICE"].includes(v) || (h2.classList.add("magicfeedback-input"), h2.required = E);
1547
+ const I = document.createElement("label");
1548
+ I.setAttribute("for", `magicfeedback-${f2}`), I.textContent = r(g2, i3), I.classList.add("magicfeedback-label");
1549
+ const D = document.createElement("label");
1550
+ if (D.textContent = r(null == k ? void 0 : k.subtitle, i3), D.classList.add("magicfeedback-sublabel"), (null === (c2 = null == k ? void 0 : k.subtitleStyle) || void 0 === c2 ? void 0 : c2.includes("italic")) && (D.style.fontStyle = "italic"), (null === (u2 = null == k ? void 0 : k.subtitleStyle) || void 0 === u2 ? void 0 : u2.includes("bold")) && (D.style.fontWeight = "bold"), (null === (p2 = null == k ? void 0 : k.subtitleStyle) || void 0 === p2 ? void 0 : p2.includes("underline")) && (D.style.textDecoration = "underline"), ["CONSENT"].includes(v)) C.classList.add("magicfeedback-consent-container"), C.appendChild(h2), C.appendChild(I), C.appendChild(D);
1551
+ else {
1552
+ if ("slim" !== t4 && (C.appendChild(I), C.appendChild(D), void 0 !== (null == k ? void 0 : k.general) && "" !== (null == k ? void 0 : k.general))) {
1553
+ const Pe = document.createElement("img");
1554
+ Pe.src = null == k ? void 0 : k.general, Pe.classList.add("magicfeedback-image"), Pe.style.maxWidth = "auto", Pe.style.height = "400px", Pe.style.margin = "10px 0", C.appendChild(Pe);
1555
+ }
1556
+ if ("LONGTEXT" === v && L > 0) {
1557
+ const Se = document.createElement("div");
1558
+ if (Se.classList.add("magicfeedback-counter"), Se.textContent = `${h2.value.length}/${L}`, Se.style.textAlign = "right", Se.style.fontSize = "15px", Se.style.marginTop = "5px", h2.addEventListener("input", (() => {
1559
+ Se.textContent = `${h2.value.length}/${L}`;
1560
+ })), C.appendChild(h2), C.appendChild(Se), (null == k ? void 0 : k.extraOption) && (null == k ? void 0 : k.extraOptionText)) {
1561
+ const Oe = document.createElement("div");
1562
+ Oe.classList.add("magicfeedback-skip-container"), Oe.classList.add("magicfeedback-checkbox-container"), Oe.style.display = "flex", Oe.style.justifyContent = "flex-start";
1563
+ const Ne = document.createElement("input");
1564
+ Ne.classList.add("magicfeedback-skip"), Ne.type = "checkbox", Ne.id = `skip-${y}`, Ne.name = y, Ne.value = "-", Ne.style.cursor = "pointer";
1565
+ const Ie = document.createElement("label");
1566
+ Ie.htmlFor = `skip-${y}`, Ie.textContent = null == k ? void 0 : k.extraOptionText, Ie.style.fontSize = "15px", Ie.style.cursor = "pointer", Ie.style.margin = "0 5px", Ne.addEventListener("click", (() => {
1567
+ h2.value = "-", d2 && d2();
1568
+ })), Oe.appendChild(Ne), Oe.appendChild(Ie), C.appendChild(Oe);
1569
+ }
1570
+ } else C.appendChild(h2);
1571
+ }
1572
+ return C;
1573
+ })(m, i2, l, `${s}${p ? `/${h}` : ""}`, 1 === t3.length ? c : void 0);
1574
+ u.push(e4);
1575
+ }
1576
+ })), u;
1577
+ }, t2.renderActions = function(e3 = "", t3, i2 = "Submit", n2 = "Back", a2 = "Next") {
1578
+ const s2 = document.createElement("div");
1579
+ s2.classList.add("magicfeedback-action-container");
1580
+ const r2 = document.createElement("button");
1581
+ r2.id = "magicfeedback-submit", r2.type = "submit", r2.classList.add("magicfeedback-submit"), r2.textContent = "MAGICSURVEY" === e3 ? a2 || "Next" : i2 || "Submit";
1582
+ const o2 = document.createElement("button");
1583
+ return o2.id = "magicfeedback-back", o2.type = "button", o2.classList.add("magicfeedback-back"), o2.textContent = n2 || "Back", o2.addEventListener("click", t3), o2.addEventListener("click", (() => {
1584
+ r2.removeAttribute("disabled");
1585
+ })), "MAGICSURVEY" === e3 && s2.appendChild(o2), s2.appendChild(r2), s2;
1586
+ }, t2.renderError = function(e3) {
1587
+ const t3 = document.createElement("div");
1588
+ return t3.classList.add("magicfeedback-error"), t3.textContent = e3, t3;
1589
+ }, t2.renderSuccess = function(e3) {
1590
+ const t3 = document.createElement("div");
1591
+ return t3.classList.add("magicfeedback-success"), t3.textContent = e3, t3;
1592
+ }, t2.renderStartMessage = function(e3, t3 = false, i2 = "Go!", n2 = () => {
1593
+ }) {
1594
+ const a2 = document.createElement("div");
1595
+ a2.classList.add("magicfeedback-start-message-container");
1596
+ const s2 = document.createElement("div");
1597
+ if (s2.classList.add("magicfeedback-start-message"), s2.innerHTML = e3, a2.appendChild(s2), t3) {
1598
+ const e4 = document.createElement("button");
1599
+ e4.id = "magicfeedback-start-message-button", e4.classList.add("magicfeedback-start-message-button"), e4.textContent = i2, e4.addEventListener("click", (() => n2())), a2.appendChild(e4);
1600
+ }
1601
+ return a2;
1602
+ };
1603
+ }, 313: function(e2, t2, i) {
1604
+ "use strict";
1605
+ var n = this && this.__awaiter || function(e3, t3, i2, n2) {
1606
+ return new (i2 || (i2 = Promise))((function(a2, s2) {
1607
+ function r2(e4) {
1608
+ try {
1609
+ l2(n2.next(e4));
1610
+ } catch (e5) {
1611
+ s2(e5);
1612
+ }
1613
+ }
1614
+ function o2(e4) {
1615
+ try {
1616
+ l2(n2.throw(e4));
1617
+ } catch (e5) {
1618
+ s2(e5);
1619
+ }
1620
+ }
1621
+ function l2(e4) {
1622
+ var t4;
1623
+ e4.done ? a2(e4.value) : (t4 = e4.value, t4 instanceof i2 ? t4 : new i2((function(e5) {
1624
+ e5(t4);
1625
+ }))).then(r2, o2);
1626
+ }
1627
+ l2((n2 = n2.apply(e3, t3 || [])).next());
1628
+ }));
1629
+ }, a = this && this.__importDefault || function(e3) {
1630
+ return e3 && e3.__esModule ? e3 : { default: e3 };
1631
+ };
1632
+ Object.defineProperty(t2, "__esModule", { value: true }), t2.getFollowUpQuestion = t2.sendFeedback = t2.getQuestions = t2.getSessionForm = t2.getForm = t2.validateEmail = void 0;
1633
+ const s = a(i(945)), r = a(i(330)), o = i(857), l = { Accept: "application/json", "Magicfeedback-Sdk-Version": r.default.version, "x-magicfeedback-parameters": window.location.search || "" };
1634
+ t2.validateEmail = function(e3) {
1635
+ return /\S+@\S+\.\S+/.test(e3);
1636
+ }, t2.getForm = function(e3, t3, i2, a2) {
1637
+ return n(this, void 0, void 0, (function* () {
1638
+ try {
1639
+ const n2 = yield (0, s.default)(e3 + o.endpoints.sdk.app_info(t3, i2), { method: "GET", headers: l });
1640
+ return yield n2.json();
1641
+ } catch (e4) {
1642
+ a2.err(e4);
1643
+ }
1644
+ }));
1645
+ }, t2.getSessionForm = function(e3, t3, i2) {
1646
+ return n(this, void 0, void 0, (function* () {
1647
+ try {
1648
+ const i3 = yield (0, s.default)(e3 + o.endpoints.sdk.session(t3), { method: "GET", headers: l });
1649
+ return yield i3.json();
1650
+ } catch (e4) {
1651
+ i2.err(e4);
1652
+ }
1653
+ }));
1654
+ }, t2.getQuestions = function(e3, t3, i2, a2) {
1655
+ return n(this, void 0, void 0, (function* () {
1656
+ try {
1657
+ const n2 = yield (0, s.default)(e3 + o.endpoints.sdk.app(t3, i2), { method: "GET", headers: l });
1658
+ if (n2.ok) {
1659
+ const e4 = yield n2.json();
1660
+ return a2.log(`Received questions for app ${t3}`, e4), e4;
1661
+ }
1662
+ throw a2.err(`Failed to get questions for app ${t3}:`, n2.status, n2.statusText), new Error("[MagicFeedback] Bad response from server");
1663
+ } catch (e4) {
1664
+ return a2.err(e4), [];
1665
+ }
1666
+ }));
1667
+ }, t2.sendFeedback = function(e3, t3, i2) {
1668
+ return n(this, void 0, void 0, (function* () {
1669
+ try {
1670
+ const n2 = yield (0, s.default)(e3 + o.endpoints.sdk.feedback, { method: "POST", headers: Object.assign({ "Content-Type": "application/json" }, l), body: JSON.stringify(t3) });
1671
+ if (n2.ok) return i2.log(`Form ${t3.integration} submitted successfully!`), (yield n2.json()).sessionId;
1672
+ throw i2.err(`Failed to submit form ${t3.integration}:`, n2.status, n2.statusText), new Error(n2.statusText);
1673
+ } catch (e4) {
1674
+ return i2.err(e4), "";
1675
+ }
1676
+ }));
1677
+ }, t2.getFollowUpQuestion = function(e3, t3, i2) {
1678
+ return n(this, void 0, void 0, (function* () {
1679
+ try {
1680
+ const n2 = yield (0, s.default)(e3 + o.endpoints.sdk.followUpQuestion, { method: "POST", headers: Object.assign({ "Content-Type": "application/json" }, l), body: JSON.stringify(t3) });
1681
+ if (n2.ok) return i2.log(`Received follow up question for form ${t3.integration}`), (yield n2.json()) || "";
1682
+ throw i2.err(`Failed to get follow up question for form ${t3.integration}:`, n2.status, n2.statusText), new Error(n2.statusText);
1683
+ } catch (e4) {
1684
+ return i2.err(e4), "";
1685
+ }
1686
+ }));
1687
+ };
1688
+ }, 256: (e2, t2) => {
1689
+ "use strict";
1690
+ Object.defineProperty(t2, "__esModule", { value: true }), t2.Log = void 0, t2.Log = class {
1691
+ constructor(e3) {
1692
+ this.config = e3;
1693
+ }
1694
+ log(...e3) {
1695
+ this.config.get("debug") && console.log("[MagicFeedback]:", ...e3);
1696
+ }
1697
+ err(...e3) {
1698
+ console.error("[MagicFeedback]:", ...e3);
1699
+ }
1700
+ };
1701
+ }, 330: (e2) => {
1702
+ "use strict";
1703
+ e2.exports = JSON.parse('{"name":"@magicfeedback/native","version":"2.1.2-beta.2","main":"./dist/magicfeedback-sdk.node.js","browser":"./dist/magicfeedback-sdk.browser.js","types":"./dist/types/src/index.d.ts","repository":{"type":"git","url":"git+ssh://git@github.com/MagicFeedback/magicfeedback-sdk.git"},"author":"farias@magicfeedback.io","license":"MIT","private":false,"scripts":{"dev":"vite","build":"webpack","build:watch":"webpack --watch --mode development","publish":"npm publish --access public","publish:beta":"npm publish --access public --tag beta","publish:alpha":"npm publish --access public --tag alpha","test":"jest","test:watch":"jest --watchAll","coverage":"vitest run --coverage"},"files":["dist"],"devDependencies":{"@babel/preset-typescript":"^7.22.5","@types/node":"^17.0.21","@types/webpack":"^5.28.0","@types/webpack-node-externals":"^2.5.3","c8":"^7.11.0","copy-webpack-plugin":"^11.0.0","jest":"^29.5.0","jest-environment-jsdom":"^29.5.0","jest-fetch-mock":"^3.0.3","nock":"^13.2.4","ts-jest":"^29.1.0","ts-loader":"^9.2.7","ts-node":"^10.7.0","typescript":"^4.6.2","vite":"^2.8.0","vite-plugin-dts":"^0.9.9","vitest":"^0.5.9","webpack":"^5.70.0","webpack-cli":"^4.9.2","webpack-node-externals":"^3.0.0"},"dependencies":{"cross-fetch":"^3.1.5","is-bundling-for-browser-or-node":"^1.1.1"},"description":"MagicFeedbackAI JavaScript Library for [MagicFeedback.io](https://magicfeedback.io/)","bugs":{"url":"https://github.com/MagicFeedback/magicfeedback-sdk/issues"},"homepage":"https://github.com/MagicFeedback/magicfeedback-sdk#readme","directories":{"example":"examples","test":"test"},"style":"./dist/styles/magicfeedback-default.css"}');
1704
+ } }, t = {}, (function i(n) {
1705
+ var a = t[n];
1706
+ if (void 0 !== a) return a.exports;
1707
+ var s = t[n] = { exports: {} };
1708
+ return e[n].call(s.exports, s, s.exports, i), s.exports;
1709
+ })(156).default;
1710
+ var e, t;
1711
+ }));
1712
+ }
1713
+ });
1714
+
1715
+ // src/ui/renderPopup.ts
1716
+ var import_native = __toESM(require_magicfeedback_sdk_browser());
1717
+ async function renderPopup(container, surveyId, productId, data, emit, onClose) {
1718
+ console.log("[MagicFeedback] Rendering popup for survey:", surveyId);
1719
+ const popup = document.createElement("div");
1720
+ popup.className = "deepdots-popup";
1721
+ popup.style.cssText = `
1722
+ background: white;
1723
+ border-radius: 8px;
1724
+ padding: 24px;
1725
+ max-width: 600px;
1726
+ width: 90%;
1727
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
1728
+ position: relative;
1729
+ `;
1730
+ const closeButton = document.createElement("button");
1731
+ closeButton.innerHTML = "&times;";
1732
+ closeButton.style.cssText = `
1733
+ position: absolute;
1734
+ top: 8px;
1735
+ right: 12px;
1736
+ border: none;
1737
+ background: none;
1738
+ font-size: 24px;
1739
+ cursor: pointer;
1740
+ color: #666;
1741
+ `;
1742
+ closeButton.onclick = () => onClose();
1743
+ const content = document.createElement("div");
1744
+ const formDivId = `magicfeedback-form-${surveyId}`;
1745
+ content.innerHTML = `
1746
+ <div id="${formDivId}" style="margin-top: 12px; width: 100%"></div>
1747
+ `;
1748
+ let surveyCompletedEmitted = false;
1749
+ const submitButton = document.createElement("button");
1750
+ submitButton.textContent = "Complete Survey";
1751
+ submitButton.style.cssText = `
1752
+ background: #4CAF50;
1753
+ color: white;
1754
+ border: none;
1755
+ padding: 12px 24px;
1756
+ border-radius: 4px;
1757
+ cursor: pointer;
1758
+ font-size: 14px;
1759
+ margin-top: 16px;
1760
+ `;
1761
+ submitButton.onclick = () => {
1762
+ if (!surveyCompletedEmitted) {
1763
+ emit("popup_clicked", surveyId, data);
1764
+ emit("survey_completed", surveyId, data);
1765
+ surveyCompletedEmitted = true;
1766
+ }
1767
+ onClose();
1768
+ };
1769
+ popup.appendChild(closeButton);
1770
+ popup.appendChild(content);
1771
+ popup.appendChild(submitButton);
1772
+ container.innerHTML = "";
1773
+ container.appendChild(popup);
1774
+ container.style.display = "flex";
1775
+ if (typeof window === "undefined" || typeof document === "undefined") {
1776
+ return;
1777
+ }
1778
+ try {
1779
+ if (!import_native.default || typeof import_native.default.form !== "function") {
1780
+ console.warn("[MagicFeedback] form() no disponible. Se usa fallback manual.");
1781
+ return;
1782
+ }
1783
+ import_native.default.init({ debug: true, env: "prod" });
1784
+ const formInstance = import_native.default.form(surveyId, productId);
1785
+ formInstance.generate(formDivId, {
1786
+ addButton: true,
1787
+ // permitir que el propio formulario gestione avance
1788
+ getMetaData: true,
1789
+ onLoadedEvent: () => {
1790
+ emit("popup_clicked", surveyId, data);
1791
+ },
1792
+ onFinishEvent: () => {
1793
+ if (!surveyCompletedEmitted) {
1794
+ emit("survey_completed", surveyId, data);
1795
+ surveyCompletedEmitted = true;
1796
+ }
1797
+ onClose();
1798
+ },
1799
+ afterSubmitEvent: ({ progress: _progress, total: _total }) => {
1800
+ }
1801
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1802
+ }).catch((err) => {
1803
+ console.error("[MagicFeedback] Error generating form:", err);
1804
+ });
1805
+ } catch (e) {
1806
+ console.error("[MagicFeedback] Exception initializing form:", e);
1807
+ }
1808
+ }
1809
+
1810
+ // src/triggers/index.ts
1811
+ function setupTrigger(popups, trigger) {
1812
+ switch (trigger.type) {
1813
+ case "time":
1814
+ setupTimeTrigger(popups, trigger);
1815
+ break;
1816
+ case "scroll":
1817
+ setupScrollTrigger(popups, trigger);
1818
+ break;
1819
+ case "exit":
1820
+ setupExitTrigger(popups, trigger);
1821
+ break;
1822
+ }
1823
+ }
1824
+ function setupTimeTrigger(popups, trigger) {
1825
+ const delay = trigger.value || 5e3;
1826
+ setTimeout(() => {
1827
+ popups.triggerSurvey(trigger.surveyId);
1828
+ }, delay);
1829
+ popups.debug(`Time trigger set for ${delay}ms`);
1830
+ }
1831
+ function setupScrollTrigger(popups, trigger) {
1832
+ const threshold = trigger.value || 50;
1833
+ const handler = () => {
1834
+ const scrollPercentage = window.scrollY / (document.documentElement.scrollHeight - window.innerHeight) * 100;
1835
+ if (scrollPercentage >= threshold) {
1836
+ popups.triggerSurvey(trigger.surveyId);
1837
+ window.removeEventListener("scroll", handler);
1838
+ }
1839
+ };
1840
+ window.addEventListener("scroll", handler);
1841
+ popups.debug(`Scroll trigger set for ${threshold}%`);
1842
+ }
1843
+ function setupExitTrigger(popups, trigger) {
1844
+ const handler = (e) => {
1845
+ if (e.clientY <= 0) {
1846
+ popups.triggerSurvey(trigger.surveyId);
1847
+ document.removeEventListener("mouseout", handler);
1848
+ }
1849
+ };
1850
+ document.addEventListener("mouseout", handler);
1851
+ popups.debug("Exit intent trigger set");
1852
+ }
1853
+
1854
+ // src/config/env.ts
1855
+ var ENVIRONMENT_MAP = {
1856
+ development: {
1857
+ apiBaseUrl: "https://api-dev.magicfeedback.com"
1858
+ },
1859
+ production: {
1860
+ apiBaseUrl: "https://api.magicfeedback.com"
1861
+ }
1862
+ };
1863
+ function resolveEnvironment(nodeEnv) {
1864
+ return ENVIRONMENT_MAP[nodeEnv || "production"];
1865
+ }
1866
+
1867
+ // src/platform/react-native-renderer.ts
1868
+ var ReactNativePopupRenderer = class {
1869
+ constructor() {
1870
+ this.mounted = false;
1871
+ this.lastSurveyId = null;
1872
+ this.emitFn = null;
1873
+ this.onCloseFn = null;
1874
+ this.completed = false;
1875
+ }
1876
+ init() {
1877
+ }
1878
+ show(surveyId, productId, data, emit, onClose) {
1879
+ this.mounted = true;
1880
+ this.lastSurveyId = surveyId;
1881
+ this.emitFn = emit;
1882
+ this.onCloseFn = onClose;
1883
+ this.completed = false;
1884
+ queueMicrotask(() => emit("popup_clicked", surveyId, data));
1885
+ console.log("[ReactNativePopupRenderer] (stub) show survey:", { surveyId, productId, data });
1886
+ }
1887
+ /** Completar la encuesta desde la capa nativa */
1888
+ completeSurvey(data) {
1889
+ if (!this.mounted || this.completed || !this.lastSurveyId || !this.emitFn) return;
1890
+ this.completed = true;
1891
+ this.emitFn("survey_completed", this.lastSurveyId, data);
1892
+ this.onCloseFn?.();
1893
+ this.mounted = false;
1894
+ console.log("[ReactNativePopupRenderer] (stub) survey completed:", { surveyId: this.lastSurveyId, data });
1895
+ this.lastSurveyId = null;
1896
+ }
1897
+ hide() {
1898
+ if (!this.mounted) return;
1899
+ this.mounted = false;
1900
+ console.log("[ReactNativePopupRenderer] (stub) hide survey:", this.lastSurveyId);
1901
+ this.lastSurveyId = null;
1902
+ }
1903
+ };
1904
+ function isReactNativeEnv() {
1905
+ return typeof navigator !== "undefined" && navigator.product === "ReactNative";
1906
+ }
1907
+ function createReactNativeRenderer() {
1908
+ return new ReactNativePopupRenderer();
1909
+ }
1910
+
1911
+ // src/platform/renderer.ts
1912
+ var NoopPopupRenderer = class {
1913
+ show() {
1914
+ }
1915
+ hide() {
1916
+ }
1917
+ };
1918
+ var BrowserPopupRenderer = class {
1919
+ constructor() {
1920
+ this.container = null;
1921
+ }
1922
+ init() {
1923
+ if (typeof document === "undefined") return;
1924
+ if (!this.container) {
1925
+ this.container = document.createElement("div");
1926
+ this.container.id = "deepdots-popup-container";
1927
+ this.container.style.cssText = `
1928
+ position: fixed;
1929
+ top: 0;
1930
+ left: 0;
1931
+ width: 100%;
1932
+ height: 100%;
1933
+ display: none;
1934
+ z-index: 999999;
1935
+ background: rgba(0, 0, 0, 0.5);
1936
+ justify-content: center;
1937
+ align-items: center;
1938
+ `;
1939
+ document.body.appendChild(this.container);
1940
+ }
1941
+ }
1942
+ show(surveyId, productId, data, emit, onClose) {
1943
+ if (!this.container) this.init();
1944
+ if (!this.container) return;
1945
+ renderPopup(this.container, surveyId, productId, data, emit, onClose);
1946
+ }
1947
+ hide() {
1948
+ if (this.container) {
1949
+ this.container.style.display = "none";
1950
+ this.container.innerHTML = "";
1951
+ }
1952
+ }
1953
+ };
1954
+ function createDefaultRenderer() {
1955
+ if (typeof document === "undefined") {
1956
+ if (isReactNativeEnv()) return createReactNativeRenderer();
1957
+ return new NoopPopupRenderer();
1958
+ }
1959
+ if (isReactNativeEnv()) return createReactNativeRenderer();
1960
+ return new BrowserPopupRenderer();
1961
+ }
1962
+
1963
+ // src/core/deepdots-popups.ts
1964
+ var DeepdotsPopups = class {
1965
+ constructor() {
1966
+ this.config = null;
1967
+ this.listeners = /* @__PURE__ */ new Map();
1968
+ this.triggers = [];
1969
+ this.initialized = false;
1970
+ this.renderer = createDefaultRenderer();
1971
+ this.popupContainer = null;
1972
+ // deprecated: mantenido para compatibilidad interna
1973
+ this.popupDefinitions = [];
1974
+ this.popupsLoaded = false;
1975
+ this.pendingAutoLaunch = false;
1976
+ this.answeredSurveys = /* @__PURE__ */ new Set();
1977
+ this.lastShown = /* @__PURE__ */ new Map();
1978
+ }
1979
+ // popupId -> timestamp mostrado
1980
+ /** Initialize the SDK with configuration */
1981
+ init(config) {
1982
+ if (this.initialized) {
1983
+ this.log("SDK already initialized");
1984
+ return;
1985
+ }
1986
+ const env = resolveEnvironment(config.nodeEnv);
1987
+ this.config = {
1988
+ apiKey: config.apiKey || void 0,
1989
+ baseUrl: env.apiBaseUrl,
1990
+ mode: config.mode || "client",
1991
+ debug: config.debug || false,
1992
+ popups: config.popups || []
1993
+ };
1994
+ this.initialized = true;
1995
+ this.log("SDK initialized", this.config);
1996
+ if (this.renderer.init) this.renderer.init();
1997
+ this.setupPopupContainer();
1998
+ if (this.config.mode === "client") {
1999
+ this.popupDefinitions = this.config.popups || [];
2000
+ this.popupsLoaded = true;
2001
+ this.configureTriggersFromDefinitions();
2002
+ } else {
2003
+ this.fetchPopupsFromServer().then((defs) => {
2004
+ this.popupDefinitions = defs;
2005
+ this.popupsLoaded = true;
2006
+ this.log("Popups loaded from server (fake)", defs);
2007
+ this.configureTriggersFromDefinitions();
2008
+ if (this.pendingAutoLaunch) {
2009
+ this.startTriggers();
2010
+ }
2011
+ });
2012
+ }
2013
+ }
2014
+ /** Enable auto-launch functionality with configured triggers */
2015
+ autoLaunch() {
2016
+ if (!this.initialized) {
2017
+ throw new Error("SDK not initialized. Call init() first.");
2018
+ }
2019
+ if (!this.popupsLoaded) {
2020
+ this.pendingAutoLaunch = true;
2021
+ this.log("Auto-launch deferred until popups are loaded");
2022
+ return;
2023
+ }
2024
+ this.startTriggers();
2025
+ }
2026
+ /** Inicia los triggers configurados */
2027
+ startTriggers() {
2028
+ this.log("Auto-launch enabled");
2029
+ this.triggers.forEach((trigger) => setupTrigger(this, trigger));
2030
+ }
2031
+ /** Show a popup immediately (by surveyId) */
2032
+ show(options) {
2033
+ console.log("Show popup called with options:", options);
2034
+ if (!this.initialized) {
2035
+ throw new Error("SDK not initialized. Call init() first.");
2036
+ }
2037
+ this.log("Showing popup", options);
2038
+ this.renderPopup(options.surveyId, options.productId, options.data);
2039
+ this.emitEvent("popup_shown", options.surveyId, options.data);
2040
+ }
2041
+ /** Mostrar popup por id de definición (usa surveyId interno) */
2042
+ showByPopupId(popupId) {
2043
+ const def = this.popupDefinitions.find((p) => p.id === popupId);
2044
+ if (!def) {
2045
+ this.log("Popup definition not found", popupId);
2046
+ return;
2047
+ }
2048
+ this.show({ surveyId: def.surveyId, productId: def.productId });
2049
+ }
2050
+ /** Configure triggers for auto-launching popups (manual) */
2051
+ configureTriggers(triggers) {
2052
+ if (!this.initialized) {
2053
+ throw new Error("SDK not initialized. Call init() first.");
2054
+ }
2055
+ this.triggers = triggers;
2056
+ this.log("Triggers configured", triggers);
2057
+ }
2058
+ /** Deriva triggers desde las definiciones de popup */
2059
+ configureTriggersFromDefinitions() {
2060
+ const derived = [];
2061
+ const validDefs = this.validatePopupDefinitions(this.popupDefinitions);
2062
+ validDefs.forEach((def) => {
2063
+ if (!def.trigger) return;
2064
+ const t = def.trigger;
2065
+ let type;
2066
+ switch (t.type) {
2067
+ case "time_on_page":
2068
+ type = "time";
2069
+ break;
2070
+ case "scroll":
2071
+ type = "scroll";
2072
+ break;
2073
+ case "exit":
2074
+ type = "exit";
2075
+ break;
2076
+ default:
2077
+ this.debug("Unsupported trigger type", t.type);
2078
+ return;
2079
+ }
2080
+ const value = type === "time" ? t.value * 1e3 : t.value;
2081
+ derived.push({ type, value, surveyId: def.surveyId });
2082
+ });
2083
+ if (derived.length) {
2084
+ this.configureTriggers(derived);
2085
+ }
2086
+ }
2087
+ /** Lógica para evaluar condiciones antes de mostrar una encuesta */
2088
+ triggerSurvey(surveyId) {
2089
+ const def = this.popupDefinitions.find((p) => p.surveyId === surveyId);
2090
+ if (!def) {
2091
+ this.debug("No popup definition for surveyId", surveyId);
2092
+ return;
2093
+ }
2094
+ if (!this.shouldShow(def)) {
2095
+ this.debug("Conditions prevented showing popup", def.id);
2096
+ return;
2097
+ }
2098
+ this.show({ surveyId: def.surveyId, productId: def.productId });
2099
+ this.lastShown.set(def.id, Date.now());
2100
+ }
2101
+ shouldShow(def) {
2102
+ const conditions = def.trigger.condition || [];
2103
+ if (!conditions.length) return true;
2104
+ return conditions.every((c) => this.evaluateCondition(def, c));
2105
+ }
2106
+ evaluateCondition(def, condition) {
2107
+ if (condition.answered === false && this.answeredSurveys.has(def.surveyId)) {
2108
+ return false;
2109
+ }
2110
+ if (condition.cooldownDays) {
2111
+ const last = this.lastShown.get(def.id);
2112
+ if (last) {
2113
+ const msSince = Date.now() - last;
2114
+ const required = condition.cooldownDays * 24 * 60 * 60 * 1e3;
2115
+ if (msSince < required) return false;
2116
+ }
2117
+ }
2118
+ return true;
2119
+ }
2120
+ /** Marcar encuesta como contestada externamente */
2121
+ markSurveyAnswered(surveyId) {
2122
+ this.answeredSurveys.add(surveyId);
2123
+ }
2124
+ /** Simula fetch al servidor para obtener popups */
2125
+ async fetchPopupsFromServer() {
2126
+ await new Promise((res) => setTimeout(res, 50));
2127
+ return this.generateFakePopups();
2128
+ }
2129
+ /** Genera datos fake para pruebas en modo server */
2130
+ generateFakePopups() {
2131
+ return [
2132
+ {
2133
+ id: "popup-123",
2134
+ title: "Would you like to help us improve?",
2135
+ message: "<p>Take a quick survey and share your thoughts.</p>",
2136
+ trigger: { type: "time_on_page", value: 1, condition: [{ answered: false, cooldownDays: 7 }] },
2137
+ actions: {
2138
+ accept: { label: "Take Survey", surveyId: "survey-abc" },
2139
+ decline: { label: "Not Now", cooldownDays: 7 }
2140
+ },
2141
+ surveyId: "survey-abc",
2142
+ productId: "product-xyz",
2143
+ style: { theme: "light", position: "bottom-right", imageUrl: null },
2144
+ segments: { lang: ["en"], path: ["/checkout"] }
2145
+ }
2146
+ ];
2147
+ }
2148
+ /** Add an event listener */
2149
+ on(eventType, listener) {
2150
+ if (!this.listeners.has(eventType)) {
2151
+ this.listeners.set(eventType, /* @__PURE__ */ new Set());
2152
+ }
2153
+ this.listeners.get(eventType).add(listener);
2154
+ }
2155
+ /** Remove an event listener */
2156
+ off(eventType, listener) {
2157
+ const listeners = this.listeners.get(eventType);
2158
+ if (listeners) {
2159
+ listeners.delete(listener);
2160
+ }
2161
+ }
2162
+ /** Setup popup container element */
2163
+ setupPopupContainer() {
2164
+ if (typeof document === "undefined") {
2165
+ return;
2166
+ }
2167
+ this.popupContainer = document.createElement("div");
2168
+ this.popupContainer.id = "deepdots-popup-container";
2169
+ this.popupContainer.style.cssText = `
2170
+ position: fixed;
2171
+ top: 0;
2172
+ left: 0;
2173
+ width: 100%;
2174
+ height: 100%;
2175
+ display: none;
2176
+ z-index: 999999;
2177
+ background: rgba(0, 0, 0, 0.5);
2178
+ justify-content: center;
2179
+ align-items: center;
2180
+ `;
2181
+ document.body.appendChild(this.popupContainer);
2182
+ }
2183
+ /** Render the popup UI */
2184
+ renderPopup(surveyId, productId, data) {
2185
+ if (this.renderer) {
2186
+ this.renderer.show(surveyId, productId, data, (type, id, payload) => this.emitEvent(type, id, payload), () => this.hidePopup());
2187
+ return;
2188
+ }
2189
+ if (!this.popupContainer) return;
2190
+ renderPopup(this.popupContainer, surveyId, productId, data, (type, id, payload) => this.emitEvent(type, id, payload), () => this.hidePopup());
2191
+ }
2192
+ /** Hide the popup */
2193
+ hidePopup() {
2194
+ if (this.renderer) {
2195
+ this.renderer.hide();
2196
+ return;
2197
+ }
2198
+ if (this.popupContainer) {
2199
+ this.popupContainer.style.display = "none";
2200
+ this.popupContainer.innerHTML = "";
2201
+ }
2202
+ }
2203
+ /** Emit an event */
2204
+ emitEvent(type, surveyId, data) {
2205
+ const event = { type, surveyId, timestamp: Date.now(), data };
2206
+ this.log("Event emitted", event);
2207
+ if (type === "survey_completed") {
2208
+ this.markSurveyAnswered(surveyId);
2209
+ }
2210
+ const listeners = this.listeners.get(type);
2211
+ if (listeners) {
2212
+ listeners.forEach((listener) => {
2213
+ try {
2214
+ listener(event);
2215
+ } catch (error) {
2216
+ console.error("Error in event listener:", error);
2217
+ }
2218
+ });
2219
+ }
2220
+ }
2221
+ /** Log debug messages */
2222
+ log(...args) {
2223
+ if (this.config?.debug) {
2224
+ console.log("[DeepdotsPopups]", ...args);
2225
+ }
2226
+ }
2227
+ /** External debug method for triggers */
2228
+ debug(...args) {
2229
+ this.log(...args);
2230
+ }
2231
+ /** Set a custom renderer */
2232
+ setRenderer(renderer) {
2233
+ this.renderer = renderer;
2234
+ if (this.initialized && this.renderer.init) {
2235
+ this.renderer.init();
2236
+ }
2237
+ }
2238
+ // Type guards
2239
+ isPopupDefinition(value) {
2240
+ if (typeof value !== "object" || value === null) return false;
2241
+ const v = value;
2242
+ return typeof v.id === "string" && typeof v.title === "string" && typeof v.message === "string" && typeof v.surveyId === "string" && typeof v.productId === "string" && !!v.trigger && typeof v.trigger.type === "string";
2243
+ }
2244
+ validatePopupDefinitions(defs) {
2245
+ return defs.filter((d) => this.isPopupDefinition(d));
2246
+ }
2247
+ };
2248
+ export {
2249
+ DeepdotsPopups
2250
+ };
2251
+ //# sourceMappingURL=index.mjs.map