@magicfeedback/native 1.3.2-beta.2 → 1.3.2-beta.4
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"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()}(self,(()=>{return e={98:function(e,t){var i="undefined"!=typeof self?self:this,n=function(){function e(){this.fetch=!1,this.DOMException=i.DOMException}return e.prototype=i,new e}();!function(e){!function(t){var i="URLSearchParams"in e,n="Symbol"in e&&"iterator"in Symbol,s="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),a="FormData"in e,o="ArrayBuffer"in e;if(o)var r=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],d=ArrayBuffer.isView||function(e){return e&&r.indexOf(Object.prototype.toString.call(e))>-1};function c(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function l(e){return"string"!=typeof e&&(e=String(e)),e}function u(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return n&&(t[Symbol.iterator]=function(){return t}),t}function p(e){this.map={},e instanceof p?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function h(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function m(e){return new Promise((function(t,i){e.onload=function(){t(e.result)},e.onerror=function(){i(e.error)}}))}function f(e){var t=new FileReader,i=m(t);return t.readAsArrayBuffer(e),i}function g(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function y(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:s&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:a&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:i&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():o&&s&&(t=e)&&DataView.prototype.isPrototypeOf(t)?(this._bodyArrayBuffer=g(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):o&&(ArrayBuffer.prototype.isPrototypeOf(e)||d(e))?this._bodyArrayBuffer=g(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):i&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},s&&(this.blob=function(){var e=h(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?h(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(f)}),this.text=function(){var e,t,i,n=h(this);if(n)return n;if(this._bodyBlob)return e=this._bodyBlob,i=m(t=new FileReader),t.readAsText(e),i;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),i=new Array(t.length),n=0;n<t.length;n++)i[n]=String.fromCharCode(t[n]);return i.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},a&&(this.formData=function(){return this.text().then(E)}),this.json=function(){return this.text().then(JSON.parse)},this}p.prototype.append=function(e,t){e=c(e),t=l(t);var i=this.map[e];this.map[e]=i?i+", "+t:t},p.prototype.delete=function(e){delete this.map[c(e)]},p.prototype.get=function(e){return e=c(e),this.has(e)?this.map[e]:null},p.prototype.has=function(e){return this.map.hasOwnProperty(c(e))},p.prototype.set=function(e,t){this.map[c(e)]=l(t)},p.prototype.forEach=function(e,t){for(var i in this.map)this.map.hasOwnProperty(i)&&e.call(t,this.map[i],i,this)},p.prototype.keys=function(){var e=[];return this.forEach((function(t,i){e.push(i)})),u(e)},p.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),u(e)},p.prototype.entries=function(){var e=[];return this.forEach((function(t,i){e.push([i,t])})),u(e)},n&&(p.prototype[Symbol.iterator]=p.prototype.entries);var v=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function b(e,t){var i,n,s=(t=t||{}).body;if(e instanceof b){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new p(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,s||null==e._bodyInit||(s=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new p(t.headers)),this.method=(n=(i=t.method||this.method||"GET").toUpperCase(),v.indexOf(n)>-1?n:i),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&s)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(s)}function E(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var i=e.split("="),n=i.shift().replace(/\+/g," "),s=i.join("=").replace(/\+/g," ");t.append(decodeURIComponent(n),decodeURIComponent(s))}})),t}function k(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new p(t.headers),this.url=t.url||"",this._initBody(e)}b.prototype.clone=function(){return new b(this,{body:this._bodyInit})},y.call(b.prototype),y.call(k.prototype),k.prototype.clone=function(){return new k(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new p(this.headers),url:this.url})},k.error=function(){var e=new k(null,{status:0,statusText:""});return e.type="error",e};var C=[301,302,303,307,308];k.redirect=function(e,t){if(-1===C.indexOf(t))throw new RangeError("Invalid status code");return new k(null,{status:t,headers:{location:e}})},t.DOMException=e.DOMException;try{new t.DOMException}catch(e){t.DOMException=function(e,t){this.message=e,this.name=t;var i=Error(e);this.stack=i.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function w(e,i){return new Promise((function(n,a){var o=new b(e,i);if(o.signal&&o.signal.aborted)return a(new t.DOMException("Aborted","AbortError"));var r=new XMLHttpRequest;function d(){r.abort()}r.onload=function(){var e,t,i={status:r.status,statusText:r.statusText,headers:(e=r.getAllResponseHeaders()||"",t=new p,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(e){var i=e.split(":"),n=i.shift().trim();if(n){var s=i.join(":").trim();t.append(n,s)}})),t)};i.url="responseURL"in r?r.responseURL:i.headers.get("X-Request-URL");var s="response"in r?r.response:r.responseText;n(new k(s,i))},r.onerror=function(){a(new TypeError("Network request failed"))},r.ontimeout=function(){a(new TypeError("Network request failed"))},r.onabort=function(){a(new t.DOMException("Aborted","AbortError"))},r.open(o.method,o.url,!0),"include"===o.credentials?r.withCredentials=!0:"omit"===o.credentials&&(r.withCredentials=!1),"responseType"in r&&s&&(r.responseType="blob"),o.headers.forEach((function(e,t){r.setRequestHeader(t,e)})),o.signal&&(o.signal.addEventListener("abort",d),r.onreadystatechange=function(){4===r.readyState&&o.signal.removeEventListener("abort",d)}),r.send(void 0===o._bodyInit?null:o._bodyInit)}))}w.polyfill=!0,e.fetch||(e.fetch=w,e.Headers=p,e.Request=b,e.Response=k),t.Headers=p,t.Request=b,t.Response=k,t.fetch=w,Object.defineProperty(t,"__esModule",{value:!0})}({})}(n),n.fetch.ponyfill=!0,delete n.fetch.polyfill;var s=n;(t=s.fetch).default=s.fetch,t.fetch=s.fetch,t.Headers=s.Headers,t.Request=s.Request,t.Response=s.Response,e.exports=t},290:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.HOST_API_URL_DEV=t.HOST_API_URL=void 0,t.HOST_API_URL="https://api.magicfeedback.io/",t.HOST_API_URL_DEV="https://api-dev.magicfeedback.io/"},607:function(e,t,i){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=n(i(519));let a=null;a||(a=(0,s.default)()),t.default=a},519:function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,a){function o(e){try{d(n.next(e))}catch(e){a(e)}}function r(e){try{d(n.throw(e))}catch(e){a(e)}}function d(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}d((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(954),a=i(712),o=i(5),r=i(341),d=i(290);t.default=function(){const e=new a.Config;let t;return{init:function(i){(null==i?void 0:i.debug)&&e.set("debug",null==i?void 0:i.debug),e.set("url",(null==i?void 0:i.env)&&"dev"===(null==i?void 0:i.env)?d.HOST_API_URL_DEV:d.HOST_API_URL),t=new o.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,s,a,o=!0,d,c){return n(this,void 0,void 0,(function*(){i||t.err("No appID provided"),s||t.err("No publicKey provided"),a||t.err("No feedback provided"),a.answers||a.profile||a.metrics||a.metadata||t.err("No feedback data provided");const n=e.get("url"),l={integration:i,publicKey:s,privateKey:c,completed:o,id:d,feedback:a};try{const e=yield(0,r.sendFeedback)(n,l,t);return t.log("sent native feedback"),e}catch(e){return t.err("error native feedback",e),!1}}))},form:function(i,n){return i||t.err("No appID provided"),n||t.err("No publicKey provided"),new s.Form(e,i,n)},session:function(i){return i||t.err("No sessionId provided"),new s.Form(e,i)}}}},314:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.History=void 0,t.History=class{constructor(){this.items=[]}enqueue(e){this.items.push(e)}dequeue(){return this.items.shift()}rollback(){return this.items.pop()}front(){return this.items[0]}back(){return this.items[this.items.length-1]}isEmpty(){return 0===this.items.length}size(){return this.items.length}}},712:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Config=void 0,t.Config=class{constructor(){this.variables={},this.variables.env="prod",this.variables.debug=!1}get(e){return this.variables[e]}set(e,t){this.variables[e]=t}}},954:function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,a){function o(e){try{d(n.next(e))}catch(e){a(e)}}function r(e){try{d(n.throw(e))}catch(e){a(e)}}function d(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}d((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const s=i(5),a=i(341),o=i(183),r=i(24),d=i(804),c=i(116),l=i(314),u=i(457);t.Form=class{constructor(e,t,i){this.config=e,this.log=new s.Log(e),this.formOptionsConfig={addButton:!0,sendButtonText:"Send",backButtonText:"Back",nextButtonText:"Next",addSuccessScreen:!0,getMetaData:!0,questionFormat:"standard"},this.selector="",this.appId=t,this.publicKey=i||"",this.url=e.get("url"),this.id="",this.formData=null,""!==this.publicKey&&this.getDataFromStorage(),this.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.history=new l.History,this.graph=new r.PageGraph([]),this.progress=0,this.total=0,this.completed=!1}getDataFromStorage(){const e=localStorage.getItem(`magicfeedback-${this.appId}`);e&&new Date(JSON.parse(e).savedAt)<new Date((new Date).getTime()+864e5)&&(this.formData=JSON.parse(e),(0,a.getForm)(this.url,this.appId,this.publicKey,this.log).then((e=>{var t,i,n,s,a;if((null==e?void 0:e.updatedAt)&&(null===(t=this.formData)||void 0===t?void 0:t.savedAt)&&(null==e?void 0:e.updatedAt)>(null===(i=this.formData)||void 0===i?void 0:i.savedAt)){if(this.formData=e,this.formData.savedAt=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}`);this.formData.pages&&0!==(null===(n=this.formData.pages)||void 0===n?void 0:n.length)||this.formatPages(),null===(s=this.formData.questions)||void 0===s||s.sort(((e,t)=>e.position-t.position)),this.formData.pages=this.formData.pages.filter((e=>{var t;return(null===(t=e.integrationQuestions)||void 0===t?void 0:t.length)>0})),(null===(a=this.formData.style)||void 0===a?void 0:a.startMessage)?this.generateWelcomeMessage(this.formData.style.startMessage):this.startForm()}})))}generate(e,t){var i,s,o;return n(this,void 0,void 0,(function*(){try{if(this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e,void 0!==this.formData&&this.formData||(this.formData=""!==this.publicKey?yield(0,a.getForm)(this.url,this.appId,this.publicKey,this.log):yield(0,a.getSessionForm)(this.url,this.appId,this.log)),void 0===this.formData||!this.formData)throw new Error(`No form for app ${this.appId}`);if(this.formData.savedAt||(this.formData.savedAt=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}`);this.formData.pages&&0!==(null===(i=this.formData.pages)||void 0===i?void 0:i.length)||this.formatPages(),null===(s=this.formData.questions)||void 0===s||s.sort(((e,t)=>e.position-t.position)),this.formData.pages=this.formData.pages.filter((e=>{var t;return(null===(t=e.integrationQuestions)||void 0===t?void 0:t.length)>0})),this.formOptionsConfig.getMetaData&&this.getMetaData(),(null===(o=this.formData.style)||void 0===o?void 0:o.startMessage)?yield this.generateWelcomeMessage(this.formData.style.startMessage):this.startForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}formatPages(){var e;if(this.formData)switch(this.formData.identity){case"MAGICSURVEY":this.formData.pages=[],null===(e=this.formData.questions)||void 0===e||e.forEach((e=>{var t,i;const n=new c.PageRoute(e.id,e.ref,c.OperatorType.NOEQUAL,null,c.TransitionType.PAGE,(e.position+1).toString(),e.position.toString()),s=new d.Page(e.position.toString(),e.position,this.appId,[e],[n]);null===(i=null===(t=this.formData)||void 0===t?void 0:t.pages)||void 0===i||i.push(s)}));break;case"MAGICFORM":const t=new d.Page("1",1,this.appId,this.formData.questions,[]);this.formData.pages=[t]}}generateContainer(){let e=document.getElementById(this.selector);if(!e&&(e=document.getElementById("magicfeedback-container-"+this.appId),!e))throw new Error(`Element with ID '${this.selector}' not found.`);return e.classList.add("magicfeedback-container"),e.id="magicfeedback-container-"+this.appId,e.innerHTML="",e}generateForm(){var e,t,i,s;return n(this,void 0,void 0,(function*(){try{if(!this.formData||!this.formData.pages||0===this.formData.pages.length)throw new Error("No form data");this.graph=new r.PageGraph(this.formData.pages.sort(((e,t)=>e.position-t.position)));let n=this.generateContainer();const a=document.createElement("form");a.classList.add("magicfeedback-form"),a.id="magicfeedback-"+this.appId;const d=document.createElement("div");d.classList.add("magicfeedback-questions"),d.id="magicfeedback-questions-"+this.appId;const c=this.graph.getFirstPage();if(!c)throw new Error("No page found");if(this.total=this.graph.findMaxDepth(),c.elements=(0,o.renderQuestions)(c.questions,this.formOptionsConfig.questionFormat,null===(e=this.formData)||void 0===e?void 0:e.lang[0],null===(t=this.formData)||void 0===t?void 0:t.product,(()=>this.send())),null===(i=c.elements)||void 0===i||i.forEach((e=>d.appendChild(e))),a.appendChild(d),this.history.enqueue(c),n.appendChild(a),this.progress=this.history.size(),this.formOptionsConfig.addButton){const e=(0,o.renderActions)(null===(s=this.formData)||void 0===s?void 0:s.identity,(()=>this.back()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);a.appendChild(e)}this.formOptionsConfig.addButton&&a.addEventListener("submit",(e=>{e.preventDefault(),this.send()})),this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}))}startForm(){this.generateForm()}generateWelcomeMessage(e){return n(this,void 0,void 0,(function*(){try{const t=this.generateContainer(),i=(0,o.renderStartMessage)(e,this.formOptionsConfig.addButton,this.formOptionsConfig.startButtonText,(()=>this.startForm()));t.appendChild(i),this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,formData:this.formData}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}))}getMetaData(){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]})}send(e,t,i){return n(this,void 0,void 0,(function*(){const n=document.getElementById("magicfeedback-questions-"+this.appId);try{i&&(this.feedback.profile=[...this.feedback.profile,...i]),t&&(this.feedback.metrics=[...this.feedback.metrics,...t]),e&&(this.feedback.metadata=[...this.feedback.metadata,...e]),this.answer(),this.formOptionsConfig.beforeSubmitEvent&&(yield this.formOptionsConfig.beforeSubmitEvent({loading:!0,progress:this.progress,total:this.total}));const s=this.history.back();if(!s)throw new Error("No page found");const a=s.getRequiredQuestions();for(const e of a)if(!this.feedback.answers.find((t=>t.key===e&&t.value.length>0)))throw this.log.err(`The question ${e} is required`),new Error("No response");const o=yield this.pushAnswers(!1);if(!o)throw new Error("No response");this.id=o,yield this.processNextQuestion(n)}catch(e){this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({loading:!1,progress:this.progress,total:this.total,error:e}))}}))}answer(){const e=document.getElementById("magicfeedback-"+this.appId);if(!e)return this.log.err(`Form "${e}" not found.`),void(this.feedback.answers=[]);if(!this.history.back())throw new Error("No page found");const t=[];let i=!1;e.querySelectorAll(".magicfeedback-input").forEach((e=>{const n=e.type,s=e.classList[0],o={key:e.name,value:[]},r="magicfeedback-consent"===s?e.checked.toString():e.value;if(o.key&&""!==o.key)switch(n){case"radio":case"checkbox":if("magicfeedback-consent"===s||e.checked){o.value.push(r);const e=t.findIndex((e=>e.key===o.key));-1!==e?t[e].value=[...t[e].value,...o.value]:t.push(o)}break;default:if(""!==r){if("email"===n){if(!(0,a.validateEmail)(r)){this.log.err("Invalid email"),i=!0;break}this.feedback.profile.push({key:"email",value:[r]})}if(e.id.includes("point-system")){const t="point-system-"+e.id.split("-")[e.id.split("-").length-1];o.value.push(`${t}: ${r}%`)}else o.value.push(r);const s=t.findIndex((e=>e.key===o.key));-1!==s?t[s].value=[...t[s].value,...o.value]:t.push(o)}}}));const n=t.filter((e=>e.key.includes("matrix")));null==n||n.forEach((e=>{const i=t.find((t=>t.key===e.key));i&&(i.value=[...new Set(i.value)])}));const s=t.filter((e=>e.key.includes("point-system")));null==s||s.forEach((e=>{100!==e.value.reduce(((e,t)=>{const i=t.split(": ")[1];return e+Number(i.replace("%",""))}),0)&&(this.log.err("The sum of the point system questions must be 100%"),i=!0)})),this.feedback.answers=i?[]:t}finish(){return n(this,void 0,void 0,(function*(){if(this.completed=!0,this.formOptionsConfig.addSuccessScreen){const e=document.getElementById("magicfeedback-container-"+this.appId);e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,o.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}this.answer();const e=yield this.pushAnswers(!0);if(!e)throw new Error("No response");this.id=e,this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:this.id,loading:!1,progress:this.progress,total:this.total,completed:this.completed,error:null}))}))}pushAnswers(e=!1){return n(this,void 0,void 0,(function*(){try{const t=this.config.get("url"),i={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,a.sendFeedback)(t,this.id?Object.assign(Object.assign({},i),{sessionId:this.id}):i,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){var t;return n(this,void 0,void 0,(function*(){if(!(null==e?void 0:e.followup))return null;try{if(0===this.feedback.answers.length)throw new Error("No answers provided");const i=this.config.get("url"),n={answer:null===(t=this.feedback.answers.find((t=>t.key===e.ref)))||void 0===t?void 0:t.value[0],publicKey:this.publicKey,sessionId:this.id,question:e};return yield(0,a.getFollowUpQuestion)(i,n,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e){var t,i,s;return n(this,void 0,void 0,(function*(){const n=this.history.back();if(!n)throw new Error("No page found");const a=n.getFollowupQuestions();if(0===(null==a?void 0:a.length))return void(yield this.renderNextQuestion(e,n));const r=[];for(const e of a){const t=n.questions.find((t=>t.ref===e));if(t){const e=yield this.callFollowUpQuestion(t);e&&r.push(e)}}if(0===r.length)return void(yield this.renderNextQuestion(e,n));const c=new d.Page(n.id,n.position,this.appId,r,n.edges),l=new u.PageNode(n.id,n.position,n.edges,c,r,!0);l.elements=(0,o.renderQuestions)(r,this.formOptionsConfig.questionFormat,null===(t=this.formData)||void 0===t?void 0:t.lang[0],null===(i=this.formData)||void 0===i?void 0:i.product,(()=>this.send())),this.history.enqueue(l),this.progress=this.history.size(),e.removeChild(e.childNodes[0]),null===(s=l.elements)||void 0===s||s.forEach((t=>e.appendChild(t))),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:this.id,loading:!1,progress:this.progress,total:this.total,followup:l.isFollowup,completed:this.completed,error:null}))}))}renderNextQuestion(e,t){var i,s,a;return n(this,void 0,void 0,(function*(){console.log(t,this.feedback.answers);const n=this.graph.getNextPage(t,this.feedback.answers);console.log(n),n?(n.elements=(0,o.renderQuestions)(n.questions,this.formOptionsConfig.questionFormat,null===(i=this.formData)||void 0===i?void 0:i.lang[0],null===(s=this.formData)||void 0===s?void 0:s.product,(()=>this.send())),e.removeChild(e.childNodes[0]),null===(a=n.elements)||void 0===a||a.forEach((t=>e.appendChild(t))),this.history.enqueue(n),this.progress=this.history.size(),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:this.id,loading:!1,progress:this.progress,total:this.total,followup:n.isFollowup,completed:this.completed,error:null}))):this.finish()}))}back(){var e;return n(this,void 0,void 0,(function*(){if(0===this.history.size())return;const t=document.getElementById("magicfeedback-questions-"+this.appId);t&&t.childNodes.length>0&&t.removeChild(t.childNodes[0]),this.history.rollback(),this.progress=this.history.size();const i=this.history.back();i&&(null===(e=i.elements)||void 0===e||e.forEach((e=>t.appendChild(e)))),this.formOptionsConfig.onBackEvent&&(yield this.formOptionsConfig.onBackEvent({loading:!1,progress:this.progress,followup:(null==i?void 0:i.isFollowup)||!1,error:i?null:"No page found"}))}))}}},804:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Page=void 0,t.Page=class{constructor(e,t,i,n,s){this.id=e,this.position=t,this.generatedAt=(new Date).toISOString(),this.updatedAt=(new Date).toISOString(),this.status="ACTIVE",this.integrationId=i,this.integrationQuestions=n,this.integrationPageRoutes=s}}},24:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.PageGraph=void 0;const n=i(457),s=i(116);t.PageGraph=class{constructor(e){this.nodes=new Map,this.buildGraph(e)}buildGraph(e){e.forEach(((t,i)=>{var a,o;if(!t.integrationPageRoutes&&e[i+1]){const n=new s.PageRoute(`${t.id}-default`,(null===(a=t.integrationQuestions[0])||void 0===a?void 0:a.ref)||"",s.OperatorType.DEFAULT,"",s.TransitionType.PAGE,(null===(o=e[i+1])||void 0===o?void 0:o.id)||"",t.id);t.integrationPageRoutes=[n]}const r=new n.PageNode(t.id,t.position,t.integrationPageRoutes||[],t,t.integrationQuestions);this.nodes.set(r.id,r)}))}getNodeById(e){return this.nodes.get(e)}getNextEdgeByDefault(e){if(e)for(const t of this.nodes.values())if(t.position===e.position+1)return t.id}getFirstPage(){let e,t=Number.MAX_VALUE;for(const i of this.nodes.values())i.position<t&&(t=i.position,e=i);return e}getNextPage(e,t){if(!e)return;e.edges.sort(((e,t)=>"DIRECT"===e.typeCondition?1:"DIRECT"===t.typeCondition?-1:0));const i=e.edges.find((e=>{const i=null==t?void 0:t.filter((t=>t.key===e.questionRef));if(!i)return!1;if("DIRECT"===e.typeCondition)return!0;switch(e.typeOperator){case s.OperatorType.EQUAL:return i.find((t=>{var i;return null===(i=t.value)||void 0===i?void 0:i.includes(e.value)}));case s.OperatorType.NOEQUAL:return!i.find((t=>{var i;return null===(i=t.value)||void 0===i?void 0:i.includes(e.value)}));case s.OperatorType.GREATER:return i.find((t=>t.value.find((t=>Number(t)>Number(e.value)))));case s.OperatorType.LESS:return i.find((t=>t.value.find((t=>Number(t)<Number(e.value)))));case s.OperatorType.GREATEREQUAL:return i.find((t=>t.value.find((t=>Number(t)>=Number(e.value)))));case s.OperatorType.LESSEQUAL:return i.find((t=>t.value.find((t=>Number(t)<=Number(e.value)))));case s.OperatorType.INQ:return i.find((t=>e.value.includes(t.value)));case s.OperatorType.NINQ:return!i.find((t=>e.value.includes(t.value)));default:return!1}}));if(!i){const t=this.getNextEdgeByDefault(e);if(!t)return;return this.getNodeById(t)}switch(i.transition){case s.TransitionType.PAGE:return this.getNodeById(i.transitionDestiny);case s.TransitionType.FINISH:return;case s.TransitionType.REDIRECT:return void(window.location.href=i.transitionDestiny);default:return}}findDepth(e){const t=this.getNodeById(e);if(!t)return 0;const i=new Set;return this.DFSUtil(t,i,0)}findMaxDepth(e){if(e||(e=this.getFirstPage()),!e)return 0;const t=new Set;let i=e.questions.find((e=>e.followup))?2:1;return i=Math.max(i,this.DFSUtil(e,t,i)),i}DFSUtil(e,t,i){t.add(e);let n=i;const s=e.edges||[];for(const e of s){const s=this.getNodeById(e.transitionDestiny);if(s&&!t.has(s)){const e=s.questions.find((e=>e.followup))?i+2:i+1,a=this.DFSUtil(s,t,e);n=Math.max(n,a)}}return n}}},457:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.PageNode=void 0,t.PageNode=class{constructor(e,t,i,n,s,a=!1){this.id=e,this.position=t,this.edges=i,this.data=n,this.questions=s,this.elements=[],this.isFollowup=a}getFollowupQuestions(){return this.questions.filter((e=>e.followup)).map((e=>e.ref))}getRequiredQuestions(){return this.questions.filter((e=>e.require)).map((e=>e.ref))}}},116:(e,t)=>{"use strict";var i,n,s,a;Object.defineProperty(t,"__esModule",{value:!0}),t.PageRoute=t.StatusType=t.OperatorType=t.ConditionType=t.TransitionType=void 0,(a=t.TransitionType||(t.TransitionType={})).PAGE="PAGE",a.FINISH="FINISH",a.REDIRECT="REDIRECT",function(e){e.LOGICAL="LOGICAL",e.DIRECT="DIRECT"}(i=t.ConditionType||(t.ConditionType={})),(s=t.OperatorType||(t.OperatorType={})).EQUAL="EQUAL",s.NOEQUAL="NOEQUAL",s.GREATER="GREATER",s.LESS="LESS",s.GREATEREQUAL="GREATEREQUAL",s.LESSEQUAL="LESSEQUAL",s.INQ="INQ",s.NINQ="NINQ",s.DEFAULT="DEFAULT",function(e){e.ACTIVE="ACTIVE",e.DEPRECATED="DEPRECATED",e.DELETE="DELETE"}(n=t.StatusType||(t.StatusType={})),t.PageRoute=class{constructor(e,t,s,a,o,r,d,c){this.id=e,this.questionRef=t,this.typeCondition=c||i.LOGICAL,this.typeOperator=s,this.value=a,this.transition=o,this.transitionDestiny=r,this.status=n.ACTIVE,this.generatedAt=new Date,this.updatedAt=new Date,this.integrationPageId=d}}},244:(e,t)=>{"use strict";var i,n;Object.defineProperty(t,"__esModule",{value:!0}),t.QuestionType=t.FEEDBACKAPPANSWERTYPE=void 0,(n=t.FEEDBACKAPPANSWERTYPE||(t.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",t.QuestionType=class{},function(e){e.FORM="form",e.DIV="div"}(i||(i={}))},374:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.endpoints=void 0,t.endpoints={sdk:{app:(e,t)=>`sdk/app/${e}/${t}`,app_info:(e,t)=>`sdk/app/${e}/${t}/info`,session:e=>`sdk/app/session/${e}/info`,feedback:"sdk/feedback",followUpQuestion:"sdk/followUpQuestion"}}},528:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.placeholder=void 0,t.placeholder={answer:e=>{switch(e){case"en":default:return"Write your answer here...";case"es":return"Escribe tu respuesta aquí...";case"da":return"Skriv dit svar her...";case"fi":return"Kirjoita vastauksesi tähän...";case"sv":return"Skriv ditt svar här...";case"no":return"Skriv svaret ditt her...";case"ar":return"اكتب إجابتك هنا...";case"bn":return"এখানে আপনার"}},number:e=>{switch(e){case"en":default:return"Write your number here...";case"es":return"Escribe tu número aquí...";case"da":return"Skriv dit nummer her...";case"fi":return"Kirjoita numerosi tähän...";case"sv":return"Skriv ditt nummer här...";case"no":return"Skriv nummeret ditt her...";case"ar":return"اكتب رقمك هنا...";case"bn":return"এখানে আপনার"}},email:e=>{switch(e){case"en":default:return"Write your email here...";case"es":return"Escribe tu correo electrónico aquí...";case"da":return"Skriv din e-mail her...";case"fi":return"Kirjoita sähköpostiosoitteesi tähän...";case"sv":return"Skriv din e-post här...";case"no":return"Skriv e-posten din her...";case"ar":return"اكتب بريدك الإلكتروني هنا...";case"bn":return"এখানে আপনার"}},date:e=>{switch(e){case"en":default:return"Write your date here...";case"es":return"Escribe tu fecha aquí...";case"da":return"Skriv din dato her...";case"fi":return"Kirjoita päivämääräsi tähän...";case"sv":return"Skriv ditt datum här...";case"no":return"Skriv datoen din her...";case"ar":return"اكتب تاريخك هنا...";case"bn":return"এখানে আপনার"}},password:e=>{switch(e){case"en":default:return"Write your password here...";case"es":return"Escribe tu contraseña aquí...";case"da":return"Skriv dit kodeord her...";case"fi":return"Kirjoita salasanasi tähän...";case"sv":return"Skriv ditt lösenord här...";case"no":return"Skriv passordet ditt her...";case"ar":return"اكتب كلمة المرور الخاصة بك هنا...";case"bn":return"এখানে আপনার"}},pointsystemerror:e=>{switch(e){case"en":default:return"The total points must be 100 %";case"es":return"El total de puntos debe ser 100 %";case"da":return"Samlet antal point skal være 100 %";case"fi":return"Kokonaispisteiden on oltava 100 %";case"sv":return"Totala poäng måste vara 100 %";case"no":return"Totalt antall poeng må være 100 %";case"ar":return"يجب أن تكون النقاط الإجمالية 100 %";case"bn":return"মোট পয়েন্ট 100 % হতে হবে"}}}},183:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.renderStartMessage=t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0;const n=i(244),s=i(528),a="https://survey-dev.magicfeedback.io/assets/emojis";function o(e,t){return"object"==typeof e?e[t]||e.en:e}function r(e,t,i,n,s,a=!0){const o=document.createElement("div");o.classList.add("magicfeedback-rating-placeholder"),o.style.display="flex",o.style.justifyContent="space-between",o.style.width=s?`calc(100% - (100% / ${t+1}))`:"100%",o.style.marginRight="auto",a&&window.innerWidth<600&&(o.style.flexDirection="column");const r=document.createElement("span");r.textContent=i,r.classList.add("magicfeedback-rating-placeholder-value"),r.style.fontSize="15px",r.style.textAlign="left",r.style.width="50%",a&&window.innerWidth<600&&(r.textContent=`${e} ➜ ${i}`,r.style.width="100%",r.style.textAlign="left",r.style.marginBottom="5px"),o.appendChild(r);const d=document.createElement("span");return d.textContent=n,d.classList.add("magicfeedback-rating-placeholder-value"),d.style.fontSize="15px",d.style.textAlign="right",d.style.width="50%",a&&window.innerWidth<600&&(d.textContent=`${t} ➜ ${n}`,d.style.width="100%",d.style.textAlign="left",d.style.marginBottom="5px"),o.appendChild(d),o}t.renderQuestions=function e(t,i="standard",d="en",c={customIcons:!1},l){if(!t)throw new Error("[MagicFeedback] No questions provided");const u=[],{customIcons:p,id:h}=c;return t.forEach((t=>{var m,f;if((null===(f=null===(m=null==t?void 0:t.questionType)||void 0===m?void 0:m.conf)||void 0===f?void 0:f.length)>0){let n=document.createElement("div");n.classList.add("magicfeedback-div");const s=document.createElement("label");s.setAttribute("for",`magicfeedback-${t.id}`),s.textContent=o(t.title,d),s.classList.add("magicfeedback-label"),n.appendChild(s),t.questionType.conf.forEach((e=>{e.ref=t.ref,t.assets[e.id]&&(e.assets={placeholder:t.assets[e.id]})})),e(t.questionType.conf,i,d,c,l).forEach((e=>{n.appendChild(e)})),u.push(n)}else{const e=function(e,t,i,d,c){var l;let u,p,{id:h,title:m,type:f,ref:g,require:y,value:v,defaultValue:b,assets:E}=e,k=document.createElement("div");k.classList.add("magicfeedback-div");const C="slim"===t?o(m,i):null==E?void 0:E.placeholder,w=(T=h,new URLSearchParams(window.location.search).get(T)),x=(null==E?void 0:E.maxCharacters)||0;var T;switch(f){case n.FEEDBACKAPPANSWERTYPE.TEXT:u=document.createElement("input"),u.type="text",u.placeholder=C||s.placeholder.answer(i||"en"),p="magicfeedback-text";break;case n.FEEDBACKAPPANSWERTYPE.LONGTEXT:u=document.createElement("textarea"),u.rows=3,x>0&&(u.maxLength=x),u.placeholder=C||s.placeholder.answer(i||"en"),p="magicfeedback-longtext";break;case n.FEEDBACKAPPANSWERTYPE.NUMBER:u=document.createElement("input"),u.type="number",u.placeholder="slim"===t?o(m,i):s.placeholder.number(i||"en"),p="magicfeedback-number",v.length&&(v.sort(((e,t)=>Number(e)-Number(t))),u.max=v[v.length-1],u.min=v[0],u.value=v[0]);break;case n.FEEDBACKAPPANSWERTYPE.RADIO:case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:u=document.createElement("div"),p="magicfeedback-"+("MULTIPLECHOICE"===f?"checkbox":"radio"),(null==E?void 0:E.extraOption)&&!v.includes(null==E?void 0:E.extraOptionText)&&v.push(null==E?void 0:E.extraOptionText),v.forEach(((e,t)=>{const a=document.createElement("div");a.classList.add(`magicfeedback-${"MULTIPLECHOICE"===f?"checkbox":"radio"}-container`);const o=document.createElement("label"),r=document.createElement("input");if(r.id=`rating-${g}-${t}`,r.type="MULTIPLECHOICE"===f?"checkbox":"radio",r.name=g,r.value=e,r.classList.add(p),r.classList.add("magicfeedback-input"),f===n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE&&(null==E?void 0:E.maxOptions)&&(null==E?void 0:E.maxOptions)>0&&r.addEventListener("change",(()=>{document.querySelectorAll(`input[name="${g}"]:checked`).length>(null==E?void 0:E.maxOptions)&&(r.checked=!1)})),e!==b&&e!==w||(r.checked=!0),o.textContent=e,o.htmlFor=`rating-${g}-${t}`,r.addEventListener("change",(t=>{const i=document.getElementById(`extra-option-${g}`);i&&(null==E?void 0:E.extraOption)&&(t.target.checked&&e===(null==E?void 0:E.extraOptionText)?(v.forEach(((e,t)=>{e!==(null==E?void 0:E.extraOptionText)&&(document.getElementById(`rating-${g}-${t}`).checked=!1)})),i.style.display="block"):(document.getElementById(`rating-${g}-${v.length-1}`).checked=!1,i.style.display="none"))})),a.appendChild(r),a.appendChild(o),u.appendChild(a),(null==E?void 0:E.extraOption)&&e===(null==E?void 0:E.extraOptionText)){const e=document.createElement("input");e.type="text",e.placeholder=(null==E?void 0:E.extraOptionPlaceholder)||s.placeholder.answer(i||"en"),e.classList.add("magicfeedback-extra-option"),e.classList.add("magicfeedback-input"),e.id=`extra-option-${g}`,e.name=`extra-option-${g}`,e.style.display="none",u.appendChild(e)}}));break;case n.FEEDBACKAPPANSWERTYPE.BOOLEAN:u=document.createElement("div"),p="magicfeedback-radio";const L=document.createElement("div");L.classList.add("magicfeedback-boolean-container"),L.style.display="flex",L.style.flexDirection="row",L.style.justifyContent="space-between",L.style.width="70%",L.style.margin="auto",((null==E?void 0:E.addIcon)?["👍","👎"]:function(e){switch(e){case"es":return["Sí","No"];case"fr":return["Oui","Non"];case"de":return["Ja","Nein"];case"it":return["Sì","No"];case"pt":return["Sim","Não"];case"nl":return["Ja","Nee"];case"pl":return["Tak","Nie"];case"ru":return["Да","Нет"];case"ja":return["はい","いいえ"];case"zh":return["是","不"];case"ko":return["예","아니"];case"da":case"sv":return["Ja","Nej"];case"fi":return["Kyllä","Ei"];case"no":return["Ja","Nei"];case"ar":return["نعم","لا"];case"bn":return["হ্যাঁ","না"];default:return["Yes","No"]}}(i)).forEach(((e,t)=>{const i=document.createElement("label");i.classList.add("magicfeedback-boolean-option"),i.htmlFor=`rating-${g}-${t}`,i.style.cursor="pointer",i.style.border="1px solid #000",i.style.display="flex",i.style.justifyContent="center",i.style.alignItems="center",i.style.margin="auto",i.style.padding="0",i.style.width="45%",i.style.height="38px";const n=document.createElement("label");n.htmlFor=`rating-${g}-${t}`,n.textContent=e,n.style.margin="0",n.style.padding="0";const s=document.createElement("input");s.id=`rating-${g}-${t}`,s.type="radio",s.name=g,s.value=e,s.classList.add(p),s.classList.add("magicfeedback-input"),s.style.position="absolute",s.style.opacity="0",s.style.width="0",s.style.height="0",s.style.margin="0",s.addEventListener("change",(()=>{c&&c()})),i.appendChild(s),i.appendChild(n),L.appendChild(i)})),u.appendChild(L);break;case n.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:u=document.createElement("div"),p="magicfeedback-rating";const S=document.createElement("div");S.classList.add("magicfeedback-rating-container");const O=(null==E?void 0:E.max)?Number(null==E?void 0:E.max):5,P=(null==E?void 0:E.min)?Number(null==E?void 0:E.min):1,I=r(P,O,null==E?void 0:E.minPlaceholder,null==E?void 0:E.maxPlaceholder,null==E?void 0:E.extraOption);for(let re=P;re<=O;re++){const de=document.createElement("div");de.classList.add("magicfeedback-rating-option");const ce=document.createElement("label");ce.htmlFor=`rating-${g}-${re}`,ce.classList.add("magicfeedback-rating-option-label-container");const le=document.createElement("label");le.htmlFor=`rating-${g}-${re}`,le.textContent=re.toString();const ue=document.createElement("img");if(ue.alt=`face-${g}-${re}`,ue.className=`rating-image${re}`,0===P&&10===O)ue.src=`${d}/${re}.svg`,ue.onerror=()=>ue.src=`${a}/${re}.svg`;else if(1===P&&5===O)switch(re){case 1:ue.src=`${d}/1.svg`,ue.onerror=()=>ue.src=`${a}/1.svg`;break;case 2:ue.src=`${d}/2.svg`,ue.onerror=()=>ue.src=`${a}/2.svg`;break;case 3:ue.src=`${d}/6.svg`,ue.onerror=()=>ue.src=`${a}/6.svg`;break;case 4:ue.src=`${d}/9.svg`,ue.onerror=()=>ue.src=`${a}/9.svg`;break;case 5:ue.src=`${d}/10.svg`,ue.onerror=()=>ue.src=`${a}/10.svg`}else{const he=Math.round(10/(O-P)*(re-P));ue.src=`${d}/${he}.svg`,ue.onerror=()=>ue.src=`${a}/${he}.svg`}const pe=document.createElement("input");pe.id=`rating-${g}-${re}`,pe.type="radio",pe.name=g,pe.value=re.toString(),pe.classList.add(p),pe.classList.add("magicfeedback-input"),ce.appendChild(pe),ce.appendChild(ue),ce.appendChild(le),de.appendChild(ce),S.appendChild(de)}if((null==E?void 0:E.extraOption)&&(null==E?void 0:E.extraOptionText)){const me=document.createElement("div");me.classList.add("magicfeedback-rating-option");const fe=document.createElement("label");fe.htmlFor=`rating-${g}-extra`,fe.classList.add("magicfeedback-rating-option-label-container");const ge=document.createElement("label");ge.htmlFor=`rating-${g}-extra`,ge.textContent=null==E?void 0:E.extraOptionText;const ye=document.createElement("img");ye.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",ye.alt=`face-${g}-extra`,ye.className="magicfeedback-rating-image-extra";const ve=document.createElement("input");ve.id=`rating-${g}-extra`,ve.type="radio",ve.name=g,ve.value="-",ve.classList.add(p),ve.classList.add("magicfeedback-input"),fe.appendChild(ve),fe.appendChild(ye),fe.appendChild(ge),me.appendChild(fe),S.appendChild(me)}u.appendChild(I),u.appendChild(S);break;case n.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:u=document.createElement("div"),p="magicfeedback-rating-number";const N=document.createElement("div");N.classList.add("magicfeedback-rating-number-container");const D=(null==E?void 0:E.max)?Number(null==E?void 0:E.max):5,$=(null==E?void 0:E.min)?Number(null==E?void 0:E.min):1,R=r($,D,null==E?void 0:E.minPlaceholder,null==E?void 0:E.maxPlaceholder,null==E?void 0:E.extraOption);for(let be=$;be<=D;be++){const Ee=document.createElement("div");Ee.classList.add("magicfeedback-rating-number-option");const ke=document.createElement("label");ke.htmlFor=`rating-${g}-${be}`,ke.classList.add("magicfeedback-rating-number-option-label-container");const Ce=document.createElement("label");Ce.htmlFor=`rating-${g}-${be}`,Ce.textContent=be.toString();const we=document.createElement("input");we.id=`rating-${g}-${be}`,we.type="radio",we.name=g,we.value=be.toString(),we.classList.add(p),we.classList.add("magicfeedback-input"),ke.appendChild(we),ke.appendChild(Ce),Ee.appendChild(ke),N.appendChild(Ee)}if((null==E?void 0:E.extraOption)&&(null==E?void 0:E.extraOptionText)){const xe=document.createElement("div");xe.classList.add("magicfeedback-rating-number-option");const Te=document.createElement("label");Te.htmlFor=`rating-${g}-extra`,Te.classList.add("magicfeedback-rating-number-option-label-container");const Ae=document.createElement("label");Ae.htmlFor=`rating-${g}-extra`,Ae.textContent=null==E?void 0:E.extraOptionText;const Le=document.createElement("input");Le.id=`rating-${g}-extra`,Le.type="radio",Le.name=g,Le.value="-",Le.classList.add(p),Le.classList.add("magicfeedback-input"),Te.appendChild(Le),Te.appendChild(Ae),xe.appendChild(Te),N.appendChild(xe)}u.appendChild(R),u.appendChild(N);break;case n.FEEDBACKAPPANSWERTYPE.RATING_STAR:u=document.createElement("div"),p="magicfeedback-rating-star";const _=function(e,t,i){const n="magicfeedback-rating-star-selected",s=document.createElement("div");s.classList.add("magicfeedback-rating-star-container"),s.style.maxWidth="300px",s.style.margin="auto";for(let t=1;t<=5;t++){const i=document.createElement("label");i.classList.add("magicfeedback-rating-star-option");const a=document.createElement("input");a.id=`rating-${e}-${t}`,a.type="radio",a.name=e,a.value=t.toString(),a.style.position="absolute",a.style.opacity="0",a.style.width="0",a.style.height="0",a.classList.add("magicfeedback-input"),a.addEventListener("change",(()=>{const e=s.querySelectorAll(".rating__star");for(let t=0;t<e.length;t++)t+1<=Number(a.value)?e[t].classList.contains(n)||e[t].classList.add(n):e[t].classList.contains(n)&&e[t].classList.remove(n)})),i.appendChild(a);const o=document.createElement("label");o.htmlFor=`rating-${e}-${t}`,o.classList.add("rating__star"),o.textContent="★",o.style.fontSize="40px",o.style.color="#CCCCCC",o.style.cursor="pointer",i.appendChild(o),s.appendChild(i)}return s.appendChild(r(1,5,t,i,!1,!1)),s}(g,null==E?void 0:E.minPlaceholder,null==E?void 0:E.maxPlaceholder);u.appendChild(_);break;case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:u=document.createElement("div"),p="magicfeedback-multiple-choice-image";const F=document.createElement("div");F.classList.add("magicfeedback-multiple-choice-image-container"),F.style.display="flex",F.style.flexDirection="row",F.style.flexWrap="wrap",F.style.justifyContent="center";const M=v.length;let B=1,q=1;switch(M){case 1:case 2:case 3:B=M,q=1;break;case 4:case 5:case 6:q=2,B=Math.ceil(M/q);break;case 7:case 8:case 9:q=3,B=Math.ceil(M/q);break;default:q=4,B=Math.ceil(M/q)}const U=void 0!==(null==E?void 0:E.addTitle)&&(null==E?void 0:E.addTitle),j=void 0!==(null==E?void 0:E.multiOption)&&(null==E?void 0:E.multiOption),G=void 0!==(null==E?void 0:E.randomPosition)&&(null==E?void 0:E.randomPosition),Q=void 0!==(null==E?void 0:E.extraOption)&&(null==E?void 0:E.extraOption);function K(e){try{const{position:t,url:i,value:n}=e,s=document.createElement("label");s.classList.add("magicfeedback-multiple-choice-image-option"),s.style.width=`calc( ${100/B}% - 10px)`,s.style.height=`calc( ${100/q}% - 10px)`,s.style.margin="5px";const a=document.createElement("label");a.htmlFor=`rating-${g}-${t}`,a.classList.add("magicfeedback-image-option-label-container"),a.style.display="flex",a.style.flexDirection="column",a.addEventListener("mouseover",(()=>{a.style.border="2px solid #000"})),a.addEventListener("mouseout",(()=>{a.style.border="none"})),a.addEventListener("click",(()=>{a.style.border="2px solid #000"}));const o=document.createElement("label");o.textContent=n,o.classList.add("magicfeedback-multiple-choice-image-label");const r=document.createElement("input");r.id=`rating-${g}-${t}`,r.type=j?"checkbox":"radio",r.name=g,r.value=n,r.style.position="absolute",r.style.opacity="0",r.style.width="0",r.style.height="0",r.classList.add("magicfeedback-input");const d=document.createElement("img");d.classList.add("magicfeedback-multiple-choice-image-image"),d.src=i,d.style.cursor="pointer",d.style.backgroundSize="cover",d.style.backgroundPosition="center",d.style.width="100%",d.style.height="100%",d.style.objectFit="cover",d.style.margin="auto",a.appendChild(r),a.appendChild(d),U&&a.appendChild(o),s.appendChild(a),F.appendChild(s)}catch(e){console.error(e)}}G&&(v=v.sort((()=>Math.random()-.5))),v.forEach((e=>K(JSON.parse(e)))),Q&&(null==E?void 0:E.extraOptionValue)&&(null==E?void 0:E.extraOptionValue.length)>0&&K(null==E?void 0:E.extraOptionValue[0]),u.appendChild(F);break;case n.FEEDBACKAPPANSWERTYPE.SELECT:u=document.createElement("select"),p="magicfeedback-select";const W=document.createElement("option");W.value="",W.text="slim"===t?o(m,i):b||"Select an option",W.disabled=!0,W.selected=!0,u.appendChild(W),v.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,u.appendChild(t)}));break;case n.FEEDBACKAPPANSWERTYPE.DATE:u=document.createElement("input"),u.type="date",u.required=y,u.placeholder=C||s.placeholder.date(i||"en"),p="magicfeedback-date";break;case n.FEEDBACKAPPANSWERTYPE.CONSENT:u=document.createElement("input"),p="magicfeedback-consent",u.type="checkbox",u.id=`magicfeedback-${h}`,u.name=g,u.value="true",u.required=y,u.classList.add("magicfeedback-consent"),u.classList.add("magicfeedback-input");break;case n.FEEDBACKAPPANSWERTYPE.EMAIL:u=document.createElement("input"),u.type="email",u.required=y,u.placeholder=C||"you@example.com",p="magicfeedback-email";break;case n.FEEDBACKAPPANSWERTYPE.PASSWORD:u=document.createElement("input"),u.type="password",u.required=y,u.placeholder=C||s.placeholder.password(i||"en"),p="magicfeedback-password";break;case n.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:u=document.createElement("div"),p="magicfeedback-multi-question-matrix";const H=document.createElement("div");H.classList.add("magicfeedback-multi-question-matrix-container");const Y=document.createElement("table");Y.classList.add("magicfeedback-multi-question-matrix-table");const V=document.createElement("thead");V.classList.add("magicfeedback-multi-question-matrix-header"),V.style.paddingBottom="15px";const z=document.createElement("tr");["",...v].forEach((e=>{const t=document.createElement("th");t.textContent=e,t.style.padding="0 10px 10px 10px ",z.appendChild(t)})),V.appendChild(z);const J=document.createElement("tbody");(null===(l=null==E?void 0:E.options)||void 0===l?void 0:l.length)>0&&(null==E||E.options.split("|").forEach((e=>{const t=document.createElement("tr");t.style.paddingBottom="15px";const i=document.createElement("td");i.classList.add("magicfeedback-multi-question-matrix-row-label");const n=document.createElement("label");n.classList.add("magicfeedback-multi-question-matrix-label"),n.style.paddingRight="15px",n.textContent=e,i.appendChild(n),t.appendChild(i),v.forEach((i=>{const n=document.createElement("td"),s=document.createElement("input");s.type="radio",s.name=`${g}-${e}`,s.value=i,s.id=`matrix-${e}`,s.classList.add("magicfeedback-input"),s.style.padding="0 10px",n.appendChild(s),t.appendChild(n)})),J.appendChild(t)}))),Y.appendChild(V),Y.appendChild(J),H.appendChild(Y),u.appendChild(H);break;case n.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:u=document.createElement("div"),p="magicfeedback-priority-list";const X=document.createElement("div");X.classList.add("magicfeedback-priority-list-container");const Z=document.createElement("ul");Z.classList.add("magicfeedback-priority-list-list"),v.forEach(((e,t)=>{const i=document.createElement("li");i.classList.add("magicfeedback-priority-list-item"),i.style.display="flex",i.style.justifyContent="space-between",i.style.alignItems="center",i.style.margin="5px";const n=document.createElement("input");n.classList.add("magicfeedback-input-magicfeedback-priority-list"),n.classList.add("magicfeedback-input"),n.type="hidden",n.id=`priority-list-${g}`,n.name=g,n.value=`${t+1}. ${e}`,i.appendChild(n);const s=document.createElement("label");s.classList.add("magicfeedback-priority-list-item-label"),s.textContent=`${t+1}. ${e}`,i.appendChild(s);const a=document.createElement("div");a.style.display="flex",a.style.alignItems="center",a.style.justifyContent="space-between";const o=document.createElement("img");o.classList.add("magicfeedback-priority-list-arrow-up"),o.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",o.style.width="20px",o.style.height="20px",o.style.cursor="pointer",o.style.margin="0 5px",o.style.color="#000",o.style.visibility=0===t?"hidden":"visible",o.addEventListener("click",(()=>{var t,a;const d=i.previousElementSibling;if(d){const c=Number(n.value.split(".")[0])-1;n.value=`${c}. ${e}`,s.textContent=`${c}. ${e}`,o.style.visibility=1===c?"hidden":"visible",r.style.visibility=c===v.length?"hidden":"visible";const l=d.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=d.querySelector(".magicfeedback-priority-list-item-label"),p=d.querySelector(".magicfeedback-priority-list-arrow-up"),h=d.querySelector(".magicfeedback-priority-list-arrow-down");if(l&&u&&p&&h){const e=Number(l.value.split(".")[0])+1;l.value=`${e}.${null===(t=u.textContent)||void 0===t?void 0:t.split(".")[1]}`,u.textContent=`${e}.${null===(a=u.textContent)||void 0===a?void 0:a.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",h.style.visibility=e===v.length?"hidden":"visible"}Z.insertBefore(i,d)}})),a.appendChild(o);const r=document.createElement("img");r.classList.add("magicfeedback-priority-list-arrow-down"),r.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",r.style.width="20px",r.style.height="20px",r.style.cursor="pointer",r.style.margin="0 5px",r.style.color="#000",r.style.transform="rotate(180deg)",r.style.visibility=t===v.length-1?"hidden":"visible",r.addEventListener("click",(()=>{var t,a;const d=i.nextElementSibling;if(d){const c=Number(n.value.split(".")[0])+1;n.value=c.toString(),s.textContent=`${c.toString()}. ${e}`,o.style.visibility=1===c?"hidden":"visible",r.style.visibility=c===v.length?"hidden":"visible";const l=d.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=d.querySelector(".magicfeedback-priority-list-item-label"),p=d.querySelector(".magicfeedback-priority-list-arrow-up"),h=d.querySelector(".magicfeedback-priority-list-arrow-down");if(l&&u&&p&&h){const e=Number(l.value.split(".")[0])-1;l.value=`${e}.${null===(t=u.textContent)||void 0===t?void 0:t.split(".")[1]}`,u.textContent=`${e}.${null===(a=u.textContent)||void 0===a?void 0:a.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",h.style.visibility=e===v.length?"hidden":"visible"}Z.insertBefore(d,i)}})),a.appendChild(r),i.appendChild(a),Z.appendChild(i)})),X.appendChild(Z),u.appendChild(X);break;case n.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:u=document.createElement("div"),p="magicfeedback-point-system";const ee=document.createElement("div");ee.classList.add("magicfeedback-point-system-container");const te=document.createElement("ul");te.classList.add("magicfeedback-point-system-list"),te.style.padding="0";const ie=100,ne=ie/v.length,se=document.createElement("div");se.classList.add("magicfeedback-error"),se.textContent=s.placeholder.pointsystemerror(i||"en"),se.style.color="#C70039",se.style.fontSize="14px",se.style.textAlign="right",se.style.width="100%",se.style.display="none";const ae=document.createElement("div");ae.classList.add("magicfeedback-point-system-total"),ae.textContent="0 / 100 %",ae.style.textAlign="right",ae.style.fontSize="15px",ae.style.marginTop="5px",v.forEach(((e,t)=>{const i=document.createElement("li");i.classList.add("magicfeedback-point-system-item"),i.style.display="flex",i.style.justifyContent="space-between",i.style.alignItems="center",i.style.margin="5px";const n=document.createElement("label");n.textContent=e,n.style.fontSize="15px",i.appendChild(n);const s=document.createElement("span");s.classList.add("magicfeedback-point-system-input-container");const a=document.createElement("input");a.name=g,a.id=`point-system-${e}`,a.type="number",a.min="0",a.max=`${ie}`,a.value="0",a.classList.add("magicfeedback-input"),a.style.width="40px",a.style.border="0",a.style.textAlign="center",a.style.margin="0 5px",a.autofocus=0===t;const o=document.createElement("span");o.textContent="%",o.style.color="#000",a.addEventListener("input",(()=>{const e=te.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>ie&&(a.value=`${ne}%`,t-=Number(a.value));const i=document.getElementById("magicfeedback-submit");i&&(t<100?(ae.style.color="orange",i.setAttribute("disabled","true")):(se.style.display="none",ae.style.color="green",i.removeAttribute("disabled"))),ae.textContent=`${t} / 100 %`})),a.addEventListener("focus",(()=>{const e=document.getElementById("magicfeedback-submit");e&&(e.setAttribute("disabled","true"),e.addEventListener("pointerover",(()=>{const e=te.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t<100&&(se.style.display="block")})))})),s.appendChild(a),s.appendChild(o),i.appendChild(s),te.appendChild(i)})),ee.appendChild(te),ee.appendChild(ae),ee.appendChild(se),u.appendChild(ee);break;case n.FEEDBACKAPPANSWERTYPE.INFO_PAGE:u=document.createElement("div"),p="magicfeedback-info-page";const oe=document.createElement("div");oe.classList.add("magicfeedback-info-message"),oe.innerHTML=C,u.appendChild(oe);break;default:return k}u.id=`magicfeedback-${h}`,u.setAttribute("name",g),u.classList.add(p),(void 0!==b||null!==w)&&(u.value=w||b),["RADIO","MULTIPLECHOICE"].includes(f)||(u.classList.add("magicfeedback-input"),u.required=y);const A=document.createElement("label");if(A.setAttribute("for",`magicfeedback-${h}`),A.textContent=o(m,i),A.classList.add("magicfeedback-label"),["CONSENT"].includes(f))k.classList.add("magicfeedback-consent-container"),k.appendChild(u),k.appendChild(A);else{if("slim"!==t&&([n.FEEDBACKAPPANSWERTYPE.INFO_PAGE].includes(f)||k.appendChild(A),void 0!==(null==E?void 0:E.general)&&""!==(null==E?void 0:E.general))){const Se=document.createElement("img");Se.src=null==E?void 0:E.general,Se.classList.add("magicfeedback-image"),Se.style.maxWidth="auto",Se.style.height="400px",Se.style.margin="10px 0",k.appendChild(Se)}if("LONGTEXT"===f&&x>0){const Oe=document.createElement("div");if(Oe.classList.add("magicfeedback-counter"),Oe.textContent=`${u.value.length}/${x}`,Oe.style.textAlign="right",Oe.style.fontSize="15px",Oe.style.marginTop="5px",u.addEventListener("input",(()=>{Oe.textContent=`${u.value.length}/${x}`})),k.appendChild(u),k.appendChild(Oe),(null==E?void 0:E.extraOption)&&(null==E?void 0:E.extraOptionText)){const Pe=document.createElement("div");Pe.classList.add("magicfeedback-skip-container"),Pe.classList.add("magicfeedback-checkbox-container"),Pe.style.display="flex",Pe.style.justifyContent="flex-start";const Ie=document.createElement("input");Ie.classList.add("magicfeedback-skip"),Ie.type="checkbox",Ie.id=`skip-${g}`,Ie.name=g,Ie.value="-",Ie.style.cursor="pointer";const Ne=document.createElement("label");Ne.htmlFor=`skip-${g}`,Ne.textContent=null==E?void 0:E.extraOptionText,Ne.style.fontSize="15px",Ne.style.cursor="pointer",Ne.style.margin="0 5px",Ie.addEventListener("click",(()=>{u.value="-",c&&c()})),Pe.appendChild(Ie),Pe.appendChild(Ne),k.appendChild(Pe)}}else k.appendChild(u)}return k}(t,i,d,`${a}${p?`/${h}`:""}`,l);u.push(e)}})),u},t.renderActions=function(e="",t,i="Submit",n="Back",s="Next"){const a=document.createElement("div");a.classList.add("magicfeedback-action-container");const o=document.createElement("button");o.id="magicfeedback-submit",o.type="submit",o.classList.add("magicfeedback-submit"),o.textContent="MAGICSURVEY"===e?s||"Next":i||"Submit";const r=document.createElement("button");return r.id="magicfeedback-back",r.type="button",r.classList.add("magicfeedback-back"),r.textContent=n||"Back",r.addEventListener("click",t),r.addEventListener("click",(()=>{o.removeAttribute("disabled")})),"MAGICSURVEY"===e&&a.appendChild(r),a.appendChild(o),a},t.renderError=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-error"),t.textContent=e,t},t.renderSuccess=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-success"),t.textContent=e,t},t.renderStartMessage=function(e,t=!1,i="Go!",n=(()=>{})){const s=document.createElement("div");s.classList.add("magicfeedback-start-message-container");const a=document.createElement("div");if(a.classList.add("magicfeedback-start-message"),a.innerHTML=e,s.appendChild(a),t){const e=document.createElement("button");e.id="magicfeedback-start-message-button",e.classList.add("magicfeedback-start-message-button"),e.textContent=i,e.addEventListener("click",(()=>n())),s.appendChild(e)}return s}},341:function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,a){function o(e){try{d(n.next(e))}catch(e){a(e)}}function r(e){try{d(n.throw(e))}catch(e){a(e)}}function d(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}d((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFollowUpQuestion=t.sendFeedback=t.getQuestions=t.getSessionForm=t.getForm=t.validateEmail=void 0;const a=s(i(98)),o=s(i(147)),r=i(374),d={Accept:"application/json","Magicfeedback-Sdk-Version":o.default.version};t.validateEmail=function(e){return/\S+@\S+\.\S+/.test(e)},t.getForm=function(e,t,i,s){return n(this,void 0,void 0,(function*(){try{const n=yield(0,a.default)(e+r.endpoints.sdk.app_info(t,i),{method:"GET",headers:d});if(n.ok){const e=yield n.json();return s.log(`Received form for app ${t}`,e),e}throw s.err(`Failed to get questions for app ${t}:`,n.status,n.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return s.err(e),null}}))},t.getSessionForm=function(e,t,i){return n(this,void 0,void 0,(function*(){try{const n=yield(0,a.default)(e+r.endpoints.sdk.session(t),{method:"GET",headers:d});if(n.ok){const e=yield n.json();return i.log(`Received form for session ${t}`,e),e}throw i.err(`Failed to get questions for session ${t}:`,n.status,n.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return i.err(e),null}}))},t.getQuestions=function(e,t,i,s){return n(this,void 0,void 0,(function*(){try{const n=yield(0,a.default)(e+r.endpoints.sdk.app(t,i),{method:"GET",headers:d});if(n.ok){const e=yield n.json();return s.log(`Received questions for app ${t}`,e),e}throw s.err(`Failed to get questions for app ${t}:`,n.status,n.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return s.err(e),[]}}))},t.sendFeedback=function(e,t,i){return n(this,void 0,void 0,(function*(){try{const n=yield(0,a.default)(e+r.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},d),body:JSON.stringify(t)});if(n.ok)return i.log(`Form ${t.integration} submitted successfully!`),(yield n.json()).sessionId;throw i.err(`Failed to submit form ${t.integration}:`,n.status,n.statusText),new Error(n.statusText)}catch(e){return i.err(e),""}}))},t.getFollowUpQuestion=function(e,t,i){return n(this,void 0,void 0,(function*(){try{const n=yield(0,a.default)(e+r.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},d),body:JSON.stringify(t)});if(n.ok)return i.log(`Received follow up question for form ${t.integration}`),(yield n.json())||"";throw i.err(`Failed to get follow up question for form ${t.integration}:`,n.status,n.statusText),new Error(n.statusText)}catch(e){return i.err(e),""}}))}},5:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Log=void 0,t.Log=class{constructor(e){this.config=e}log(...e){this.config.get("debug")&&console.log("[MagicFeedback]:",...e)}err(...e){console.error("[MagicFeedback]:",...e)}}},147:e=>{"use strict";e.exports=JSON.parse('{"name":"@magicfeedback/native","version":"1.3.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","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","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"}}')}},t={},function i(n){var s=t[n];if(void 0!==s)return s.exports;var a=t[n]={exports:{}};return e[n].call(a.exports,a,a.exports,i),a.exports}(607).default;var e,t}));
|
|
1
|
+
!function(e,t){"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()}(self,(()=>{return e={98:function(e,t){var i="undefined"!=typeof self?self:this,n=function(){function e(){this.fetch=!1,this.DOMException=i.DOMException}return e.prototype=i,new e}();!function(e){!function(t){var i="URLSearchParams"in e,n="Symbol"in e&&"iterator"in Symbol,s="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),a="FormData"in e,o="ArrayBuffer"in e;if(o)var r=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],d=ArrayBuffer.isView||function(e){return e&&r.indexOf(Object.prototype.toString.call(e))>-1};function c(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function l(e){return"string"!=typeof e&&(e=String(e)),e}function u(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return n&&(t[Symbol.iterator]=function(){return t}),t}function p(e){this.map={},e instanceof p?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function h(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function m(e){return new Promise((function(t,i){e.onload=function(){t(e.result)},e.onerror=function(){i(e.error)}}))}function f(e){var t=new FileReader,i=m(t);return t.readAsArrayBuffer(e),i}function g(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function y(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:s&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:a&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:i&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():o&&s&&(t=e)&&DataView.prototype.isPrototypeOf(t)?(this._bodyArrayBuffer=g(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):o&&(ArrayBuffer.prototype.isPrototypeOf(e)||d(e))?this._bodyArrayBuffer=g(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):i&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},s&&(this.blob=function(){var e=h(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?h(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(f)}),this.text=function(){var e,t,i,n=h(this);if(n)return n;if(this._bodyBlob)return e=this._bodyBlob,i=m(t=new FileReader),t.readAsText(e),i;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),i=new Array(t.length),n=0;n<t.length;n++)i[n]=String.fromCharCode(t[n]);return i.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},a&&(this.formData=function(){return this.text().then(E)}),this.json=function(){return this.text().then(JSON.parse)},this}p.prototype.append=function(e,t){e=c(e),t=l(t);var i=this.map[e];this.map[e]=i?i+", "+t:t},p.prototype.delete=function(e){delete this.map[c(e)]},p.prototype.get=function(e){return e=c(e),this.has(e)?this.map[e]:null},p.prototype.has=function(e){return this.map.hasOwnProperty(c(e))},p.prototype.set=function(e,t){this.map[c(e)]=l(t)},p.prototype.forEach=function(e,t){for(var i in this.map)this.map.hasOwnProperty(i)&&e.call(t,this.map[i],i,this)},p.prototype.keys=function(){var e=[];return this.forEach((function(t,i){e.push(i)})),u(e)},p.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),u(e)},p.prototype.entries=function(){var e=[];return this.forEach((function(t,i){e.push([i,t])})),u(e)},n&&(p.prototype[Symbol.iterator]=p.prototype.entries);var v=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function b(e,t){var i,n,s=(t=t||{}).body;if(e instanceof b){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new p(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,s||null==e._bodyInit||(s=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new p(t.headers)),this.method=(n=(i=t.method||this.method||"GET").toUpperCase(),v.indexOf(n)>-1?n:i),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&s)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(s)}function E(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var i=e.split("="),n=i.shift().replace(/\+/g," "),s=i.join("=").replace(/\+/g," ");t.append(decodeURIComponent(n),decodeURIComponent(s))}})),t}function k(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new p(t.headers),this.url=t.url||"",this._initBody(e)}b.prototype.clone=function(){return new b(this,{body:this._bodyInit})},y.call(b.prototype),y.call(k.prototype),k.prototype.clone=function(){return new k(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new p(this.headers),url:this.url})},k.error=function(){var e=new k(null,{status:0,statusText:""});return e.type="error",e};var C=[301,302,303,307,308];k.redirect=function(e,t){if(-1===C.indexOf(t))throw new RangeError("Invalid status code");return new k(null,{status:t,headers:{location:e}})},t.DOMException=e.DOMException;try{new t.DOMException}catch(e){t.DOMException=function(e,t){this.message=e,this.name=t;var i=Error(e);this.stack=i.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function w(e,i){return new Promise((function(n,a){var o=new b(e,i);if(o.signal&&o.signal.aborted)return a(new t.DOMException("Aborted","AbortError"));var r=new XMLHttpRequest;function d(){r.abort()}r.onload=function(){var e,t,i={status:r.status,statusText:r.statusText,headers:(e=r.getAllResponseHeaders()||"",t=new p,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(e){var i=e.split(":"),n=i.shift().trim();if(n){var s=i.join(":").trim();t.append(n,s)}})),t)};i.url="responseURL"in r?r.responseURL:i.headers.get("X-Request-URL");var s="response"in r?r.response:r.responseText;n(new k(s,i))},r.onerror=function(){a(new TypeError("Network request failed"))},r.ontimeout=function(){a(new TypeError("Network request failed"))},r.onabort=function(){a(new t.DOMException("Aborted","AbortError"))},r.open(o.method,o.url,!0),"include"===o.credentials?r.withCredentials=!0:"omit"===o.credentials&&(r.withCredentials=!1),"responseType"in r&&s&&(r.responseType="blob"),o.headers.forEach((function(e,t){r.setRequestHeader(t,e)})),o.signal&&(o.signal.addEventListener("abort",d),r.onreadystatechange=function(){4===r.readyState&&o.signal.removeEventListener("abort",d)}),r.send(void 0===o._bodyInit?null:o._bodyInit)}))}w.polyfill=!0,e.fetch||(e.fetch=w,e.Headers=p,e.Request=b,e.Response=k),t.Headers=p,t.Request=b,t.Response=k,t.fetch=w,Object.defineProperty(t,"__esModule",{value:!0})}({})}(n),n.fetch.ponyfill=!0,delete n.fetch.polyfill;var s=n;(t=s.fetch).default=s.fetch,t.fetch=s.fetch,t.Headers=s.Headers,t.Request=s.Request,t.Response=s.Response,e.exports=t},290:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.HOST_API_URL_DEV=t.HOST_API_URL=void 0,t.HOST_API_URL="https://api.magicfeedback.io/",t.HOST_API_URL_DEV="https://api-dev.magicfeedback.io/"},607:function(e,t,i){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=n(i(519));let a=null;a||(a=(0,s.default)()),t.default=a},519:function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,a){function o(e){try{d(n.next(e))}catch(e){a(e)}}function r(e){try{d(n.throw(e))}catch(e){a(e)}}function d(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}d((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(954),a=i(712),o=i(5),r=i(341),d=i(290);t.default=function(){const e=new a.Config;let t;return{init:function(i){(null==i?void 0:i.debug)&&e.set("debug",null==i?void 0:i.debug),e.set("url",(null==i?void 0:i.env)&&"dev"===(null==i?void 0:i.env)?d.HOST_API_URL_DEV:d.HOST_API_URL),t=new o.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,s,a,o=!0,d,c){return n(this,void 0,void 0,(function*(){i||t.err("No appID provided"),s||t.err("No publicKey provided"),a||t.err("No feedback provided"),a.answers||a.profile||a.metrics||a.metadata||t.err("No feedback data provided");const n=e.get("url"),l={integration:i,publicKey:s,privateKey:c,completed:o,id:d,feedback:a};try{const e=yield(0,r.sendFeedback)(n,l,t);return t.log("sent native feedback"),e}catch(e){return t.err("error native feedback",e),!1}}))},form:function(i,n){return i||t.err("No appID provided"),n||t.err("No publicKey provided"),new s.Form(e,i,n)},session:function(i){return i||t.err("No sessionId provided"),new s.Form(e,i)}}}},314:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.History=void 0,t.History=class{constructor(){this.items=[]}enqueue(e){this.items.push(e)}dequeue(){return this.items.shift()}rollback(){return this.items.pop()}front(){return this.items[0]}back(){return this.items[this.items.length-1]}isEmpty(){return 0===this.items.length}size(){return this.items.length}}},712:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Config=void 0,t.Config=class{constructor(){this.variables={},this.variables.env="prod",this.variables.debug=!1}get(e){return this.variables[e]}set(e,t){this.variables[e]=t}}},954:function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,a){function o(e){try{d(n.next(e))}catch(e){a(e)}}function r(e){try{d(n.throw(e))}catch(e){a(e)}}function d(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}d((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const s=i(5),a=i(341),o=i(183),r=i(24),d=i(804),c=i(116),l=i(314),u=i(457);t.Form=class{constructor(e,t,i){this.config=e,this.log=new s.Log(e),this.formOptionsConfig={addButton:!0,sendButtonText:"Send",backButtonText:"Back",nextButtonText:"Next",addSuccessScreen:!0,getMetaData:!0,questionFormat:"standard"},this.selector="",this.appId=t,this.publicKey=i||"",this.url=e.get("url"),this.id="",this.formData=null,""!==this.publicKey&&this.getDataFromStorage(),this.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.history=new l.History,this.graph=new r.PageGraph([]),this.progress=0,this.total=0,this.completed=!1}getDataFromStorage(){const e=localStorage.getItem(`magicfeedback-${this.appId}`);e&&new Date(JSON.parse(e).savedAt)<new Date((new Date).getTime()+864e5)&&(this.formData=JSON.parse(e),(0,a.getForm)(this.url,this.appId,this.publicKey,this.log).then((e=>{var t,i,n,s,a;if((null==e?void 0:e.updatedAt)&&(null===(t=this.formData)||void 0===t?void 0:t.savedAt)&&(null==e?void 0:e.updatedAt)>(null===(i=this.formData)||void 0===i?void 0:i.savedAt)){if(this.formData=e,this.formData.savedAt=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}`);this.formData.pages&&0!==(null===(n=this.formData.pages)||void 0===n?void 0:n.length)||this.formatPages(),null===(s=this.formData.questions)||void 0===s||s.sort(((e,t)=>e.position-t.position)),this.formData.pages=this.formData.pages.filter((e=>{var t;return(null===(t=e.integrationQuestions)||void 0===t?void 0:t.length)>0})),(null===(a=this.formData.style)||void 0===a?void 0:a.startMessage)?this.generateWelcomeMessage(this.formData.style.startMessage):this.startForm()}})))}generate(e,t){var i,s,o;return n(this,void 0,void 0,(function*(){try{if(this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e,void 0!==this.formData&&this.formData||(this.formData=""!==this.publicKey?yield(0,a.getForm)(this.url,this.appId,this.publicKey,this.log):yield(0,a.getSessionForm)(this.url,this.appId,this.log)),void 0===this.formData||!this.formData)throw new Error(`No form for app ${this.appId}`);if(this.formData.savedAt||(this.formData.savedAt=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}`);this.formData.pages&&0!==(null===(i=this.formData.pages)||void 0===i?void 0:i.length)||this.formatPages(),null===(s=this.formData.questions)||void 0===s||s.sort(((e,t)=>e.position-t.position)),this.formData.pages=this.formData.pages.filter((e=>{var t;return(null===(t=e.integrationQuestions)||void 0===t?void 0:t.length)>0})),this.formOptionsConfig.getMetaData&&this.getMetaData(),(null===(o=this.formData.style)||void 0===o?void 0:o.startMessage)?yield this.generateWelcomeMessage(this.formData.style.startMessage):this.startForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}formatPages(){var e;if(this.formData)switch(this.formData.identity){case"MAGICSURVEY":this.formData.pages=[],null===(e=this.formData.questions)||void 0===e||e.forEach((e=>{var t,i;const n=new c.PageRoute(e.id,e.ref,c.OperatorType.NOEQUAL,null,c.TransitionType.PAGE,(e.position+1).toString(),e.position.toString()),s=new d.Page(e.position.toString(),e.position,this.appId,[e],[n]);null===(i=null===(t=this.formData)||void 0===t?void 0:t.pages)||void 0===i||i.push(s)}));break;case"MAGICFORM":const t=new d.Page("1",1,this.appId,this.formData.questions,[]);this.formData.pages=[t]}}generateContainer(){let e=document.getElementById(this.selector);if(!e&&(e=document.getElementById("magicfeedback-container-"+this.appId),!e))throw new Error(`Element with ID '${this.selector}' not found.`);return e.classList.add("magicfeedback-container"),e.id="magicfeedback-container-"+this.appId,e.innerHTML="",e}generateForm(){var e,t,i,s;return n(this,void 0,void 0,(function*(){try{if(!this.formData||!this.formData.pages||0===this.formData.pages.length)throw new Error("No form data");this.graph=new r.PageGraph(this.formData.pages.sort(((e,t)=>e.position-t.position)));let n=this.generateContainer();const a=document.createElement("form");a.classList.add("magicfeedback-form"),a.id="magicfeedback-"+this.appId;const d=document.createElement("div");d.classList.add("magicfeedback-questions"),d.id="magicfeedback-questions-"+this.appId;const c=this.graph.getFirstPage();if(!c)throw new Error("No page found");if(this.total=this.graph.findMaxDepth(),c.elements=(0,o.renderQuestions)(c.questions,this.formOptionsConfig.questionFormat,null===(e=this.formData)||void 0===e?void 0:e.lang[0],null===(t=this.formData)||void 0===t?void 0:t.product,(()=>this.send())),null===(i=c.elements)||void 0===i||i.forEach((e=>d.appendChild(e))),a.appendChild(d),this.history.enqueue(c),n.appendChild(a),this.progress=this.history.size(),this.formOptionsConfig.addButton){const e=(0,o.renderActions)(null===(s=this.formData)||void 0===s?void 0:s.identity,(()=>this.back()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);a.appendChild(e)}this.formOptionsConfig.addButton&&a.addEventListener("submit",(e=>{e.preventDefault(),this.send()})),this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}))}startForm(){this.generateForm()}generateWelcomeMessage(e){return n(this,void 0,void 0,(function*(){try{const t=this.generateContainer(),i=(0,o.renderStartMessage)(e,this.formOptionsConfig.addButton,this.formOptionsConfig.startButtonText,(()=>this.startForm()));t.appendChild(i),this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,formData:this.formData}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}))}getMetaData(){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]})}send(e,t,i){return n(this,void 0,void 0,(function*(){const n=document.getElementById("magicfeedback-questions-"+this.appId);try{i&&(this.feedback.profile=[...this.feedback.profile,...i]),t&&(this.feedback.metrics=[...this.feedback.metrics,...t]),e&&(this.feedback.metadata=[...this.feedback.metadata,...e]),this.answer(),this.formOptionsConfig.beforeSubmitEvent&&(yield this.formOptionsConfig.beforeSubmitEvent({loading:!0,progress:this.progress,total:this.total}));const s=this.history.back();if(!s)throw new Error("No page found");const a=s.getRequiredQuestions();for(const e of a)if(!this.feedback.answers.find((t=>t.key===e&&t.value.length>0)))throw this.log.err(`The question ${e} is required`),new Error("No response");const o=yield this.pushAnswers(!1);if(!o)throw new Error("No response");this.id=o,yield this.processNextQuestion(n)}catch(e){this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({loading:!1,progress:this.progress,total:this.total,error:e}))}}))}answer(){const e=document.getElementById("magicfeedback-"+this.appId);if(!e)return this.log.err(`Form "${e}" not found.`),void(this.feedback.answers=[]);if(!this.history.back())throw new Error("No page found");const t=[];let i=!1;e.querySelectorAll(".magicfeedback-input").forEach((e=>{const n=e.type,s=e.classList[0],o={key:e.name,value:[]},r="magicfeedback-consent"===s?e.checked.toString():e.value;if(o.key&&""!==o.key)switch(n){case"radio":case"checkbox":if("magicfeedback-consent"===s||e.checked){o.value.push(r);const e=t.findIndex((e=>e.key===o.key));-1!==e?t[e].value=[...t[e].value,...o.value]:t.push(o)}break;default:if(""!==r){if("email"===n){if(!(0,a.validateEmail)(r)){this.log.err("Invalid email"),i=!0;break}this.feedback.profile.push({key:"email",value:[r]})}if(e.id.includes("point-system")){const t="point-system-"+e.id.split("-")[e.id.split("-").length-1];o.value.push(`${t}: ${r}%`)}else o.value.push(r);const s=t.findIndex((e=>e.key===o.key));-1!==s?t[s].value=[...t[s].value,...o.value]:t.push(o)}}}));const n=t.filter((e=>e.key.includes("matrix")));null==n||n.forEach((e=>{const i=t.find((t=>t.key===e.key));i&&(i.value=[...new Set(i.value)])}));const s=t.filter((e=>e.key.includes("point-system")));null==s||s.forEach((e=>{100!==e.value.reduce(((e,t)=>{const i=t.split(": ")[1];return e+Number(i.replace("%",""))}),0)&&(this.log.err("The sum of the point system questions must be 100%"),i=!0)})),this.feedback.answers=i?[]:t}finish(){return n(this,void 0,void 0,(function*(){if(this.completed=!0,this.formOptionsConfig.addSuccessScreen){const e=document.getElementById("magicfeedback-container-"+this.appId);e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,o.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}this.answer();const e=yield this.pushAnswers(!0);if(!e)throw new Error("No response");this.id=e,this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:this.id,loading:!1,progress:this.progress,total:this.total,completed:this.completed,error:null}))}))}pushAnswers(e=!1){return n(this,void 0,void 0,(function*(){try{const t=this.config.get("url"),i={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,a.sendFeedback)(t,this.id?Object.assign(Object.assign({},i),{sessionId:this.id}):i,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){var t;return n(this,void 0,void 0,(function*(){if(!(null==e?void 0:e.followup))return null;try{if(0===this.feedback.answers.length)throw new Error("No answers provided");const i=this.config.get("url"),n={answer:null===(t=this.feedback.answers.find((t=>t.key===e.ref)))||void 0===t?void 0:t.value[0],publicKey:this.publicKey,sessionId:this.id,question:e};return yield(0,a.getFollowUpQuestion)(i,n,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e){var t,i,s;return n(this,void 0,void 0,(function*(){const n=this.history.back();if(!n)throw new Error("No page found");const a=n.getFollowupQuestions();if(0===(null==a?void 0:a.length))return void(yield this.renderNextQuestion(e,n));const r=[];for(const e of a){const t=n.questions.find((t=>t.ref===e));if(t){const e=yield this.callFollowUpQuestion(t);e&&r.push(e)}}if(0===r.length)return void(yield this.renderNextQuestion(e,n));const c=new d.Page(n.id,n.position,this.appId,r,n.edges),l=new u.PageNode(n.id,n.position,n.edges,c,r,!0);l.elements=(0,o.renderQuestions)(r,this.formOptionsConfig.questionFormat,null===(t=this.formData)||void 0===t?void 0:t.lang[0],null===(i=this.formData)||void 0===i?void 0:i.product,(()=>this.send())),this.history.enqueue(l),this.progress=this.history.size(),e.removeChild(e.childNodes[0]),null===(s=l.elements)||void 0===s||s.forEach((t=>e.appendChild(t))),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:this.id,loading:!1,progress:this.progress,total:this.total,followup:l.isFollowup,completed:this.completed,error:null}))}))}renderNextQuestion(e,t){var i,s,a;return n(this,void 0,void 0,(function*(){console.log(t,this.feedback.answers);const n=this.graph.getNextPage(t,this.feedback.answers);console.log(n),n?(n.elements=(0,o.renderQuestions)(n.questions,this.formOptionsConfig.questionFormat,null===(i=this.formData)||void 0===i?void 0:i.lang[0],null===(s=this.formData)||void 0===s?void 0:s.product,(()=>this.send())),e.removeChild(e.childNodes[0]),null===(a=n.elements)||void 0===a||a.forEach((t=>e.appendChild(t))),this.history.enqueue(n),this.progress=this.history.size(),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:this.id,loading:!1,progress:this.progress,total:this.total,followup:n.isFollowup,completed:this.completed,error:null}))):this.finish()}))}back(){var e;return n(this,void 0,void 0,(function*(){if(0===this.history.size())return;const t=document.getElementById("magicfeedback-questions-"+this.appId);t&&t.childNodes.length>0&&t.removeChild(t.childNodes[0]),this.history.rollback(),this.progress=this.history.size();const i=this.history.back();i&&(null===(e=i.elements)||void 0===e||e.forEach((e=>t.appendChild(e)))),this.formOptionsConfig.onBackEvent&&(yield this.formOptionsConfig.onBackEvent({loading:!1,progress:this.progress,followup:(null==i?void 0:i.isFollowup)||!1,error:i?null:"No page found"}))}))}}},804:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Page=void 0,t.Page=class{constructor(e,t,i,n,s){this.id=e,this.position=t,this.generatedAt=(new Date).toISOString(),this.updatedAt=(new Date).toISOString(),this.status="ACTIVE",this.integrationId=i,this.integrationQuestions=n,this.integrationPageRoutes=s}}},24:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.PageGraph=void 0;const n=i(457),s=i(116);t.PageGraph=class{constructor(e){this.nodes=new Map,this.buildGraph(e)}buildGraph(e){e.forEach(((t,i)=>{var a,o;if(!t.integrationPageRoutes&&e[i+1]){const n=new s.PageRoute(`${t.id}-default`,(null===(a=t.integrationQuestions[0])||void 0===a?void 0:a.ref)||"",s.OperatorType.DEFAULT,"",s.TransitionType.PAGE,(null===(o=e[i+1])||void 0===o?void 0:o.id)||"",t.id);t.integrationPageRoutes=[n]}const r=new n.PageNode(t.id,t.position,t.integrationPageRoutes||[],t,t.integrationQuestions);this.nodes.set(r.id,r)}))}getNodeById(e){return this.nodes.get(e)}getNextEdgeByDefault(e){if(e)for(const t of this.nodes.values())if(t.position===e.position+1)return t.id}getFirstPage(){let e,t=Number.MAX_VALUE;for(const i of this.nodes.values())i.position<t&&(t=i.position,e=i);return e}getNextPage(e,t){if(!e)return;e.edges.sort(((e,t)=>"DIRECT"===e.typeCondition?1:"DIRECT"===t.typeCondition?-1:0));const i=e.edges.find((e=>{const i=null==t?void 0:t.filter((t=>t.key===e.questionRef));if(!i)return!1;if("DIRECT"===e.typeCondition)return!0;switch(e.typeOperator){case s.OperatorType.EQUAL:return i.find((t=>{var i;return null===(i=t.value)||void 0===i?void 0:i.includes(e.value)}));case s.OperatorType.NOEQUAL:return!i.find((t=>{var i;return null===(i=t.value)||void 0===i?void 0:i.includes(e.value)}));case s.OperatorType.GREATER:return i.find((t=>t.value.find((t=>Number(t)>Number(e.value)))));case s.OperatorType.LESS:return i.find((t=>t.value.find((t=>Number(t)<Number(e.value)))));case s.OperatorType.GREATEREQUAL:return i.find((t=>t.value.find((t=>Number(t)>=Number(e.value)))));case s.OperatorType.LESSEQUAL:return i.find((t=>t.value.find((t=>Number(t)<=Number(e.value)))));case s.OperatorType.INQ:return i.find((t=>e.value.includes(t.value)));case s.OperatorType.NINQ:return!i.find((t=>e.value.includes(t.value)));default:return!1}}));if(!i){const t=this.getNextEdgeByDefault(e);if(!t)return;return this.getNodeById(t)}switch(i.transition){case s.TransitionType.PAGE:return this.getNodeById(i.transitionDestiny);case s.TransitionType.FINISH:return;case s.TransitionType.REDIRECT:return void(window.location.href=i.transitionDestiny);default:return}}findDepth(e){const t=this.getNodeById(e);if(!t)return 0;const i=new Set;return this.DFSUtil(t,i,0)}findMaxDepth(e){if(e||(e=this.getFirstPage()),!e)return 0;const t=new Set;let i=e.questions.find((e=>e.followup))?2:1;return i=Math.max(i,this.DFSUtil(e,t,i)),i}DFSUtil(e,t,i){t.add(e);let n=i;const s=e.edges||[];for(const e of s){const s=this.getNodeById(e.transitionDestiny);if(s&&!t.has(s)){const e=s.questions.find((e=>e.followup))?i+2:i+1,a=this.DFSUtil(s,t,e);n=Math.max(n,a)}}return n}}},457:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.PageNode=void 0,t.PageNode=class{constructor(e,t,i,n,s,a=!1){this.id=e,this.position=t,this.edges=i,this.data=n,this.questions=s,this.elements=[],this.isFollowup=a}getFollowupQuestions(){return this.questions.filter((e=>e.followup)).map((e=>e.ref))}getRequiredQuestions(){return this.questions.filter((e=>e.require)).map((e=>e.ref))}}},116:(e,t)=>{"use strict";var i,n,s,a;Object.defineProperty(t,"__esModule",{value:!0}),t.PageRoute=t.StatusType=t.OperatorType=t.ConditionType=t.TransitionType=void 0,(a=t.TransitionType||(t.TransitionType={})).PAGE="PAGE",a.FINISH="FINISH",a.REDIRECT="REDIRECT",function(e){e.LOGICAL="LOGICAL",e.DIRECT="DIRECT"}(i=t.ConditionType||(t.ConditionType={})),(s=t.OperatorType||(t.OperatorType={})).EQUAL="EQUAL",s.NOEQUAL="NOEQUAL",s.GREATER="GREATER",s.LESS="LESS",s.GREATEREQUAL="GREATEREQUAL",s.LESSEQUAL="LESSEQUAL",s.INQ="INQ",s.NINQ="NINQ",s.DEFAULT="DEFAULT",function(e){e.ACTIVE="ACTIVE",e.DEPRECATED="DEPRECATED",e.DELETE="DELETE"}(n=t.StatusType||(t.StatusType={})),t.PageRoute=class{constructor(e,t,s,a,o,r,d,c){this.id=e,this.questionRef=t,this.typeCondition=c||i.LOGICAL,this.typeOperator=s,this.value=a,this.transition=o,this.transitionDestiny=r,this.status=n.ACTIVE,this.generatedAt=new Date,this.updatedAt=new Date,this.integrationPageId=d}}},244:(e,t)=>{"use strict";var i,n;Object.defineProperty(t,"__esModule",{value:!0}),t.QuestionType=t.FEEDBACKAPPANSWERTYPE=void 0,(n=t.FEEDBACKAPPANSWERTYPE||(t.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",t.QuestionType=class{},function(e){e.FORM="form",e.DIV="div"}(i||(i={}))},374:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.endpoints=void 0,t.endpoints={sdk:{app:(e,t)=>`sdk/app/${e}/${t}`,app_info:(e,t)=>`sdk/app/${e}/${t}/info`,session:e=>`sdk/app/session/${e}/info`,feedback:"sdk/feedback",followUpQuestion:"sdk/followUpQuestion"}}},528:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.placeholder=void 0,t.placeholder={answer:e=>{switch(e){case"en":default:return"Write your answer here...";case"es":return"Escribe tu respuesta aquí...";case"da":return"Skriv dit svar her...";case"fi":return"Kirjoita vastauksesi tähän...";case"sv":return"Skriv ditt svar här...";case"no":return"Skriv svaret ditt her...";case"ar":return"اكتب إجابتك هنا...";case"bn":return"এখানে আপনার"}},number:e=>{switch(e){case"en":default:return"Write your number here...";case"es":return"Escribe tu número aquí...";case"da":return"Skriv dit nummer her...";case"fi":return"Kirjoita numerosi tähän...";case"sv":return"Skriv ditt nummer här...";case"no":return"Skriv nummeret ditt her...";case"ar":return"اكتب رقمك هنا...";case"bn":return"এখানে আপনার"}},email:e=>{switch(e){case"en":default:return"Write your email here...";case"es":return"Escribe tu correo electrónico aquí...";case"da":return"Skriv din e-mail her...";case"fi":return"Kirjoita sähköpostiosoitteesi tähän...";case"sv":return"Skriv din e-post här...";case"no":return"Skriv e-posten din her...";case"ar":return"اكتب بريدك الإلكتروني هنا...";case"bn":return"এখানে আপনার"}},date:e=>{switch(e){case"en":default:return"Write your date here...";case"es":return"Escribe tu fecha aquí...";case"da":return"Skriv din dato her...";case"fi":return"Kirjoita päivämääräsi tähän...";case"sv":return"Skriv ditt datum här...";case"no":return"Skriv datoen din her...";case"ar":return"اكتب تاريخك هنا...";case"bn":return"এখানে আপনার"}},password:e=>{switch(e){case"en":default:return"Write your password here...";case"es":return"Escribe tu contraseña aquí...";case"da":return"Skriv dit kodeord her...";case"fi":return"Kirjoita salasanasi tähän...";case"sv":return"Skriv ditt lösenord här...";case"no":return"Skriv passordet ditt her...";case"ar":return"اكتب كلمة المرور الخاصة بك هنا...";case"bn":return"এখানে আপনার"}},pointsystemerror:e=>{switch(e){case"en":default:return"The total points must be 100 %";case"es":return"El total de puntos debe ser 100 %";case"da":return"Samlet antal point skal være 100 %";case"fi":return"Kokonaispisteiden on oltava 100 %";case"sv":return"Totala poäng måste vara 100 %";case"no":return"Totalt antall poeng må være 100 %";case"ar":return"يجب أن تكون النقاط الإجمالية 100 %";case"bn":return"মোট পয়েন্ট 100 % হতে হবে"}}}},183:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.renderStartMessage=t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0;const n=i(244),s=i(528),a="https://survey-dev.magicfeedback.io/assets/emojis";function o(e,t){return e?"object"==typeof e?e[t]||e.en:e:""}function r(e,t,i,n,s,a=!0){const o=document.createElement("div");o.classList.add("magicfeedback-rating-placeholder"),o.style.display="flex",o.style.justifyContent="space-between",o.style.width=s?`calc(100% - (100% / ${t+1}))`:"100%",o.style.marginRight="auto",a&&window.innerWidth<600&&(o.style.flexDirection="column");const r=document.createElement("span");r.textContent=i,r.classList.add("magicfeedback-rating-placeholder-value"),r.style.fontSize="15px",r.style.textAlign="left",r.style.width="50%",a&&window.innerWidth<600&&(r.textContent=`${e} ➜ ${i}`,r.style.width="100%",r.style.textAlign="left",r.style.marginBottom="5px"),o.appendChild(r);const d=document.createElement("span");return d.textContent=n,d.classList.add("magicfeedback-rating-placeholder-value"),d.style.fontSize="15px",d.style.textAlign="right",d.style.width="50%",a&&window.innerWidth<600&&(d.textContent=`${t} ➜ ${n}`,d.style.width="100%",d.style.textAlign="left",d.style.marginBottom="5px"),o.appendChild(d),o}t.renderQuestions=function e(t,i="standard",d="en",c={customIcons:!1},l){if(!t)throw new Error("[MagicFeedback] No questions provided");const u=[],{customIcons:p,id:h}=c;return t.forEach((t=>{var m,f;if((null===(f=null===(m=null==t?void 0:t.questionType)||void 0===m?void 0:m.conf)||void 0===f?void 0:f.length)>0){let n=document.createElement("div");n.classList.add("magicfeedback-div");const s=document.createElement("label");s.setAttribute("for",`magicfeedback-${t.id}`),s.textContent=o(t.title,d),s.classList.add("magicfeedback-label"),n.appendChild(s),t.questionType.conf.forEach((e=>{e.ref=t.ref,t.assets[e.id]&&(e.assets={placeholder:t.assets[e.id]})})),e(t.questionType.conf,i,d,c,l).forEach((e=>{n.appendChild(e)})),u.push(n)}else{const e=function(e,t,i,d,c){let l,u,{id:p,title:h,type:m,ref:f,require:g,value:y,defaultValue:v,assets:b}=e,E=document.createElement("div");E.classList.add("magicfeedback-div");const k="slim"===t?o(h,i):null==b?void 0:b.placeholder,C=(T=p,new URLSearchParams(window.location.search).get(T)),w=(null==b?void 0:b.maxCharacters)||0,x=void 0!==(null==b?void 0:b.randomPosition)&&(null==b?void 0:b.randomPosition);var T;switch(m){case n.FEEDBACKAPPANSWERTYPE.TEXT:l=document.createElement("input"),l.type="text",l.placeholder=k||s.placeholder.answer(i||"en"),u="magicfeedback-text";break;case n.FEEDBACKAPPANSWERTYPE.LONGTEXT:l=document.createElement("textarea"),l.rows=3,w>0&&(l.maxLength=w),l.placeholder=k||s.placeholder.answer(i||"en"),u="magicfeedback-longtext";break;case n.FEEDBACKAPPANSWERTYPE.NUMBER:l=document.createElement("input"),l.type="number",l.placeholder="slim"===t?o(h,i):s.placeholder.number(i||"en"),u="magicfeedback-number",y.length&&(y.sort(((e,t)=>Number(e)-Number(t))),l.max=y[y.length-1],l.min=y[0],l.value=y[0]);break;case n.FEEDBACKAPPANSWERTYPE.RADIO:case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:l=document.createElement("div"),u="magicfeedback-"+("MULTIPLECHOICE"===m?"checkbox":"radio"),(null==b?void 0:b.extraOption)&&!y.includes(null==b?void 0:b.extraOptionText)&&y.push(null==b?void 0:b.extraOptionText),x&&(y=y.sort((()=>Math.random()-.5))),y.forEach(((e,t)=>{const a=document.createElement("div");a.classList.add(`magicfeedback-${"MULTIPLECHOICE"===m?"checkbox":"radio"}-container`);const o=document.createElement("label"),r=document.createElement("input");if(r.id=`rating-${f}-${t}`,r.type="MULTIPLECHOICE"===m?"checkbox":"radio",r.name=f,r.value=e,r.classList.add(u),r.classList.add("magicfeedback-input"),m===n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE&&(null==b?void 0:b.maxOptions)&&(null==b?void 0:b.maxOptions)>0&&r.addEventListener("change",(()=>{document.querySelectorAll(`input[name="${f}"]:checked`).length>(null==b?void 0:b.maxOptions)&&(r.checked=!1)})),e!==v&&e!==C||(r.checked=!0),o.textContent=e,o.htmlFor=`rating-${f}-${t}`,r.addEventListener("change",(t=>{const i=document.getElementById(`extra-option-${f}`);i&&(null==b?void 0:b.extraOption)&&(t.target.checked&&e===(null==b?void 0:b.extraOptionText)?(y.forEach(((e,t)=>{e!==(null==b?void 0:b.extraOptionText)&&(document.getElementById(`rating-${f}-${t}`).checked=!1)})),i.style.display="block"):(document.getElementById(`rating-${f}-${y.length-1}`).checked=!1,i.style.display="none"))})),a.appendChild(r),a.appendChild(o),l.appendChild(a),(null==b?void 0:b.extraOption)&&e===(null==b?void 0:b.extraOptionText)){const e=document.createElement("input");e.type="text",e.placeholder=(null==b?void 0:b.extraOptionPlaceholder)||s.placeholder.answer(i||"en"),e.classList.add("magicfeedback-extra-option"),e.classList.add("magicfeedback-input"),e.id=`extra-option-${f}`,e.name=`extra-option-${f}`,e.style.display="none",l.appendChild(e)}}));break;case n.FEEDBACKAPPANSWERTYPE.BOOLEAN:l=document.createElement("div"),u="magicfeedback-radio";const S=document.createElement("div");S.classList.add("magicfeedback-boolean-container"),S.style.display="flex",S.style.flexDirection="row",S.style.justifyContent="space-between",S.style.width="70%",S.style.margin="auto",((null==b?void 0:b.addIcon)?["👍","👎"]:function(e){switch(e){case"es":return["Sí","No"];case"fr":return["Oui","Non"];case"de":return["Ja","Nein"];case"it":return["Sì","No"];case"pt":return["Sim","Não"];case"nl":return["Ja","Nee"];case"pl":return["Tak","Nie"];case"ru":return["Да","Нет"];case"ja":return["はい","いいえ"];case"zh":return["是","不"];case"ko":return["예","아니"];case"da":case"sv":return["Ja","Nej"];case"fi":return["Kyllä","Ei"];case"no":return["Ja","Nei"];case"ar":return["نعم","لا"];case"bn":return["হ্যাঁ","না"];default:return["Yes","No"]}}(i)).forEach(((e,t)=>{const i=document.createElement("label");i.classList.add("magicfeedback-boolean-option"),i.htmlFor=`rating-${f}-${t}`,i.style.cursor="pointer",i.style.border="1px solid #000",i.style.display="flex",i.style.justifyContent="center",i.style.alignItems="center",i.style.margin="auto",i.style.padding="0",i.style.width="45%",i.style.height="38px";const n=document.createElement("label");n.htmlFor=`rating-${f}-${t}`,n.textContent=e,n.style.margin="0",n.style.padding="0";const s=document.createElement("input");s.id=`rating-${f}-${t}`,s.type="radio",s.name=f,s.value=e,s.classList.add(u),s.classList.add("magicfeedback-input"),s.style.position="absolute",s.style.opacity="0",s.style.width="0",s.style.height="0",s.style.margin="0",s.addEventListener("change",(()=>{c&&c()})),i.appendChild(s),i.appendChild(n),S.appendChild(i)})),l.appendChild(S);break;case n.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:l=document.createElement("div"),u="magicfeedback-rating";const O=document.createElement("div");O.classList.add("magicfeedback-rating-container");const P=(null==b?void 0:b.max)?Number(null==b?void 0:b.max):5,I=(null==b?void 0:b.min)?Number(null==b?void 0:b.min):1,N=r(I,P,null==b?void 0:b.minPlaceholder,null==b?void 0:b.maxPlaceholder,null==b?void 0:b.extraOption);for(let de=I;de<=P;de++){const ce=document.createElement("div");ce.classList.add("magicfeedback-rating-option");const le=document.createElement("label");le.htmlFor=`rating-${f}-${de}`,le.classList.add("magicfeedback-rating-option-label-container");const ue=document.createElement("label");ue.htmlFor=`rating-${f}-${de}`,ue.textContent=de.toString();const pe=document.createElement("img");if(pe.alt=`face-${f}-${de}`,pe.className=`rating-image${de}`,0===I&&10===P)pe.src=`${d}/${de}.svg`,pe.onerror=()=>pe.src=`${a}/${de}.svg`;else if(1===I&&5===P)switch(de){case 1:pe.src=`${d}/1.svg`,pe.onerror=()=>pe.src=`${a}/1.svg`;break;case 2:pe.src=`${d}/2.svg`,pe.onerror=()=>pe.src=`${a}/2.svg`;break;case 3:pe.src=`${d}/6.svg`,pe.onerror=()=>pe.src=`${a}/6.svg`;break;case 4:pe.src=`${d}/9.svg`,pe.onerror=()=>pe.src=`${a}/9.svg`;break;case 5:pe.src=`${d}/10.svg`,pe.onerror=()=>pe.src=`${a}/10.svg`}else{const me=Math.round(10/(P-I)*(de-I));pe.src=`${d}/${me}.svg`,pe.onerror=()=>pe.src=`${a}/${me}.svg`}const he=document.createElement("input");he.id=`rating-${f}-${de}`,he.type="radio",he.name=f,he.value=de.toString(),he.classList.add(u),he.classList.add("magicfeedback-input"),le.appendChild(he),le.appendChild(pe),le.appendChild(ue),ce.appendChild(le),O.appendChild(ce)}if((null==b?void 0:b.extraOption)&&(null==b?void 0:b.extraOptionText)){const fe=document.createElement("div");fe.classList.add("magicfeedback-rating-option");const ge=document.createElement("label");ge.htmlFor=`rating-${f}-extra`,ge.classList.add("magicfeedback-rating-option-label-container");const ye=document.createElement("label");ye.htmlFor=`rating-${f}-extra`,ye.textContent=null==b?void 0:b.extraOptionText;const ve=document.createElement("img");ve.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",ve.alt=`face-${f}-extra`,ve.className="magicfeedback-rating-image-extra";const be=document.createElement("input");be.id=`rating-${f}-extra`,be.type="radio",be.name=f,be.value="-",be.classList.add(u),be.classList.add("magicfeedback-input"),ge.appendChild(be),ge.appendChild(ve),ge.appendChild(ye),fe.appendChild(ge),O.appendChild(fe)}l.appendChild(N),l.appendChild(O);break;case n.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:l=document.createElement("div"),u="magicfeedback-rating-number";const D=document.createElement("div");D.classList.add("magicfeedback-rating-number-container");const $=(null==b?void 0:b.max)?Number(null==b?void 0:b.max):5,_=(null==b?void 0:b.min)?Number(null==b?void 0:b.min):1,R=r(_,$,null==b?void 0:b.minPlaceholder,null==b?void 0:b.maxPlaceholder,null==b?void 0:b.extraOption);for(let Ee=_;Ee<=$;Ee++){const ke=document.createElement("div");ke.classList.add("magicfeedback-rating-number-option");const Ce=document.createElement("label");Ce.htmlFor=`rating-${f}-${Ee}`,Ce.classList.add("magicfeedback-rating-number-option-label-container");const we=document.createElement("label");we.htmlFor=`rating-${f}-${Ee}`,we.textContent=Ee.toString();const xe=document.createElement("input");xe.id=`rating-${f}-${Ee}`,xe.type="radio",xe.name=f,xe.value=Ee.toString(),xe.classList.add(u),xe.classList.add("magicfeedback-input"),Ce.appendChild(xe),Ce.appendChild(we),ke.appendChild(Ce),D.appendChild(ke)}if((null==b?void 0:b.extraOption)&&(null==b?void 0:b.extraOptionText)){const Te=document.createElement("div");Te.classList.add("magicfeedback-rating-number-option");const Ae=document.createElement("label");Ae.htmlFor=`rating-${f}-extra`,Ae.classList.add("magicfeedback-rating-number-option-label-container");const Le=document.createElement("label");Le.htmlFor=`rating-${f}-extra`,Le.textContent=null==b?void 0:b.extraOptionText;const Se=document.createElement("input");Se.id=`rating-${f}-extra`,Se.type="radio",Se.name=f,Se.value="-",Se.classList.add(u),Se.classList.add("magicfeedback-input"),Ae.appendChild(Se),Ae.appendChild(Le),Te.appendChild(Ae),D.appendChild(Te)}l.appendChild(R),l.appendChild(D);break;case n.FEEDBACKAPPANSWERTYPE.RATING_STAR:l=document.createElement("div"),u="magicfeedback-rating-star";const F=function(e,t,i){const n="magicfeedback-rating-star-selected",s=document.createElement("div");s.classList.add("magicfeedback-rating-star-container"),s.style.maxWidth="300px",s.style.margin="auto";for(let t=1;t<=5;t++){const i=document.createElement("label");i.classList.add("magicfeedback-rating-star-option");const a=document.createElement("input");a.id=`rating-${e}-${t}`,a.type="radio",a.name=e,a.value=t.toString(),a.style.position="absolute",a.style.opacity="0",a.style.width="0",a.style.height="0",a.classList.add("magicfeedback-input"),a.addEventListener("change",(()=>{const e=s.querySelectorAll(".rating__star");for(let t=0;t<e.length;t++)t+1<=Number(a.value)?e[t].classList.contains(n)||e[t].classList.add(n):e[t].classList.contains(n)&&e[t].classList.remove(n)})),i.appendChild(a);const o=document.createElement("label");o.htmlFor=`rating-${e}-${t}`,o.classList.add("rating__star"),o.textContent="★",o.style.fontSize="40px",o.style.color="#CCCCCC",o.style.cursor="pointer",i.appendChild(o),s.appendChild(i)}return s.appendChild(r(1,5,t,i,!1,!1)),s}(f,null==b?void 0:b.minPlaceholder,null==b?void 0:b.maxPlaceholder);l.appendChild(F);break;case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:l=document.createElement("div"),u="magicfeedback-multiple-choice-image";const M=document.createElement("div");M.classList.add("magicfeedback-multiple-choice-image-container"),M.style.display="flex",M.style.flexDirection="row",M.style.flexWrap="wrap",M.style.justifyContent="center";const B=y.length;let q=1,U=1;switch(B){case 1:case 2:case 3:q=B,U=1;break;case 4:case 5:case 6:U=2,q=Math.ceil(B/U);break;case 7:case 8:case 9:U=3,q=Math.ceil(B/U);break;default:U=4,q=Math.ceil(B/U)}const j=void 0!==(null==b?void 0:b.addTitle)&&(null==b?void 0:b.addTitle),G=void 0!==(null==b?void 0:b.multiOption)&&(null==b?void 0:b.multiOption),Q=void 0!==(null==b?void 0:b.extraOption)&&(null==b?void 0:b.extraOption);function K(e){try{const{position:t,url:i,value:n}=e,s=document.createElement("label");s.classList.add("magicfeedback-multiple-choice-image-option"),s.style.width=`calc( ${100/q}% - 10px)`,s.style.height=`calc( ${100/U}% - 10px)`,s.style.margin="5px";const a=document.createElement("label");a.htmlFor=`rating-${f}-${t}`,a.classList.add("magicfeedback-image-option-label-container"),a.style.display="flex",a.style.flexDirection="column",a.addEventListener("mouseover",(()=>{a.style.border="2px solid #000"})),a.addEventListener("mouseout",(()=>{a.style.border="none"})),a.addEventListener("click",(()=>{a.style.border="2px solid #000"}));const o=document.createElement("label");o.textContent=n,o.classList.add("magicfeedback-multiple-choice-image-label");const r=document.createElement("input");r.id=`rating-${f}-${t}`,r.type=G?"checkbox":"radio",r.name=f,r.value=n,r.style.position="absolute",r.style.opacity="0",r.style.width="0",r.style.height="0",r.classList.add("magicfeedback-input");const d=document.createElement("img");d.classList.add("magicfeedback-multiple-choice-image-image"),d.src=i,d.style.cursor="pointer",d.style.backgroundSize="cover",d.style.backgroundPosition="center",d.style.width="100%",d.style.height="100%",d.style.objectFit="cover",d.style.margin="auto",a.appendChild(r),a.appendChild(d),j&&a.appendChild(o),s.appendChild(a),M.appendChild(s)}catch(e){console.error(e)}}x&&(y=y.sort((()=>Math.random()-.5))),y.forEach((e=>K(JSON.parse(e)))),Q&&(null==b?void 0:b.extraOptionValue)&&(null==b?void 0:b.extraOptionValue.length)>0&&K(null==b?void 0:b.extraOptionValue[0]),l.appendChild(M);break;case n.FEEDBACKAPPANSWERTYPE.SELECT:l=document.createElement("select"),u="magicfeedback-select";const W=document.createElement("option");W.value="",W.text="slim"===t?o(h,i):v||"Select an option",W.disabled=!0,W.selected=!0,l.appendChild(W),y.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,l.appendChild(t)}));break;case n.FEEDBACKAPPANSWERTYPE.DATE:l=document.createElement("input"),l.type="date",l.required=g,l.placeholder=k||s.placeholder.date(i||"en"),u="magicfeedback-date";break;case n.FEEDBACKAPPANSWERTYPE.CONSENT:l=document.createElement("input"),u="magicfeedback-consent",l.type="checkbox",l.id=`magicfeedback-${p}`,l.name=f,l.value="true",l.required=g,l.classList.add("magicfeedback-consent"),l.classList.add("magicfeedback-input");break;case n.FEEDBACKAPPANSWERTYPE.EMAIL:l=document.createElement("input"),l.type="email",l.required=g,l.placeholder=k||"you@example.com",u="magicfeedback-email";break;case n.FEEDBACKAPPANSWERTYPE.PASSWORD:l=document.createElement("input"),l.type="password",l.required=g,l.placeholder=k||s.placeholder.password(i||"en"),u="magicfeedback-password";break;case n.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:l=document.createElement("div"),u="magicfeedback-multi-question-matrix";const H=document.createElement("div");H.classList.add("magicfeedback-multi-question-matrix-container");const Y=document.createElement("table");Y.classList.add("magicfeedback-multi-question-matrix-table");const V=document.createElement("thead");V.classList.add("magicfeedback-multi-question-matrix-header"),V.style.paddingBottom="15px";const z=document.createElement("tr"),J=document.createElement("th");z.appendChild(J),y.forEach((e=>{const t=document.createElement("th");t.textContent=e,z.appendChild(t)})),V.appendChild(z),Y.appendChild(V);const X=document.createElement("tbody");null==b||b.options.split("|").forEach(((e,t)=>{const i=document.createElement("tr"),n=document.createElement("td");n.textContent=e,i.appendChild(n),y.forEach(((e,n)=>{const s=document.createElement("td"),a=document.createElement("input");a.type=G?"checkbox":"radio",a.name=`matrix-${f}-${t}`,a.value=e,a.id=`matrix-${f}-${t}-${n}`,a.classList.add("magicfeedback-input");const o=document.createElement("label");o.htmlFor=a.id,o.textContent=e,s.appendChild(a),s.appendChild(o),i.appendChild(s)})),X.appendChild(i)})),Y.appendChild(X),H.appendChild(Y),l.appendChild(H);break;case n.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:l=document.createElement("div"),u="magicfeedback-priority-list";const Z=document.createElement("div");Z.classList.add("magicfeedback-priority-list-container");const ee=document.createElement("ul");ee.classList.add("magicfeedback-priority-list-list"),y.forEach(((e,t)=>{const i=document.createElement("li");i.classList.add("magicfeedback-priority-list-item"),i.style.display="flex",i.style.justifyContent="space-between",i.style.alignItems="center",i.style.margin="5px";const n=document.createElement("input");n.classList.add("magicfeedback-input-magicfeedback-priority-list"),n.classList.add("magicfeedback-input"),n.type="hidden",n.id=`priority-list-${f}`,n.name=f,n.value=`${t+1}. ${e}`,i.appendChild(n);const s=document.createElement("label");s.classList.add("magicfeedback-priority-list-item-label"),s.textContent=`${t+1}. ${e}`,i.appendChild(s);const a=document.createElement("div");a.style.display="flex",a.style.alignItems="center",a.style.justifyContent="space-between";const o=document.createElement("img");o.classList.add("magicfeedback-priority-list-arrow-up"),o.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",o.style.width="20px",o.style.height="20px",o.style.cursor="pointer",o.style.margin="0 5px",o.style.color="#000",o.style.visibility=0===t?"hidden":"visible",o.addEventListener("click",(()=>{var t,a;const d=i.previousElementSibling;if(d){const c=Number(n.value.split(".")[0])-1;n.value=`${c}. ${e}`,s.textContent=`${c}. ${e}`,o.style.visibility=1===c?"hidden":"visible",r.style.visibility=c===y.length?"hidden":"visible";const l=d.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=d.querySelector(".magicfeedback-priority-list-item-label"),p=d.querySelector(".magicfeedback-priority-list-arrow-up"),h=d.querySelector(".magicfeedback-priority-list-arrow-down");if(l&&u&&p&&h){const e=Number(l.value.split(".")[0])+1;l.value=`${e}.${null===(t=u.textContent)||void 0===t?void 0:t.split(".")[1]}`,u.textContent=`${e}.${null===(a=u.textContent)||void 0===a?void 0:a.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",h.style.visibility=e===y.length?"hidden":"visible"}ee.insertBefore(i,d)}})),a.appendChild(o);const r=document.createElement("img");r.classList.add("magicfeedback-priority-list-arrow-down"),r.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",r.style.width="20px",r.style.height="20px",r.style.cursor="pointer",r.style.margin="0 5px",r.style.color="#000",r.style.transform="rotate(180deg)",r.style.visibility=t===y.length-1?"hidden":"visible",r.addEventListener("click",(()=>{var t,a;const d=i.nextElementSibling;if(d){const c=Number(n.value.split(".")[0])+1;n.value=c.toString(),s.textContent=`${c.toString()}. ${e}`,o.style.visibility=1===c?"hidden":"visible",r.style.visibility=c===y.length?"hidden":"visible";const l=d.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=d.querySelector(".magicfeedback-priority-list-item-label"),p=d.querySelector(".magicfeedback-priority-list-arrow-up"),h=d.querySelector(".magicfeedback-priority-list-arrow-down");if(l&&u&&p&&h){const e=Number(l.value.split(".")[0])-1;l.value=`${e}.${null===(t=u.textContent)||void 0===t?void 0:t.split(".")[1]}`,u.textContent=`${e}.${null===(a=u.textContent)||void 0===a?void 0:a.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",h.style.visibility=e===y.length?"hidden":"visible"}ee.insertBefore(d,i)}})),a.appendChild(r),i.appendChild(a),ee.appendChild(i)})),Z.appendChild(ee),l.appendChild(Z);break;case n.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:l=document.createElement("div"),u="magicfeedback-point-system";const te=document.createElement("div");te.classList.add("magicfeedback-point-system-container");const ie=document.createElement("ul");ie.classList.add("magicfeedback-point-system-list"),ie.style.padding="0";const ne=100,se=ne/y.length,ae=document.createElement("div");ae.classList.add("magicfeedback-error"),ae.textContent=s.placeholder.pointsystemerror(i||"en"),ae.style.color="#C70039",ae.style.fontSize="14px",ae.style.textAlign="right",ae.style.width="100%",ae.style.display="none";const oe=document.createElement("div");oe.classList.add("magicfeedback-point-system-total"),oe.textContent="0 / 100 %",oe.style.textAlign="right",oe.style.fontSize="15px",oe.style.marginTop="5px",y.forEach(((e,t)=>{const i=document.createElement("li");i.classList.add("magicfeedback-point-system-item"),i.style.display="flex",i.style.justifyContent="space-between",i.style.alignItems="center",i.style.margin="5px";const n=document.createElement("label");n.textContent=e,n.style.fontSize="15px",i.appendChild(n);const s=document.createElement("span");s.classList.add("magicfeedback-point-system-input-container");const a=document.createElement("input");a.name=f,a.id=`point-system-${e}`,a.type="number",a.min="0",a.max=`${ne}`,a.value="0",a.classList.add("magicfeedback-input"),a.style.width="40px",a.style.border="0",a.style.textAlign="center",a.style.margin="0 5px",a.autofocus=0===t;const o=document.createElement("span");o.textContent="%",o.style.color="#000",a.addEventListener("input",(()=>{const e=ie.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>ne&&(a.value=`${se}%`,t-=Number(a.value));const i=document.getElementById("magicfeedback-submit");i&&(t<100?(oe.style.color="orange",i.setAttribute("disabled","true")):(ae.style.display="none",oe.style.color="green",i.removeAttribute("disabled"))),oe.textContent=`${t} / 100 %`})),a.addEventListener("focus",(()=>{const e=document.getElementById("magicfeedback-submit");e&&(e.setAttribute("disabled","true"),e.addEventListener("pointerover",(()=>{const e=ie.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t<100&&(ae.style.display="block")})))})),s.appendChild(a),s.appendChild(o),i.appendChild(s),ie.appendChild(i)})),te.appendChild(ie),te.appendChild(oe),te.appendChild(ae),l.appendChild(te);break;case n.FEEDBACKAPPANSWERTYPE.INFO_PAGE:l=document.createElement("div"),u="magicfeedback-info-page";const re=document.createElement("div");re.classList.add("magicfeedback-info-message"),re.innerHTML=k,l.appendChild(re);break;default:return E}l.id=`magicfeedback-${p}`,l.setAttribute("name",f),l.classList.add(u),(void 0!==v||null!==C)&&(l.value=C||v),["RADIO","MULTIPLECHOICE"].includes(m)||(l.classList.add("magicfeedback-input"),l.required=g);const A=document.createElement("label");A.setAttribute("for",`magicfeedback-${p}`),A.textContent=o(h,i),A.classList.add("magicfeedback-label");const L=document.createElement("label");if(L.textContent=o(null==b?void 0:b.subtitle,i),L.classList.add("magicfeedback-sublabel"),["CONSENT"].includes(m))E.classList.add("magicfeedback-consent-container"),E.appendChild(l),E.appendChild(A),E.appendChild(L);else{if("slim"!==t&&([n.FEEDBACKAPPANSWERTYPE.INFO_PAGE].includes(m)||(E.appendChild(A),E.appendChild(L)),void 0!==(null==b?void 0:b.general)&&""!==(null==b?void 0:b.general))){const Oe=document.createElement("img");Oe.src=null==b?void 0:b.general,Oe.classList.add("magicfeedback-image"),Oe.style.maxWidth="auto",Oe.style.height="400px",Oe.style.margin="10px 0",E.appendChild(Oe)}if("LONGTEXT"===m&&w>0){const Pe=document.createElement("div");if(Pe.classList.add("magicfeedback-counter"),Pe.textContent=`${l.value.length}/${w}`,Pe.style.textAlign="right",Pe.style.fontSize="15px",Pe.style.marginTop="5px",l.addEventListener("input",(()=>{Pe.textContent=`${l.value.length}/${w}`})),E.appendChild(l),E.appendChild(Pe),(null==b?void 0:b.extraOption)&&(null==b?void 0:b.extraOptionText)){const Ie=document.createElement("div");Ie.classList.add("magicfeedback-skip-container"),Ie.classList.add("magicfeedback-checkbox-container"),Ie.style.display="flex",Ie.style.justifyContent="flex-start";const Ne=document.createElement("input");Ne.classList.add("magicfeedback-skip"),Ne.type="checkbox",Ne.id=`skip-${f}`,Ne.name=f,Ne.value="-",Ne.style.cursor="pointer";const De=document.createElement("label");De.htmlFor=`skip-${f}`,De.textContent=null==b?void 0:b.extraOptionText,De.style.fontSize="15px",De.style.cursor="pointer",De.style.margin="0 5px",Ne.addEventListener("click",(()=>{l.value="-",c&&c()})),Ie.appendChild(Ne),Ie.appendChild(De),E.appendChild(Ie)}}else E.appendChild(l)}return E}(t,i,d,`${a}${p?`/${h}`:""}`,l);u.push(e)}})),u},t.renderActions=function(e="",t,i="Submit",n="Back",s="Next"){const a=document.createElement("div");a.classList.add("magicfeedback-action-container");const o=document.createElement("button");o.id="magicfeedback-submit",o.type="submit",o.classList.add("magicfeedback-submit"),o.textContent="MAGICSURVEY"===e?s||"Next":i||"Submit";const r=document.createElement("button");return r.id="magicfeedback-back",r.type="button",r.classList.add("magicfeedback-back"),r.textContent=n||"Back",r.addEventListener("click",t),r.addEventListener("click",(()=>{o.removeAttribute("disabled")})),"MAGICSURVEY"===e&&a.appendChild(r),a.appendChild(o),a},t.renderError=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-error"),t.textContent=e,t},t.renderSuccess=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-success"),t.textContent=e,t},t.renderStartMessage=function(e,t=!1,i="Go!",n=(()=>{})){const s=document.createElement("div");s.classList.add("magicfeedback-start-message-container");const a=document.createElement("div");if(a.classList.add("magicfeedback-start-message"),a.innerHTML=e,s.appendChild(a),t){const e=document.createElement("button");e.id="magicfeedback-start-message-button",e.classList.add("magicfeedback-start-message-button"),e.textContent=i,e.addEventListener("click",(()=>n())),s.appendChild(e)}return s}},341:function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,a){function o(e){try{d(n.next(e))}catch(e){a(e)}}function r(e){try{d(n.throw(e))}catch(e){a(e)}}function d(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}d((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFollowUpQuestion=t.sendFeedback=t.getQuestions=t.getSessionForm=t.getForm=t.validateEmail=void 0;const a=s(i(98)),o=s(i(147)),r=i(374),d={Accept:"application/json","Magicfeedback-Sdk-Version":o.default.version};t.validateEmail=function(e){return/\S+@\S+\.\S+/.test(e)},t.getForm=function(e,t,i,s){return n(this,void 0,void 0,(function*(){try{const n=yield(0,a.default)(e+r.endpoints.sdk.app_info(t,i),{method:"GET",headers:d});if(n.ok){const e=yield n.json();return s.log(`Received form for app ${t}`,e),e}throw s.err(`Failed to get questions for app ${t}:`,n.status,n.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return s.err(e),null}}))},t.getSessionForm=function(e,t,i){return n(this,void 0,void 0,(function*(){try{const n=yield(0,a.default)(e+r.endpoints.sdk.session(t),{method:"GET",headers:d});if(n.ok){const e=yield n.json();return i.log(`Received form for session ${t}`,e),e}throw i.err(`Failed to get questions for session ${t}:`,n.status,n.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return i.err(e),null}}))},t.getQuestions=function(e,t,i,s){return n(this,void 0,void 0,(function*(){try{const n=yield(0,a.default)(e+r.endpoints.sdk.app(t,i),{method:"GET",headers:d});if(n.ok){const e=yield n.json();return s.log(`Received questions for app ${t}`,e),e}throw s.err(`Failed to get questions for app ${t}:`,n.status,n.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return s.err(e),[]}}))},t.sendFeedback=function(e,t,i){return n(this,void 0,void 0,(function*(){try{const n=yield(0,a.default)(e+r.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},d),body:JSON.stringify(t)});if(n.ok)return i.log(`Form ${t.integration} submitted successfully!`),(yield n.json()).sessionId;throw i.err(`Failed to submit form ${t.integration}:`,n.status,n.statusText),new Error(n.statusText)}catch(e){return i.err(e),""}}))},t.getFollowUpQuestion=function(e,t,i){return n(this,void 0,void 0,(function*(){try{const n=yield(0,a.default)(e+r.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},d),body:JSON.stringify(t)});if(n.ok)return i.log(`Received follow up question for form ${t.integration}`),(yield n.json())||"";throw i.err(`Failed to get follow up question for form ${t.integration}:`,n.status,n.statusText),new Error(n.statusText)}catch(e){return i.err(e),""}}))}},5:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Log=void 0,t.Log=class{constructor(e){this.config=e}log(...e){this.config.get("debug")&&console.log("[MagicFeedback]:",...e)}err(...e){console.error("[MagicFeedback]:",...e)}}},147:e=>{"use strict";e.exports=JSON.parse('{"name":"@magicfeedback/native","version":"1.3.2-beta.4","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","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","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"}}')}},t={},function i(n){var s=t[n];if(void 0!==s)return s.exports;var a=t[n]={exports:{}};return e[n].call(a.exports,a,a.exports,i),a.exports}(607).default;var e,t}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"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()}(global,(()=>(()=>{"use strict";var e={290:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HOST_API_URL_DEV=t.HOST_API_URL=void 0,t.HOST_API_URL="https://api.magicfeedback.io/",t.HOST_API_URL_DEV="https://api-dev.magicfeedback.io/"},607:function(e,t,i){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=n(i(519));let s=null;s||(s=(0,a.default)()),t.default=s},519:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function o(e){try{d(n.next(e))}catch(e){s(e)}}function r(e){try{d(n.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}d((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const a=i(954),s=i(712),o=i(5),r=i(341),d=i(290);t.default=function(){const e=new s.Config;let t;return{init:function(i){(null==i?void 0:i.debug)&&e.set("debug",null==i?void 0:i.debug),e.set("url",(null==i?void 0:i.env)&&"dev"===(null==i?void 0:i.env)?d.HOST_API_URL_DEV:d.HOST_API_URL),t=new o.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,a,s,o=!0,d,c){return n(this,void 0,void 0,(function*(){i||t.err("No appID provided"),a||t.err("No publicKey provided"),s||t.err("No feedback provided"),s.answers||s.profile||s.metrics||s.metadata||t.err("No feedback data provided");const n=e.get("url"),l={integration:i,publicKey:a,privateKey:c,completed:o,id:d,feedback:s};try{const e=yield(0,r.sendFeedback)(n,l,t);return t.log("sent native feedback"),e}catch(e){return t.err("error native feedback",e),!1}}))},form:function(i,n){return i||t.err("No appID provided"),n||t.err("No publicKey provided"),new a.Form(e,i,n)},session:function(i){return i||t.err("No sessionId provided"),new a.Form(e,i)}}}},314:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.History=void 0,t.History=class{constructor(){this.items=[]}enqueue(e){this.items.push(e)}dequeue(){return this.items.shift()}rollback(){return this.items.pop()}front(){return this.items[0]}back(){return this.items[this.items.length-1]}isEmpty(){return 0===this.items.length}size(){return this.items.length}}},712:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Config=void 0,t.Config=class{constructor(){this.variables={},this.variables.env="prod",this.variables.debug=!1}get(e){return this.variables[e]}set(e,t){this.variables[e]=t}}},954:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function o(e){try{d(n.next(e))}catch(e){s(e)}}function r(e){try{d(n.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}d((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const a=i(5),s=i(341),o=i(183),r=i(24),d=i(804),c=i(116),l=i(314),u=i(457);t.Form=class{constructor(e,t,i){this.config=e,this.log=new a.Log(e),this.formOptionsConfig={addButton:!0,sendButtonText:"Send",backButtonText:"Back",nextButtonText:"Next",addSuccessScreen:!0,getMetaData:!0,questionFormat:"standard"},this.selector="",this.appId=t,this.publicKey=i||"",this.url=e.get("url"),this.id="",this.formData=null,""!==this.publicKey&&this.getDataFromStorage(),this.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.history=new l.History,this.graph=new r.PageGraph([]),this.progress=0,this.total=0,this.completed=!1}getDataFromStorage(){const e=localStorage.getItem(`magicfeedback-${this.appId}`);e&&new Date(JSON.parse(e).savedAt)<new Date((new Date).getTime()+864e5)&&(this.formData=JSON.parse(e),(0,s.getForm)(this.url,this.appId,this.publicKey,this.log).then((e=>{var t,i,n,a,s;if((null==e?void 0:e.updatedAt)&&(null===(t=this.formData)||void 0===t?void 0:t.savedAt)&&(null==e?void 0:e.updatedAt)>(null===(i=this.formData)||void 0===i?void 0:i.savedAt)){if(this.formData=e,this.formData.savedAt=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}`);this.formData.pages&&0!==(null===(n=this.formData.pages)||void 0===n?void 0:n.length)||this.formatPages(),null===(a=this.formData.questions)||void 0===a||a.sort(((e,t)=>e.position-t.position)),this.formData.pages=this.formData.pages.filter((e=>{var t;return(null===(t=e.integrationQuestions)||void 0===t?void 0:t.length)>0})),(null===(s=this.formData.style)||void 0===s?void 0:s.startMessage)?this.generateWelcomeMessage(this.formData.style.startMessage):this.startForm()}})))}generate(e,t){var i,a,o;return n(this,void 0,void 0,(function*(){try{if(this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e,void 0!==this.formData&&this.formData||(this.formData=""!==this.publicKey?yield(0,s.getForm)(this.url,this.appId,this.publicKey,this.log):yield(0,s.getSessionForm)(this.url,this.appId,this.log)),void 0===this.formData||!this.formData)throw new Error(`No form for app ${this.appId}`);if(this.formData.savedAt||(this.formData.savedAt=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}`);this.formData.pages&&0!==(null===(i=this.formData.pages)||void 0===i?void 0:i.length)||this.formatPages(),null===(a=this.formData.questions)||void 0===a||a.sort(((e,t)=>e.position-t.position)),this.formData.pages=this.formData.pages.filter((e=>{var t;return(null===(t=e.integrationQuestions)||void 0===t?void 0:t.length)>0})),this.formOptionsConfig.getMetaData&&this.getMetaData(),(null===(o=this.formData.style)||void 0===o?void 0:o.startMessage)?yield this.generateWelcomeMessage(this.formData.style.startMessage):this.startForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}formatPages(){var e;if(this.formData)switch(this.formData.identity){case"MAGICSURVEY":this.formData.pages=[],null===(e=this.formData.questions)||void 0===e||e.forEach((e=>{var t,i;const n=new c.PageRoute(e.id,e.ref,c.OperatorType.NOEQUAL,null,c.TransitionType.PAGE,(e.position+1).toString(),e.position.toString()),a=new d.Page(e.position.toString(),e.position,this.appId,[e],[n]);null===(i=null===(t=this.formData)||void 0===t?void 0:t.pages)||void 0===i||i.push(a)}));break;case"MAGICFORM":const t=new d.Page("1",1,this.appId,this.formData.questions,[]);this.formData.pages=[t]}}generateContainer(){let e=document.getElementById(this.selector);if(!e&&(e=document.getElementById("magicfeedback-container-"+this.appId),!e))throw new Error(`Element with ID '${this.selector}' not found.`);return e.classList.add("magicfeedback-container"),e.id="magicfeedback-container-"+this.appId,e.innerHTML="",e}generateForm(){var e,t,i,a;return n(this,void 0,void 0,(function*(){try{if(!this.formData||!this.formData.pages||0===this.formData.pages.length)throw new Error("No form data");this.graph=new r.PageGraph(this.formData.pages.sort(((e,t)=>e.position-t.position)));let n=this.generateContainer();const s=document.createElement("form");s.classList.add("magicfeedback-form"),s.id="magicfeedback-"+this.appId;const d=document.createElement("div");d.classList.add("magicfeedback-questions"),d.id="magicfeedback-questions-"+this.appId;const c=this.graph.getFirstPage();if(!c)throw new Error("No page found");if(this.total=this.graph.findMaxDepth(),c.elements=(0,o.renderQuestions)(c.questions,this.formOptionsConfig.questionFormat,null===(e=this.formData)||void 0===e?void 0:e.lang[0],null===(t=this.formData)||void 0===t?void 0:t.product,(()=>this.send())),null===(i=c.elements)||void 0===i||i.forEach((e=>d.appendChild(e))),s.appendChild(d),this.history.enqueue(c),n.appendChild(s),this.progress=this.history.size(),this.formOptionsConfig.addButton){const e=(0,o.renderActions)(null===(a=this.formData)||void 0===a?void 0:a.identity,(()=>this.back()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);s.appendChild(e)}this.formOptionsConfig.addButton&&s.addEventListener("submit",(e=>{e.preventDefault(),this.send()})),this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}))}startForm(){this.generateForm()}generateWelcomeMessage(e){return n(this,void 0,void 0,(function*(){try{const t=this.generateContainer(),i=(0,o.renderStartMessage)(e,this.formOptionsConfig.addButton,this.formOptionsConfig.startButtonText,(()=>this.startForm()));t.appendChild(i),this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,formData:this.formData}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}))}getMetaData(){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]})}send(e,t,i){return n(this,void 0,void 0,(function*(){const n=document.getElementById("magicfeedback-questions-"+this.appId);try{i&&(this.feedback.profile=[...this.feedback.profile,...i]),t&&(this.feedback.metrics=[...this.feedback.metrics,...t]),e&&(this.feedback.metadata=[...this.feedback.metadata,...e]),this.answer(),this.formOptionsConfig.beforeSubmitEvent&&(yield this.formOptionsConfig.beforeSubmitEvent({loading:!0,progress:this.progress,total:this.total}));const a=this.history.back();if(!a)throw new Error("No page found");const s=a.getRequiredQuestions();for(const e of s)if(!this.feedback.answers.find((t=>t.key===e&&t.value.length>0)))throw this.log.err(`The question ${e} is required`),new Error("No response");const o=yield this.pushAnswers(!1);if(!o)throw new Error("No response");this.id=o,yield this.processNextQuestion(n)}catch(e){this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({loading:!1,progress:this.progress,total:this.total,error:e}))}}))}answer(){const e=document.getElementById("magicfeedback-"+this.appId);if(!e)return this.log.err(`Form "${e}" not found.`),void(this.feedback.answers=[]);if(!this.history.back())throw new Error("No page found");const t=[];let i=!1;e.querySelectorAll(".magicfeedback-input").forEach((e=>{const n=e.type,a=e.classList[0],o={key:e.name,value:[]},r="magicfeedback-consent"===a?e.checked.toString():e.value;if(o.key&&""!==o.key)switch(n){case"radio":case"checkbox":if("magicfeedback-consent"===a||e.checked){o.value.push(r);const e=t.findIndex((e=>e.key===o.key));-1!==e?t[e].value=[...t[e].value,...o.value]:t.push(o)}break;default:if(""!==r){if("email"===n){if(!(0,s.validateEmail)(r)){this.log.err("Invalid email"),i=!0;break}this.feedback.profile.push({key:"email",value:[r]})}if(e.id.includes("point-system")){const t="point-system-"+e.id.split("-")[e.id.split("-").length-1];o.value.push(`${t}: ${r}%`)}else o.value.push(r);const a=t.findIndex((e=>e.key===o.key));-1!==a?t[a].value=[...t[a].value,...o.value]:t.push(o)}}}));const n=t.filter((e=>e.key.includes("matrix")));null==n||n.forEach((e=>{const i=t.find((t=>t.key===e.key));i&&(i.value=[...new Set(i.value)])}));const a=t.filter((e=>e.key.includes("point-system")));null==a||a.forEach((e=>{100!==e.value.reduce(((e,t)=>{const i=t.split(": ")[1];return e+Number(i.replace("%",""))}),0)&&(this.log.err("The sum of the point system questions must be 100%"),i=!0)})),this.feedback.answers=i?[]:t}finish(){return n(this,void 0,void 0,(function*(){if(this.completed=!0,this.formOptionsConfig.addSuccessScreen){const e=document.getElementById("magicfeedback-container-"+this.appId);e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,o.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}this.answer();const e=yield this.pushAnswers(!0);if(!e)throw new Error("No response");this.id=e,this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:this.id,loading:!1,progress:this.progress,total:this.total,completed:this.completed,error:null}))}))}pushAnswers(e=!1){return n(this,void 0,void 0,(function*(){try{const t=this.config.get("url"),i={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,s.sendFeedback)(t,this.id?Object.assign(Object.assign({},i),{sessionId:this.id}):i,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){var t;return n(this,void 0,void 0,(function*(){if(!(null==e?void 0:e.followup))return null;try{if(0===this.feedback.answers.length)throw new Error("No answers provided");const i=this.config.get("url"),n={answer:null===(t=this.feedback.answers.find((t=>t.key===e.ref)))||void 0===t?void 0:t.value[0],publicKey:this.publicKey,sessionId:this.id,question:e};return yield(0,s.getFollowUpQuestion)(i,n,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e){var t,i,a;return n(this,void 0,void 0,(function*(){const n=this.history.back();if(!n)throw new Error("No page found");const s=n.getFollowupQuestions();if(0===(null==s?void 0:s.length))return void(yield this.renderNextQuestion(e,n));const r=[];for(const e of s){const t=n.questions.find((t=>t.ref===e));if(t){const e=yield this.callFollowUpQuestion(t);e&&r.push(e)}}if(0===r.length)return void(yield this.renderNextQuestion(e,n));const c=new d.Page(n.id,n.position,this.appId,r,n.edges),l=new u.PageNode(n.id,n.position,n.edges,c,r,!0);l.elements=(0,o.renderQuestions)(r,this.formOptionsConfig.questionFormat,null===(t=this.formData)||void 0===t?void 0:t.lang[0],null===(i=this.formData)||void 0===i?void 0:i.product,(()=>this.send())),this.history.enqueue(l),this.progress=this.history.size(),e.removeChild(e.childNodes[0]),null===(a=l.elements)||void 0===a||a.forEach((t=>e.appendChild(t))),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:this.id,loading:!1,progress:this.progress,total:this.total,followup:l.isFollowup,completed:this.completed,error:null}))}))}renderNextQuestion(e,t){var i,a,s;return n(this,void 0,void 0,(function*(){console.log(t,this.feedback.answers);const n=this.graph.getNextPage(t,this.feedback.answers);console.log(n),n?(n.elements=(0,o.renderQuestions)(n.questions,this.formOptionsConfig.questionFormat,null===(i=this.formData)||void 0===i?void 0:i.lang[0],null===(a=this.formData)||void 0===a?void 0:a.product,(()=>this.send())),e.removeChild(e.childNodes[0]),null===(s=n.elements)||void 0===s||s.forEach((t=>e.appendChild(t))),this.history.enqueue(n),this.progress=this.history.size(),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:this.id,loading:!1,progress:this.progress,total:this.total,followup:n.isFollowup,completed:this.completed,error:null}))):this.finish()}))}back(){var e;return n(this,void 0,void 0,(function*(){if(0===this.history.size())return;const t=document.getElementById("magicfeedback-questions-"+this.appId);t&&t.childNodes.length>0&&t.removeChild(t.childNodes[0]),this.history.rollback(),this.progress=this.history.size();const i=this.history.back();i&&(null===(e=i.elements)||void 0===e||e.forEach((e=>t.appendChild(e)))),this.formOptionsConfig.onBackEvent&&(yield this.formOptionsConfig.onBackEvent({loading:!1,progress:this.progress,followup:(null==i?void 0:i.isFollowup)||!1,error:i?null:"No page found"}))}))}}},804:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Page=void 0,t.Page=class{constructor(e,t,i,n,a){this.id=e,this.position=t,this.generatedAt=(new Date).toISOString(),this.updatedAt=(new Date).toISOString(),this.status="ACTIVE",this.integrationId=i,this.integrationQuestions=n,this.integrationPageRoutes=a}}},24:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PageGraph=void 0;const n=i(457),a=i(116);t.PageGraph=class{constructor(e){this.nodes=new Map,this.buildGraph(e)}buildGraph(e){e.forEach(((t,i)=>{var s,o;if(!t.integrationPageRoutes&&e[i+1]){const n=new a.PageRoute(`${t.id}-default`,(null===(s=t.integrationQuestions[0])||void 0===s?void 0:s.ref)||"",a.OperatorType.DEFAULT,"",a.TransitionType.PAGE,(null===(o=e[i+1])||void 0===o?void 0:o.id)||"",t.id);t.integrationPageRoutes=[n]}const r=new n.PageNode(t.id,t.position,t.integrationPageRoutes||[],t,t.integrationQuestions);this.nodes.set(r.id,r)}))}getNodeById(e){return this.nodes.get(e)}getNextEdgeByDefault(e){if(e)for(const t of this.nodes.values())if(t.position===e.position+1)return t.id}getFirstPage(){let e,t=Number.MAX_VALUE;for(const i of this.nodes.values())i.position<t&&(t=i.position,e=i);return e}getNextPage(e,t){if(!e)return;e.edges.sort(((e,t)=>"DIRECT"===e.typeCondition?1:"DIRECT"===t.typeCondition?-1:0));const i=e.edges.find((e=>{const i=null==t?void 0:t.filter((t=>t.key===e.questionRef));if(!i)return!1;if("DIRECT"===e.typeCondition)return!0;switch(e.typeOperator){case a.OperatorType.EQUAL:return i.find((t=>{var i;return null===(i=t.value)||void 0===i?void 0:i.includes(e.value)}));case a.OperatorType.NOEQUAL:return!i.find((t=>{var i;return null===(i=t.value)||void 0===i?void 0:i.includes(e.value)}));case a.OperatorType.GREATER:return i.find((t=>t.value.find((t=>Number(t)>Number(e.value)))));case a.OperatorType.LESS:return i.find((t=>t.value.find((t=>Number(t)<Number(e.value)))));case a.OperatorType.GREATEREQUAL:return i.find((t=>t.value.find((t=>Number(t)>=Number(e.value)))));case a.OperatorType.LESSEQUAL:return i.find((t=>t.value.find((t=>Number(t)<=Number(e.value)))));case a.OperatorType.INQ:return i.find((t=>e.value.includes(t.value)));case a.OperatorType.NINQ:return!i.find((t=>e.value.includes(t.value)));default:return!1}}));if(!i){const t=this.getNextEdgeByDefault(e);if(!t)return;return this.getNodeById(t)}switch(i.transition){case a.TransitionType.PAGE:return this.getNodeById(i.transitionDestiny);case a.TransitionType.FINISH:return;case a.TransitionType.REDIRECT:return void(window.location.href=i.transitionDestiny);default:return}}findDepth(e){const t=this.getNodeById(e);if(!t)return 0;const i=new Set;return this.DFSUtil(t,i,0)}findMaxDepth(e){if(e||(e=this.getFirstPage()),!e)return 0;const t=new Set;let i=e.questions.find((e=>e.followup))?2:1;return i=Math.max(i,this.DFSUtil(e,t,i)),i}DFSUtil(e,t,i){t.add(e);let n=i;const a=e.edges||[];for(const e of a){const a=this.getNodeById(e.transitionDestiny);if(a&&!t.has(a)){const e=a.questions.find((e=>e.followup))?i+2:i+1,s=this.DFSUtil(a,t,e);n=Math.max(n,s)}}return n}}},457:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PageNode=void 0,t.PageNode=class{constructor(e,t,i,n,a,s=!1){this.id=e,this.position=t,this.edges=i,this.data=n,this.questions=a,this.elements=[],this.isFollowup=s}getFollowupQuestions(){return this.questions.filter((e=>e.followup)).map((e=>e.ref))}getRequiredQuestions(){return this.questions.filter((e=>e.require)).map((e=>e.ref))}}},116:(e,t)=>{var i,n,a,s;Object.defineProperty(t,"__esModule",{value:!0}),t.PageRoute=t.StatusType=t.OperatorType=t.ConditionType=t.TransitionType=void 0,(s=t.TransitionType||(t.TransitionType={})).PAGE="PAGE",s.FINISH="FINISH",s.REDIRECT="REDIRECT",function(e){e.LOGICAL="LOGICAL",e.DIRECT="DIRECT"}(i=t.ConditionType||(t.ConditionType={})),(a=t.OperatorType||(t.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(e){e.ACTIVE="ACTIVE",e.DEPRECATED="DEPRECATED",e.DELETE="DELETE"}(n=t.StatusType||(t.StatusType={})),t.PageRoute=class{constructor(e,t,a,s,o,r,d,c){this.id=e,this.questionRef=t,this.typeCondition=c||i.LOGICAL,this.typeOperator=a,this.value=s,this.transition=o,this.transitionDestiny=r,this.status=n.ACTIVE,this.generatedAt=new Date,this.updatedAt=new Date,this.integrationPageId=d}}},244:(e,t)=>{var i,n;Object.defineProperty(t,"__esModule",{value:!0}),t.QuestionType=t.FEEDBACKAPPANSWERTYPE=void 0,(n=t.FEEDBACKAPPANSWERTYPE||(t.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",t.QuestionType=class{},function(e){e.FORM="form",e.DIV="div"}(i||(i={}))},374:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.endpoints=void 0,t.endpoints={sdk:{app:(e,t)=>`sdk/app/${e}/${t}`,app_info:(e,t)=>`sdk/app/${e}/${t}/info`,session:e=>`sdk/app/session/${e}/info`,feedback:"sdk/feedback",followUpQuestion:"sdk/followUpQuestion"}}},528:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.placeholder=void 0,t.placeholder={answer:e=>{switch(e){case"en":default:return"Write your answer here...";case"es":return"Escribe tu respuesta aquí...";case"da":return"Skriv dit svar her...";case"fi":return"Kirjoita vastauksesi tähän...";case"sv":return"Skriv ditt svar här...";case"no":return"Skriv svaret ditt her...";case"ar":return"اكتب إجابتك هنا...";case"bn":return"এখানে আপনার"}},number:e=>{switch(e){case"en":default:return"Write your number here...";case"es":return"Escribe tu número aquí...";case"da":return"Skriv dit nummer her...";case"fi":return"Kirjoita numerosi tähän...";case"sv":return"Skriv ditt nummer här...";case"no":return"Skriv nummeret ditt her...";case"ar":return"اكتب رقمك هنا...";case"bn":return"এখানে আপনার"}},email:e=>{switch(e){case"en":default:return"Write your email here...";case"es":return"Escribe tu correo electrónico aquí...";case"da":return"Skriv din e-mail her...";case"fi":return"Kirjoita sähköpostiosoitteesi tähän...";case"sv":return"Skriv din e-post här...";case"no":return"Skriv e-posten din her...";case"ar":return"اكتب بريدك الإلكتروني هنا...";case"bn":return"এখানে আপনার"}},date:e=>{switch(e){case"en":default:return"Write your date here...";case"es":return"Escribe tu fecha aquí...";case"da":return"Skriv din dato her...";case"fi":return"Kirjoita päivämääräsi tähän...";case"sv":return"Skriv ditt datum här...";case"no":return"Skriv datoen din her...";case"ar":return"اكتب تاريخك هنا...";case"bn":return"এখানে আপনার"}},password:e=>{switch(e){case"en":default:return"Write your password here...";case"es":return"Escribe tu contraseña aquí...";case"da":return"Skriv dit kodeord her...";case"fi":return"Kirjoita salasanasi tähän...";case"sv":return"Skriv ditt lösenord här...";case"no":return"Skriv passordet ditt her...";case"ar":return"اكتب كلمة المرور الخاصة بك هنا...";case"bn":return"এখানে আপনার"}},pointsystemerror:e=>{switch(e){case"en":default:return"The total points must be 100 %";case"es":return"El total de puntos debe ser 100 %";case"da":return"Samlet antal point skal være 100 %";case"fi":return"Kokonaispisteiden on oltava 100 %";case"sv":return"Totala poäng måste vara 100 %";case"no":return"Totalt antall poeng må være 100 %";case"ar":return"يجب أن تكون النقاط الإجمالية 100 %";case"bn":return"মোট পয়েন্ট 100 % হতে হবে"}}}},183:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.renderStartMessage=t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0;const n=i(244),a=i(528),s="https://survey-dev.magicfeedback.io/assets/emojis";function o(e,t){return"object"==typeof e?e[t]||e.en:e}function r(e,t,i,n,a,s=!0){const o=document.createElement("div");o.classList.add("magicfeedback-rating-placeholder"),o.style.display="flex",o.style.justifyContent="space-between",o.style.width=a?`calc(100% - (100% / ${t+1}))`:"100%",o.style.marginRight="auto",s&&window.innerWidth<600&&(o.style.flexDirection="column");const r=document.createElement("span");r.textContent=i,r.classList.add("magicfeedback-rating-placeholder-value"),r.style.fontSize="15px",r.style.textAlign="left",r.style.width="50%",s&&window.innerWidth<600&&(r.textContent=`${e} ➜ ${i}`,r.style.width="100%",r.style.textAlign="left",r.style.marginBottom="5px"),o.appendChild(r);const d=document.createElement("span");return d.textContent=n,d.classList.add("magicfeedback-rating-placeholder-value"),d.style.fontSize="15px",d.style.textAlign="right",d.style.width="50%",s&&window.innerWidth<600&&(d.textContent=`${t} ➜ ${n}`,d.style.width="100%",d.style.textAlign="left",d.style.marginBottom="5px"),o.appendChild(d),o}t.renderQuestions=function e(t,i="standard",d="en",c={customIcons:!1},l){if(!t)throw new Error("[MagicFeedback] No questions provided");const u=[],{customIcons:p,id:m}=c;return t.forEach((t=>{var h,f;if((null===(f=null===(h=null==t?void 0:t.questionType)||void 0===h?void 0:h.conf)||void 0===f?void 0:f.length)>0){let n=document.createElement("div");n.classList.add("magicfeedback-div");const a=document.createElement("label");a.setAttribute("for",`magicfeedback-${t.id}`),a.textContent=o(t.title,d),a.classList.add("magicfeedback-label"),n.appendChild(a),t.questionType.conf.forEach((e=>{e.ref=t.ref,t.assets[e.id]&&(e.assets={placeholder:t.assets[e.id]})})),e(t.questionType.conf,i,d,c,l).forEach((e=>{n.appendChild(e)})),u.push(n)}else{const e=function(e,t,i,d,c){var l;let u,p,{id:m,title:h,type:f,ref:g,require:v,value:b,defaultValue:y,assets:E}=e,k=document.createElement("div");k.classList.add("magicfeedback-div");const C="slim"===t?o(h,i):null==E?void 0:E.placeholder,x=(T=m,new URLSearchParams(window.location.search).get(T)),w=(null==E?void 0:E.maxCharacters)||0;var T;switch(f){case n.FEEDBACKAPPANSWERTYPE.TEXT:u=document.createElement("input"),u.type="text",u.placeholder=C||a.placeholder.answer(i||"en"),p="magicfeedback-text";break;case n.FEEDBACKAPPANSWERTYPE.LONGTEXT:u=document.createElement("textarea"),u.rows=3,w>0&&(u.maxLength=w),u.placeholder=C||a.placeholder.answer(i||"en"),p="magicfeedback-longtext";break;case n.FEEDBACKAPPANSWERTYPE.NUMBER:u=document.createElement("input"),u.type="number",u.placeholder="slim"===t?o(h,i):a.placeholder.number(i||"en"),p="magicfeedback-number",b.length&&(b.sort(((e,t)=>Number(e)-Number(t))),u.max=b[b.length-1],u.min=b[0],u.value=b[0]);break;case n.FEEDBACKAPPANSWERTYPE.RADIO:case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:u=document.createElement("div"),p="magicfeedback-"+("MULTIPLECHOICE"===f?"checkbox":"radio"),(null==E?void 0:E.extraOption)&&!b.includes(null==E?void 0:E.extraOptionText)&&b.push(null==E?void 0:E.extraOptionText),b.forEach(((e,t)=>{const s=document.createElement("div");s.classList.add(`magicfeedback-${"MULTIPLECHOICE"===f?"checkbox":"radio"}-container`);const o=document.createElement("label"),r=document.createElement("input");if(r.id=`rating-${g}-${t}`,r.type="MULTIPLECHOICE"===f?"checkbox":"radio",r.name=g,r.value=e,r.classList.add(p),r.classList.add("magicfeedback-input"),f===n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE&&(null==E?void 0:E.maxOptions)&&(null==E?void 0:E.maxOptions)>0&&r.addEventListener("change",(()=>{document.querySelectorAll(`input[name="${g}"]:checked`).length>(null==E?void 0:E.maxOptions)&&(r.checked=!1)})),e!==y&&e!==x||(r.checked=!0),o.textContent=e,o.htmlFor=`rating-${g}-${t}`,r.addEventListener("change",(t=>{const i=document.getElementById(`extra-option-${g}`);i&&(null==E?void 0:E.extraOption)&&(t.target.checked&&e===(null==E?void 0:E.extraOptionText)?(b.forEach(((e,t)=>{e!==(null==E?void 0:E.extraOptionText)&&(document.getElementById(`rating-${g}-${t}`).checked=!1)})),i.style.display="block"):(document.getElementById(`rating-${g}-${b.length-1}`).checked=!1,i.style.display="none"))})),s.appendChild(r),s.appendChild(o),u.appendChild(s),(null==E?void 0:E.extraOption)&&e===(null==E?void 0:E.extraOptionText)){const e=document.createElement("input");e.type="text",e.placeholder=(null==E?void 0:E.extraOptionPlaceholder)||a.placeholder.answer(i||"en"),e.classList.add("magicfeedback-extra-option"),e.classList.add("magicfeedback-input"),e.id=`extra-option-${g}`,e.name=`extra-option-${g}`,e.style.display="none",u.appendChild(e)}}));break;case n.FEEDBACKAPPANSWERTYPE.BOOLEAN:u=document.createElement("div"),p="magicfeedback-radio";const A=document.createElement("div");A.classList.add("magicfeedback-boolean-container"),A.style.display="flex",A.style.flexDirection="row",A.style.justifyContent="space-between",A.style.width="70%",A.style.margin="auto",((null==E?void 0:E.addIcon)?["👍","👎"]:function(e){switch(e){case"es":return["Sí","No"];case"fr":return["Oui","Non"];case"de":return["Ja","Nein"];case"it":return["Sì","No"];case"pt":return["Sim","Não"];case"nl":return["Ja","Nee"];case"pl":return["Tak","Nie"];case"ru":return["Да","Нет"];case"ja":return["はい","いいえ"];case"zh":return["是","不"];case"ko":return["예","아니"];case"da":case"sv":return["Ja","Nej"];case"fi":return["Kyllä","Ei"];case"no":return["Ja","Nei"];case"ar":return["نعم","لا"];case"bn":return["হ্যাঁ","না"];default:return["Yes","No"]}}(i)).forEach(((e,t)=>{const i=document.createElement("label");i.classList.add("magicfeedback-boolean-option"),i.htmlFor=`rating-${g}-${t}`,i.style.cursor="pointer",i.style.border="1px solid #000",i.style.display="flex",i.style.justifyContent="center",i.style.alignItems="center",i.style.margin="auto",i.style.padding="0",i.style.width="45%",i.style.height="38px";const n=document.createElement("label");n.htmlFor=`rating-${g}-${t}`,n.textContent=e,n.style.margin="0",n.style.padding="0";const a=document.createElement("input");a.id=`rating-${g}-${t}`,a.type="radio",a.name=g,a.value=e,a.classList.add(p),a.classList.add("magicfeedback-input"),a.style.position="absolute",a.style.opacity="0",a.style.width="0",a.style.height="0",a.style.margin="0",a.addEventListener("change",(()=>{c&&c()})),i.appendChild(a),i.appendChild(n),A.appendChild(i)})),u.appendChild(A);break;case n.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:u=document.createElement("div"),p="magicfeedback-rating";const S=document.createElement("div");S.classList.add("magicfeedback-rating-container");const O=(null==E?void 0:E.max)?Number(null==E?void 0:E.max):5,I=(null==E?void 0:E.min)?Number(null==E?void 0:E.min):1,N=r(I,O,null==E?void 0:E.minPlaceholder,null==E?void 0:E.maxPlaceholder,null==E?void 0:E.extraOption);for(let re=I;re<=O;re++){const de=document.createElement("div");de.classList.add("magicfeedback-rating-option");const ce=document.createElement("label");ce.htmlFor=`rating-${g}-${re}`,ce.classList.add("magicfeedback-rating-option-label-container");const le=document.createElement("label");le.htmlFor=`rating-${g}-${re}`,le.textContent=re.toString();const ue=document.createElement("img");if(ue.alt=`face-${g}-${re}`,ue.className=`rating-image${re}`,0===I&&10===O)ue.src=`${d}/${re}.svg`,ue.onerror=()=>ue.src=`${s}/${re}.svg`;else if(1===I&&5===O)switch(re){case 1:ue.src=`${d}/1.svg`,ue.onerror=()=>ue.src=`${s}/1.svg`;break;case 2:ue.src=`${d}/2.svg`,ue.onerror=()=>ue.src=`${s}/2.svg`;break;case 3:ue.src=`${d}/6.svg`,ue.onerror=()=>ue.src=`${s}/6.svg`;break;case 4:ue.src=`${d}/9.svg`,ue.onerror=()=>ue.src=`${s}/9.svg`;break;case 5:ue.src=`${d}/10.svg`,ue.onerror=()=>ue.src=`${s}/10.svg`}else{const me=Math.round(10/(O-I)*(re-I));ue.src=`${d}/${me}.svg`,ue.onerror=()=>ue.src=`${s}/${me}.svg`}const pe=document.createElement("input");pe.id=`rating-${g}-${re}`,pe.type="radio",pe.name=g,pe.value=re.toString(),pe.classList.add(p),pe.classList.add("magicfeedback-input"),ce.appendChild(pe),ce.appendChild(ue),ce.appendChild(le),de.appendChild(ce),S.appendChild(de)}if((null==E?void 0:E.extraOption)&&(null==E?void 0:E.extraOptionText)){const he=document.createElement("div");he.classList.add("magicfeedback-rating-option");const fe=document.createElement("label");fe.htmlFor=`rating-${g}-extra`,fe.classList.add("magicfeedback-rating-option-label-container");const ge=document.createElement("label");ge.htmlFor=`rating-${g}-extra`,ge.textContent=null==E?void 0:E.extraOptionText;const ve=document.createElement("img");ve.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",ve.alt=`face-${g}-extra`,ve.className="magicfeedback-rating-image-extra";const be=document.createElement("input");be.id=`rating-${g}-extra`,be.type="radio",be.name=g,be.value="-",be.classList.add(p),be.classList.add("magicfeedback-input"),fe.appendChild(be),fe.appendChild(ve),fe.appendChild(ge),he.appendChild(fe),S.appendChild(he)}u.appendChild(N),u.appendChild(S);break;case n.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:u=document.createElement("div"),p="magicfeedback-rating-number";const P=document.createElement("div");P.classList.add("magicfeedback-rating-number-container");const D=(null==E?void 0:E.max)?Number(null==E?void 0:E.max):5,$=(null==E?void 0:E.min)?Number(null==E?void 0:E.min):1,F=r($,D,null==E?void 0:E.minPlaceholder,null==E?void 0:E.maxPlaceholder,null==E?void 0:E.extraOption);for(let ye=$;ye<=D;ye++){const Ee=document.createElement("div");Ee.classList.add("magicfeedback-rating-number-option");const ke=document.createElement("label");ke.htmlFor=`rating-${g}-${ye}`,ke.classList.add("magicfeedback-rating-number-option-label-container");const Ce=document.createElement("label");Ce.htmlFor=`rating-${g}-${ye}`,Ce.textContent=ye.toString();const xe=document.createElement("input");xe.id=`rating-${g}-${ye}`,xe.type="radio",xe.name=g,xe.value=ye.toString(),xe.classList.add(p),xe.classList.add("magicfeedback-input"),ke.appendChild(xe),ke.appendChild(Ce),Ee.appendChild(ke),P.appendChild(Ee)}if((null==E?void 0:E.extraOption)&&(null==E?void 0:E.extraOptionText)){const we=document.createElement("div");we.classList.add("magicfeedback-rating-number-option");const Te=document.createElement("label");Te.htmlFor=`rating-${g}-extra`,Te.classList.add("magicfeedback-rating-number-option-label-container");const Le=document.createElement("label");Le.htmlFor=`rating-${g}-extra`,Le.textContent=null==E?void 0:E.extraOptionText;const Ae=document.createElement("input");Ae.id=`rating-${g}-extra`,Ae.type="radio",Ae.name=g,Ae.value="-",Ae.classList.add(p),Ae.classList.add("magicfeedback-input"),Te.appendChild(Ae),Te.appendChild(Le),we.appendChild(Te),P.appendChild(we)}u.appendChild(F),u.appendChild(P);break;case n.FEEDBACKAPPANSWERTYPE.RATING_STAR:u=document.createElement("div"),p="magicfeedback-rating-star";const R=function(e,t,i){const n="magicfeedback-rating-star-selected",a=document.createElement("div");a.classList.add("magicfeedback-rating-star-container"),a.style.maxWidth="300px",a.style.margin="auto";for(let t=1;t<=5;t++){const i=document.createElement("label");i.classList.add("magicfeedback-rating-star-option");const s=document.createElement("input");s.id=`rating-${e}-${t}`,s.type="radio",s.name=e,s.value=t.toString(),s.style.position="absolute",s.style.opacity="0",s.style.width="0",s.style.height="0",s.classList.add("magicfeedback-input"),s.addEventListener("change",(()=>{const e=a.querySelectorAll(".rating__star");for(let t=0;t<e.length;t++)t+1<=Number(s.value)?e[t].classList.contains(n)||e[t].classList.add(n):e[t].classList.contains(n)&&e[t].classList.remove(n)})),i.appendChild(s);const o=document.createElement("label");o.htmlFor=`rating-${e}-${t}`,o.classList.add("rating__star"),o.textContent="★",o.style.fontSize="40px",o.style.color="#CCCCCC",o.style.cursor="pointer",i.appendChild(o),a.appendChild(i)}return a.appendChild(r(1,5,t,i,!1,!1)),a}(g,null==E?void 0:E.minPlaceholder,null==E?void 0:E.maxPlaceholder);u.appendChild(R);break;case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:u=document.createElement("div"),p="magicfeedback-multiple-choice-image";const M=document.createElement("div");M.classList.add("magicfeedback-multiple-choice-image-container"),M.style.display="flex",M.style.flexDirection="row",M.style.flexWrap="wrap",M.style.justifyContent="center";const _=b.length;let q=1,B=1;switch(_){case 1:case 2:case 3:q=_,B=1;break;case 4:case 5:case 6:B=2,q=Math.ceil(_/B);break;case 7:case 8:case 9:B=3,q=Math.ceil(_/B);break;default:B=4,q=Math.ceil(_/B)}const U=void 0!==(null==E?void 0:E.addTitle)&&(null==E?void 0:E.addTitle),j=void 0!==(null==E?void 0:E.multiOption)&&(null==E?void 0:E.multiOption),Q=void 0!==(null==E?void 0:E.randomPosition)&&(null==E?void 0:E.randomPosition),G=void 0!==(null==E?void 0:E.extraOption)&&(null==E?void 0:E.extraOption);function K(e){try{const{position:t,url:i,value:n}=e,a=document.createElement("label");a.classList.add("magicfeedback-multiple-choice-image-option"),a.style.width=`calc( ${100/q}% - 10px)`,a.style.height=`calc( ${100/B}% - 10px)`,a.style.margin="5px";const s=document.createElement("label");s.htmlFor=`rating-${g}-${t}`,s.classList.add("magicfeedback-image-option-label-container"),s.style.display="flex",s.style.flexDirection="column",s.addEventListener("mouseover",(()=>{s.style.border="2px solid #000"})),s.addEventListener("mouseout",(()=>{s.style.border="none"})),s.addEventListener("click",(()=>{s.style.border="2px solid #000"}));const o=document.createElement("label");o.textContent=n,o.classList.add("magicfeedback-multiple-choice-image-label");const r=document.createElement("input");r.id=`rating-${g}-${t}`,r.type=j?"checkbox":"radio",r.name=g,r.value=n,r.style.position="absolute",r.style.opacity="0",r.style.width="0",r.style.height="0",r.classList.add("magicfeedback-input");const d=document.createElement("img");d.classList.add("magicfeedback-multiple-choice-image-image"),d.src=i,d.style.cursor="pointer",d.style.backgroundSize="cover",d.style.backgroundPosition="center",d.style.width="100%",d.style.height="100%",d.style.objectFit="cover",d.style.margin="auto",s.appendChild(r),s.appendChild(d),U&&s.appendChild(o),a.appendChild(s),M.appendChild(a)}catch(e){console.error(e)}}Q&&(b=b.sort((()=>Math.random()-.5))),b.forEach((e=>K(JSON.parse(e)))),G&&(null==E?void 0:E.extraOptionValue)&&(null==E?void 0:E.extraOptionValue.length)>0&&K(null==E?void 0:E.extraOptionValue[0]),u.appendChild(M);break;case n.FEEDBACKAPPANSWERTYPE.SELECT:u=document.createElement("select"),p="magicfeedback-select";const W=document.createElement("option");W.value="",W.text="slim"===t?o(h,i):y||"Select an option",W.disabled=!0,W.selected=!0,u.appendChild(W),b.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,u.appendChild(t)}));break;case n.FEEDBACKAPPANSWERTYPE.DATE:u=document.createElement("input"),u.type="date",u.required=v,u.placeholder=C||a.placeholder.date(i||"en"),p="magicfeedback-date";break;case n.FEEDBACKAPPANSWERTYPE.CONSENT:u=document.createElement("input"),p="magicfeedback-consent",u.type="checkbox",u.id=`magicfeedback-${m}`,u.name=g,u.value="true",u.required=v,u.classList.add("magicfeedback-consent"),u.classList.add("magicfeedback-input");break;case n.FEEDBACKAPPANSWERTYPE.EMAIL:u=document.createElement("input"),u.type="email",u.required=v,u.placeholder=C||"you@example.com",p="magicfeedback-email";break;case n.FEEDBACKAPPANSWERTYPE.PASSWORD:u=document.createElement("input"),u.type="password",u.required=v,u.placeholder=C||a.placeholder.password(i||"en"),p="magicfeedback-password";break;case n.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:u=document.createElement("div"),p="magicfeedback-multi-question-matrix";const Y=document.createElement("div");Y.classList.add("magicfeedback-multi-question-matrix-container");const H=document.createElement("table");H.classList.add("magicfeedback-multi-question-matrix-table");const V=document.createElement("thead");V.classList.add("magicfeedback-multi-question-matrix-header"),V.style.paddingBottom="15px";const z=document.createElement("tr");["",...b].forEach((e=>{const t=document.createElement("th");t.textContent=e,t.style.padding="0 10px 10px 10px ",z.appendChild(t)})),V.appendChild(z);const J=document.createElement("tbody");(null===(l=null==E?void 0:E.options)||void 0===l?void 0:l.length)>0&&(null==E||E.options.split("|").forEach((e=>{const t=document.createElement("tr");t.style.paddingBottom="15px";const i=document.createElement("td");i.classList.add("magicfeedback-multi-question-matrix-row-label");const n=document.createElement("label");n.classList.add("magicfeedback-multi-question-matrix-label"),n.style.paddingRight="15px",n.textContent=e,i.appendChild(n),t.appendChild(i),b.forEach((i=>{const n=document.createElement("td"),a=document.createElement("input");a.type="radio",a.name=`${g}-${e}`,a.value=i,a.id=`matrix-${e}`,a.classList.add("magicfeedback-input"),a.style.padding="0 10px",n.appendChild(a),t.appendChild(n)})),J.appendChild(t)}))),H.appendChild(V),H.appendChild(J),Y.appendChild(H),u.appendChild(Y);break;case n.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:u=document.createElement("div"),p="magicfeedback-priority-list";const X=document.createElement("div");X.classList.add("magicfeedback-priority-list-container");const Z=document.createElement("ul");Z.classList.add("magicfeedback-priority-list-list"),b.forEach(((e,t)=>{const i=document.createElement("li");i.classList.add("magicfeedback-priority-list-item"),i.style.display="flex",i.style.justifyContent="space-between",i.style.alignItems="center",i.style.margin="5px";const n=document.createElement("input");n.classList.add("magicfeedback-input-magicfeedback-priority-list"),n.classList.add("magicfeedback-input"),n.type="hidden",n.id=`priority-list-${g}`,n.name=g,n.value=`${t+1}. ${e}`,i.appendChild(n);const a=document.createElement("label");a.classList.add("magicfeedback-priority-list-item-label"),a.textContent=`${t+1}. ${e}`,i.appendChild(a);const s=document.createElement("div");s.style.display="flex",s.style.alignItems="center",s.style.justifyContent="space-between";const o=document.createElement("img");o.classList.add("magicfeedback-priority-list-arrow-up"),o.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",o.style.width="20px",o.style.height="20px",o.style.cursor="pointer",o.style.margin="0 5px",o.style.color="#000",o.style.visibility=0===t?"hidden":"visible",o.addEventListener("click",(()=>{var t,s;const d=i.previousElementSibling;if(d){const c=Number(n.value.split(".")[0])-1;n.value=`${c}. ${e}`,a.textContent=`${c}. ${e}`,o.style.visibility=1===c?"hidden":"visible",r.style.visibility=c===b.length?"hidden":"visible";const l=d.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=d.querySelector(".magicfeedback-priority-list-item-label"),p=d.querySelector(".magicfeedback-priority-list-arrow-up"),m=d.querySelector(".magicfeedback-priority-list-arrow-down");if(l&&u&&p&&m){const e=Number(l.value.split(".")[0])+1;l.value=`${e}.${null===(t=u.textContent)||void 0===t?void 0:t.split(".")[1]}`,u.textContent=`${e}.${null===(s=u.textContent)||void 0===s?void 0:s.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",m.style.visibility=e===b.length?"hidden":"visible"}Z.insertBefore(i,d)}})),s.appendChild(o);const r=document.createElement("img");r.classList.add("magicfeedback-priority-list-arrow-down"),r.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",r.style.width="20px",r.style.height="20px",r.style.cursor="pointer",r.style.margin="0 5px",r.style.color="#000",r.style.transform="rotate(180deg)",r.style.visibility=t===b.length-1?"hidden":"visible",r.addEventListener("click",(()=>{var t,s;const d=i.nextElementSibling;if(d){const c=Number(n.value.split(".")[0])+1;n.value=c.toString(),a.textContent=`${c.toString()}. ${e}`,o.style.visibility=1===c?"hidden":"visible",r.style.visibility=c===b.length?"hidden":"visible";const l=d.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=d.querySelector(".magicfeedback-priority-list-item-label"),p=d.querySelector(".magicfeedback-priority-list-arrow-up"),m=d.querySelector(".magicfeedback-priority-list-arrow-down");if(l&&u&&p&&m){const e=Number(l.value.split(".")[0])-1;l.value=`${e}.${null===(t=u.textContent)||void 0===t?void 0:t.split(".")[1]}`,u.textContent=`${e}.${null===(s=u.textContent)||void 0===s?void 0:s.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",m.style.visibility=e===b.length?"hidden":"visible"}Z.insertBefore(d,i)}})),s.appendChild(r),i.appendChild(s),Z.appendChild(i)})),X.appendChild(Z),u.appendChild(X);break;case n.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:u=document.createElement("div"),p="magicfeedback-point-system";const ee=document.createElement("div");ee.classList.add("magicfeedback-point-system-container");const te=document.createElement("ul");te.classList.add("magicfeedback-point-system-list"),te.style.padding="0";const ie=100,ne=ie/b.length,ae=document.createElement("div");ae.classList.add("magicfeedback-error"),ae.textContent=a.placeholder.pointsystemerror(i||"en"),ae.style.color="#C70039",ae.style.fontSize="14px",ae.style.textAlign="right",ae.style.width="100%",ae.style.display="none";const se=document.createElement("div");se.classList.add("magicfeedback-point-system-total"),se.textContent="0 / 100 %",se.style.textAlign="right",se.style.fontSize="15px",se.style.marginTop="5px",b.forEach(((e,t)=>{const i=document.createElement("li");i.classList.add("magicfeedback-point-system-item"),i.style.display="flex",i.style.justifyContent="space-between",i.style.alignItems="center",i.style.margin="5px";const n=document.createElement("label");n.textContent=e,n.style.fontSize="15px",i.appendChild(n);const a=document.createElement("span");a.classList.add("magicfeedback-point-system-input-container");const s=document.createElement("input");s.name=g,s.id=`point-system-${e}`,s.type="number",s.min="0",s.max=`${ie}`,s.value="0",s.classList.add("magicfeedback-input"),s.style.width="40px",s.style.border="0",s.style.textAlign="center",s.style.margin="0 5px",s.autofocus=0===t;const o=document.createElement("span");o.textContent="%",o.style.color="#000",s.addEventListener("input",(()=>{const e=te.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>ie&&(s.value=`${ne}%`,t-=Number(s.value));const i=document.getElementById("magicfeedback-submit");i&&(t<100?(se.style.color="orange",i.setAttribute("disabled","true")):(ae.style.display="none",se.style.color="green",i.removeAttribute("disabled"))),se.textContent=`${t} / 100 %`})),s.addEventListener("focus",(()=>{const e=document.getElementById("magicfeedback-submit");e&&(e.setAttribute("disabled","true"),e.addEventListener("pointerover",(()=>{const e=te.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t<100&&(ae.style.display="block")})))})),a.appendChild(s),a.appendChild(o),i.appendChild(a),te.appendChild(i)})),ee.appendChild(te),ee.appendChild(se),ee.appendChild(ae),u.appendChild(ee);break;case n.FEEDBACKAPPANSWERTYPE.INFO_PAGE:u=document.createElement("div"),p="magicfeedback-info-page";const oe=document.createElement("div");oe.classList.add("magicfeedback-info-message"),oe.innerHTML=C,u.appendChild(oe);break;default:return k}u.id=`magicfeedback-${m}`,u.setAttribute("name",g),u.classList.add(p),(void 0!==y||null!==x)&&(u.value=x||y),["RADIO","MULTIPLECHOICE"].includes(f)||(u.classList.add("magicfeedback-input"),u.required=v);const L=document.createElement("label");if(L.setAttribute("for",`magicfeedback-${m}`),L.textContent=o(h,i),L.classList.add("magicfeedback-label"),["CONSENT"].includes(f))k.classList.add("magicfeedback-consent-container"),k.appendChild(u),k.appendChild(L);else{if("slim"!==t&&([n.FEEDBACKAPPANSWERTYPE.INFO_PAGE].includes(f)||k.appendChild(L),void 0!==(null==E?void 0:E.general)&&""!==(null==E?void 0:E.general))){const Se=document.createElement("img");Se.src=null==E?void 0:E.general,Se.classList.add("magicfeedback-image"),Se.style.maxWidth="auto",Se.style.height="400px",Se.style.margin="10px 0",k.appendChild(Se)}if("LONGTEXT"===f&&w>0){const Oe=document.createElement("div");if(Oe.classList.add("magicfeedback-counter"),Oe.textContent=`${u.value.length}/${w}`,Oe.style.textAlign="right",Oe.style.fontSize="15px",Oe.style.marginTop="5px",u.addEventListener("input",(()=>{Oe.textContent=`${u.value.length}/${w}`})),k.appendChild(u),k.appendChild(Oe),(null==E?void 0:E.extraOption)&&(null==E?void 0:E.extraOptionText)){const Ie=document.createElement("div");Ie.classList.add("magicfeedback-skip-container"),Ie.classList.add("magicfeedback-checkbox-container"),Ie.style.display="flex",Ie.style.justifyContent="flex-start";const Ne=document.createElement("input");Ne.classList.add("magicfeedback-skip"),Ne.type="checkbox",Ne.id=`skip-${g}`,Ne.name=g,Ne.value="-",Ne.style.cursor="pointer";const Pe=document.createElement("label");Pe.htmlFor=`skip-${g}`,Pe.textContent=null==E?void 0:E.extraOptionText,Pe.style.fontSize="15px",Pe.style.cursor="pointer",Pe.style.margin="0 5px",Ne.addEventListener("click",(()=>{u.value="-",c&&c()})),Ie.appendChild(Ne),Ie.appendChild(Pe),k.appendChild(Ie)}}else k.appendChild(u)}return k}(t,i,d,`${s}${p?`/${m}`:""}`,l);u.push(e)}})),u},t.renderActions=function(e="",t,i="Submit",n="Back",a="Next"){const s=document.createElement("div");s.classList.add("magicfeedback-action-container");const o=document.createElement("button");o.id="magicfeedback-submit",o.type="submit",o.classList.add("magicfeedback-submit"),o.textContent="MAGICSURVEY"===e?a||"Next":i||"Submit";const r=document.createElement("button");return r.id="magicfeedback-back",r.type="button",r.classList.add("magicfeedback-back"),r.textContent=n||"Back",r.addEventListener("click",t),r.addEventListener("click",(()=>{o.removeAttribute("disabled")})),"MAGICSURVEY"===e&&s.appendChild(r),s.appendChild(o),s},t.renderError=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-error"),t.textContent=e,t},t.renderSuccess=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-success"),t.textContent=e,t},t.renderStartMessage=function(e,t=!1,i="Go!",n=(()=>{})){const a=document.createElement("div");a.classList.add("magicfeedback-start-message-container");const s=document.createElement("div");if(s.classList.add("magicfeedback-start-message"),s.innerHTML=e,a.appendChild(s),t){const e=document.createElement("button");e.id="magicfeedback-start-message-button",e.classList.add("magicfeedback-start-message-button"),e.textContent=i,e.addEventListener("click",(()=>n())),a.appendChild(e)}return a}},341:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function o(e){try{d(n.next(e))}catch(e){s(e)}}function r(e){try{d(n.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}d((n=n.apply(e,t||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFollowUpQuestion=t.sendFeedback=t.getQuestions=t.getSessionForm=t.getForm=t.validateEmail=void 0;const s=a(i(31)),o=a(i(147)),r=i(374),d={Accept:"application/json","Magicfeedback-Sdk-Version":o.default.version};t.validateEmail=function(e){return/\S+@\S+\.\S+/.test(e)},t.getForm=function(e,t,i,a){return n(this,void 0,void 0,(function*(){try{const n=yield(0,s.default)(e+r.endpoints.sdk.app_info(t,i),{method:"GET",headers:d});if(n.ok){const e=yield n.json();return a.log(`Received form for app ${t}`,e),e}throw a.err(`Failed to get questions for app ${t}:`,n.status,n.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return a.err(e),null}}))},t.getSessionForm=function(e,t,i){return n(this,void 0,void 0,(function*(){try{const n=yield(0,s.default)(e+r.endpoints.sdk.session(t),{method:"GET",headers:d});if(n.ok){const e=yield n.json();return i.log(`Received form for session ${t}`,e),e}throw i.err(`Failed to get questions for session ${t}:`,n.status,n.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return i.err(e),null}}))},t.getQuestions=function(e,t,i,a){return n(this,void 0,void 0,(function*(){try{const n=yield(0,s.default)(e+r.endpoints.sdk.app(t,i),{method:"GET",headers:d});if(n.ok){const e=yield n.json();return a.log(`Received questions for app ${t}`,e),e}throw a.err(`Failed to get questions for app ${t}:`,n.status,n.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return a.err(e),[]}}))},t.sendFeedback=function(e,t,i){return n(this,void 0,void 0,(function*(){try{const n=yield(0,s.default)(e+r.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},d),body:JSON.stringify(t)});if(n.ok)return i.log(`Form ${t.integration} submitted successfully!`),(yield n.json()).sessionId;throw i.err(`Failed to submit form ${t.integration}:`,n.status,n.statusText),new Error(n.statusText)}catch(e){return i.err(e),""}}))},t.getFollowUpQuestion=function(e,t,i){return n(this,void 0,void 0,(function*(){try{const n=yield(0,s.default)(e+r.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},d),body:JSON.stringify(t)});if(n.ok)return i.log(`Received follow up question for form ${t.integration}`),(yield n.json())||"";throw i.err(`Failed to get follow up question for form ${t.integration}:`,n.status,n.statusText),new Error(n.statusText)}catch(e){return i.err(e),""}}))}},5:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Log=void 0,t.Log=class{constructor(e){this.config=e}log(...e){this.config.get("debug")&&console.log("[MagicFeedback]:",...e)}err(...e){console.error("[MagicFeedback]:",...e)}}},31:e=>{e.exports=require("cross-fetch")},147:e=>{e.exports=JSON.parse('{"name":"@magicfeedback/native","version":"1.3.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","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","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"}}')}},t={},i=function i(n){var a=t[n];if(void 0!==a)return a.exports;var s=t[n]={exports:{}};return e[n].call(s.exports,s,s.exports,i),s.exports}(607);return i.default})()));
|
|
1
|
+
!function(e,t){"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()}(global,(()=>(()=>{"use strict";var e={290:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HOST_API_URL_DEV=t.HOST_API_URL=void 0,t.HOST_API_URL="https://api.magicfeedback.io/",t.HOST_API_URL_DEV="https://api-dev.magicfeedback.io/"},607:function(e,t,i){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=n(i(519));let s=null;s||(s=(0,a.default)()),t.default=s},519:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function o(e){try{d(n.next(e))}catch(e){s(e)}}function r(e){try{d(n.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}d((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const a=i(954),s=i(712),o=i(5),r=i(341),d=i(290);t.default=function(){const e=new s.Config;let t;return{init:function(i){(null==i?void 0:i.debug)&&e.set("debug",null==i?void 0:i.debug),e.set("url",(null==i?void 0:i.env)&&"dev"===(null==i?void 0:i.env)?d.HOST_API_URL_DEV:d.HOST_API_URL),t=new o.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,a,s,o=!0,d,c){return n(this,void 0,void 0,(function*(){i||t.err("No appID provided"),a||t.err("No publicKey provided"),s||t.err("No feedback provided"),s.answers||s.profile||s.metrics||s.metadata||t.err("No feedback data provided");const n=e.get("url"),l={integration:i,publicKey:a,privateKey:c,completed:o,id:d,feedback:s};try{const e=yield(0,r.sendFeedback)(n,l,t);return t.log("sent native feedback"),e}catch(e){return t.err("error native feedback",e),!1}}))},form:function(i,n){return i||t.err("No appID provided"),n||t.err("No publicKey provided"),new a.Form(e,i,n)},session:function(i){return i||t.err("No sessionId provided"),new a.Form(e,i)}}}},314:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.History=void 0,t.History=class{constructor(){this.items=[]}enqueue(e){this.items.push(e)}dequeue(){return this.items.shift()}rollback(){return this.items.pop()}front(){return this.items[0]}back(){return this.items[this.items.length-1]}isEmpty(){return 0===this.items.length}size(){return this.items.length}}},712:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Config=void 0,t.Config=class{constructor(){this.variables={},this.variables.env="prod",this.variables.debug=!1}get(e){return this.variables[e]}set(e,t){this.variables[e]=t}}},954:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function o(e){try{d(n.next(e))}catch(e){s(e)}}function r(e){try{d(n.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}d((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const a=i(5),s=i(341),o=i(183),r=i(24),d=i(804),c=i(116),l=i(314),u=i(457);t.Form=class{constructor(e,t,i){this.config=e,this.log=new a.Log(e),this.formOptionsConfig={addButton:!0,sendButtonText:"Send",backButtonText:"Back",nextButtonText:"Next",addSuccessScreen:!0,getMetaData:!0,questionFormat:"standard"},this.selector="",this.appId=t,this.publicKey=i||"",this.url=e.get("url"),this.id="",this.formData=null,""!==this.publicKey&&this.getDataFromStorage(),this.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.history=new l.History,this.graph=new r.PageGraph([]),this.progress=0,this.total=0,this.completed=!1}getDataFromStorage(){const e=localStorage.getItem(`magicfeedback-${this.appId}`);e&&new Date(JSON.parse(e).savedAt)<new Date((new Date).getTime()+864e5)&&(this.formData=JSON.parse(e),(0,s.getForm)(this.url,this.appId,this.publicKey,this.log).then((e=>{var t,i,n,a,s;if((null==e?void 0:e.updatedAt)&&(null===(t=this.formData)||void 0===t?void 0:t.savedAt)&&(null==e?void 0:e.updatedAt)>(null===(i=this.formData)||void 0===i?void 0:i.savedAt)){if(this.formData=e,this.formData.savedAt=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}`);this.formData.pages&&0!==(null===(n=this.formData.pages)||void 0===n?void 0:n.length)||this.formatPages(),null===(a=this.formData.questions)||void 0===a||a.sort(((e,t)=>e.position-t.position)),this.formData.pages=this.formData.pages.filter((e=>{var t;return(null===(t=e.integrationQuestions)||void 0===t?void 0:t.length)>0})),(null===(s=this.formData.style)||void 0===s?void 0:s.startMessage)?this.generateWelcomeMessage(this.formData.style.startMessage):this.startForm()}})))}generate(e,t){var i,a,o;return n(this,void 0,void 0,(function*(){try{if(this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e,void 0!==this.formData&&this.formData||(this.formData=""!==this.publicKey?yield(0,s.getForm)(this.url,this.appId,this.publicKey,this.log):yield(0,s.getSessionForm)(this.url,this.appId,this.log)),void 0===this.formData||!this.formData)throw new Error(`No form for app ${this.appId}`);if(this.formData.savedAt||(this.formData.savedAt=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}`);this.formData.pages&&0!==(null===(i=this.formData.pages)||void 0===i?void 0:i.length)||this.formatPages(),null===(a=this.formData.questions)||void 0===a||a.sort(((e,t)=>e.position-t.position)),this.formData.pages=this.formData.pages.filter((e=>{var t;return(null===(t=e.integrationQuestions)||void 0===t?void 0:t.length)>0})),this.formOptionsConfig.getMetaData&&this.getMetaData(),(null===(o=this.formData.style)||void 0===o?void 0:o.startMessage)?yield this.generateWelcomeMessage(this.formData.style.startMessage):this.startForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}formatPages(){var e;if(this.formData)switch(this.formData.identity){case"MAGICSURVEY":this.formData.pages=[],null===(e=this.formData.questions)||void 0===e||e.forEach((e=>{var t,i;const n=new c.PageRoute(e.id,e.ref,c.OperatorType.NOEQUAL,null,c.TransitionType.PAGE,(e.position+1).toString(),e.position.toString()),a=new d.Page(e.position.toString(),e.position,this.appId,[e],[n]);null===(i=null===(t=this.formData)||void 0===t?void 0:t.pages)||void 0===i||i.push(a)}));break;case"MAGICFORM":const t=new d.Page("1",1,this.appId,this.formData.questions,[]);this.formData.pages=[t]}}generateContainer(){let e=document.getElementById(this.selector);if(!e&&(e=document.getElementById("magicfeedback-container-"+this.appId),!e))throw new Error(`Element with ID '${this.selector}' not found.`);return e.classList.add("magicfeedback-container"),e.id="magicfeedback-container-"+this.appId,e.innerHTML="",e}generateForm(){var e,t,i,a;return n(this,void 0,void 0,(function*(){try{if(!this.formData||!this.formData.pages||0===this.formData.pages.length)throw new Error("No form data");this.graph=new r.PageGraph(this.formData.pages.sort(((e,t)=>e.position-t.position)));let n=this.generateContainer();const s=document.createElement("form");s.classList.add("magicfeedback-form"),s.id="magicfeedback-"+this.appId;const d=document.createElement("div");d.classList.add("magicfeedback-questions"),d.id="magicfeedback-questions-"+this.appId;const c=this.graph.getFirstPage();if(!c)throw new Error("No page found");if(this.total=this.graph.findMaxDepth(),c.elements=(0,o.renderQuestions)(c.questions,this.formOptionsConfig.questionFormat,null===(e=this.formData)||void 0===e?void 0:e.lang[0],null===(t=this.formData)||void 0===t?void 0:t.product,(()=>this.send())),null===(i=c.elements)||void 0===i||i.forEach((e=>d.appendChild(e))),s.appendChild(d),this.history.enqueue(c),n.appendChild(s),this.progress=this.history.size(),this.formOptionsConfig.addButton){const e=(0,o.renderActions)(null===(a=this.formData)||void 0===a?void 0:a.identity,(()=>this.back()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);s.appendChild(e)}this.formOptionsConfig.addButton&&s.addEventListener("submit",(e=>{e.preventDefault(),this.send()})),this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}))}startForm(){this.generateForm()}generateWelcomeMessage(e){return n(this,void 0,void 0,(function*(){try{const t=this.generateContainer(),i=(0,o.renderStartMessage)(e,this.formOptionsConfig.addButton,this.formOptionsConfig.startButtonText,(()=>this.startForm()));t.appendChild(i),this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,formData:this.formData}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}))}getMetaData(){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]})}send(e,t,i){return n(this,void 0,void 0,(function*(){const n=document.getElementById("magicfeedback-questions-"+this.appId);try{i&&(this.feedback.profile=[...this.feedback.profile,...i]),t&&(this.feedback.metrics=[...this.feedback.metrics,...t]),e&&(this.feedback.metadata=[...this.feedback.metadata,...e]),this.answer(),this.formOptionsConfig.beforeSubmitEvent&&(yield this.formOptionsConfig.beforeSubmitEvent({loading:!0,progress:this.progress,total:this.total}));const a=this.history.back();if(!a)throw new Error("No page found");const s=a.getRequiredQuestions();for(const e of s)if(!this.feedback.answers.find((t=>t.key===e&&t.value.length>0)))throw this.log.err(`The question ${e} is required`),new Error("No response");const o=yield this.pushAnswers(!1);if(!o)throw new Error("No response");this.id=o,yield this.processNextQuestion(n)}catch(e){this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({loading:!1,progress:this.progress,total:this.total,error:e}))}}))}answer(){const e=document.getElementById("magicfeedback-"+this.appId);if(!e)return this.log.err(`Form "${e}" not found.`),void(this.feedback.answers=[]);if(!this.history.back())throw new Error("No page found");const t=[];let i=!1;e.querySelectorAll(".magicfeedback-input").forEach((e=>{const n=e.type,a=e.classList[0],o={key:e.name,value:[]},r="magicfeedback-consent"===a?e.checked.toString():e.value;if(o.key&&""!==o.key)switch(n){case"radio":case"checkbox":if("magicfeedback-consent"===a||e.checked){o.value.push(r);const e=t.findIndex((e=>e.key===o.key));-1!==e?t[e].value=[...t[e].value,...o.value]:t.push(o)}break;default:if(""!==r){if("email"===n){if(!(0,s.validateEmail)(r)){this.log.err("Invalid email"),i=!0;break}this.feedback.profile.push({key:"email",value:[r]})}if(e.id.includes("point-system")){const t="point-system-"+e.id.split("-")[e.id.split("-").length-1];o.value.push(`${t}: ${r}%`)}else o.value.push(r);const a=t.findIndex((e=>e.key===o.key));-1!==a?t[a].value=[...t[a].value,...o.value]:t.push(o)}}}));const n=t.filter((e=>e.key.includes("matrix")));null==n||n.forEach((e=>{const i=t.find((t=>t.key===e.key));i&&(i.value=[...new Set(i.value)])}));const a=t.filter((e=>e.key.includes("point-system")));null==a||a.forEach((e=>{100!==e.value.reduce(((e,t)=>{const i=t.split(": ")[1];return e+Number(i.replace("%",""))}),0)&&(this.log.err("The sum of the point system questions must be 100%"),i=!0)})),this.feedback.answers=i?[]:t}finish(){return n(this,void 0,void 0,(function*(){if(this.completed=!0,this.formOptionsConfig.addSuccessScreen){const e=document.getElementById("magicfeedback-container-"+this.appId);e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,o.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}this.answer();const e=yield this.pushAnswers(!0);if(!e)throw new Error("No response");this.id=e,this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:this.id,loading:!1,progress:this.progress,total:this.total,completed:this.completed,error:null}))}))}pushAnswers(e=!1){return n(this,void 0,void 0,(function*(){try{const t=this.config.get("url"),i={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,s.sendFeedback)(t,this.id?Object.assign(Object.assign({},i),{sessionId:this.id}):i,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){var t;return n(this,void 0,void 0,(function*(){if(!(null==e?void 0:e.followup))return null;try{if(0===this.feedback.answers.length)throw new Error("No answers provided");const i=this.config.get("url"),n={answer:null===(t=this.feedback.answers.find((t=>t.key===e.ref)))||void 0===t?void 0:t.value[0],publicKey:this.publicKey,sessionId:this.id,question:e};return yield(0,s.getFollowUpQuestion)(i,n,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e){var t,i,a;return n(this,void 0,void 0,(function*(){const n=this.history.back();if(!n)throw new Error("No page found");const s=n.getFollowupQuestions();if(0===(null==s?void 0:s.length))return void(yield this.renderNextQuestion(e,n));const r=[];for(const e of s){const t=n.questions.find((t=>t.ref===e));if(t){const e=yield this.callFollowUpQuestion(t);e&&r.push(e)}}if(0===r.length)return void(yield this.renderNextQuestion(e,n));const c=new d.Page(n.id,n.position,this.appId,r,n.edges),l=new u.PageNode(n.id,n.position,n.edges,c,r,!0);l.elements=(0,o.renderQuestions)(r,this.formOptionsConfig.questionFormat,null===(t=this.formData)||void 0===t?void 0:t.lang[0],null===(i=this.formData)||void 0===i?void 0:i.product,(()=>this.send())),this.history.enqueue(l),this.progress=this.history.size(),e.removeChild(e.childNodes[0]),null===(a=l.elements)||void 0===a||a.forEach((t=>e.appendChild(t))),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:this.id,loading:!1,progress:this.progress,total:this.total,followup:l.isFollowup,completed:this.completed,error:null}))}))}renderNextQuestion(e,t){var i,a,s;return n(this,void 0,void 0,(function*(){console.log(t,this.feedback.answers);const n=this.graph.getNextPage(t,this.feedback.answers);console.log(n),n?(n.elements=(0,o.renderQuestions)(n.questions,this.formOptionsConfig.questionFormat,null===(i=this.formData)||void 0===i?void 0:i.lang[0],null===(a=this.formData)||void 0===a?void 0:a.product,(()=>this.send())),e.removeChild(e.childNodes[0]),null===(s=n.elements)||void 0===s||s.forEach((t=>e.appendChild(t))),this.history.enqueue(n),this.progress=this.history.size(),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:this.id,loading:!1,progress:this.progress,total:this.total,followup:n.isFollowup,completed:this.completed,error:null}))):this.finish()}))}back(){var e;return n(this,void 0,void 0,(function*(){if(0===this.history.size())return;const t=document.getElementById("magicfeedback-questions-"+this.appId);t&&t.childNodes.length>0&&t.removeChild(t.childNodes[0]),this.history.rollback(),this.progress=this.history.size();const i=this.history.back();i&&(null===(e=i.elements)||void 0===e||e.forEach((e=>t.appendChild(e)))),this.formOptionsConfig.onBackEvent&&(yield this.formOptionsConfig.onBackEvent({loading:!1,progress:this.progress,followup:(null==i?void 0:i.isFollowup)||!1,error:i?null:"No page found"}))}))}}},804:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Page=void 0,t.Page=class{constructor(e,t,i,n,a){this.id=e,this.position=t,this.generatedAt=(new Date).toISOString(),this.updatedAt=(new Date).toISOString(),this.status="ACTIVE",this.integrationId=i,this.integrationQuestions=n,this.integrationPageRoutes=a}}},24:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PageGraph=void 0;const n=i(457),a=i(116);t.PageGraph=class{constructor(e){this.nodes=new Map,this.buildGraph(e)}buildGraph(e){e.forEach(((t,i)=>{var s,o;if(!t.integrationPageRoutes&&e[i+1]){const n=new a.PageRoute(`${t.id}-default`,(null===(s=t.integrationQuestions[0])||void 0===s?void 0:s.ref)||"",a.OperatorType.DEFAULT,"",a.TransitionType.PAGE,(null===(o=e[i+1])||void 0===o?void 0:o.id)||"",t.id);t.integrationPageRoutes=[n]}const r=new n.PageNode(t.id,t.position,t.integrationPageRoutes||[],t,t.integrationQuestions);this.nodes.set(r.id,r)}))}getNodeById(e){return this.nodes.get(e)}getNextEdgeByDefault(e){if(e)for(const t of this.nodes.values())if(t.position===e.position+1)return t.id}getFirstPage(){let e,t=Number.MAX_VALUE;for(const i of this.nodes.values())i.position<t&&(t=i.position,e=i);return e}getNextPage(e,t){if(!e)return;e.edges.sort(((e,t)=>"DIRECT"===e.typeCondition?1:"DIRECT"===t.typeCondition?-1:0));const i=e.edges.find((e=>{const i=null==t?void 0:t.filter((t=>t.key===e.questionRef));if(!i)return!1;if("DIRECT"===e.typeCondition)return!0;switch(e.typeOperator){case a.OperatorType.EQUAL:return i.find((t=>{var i;return null===(i=t.value)||void 0===i?void 0:i.includes(e.value)}));case a.OperatorType.NOEQUAL:return!i.find((t=>{var i;return null===(i=t.value)||void 0===i?void 0:i.includes(e.value)}));case a.OperatorType.GREATER:return i.find((t=>t.value.find((t=>Number(t)>Number(e.value)))));case a.OperatorType.LESS:return i.find((t=>t.value.find((t=>Number(t)<Number(e.value)))));case a.OperatorType.GREATEREQUAL:return i.find((t=>t.value.find((t=>Number(t)>=Number(e.value)))));case a.OperatorType.LESSEQUAL:return i.find((t=>t.value.find((t=>Number(t)<=Number(e.value)))));case a.OperatorType.INQ:return i.find((t=>e.value.includes(t.value)));case a.OperatorType.NINQ:return!i.find((t=>e.value.includes(t.value)));default:return!1}}));if(!i){const t=this.getNextEdgeByDefault(e);if(!t)return;return this.getNodeById(t)}switch(i.transition){case a.TransitionType.PAGE:return this.getNodeById(i.transitionDestiny);case a.TransitionType.FINISH:return;case a.TransitionType.REDIRECT:return void(window.location.href=i.transitionDestiny);default:return}}findDepth(e){const t=this.getNodeById(e);if(!t)return 0;const i=new Set;return this.DFSUtil(t,i,0)}findMaxDepth(e){if(e||(e=this.getFirstPage()),!e)return 0;const t=new Set;let i=e.questions.find((e=>e.followup))?2:1;return i=Math.max(i,this.DFSUtil(e,t,i)),i}DFSUtil(e,t,i){t.add(e);let n=i;const a=e.edges||[];for(const e of a){const a=this.getNodeById(e.transitionDestiny);if(a&&!t.has(a)){const e=a.questions.find((e=>e.followup))?i+2:i+1,s=this.DFSUtil(a,t,e);n=Math.max(n,s)}}return n}}},457:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PageNode=void 0,t.PageNode=class{constructor(e,t,i,n,a,s=!1){this.id=e,this.position=t,this.edges=i,this.data=n,this.questions=a,this.elements=[],this.isFollowup=s}getFollowupQuestions(){return this.questions.filter((e=>e.followup)).map((e=>e.ref))}getRequiredQuestions(){return this.questions.filter((e=>e.require)).map((e=>e.ref))}}},116:(e,t)=>{var i,n,a,s;Object.defineProperty(t,"__esModule",{value:!0}),t.PageRoute=t.StatusType=t.OperatorType=t.ConditionType=t.TransitionType=void 0,(s=t.TransitionType||(t.TransitionType={})).PAGE="PAGE",s.FINISH="FINISH",s.REDIRECT="REDIRECT",function(e){e.LOGICAL="LOGICAL",e.DIRECT="DIRECT"}(i=t.ConditionType||(t.ConditionType={})),(a=t.OperatorType||(t.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(e){e.ACTIVE="ACTIVE",e.DEPRECATED="DEPRECATED",e.DELETE="DELETE"}(n=t.StatusType||(t.StatusType={})),t.PageRoute=class{constructor(e,t,a,s,o,r,d,c){this.id=e,this.questionRef=t,this.typeCondition=c||i.LOGICAL,this.typeOperator=a,this.value=s,this.transition=o,this.transitionDestiny=r,this.status=n.ACTIVE,this.generatedAt=new Date,this.updatedAt=new Date,this.integrationPageId=d}}},244:(e,t)=>{var i,n;Object.defineProperty(t,"__esModule",{value:!0}),t.QuestionType=t.FEEDBACKAPPANSWERTYPE=void 0,(n=t.FEEDBACKAPPANSWERTYPE||(t.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",t.QuestionType=class{},function(e){e.FORM="form",e.DIV="div"}(i||(i={}))},374:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.endpoints=void 0,t.endpoints={sdk:{app:(e,t)=>`sdk/app/${e}/${t}`,app_info:(e,t)=>`sdk/app/${e}/${t}/info`,session:e=>`sdk/app/session/${e}/info`,feedback:"sdk/feedback",followUpQuestion:"sdk/followUpQuestion"}}},528:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.placeholder=void 0,t.placeholder={answer:e=>{switch(e){case"en":default:return"Write your answer here...";case"es":return"Escribe tu respuesta aquí...";case"da":return"Skriv dit svar her...";case"fi":return"Kirjoita vastauksesi tähän...";case"sv":return"Skriv ditt svar här...";case"no":return"Skriv svaret ditt her...";case"ar":return"اكتب إجابتك هنا...";case"bn":return"এখানে আপনার"}},number:e=>{switch(e){case"en":default:return"Write your number here...";case"es":return"Escribe tu número aquí...";case"da":return"Skriv dit nummer her...";case"fi":return"Kirjoita numerosi tähän...";case"sv":return"Skriv ditt nummer här...";case"no":return"Skriv nummeret ditt her...";case"ar":return"اكتب رقمك هنا...";case"bn":return"এখানে আপনার"}},email:e=>{switch(e){case"en":default:return"Write your email here...";case"es":return"Escribe tu correo electrónico aquí...";case"da":return"Skriv din e-mail her...";case"fi":return"Kirjoita sähköpostiosoitteesi tähän...";case"sv":return"Skriv din e-post här...";case"no":return"Skriv e-posten din her...";case"ar":return"اكتب بريدك الإلكتروني هنا...";case"bn":return"এখানে আপনার"}},date:e=>{switch(e){case"en":default:return"Write your date here...";case"es":return"Escribe tu fecha aquí...";case"da":return"Skriv din dato her...";case"fi":return"Kirjoita päivämääräsi tähän...";case"sv":return"Skriv ditt datum här...";case"no":return"Skriv datoen din her...";case"ar":return"اكتب تاريخك هنا...";case"bn":return"এখানে আপনার"}},password:e=>{switch(e){case"en":default:return"Write your password here...";case"es":return"Escribe tu contraseña aquí...";case"da":return"Skriv dit kodeord her...";case"fi":return"Kirjoita salasanasi tähän...";case"sv":return"Skriv ditt lösenord här...";case"no":return"Skriv passordet ditt her...";case"ar":return"اكتب كلمة المرور الخاصة بك هنا...";case"bn":return"এখানে আপনার"}},pointsystemerror:e=>{switch(e){case"en":default:return"The total points must be 100 %";case"es":return"El total de puntos debe ser 100 %";case"da":return"Samlet antal point skal være 100 %";case"fi":return"Kokonaispisteiden on oltava 100 %";case"sv":return"Totala poäng måste vara 100 %";case"no":return"Totalt antall poeng må være 100 %";case"ar":return"يجب أن تكون النقاط الإجمالية 100 %";case"bn":return"মোট পয়েন্ট 100 % হতে হবে"}}}},183:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.renderStartMessage=t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0;const n=i(244),a=i(528),s="https://survey-dev.magicfeedback.io/assets/emojis";function o(e,t){return e?"object"==typeof e?e[t]||e.en:e:""}function r(e,t,i,n,a,s=!0){const o=document.createElement("div");o.classList.add("magicfeedback-rating-placeholder"),o.style.display="flex",o.style.justifyContent="space-between",o.style.width=a?`calc(100% - (100% / ${t+1}))`:"100%",o.style.marginRight="auto",s&&window.innerWidth<600&&(o.style.flexDirection="column");const r=document.createElement("span");r.textContent=i,r.classList.add("magicfeedback-rating-placeholder-value"),r.style.fontSize="15px",r.style.textAlign="left",r.style.width="50%",s&&window.innerWidth<600&&(r.textContent=`${e} ➜ ${i}`,r.style.width="100%",r.style.textAlign="left",r.style.marginBottom="5px"),o.appendChild(r);const d=document.createElement("span");return d.textContent=n,d.classList.add("magicfeedback-rating-placeholder-value"),d.style.fontSize="15px",d.style.textAlign="right",d.style.width="50%",s&&window.innerWidth<600&&(d.textContent=`${t} ➜ ${n}`,d.style.width="100%",d.style.textAlign="left",d.style.marginBottom="5px"),o.appendChild(d),o}t.renderQuestions=function e(t,i="standard",d="en",c={customIcons:!1},l){if(!t)throw new Error("[MagicFeedback] No questions provided");const u=[],{customIcons:p,id:m}=c;return t.forEach((t=>{var h,f;if((null===(f=null===(h=null==t?void 0:t.questionType)||void 0===h?void 0:h.conf)||void 0===f?void 0:f.length)>0){let n=document.createElement("div");n.classList.add("magicfeedback-div");const a=document.createElement("label");a.setAttribute("for",`magicfeedback-${t.id}`),a.textContent=o(t.title,d),a.classList.add("magicfeedback-label"),n.appendChild(a),t.questionType.conf.forEach((e=>{e.ref=t.ref,t.assets[e.id]&&(e.assets={placeholder:t.assets[e.id]})})),e(t.questionType.conf,i,d,c,l).forEach((e=>{n.appendChild(e)})),u.push(n)}else{const e=function(e,t,i,d,c){let l,u,{id:p,title:m,type:h,ref:f,require:g,value:v,defaultValue:b,assets:y}=e,E=document.createElement("div");E.classList.add("magicfeedback-div");const k="slim"===t?o(m,i):null==y?void 0:y.placeholder,C=(T=p,new URLSearchParams(window.location.search).get(T)),x=(null==y?void 0:y.maxCharacters)||0,w=void 0!==(null==y?void 0:y.randomPosition)&&(null==y?void 0:y.randomPosition);var T;switch(h){case n.FEEDBACKAPPANSWERTYPE.TEXT:l=document.createElement("input"),l.type="text",l.placeholder=k||a.placeholder.answer(i||"en"),u="magicfeedback-text";break;case n.FEEDBACKAPPANSWERTYPE.LONGTEXT:l=document.createElement("textarea"),l.rows=3,x>0&&(l.maxLength=x),l.placeholder=k||a.placeholder.answer(i||"en"),u="magicfeedback-longtext";break;case n.FEEDBACKAPPANSWERTYPE.NUMBER:l=document.createElement("input"),l.type="number",l.placeholder="slim"===t?o(m,i):a.placeholder.number(i||"en"),u="magicfeedback-number",v.length&&(v.sort(((e,t)=>Number(e)-Number(t))),l.max=v[v.length-1],l.min=v[0],l.value=v[0]);break;case n.FEEDBACKAPPANSWERTYPE.RADIO:case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:l=document.createElement("div"),u="magicfeedback-"+("MULTIPLECHOICE"===h?"checkbox":"radio"),(null==y?void 0:y.extraOption)&&!v.includes(null==y?void 0:y.extraOptionText)&&v.push(null==y?void 0:y.extraOptionText),w&&(v=v.sort((()=>Math.random()-.5))),v.forEach(((e,t)=>{const s=document.createElement("div");s.classList.add(`magicfeedback-${"MULTIPLECHOICE"===h?"checkbox":"radio"}-container`);const o=document.createElement("label"),r=document.createElement("input");if(r.id=`rating-${f}-${t}`,r.type="MULTIPLECHOICE"===h?"checkbox":"radio",r.name=f,r.value=e,r.classList.add(u),r.classList.add("magicfeedback-input"),h===n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE&&(null==y?void 0:y.maxOptions)&&(null==y?void 0:y.maxOptions)>0&&r.addEventListener("change",(()=>{document.querySelectorAll(`input[name="${f}"]:checked`).length>(null==y?void 0:y.maxOptions)&&(r.checked=!1)})),e!==b&&e!==C||(r.checked=!0),o.textContent=e,o.htmlFor=`rating-${f}-${t}`,r.addEventListener("change",(t=>{const i=document.getElementById(`extra-option-${f}`);i&&(null==y?void 0:y.extraOption)&&(t.target.checked&&e===(null==y?void 0:y.extraOptionText)?(v.forEach(((e,t)=>{e!==(null==y?void 0:y.extraOptionText)&&(document.getElementById(`rating-${f}-${t}`).checked=!1)})),i.style.display="block"):(document.getElementById(`rating-${f}-${v.length-1}`).checked=!1,i.style.display="none"))})),s.appendChild(r),s.appendChild(o),l.appendChild(s),(null==y?void 0:y.extraOption)&&e===(null==y?void 0:y.extraOptionText)){const e=document.createElement("input");e.type="text",e.placeholder=(null==y?void 0:y.extraOptionPlaceholder)||a.placeholder.answer(i||"en"),e.classList.add("magicfeedback-extra-option"),e.classList.add("magicfeedback-input"),e.id=`extra-option-${f}`,e.name=`extra-option-${f}`,e.style.display="none",l.appendChild(e)}}));break;case n.FEEDBACKAPPANSWERTYPE.BOOLEAN:l=document.createElement("div"),u="magicfeedback-radio";const S=document.createElement("div");S.classList.add("magicfeedback-boolean-container"),S.style.display="flex",S.style.flexDirection="row",S.style.justifyContent="space-between",S.style.width="70%",S.style.margin="auto",((null==y?void 0:y.addIcon)?["👍","👎"]:function(e){switch(e){case"es":return["Sí","No"];case"fr":return["Oui","Non"];case"de":return["Ja","Nein"];case"it":return["Sì","No"];case"pt":return["Sim","Não"];case"nl":return["Ja","Nee"];case"pl":return["Tak","Nie"];case"ru":return["Да","Нет"];case"ja":return["はい","いいえ"];case"zh":return["是","不"];case"ko":return["예","아니"];case"da":case"sv":return["Ja","Nej"];case"fi":return["Kyllä","Ei"];case"no":return["Ja","Nei"];case"ar":return["نعم","لا"];case"bn":return["হ্যাঁ","না"];default:return["Yes","No"]}}(i)).forEach(((e,t)=>{const i=document.createElement("label");i.classList.add("magicfeedback-boolean-option"),i.htmlFor=`rating-${f}-${t}`,i.style.cursor="pointer",i.style.border="1px solid #000",i.style.display="flex",i.style.justifyContent="center",i.style.alignItems="center",i.style.margin="auto",i.style.padding="0",i.style.width="45%",i.style.height="38px";const n=document.createElement("label");n.htmlFor=`rating-${f}-${t}`,n.textContent=e,n.style.margin="0",n.style.padding="0";const a=document.createElement("input");a.id=`rating-${f}-${t}`,a.type="radio",a.name=f,a.value=e,a.classList.add(u),a.classList.add("magicfeedback-input"),a.style.position="absolute",a.style.opacity="0",a.style.width="0",a.style.height="0",a.style.margin="0",a.addEventListener("change",(()=>{c&&c()})),i.appendChild(a),i.appendChild(n),S.appendChild(i)})),l.appendChild(S);break;case n.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:l=document.createElement("div"),u="magicfeedback-rating";const O=document.createElement("div");O.classList.add("magicfeedback-rating-container");const I=(null==y?void 0:y.max)?Number(null==y?void 0:y.max):5,N=(null==y?void 0:y.min)?Number(null==y?void 0:y.min):1,P=r(N,I,null==y?void 0:y.minPlaceholder,null==y?void 0:y.maxPlaceholder,null==y?void 0:y.extraOption);for(let de=N;de<=I;de++){const ce=document.createElement("div");ce.classList.add("magicfeedback-rating-option");const le=document.createElement("label");le.htmlFor=`rating-${f}-${de}`,le.classList.add("magicfeedback-rating-option-label-container");const ue=document.createElement("label");ue.htmlFor=`rating-${f}-${de}`,ue.textContent=de.toString();const pe=document.createElement("img");if(pe.alt=`face-${f}-${de}`,pe.className=`rating-image${de}`,0===N&&10===I)pe.src=`${d}/${de}.svg`,pe.onerror=()=>pe.src=`${s}/${de}.svg`;else if(1===N&&5===I)switch(de){case 1:pe.src=`${d}/1.svg`,pe.onerror=()=>pe.src=`${s}/1.svg`;break;case 2:pe.src=`${d}/2.svg`,pe.onerror=()=>pe.src=`${s}/2.svg`;break;case 3:pe.src=`${d}/6.svg`,pe.onerror=()=>pe.src=`${s}/6.svg`;break;case 4:pe.src=`${d}/9.svg`,pe.onerror=()=>pe.src=`${s}/9.svg`;break;case 5:pe.src=`${d}/10.svg`,pe.onerror=()=>pe.src=`${s}/10.svg`}else{const he=Math.round(10/(I-N)*(de-N));pe.src=`${d}/${he}.svg`,pe.onerror=()=>pe.src=`${s}/${he}.svg`}const me=document.createElement("input");me.id=`rating-${f}-${de}`,me.type="radio",me.name=f,me.value=de.toString(),me.classList.add(u),me.classList.add("magicfeedback-input"),le.appendChild(me),le.appendChild(pe),le.appendChild(ue),ce.appendChild(le),O.appendChild(ce)}if((null==y?void 0:y.extraOption)&&(null==y?void 0:y.extraOptionText)){const fe=document.createElement("div");fe.classList.add("magicfeedback-rating-option");const ge=document.createElement("label");ge.htmlFor=`rating-${f}-extra`,ge.classList.add("magicfeedback-rating-option-label-container");const ve=document.createElement("label");ve.htmlFor=`rating-${f}-extra`,ve.textContent=null==y?void 0:y.extraOptionText;const be=document.createElement("img");be.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",be.alt=`face-${f}-extra`,be.className="magicfeedback-rating-image-extra";const ye=document.createElement("input");ye.id=`rating-${f}-extra`,ye.type="radio",ye.name=f,ye.value="-",ye.classList.add(u),ye.classList.add("magicfeedback-input"),ge.appendChild(ye),ge.appendChild(be),ge.appendChild(ve),fe.appendChild(ge),O.appendChild(fe)}l.appendChild(P),l.appendChild(O);break;case n.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:l=document.createElement("div"),u="magicfeedback-rating-number";const D=document.createElement("div");D.classList.add("magicfeedback-rating-number-container");const $=(null==y?void 0:y.max)?Number(null==y?void 0:y.max):5,F=(null==y?void 0:y.min)?Number(null==y?void 0:y.min):1,R=r(F,$,null==y?void 0:y.minPlaceholder,null==y?void 0:y.maxPlaceholder,null==y?void 0:y.extraOption);for(let Ee=F;Ee<=$;Ee++){const ke=document.createElement("div");ke.classList.add("magicfeedback-rating-number-option");const Ce=document.createElement("label");Ce.htmlFor=`rating-${f}-${Ee}`,Ce.classList.add("magicfeedback-rating-number-option-label-container");const xe=document.createElement("label");xe.htmlFor=`rating-${f}-${Ee}`,xe.textContent=Ee.toString();const we=document.createElement("input");we.id=`rating-${f}-${Ee}`,we.type="radio",we.name=f,we.value=Ee.toString(),we.classList.add(u),we.classList.add("magicfeedback-input"),Ce.appendChild(we),Ce.appendChild(xe),ke.appendChild(Ce),D.appendChild(ke)}if((null==y?void 0:y.extraOption)&&(null==y?void 0:y.extraOptionText)){const Te=document.createElement("div");Te.classList.add("magicfeedback-rating-number-option");const Ae=document.createElement("label");Ae.htmlFor=`rating-${f}-extra`,Ae.classList.add("magicfeedback-rating-number-option-label-container");const Le=document.createElement("label");Le.htmlFor=`rating-${f}-extra`,Le.textContent=null==y?void 0:y.extraOptionText;const Se=document.createElement("input");Se.id=`rating-${f}-extra`,Se.type="radio",Se.name=f,Se.value="-",Se.classList.add(u),Se.classList.add("magicfeedback-input"),Ae.appendChild(Se),Ae.appendChild(Le),Te.appendChild(Ae),D.appendChild(Te)}l.appendChild(R),l.appendChild(D);break;case n.FEEDBACKAPPANSWERTYPE.RATING_STAR:l=document.createElement("div"),u="magicfeedback-rating-star";const M=function(e,t,i){const n="magicfeedback-rating-star-selected",a=document.createElement("div");a.classList.add("magicfeedback-rating-star-container"),a.style.maxWidth="300px",a.style.margin="auto";for(let t=1;t<=5;t++){const i=document.createElement("label");i.classList.add("magicfeedback-rating-star-option");const s=document.createElement("input");s.id=`rating-${e}-${t}`,s.type="radio",s.name=e,s.value=t.toString(),s.style.position="absolute",s.style.opacity="0",s.style.width="0",s.style.height="0",s.classList.add("magicfeedback-input"),s.addEventListener("change",(()=>{const e=a.querySelectorAll(".rating__star");for(let t=0;t<e.length;t++)t+1<=Number(s.value)?e[t].classList.contains(n)||e[t].classList.add(n):e[t].classList.contains(n)&&e[t].classList.remove(n)})),i.appendChild(s);const o=document.createElement("label");o.htmlFor=`rating-${e}-${t}`,o.classList.add("rating__star"),o.textContent="★",o.style.fontSize="40px",o.style.color="#CCCCCC",o.style.cursor="pointer",i.appendChild(o),a.appendChild(i)}return a.appendChild(r(1,5,t,i,!1,!1)),a}(f,null==y?void 0:y.minPlaceholder,null==y?void 0:y.maxPlaceholder);l.appendChild(M);break;case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:l=document.createElement("div"),u="magicfeedback-multiple-choice-image";const _=document.createElement("div");_.classList.add("magicfeedback-multiple-choice-image-container"),_.style.display="flex",_.style.flexDirection="row",_.style.flexWrap="wrap",_.style.justifyContent="center";const q=v.length;let B=1,U=1;switch(q){case 1:case 2:case 3:B=q,U=1;break;case 4:case 5:case 6:U=2,B=Math.ceil(q/U);break;case 7:case 8:case 9:U=3,B=Math.ceil(q/U);break;default:U=4,B=Math.ceil(q/U)}const j=void 0!==(null==y?void 0:y.addTitle)&&(null==y?void 0:y.addTitle),Q=void 0!==(null==y?void 0:y.multiOption)&&(null==y?void 0:y.multiOption),G=void 0!==(null==y?void 0:y.extraOption)&&(null==y?void 0:y.extraOption);function K(e){try{const{position:t,url:i,value:n}=e,a=document.createElement("label");a.classList.add("magicfeedback-multiple-choice-image-option"),a.style.width=`calc( ${100/B}% - 10px)`,a.style.height=`calc( ${100/U}% - 10px)`,a.style.margin="5px";const s=document.createElement("label");s.htmlFor=`rating-${f}-${t}`,s.classList.add("magicfeedback-image-option-label-container"),s.style.display="flex",s.style.flexDirection="column",s.addEventListener("mouseover",(()=>{s.style.border="2px solid #000"})),s.addEventListener("mouseout",(()=>{s.style.border="none"})),s.addEventListener("click",(()=>{s.style.border="2px solid #000"}));const o=document.createElement("label");o.textContent=n,o.classList.add("magicfeedback-multiple-choice-image-label");const r=document.createElement("input");r.id=`rating-${f}-${t}`,r.type=Q?"checkbox":"radio",r.name=f,r.value=n,r.style.position="absolute",r.style.opacity="0",r.style.width="0",r.style.height="0",r.classList.add("magicfeedback-input");const d=document.createElement("img");d.classList.add("magicfeedback-multiple-choice-image-image"),d.src=i,d.style.cursor="pointer",d.style.backgroundSize="cover",d.style.backgroundPosition="center",d.style.width="100%",d.style.height="100%",d.style.objectFit="cover",d.style.margin="auto",s.appendChild(r),s.appendChild(d),j&&s.appendChild(o),a.appendChild(s),_.appendChild(a)}catch(e){console.error(e)}}w&&(v=v.sort((()=>Math.random()-.5))),v.forEach((e=>K(JSON.parse(e)))),G&&(null==y?void 0:y.extraOptionValue)&&(null==y?void 0:y.extraOptionValue.length)>0&&K(null==y?void 0:y.extraOptionValue[0]),l.appendChild(_);break;case n.FEEDBACKAPPANSWERTYPE.SELECT:l=document.createElement("select"),u="magicfeedback-select";const W=document.createElement("option");W.value="",W.text="slim"===t?o(m,i):b||"Select an option",W.disabled=!0,W.selected=!0,l.appendChild(W),v.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,l.appendChild(t)}));break;case n.FEEDBACKAPPANSWERTYPE.DATE:l=document.createElement("input"),l.type="date",l.required=g,l.placeholder=k||a.placeholder.date(i||"en"),u="magicfeedback-date";break;case n.FEEDBACKAPPANSWERTYPE.CONSENT:l=document.createElement("input"),u="magicfeedback-consent",l.type="checkbox",l.id=`magicfeedback-${p}`,l.name=f,l.value="true",l.required=g,l.classList.add("magicfeedback-consent"),l.classList.add("magicfeedback-input");break;case n.FEEDBACKAPPANSWERTYPE.EMAIL:l=document.createElement("input"),l.type="email",l.required=g,l.placeholder=k||"you@example.com",u="magicfeedback-email";break;case n.FEEDBACKAPPANSWERTYPE.PASSWORD:l=document.createElement("input"),l.type="password",l.required=g,l.placeholder=k||a.placeholder.password(i||"en"),u="magicfeedback-password";break;case n.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:l=document.createElement("div"),u="magicfeedback-multi-question-matrix";const Y=document.createElement("div");Y.classList.add("magicfeedback-multi-question-matrix-container");const H=document.createElement("table");H.classList.add("magicfeedback-multi-question-matrix-table");const V=document.createElement("thead");V.classList.add("magicfeedback-multi-question-matrix-header"),V.style.paddingBottom="15px";const z=document.createElement("tr"),J=document.createElement("th");z.appendChild(J),v.forEach((e=>{const t=document.createElement("th");t.textContent=e,z.appendChild(t)})),V.appendChild(z),H.appendChild(V);const X=document.createElement("tbody");null==y||y.options.split("|").forEach(((e,t)=>{const i=document.createElement("tr"),n=document.createElement("td");n.textContent=e,i.appendChild(n),v.forEach(((e,n)=>{const a=document.createElement("td"),s=document.createElement("input");s.type=Q?"checkbox":"radio",s.name=`matrix-${f}-${t}`,s.value=e,s.id=`matrix-${f}-${t}-${n}`,s.classList.add("magicfeedback-input");const o=document.createElement("label");o.htmlFor=s.id,o.textContent=e,a.appendChild(s),a.appendChild(o),i.appendChild(a)})),X.appendChild(i)})),H.appendChild(X),Y.appendChild(H),l.appendChild(Y);break;case n.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:l=document.createElement("div"),u="magicfeedback-priority-list";const Z=document.createElement("div");Z.classList.add("magicfeedback-priority-list-container");const ee=document.createElement("ul");ee.classList.add("magicfeedback-priority-list-list"),v.forEach(((e,t)=>{const i=document.createElement("li");i.classList.add("magicfeedback-priority-list-item"),i.style.display="flex",i.style.justifyContent="space-between",i.style.alignItems="center",i.style.margin="5px";const n=document.createElement("input");n.classList.add("magicfeedback-input-magicfeedback-priority-list"),n.classList.add("magicfeedback-input"),n.type="hidden",n.id=`priority-list-${f}`,n.name=f,n.value=`${t+1}. ${e}`,i.appendChild(n);const a=document.createElement("label");a.classList.add("magicfeedback-priority-list-item-label"),a.textContent=`${t+1}. ${e}`,i.appendChild(a);const s=document.createElement("div");s.style.display="flex",s.style.alignItems="center",s.style.justifyContent="space-between";const o=document.createElement("img");o.classList.add("magicfeedback-priority-list-arrow-up"),o.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",o.style.width="20px",o.style.height="20px",o.style.cursor="pointer",o.style.margin="0 5px",o.style.color="#000",o.style.visibility=0===t?"hidden":"visible",o.addEventListener("click",(()=>{var t,s;const d=i.previousElementSibling;if(d){const c=Number(n.value.split(".")[0])-1;n.value=`${c}. ${e}`,a.textContent=`${c}. ${e}`,o.style.visibility=1===c?"hidden":"visible",r.style.visibility=c===v.length?"hidden":"visible";const l=d.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=d.querySelector(".magicfeedback-priority-list-item-label"),p=d.querySelector(".magicfeedback-priority-list-arrow-up"),m=d.querySelector(".magicfeedback-priority-list-arrow-down");if(l&&u&&p&&m){const e=Number(l.value.split(".")[0])+1;l.value=`${e}.${null===(t=u.textContent)||void 0===t?void 0:t.split(".")[1]}`,u.textContent=`${e}.${null===(s=u.textContent)||void 0===s?void 0:s.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",m.style.visibility=e===v.length?"hidden":"visible"}ee.insertBefore(i,d)}})),s.appendChild(o);const r=document.createElement("img");r.classList.add("magicfeedback-priority-list-arrow-down"),r.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",r.style.width="20px",r.style.height="20px",r.style.cursor="pointer",r.style.margin="0 5px",r.style.color="#000",r.style.transform="rotate(180deg)",r.style.visibility=t===v.length-1?"hidden":"visible",r.addEventListener("click",(()=>{var t,s;const d=i.nextElementSibling;if(d){const c=Number(n.value.split(".")[0])+1;n.value=c.toString(),a.textContent=`${c.toString()}. ${e}`,o.style.visibility=1===c?"hidden":"visible",r.style.visibility=c===v.length?"hidden":"visible";const l=d.querySelector(".magicfeedback-input-magicfeedback-priority-list"),u=d.querySelector(".magicfeedback-priority-list-item-label"),p=d.querySelector(".magicfeedback-priority-list-arrow-up"),m=d.querySelector(".magicfeedback-priority-list-arrow-down");if(l&&u&&p&&m){const e=Number(l.value.split(".")[0])-1;l.value=`${e}.${null===(t=u.textContent)||void 0===t?void 0:t.split(".")[1]}`,u.textContent=`${e}.${null===(s=u.textContent)||void 0===s?void 0:s.split(".")[1]}`,p.style.visibility=1===e?"hidden":"visible",m.style.visibility=e===v.length?"hidden":"visible"}ee.insertBefore(d,i)}})),s.appendChild(r),i.appendChild(s),ee.appendChild(i)})),Z.appendChild(ee),l.appendChild(Z);break;case n.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:l=document.createElement("div"),u="magicfeedback-point-system";const te=document.createElement("div");te.classList.add("magicfeedback-point-system-container");const ie=document.createElement("ul");ie.classList.add("magicfeedback-point-system-list"),ie.style.padding="0";const ne=100,ae=ne/v.length,se=document.createElement("div");se.classList.add("magicfeedback-error"),se.textContent=a.placeholder.pointsystemerror(i||"en"),se.style.color="#C70039",se.style.fontSize="14px",se.style.textAlign="right",se.style.width="100%",se.style.display="none";const oe=document.createElement("div");oe.classList.add("magicfeedback-point-system-total"),oe.textContent="0 / 100 %",oe.style.textAlign="right",oe.style.fontSize="15px",oe.style.marginTop="5px",v.forEach(((e,t)=>{const i=document.createElement("li");i.classList.add("magicfeedback-point-system-item"),i.style.display="flex",i.style.justifyContent="space-between",i.style.alignItems="center",i.style.margin="5px";const n=document.createElement("label");n.textContent=e,n.style.fontSize="15px",i.appendChild(n);const a=document.createElement("span");a.classList.add("magicfeedback-point-system-input-container");const s=document.createElement("input");s.name=f,s.id=`point-system-${e}`,s.type="number",s.min="0",s.max=`${ne}`,s.value="0",s.classList.add("magicfeedback-input"),s.style.width="40px",s.style.border="0",s.style.textAlign="center",s.style.margin="0 5px",s.autofocus=0===t;const o=document.createElement("span");o.textContent="%",o.style.color="#000",s.addEventListener("input",(()=>{const e=ie.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>ne&&(s.value=`${ae}%`,t-=Number(s.value));const i=document.getElementById("magicfeedback-submit");i&&(t<100?(oe.style.color="orange",i.setAttribute("disabled","true")):(se.style.display="none",oe.style.color="green",i.removeAttribute("disabled"))),oe.textContent=`${t} / 100 %`})),s.addEventListener("focus",(()=>{const e=document.getElementById("magicfeedback-submit");e&&(e.setAttribute("disabled","true"),e.addEventListener("pointerover",(()=>{const e=ie.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t<100&&(se.style.display="block")})))})),a.appendChild(s),a.appendChild(o),i.appendChild(a),ie.appendChild(i)})),te.appendChild(ie),te.appendChild(oe),te.appendChild(se),l.appendChild(te);break;case n.FEEDBACKAPPANSWERTYPE.INFO_PAGE:l=document.createElement("div"),u="magicfeedback-info-page";const re=document.createElement("div");re.classList.add("magicfeedback-info-message"),re.innerHTML=k,l.appendChild(re);break;default:return E}l.id=`magicfeedback-${p}`,l.setAttribute("name",f),l.classList.add(u),(void 0!==b||null!==C)&&(l.value=C||b),["RADIO","MULTIPLECHOICE"].includes(h)||(l.classList.add("magicfeedback-input"),l.required=g);const A=document.createElement("label");A.setAttribute("for",`magicfeedback-${p}`),A.textContent=o(m,i),A.classList.add("magicfeedback-label");const L=document.createElement("label");if(L.textContent=o(null==y?void 0:y.subtitle,i),L.classList.add("magicfeedback-sublabel"),["CONSENT"].includes(h))E.classList.add("magicfeedback-consent-container"),E.appendChild(l),E.appendChild(A),E.appendChild(L);else{if("slim"!==t&&([n.FEEDBACKAPPANSWERTYPE.INFO_PAGE].includes(h)||(E.appendChild(A),E.appendChild(L)),void 0!==(null==y?void 0:y.general)&&""!==(null==y?void 0:y.general))){const Oe=document.createElement("img");Oe.src=null==y?void 0:y.general,Oe.classList.add("magicfeedback-image"),Oe.style.maxWidth="auto",Oe.style.height="400px",Oe.style.margin="10px 0",E.appendChild(Oe)}if("LONGTEXT"===h&&x>0){const Ie=document.createElement("div");if(Ie.classList.add("magicfeedback-counter"),Ie.textContent=`${l.value.length}/${x}`,Ie.style.textAlign="right",Ie.style.fontSize="15px",Ie.style.marginTop="5px",l.addEventListener("input",(()=>{Ie.textContent=`${l.value.length}/${x}`})),E.appendChild(l),E.appendChild(Ie),(null==y?void 0:y.extraOption)&&(null==y?void 0:y.extraOptionText)){const Ne=document.createElement("div");Ne.classList.add("magicfeedback-skip-container"),Ne.classList.add("magicfeedback-checkbox-container"),Ne.style.display="flex",Ne.style.justifyContent="flex-start";const Pe=document.createElement("input");Pe.classList.add("magicfeedback-skip"),Pe.type="checkbox",Pe.id=`skip-${f}`,Pe.name=f,Pe.value="-",Pe.style.cursor="pointer";const De=document.createElement("label");De.htmlFor=`skip-${f}`,De.textContent=null==y?void 0:y.extraOptionText,De.style.fontSize="15px",De.style.cursor="pointer",De.style.margin="0 5px",Pe.addEventListener("click",(()=>{l.value="-",c&&c()})),Ne.appendChild(Pe),Ne.appendChild(De),E.appendChild(Ne)}}else E.appendChild(l)}return E}(t,i,d,`${s}${p?`/${m}`:""}`,l);u.push(e)}})),u},t.renderActions=function(e="",t,i="Submit",n="Back",a="Next"){const s=document.createElement("div");s.classList.add("magicfeedback-action-container");const o=document.createElement("button");o.id="magicfeedback-submit",o.type="submit",o.classList.add("magicfeedback-submit"),o.textContent="MAGICSURVEY"===e?a||"Next":i||"Submit";const r=document.createElement("button");return r.id="magicfeedback-back",r.type="button",r.classList.add("magicfeedback-back"),r.textContent=n||"Back",r.addEventListener("click",t),r.addEventListener("click",(()=>{o.removeAttribute("disabled")})),"MAGICSURVEY"===e&&s.appendChild(r),s.appendChild(o),s},t.renderError=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-error"),t.textContent=e,t},t.renderSuccess=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-success"),t.textContent=e,t},t.renderStartMessage=function(e,t=!1,i="Go!",n=(()=>{})){const a=document.createElement("div");a.classList.add("magicfeedback-start-message-container");const s=document.createElement("div");if(s.classList.add("magicfeedback-start-message"),s.innerHTML=e,a.appendChild(s),t){const e=document.createElement("button");e.id="magicfeedback-start-message-button",e.classList.add("magicfeedback-start-message-button"),e.textContent=i,e.addEventListener("click",(()=>n())),a.appendChild(e)}return a}},341:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function o(e){try{d(n.next(e))}catch(e){s(e)}}function r(e){try{d(n.throw(e))}catch(e){s(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}d((n=n.apply(e,t||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFollowUpQuestion=t.sendFeedback=t.getQuestions=t.getSessionForm=t.getForm=t.validateEmail=void 0;const s=a(i(31)),o=a(i(147)),r=i(374),d={Accept:"application/json","Magicfeedback-Sdk-Version":o.default.version};t.validateEmail=function(e){return/\S+@\S+\.\S+/.test(e)},t.getForm=function(e,t,i,a){return n(this,void 0,void 0,(function*(){try{const n=yield(0,s.default)(e+r.endpoints.sdk.app_info(t,i),{method:"GET",headers:d});if(n.ok){const e=yield n.json();return a.log(`Received form for app ${t}`,e),e}throw a.err(`Failed to get questions for app ${t}:`,n.status,n.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return a.err(e),null}}))},t.getSessionForm=function(e,t,i){return n(this,void 0,void 0,(function*(){try{const n=yield(0,s.default)(e+r.endpoints.sdk.session(t),{method:"GET",headers:d});if(n.ok){const e=yield n.json();return i.log(`Received form for session ${t}`,e),e}throw i.err(`Failed to get questions for session ${t}:`,n.status,n.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return i.err(e),null}}))},t.getQuestions=function(e,t,i,a){return n(this,void 0,void 0,(function*(){try{const n=yield(0,s.default)(e+r.endpoints.sdk.app(t,i),{method:"GET",headers:d});if(n.ok){const e=yield n.json();return a.log(`Received questions for app ${t}`,e),e}throw a.err(`Failed to get questions for app ${t}:`,n.status,n.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return a.err(e),[]}}))},t.sendFeedback=function(e,t,i){return n(this,void 0,void 0,(function*(){try{const n=yield(0,s.default)(e+r.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},d),body:JSON.stringify(t)});if(n.ok)return i.log(`Form ${t.integration} submitted successfully!`),(yield n.json()).sessionId;throw i.err(`Failed to submit form ${t.integration}:`,n.status,n.statusText),new Error(n.statusText)}catch(e){return i.err(e),""}}))},t.getFollowUpQuestion=function(e,t,i){return n(this,void 0,void 0,(function*(){try{const n=yield(0,s.default)(e+r.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},d),body:JSON.stringify(t)});if(n.ok)return i.log(`Received follow up question for form ${t.integration}`),(yield n.json())||"";throw i.err(`Failed to get follow up question for form ${t.integration}:`,n.status,n.statusText),new Error(n.statusText)}catch(e){return i.err(e),""}}))}},5:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Log=void 0,t.Log=class{constructor(e){this.config=e}log(...e){this.config.get("debug")&&console.log("[MagicFeedback]:",...e)}err(...e){console.error("[MagicFeedback]:",...e)}}},31:e=>{e.exports=require("cross-fetch")},147:e=>{e.exports=JSON.parse('{"name":"@magicfeedback/native","version":"1.3.2-beta.4","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","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","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"}}')}},t={},i=function i(n){var a=t[n];if(void 0!==a)return a.exports;var s=t[n]={exports:{}};return e[n].call(s.exports,s,s.exports,i),s.exports}(607);return i.default})()));
|