@magicfeedback/native 2.1.7-alpha.2 → 2.1.7-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.magicfeedback=t():e.magicfeedback=t()}(self,(()=>{return e={945: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,a="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),s="FormData"in e,r="ArrayBuffer"in e;if(r)var o=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],l=ArrayBuffer.isView||function(e){return e&&o.indexOf(Object.prototype.toString.call(e))>-1};function d(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 m(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function h(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=h(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:a&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:s&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:i&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():r&&a&&(t=e)&&DataView.prototype.isPrototypeOf(t)?(this._bodyArrayBuffer=g(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):r&&(ArrayBuffer.prototype.isPrototypeOf(e)||l(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"))},a&&(this.blob=function(){var e=m(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?m(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(f)}),this.text=function(){var e,t,i,n=m(this);if(n)return n;if(this._bodyBlob)return e=this._bodyBlob,i=h(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)},s&&(this.formData=function(){return this.text().then(E)}),this.json=function(){return this.text().then(JSON.parse)},this}p.prototype.append=function(e,t){e=d(e),t=c(t);var i=this.map[e];this.map[e]=i?i+", "+t:t},p.prototype.delete=function(e){delete this.map[d(e)]},p.prototype.get=function(e){return e=d(e),this.has(e)?this.map[e]:null},p.prototype.has=function(e){return this.map.hasOwnProperty(d(e))},p.prototype.set=function(e,t){this.map[d(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 y=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function b(e,t){var i,n,a=(t=t||{}).body;if(e instanceof b){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new p(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,a||null==e._bodyInit||(a=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(),y.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)&&a)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(a)}function E(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var i=e.split("="),n=i.shift().replace(/\+/g," "),a=i.join("=").replace(/\+/g," ");t.append(decodeURIComponent(n),decodeURIComponent(a))}})),t}function k(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new p(t.headers),this.url=t.url||"",this._initBody(e)}b.prototype.clone=function(){return new b(this,{body:this._bodyInit})},v.call(b.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 A=[301,302,303,307,308];k.redirect=function(e,t){if(-1===A.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 C(e,i){return new Promise((function(n,s){var r=new b(e,i);if(r.signal&&r.signal.aborted)return s(new t.DOMException("Aborted","AbortError"));var o=new XMLHttpRequest;function l(){o.abort()}o.onload=function(){var e,t,i={status:o.status,statusText:o.statusText,headers:(e=o.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 a=i.join(":").trim();t.append(n,a)}})),t)};i.url="responseURL"in o?o.responseURL:i.headers.get("X-Request-URL");var a="response"in o?o.response:o.responseText;n(new k(a,i))},o.onerror=function(){s(new TypeError("Network request failed"))},o.ontimeout=function(){s(new TypeError("Network request failed"))},o.onabort=function(){s(new t.DOMException("Aborted","AbortError"))},o.open(r.method,r.url,!0),"include"===r.credentials?o.withCredentials=!0:"omit"===r.credentials&&(o.withCredentials=!1),"responseType"in o&&a&&(o.responseType="blob"),r.headers.forEach((function(e,t){o.setRequestHeader(t,e)})),r.signal&&(r.signal.addEventListener("abort",l),o.onreadystatechange=function(){4===o.readyState&&r.signal.removeEventListener("abort",l)}),o.send(void 0===r._bodyInit?null:r._bodyInit)}))}C.polyfill=!0,e.fetch||(e.fetch=C,e.Headers=p,e.Request=b,e.Response=k),t.Headers=p,t.Request=b,t.Response=k,t.fetch=C,Object.defineProperty(t,"__esModule",{value:!0})}({})}(n),n.fetch.ponyfill=!0,delete n.fetch.polyfill;var a=n;(t=a.fetch).default=a.fetch,t.fetch=a.fetch,t.Headers=a.Headers,t.Request=a.Request,t.Response=a.Response,e.exports=t},317:(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.deepdots.com/",t.HOST_API_URL_DEV="https://api-dev.deepdots.com/"},156: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 a=n(i(927));let s=null;s||(s=(0,a.default)()),t.default=s},927:function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function r(e){try{l(n.next(e))}catch(e){s(e)}}function o(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const a=i(57),s=i(665),r=i(256),o=i(313),l=i(317);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)?l.HOST_API_URL_DEV:l.HOST_API_URL),e.set("env",null==i?void 0:i.env),t=new r.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,a,s,r=!0,l,d){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:d,completed:r,id:l,feedback:s};try{const e=yield(0,o.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)}}}},79:(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}get(e){return this.items[e]}}},665:(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}}},57:function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function r(e){try{l(n.next(e))}catch(e){s(e)}}function o(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const a=i(558),s=i(256),r=i(313),o=i(213),l=i(217),d=i(700),c=i(591),u=i(79),p=i(636);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 l.PageGraph([]),this.progress=0,this.total=0,this.completed=!1,this.timeToCompleted=0}generate(e,t){var i,a,s,o,l,d,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,r.getForm)(this.url,this.appId,this.publicKey,this.log):yield(0,r.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===(o=n.pages)||void 0===o||o.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===(l=this.formData.pages)||void 0===l?void 0:l.length)||this.formatPages(),null===(d=this.formData.questions)||void 0===d||d.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,[],c.TransitionType.PAGE,(e.position+1).toString(),e.position.toString()),a=new d.Page(e.position.toString(),e.position,this.appId,[e],[n]);null===(i=null===(t=this.formData)||void 0===t?void 0:t.pages)||void 0===i||i.push(a)}));break;case"MAGICFORM":const t=new d.Page("1",1,this.appId,this.formData.questions,[]);this.formData.pages=[t]}}generateContainer(){let e=document.getElementById(this.selector);if(!e&&(e=document.getElementById("magicfeedback-container-"+this.appId),!e))throw new Error(`Element with ID '${this.selector}' not found.`);return e.classList.add("magicfeedback-container"),e.id="magicfeedback-container-"+this.appId,e.innerHTML="",e}generateForm(){var e,t,i,a;return n(this,void 0,void 0,(function*(){try{if(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 l.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 r=document.createElement("div");r.classList.add("magicfeedback-questions"),r.id="magicfeedback-questions-"+this.appId;const d=this.graph.getFirstPage();if(!d)throw new Error("No page found");if(this.total=this.graph.findMaxDepth(),d.elements=(0,o.renderQuestions)(d.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=d.elements)||void 0===i||i.forEach((e=>r.appendChild(e))),s.appendChild(r),this.history.enqueue(d),n.appendChild(s),this.progress=this.total-this.graph.findMaxDepth(d),this.formOptionsConfig.addButton){const e=(0,o.renderActions)(null===(a=this.formData)||void 0===a?void 0:a.identity,(()=>this.back()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);s.appendChild(e)}this.formOptionsConfig.addButton&&s.addEventListener("submit",(e=>{e.preventDefault(),this.send()})),this.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,o.renderStartMessage)(e,this.formOptionsConfig.addButton,this.formOptionsConfig.startButtonText,(()=>this.startForm()));t.appendChild(i),this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,formData:this.formData}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}))}getMetaData(){this.formOptionsConfig.customMetaData&&(this.feedback.metadata=[...this.feedback.metadata,...this.formOptionsConfig.customMetaData]),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&&![a.FEEDBACKAPPANSWERTYPE.CONSENT,a.FEEDBACKAPPANSWERTYPE.INFO_PAGE].includes(e.type)))){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),!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")}if(e.type===a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX){const i=this.feedback.answers.find((t=>t.key===e.ref));if(!i)throw this.log.err(`The matrix question ${e.ref} is required`),new Error("No response");const n=this.parseMatrixAnswerPre(i),a=Array.isArray(null==t?void 0:t.options)?t.options:[];if(a.length>0){if(a.find((e=>{const t=n.find((t=>t.key===e));return!t||!Array.isArray(t.value)||0===t.value.length})))throw this.log.err(`The matrix question ${e.ref} requires an answer in every row`),new Error("No response")}else if(0===n.length||n.some((e=>!Array.isArray(e.value)||0===e.value.length)))throw this.log.err(`The matrix question ${e.ref} requires an answer in every row`),new Error("No response")}}const r=yield this.pushAnswers(!1);if(!r)throw new Error("No response");this.id=r,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.`),this.feedback.answers=[],[];const t=this.history.back();if(!t){this.log.err("No page found");const t=e.querySelectorAll(".magicfeedback-input"),i=[],n={};return t.forEach((e=>{var t;const a=e,s=a.name;if(!s)return;const r=a.type;if(("radio"===r||"checkbox"===r)&&!a.checked)return;const o=a.value,l=a.classList[0];if((null==l?void 0:l.includes("magicfeedback-priority-list"))||(null===(t=a.id)||void 0===t?void 0:t.startsWith("priority-list-")))return n[s]||(n[s]=[]),void n[s].push(o);const d="magicfeedback-consent"===l?a.checked.toString():o;if(null==d)return;const c={key:s,value:[d]};i.push(c)})),Object.entries(n).forEach((([e,t])=>{const n=t.slice().sort(((e,t)=>Number(e.split(".")[0])-Number(t.split(".")[0])));i.push({key:e,value:n})})),this.feedback.answers=i,i}const i=[];let n=!1;const s=e.querySelectorAll(".magicfeedback-input"),o={};return s.forEach((e=>{const s=e,l=t.questions.find((e=>{var t;return null===(t=s.name)||void 0===t?void 0:t.includes(e.ref)})),d=s.type,c=s.classList[0],u={key:s.name,value:[]},p="magicfeedback-consent"===c?s.checked.toString():s.value;if(u.key&&""!==u.key)switch(null==l?void 0:l.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:""!==p&&("email"===d?(0,r.validateEmail)(p)?(this.feedback.profile.push({key:"email",value:[p]}),u.value.push(p),i.push(u)):(this.log.err("Invalid email"),n=!0):(u.value.push(p),i.push(u)));break;case a.FEEDBACKAPPANSWERTYPE.RADIO:case a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:case a.FEEDBACKAPPANSWERTYPE.BOOLEAN:s.checked&&(u.value.push(p),i.push(u));break;case a.FEEDBACKAPPANSWERTYPE.CONSENT:u.value.push(s.checked.toString()),i.push(u);break;case a.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:case a.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:case a.FEEDBACKAPPANSWERTYPE.RATING_STAR:s.checked&&(u.value.push(p),i.push(u));break;case a.FEEDBACKAPPANSWERTYPE.SELECT:""!==p&&(u.value.push(p),i.push(u));break;case a.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:"hidden"===d&&(o[u.key]||(o[u.key]=[]),o[u.key].push(p));case a.FEEDBACKAPPANSWERTYPE.UPLOAD_IMAGE:case a.FEEDBACKAPPANSWERTYPE.UPLOAD_FILE:}})),n?[]:(Object.entries(o).forEach((([e,t])=>{if(!t||0===t.length)return;const n=t.slice().sort(((e,t)=>Number(e.split(".")[0])-Number(t.split(".")[0])));i.push({key:e,value:n})})),this.feedback.answers=i,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,o.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,r.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,r.getFollowUpQuestion)(i,n,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e){var t,i,a;return n(this,void 0,void 0,(function*(){const n=this.history.back();if(!n)throw new Error("No page found");const s=n.getFollowupQuestions();if(0===(null==s?void 0:s.length))return void(yield this.renderNextQuestion(e,n));const r=[];for(const e of s){const t=n.questions.find((t=>t.ref===e));if(t){const e=yield this.callFollowUpQuestion(t);e&&r.push(e)}}if(0===r.length)return void(yield this.renderNextQuestion(e,n));const l=new d.Page(n.id,n.position,this.appId,r,n.edges),c=new p.PageNode(n.id,n.position,n.edges,l,r,!0);c.elements=(0,o.renderQuestions)(r,this.formOptionsConfig.questionFormat,null===(t=this.formData)||void 0===t?void 0:t.lang[0],null===(i=this.formData)||void 0===i?void 0:i.product,(()=>this.send())),this.history.enqueue(c),this.progress+=.5,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,s,r,l,d;return n(this,void 0,void 0,(function*(){let n=this.graph.getNextPage(t,this.feedback.answers);if(!n)return void this.finish();const u=n.edges.filter((e=>"PRECONDITIONAL"===e.typeCondition)).sort(((e,t)=>e.position<t.position?-1:e.position>t.position?1:0));if((null==u?void 0:u.length)>0){let t=null;const r=u.map((e=>e.questionRef));for(let e=this.history.size()-1;e>=0;e--){const n=this.history.get(e);if(n&&(t=null===(i=n.answers)||void 0===i?void 0:i.find((e=>r.includes(e.key))),t))break}let o=!u.some((e=>e.transition===c.TransitionType.ALLOW));if(t)for(const i of u){let r=!1;const l=null===(s=this.formData)||void 0===s?void 0:s.questions.find((e=>e.ref===i.questionRef)),d=Array.isArray(t.value)?t.value:[t.value],u=Array.isArray(i.value)?i.value:[i.value];if((null==l?void 0:l.type)===a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX)r=this.evaluateMatrixPreconditional(i,t);else switch(i.typeOperator){case"EQUAL":case"INQ":r=d.some((e=>u.includes(e)));break;case"NOEQUAL":case"NINQ":r=d.every((e=>!u.includes(e)));break;case"GREATER":r=d.some((e=>Number(e)>Number(u[0])));break;case"LESS":r=d.some((e=>Number(e)<Number(u[0])));break;case"GREATEREQUAL":r=d.some((e=>Number(e)>=Number(u[0])));break;case"LESSEQUAL":r=d.some((e=>Number(e)<=Number(u[0])))}if(r)switch(this.feedback.answers=[],i.transition){case c.TransitionType.NEXT:return void(n&&(yield this.renderNextQuestion(e,n)));case c.TransitionType.ALLOW:o=!0}}if(!o)return this.feedback.answers=[],void(n&&(yield this.renderNextQuestion(e,n)))}n.elements=(0,o.renderQuestions)(n.questions,this.formOptionsConfig.questionFormat,null===(r=this.formData)||void 0===r?void 0:r.lang[0],null===(l=this.formData)||void 0===l?void 0:l.product,(()=>this.send())),e.innerHTML="",null===(d=n.elements)||void 0===d||d.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}))}))}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"}))}))}previewQuestion(e,t,i){var n,a;const s=Array.isArray(t)?t:[t];if(!s||0===s.length)throw new Error("[MagicFeedback] No question provided for preview");const r=document.getElementById(e);if(!r)throw new Error(`[MagicFeedback] Element with ID '${e}' not found.`);const{format:l=this.formOptionsConfig.questionFormat||"standard",language:d=(null===(n=this.formData)||void 0===n?void 0:n.lang)&&this.formData.lang[0]||"en",product:c=(null===(a=this.formData)||void 0===a?void 0:a.product)||{customIcons:!1},clearContainer:u=!0,wrap:p=!0}=i||{};u&&(r.innerHTML="");let m=[];try{m=(0,o.renderQuestions)(s,l,d,c)}catch(e){throw this.log.err(e),e}let h=r;if(p){const e=document.createElement("div");e.classList.add("magicfeedback-preview-question"),h.appendChild(e),h=e}return m.forEach((e=>h.appendChild(e))),r}parseMatrixAnswerPre(e){if(!e||!e.value)return[];if(1===e.value.length&&"string"==typeof e.value[0]&&e.value[0].trim().startsWith("["))try{const t=JSON.parse(e.value[0]);if(Array.isArray(t))return t}catch(e){return[]}return Array.isArray(e.value)&&e.value.length>0&&"object"==typeof e.value[0]&&null!==e.value[0]&&"key"in e.value[0]?e.value:[]}evaluateMatrixPreconditional(e,t){const i=Array.isArray(e.value)?e.value:[e.value],n=new Set(e.option||[]),a=this.parseMatrixAnswerPre(t);if(!a.length)return!1;const s=n.size>0?a.filter((e=>n.has(e.key))):a;if(!s.length)return!1;switch(e.typeOperator){case"EQUAL":case"INQ":return s.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.includes(e)))));case"NOEQUAL":case"NINQ":return s.every((e=>(Array.isArray(e.value)?e.value:[e.value]).every((e=>!i.includes(e)))));case"GREATER":return s.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)>Number(t)))))));case"LESS":return s.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)<Number(t)))))));case"GREATEREQUAL":return s.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)>=Number(t)))))));case"LESSEQUAL":return s.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)<=Number(t)))))));default:return!1}}}},700:(e,t)=>{"use strict";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}}},217:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.PageGraph=void 0;const n=i(636),a=i(558),s=i(591);t.PageGraph=class{constructor(e){this.nodes=new Map,this.buildGraph(e)}buildGraph(e){e.forEach((e=>{var t;e.integrationPageRoutes&&(e.integrationPageRoutes=(null===(t=e.integrationPageRoutes)||void 0===t?void 0:t.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 i=new n.PageNode(e.id,e.position,e.integrationPageRoutes||[],e,e.integrationQuestions);this.nodes.set(i.id,i)}))}getNodeById(e){return this.nodes.get(e)}getNextEdgeByDefault(e){if(!e)return;const t=e.edges.find((e=>e.typeCondition===s.ConditionType.DIRECT));if(!t||![s.TransitionType.FINISH,s.TransitionType.REDIRECT].includes(t.transition)){if(t&&t.transitionDestiny)return t.transitionDestiny;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((i=>{const n=e.questions.find((e=>e.ref===i.questionRef)),r=null==t?void 0:t.filter((e=>e.key===i.questionRef));if("DIRECT"===i.typeCondition)return!0;if(!r||0===r.length)return!1;if((null==n?void 0:n.type)===a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX)return this.evaluateMatrixCondition(i,r);const o=Array.isArray(i.value)?i.value:[i.value];switch(i.typeOperator){case s.OperatorType.EQUAL:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.includes(e)))));case s.OperatorType.NOEQUAL:return r.every((e=>(Array.isArray(e.value)?e.value:[e.value]).every((e=>!o.includes(e)))));case s.OperatorType.GREATER:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.some((t=>Number(e)>Number(t)))))));case s.OperatorType.LESS:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.some((t=>Number(e)<Number(t)))))));case s.OperatorType.GREATEREQUAL:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.some((t=>Number(e)>=Number(t)))))));case s.OperatorType.LESSEQUAL:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.some((t=>Number(e)<=Number(t)))))));case s.OperatorType.INQ:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.includes(e)))));case s.OperatorType.NINQ:return r.every((e=>(Array.isArray(e.value)?e.value:[e.value]).every((e=>!o.includes(e)))));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=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.filter((e=>e.typeCondition!==s.ConditionType.PRECONDITIONAL))||[]],r=this.getNextEdgeByDefault(e);if(r){const i=this.getNodeById(r);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 a=this.getNodeById(e.transitionDestiny);if(a&&!t.has(a)){const e=i+1,s=new Set(t),r=this.DFSUtil(a,s,e);n=Math.max(n,r)}}return n}parseMatrixAnswer(e){if(!e||!e.value)return[];if(1===e.value.length&&"string"==typeof e.value[0]&&e.value[0].trim().startsWith("["))try{const t=JSON.parse(e.value[0]);if(Array.isArray(t))return t}catch(e){return[]}return Array.isArray(e.value)&&e.value.length>0&&"object"==typeof e.value[0]&&null!==e.value[0]&&"key"in e.value[0]?e.value:[]}evaluateMatrixCondition(e,t){const i=Array.isArray(e.value)?e.value:[e.value],n=new Set(e.option||[]),a=t[0],r=this.parseMatrixAnswer(a);if(!r.length)return!1;const o=n.size>0?r.filter((e=>n.has(e.key))):r;if(!o.length)return!1;switch(e.typeOperator){case s.OperatorType.EQUAL:case s.OperatorType.INQ:return o.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.includes(e)))));case s.OperatorType.NOEQUAL:case s.OperatorType.NINQ:return o.every((e=>(Array.isArray(e.value)?e.value:[e.value]).every((e=>!i.includes(e)))));case s.OperatorType.GREATER:return o.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)>Number(t)))))));case s.OperatorType.LESS:return o.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)<Number(t)))))));case s.OperatorType.GREATEREQUAL:return o.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)>=Number(t)))))));case s.OperatorType.LESSEQUAL:return o.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)<=Number(t)))))));default:return!1}}}},636:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.PageNode=void 0,t.PageNode=class{constructor(e,t,i,n,a,s=!1){this.answers=[],this.id=e,this.position=t,this.edges=i,this.data=n,this.questions=a.sort(((e,t)=>e.position-t.position)),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))}setAnswer(e){this.answers=e}}},591:(e,t)=>{"use strict";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",s.NEXT="NEXT",s.ALLOW="ALLOW",function(e){e.LOGICAL="LOGICAL",e.DIRECT="DIRECT",e.PRECONDITIONAL="PRECONDITIONAL"}(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,r,o,l,d,c,u){this.id=e,this.questionRef=t,this.typeCondition=d||i.LOGICAL,this.typeOperator=a,this.value=s||[],this.transition=r,this.transitionDestiny=o,this.status=n.ACTIVE,this.generatedAt=new Date,this.updatedAt=new Date,this.integrationPageId=l,this.position=c||0,this.option=u||[]}}},558:(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={}))},857:(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"}}},784:(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 % হতে হবে"}}}},213:(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(558),a=i(784),s="https://survey-dev.magicfeedback.io/assets/emojis";function r(e,t){return e?"object"==typeof e?e[t]||e.en:e:""}function o(e,t,i,n,a,s=!0,r="ltr",o="row"){const l=document.createElement("div");l.classList.add("magicfeedback-rating-placeholder"),l.style.display="flex",l.style.flexDirection=o,l.style.alignItems="center",l.style.justifyContent="space-between",l.style.width=a?`calc(100% - (100% / ${t+1}))`:"100%",l.style.marginRight="auto",s&&window.innerWidth<600&&(l.style.flexDirection="column");const d=document.createElement("span");d.textContent=i,d.classList.add("magicfeedback-rating-placeholder-value"),d.style.fontSize="15px",d.style.textAlign="ltr"===r?"left":"right",d.style.width="50%",(s&&window.innerWidth<600||"column"===o)&&(d.textContent=`${e} = ${i}`,d.style.width="100%",d.style.textAlign="left",d.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"===r?"right":"left",c.style.width="50%",(s&&window.innerWidth<600||"column"===o)&&(c.textContent=`${t} = ${n}`,c.style.width="100%",c.style.textAlign="left",c.style.marginBottom="5px"),"ltr"===r?(i&&l.appendChild(d),n&&l.appendChild(c)):(n&&l.appendChild(c),i&&l.appendChild(d)),l}t.renderQuestions=function e(t,i="standard",l="en",d={customIcons:!1},c){if(!t)throw new Error("[MagicFeedback] No questions provided");const u=[],{customIcons:p,id:m}=d;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=r(h.title,l),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,l,d,c).forEach((e=>{t.appendChild(e)})),u.push(t)}else{const e=function(e,t,i,l,d){var c,u,p;let m,h,{id:f,title:g,type:v,ref:y,require:b,value:E,defaultValue:k,assets:A}=e,C=document.createElement("div");C.classList.add("magicfeedback-div");const x=window.innerWidth<600,w="slim"===t?r(g,i):null==A?void 0:A.placeholder,T=(N=y,new URLSearchParams(window.location.search).get(N)),L=(null==A?void 0:A.maxCharacters)||0,O=void 0!==(null==A?void 0:A.randomPosition)&&(null==A?void 0:A.randomPosition),S=(null==A?void 0:A.direction)||"row",P=(null==A?void 0:A.order)||"ltr";var N;switch(v){case n.FEEDBACKAPPANSWERTYPE.TEXT:m=document.createElement("input"),m.type="text",m.placeholder=w||a.placeholder.answer(i||"en"),T&&(m.value=T),m.addEventListener("keyup",(e=>{e.preventDefault(),console.log(e.key,e),"Enter"===e.key&&d&&d()})),h="magicfeedback-text";break;case n.FEEDBACKAPPANSWERTYPE.LONGTEXT:m=document.createElement("textarea"),m.rows=3,L>0&&(m.maxLength=L),m.placeholder=w||a.placeholder.answer(i||"en"),T&&(m.value=T),h="magicfeedback-longtext";break;case n.FEEDBACKAPPANSWERTYPE.NUMBER:m=document.createElement("input"),m.type="number",m.placeholder="slim"===t?r(g,i):a.placeholder.number(i||"en"),h="magicfeedback-number",E.length&&(E.sort(((e,t)=>Number(e)-Number(t))),m.max=E[E.length-1],m.min=E[0],m.value=E[0]),T&&!isNaN(Number(T))&&(m.value=T);break;case n.FEEDBACKAPPANSWERTYPE.RADIO:case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:m=document.createElement("div"),h="magicfeedback-"+("MULTIPLECHOICE"===v?"checkbox":"radio");let $=E||[];O&&($=$.sort((()=>Math.random()-.5)));let R=(null==A?void 0:A.exclusiveAnswers)||[];(null==A?void 0:A.extraOption)&&(R=R.filter((e=>e!==A.extraOptionText))),R.length>0&&(null==R||R.forEach((e=>{$.includes(e)||$.push(e)}))),(null==A?void 0:A.extraOption)&&!$.includes(null==A?void 0:A.extraOptionText)&&$.push(null==A?void 0:A.extraOptionText),$.forEach(((e,t)=>{const s=document.createElement("div");s.classList.add(`magicfeedback-${"MULTIPLECHOICE"===v?"checkbox":"radio"}-container`);const r=document.createElement("label"),o=document.createElement("input");if(o.id=`rating-${y}-${t}`,o.type="MULTIPLECHOICE"===v?"checkbox":"radio",o.name=y,o.value=e,o.classList.add(h),o.classList.add("magicfeedback-input"),v===n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE&&(null==A?void 0:A.maxOptions)&&(null==A?void 0:A.maxOptions)>0&&o.addEventListener("change",(()=>{document.querySelectorAll(`input[name="${y}"]:checked`).length>(null==A?void 0:A.maxOptions)&&(o.checked=!1)})),v===n.FEEDBACKAPPANSWERTYPE.RADIO&&d&&(!(null==A?void 0:A.extraOptionText)||(null==A?void 0:A.extraOptionText)&&e!==(null==A?void 0:A.extraOptionText))&&o.addEventListener("change",(()=>{d()})),e!==k&&e!==T||(o.checked=!0),r.textContent=e,r.htmlFor=`rating-${y}-${t}`,o.addEventListener("change",(t=>{const i=document.getElementById(`extra-option-${y}`);t.target.checked&&R.includes(e)?(console.log("exclusiveAnswers",R,e),$.forEach((t=>{t!==e&&(document.querySelector(`input[value="${t}"]`).checked=!1)})),i&&(i.style.display="none")):R.forEach((t=>{t!==e&&(document.querySelector(`input[value="${t}"]`).checked=!1)})),(null==A?void 0:A.extraOption)&&e===(null==A?void 0:A.extraOptionText)&&i&&(i.style.display=t.target.checked?"block":"none")})),s.appendChild(o),s.appendChild(r),m.appendChild(s),(null==A?void 0:A.extraOption)&&e===(null==A?void 0:A.extraOptionText)){const e=document.createElement("input");e.type="text",e.placeholder=(null==A?void 0:A.extraOptionPlaceholder)||a.placeholder.answer(i||"en"),e.classList.add("magicfeedback-extra-option"),e.classList.add("magicfeedback-input"),e.id=`extra-option-${y}`,e.name=`extra-option-${y}`,e.style.display="none",m.appendChild(e)}}));break;case n.FEEDBACKAPPANSWERTYPE.BOOLEAN:m=document.createElement("div"),h="magicfeedback-radio";const _=document.createElement("div");_.classList.add("magicfeedback-boolean-container"),_.style.display="flex",_.style.flexDirection="row",_.style.justifyContent="space-between",_.style.width="70%",_.style.margin="auto",((null==A?void 0:A.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-${y}-${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-${y}-${t}`,n.textContent=e,n.style.margin="0",n.style.padding="0";const a=document.createElement("input");a.id=`rating-${y}-${t}`,a.type="radio",a.name=y,a.value=["Yes","No"][t],a.classList.add(h),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",(()=>{d&&d()})),T&&T.toLowerCase()===a.value.toLowerCase()&&(a.checked=!0),i.appendChild(a),i.appendChild(n),_.appendChild(i)})),m.appendChild(_);break;case n.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:m=document.createElement("div"),h="magicfeedback-rating";const F=document.createElement("div");F.classList.add("magicfeedback-rating-container");const M=(null==A?void 0:A.max)?Number(null==A?void 0:A.max):5,B=(null==A?void 0:A.min)?Number(null==A?void 0:A.min):1,U=o(B,M,null==A?void 0:A.minPlaceholder,null==A?void 0:A.maxPlaceholder,null==A?void 0:A.extraOption);for(let de=B;de<=M;de++){const ce=document.createElement("div");ce.classList.add("magicfeedback-rating-option");const ue=document.createElement("label");ue.htmlFor=`rating-${y}-${de}`,ue.classList.add("magicfeedback-rating-option-label-container");const pe=document.createElement("label");pe.htmlFor=`rating-${y}-${de}`,pe.textContent=de.toString();const me=document.createElement("img");if(me.alt=`face-${y}-${de}`,me.className=`rating-image${de}`,0===B&&10===M)me.src=`${l}/${de}.svg`,me.onerror=()=>me.src=`${s}/${de}.svg`;else if(1===B&&5===M)switch(de){case 1:me.src=`${l}/1.svg`,me.onerror=()=>me.src=`${s}/1.svg`;break;case 2:me.src=`${l}/2.svg`,me.onerror=()=>me.src=`${s}/2.svg`;break;case 3:me.src=`${l}/6.svg`,me.onerror=()=>me.src=`${s}/6.svg`;break;case 4:me.src=`${l}/9.svg`,me.onerror=()=>me.src=`${s}/9.svg`;break;case 5:me.src=`${l}/10.svg`,me.onerror=()=>me.src=`${s}/10.svg`}else{const fe=Math.round(10/(M-B)*(de-B));me.src=`${l}/${fe}.svg`,me.onerror=()=>me.src=`${s}/${fe}.svg`}const he=document.createElement("input");he.id=`rating-${y}-${de}`,he.type="radio",he.name=y,he.value=de.toString(),he.classList.add(h),he.classList.add("magicfeedback-input"),d&&he.addEventListener("change",(()=>{d()})),T&&T===he.value&&(he.checked=!0),ue.appendChild(he),ue.appendChild(me),ue.appendChild(pe),ce.appendChild(ue),F.appendChild(ce)}if((null==A?void 0:A.extraOption)&&(null==A?void 0:A.extraOptionText)){const ge=document.createElement("div");ge.classList.add("magicfeedback-rating-option");const ve=document.createElement("label");ve.htmlFor=`rating-${y}-extra`,ve.classList.add("magicfeedback-rating-option-label-container");const ye=document.createElement("label");ye.htmlFor=`rating-${y}-extra`,ye.textContent=null==A?void 0:A.extraOptionText;const be=document.createElement("img");be.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",be.alt=`face-${y}-extra`,be.className="magicfeedback-rating-image-extra";const Ee=document.createElement("input");Ee.id=`rating-${y}-extra`,Ee.type="radio",Ee.name=y,Ee.value="-",Ee.classList.add(h),Ee.classList.add("magicfeedback-input"),d&&Ee.addEventListener("change",(()=>{d()})),ve.appendChild(Ee),ve.appendChild(be),ve.appendChild(ye),ge.appendChild(ve),F.appendChild(ge)}m.appendChild(U),m.appendChild(F);break;case n.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:h="magicfeedback-rating-number",m=function(e,t,i,n,a,s,r,o){const l=document.createElement("div");l.classList.add("magicfeedback-rating-number");const d="ltr"===i?n:`${n}-reverse`,c=document.createElement("div");c.classList.add("magicfeedback-rating-number-container"),c.classList.add(`magicfeedback-rating-number-container-${i}`),c.classList.add(`magicfeedback-rating-number-container-${n}`),c.style.display="flex",c.style.flexDirection=d,c.setAttribute("role","radiogroup"),c.setAttribute("aria-label",(null==t?void 0:t.ariaLabel)||"Rating");const u=(null==t?void 0:t.max)?Number(null==t?void 0:t.max):10,p=(null==t?void 0:t.min)?Number(null==t?void 0:t.min):0,m=(null==t?void 0:t.numberPlaceholders)||null,h=!(a||"column"===n);for(let i=p;i<=u;i++){const l=document.createElement("div");l.classList.add("magicfeedback-rating-number-option"),l.classList.add(`magicfeedback-rating-number-option-${n}`);const d=document.createElement("label");if(d.htmlFor=`rating-${e}-${i}`,d.classList.add("magicfeedback-rating-number-option-label-container"),h&&(d.style.position="relative",d.style.overflow="visible"),h){const e=document.createElement("span");e.classList.add("magicfeedback-rating-number-cap"),e.classList.add("magicfeedback-rating-placeholder-value"),e.style.fontSize="14px",e.style.whiteSpace="nowrap",e.style.wordBreak="normal",i===p&&(null==t?void 0:t.minPlaceholder)?(e.textContent=t.minPlaceholder,e.dataset.capType="min"):i===u&&(null==t?void 0:t.maxPlaceholder)?(e.textContent=t.maxPlaceholder,e.dataset.capType="max"):e.dataset.capType="mid",d.appendChild(e)}let f=i.toString();h?m&&m[i]&&!a&&(d.title=m[i]):m&&m[i]?f+=` = ${m[i]}`:i===p&&(null==t?void 0:t.minPlaceholder)?f+=` = ${null==t?void 0:t.minPlaceholder}`:i===u&&(null==t?void 0:t.maxPlaceholder)&&(f+=` = ${null==t?void 0:t.maxPlaceholder}`);const g=document.createElement("input");g.id=`rating-${e}-${i}`,g.type="radio",g.name=e,g.value=i.toString(),g.classList.add(s),g.classList.add("magicfeedback-input"),g.setAttribute("aria-label",`${i}`),r&&g.addEventListener("change",(()=>r())),o&&o===g.value&&(g.checked=!0);const v=document.createElement("label");v.htmlFor=`rating-${e}-${i}`,v.textContent=f,v.classList.add("magicfeedback-rating-number-value"),d.appendChild(g),d.appendChild(v),l.appendChild(d),c.appendChild(l)}if((null==t?void 0:t.extraOption)&&(null==t?void 0:t.extraOptionText)){const n=document.createElement("div");n.classList.add("magicfeedback-rating-number-option");const a=document.createElement("label");if(a.htmlFor=`rating-${e}-extra`,a.classList.add("magicfeedback-rating-number-option-label-container"),h&&(a.style.position="relative",a.style.overflow="visible"),h){const e=document.createElement("span");e.classList.add("magicfeedback-rating-number-cap"),e.dataset.capType="extra",e.style.fontSize="12px",e.style.whiteSpace="nowrap",e.style.wordBreak="normal",a.appendChild(e)}const o=document.createElement("input");o.id=`rating-${e}-extra`,o.type="radio",o.name=e,o.value="-",o.classList.add(s),o.classList.add("magicfeedback-input"),o.setAttribute("aria-label",null==t?void 0:t.extraOptionText),r&&o.addEventListener("change",(()=>r()));const l=document.createElement("label");l.htmlFor=`rating-${e}-extra`,l.textContent=null==t?void 0:t.extraOptionText,l.classList.add("magicfeedback-rating-number-value"),a.appendChild(o),a.appendChild(l),n.appendChild(a),"ltr"===i?c.appendChild(n):c.insertBefore(n,c.firstChild)}return l.appendChild(c),h&&requestAnimationFrame((()=>{const e=Array.from(c.querySelectorAll(".magicfeedback-rating-number-cap"));if(0===e.length)return;let t=0;e.forEach((e=>{var i;if(null===(i=e.textContent)||void 0===i?void 0:i.trim()){const i=e.getBoundingClientRect().height||0;i>t&&(t=i)}})),c.style.position="relative",c.style.paddingTop=`${0===t?"42":t+6}px`,e.forEach((e=>{const n=e.getBoundingClientRect().height||0;console.log(t,n,6),e.style.position="absolute",e.style.top=`-${0===t?"42":t+n}px`,e.style.zIndex="1",e.style.pointerEvents="none",e.style.padding="0",e.style.boxSizing="border-box",e.style.whiteSpace="nowrap",e.style.wordBreak="normal",e.style.maxWidth="none",e.style.width="max-content";const a=e.dataset.capType;"min"===a?("ltr"===i?(e.style.left="10px",e.style.textAlign="left"):(e.style.right="10px",e.style.textAlign="right"),e.style.transform="none"):"max"===a?("ltr"===i?(e.style.right="10px",e.style.textAlign="right"):(e.style.left="10px",e.style.textAlign="left"),e.style.transform="none"):(e.style.left="50%",e.style.transform="translateX(-50%)",e.style.textAlign="center")})),c.style.overflow="visible"})),l}(y,A,P,S,x,h,d,T);break;case n.FEEDBACKAPPANSWERTYPE.RATING_STAR:m=document.createElement("div"),h="magicfeedback-rating-star";const q=function(e,t,i,n=()=>{},a){const s="magicfeedback-rating-star-selected",r=document.createElement("div");r.classList.add("magicfeedback-rating-star-container"),r.style.maxWidth="300px",r.style.margin="auto",r.dataset.originalSelection="0";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"),a&&a===o.value&&(o.checked=!0),o.addEventListener("change",(()=>{const e=r.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);r.dataset.originalSelection=o.value,n&&n()})),i.appendChild(o);const l=document.createElement("label");l.htmlFor=`rating-${e}-${t}`,l.classList.add("rating__star"),l.textContent="★",l.style.fontSize="40px",l.style.color="#CCCCCC",l.style.cursor="pointer",l.addEventListener("mouseenter",(()=>{const e=r.querySelectorAll(".rating__star"),i=t-1;e.forEach(((e,t)=>{t<=i?e.classList.contains(s)||e.classList.add(s):e.classList.contains(s)&&e.classList.remove(s)}))})),l.addEventListener("mouseleave",(()=>{const e=Number(r.dataset.originalSelection||"0");r.querySelectorAll(".rating__star").forEach(((t,i)=>{i<e?t.classList.contains(s)||t.classList.add(s):t.classList.contains(s)&&t.classList.remove(s)}))})),i.appendChild(l),r.appendChild(i)}return r.appendChild(o(1,5,t,i,!1,!1)),r}(y,null==A?void 0:A.minPlaceholder,null==A?void 0:A.maxPlaceholder,d,T);m.appendChild(q);break;case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:m=document.createElement("div"),h="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 W=E.length;let Q=1,K=1;if(window.innerWidth<600)Q=1,K=W;else switch(W){case 1:case 2:case 3:Q=W,K=1;break;case 4:case 5:case 6:K=2,Q=Math.ceil(W/K);break;case 7:case 8:case 9:K=3,Q=Math.ceil(W/K);break;default:K=4,Q=Math.ceil(W/K)}const G=void 0!==(null==A?void 0:A.addTitle)&&(null==A?void 0:A.addTitle),Y=void 0!==(null==A?void 0:A.multiOption)&&(null==A?void 0:A.multiOption),z=void 0!==(null==A?void 0:A.extraOption)&&(null==A?void 0:A.extraOption);function H(e){try{const{position:t,url:i,value:n}=e,a=document.createElement("label");a.classList.add("magicfeedback-multiple-choice-image-option"),a.style.width=`calc( ${100/Q}% - 10px)`,a.style.height=`calc( ${100/K}% - 10px)`,a.style.margin="5px";const s=document.createElement("label");s.htmlFor=`rating-${y}-${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 r=document.createElement("label");r.textContent=n,r.classList.add("magicfeedback-multiple-choice-image-label");const o=document.createElement("input");o.id=`rating-${y}-${t}`,o.type=Y?"checkbox":"radio",o.name=y,o.value=n,o.style.position="absolute",o.style.opacity="0",o.style.width="0",o.style.height="0",o.classList.add("magicfeedback-input"),T&&T===o.value&&(o.checked=!0),!Y&&d&&o.addEventListener("change",(()=>{console.log("send"),d()}));const l=document.createElement("img");l.classList.add("magicfeedback-multiple-choice-image-image"),l.src=i,l.style.cursor="pointer",l.style.backgroundSize="cover",l.style.backgroundPosition="center",l.style.width="100%",l.style.height="100%",l.style.objectFit="cover",l.style.margin="auto",s.appendChild(o),s.appendChild(l),G&&s.appendChild(r),a.appendChild(s),j.appendChild(a)}catch(e){console.error(e)}}O&&(E=E.sort((()=>Math.random()-.5))),E.forEach((e=>H(JSON.parse(e)))),z&&(null==A?void 0:A.extraOptionValue)&&(null==A?void 0:A.extraOptionValue.length)>0&&H(null==A?void 0:A.extraOptionValue[0]),m.appendChild(j);break;case n.FEEDBACKAPPANSWERTYPE.SELECT:m=document.createElement("select"),h="magicfeedback-select";const V=document.createElement("option");V.value="",V.text="slim"===t?r(g,i):k||"Select an option",V.disabled=!0,V.selected=!0,m.appendChild(V),E.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,m.appendChild(t)})),T&&E.includes(T)&&(m.value=T),d&&m.addEventListener("change",(()=>{d()}));break;case n.FEEDBACKAPPANSWERTYPE.DATE:m=document.createElement("input"),m.type="date",m.required=b,m.placeholder=w||a.placeholder.date(i||"en"),h="magicfeedback-date",T&&(m.value=T);break;case n.FEEDBACKAPPANSWERTYPE.CONSENT:m=document.createElement("input"),h="magicfeedback-consent",m.type="checkbox",m.id=`magicfeedback-${f}`,m.name=y,m.value="true",m.required=b,m.classList.add("magicfeedback-consent"),m.classList.add("magicfeedback-input"),T&&E.includes(T)&&(m.checked=!0),d&&m.addEventListener("change",(()=>{d()}));break;case n.FEEDBACKAPPANSWERTYPE.EMAIL:m=document.createElement("input"),m.type="email",m.required=b,m.placeholder=w||"you@example.com",h="magicfeedback-email",T&&(m.value=T);break;case n.FEEDBACKAPPANSWERTYPE.PASSWORD:m=document.createElement("input"),m.type="password",m.required=b,m.placeholder=w||a.placeholder.password(i||"en"),h="magicfeedback-password",T&&(m.value=T);break;case n.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:m=document.createElement("div"),h="magicfeedback-multi-question-matrix";const X=document.createElement("div");X.classList.add("magicfeedback-multi-question-matrix-container");let J=(null==A?void 0:A.options)||[],Z=[...E],ee=[];if(O&&(J=null==J?void 0:J.sort((()=>Math.random()-.5)),Z=[...Z].sort((()=>Math.random()-.5))),(null==A?void 0:A.exclusiveAnswers)&&(ee=null==A?void 0:A.exclusiveAnswers,null==ee||ee.forEach((e=>{Z.includes(e)||Z.push(e)}))),window.innerWidth<600){const ke=document.createElement("div");ke.classList.add("magicfeedback-multi-question-matrix-list"),null==J||J.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),Z.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=`${y}-${e}-${i}`,s.type="radio",s.name=`${y}-${e}`,s.value=i,s.classList.add("magicfeedback-input"),a.textContent=i,a.htmlFor=`${y}-${e}-${i}`,n.appendChild(s),n.appendChild(a),t.appendChild(n)})),ke.appendChild(t)})),X.appendChild(ke)}else{const Ae=document.createElement("table");Ae.classList.add("magicfeedback-multi-question-matrix-table");const Ce=document.createElement("thead");Ce.classList.add("magicfeedback-multi-question-matrix-header"),Ce.style.paddingBottom="15px";const xe=document.createElement("tr"),we=document.createElement("th");xe.appendChild(we),Z.forEach((e=>{const t=document.createElement("th");t.textContent=e,xe.appendChild(t)})),Ce.appendChild(xe),Ae.appendChild(Ce);const Te=document.createElement("tbody");null==J||J.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",i.style.padding="10px";const n=document.createElement("label");n.classList.add("magicfeedback-multi-question-matrix-label"),n.textContent=e,i.appendChild(n),t.appendChild(i),Z.forEach((i=>{const n=document.createElement("td"),a=document.createElement("input");a.type="radio",a.name=`${y}-${e}`,a.value=i,a.id=`${y}-${e}-${i}`,a.classList.add("magicfeedback-input"),n.appendChild(a),t.appendChild(n)})),Te.appendChild(t)})),Ae.appendChild(Te),X.appendChild(Ae)}m.appendChild(X);break;case n.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:m=document.createElement("div"),h="magicfeedback-priority-list";const te=function(e){const{value:t,ref:i,randomPosition:n=!1,limitPriority:a=!1,maxPriority:s=0,language:r="en"}=e,o=e=>{const t={en:{selectUpTo:"Select up to",options:"options",thenOrder:"and then order them",selectOptions:"Select options",cancel:"Cancel",confirm:"Confirm",selectOptionNumber:"Select option #",prioritized:"Prioritized",of:"of"},es:{selectUpTo:"Selecciona hasta",options:"opciones",thenOrder:"y luego ordénalas",selectOptions:"Seleccionar opciones",cancel:"Cancelar",confirm:"Confirmar",selectOptionNumber:"Selecciona la opción #",prioritized:"Has priorizado",of:"de"},fr:{selectUpTo:"Sélectionnez jusqu’à",options:"options",thenOrder:"puis ordonnez-les",selectOptions:"Sélectionner des options",cancel:"Annuler",confirm:"Confirmer",selectOptionNumber:"Sélectionnez l’option #",prioritized:"Priorisé",of:"sur"},de:{selectUpTo:"Wählen Sie bis zu",options:"Optionen",thenOrder:"und ordnen Sie sie anschließend",selectOptions:"Optionen auswählen",cancel:"Abbrechen",confirm:"Bestätigen",selectOptionNumber:"Option # auswählen",prioritized:"Priorisiert",of:"von"},it:{selectUpTo:"Seleziona fino a",options:"opzioni",thenOrder:"e poi ordinare",selectOptions:"Seleziona opzioni",cancel:"Annulla",confirm:"Conferma",selectOptionNumber:"Seleziona l’opzione #",prioritized:"Hai dato priorità",of:"di"},pt:{selectUpTo:"Selecione até",options:"opções",thenOrder:"e depois ordene",selectOptions:"Selecionar opções",cancel:"Cancelar",confirm:"Confirmar",selectOptionNumber:"Selecione a opção #",prioritized:"Priorizado",of:"de"},da:{selectUpTo:"Vælg op til",options:"muligheder",thenOrder:"og ordne dem derefter",selectOptions:"Vælg muligheder",cancel:"Annuller",confirm:"Bekræfte",selectOptionNumber:"Vælg mulighed #",prioritized:"Prioriteret",of:"af"},fi:{selectUpTo:"Valitse enintään",options:"vaihtoehtoa",thenOrder:"ja järjestä ne sitten",selectOptions:"Valitse vaihtoehdot",cancel:"Peruuta",confirm:"Vahvista",selectOptionNumber:"Valitse vaihtoehto #",prioritized:"Priorisoitu",of:" / "},sv:{selectUpTo:"Välj upp till",options:"alternativ",thenOrder:"och ordna dem sedan",selectOptions:"Välj alternativ",cancel:"Avbryt",confirm:"Bekräfta",selectOptionNumber:"Välj alternativ #",prioritized:"Prioriterat",of:"av"},no:{selectUpTo:"Velg opptil",options:"alternativer",thenOrder:"og ordne dem deretter",selectOptions:"Velg alternativer",cancel:"Avbryt",confirm:"Bekreft",selectOptionNumber:"Velg alternativ #",prioritized:"Prioritert",of:"av"}};return t[t[r]?r:"en"][e]},l=document.createElement("div");if(l.classList.add("magicfeedback-priority-list-container"),a&&s&&s>0){const e=[],a=document.createElement("div");a.classList.add("magicfeedback-priority-list-header");const r=document.createElement("div");r.classList.add("magicfeedback-priority-list-instruction"),r.textContent=`${o("selectUpTo")} ${s} ${o("options")} ${o("thenOrder")} (0/${s})`;const d=document.createElement("button");d.type="button",d.textContent=o("selectOptions"),d.classList.add("magicfeedback-button"),d.classList.add("magicfeedback-priority-list-open-btn"),a.appendChild(r),a.appendChild(d);const c=document.createElement("div");c.classList.add("magicfeedback-priority-list-reorder");const u=document.createElement("ul");u.classList.add("magicfeedback-priority-list-list"),c.appendChild(u);const p=()=>{u.innerHTML="",e.forEach(((t,n)=>{const a=document.createElement("li");a.classList.add("magicfeedback-priority-list-item");const s=document.createElement("input");s.classList.add("magicfeedback-input-magicfeedback-priority-list"),s.classList.add("magicfeedback-input"),s.type="hidden",s.id=`priority-list-${i}`,s.name=i,s.value=`${n+1}. ${t}`,a.appendChild(s);const r=document.createElement("label");r.classList.add("magicfeedback-priority-list-item-label"),r.textContent=`${n+1}. ${t}`,a.appendChild(r);const o=document.createElement("div");o.classList.add("magicfeedback-priority-list-arrows");const l=document.createElement("img");l.classList.add("magicfeedback-priority-list-arrow-up"),l.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",l.style.visibility=0===n?"hidden":"visible";const d=document.createElement("img");d.classList.add("magicfeedback-priority-list-arrow-down"),d.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",d.style.transform="rotate(180deg)",d.style.visibility=n===e.length-1?"hidden":"visible",l.addEventListener("click",(()=>{var i,n,o,c;const p=a.previousElementSibling;if(p){const m=Number(null===(i=s.value)||void 0===i?void 0:i.split(".")[0])-1;s.value=`${m}. ${t}`,r.textContent=`${m}. ${t}`,l.style.visibility=1===m?"hidden":"visible",d.style.visibility=m===e.length?"hidden":"visible";const h=p.querySelector(".magicfeedback-input-magicfeedback-priority-list"),f=p.querySelector(".magicfeedback-priority-list-item-label"),g=p.querySelector(".magicfeedback-priority-list-arrow-up"),v=p.querySelector(".magicfeedback-priority-list-arrow-down");if(h&&f&&g&&v){const t=Number(null===(n=h.value)||void 0===n?void 0:n.split(".")[0])+1;h.value=`${t}.${null===(o=f.textContent)||void 0===o?void 0:o.split(".")[1]}`,f.textContent=`${t}.${null===(c=f.textContent)||void 0===c?void 0:c.split(".")[1]}`,g.style.visibility=1===t?"hidden":"visible",v.style.visibility=t===e.length?"hidden":"visible"}u.insertBefore(a,p)}})),d.addEventListener("click",(()=>{var i,n,o;const c=a.nextElementSibling;if(c){const p=Number(null===(i=s.value)||void 0===i?void 0:i.split(".")[0])+1;s.value=`${p}. ${t}`,r.textContent=`${p}. ${t}`,l.style.visibility=1===p?"hidden":"visible",d.style.visibility=p===e.length?"hidden":"visible";const m=c.querySelector(".magicfeedback-input-magicfeedback-priority-list"),h=c.querySelector(".magicfeedback-priority-list-item-label"),f=c.querySelector(".magicfeedback-priority-list-arrow-up"),g=c.querySelector(".magicfeedback-priority-list-arrow-down");if(m&&h&&f&&g){const t=Number(m.value.split(".")[0])-1;m.value=`${t}.${null===(n=h.textContent)||void 0===n?void 0:n.split(".")[1]}`,h.textContent=`${t}.${null===(o=h.textContent)||void 0===o?void 0:o.split(".")[1]}`,f.style.visibility=1===t?"hidden":"visible",g.style.visibility=t===e.length?"hidden":"visible"}u.insertBefore(c,a)}})),o.appendChild(l),o.appendChild(d),a.appendChild(o),u.appendChild(a)}))},m=document.createElement("div");m.classList.add("magicfeedback-modal-backdrop"),m.style.position="fixed",m.style.top="0",m.style.left="0",m.style.width="100vw",m.style.height="100vh",m.style.background="rgba(0,0,0,0.4)",m.style.display="none",m.style.alignItems="center",m.style.justifyContent="center",m.style.zIndex="9999";const h=document.createElement("div");h.classList.add("magicfeedback-modal"),h.style.background="#fff",h.style.borderRadius="8px",h.style.boxShadow="0 8px 24px rgba(0,0,0,0.2)",h.style.maxWidth="520px",h.style.width="90%",h.style.maxHeight="80vh",h.style.overflow="auto",h.style.padding="16px",h.style.position="relative";const f=document.createElement("h5");f.classList.add("magicfeedback-modal-title");const g=()=>Math.min(e.length+1,s),v=()=>{f.textContent=`${o("selectOptionNumber")}${g()}`};v();const y=document.createElement("div");y.classList.add("magicfeedback-modal-list"),(n?[...t].sort((()=>Math.random()-.5)):[...t]).forEach((t=>{const n=document.createElement("label");n.classList.add("magicfeedback-modal-row");const a=document.createElement("input");a.type="checkbox",a.classList.add("magicfeedback-input"),a.name=`${i}-selection`,a.value=t;const l=document.createElement("span");l.textContent=t,a.addEventListener("change",(()=>{if(a.checked){if(e.length>=s)return a.checked=!1,n.classList.add("magicfeedback-warning"),void setTimeout((()=>{n.classList.remove("magicfeedback-warning")}),800);e.push(t)}else{const i=e.indexOf(t);-1!==i&&e.splice(i,1)}r.textContent=`${o("selectUpTo")} ${s} ${o("options")} ${o("thenOrder")} (${e.length}/${s})`,v(),k()})),n.appendChild(a),n.appendChild(l),y.appendChild(n)}));const b=document.createElement("div");b.classList.add("magicfeedback-modal-actions");const E=document.createElement("div");E.classList.add("magicfeedback-modal-counter");const k=()=>{const t=o("of");E.textContent=`${o("prioritized")} ${e.length} ${t} ${s}`};k();const A=document.createElement("button");A.type="button",A.classList.add("magicfeedback-modal-close"),A.setAttribute("aria-label",o("cancel")),A.title=o("cancel"),A.textContent="×",A.addEventListener("click",(()=>{m.style.display="none"}));const C=document.createElement("button");return C.type="button",C.textContent=o("confirm"),C.classList.add("magicfeedback-button"),C.classList.add("magicfeedback-button-primary"),C.addEventListener("click",(()=>{m.style.display="none",p()})),b.appendChild(E),b.appendChild(C),h.appendChild(A),h.appendChild(f),h.appendChild(y),h.appendChild(b),m.appendChild(h),d.addEventListener("click",(()=>{m.style.display="flex",v(),k()})),m.addEventListener("click",(e=>{e.target===m&&(m.style.display="none")})),l.appendChild(a),l.appendChild(c),l.appendChild(m),p(),l}const d=document.createElement("ul");d.classList.add("magicfeedback-priority-list-list");const c=n?[...t].sort((()=>Math.random()-.5)):[...t];return c.forEach(((e,t)=>{const n=document.createElement("li");n.classList.add("magicfeedback-priority-list-item"),n.style.display="flex",n.style.justifyContent="space-between",n.style.alignItems="center",n.style.margin="5px";const a=document.createElement("input");a.classList.add("magicfeedback-input-magicfeedback-priority-list"),a.classList.add("magicfeedback-input"),a.type="hidden",a.id=`priority-list-${i}`,a.name=i,a.value=`${t+1}. ${e}`,n.appendChild(a);const s=document.createElement("label");s.classList.add("magicfeedback-priority-list-item-label"),s.textContent=`${t+1}. ${e}`,n.appendChild(s);const r=document.createElement("div");r.style.display="flex",r.style.alignItems="center",r.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,i,r,u;const p=n.previousElementSibling;if(p){const m=Number(null===(t=a.value)||void 0===t?void 0:t.split(".")[0])-1;a.value=`${m}. ${e}`,s.textContent=`${m}. ${e}`,o.style.visibility=1===m?"hidden":"visible",l.style.visibility=m===c.length?"hidden":"visible";const h=p.querySelector(".magicfeedback-input-magicfeedback-priority-list"),f=p.querySelector(".magicfeedback-priority-list-item-label"),g=p.querySelector(".magicfeedback-priority-list-arrow-up"),v=p.querySelector(".magicfeedback-priority-list-arrow-down");if(h&&f&&g&&v){const e=Number(null===(i=h.value)||void 0===i?void 0:i.split(".")[0])+1;h.value=`${e}.${null===(r=f.textContent)||void 0===r?void 0:r.split(".")[1]}`,f.textContent=`${e}.${null===(u=f.textContent)||void 0===u?void 0:u.split(".")[1]}`,g.style.visibility=1===e?"hidden":"visible",v.style.visibility=e===c.length?"hidden":"visible"}d.insertBefore(n,p)}}));const l=document.createElement("img");l.classList.add("magicfeedback-priority-list-arrow-down"),l.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",l.style.width="20px",l.style.height="20px",l.style.cursor="pointer",l.style.margin="0 5px",l.style.color="#000",l.style.transform="rotate(180deg)",l.style.visibility=t===c.length-1?"hidden":"visible",l.addEventListener("click",(()=>{var t,i,r;const u=n.nextElementSibling;if(u){const p=Number(null===(t=a.value)||void 0===t?void 0:t.split(".")[0])+1;a.value=`${p}. ${e}`,s.textContent=`${p}. ${e}`,o.style.visibility=1===p?"hidden":"visible",l.style.visibility=p===c.length?"hidden":"visible";const m=u.querySelector(".magicfeedback-input-magicfeedback-priority-list"),h=u.querySelector(".magicfeedback-priority-list-item-label"),f=u.querySelector(".magicfeedback-priority-list-arrow-up"),g=u.querySelector(".magicfeedback-priority-list-arrow-down");if(m&&h&&f&&g){const e=Number(m.value.split(".")[0])-1;m.value=`${e}.${null===(i=h.textContent)||void 0===i?void 0:i.split(".")[1]}`,h.textContent=`${e}.${null===(r=h.textContent)||void 0===r?void 0:r.split(".")[1]}`,f.style.visibility=1===e?"hidden":"visible",g.style.visibility=e===c.length?"hidden":"visible"}d.insertBefore(u,n)}})),r.appendChild(o),r.appendChild(l),n.appendChild(r),d.appendChild(n)})),l.appendChild(d),l}({value:E,ref:y,randomPosition:O,limitPriority:(null==A?void 0:A.limitPriority)||!1,maxPriority:(null==A?void 0:A.maxPriority)||0,language:i||"en"});m.appendChild(te);break;case n.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:m=document.createElement("div"),h="magicfeedback-point-system";const ie=document.createElement("div");ie.classList.add("magicfeedback-point-system-container");const ne=document.createElement("ul");ne.classList.add("magicfeedback-point-system-list"),ne.style.padding="0";const ae=100,se=ae/E.length,re=document.createElement("div");re.classList.add("magicfeedback-error"),re.textContent=a.placeholder.pointsystemerror(i||"en"),re.style.color="#C70039",re.style.fontSize="14px",re.style.textAlign="right",re.style.width="100%",re.style.display="none";const oe=document.createElement("div");oe.classList.add("magicfeedback-point-system-total"),oe.textContent="0 / 100 %",oe.style.textAlign="right",oe.style.fontSize="15px",oe.style.marginTop="5px",E.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=y,s.id=`${e}`,s.type="number",s.min="0",s.max=`${ae}`,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 r=document.createElement("span");r.textContent="%",r.style.color="#000",s.addEventListener("input",(()=>{const e=ne.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>ae&&(s.value=`${se}%`,t-=Number(s.value));const i=document.getElementById("magicfeedback-submit");i&&(t<100?(oe.style.color="orange",i.setAttribute("disabled","true")):(re.style.display="none",oe.style.color="green",i.removeAttribute("disabled"))),oe.textContent=`${t} / 100 %`})),s.addEventListener("focus",(()=>{const e=document.getElementById("magicfeedback-submit");e&&(e.setAttribute("disabled","true"),e.addEventListener("pointerover",(()=>{const e=ne.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t<100&&(re.style.display="block")})))})),a.appendChild(s),a.appendChild(r),i.appendChild(a),ne.appendChild(i)})),ie.appendChild(ne),ie.appendChild(oe),ie.appendChild(re),m.appendChild(ie);break;case n.FEEDBACKAPPANSWERTYPE.INFO_PAGE:m=document.createElement("div"),h="magicfeedback-info-page";const le=document.createElement("div");le.classList.add("magicfeedback-info-message"),le.innerHTML=w,m.appendChild(le);break;case n.FEEDBACKAPPANSWERTYPE.UPLOAD_IMAGE:m=document.createElement("input"),m.type="file",m.accept="image/*",m.required=b,m.multiple=(null==A?void 0:A.multiple)||!1,m.maxLength=(null==A?void 0:A.maxFiles)||1,h="magicfeedback-upload-image";break;case n.FEEDBACKAPPANSWERTYPE.UPLOAD_FILE:m=document.createElement("input"),m.type="file",m.required=b,m.multiple=(null==A?void 0:A.multiple)||!1,m.maxLength=(null==A?void 0:A.maxFiles)||1,h="magicfeedback-upload-file";break;default:return C}m.id=`magicfeedback-${f}`,m.setAttribute("name",y),m.classList.add(h),(void 0!==k||null!==T)&&(m.value=T||k),["RADIO","MULTIPLECHOICE"].includes(v)||(m.classList.add("magicfeedback-input"),m.required=b);const I=document.createElement("label");I.setAttribute("for",`magicfeedback-${f}`),I.textContent=r(g,i),I.classList.add("magicfeedback-label");const D=document.createElement("label");if(D.textContent=r(null==A?void 0:A.subtitle,i),D.classList.add("magicfeedback-sublabel"),(null===(c=null==A?void 0:A.subtitleStyle)||void 0===c?void 0:c.includes("italic"))&&(D.style.fontStyle="italic"),(null===(u=null==A?void 0:A.subtitleStyle)||void 0===u?void 0:u.includes("bold"))&&(D.style.fontWeight="bold"),(null===(p=null==A?void 0:A.subtitleStyle)||void 0===p?void 0:p.includes("underline"))&&(D.style.textDecoration="underline"),["CONSENT"].includes(v))C.classList.add("magicfeedback-consent-container"),C.appendChild(m),C.appendChild(I),C.appendChild(D);else{if("slim"!==t&&(C.appendChild(I),C.appendChild(D),void 0!==(null==A?void 0:A.general)&&""!==(null==A?void 0:A.general))){const Le=document.createElement("img");Le.src=null==A?void 0:A.general,Le.classList.add("magicfeedback-image"),Le.style.maxWidth="auto",Le.style.height="400px",Le.style.margin="10px 0",C.appendChild(Le)}if("LONGTEXT"===v&&L>0){const Oe=document.createElement("div");if(Oe.classList.add("magicfeedback-counter"),Oe.textContent=`${m.value.length}/${L}`,Oe.style.textAlign="right",Oe.style.fontSize="15px",Oe.style.marginTop="5px",m.addEventListener("input",(()=>{Oe.textContent=`${m.value.length}/${L}`})),C.appendChild(m),C.appendChild(Oe),(null==A?void 0:A.extraOption)&&(null==A?void 0:A.extraOptionText)){const Se=document.createElement("div");Se.classList.add("magicfeedback-skip-container"),Se.classList.add("magicfeedback-checkbox-container"),Se.style.display="flex",Se.style.justifyContent="flex-start";const Pe=document.createElement("input");Pe.classList.add("magicfeedback-skip"),Pe.type="checkbox",Pe.id=`skip-${y}`,Pe.name=y,Pe.value="-",Pe.style.cursor="pointer";const Ne=document.createElement("label");Ne.htmlFor=`skip-${y}`,Ne.textContent=null==A?void 0:A.extraOptionText,Ne.style.fontSize="15px",Ne.style.cursor="pointer",Ne.style.margin="0 5px",Pe.addEventListener("click",(()=>{m.value="-",d&&d()})),Se.appendChild(Pe),Se.appendChild(Ne),C.appendChild(Se)}}else C.appendChild(m)}return C}(h,i,l,`${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 r=document.createElement("button");r.id="magicfeedback-submit",r.type="submit",r.classList.add("magicfeedback-submit"),r.textContent="MAGICSURVEY"===e?a||"Next":i||"Submit";const o=document.createElement("button");return o.id="magicfeedback-back",o.type="button",o.classList.add("magicfeedback-back"),o.textContent=n||"Back",o.addEventListener("click",t),o.addEventListener("click",(()=>{r.removeAttribute("disabled")})),"MAGICSURVEY"===e&&s.appendChild(o),s.appendChild(r),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}},313:function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function r(e){try{l(n.next(e))}catch(e){s(e)}}function o(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}l((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(945)),r=a(i(330)),o=i(857),l={Accept:"application/json","Magicfeedback-Sdk-Version":r.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+o.endpoints.sdk.app_info(t,i),{method:"GET",headers:l});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+o.endpoints.sdk.session(t),{method:"GET",headers:l});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+o.endpoints.sdk.app(t,i),{method:"GET",headers:l});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+o.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},l),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+o.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},l),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),""}}))}},256:(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)}}},330:e=>{"use strict";e.exports=JSON.parse('{"name":"@magicfeedback/native","version":"2.1.7-alpha.2","main":"./dist/magicfeedback-sdk.node.js","browser":"./dist/magicfeedback-sdk.browser.js","types":"./dist/types/src/index.d.ts","repository":{"type":"git","url":"git+ssh://git@github.com/MagicFeedback/magicfeedback-sdk.git"},"author":"farias@magicfeedback.io","license":"MIT","private":false,"scripts":{"dev":"vite","build":"webpack","build:watch":"webpack --watch --mode development","release":"npm publish --access public","release:beta":"npm publish --access public --tag beta","release:alpha":"npm publish --access public --tag alpha","test":"jest","test:watch":"jest --watchAll","coverage":"vitest run --coverage","publish:sdk":"bash publish.sh","publish:sdk:dry-run":"NPM_DRY_RUN=1 bash publish.sh"},"files":["dist"],"devDependencies":{"@babel/preset-typescript":"^7.22.5","@types/node":"^17.0.21","@types/webpack":"^5.28.0","@types/webpack-node-externals":"^2.5.3","c8":"^7.11.0","copy-webpack-plugin":"^11.0.0","jest":"^29.5.0","jest-environment-jsdom":"^29.5.0","jest-fetch-mock":"^3.0.3","nock":"^13.2.4","ts-jest":"^29.1.0","ts-loader":"^9.2.7","ts-node":"^10.7.0","typescript":"^4.6.2","vite":"^2.8.0","vite-plugin-dts":"^0.9.9","vitest":"^0.5.9","webpack":"^5.70.0","webpack-cli":"^4.9.2","webpack-node-externals":"^3.0.0"},"dependencies":{"cross-fetch":"^3.1.5","is-bundling-for-browser-or-node":"^1.1.1"},"description":"MagicFeedbackAI JavaScript Library for [MagicFeedback.io](https://magicfeedback.io/)","bugs":{"url":"https://github.com/MagicFeedback/magicfeedback-sdk/issues"},"homepage":"https://github.com/MagicFeedback/magicfeedback-sdk#readme","directories":{"example":"examples","test":"test"},"style":"./dist/styles/magicfeedback-default.css"}')}},t={},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}(156).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={945: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,a="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),s="FormData"in e,r="ArrayBuffer"in e;if(r)var o=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],l=ArrayBuffer.isView||function(e){return e&&o.indexOf(Object.prototype.toString.call(e))>-1};function d(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 m(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function h(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=h(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:a&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:s&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:i&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():r&&a&&(t=e)&&DataView.prototype.isPrototypeOf(t)?(this._bodyArrayBuffer=g(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):r&&(ArrayBuffer.prototype.isPrototypeOf(e)||l(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"))},a&&(this.blob=function(){var e=m(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?m(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(f)}),this.text=function(){var e,t,i,n=m(this);if(n)return n;if(this._bodyBlob)return e=this._bodyBlob,i=h(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)},s&&(this.formData=function(){return this.text().then(E)}),this.json=function(){return this.text().then(JSON.parse)},this}p.prototype.append=function(e,t){e=d(e),t=c(t);var i=this.map[e];this.map[e]=i?i+", "+t:t},p.prototype.delete=function(e){delete this.map[d(e)]},p.prototype.get=function(e){return e=d(e),this.has(e)?this.map[e]:null},p.prototype.has=function(e){return this.map.hasOwnProperty(d(e))},p.prototype.set=function(e,t){this.map[d(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 y=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function b(e,t){var i,n,a=(t=t||{}).body;if(e instanceof b){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new p(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,a||null==e._bodyInit||(a=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(),y.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)&&a)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(a)}function E(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var i=e.split("="),n=i.shift().replace(/\+/g," "),a=i.join("=").replace(/\+/g," ");t.append(decodeURIComponent(n),decodeURIComponent(a))}})),t}function k(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new p(t.headers),this.url=t.url||"",this._initBody(e)}b.prototype.clone=function(){return new b(this,{body:this._bodyInit})},v.call(b.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 A=[301,302,303,307,308];k.redirect=function(e,t){if(-1===A.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 C(e,i){return new Promise((function(n,s){var r=new b(e,i);if(r.signal&&r.signal.aborted)return s(new t.DOMException("Aborted","AbortError"));var o=new XMLHttpRequest;function l(){o.abort()}o.onload=function(){var e,t,i={status:o.status,statusText:o.statusText,headers:(e=o.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 a=i.join(":").trim();t.append(n,a)}})),t)};i.url="responseURL"in o?o.responseURL:i.headers.get("X-Request-URL");var a="response"in o?o.response:o.responseText;n(new k(a,i))},o.onerror=function(){s(new TypeError("Network request failed"))},o.ontimeout=function(){s(new TypeError("Network request failed"))},o.onabort=function(){s(new t.DOMException("Aborted","AbortError"))},o.open(r.method,r.url,!0),"include"===r.credentials?o.withCredentials=!0:"omit"===r.credentials&&(o.withCredentials=!1),"responseType"in o&&a&&(o.responseType="blob"),r.headers.forEach((function(e,t){o.setRequestHeader(t,e)})),r.signal&&(r.signal.addEventListener("abort",l),o.onreadystatechange=function(){4===o.readyState&&r.signal.removeEventListener("abort",l)}),o.send(void 0===r._bodyInit?null:r._bodyInit)}))}C.polyfill=!0,e.fetch||(e.fetch=C,e.Headers=p,e.Request=b,e.Response=k),t.Headers=p,t.Request=b,t.Response=k,t.fetch=C,Object.defineProperty(t,"__esModule",{value:!0})}({})}(n),n.fetch.ponyfill=!0,delete n.fetch.polyfill;var a=n;(t=a.fetch).default=a.fetch,t.fetch=a.fetch,t.Headers=a.Headers,t.Request=a.Request,t.Response=a.Response,e.exports=t},317:(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.deepdots.com/",t.HOST_API_URL_DEV="https://api-dev.deepdots.com/"},156: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 a=n(i(927));let s=null;s||(s=(0,a.default)()),t.default=s},927:function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function r(e){try{l(n.next(e))}catch(e){s(e)}}function o(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const a=i(57),s=i(665),r=i(256),o=i(313),l=i(317);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)?l.HOST_API_URL_DEV:l.HOST_API_URL),e.set("env",null==i?void 0:i.env),t=new r.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,a,s,r=!0,l,d){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:d,completed:r,id:l,feedback:s};try{const e=yield(0,o.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)}}}},79:(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}get(e){return this.items[e]}}},665:(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}}},57:function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function r(e){try{l(n.next(e))}catch(e){s(e)}}function o(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const a=i(558),s=i(256),r=i(313),o=i(213),l=i(217),d=i(700),c=i(591),u=i(79),p=i(636);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,customMetaData:[],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 l.PageGraph([]),this.progress=0,this.total=0,this.completed=!1,this.timeToCompleted=0}generate(e,t){var i,a,s,o,l,d,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,r.getForm)(this.url,this.appId,this.publicKey,this.log):yield(0,r.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===(o=n.pages)||void 0===o||o.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===(l=this.formData.pages)||void 0===l?void 0:l.length)||this.formatPages(),null===(d=this.formData.questions)||void 0===d||d.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,[],c.TransitionType.PAGE,(e.position+1).toString(),e.position.toString()),a=new d.Page(e.position.toString(),e.position,this.appId,[e],[n]);null===(i=null===(t=this.formData)||void 0===t?void 0:t.pages)||void 0===i||i.push(a)}));break;case"MAGICFORM":const t=new d.Page("1",1,this.appId,this.formData.questions,[]);this.formData.pages=[t]}}generateContainer(){let e=document.getElementById(this.selector);if(!e&&(e=document.getElementById("magicfeedback-container-"+this.appId),!e))throw new Error(`Element with ID '${this.selector}' not found.`);return e.classList.add("magicfeedback-container"),e.id="magicfeedback-container-"+this.appId,e.innerHTML="",e}generateForm(){var e,t,i,a;return n(this,void 0,void 0,(function*(){try{if(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 l.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 r=document.createElement("div");r.classList.add("magicfeedback-questions"),r.id="magicfeedback-questions-"+this.appId;const d=this.graph.getFirstPage();if(!d)throw new Error("No page found");if(this.total=this.graph.findMaxDepth(),d.elements=(0,o.renderQuestions)(d.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=d.elements)||void 0===i||i.forEach((e=>r.appendChild(e))),s.appendChild(r),this.history.enqueue(d),n.appendChild(s),this.progress=this.total-this.graph.findMaxDepth(d),this.formOptionsConfig.addButton){const e=(0,o.renderActions)(null===(a=this.formData)||void 0===a?void 0:a.identity,(()=>this.back()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);s.appendChild(e)}this.formOptionsConfig.addButton&&s.addEventListener("submit",(e=>{e.preventDefault(),this.send()})),this.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,o.renderStartMessage)(e,this.formOptionsConfig.addButton,this.formOptionsConfig.startButtonText,(()=>this.startForm()));t.appendChild(i),this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,formData:this.formData}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}))}getMetaData(){console.log("Generating meta data",this.formOptionsConfig.customMetaData),this.formOptionsConfig.customMetaData&&(this.feedback.metadata=[...this.feedback.metadata,...this.formOptionsConfig.customMetaData]),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&&![a.FEEDBACKAPPANSWERTYPE.CONSENT,a.FEEDBACKAPPANSWERTYPE.INFO_PAGE].includes(e.type)))){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),!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")}if(e.type===a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX){const i=this.feedback.answers.find((t=>t.key===e.ref));if(!i)throw this.log.err(`The matrix question ${e.ref} is required`),new Error("No response");const n=this.parseMatrixAnswerPre(i),a=Array.isArray(null==t?void 0:t.options)?t.options:[];if(a.length>0){if(a.find((e=>{const t=n.find((t=>t.key===e));return!t||!Array.isArray(t.value)||0===t.value.length})))throw this.log.err(`The matrix question ${e.ref} requires an answer in every row`),new Error("No response")}else if(0===n.length||n.some((e=>!Array.isArray(e.value)||0===e.value.length)))throw this.log.err(`The matrix question ${e.ref} requires an answer in every row`),new Error("No response")}}const r=yield this.pushAnswers(!1);if(!r)throw new Error("No response");this.id=r,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.`),this.feedback.answers=[],[];const t=this.history.back();if(!t){this.log.err("No page found");const t=e.querySelectorAll(".magicfeedback-input"),i=[],n={};return t.forEach((e=>{var t;const a=e,s=a.name;if(!s)return;const r=a.type;if(("radio"===r||"checkbox"===r)&&!a.checked)return;const o=a.value,l=a.classList[0];if((null==l?void 0:l.includes("magicfeedback-priority-list"))||(null===(t=a.id)||void 0===t?void 0:t.startsWith("priority-list-")))return n[s]||(n[s]=[]),void n[s].push(o);const d="magicfeedback-consent"===l?a.checked.toString():o;if(null==d)return;const c={key:s,value:[d]};i.push(c)})),Object.entries(n).forEach((([e,t])=>{const n=t.slice().sort(((e,t)=>Number(e.split(".")[0])-Number(t.split(".")[0])));i.push({key:e,value:n})})),this.feedback.answers=i,i}const i=[];let n=!1;const s=e.querySelectorAll(".magicfeedback-input"),o={};return s.forEach((e=>{const s=e,l=t.questions.find((e=>{var t;return null===(t=s.name)||void 0===t?void 0:t.includes(e.ref)})),d=s.type,c=s.classList[0],u={key:s.name,value:[]},p="magicfeedback-consent"===c?s.checked.toString():s.value;if(u.key&&""!==u.key)switch(null==l?void 0:l.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:""!==p&&("email"===d?(0,r.validateEmail)(p)?(this.feedback.profile.push({key:"email",value:[p]}),u.value.push(p),i.push(u)):(this.log.err("Invalid email"),n=!0):(u.value.push(p),i.push(u)));break;case a.FEEDBACKAPPANSWERTYPE.RADIO:case a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:case a.FEEDBACKAPPANSWERTYPE.BOOLEAN:s.checked&&(u.value.push(p),i.push(u));break;case a.FEEDBACKAPPANSWERTYPE.CONSENT:u.value.push(s.checked.toString()),i.push(u);break;case a.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:case a.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:case a.FEEDBACKAPPANSWERTYPE.RATING_STAR:s.checked&&(u.value.push(p),i.push(u));break;case a.FEEDBACKAPPANSWERTYPE.SELECT:""!==p&&(u.value.push(p),i.push(u));break;case a.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:"hidden"===d&&(o[u.key]||(o[u.key]=[]),o[u.key].push(p));case a.FEEDBACKAPPANSWERTYPE.UPLOAD_IMAGE:case a.FEEDBACKAPPANSWERTYPE.UPLOAD_FILE:}})),n?[]:(Object.entries(o).forEach((([e,t])=>{if(!t||0===t.length)return;const n=t.slice().sort(((e,t)=>Number(e.split(".")[0])-Number(t.split(".")[0])));i.push({key:e,value:n})})),this.feedback.answers=i,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,o.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,r.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,r.getFollowUpQuestion)(i,n,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e){var t,i,a;return n(this,void 0,void 0,(function*(){const n=this.history.back();if(!n)throw new Error("No page found");const s=n.getFollowupQuestions();if(0===(null==s?void 0:s.length))return void(yield this.renderNextQuestion(e,n));const r=[];for(const e of s){const t=n.questions.find((t=>t.ref===e));if(t){const e=yield this.callFollowUpQuestion(t);e&&r.push(e)}}if(0===r.length)return void(yield this.renderNextQuestion(e,n));const l=new d.Page(n.id,n.position,this.appId,r,n.edges),c=new p.PageNode(n.id,n.position,n.edges,l,r,!0);c.elements=(0,o.renderQuestions)(r,this.formOptionsConfig.questionFormat,null===(t=this.formData)||void 0===t?void 0:t.lang[0],null===(i=this.formData)||void 0===i?void 0:i.product,(()=>this.send())),this.history.enqueue(c),this.progress+=.5,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,s,r,l,d;return n(this,void 0,void 0,(function*(){let n=this.graph.getNextPage(t,this.feedback.answers);if(!n)return void this.finish();const u=n.edges.filter((e=>"PRECONDITIONAL"===e.typeCondition)).sort(((e,t)=>e.position<t.position?-1:e.position>t.position?1:0));if((null==u?void 0:u.length)>0){let t=null;const r=u.map((e=>e.questionRef));for(let e=this.history.size()-1;e>=0;e--){const n=this.history.get(e);if(n&&(t=null===(i=n.answers)||void 0===i?void 0:i.find((e=>r.includes(e.key))),t))break}let o=!u.some((e=>e.transition===c.TransitionType.ALLOW));if(t)for(const i of u){let r=!1;const l=null===(s=this.formData)||void 0===s?void 0:s.questions.find((e=>e.ref===i.questionRef)),d=Array.isArray(t.value)?t.value:[t.value],u=Array.isArray(i.value)?i.value:[i.value];if((null==l?void 0:l.type)===a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX)r=this.evaluateMatrixPreconditional(i,t);else switch(i.typeOperator){case"EQUAL":case"INQ":r=d.some((e=>u.includes(e)));break;case"NOEQUAL":case"NINQ":r=d.every((e=>!u.includes(e)));break;case"GREATER":r=d.some((e=>Number(e)>Number(u[0])));break;case"LESS":r=d.some((e=>Number(e)<Number(u[0])));break;case"GREATEREQUAL":r=d.some((e=>Number(e)>=Number(u[0])));break;case"LESSEQUAL":r=d.some((e=>Number(e)<=Number(u[0])))}if(r)switch(this.feedback.answers=[],i.transition){case c.TransitionType.NEXT:return void(n&&(yield this.renderNextQuestion(e,n)));case c.TransitionType.ALLOW:o=!0}}if(!o)return this.feedback.answers=[],void(n&&(yield this.renderNextQuestion(e,n)))}n.elements=(0,o.renderQuestions)(n.questions,this.formOptionsConfig.questionFormat,null===(r=this.formData)||void 0===r?void 0:r.lang[0],null===(l=this.formData)||void 0===l?void 0:l.product,(()=>this.send())),e.innerHTML="",null===(d=n.elements)||void 0===d||d.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}))}))}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"}))}))}previewQuestion(e,t,i){var n,a;const s=Array.isArray(t)?t:[t];if(!s||0===s.length)throw new Error("[MagicFeedback] No question provided for preview");const r=document.getElementById(e);if(!r)throw new Error(`[MagicFeedback] Element with ID '${e}' not found.`);const{format:l=this.formOptionsConfig.questionFormat||"standard",language:d=(null===(n=this.formData)||void 0===n?void 0:n.lang)&&this.formData.lang[0]||"en",product:c=(null===(a=this.formData)||void 0===a?void 0:a.product)||{customIcons:!1},clearContainer:u=!0,wrap:p=!0}=i||{};u&&(r.innerHTML="");let m=[];try{m=(0,o.renderQuestions)(s,l,d,c)}catch(e){throw this.log.err(e),e}let h=r;if(p){const e=document.createElement("div");e.classList.add("magicfeedback-preview-question"),h.appendChild(e),h=e}return m.forEach((e=>h.appendChild(e))),r}parseMatrixAnswerPre(e){if(!e||!e.value)return[];if(1===e.value.length&&"string"==typeof e.value[0]&&e.value[0].trim().startsWith("["))try{const t=JSON.parse(e.value[0]);if(Array.isArray(t))return t}catch(e){return[]}return Array.isArray(e.value)&&e.value.length>0&&"object"==typeof e.value[0]&&null!==e.value[0]&&"key"in e.value[0]?e.value:[]}evaluateMatrixPreconditional(e,t){const i=Array.isArray(e.value)?e.value:[e.value],n=new Set(e.option||[]),a=this.parseMatrixAnswerPre(t);if(!a.length)return!1;const s=n.size>0?a.filter((e=>n.has(e.key))):a;if(!s.length)return!1;switch(e.typeOperator){case"EQUAL":case"INQ":return s.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.includes(e)))));case"NOEQUAL":case"NINQ":return s.every((e=>(Array.isArray(e.value)?e.value:[e.value]).every((e=>!i.includes(e)))));case"GREATER":return s.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)>Number(t)))))));case"LESS":return s.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)<Number(t)))))));case"GREATEREQUAL":return s.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)>=Number(t)))))));case"LESSEQUAL":return s.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)<=Number(t)))))));default:return!1}}}},700:(e,t)=>{"use strict";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}}},217:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.PageGraph=void 0;const n=i(636),a=i(558),s=i(591);t.PageGraph=class{constructor(e){this.nodes=new Map,this.buildGraph(e)}buildGraph(e){e.forEach((e=>{var t;e.integrationPageRoutes&&(e.integrationPageRoutes=(null===(t=e.integrationPageRoutes)||void 0===t?void 0:t.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 i=new n.PageNode(e.id,e.position,e.integrationPageRoutes||[],e,e.integrationQuestions);this.nodes.set(i.id,i)}))}getNodeById(e){return this.nodes.get(e)}getNextEdgeByDefault(e){if(!e)return;const t=e.edges.find((e=>e.typeCondition===s.ConditionType.DIRECT));if(!t||![s.TransitionType.FINISH,s.TransitionType.REDIRECT].includes(t.transition)){if(t&&t.transitionDestiny)return t.transitionDestiny;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((i=>{const n=e.questions.find((e=>e.ref===i.questionRef)),r=null==t?void 0:t.filter((e=>e.key===i.questionRef));if("DIRECT"===i.typeCondition)return!0;if(!r||0===r.length)return!1;if((null==n?void 0:n.type)===a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX)return this.evaluateMatrixCondition(i,r);const o=Array.isArray(i.value)?i.value:[i.value];switch(i.typeOperator){case s.OperatorType.EQUAL:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.includes(e)))));case s.OperatorType.NOEQUAL:return r.every((e=>(Array.isArray(e.value)?e.value:[e.value]).every((e=>!o.includes(e)))));case s.OperatorType.GREATER:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.some((t=>Number(e)>Number(t)))))));case s.OperatorType.LESS:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.some((t=>Number(e)<Number(t)))))));case s.OperatorType.GREATEREQUAL:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.some((t=>Number(e)>=Number(t)))))));case s.OperatorType.LESSEQUAL:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.some((t=>Number(e)<=Number(t)))))));case s.OperatorType.INQ:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.includes(e)))));case s.OperatorType.NINQ:return r.every((e=>(Array.isArray(e.value)?e.value:[e.value]).every((e=>!o.includes(e)))));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=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.filter((e=>e.typeCondition!==s.ConditionType.PRECONDITIONAL))||[]],r=this.getNextEdgeByDefault(e);if(r){const i=this.getNodeById(r);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 a=this.getNodeById(e.transitionDestiny);if(a&&!t.has(a)){const e=i+1,s=new Set(t),r=this.DFSUtil(a,s,e);n=Math.max(n,r)}}return n}parseMatrixAnswer(e){if(!e||!e.value)return[];if(1===e.value.length&&"string"==typeof e.value[0]&&e.value[0].trim().startsWith("["))try{const t=JSON.parse(e.value[0]);if(Array.isArray(t))return t}catch(e){return[]}return Array.isArray(e.value)&&e.value.length>0&&"object"==typeof e.value[0]&&null!==e.value[0]&&"key"in e.value[0]?e.value:[]}evaluateMatrixCondition(e,t){const i=Array.isArray(e.value)?e.value:[e.value],n=new Set(e.option||[]),a=t[0],r=this.parseMatrixAnswer(a);if(!r.length)return!1;const o=n.size>0?r.filter((e=>n.has(e.key))):r;if(!o.length)return!1;switch(e.typeOperator){case s.OperatorType.EQUAL:case s.OperatorType.INQ:return o.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.includes(e)))));case s.OperatorType.NOEQUAL:case s.OperatorType.NINQ:return o.every((e=>(Array.isArray(e.value)?e.value:[e.value]).every((e=>!i.includes(e)))));case s.OperatorType.GREATER:return o.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)>Number(t)))))));case s.OperatorType.LESS:return o.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)<Number(t)))))));case s.OperatorType.GREATEREQUAL:return o.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)>=Number(t)))))));case s.OperatorType.LESSEQUAL:return o.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)<=Number(t)))))));default:return!1}}}},636:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.PageNode=void 0,t.PageNode=class{constructor(e,t,i,n,a,s=!1){this.answers=[],this.id=e,this.position=t,this.edges=i,this.data=n,this.questions=a.sort(((e,t)=>e.position-t.position)),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))}setAnswer(e){this.answers=e}}},591:(e,t)=>{"use strict";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",s.NEXT="NEXT",s.ALLOW="ALLOW",function(e){e.LOGICAL="LOGICAL",e.DIRECT="DIRECT",e.PRECONDITIONAL="PRECONDITIONAL"}(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,r,o,l,d,c,u){this.id=e,this.questionRef=t,this.typeCondition=d||i.LOGICAL,this.typeOperator=a,this.value=s||[],this.transition=r,this.transitionDestiny=o,this.status=n.ACTIVE,this.generatedAt=new Date,this.updatedAt=new Date,this.integrationPageId=l,this.position=c||0,this.option=u||[]}}},558:(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={}))},857:(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"}}},784:(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 % হতে হবে"}}}},213:(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(558),a=i(784),s="https://survey-dev.magicfeedback.io/assets/emojis";function r(e,t){return e?"object"==typeof e?e[t]||e.en:e:""}function o(e,t,i,n,a,s=!0,r="ltr",o="row"){const l=document.createElement("div");l.classList.add("magicfeedback-rating-placeholder"),l.style.display="flex",l.style.flexDirection=o,l.style.alignItems="center",l.style.justifyContent="space-between",l.style.width=a?`calc(100% - (100% / ${t+1}))`:"100%",l.style.marginRight="auto",s&&window.innerWidth<600&&(l.style.flexDirection="column");const d=document.createElement("span");d.textContent=i,d.classList.add("magicfeedback-rating-placeholder-value"),d.style.fontSize="15px",d.style.textAlign="ltr"===r?"left":"right",d.style.width="50%",(s&&window.innerWidth<600||"column"===o)&&(d.textContent=`${e} = ${i}`,d.style.width="100%",d.style.textAlign="left",d.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"===r?"right":"left",c.style.width="50%",(s&&window.innerWidth<600||"column"===o)&&(c.textContent=`${t} = ${n}`,c.style.width="100%",c.style.textAlign="left",c.style.marginBottom="5px"),"ltr"===r?(i&&l.appendChild(d),n&&l.appendChild(c)):(n&&l.appendChild(c),i&&l.appendChild(d)),l}t.renderQuestions=function e(t,i="standard",l="en",d={customIcons:!1},c){if(!t)throw new Error("[MagicFeedback] No questions provided");const u=[],{customIcons:p,id:m}=d;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=r(h.title,l),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,l,d,c).forEach((e=>{t.appendChild(e)})),u.push(t)}else{const e=function(e,t,i,l,d){var c,u,p;let m,h,{id:f,title:g,type:v,ref:y,require:b,value:E,defaultValue:k,assets:A}=e,C=document.createElement("div");C.classList.add("magicfeedback-div");const x=window.innerWidth<600,w="slim"===t?r(g,i):null==A?void 0:A.placeholder,T=(N=y,new URLSearchParams(window.location.search).get(N)),L=(null==A?void 0:A.maxCharacters)||0,O=void 0!==(null==A?void 0:A.randomPosition)&&(null==A?void 0:A.randomPosition),P=(null==A?void 0:A.direction)||"row",S=(null==A?void 0:A.order)||"ltr";var N;switch(v){case n.FEEDBACKAPPANSWERTYPE.TEXT:m=document.createElement("input"),m.type="text",m.placeholder=w||a.placeholder.answer(i||"en"),T&&(m.value=T),m.addEventListener("keyup",(e=>{e.preventDefault(),console.log(e.key,e),"Enter"===e.key&&d&&d()})),h="magicfeedback-text";break;case n.FEEDBACKAPPANSWERTYPE.LONGTEXT:m=document.createElement("textarea"),m.rows=3,L>0&&(m.maxLength=L),m.placeholder=w||a.placeholder.answer(i||"en"),T&&(m.value=T),h="magicfeedback-longtext";break;case n.FEEDBACKAPPANSWERTYPE.NUMBER:m=document.createElement("input"),m.type="number",m.placeholder="slim"===t?r(g,i):a.placeholder.number(i||"en"),h="magicfeedback-number",E.length&&(E.sort(((e,t)=>Number(e)-Number(t))),m.max=E[E.length-1],m.min=E[0],m.value=E[0]),T&&!isNaN(Number(T))&&(m.value=T);break;case n.FEEDBACKAPPANSWERTYPE.RADIO:case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:m=document.createElement("div"),h="magicfeedback-"+("MULTIPLECHOICE"===v?"checkbox":"radio");let $=E||[];O&&($=$.sort((()=>Math.random()-.5)));let R=(null==A?void 0:A.exclusiveAnswers)||[];(null==A?void 0:A.extraOption)&&(R=R.filter((e=>e!==A.extraOptionText))),R.length>0&&(null==R||R.forEach((e=>{$.includes(e)||$.push(e)}))),(null==A?void 0:A.extraOption)&&!$.includes(null==A?void 0:A.extraOptionText)&&$.push(null==A?void 0:A.extraOptionText),$.forEach(((e,t)=>{const s=document.createElement("div");s.classList.add(`magicfeedback-${"MULTIPLECHOICE"===v?"checkbox":"radio"}-container`);const r=document.createElement("label"),o=document.createElement("input");if(o.id=`rating-${y}-${t}`,o.type="MULTIPLECHOICE"===v?"checkbox":"radio",o.name=y,o.value=e,o.classList.add(h),o.classList.add("magicfeedback-input"),v===n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE&&(null==A?void 0:A.maxOptions)&&(null==A?void 0:A.maxOptions)>0&&o.addEventListener("change",(()=>{document.querySelectorAll(`input[name="${y}"]:checked`).length>(null==A?void 0:A.maxOptions)&&(o.checked=!1)})),v===n.FEEDBACKAPPANSWERTYPE.RADIO&&d&&(!(null==A?void 0:A.extraOptionText)||(null==A?void 0:A.extraOptionText)&&e!==(null==A?void 0:A.extraOptionText))&&o.addEventListener("change",(()=>{d()})),e!==k&&e!==T||(o.checked=!0),r.textContent=e,r.htmlFor=`rating-${y}-${t}`,o.addEventListener("change",(t=>{const i=document.getElementById(`extra-option-${y}`);t.target.checked&&R.includes(e)?(console.log("exclusiveAnswers",R,e),$.forEach((t=>{t!==e&&(document.querySelector(`input[value="${t}"]`).checked=!1)})),i&&(i.style.display="none")):R.forEach((t=>{t!==e&&(document.querySelector(`input[value="${t}"]`).checked=!1)})),(null==A?void 0:A.extraOption)&&e===(null==A?void 0:A.extraOptionText)&&i&&(i.style.display=t.target.checked?"block":"none")})),s.appendChild(o),s.appendChild(r),m.appendChild(s),(null==A?void 0:A.extraOption)&&e===(null==A?void 0:A.extraOptionText)){const e=document.createElement("input");e.type="text",e.placeholder=(null==A?void 0:A.extraOptionPlaceholder)||a.placeholder.answer(i||"en"),e.classList.add("magicfeedback-extra-option"),e.classList.add("magicfeedback-input"),e.id=`extra-option-${y}`,e.name=`extra-option-${y}`,e.style.display="none",m.appendChild(e)}}));break;case n.FEEDBACKAPPANSWERTYPE.BOOLEAN:m=document.createElement("div"),h="magicfeedback-radio";const _=document.createElement("div");_.classList.add("magicfeedback-boolean-container"),_.style.display="flex",_.style.flexDirection="row",_.style.justifyContent="space-between",_.style.width="70%",_.style.margin="auto",((null==A?void 0:A.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-${y}-${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-${y}-${t}`,n.textContent=e,n.style.margin="0",n.style.padding="0";const a=document.createElement("input");a.id=`rating-${y}-${t}`,a.type="radio",a.name=y,a.value=["Yes","No"][t],a.classList.add(h),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",(()=>{d&&d()})),T&&T.toLowerCase()===a.value.toLowerCase()&&(a.checked=!0),i.appendChild(a),i.appendChild(n),_.appendChild(i)})),m.appendChild(_);break;case n.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:m=document.createElement("div"),h="magicfeedback-rating";const F=document.createElement("div");F.classList.add("magicfeedback-rating-container");const M=(null==A?void 0:A.max)?Number(null==A?void 0:A.max):5,B=(null==A?void 0:A.min)?Number(null==A?void 0:A.min):1,U=o(B,M,null==A?void 0:A.minPlaceholder,null==A?void 0:A.maxPlaceholder,null==A?void 0:A.extraOption);for(let de=B;de<=M;de++){const ce=document.createElement("div");ce.classList.add("magicfeedback-rating-option");const ue=document.createElement("label");ue.htmlFor=`rating-${y}-${de}`,ue.classList.add("magicfeedback-rating-option-label-container");const pe=document.createElement("label");pe.htmlFor=`rating-${y}-${de}`,pe.textContent=de.toString();const me=document.createElement("img");if(me.alt=`face-${y}-${de}`,me.className=`rating-image${de}`,0===B&&10===M)me.src=`${l}/${de}.svg`,me.onerror=()=>me.src=`${s}/${de}.svg`;else if(1===B&&5===M)switch(de){case 1:me.src=`${l}/1.svg`,me.onerror=()=>me.src=`${s}/1.svg`;break;case 2:me.src=`${l}/2.svg`,me.onerror=()=>me.src=`${s}/2.svg`;break;case 3:me.src=`${l}/6.svg`,me.onerror=()=>me.src=`${s}/6.svg`;break;case 4:me.src=`${l}/9.svg`,me.onerror=()=>me.src=`${s}/9.svg`;break;case 5:me.src=`${l}/10.svg`,me.onerror=()=>me.src=`${s}/10.svg`}else{const fe=Math.round(10/(M-B)*(de-B));me.src=`${l}/${fe}.svg`,me.onerror=()=>me.src=`${s}/${fe}.svg`}const he=document.createElement("input");he.id=`rating-${y}-${de}`,he.type="radio",he.name=y,he.value=de.toString(),he.classList.add(h),he.classList.add("magicfeedback-input"),d&&he.addEventListener("change",(()=>{d()})),T&&T===he.value&&(he.checked=!0),ue.appendChild(he),ue.appendChild(me),ue.appendChild(pe),ce.appendChild(ue),F.appendChild(ce)}if((null==A?void 0:A.extraOption)&&(null==A?void 0:A.extraOptionText)){const ge=document.createElement("div");ge.classList.add("magicfeedback-rating-option");const ve=document.createElement("label");ve.htmlFor=`rating-${y}-extra`,ve.classList.add("magicfeedback-rating-option-label-container");const ye=document.createElement("label");ye.htmlFor=`rating-${y}-extra`,ye.textContent=null==A?void 0:A.extraOptionText;const be=document.createElement("img");be.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",be.alt=`face-${y}-extra`,be.className="magicfeedback-rating-image-extra";const Ee=document.createElement("input");Ee.id=`rating-${y}-extra`,Ee.type="radio",Ee.name=y,Ee.value="-",Ee.classList.add(h),Ee.classList.add("magicfeedback-input"),d&&Ee.addEventListener("change",(()=>{d()})),ve.appendChild(Ee),ve.appendChild(be),ve.appendChild(ye),ge.appendChild(ve),F.appendChild(ge)}m.appendChild(U),m.appendChild(F);break;case n.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:h="magicfeedback-rating-number",m=function(e,t,i,n,a,s,r,o){const l=document.createElement("div");l.classList.add("magicfeedback-rating-number");const d="ltr"===i?n:`${n}-reverse`,c=document.createElement("div");c.classList.add("magicfeedback-rating-number-container"),c.classList.add(`magicfeedback-rating-number-container-${i}`),c.classList.add(`magicfeedback-rating-number-container-${n}`),c.style.display="flex",c.style.flexDirection=d,c.setAttribute("role","radiogroup"),c.setAttribute("aria-label",(null==t?void 0:t.ariaLabel)||"Rating");const u=(null==t?void 0:t.max)?Number(null==t?void 0:t.max):10,p=(null==t?void 0:t.min)?Number(null==t?void 0:t.min):0,m=(null==t?void 0:t.numberPlaceholders)||null,h=!(a||"column"===n);for(let i=p;i<=u;i++){const l=document.createElement("div");l.classList.add("magicfeedback-rating-number-option"),l.classList.add(`magicfeedback-rating-number-option-${n}`);const d=document.createElement("label");if(d.htmlFor=`rating-${e}-${i}`,d.classList.add("magicfeedback-rating-number-option-label-container"),h&&(d.style.position="relative",d.style.overflow="visible"),h){const e=document.createElement("span");e.classList.add("magicfeedback-rating-number-cap"),e.classList.add("magicfeedback-rating-placeholder-value"),e.style.fontSize="14px",e.style.whiteSpace="nowrap",e.style.wordBreak="normal",i===p&&(null==t?void 0:t.minPlaceholder)?(e.textContent=t.minPlaceholder,e.dataset.capType="min"):i===u&&(null==t?void 0:t.maxPlaceholder)?(e.textContent=t.maxPlaceholder,e.dataset.capType="max"):e.dataset.capType="mid",d.appendChild(e)}let f=i.toString();h?m&&m[i]&&!a&&(d.title=m[i]):m&&m[i]?f+=` = ${m[i]}`:i===p&&(null==t?void 0:t.minPlaceholder)?f+=` = ${null==t?void 0:t.minPlaceholder}`:i===u&&(null==t?void 0:t.maxPlaceholder)&&(f+=` = ${null==t?void 0:t.maxPlaceholder}`);const g=document.createElement("input");g.id=`rating-${e}-${i}`,g.type="radio",g.name=e,g.value=i.toString(),g.classList.add(s),g.classList.add("magicfeedback-input"),g.setAttribute("aria-label",`${i}`),r&&g.addEventListener("change",(()=>r())),o&&o===g.value&&(g.checked=!0);const v=document.createElement("label");v.htmlFor=`rating-${e}-${i}`,v.textContent=f,v.classList.add("magicfeedback-rating-number-value"),d.appendChild(g),d.appendChild(v),l.appendChild(d),c.appendChild(l)}if((null==t?void 0:t.extraOption)&&(null==t?void 0:t.extraOptionText)){const n=document.createElement("div");n.classList.add("magicfeedback-rating-number-option");const a=document.createElement("label");if(a.htmlFor=`rating-${e}-extra`,a.classList.add("magicfeedback-rating-number-option-label-container"),h&&(a.style.position="relative",a.style.overflow="visible"),h){const e=document.createElement("span");e.classList.add("magicfeedback-rating-number-cap"),e.dataset.capType="extra",e.style.fontSize="12px",e.style.whiteSpace="nowrap",e.style.wordBreak="normal",a.appendChild(e)}const o=document.createElement("input");o.id=`rating-${e}-extra`,o.type="radio",o.name=e,o.value="-",o.classList.add(s),o.classList.add("magicfeedback-input"),o.setAttribute("aria-label",null==t?void 0:t.extraOptionText),r&&o.addEventListener("change",(()=>r()));const l=document.createElement("label");l.htmlFor=`rating-${e}-extra`,l.textContent=null==t?void 0:t.extraOptionText,l.classList.add("magicfeedback-rating-number-value"),a.appendChild(o),a.appendChild(l),n.appendChild(a),"ltr"===i?c.appendChild(n):c.insertBefore(n,c.firstChild)}return l.appendChild(c),h&&requestAnimationFrame((()=>{const e=Array.from(c.querySelectorAll(".magicfeedback-rating-number-cap"));if(0===e.length)return;let t=0;e.forEach((e=>{var i;if(null===(i=e.textContent)||void 0===i?void 0:i.trim()){const i=e.getBoundingClientRect().height||0;i>t&&(t=i)}})),c.style.position="relative",c.style.paddingTop=`${0===t?"42":t+6}px`,e.forEach((e=>{const n=e.getBoundingClientRect().height||0;console.log(t,n,6),e.style.position="absolute",e.style.top=`-${0===t?"42":t+n}px`,e.style.zIndex="1",e.style.pointerEvents="none",e.style.padding="0",e.style.boxSizing="border-box",e.style.whiteSpace="nowrap",e.style.wordBreak="normal",e.style.maxWidth="none",e.style.width="max-content";const a=e.dataset.capType;"min"===a?("ltr"===i?(e.style.left="10px",e.style.textAlign="left"):(e.style.right="10px",e.style.textAlign="right"),e.style.transform="none"):"max"===a?("ltr"===i?(e.style.right="10px",e.style.textAlign="right"):(e.style.left="10px",e.style.textAlign="left"),e.style.transform="none"):(e.style.left="50%",e.style.transform="translateX(-50%)",e.style.textAlign="center")})),c.style.overflow="visible"})),l}(y,A,S,P,x,h,d,T);break;case n.FEEDBACKAPPANSWERTYPE.RATING_STAR:m=document.createElement("div"),h="magicfeedback-rating-star";const q=function(e,t,i,n=()=>{},a){const s="magicfeedback-rating-star-selected",r=document.createElement("div");r.classList.add("magicfeedback-rating-star-container"),r.style.maxWidth="300px",r.style.margin="auto",r.dataset.originalSelection="0";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"),a&&a===o.value&&(o.checked=!0),o.addEventListener("change",(()=>{const e=r.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);r.dataset.originalSelection=o.value,n&&n()})),i.appendChild(o);const l=document.createElement("label");l.htmlFor=`rating-${e}-${t}`,l.classList.add("rating__star"),l.textContent="★",l.style.fontSize="40px",l.style.color="#CCCCCC",l.style.cursor="pointer",l.addEventListener("mouseenter",(()=>{const e=r.querySelectorAll(".rating__star"),i=t-1;e.forEach(((e,t)=>{t<=i?e.classList.contains(s)||e.classList.add(s):e.classList.contains(s)&&e.classList.remove(s)}))})),l.addEventListener("mouseleave",(()=>{const e=Number(r.dataset.originalSelection||"0");r.querySelectorAll(".rating__star").forEach(((t,i)=>{i<e?t.classList.contains(s)||t.classList.add(s):t.classList.contains(s)&&t.classList.remove(s)}))})),i.appendChild(l),r.appendChild(i)}return r.appendChild(o(1,5,t,i,!1,!1)),r}(y,null==A?void 0:A.minPlaceholder,null==A?void 0:A.maxPlaceholder,d,T);m.appendChild(q);break;case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:m=document.createElement("div"),h="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 W=E.length;let Q=1,K=1;if(window.innerWidth<600)Q=1,K=W;else switch(W){case 1:case 2:case 3:Q=W,K=1;break;case 4:case 5:case 6:K=2,Q=Math.ceil(W/K);break;case 7:case 8:case 9:K=3,Q=Math.ceil(W/K);break;default:K=4,Q=Math.ceil(W/K)}const G=void 0!==(null==A?void 0:A.addTitle)&&(null==A?void 0:A.addTitle),Y=void 0!==(null==A?void 0:A.multiOption)&&(null==A?void 0:A.multiOption),z=void 0!==(null==A?void 0:A.extraOption)&&(null==A?void 0:A.extraOption);function H(e){try{const{position:t,url:i,value:n}=e,a=document.createElement("label");a.classList.add("magicfeedback-multiple-choice-image-option"),a.style.width=`calc( ${100/Q}% - 10px)`,a.style.height=`calc( ${100/K}% - 10px)`,a.style.margin="5px";const s=document.createElement("label");s.htmlFor=`rating-${y}-${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 r=document.createElement("label");r.textContent=n,r.classList.add("magicfeedback-multiple-choice-image-label");const o=document.createElement("input");o.id=`rating-${y}-${t}`,o.type=Y?"checkbox":"radio",o.name=y,o.value=n,o.style.position="absolute",o.style.opacity="0",o.style.width="0",o.style.height="0",o.classList.add("magicfeedback-input"),T&&T===o.value&&(o.checked=!0),!Y&&d&&o.addEventListener("change",(()=>{console.log("send"),d()}));const l=document.createElement("img");l.classList.add("magicfeedback-multiple-choice-image-image"),l.src=i,l.style.cursor="pointer",l.style.backgroundSize="cover",l.style.backgroundPosition="center",l.style.width="100%",l.style.height="100%",l.style.objectFit="cover",l.style.margin="auto",s.appendChild(o),s.appendChild(l),G&&s.appendChild(r),a.appendChild(s),j.appendChild(a)}catch(e){console.error(e)}}O&&(E=E.sort((()=>Math.random()-.5))),E.forEach((e=>H(JSON.parse(e)))),z&&(null==A?void 0:A.extraOptionValue)&&(null==A?void 0:A.extraOptionValue.length)>0&&H(null==A?void 0:A.extraOptionValue[0]),m.appendChild(j);break;case n.FEEDBACKAPPANSWERTYPE.SELECT:m=document.createElement("select"),h="magicfeedback-select";const V=document.createElement("option");V.value="",V.text="slim"===t?r(g,i):k||"Select an option",V.disabled=!0,V.selected=!0,m.appendChild(V),E.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,m.appendChild(t)})),T&&E.includes(T)&&(m.value=T),d&&m.addEventListener("change",(()=>{d()}));break;case n.FEEDBACKAPPANSWERTYPE.DATE:m=document.createElement("input"),m.type="date",m.required=b,m.placeholder=w||a.placeholder.date(i||"en"),h="magicfeedback-date",T&&(m.value=T);break;case n.FEEDBACKAPPANSWERTYPE.CONSENT:m=document.createElement("input"),h="magicfeedback-consent",m.type="checkbox",m.id=`magicfeedback-${f}`,m.name=y,m.value="true",m.required=b,m.classList.add("magicfeedback-consent"),m.classList.add("magicfeedback-input"),T&&E.includes(T)&&(m.checked=!0),d&&m.addEventListener("change",(()=>{d()}));break;case n.FEEDBACKAPPANSWERTYPE.EMAIL:m=document.createElement("input"),m.type="email",m.required=b,m.placeholder=w||"you@example.com",h="magicfeedback-email",T&&(m.value=T);break;case n.FEEDBACKAPPANSWERTYPE.PASSWORD:m=document.createElement("input"),m.type="password",m.required=b,m.placeholder=w||a.placeholder.password(i||"en"),h="magicfeedback-password",T&&(m.value=T);break;case n.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:m=document.createElement("div"),h="magicfeedback-multi-question-matrix";const X=document.createElement("div");X.classList.add("magicfeedback-multi-question-matrix-container");let J=(null==A?void 0:A.options)||[],Z=[...E],ee=[];if(O&&(J=null==J?void 0:J.sort((()=>Math.random()-.5)),Z=[...Z].sort((()=>Math.random()-.5))),(null==A?void 0:A.exclusiveAnswers)&&(ee=null==A?void 0:A.exclusiveAnswers,null==ee||ee.forEach((e=>{Z.includes(e)||Z.push(e)}))),window.innerWidth<600){const ke=document.createElement("div");ke.classList.add("magicfeedback-multi-question-matrix-list"),null==J||J.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),Z.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=`${y}-${e}-${i}`,s.type="radio",s.name=`${y}-${e}`,s.value=i,s.classList.add("magicfeedback-input"),a.textContent=i,a.htmlFor=`${y}-${e}-${i}`,n.appendChild(s),n.appendChild(a),t.appendChild(n)})),ke.appendChild(t)})),X.appendChild(ke)}else{const Ae=document.createElement("table");Ae.classList.add("magicfeedback-multi-question-matrix-table");const Ce=document.createElement("thead");Ce.classList.add("magicfeedback-multi-question-matrix-header"),Ce.style.paddingBottom="15px";const xe=document.createElement("tr"),we=document.createElement("th");xe.appendChild(we),Z.forEach((e=>{const t=document.createElement("th");t.textContent=e,xe.appendChild(t)})),Ce.appendChild(xe),Ae.appendChild(Ce);const Te=document.createElement("tbody");null==J||J.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",i.style.padding="10px";const n=document.createElement("label");n.classList.add("magicfeedback-multi-question-matrix-label"),n.textContent=e,i.appendChild(n),t.appendChild(i),Z.forEach((i=>{const n=document.createElement("td"),a=document.createElement("input");a.type="radio",a.name=`${y}-${e}`,a.value=i,a.id=`${y}-${e}-${i}`,a.classList.add("magicfeedback-input"),n.appendChild(a),t.appendChild(n)})),Te.appendChild(t)})),Ae.appendChild(Te),X.appendChild(Ae)}m.appendChild(X);break;case n.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:m=document.createElement("div"),h="magicfeedback-priority-list";const te=function(e){const{value:t,ref:i,randomPosition:n=!1,limitPriority:a=!1,maxPriority:s=0,language:r="en"}=e,o=e=>{const t={en:{selectUpTo:"Select up to",options:"options",thenOrder:"and then order them",selectOptions:"Select options",cancel:"Cancel",confirm:"Confirm",selectOptionNumber:"Select option #",prioritized:"Prioritized",of:"of"},es:{selectUpTo:"Selecciona hasta",options:"opciones",thenOrder:"y luego ordénalas",selectOptions:"Seleccionar opciones",cancel:"Cancelar",confirm:"Confirmar",selectOptionNumber:"Selecciona la opción #",prioritized:"Has priorizado",of:"de"},fr:{selectUpTo:"Sélectionnez jusqu’à",options:"options",thenOrder:"puis ordonnez-les",selectOptions:"Sélectionner des options",cancel:"Annuler",confirm:"Confirmer",selectOptionNumber:"Sélectionnez l’option #",prioritized:"Priorisé",of:"sur"},de:{selectUpTo:"Wählen Sie bis zu",options:"Optionen",thenOrder:"und ordnen Sie sie anschließend",selectOptions:"Optionen auswählen",cancel:"Abbrechen",confirm:"Bestätigen",selectOptionNumber:"Option # auswählen",prioritized:"Priorisiert",of:"von"},it:{selectUpTo:"Seleziona fino a",options:"opzioni",thenOrder:"e poi ordinare",selectOptions:"Seleziona opzioni",cancel:"Annulla",confirm:"Conferma",selectOptionNumber:"Seleziona l’opzione #",prioritized:"Hai dato priorità",of:"di"},pt:{selectUpTo:"Selecione até",options:"opções",thenOrder:"e depois ordene",selectOptions:"Selecionar opções",cancel:"Cancelar",confirm:"Confirmar",selectOptionNumber:"Selecione a opção #",prioritized:"Priorizado",of:"de"},da:{selectUpTo:"Vælg op til",options:"muligheder.",thenOrder:"Du kan omrangere dem hvis nødvendigt efterfølgende",selectOptions:"Foretag valg til prioritering",cancel:"Annuller",confirm:"Bekræft",selectOptionNumber:"Prioritér dit valg #",prioritized:"Prioriteret",of:"af"},fi:{selectUpTo:"Valitse enintään",options:"vaihtoehtoa",thenOrder:"ja järjestä ne sitten",selectOptions:"Valitse vaihtoehdot",cancel:"Peruuta",confirm:"Vahvista",selectOptionNumber:"Valitse vaihtoehto #",prioritized:"Priorisoitu",of:" / "},sv:{selectUpTo:"Välj upp till",options:"alternativ",thenOrder:"och ordna dem sedan",selectOptions:"Välj alternativ",cancel:"Avbryt",confirm:"Bekräfta",selectOptionNumber:"Välj alternativ #",prioritized:"Prioriterat",of:"av"},no:{selectUpTo:"Velg opptil",options:"alternativer",thenOrder:"og ordne dem deretter",selectOptions:"Velg alternativer",cancel:"Avbryt",confirm:"Bekreft",selectOptionNumber:"Velg alternativ #",prioritized:"Prioritert",of:"av"}};return t[t[r]?r:"en"][e]},l=document.createElement("div");if(l.classList.add("magicfeedback-priority-list-container"),a&&s&&s>0){const e=[],a=document.createElement("div");a.classList.add("magicfeedback-priority-list-header");const r=document.createElement("div");r.classList.add("magicfeedback-priority-list-instruction"),r.textContent=`${o("selectUpTo")} ${s} ${o("options")} ${o("thenOrder")} (0/${s})`;const d=document.createElement("button");d.type="button",d.textContent=o("selectOptions"),d.classList.add("magicfeedback-button"),d.classList.add("magicfeedback-priority-list-open-btn"),a.appendChild(r),a.appendChild(d);const c=document.createElement("div");c.classList.add("magicfeedback-priority-list-reorder");const u=document.createElement("ul");u.classList.add("magicfeedback-priority-list-list"),c.appendChild(u);const p=()=>{u.innerHTML="",e.forEach(((t,n)=>{const a=document.createElement("li");a.classList.add("magicfeedback-priority-list-item");const s=document.createElement("input");s.classList.add("magicfeedback-input-magicfeedback-priority-list"),s.classList.add("magicfeedback-input"),s.type="hidden",s.id=`priority-list-${i}`,s.name=i,s.value=`${n+1}. ${t}`,a.appendChild(s);const r=document.createElement("label");r.classList.add("magicfeedback-priority-list-item-label"),r.textContent=`${n+1}. ${t}`,a.appendChild(r);const o=document.createElement("div");o.classList.add("magicfeedback-priority-list-arrows");const l=document.createElement("img");l.classList.add("magicfeedback-priority-list-arrow-up"),l.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",l.style.visibility=0===n?"hidden":"visible";const d=document.createElement("img");d.classList.add("magicfeedback-priority-list-arrow-down"),d.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",d.style.transform="rotate(180deg)",d.style.visibility=n===e.length-1?"hidden":"visible",l.addEventListener("click",(()=>{var i,n,o,c;const p=a.previousElementSibling;if(p){const m=Number(null===(i=s.value)||void 0===i?void 0:i.split(".")[0])-1;s.value=`${m}. ${t}`,r.textContent=`${m}. ${t}`,l.style.visibility=1===m?"hidden":"visible",d.style.visibility=m===e.length?"hidden":"visible";const h=p.querySelector(".magicfeedback-input-magicfeedback-priority-list"),f=p.querySelector(".magicfeedback-priority-list-item-label"),g=p.querySelector(".magicfeedback-priority-list-arrow-up"),v=p.querySelector(".magicfeedback-priority-list-arrow-down");if(h&&f&&g&&v){const t=Number(null===(n=h.value)||void 0===n?void 0:n.split(".")[0])+1;h.value=`${t}.${null===(o=f.textContent)||void 0===o?void 0:o.split(".")[1]}`,f.textContent=`${t}.${null===(c=f.textContent)||void 0===c?void 0:c.split(".")[1]}`,g.style.visibility=1===t?"hidden":"visible",v.style.visibility=t===e.length?"hidden":"visible"}u.insertBefore(a,p)}})),d.addEventListener("click",(()=>{var i,n,o;const c=a.nextElementSibling;if(c){const p=Number(null===(i=s.value)||void 0===i?void 0:i.split(".")[0])+1;s.value=`${p}. ${t}`,r.textContent=`${p}. ${t}`,l.style.visibility=1===p?"hidden":"visible",d.style.visibility=p===e.length?"hidden":"visible";const m=c.querySelector(".magicfeedback-input-magicfeedback-priority-list"),h=c.querySelector(".magicfeedback-priority-list-item-label"),f=c.querySelector(".magicfeedback-priority-list-arrow-up"),g=c.querySelector(".magicfeedback-priority-list-arrow-down");if(m&&h&&f&&g){const t=Number(m.value.split(".")[0])-1;m.value=`${t}.${null===(n=h.textContent)||void 0===n?void 0:n.split(".")[1]}`,h.textContent=`${t}.${null===(o=h.textContent)||void 0===o?void 0:o.split(".")[1]}`,f.style.visibility=1===t?"hidden":"visible",g.style.visibility=t===e.length?"hidden":"visible"}u.insertBefore(c,a)}})),o.appendChild(l),o.appendChild(d),a.appendChild(o),u.appendChild(a)}))},m=document.createElement("div");m.classList.add("magicfeedback-modal-backdrop"),m.style.position="fixed",m.style.top="0",m.style.left="0",m.style.width="100vw",m.style.height="100vh",m.style.background="rgba(0,0,0,0.4)",m.style.display="none",m.style.alignItems="center",m.style.justifyContent="center",m.style.zIndex="9999";const h=document.createElement("div");h.classList.add("magicfeedback-modal"),h.style.background="#fff",h.style.borderRadius="8px",h.style.boxShadow="0 8px 24px rgba(0,0,0,0.2)",h.style.maxWidth="520px",h.style.width="90%",h.style.maxHeight="80vh",h.style.overflow="auto",h.style.padding="16px",h.style.position="relative";const f=document.createElement("h5");f.classList.add("magicfeedback-modal-title");const g=()=>Math.min(e.length+1,s),v=()=>{f.textContent=`${o("selectOptionNumber")}${g()}`};v();const y=document.createElement("div");y.classList.add("magicfeedback-modal-list"),(n?[...t].sort((()=>Math.random()-.5)):[...t]).forEach((t=>{const n=document.createElement("label");n.classList.add("magicfeedback-modal-row");const a=document.createElement("input");a.type="checkbox",a.classList.add("magicfeedback-input"),a.name=`${i}-selection`,a.value=t;const l=document.createElement("span");l.textContent=t,a.addEventListener("change",(()=>{if(a.checked){if(e.length>=s)return a.checked=!1,n.classList.add("magicfeedback-warning"),void setTimeout((()=>{n.classList.remove("magicfeedback-warning")}),800);e.push(t)}else{const i=e.indexOf(t);-1!==i&&e.splice(i,1)}r.textContent=`${o("selectUpTo")} ${s} ${o("options")} ${o("thenOrder")} (${e.length}/${s})`,v(),k()})),n.appendChild(a),n.appendChild(l),y.appendChild(n)}));const b=document.createElement("div");b.classList.add("magicfeedback-modal-actions");const E=document.createElement("div");E.classList.add("magicfeedback-modal-counter");const k=()=>{const t=o("of");E.textContent=`${o("prioritized")} ${e.length} ${t} ${s}`};k();const A=document.createElement("button");A.type="button",A.classList.add("magicfeedback-modal-close"),A.setAttribute("aria-label",o("cancel")),A.title=o("cancel"),A.textContent="×",A.addEventListener("click",(()=>{m.style.display="none"}));const C=document.createElement("button");return C.type="button",C.textContent=o("confirm"),C.classList.add("magicfeedback-button"),C.classList.add("magicfeedback-button-primary"),C.addEventListener("click",(()=>{m.style.display="none",p()})),b.appendChild(E),b.appendChild(C),h.appendChild(A),h.appendChild(f),h.appendChild(y),h.appendChild(b),m.appendChild(h),d.addEventListener("click",(()=>{m.style.display="flex",v(),k()})),m.addEventListener("click",(e=>{e.target===m&&(m.style.display="none")})),l.appendChild(a),l.appendChild(c),l.appendChild(m),p(),l}const d=document.createElement("ul");d.classList.add("magicfeedback-priority-list-list");const c=n?[...t].sort((()=>Math.random()-.5)):[...t];return c.forEach(((e,t)=>{const n=document.createElement("li");n.classList.add("magicfeedback-priority-list-item"),n.style.display="flex",n.style.justifyContent="space-between",n.style.alignItems="center",n.style.margin="5px";const a=document.createElement("input");a.classList.add("magicfeedback-input-magicfeedback-priority-list"),a.classList.add("magicfeedback-input"),a.type="hidden",a.id=`priority-list-${i}`,a.name=i,a.value=`${t+1}. ${e}`,n.appendChild(a);const s=document.createElement("label");s.classList.add("magicfeedback-priority-list-item-label"),s.textContent=`${t+1}. ${e}`,n.appendChild(s);const r=document.createElement("div");r.style.display="flex",r.style.alignItems="center",r.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,i,r,u;const p=n.previousElementSibling;if(p){const m=Number(null===(t=a.value)||void 0===t?void 0:t.split(".")[0])-1;a.value=`${m}. ${e}`,s.textContent=`${m}. ${e}`,o.style.visibility=1===m?"hidden":"visible",l.style.visibility=m===c.length?"hidden":"visible";const h=p.querySelector(".magicfeedback-input-magicfeedback-priority-list"),f=p.querySelector(".magicfeedback-priority-list-item-label"),g=p.querySelector(".magicfeedback-priority-list-arrow-up"),v=p.querySelector(".magicfeedback-priority-list-arrow-down");if(h&&f&&g&&v){const e=Number(null===(i=h.value)||void 0===i?void 0:i.split(".")[0])+1;h.value=`${e}.${null===(r=f.textContent)||void 0===r?void 0:r.split(".")[1]}`,f.textContent=`${e}.${null===(u=f.textContent)||void 0===u?void 0:u.split(".")[1]}`,g.style.visibility=1===e?"hidden":"visible",v.style.visibility=e===c.length?"hidden":"visible"}d.insertBefore(n,p)}}));const l=document.createElement("img");l.classList.add("magicfeedback-priority-list-arrow-down"),l.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",l.style.width="20px",l.style.height="20px",l.style.cursor="pointer",l.style.margin="0 5px",l.style.color="#000",l.style.transform="rotate(180deg)",l.style.visibility=t===c.length-1?"hidden":"visible",l.addEventListener("click",(()=>{var t,i,r;const u=n.nextElementSibling;if(u){const p=Number(null===(t=a.value)||void 0===t?void 0:t.split(".")[0])+1;a.value=`${p}. ${e}`,s.textContent=`${p}. ${e}`,o.style.visibility=1===p?"hidden":"visible",l.style.visibility=p===c.length?"hidden":"visible";const m=u.querySelector(".magicfeedback-input-magicfeedback-priority-list"),h=u.querySelector(".magicfeedback-priority-list-item-label"),f=u.querySelector(".magicfeedback-priority-list-arrow-up"),g=u.querySelector(".magicfeedback-priority-list-arrow-down");if(m&&h&&f&&g){const e=Number(m.value.split(".")[0])-1;m.value=`${e}.${null===(i=h.textContent)||void 0===i?void 0:i.split(".")[1]}`,h.textContent=`${e}.${null===(r=h.textContent)||void 0===r?void 0:r.split(".")[1]}`,f.style.visibility=1===e?"hidden":"visible",g.style.visibility=e===c.length?"hidden":"visible"}d.insertBefore(u,n)}})),r.appendChild(o),r.appendChild(l),n.appendChild(r),d.appendChild(n)})),l.appendChild(d),l}({value:E,ref:y,randomPosition:O,limitPriority:(null==A?void 0:A.limitPriority)||!1,maxPriority:(null==A?void 0:A.maxPriority)||0,language:i||"en"});m.appendChild(te);break;case n.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:m=document.createElement("div"),h="magicfeedback-point-system";const ie=document.createElement("div");ie.classList.add("magicfeedback-point-system-container");const ne=document.createElement("ul");ne.classList.add("magicfeedback-point-system-list"),ne.style.padding="0";const ae=100,se=ae/E.length,re=document.createElement("div");re.classList.add("magicfeedback-error"),re.textContent=a.placeholder.pointsystemerror(i||"en"),re.style.color="#C70039",re.style.fontSize="14px",re.style.textAlign="right",re.style.width="100%",re.style.display="none";const oe=document.createElement("div");oe.classList.add("magicfeedback-point-system-total"),oe.textContent="0 / 100 %",oe.style.textAlign="right",oe.style.fontSize="15px",oe.style.marginTop="5px",E.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=y,s.id=`${e}`,s.type="number",s.min="0",s.max=`${ae}`,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 r=document.createElement("span");r.textContent="%",r.style.color="#000",s.addEventListener("input",(()=>{const e=ne.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>ae&&(s.value=`${se}%`,t-=Number(s.value));const i=document.getElementById("magicfeedback-submit");i&&(t<100?(oe.style.color="orange",i.setAttribute("disabled","true")):(re.style.display="none",oe.style.color="green",i.removeAttribute("disabled"))),oe.textContent=`${t} / 100 %`})),s.addEventListener("focus",(()=>{const e=document.getElementById("magicfeedback-submit");e&&(e.setAttribute("disabled","true"),e.addEventListener("pointerover",(()=>{const e=ne.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t<100&&(re.style.display="block")})))})),a.appendChild(s),a.appendChild(r),i.appendChild(a),ne.appendChild(i)})),ie.appendChild(ne),ie.appendChild(oe),ie.appendChild(re),m.appendChild(ie);break;case n.FEEDBACKAPPANSWERTYPE.INFO_PAGE:m=document.createElement("div"),h="magicfeedback-info-page";const le=document.createElement("div");le.classList.add("magicfeedback-info-message"),le.innerHTML=w,m.appendChild(le);break;case n.FEEDBACKAPPANSWERTYPE.UPLOAD_IMAGE:m=document.createElement("input"),m.type="file",m.accept="image/*",m.required=b,m.multiple=(null==A?void 0:A.multiple)||!1,m.maxLength=(null==A?void 0:A.maxFiles)||1,h="magicfeedback-upload-image";break;case n.FEEDBACKAPPANSWERTYPE.UPLOAD_FILE:m=document.createElement("input"),m.type="file",m.required=b,m.multiple=(null==A?void 0:A.multiple)||!1,m.maxLength=(null==A?void 0:A.maxFiles)||1,h="magicfeedback-upload-file";break;default:return C}m.id=`magicfeedback-${f}`,m.setAttribute("name",y),m.classList.add(h),(void 0!==k||null!==T)&&(m.value=T||k),["RADIO","MULTIPLECHOICE"].includes(v)||(m.classList.add("magicfeedback-input"),m.required=b);const I=document.createElement("label");I.setAttribute("for",`magicfeedback-${f}`),I.textContent=r(g,i),I.classList.add("magicfeedback-label");const D=document.createElement("label");if(D.textContent=r(null==A?void 0:A.subtitle,i),D.classList.add("magicfeedback-sublabel"),(null===(c=null==A?void 0:A.subtitleStyle)||void 0===c?void 0:c.includes("italic"))&&(D.style.fontStyle="italic"),(null===(u=null==A?void 0:A.subtitleStyle)||void 0===u?void 0:u.includes("bold"))&&(D.style.fontWeight="bold"),(null===(p=null==A?void 0:A.subtitleStyle)||void 0===p?void 0:p.includes("underline"))&&(D.style.textDecoration="underline"),["CONSENT"].includes(v))C.classList.add("magicfeedback-consent-container"),C.appendChild(m),C.appendChild(I),C.appendChild(D);else{if("slim"!==t&&(C.appendChild(I),C.appendChild(D),void 0!==(null==A?void 0:A.general)&&""!==(null==A?void 0:A.general))){const Le=document.createElement("img");Le.src=null==A?void 0:A.general,Le.classList.add("magicfeedback-image"),Le.style.maxWidth="auto",Le.style.height="400px",Le.style.margin="10px 0",C.appendChild(Le)}if("LONGTEXT"===v&&L>0){const Oe=document.createElement("div");if(Oe.classList.add("magicfeedback-counter"),Oe.textContent=`${m.value.length}/${L}`,Oe.style.textAlign="right",Oe.style.fontSize="15px",Oe.style.marginTop="5px",m.addEventListener("input",(()=>{Oe.textContent=`${m.value.length}/${L}`})),C.appendChild(m),C.appendChild(Oe),(null==A?void 0:A.extraOption)&&(null==A?void 0:A.extraOptionText)){const Pe=document.createElement("div");Pe.classList.add("magicfeedback-skip-container"),Pe.classList.add("magicfeedback-checkbox-container"),Pe.style.display="flex",Pe.style.justifyContent="flex-start";const Se=document.createElement("input");Se.classList.add("magicfeedback-skip"),Se.type="checkbox",Se.id=`skip-${y}`,Se.name=y,Se.value="-",Se.style.cursor="pointer";const Ne=document.createElement("label");Ne.htmlFor=`skip-${y}`,Ne.textContent=null==A?void 0:A.extraOptionText,Ne.style.fontSize="15px",Ne.style.cursor="pointer",Ne.style.margin="0 5px",Se.addEventListener("click",(()=>{m.value="-",d&&d()})),Pe.appendChild(Se),Pe.appendChild(Ne),C.appendChild(Pe)}}else C.appendChild(m)}return C}(h,i,l,`${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 r=document.createElement("button");r.id="magicfeedback-submit",r.type="submit",r.classList.add("magicfeedback-submit"),r.textContent="MAGICSURVEY"===e?a||"Next":i||"Submit";const o=document.createElement("button");return o.id="magicfeedback-back",o.type="button",o.classList.add("magicfeedback-back"),o.textContent=n||"Back",o.addEventListener("click",t),o.addEventListener("click",(()=>{r.removeAttribute("disabled")})),"MAGICSURVEY"===e&&s.appendChild(o),s.appendChild(r),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}},313:function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function r(e){try{l(n.next(e))}catch(e){s(e)}}function o(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}l((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(945)),r=a(i(330)),o=i(857),l={Accept:"application/json","Magicfeedback-Sdk-Version":r.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+o.endpoints.sdk.app_info(t,i),{method:"GET",headers:l});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+o.endpoints.sdk.session(t),{method:"GET",headers:l});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+o.endpoints.sdk.app(t,i),{method:"GET",headers:l});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+o.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},l),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+o.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},l),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),""}}))}},256:(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)}}},330:e=>{"use strict";e.exports=JSON.parse('{"name":"@magicfeedback/native","version":"2.1.7-alpha.4","main":"./dist/magicfeedback-sdk.node.js","browser":"./dist/magicfeedback-sdk.browser.js","types":"./dist/types/src/index.d.ts","repository":{"type":"git","url":"git+ssh://git@github.com/MagicFeedback/magicfeedback-sdk.git"},"author":"farias@magicfeedback.io","license":"MIT","private":false,"scripts":{"dev":"vite","build":"webpack","build:watch":"webpack --watch --mode development","release":"npm publish --access public","release:beta":"npm publish --access public --tag beta","release:alpha":"npm publish --access public --tag alpha","test":"jest","test:watch":"jest --watchAll","coverage":"vitest run --coverage","publish:sdk":"bash publish.sh","publish:sdk:dry-run":"NPM_DRY_RUN=1 bash publish.sh"},"files":["dist"],"devDependencies":{"@babel/preset-typescript":"^7.22.5","@types/node":"^17.0.21","@types/webpack":"^5.28.0","@types/webpack-node-externals":"^2.5.3","c8":"^7.11.0","copy-webpack-plugin":"^11.0.0","jest":"^29.5.0","jest-environment-jsdom":"^29.5.0","jest-fetch-mock":"^3.0.3","nock":"^13.2.4","ts-jest":"^29.1.0","ts-loader":"^9.2.7","ts-node":"^10.7.0","typescript":"^4.6.2","vite":"^2.8.0","vite-plugin-dts":"^0.9.9","vitest":"^0.5.9","webpack":"^5.70.0","webpack-cli":"^4.9.2","webpack-node-externals":"^3.0.0"},"dependencies":{"cross-fetch":"^3.1.5","is-bundling-for-browser-or-node":"^1.1.1"},"description":"MagicFeedbackAI JavaScript Library for [MagicFeedback.io](https://magicfeedback.io/)","bugs":{"url":"https://github.com/MagicFeedback/magicfeedback-sdk/issues"},"homepage":"https://github.com/MagicFeedback/magicfeedback-sdk#readme","directories":{"example":"examples","test":"test"},"style":"./dist/styles/magicfeedback-default.css"}')}},t={},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}(156).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={317:(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.deepdots.com/",t.HOST_API_URL_DEV="https://api-dev.deepdots.com/"},156: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(927));let s=null;s||(s=(0,a.default)()),t.default=s},927:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function r(e){try{l(n.next(e))}catch(e){s(e)}}function o(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const a=i(57),s=i(665),r=i(256),o=i(313),l=i(317);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)?l.HOST_API_URL_DEV:l.HOST_API_URL),e.set("env",null==i?void 0:i.env),t=new r.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,a,s,r=!0,l,d){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:d,completed:r,id:l,feedback:s};try{const e=yield(0,o.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)}}}},79:(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}get(e){return this.items[e]}}},665:(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}}},57:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function r(e){try{l(n.next(e))}catch(e){s(e)}}function o(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const a=i(558),s=i(256),r=i(313),o=i(213),l=i(217),d=i(700),c=i(591),u=i(79),p=i(636);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 l.PageGraph([]),this.progress=0,this.total=0,this.completed=!1,this.timeToCompleted=0}generate(e,t){var i,a,s,o,l,d,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,r.getForm)(this.url,this.appId,this.publicKey,this.log):yield(0,r.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===(o=n.pages)||void 0===o||o.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===(l=this.formData.pages)||void 0===l?void 0:l.length)||this.formatPages(),null===(d=this.formData.questions)||void 0===d||d.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,[],c.TransitionType.PAGE,(e.position+1).toString(),e.position.toString()),a=new d.Page(e.position.toString(),e.position,this.appId,[e],[n]);null===(i=null===(t=this.formData)||void 0===t?void 0:t.pages)||void 0===i||i.push(a)}));break;case"MAGICFORM":const t=new d.Page("1",1,this.appId,this.formData.questions,[]);this.formData.pages=[t]}}generateContainer(){let e=document.getElementById(this.selector);if(!e&&(e=document.getElementById("magicfeedback-container-"+this.appId),!e))throw new Error(`Element with ID '${this.selector}' not found.`);return e.classList.add("magicfeedback-container"),e.id="magicfeedback-container-"+this.appId,e.innerHTML="",e}generateForm(){var e,t,i,a;return n(this,void 0,void 0,(function*(){try{if(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 l.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 r=document.createElement("div");r.classList.add("magicfeedback-questions"),r.id="magicfeedback-questions-"+this.appId;const d=this.graph.getFirstPage();if(!d)throw new Error("No page found");if(this.total=this.graph.findMaxDepth(),d.elements=(0,o.renderQuestions)(d.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=d.elements)||void 0===i||i.forEach((e=>r.appendChild(e))),s.appendChild(r),this.history.enqueue(d),n.appendChild(s),this.progress=this.total-this.graph.findMaxDepth(d),this.formOptionsConfig.addButton){const e=(0,o.renderActions)(null===(a=this.formData)||void 0===a?void 0:a.identity,(()=>this.back()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);s.appendChild(e)}this.formOptionsConfig.addButton&&s.addEventListener("submit",(e=>{e.preventDefault(),this.send()})),this.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,o.renderStartMessage)(e,this.formOptionsConfig.addButton,this.formOptionsConfig.startButtonText,(()=>this.startForm()));t.appendChild(i),this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,formData:this.formData}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}))}getMetaData(){this.formOptionsConfig.customMetaData&&(this.feedback.metadata=[...this.feedback.metadata,...this.formOptionsConfig.customMetaData]),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&&![a.FEEDBACKAPPANSWERTYPE.CONSENT,a.FEEDBACKAPPANSWERTYPE.INFO_PAGE].includes(e.type)))){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),!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")}if(e.type===a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX){const i=this.feedback.answers.find((t=>t.key===e.ref));if(!i)throw this.log.err(`The matrix question ${e.ref} is required`),new Error("No response");const n=this.parseMatrixAnswerPre(i),a=Array.isArray(null==t?void 0:t.options)?t.options:[];if(a.length>0){if(a.find((e=>{const t=n.find((t=>t.key===e));return!t||!Array.isArray(t.value)||0===t.value.length})))throw this.log.err(`The matrix question ${e.ref} requires an answer in every row`),new Error("No response")}else if(0===n.length||n.some((e=>!Array.isArray(e.value)||0===e.value.length)))throw this.log.err(`The matrix question ${e.ref} requires an answer in every row`),new Error("No response")}}const r=yield this.pushAnswers(!1);if(!r)throw new Error("No response");this.id=r,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.`),this.feedback.answers=[],[];const t=this.history.back();if(!t){this.log.err("No page found");const t=e.querySelectorAll(".magicfeedback-input"),i=[],n={};return t.forEach((e=>{var t;const a=e,s=a.name;if(!s)return;const r=a.type;if(("radio"===r||"checkbox"===r)&&!a.checked)return;const o=a.value,l=a.classList[0];if((null==l?void 0:l.includes("magicfeedback-priority-list"))||(null===(t=a.id)||void 0===t?void 0:t.startsWith("priority-list-")))return n[s]||(n[s]=[]),void n[s].push(o);const d="magicfeedback-consent"===l?a.checked.toString():o;if(null==d)return;const c={key:s,value:[d]};i.push(c)})),Object.entries(n).forEach((([e,t])=>{const n=t.slice().sort(((e,t)=>Number(e.split(".")[0])-Number(t.split(".")[0])));i.push({key:e,value:n})})),this.feedback.answers=i,i}const i=[];let n=!1;const s=e.querySelectorAll(".magicfeedback-input"),o={};return s.forEach((e=>{const s=e,l=t.questions.find((e=>{var t;return null===(t=s.name)||void 0===t?void 0:t.includes(e.ref)})),d=s.type,c=s.classList[0],u={key:s.name,value:[]},p="magicfeedback-consent"===c?s.checked.toString():s.value;if(u.key&&""!==u.key)switch(null==l?void 0:l.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:""!==p&&("email"===d?(0,r.validateEmail)(p)?(this.feedback.profile.push({key:"email",value:[p]}),u.value.push(p),i.push(u)):(this.log.err("Invalid email"),n=!0):(u.value.push(p),i.push(u)));break;case a.FEEDBACKAPPANSWERTYPE.RADIO:case a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:case a.FEEDBACKAPPANSWERTYPE.BOOLEAN:s.checked&&(u.value.push(p),i.push(u));break;case a.FEEDBACKAPPANSWERTYPE.CONSENT:u.value.push(s.checked.toString()),i.push(u);break;case a.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:case a.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:case a.FEEDBACKAPPANSWERTYPE.RATING_STAR:s.checked&&(u.value.push(p),i.push(u));break;case a.FEEDBACKAPPANSWERTYPE.SELECT:""!==p&&(u.value.push(p),i.push(u));break;case a.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:"hidden"===d&&(o[u.key]||(o[u.key]=[]),o[u.key].push(p));case a.FEEDBACKAPPANSWERTYPE.UPLOAD_IMAGE:case a.FEEDBACKAPPANSWERTYPE.UPLOAD_FILE:}})),n?[]:(Object.entries(o).forEach((([e,t])=>{if(!t||0===t.length)return;const n=t.slice().sort(((e,t)=>Number(e.split(".")[0])-Number(t.split(".")[0])));i.push({key:e,value:n})})),this.feedback.answers=i,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,o.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,r.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,r.getFollowUpQuestion)(i,n,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e){var t,i,a;return n(this,void 0,void 0,(function*(){const n=this.history.back();if(!n)throw new Error("No page found");const s=n.getFollowupQuestions();if(0===(null==s?void 0:s.length))return void(yield this.renderNextQuestion(e,n));const r=[];for(const e of s){const t=n.questions.find((t=>t.ref===e));if(t){const e=yield this.callFollowUpQuestion(t);e&&r.push(e)}}if(0===r.length)return void(yield this.renderNextQuestion(e,n));const l=new d.Page(n.id,n.position,this.appId,r,n.edges),c=new p.PageNode(n.id,n.position,n.edges,l,r,!0);c.elements=(0,o.renderQuestions)(r,this.formOptionsConfig.questionFormat,null===(t=this.formData)||void 0===t?void 0:t.lang[0],null===(i=this.formData)||void 0===i?void 0:i.product,(()=>this.send())),this.history.enqueue(c),this.progress+=.5,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,s,r,l,d;return n(this,void 0,void 0,(function*(){let n=this.graph.getNextPage(t,this.feedback.answers);if(!n)return void this.finish();const u=n.edges.filter((e=>"PRECONDITIONAL"===e.typeCondition)).sort(((e,t)=>e.position<t.position?-1:e.position>t.position?1:0));if((null==u?void 0:u.length)>0){let t=null;const r=u.map((e=>e.questionRef));for(let e=this.history.size()-1;e>=0;e--){const n=this.history.get(e);if(n&&(t=null===(i=n.answers)||void 0===i?void 0:i.find((e=>r.includes(e.key))),t))break}let o=!u.some((e=>e.transition===c.TransitionType.ALLOW));if(t)for(const i of u){let r=!1;const l=null===(s=this.formData)||void 0===s?void 0:s.questions.find((e=>e.ref===i.questionRef)),d=Array.isArray(t.value)?t.value:[t.value],u=Array.isArray(i.value)?i.value:[i.value];if((null==l?void 0:l.type)===a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX)r=this.evaluateMatrixPreconditional(i,t);else switch(i.typeOperator){case"EQUAL":case"INQ":r=d.some((e=>u.includes(e)));break;case"NOEQUAL":case"NINQ":r=d.every((e=>!u.includes(e)));break;case"GREATER":r=d.some((e=>Number(e)>Number(u[0])));break;case"LESS":r=d.some((e=>Number(e)<Number(u[0])));break;case"GREATEREQUAL":r=d.some((e=>Number(e)>=Number(u[0])));break;case"LESSEQUAL":r=d.some((e=>Number(e)<=Number(u[0])))}if(r)switch(this.feedback.answers=[],i.transition){case c.TransitionType.NEXT:return void(n&&(yield this.renderNextQuestion(e,n)));case c.TransitionType.ALLOW:o=!0}}if(!o)return this.feedback.answers=[],void(n&&(yield this.renderNextQuestion(e,n)))}n.elements=(0,o.renderQuestions)(n.questions,this.formOptionsConfig.questionFormat,null===(r=this.formData)||void 0===r?void 0:r.lang[0],null===(l=this.formData)||void 0===l?void 0:l.product,(()=>this.send())),e.innerHTML="",null===(d=n.elements)||void 0===d||d.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}))}))}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"}))}))}previewQuestion(e,t,i){var n,a;const s=Array.isArray(t)?t:[t];if(!s||0===s.length)throw new Error("[MagicFeedback] No question provided for preview");const r=document.getElementById(e);if(!r)throw new Error(`[MagicFeedback] Element with ID '${e}' not found.`);const{format:l=this.formOptionsConfig.questionFormat||"standard",language:d=(null===(n=this.formData)||void 0===n?void 0:n.lang)&&this.formData.lang[0]||"en",product:c=(null===(a=this.formData)||void 0===a?void 0:a.product)||{customIcons:!1},clearContainer:u=!0,wrap:p=!0}=i||{};u&&(r.innerHTML="");let m=[];try{m=(0,o.renderQuestions)(s,l,d,c)}catch(e){throw this.log.err(e),e}let h=r;if(p){const e=document.createElement("div");e.classList.add("magicfeedback-preview-question"),h.appendChild(e),h=e}return m.forEach((e=>h.appendChild(e))),r}parseMatrixAnswerPre(e){if(!e||!e.value)return[];if(1===e.value.length&&"string"==typeof e.value[0]&&e.value[0].trim().startsWith("["))try{const t=JSON.parse(e.value[0]);if(Array.isArray(t))return t}catch(e){return[]}return Array.isArray(e.value)&&e.value.length>0&&"object"==typeof e.value[0]&&null!==e.value[0]&&"key"in e.value[0]?e.value:[]}evaluateMatrixPreconditional(e,t){const i=Array.isArray(e.value)?e.value:[e.value],n=new Set(e.option||[]),a=this.parseMatrixAnswerPre(t);if(!a.length)return!1;const s=n.size>0?a.filter((e=>n.has(e.key))):a;if(!s.length)return!1;switch(e.typeOperator){case"EQUAL":case"INQ":return s.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.includes(e)))));case"NOEQUAL":case"NINQ":return s.every((e=>(Array.isArray(e.value)?e.value:[e.value]).every((e=>!i.includes(e)))));case"GREATER":return s.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)>Number(t)))))));case"LESS":return s.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)<Number(t)))))));case"GREATEREQUAL":return s.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)>=Number(t)))))));case"LESSEQUAL":return s.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)<=Number(t)))))));default:return!1}}}},700:(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}}},217:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PageGraph=void 0;const n=i(636),a=i(558),s=i(591);t.PageGraph=class{constructor(e){this.nodes=new Map,this.buildGraph(e)}buildGraph(e){e.forEach((e=>{var t;e.integrationPageRoutes&&(e.integrationPageRoutes=(null===(t=e.integrationPageRoutes)||void 0===t?void 0:t.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 i=new n.PageNode(e.id,e.position,e.integrationPageRoutes||[],e,e.integrationQuestions);this.nodes.set(i.id,i)}))}getNodeById(e){return this.nodes.get(e)}getNextEdgeByDefault(e){if(!e)return;const t=e.edges.find((e=>e.typeCondition===s.ConditionType.DIRECT));if(!t||![s.TransitionType.FINISH,s.TransitionType.REDIRECT].includes(t.transition)){if(t&&t.transitionDestiny)return t.transitionDestiny;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((i=>{const n=e.questions.find((e=>e.ref===i.questionRef)),r=null==t?void 0:t.filter((e=>e.key===i.questionRef));if("DIRECT"===i.typeCondition)return!0;if(!r||0===r.length)return!1;if((null==n?void 0:n.type)===a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX)return this.evaluateMatrixCondition(i,r);const o=Array.isArray(i.value)?i.value:[i.value];switch(i.typeOperator){case s.OperatorType.EQUAL:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.includes(e)))));case s.OperatorType.NOEQUAL:return r.every((e=>(Array.isArray(e.value)?e.value:[e.value]).every((e=>!o.includes(e)))));case s.OperatorType.GREATER:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.some((t=>Number(e)>Number(t)))))));case s.OperatorType.LESS:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.some((t=>Number(e)<Number(t)))))));case s.OperatorType.GREATEREQUAL:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.some((t=>Number(e)>=Number(t)))))));case s.OperatorType.LESSEQUAL:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.some((t=>Number(e)<=Number(t)))))));case s.OperatorType.INQ:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.includes(e)))));case s.OperatorType.NINQ:return r.every((e=>(Array.isArray(e.value)?e.value:[e.value]).every((e=>!o.includes(e)))));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=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.filter((e=>e.typeCondition!==s.ConditionType.PRECONDITIONAL))||[]],r=this.getNextEdgeByDefault(e);if(r){const i=this.getNodeById(r);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 a=this.getNodeById(e.transitionDestiny);if(a&&!t.has(a)){const e=i+1,s=new Set(t),r=this.DFSUtil(a,s,e);n=Math.max(n,r)}}return n}parseMatrixAnswer(e){if(!e||!e.value)return[];if(1===e.value.length&&"string"==typeof e.value[0]&&e.value[0].trim().startsWith("["))try{const t=JSON.parse(e.value[0]);if(Array.isArray(t))return t}catch(e){return[]}return Array.isArray(e.value)&&e.value.length>0&&"object"==typeof e.value[0]&&null!==e.value[0]&&"key"in e.value[0]?e.value:[]}evaluateMatrixCondition(e,t){const i=Array.isArray(e.value)?e.value:[e.value],n=new Set(e.option||[]),a=t[0],r=this.parseMatrixAnswer(a);if(!r.length)return!1;const o=n.size>0?r.filter((e=>n.has(e.key))):r;if(!o.length)return!1;switch(e.typeOperator){case s.OperatorType.EQUAL:case s.OperatorType.INQ:return o.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.includes(e)))));case s.OperatorType.NOEQUAL:case s.OperatorType.NINQ:return o.every((e=>(Array.isArray(e.value)?e.value:[e.value]).every((e=>!i.includes(e)))));case s.OperatorType.GREATER:return o.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)>Number(t)))))));case s.OperatorType.LESS:return o.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)<Number(t)))))));case s.OperatorType.GREATEREQUAL:return o.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)>=Number(t)))))));case s.OperatorType.LESSEQUAL:return o.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)<=Number(t)))))));default:return!1}}}},636:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PageNode=void 0,t.PageNode=class{constructor(e,t,i,n,a,s=!1){this.answers=[],this.id=e,this.position=t,this.edges=i,this.data=n,this.questions=a.sort(((e,t)=>e.position-t.position)),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))}setAnswer(e){this.answers=e}}},591:(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",s.NEXT="NEXT",s.ALLOW="ALLOW",function(e){e.LOGICAL="LOGICAL",e.DIRECT="DIRECT",e.PRECONDITIONAL="PRECONDITIONAL"}(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,r,o,l,d,c,u){this.id=e,this.questionRef=t,this.typeCondition=d||i.LOGICAL,this.typeOperator=a,this.value=s||[],this.transition=r,this.transitionDestiny=o,this.status=n.ACTIVE,this.generatedAt=new Date,this.updatedAt=new Date,this.integrationPageId=l,this.position=c||0,this.option=u||[]}}},558:(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={}))},857:(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"}}},784:(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 % হতে হবে"}}}},213:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.renderStartMessage=t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0;const n=i(558),a=i(784),s="https://survey-dev.magicfeedback.io/assets/emojis";function r(e,t){return e?"object"==typeof e?e[t]||e.en:e:""}function o(e,t,i,n,a,s=!0,r="ltr",o="row"){const l=document.createElement("div");l.classList.add("magicfeedback-rating-placeholder"),l.style.display="flex",l.style.flexDirection=o,l.style.alignItems="center",l.style.justifyContent="space-between",l.style.width=a?`calc(100% - (100% / ${t+1}))`:"100%",l.style.marginRight="auto",s&&window.innerWidth<600&&(l.style.flexDirection="column");const d=document.createElement("span");d.textContent=i,d.classList.add("magicfeedback-rating-placeholder-value"),d.style.fontSize="15px",d.style.textAlign="ltr"===r?"left":"right",d.style.width="50%",(s&&window.innerWidth<600||"column"===o)&&(d.textContent=`${e} = ${i}`,d.style.width="100%",d.style.textAlign="left",d.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"===r?"right":"left",c.style.width="50%",(s&&window.innerWidth<600||"column"===o)&&(c.textContent=`${t} = ${n}`,c.style.width="100%",c.style.textAlign="left",c.style.marginBottom="5px"),"ltr"===r?(i&&l.appendChild(d),n&&l.appendChild(c)):(n&&l.appendChild(c),i&&l.appendChild(d)),l}t.renderQuestions=function e(t,i="standard",l="en",d={customIcons:!1},c){if(!t)throw new Error("[MagicFeedback] No questions provided");const u=[],{customIcons:p,id:m}=d;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=r(h.title,l),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,l,d,c).forEach((e=>{t.appendChild(e)})),u.push(t)}else{const e=function(e,t,i,l,d){var c,u,p;let m,h,{id:f,title:g,type:v,ref:y,require:b,value:E,defaultValue:k,assets:A}=e,C=document.createElement("div");C.classList.add("magicfeedback-div");const x=window.innerWidth<600,T="slim"===t?r(g,i):null==A?void 0:A.placeholder,L=(P=y,new URLSearchParams(window.location.search).get(P)),w=(null==A?void 0:A.maxCharacters)||0,S=void 0!==(null==A?void 0:A.randomPosition)&&(null==A?void 0:A.randomPosition),N=(null==A?void 0:A.direction)||"row",O=(null==A?void 0:A.order)||"ltr";var P;switch(v){case n.FEEDBACKAPPANSWERTYPE.TEXT:m=document.createElement("input"),m.type="text",m.placeholder=T||a.placeholder.answer(i||"en"),L&&(m.value=L),m.addEventListener("keyup",(e=>{e.preventDefault(),console.log(e.key,e),"Enter"===e.key&&d&&d()})),h="magicfeedback-text";break;case n.FEEDBACKAPPANSWERTYPE.LONGTEXT:m=document.createElement("textarea"),m.rows=3,w>0&&(m.maxLength=w),m.placeholder=T||a.placeholder.answer(i||"en"),L&&(m.value=L),h="magicfeedback-longtext";break;case n.FEEDBACKAPPANSWERTYPE.NUMBER:m=document.createElement("input"),m.type="number",m.placeholder="slim"===t?r(g,i):a.placeholder.number(i||"en"),h="magicfeedback-number",E.length&&(E.sort(((e,t)=>Number(e)-Number(t))),m.max=E[E.length-1],m.min=E[0],m.value=E[0]),L&&!isNaN(Number(L))&&(m.value=L);break;case n.FEEDBACKAPPANSWERTYPE.RADIO:case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:m=document.createElement("div"),h="magicfeedback-"+("MULTIPLECHOICE"===v?"checkbox":"radio");let D=E||[];S&&(D=D.sort((()=>Math.random()-.5)));let R=(null==A?void 0:A.exclusiveAnswers)||[];(null==A?void 0:A.extraOption)&&(R=R.filter((e=>e!==A.extraOptionText))),R.length>0&&(null==R||R.forEach((e=>{D.includes(e)||D.push(e)}))),(null==A?void 0:A.extraOption)&&!D.includes(null==A?void 0:A.extraOptionText)&&D.push(null==A?void 0:A.extraOptionText),D.forEach(((e,t)=>{const s=document.createElement("div");s.classList.add(`magicfeedback-${"MULTIPLECHOICE"===v?"checkbox":"radio"}-container`);const r=document.createElement("label"),o=document.createElement("input");if(o.id=`rating-${y}-${t}`,o.type="MULTIPLECHOICE"===v?"checkbox":"radio",o.name=y,o.value=e,o.classList.add(h),o.classList.add("magicfeedback-input"),v===n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE&&(null==A?void 0:A.maxOptions)&&(null==A?void 0:A.maxOptions)>0&&o.addEventListener("change",(()=>{document.querySelectorAll(`input[name="${y}"]:checked`).length>(null==A?void 0:A.maxOptions)&&(o.checked=!1)})),v===n.FEEDBACKAPPANSWERTYPE.RADIO&&d&&(!(null==A?void 0:A.extraOptionText)||(null==A?void 0:A.extraOptionText)&&e!==(null==A?void 0:A.extraOptionText))&&o.addEventListener("change",(()=>{d()})),e!==k&&e!==L||(o.checked=!0),r.textContent=e,r.htmlFor=`rating-${y}-${t}`,o.addEventListener("change",(t=>{const i=document.getElementById(`extra-option-${y}`);t.target.checked&&R.includes(e)?(console.log("exclusiveAnswers",R,e),D.forEach((t=>{t!==e&&(document.querySelector(`input[value="${t}"]`).checked=!1)})),i&&(i.style.display="none")):R.forEach((t=>{t!==e&&(document.querySelector(`input[value="${t}"]`).checked=!1)})),(null==A?void 0:A.extraOption)&&e===(null==A?void 0:A.extraOptionText)&&i&&(i.style.display=t.target.checked?"block":"none")})),s.appendChild(o),s.appendChild(r),m.appendChild(s),(null==A?void 0:A.extraOption)&&e===(null==A?void 0:A.extraOptionText)){const e=document.createElement("input");e.type="text",e.placeholder=(null==A?void 0:A.extraOptionPlaceholder)||a.placeholder.answer(i||"en"),e.classList.add("magicfeedback-extra-option"),e.classList.add("magicfeedback-input"),e.id=`extra-option-${y}`,e.name=`extra-option-${y}`,e.style.display="none",m.appendChild(e)}}));break;case n.FEEDBACKAPPANSWERTYPE.BOOLEAN:m=document.createElement("div"),h="magicfeedback-radio";const F=document.createElement("div");F.classList.add("magicfeedback-boolean-container"),F.style.display="flex",F.style.flexDirection="row",F.style.justifyContent="space-between",F.style.width="70%",F.style.margin="auto",((null==A?void 0:A.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-${y}-${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-${y}-${t}`,n.textContent=e,n.style.margin="0",n.style.padding="0";const a=document.createElement("input");a.id=`rating-${y}-${t}`,a.type="radio",a.name=y,a.value=["Yes","No"][t],a.classList.add(h),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",(()=>{d&&d()})),L&&L.toLowerCase()===a.value.toLowerCase()&&(a.checked=!0),i.appendChild(a),i.appendChild(n),F.appendChild(i)})),m.appendChild(F);break;case n.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:m=document.createElement("div"),h="magicfeedback-rating";const M=document.createElement("div");M.classList.add("magicfeedback-rating-container");const _=(null==A?void 0:A.max)?Number(null==A?void 0:A.max):5,B=(null==A?void 0:A.min)?Number(null==A?void 0:A.min):1,q=o(B,_,null==A?void 0:A.minPlaceholder,null==A?void 0:A.maxPlaceholder,null==A?void 0:A.extraOption);for(let de=B;de<=_;de++){const ce=document.createElement("div");ce.classList.add("magicfeedback-rating-option");const ue=document.createElement("label");ue.htmlFor=`rating-${y}-${de}`,ue.classList.add("magicfeedback-rating-option-label-container");const pe=document.createElement("label");pe.htmlFor=`rating-${y}-${de}`,pe.textContent=de.toString();const me=document.createElement("img");if(me.alt=`face-${y}-${de}`,me.className=`rating-image${de}`,0===B&&10===_)me.src=`${l}/${de}.svg`,me.onerror=()=>me.src=`${s}/${de}.svg`;else if(1===B&&5===_)switch(de){case 1:me.src=`${l}/1.svg`,me.onerror=()=>me.src=`${s}/1.svg`;break;case 2:me.src=`${l}/2.svg`,me.onerror=()=>me.src=`${s}/2.svg`;break;case 3:me.src=`${l}/6.svg`,me.onerror=()=>me.src=`${s}/6.svg`;break;case 4:me.src=`${l}/9.svg`,me.onerror=()=>me.src=`${s}/9.svg`;break;case 5:me.src=`${l}/10.svg`,me.onerror=()=>me.src=`${s}/10.svg`}else{const fe=Math.round(10/(_-B)*(de-B));me.src=`${l}/${fe}.svg`,me.onerror=()=>me.src=`${s}/${fe}.svg`}const he=document.createElement("input");he.id=`rating-${y}-${de}`,he.type="radio",he.name=y,he.value=de.toString(),he.classList.add(h),he.classList.add("magicfeedback-input"),d&&he.addEventListener("change",(()=>{d()})),L&&L===he.value&&(he.checked=!0),ue.appendChild(he),ue.appendChild(me),ue.appendChild(pe),ce.appendChild(ue),M.appendChild(ce)}if((null==A?void 0:A.extraOption)&&(null==A?void 0:A.extraOptionText)){const ge=document.createElement("div");ge.classList.add("magicfeedback-rating-option");const ve=document.createElement("label");ve.htmlFor=`rating-${y}-extra`,ve.classList.add("magicfeedback-rating-option-label-container");const ye=document.createElement("label");ye.htmlFor=`rating-${y}-extra`,ye.textContent=null==A?void 0:A.extraOptionText;const be=document.createElement("img");be.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",be.alt=`face-${y}-extra`,be.className="magicfeedback-rating-image-extra";const Ee=document.createElement("input");Ee.id=`rating-${y}-extra`,Ee.type="radio",Ee.name=y,Ee.value="-",Ee.classList.add(h),Ee.classList.add("magicfeedback-input"),d&&Ee.addEventListener("change",(()=>{d()})),ve.appendChild(Ee),ve.appendChild(be),ve.appendChild(ye),ge.appendChild(ve),M.appendChild(ge)}m.appendChild(q),m.appendChild(M);break;case n.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:h="magicfeedback-rating-number",m=function(e,t,i,n,a,s,r,o){const l=document.createElement("div");l.classList.add("magicfeedback-rating-number");const d="ltr"===i?n:`${n}-reverse`,c=document.createElement("div");c.classList.add("magicfeedback-rating-number-container"),c.classList.add(`magicfeedback-rating-number-container-${i}`),c.classList.add(`magicfeedback-rating-number-container-${n}`),c.style.display="flex",c.style.flexDirection=d,c.setAttribute("role","radiogroup"),c.setAttribute("aria-label",(null==t?void 0:t.ariaLabel)||"Rating");const u=(null==t?void 0:t.max)?Number(null==t?void 0:t.max):10,p=(null==t?void 0:t.min)?Number(null==t?void 0:t.min):0,m=(null==t?void 0:t.numberPlaceholders)||null,h=!(a||"column"===n);for(let i=p;i<=u;i++){const l=document.createElement("div");l.classList.add("magicfeedback-rating-number-option"),l.classList.add(`magicfeedback-rating-number-option-${n}`);const d=document.createElement("label");if(d.htmlFor=`rating-${e}-${i}`,d.classList.add("magicfeedback-rating-number-option-label-container"),h&&(d.style.position="relative",d.style.overflow="visible"),h){const e=document.createElement("span");e.classList.add("magicfeedback-rating-number-cap"),e.classList.add("magicfeedback-rating-placeholder-value"),e.style.fontSize="14px",e.style.whiteSpace="nowrap",e.style.wordBreak="normal",i===p&&(null==t?void 0:t.minPlaceholder)?(e.textContent=t.minPlaceholder,e.dataset.capType="min"):i===u&&(null==t?void 0:t.maxPlaceholder)?(e.textContent=t.maxPlaceholder,e.dataset.capType="max"):e.dataset.capType="mid",d.appendChild(e)}let f=i.toString();h?m&&m[i]&&!a&&(d.title=m[i]):m&&m[i]?f+=` = ${m[i]}`:i===p&&(null==t?void 0:t.minPlaceholder)?f+=` = ${null==t?void 0:t.minPlaceholder}`:i===u&&(null==t?void 0:t.maxPlaceholder)&&(f+=` = ${null==t?void 0:t.maxPlaceholder}`);const g=document.createElement("input");g.id=`rating-${e}-${i}`,g.type="radio",g.name=e,g.value=i.toString(),g.classList.add(s),g.classList.add("magicfeedback-input"),g.setAttribute("aria-label",`${i}`),r&&g.addEventListener("change",(()=>r())),o&&o===g.value&&(g.checked=!0);const v=document.createElement("label");v.htmlFor=`rating-${e}-${i}`,v.textContent=f,v.classList.add("magicfeedback-rating-number-value"),d.appendChild(g),d.appendChild(v),l.appendChild(d),c.appendChild(l)}if((null==t?void 0:t.extraOption)&&(null==t?void 0:t.extraOptionText)){const n=document.createElement("div");n.classList.add("magicfeedback-rating-number-option");const a=document.createElement("label");if(a.htmlFor=`rating-${e}-extra`,a.classList.add("magicfeedback-rating-number-option-label-container"),h&&(a.style.position="relative",a.style.overflow="visible"),h){const e=document.createElement("span");e.classList.add("magicfeedback-rating-number-cap"),e.dataset.capType="extra",e.style.fontSize="12px",e.style.whiteSpace="nowrap",e.style.wordBreak="normal",a.appendChild(e)}const o=document.createElement("input");o.id=`rating-${e}-extra`,o.type="radio",o.name=e,o.value="-",o.classList.add(s),o.classList.add("magicfeedback-input"),o.setAttribute("aria-label",null==t?void 0:t.extraOptionText),r&&o.addEventListener("change",(()=>r()));const l=document.createElement("label");l.htmlFor=`rating-${e}-extra`,l.textContent=null==t?void 0:t.extraOptionText,l.classList.add("magicfeedback-rating-number-value"),a.appendChild(o),a.appendChild(l),n.appendChild(a),"ltr"===i?c.appendChild(n):c.insertBefore(n,c.firstChild)}return l.appendChild(c),h&&requestAnimationFrame((()=>{const e=Array.from(c.querySelectorAll(".magicfeedback-rating-number-cap"));if(0===e.length)return;let t=0;e.forEach((e=>{var i;if(null===(i=e.textContent)||void 0===i?void 0:i.trim()){const i=e.getBoundingClientRect().height||0;i>t&&(t=i)}})),c.style.position="relative",c.style.paddingTop=`${0===t?"42":t+6}px`,e.forEach((e=>{const n=e.getBoundingClientRect().height||0;console.log(t,n,6),e.style.position="absolute",e.style.top=`-${0===t?"42":t+n}px`,e.style.zIndex="1",e.style.pointerEvents="none",e.style.padding="0",e.style.boxSizing="border-box",e.style.whiteSpace="nowrap",e.style.wordBreak="normal",e.style.maxWidth="none",e.style.width="max-content";const a=e.dataset.capType;"min"===a?("ltr"===i?(e.style.left="10px",e.style.textAlign="left"):(e.style.right="10px",e.style.textAlign="right"),e.style.transform="none"):"max"===a?("ltr"===i?(e.style.right="10px",e.style.textAlign="right"):(e.style.left="10px",e.style.textAlign="left"),e.style.transform="none"):(e.style.left="50%",e.style.transform="translateX(-50%)",e.style.textAlign="center")})),c.style.overflow="visible"})),l}(y,A,O,N,x,h,d,L);break;case n.FEEDBACKAPPANSWERTYPE.RATING_STAR:m=document.createElement("div"),h="magicfeedback-rating-star";const U=function(e,t,i,n=()=>{},a){const s="magicfeedback-rating-star-selected",r=document.createElement("div");r.classList.add("magicfeedback-rating-star-container"),r.style.maxWidth="300px",r.style.margin="auto",r.dataset.originalSelection="0";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"),a&&a===o.value&&(o.checked=!0),o.addEventListener("change",(()=>{const e=r.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);r.dataset.originalSelection=o.value,n&&n()})),i.appendChild(o);const l=document.createElement("label");l.htmlFor=`rating-${e}-${t}`,l.classList.add("rating__star"),l.textContent="★",l.style.fontSize="40px",l.style.color="#CCCCCC",l.style.cursor="pointer",l.addEventListener("mouseenter",(()=>{const e=r.querySelectorAll(".rating__star"),i=t-1;e.forEach(((e,t)=>{t<=i?e.classList.contains(s)||e.classList.add(s):e.classList.contains(s)&&e.classList.remove(s)}))})),l.addEventListener("mouseleave",(()=>{const e=Number(r.dataset.originalSelection||"0");r.querySelectorAll(".rating__star").forEach(((t,i)=>{i<e?t.classList.contains(s)||t.classList.add(s):t.classList.contains(s)&&t.classList.remove(s)}))})),i.appendChild(l),r.appendChild(i)}return r.appendChild(o(1,5,t,i,!1,!1)),r}(y,null==A?void 0:A.minPlaceholder,null==A?void 0:A.maxPlaceholder,d,L);m.appendChild(U);break;case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:m=document.createElement("div"),h="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 Q=E.length;let j=1,K=1;if(window.innerWidth<600)j=1,K=Q;else switch(Q){case 1:case 2:case 3:j=Q,K=1;break;case 4:case 5:case 6:K=2,j=Math.ceil(Q/K);break;case 7:case 8:case 9:K=3,j=Math.ceil(Q/K);break;default:K=4,j=Math.ceil(Q/K)}const G=void 0!==(null==A?void 0:A.addTitle)&&(null==A?void 0:A.addTitle),Y=void 0!==(null==A?void 0:A.multiOption)&&(null==A?void 0:A.multiOption),z=void 0!==(null==A?void 0:A.extraOption)&&(null==A?void 0:A.extraOption);function H(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/j}% - 10px)`,a.style.height=`calc( ${100/K}% - 10px)`,a.style.margin="5px";const s=document.createElement("label");s.htmlFor=`rating-${y}-${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 r=document.createElement("label");r.textContent=n,r.classList.add("magicfeedback-multiple-choice-image-label");const o=document.createElement("input");o.id=`rating-${y}-${t}`,o.type=Y?"checkbox":"radio",o.name=y,o.value=n,o.style.position="absolute",o.style.opacity="0",o.style.width="0",o.style.height="0",o.classList.add("magicfeedback-input"),L&&L===o.value&&(o.checked=!0),!Y&&d&&o.addEventListener("change",(()=>{console.log("send"),d()}));const l=document.createElement("img");l.classList.add("magicfeedback-multiple-choice-image-image"),l.src=i,l.style.cursor="pointer",l.style.backgroundSize="cover",l.style.backgroundPosition="center",l.style.width="100%",l.style.height="100%",l.style.objectFit="cover",l.style.margin="auto",s.appendChild(o),s.appendChild(l),G&&s.appendChild(r),a.appendChild(s),W.appendChild(a)}catch(e){console.error(e)}}S&&(E=E.sort((()=>Math.random()-.5))),E.forEach((e=>H(JSON.parse(e)))),z&&(null==A?void 0:A.extraOptionValue)&&(null==A?void 0:A.extraOptionValue.length)>0&&H(null==A?void 0:A.extraOptionValue[0]),m.appendChild(W);break;case n.FEEDBACKAPPANSWERTYPE.SELECT:m=document.createElement("select"),h="magicfeedback-select";const V=document.createElement("option");V.value="",V.text="slim"===t?r(g,i):k||"Select an option",V.disabled=!0,V.selected=!0,m.appendChild(V),E.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,m.appendChild(t)})),L&&E.includes(L)&&(m.value=L),d&&m.addEventListener("change",(()=>{d()}));break;case n.FEEDBACKAPPANSWERTYPE.DATE:m=document.createElement("input"),m.type="date",m.required=b,m.placeholder=T||a.placeholder.date(i||"en"),h="magicfeedback-date",L&&(m.value=L);break;case n.FEEDBACKAPPANSWERTYPE.CONSENT:m=document.createElement("input"),h="magicfeedback-consent",m.type="checkbox",m.id=`magicfeedback-${f}`,m.name=y,m.value="true",m.required=b,m.classList.add("magicfeedback-consent"),m.classList.add("magicfeedback-input"),L&&E.includes(L)&&(m.checked=!0),d&&m.addEventListener("change",(()=>{d()}));break;case n.FEEDBACKAPPANSWERTYPE.EMAIL:m=document.createElement("input"),m.type="email",m.required=b,m.placeholder=T||"you@example.com",h="magicfeedback-email",L&&(m.value=L);break;case n.FEEDBACKAPPANSWERTYPE.PASSWORD:m=document.createElement("input"),m.type="password",m.required=b,m.placeholder=T||a.placeholder.password(i||"en"),h="magicfeedback-password",L&&(m.value=L);break;case n.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:m=document.createElement("div"),h="magicfeedback-multi-question-matrix";const X=document.createElement("div");X.classList.add("magicfeedback-multi-question-matrix-container");let J=(null==A?void 0:A.options)||[],Z=[...E],ee=[];if(S&&(J=null==J?void 0:J.sort((()=>Math.random()-.5)),Z=[...Z].sort((()=>Math.random()-.5))),(null==A?void 0:A.exclusiveAnswers)&&(ee=null==A?void 0:A.exclusiveAnswers,null==ee||ee.forEach((e=>{Z.includes(e)||Z.push(e)}))),window.innerWidth<600){const ke=document.createElement("div");ke.classList.add("magicfeedback-multi-question-matrix-list"),null==J||J.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),Z.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=`${y}-${e}-${i}`,s.type="radio",s.name=`${y}-${e}`,s.value=i,s.classList.add("magicfeedback-input"),a.textContent=i,a.htmlFor=`${y}-${e}-${i}`,n.appendChild(s),n.appendChild(a),t.appendChild(n)})),ke.appendChild(t)})),X.appendChild(ke)}else{const Ae=document.createElement("table");Ae.classList.add("magicfeedback-multi-question-matrix-table");const Ce=document.createElement("thead");Ce.classList.add("magicfeedback-multi-question-matrix-header"),Ce.style.paddingBottom="15px";const xe=document.createElement("tr"),Te=document.createElement("th");xe.appendChild(Te),Z.forEach((e=>{const t=document.createElement("th");t.textContent=e,xe.appendChild(t)})),Ce.appendChild(xe),Ae.appendChild(Ce);const Le=document.createElement("tbody");null==J||J.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",i.style.padding="10px";const n=document.createElement("label");n.classList.add("magicfeedback-multi-question-matrix-label"),n.textContent=e,i.appendChild(n),t.appendChild(i),Z.forEach((i=>{const n=document.createElement("td"),a=document.createElement("input");a.type="radio",a.name=`${y}-${e}`,a.value=i,a.id=`${y}-${e}-${i}`,a.classList.add("magicfeedback-input"),n.appendChild(a),t.appendChild(n)})),Le.appendChild(t)})),Ae.appendChild(Le),X.appendChild(Ae)}m.appendChild(X);break;case n.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:m=document.createElement("div"),h="magicfeedback-priority-list";const te=function(e){const{value:t,ref:i,randomPosition:n=!1,limitPriority:a=!1,maxPriority:s=0,language:r="en"}=e,o=e=>{const t={en:{selectUpTo:"Select up to",options:"options",thenOrder:"and then order them",selectOptions:"Select options",cancel:"Cancel",confirm:"Confirm",selectOptionNumber:"Select option #",prioritized:"Prioritized",of:"of"},es:{selectUpTo:"Selecciona hasta",options:"opciones",thenOrder:"y luego ordénalas",selectOptions:"Seleccionar opciones",cancel:"Cancelar",confirm:"Confirmar",selectOptionNumber:"Selecciona la opción #",prioritized:"Has priorizado",of:"de"},fr:{selectUpTo:"Sélectionnez jusqu’à",options:"options",thenOrder:"puis ordonnez-les",selectOptions:"Sélectionner des options",cancel:"Annuler",confirm:"Confirmer",selectOptionNumber:"Sélectionnez l’option #",prioritized:"Priorisé",of:"sur"},de:{selectUpTo:"Wählen Sie bis zu",options:"Optionen",thenOrder:"und ordnen Sie sie anschließend",selectOptions:"Optionen auswählen",cancel:"Abbrechen",confirm:"Bestätigen",selectOptionNumber:"Option # auswählen",prioritized:"Priorisiert",of:"von"},it:{selectUpTo:"Seleziona fino a",options:"opzioni",thenOrder:"e poi ordinare",selectOptions:"Seleziona opzioni",cancel:"Annulla",confirm:"Conferma",selectOptionNumber:"Seleziona l’opzione #",prioritized:"Hai dato priorità",of:"di"},pt:{selectUpTo:"Selecione até",options:"opções",thenOrder:"e depois ordene",selectOptions:"Selecionar opções",cancel:"Cancelar",confirm:"Confirmar",selectOptionNumber:"Selecione a opção #",prioritized:"Priorizado",of:"de"},da:{selectUpTo:"Vælg op til",options:"muligheder",thenOrder:"og ordne dem derefter",selectOptions:"Vælg muligheder",cancel:"Annuller",confirm:"Bekræfte",selectOptionNumber:"Vælg mulighed #",prioritized:"Prioriteret",of:"af"},fi:{selectUpTo:"Valitse enintään",options:"vaihtoehtoa",thenOrder:"ja järjestä ne sitten",selectOptions:"Valitse vaihtoehdot",cancel:"Peruuta",confirm:"Vahvista",selectOptionNumber:"Valitse vaihtoehto #",prioritized:"Priorisoitu",of:" / "},sv:{selectUpTo:"Välj upp till",options:"alternativ",thenOrder:"och ordna dem sedan",selectOptions:"Välj alternativ",cancel:"Avbryt",confirm:"Bekräfta",selectOptionNumber:"Välj alternativ #",prioritized:"Prioriterat",of:"av"},no:{selectUpTo:"Velg opptil",options:"alternativer",thenOrder:"og ordne dem deretter",selectOptions:"Velg alternativer",cancel:"Avbryt",confirm:"Bekreft",selectOptionNumber:"Velg alternativ #",prioritized:"Prioritert",of:"av"}};return t[t[r]?r:"en"][e]},l=document.createElement("div");if(l.classList.add("magicfeedback-priority-list-container"),a&&s&&s>0){const e=[],a=document.createElement("div");a.classList.add("magicfeedback-priority-list-header");const r=document.createElement("div");r.classList.add("magicfeedback-priority-list-instruction"),r.textContent=`${o("selectUpTo")} ${s} ${o("options")} ${o("thenOrder")} (0/${s})`;const d=document.createElement("button");d.type="button",d.textContent=o("selectOptions"),d.classList.add("magicfeedback-button"),d.classList.add("magicfeedback-priority-list-open-btn"),a.appendChild(r),a.appendChild(d);const c=document.createElement("div");c.classList.add("magicfeedback-priority-list-reorder");const u=document.createElement("ul");u.classList.add("magicfeedback-priority-list-list"),c.appendChild(u);const p=()=>{u.innerHTML="",e.forEach(((t,n)=>{const a=document.createElement("li");a.classList.add("magicfeedback-priority-list-item");const s=document.createElement("input");s.classList.add("magicfeedback-input-magicfeedback-priority-list"),s.classList.add("magicfeedback-input"),s.type="hidden",s.id=`priority-list-${i}`,s.name=i,s.value=`${n+1}. ${t}`,a.appendChild(s);const r=document.createElement("label");r.classList.add("magicfeedback-priority-list-item-label"),r.textContent=`${n+1}. ${t}`,a.appendChild(r);const o=document.createElement("div");o.classList.add("magicfeedback-priority-list-arrows");const l=document.createElement("img");l.classList.add("magicfeedback-priority-list-arrow-up"),l.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",l.style.visibility=0===n?"hidden":"visible";const d=document.createElement("img");d.classList.add("magicfeedback-priority-list-arrow-down"),d.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",d.style.transform="rotate(180deg)",d.style.visibility=n===e.length-1?"hidden":"visible",l.addEventListener("click",(()=>{var i,n,o,c;const p=a.previousElementSibling;if(p){const m=Number(null===(i=s.value)||void 0===i?void 0:i.split(".")[0])-1;s.value=`${m}. ${t}`,r.textContent=`${m}. ${t}`,l.style.visibility=1===m?"hidden":"visible",d.style.visibility=m===e.length?"hidden":"visible";const h=p.querySelector(".magicfeedback-input-magicfeedback-priority-list"),f=p.querySelector(".magicfeedback-priority-list-item-label"),g=p.querySelector(".magicfeedback-priority-list-arrow-up"),v=p.querySelector(".magicfeedback-priority-list-arrow-down");if(h&&f&&g&&v){const t=Number(null===(n=h.value)||void 0===n?void 0:n.split(".")[0])+1;h.value=`${t}.${null===(o=f.textContent)||void 0===o?void 0:o.split(".")[1]}`,f.textContent=`${t}.${null===(c=f.textContent)||void 0===c?void 0:c.split(".")[1]}`,g.style.visibility=1===t?"hidden":"visible",v.style.visibility=t===e.length?"hidden":"visible"}u.insertBefore(a,p)}})),d.addEventListener("click",(()=>{var i,n,o;const c=a.nextElementSibling;if(c){const p=Number(null===(i=s.value)||void 0===i?void 0:i.split(".")[0])+1;s.value=`${p}. ${t}`,r.textContent=`${p}. ${t}`,l.style.visibility=1===p?"hidden":"visible",d.style.visibility=p===e.length?"hidden":"visible";const m=c.querySelector(".magicfeedback-input-magicfeedback-priority-list"),h=c.querySelector(".magicfeedback-priority-list-item-label"),f=c.querySelector(".magicfeedback-priority-list-arrow-up"),g=c.querySelector(".magicfeedback-priority-list-arrow-down");if(m&&h&&f&&g){const t=Number(m.value.split(".")[0])-1;m.value=`${t}.${null===(n=h.textContent)||void 0===n?void 0:n.split(".")[1]}`,h.textContent=`${t}.${null===(o=h.textContent)||void 0===o?void 0:o.split(".")[1]}`,f.style.visibility=1===t?"hidden":"visible",g.style.visibility=t===e.length?"hidden":"visible"}u.insertBefore(c,a)}})),o.appendChild(l),o.appendChild(d),a.appendChild(o),u.appendChild(a)}))},m=document.createElement("div");m.classList.add("magicfeedback-modal-backdrop"),m.style.position="fixed",m.style.top="0",m.style.left="0",m.style.width="100vw",m.style.height="100vh",m.style.background="rgba(0,0,0,0.4)",m.style.display="none",m.style.alignItems="center",m.style.justifyContent="center",m.style.zIndex="9999";const h=document.createElement("div");h.classList.add("magicfeedback-modal"),h.style.background="#fff",h.style.borderRadius="8px",h.style.boxShadow="0 8px 24px rgba(0,0,0,0.2)",h.style.maxWidth="520px",h.style.width="90%",h.style.maxHeight="80vh",h.style.overflow="auto",h.style.padding="16px",h.style.position="relative";const f=document.createElement("h5");f.classList.add("magicfeedback-modal-title");const g=()=>Math.min(e.length+1,s),v=()=>{f.textContent=`${o("selectOptionNumber")}${g()}`};v();const y=document.createElement("div");y.classList.add("magicfeedback-modal-list"),(n?[...t].sort((()=>Math.random()-.5)):[...t]).forEach((t=>{const n=document.createElement("label");n.classList.add("magicfeedback-modal-row");const a=document.createElement("input");a.type="checkbox",a.classList.add("magicfeedback-input"),a.name=`${i}-selection`,a.value=t;const l=document.createElement("span");l.textContent=t,a.addEventListener("change",(()=>{if(a.checked){if(e.length>=s)return a.checked=!1,n.classList.add("magicfeedback-warning"),void setTimeout((()=>{n.classList.remove("magicfeedback-warning")}),800);e.push(t)}else{const i=e.indexOf(t);-1!==i&&e.splice(i,1)}r.textContent=`${o("selectUpTo")} ${s} ${o("options")} ${o("thenOrder")} (${e.length}/${s})`,v(),k()})),n.appendChild(a),n.appendChild(l),y.appendChild(n)}));const b=document.createElement("div");b.classList.add("magicfeedback-modal-actions");const E=document.createElement("div");E.classList.add("magicfeedback-modal-counter");const k=()=>{const t=o("of");E.textContent=`${o("prioritized")} ${e.length} ${t} ${s}`};k();const A=document.createElement("button");A.type="button",A.classList.add("magicfeedback-modal-close"),A.setAttribute("aria-label",o("cancel")),A.title=o("cancel"),A.textContent="×",A.addEventListener("click",(()=>{m.style.display="none"}));const C=document.createElement("button");return C.type="button",C.textContent=o("confirm"),C.classList.add("magicfeedback-button"),C.classList.add("magicfeedback-button-primary"),C.addEventListener("click",(()=>{m.style.display="none",p()})),b.appendChild(E),b.appendChild(C),h.appendChild(A),h.appendChild(f),h.appendChild(y),h.appendChild(b),m.appendChild(h),d.addEventListener("click",(()=>{m.style.display="flex",v(),k()})),m.addEventListener("click",(e=>{e.target===m&&(m.style.display="none")})),l.appendChild(a),l.appendChild(c),l.appendChild(m),p(),l}const d=document.createElement("ul");d.classList.add("magicfeedback-priority-list-list");const c=n?[...t].sort((()=>Math.random()-.5)):[...t];return c.forEach(((e,t)=>{const n=document.createElement("li");n.classList.add("magicfeedback-priority-list-item"),n.style.display="flex",n.style.justifyContent="space-between",n.style.alignItems="center",n.style.margin="5px";const a=document.createElement("input");a.classList.add("magicfeedback-input-magicfeedback-priority-list"),a.classList.add("magicfeedback-input"),a.type="hidden",a.id=`priority-list-${i}`,a.name=i,a.value=`${t+1}. ${e}`,n.appendChild(a);const s=document.createElement("label");s.classList.add("magicfeedback-priority-list-item-label"),s.textContent=`${t+1}. ${e}`,n.appendChild(s);const r=document.createElement("div");r.style.display="flex",r.style.alignItems="center",r.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,i,r,u;const p=n.previousElementSibling;if(p){const m=Number(null===(t=a.value)||void 0===t?void 0:t.split(".")[0])-1;a.value=`${m}. ${e}`,s.textContent=`${m}. ${e}`,o.style.visibility=1===m?"hidden":"visible",l.style.visibility=m===c.length?"hidden":"visible";const h=p.querySelector(".magicfeedback-input-magicfeedback-priority-list"),f=p.querySelector(".magicfeedback-priority-list-item-label"),g=p.querySelector(".magicfeedback-priority-list-arrow-up"),v=p.querySelector(".magicfeedback-priority-list-arrow-down");if(h&&f&&g&&v){const e=Number(null===(i=h.value)||void 0===i?void 0:i.split(".")[0])+1;h.value=`${e}.${null===(r=f.textContent)||void 0===r?void 0:r.split(".")[1]}`,f.textContent=`${e}.${null===(u=f.textContent)||void 0===u?void 0:u.split(".")[1]}`,g.style.visibility=1===e?"hidden":"visible",v.style.visibility=e===c.length?"hidden":"visible"}d.insertBefore(n,p)}}));const l=document.createElement("img");l.classList.add("magicfeedback-priority-list-arrow-down"),l.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",l.style.width="20px",l.style.height="20px",l.style.cursor="pointer",l.style.margin="0 5px",l.style.color="#000",l.style.transform="rotate(180deg)",l.style.visibility=t===c.length-1?"hidden":"visible",l.addEventListener("click",(()=>{var t,i,r;const u=n.nextElementSibling;if(u){const p=Number(null===(t=a.value)||void 0===t?void 0:t.split(".")[0])+1;a.value=`${p}. ${e}`,s.textContent=`${p}. ${e}`,o.style.visibility=1===p?"hidden":"visible",l.style.visibility=p===c.length?"hidden":"visible";const m=u.querySelector(".magicfeedback-input-magicfeedback-priority-list"),h=u.querySelector(".magicfeedback-priority-list-item-label"),f=u.querySelector(".magicfeedback-priority-list-arrow-up"),g=u.querySelector(".magicfeedback-priority-list-arrow-down");if(m&&h&&f&&g){const e=Number(m.value.split(".")[0])-1;m.value=`${e}.${null===(i=h.textContent)||void 0===i?void 0:i.split(".")[1]}`,h.textContent=`${e}.${null===(r=h.textContent)||void 0===r?void 0:r.split(".")[1]}`,f.style.visibility=1===e?"hidden":"visible",g.style.visibility=e===c.length?"hidden":"visible"}d.insertBefore(u,n)}})),r.appendChild(o),r.appendChild(l),n.appendChild(r),d.appendChild(n)})),l.appendChild(d),l}({value:E,ref:y,randomPosition:S,limitPriority:(null==A?void 0:A.limitPriority)||!1,maxPriority:(null==A?void 0:A.maxPriority)||0,language:i||"en"});m.appendChild(te);break;case n.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:m=document.createElement("div"),h="magicfeedback-point-system";const ie=document.createElement("div");ie.classList.add("magicfeedback-point-system-container");const ne=document.createElement("ul");ne.classList.add("magicfeedback-point-system-list"),ne.style.padding="0";const ae=100,se=ae/E.length,re=document.createElement("div");re.classList.add("magicfeedback-error"),re.textContent=a.placeholder.pointsystemerror(i||"en"),re.style.color="#C70039",re.style.fontSize="14px",re.style.textAlign="right",re.style.width="100%",re.style.display="none";const oe=document.createElement("div");oe.classList.add("magicfeedback-point-system-total"),oe.textContent="0 / 100 %",oe.style.textAlign="right",oe.style.fontSize="15px",oe.style.marginTop="5px",E.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=y,s.id=`${e}`,s.type="number",s.min="0",s.max=`${ae}`,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 r=document.createElement("span");r.textContent="%",r.style.color="#000",s.addEventListener("input",(()=>{const e=ne.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>ae&&(s.value=`${se}%`,t-=Number(s.value));const i=document.getElementById("magicfeedback-submit");i&&(t<100?(oe.style.color="orange",i.setAttribute("disabled","true")):(re.style.display="none",oe.style.color="green",i.removeAttribute("disabled"))),oe.textContent=`${t} / 100 %`})),s.addEventListener("focus",(()=>{const e=document.getElementById("magicfeedback-submit");e&&(e.setAttribute("disabled","true"),e.addEventListener("pointerover",(()=>{const e=ne.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t<100&&(re.style.display="block")})))})),a.appendChild(s),a.appendChild(r),i.appendChild(a),ne.appendChild(i)})),ie.appendChild(ne),ie.appendChild(oe),ie.appendChild(re),m.appendChild(ie);break;case n.FEEDBACKAPPANSWERTYPE.INFO_PAGE:m=document.createElement("div"),h="magicfeedback-info-page";const le=document.createElement("div");le.classList.add("magicfeedback-info-message"),le.innerHTML=T,m.appendChild(le);break;case n.FEEDBACKAPPANSWERTYPE.UPLOAD_IMAGE:m=document.createElement("input"),m.type="file",m.accept="image/*",m.required=b,m.multiple=(null==A?void 0:A.multiple)||!1,m.maxLength=(null==A?void 0:A.maxFiles)||1,h="magicfeedback-upload-image";break;case n.FEEDBACKAPPANSWERTYPE.UPLOAD_FILE:m=document.createElement("input"),m.type="file",m.required=b,m.multiple=(null==A?void 0:A.multiple)||!1,m.maxLength=(null==A?void 0:A.maxFiles)||1,h="magicfeedback-upload-file";break;default:return C}m.id=`magicfeedback-${f}`,m.setAttribute("name",y),m.classList.add(h),(void 0!==k||null!==L)&&(m.value=L||k),["RADIO","MULTIPLECHOICE"].includes(v)||(m.classList.add("magicfeedback-input"),m.required=b);const I=document.createElement("label");I.setAttribute("for",`magicfeedback-${f}`),I.textContent=r(g,i),I.classList.add("magicfeedback-label");const $=document.createElement("label");if($.textContent=r(null==A?void 0:A.subtitle,i),$.classList.add("magicfeedback-sublabel"),(null===(c=null==A?void 0:A.subtitleStyle)||void 0===c?void 0:c.includes("italic"))&&($.style.fontStyle="italic"),(null===(u=null==A?void 0:A.subtitleStyle)||void 0===u?void 0:u.includes("bold"))&&($.style.fontWeight="bold"),(null===(p=null==A?void 0:A.subtitleStyle)||void 0===p?void 0:p.includes("underline"))&&($.style.textDecoration="underline"),["CONSENT"].includes(v))C.classList.add("magicfeedback-consent-container"),C.appendChild(m),C.appendChild(I),C.appendChild($);else{if("slim"!==t&&(C.appendChild(I),C.appendChild($),void 0!==(null==A?void 0:A.general)&&""!==(null==A?void 0:A.general))){const we=document.createElement("img");we.src=null==A?void 0:A.general,we.classList.add("magicfeedback-image"),we.style.maxWidth="auto",we.style.height="400px",we.style.margin="10px 0",C.appendChild(we)}if("LONGTEXT"===v&&w>0){const Se=document.createElement("div");if(Se.classList.add("magicfeedback-counter"),Se.textContent=`${m.value.length}/${w}`,Se.style.textAlign="right",Se.style.fontSize="15px",Se.style.marginTop="5px",m.addEventListener("input",(()=>{Se.textContent=`${m.value.length}/${w}`})),C.appendChild(m),C.appendChild(Se),(null==A?void 0:A.extraOption)&&(null==A?void 0:A.extraOptionText)){const Ne=document.createElement("div");Ne.classList.add("magicfeedback-skip-container"),Ne.classList.add("magicfeedback-checkbox-container"),Ne.style.display="flex",Ne.style.justifyContent="flex-start";const Oe=document.createElement("input");Oe.classList.add("magicfeedback-skip"),Oe.type="checkbox",Oe.id=`skip-${y}`,Oe.name=y,Oe.value="-",Oe.style.cursor="pointer";const Pe=document.createElement("label");Pe.htmlFor=`skip-${y}`,Pe.textContent=null==A?void 0:A.extraOptionText,Pe.style.fontSize="15px",Pe.style.cursor="pointer",Pe.style.margin="0 5px",Oe.addEventListener("click",(()=>{m.value="-",d&&d()})),Ne.appendChild(Oe),Ne.appendChild(Pe),C.appendChild(Ne)}}else C.appendChild(m)}return C}(h,i,l,`${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 r=document.createElement("button");r.id="magicfeedback-submit",r.type="submit",r.classList.add("magicfeedback-submit"),r.textContent="MAGICSURVEY"===e?a||"Next":i||"Submit";const o=document.createElement("button");return o.id="magicfeedback-back",o.type="button",o.classList.add("magicfeedback-back"),o.textContent=n||"Back",o.addEventListener("click",t),o.addEventListener("click",(()=>{r.removeAttribute("disabled")})),"MAGICSURVEY"===e&&s.appendChild(o),s.appendChild(r),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}},313:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function r(e){try{l(n.next(e))}catch(e){s(e)}}function o(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}l((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(713)),r=a(i(330)),o=i(857),l={Accept:"application/json","Magicfeedback-Sdk-Version":r.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+o.endpoints.sdk.app_info(t,i),{method:"GET",headers:l});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+o.endpoints.sdk.session(t),{method:"GET",headers:l});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+o.endpoints.sdk.app(t,i),{method:"GET",headers:l});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+o.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},l),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+o.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},l),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),""}}))}},256:(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)}}},713:e=>{e.exports=require("cross-fetch")},330:e=>{e.exports=JSON.parse('{"name":"@magicfeedback/native","version":"2.1.7-alpha.2","main":"./dist/magicfeedback-sdk.node.js","browser":"./dist/magicfeedback-sdk.browser.js","types":"./dist/types/src/index.d.ts","repository":{"type":"git","url":"git+ssh://git@github.com/MagicFeedback/magicfeedback-sdk.git"},"author":"farias@magicfeedback.io","license":"MIT","private":false,"scripts":{"dev":"vite","build":"webpack","build:watch":"webpack --watch --mode development","release":"npm publish --access public","release:beta":"npm publish --access public --tag beta","release:alpha":"npm publish --access public --tag alpha","test":"jest","test:watch":"jest --watchAll","coverage":"vitest run --coverage","publish:sdk":"bash publish.sh","publish:sdk:dry-run":"NPM_DRY_RUN=1 bash publish.sh"},"files":["dist"],"devDependencies":{"@babel/preset-typescript":"^7.22.5","@types/node":"^17.0.21","@types/webpack":"^5.28.0","@types/webpack-node-externals":"^2.5.3","c8":"^7.11.0","copy-webpack-plugin":"^11.0.0","jest":"^29.5.0","jest-environment-jsdom":"^29.5.0","jest-fetch-mock":"^3.0.3","nock":"^13.2.4","ts-jest":"^29.1.0","ts-loader":"^9.2.7","ts-node":"^10.7.0","typescript":"^4.6.2","vite":"^2.8.0","vite-plugin-dts":"^0.9.9","vitest":"^0.5.9","webpack":"^5.70.0","webpack-cli":"^4.9.2","webpack-node-externals":"^3.0.0"},"dependencies":{"cross-fetch":"^3.1.5","is-bundling-for-browser-or-node":"^1.1.1"},"description":"MagicFeedbackAI JavaScript Library for [MagicFeedback.io](https://magicfeedback.io/)","bugs":{"url":"https://github.com/MagicFeedback/magicfeedback-sdk/issues"},"homepage":"https://github.com/MagicFeedback/magicfeedback-sdk#readme","directories":{"example":"examples","test":"test"},"style":"./dist/styles/magicfeedback-default.css"}')}},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}(156);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={317:(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.deepdots.com/",t.HOST_API_URL_DEV="https://api-dev.deepdots.com/"},156: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(927));let s=null;s||(s=(0,a.default)()),t.default=s},927:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function r(e){try{l(n.next(e))}catch(e){s(e)}}function o(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const a=i(57),s=i(665),r=i(256),o=i(313),l=i(317);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)?l.HOST_API_URL_DEV:l.HOST_API_URL),e.set("env",null==i?void 0:i.env),t=new r.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,a,s,r=!0,l,d){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:d,completed:r,id:l,feedback:s};try{const e=yield(0,o.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)}}}},79:(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}get(e){return this.items[e]}}},665:(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}}},57:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function r(e){try{l(n.next(e))}catch(e){s(e)}}function o(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const a=i(558),s=i(256),r=i(313),o=i(213),l=i(217),d=i(700),c=i(591),u=i(79),p=i(636);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,customMetaData:[],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 l.PageGraph([]),this.progress=0,this.total=0,this.completed=!1,this.timeToCompleted=0}generate(e,t){var i,a,s,o,l,d,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,r.getForm)(this.url,this.appId,this.publicKey,this.log):yield(0,r.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===(o=n.pages)||void 0===o||o.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===(l=this.formData.pages)||void 0===l?void 0:l.length)||this.formatPages(),null===(d=this.formData.questions)||void 0===d||d.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,[],c.TransitionType.PAGE,(e.position+1).toString(),e.position.toString()),a=new d.Page(e.position.toString(),e.position,this.appId,[e],[n]);null===(i=null===(t=this.formData)||void 0===t?void 0:t.pages)||void 0===i||i.push(a)}));break;case"MAGICFORM":const t=new d.Page("1",1,this.appId,this.formData.questions,[]);this.formData.pages=[t]}}generateContainer(){let e=document.getElementById(this.selector);if(!e&&(e=document.getElementById("magicfeedback-container-"+this.appId),!e))throw new Error(`Element with ID '${this.selector}' not found.`);return e.classList.add("magicfeedback-container"),e.id="magicfeedback-container-"+this.appId,e.innerHTML="",e}generateForm(){var e,t,i,a;return n(this,void 0,void 0,(function*(){try{if(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 l.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 r=document.createElement("div");r.classList.add("magicfeedback-questions"),r.id="magicfeedback-questions-"+this.appId;const d=this.graph.getFirstPage();if(!d)throw new Error("No page found");if(this.total=this.graph.findMaxDepth(),d.elements=(0,o.renderQuestions)(d.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=d.elements)||void 0===i||i.forEach((e=>r.appendChild(e))),s.appendChild(r),this.history.enqueue(d),n.appendChild(s),this.progress=this.total-this.graph.findMaxDepth(d),this.formOptionsConfig.addButton){const e=(0,o.renderActions)(null===(a=this.formData)||void 0===a?void 0:a.identity,(()=>this.back()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);s.appendChild(e)}this.formOptionsConfig.addButton&&s.addEventListener("submit",(e=>{e.preventDefault(),this.send()})),this.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,o.renderStartMessage)(e,this.formOptionsConfig.addButton,this.formOptionsConfig.startButtonText,(()=>this.startForm()));t.appendChild(i),this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,formData:this.formData}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}))}getMetaData(){console.log("Generating meta data",this.formOptionsConfig.customMetaData),this.formOptionsConfig.customMetaData&&(this.feedback.metadata=[...this.feedback.metadata,...this.formOptionsConfig.customMetaData]),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&&![a.FEEDBACKAPPANSWERTYPE.CONSENT,a.FEEDBACKAPPANSWERTYPE.INFO_PAGE].includes(e.type)))){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),!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")}if(e.type===a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX){const i=this.feedback.answers.find((t=>t.key===e.ref));if(!i)throw this.log.err(`The matrix question ${e.ref} is required`),new Error("No response");const n=this.parseMatrixAnswerPre(i),a=Array.isArray(null==t?void 0:t.options)?t.options:[];if(a.length>0){if(a.find((e=>{const t=n.find((t=>t.key===e));return!t||!Array.isArray(t.value)||0===t.value.length})))throw this.log.err(`The matrix question ${e.ref} requires an answer in every row`),new Error("No response")}else if(0===n.length||n.some((e=>!Array.isArray(e.value)||0===e.value.length)))throw this.log.err(`The matrix question ${e.ref} requires an answer in every row`),new Error("No response")}}const r=yield this.pushAnswers(!1);if(!r)throw new Error("No response");this.id=r,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.`),this.feedback.answers=[],[];const t=this.history.back();if(!t){this.log.err("No page found");const t=e.querySelectorAll(".magicfeedback-input"),i=[],n={};return t.forEach((e=>{var t;const a=e,s=a.name;if(!s)return;const r=a.type;if(("radio"===r||"checkbox"===r)&&!a.checked)return;const o=a.value,l=a.classList[0];if((null==l?void 0:l.includes("magicfeedback-priority-list"))||(null===(t=a.id)||void 0===t?void 0:t.startsWith("priority-list-")))return n[s]||(n[s]=[]),void n[s].push(o);const d="magicfeedback-consent"===l?a.checked.toString():o;if(null==d)return;const c={key:s,value:[d]};i.push(c)})),Object.entries(n).forEach((([e,t])=>{const n=t.slice().sort(((e,t)=>Number(e.split(".")[0])-Number(t.split(".")[0])));i.push({key:e,value:n})})),this.feedback.answers=i,i}const i=[];let n=!1;const s=e.querySelectorAll(".magicfeedback-input"),o={};return s.forEach((e=>{const s=e,l=t.questions.find((e=>{var t;return null===(t=s.name)||void 0===t?void 0:t.includes(e.ref)})),d=s.type,c=s.classList[0],u={key:s.name,value:[]},p="magicfeedback-consent"===c?s.checked.toString():s.value;if(u.key&&""!==u.key)switch(null==l?void 0:l.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:""!==p&&("email"===d?(0,r.validateEmail)(p)?(this.feedback.profile.push({key:"email",value:[p]}),u.value.push(p),i.push(u)):(this.log.err("Invalid email"),n=!0):(u.value.push(p),i.push(u)));break;case a.FEEDBACKAPPANSWERTYPE.RADIO:case a.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:case a.FEEDBACKAPPANSWERTYPE.BOOLEAN:s.checked&&(u.value.push(p),i.push(u));break;case a.FEEDBACKAPPANSWERTYPE.CONSENT:u.value.push(s.checked.toString()),i.push(u);break;case a.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:case a.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:case a.FEEDBACKAPPANSWERTYPE.RATING_STAR:s.checked&&(u.value.push(p),i.push(u));break;case a.FEEDBACKAPPANSWERTYPE.SELECT:""!==p&&(u.value.push(p),i.push(u));break;case a.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:"hidden"===d&&(o[u.key]||(o[u.key]=[]),o[u.key].push(p));case a.FEEDBACKAPPANSWERTYPE.UPLOAD_IMAGE:case a.FEEDBACKAPPANSWERTYPE.UPLOAD_FILE:}})),n?[]:(Object.entries(o).forEach((([e,t])=>{if(!t||0===t.length)return;const n=t.slice().sort(((e,t)=>Number(e.split(".")[0])-Number(t.split(".")[0])));i.push({key:e,value:n})})),this.feedback.answers=i,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,o.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,r.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,r.getFollowUpQuestion)(i,n,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e){var t,i,a;return n(this,void 0,void 0,(function*(){const n=this.history.back();if(!n)throw new Error("No page found");const s=n.getFollowupQuestions();if(0===(null==s?void 0:s.length))return void(yield this.renderNextQuestion(e,n));const r=[];for(const e of s){const t=n.questions.find((t=>t.ref===e));if(t){const e=yield this.callFollowUpQuestion(t);e&&r.push(e)}}if(0===r.length)return void(yield this.renderNextQuestion(e,n));const l=new d.Page(n.id,n.position,this.appId,r,n.edges),c=new p.PageNode(n.id,n.position,n.edges,l,r,!0);c.elements=(0,o.renderQuestions)(r,this.formOptionsConfig.questionFormat,null===(t=this.formData)||void 0===t?void 0:t.lang[0],null===(i=this.formData)||void 0===i?void 0:i.product,(()=>this.send())),this.history.enqueue(c),this.progress+=.5,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,s,r,l,d;return n(this,void 0,void 0,(function*(){let n=this.graph.getNextPage(t,this.feedback.answers);if(!n)return void this.finish();const u=n.edges.filter((e=>"PRECONDITIONAL"===e.typeCondition)).sort(((e,t)=>e.position<t.position?-1:e.position>t.position?1:0));if((null==u?void 0:u.length)>0){let t=null;const r=u.map((e=>e.questionRef));for(let e=this.history.size()-1;e>=0;e--){const n=this.history.get(e);if(n&&(t=null===(i=n.answers)||void 0===i?void 0:i.find((e=>r.includes(e.key))),t))break}let o=!u.some((e=>e.transition===c.TransitionType.ALLOW));if(t)for(const i of u){let r=!1;const l=null===(s=this.formData)||void 0===s?void 0:s.questions.find((e=>e.ref===i.questionRef)),d=Array.isArray(t.value)?t.value:[t.value],u=Array.isArray(i.value)?i.value:[i.value];if((null==l?void 0:l.type)===a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX)r=this.evaluateMatrixPreconditional(i,t);else switch(i.typeOperator){case"EQUAL":case"INQ":r=d.some((e=>u.includes(e)));break;case"NOEQUAL":case"NINQ":r=d.every((e=>!u.includes(e)));break;case"GREATER":r=d.some((e=>Number(e)>Number(u[0])));break;case"LESS":r=d.some((e=>Number(e)<Number(u[0])));break;case"GREATEREQUAL":r=d.some((e=>Number(e)>=Number(u[0])));break;case"LESSEQUAL":r=d.some((e=>Number(e)<=Number(u[0])))}if(r)switch(this.feedback.answers=[],i.transition){case c.TransitionType.NEXT:return void(n&&(yield this.renderNextQuestion(e,n)));case c.TransitionType.ALLOW:o=!0}}if(!o)return this.feedback.answers=[],void(n&&(yield this.renderNextQuestion(e,n)))}n.elements=(0,o.renderQuestions)(n.questions,this.formOptionsConfig.questionFormat,null===(r=this.formData)||void 0===r?void 0:r.lang[0],null===(l=this.formData)||void 0===l?void 0:l.product,(()=>this.send())),e.innerHTML="",null===(d=n.elements)||void 0===d||d.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}))}))}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"}))}))}previewQuestion(e,t,i){var n,a;const s=Array.isArray(t)?t:[t];if(!s||0===s.length)throw new Error("[MagicFeedback] No question provided for preview");const r=document.getElementById(e);if(!r)throw new Error(`[MagicFeedback] Element with ID '${e}' not found.`);const{format:l=this.formOptionsConfig.questionFormat||"standard",language:d=(null===(n=this.formData)||void 0===n?void 0:n.lang)&&this.formData.lang[0]||"en",product:c=(null===(a=this.formData)||void 0===a?void 0:a.product)||{customIcons:!1},clearContainer:u=!0,wrap:p=!0}=i||{};u&&(r.innerHTML="");let m=[];try{m=(0,o.renderQuestions)(s,l,d,c)}catch(e){throw this.log.err(e),e}let h=r;if(p){const e=document.createElement("div");e.classList.add("magicfeedback-preview-question"),h.appendChild(e),h=e}return m.forEach((e=>h.appendChild(e))),r}parseMatrixAnswerPre(e){if(!e||!e.value)return[];if(1===e.value.length&&"string"==typeof e.value[0]&&e.value[0].trim().startsWith("["))try{const t=JSON.parse(e.value[0]);if(Array.isArray(t))return t}catch(e){return[]}return Array.isArray(e.value)&&e.value.length>0&&"object"==typeof e.value[0]&&null!==e.value[0]&&"key"in e.value[0]?e.value:[]}evaluateMatrixPreconditional(e,t){const i=Array.isArray(e.value)?e.value:[e.value],n=new Set(e.option||[]),a=this.parseMatrixAnswerPre(t);if(!a.length)return!1;const s=n.size>0?a.filter((e=>n.has(e.key))):a;if(!s.length)return!1;switch(e.typeOperator){case"EQUAL":case"INQ":return s.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.includes(e)))));case"NOEQUAL":case"NINQ":return s.every((e=>(Array.isArray(e.value)?e.value:[e.value]).every((e=>!i.includes(e)))));case"GREATER":return s.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)>Number(t)))))));case"LESS":return s.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)<Number(t)))))));case"GREATEREQUAL":return s.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)>=Number(t)))))));case"LESSEQUAL":return s.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)<=Number(t)))))));default:return!1}}}},700:(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}}},217:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PageGraph=void 0;const n=i(636),a=i(558),s=i(591);t.PageGraph=class{constructor(e){this.nodes=new Map,this.buildGraph(e)}buildGraph(e){e.forEach((e=>{var t;e.integrationPageRoutes&&(e.integrationPageRoutes=(null===(t=e.integrationPageRoutes)||void 0===t?void 0:t.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 i=new n.PageNode(e.id,e.position,e.integrationPageRoutes||[],e,e.integrationQuestions);this.nodes.set(i.id,i)}))}getNodeById(e){return this.nodes.get(e)}getNextEdgeByDefault(e){if(!e)return;const t=e.edges.find((e=>e.typeCondition===s.ConditionType.DIRECT));if(!t||![s.TransitionType.FINISH,s.TransitionType.REDIRECT].includes(t.transition)){if(t&&t.transitionDestiny)return t.transitionDestiny;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((i=>{const n=e.questions.find((e=>e.ref===i.questionRef)),r=null==t?void 0:t.filter((e=>e.key===i.questionRef));if("DIRECT"===i.typeCondition)return!0;if(!r||0===r.length)return!1;if((null==n?void 0:n.type)===a.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX)return this.evaluateMatrixCondition(i,r);const o=Array.isArray(i.value)?i.value:[i.value];switch(i.typeOperator){case s.OperatorType.EQUAL:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.includes(e)))));case s.OperatorType.NOEQUAL:return r.every((e=>(Array.isArray(e.value)?e.value:[e.value]).every((e=>!o.includes(e)))));case s.OperatorType.GREATER:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.some((t=>Number(e)>Number(t)))))));case s.OperatorType.LESS:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.some((t=>Number(e)<Number(t)))))));case s.OperatorType.GREATEREQUAL:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.some((t=>Number(e)>=Number(t)))))));case s.OperatorType.LESSEQUAL:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.some((t=>Number(e)<=Number(t)))))));case s.OperatorType.INQ:return r.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>o.includes(e)))));case s.OperatorType.NINQ:return r.every((e=>(Array.isArray(e.value)?e.value:[e.value]).every((e=>!o.includes(e)))));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=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.filter((e=>e.typeCondition!==s.ConditionType.PRECONDITIONAL))||[]],r=this.getNextEdgeByDefault(e);if(r){const i=this.getNodeById(r);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 a=this.getNodeById(e.transitionDestiny);if(a&&!t.has(a)){const e=i+1,s=new Set(t),r=this.DFSUtil(a,s,e);n=Math.max(n,r)}}return n}parseMatrixAnswer(e){if(!e||!e.value)return[];if(1===e.value.length&&"string"==typeof e.value[0]&&e.value[0].trim().startsWith("["))try{const t=JSON.parse(e.value[0]);if(Array.isArray(t))return t}catch(e){return[]}return Array.isArray(e.value)&&e.value.length>0&&"object"==typeof e.value[0]&&null!==e.value[0]&&"key"in e.value[0]?e.value:[]}evaluateMatrixCondition(e,t){const i=Array.isArray(e.value)?e.value:[e.value],n=new Set(e.option||[]),a=t[0],r=this.parseMatrixAnswer(a);if(!r.length)return!1;const o=n.size>0?r.filter((e=>n.has(e.key))):r;if(!o.length)return!1;switch(e.typeOperator){case s.OperatorType.EQUAL:case s.OperatorType.INQ:return o.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.includes(e)))));case s.OperatorType.NOEQUAL:case s.OperatorType.NINQ:return o.every((e=>(Array.isArray(e.value)?e.value:[e.value]).every((e=>!i.includes(e)))));case s.OperatorType.GREATER:return o.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)>Number(t)))))));case s.OperatorType.LESS:return o.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)<Number(t)))))));case s.OperatorType.GREATEREQUAL:return o.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)>=Number(t)))))));case s.OperatorType.LESSEQUAL:return o.some((e=>(Array.isArray(e.value)?e.value:[e.value]).some((e=>i.some((t=>Number(e)<=Number(t)))))));default:return!1}}}},636:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PageNode=void 0,t.PageNode=class{constructor(e,t,i,n,a,s=!1){this.answers=[],this.id=e,this.position=t,this.edges=i,this.data=n,this.questions=a.sort(((e,t)=>e.position-t.position)),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))}setAnswer(e){this.answers=e}}},591:(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",s.NEXT="NEXT",s.ALLOW="ALLOW",function(e){e.LOGICAL="LOGICAL",e.DIRECT="DIRECT",e.PRECONDITIONAL="PRECONDITIONAL"}(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,r,o,l,d,c,u){this.id=e,this.questionRef=t,this.typeCondition=d||i.LOGICAL,this.typeOperator=a,this.value=s||[],this.transition=r,this.transitionDestiny=o,this.status=n.ACTIVE,this.generatedAt=new Date,this.updatedAt=new Date,this.integrationPageId=l,this.position=c||0,this.option=u||[]}}},558:(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={}))},857:(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"}}},784:(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 % হতে হবে"}}}},213:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.renderStartMessage=t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0;const n=i(558),a=i(784),s="https://survey-dev.magicfeedback.io/assets/emojis";function r(e,t){return e?"object"==typeof e?e[t]||e.en:e:""}function o(e,t,i,n,a,s=!0,r="ltr",o="row"){const l=document.createElement("div");l.classList.add("magicfeedback-rating-placeholder"),l.style.display="flex",l.style.flexDirection=o,l.style.alignItems="center",l.style.justifyContent="space-between",l.style.width=a?`calc(100% - (100% / ${t+1}))`:"100%",l.style.marginRight="auto",s&&window.innerWidth<600&&(l.style.flexDirection="column");const d=document.createElement("span");d.textContent=i,d.classList.add("magicfeedback-rating-placeholder-value"),d.style.fontSize="15px",d.style.textAlign="ltr"===r?"left":"right",d.style.width="50%",(s&&window.innerWidth<600||"column"===o)&&(d.textContent=`${e} = ${i}`,d.style.width="100%",d.style.textAlign="left",d.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"===r?"right":"left",c.style.width="50%",(s&&window.innerWidth<600||"column"===o)&&(c.textContent=`${t} = ${n}`,c.style.width="100%",c.style.textAlign="left",c.style.marginBottom="5px"),"ltr"===r?(i&&l.appendChild(d),n&&l.appendChild(c)):(n&&l.appendChild(c),i&&l.appendChild(d)),l}t.renderQuestions=function e(t,i="standard",l="en",d={customIcons:!1},c){if(!t)throw new Error("[MagicFeedback] No questions provided");const u=[],{customIcons:p,id:m}=d;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=r(h.title,l),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,l,d,c).forEach((e=>{t.appendChild(e)})),u.push(t)}else{const e=function(e,t,i,l,d){var c,u,p;let m,h,{id:f,title:g,type:v,ref:y,require:b,value:E,defaultValue:k,assets:A}=e,C=document.createElement("div");C.classList.add("magicfeedback-div");const x=window.innerWidth<600,T="slim"===t?r(g,i):null==A?void 0:A.placeholder,L=(P=y,new URLSearchParams(window.location.search).get(P)),w=(null==A?void 0:A.maxCharacters)||0,S=void 0!==(null==A?void 0:A.randomPosition)&&(null==A?void 0:A.randomPosition),N=(null==A?void 0:A.direction)||"row",O=(null==A?void 0:A.order)||"ltr";var P;switch(v){case n.FEEDBACKAPPANSWERTYPE.TEXT:m=document.createElement("input"),m.type="text",m.placeholder=T||a.placeholder.answer(i||"en"),L&&(m.value=L),m.addEventListener("keyup",(e=>{e.preventDefault(),console.log(e.key,e),"Enter"===e.key&&d&&d()})),h="magicfeedback-text";break;case n.FEEDBACKAPPANSWERTYPE.LONGTEXT:m=document.createElement("textarea"),m.rows=3,w>0&&(m.maxLength=w),m.placeholder=T||a.placeholder.answer(i||"en"),L&&(m.value=L),h="magicfeedback-longtext";break;case n.FEEDBACKAPPANSWERTYPE.NUMBER:m=document.createElement("input"),m.type="number",m.placeholder="slim"===t?r(g,i):a.placeholder.number(i||"en"),h="magicfeedback-number",E.length&&(E.sort(((e,t)=>Number(e)-Number(t))),m.max=E[E.length-1],m.min=E[0],m.value=E[0]),L&&!isNaN(Number(L))&&(m.value=L);break;case n.FEEDBACKAPPANSWERTYPE.RADIO:case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE:m=document.createElement("div"),h="magicfeedback-"+("MULTIPLECHOICE"===v?"checkbox":"radio");let D=E||[];S&&(D=D.sort((()=>Math.random()-.5)));let R=(null==A?void 0:A.exclusiveAnswers)||[];(null==A?void 0:A.extraOption)&&(R=R.filter((e=>e!==A.extraOptionText))),R.length>0&&(null==R||R.forEach((e=>{D.includes(e)||D.push(e)}))),(null==A?void 0:A.extraOption)&&!D.includes(null==A?void 0:A.extraOptionText)&&D.push(null==A?void 0:A.extraOptionText),D.forEach(((e,t)=>{const s=document.createElement("div");s.classList.add(`magicfeedback-${"MULTIPLECHOICE"===v?"checkbox":"radio"}-container`);const r=document.createElement("label"),o=document.createElement("input");if(o.id=`rating-${y}-${t}`,o.type="MULTIPLECHOICE"===v?"checkbox":"radio",o.name=y,o.value=e,o.classList.add(h),o.classList.add("magicfeedback-input"),v===n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOICE&&(null==A?void 0:A.maxOptions)&&(null==A?void 0:A.maxOptions)>0&&o.addEventListener("change",(()=>{document.querySelectorAll(`input[name="${y}"]:checked`).length>(null==A?void 0:A.maxOptions)&&(o.checked=!1)})),v===n.FEEDBACKAPPANSWERTYPE.RADIO&&d&&(!(null==A?void 0:A.extraOptionText)||(null==A?void 0:A.extraOptionText)&&e!==(null==A?void 0:A.extraOptionText))&&o.addEventListener("change",(()=>{d()})),e!==k&&e!==L||(o.checked=!0),r.textContent=e,r.htmlFor=`rating-${y}-${t}`,o.addEventListener("change",(t=>{const i=document.getElementById(`extra-option-${y}`);t.target.checked&&R.includes(e)?(console.log("exclusiveAnswers",R,e),D.forEach((t=>{t!==e&&(document.querySelector(`input[value="${t}"]`).checked=!1)})),i&&(i.style.display="none")):R.forEach((t=>{t!==e&&(document.querySelector(`input[value="${t}"]`).checked=!1)})),(null==A?void 0:A.extraOption)&&e===(null==A?void 0:A.extraOptionText)&&i&&(i.style.display=t.target.checked?"block":"none")})),s.appendChild(o),s.appendChild(r),m.appendChild(s),(null==A?void 0:A.extraOption)&&e===(null==A?void 0:A.extraOptionText)){const e=document.createElement("input");e.type="text",e.placeholder=(null==A?void 0:A.extraOptionPlaceholder)||a.placeholder.answer(i||"en"),e.classList.add("magicfeedback-extra-option"),e.classList.add("magicfeedback-input"),e.id=`extra-option-${y}`,e.name=`extra-option-${y}`,e.style.display="none",m.appendChild(e)}}));break;case n.FEEDBACKAPPANSWERTYPE.BOOLEAN:m=document.createElement("div"),h="magicfeedback-radio";const F=document.createElement("div");F.classList.add("magicfeedback-boolean-container"),F.style.display="flex",F.style.flexDirection="row",F.style.justifyContent="space-between",F.style.width="70%",F.style.margin="auto",((null==A?void 0:A.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-${y}-${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-${y}-${t}`,n.textContent=e,n.style.margin="0",n.style.padding="0";const a=document.createElement("input");a.id=`rating-${y}-${t}`,a.type="radio",a.name=y,a.value=["Yes","No"][t],a.classList.add(h),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",(()=>{d&&d()})),L&&L.toLowerCase()===a.value.toLowerCase()&&(a.checked=!0),i.appendChild(a),i.appendChild(n),F.appendChild(i)})),m.appendChild(F);break;case n.FEEDBACKAPPANSWERTYPE.RATING_EMOJI:m=document.createElement("div"),h="magicfeedback-rating";const M=document.createElement("div");M.classList.add("magicfeedback-rating-container");const _=(null==A?void 0:A.max)?Number(null==A?void 0:A.max):5,B=(null==A?void 0:A.min)?Number(null==A?void 0:A.min):1,q=o(B,_,null==A?void 0:A.minPlaceholder,null==A?void 0:A.maxPlaceholder,null==A?void 0:A.extraOption);for(let de=B;de<=_;de++){const ce=document.createElement("div");ce.classList.add("magicfeedback-rating-option");const ue=document.createElement("label");ue.htmlFor=`rating-${y}-${de}`,ue.classList.add("magicfeedback-rating-option-label-container");const pe=document.createElement("label");pe.htmlFor=`rating-${y}-${de}`,pe.textContent=de.toString();const me=document.createElement("img");if(me.alt=`face-${y}-${de}`,me.className=`rating-image${de}`,0===B&&10===_)me.src=`${l}/${de}.svg`,me.onerror=()=>me.src=`${s}/${de}.svg`;else if(1===B&&5===_)switch(de){case 1:me.src=`${l}/1.svg`,me.onerror=()=>me.src=`${s}/1.svg`;break;case 2:me.src=`${l}/2.svg`,me.onerror=()=>me.src=`${s}/2.svg`;break;case 3:me.src=`${l}/6.svg`,me.onerror=()=>me.src=`${s}/6.svg`;break;case 4:me.src=`${l}/9.svg`,me.onerror=()=>me.src=`${s}/9.svg`;break;case 5:me.src=`${l}/10.svg`,me.onerror=()=>me.src=`${s}/10.svg`}else{const fe=Math.round(10/(_-B)*(de-B));me.src=`${l}/${fe}.svg`,me.onerror=()=>me.src=`${s}/${fe}.svg`}const he=document.createElement("input");he.id=`rating-${y}-${de}`,he.type="radio",he.name=y,he.value=de.toString(),he.classList.add(h),he.classList.add("magicfeedback-input"),d&&he.addEventListener("change",(()=>{d()})),L&&L===he.value&&(he.checked=!0),ue.appendChild(he),ue.appendChild(me),ue.appendChild(pe),ce.appendChild(ue),M.appendChild(ce)}if((null==A?void 0:A.extraOption)&&(null==A?void 0:A.extraOptionText)){const ge=document.createElement("div");ge.classList.add("magicfeedback-rating-option");const ve=document.createElement("label");ve.htmlFor=`rating-${y}-extra`,ve.classList.add("magicfeedback-rating-option-label-container");const ye=document.createElement("label");ye.htmlFor=`rating-${y}-extra`,ye.textContent=null==A?void 0:A.extraOptionText;const be=document.createElement("img");be.src="https://magicfeedback-c6458-dev.web.app/assets/question.svg",be.alt=`face-${y}-extra`,be.className="magicfeedback-rating-image-extra";const Ee=document.createElement("input");Ee.id=`rating-${y}-extra`,Ee.type="radio",Ee.name=y,Ee.value="-",Ee.classList.add(h),Ee.classList.add("magicfeedback-input"),d&&Ee.addEventListener("change",(()=>{d()})),ve.appendChild(Ee),ve.appendChild(be),ve.appendChild(ye),ge.appendChild(ve),M.appendChild(ge)}m.appendChild(q),m.appendChild(M);break;case n.FEEDBACKAPPANSWERTYPE.RATING_NUMBER:h="magicfeedback-rating-number",m=function(e,t,i,n,a,s,r,o){const l=document.createElement("div");l.classList.add("magicfeedback-rating-number");const d="ltr"===i?n:`${n}-reverse`,c=document.createElement("div");c.classList.add("magicfeedback-rating-number-container"),c.classList.add(`magicfeedback-rating-number-container-${i}`),c.classList.add(`magicfeedback-rating-number-container-${n}`),c.style.display="flex",c.style.flexDirection=d,c.setAttribute("role","radiogroup"),c.setAttribute("aria-label",(null==t?void 0:t.ariaLabel)||"Rating");const u=(null==t?void 0:t.max)?Number(null==t?void 0:t.max):10,p=(null==t?void 0:t.min)?Number(null==t?void 0:t.min):0,m=(null==t?void 0:t.numberPlaceholders)||null,h=!(a||"column"===n);for(let i=p;i<=u;i++){const l=document.createElement("div");l.classList.add("magicfeedback-rating-number-option"),l.classList.add(`magicfeedback-rating-number-option-${n}`);const d=document.createElement("label");if(d.htmlFor=`rating-${e}-${i}`,d.classList.add("magicfeedback-rating-number-option-label-container"),h&&(d.style.position="relative",d.style.overflow="visible"),h){const e=document.createElement("span");e.classList.add("magicfeedback-rating-number-cap"),e.classList.add("magicfeedback-rating-placeholder-value"),e.style.fontSize="14px",e.style.whiteSpace="nowrap",e.style.wordBreak="normal",i===p&&(null==t?void 0:t.minPlaceholder)?(e.textContent=t.minPlaceholder,e.dataset.capType="min"):i===u&&(null==t?void 0:t.maxPlaceholder)?(e.textContent=t.maxPlaceholder,e.dataset.capType="max"):e.dataset.capType="mid",d.appendChild(e)}let f=i.toString();h?m&&m[i]&&!a&&(d.title=m[i]):m&&m[i]?f+=` = ${m[i]}`:i===p&&(null==t?void 0:t.minPlaceholder)?f+=` = ${null==t?void 0:t.minPlaceholder}`:i===u&&(null==t?void 0:t.maxPlaceholder)&&(f+=` = ${null==t?void 0:t.maxPlaceholder}`);const g=document.createElement("input");g.id=`rating-${e}-${i}`,g.type="radio",g.name=e,g.value=i.toString(),g.classList.add(s),g.classList.add("magicfeedback-input"),g.setAttribute("aria-label",`${i}`),r&&g.addEventListener("change",(()=>r())),o&&o===g.value&&(g.checked=!0);const v=document.createElement("label");v.htmlFor=`rating-${e}-${i}`,v.textContent=f,v.classList.add("magicfeedback-rating-number-value"),d.appendChild(g),d.appendChild(v),l.appendChild(d),c.appendChild(l)}if((null==t?void 0:t.extraOption)&&(null==t?void 0:t.extraOptionText)){const n=document.createElement("div");n.classList.add("magicfeedback-rating-number-option");const a=document.createElement("label");if(a.htmlFor=`rating-${e}-extra`,a.classList.add("magicfeedback-rating-number-option-label-container"),h&&(a.style.position="relative",a.style.overflow="visible"),h){const e=document.createElement("span");e.classList.add("magicfeedback-rating-number-cap"),e.dataset.capType="extra",e.style.fontSize="12px",e.style.whiteSpace="nowrap",e.style.wordBreak="normal",a.appendChild(e)}const o=document.createElement("input");o.id=`rating-${e}-extra`,o.type="radio",o.name=e,o.value="-",o.classList.add(s),o.classList.add("magicfeedback-input"),o.setAttribute("aria-label",null==t?void 0:t.extraOptionText),r&&o.addEventListener("change",(()=>r()));const l=document.createElement("label");l.htmlFor=`rating-${e}-extra`,l.textContent=null==t?void 0:t.extraOptionText,l.classList.add("magicfeedback-rating-number-value"),a.appendChild(o),a.appendChild(l),n.appendChild(a),"ltr"===i?c.appendChild(n):c.insertBefore(n,c.firstChild)}return l.appendChild(c),h&&requestAnimationFrame((()=>{const e=Array.from(c.querySelectorAll(".magicfeedback-rating-number-cap"));if(0===e.length)return;let t=0;e.forEach((e=>{var i;if(null===(i=e.textContent)||void 0===i?void 0:i.trim()){const i=e.getBoundingClientRect().height||0;i>t&&(t=i)}})),c.style.position="relative",c.style.paddingTop=`${0===t?"42":t+6}px`,e.forEach((e=>{const n=e.getBoundingClientRect().height||0;console.log(t,n,6),e.style.position="absolute",e.style.top=`-${0===t?"42":t+n}px`,e.style.zIndex="1",e.style.pointerEvents="none",e.style.padding="0",e.style.boxSizing="border-box",e.style.whiteSpace="nowrap",e.style.wordBreak="normal",e.style.maxWidth="none",e.style.width="max-content";const a=e.dataset.capType;"min"===a?("ltr"===i?(e.style.left="10px",e.style.textAlign="left"):(e.style.right="10px",e.style.textAlign="right"),e.style.transform="none"):"max"===a?("ltr"===i?(e.style.right="10px",e.style.textAlign="right"):(e.style.left="10px",e.style.textAlign="left"),e.style.transform="none"):(e.style.left="50%",e.style.transform="translateX(-50%)",e.style.textAlign="center")})),c.style.overflow="visible"})),l}(y,A,O,N,x,h,d,L);break;case n.FEEDBACKAPPANSWERTYPE.RATING_STAR:m=document.createElement("div"),h="magicfeedback-rating-star";const U=function(e,t,i,n=()=>{},a){const s="magicfeedback-rating-star-selected",r=document.createElement("div");r.classList.add("magicfeedback-rating-star-container"),r.style.maxWidth="300px",r.style.margin="auto",r.dataset.originalSelection="0";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"),a&&a===o.value&&(o.checked=!0),o.addEventListener("change",(()=>{const e=r.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);r.dataset.originalSelection=o.value,n&&n()})),i.appendChild(o);const l=document.createElement("label");l.htmlFor=`rating-${e}-${t}`,l.classList.add("rating__star"),l.textContent="★",l.style.fontSize="40px",l.style.color="#CCCCCC",l.style.cursor="pointer",l.addEventListener("mouseenter",(()=>{const e=r.querySelectorAll(".rating__star"),i=t-1;e.forEach(((e,t)=>{t<=i?e.classList.contains(s)||e.classList.add(s):e.classList.contains(s)&&e.classList.remove(s)}))})),l.addEventListener("mouseleave",(()=>{const e=Number(r.dataset.originalSelection||"0");r.querySelectorAll(".rating__star").forEach(((t,i)=>{i<e?t.classList.contains(s)||t.classList.add(s):t.classList.contains(s)&&t.classList.remove(s)}))})),i.appendChild(l),r.appendChild(i)}return r.appendChild(o(1,5,t,i,!1,!1)),r}(y,null==A?void 0:A.minPlaceholder,null==A?void 0:A.maxPlaceholder,d,L);m.appendChild(U);break;case n.FEEDBACKAPPANSWERTYPE.MULTIPLECHOISE_IMAGE:m=document.createElement("div"),h="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 Q=E.length;let j=1,K=1;if(window.innerWidth<600)j=1,K=Q;else switch(Q){case 1:case 2:case 3:j=Q,K=1;break;case 4:case 5:case 6:K=2,j=Math.ceil(Q/K);break;case 7:case 8:case 9:K=3,j=Math.ceil(Q/K);break;default:K=4,j=Math.ceil(Q/K)}const G=void 0!==(null==A?void 0:A.addTitle)&&(null==A?void 0:A.addTitle),Y=void 0!==(null==A?void 0:A.multiOption)&&(null==A?void 0:A.multiOption),z=void 0!==(null==A?void 0:A.extraOption)&&(null==A?void 0:A.extraOption);function H(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/j}% - 10px)`,a.style.height=`calc( ${100/K}% - 10px)`,a.style.margin="5px";const s=document.createElement("label");s.htmlFor=`rating-${y}-${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 r=document.createElement("label");r.textContent=n,r.classList.add("magicfeedback-multiple-choice-image-label");const o=document.createElement("input");o.id=`rating-${y}-${t}`,o.type=Y?"checkbox":"radio",o.name=y,o.value=n,o.style.position="absolute",o.style.opacity="0",o.style.width="0",o.style.height="0",o.classList.add("magicfeedback-input"),L&&L===o.value&&(o.checked=!0),!Y&&d&&o.addEventListener("change",(()=>{console.log("send"),d()}));const l=document.createElement("img");l.classList.add("magicfeedback-multiple-choice-image-image"),l.src=i,l.style.cursor="pointer",l.style.backgroundSize="cover",l.style.backgroundPosition="center",l.style.width="100%",l.style.height="100%",l.style.objectFit="cover",l.style.margin="auto",s.appendChild(o),s.appendChild(l),G&&s.appendChild(r),a.appendChild(s),W.appendChild(a)}catch(e){console.error(e)}}S&&(E=E.sort((()=>Math.random()-.5))),E.forEach((e=>H(JSON.parse(e)))),z&&(null==A?void 0:A.extraOptionValue)&&(null==A?void 0:A.extraOptionValue.length)>0&&H(null==A?void 0:A.extraOptionValue[0]),m.appendChild(W);break;case n.FEEDBACKAPPANSWERTYPE.SELECT:m=document.createElement("select"),h="magicfeedback-select";const V=document.createElement("option");V.value="",V.text="slim"===t?r(g,i):k||"Select an option",V.disabled=!0,V.selected=!0,m.appendChild(V),E.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,m.appendChild(t)})),L&&E.includes(L)&&(m.value=L),d&&m.addEventListener("change",(()=>{d()}));break;case n.FEEDBACKAPPANSWERTYPE.DATE:m=document.createElement("input"),m.type="date",m.required=b,m.placeholder=T||a.placeholder.date(i||"en"),h="magicfeedback-date",L&&(m.value=L);break;case n.FEEDBACKAPPANSWERTYPE.CONSENT:m=document.createElement("input"),h="magicfeedback-consent",m.type="checkbox",m.id=`magicfeedback-${f}`,m.name=y,m.value="true",m.required=b,m.classList.add("magicfeedback-consent"),m.classList.add("magicfeedback-input"),L&&E.includes(L)&&(m.checked=!0),d&&m.addEventListener("change",(()=>{d()}));break;case n.FEEDBACKAPPANSWERTYPE.EMAIL:m=document.createElement("input"),m.type="email",m.required=b,m.placeholder=T||"you@example.com",h="magicfeedback-email",L&&(m.value=L);break;case n.FEEDBACKAPPANSWERTYPE.PASSWORD:m=document.createElement("input"),m.type="password",m.required=b,m.placeholder=T||a.placeholder.password(i||"en"),h="magicfeedback-password",L&&(m.value=L);break;case n.FEEDBACKAPPANSWERTYPE.MULTI_QUESTION_MATRIX:m=document.createElement("div"),h="magicfeedback-multi-question-matrix";const X=document.createElement("div");X.classList.add("magicfeedback-multi-question-matrix-container");let J=(null==A?void 0:A.options)||[],Z=[...E],ee=[];if(S&&(J=null==J?void 0:J.sort((()=>Math.random()-.5)),Z=[...Z].sort((()=>Math.random()-.5))),(null==A?void 0:A.exclusiveAnswers)&&(ee=null==A?void 0:A.exclusiveAnswers,null==ee||ee.forEach((e=>{Z.includes(e)||Z.push(e)}))),window.innerWidth<600){const ke=document.createElement("div");ke.classList.add("magicfeedback-multi-question-matrix-list"),null==J||J.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),Z.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=`${y}-${e}-${i}`,s.type="radio",s.name=`${y}-${e}`,s.value=i,s.classList.add("magicfeedback-input"),a.textContent=i,a.htmlFor=`${y}-${e}-${i}`,n.appendChild(s),n.appendChild(a),t.appendChild(n)})),ke.appendChild(t)})),X.appendChild(ke)}else{const Ae=document.createElement("table");Ae.classList.add("magicfeedback-multi-question-matrix-table");const Ce=document.createElement("thead");Ce.classList.add("magicfeedback-multi-question-matrix-header"),Ce.style.paddingBottom="15px";const xe=document.createElement("tr"),Te=document.createElement("th");xe.appendChild(Te),Z.forEach((e=>{const t=document.createElement("th");t.textContent=e,xe.appendChild(t)})),Ce.appendChild(xe),Ae.appendChild(Ce);const Le=document.createElement("tbody");null==J||J.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",i.style.padding="10px";const n=document.createElement("label");n.classList.add("magicfeedback-multi-question-matrix-label"),n.textContent=e,i.appendChild(n),t.appendChild(i),Z.forEach((i=>{const n=document.createElement("td"),a=document.createElement("input");a.type="radio",a.name=`${y}-${e}`,a.value=i,a.id=`${y}-${e}-${i}`,a.classList.add("magicfeedback-input"),n.appendChild(a),t.appendChild(n)})),Le.appendChild(t)})),Ae.appendChild(Le),X.appendChild(Ae)}m.appendChild(X);break;case n.FEEDBACKAPPANSWERTYPE.PRIORITY_LIST:m=document.createElement("div"),h="magicfeedback-priority-list";const te=function(e){const{value:t,ref:i,randomPosition:n=!1,limitPriority:a=!1,maxPriority:s=0,language:r="en"}=e,o=e=>{const t={en:{selectUpTo:"Select up to",options:"options",thenOrder:"and then order them",selectOptions:"Select options",cancel:"Cancel",confirm:"Confirm",selectOptionNumber:"Select option #",prioritized:"Prioritized",of:"of"},es:{selectUpTo:"Selecciona hasta",options:"opciones",thenOrder:"y luego ordénalas",selectOptions:"Seleccionar opciones",cancel:"Cancelar",confirm:"Confirmar",selectOptionNumber:"Selecciona la opción #",prioritized:"Has priorizado",of:"de"},fr:{selectUpTo:"Sélectionnez jusqu’à",options:"options",thenOrder:"puis ordonnez-les",selectOptions:"Sélectionner des options",cancel:"Annuler",confirm:"Confirmer",selectOptionNumber:"Sélectionnez l’option #",prioritized:"Priorisé",of:"sur"},de:{selectUpTo:"Wählen Sie bis zu",options:"Optionen",thenOrder:"und ordnen Sie sie anschließend",selectOptions:"Optionen auswählen",cancel:"Abbrechen",confirm:"Bestätigen",selectOptionNumber:"Option # auswählen",prioritized:"Priorisiert",of:"von"},it:{selectUpTo:"Seleziona fino a",options:"opzioni",thenOrder:"e poi ordinare",selectOptions:"Seleziona opzioni",cancel:"Annulla",confirm:"Conferma",selectOptionNumber:"Seleziona l’opzione #",prioritized:"Hai dato priorità",of:"di"},pt:{selectUpTo:"Selecione até",options:"opções",thenOrder:"e depois ordene",selectOptions:"Selecionar opções",cancel:"Cancelar",confirm:"Confirmar",selectOptionNumber:"Selecione a opção #",prioritized:"Priorizado",of:"de"},da:{selectUpTo:"Vælg op til",options:"muligheder.",thenOrder:"Du kan omrangere dem hvis nødvendigt efterfølgende",selectOptions:"Foretag valg til prioritering",cancel:"Annuller",confirm:"Bekræft",selectOptionNumber:"Prioritér dit valg #",prioritized:"Prioriteret",of:"af"},fi:{selectUpTo:"Valitse enintään",options:"vaihtoehtoa",thenOrder:"ja järjestä ne sitten",selectOptions:"Valitse vaihtoehdot",cancel:"Peruuta",confirm:"Vahvista",selectOptionNumber:"Valitse vaihtoehto #",prioritized:"Priorisoitu",of:" / "},sv:{selectUpTo:"Välj upp till",options:"alternativ",thenOrder:"och ordna dem sedan",selectOptions:"Välj alternativ",cancel:"Avbryt",confirm:"Bekräfta",selectOptionNumber:"Välj alternativ #",prioritized:"Prioriterat",of:"av"},no:{selectUpTo:"Velg opptil",options:"alternativer",thenOrder:"og ordne dem deretter",selectOptions:"Velg alternativer",cancel:"Avbryt",confirm:"Bekreft",selectOptionNumber:"Velg alternativ #",prioritized:"Prioritert",of:"av"}};return t[t[r]?r:"en"][e]},l=document.createElement("div");if(l.classList.add("magicfeedback-priority-list-container"),a&&s&&s>0){const e=[],a=document.createElement("div");a.classList.add("magicfeedback-priority-list-header");const r=document.createElement("div");r.classList.add("magicfeedback-priority-list-instruction"),r.textContent=`${o("selectUpTo")} ${s} ${o("options")} ${o("thenOrder")} (0/${s})`;const d=document.createElement("button");d.type="button",d.textContent=o("selectOptions"),d.classList.add("magicfeedback-button"),d.classList.add("magicfeedback-priority-list-open-btn"),a.appendChild(r),a.appendChild(d);const c=document.createElement("div");c.classList.add("magicfeedback-priority-list-reorder");const u=document.createElement("ul");u.classList.add("magicfeedback-priority-list-list"),c.appendChild(u);const p=()=>{u.innerHTML="",e.forEach(((t,n)=>{const a=document.createElement("li");a.classList.add("magicfeedback-priority-list-item");const s=document.createElement("input");s.classList.add("magicfeedback-input-magicfeedback-priority-list"),s.classList.add("magicfeedback-input"),s.type="hidden",s.id=`priority-list-${i}`,s.name=i,s.value=`${n+1}. ${t}`,a.appendChild(s);const r=document.createElement("label");r.classList.add("magicfeedback-priority-list-item-label"),r.textContent=`${n+1}. ${t}`,a.appendChild(r);const o=document.createElement("div");o.classList.add("magicfeedback-priority-list-arrows");const l=document.createElement("img");l.classList.add("magicfeedback-priority-list-arrow-up"),l.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",l.style.visibility=0===n?"hidden":"visible";const d=document.createElement("img");d.classList.add("magicfeedback-priority-list-arrow-down"),d.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",d.style.transform="rotate(180deg)",d.style.visibility=n===e.length-1?"hidden":"visible",l.addEventListener("click",(()=>{var i,n,o,c;const p=a.previousElementSibling;if(p){const m=Number(null===(i=s.value)||void 0===i?void 0:i.split(".")[0])-1;s.value=`${m}. ${t}`,r.textContent=`${m}. ${t}`,l.style.visibility=1===m?"hidden":"visible",d.style.visibility=m===e.length?"hidden":"visible";const h=p.querySelector(".magicfeedback-input-magicfeedback-priority-list"),f=p.querySelector(".magicfeedback-priority-list-item-label"),g=p.querySelector(".magicfeedback-priority-list-arrow-up"),v=p.querySelector(".magicfeedback-priority-list-arrow-down");if(h&&f&&g&&v){const t=Number(null===(n=h.value)||void 0===n?void 0:n.split(".")[0])+1;h.value=`${t}.${null===(o=f.textContent)||void 0===o?void 0:o.split(".")[1]}`,f.textContent=`${t}.${null===(c=f.textContent)||void 0===c?void 0:c.split(".")[1]}`,g.style.visibility=1===t?"hidden":"visible",v.style.visibility=t===e.length?"hidden":"visible"}u.insertBefore(a,p)}})),d.addEventListener("click",(()=>{var i,n,o;const c=a.nextElementSibling;if(c){const p=Number(null===(i=s.value)||void 0===i?void 0:i.split(".")[0])+1;s.value=`${p}. ${t}`,r.textContent=`${p}. ${t}`,l.style.visibility=1===p?"hidden":"visible",d.style.visibility=p===e.length?"hidden":"visible";const m=c.querySelector(".magicfeedback-input-magicfeedback-priority-list"),h=c.querySelector(".magicfeedback-priority-list-item-label"),f=c.querySelector(".magicfeedback-priority-list-arrow-up"),g=c.querySelector(".magicfeedback-priority-list-arrow-down");if(m&&h&&f&&g){const t=Number(m.value.split(".")[0])-1;m.value=`${t}.${null===(n=h.textContent)||void 0===n?void 0:n.split(".")[1]}`,h.textContent=`${t}.${null===(o=h.textContent)||void 0===o?void 0:o.split(".")[1]}`,f.style.visibility=1===t?"hidden":"visible",g.style.visibility=t===e.length?"hidden":"visible"}u.insertBefore(c,a)}})),o.appendChild(l),o.appendChild(d),a.appendChild(o),u.appendChild(a)}))},m=document.createElement("div");m.classList.add("magicfeedback-modal-backdrop"),m.style.position="fixed",m.style.top="0",m.style.left="0",m.style.width="100vw",m.style.height="100vh",m.style.background="rgba(0,0,0,0.4)",m.style.display="none",m.style.alignItems="center",m.style.justifyContent="center",m.style.zIndex="9999";const h=document.createElement("div");h.classList.add("magicfeedback-modal"),h.style.background="#fff",h.style.borderRadius="8px",h.style.boxShadow="0 8px 24px rgba(0,0,0,0.2)",h.style.maxWidth="520px",h.style.width="90%",h.style.maxHeight="80vh",h.style.overflow="auto",h.style.padding="16px",h.style.position="relative";const f=document.createElement("h5");f.classList.add("magicfeedback-modal-title");const g=()=>Math.min(e.length+1,s),v=()=>{f.textContent=`${o("selectOptionNumber")}${g()}`};v();const y=document.createElement("div");y.classList.add("magicfeedback-modal-list"),(n?[...t].sort((()=>Math.random()-.5)):[...t]).forEach((t=>{const n=document.createElement("label");n.classList.add("magicfeedback-modal-row");const a=document.createElement("input");a.type="checkbox",a.classList.add("magicfeedback-input"),a.name=`${i}-selection`,a.value=t;const l=document.createElement("span");l.textContent=t,a.addEventListener("change",(()=>{if(a.checked){if(e.length>=s)return a.checked=!1,n.classList.add("magicfeedback-warning"),void setTimeout((()=>{n.classList.remove("magicfeedback-warning")}),800);e.push(t)}else{const i=e.indexOf(t);-1!==i&&e.splice(i,1)}r.textContent=`${o("selectUpTo")} ${s} ${o("options")} ${o("thenOrder")} (${e.length}/${s})`,v(),k()})),n.appendChild(a),n.appendChild(l),y.appendChild(n)}));const b=document.createElement("div");b.classList.add("magicfeedback-modal-actions");const E=document.createElement("div");E.classList.add("magicfeedback-modal-counter");const k=()=>{const t=o("of");E.textContent=`${o("prioritized")} ${e.length} ${t} ${s}`};k();const A=document.createElement("button");A.type="button",A.classList.add("magicfeedback-modal-close"),A.setAttribute("aria-label",o("cancel")),A.title=o("cancel"),A.textContent="×",A.addEventListener("click",(()=>{m.style.display="none"}));const C=document.createElement("button");return C.type="button",C.textContent=o("confirm"),C.classList.add("magicfeedback-button"),C.classList.add("magicfeedback-button-primary"),C.addEventListener("click",(()=>{m.style.display="none",p()})),b.appendChild(E),b.appendChild(C),h.appendChild(A),h.appendChild(f),h.appendChild(y),h.appendChild(b),m.appendChild(h),d.addEventListener("click",(()=>{m.style.display="flex",v(),k()})),m.addEventListener("click",(e=>{e.target===m&&(m.style.display="none")})),l.appendChild(a),l.appendChild(c),l.appendChild(m),p(),l}const d=document.createElement("ul");d.classList.add("magicfeedback-priority-list-list");const c=n?[...t].sort((()=>Math.random()-.5)):[...t];return c.forEach(((e,t)=>{const n=document.createElement("li");n.classList.add("magicfeedback-priority-list-item"),n.style.display="flex",n.style.justifyContent="space-between",n.style.alignItems="center",n.style.margin="5px";const a=document.createElement("input");a.classList.add("magicfeedback-input-magicfeedback-priority-list"),a.classList.add("magicfeedback-input"),a.type="hidden",a.id=`priority-list-${i}`,a.name=i,a.value=`${t+1}. ${e}`,n.appendChild(a);const s=document.createElement("label");s.classList.add("magicfeedback-priority-list-item-label"),s.textContent=`${t+1}. ${e}`,n.appendChild(s);const r=document.createElement("div");r.style.display="flex",r.style.alignItems="center",r.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,i,r,u;const p=n.previousElementSibling;if(p){const m=Number(null===(t=a.value)||void 0===t?void 0:t.split(".")[0])-1;a.value=`${m}. ${e}`,s.textContent=`${m}. ${e}`,o.style.visibility=1===m?"hidden":"visible",l.style.visibility=m===c.length?"hidden":"visible";const h=p.querySelector(".magicfeedback-input-magicfeedback-priority-list"),f=p.querySelector(".magicfeedback-priority-list-item-label"),g=p.querySelector(".magicfeedback-priority-list-arrow-up"),v=p.querySelector(".magicfeedback-priority-list-arrow-down");if(h&&f&&g&&v){const e=Number(null===(i=h.value)||void 0===i?void 0:i.split(".")[0])+1;h.value=`${e}.${null===(r=f.textContent)||void 0===r?void 0:r.split(".")[1]}`,f.textContent=`${e}.${null===(u=f.textContent)||void 0===u?void 0:u.split(".")[1]}`,g.style.visibility=1===e?"hidden":"visible",v.style.visibility=e===c.length?"hidden":"visible"}d.insertBefore(n,p)}}));const l=document.createElement("img");l.classList.add("magicfeedback-priority-list-arrow-down"),l.src="https://magicfeedback-c6458-dev.web.app/assets/arrow.svg",l.style.width="20px",l.style.height="20px",l.style.cursor="pointer",l.style.margin="0 5px",l.style.color="#000",l.style.transform="rotate(180deg)",l.style.visibility=t===c.length-1?"hidden":"visible",l.addEventListener("click",(()=>{var t,i,r;const u=n.nextElementSibling;if(u){const p=Number(null===(t=a.value)||void 0===t?void 0:t.split(".")[0])+1;a.value=`${p}. ${e}`,s.textContent=`${p}. ${e}`,o.style.visibility=1===p?"hidden":"visible",l.style.visibility=p===c.length?"hidden":"visible";const m=u.querySelector(".magicfeedback-input-magicfeedback-priority-list"),h=u.querySelector(".magicfeedback-priority-list-item-label"),f=u.querySelector(".magicfeedback-priority-list-arrow-up"),g=u.querySelector(".magicfeedback-priority-list-arrow-down");if(m&&h&&f&&g){const e=Number(m.value.split(".")[0])-1;m.value=`${e}.${null===(i=h.textContent)||void 0===i?void 0:i.split(".")[1]}`,h.textContent=`${e}.${null===(r=h.textContent)||void 0===r?void 0:r.split(".")[1]}`,f.style.visibility=1===e?"hidden":"visible",g.style.visibility=e===c.length?"hidden":"visible"}d.insertBefore(u,n)}})),r.appendChild(o),r.appendChild(l),n.appendChild(r),d.appendChild(n)})),l.appendChild(d),l}({value:E,ref:y,randomPosition:S,limitPriority:(null==A?void 0:A.limitPriority)||!1,maxPriority:(null==A?void 0:A.maxPriority)||0,language:i||"en"});m.appendChild(te);break;case n.FEEDBACKAPPANSWERTYPE.POINT_SYSTEM:m=document.createElement("div"),h="magicfeedback-point-system";const ie=document.createElement("div");ie.classList.add("magicfeedback-point-system-container");const ne=document.createElement("ul");ne.classList.add("magicfeedback-point-system-list"),ne.style.padding="0";const ae=100,se=ae/E.length,re=document.createElement("div");re.classList.add("magicfeedback-error"),re.textContent=a.placeholder.pointsystemerror(i||"en"),re.style.color="#C70039",re.style.fontSize="14px",re.style.textAlign="right",re.style.width="100%",re.style.display="none";const oe=document.createElement("div");oe.classList.add("magicfeedback-point-system-total"),oe.textContent="0 / 100 %",oe.style.textAlign="right",oe.style.fontSize="15px",oe.style.marginTop="5px",E.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=y,s.id=`${e}`,s.type="number",s.min="0",s.max=`${ae}`,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 r=document.createElement("span");r.textContent="%",r.style.color="#000",s.addEventListener("input",(()=>{const e=ne.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t>ae&&(s.value=`${se}%`,t-=Number(s.value));const i=document.getElementById("magicfeedback-submit");i&&(t<100?(oe.style.color="orange",i.setAttribute("disabled","true")):(re.style.display="none",oe.style.color="green",i.removeAttribute("disabled"))),oe.textContent=`${t} / 100 %`})),s.addEventListener("focus",(()=>{const e=document.getElementById("magicfeedback-submit");e&&(e.setAttribute("disabled","true"),e.addEventListener("pointerover",(()=>{const e=ne.querySelectorAll("input");let t=0;e.forEach((e=>{t+=Number(e.value)})),t<100&&(re.style.display="block")})))})),a.appendChild(s),a.appendChild(r),i.appendChild(a),ne.appendChild(i)})),ie.appendChild(ne),ie.appendChild(oe),ie.appendChild(re),m.appendChild(ie);break;case n.FEEDBACKAPPANSWERTYPE.INFO_PAGE:m=document.createElement("div"),h="magicfeedback-info-page";const le=document.createElement("div");le.classList.add("magicfeedback-info-message"),le.innerHTML=T,m.appendChild(le);break;case n.FEEDBACKAPPANSWERTYPE.UPLOAD_IMAGE:m=document.createElement("input"),m.type="file",m.accept="image/*",m.required=b,m.multiple=(null==A?void 0:A.multiple)||!1,m.maxLength=(null==A?void 0:A.maxFiles)||1,h="magicfeedback-upload-image";break;case n.FEEDBACKAPPANSWERTYPE.UPLOAD_FILE:m=document.createElement("input"),m.type="file",m.required=b,m.multiple=(null==A?void 0:A.multiple)||!1,m.maxLength=(null==A?void 0:A.maxFiles)||1,h="magicfeedback-upload-file";break;default:return C}m.id=`magicfeedback-${f}`,m.setAttribute("name",y),m.classList.add(h),(void 0!==k||null!==L)&&(m.value=L||k),["RADIO","MULTIPLECHOICE"].includes(v)||(m.classList.add("magicfeedback-input"),m.required=b);const I=document.createElement("label");I.setAttribute("for",`magicfeedback-${f}`),I.textContent=r(g,i),I.classList.add("magicfeedback-label");const $=document.createElement("label");if($.textContent=r(null==A?void 0:A.subtitle,i),$.classList.add("magicfeedback-sublabel"),(null===(c=null==A?void 0:A.subtitleStyle)||void 0===c?void 0:c.includes("italic"))&&($.style.fontStyle="italic"),(null===(u=null==A?void 0:A.subtitleStyle)||void 0===u?void 0:u.includes("bold"))&&($.style.fontWeight="bold"),(null===(p=null==A?void 0:A.subtitleStyle)||void 0===p?void 0:p.includes("underline"))&&($.style.textDecoration="underline"),["CONSENT"].includes(v))C.classList.add("magicfeedback-consent-container"),C.appendChild(m),C.appendChild(I),C.appendChild($);else{if("slim"!==t&&(C.appendChild(I),C.appendChild($),void 0!==(null==A?void 0:A.general)&&""!==(null==A?void 0:A.general))){const we=document.createElement("img");we.src=null==A?void 0:A.general,we.classList.add("magicfeedback-image"),we.style.maxWidth="auto",we.style.height="400px",we.style.margin="10px 0",C.appendChild(we)}if("LONGTEXT"===v&&w>0){const Se=document.createElement("div");if(Se.classList.add("magicfeedback-counter"),Se.textContent=`${m.value.length}/${w}`,Se.style.textAlign="right",Se.style.fontSize="15px",Se.style.marginTop="5px",m.addEventListener("input",(()=>{Se.textContent=`${m.value.length}/${w}`})),C.appendChild(m),C.appendChild(Se),(null==A?void 0:A.extraOption)&&(null==A?void 0:A.extraOptionText)){const Ne=document.createElement("div");Ne.classList.add("magicfeedback-skip-container"),Ne.classList.add("magicfeedback-checkbox-container"),Ne.style.display="flex",Ne.style.justifyContent="flex-start";const Oe=document.createElement("input");Oe.classList.add("magicfeedback-skip"),Oe.type="checkbox",Oe.id=`skip-${y}`,Oe.name=y,Oe.value="-",Oe.style.cursor="pointer";const Pe=document.createElement("label");Pe.htmlFor=`skip-${y}`,Pe.textContent=null==A?void 0:A.extraOptionText,Pe.style.fontSize="15px",Pe.style.cursor="pointer",Pe.style.margin="0 5px",Oe.addEventListener("click",(()=>{m.value="-",d&&d()})),Ne.appendChild(Oe),Ne.appendChild(Pe),C.appendChild(Ne)}}else C.appendChild(m)}return C}(h,i,l,`${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 r=document.createElement("button");r.id="magicfeedback-submit",r.type="submit",r.classList.add("magicfeedback-submit"),r.textContent="MAGICSURVEY"===e?a||"Next":i||"Submit";const o=document.createElement("button");return o.id="magicfeedback-back",o.type="button",o.classList.add("magicfeedback-back"),o.textContent=n||"Back",o.addEventListener("click",t),o.addEventListener("click",(()=>{r.removeAttribute("disabled")})),"MAGICSURVEY"===e&&s.appendChild(o),s.appendChild(r),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}},313:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,s){function r(e){try{l(n.next(e))}catch(e){s(e)}}function o(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}l((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(713)),r=a(i(330)),o=i(857),l={Accept:"application/json","Magicfeedback-Sdk-Version":r.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+o.endpoints.sdk.app_info(t,i),{method:"GET",headers:l});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+o.endpoints.sdk.session(t),{method:"GET",headers:l});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+o.endpoints.sdk.app(t,i),{method:"GET",headers:l});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+o.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},l),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+o.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},l),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),""}}))}},256:(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)}}},713:e=>{e.exports=require("cross-fetch")},330:e=>{e.exports=JSON.parse('{"name":"@magicfeedback/native","version":"2.1.7-alpha.4","main":"./dist/magicfeedback-sdk.node.js","browser":"./dist/magicfeedback-sdk.browser.js","types":"./dist/types/src/index.d.ts","repository":{"type":"git","url":"git+ssh://git@github.com/MagicFeedback/magicfeedback-sdk.git"},"author":"farias@magicfeedback.io","license":"MIT","private":false,"scripts":{"dev":"vite","build":"webpack","build:watch":"webpack --watch --mode development","release":"npm publish --access public","release:beta":"npm publish --access public --tag beta","release:alpha":"npm publish --access public --tag alpha","test":"jest","test:watch":"jest --watchAll","coverage":"vitest run --coverage","publish:sdk":"bash publish.sh","publish:sdk:dry-run":"NPM_DRY_RUN=1 bash publish.sh"},"files":["dist"],"devDependencies":{"@babel/preset-typescript":"^7.22.5","@types/node":"^17.0.21","@types/webpack":"^5.28.0","@types/webpack-node-externals":"^2.5.3","c8":"^7.11.0","copy-webpack-plugin":"^11.0.0","jest":"^29.5.0","jest-environment-jsdom":"^29.5.0","jest-fetch-mock":"^3.0.3","nock":"^13.2.4","ts-jest":"^29.1.0","ts-loader":"^9.2.7","ts-node":"^10.7.0","typescript":"^4.6.2","vite":"^2.8.0","vite-plugin-dts":"^0.9.9","vitest":"^0.5.9","webpack":"^5.70.0","webpack-cli":"^4.9.2","webpack-node-externals":"^3.0.0"},"dependencies":{"cross-fetch":"^3.1.5","is-bundling-for-browser-or-node":"^1.1.1"},"description":"MagicFeedbackAI JavaScript Library for [MagicFeedback.io](https://magicfeedback.io/)","bugs":{"url":"https://github.com/MagicFeedback/magicfeedback-sdk/issues"},"homepage":"https://github.com/MagicFeedback/magicfeedback-sdk#readme","directories":{"example":"examples","test":"test"},"style":"./dist/styles/magicfeedback-default.css"}')}},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}(156);return i.default})()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magicfeedback/native",
3
- "version": "2.1.7-alpha.2",
3
+ "version": "2.1.7-alpha.4",
4
4
  "main": "./dist/magicfeedback-sdk.node.js",
5
5
  "browser": "./dist/magicfeedback-sdk.browser.js",
6
6
  "types": "./dist/types/src/index.d.ts",