@magicfeedback/native 1.4.9 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -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 l(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 c(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 v(){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(b)}),this.json=function(){return this.text().then(JSON.parse)},this}p.prototype.append=function(e,t){e=l(e),t=c(t);var i=this.map[e];this.map[e]=i?i+", "+t:t},p.prototype.delete=function(e){delete this.map[l(e)]},p.prototype.get=function(e){return e=l(e),this.has(e)?this.map[e]:null},p.prototype.has=function(e){return this.map.hasOwnProperty(l(e))},p.prototype.set=function(e,t){this.map[l(e)]=c(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 E=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function y(e,t){var i,n,s=(t=t||{}).body;if(e instanceof y){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(),E.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 b(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)}y.prototype.clone=function(){return new y(this,{body:this._bodyInit})},v.call(y.prototype),v.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 A(e,i){return new Promise((function(n,a){var o=new y(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)}))}A.polyfill=!0,e.fetch||(e.fetch=A,e.Headers=p,e.Request=y,e.Response=k),t.Headers=p,t.Request=y,t.Response=k,t.fetch=A,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.deepdots.com/"},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,l){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"),c={integration:i,publicKey:s,privateKey:l,completed:o,id:d,feedback:a};try{const e=yield(0,r.sendFeedback)(n,c,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(244),a=i(5),o=i(341),r=i(183),d=i(24),l=i(804),c=i(116),u=i(314),p=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.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.history=new u.History,this.graph=new d.PageGraph([]),this.progress=0,this.total=0,this.completed=!1,this.timeToCompleted=0}generate(e,t){var i,s,a,r,d,l,c;return n(this,void 0,void 0,(function*(){try{this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e;let n=this.formData;if(void 0!==this.formData&&this.formData||(n=""!==this.publicKey?yield(0,o.getForm)(this.url,this.appId,this.publicKey,this.log):yield(0,o.getSessionForm)(this.url,this.appId,this.log)),void 0===n||!n)throw new Error(`No data for app ${this.appId}`);if(null===(i=n.error)||void 0===i?void 0:i.message)throw new Error(n.error.message);if(n.questions=(null===(s=n.questions)||void 0===s?void 0:s.filter((e=>"ACTIVE"===e.status)))||[],n.pages=(null===(a=n.pages)||void 0===a?void 0:a.filter((e=>"ACTIVE"===e.status)))||[],null===(r=n.pages)||void 0===r||r.forEach((e=>{var t;return e.integrationQuestions=null===(t=e.integrationQuestions)||void 0===t?void 0:t.filter((e=>"ACTIVE"===e.status))})),this.formData=n,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===(d=this.formData.pages)||void 0===d?void 0:d.length)||this.formatPages(),null===(l=this.formData.questions)||void 0===l||l.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===(c=this.formData.style)||void 0===c?void 0:c.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 l.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 l.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 d.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,a.addEventListener("submit",(e=>e.preventDefault()));const o=document.createElement("div");o.classList.add("magicfeedback-questions"),o.id="magicfeedback-questions-"+this.appId;const l=this.graph.getFirstPage();if(!l)throw new Error("No page found");if(this.total=this.graph.findMaxDepth(),l.elements=(0,r.renderQuestions)(l.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=l.elements)||void 0===i||i.forEach((e=>o.appendChild(e))),a.appendChild(o),this.history.enqueue(l),n.appendChild(a),this.progress=this.total-this.graph.findMaxDepth(l),this.formOptionsConfig.addButton){const e=(0,r.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.timeToCompleted=(new Date).getTime()/1e3,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,r.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");for(const e of s.questions.filter((e=>e.require))){const t=e.assets,i=this.feedback.answers.filter((t=>t.key.includes(e.ref)&&!t.key.includes("extra-option")));if(0===i.length||i.find((e=>0===e.value.length)))throw this.log.err(`The question ${e.ref} is required`),new Error("No response");if(null==t?void 0:t.minOptions){let n=[];if((null==t?void 0:t.exclusiveAnswers)&&(n=null==t?void 0:t.exclusiveAnswers),(null==t?void 0:t.extraOption)&&n.push(null==t?void 0:t.extraOptionText),!i[0].value.find((e=>n.includes(e)))&&i[0].value.length<(null==t?void 0:t.minOptions))throw this.log.err(`The question ${e.ref} requires at least ${null==t?void 0:t.minOptions} options`),new Error("No response")}}const a=yield this.pushAnswers(!1);if(!a)throw new Error("No response");this.id=a,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=[]);const t=this.history.back();if(!t)throw new Error("No page found");const i=[];let n=!1;e.querySelectorAll(".magicfeedback-input").forEach((e=>{const a=t.questions.find((t=>{var i;return null===(i=e.name)||void 0===i?void 0:i.includes(t.ref)})),r=e.type,d=e.classList[0],l={key:e.name,value:[]},c="magicfeedback-consent"===d?e.checked.toString():e.value;if(l.key&&""!==l.key){switch(null==a?void 0:a.type){case s.FEEDBACKAPPANSWERTYPE.EMAIL:case s.FEEDBACKAPPANSWERTYPE.TEXT:case s.FEEDBACKAPPANSWERTYPE.LONGTEXT:case s.FEEDBACKAPPANSWERTYPE.NUMBER:case s.FEEDBACKAPPANSWERTYPE.DATE:case s.FEEDBACKAPPANSWERTYPE.CONTACT:if(""!==c){if("email"===r){if(!(0,o.validateEmail)(c)){this.log.err("Invalid email"),n=!0;break}this.feedback.profile.push({key:"email",value:[c]})}l.value.push(c)}break;case s.FEEDBACKAPPANSWERTYPE.CONSENT:l.value.push(String(e.checked));break;case s.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:const t=e.id;l.value.push(`${t}:${c}%`);break;case s.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:case s.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:case s.FEEDBACKAPPANSWERTYPE.RATING_STAR:case s.FEEDBACKAPPANSWERTYPE.RADIO:case s.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:case s.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:(e.checked||e.id.includes("extra-option-"))&&l.value.push(c);break;case s.FEEDBACKAPPANSWERTYPE.SELECT:l.value.push(c);break;case s.FEEDBACKAPPANSWERTYPE.BOOLEAN:case s.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:e.checked&&l.value.push(c);break;case s.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:l.value.push(c)}if((null==i?void 0:i.length)>0&&(null==i?void 0:i.find((e=>e.key===l.key)))){const e=i.findIndex((e=>e.key===l.key));i[e].value=[...i[e].value,...l.value]}else i.push(l)}})),this.feedback.answers=n?[]:i}finish(){return n(this,void 0,void 0,(function*(){if(this.completed=!0,this.timeToCompleted=(new Date).getTime()-this.timeToCompleted,this.feedback.metadata.push({key:"time-to-complete",value:[this.timeToCompleted.toString()]}),this.formOptionsConfig.addSuccessScreen){const e=document.getElementById("magicfeedback-container-"+this.appId);e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,r.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}this.answer();try{const e=yield this.pushAnswers(!0);if(!e)throw this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({loading:!1,progress:this.progress,total:this.total,completed:this.completed,error:`An error occurred while submitting the form ${this.appId}:`})),new Error("An error occurred while submitting the form ${this.appId}:");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}))}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,completed:this.completed,error:e}))}}))}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,o.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=Object.assign(Object.assign(Object.assign({answer:null===(t=this.feedback.answers.find((t=>t.key===e.ref)))||void 0===t?void 0:t.value[0]},""!==this.publicKey&&{publicKey:this.publicKey}),""===this.publicKey&&{campaignSessionId:this.appId}),{sessionId:this.id,question:e});return yield(0,o.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 o=[];for(const e of a){const t=n.questions.find((t=>t.ref===e));if(t){const e=yield this.callFollowUpQuestion(t);e&&o.push(e)}}if(0===o.length)return void(yield this.renderNextQuestion(e,n));const d=new l.Page(n.id,n.position,this.appId,o,n.edges),c=new p.PageNode(n.id,n.position,n.edges,d,o,!0);c.elements=(0,r.renderQuestions)(o,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(c),this.progress++,e.innerHTML="",null===(s=c.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:c.isFollowup,completed:this.completed,error:null}))}))}renderNextQuestion(e,t){var i,s,a;return n(this,void 0,void 0,(function*(){const n=this.graph.getNextPage(t,this.feedback.answers);n?(n.elements=(0,r.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.innerHTML="",null===(a=n.elements)||void 0===a||a.forEach((t=>e.appendChild(t))),this.history.enqueue(n),this.progress=this.total-this.graph.findMaxDepth(n),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.innerHTML=""),this.history.rollback();const i=this.history.back();i?(null===(e=i.elements)||void 0===e||e.forEach((e=>t.appendChild(e))),this.progress=this.total-this.graph.findMaxDepth(i)):this.progress=this.history.size(),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,r;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]}t.integrationPageRoutes&&(t.integrationPageRoutes=(null===(r=t.integrationPageRoutes)||void 0===r?void 0:r.sort(((e,t)=>new Date((null==e?void 0:e.generatedAt)||"").getTime()-new Date((null==t?void 0:t.generatedAt)||"").getTime()?"DIRECT"===e.typeCondition?1:-1:0)))||[]);const d=new n.PageNode(t.id,t.position,t.integrationPageRoutes||[],t,t.integrationQuestions);this.nodes.set(d.id,d)}))}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){var i;if(!e)return;e.edges.sort(((e,t)=>"DIRECT"===e.typeCondition?1:"DIRECT"===t.typeCondition?-1:0));const n=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(!n){const t=this.getNextEdgeByDefault(e);if(!t)return;return this.getNodeById(t)}switch(n.transition){case s.TransitionType.PAGE:if(!n.transitionDestiny)return;return this.getNodeById(n.transitionDestiny);case s.TransitionType.FINISH:return;case s.TransitionType.REDIRECT:return void(window.location.href=(null===(i=n.transitionDestiny)||void 0===i?void 0:i.includes("?"))?`${n.transitionDestiny}&${window.location.search.slice(1)}`:`${n.transitionDestiny}${window.location.search}`);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||[],o=this.getNextEdgeByDefault(e);if(o){const i=this.getNodeById(o);i&&!t.has(i)&&a.push(new s.PageRoute(i.id,"",s.OperatorType.DEFAULT,"",s.TransitionType.PAGE,i.id,e.id))}for(const e of a){if(!e.transitionDestiny)continue;const s=this.getNodeById(e.transitionDestiny);if(s&&!t.has(s)){const e=s.questions.find((e=>e.followup))?i+2:i+1,a=new Set(t),o=this.DFSUtil(s,a,e);n=Math.max(n,o)}}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,l){this.id=e,this.questionRef=t,this.typeCondition=l||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",n.UPLOAD_FILE="UPLOAD_FILE",n.UPLOAD_IMAGE="UPLOAD_IMAGE",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,o="ltr",r="row"){const d=document.createElement("div");d.classList.add("magicfeedback-rating-placeholder"),d.style.display="flex",d.style.flexDirection=r,d.style.alignItems="center",d.style.justifyContent="space-between",d.style.width=s?`calc(100% - (100% / ${t+1}))`:"100%",d.style.marginRight="auto",a&&window.innerWidth<600&&(d.style.flexDirection="column");const l=document.createElement("span");l.textContent=i,l.classList.add("magicfeedback-rating-placeholder-value"),l.style.fontSize="15px",l.style.textAlign="ltr"===o?"left":"right",l.style.width="50%",(a&&window.innerWidth<600||"column"===r)&&(l.textContent=`${e} = ${i}`,l.style.width="100%",l.style.textAlign="left",l.style.marginBottom="5px");const c=document.createElement("span");return c.textContent=n,c.classList.add("magicfeedback-rating-placeholder-value"),c.style.fontSize="15px",c.style.textAlign="ltr"===o?"right":"left",c.style.width="50%",(a&&window.innerWidth<600||"column"===r)&&(c.textContent=`${t} = ${n}`,c.style.width="100%",c.style.textAlign="left",c.style.marginBottom="5px"),"ltr"===o?(i&&d.appendChild(l),n&&d.appendChild(c)):(n&&d.appendChild(c),i&&d.appendChild(l)),d}t.renderQuestions=function e(t,i="standard",d="en",l={customIcons:!1},c){if(!t)throw new Error("[MagicFeedback] No questions provided");const u=[],{customIcons:p,id:h}=l;return t.forEach((m=>{var f,g;if((null===(g=null===(f=null==m?void 0:m.questionType)||void 0===f?void 0:f.conf)||void 0===g?void 0:g.length)>0){let t=document.createElement("div");t.classList.add("magicfeedback-div");const n=document.createElement("label");n.setAttribute("for",`magicfeedback-${m.id}`),n.textContent=o(m.title,d),n.classList.add("magicfeedback-label"),t.appendChild(n),m.questionType.conf.forEach((e=>{e.ref=m.ref,m.assets[e.id]&&(e.assets={placeholder:m.assets[e.id]})})),e(m.questionType.conf,i,d,l,c).forEach((e=>{t.appendChild(e)})),u.push(t)}else{const e=function(e,t,i,d,l){let c,u,{id:p,title:h,type:m,ref:f,require:g,value:v,defaultValue:E,assets:y}=e,b=document.createElement("div");b.classList.add("magicfeedback-div");const k=window.innerWidth<600,C="slim"===t?o(h,i):null==y?void 0:y.placeholder,A=(L=p,new URLSearchParams(window.location.search).get(L)),x=(null==y?void 0:y.maxCharacters)||0,T=void 0!==(null==y?void 0:y.randomPosition)&&(null==y?void 0:y.randomPosition),w=(null==y?void 0:y.direction)||"row",P=(null==y?void 0:y.order)||"ltr";var L;switch(m){case n.FEEDBACKAPPANSWERTYPE.TEXT:c=document.createElement("input"),c.type="text",c.placeholder=C||s.placeholder.answer(i||"en"),c.addEventListener("keyup",(e=>{e.preventDefault(),console.log(e.key,e),"Enter"===e.key&&l&&l()})),u="magicfeedback-text";break;case n.FEEDBACKAPPANSWERTYPE.LONGTEXT:c=document.createElement("textarea"),c.rows=3,x>0&&(c.maxLength=x),c.placeholder=C||s.placeholder.answer(i||"en"),u="magicfeedback-longtext";break;case n.FEEDBACKAPPANSWERTYPE.NUMBER:c=document.createElement("input"),c.type="number",c.placeholder="slim"===t?o(h,i):s.placeholder.number(i||"en"),u="magicfeedback-number",v.length&&(v.sort(((e,t)=>Number(e)-Number(t))),c.max=v[v.length-1],c.min=v[0],c.value=v[0]);break;case n.FEEDBACKAPPANSWERTYPE.RADIO:case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:c=document.createElement("div"),u="magicfeedback-"+("MULTIPLECHOICE"===m?"checkbox":"radio");let I=v||[];T&&(I=I.sort((()=>Math.random()-.5)));let N=[];(null==y?void 0:y.exclusiveAnswers)&&(N=null==y?void 0:y.exclusiveAnswers,null==N||N.forEach((e=>{I.includes(e)||I.push(e)}))),(null==y?void 0:y.extraOption)&&(N.push(null==y?void 0:y.extraOptionText),I.includes(null==y?void 0:y.extraOptionText)||I.push(null==y?void 0:y.extraOptionText)),I.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==y?void 0:y.maxOptions)&&(null==y?void 0:y.maxOptions)>0&&r.addEventListener("change",(()=>{const e=document.querySelectorAll(`input[name="${f}"]:checked`);e.length>(null==y?void 0:y.maxOptions)&&(r.checked=!1),l&&e.length===(null==y?void 0:y.maxOptions)&&l()})),m===n.FEEDBACKAPPANSWERTYPE.RADIO&&l&&r.addEventListener("change",(()=>{l()})),e!==E&&e!==A||(r.checked=!0),o.textContent=e,o.htmlFor=`rating-${f}-${t}`,r.addEventListener("change",(t=>{const i=document.getElementById(`extra-option-${f}`);t.target.checked&&N.includes(e)?(I.forEach((t=>{t!==e&&(document.querySelector(`input[value="${t}"]`).checked=!1)})),i&&(i.style.display=(null==y?void 0:y.extraOption)&&e===(null==y?void 0:y.extraOptionText)?"block":"none")):(N.forEach((t=>{t!==e&&(document.querySelector(`input[value="${t}"]`).checked=!1)})),i&&(i.style.display="none"))})),a.appendChild(r),a.appendChild(o),c.appendChild(a),(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)||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",c.appendChild(e)}}));break;case n.FEEDBACKAPPANSWERTYPE.BOOLEAN:c=document.createElement("div"),u="magicfeedback-radio";const D=document.createElement("div");D.classList.add("magicfeedback-boolean-container"),D.style.display="flex",D.style.flexDirection="row",D.style.justifyContent="space-between",D.style.width="70%",D.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 s=document.createElement("input");s.id=`rating-${f}-${t}`,s.type="radio",s.name=f,s.value=v[t],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",(()=>{l&&l()})),i.appendChild(s),i.appendChild(n),D.appendChild(i)})),c.appendChild(D);break;case n.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:c=document.createElement("div"),u="magicfeedback-rating";const R=document.createElement("div");R.classList.add("magicfeedback-rating-container");const $=(null==y?void 0:y.max)?Number(null==y?void 0:y.max):5,_=(null==y?void 0:y.min)?Number(null==y?void 0:y.min):1,F=r(_,$,null==y?void 0:y.minPlaceholder,null==y?void 0:y.maxPlaceholder,null==y?void 0:y.extraOption);for(let pe=_;pe<=$;pe++){const he=document.createElement("div");he.classList.add("magicfeedback-rating-option");const me=document.createElement("label");me.htmlFor=`rating-${f}-${pe}`,me.classList.add("magicfeedback-rating-option-label-container");const fe=document.createElement("label");fe.htmlFor=`rating-${f}-${pe}`,fe.textContent=pe.toString();const ge=document.createElement("img");if(ge.alt=`face-${f}-${pe}`,ge.className=`rating-image${pe}`,0===_&&10===$)ge.src=`${d}/${pe}.svg`,ge.onerror=()=>ge.src=`${a}/${pe}.svg`;else if(1===_&&5===$)switch(pe){case 1:ge.src=`${d}/1.svg`,ge.onerror=()=>ge.src=`${a}/1.svg`;break;case 2:ge.src=`${d}/2.svg`,ge.onerror=()=>ge.src=`${a}/2.svg`;break;case 3:ge.src=`${d}/6.svg`,ge.onerror=()=>ge.src=`${a}/6.svg`;break;case 4:ge.src=`${d}/9.svg`,ge.onerror=()=>ge.src=`${a}/9.svg`;break;case 5:ge.src=`${d}/10.svg`,ge.onerror=()=>ge.src=`${a}/10.svg`}else{const Ee=Math.round(10/($-_)*(pe-_));ge.src=`${d}/${Ee}.svg`,ge.onerror=()=>ge.src=`${a}/${Ee}.svg`}const ve=document.createElement("input");ve.id=`rating-${f}-${pe}`,ve.type="radio",ve.name=f,ve.value=pe.toString(),ve.classList.add(u),ve.classList.add("magicfeedback-input"),l&&ve.addEventListener("change",(()=>{l()})),me.appendChild(ve),me.appendChild(ge),me.appendChild(fe),he.appendChild(me),R.appendChild(he)}if((null==y?void 0:y.extraOption)&&(null==y?void 0:y.extraOptionText)){const ye=document.createElement("div");ye.classList.add("magicfeedback-rating-option");const be=document.createElement("label");be.htmlFor=`rating-${f}-extra`,be.classList.add("magicfeedback-rating-option-label-container");const ke=document.createElement("label");ke.htmlFor=`rating-${f}-extra`,ke.textContent=null==y?void 0:y.extraOptionText;const Ce=document.createElement("img");Ce.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",Ce.alt=`face-${f}-extra`,Ce.className="magicfeedback-rating-image-extra";const Ae=document.createElement("input");Ae.id=`rating-${f}-extra`,Ae.type="radio",Ae.name=f,Ae.value="-",Ae.classList.add(u),Ae.classList.add("magicfeedback-input"),l&&Ae.addEventListener("change",(()=>{l()})),be.appendChild(Ae),be.appendChild(Ce),be.appendChild(ke),ye.appendChild(be),R.appendChild(ye)}c.appendChild(F),c.appendChild(R);break;case n.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:c=document.createElement("div"),u="magicfeedback-rating-number";const M="ltr"===P?w:`${w}-reverse`,B=document.createElement("div");B.classList.add("magicfeedback-rating-number-container"),B.classList.add(`magicfeedback-rating-number-container-${P}`),B.classList.add(`magicfeedback-rating-number-container-${w}`),B.style.display="flex",B.style.flexDirection=M;const U=(null==y?void 0:y.max)?Number(null==y?void 0:y.max):10,q=(null==y?void 0:y.min)?Number(null==y?void 0:y.min):0,j=r(q,U,null==y?void 0:y.minPlaceholder,null==y?void 0:y.maxPlaceholder,null==y?void 0:y.extraOption,!0,P,w);for(let xe=q;xe<=U;xe++){const Te=document.createElement("div");Te.classList.add("magicfeedback-rating-number-option"),Te.classList.add(`magicfeedback-rating-number-option-${w}`);const we=document.createElement("label");we.htmlFor=`rating-${f}-${xe}`,we.classList.add("magicfeedback-rating-number-option-label-container");let Pe=xe.toString();(k||"column"===w)&&xe===q&&(null==y?void 0:y.minPlaceholder)&&(Pe+=` = ${null==y?void 0:y.minPlaceholder}`),(k||"column"===w)&&xe===U&&(null==y?void 0:y.maxPlaceholder)&&(Pe+=` = ${null==y?void 0:y.maxPlaceholder}`);const Le=document.createElement("label");Le.htmlFor=`rating-${f}-${xe}`,Le.textContent=Pe;const Se=document.createElement("input");Se.id=`rating-${f}-${xe}`,Se.type="radio",Se.name=f,Se.value=xe.toString(),Se.classList.add(u),Se.classList.add("magicfeedback-input"),l&&Se.addEventListener("change",(()=>{l()})),we.appendChild(Se),we.appendChild(Le),Te.appendChild(we),B.appendChild(Te)}if((null==y?void 0:y.extraOption)&&(null==y?void 0:y.extraOptionText)){const Oe=document.createElement("div");Oe.classList.add("magicfeedback-rating-number-option");const Ie=document.createElement("label");Ie.htmlFor=`rating-${f}-extra`,Ie.classList.add("magicfeedback-rating-number-option-label-container");const Ne=document.createElement("label");Ne.htmlFor=`rating-${f}-extra`,Ne.textContent=null==y?void 0:y.extraOptionText;const De=document.createElement("input");De.id=`rating-${f}-extra`,De.type="radio",De.name=f,De.value="-",De.classList.add(u),De.classList.add("magicfeedback-input"),l&&De.addEventListener("change",(()=>{l()})),Ie.appendChild(De),Ie.appendChild(Ne),Oe.appendChild(Ie),B.appendChild(Oe)}k||"column"===w||c.appendChild(j),c.appendChild(B);break;case n.FEEDBACKAPPANSWERTYPE.RATING_STAR:c=document.createElement("div"),u="magicfeedback-rating-star";const K=function(e,t,i,n=(()=>{})){const s="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 o=document.createElement("input");o.id=`rating-${e}-${t}`,o.type="radio",o.name=e,o.value=t.toString(),o.style.position="absolute",o.style.opacity="0",o.style.width="0",o.style.height="0",o.classList.add("magicfeedback-input"),o.addEventListener("change",(()=>{const e=a.querySelectorAll(".rating__star");for(let t=0;t<e.length;t++)t+1<=Number(o.value)?e[t].classList.contains(s)||e[t].classList.add(s):e[t].classList.contains(s)&&e[t].classList.remove(s);n&&n()})),i.appendChild(o);const r=document.createElement("label");r.htmlFor=`rating-${e}-${t}`,r.classList.add("rating__star"),r.textContent="★",r.style.fontSize="40px",r.style.color="#CCCCCC",r.style.cursor="pointer",i.appendChild(r),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);c.appendChild(K);break;case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:c=document.createElement("div"),u="magicfeedback-multiple-choice-image";const W=document.createElement("div");W.classList.add("magicfeedback-multiple-choice-image-container"),W.style.display="flex",W.style.flexDirection="row",W.style.flexWrap="wrap",W.style.justifyContent="center";const G=v.length;let Y=1,Q=1;if(window.innerWidth<600)Y=1,Q=G;else switch(G){case 1:case 2:case 3:Y=G,Q=1;break;case 4:case 5:case 6:Q=2,Y=Math.ceil(G/Q);break;case 7:case 8:case 9:Q=3,Y=Math.ceil(G/Q);break;default:Q=4,Y=Math.ceil(G/Q)}const H=void 0!==(null==y?void 0:y.addTitle)&&(null==y?void 0:y.addTitle),V=void 0!==(null==y?void 0:y.multiOption)&&(null==y?void 0:y.multiOption),X=void 0!==(null==y?void 0:y.extraOption)&&(null==y?void 0:y.extraOption);function z(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/Y}% - 10px)`,s.style.height=`calc( ${100/Q}% - 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=V?"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"),console.log("send",l),console.log("multiOptions",V),!V&&l&&r.addEventListener("change",(()=>{console.log("send"),l()}));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),H&&a.appendChild(o),s.appendChild(a),W.appendChild(s)}catch(e){console.error(e)}}T&&(v=v.sort((()=>Math.random()-.5))),v.forEach((e=>z(JSON.parse(e)))),X&&(null==y?void 0:y.extraOptionValue)&&(null==y?void 0:y.extraOptionValue.length)>0&&z(null==y?void 0:y.extraOptionValue[0]),c.appendChild(W);break;case n.FEEDBACKAPPANSWERTYPE.SELECT:c=document.createElement("select"),u="magicfeedback-select";const J=document.createElement("option");J.value="",J.text="slim"===t?o(h,i):E||"Select an option",J.disabled=!0,J.selected=!0,c.appendChild(J),v.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,c.appendChild(t)})),l&&c.addEventListener("change",(()=>{l()}));break;case n.FEEDBACKAPPANSWERTYPE.DATE:c=document.createElement("input"),c.type="date",c.required=g,c.placeholder=C||s.placeholder.date(i||"en"),u="magicfeedback-date";break;case n.FEEDBACKAPPANSWERTYPE.CONSENT:c=document.createElement("input"),u="magicfeedback-consent",c.type="checkbox",c.id=`magicfeedback-${p}`,c.name=f,c.value="true",c.required=g,c.classList.add("magicfeedback-consent"),c.classList.add("magicfeedback-input"),l&&c.addEventListener("change",(()=>{l()}));break;case n.FEEDBACKAPPANSWERTYPE.EMAIL:c=document.createElement("input"),c.type="email",c.required=g,c.placeholder=C||"you@example.com",u="magicfeedback-email";break;case n.FEEDBACKAPPANSWERTYPE.PASSWORD:c=document.createElement("input"),c.type="password",c.required=g,c.placeholder=C||s.placeholder.password(i||"en"),u="magicfeedback-password";break;case n.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:c=document.createElement("div"),u="magicfeedback-multi-question-matrix";const Z=document.createElement("div");Z.classList.add("magicfeedback-multi-question-matrix-container");let ee=(null==y?void 0:y.options)||[],te=[...v],ie=[];if(T&&(ee=null==ee?void 0:ee.sort((()=>Math.random()-.5)),te=[...te].sort((()=>Math.random()-.5))),(null==y?void 0:y.exclusiveAnswers)&&(ie=null==y?void 0:y.exclusiveAnswers,null==ie||ie.forEach((e=>{te.includes(e)||te.push(e)}))),window.innerWidth<600){const Re=document.createElement("div");Re.classList.add("magicfeedback-multi-question-matrix-list"),null==ee||ee.forEach((e=>{const t=document.createElement("div");t.classList.add("magicfeedback-multi-question-matrix-list-item"),t.style.display="flex",t.style.flexDirection="column",t.style.alignItems="flex-start",t.style.marginBottom="10px";const i=document.createElement("label");i.classList.add("magicfeedback-multi-question-matrix-label"),i.style.paddingBottom="10px",i.textContent=e,t.appendChild(i),te.forEach((i=>{const n=document.createElement("div");n.classList.add("magicfeedback-radio-container"),n.style.display="flex",n.style.alignItems="center",n.style.justifyContent="flex-start",n.style.width="99%",n.style.margin="5px auto";const s=document.createElement("label"),a=document.createElement("input");a.id=`${f}-${e}-${i}`,a.type="radio",a.name=`${f}-${e}`,a.value=i,a.classList.add("magicfeedback-input"),s.textContent=i,s.htmlFor=`${f}-${e}-${i}`,n.appendChild(a),n.appendChild(s),t.appendChild(n)})),Re.appendChild(t)})),Z.appendChild(Re)}else{const $e=document.createElement("table");$e.classList.add("magicfeedback-multi-question-matrix-table");const _e=document.createElement("thead");_e.classList.add("magicfeedback-multi-question-matrix-header"),_e.style.paddingBottom="15px";const Fe=document.createElement("tr"),Me=document.createElement("th");Fe.appendChild(Me),te.forEach((e=>{const t=document.createElement("th");t.textContent=e,Fe.appendChild(t)})),_e.appendChild(Fe),$e.appendChild(_e);const Be=document.createElement("tbody");null==ee||ee.forEach((e=>{const t=document.createElement("tr");t.classList.add("magicfeedback-multi-question-matrix-row-tr");const i=document.createElement("td");i.style.minWidth="200px";const n=document.createElement("label");n.classList.add("magicfeedback-multi-question-matrix-label"),n.style.paddingRight="20px",n.textContent=e,i.appendChild(n),t.appendChild(i),te.forEach((i=>{const n=document.createElement("td"),s=document.createElement("input");s.type="radio",s.name=`${f}-${e}`,s.value=i,s.id=`${f}-${e}-${i}`,s.classList.add("magicfeedback-input"),n.appendChild(s),t.appendChild(n)})),Be.appendChild(t)})),$e.appendChild(Be),Z.appendChild($e)}c.appendChild(Z);break;case n.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:c=document.createElement("div"),u="magicfeedback-priority-list";const ne=document.createElement("div");ne.classList.add("magicfeedback-priority-list-container");const se=document.createElement("ul");se.classList.add("magicfeedback-priority-list-list"),T&&(v=v.sort((()=>Math.random()-.5))),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 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,d,l;const c=i.previousElementSibling;if(c){const u=Number(null===(t=n.value)||void 0===t?void 0:t.split(".")[0])-1;n.value=`${u}. ${e}`,s.textContent=`${u}. ${e}`,o.style.visibility=1===u?"hidden":"visible",r.style.visibility=u===v.length?"hidden":"visible";const p=c.querySelector(".magicfeedback-input-magicfeedback-priority-list"),h=c.querySelector(".magicfeedback-priority-list-item-label"),m=c.querySelector(".magicfeedback-priority-list-arrow-up"),f=c.querySelector(".magicfeedback-priority-list-arrow-down");if(p&&h&&m&&f){const e=Number(null===(a=p.value)||void 0===a?void 0:a.split(".")[0])+1;p.value=`${e}.${null===(d=h.textContent)||void 0===d?void 0:d.split(".")[1]}`,h.textContent=`${e}.${null===(l=h.textContent)||void 0===l?void 0:l.split(".")[1]}`,m.style.visibility=1===e?"hidden":"visible",f.style.visibility=e===v.length?"hidden":"visible"}se.insertBefore(i,c)}})),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,d;const l=i.nextElementSibling;if(l){const c=Number(null===(t=n.value)||void 0===t?void 0:t.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 u=l.querySelector(".magicfeedback-input-magicfeedback-priority-list"),p=l.querySelector(".magicfeedback-priority-list-item-label"),h=l.querySelector(".magicfeedback-priority-list-arrow-up"),m=l.querySelector(".magicfeedback-priority-list-arrow-down");if(u&&p&&h&&m){const e=Number(u.value.split(".")[0])-1;u.value=`${e}.${null===(a=p.textContent)||void 0===a?void 0:a.split(".")[1]}`,p.textContent=`${e}.${null===(d=p.textContent)||void 0===d?void 0:d.split(".")[1]}`,h.style.visibility=1===e?"hidden":"visible",m.style.visibility=e===v.length?"hidden":"visible"}se.insertBefore(l,i)}})),a.appendChild(r),i.appendChild(a),se.appendChild(i)})),ne.appendChild(se),c.appendChild(ne);break;case n.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:c=document.createElement("div"),u="magicfeedback-point-system";const ae=document.createElement("div");ae.classList.add("magicfeedback-point-system-container");const oe=document.createElement("ul");oe.classList.add("magicfeedback-point-system-list"),oe.style.padding="0";const re=100,de=re/v.length,le=document.createElement("div");le.classList.add("magicfeedback-error"),le.textContent=s.placeholder.pointsystemerror(i||"en"),le.style.color="#C70039",le.style.fontSize="14px",le.style.textAlign="right",le.style.width="100%",le.style.display="none";const ce=document.createElement("div");ce.classList.add("magicfeedback-point-system-total"),ce.textContent="0 / 100 %",ce.style.textAlign="right",ce.style.fontSize="15px",ce.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=f,a.id=`${e}`,a.type="number",a.min="0",a.max=`${re}`,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=oe.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>re&&(a.value=`${de}%`,t-=Number(a.value));const i=document.getElementById("magicfeedback-submit");i&&(t<100?(ce.style.color="orange",i.setAttribute("disabled","true")):(le.style.display="none",ce.style.color="green",i.removeAttribute("disabled"))),ce.textContent=`${t} / 100 %`})),a.addEventListener("focus",(()=>{const e=document.getElementById("magicfeedback-submit");e&&(e.setAttribute("disabled","true"),e.addEventListener("pointerover",(()=>{const e=oe.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t<100&&(le.style.display="block")})))})),s.appendChild(a),s.appendChild(o),i.appendChild(s),oe.appendChild(i)})),ae.appendChild(oe),ae.appendChild(ce),ae.appendChild(le),c.appendChild(ae);break;case n.FEEDBACKAPPANSWERTYPE.INFO_PAGE:c=document.createElement("div"),u="magicfeedback-info-page";const ue=document.createElement("div");ue.classList.add("magicfeedback-info-message"),ue.innerHTML=C,c.appendChild(ue);break;case n.FEEDBACKAPPANSWERTYPE.UPLOAD_IMAGE:c=document.createElement("input"),c.type="file",c.accept="image/*",c.required=g,c.multiple=(null==y?void 0:y.multiple)||!1,c.maxLength=(null==y?void 0:y.maxFiles)||1,u="magicfeedback-upload-image";break;case n.FEEDBACKAPPANSWERTYPE.UPLOAD_FILE:c=document.createElement("input"),c.type="file",c.required=g,c.multiple=(null==y?void 0:y.multiple)||!1,c.maxLength=(null==y?void 0:y.maxFiles)||1,u="magicfeedback-upload-file";break;default:return b}c.id=`magicfeedback-${p}`,c.setAttribute("name",f),c.classList.add(u),(void 0!==E||null!==A)&&(c.value=A||E),["RADIO","MULTIPLECHOICE"].includes(m)||(c.classList.add("magicfeedback-input"),c.required=g);const S=document.createElement("label");S.setAttribute("for",`magicfeedback-${p}`),S.textContent=o(h,i),S.classList.add("magicfeedback-label");const O=document.createElement("label");if(O.textContent=o(null==y?void 0:y.subtitle,i),O.classList.add("magicfeedback-sublabel"),["CONSENT"].includes(m))b.classList.add("magicfeedback-consent-container"),b.appendChild(c),b.appendChild(S),b.appendChild(O);else{if("slim"!==t&&([n.FEEDBACKAPPANSWERTYPE.INFO_PAGE].includes(m)||(b.appendChild(S),b.appendChild(O)),void 0!==(null==y?void 0:y.general)&&""!==(null==y?void 0:y.general))){const Ue=document.createElement("img");Ue.src=null==y?void 0:y.general,Ue.classList.add("magicfeedback-image"),Ue.style.maxWidth="auto",Ue.style.height="400px",Ue.style.margin="10px 0",b.appendChild(Ue)}if("LONGTEXT"===m&&x>0){const qe=document.createElement("div");if(qe.classList.add("magicfeedback-counter"),qe.textContent=`${c.value.length}/${x}`,qe.style.textAlign="right",qe.style.fontSize="15px",qe.style.marginTop="5px",c.addEventListener("input",(()=>{qe.textContent=`${c.value.length}/${x}`})),b.appendChild(c),b.appendChild(qe),(null==y?void 0:y.extraOption)&&(null==y?void 0:y.extraOptionText)){const je=document.createElement("div");je.classList.add("magicfeedback-skip-container"),je.classList.add("magicfeedback-checkbox-container"),je.style.display="flex",je.style.justifyContent="flex-start";const Ke=document.createElement("input");Ke.classList.add("magicfeedback-skip"),Ke.type="checkbox",Ke.id=`skip-${f}`,Ke.name=f,Ke.value="-",Ke.style.cursor="pointer";const We=document.createElement("label");We.htmlFor=`skip-${f}`,We.textContent=null==y?void 0:y.extraOptionText,We.style.fontSize="15px",We.style.cursor="pointer",We.style.margin="0 5px",Ke.addEventListener("click",(()=>{c.value="-",l&&l()})),je.appendChild(Ke),je.appendChild(We),b.appendChild(je)}}else b.appendChild(c)}return b}(m,i,d,`${a}${p?`/${h}`:""}`,1===t.length?c:void 0);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,"x-magicfeedback-parameters":window.location.search||""};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});return yield n.json()}catch(e){s.err(e)}}))},t.getSessionForm=function(e,t,i){return n(this,void 0,void 0,(function*(){try{const i=yield(0,a.default)(e+r.endpoints.sdk.session(t),{method:"GET",headers:d});return yield i.json()}catch(e){i.err(e)}}))},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.4.9","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 l(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 c(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 v(){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(b)}),this.json=function(){return this.text().then(JSON.parse)},this}p.prototype.append=function(e,t){e=l(e),t=c(t);var i=this.map[e];this.map[e]=i?i+", "+t:t},p.prototype.delete=function(e){delete this.map[l(e)]},p.prototype.get=function(e){return e=l(e),this.has(e)?this.map[e]:null},p.prototype.has=function(e){return this.map.hasOwnProperty(l(e))},p.prototype.set=function(e,t){this.map[l(e)]=c(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 E=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function y(e,t){var i,n,s=(t=t||{}).body;if(e instanceof y){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(),E.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 b(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)}y.prototype.clone=function(){return new y(this,{body:this._bodyInit})},v.call(y.prototype),v.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 A(e,i){return new Promise((function(n,a){var o=new y(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)}))}A.polyfill=!0,e.fetch||(e.fetch=A,e.Headers=p,e.Request=y,e.Response=k),t.Headers=p,t.Request=y,t.Response=k,t.fetch=A,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.deepdots.com/"},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,l){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"),c={integration:i,publicKey:s,privateKey:l,completed:o,id:d,feedback:a};try{const e=yield(0,r.sendFeedback)(n,c,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(244),a=i(5),o=i(341),r=i(183),d=i(24),l=i(804),c=i(116),u=i(314),p=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.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.history=new u.History,this.graph=new d.PageGraph([]),this.progress=0,this.total=0,this.completed=!1,this.timeToCompleted=0}generate(e,t){var i,s,a,r,d,l,c;return n(this,void 0,void 0,(function*(){try{this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e;let n=this.formData;if(void 0!==this.formData&&this.formData||(n=""!==this.publicKey?yield(0,o.getForm)(this.url,this.appId,this.publicKey,this.log):yield(0,o.getSessionForm)(this.url,this.appId,this.log)),void 0===n||!n)throw new Error(`No data for app ${this.appId}`);if(null===(i=n.error)||void 0===i?void 0:i.message)throw new Error(n.error.message);if(n.questions=(null===(s=n.questions)||void 0===s?void 0:s.filter((e=>"ACTIVE"===e.status)))||[],n.pages=(null===(a=n.pages)||void 0===a?void 0:a.filter((e=>"ACTIVE"===e.status)))||[],null===(r=n.pages)||void 0===r||r.forEach((e=>{var t;return e.integrationQuestions=null===(t=e.integrationQuestions)||void 0===t?void 0:t.filter((e=>"ACTIVE"===e.status))})),this.formData=n,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===(d=this.formData.pages)||void 0===d?void 0:d.length)||this.formatPages(),null===(l=this.formData.questions)||void 0===l||l.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===(c=this.formData.style)||void 0===c?void 0:c.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 l.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 l.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(console.log("Generating form for appId:",this.appId),!this.formData||!this.formData.pages||0===this.formData.pages.length)throw new Error("No form data");this.graph=new d.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,a.addEventListener("submit",(e=>e.preventDefault()));const o=document.createElement("div");o.classList.add("magicfeedback-questions"),o.id="magicfeedback-questions-"+this.appId;const l=this.graph.getFirstPage();if(!l)throw new Error("No page found");if(this.total=this.graph.findMaxDepth(),l.elements=(0,r.renderQuestions)(l.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=l.elements)||void 0===i||i.forEach((e=>o.appendChild(e))),a.appendChild(o),this.history.enqueue(l),n.appendChild(a),this.progress=this.total-this.graph.findMaxDepth(l),this.formOptionsConfig.addButton){const e=(0,r.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.timeToCompleted=(new Date).getTime()/1e3,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,r.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");for(const e of s.questions.filter((e=>e.require))){const t=e.assets,i=this.feedback.answers.filter((t=>t.key.includes(e.ref)&&!t.key.includes("extra-option")));if(0===i.length||i.find((e=>0===e.value.length)))throw this.log.err(`The question ${e.ref} is required`),new Error("No response");if(null==t?void 0:t.minOptions){let n=[];if((null==t?void 0:t.exclusiveAnswers)&&(n=null==t?void 0:t.exclusiveAnswers),(null==t?void 0:t.extraOption)&&n.push(null==t?void 0:t.extraOptionText),!i[0].value.find((e=>n.includes(e)))&&i[0].value.length<(null==t?void 0:t.minOptions))throw this.log.err(`The question ${e.ref} requires at least ${null==t?void 0:t.minOptions} options`),new Error("No response")}}const a=yield this.pushAnswers(!1);if(!a)throw new Error("No response");this.id=a,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=[]);const t=this.history.back();if(!t)throw new Error("No page found");const i=[];let n=!1;e.querySelectorAll(".magicfeedback-input").forEach((e=>{const a=t.questions.find((t=>{var i;return null===(i=e.name)||void 0===i?void 0:i.includes(t.ref)})),r=e.type,d=e.classList[0],l={key:e.name,value:[]},c="magicfeedback-consent"===d?e.checked.toString():e.value;if(l.key&&""!==l.key){switch(null==a?void 0:a.type){case s.FEEDBACKAPPANSWERTYPE.EMAIL:case s.FEEDBACKAPPANSWERTYPE.TEXT:case s.FEEDBACKAPPANSWERTYPE.LONGTEXT:case s.FEEDBACKAPPANSWERTYPE.NUMBER:case s.FEEDBACKAPPANSWERTYPE.DATE:case s.FEEDBACKAPPANSWERTYPE.CONTACT:if(""!==c){if("email"===r){if(!(0,o.validateEmail)(c)){this.log.err("Invalid email"),n=!0;break}this.feedback.profile.push({key:"email",value:[c]})}l.value.push(c)}break;case s.FEEDBACKAPPANSWERTYPE.CONSENT:l.value.push(String(e.checked));break;case s.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:const t=e.id;l.value.push(`${t}:${c}%`);break;case s.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:case s.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:case s.FEEDBACKAPPANSWERTYPE.RATING_STAR:case s.FEEDBACKAPPANSWERTYPE.RADIO:case s.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:case s.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:(e.checked||e.id.includes("extra-option-"))&&l.value.push(c);break;case s.FEEDBACKAPPANSWERTYPE.SELECT:l.value.push(c);break;case s.FEEDBACKAPPANSWERTYPE.BOOLEAN:case s.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:e.checked&&l.value.push(c);break;case s.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:l.value.push(c)}if((null==i?void 0:i.length)>0&&(null==i?void 0:i.find((e=>e.key===l.key)))){const e=i.findIndex((e=>e.key===l.key));i[e].value=[...i[e].value,...l.value]}else i.push(l)}})),this.feedback.answers=n?[]:i}finish(){return n(this,void 0,void 0,(function*(){if(this.completed=!0,this.timeToCompleted=(new Date).getTime()-this.timeToCompleted,this.feedback.metadata.push({key:"time-to-complete",value:[this.timeToCompleted.toString()]}),this.formOptionsConfig.addSuccessScreen){const e=document.getElementById("magicfeedback-container-"+this.appId);e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,r.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}this.answer();try{const e=yield this.pushAnswers(!0);if(!e)throw this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({loading:!1,progress:this.progress,total:this.total,completed:this.completed,error:`An error occurred while submitting the form ${this.appId}:`})),new Error("An error occurred while submitting the form ${this.appId}:");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}))}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,completed:this.completed,error:e}))}}))}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,o.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=Object.assign(Object.assign(Object.assign({answer:null===(t=this.feedback.answers.find((t=>t.key===e.ref)))||void 0===t?void 0:t.value[0]},""!==this.publicKey&&{publicKey:this.publicKey}),""===this.publicKey&&{campaignSessionId:this.appId}),{sessionId:this.id,question:e});return yield(0,o.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 o=[];for(const e of a){const t=n.questions.find((t=>t.ref===e));if(t){const e=yield this.callFollowUpQuestion(t);e&&o.push(e)}}if(0===o.length)return void(yield this.renderNextQuestion(e,n));const d=new l.Page(n.id,n.position,this.appId,o,n.edges),c=new p.PageNode(n.id,n.position,n.edges,d,o,!0);c.elements=(0,r.renderQuestions)(o,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(c),this.progress++,e.innerHTML="",null===(s=c.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:c.isFollowup,completed:this.completed,error:null}))}))}renderNextQuestion(e,t){var i,s,a;return n(this,void 0,void 0,(function*(){const n=this.graph.getNextPage(t,this.feedback.answers);n?(n.elements=(0,r.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.innerHTML="",null===(a=n.elements)||void 0===a||a.forEach((t=>e.appendChild(t))),this.history.enqueue(n),this.progress=this.total-this.graph.findMaxDepth(n),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.innerHTML=""),this.history.rollback();const i=this.history.back();i?(null===(e=i.elements)||void 0===e||e.forEach((e=>t.appendChild(e))),this.progress=this.total-this.graph.findMaxDepth(i)):this.progress=this.history.size(),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,r;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]}t.integrationPageRoutes&&(t.integrationPageRoutes=(null===(r=t.integrationPageRoutes)||void 0===r?void 0:r.sort(((e,t)=>new Date((null==e?void 0:e.generatedAt)||"").getTime()-new Date((null==t?void 0:t.generatedAt)||"").getTime()?"DIRECT"===e.typeCondition?1:-1:0)))||[]);const d=new n.PageNode(t.id,t.position,t.integrationPageRoutes||[],t,t.integrationQuestions);this.nodes.set(d.id,d)}))}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){var i;if(!e)return;e.edges.sort(((e,t)=>"DIRECT"===e.typeCondition?1:"DIRECT"===t.typeCondition?-1:0));const n=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(!n){const t=this.getNextEdgeByDefault(e);if(!t)return;return this.getNodeById(t)}switch(n.transition){case s.TransitionType.PAGE:if(!n.transitionDestiny)return;return this.getNodeById(n.transitionDestiny);case s.TransitionType.FINISH:return;case s.TransitionType.REDIRECT:return void(window.location.href=(null===(i=n.transitionDestiny)||void 0===i?void 0:i.includes("?"))?`${n.transitionDestiny}&${window.location.search.slice(1)}`:`${n.transitionDestiny}${window.location.search}`);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||[]],o=this.getNextEdgeByDefault(e);if(o){const i=this.getNodeById(o);i&&!t.has(i)&&a.push(new s.PageRoute(i.id,"",s.OperatorType.DEFAULT,"",s.TransitionType.PAGE,i.id,e.id))}for(const e of a){if(!e.transitionDestiny)continue;const s=this.getNodeById(e.transitionDestiny);if(s&&!t.has(s)){const e=s.questions.find((e=>e.followup))?i+2:i+1,a=new Set(t),o=this.DFSUtil(s,a,e);n=Math.max(n,o)}}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,l){this.id=e,this.questionRef=t,this.typeCondition=l||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",n.UPLOAD_FILE="UPLOAD_FILE",n.UPLOAD_IMAGE="UPLOAD_IMAGE",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,o="ltr",r="row"){const d=document.createElement("div");d.classList.add("magicfeedback-rating-placeholder"),d.style.display="flex",d.style.flexDirection=r,d.style.alignItems="center",d.style.justifyContent="space-between",d.style.width=s?`calc(100% - (100% / ${t+1}))`:"100%",d.style.marginRight="auto",a&&window.innerWidth<600&&(d.style.flexDirection="column");const l=document.createElement("span");l.textContent=i,l.classList.add("magicfeedback-rating-placeholder-value"),l.style.fontSize="15px",l.style.textAlign="ltr"===o?"left":"right",l.style.width="50%",(a&&window.innerWidth<600||"column"===r)&&(l.textContent=`${e} = ${i}`,l.style.width="100%",l.style.textAlign="left",l.style.marginBottom="5px");const c=document.createElement("span");return c.textContent=n,c.classList.add("magicfeedback-rating-placeholder-value"),c.style.fontSize="15px",c.style.textAlign="ltr"===o?"right":"left",c.style.width="50%",(a&&window.innerWidth<600||"column"===r)&&(c.textContent=`${t} = ${n}`,c.style.width="100%",c.style.textAlign="left",c.style.marginBottom="5px"),"ltr"===o?(i&&d.appendChild(l),n&&d.appendChild(c)):(n&&d.appendChild(c),i&&d.appendChild(l)),d}t.renderQuestions=function e(t,i="standard",d="en",l={customIcons:!1},c){if(!t)throw new Error("[MagicFeedback] No questions provided");const u=[],{customIcons:p,id:h}=l;return t.forEach((m=>{var f,g;if((null===(g=null===(f=null==m?void 0:m.questionType)||void 0===f?void 0:f.conf)||void 0===g?void 0:g.length)>0){let t=document.createElement("div");t.classList.add("magicfeedback-div");const n=document.createElement("label");n.setAttribute("for",`magicfeedback-${m.id}`),n.textContent=o(m.title,d),n.classList.add("magicfeedback-label"),t.appendChild(n),m.questionType.conf.forEach((e=>{e.ref=m.ref,m.assets[e.id]&&(e.assets={placeholder:m.assets[e.id]})})),e(m.questionType.conf,i,d,l,c).forEach((e=>{t.appendChild(e)})),u.push(t)}else{const e=function(e,t,i,d,l){let c,u,{id:p,title:h,type:m,ref:f,require:g,value:v,defaultValue:E,assets:y}=e,b=document.createElement("div");b.classList.add("magicfeedback-div");const k=window.innerWidth<600,C="slim"===t?o(h,i):null==y?void 0:y.placeholder,A=(L=p,new URLSearchParams(window.location.search).get(L)),x=(null==y?void 0:y.maxCharacters)||0,T=void 0!==(null==y?void 0:y.randomPosition)&&(null==y?void 0:y.randomPosition),w=(null==y?void 0:y.direction)||"row",P=(null==y?void 0:y.order)||"ltr";var L;switch(m){case n.FEEDBACKAPPANSWERTYPE.TEXT:c=document.createElement("input"),c.type="text",c.placeholder=C||s.placeholder.answer(i||"en"),c.addEventListener("keyup",(e=>{e.preventDefault(),console.log(e.key,e),"Enter"===e.key&&l&&l()})),u="magicfeedback-text";break;case n.FEEDBACKAPPANSWERTYPE.LONGTEXT:c=document.createElement("textarea"),c.rows=3,x>0&&(c.maxLength=x),c.placeholder=C||s.placeholder.answer(i||"en"),u="magicfeedback-longtext";break;case n.FEEDBACKAPPANSWERTYPE.NUMBER:c=document.createElement("input"),c.type="number",c.placeholder="slim"===t?o(h,i):s.placeholder.number(i||"en"),u="magicfeedback-number",v.length&&(v.sort(((e,t)=>Number(e)-Number(t))),c.max=v[v.length-1],c.min=v[0],c.value=v[0]);break;case n.FEEDBACKAPPANSWERTYPE.RADIO:case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:c=document.createElement("div"),u="magicfeedback-"+("MULTIPLECHOICE"===m?"checkbox":"radio");let I=v||[];T&&(I=I.sort((()=>Math.random()-.5)));let N=[];(null==y?void 0:y.exclusiveAnswers)&&(N=null==y?void 0:y.exclusiveAnswers,null==N||N.forEach((e=>{I.includes(e)||I.push(e)}))),(null==y?void 0:y.extraOption)&&(N.push(null==y?void 0:y.extraOptionText),I.includes(null==y?void 0:y.extraOptionText)||I.push(null==y?void 0:y.extraOptionText)),I.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==y?void 0:y.maxOptions)&&(null==y?void 0:y.maxOptions)>0&&r.addEventListener("change",(()=>{const e=document.querySelectorAll(`input[name="${f}"]:checked`);e.length>(null==y?void 0:y.maxOptions)&&(r.checked=!1),l&&e.length===(null==y?void 0:y.maxOptions)&&l()})),m===n.FEEDBACKAPPANSWERTYPE.RADIO&&l&&r.addEventListener("change",(()=>{l()})),e!==E&&e!==A||(r.checked=!0),o.textContent=e,o.htmlFor=`rating-${f}-${t}`,r.addEventListener("change",(t=>{const i=document.getElementById(`extra-option-${f}`);t.target.checked&&N.includes(e)?(I.forEach((t=>{t!==e&&(document.querySelector(`input[value="${t}"]`).checked=!1)})),i&&(i.style.display=(null==y?void 0:y.extraOption)&&e===(null==y?void 0:y.extraOptionText)?"block":"none")):(N.forEach((t=>{t!==e&&(document.querySelector(`input[value="${t}"]`).checked=!1)})),i&&(i.style.display="none"))})),a.appendChild(r),a.appendChild(o),c.appendChild(a),(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)||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",c.appendChild(e)}}));break;case n.FEEDBACKAPPANSWERTYPE.BOOLEAN:c=document.createElement("div"),u="magicfeedback-radio";const D=document.createElement("div");D.classList.add("magicfeedback-boolean-container"),D.style.display="flex",D.style.flexDirection="row",D.style.justifyContent="space-between",D.style.width="70%",D.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 s=document.createElement("input");s.id=`rating-${f}-${t}`,s.type="radio",s.name=f,s.value=v[t],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",(()=>{l&&l()})),i.appendChild(s),i.appendChild(n),D.appendChild(i)})),c.appendChild(D);break;case n.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:c=document.createElement("div"),u="magicfeedback-rating";const R=document.createElement("div");R.classList.add("magicfeedback-rating-container");const $=(null==y?void 0:y.max)?Number(null==y?void 0:y.max):5,_=(null==y?void 0:y.min)?Number(null==y?void 0:y.min):1,F=r(_,$,null==y?void 0:y.minPlaceholder,null==y?void 0:y.maxPlaceholder,null==y?void 0:y.extraOption);for(let pe=_;pe<=$;pe++){const he=document.createElement("div");he.classList.add("magicfeedback-rating-option");const me=document.createElement("label");me.htmlFor=`rating-${f}-${pe}`,me.classList.add("magicfeedback-rating-option-label-container");const fe=document.createElement("label");fe.htmlFor=`rating-${f}-${pe}`,fe.textContent=pe.toString();const ge=document.createElement("img");if(ge.alt=`face-${f}-${pe}`,ge.className=`rating-image${pe}`,0===_&&10===$)ge.src=`${d}/${pe}.svg`,ge.onerror=()=>ge.src=`${a}/${pe}.svg`;else if(1===_&&5===$)switch(pe){case 1:ge.src=`${d}/1.svg`,ge.onerror=()=>ge.src=`${a}/1.svg`;break;case 2:ge.src=`${d}/2.svg`,ge.onerror=()=>ge.src=`${a}/2.svg`;break;case 3:ge.src=`${d}/6.svg`,ge.onerror=()=>ge.src=`${a}/6.svg`;break;case 4:ge.src=`${d}/9.svg`,ge.onerror=()=>ge.src=`${a}/9.svg`;break;case 5:ge.src=`${d}/10.svg`,ge.onerror=()=>ge.src=`${a}/10.svg`}else{const Ee=Math.round(10/($-_)*(pe-_));ge.src=`${d}/${Ee}.svg`,ge.onerror=()=>ge.src=`${a}/${Ee}.svg`}const ve=document.createElement("input");ve.id=`rating-${f}-${pe}`,ve.type="radio",ve.name=f,ve.value=pe.toString(),ve.classList.add(u),ve.classList.add("magicfeedback-input"),l&&ve.addEventListener("change",(()=>{l()})),me.appendChild(ve),me.appendChild(ge),me.appendChild(fe),he.appendChild(me),R.appendChild(he)}if((null==y?void 0:y.extraOption)&&(null==y?void 0:y.extraOptionText)){const ye=document.createElement("div");ye.classList.add("magicfeedback-rating-option");const be=document.createElement("label");be.htmlFor=`rating-${f}-extra`,be.classList.add("magicfeedback-rating-option-label-container");const ke=document.createElement("label");ke.htmlFor=`rating-${f}-extra`,ke.textContent=null==y?void 0:y.extraOptionText;const Ce=document.createElement("img");Ce.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",Ce.alt=`face-${f}-extra`,Ce.className="magicfeedback-rating-image-extra";const Ae=document.createElement("input");Ae.id=`rating-${f}-extra`,Ae.type="radio",Ae.name=f,Ae.value="-",Ae.classList.add(u),Ae.classList.add("magicfeedback-input"),l&&Ae.addEventListener("change",(()=>{l()})),be.appendChild(Ae),be.appendChild(Ce),be.appendChild(ke),ye.appendChild(be),R.appendChild(ye)}c.appendChild(F),c.appendChild(R);break;case n.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:c=document.createElement("div"),u="magicfeedback-rating-number";const M="ltr"===P?w:`${w}-reverse`,B=document.createElement("div");B.classList.add("magicfeedback-rating-number-container"),B.classList.add(`magicfeedback-rating-number-container-${P}`),B.classList.add(`magicfeedback-rating-number-container-${w}`),B.style.display="flex",B.style.flexDirection=M;const U=(null==y?void 0:y.max)?Number(null==y?void 0:y.max):10,q=(null==y?void 0:y.min)?Number(null==y?void 0:y.min):0,j=r(q,U,null==y?void 0:y.minPlaceholder,null==y?void 0:y.maxPlaceholder,null==y?void 0:y.extraOption,!0,P,w);for(let xe=q;xe<=U;xe++){const Te=document.createElement("div");Te.classList.add("magicfeedback-rating-number-option"),Te.classList.add(`magicfeedback-rating-number-option-${w}`);const we=document.createElement("label");we.htmlFor=`rating-${f}-${xe}`,we.classList.add("magicfeedback-rating-number-option-label-container");let Pe=xe.toString();(k||"column"===w)&&xe===q&&(null==y?void 0:y.minPlaceholder)&&(Pe+=` = ${null==y?void 0:y.minPlaceholder}`),(k||"column"===w)&&xe===U&&(null==y?void 0:y.maxPlaceholder)&&(Pe+=` = ${null==y?void 0:y.maxPlaceholder}`);const Le=document.createElement("label");Le.htmlFor=`rating-${f}-${xe}`,Le.textContent=Pe;const Se=document.createElement("input");Se.id=`rating-${f}-${xe}`,Se.type="radio",Se.name=f,Se.value=xe.toString(),Se.classList.add(u),Se.classList.add("magicfeedback-input"),l&&Se.addEventListener("change",(()=>{l()})),we.appendChild(Se),we.appendChild(Le),Te.appendChild(we),B.appendChild(Te)}if((null==y?void 0:y.extraOption)&&(null==y?void 0:y.extraOptionText)){const Oe=document.createElement("div");Oe.classList.add("magicfeedback-rating-number-option");const Ie=document.createElement("label");Ie.htmlFor=`rating-${f}-extra`,Ie.classList.add("magicfeedback-rating-number-option-label-container");const Ne=document.createElement("label");Ne.htmlFor=`rating-${f}-extra`,Ne.textContent=null==y?void 0:y.extraOptionText;const De=document.createElement("input");De.id=`rating-${f}-extra`,De.type="radio",De.name=f,De.value="-",De.classList.add(u),De.classList.add("magicfeedback-input"),l&&De.addEventListener("change",(()=>{l()})),Ie.appendChild(De),Ie.appendChild(Ne),Oe.appendChild(Ie),B.appendChild(Oe)}k||"column"===w||c.appendChild(j),c.appendChild(B);break;case n.FEEDBACKAPPANSWERTYPE.RATING_STAR:c=document.createElement("div"),u="magicfeedback-rating-star";const K=function(e,t,i,n=(()=>{})){const s="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 o=document.createElement("input");o.id=`rating-${e}-${t}`,o.type="radio",o.name=e,o.value=t.toString(),o.style.position="absolute",o.style.opacity="0",o.style.width="0",o.style.height="0",o.classList.add("magicfeedback-input"),o.addEventListener("change",(()=>{const e=a.querySelectorAll(".rating__star");for(let t=0;t<e.length;t++)t+1<=Number(o.value)?e[t].classList.contains(s)||e[t].classList.add(s):e[t].classList.contains(s)&&e[t].classList.remove(s);n&&n()})),i.appendChild(o);const r=document.createElement("label");r.htmlFor=`rating-${e}-${t}`,r.classList.add("rating__star"),r.textContent="★",r.style.fontSize="40px",r.style.color="#CCCCCC",r.style.cursor="pointer",i.appendChild(r),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);c.appendChild(K);break;case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:c=document.createElement("div"),u="magicfeedback-multiple-choice-image";const W=document.createElement("div");W.classList.add("magicfeedback-multiple-choice-image-container"),W.style.display="flex",W.style.flexDirection="row",W.style.flexWrap="wrap",W.style.justifyContent="center";const G=v.length;let Y=1,Q=1;if(window.innerWidth<600)Y=1,Q=G;else switch(G){case 1:case 2:case 3:Y=G,Q=1;break;case 4:case 5:case 6:Q=2,Y=Math.ceil(G/Q);break;case 7:case 8:case 9:Q=3,Y=Math.ceil(G/Q);break;default:Q=4,Y=Math.ceil(G/Q)}const H=void 0!==(null==y?void 0:y.addTitle)&&(null==y?void 0:y.addTitle),V=void 0!==(null==y?void 0:y.multiOption)&&(null==y?void 0:y.multiOption),X=void 0!==(null==y?void 0:y.extraOption)&&(null==y?void 0:y.extraOption);function z(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/Y}% - 10px)`,s.style.height=`calc( ${100/Q}% - 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=V?"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"),console.log("send",l),console.log("multiOptions",V),!V&&l&&r.addEventListener("change",(()=>{console.log("send"),l()}));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),H&&a.appendChild(o),s.appendChild(a),W.appendChild(s)}catch(e){console.error(e)}}T&&(v=v.sort((()=>Math.random()-.5))),v.forEach((e=>z(JSON.parse(e)))),X&&(null==y?void 0:y.extraOptionValue)&&(null==y?void 0:y.extraOptionValue.length)>0&&z(null==y?void 0:y.extraOptionValue[0]),c.appendChild(W);break;case n.FEEDBACKAPPANSWERTYPE.SELECT:c=document.createElement("select"),u="magicfeedback-select";const J=document.createElement("option");J.value="",J.text="slim"===t?o(h,i):E||"Select an option",J.disabled=!0,J.selected=!0,c.appendChild(J),v.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,c.appendChild(t)})),l&&c.addEventListener("change",(()=>{l()}));break;case n.FEEDBACKAPPANSWERTYPE.DATE:c=document.createElement("input"),c.type="date",c.required=g,c.placeholder=C||s.placeholder.date(i||"en"),u="magicfeedback-date";break;case n.FEEDBACKAPPANSWERTYPE.CONSENT:c=document.createElement("input"),u="magicfeedback-consent",c.type="checkbox",c.id=`magicfeedback-${p}`,c.name=f,c.value="true",c.required=g,c.classList.add("magicfeedback-consent"),c.classList.add("magicfeedback-input"),l&&c.addEventListener("change",(()=>{l()}));break;case n.FEEDBACKAPPANSWERTYPE.EMAIL:c=document.createElement("input"),c.type="email",c.required=g,c.placeholder=C||"you@example.com",u="magicfeedback-email";break;case n.FEEDBACKAPPANSWERTYPE.PASSWORD:c=document.createElement("input"),c.type="password",c.required=g,c.placeholder=C||s.placeholder.password(i||"en"),u="magicfeedback-password";break;case n.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:c=document.createElement("div"),u="magicfeedback-multi-question-matrix";const Z=document.createElement("div");Z.classList.add("magicfeedback-multi-question-matrix-container");let ee=(null==y?void 0:y.options)||[],te=[...v],ie=[];if(T&&(ee=null==ee?void 0:ee.sort((()=>Math.random()-.5)),te=[...te].sort((()=>Math.random()-.5))),(null==y?void 0:y.exclusiveAnswers)&&(ie=null==y?void 0:y.exclusiveAnswers,null==ie||ie.forEach((e=>{te.includes(e)||te.push(e)}))),window.innerWidth<600){const Re=document.createElement("div");Re.classList.add("magicfeedback-multi-question-matrix-list"),null==ee||ee.forEach((e=>{const t=document.createElement("div");t.classList.add("magicfeedback-multi-question-matrix-list-item"),t.style.display="flex",t.style.flexDirection="column",t.style.alignItems="flex-start",t.style.marginBottom="10px";const i=document.createElement("label");i.classList.add("magicfeedback-multi-question-matrix-label"),i.style.paddingBottom="10px",i.textContent=e,t.appendChild(i),te.forEach((i=>{const n=document.createElement("div");n.classList.add("magicfeedback-radio-container"),n.style.display="flex",n.style.alignItems="center",n.style.justifyContent="flex-start",n.style.width="99%",n.style.margin="5px auto";const s=document.createElement("label"),a=document.createElement("input");a.id=`${f}-${e}-${i}`,a.type="radio",a.name=`${f}-${e}`,a.value=i,a.classList.add("magicfeedback-input"),s.textContent=i,s.htmlFor=`${f}-${e}-${i}`,n.appendChild(a),n.appendChild(s),t.appendChild(n)})),Re.appendChild(t)})),Z.appendChild(Re)}else{const $e=document.createElement("table");$e.classList.add("magicfeedback-multi-question-matrix-table");const _e=document.createElement("thead");_e.classList.add("magicfeedback-multi-question-matrix-header"),_e.style.paddingBottom="15px";const Fe=document.createElement("tr"),Me=document.createElement("th");Fe.appendChild(Me),te.forEach((e=>{const t=document.createElement("th");t.textContent=e,Fe.appendChild(t)})),_e.appendChild(Fe),$e.appendChild(_e);const Be=document.createElement("tbody");null==ee||ee.forEach((e=>{const t=document.createElement("tr");t.classList.add("magicfeedback-multi-question-matrix-row-tr");const i=document.createElement("td");i.style.minWidth="200px";const n=document.createElement("label");n.classList.add("magicfeedback-multi-question-matrix-label"),n.style.paddingRight="20px",n.textContent=e,i.appendChild(n),t.appendChild(i),te.forEach((i=>{const n=document.createElement("td"),s=document.createElement("input");s.type="radio",s.name=`${f}-${e}`,s.value=i,s.id=`${f}-${e}-${i}`,s.classList.add("magicfeedback-input"),n.appendChild(s),t.appendChild(n)})),Be.appendChild(t)})),$e.appendChild(Be),Z.appendChild($e)}c.appendChild(Z);break;case n.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:c=document.createElement("div"),u="magicfeedback-priority-list";const ne=document.createElement("div");ne.classList.add("magicfeedback-priority-list-container");const se=document.createElement("ul");se.classList.add("magicfeedback-priority-list-list"),T&&(v=v.sort((()=>Math.random()-.5))),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 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,d,l;const c=i.previousElementSibling;if(c){const u=Number(null===(t=n.value)||void 0===t?void 0:t.split(".")[0])-1;n.value=`${u}. ${e}`,s.textContent=`${u}. ${e}`,o.style.visibility=1===u?"hidden":"visible",r.style.visibility=u===v.length?"hidden":"visible";const p=c.querySelector(".magicfeedback-input-magicfeedback-priority-list"),h=c.querySelector(".magicfeedback-priority-list-item-label"),m=c.querySelector(".magicfeedback-priority-list-arrow-up"),f=c.querySelector(".magicfeedback-priority-list-arrow-down");if(p&&h&&m&&f){const e=Number(null===(a=p.value)||void 0===a?void 0:a.split(".")[0])+1;p.value=`${e}.${null===(d=h.textContent)||void 0===d?void 0:d.split(".")[1]}`,h.textContent=`${e}.${null===(l=h.textContent)||void 0===l?void 0:l.split(".")[1]}`,m.style.visibility=1===e?"hidden":"visible",f.style.visibility=e===v.length?"hidden":"visible"}se.insertBefore(i,c)}})),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,d;const l=i.nextElementSibling;if(l){const c=Number(null===(t=n.value)||void 0===t?void 0:t.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 u=l.querySelector(".magicfeedback-input-magicfeedback-priority-list"),p=l.querySelector(".magicfeedback-priority-list-item-label"),h=l.querySelector(".magicfeedback-priority-list-arrow-up"),m=l.querySelector(".magicfeedback-priority-list-arrow-down");if(u&&p&&h&&m){const e=Number(u.value.split(".")[0])-1;u.value=`${e}.${null===(a=p.textContent)||void 0===a?void 0:a.split(".")[1]}`,p.textContent=`${e}.${null===(d=p.textContent)||void 0===d?void 0:d.split(".")[1]}`,h.style.visibility=1===e?"hidden":"visible",m.style.visibility=e===v.length?"hidden":"visible"}se.insertBefore(l,i)}})),a.appendChild(r),i.appendChild(a),se.appendChild(i)})),ne.appendChild(se),c.appendChild(ne);break;case n.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:c=document.createElement("div"),u="magicfeedback-point-system";const ae=document.createElement("div");ae.classList.add("magicfeedback-point-system-container");const oe=document.createElement("ul");oe.classList.add("magicfeedback-point-system-list"),oe.style.padding="0";const re=100,de=re/v.length,le=document.createElement("div");le.classList.add("magicfeedback-error"),le.textContent=s.placeholder.pointsystemerror(i||"en"),le.style.color="#C70039",le.style.fontSize="14px",le.style.textAlign="right",le.style.width="100%",le.style.display="none";const ce=document.createElement("div");ce.classList.add("magicfeedback-point-system-total"),ce.textContent="0 / 100 %",ce.style.textAlign="right",ce.style.fontSize="15px",ce.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=f,a.id=`${e}`,a.type="number",a.min="0",a.max=`${re}`,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=oe.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>re&&(a.value=`${de}%`,t-=Number(a.value));const i=document.getElementById("magicfeedback-submit");i&&(t<100?(ce.style.color="orange",i.setAttribute("disabled","true")):(le.style.display="none",ce.style.color="green",i.removeAttribute("disabled"))),ce.textContent=`${t} / 100 %`})),a.addEventListener("focus",(()=>{const e=document.getElementById("magicfeedback-submit");e&&(e.setAttribute("disabled","true"),e.addEventListener("pointerover",(()=>{const e=oe.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t<100&&(le.style.display="block")})))})),s.appendChild(a),s.appendChild(o),i.appendChild(s),oe.appendChild(i)})),ae.appendChild(oe),ae.appendChild(ce),ae.appendChild(le),c.appendChild(ae);break;case n.FEEDBACKAPPANSWERTYPE.INFO_PAGE:c=document.createElement("div"),u="magicfeedback-info-page";const ue=document.createElement("div");ue.classList.add("magicfeedback-info-message"),ue.innerHTML=C,c.appendChild(ue);break;case n.FEEDBACKAPPANSWERTYPE.UPLOAD_IMAGE:c=document.createElement("input"),c.type="file",c.accept="image/*",c.required=g,c.multiple=(null==y?void 0:y.multiple)||!1,c.maxLength=(null==y?void 0:y.maxFiles)||1,u="magicfeedback-upload-image";break;case n.FEEDBACKAPPANSWERTYPE.UPLOAD_FILE:c=document.createElement("input"),c.type="file",c.required=g,c.multiple=(null==y?void 0:y.multiple)||!1,c.maxLength=(null==y?void 0:y.maxFiles)||1,u="magicfeedback-upload-file";break;default:return b}c.id=`magicfeedback-${p}`,c.setAttribute("name",f),c.classList.add(u),(void 0!==E||null!==A)&&(c.value=A||E),["RADIO","MULTIPLECHOICE"].includes(m)||(c.classList.add("magicfeedback-input"),c.required=g);const S=document.createElement("label");S.setAttribute("for",`magicfeedback-${p}`),S.textContent=o(h,i),S.classList.add("magicfeedback-label");const O=document.createElement("label");if(O.textContent=o(null==y?void 0:y.subtitle,i),O.classList.add("magicfeedback-sublabel"),["CONSENT"].includes(m))b.classList.add("magicfeedback-consent-container"),b.appendChild(c),b.appendChild(S),b.appendChild(O);else{if("slim"!==t&&([n.FEEDBACKAPPANSWERTYPE.INFO_PAGE].includes(m)||(b.appendChild(S),b.appendChild(O)),void 0!==(null==y?void 0:y.general)&&""!==(null==y?void 0:y.general))){const Ue=document.createElement("img");Ue.src=null==y?void 0:y.general,Ue.classList.add("magicfeedback-image"),Ue.style.maxWidth="auto",Ue.style.height="400px",Ue.style.margin="10px 0",b.appendChild(Ue)}if("LONGTEXT"===m&&x>0){const qe=document.createElement("div");if(qe.classList.add("magicfeedback-counter"),qe.textContent=`${c.value.length}/${x}`,qe.style.textAlign="right",qe.style.fontSize="15px",qe.style.marginTop="5px",c.addEventListener("input",(()=>{qe.textContent=`${c.value.length}/${x}`})),b.appendChild(c),b.appendChild(qe),(null==y?void 0:y.extraOption)&&(null==y?void 0:y.extraOptionText)){const je=document.createElement("div");je.classList.add("magicfeedback-skip-container"),je.classList.add("magicfeedback-checkbox-container"),je.style.display="flex",je.style.justifyContent="flex-start";const Ke=document.createElement("input");Ke.classList.add("magicfeedback-skip"),Ke.type="checkbox",Ke.id=`skip-${f}`,Ke.name=f,Ke.value="-",Ke.style.cursor="pointer";const We=document.createElement("label");We.htmlFor=`skip-${f}`,We.textContent=null==y?void 0:y.extraOptionText,We.style.fontSize="15px",We.style.cursor="pointer",We.style.margin="0 5px",Ke.addEventListener("click",(()=>{c.value="-",l&&l()})),je.appendChild(Ke),je.appendChild(We),b.appendChild(je)}}else b.appendChild(c)}return b}(m,i,d,`${a}${p?`/${h}`:""}`,1===t.length?c:void 0);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,"x-magicfeedback-parameters":window.location.search||""};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});return yield n.json()}catch(e){s.err(e)}}))},t.getSessionForm=function(e,t,i){return n(this,void 0,void 0,(function*(){try{const i=yield(0,a.default)(e+r.endpoints.sdk.session(t),{method:"GET",headers:d});return yield i.json()}catch(e){i.err(e)}}))},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":"2.0.0-beta.1","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.deepdots.com/"},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,l){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"),c={integration:i,publicKey:a,privateKey:l,completed:o,id:d,feedback:s};try{const e=yield(0,r.sendFeedback)(n,c,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(244),s=i(5),o=i(341),r=i(183),d=i(24),l=i(804),c=i(116),u=i(314),p=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.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.history=new u.History,this.graph=new d.PageGraph([]),this.progress=0,this.total=0,this.completed=!1,this.timeToCompleted=0}generate(e,t){var i,a,s,r,d,l,c;return n(this,void 0,void 0,(function*(){try{this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e;let n=this.formData;if(void 0!==this.formData&&this.formData||(n=""!==this.publicKey?yield(0,o.getForm)(this.url,this.appId,this.publicKey,this.log):yield(0,o.getSessionForm)(this.url,this.appId,this.log)),void 0===n||!n)throw new Error(`No data for app ${this.appId}`);if(null===(i=n.error)||void 0===i?void 0:i.message)throw new Error(n.error.message);if(n.questions=(null===(a=n.questions)||void 0===a?void 0:a.filter((e=>"ACTIVE"===e.status)))||[],n.pages=(null===(s=n.pages)||void 0===s?void 0:s.filter((e=>"ACTIVE"===e.status)))||[],null===(r=n.pages)||void 0===r||r.forEach((e=>{var t;return e.integrationQuestions=null===(t=e.integrationQuestions)||void 0===t?void 0:t.filter((e=>"ACTIVE"===e.status))})),this.formData=n,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===(d=this.formData.pages)||void 0===d?void 0:d.length)||this.formatPages(),null===(l=this.formData.questions)||void 0===l||l.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===(c=this.formData.style)||void 0===c?void 0:c.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 l.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 l.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 d.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,s.addEventListener("submit",(e=>e.preventDefault()));const o=document.createElement("div");o.classList.add("magicfeedback-questions"),o.id="magicfeedback-questions-"+this.appId;const l=this.graph.getFirstPage();if(!l)throw new Error("No page found");if(this.total=this.graph.findMaxDepth(),l.elements=(0,r.renderQuestions)(l.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=l.elements)||void 0===i||i.forEach((e=>o.appendChild(e))),s.appendChild(o),this.history.enqueue(l),n.appendChild(s),this.progress=this.total-this.graph.findMaxDepth(l),this.formOptionsConfig.addButton){const e=(0,r.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.timeToCompleted=(new Date).getTime()/1e3,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,r.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");for(const e of a.questions.filter((e=>e.require))){const t=e.assets,i=this.feedback.answers.filter((t=>t.key.includes(e.ref)&&!t.key.includes("extra-option")));if(0===i.length||i.find((e=>0===e.value.length)))throw this.log.err(`The question ${e.ref} is required`),new Error("No response");if(null==t?void 0:t.minOptions){let n=[];if((null==t?void 0:t.exclusiveAnswers)&&(n=null==t?void 0:t.exclusiveAnswers),(null==t?void 0:t.extraOption)&&n.push(null==t?void 0:t.extraOptionText),!i[0].value.find((e=>n.includes(e)))&&i[0].value.length<(null==t?void 0:t.minOptions))throw this.log.err(`The question ${e.ref} requires at least ${null==t?void 0:t.minOptions} options`),new Error("No response")}}const s=yield this.pushAnswers(!1);if(!s)throw new Error("No response");this.id=s,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=[]);const t=this.history.back();if(!t)throw new Error("No page found");const i=[];let n=!1;e.querySelectorAll(".magicfeedback-input").forEach((e=>{const s=t.questions.find((t=>{var i;return null===(i=e.name)||void 0===i?void 0:i.includes(t.ref)})),r=e.type,d=e.classList[0],l={key:e.name,value:[]},c="magicfeedback-consent"===d?e.checked.toString():e.value;if(l.key&&""!==l.key){switch(null==s?void 0:s.type){case a.FEEDBACKAPPANSWERTYPE.EMAIL:case a.FEEDBACKAPPANSWERTYPE.TEXT:case a.FEEDBACKAPPANSWERTYPE.LONGTEXT:case a.FEEDBACKAPPANSWERTYPE.NUMBER:case a.FEEDBACKAPPANSWERTYPE.DATE:case a.FEEDBACKAPPANSWERTYPE.CONTACT:if(""!==c){if("email"===r){if(!(0,o.validateEmail)(c)){this.log.err("Invalid email"),n=!0;break}this.feedback.profile.push({key:"email",value:[c]})}l.value.push(c)}break;case a.FEEDBACKAPPANSWERTYPE.CONSENT:l.value.push(String(e.checked));break;case a.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:const t=e.id;l.value.push(`${t}:${c}%`);break;case a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:case a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:case a.FEEDBACKAPPANSWERTYPE.RATING_STAR:case a.FEEDBACKAPPANSWERTYPE.RADIO:case a.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:case a.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:(e.checked||e.id.includes("extra-option-"))&&l.value.push(c);break;case a.FEEDBACKAPPANSWERTYPE.SELECT:l.value.push(c);break;case a.FEEDBACKAPPANSWERTYPE.BOOLEAN:case a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:e.checked&&l.value.push(c);break;case a.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:l.value.push(c)}if((null==i?void 0:i.length)>0&&(null==i?void 0:i.find((e=>e.key===l.key)))){const e=i.findIndex((e=>e.key===l.key));i[e].value=[...i[e].value,...l.value]}else i.push(l)}})),this.feedback.answers=n?[]:i}finish(){return n(this,void 0,void 0,(function*(){if(this.completed=!0,this.timeToCompleted=(new Date).getTime()-this.timeToCompleted,this.feedback.metadata.push({key:"time-to-complete",value:[this.timeToCompleted.toString()]}),this.formOptionsConfig.addSuccessScreen){const e=document.getElementById("magicfeedback-container-"+this.appId);e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,r.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}this.answer();try{const e=yield this.pushAnswers(!0);if(!e)throw this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({loading:!1,progress:this.progress,total:this.total,completed:this.completed,error:`An error occurred while submitting the form ${this.appId}:`})),new Error("An error occurred while submitting the form ${this.appId}:");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}))}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,completed:this.completed,error:e}))}}))}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,o.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=Object.assign(Object.assign(Object.assign({answer:null===(t=this.feedback.answers.find((t=>t.key===e.ref)))||void 0===t?void 0:t.value[0]},""!==this.publicKey&&{publicKey:this.publicKey}),""===this.publicKey&&{campaignSessionId:this.appId}),{sessionId:this.id,question:e});return yield(0,o.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 o=[];for(const e of s){const t=n.questions.find((t=>t.ref===e));if(t){const e=yield this.callFollowUpQuestion(t);e&&o.push(e)}}if(0===o.length)return void(yield this.renderNextQuestion(e,n));const d=new l.Page(n.id,n.position,this.appId,o,n.edges),c=new p.PageNode(n.id,n.position,n.edges,d,o,!0);c.elements=(0,r.renderQuestions)(o,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(c),this.progress++,e.innerHTML="",null===(a=c.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:c.isFollowup,completed:this.completed,error:null}))}))}renderNextQuestion(e,t){var i,a,s;return n(this,void 0,void 0,(function*(){const n=this.graph.getNextPage(t,this.feedback.answers);n?(n.elements=(0,r.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.innerHTML="",null===(s=n.elements)||void 0===s||s.forEach((t=>e.appendChild(t))),this.history.enqueue(n),this.progress=this.total-this.graph.findMaxDepth(n),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.innerHTML=""),this.history.rollback();const i=this.history.back();i?(null===(e=i.elements)||void 0===e||e.forEach((e=>t.appendChild(e))),this.progress=this.total-this.graph.findMaxDepth(i)):this.progress=this.history.size(),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,r;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]}t.integrationPageRoutes&&(t.integrationPageRoutes=(null===(r=t.integrationPageRoutes)||void 0===r?void 0:r.sort(((e,t)=>new Date((null==e?void 0:e.generatedAt)||"").getTime()-new Date((null==t?void 0:t.generatedAt)||"").getTime()?"DIRECT"===e.typeCondition?1:-1:0)))||[]);const d=new n.PageNode(t.id,t.position,t.integrationPageRoutes||[],t,t.integrationQuestions);this.nodes.set(d.id,d)}))}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){var i;if(!e)return;e.edges.sort(((e,t)=>"DIRECT"===e.typeCondition?1:"DIRECT"===t.typeCondition?-1:0));const n=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(!n){const t=this.getNextEdgeByDefault(e);if(!t)return;return this.getNodeById(t)}switch(n.transition){case a.TransitionType.PAGE:if(!n.transitionDestiny)return;return this.getNodeById(n.transitionDestiny);case a.TransitionType.FINISH:return;case a.TransitionType.REDIRECT:return void(window.location.href=(null===(i=n.transitionDestiny)||void 0===i?void 0:i.includes("?"))?`${n.transitionDestiny}&${window.location.search.slice(1)}`:`${n.transitionDestiny}${window.location.search}`);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||[],o=this.getNextEdgeByDefault(e);if(o){const i=this.getNodeById(o);i&&!t.has(i)&&s.push(new a.PageRoute(i.id,"",a.OperatorType.DEFAULT,"",a.TransitionType.PAGE,i.id,e.id))}for(const e of s){if(!e.transitionDestiny)continue;const a=this.getNodeById(e.transitionDestiny);if(a&&!t.has(a)){const e=a.questions.find((e=>e.followup))?i+2:i+1,s=new Set(t),o=this.DFSUtil(a,s,e);n=Math.max(n,o)}}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,l){this.id=e,this.questionRef=t,this.typeCondition=l||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",n.UPLOAD_FILE="UPLOAD_FILE",n.UPLOAD_IMAGE="UPLOAD_IMAGE",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,o="ltr",r="row"){const d=document.createElement("div");d.classList.add("magicfeedback-rating-placeholder"),d.style.display="flex",d.style.flexDirection=r,d.style.alignItems="center",d.style.justifyContent="space-between",d.style.width=a?`calc(100% - (100% / ${t+1}))`:"100%",d.style.marginRight="auto",s&&window.innerWidth<600&&(d.style.flexDirection="column");const l=document.createElement("span");l.textContent=i,l.classList.add("magicfeedback-rating-placeholder-value"),l.style.fontSize="15px",l.style.textAlign="ltr"===o?"left":"right",l.style.width="50%",(s&&window.innerWidth<600||"column"===r)&&(l.textContent=`${e} = ${i}`,l.style.width="100%",l.style.textAlign="left",l.style.marginBottom="5px");const c=document.createElement("span");return c.textContent=n,c.classList.add("magicfeedback-rating-placeholder-value"),c.style.fontSize="15px",c.style.textAlign="ltr"===o?"right":"left",c.style.width="50%",(s&&window.innerWidth<600||"column"===r)&&(c.textContent=`${t} = ${n}`,c.style.width="100%",c.style.textAlign="left",c.style.marginBottom="5px"),"ltr"===o?(i&&d.appendChild(l),n&&d.appendChild(c)):(n&&d.appendChild(c),i&&d.appendChild(l)),d}t.renderQuestions=function e(t,i="standard",d="en",l={customIcons:!1},c){if(!t)throw new Error("[MagicFeedback] No questions provided");const u=[],{customIcons:p,id:m}=l;return t.forEach((h=>{var f,g;if((null===(g=null===(f=null==h?void 0:h.questionType)||void 0===f?void 0:f.conf)||void 0===g?void 0:g.length)>0){let t=document.createElement("div");t.classList.add("magicfeedback-div");const n=document.createElement("label");n.setAttribute("for",`magicfeedback-${h.id}`),n.textContent=o(h.title,d),n.classList.add("magicfeedback-label"),t.appendChild(n),h.questionType.conf.forEach((e=>{e.ref=h.ref,h.assets[e.id]&&(e.assets={placeholder:h.assets[e.id]})})),e(h.questionType.conf,i,d,l,c).forEach((e=>{t.appendChild(e)})),u.push(t)}else{const e=function(e,t,i,d,l){let c,u,{id:p,title:m,type:h,ref:f,require:g,value:v,defaultValue:E,assets:b}=e,y=document.createElement("div");y.classList.add("magicfeedback-div");const k=window.innerWidth<600,C="slim"===t?o(m,i):null==b?void 0:b.placeholder,A=(w=p,new URLSearchParams(window.location.search).get(w)),x=(null==b?void 0:b.maxCharacters)||0,T=void 0!==(null==b?void 0:b.randomPosition)&&(null==b?void 0:b.randomPosition),L=(null==b?void 0:b.direction)||"row",P=(null==b?void 0:b.order)||"ltr";var w;switch(h){case n.FEEDBACKAPPANSWERTYPE.TEXT:c=document.createElement("input"),c.type="text",c.placeholder=C||a.placeholder.answer(i||"en"),c.addEventListener("keyup",(e=>{e.preventDefault(),console.log(e.key,e),"Enter"===e.key&&l&&l()})),u="magicfeedback-text";break;case n.FEEDBACKAPPANSWERTYPE.LONGTEXT:c=document.createElement("textarea"),c.rows=3,x>0&&(c.maxLength=x),c.placeholder=C||a.placeholder.answer(i||"en"),u="magicfeedback-longtext";break;case n.FEEDBACKAPPANSWERTYPE.NUMBER:c=document.createElement("input"),c.type="number",c.placeholder="slim"===t?o(m,i):a.placeholder.number(i||"en"),u="magicfeedback-number",v.length&&(v.sort(((e,t)=>Number(e)-Number(t))),c.max=v[v.length-1],c.min=v[0],c.value=v[0]);break;case n.FEEDBACKAPPANSWERTYPE.RADIO:case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:c=document.createElement("div"),u="magicfeedback-"+("MULTIPLECHOICE"===h?"checkbox":"radio");let I=v||[];T&&(I=I.sort((()=>Math.random()-.5)));let N=[];(null==b?void 0:b.exclusiveAnswers)&&(N=null==b?void 0:b.exclusiveAnswers,null==N||N.forEach((e=>{I.includes(e)||I.push(e)}))),(null==b?void 0:b.extraOption)&&(N.push(null==b?void 0:b.extraOptionText),I.includes(null==b?void 0:b.extraOptionText)||I.push(null==b?void 0:b.extraOptionText)),I.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==b?void 0:b.maxOptions)&&(null==b?void 0:b.maxOptions)>0&&r.addEventListener("change",(()=>{const e=document.querySelectorAll(`input[name="${f}"]:checked`);e.length>(null==b?void 0:b.maxOptions)&&(r.checked=!1),l&&e.length===(null==b?void 0:b.maxOptions)&&l()})),h===n.FEEDBACKAPPANSWERTYPE.RADIO&&l&&r.addEventListener("change",(()=>{l()})),e!==E&&e!==A||(r.checked=!0),o.textContent=e,o.htmlFor=`rating-${f}-${t}`,r.addEventListener("change",(t=>{const i=document.getElementById(`extra-option-${f}`);t.target.checked&&N.includes(e)?(I.forEach((t=>{t!==e&&(document.querySelector(`input[value="${t}"]`).checked=!1)})),i&&(i.style.display=(null==b?void 0:b.extraOption)&&e===(null==b?void 0:b.extraOptionText)?"block":"none")):(N.forEach((t=>{t!==e&&(document.querySelector(`input[value="${t}"]`).checked=!1)})),i&&(i.style.display="none"))})),s.appendChild(r),s.appendChild(o),c.appendChild(s),(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)||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",c.appendChild(e)}}));break;case n.FEEDBACKAPPANSWERTYPE.BOOLEAN:c=document.createElement("div"),u="magicfeedback-radio";const D=document.createElement("div");D.classList.add("magicfeedback-boolean-container"),D.style.display="flex",D.style.flexDirection="row",D.style.justifyContent="space-between",D.style.width="70%",D.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 a=document.createElement("input");a.id=`rating-${f}-${t}`,a.type="radio",a.name=f,a.value=v[t],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",(()=>{l&&l()})),i.appendChild(a),i.appendChild(n),D.appendChild(i)})),c.appendChild(D);break;case n.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:c=document.createElement("div"),u="magicfeedback-rating";const $=document.createElement("div");$.classList.add("magicfeedback-rating-container");const R=(null==b?void 0:b.max)?Number(null==b?void 0:b.max):5,F=(null==b?void 0:b.min)?Number(null==b?void 0:b.min):1,M=r(F,R,null==b?void 0:b.minPlaceholder,null==b?void 0:b.maxPlaceholder,null==b?void 0:b.extraOption);for(let pe=F;pe<=R;pe++){const me=document.createElement("div");me.classList.add("magicfeedback-rating-option");const he=document.createElement("label");he.htmlFor=`rating-${f}-${pe}`,he.classList.add("magicfeedback-rating-option-label-container");const fe=document.createElement("label");fe.htmlFor=`rating-${f}-${pe}`,fe.textContent=pe.toString();const ge=document.createElement("img");if(ge.alt=`face-${f}-${pe}`,ge.className=`rating-image${pe}`,0===F&&10===R)ge.src=`${d}/${pe}.svg`,ge.onerror=()=>ge.src=`${s}/${pe}.svg`;else if(1===F&&5===R)switch(pe){case 1:ge.src=`${d}/1.svg`,ge.onerror=()=>ge.src=`${s}/1.svg`;break;case 2:ge.src=`${d}/2.svg`,ge.onerror=()=>ge.src=`${s}/2.svg`;break;case 3:ge.src=`${d}/6.svg`,ge.onerror=()=>ge.src=`${s}/6.svg`;break;case 4:ge.src=`${d}/9.svg`,ge.onerror=()=>ge.src=`${s}/9.svg`;break;case 5:ge.src=`${d}/10.svg`,ge.onerror=()=>ge.src=`${s}/10.svg`}else{const Ee=Math.round(10/(R-F)*(pe-F));ge.src=`${d}/${Ee}.svg`,ge.onerror=()=>ge.src=`${s}/${Ee}.svg`}const ve=document.createElement("input");ve.id=`rating-${f}-${pe}`,ve.type="radio",ve.name=f,ve.value=pe.toString(),ve.classList.add(u),ve.classList.add("magicfeedback-input"),l&&ve.addEventListener("change",(()=>{l()})),he.appendChild(ve),he.appendChild(ge),he.appendChild(fe),me.appendChild(he),$.appendChild(me)}if((null==b?void 0:b.extraOption)&&(null==b?void 0:b.extraOptionText)){const be=document.createElement("div");be.classList.add("magicfeedback-rating-option");const ye=document.createElement("label");ye.htmlFor=`rating-${f}-extra`,ye.classList.add("magicfeedback-rating-option-label-container");const ke=document.createElement("label");ke.htmlFor=`rating-${f}-extra`,ke.textContent=null==b?void 0:b.extraOptionText;const Ce=document.createElement("img");Ce.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",Ce.alt=`face-${f}-extra`,Ce.className="magicfeedback-rating-image-extra";const Ae=document.createElement("input");Ae.id=`rating-${f}-extra`,Ae.type="radio",Ae.name=f,Ae.value="-",Ae.classList.add(u),Ae.classList.add("magicfeedback-input"),l&&Ae.addEventListener("change",(()=>{l()})),ye.appendChild(Ae),ye.appendChild(Ce),ye.appendChild(ke),be.appendChild(ye),$.appendChild(be)}c.appendChild(M),c.appendChild($);break;case n.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:c=document.createElement("div"),u="magicfeedback-rating-number";const _="ltr"===P?L:`${L}-reverse`,B=document.createElement("div");B.classList.add("magicfeedback-rating-number-container"),B.classList.add(`magicfeedback-rating-number-container-${P}`),B.classList.add(`magicfeedback-rating-number-container-${L}`),B.style.display="flex",B.style.flexDirection=_;const q=(null==b?void 0:b.max)?Number(null==b?void 0:b.max):10,U=(null==b?void 0:b.min)?Number(null==b?void 0:b.min):0,K=r(U,q,null==b?void 0:b.minPlaceholder,null==b?void 0:b.maxPlaceholder,null==b?void 0:b.extraOption,!0,P,L);for(let xe=U;xe<=q;xe++){const Te=document.createElement("div");Te.classList.add("magicfeedback-rating-number-option"),Te.classList.add(`magicfeedback-rating-number-option-${L}`);const Le=document.createElement("label");Le.htmlFor=`rating-${f}-${xe}`,Le.classList.add("magicfeedback-rating-number-option-label-container");let Pe=xe.toString();(k||"column"===L)&&xe===U&&(null==b?void 0:b.minPlaceholder)&&(Pe+=` = ${null==b?void 0:b.minPlaceholder}`),(k||"column"===L)&&xe===q&&(null==b?void 0:b.maxPlaceholder)&&(Pe+=` = ${null==b?void 0:b.maxPlaceholder}`);const we=document.createElement("label");we.htmlFor=`rating-${f}-${xe}`,we.textContent=Pe;const Se=document.createElement("input");Se.id=`rating-${f}-${xe}`,Se.type="radio",Se.name=f,Se.value=xe.toString(),Se.classList.add(u),Se.classList.add("magicfeedback-input"),l&&Se.addEventListener("change",(()=>{l()})),Le.appendChild(Se),Le.appendChild(we),Te.appendChild(Le),B.appendChild(Te)}if((null==b?void 0:b.extraOption)&&(null==b?void 0:b.extraOptionText)){const Oe=document.createElement("div");Oe.classList.add("magicfeedback-rating-number-option");const Ie=document.createElement("label");Ie.htmlFor=`rating-${f}-extra`,Ie.classList.add("magicfeedback-rating-number-option-label-container");const Ne=document.createElement("label");Ne.htmlFor=`rating-${f}-extra`,Ne.textContent=null==b?void 0:b.extraOptionText;const De=document.createElement("input");De.id=`rating-${f}-extra`,De.type="radio",De.name=f,De.value="-",De.classList.add(u),De.classList.add("magicfeedback-input"),l&&De.addEventListener("change",(()=>{l()})),Ie.appendChild(De),Ie.appendChild(Ne),Oe.appendChild(Ie),B.appendChild(Oe)}k||"column"===L||c.appendChild(K),c.appendChild(B);break;case n.FEEDBACKAPPANSWERTYPE.RATING_STAR:c=document.createElement("div"),u="magicfeedback-rating-star";const W=function(e,t,i,n=(()=>{})){const a="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 o=document.createElement("input");o.id=`rating-${e}-${t}`,o.type="radio",o.name=e,o.value=t.toString(),o.style.position="absolute",o.style.opacity="0",o.style.width="0",o.style.height="0",o.classList.add("magicfeedback-input"),o.addEventListener("change",(()=>{const e=s.querySelectorAll(".rating__star");for(let t=0;t<e.length;t++)t+1<=Number(o.value)?e[t].classList.contains(a)||e[t].classList.add(a):e[t].classList.contains(a)&&e[t].classList.remove(a);n&&n()})),i.appendChild(o);const r=document.createElement("label");r.htmlFor=`rating-${e}-${t}`,r.classList.add("rating__star"),r.textContent="★",r.style.fontSize="40px",r.style.color="#CCCCCC",r.style.cursor="pointer",i.appendChild(r),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);c.appendChild(W);break;case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:c=document.createElement("div"),u="magicfeedback-multiple-choice-image";const j=document.createElement("div");j.classList.add("magicfeedback-multiple-choice-image-container"),j.style.display="flex",j.style.flexDirection="row",j.style.flexWrap="wrap",j.style.justifyContent="center";const G=v.length;let Y=1,Q=1;if(window.innerWidth<600)Y=1,Q=G;else switch(G){case 1:case 2:case 3:Y=G,Q=1;break;case 4:case 5:case 6:Q=2,Y=Math.ceil(G/Q);break;case 7:case 8:case 9:Q=3,Y=Math.ceil(G/Q);break;default:Q=4,Y=Math.ceil(G/Q)}const H=void 0!==(null==b?void 0:b.addTitle)&&(null==b?void 0:b.addTitle),V=void 0!==(null==b?void 0:b.multiOption)&&(null==b?void 0:b.multiOption),z=void 0!==(null==b?void 0:b.extraOption)&&(null==b?void 0:b.extraOption);function J(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/Y}% - 10px)`,a.style.height=`calc( ${100/Q}% - 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=V?"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"),console.log("send",l),console.log("multiOptions",V),!V&&l&&r.addEventListener("change",(()=>{console.log("send"),l()}));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),H&&s.appendChild(o),a.appendChild(s),j.appendChild(a)}catch(e){console.error(e)}}T&&(v=v.sort((()=>Math.random()-.5))),v.forEach((e=>J(JSON.parse(e)))),z&&(null==b?void 0:b.extraOptionValue)&&(null==b?void 0:b.extraOptionValue.length)>0&&J(null==b?void 0:b.extraOptionValue[0]),c.appendChild(j);break;case n.FEEDBACKAPPANSWERTYPE.SELECT:c=document.createElement("select"),u="magicfeedback-select";const X=document.createElement("option");X.value="",X.text="slim"===t?o(m,i):E||"Select an option",X.disabled=!0,X.selected=!0,c.appendChild(X),v.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,c.appendChild(t)})),l&&c.addEventListener("change",(()=>{l()}));break;case n.FEEDBACKAPPANSWERTYPE.DATE:c=document.createElement("input"),c.type="date",c.required=g,c.placeholder=C||a.placeholder.date(i||"en"),u="magicfeedback-date";break;case n.FEEDBACKAPPANSWERTYPE.CONSENT:c=document.createElement("input"),u="magicfeedback-consent",c.type="checkbox",c.id=`magicfeedback-${p}`,c.name=f,c.value="true",c.required=g,c.classList.add("magicfeedback-consent"),c.classList.add("magicfeedback-input"),l&&c.addEventListener("change",(()=>{l()}));break;case n.FEEDBACKAPPANSWERTYPE.EMAIL:c=document.createElement("input"),c.type="email",c.required=g,c.placeholder=C||"you@example.com",u="magicfeedback-email";break;case n.FEEDBACKAPPANSWERTYPE.PASSWORD:c=document.createElement("input"),c.type="password",c.required=g,c.placeholder=C||a.placeholder.password(i||"en"),u="magicfeedback-password";break;case n.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:c=document.createElement("div"),u="magicfeedback-multi-question-matrix";const Z=document.createElement("div");Z.classList.add("magicfeedback-multi-question-matrix-container");let ee=(null==b?void 0:b.options)||[],te=[...v],ie=[];if(T&&(ee=null==ee?void 0:ee.sort((()=>Math.random()-.5)),te=[...te].sort((()=>Math.random()-.5))),(null==b?void 0:b.exclusiveAnswers)&&(ie=null==b?void 0:b.exclusiveAnswers,null==ie||ie.forEach((e=>{te.includes(e)||te.push(e)}))),window.innerWidth<600){const $e=document.createElement("div");$e.classList.add("magicfeedback-multi-question-matrix-list"),null==ee||ee.forEach((e=>{const t=document.createElement("div");t.classList.add("magicfeedback-multi-question-matrix-list-item"),t.style.display="flex",t.style.flexDirection="column",t.style.alignItems="flex-start",t.style.marginBottom="10px";const i=document.createElement("label");i.classList.add("magicfeedback-multi-question-matrix-label"),i.style.paddingBottom="10px",i.textContent=e,t.appendChild(i),te.forEach((i=>{const n=document.createElement("div");n.classList.add("magicfeedback-radio-container"),n.style.display="flex",n.style.alignItems="center",n.style.justifyContent="flex-start",n.style.width="99%",n.style.margin="5px auto";const a=document.createElement("label"),s=document.createElement("input");s.id=`${f}-${e}-${i}`,s.type="radio",s.name=`${f}-${e}`,s.value=i,s.classList.add("magicfeedback-input"),a.textContent=i,a.htmlFor=`${f}-${e}-${i}`,n.appendChild(s),n.appendChild(a),t.appendChild(n)})),$e.appendChild(t)})),Z.appendChild($e)}else{const Re=document.createElement("table");Re.classList.add("magicfeedback-multi-question-matrix-table");const Fe=document.createElement("thead");Fe.classList.add("magicfeedback-multi-question-matrix-header"),Fe.style.paddingBottom="15px";const Me=document.createElement("tr"),_e=document.createElement("th");Me.appendChild(_e),te.forEach((e=>{const t=document.createElement("th");t.textContent=e,Me.appendChild(t)})),Fe.appendChild(Me),Re.appendChild(Fe);const Be=document.createElement("tbody");null==ee||ee.forEach((e=>{const t=document.createElement("tr");t.classList.add("magicfeedback-multi-question-matrix-row-tr");const i=document.createElement("td");i.style.minWidth="200px";const n=document.createElement("label");n.classList.add("magicfeedback-multi-question-matrix-label"),n.style.paddingRight="20px",n.textContent=e,i.appendChild(n),t.appendChild(i),te.forEach((i=>{const n=document.createElement("td"),a=document.createElement("input");a.type="radio",a.name=`${f}-${e}`,a.value=i,a.id=`${f}-${e}-${i}`,a.classList.add("magicfeedback-input"),n.appendChild(a),t.appendChild(n)})),Be.appendChild(t)})),Re.appendChild(Be),Z.appendChild(Re)}c.appendChild(Z);break;case n.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:c=document.createElement("div"),u="magicfeedback-priority-list";const ne=document.createElement("div");ne.classList.add("magicfeedback-priority-list-container");const ae=document.createElement("ul");ae.classList.add("magicfeedback-priority-list-list"),T&&(v=v.sort((()=>Math.random()-.5))),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,d,l;const c=i.previousElementSibling;if(c){const u=Number(null===(t=n.value)||void 0===t?void 0:t.split(".")[0])-1;n.value=`${u}. ${e}`,a.textContent=`${u}. ${e}`,o.style.visibility=1===u?"hidden":"visible",r.style.visibility=u===v.length?"hidden":"visible";const p=c.querySelector(".magicfeedback-input-magicfeedback-priority-list"),m=c.querySelector(".magicfeedback-priority-list-item-label"),h=c.querySelector(".magicfeedback-priority-list-arrow-up"),f=c.querySelector(".magicfeedback-priority-list-arrow-down");if(p&&m&&h&&f){const e=Number(null===(s=p.value)||void 0===s?void 0:s.split(".")[0])+1;p.value=`${e}.${null===(d=m.textContent)||void 0===d?void 0:d.split(".")[1]}`,m.textContent=`${e}.${null===(l=m.textContent)||void 0===l?void 0:l.split(".")[1]}`,h.style.visibility=1===e?"hidden":"visible",f.style.visibility=e===v.length?"hidden":"visible"}ae.insertBefore(i,c)}})),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,d;const l=i.nextElementSibling;if(l){const c=Number(null===(t=n.value)||void 0===t?void 0:t.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 u=l.querySelector(".magicfeedback-input-magicfeedback-priority-list"),p=l.querySelector(".magicfeedback-priority-list-item-label"),m=l.querySelector(".magicfeedback-priority-list-arrow-up"),h=l.querySelector(".magicfeedback-priority-list-arrow-down");if(u&&p&&m&&h){const e=Number(u.value.split(".")[0])-1;u.value=`${e}.${null===(s=p.textContent)||void 0===s?void 0:s.split(".")[1]}`,p.textContent=`${e}.${null===(d=p.textContent)||void 0===d?void 0:d.split(".")[1]}`,m.style.visibility=1===e?"hidden":"visible",h.style.visibility=e===v.length?"hidden":"visible"}ae.insertBefore(l,i)}})),s.appendChild(r),i.appendChild(s),ae.appendChild(i)})),ne.appendChild(ae),c.appendChild(ne);break;case n.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:c=document.createElement("div"),u="magicfeedback-point-system";const se=document.createElement("div");se.classList.add("magicfeedback-point-system-container");const oe=document.createElement("ul");oe.classList.add("magicfeedback-point-system-list"),oe.style.padding="0";const re=100,de=re/v.length,le=document.createElement("div");le.classList.add("magicfeedback-error"),le.textContent=a.placeholder.pointsystemerror(i||"en"),le.style.color="#C70039",le.style.fontSize="14px",le.style.textAlign="right",le.style.width="100%",le.style.display="none";const ce=document.createElement("div");ce.classList.add("magicfeedback-point-system-total"),ce.textContent="0 / 100 %",ce.style.textAlign="right",ce.style.fontSize="15px",ce.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=`${e}`,s.type="number",s.min="0",s.max=`${re}`,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=oe.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>re&&(s.value=`${de}%`,t-=Number(s.value));const i=document.getElementById("magicfeedback-submit");i&&(t<100?(ce.style.color="orange",i.setAttribute("disabled","true")):(le.style.display="none",ce.style.color="green",i.removeAttribute("disabled"))),ce.textContent=`${t} / 100 %`})),s.addEventListener("focus",(()=>{const e=document.getElementById("magicfeedback-submit");e&&(e.setAttribute("disabled","true"),e.addEventListener("pointerover",(()=>{const e=oe.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t<100&&(le.style.display="block")})))})),a.appendChild(s),a.appendChild(o),i.appendChild(a),oe.appendChild(i)})),se.appendChild(oe),se.appendChild(ce),se.appendChild(le),c.appendChild(se);break;case n.FEEDBACKAPPANSWERTYPE.INFO_PAGE:c=document.createElement("div"),u="magicfeedback-info-page";const ue=document.createElement("div");ue.classList.add("magicfeedback-info-message"),ue.innerHTML=C,c.appendChild(ue);break;case n.FEEDBACKAPPANSWERTYPE.UPLOAD_IMAGE:c=document.createElement("input"),c.type="file",c.accept="image/*",c.required=g,c.multiple=(null==b?void 0:b.multiple)||!1,c.maxLength=(null==b?void 0:b.maxFiles)||1,u="magicfeedback-upload-image";break;case n.FEEDBACKAPPANSWERTYPE.UPLOAD_FILE:c=document.createElement("input"),c.type="file",c.required=g,c.multiple=(null==b?void 0:b.multiple)||!1,c.maxLength=(null==b?void 0:b.maxFiles)||1,u="magicfeedback-upload-file";break;default:return y}c.id=`magicfeedback-${p}`,c.setAttribute("name",f),c.classList.add(u),(void 0!==E||null!==A)&&(c.value=A||E),["RADIO","MULTIPLECHOICE"].includes(h)||(c.classList.add("magicfeedback-input"),c.required=g);const S=document.createElement("label");S.setAttribute("for",`magicfeedback-${p}`),S.textContent=o(m,i),S.classList.add("magicfeedback-label");const O=document.createElement("label");if(O.textContent=o(null==b?void 0:b.subtitle,i),O.classList.add("magicfeedback-sublabel"),["CONSENT"].includes(h))y.classList.add("magicfeedback-consent-container"),y.appendChild(c),y.appendChild(S),y.appendChild(O);else{if("slim"!==t&&([n.FEEDBACKAPPANSWERTYPE.INFO_PAGE].includes(h)||(y.appendChild(S),y.appendChild(O)),void 0!==(null==b?void 0:b.general)&&""!==(null==b?void 0:b.general))){const qe=document.createElement("img");qe.src=null==b?void 0:b.general,qe.classList.add("magicfeedback-image"),qe.style.maxWidth="auto",qe.style.height="400px",qe.style.margin="10px 0",y.appendChild(qe)}if("LONGTEXT"===h&&x>0){const Ue=document.createElement("div");if(Ue.classList.add("magicfeedback-counter"),Ue.textContent=`${c.value.length}/${x}`,Ue.style.textAlign="right",Ue.style.fontSize="15px",Ue.style.marginTop="5px",c.addEventListener("input",(()=>{Ue.textContent=`${c.value.length}/${x}`})),y.appendChild(c),y.appendChild(Ue),(null==b?void 0:b.extraOption)&&(null==b?void 0:b.extraOptionText)){const Ke=document.createElement("div");Ke.classList.add("magicfeedback-skip-container"),Ke.classList.add("magicfeedback-checkbox-container"),Ke.style.display="flex",Ke.style.justifyContent="flex-start";const We=document.createElement("input");We.classList.add("magicfeedback-skip"),We.type="checkbox",We.id=`skip-${f}`,We.name=f,We.value="-",We.style.cursor="pointer";const je=document.createElement("label");je.htmlFor=`skip-${f}`,je.textContent=null==b?void 0:b.extraOptionText,je.style.fontSize="15px",je.style.cursor="pointer",je.style.margin="0 5px",We.addEventListener("click",(()=>{c.value="-",l&&l()})),Ke.appendChild(We),Ke.appendChild(je),y.appendChild(Ke)}}else y.appendChild(c)}return y}(h,i,d,`${s}${p?`/${m}`:""}`,1===t.length?c:void 0);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,"x-magicfeedback-parameters":window.location.search||""};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});return yield n.json()}catch(e){a.err(e)}}))},t.getSessionForm=function(e,t,i){return n(this,void 0,void 0,(function*(){try{const i=yield(0,s.default)(e+r.endpoints.sdk.session(t),{method:"GET",headers:d});return yield i.json()}catch(e){i.err(e)}}))},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.4.9","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.deepdots.com/"},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,l){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"),c={integration:i,publicKey:a,privateKey:l,completed:o,id:d,feedback:s};try{const e=yield(0,r.sendFeedback)(n,c,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(244),s=i(5),o=i(341),r=i(183),d=i(24),l=i(804),c=i(116),u=i(314),p=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.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.history=new u.History,this.graph=new d.PageGraph([]),this.progress=0,this.total=0,this.completed=!1,this.timeToCompleted=0}generate(e,t){var i,a,s,r,d,l,c;return n(this,void 0,void 0,(function*(){try{this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e;let n=this.formData;if(void 0!==this.formData&&this.formData||(n=""!==this.publicKey?yield(0,o.getForm)(this.url,this.appId,this.publicKey,this.log):yield(0,o.getSessionForm)(this.url,this.appId,this.log)),void 0===n||!n)throw new Error(`No data for app ${this.appId}`);if(null===(i=n.error)||void 0===i?void 0:i.message)throw new Error(n.error.message);if(n.questions=(null===(a=n.questions)||void 0===a?void 0:a.filter((e=>"ACTIVE"===e.status)))||[],n.pages=(null===(s=n.pages)||void 0===s?void 0:s.filter((e=>"ACTIVE"===e.status)))||[],null===(r=n.pages)||void 0===r||r.forEach((e=>{var t;return e.integrationQuestions=null===(t=e.integrationQuestions)||void 0===t?void 0:t.filter((e=>"ACTIVE"===e.status))})),this.formData=n,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===(d=this.formData.pages)||void 0===d?void 0:d.length)||this.formatPages(),null===(l=this.formData.questions)||void 0===l||l.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===(c=this.formData.style)||void 0===c?void 0:c.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 l.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 l.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(console.log("Generating form for appId:",this.appId),!this.formData||!this.formData.pages||0===this.formData.pages.length)throw new Error("No form data");this.graph=new d.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,s.addEventListener("submit",(e=>e.preventDefault()));const o=document.createElement("div");o.classList.add("magicfeedback-questions"),o.id="magicfeedback-questions-"+this.appId;const l=this.graph.getFirstPage();if(!l)throw new Error("No page found");if(this.total=this.graph.findMaxDepth(),l.elements=(0,r.renderQuestions)(l.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=l.elements)||void 0===i||i.forEach((e=>o.appendChild(e))),s.appendChild(o),this.history.enqueue(l),n.appendChild(s),this.progress=this.total-this.graph.findMaxDepth(l),this.formOptionsConfig.addButton){const e=(0,r.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.timeToCompleted=(new Date).getTime()/1e3,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,r.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");for(const e of a.questions.filter((e=>e.require))){const t=e.assets,i=this.feedback.answers.filter((t=>t.key.includes(e.ref)&&!t.key.includes("extra-option")));if(0===i.length||i.find((e=>0===e.value.length)))throw this.log.err(`The question ${e.ref} is required`),new Error("No response");if(null==t?void 0:t.minOptions){let n=[];if((null==t?void 0:t.exclusiveAnswers)&&(n=null==t?void 0:t.exclusiveAnswers),(null==t?void 0:t.extraOption)&&n.push(null==t?void 0:t.extraOptionText),!i[0].value.find((e=>n.includes(e)))&&i[0].value.length<(null==t?void 0:t.minOptions))throw this.log.err(`The question ${e.ref} requires at least ${null==t?void 0:t.minOptions} options`),new Error("No response")}}const s=yield this.pushAnswers(!1);if(!s)throw new Error("No response");this.id=s,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=[]);const t=this.history.back();if(!t)throw new Error("No page found");const i=[];let n=!1;e.querySelectorAll(".magicfeedback-input").forEach((e=>{const s=t.questions.find((t=>{var i;return null===(i=e.name)||void 0===i?void 0:i.includes(t.ref)})),r=e.type,d=e.classList[0],l={key:e.name,value:[]},c="magicfeedback-consent"===d?e.checked.toString():e.value;if(l.key&&""!==l.key){switch(null==s?void 0:s.type){case a.FEEDBACKAPPANSWERTYPE.EMAIL:case a.FEEDBACKAPPANSWERTYPE.TEXT:case a.FEEDBACKAPPANSWERTYPE.LONGTEXT:case a.FEEDBACKAPPANSWERTYPE.NUMBER:case a.FEEDBACKAPPANSWERTYPE.DATE:case a.FEEDBACKAPPANSWERTYPE.CONTACT:if(""!==c){if("email"===r){if(!(0,o.validateEmail)(c)){this.log.err("Invalid email"),n=!0;break}this.feedback.profile.push({key:"email",value:[c]})}l.value.push(c)}break;case a.FEEDBACKAPPANSWERTYPE.CONSENT:l.value.push(String(e.checked));break;case a.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:const t=e.id;l.value.push(`${t}:${c}%`);break;case a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:case a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:case a.FEEDBACKAPPANSWERTYPE.RATING_STAR:case a.FEEDBACKAPPANSWERTYPE.RADIO:case a.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:case a.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:(e.checked||e.id.includes("extra-option-"))&&l.value.push(c);break;case a.FEEDBACKAPPANSWERTYPE.SELECT:l.value.push(c);break;case a.FEEDBACKAPPANSWERTYPE.BOOLEAN:case a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:e.checked&&l.value.push(c);break;case a.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:l.value.push(c)}if((null==i?void 0:i.length)>0&&(null==i?void 0:i.find((e=>e.key===l.key)))){const e=i.findIndex((e=>e.key===l.key));i[e].value=[...i[e].value,...l.value]}else i.push(l)}})),this.feedback.answers=n?[]:i}finish(){return n(this,void 0,void 0,(function*(){if(this.completed=!0,this.timeToCompleted=(new Date).getTime()-this.timeToCompleted,this.feedback.metadata.push({key:"time-to-complete",value:[this.timeToCompleted.toString()]}),this.formOptionsConfig.addSuccessScreen){const e=document.getElementById("magicfeedback-container-"+this.appId);e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,r.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}this.answer();try{const e=yield this.pushAnswers(!0);if(!e)throw this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({loading:!1,progress:this.progress,total:this.total,completed:this.completed,error:`An error occurred while submitting the form ${this.appId}:`})),new Error("An error occurred while submitting the form ${this.appId}:");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}))}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,completed:this.completed,error:e}))}}))}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,o.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=Object.assign(Object.assign(Object.assign({answer:null===(t=this.feedback.answers.find((t=>t.key===e.ref)))||void 0===t?void 0:t.value[0]},""!==this.publicKey&&{publicKey:this.publicKey}),""===this.publicKey&&{campaignSessionId:this.appId}),{sessionId:this.id,question:e});return yield(0,o.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 o=[];for(const e of s){const t=n.questions.find((t=>t.ref===e));if(t){const e=yield this.callFollowUpQuestion(t);e&&o.push(e)}}if(0===o.length)return void(yield this.renderNextQuestion(e,n));const d=new l.Page(n.id,n.position,this.appId,o,n.edges),c=new p.PageNode(n.id,n.position,n.edges,d,o,!0);c.elements=(0,r.renderQuestions)(o,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(c),this.progress++,e.innerHTML="",null===(a=c.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:c.isFollowup,completed:this.completed,error:null}))}))}renderNextQuestion(e,t){var i,a,s;return n(this,void 0,void 0,(function*(){const n=this.graph.getNextPage(t,this.feedback.answers);n?(n.elements=(0,r.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.innerHTML="",null===(s=n.elements)||void 0===s||s.forEach((t=>e.appendChild(t))),this.history.enqueue(n),this.progress=this.total-this.graph.findMaxDepth(n),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.innerHTML=""),this.history.rollback();const i=this.history.back();i?(null===(e=i.elements)||void 0===e||e.forEach((e=>t.appendChild(e))),this.progress=this.total-this.graph.findMaxDepth(i)):this.progress=this.history.size(),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,r;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]}t.integrationPageRoutes&&(t.integrationPageRoutes=(null===(r=t.integrationPageRoutes)||void 0===r?void 0:r.sort(((e,t)=>new Date((null==e?void 0:e.generatedAt)||"").getTime()-new Date((null==t?void 0:t.generatedAt)||"").getTime()?"DIRECT"===e.typeCondition?1:-1:0)))||[]);const d=new n.PageNode(t.id,t.position,t.integrationPageRoutes||[],t,t.integrationQuestions);this.nodes.set(d.id,d)}))}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){var i;if(!e)return;e.edges.sort(((e,t)=>"DIRECT"===e.typeCondition?1:"DIRECT"===t.typeCondition?-1:0));const n=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(!n){const t=this.getNextEdgeByDefault(e);if(!t)return;return this.getNodeById(t)}switch(n.transition){case a.TransitionType.PAGE:if(!n.transitionDestiny)return;return this.getNodeById(n.transitionDestiny);case a.TransitionType.FINISH:return;case a.TransitionType.REDIRECT:return void(window.location.href=(null===(i=n.transitionDestiny)||void 0===i?void 0:i.includes("?"))?`${n.transitionDestiny}&${window.location.search.slice(1)}`:`${n.transitionDestiny}${window.location.search}`);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||[]],o=this.getNextEdgeByDefault(e);if(o){const i=this.getNodeById(o);i&&!t.has(i)&&s.push(new a.PageRoute(i.id,"",a.OperatorType.DEFAULT,"",a.TransitionType.PAGE,i.id,e.id))}for(const e of s){if(!e.transitionDestiny)continue;const a=this.getNodeById(e.transitionDestiny);if(a&&!t.has(a)){const e=a.questions.find((e=>e.followup))?i+2:i+1,s=new Set(t),o=this.DFSUtil(a,s,e);n=Math.max(n,o)}}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,l){this.id=e,this.questionRef=t,this.typeCondition=l||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",n.UPLOAD_FILE="UPLOAD_FILE",n.UPLOAD_IMAGE="UPLOAD_IMAGE",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,o="ltr",r="row"){const d=document.createElement("div");d.classList.add("magicfeedback-rating-placeholder"),d.style.display="flex",d.style.flexDirection=r,d.style.alignItems="center",d.style.justifyContent="space-between",d.style.width=a?`calc(100% - (100% / ${t+1}))`:"100%",d.style.marginRight="auto",s&&window.innerWidth<600&&(d.style.flexDirection="column");const l=document.createElement("span");l.textContent=i,l.classList.add("magicfeedback-rating-placeholder-value"),l.style.fontSize="15px",l.style.textAlign="ltr"===o?"left":"right",l.style.width="50%",(s&&window.innerWidth<600||"column"===r)&&(l.textContent=`${e} = ${i}`,l.style.width="100%",l.style.textAlign="left",l.style.marginBottom="5px");const c=document.createElement("span");return c.textContent=n,c.classList.add("magicfeedback-rating-placeholder-value"),c.style.fontSize="15px",c.style.textAlign="ltr"===o?"right":"left",c.style.width="50%",(s&&window.innerWidth<600||"column"===r)&&(c.textContent=`${t} = ${n}`,c.style.width="100%",c.style.textAlign="left",c.style.marginBottom="5px"),"ltr"===o?(i&&d.appendChild(l),n&&d.appendChild(c)):(n&&d.appendChild(c),i&&d.appendChild(l)),d}t.renderQuestions=function e(t,i="standard",d="en",l={customIcons:!1},c){if(!t)throw new Error("[MagicFeedback] No questions provided");const u=[],{customIcons:p,id:m}=l;return t.forEach((h=>{var f,g;if((null===(g=null===(f=null==h?void 0:h.questionType)||void 0===f?void 0:f.conf)||void 0===g?void 0:g.length)>0){let t=document.createElement("div");t.classList.add("magicfeedback-div");const n=document.createElement("label");n.setAttribute("for",`magicfeedback-${h.id}`),n.textContent=o(h.title,d),n.classList.add("magicfeedback-label"),t.appendChild(n),h.questionType.conf.forEach((e=>{e.ref=h.ref,h.assets[e.id]&&(e.assets={placeholder:h.assets[e.id]})})),e(h.questionType.conf,i,d,l,c).forEach((e=>{t.appendChild(e)})),u.push(t)}else{const e=function(e,t,i,d,l){let c,u,{id:p,title:m,type:h,ref:f,require:g,value:v,defaultValue:E,assets:b}=e,y=document.createElement("div");y.classList.add("magicfeedback-div");const k=window.innerWidth<600,C="slim"===t?o(m,i):null==b?void 0:b.placeholder,A=(w=p,new URLSearchParams(window.location.search).get(w)),x=(null==b?void 0:b.maxCharacters)||0,T=void 0!==(null==b?void 0:b.randomPosition)&&(null==b?void 0:b.randomPosition),L=(null==b?void 0:b.direction)||"row",P=(null==b?void 0:b.order)||"ltr";var w;switch(h){case n.FEEDBACKAPPANSWERTYPE.TEXT:c=document.createElement("input"),c.type="text",c.placeholder=C||a.placeholder.answer(i||"en"),c.addEventListener("keyup",(e=>{e.preventDefault(),console.log(e.key,e),"Enter"===e.key&&l&&l()})),u="magicfeedback-text";break;case n.FEEDBACKAPPANSWERTYPE.LONGTEXT:c=document.createElement("textarea"),c.rows=3,x>0&&(c.maxLength=x),c.placeholder=C||a.placeholder.answer(i||"en"),u="magicfeedback-longtext";break;case n.FEEDBACKAPPANSWERTYPE.NUMBER:c=document.createElement("input"),c.type="number",c.placeholder="slim"===t?o(m,i):a.placeholder.number(i||"en"),u="magicfeedback-number",v.length&&(v.sort(((e,t)=>Number(e)-Number(t))),c.max=v[v.length-1],c.min=v[0],c.value=v[0]);break;case n.FEEDBACKAPPANSWERTYPE.RADIO:case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:c=document.createElement("div"),u="magicfeedback-"+("MULTIPLECHOICE"===h?"checkbox":"radio");let I=v||[];T&&(I=I.sort((()=>Math.random()-.5)));let N=[];(null==b?void 0:b.exclusiveAnswers)&&(N=null==b?void 0:b.exclusiveAnswers,null==N||N.forEach((e=>{I.includes(e)||I.push(e)}))),(null==b?void 0:b.extraOption)&&(N.push(null==b?void 0:b.extraOptionText),I.includes(null==b?void 0:b.extraOptionText)||I.push(null==b?void 0:b.extraOptionText)),I.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==b?void 0:b.maxOptions)&&(null==b?void 0:b.maxOptions)>0&&r.addEventListener("change",(()=>{const e=document.querySelectorAll(`input[name="${f}"]:checked`);e.length>(null==b?void 0:b.maxOptions)&&(r.checked=!1),l&&e.length===(null==b?void 0:b.maxOptions)&&l()})),h===n.FEEDBACKAPPANSWERTYPE.RADIO&&l&&r.addEventListener("change",(()=>{l()})),e!==E&&e!==A||(r.checked=!0),o.textContent=e,o.htmlFor=`rating-${f}-${t}`,r.addEventListener("change",(t=>{const i=document.getElementById(`extra-option-${f}`);t.target.checked&&N.includes(e)?(I.forEach((t=>{t!==e&&(document.querySelector(`input[value="${t}"]`).checked=!1)})),i&&(i.style.display=(null==b?void 0:b.extraOption)&&e===(null==b?void 0:b.extraOptionText)?"block":"none")):(N.forEach((t=>{t!==e&&(document.querySelector(`input[value="${t}"]`).checked=!1)})),i&&(i.style.display="none"))})),s.appendChild(r),s.appendChild(o),c.appendChild(s),(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)||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",c.appendChild(e)}}));break;case n.FEEDBACKAPPANSWERTYPE.BOOLEAN:c=document.createElement("div"),u="magicfeedback-radio";const D=document.createElement("div");D.classList.add("magicfeedback-boolean-container"),D.style.display="flex",D.style.flexDirection="row",D.style.justifyContent="space-between",D.style.width="70%",D.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 a=document.createElement("input");a.id=`rating-${f}-${t}`,a.type="radio",a.name=f,a.value=v[t],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",(()=>{l&&l()})),i.appendChild(a),i.appendChild(n),D.appendChild(i)})),c.appendChild(D);break;case n.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:c=document.createElement("div"),u="magicfeedback-rating";const $=document.createElement("div");$.classList.add("magicfeedback-rating-container");const R=(null==b?void 0:b.max)?Number(null==b?void 0:b.max):5,F=(null==b?void 0:b.min)?Number(null==b?void 0:b.min):1,M=r(F,R,null==b?void 0:b.minPlaceholder,null==b?void 0:b.maxPlaceholder,null==b?void 0:b.extraOption);for(let pe=F;pe<=R;pe++){const me=document.createElement("div");me.classList.add("magicfeedback-rating-option");const he=document.createElement("label");he.htmlFor=`rating-${f}-${pe}`,he.classList.add("magicfeedback-rating-option-label-container");const fe=document.createElement("label");fe.htmlFor=`rating-${f}-${pe}`,fe.textContent=pe.toString();const ge=document.createElement("img");if(ge.alt=`face-${f}-${pe}`,ge.className=`rating-image${pe}`,0===F&&10===R)ge.src=`${d}/${pe}.svg`,ge.onerror=()=>ge.src=`${s}/${pe}.svg`;else if(1===F&&5===R)switch(pe){case 1:ge.src=`${d}/1.svg`,ge.onerror=()=>ge.src=`${s}/1.svg`;break;case 2:ge.src=`${d}/2.svg`,ge.onerror=()=>ge.src=`${s}/2.svg`;break;case 3:ge.src=`${d}/6.svg`,ge.onerror=()=>ge.src=`${s}/6.svg`;break;case 4:ge.src=`${d}/9.svg`,ge.onerror=()=>ge.src=`${s}/9.svg`;break;case 5:ge.src=`${d}/10.svg`,ge.onerror=()=>ge.src=`${s}/10.svg`}else{const Ee=Math.round(10/(R-F)*(pe-F));ge.src=`${d}/${Ee}.svg`,ge.onerror=()=>ge.src=`${s}/${Ee}.svg`}const ve=document.createElement("input");ve.id=`rating-${f}-${pe}`,ve.type="radio",ve.name=f,ve.value=pe.toString(),ve.classList.add(u),ve.classList.add("magicfeedback-input"),l&&ve.addEventListener("change",(()=>{l()})),he.appendChild(ve),he.appendChild(ge),he.appendChild(fe),me.appendChild(he),$.appendChild(me)}if((null==b?void 0:b.extraOption)&&(null==b?void 0:b.extraOptionText)){const be=document.createElement("div");be.classList.add("magicfeedback-rating-option");const ye=document.createElement("label");ye.htmlFor=`rating-${f}-extra`,ye.classList.add("magicfeedback-rating-option-label-container");const ke=document.createElement("label");ke.htmlFor=`rating-${f}-extra`,ke.textContent=null==b?void 0:b.extraOptionText;const Ce=document.createElement("img");Ce.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",Ce.alt=`face-${f}-extra`,Ce.className="magicfeedback-rating-image-extra";const Ae=document.createElement("input");Ae.id=`rating-${f}-extra`,Ae.type="radio",Ae.name=f,Ae.value="-",Ae.classList.add(u),Ae.classList.add("magicfeedback-input"),l&&Ae.addEventListener("change",(()=>{l()})),ye.appendChild(Ae),ye.appendChild(Ce),ye.appendChild(ke),be.appendChild(ye),$.appendChild(be)}c.appendChild(M),c.appendChild($);break;case n.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:c=document.createElement("div"),u="magicfeedback-rating-number";const _="ltr"===P?L:`${L}-reverse`,B=document.createElement("div");B.classList.add("magicfeedback-rating-number-container"),B.classList.add(`magicfeedback-rating-number-container-${P}`),B.classList.add(`magicfeedback-rating-number-container-${L}`),B.style.display="flex",B.style.flexDirection=_;const q=(null==b?void 0:b.max)?Number(null==b?void 0:b.max):10,U=(null==b?void 0:b.min)?Number(null==b?void 0:b.min):0,K=r(U,q,null==b?void 0:b.minPlaceholder,null==b?void 0:b.maxPlaceholder,null==b?void 0:b.extraOption,!0,P,L);for(let xe=U;xe<=q;xe++){const Te=document.createElement("div");Te.classList.add("magicfeedback-rating-number-option"),Te.classList.add(`magicfeedback-rating-number-option-${L}`);const Le=document.createElement("label");Le.htmlFor=`rating-${f}-${xe}`,Le.classList.add("magicfeedback-rating-number-option-label-container");let Pe=xe.toString();(k||"column"===L)&&xe===U&&(null==b?void 0:b.minPlaceholder)&&(Pe+=` = ${null==b?void 0:b.minPlaceholder}`),(k||"column"===L)&&xe===q&&(null==b?void 0:b.maxPlaceholder)&&(Pe+=` = ${null==b?void 0:b.maxPlaceholder}`);const we=document.createElement("label");we.htmlFor=`rating-${f}-${xe}`,we.textContent=Pe;const Se=document.createElement("input");Se.id=`rating-${f}-${xe}`,Se.type="radio",Se.name=f,Se.value=xe.toString(),Se.classList.add(u),Se.classList.add("magicfeedback-input"),l&&Se.addEventListener("change",(()=>{l()})),Le.appendChild(Se),Le.appendChild(we),Te.appendChild(Le),B.appendChild(Te)}if((null==b?void 0:b.extraOption)&&(null==b?void 0:b.extraOptionText)){const Oe=document.createElement("div");Oe.classList.add("magicfeedback-rating-number-option");const Ie=document.createElement("label");Ie.htmlFor=`rating-${f}-extra`,Ie.classList.add("magicfeedback-rating-number-option-label-container");const Ne=document.createElement("label");Ne.htmlFor=`rating-${f}-extra`,Ne.textContent=null==b?void 0:b.extraOptionText;const De=document.createElement("input");De.id=`rating-${f}-extra`,De.type="radio",De.name=f,De.value="-",De.classList.add(u),De.classList.add("magicfeedback-input"),l&&De.addEventListener("change",(()=>{l()})),Ie.appendChild(De),Ie.appendChild(Ne),Oe.appendChild(Ie),B.appendChild(Oe)}k||"column"===L||c.appendChild(K),c.appendChild(B);break;case n.FEEDBACKAPPANSWERTYPE.RATING_STAR:c=document.createElement("div"),u="magicfeedback-rating-star";const W=function(e,t,i,n=(()=>{})){const a="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 o=document.createElement("input");o.id=`rating-${e}-${t}`,o.type="radio",o.name=e,o.value=t.toString(),o.style.position="absolute",o.style.opacity="0",o.style.width="0",o.style.height="0",o.classList.add("magicfeedback-input"),o.addEventListener("change",(()=>{const e=s.querySelectorAll(".rating__star");for(let t=0;t<e.length;t++)t+1<=Number(o.value)?e[t].classList.contains(a)||e[t].classList.add(a):e[t].classList.contains(a)&&e[t].classList.remove(a);n&&n()})),i.appendChild(o);const r=document.createElement("label");r.htmlFor=`rating-${e}-${t}`,r.classList.add("rating__star"),r.textContent="★",r.style.fontSize="40px",r.style.color="#CCCCCC",r.style.cursor="pointer",i.appendChild(r),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);c.appendChild(W);break;case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:c=document.createElement("div"),u="magicfeedback-multiple-choice-image";const j=document.createElement("div");j.classList.add("magicfeedback-multiple-choice-image-container"),j.style.display="flex",j.style.flexDirection="row",j.style.flexWrap="wrap",j.style.justifyContent="center";const G=v.length;let Y=1,Q=1;if(window.innerWidth<600)Y=1,Q=G;else switch(G){case 1:case 2:case 3:Y=G,Q=1;break;case 4:case 5:case 6:Q=2,Y=Math.ceil(G/Q);break;case 7:case 8:case 9:Q=3,Y=Math.ceil(G/Q);break;default:Q=4,Y=Math.ceil(G/Q)}const H=void 0!==(null==b?void 0:b.addTitle)&&(null==b?void 0:b.addTitle),V=void 0!==(null==b?void 0:b.multiOption)&&(null==b?void 0:b.multiOption),z=void 0!==(null==b?void 0:b.extraOption)&&(null==b?void 0:b.extraOption);function J(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/Y}% - 10px)`,a.style.height=`calc( ${100/Q}% - 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=V?"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"),console.log("send",l),console.log("multiOptions",V),!V&&l&&r.addEventListener("change",(()=>{console.log("send"),l()}));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),H&&s.appendChild(o),a.appendChild(s),j.appendChild(a)}catch(e){console.error(e)}}T&&(v=v.sort((()=>Math.random()-.5))),v.forEach((e=>J(JSON.parse(e)))),z&&(null==b?void 0:b.extraOptionValue)&&(null==b?void 0:b.extraOptionValue.length)>0&&J(null==b?void 0:b.extraOptionValue[0]),c.appendChild(j);break;case n.FEEDBACKAPPANSWERTYPE.SELECT:c=document.createElement("select"),u="magicfeedback-select";const X=document.createElement("option");X.value="",X.text="slim"===t?o(m,i):E||"Select an option",X.disabled=!0,X.selected=!0,c.appendChild(X),v.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,c.appendChild(t)})),l&&c.addEventListener("change",(()=>{l()}));break;case n.FEEDBACKAPPANSWERTYPE.DATE:c=document.createElement("input"),c.type="date",c.required=g,c.placeholder=C||a.placeholder.date(i||"en"),u="magicfeedback-date";break;case n.FEEDBACKAPPANSWERTYPE.CONSENT:c=document.createElement("input"),u="magicfeedback-consent",c.type="checkbox",c.id=`magicfeedback-${p}`,c.name=f,c.value="true",c.required=g,c.classList.add("magicfeedback-consent"),c.classList.add("magicfeedback-input"),l&&c.addEventListener("change",(()=>{l()}));break;case n.FEEDBACKAPPANSWERTYPE.EMAIL:c=document.createElement("input"),c.type="email",c.required=g,c.placeholder=C||"you@example.com",u="magicfeedback-email";break;case n.FEEDBACKAPPANSWERTYPE.PASSWORD:c=document.createElement("input"),c.type="password",c.required=g,c.placeholder=C||a.placeholder.password(i||"en"),u="magicfeedback-password";break;case n.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:c=document.createElement("div"),u="magicfeedback-multi-question-matrix";const Z=document.createElement("div");Z.classList.add("magicfeedback-multi-question-matrix-container");let ee=(null==b?void 0:b.options)||[],te=[...v],ie=[];if(T&&(ee=null==ee?void 0:ee.sort((()=>Math.random()-.5)),te=[...te].sort((()=>Math.random()-.5))),(null==b?void 0:b.exclusiveAnswers)&&(ie=null==b?void 0:b.exclusiveAnswers,null==ie||ie.forEach((e=>{te.includes(e)||te.push(e)}))),window.innerWidth<600){const $e=document.createElement("div");$e.classList.add("magicfeedback-multi-question-matrix-list"),null==ee||ee.forEach((e=>{const t=document.createElement("div");t.classList.add("magicfeedback-multi-question-matrix-list-item"),t.style.display="flex",t.style.flexDirection="column",t.style.alignItems="flex-start",t.style.marginBottom="10px";const i=document.createElement("label");i.classList.add("magicfeedback-multi-question-matrix-label"),i.style.paddingBottom="10px",i.textContent=e,t.appendChild(i),te.forEach((i=>{const n=document.createElement("div");n.classList.add("magicfeedback-radio-container"),n.style.display="flex",n.style.alignItems="center",n.style.justifyContent="flex-start",n.style.width="99%",n.style.margin="5px auto";const a=document.createElement("label"),s=document.createElement("input");s.id=`${f}-${e}-${i}`,s.type="radio",s.name=`${f}-${e}`,s.value=i,s.classList.add("magicfeedback-input"),a.textContent=i,a.htmlFor=`${f}-${e}-${i}`,n.appendChild(s),n.appendChild(a),t.appendChild(n)})),$e.appendChild(t)})),Z.appendChild($e)}else{const Re=document.createElement("table");Re.classList.add("magicfeedback-multi-question-matrix-table");const Fe=document.createElement("thead");Fe.classList.add("magicfeedback-multi-question-matrix-header"),Fe.style.paddingBottom="15px";const Me=document.createElement("tr"),_e=document.createElement("th");Me.appendChild(_e),te.forEach((e=>{const t=document.createElement("th");t.textContent=e,Me.appendChild(t)})),Fe.appendChild(Me),Re.appendChild(Fe);const Be=document.createElement("tbody");null==ee||ee.forEach((e=>{const t=document.createElement("tr");t.classList.add("magicfeedback-multi-question-matrix-row-tr");const i=document.createElement("td");i.style.minWidth="200px";const n=document.createElement("label");n.classList.add("magicfeedback-multi-question-matrix-label"),n.style.paddingRight="20px",n.textContent=e,i.appendChild(n),t.appendChild(i),te.forEach((i=>{const n=document.createElement("td"),a=document.createElement("input");a.type="radio",a.name=`${f}-${e}`,a.value=i,a.id=`${f}-${e}-${i}`,a.classList.add("magicfeedback-input"),n.appendChild(a),t.appendChild(n)})),Be.appendChild(t)})),Re.appendChild(Be),Z.appendChild(Re)}c.appendChild(Z);break;case n.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:c=document.createElement("div"),u="magicfeedback-priority-list";const ne=document.createElement("div");ne.classList.add("magicfeedback-priority-list-container");const ae=document.createElement("ul");ae.classList.add("magicfeedback-priority-list-list"),T&&(v=v.sort((()=>Math.random()-.5))),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,d,l;const c=i.previousElementSibling;if(c){const u=Number(null===(t=n.value)||void 0===t?void 0:t.split(".")[0])-1;n.value=`${u}. ${e}`,a.textContent=`${u}. ${e}`,o.style.visibility=1===u?"hidden":"visible",r.style.visibility=u===v.length?"hidden":"visible";const p=c.querySelector(".magicfeedback-input-magicfeedback-priority-list"),m=c.querySelector(".magicfeedback-priority-list-item-label"),h=c.querySelector(".magicfeedback-priority-list-arrow-up"),f=c.querySelector(".magicfeedback-priority-list-arrow-down");if(p&&m&&h&&f){const e=Number(null===(s=p.value)||void 0===s?void 0:s.split(".")[0])+1;p.value=`${e}.${null===(d=m.textContent)||void 0===d?void 0:d.split(".")[1]}`,m.textContent=`${e}.${null===(l=m.textContent)||void 0===l?void 0:l.split(".")[1]}`,h.style.visibility=1===e?"hidden":"visible",f.style.visibility=e===v.length?"hidden":"visible"}ae.insertBefore(i,c)}})),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,d;const l=i.nextElementSibling;if(l){const c=Number(null===(t=n.value)||void 0===t?void 0:t.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 u=l.querySelector(".magicfeedback-input-magicfeedback-priority-list"),p=l.querySelector(".magicfeedback-priority-list-item-label"),m=l.querySelector(".magicfeedback-priority-list-arrow-up"),h=l.querySelector(".magicfeedback-priority-list-arrow-down");if(u&&p&&m&&h){const e=Number(u.value.split(".")[0])-1;u.value=`${e}.${null===(s=p.textContent)||void 0===s?void 0:s.split(".")[1]}`,p.textContent=`${e}.${null===(d=p.textContent)||void 0===d?void 0:d.split(".")[1]}`,m.style.visibility=1===e?"hidden":"visible",h.style.visibility=e===v.length?"hidden":"visible"}ae.insertBefore(l,i)}})),s.appendChild(r),i.appendChild(s),ae.appendChild(i)})),ne.appendChild(ae),c.appendChild(ne);break;case n.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:c=document.createElement("div"),u="magicfeedback-point-system";const se=document.createElement("div");se.classList.add("magicfeedback-point-system-container");const oe=document.createElement("ul");oe.classList.add("magicfeedback-point-system-list"),oe.style.padding="0";const re=100,de=re/v.length,le=document.createElement("div");le.classList.add("magicfeedback-error"),le.textContent=a.placeholder.pointsystemerror(i||"en"),le.style.color="#C70039",le.style.fontSize="14px",le.style.textAlign="right",le.style.width="100%",le.style.display="none";const ce=document.createElement("div");ce.classList.add("magicfeedback-point-system-total"),ce.textContent="0 / 100 %",ce.style.textAlign="right",ce.style.fontSize="15px",ce.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=`${e}`,s.type="number",s.min="0",s.max=`${re}`,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=oe.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>re&&(s.value=`${de}%`,t-=Number(s.value));const i=document.getElementById("magicfeedback-submit");i&&(t<100?(ce.style.color="orange",i.setAttribute("disabled","true")):(le.style.display="none",ce.style.color="green",i.removeAttribute("disabled"))),ce.textContent=`${t} / 100 %`})),s.addEventListener("focus",(()=>{const e=document.getElementById("magicfeedback-submit");e&&(e.setAttribute("disabled","true"),e.addEventListener("pointerover",(()=>{const e=oe.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t<100&&(le.style.display="block")})))})),a.appendChild(s),a.appendChild(o),i.appendChild(a),oe.appendChild(i)})),se.appendChild(oe),se.appendChild(ce),se.appendChild(le),c.appendChild(se);break;case n.FEEDBACKAPPANSWERTYPE.INFO_PAGE:c=document.createElement("div"),u="magicfeedback-info-page";const ue=document.createElement("div");ue.classList.add("magicfeedback-info-message"),ue.innerHTML=C,c.appendChild(ue);break;case n.FEEDBACKAPPANSWERTYPE.UPLOAD_IMAGE:c=document.createElement("input"),c.type="file",c.accept="image/*",c.required=g,c.multiple=(null==b?void 0:b.multiple)||!1,c.maxLength=(null==b?void 0:b.maxFiles)||1,u="magicfeedback-upload-image";break;case n.FEEDBACKAPPANSWERTYPE.UPLOAD_FILE:c=document.createElement("input"),c.type="file",c.required=g,c.multiple=(null==b?void 0:b.multiple)||!1,c.maxLength=(null==b?void 0:b.maxFiles)||1,u="magicfeedback-upload-file";break;default:return y}c.id=`magicfeedback-${p}`,c.setAttribute("name",f),c.classList.add(u),(void 0!==E||null!==A)&&(c.value=A||E),["RADIO","MULTIPLECHOICE"].includes(h)||(c.classList.add("magicfeedback-input"),c.required=g);const S=document.createElement("label");S.setAttribute("for",`magicfeedback-${p}`),S.textContent=o(m,i),S.classList.add("magicfeedback-label");const O=document.createElement("label");if(O.textContent=o(null==b?void 0:b.subtitle,i),O.classList.add("magicfeedback-sublabel"),["CONSENT"].includes(h))y.classList.add("magicfeedback-consent-container"),y.appendChild(c),y.appendChild(S),y.appendChild(O);else{if("slim"!==t&&([n.FEEDBACKAPPANSWERTYPE.INFO_PAGE].includes(h)||(y.appendChild(S),y.appendChild(O)),void 0!==(null==b?void 0:b.general)&&""!==(null==b?void 0:b.general))){const qe=document.createElement("img");qe.src=null==b?void 0:b.general,qe.classList.add("magicfeedback-image"),qe.style.maxWidth="auto",qe.style.height="400px",qe.style.margin="10px 0",y.appendChild(qe)}if("LONGTEXT"===h&&x>0){const Ue=document.createElement("div");if(Ue.classList.add("magicfeedback-counter"),Ue.textContent=`${c.value.length}/${x}`,Ue.style.textAlign="right",Ue.style.fontSize="15px",Ue.style.marginTop="5px",c.addEventListener("input",(()=>{Ue.textContent=`${c.value.length}/${x}`})),y.appendChild(c),y.appendChild(Ue),(null==b?void 0:b.extraOption)&&(null==b?void 0:b.extraOptionText)){const Ke=document.createElement("div");Ke.classList.add("magicfeedback-skip-container"),Ke.classList.add("magicfeedback-checkbox-container"),Ke.style.display="flex",Ke.style.justifyContent="flex-start";const We=document.createElement("input");We.classList.add("magicfeedback-skip"),We.type="checkbox",We.id=`skip-${f}`,We.name=f,We.value="-",We.style.cursor="pointer";const je=document.createElement("label");je.htmlFor=`skip-${f}`,je.textContent=null==b?void 0:b.extraOptionText,je.style.fontSize="15px",je.style.cursor="pointer",je.style.margin="0 5px",We.addEventListener("click",(()=>{c.value="-",l&&l()})),Ke.appendChild(We),Ke.appendChild(je),y.appendChild(Ke)}}else y.appendChild(c)}return y}(h,i,d,`${s}${p?`/${m}`:""}`,1===t.length?c:void 0);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,"x-magicfeedback-parameters":window.location.search||""};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});return yield n.json()}catch(e){a.err(e)}}))},t.getSessionForm=function(e,t,i){return n(this,void 0,void 0,(function*(){try{const i=yield(0,s.default)(e+r.endpoints.sdk.session(t),{method:"GET",headers:d});return yield i.json()}catch(e){i.err(e)}}))},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":"2.0.0-beta.1","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})()));
|