if(!customElements.get("dynamic-quotation")){class e extends HTMLElement{constructor(){super(),this.uniqueSuffix="_"+Math.random().toString(36).substr(2,9),this.classList.add(this.uniqueSuffix),this.exchangeRate=1,this.onValidation=()=>{},this.onThinking=()=>{},this.onStopThinking=()=>{},this.onInitialized=()=>{},this.quotationCached={},this.fixedFees={"Fixed Fee":0},this.percentageFees={"Percentage Fee":0},this.minSource=1,this.maxSource=1e3,this.repositionScroll=!0,this.targetChoice=!1,this.minTarget=this.minSource*this.exchangeRate,this.maxTarget=this.maxSource*this.exchangeRate,this.sourceCurrency="USD",this.targetCurrency="SRM",this.source=1,this.target=1*this.exchangeRate,this.feeApplyTo="target",this.showFlag=!0,this.showCurrency=!0,this.components=["source","details","target"],this.i18n={},this.sourceCls="",this.targetCls="",this.detailsCls="",this.sourceDiscountApplied=0,this.sourceInputAllowed=!0,this.targetInputAllowed=!0,this.detailsCollapsed=!0,
this.backendQuotationEndpoint=null,this.flagsEndpoint="https://remesita.s3.amazonaws.com/cdn/currency",
this.defaultStyles=`\n @-webkit-keyframes fadeIn {from {opacity: 0;}to {opacity: 1;}} \n @keyframes fadeIn {from {opacity: 0;}to {opacity: 1;}} \n .${this.uniqueSuffix}{\n -webkit-animation-name: fadeIn;\n animation-name: fadeIn;\n -webkit-animation-duration: .75s;\n animation-duration: .75s;\n -webkit-transition: all .75s ease-in-out;\n transition: all .75s ease-in-out;\n }\n .${this.uniqueSuffix} .quotation-container {\n display: flex;\n flex-direction: column;\n align-items: start;\n }\n .${this.uniqueSuffix} .error {\n border: 1px solid red;\n }\n .${this.uniqueSuffix} .error-caption {\n color: red;\n font-size: 0.8rem;\n padding:2px;\n }\n .${this.uniqueSuffix} .input-caption {\n display: flex;\n background: #157489;\n border-bottom: 1px solid #cccccc;\n border-left: 1px solid #cccccc;\n border-right: 1px solid #cccccc;\n margin-top: -10px;\n z-index:0;\n padding: 12px 8px 8px;\n color: #87c4cd;\n font-size:0.8rem !important;\n border-bottom-left-radius: 5px;\n border-bottom-right-radius: 5px;\n }\n .${this.uniqueSuffix} .no-select {\n user-select: none;\n }\n .${this.uniqueSuffix} .quotation-field-container {\n display: flex;\n margin-bottom: 10px;\n flex-direction: column;\n flex: 100% 0 0;\n width: 100%;\n margin-bottom: 10px; \n }\n .${this.uniqueSuffix} .quotation-field-container label {\n padding-bottom: 3px;\n color: #333;\n }\n .${this.uniqueSuffix} .quotation-field-container.focused label {\n color: #00afd6;\n }\n .${this.uniqueSuffix} .quotation-field-container .quotation-input {\n display: flex;\n justify-content: space-between;\n padding: 10px;\n font-size: 1.2rem;\n border: 1px solid #ccc;\n border-radius: 5px;\n box-shadow: none;\n background-color: transparent; \n }\n .${this.uniqueSuffix} .quotation-field-container input {\n width: 100%;\n flex: 100% 0 1;\n font-size: 1.2rem;\n background: transparent !important;\n border: none !important;\n box-shadow: none !important;\n display: flex;\n }\n .${this.uniqueSuffix} .quotation-field-container select {\n width: 100%;\n flex: 100% 0 1;\n font-size: 1.2rem;\n background: transparent !important;\n border: none !important;\n box-shadow: none !important;\n display: flex;\n }\n .${this.uniqueSuffix} .quotation-field-container select:focus {\n outline: none;\n border: none;\n }\n .${this.uniqueSuffix} .quotation-promo {\n border: 1px solid #077a90;\n padding: 10px;\n border-radius: 5px;\n background: #19363c;\n font-size: 0.8rem;\n cursor:pointer;\n } \n .${this.uniqueSuffix} .quotation-field-container input[type="number"]::-webkit-outer-spin-button, .${this.uniqueSuffix} .quotation-field-container input[type="number"]::-webkit-inner-spin-button {\n -webkit-appearance: none;\n margin: 0;\n }\n .${this.uniqueSuffix} .quotation-field-container input[type="number"] {\n -moz-appearance: textfield; \n }\n .${this.uniqueSuffix} .quotation-field-container input[type="number"]:focus {\n outline: none;\n border: none;\n }\n .${this.uniqueSuffix} .quotation-field-container span {\n width: 40px;\n font-size: .8rem;\n color: gray;\n line-height: 34px;\n padding: 3px;\n font-family: monospace;\n }\n .${this.uniqueSuffix} .quotation-field-container.focused .quotation-input { \n align-items: center;\n border: 2px solid rgb(0, 208, 255) !important;\n background-color: #cacaca21;\n box-shadow: 0px 2px 8px #00afd6;\n }\n .${this.uniqueSuffix} .quotation-field-container.focused .quotation-input input,\n .${this.uniqueSuffix} .quotation-field-container.focused .quotation-input select{ \n display: flex;\n } \n .${this.uniqueSuffix} .quotation-details-container {\n display: block;\n width: 100%;\n margin: auto;\n border: 1px solid #ccc;\n background-color: #f9f9f9;\n border-radius: 5px;\n margin-bottom: 5px;\n font-size: 0.8rem; \n font-family: sans-serif;\n }\n .${this.uniqueSuffix} .quotation-details-container .quotation-details {\n padding-top: 6px;\n padding-bottom: 6px;\n }\n .${this.uniqueSuffix} .quotation-details-container .view-more,\n .${this.uniqueSuffix} .quotation-details-container .view-less{\n display:block;\n width:100%;\n padding:5px;\n color:gray;\n text-align:center;\n cursor:pointer;\n }\n .${this.uniqueSuffix} .quotation-details-container hr{\n width:100%;\n height:0.1px;\n margin: 4px 0px;\n line-height: 1px;\n border-block-color: gray;\n border-top: 0px none;\n height: 0.1rem;\n border-bottom: 1px dashed gray;\n }\n .${this.uniqueSuffix} .quotation-details-container ul ul{\n color: gray;\n }\n .${this.uniqueSuffix} .quotation-details-container .details-error{\n text-align:center;\n padding: 10px;\n font-size: 1.2rem;\n color: red;\n margin-bottom:6px;\n }\n .${this.uniqueSuffix} .loading-border{ overflow: hidden; position:relative; } \n .${this.uniqueSuffix} .loading-border div,\n .${this.uniqueSuffix} .loading-border span,\n .${this.uniqueSuffix} .loading-border input{\n z-index:1\n } \n .${this.uniqueSuffix} .loading-border::after {\n content: "";\n display: block;\n width: calc(100% - 2px);\n height: calc(100% - 2px);\n background: white;\n position: absolute;\n z-index: 1;\n top: 1px;\n left: 1px;\n }\n .${this.uniqueSuffix} .loading-border::before {\n content: "";\n display: block;\n background: linear-gradient(\n 90deg,\n hsla(197, 100%, 64%, 1) 0%,\n hsla(339, 100%, 55%, 1) 100%\n );\n height: 500px;\n width: 500px;\n position: absolute;\n animation: rotate 8s linear infinite;\n z-index: 0;\n }\n @keyframes rotate {\n from {\n transform: rotate(0);\n }\n\n to {\n transform: rotate(360deg);\n }\n }\n .detailless .quotation-details-container{\n display:none !important;\n } \n `,
this.overrideStyles=null,this.totalFees=0}trans(e,t){let i=void 0!==this.i18n[e]?(this.i18n[e]??e).trim():e.trim();if(void 0!==t)for(var e in t)i=i.replace(e,t[e]).trim();return i.trim()}refresh(){const e=$(`#quotationSource${this.uniqueSuffix}`).is(":focus")?"quotationSource":"quotationTarget";this.render(e),this.setupEventHandlers()}render(e){this._componets={source:`
\n
${this.trans("Source amount on _CURRENCY_",{_CURRENCY_:this.sourceCurrency
})} \n
\n \n ${this.showFlag?` `:""}\n ${this.showCurrency?`${this.sourceCurrency} `:""}\n
\n
\n
`,target:`\n
${this.trans("Target amount on _CURRENCY_",{_CURRENCY_:this.targetCurrency
})} \n
\n ${this.targetChoice?`\n ${this.targetChoice.map(((e,t)=>`${e.label.replace(" "+e?.currency,"").trim()} `)).join("")}\n `:` `}\n \n ${this.showFlag?` `:""}\n ${this.showCurrency?`${this.targetCurrency} `:""}\n
\n
\n
\n
\n
`,
details:``};let t=[],i=[];for(var n in this.components.forEach((e=>{t.push(this._componets[e])})),this._componets)this.components.includes(n)||i.push(this._componets[n]);let s="";if(this.overrideStyles)for(let e in this.overrideStyles){let t=[];for(let i in this.overrideStyles[e])t.push(`${i}:${this.overrideStyles[e][i]};`);s+=`.${this.uniqueSuffix} ${e} {${t.join("")}}`}this.innerHTML=`\n \n \n\n \n ${t.join("")}\n
${i.join("")}
\n
\n `,void 0!==e&&$(`#${e}${this.uniqueSuffix}`).focus()}markdownToHTML(e){
const t=(e,t)=>{const i=new RegExp(`(^[\\s]*[${"ul"===t?"-*+":"\\d+"}].+?$)+`,"gm");return e.replace(i,(e=>{const i=e.split("\n").map((e=>{let i=e.trim();return i="ul"===t?i.replace(/^[-*+]\s+/,""):i.replace(/^\d+\.\s+/,""),`${i} `})).join("");return"ul"===t?``:`${i} `}))};let i=e;i=(e=>{const t={"&":"&","<":"<",">":">",'"':""","'":"'"};return e.replace(/[&<>"']/g,(e=>t[e]))})(i),i=i.replace(/^###\s+([^\s]{0,}[^ \n]+?)(?:\s{2,}|\n|$)/gm,((e,t,i,n)=>{const s=`${t} `,a=n.slice(i+e.length).split("\n")[0].trim();return s+(a?`\n${a}`:"")}));for(let e=6;e>=1;e--){const t=new RegExp(`^#{${e}}\\s+(.*)$`,"gm");i=i.replace(t,`$1 `)}return i=i.replace(/\*\*(.*?)\*\*/g,"$1 "),i=i.replace(/__(.*?)__/g,"$1 "),i=i.replace(/\*(.*?)\*/g,"$1 "),i=i.replace(/_(.*?)_/g,"$1 "),i=t(i,"ul"),i=t(i,"ol"),i=i.replace(/```(.*?)```/gs,"$1
"),
i=i.replace(/\n{2,}/g,""),i=i.replace(/#/g,""),i=`
${i}
`,i=i.replace(/\s*<\/p>/g,""),i=i.replace(/<\/p>\s*
/g,"
"),i=i.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'$1 '),i=i.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,' '),i=i.replace(/^> (.*$)/gim,"
$1 "),i=i.replace(/`([^`]+)`/g,"$1
"),i=i.replace(/\s\s+/g," "),i.trim()}setupEventHandlers(){const e=this.querySelector(`#quotationSource${this.uniqueSuffix}`),t=this.querySelector(`#quotationTarget${this.uniqueSuffix}`);e.addEventListener("input",(async()=>{await this.calculateTarget(),this.validateForm()})),t.addEventListener("remex-select"==t.tagName.toLowerCase()?"change":"input",(async()=>{if(this.querySelector(`#quotationTargetPromo${this.uniqueSuffix}`).style.display="none",this.querySelector(`#quotationTargetPromo${this.uniqueSuffix}`).onclick=()=>!1,
"remex-select"==t.tagName.toLowerCase()&&null!=t.selectedItem&&t.selectedItem.attributes.choice&&(this.targetChoiced=this.targetChoice.find((e=>e.id==t.selectedItem.attributes.choice)),this.exchangeRate=parseFloat(t.selectedItem.attributes.exchangerate),this.sourceDiscountApplied=0,this.minSource=0,this.maxSource=1e7,this.targetChoiced?.discount>0&&(this.sourceValue=this.targetChoiced.amount-this.targetChoiced?.discount,this.sourceDiscountApplied=this.targetChoiced?.discount),this.querySelector(`#quotationTargetCaption${this.uniqueSuffix}`).style.display="none",(this.targetChoiced?.caption??"").length>0&&(this.querySelector(`#quotationTargetCaption${this.uniqueSuffix}`).style.display="flex",this.querySelector(`#quotationTargetCaption${this.uniqueSuffix}`).innerHTML=this.targetChoiced?.caption),null!=this.targetChoiced?.promo)){moment&&moment.locale(window.currentLocale??document.querySelector("html").getAttribute("lang")??"es")
;const e=moment?moment(this.targetChoiced?.promo.startDate).format("LLL"):this.targetChoiced?.promo.startDate.split("T")[0],t=moment?moment(this.targetChoiced?.promo.endDate).format("LLL"):this.targetChoiced?.promo.endDate.split("T")[0];this.querySelector(`#quotationTargetPromo${this.uniqueSuffix}`).innerHTML=`${this.targetChoiced?.promo.title} ${this.trans("Promo activa desde")} ${e} ${this.trans("hasta")} ${t} `,this.querySelector(`#quotationTargetPromo${this.uniqueSuffix}`).style.display="block",this.querySelector(`#quotationTargetPromo${this.uniqueSuffix}`).onclick=()=>{$.ajax({type:"GET",url:"/rest/v1/promo/"+this.targetChoiced?.promo.id,success:e=>{window.alertModal(this.targetChoiced?.promo.title,`${this.markdownToHTML(e.description)}
`)}})}}await this.calculateSource()&&this.validateForm()})),[e,e].forEach((e=>{e.addEventListener("focus",(e=>{this.repositionScroll&&setTimeout((()=>{
const t=e.target.getBoundingClientRect();window.scrollTo({top:t.top+window.pageYOffset-20,behavior:"smooth"})}),300)}))})),[e,e].forEach((e=>{e.addEventListener("blur",(()=>{this.repositionScroll&&setTimeout((()=>{window.scrollTo({top:0,behavior:"smooth"})}),300)}))})),setTimeout((()=>{if(this.targetChoice){const e=this.targetChoice.find((e=>null!==e.promo));if(null!=e&&(t.selectedIndex=Math.max(0,this.targetChoice.indexOf(e))),-1==t.selectedIndex){const e=this.targetChoice.find((e=>!0===e.choice));null!=e&&(t.selectedIndex=Math.max(0,this.targetChoice.indexOf(e)))}-1==t.selectedIndex&&(t.selectedIndex=0);const i=new Event("change",{bubbles:!0,cancelable:!0});t.dispatchEvent(i)}}),10)}updateDetails(e,t){this.classList.remove("detailless");const i=this.querySelector(`#quotationDetails${this.uniqueSuffix}`),n=this.getFees();if(e||(e=0),t||(t=0),0==e&&0==t)return i.innerHTML="",i.style.display="none",!1
;let s="display: flex; justify-content: space-between;width: 100%;",a='';if("string"==typeof this.exchangeRate&&(this.exchangeRate=parseFloat(this.exchangeRate)),this.sourceDiscountApplied>0&&(a+=` -${this.sourceDiscountApplied.toFixedIntelligent(4,"BTC"==this.sourceCurrency?8:4)} ${this.sourceCurrency}${this.trans("Discount applied")} `),"target"==this.feeApplyTo){if(this.exchangeRate>=1){let e=1==this.exchangeRate?1:this.exchangeRate.toFixedIntelligent(4,"BTC"==this.targetCurrency?8:4);"BTC"!=this.targetCurrency&&1!=this.exchangeRate&&(e=e.split(".")[0]+`.${e.split(".")[1].substr(0,2)}${e.split(".")[1].substr(2,2)} `),a+=`↳ 1 ${this.sourceCurrency} ⇄ ${e} ${this.targetCurrency} ${this.trans("Exchange Rate _RATE_",{_RATE_:""})} `
}else a+=`↳ 1 ${this.targetCurrency} ⇄ ${(1/this.exchangeRate).toFixedIntelligent(4,"BTC"==this.sourceCurrency?8:4)} ${this.sourceCurrency} ${this.trans("Exchange Rate _RATE_",{_RATE_:""})} `;if(1!=this.exchangeRate&&(n.fixed>0||n.percentage>0)&&(a+=` ${(e*this.exchangeRate).toFixedIntelligent(2,"BTC"==this.targetCurrency?8:2)} ${this.targetCurrency} ${this.trans("Conversion before taxes")} `),a+=` `,n.fixed>0&&n.percentage>0){a+=` -${(e*this.exchangeRate*n.percentage+n.fixed).toFixedIntelligent("BTC"==this.targetCurrency?8:2)} ${this.targetCurrency} ${this.trans("Total commissions")} `,
a+=``;for(let e in n.fixedItems)n.fixedItems[e]>0&&(a+=` -${n.fixedItems[e].toFixedIntelligent(2)} ${this.targetCurrency} ${this.trans(e)} `);for(let t in n.percentageItems){let i=e*this.exchangeRate*n.percentageItems[t];i>0&&(a+=` -${i.toFixedIntelligent("BTC"==this.targetCurrency?8:2)} ${this.targetCurrency} ${this.trans(t,{_RATE_:`(${100*n.percentageItems[t]}%)`})} `)}a+=" ",this.components.includes("target")||(a+=` `,a+=` = ${t.toFixedIntelligent("BTC"==this.sourceCurrency?8:2,"BTC"==this.sourceCurrency?8:2)} ${this.targetCurrency} ${this.trans("Recipient amount")}. `),
a+=` `,a+=`\n ${this.trans("View more")} »
\n ⛌ ${this.trans("View less")}
\n `}else if(n.fixed>0){if(a+=` -${n.fixed.toFixedIntelligent(2)} ${this.targetCurrency} ${this.trans("Fixed Fee")} `,n.fixedItems.length>1){a+=``;for(let e in n.fixedItems)n.fixedItems[e]>0&&(a+=` -${n.fixedItems[e].toFixedIntelligent(2)} ${this.targetCurrency} ${this.trans(e)} `);a+=" "}
this.components.includes("target")||(a+=` `,a+=` = ${t.toFixedIntelligent("BTC"==this.sourceCurrency?8:2,"BTC"==this.sourceCurrency?8:2)} ${this.targetCurrency} ${this.trans("Recipient amount")}. `)}else if(n.percentage>0){if(a+=` -${(e*this.exchangeRate*n.percentage).toFixedIntelligent("BTC"==this.targetCurrency?8:2)} ${this.targetCurrency} ${this.trans("Percentage Fee _RATE_",{_RATE_:`(${100*n.percentage}%)`})} `,n.percentageItems.length>1){a+=``;for(let t in n.percentageItems){let i=e*this.exchangeRate*n.percentageItems[t];i>0&&(a+=` -${i.toFixedIntelligent("BTC"==this.targetCurrency?8:2)} ${this.targetCurrency} ${this.trans(t,{
_RATE_:`(${100*n.percentageItems[t]}%)`})} `)}a+=" "}this.components.includes("target")||(a+=` `,a+=` = ${t.toFixedIntelligent("BTC"==this.sourceCurrency?8:2,"BTC"==this.sourceCurrency?8:2)} ${this.targetCurrency} ${this.trans("Recipient amount")}. `)}else this.components.includes("target")||1==this.exchangeRate||(a+=` `,a+=` = ${t.toFixedIntelligent("BTC"==this.sourceCurrency?8:2,"BTC"==this.sourceCurrency?8:2)} ${this.targetCurrency} ${this.trans("Recipient amount")}. `)}else if(n.fixed>0&&n.percentage>0){if(1!=this.exchangeRate){let t=((e-(this.totalFees??0))*n.percentage+n.fixed).toFixedIntelligent("BTC"==this.sourceCurrency?8:2)
;"BTC"!=this.sourceCurrency&&(t=t.split(".")[0]+`.${t.split(".")[1].substr(0,2)}${t.split(".")[1].substr(2,2)} `),a+=` -${t} ${this.sourceCurrency} ${this.trans("Total commissions")}. `}a+=``;for(let e in n.fixedItems)n.fixedItems[e]>0&&(a+=` -${n.fixedItems[e].toFixedIntelligent(2,"BTC"==this.sourceCurrency?8:4)} ${this.sourceCurrency} ${this.trans(e)} `);for(let t in n.percentageItems){let i=(e-(this.totalFees??0))*n.percentageItems[t];i>0&&(a+=` -${i.toFixedIntelligent(2,"BTC"==this.targetCurrency?8:2)} ${this.sourceCurrency} ${this.trans(t,{_RATE_:`(${100*n.percentageItems[t]}%)`})} `)}if(a+=" ",a+=` `,
a+=` = ${(e-(this.totalFees??0)).toFixedIntelligent(2,"BTC"==this.sourceCurrency?8:2)} ${this.sourceCurrency} ${this.trans("Total conversion")}. `,a+=` `,this.exchangeRate>=1){let e=1==this.exchangeRate?1:this.exchangeRate.toFixedIntelligent(4,"BTC"==this.targetCurrency?8:4);"BTC"!=this.targetCurrency&&1!=this.exchangeRate&&(e=e.split(".")[0]+`.${e.split(".")[1].substr(0,2)}${e.split(".")[1].substr(2,2)} `),a+=`↳ 1 ${this.sourceCurrency} ⇄ ${e} ${this.targetCurrency} ${this.trans("Exchange Rate _RATE_",{_RATE_:""})} `}else a+=`↳ 1 ${this.targetCurrency} ⇄ ${(1/this.exchangeRate).toFixedIntelligent(4,"BTC"==this.sourceCurrency?8:4)} ${this.sourceCurrency} ${this.trans("Exchange Rate _RATE_",{_RATE_:""
})} `;this.components.includes("target")||(a+=` `,a+=` = ${t.toFixedIntelligent("BTC"==this.sourceCurrency?8:2,"BTC"==this.sourceCurrency?8:2)} ${this.targetCurrency} ${this.trans("Recipient amount")}. `),a+=` `,a+=`\n ${this.trans("View more")} »
\n ⛌ ${this.trans("View less")}
\n `}else if(n.fixed>0){if(a+=` -${n.fixed.toFixedIntelligent(2)} ${this.sourceCurrency} ${this.trans("Fixed Fee")} `,n.fixedItems.length>1){
a+=``;for(let e in n.fixedItems)n.fixedItems[e]>0&&(a+=` -${n.fixedItems[e].toFixedIntelligent(2)} ${this.sourceCurrency} ${this.trans(e)}. `);a+=" "}a+=` `,a+=` = ${(e-(this.totalFees??0)).toFixedIntelligent(2,"BTC"==this.sourceCurrency?8:2)} ${this.sourceCurrency} ${this.trans("Total conversion")}. `,this.exchangeRate>=1?a+=`↳ 1 ${this.sourceCurrency} = ${this.exchangeRate.toFixedIntelligent(4,"BTC"==this.targetCurrency?8:4)} ${this.targetCurrency} ${this.trans("Exchange Rate _RATE_",{_RATE_:100*n.percentage>0?`(${100*n.percentage}%)`:""
})}. `:a+=`↳ 1 ${this.targetCurrency} ⇄ ${(1/this.exchangeRate).toFixedIntelligent(4,"BTC"==this.sourceCurrency?8:4)} ${this.sourceCurrency} ${this.trans("Exchange Rate _RATE_",{_RATE_:""})} `,a+=` = ${(e-(this.totalFees??0)).toFixedIntelligent(2,"BTC"==this.sourceCurrency?8:2)} ${this.sourceCurrency} ${this.trans("Total conversion")}. `,this.components.includes("target")||(a+=` `,a+=` = ${t.toFixedIntelligent("BTC"==this.sourceCurrency?8:2,"BTC"==this.sourceCurrency?8:2)} ${this.targetCurrency} ${this.trans("Recipient amount")}. `)}else e*n.percentage?(a+=` -${(e*n.percentage).toFixedIntelligent(2)} ${this.sourceCurrency} ${this.trans("Percentage Fee _RATE_",{
_RATE_:`(${100*n.percentage}%)`})} `,a+=` `,1==this.exchangeRate?a+=`↳ 1 ${this.sourceCurrency} = ${this.exchangeRate.toFixedIntelligent(4,"BTC"==this.targetCurrency?8:4)} ${this.targetCurrency} ${this.trans("Exchange Rate _RATE_",{_RATE_:"(1x1)"}).trim()} `:this.exchangeRate>1?a+=`↳ 1 ${this.sourceCurrency} = ${this.exchangeRate.toFixedIntelligent(4,"BTC"==this.targetCurrency?8:4)} ${this.targetCurrency} ${this.trans("Exchange Rate _RATE_",{_RATE_:`(${100*n.percentage}%)`})}. `:a+=`↳ 1 ${this.targetCurrency} ⇄ ${(1/this.exchangeRate).toFixedIntelligent(4,"BTC"==this.sourceCurrency?8:4)} ${this.sourceCurrency} ${this.trans("Exchange Rate _RATE_",{_RATE_:""})} `,
this.components.includes("target")||(a+=` `,a+=` = ${t.toFixedIntelligent("BTC"==this.sourceCurrency?8:2,"BTC"==this.sourceCurrency?8:2)} ${this.targetCurrency} ${this.trans("Recipient amount")}. `)):this.components.includes("target")||1==this.exchangeRate?1!=this.exchangeRate&&(this.exchangeRate>1?a+=`↳ 1 ${this.sourceCurrency} = ${this.exchangeRate.toFixedIntelligent(4,"BTC"==this.targetCurrency?8:4)} ${this.targetCurrency} ${this.trans("Exchange Rate _RATE_",{_RATE_:100*n.percentage>0?`(${100*n.percentage}%)`:""})} `:a+=`↳ 1 ${this.targetCurrency} ⇄ ${(1/this.exchangeRate).toFixedIntelligent(4,"BTC"==this.sourceCurrency?8:4)} ${this.sourceCurrency} ${this.trans("Exchange Rate _RATE_",{_RATE_:""
})} `):(a+=` `,a+=` = ${t.toFixedIntelligent("BTC"==this.sourceCurrency?8:2,"BTC"==this.sourceCurrency?8:2)} ${this.targetCurrency} ${this.trans("Recipient amount")}. `);a+="",i.innerHTML=a,i.style.display="block",this.querySelector(".view-more")&&this.querySelector(".view-more").addEventListener("click",(()=>{this.querySelectorAll(`.quotationDetailsToggle${this.uniqueSuffix}`).forEach((e=>e.style.display="flex")),this.querySelector(`#viewLess${this.uniqueSuffix}`).style.display="block",this.querySelector(".view-more").style.display="none",this.detailsCollapsed=!1})),this.querySelector(".view-less")&&this.querySelector(".view-less").addEventListener("click",(()=>{this.querySelectorAll(`.quotationDetailsToggle${this.uniqueSuffix}`).forEach((e=>e.style.display="none")),
this.querySelector(`#viewMore${this.uniqueSuffix}`).style.display="block",this.querySelector(".view-less").style.display="none",this.detailsCollapsed=!0})),!this.detailsCollapsed&&this.querySelector(".view-more")&&this.querySelector(".view-more").click()}getFees(){const e={fixed:0,fixedItems:{},percentage:0,percentageItems:{}};if(this.fixedFees){e.fixedItems=this.fixedFees;for(let t in this.fixedFees)e.fixed+=this.fixedFees[t]}if(this.percentageFees){e.percentageItems=this.percentageFees;for(let t in this.percentageFees)e.percentage+=this.percentageFees[t]}return e}setCookie(e,t,i){const n=new Date;n.setTime(n.getTime()+24*i*60*60*1e3);let s="expires="+n.toUTCString();document.cookie=e+"="+t+";"+s+";path=/"}getCookie(e){let t=e+"=",i=decodeURIComponent(document.cookie).split(";");for(let e=0;e{"target"===this.feeApplyTo?(t=e*this.exchangeRate-(this.getFees().fixed+e*this.exchangeRate*this.getFees().percentage),this.totalFees=e*this.exchangeRate-t):(t=(e-(this.getFees().fixed+e*this.getFees().percentage))*this.exchangeRate,this.totalFees=e-t/this.exchangeRate),t<=0&&(t=0),i.value=t.toFixedIntelligent(2,"BTC"==this.targetCurrency?8:2),this.updateDetails(e,t),setTimeout((()=>this._waiting=!1),100)};if(0==n)return e=0,s(n,e);if(this.backendQuotationEndpoint){if(!this.quotationCached["target"+this.targetCurrency+n]){t.parentElement.classList.add("loading-border");try{this.quotationCached["target"+this.targetCurrency+n]=await this.fetch("POST",this.backendQuotationEndpoint,{source:n,targetCurrency:this.targetCurrency})}catch(e){throw t.parentElement.classList.remove("loading-border"),error}}
const e=this.quotationCached["target"+this.targetCurrency+n];this.fixedFees=e.fixedFees,this.percentageFees=e.percentageFees,this.exchangeRate=e.exchangeRate,t.parentElement.classList.remove("loading-border"),s(e.sourceAmount,e.targetAmount)}else s(n,e)}async calculateSource(){let e=this.querySelector(`#quotationSource${this.uniqueSuffix}`),t=this.querySelector(`#quotationTarget${this.uniqueSuffix}`),i=parseFloat(t.value)||0,n=t=>{if(this._waiting=!1,"target"===this.feeApplyTo)s=(t+this.getFees().fixed)/(this.exchangeRate*(1-this.getFees().percentage)),this.totalFees=s*this.exchangeRate-t;else{let e=t/this.exchangeRate;s=e+(this.getFees().fixed??0)+e*(this.getFees().percentage??0)-(this.sourceDiscountApplied??0),this.totalFees=s-e}s<=0&&(t=0),this.sourceValue=s,e.value=s.toFixedIntelligent("BTC"==this.sourceCurrency?8:2,"BTC"==this.sourceCurrency?8:2),this.updateDetails(s,t)};if(this.backendQuotationEndpoint){if(!this.quotationCached["source"+this.targetCurrency+i]){
e.parentElement.classList.add("loading-border");let t="display: flex; justify-content: space-between;width: 100%;",s=this.querySelector(`#quotationDetails${this.uniqueSuffix}`);try{s.style.display="block",s.style.filter="blur(3px)",0==(s.innerHTML??"").length&&(s.innerHTML=`${this.trans("Calculating")}... `),this.quotationCached["source"+this.targetCurrency+i]=await this.fetch("POST",this.backendQuotationEndpoint,{target:i,targetCurrency:this.targetCurrency}),s.style.filter="blur(0px)"}catch(t){throw e.parentElement.classList.remove("loading-border"),n(i),s.style.filter="blur(0px)",t}}const t=this.quotationCached["source"+this.targetCurrency+i];this.fixedFees=t.fixedFees??this.fixedFees,this.percentageFees=t.percentageFees??this.percentageFees,this.exchangeRate=t.exchangeRate??this.exchangeRate,e.parentElement.classList.remove("loading-border"),
e.value=t.sourceAmount.toFixedIntelligent("BTC"==this.sourceCurrency?8:2,"BTC"==this.sourceCurrency?8:2),this.sourceValue=e.value,this.totalFees=t.totalFees,this.updateDetails(e.value,i)}else n(i);return!0}async fetch(e,t,i){this.onThinking(),this._waiting=!0;const n={};n["x-cpl"]=this.getCookie("x-cpl")??"1",window.auth&&window.auth.fingerprint&&(window.fspt=window.auth.fingerprint),window.fspt&&(n.fingerprint=window.auth.fingerprint),(window?.auth?.user?.token??"").length&&(n.token=window.auth.user.token);const s={method:e,headers:new Headers({"Content-Type":"application/json",...n}),body:"GET"==e?null:JSON.stringify(i??{})};try{const e=await fetch(t,s),i=await e.json();return this.onStopThinking(),this._waiting=!1,i}catch(e){throw this.onStopThinking(),this._waiting=!1,e}}validateForm(){
let e=this.querySelector(`#quotationSource${this.uniqueSuffix}`),t=this.querySelector(`#quotationTarget${this.uniqueSuffix}`),i=this.querySelector(`#quotationSourceError${this.uniqueSuffix}`),n=this.querySelector(`#quotationTargetError${this.uniqueSuffix}`),s=!0,a=parseFloat(e.value)||0,o=parseFloat(t.value)||0;"remex-select"!=e.tagName.toLowerCase()&&(athis.maxSource)&&""!=(e.value??"")?(e.classList.add("error"),i.textContent=this.trans("Value must be between _MIN_ and _MAX_ _CURRENCY_",{_MIN_:this.minSource,_MAX_:this.maxSource,_CURRENCY_:this.sourceCurrency}),s=!1):(e.classList.remove("error"),i.textContent=""),"remex-select"!=t.tagName.toLowerCase()&&(othis.maxTarget)&&""!=(t.value??"")?(t.classList.add("error"),n.textContent=this.trans("Value must be between _MIN_ and _MAX_ _CURRENCY_",{_MIN_:this.minTarget,_MAX_:this.maxTarget,_CURRENCY_:this.targetCurrency}),s=!1):(t.classList.remove("error"),n.textContent="");const r={success:s,
error:n.textContent??"",sourceValue:a,targetValue:o,targetChoiced:this.targetChoiced??null,totalFees:this.totalFees,exchangeRate:this.exchangeRate??1};if(o==a&&this.classList.add("detailless"),this.dispatchEvent(new CustomEvent("validation",{detail:r})),!s){const e=this.querySelector(`#quotationDetails${this.uniqueSuffix}`);e&&(e.style.display="none")}this._waiting||this.onValidation(r)}setupDQ(e){void 0!==e.backendQuotationEndpoint&&(this.backendQuotationEndpoint=e.backendQuotationEndpoint),void 0!==e.exchangeRate&&(this.exchangeRate=e.exchangeRate),void 0!==e.targetChoice&&(this.targetChoice=e.targetChoice),void 0!==e.fixedFees&&(this.fixedFees=e.fixedFees),void 0!==e.percentageFees&&(this.percentageFees=e.percentageFees),void 0!==e.minSource&&(this.minSource=e.minSource),void 0!==e.maxSource&&(this.maxSource=e.maxSource),void 0!==e.minTarget&&(this.minTarget=e.minTarget),void 0!==e.maxTarget&&(this.maxTarget=e.maxTarget),
void 0!==e.sourceCurrency&&(this.sourceCurrency=e.sourceCurrency),void 0!==e.targetCurrency&&(this.targetCurrency=e.targetCurrency),void 0!==e.source&&(this.source=e.source),void 0!==e.target&&(this.target=e.target),void 0!==e.feeApplyTo&&(this.feeApplyTo=e.feeApplyTo),void 0!==e.components&&(this.components=e.components),void 0!==e.i18n&&(this.i18n=e.i18n),void 0!==e.styles&&(this.overrideStyles=e.styles),void 0!==e.sourceCls&&(this.sourceCls=e.sourceCls),void 0!==e.targetCls&&(this.targetCls=e.targetCls),void 0!==e.detailsCls&&(this.detailsCls=e.detailsCls),void 0!==e.flagsEndpoint&&(this.flagsEndpoint=e.flagsEndpoint),void 0!==e.showFlag&&(this.showFlag=e.showFlag),void 0!==e.showCurrency&&(this.showCurrency=e.showCurrency),void 0!==e.detailsCollapsed&&(this.detailsCollapsed=e.detailsCollapsed),void 0!==e.onValidation&&(this.onValidation=e.onValidation),void 0!==e.onInitialized&&(this.onInitialized=e.onInitialized),void 0!==e.onThinking&&(this.onThinking=e.onThinking),
void 0!==e.onStopThinking&&(this.onStopThinking=e.onStopThinking),void 0!==e.repositionScroll&&(this.repositionScroll=e.repositionScroll),this.refresh(),void 0!==e.source?(this.querySelector(`#quotationSource${this.uniqueSuffix}`).value=this.source,this.querySelector(`#quotationSource${this.uniqueSuffix}`).focus(),this.calculateTarget()):void 0!==e.target&&(this.querySelector(`#quotationTarget${this.uniqueSuffix}`).value=this.target,this.querySelector(`#quotationTarget${this.uniqueSuffix}`).focus(),this._waiting||setTimeout((()=>this.calculateSource()),100)),setTimeout((()=>this.validateForm()),100),this.onInitialized()}}if(customElements.define("dynamic-quotation",e),"undefined"!=typeof jQuery&&(jQuery.fn.setupDQ=function(e){return this.each((function(){"dynamic-quotation"===this.tagName.toLowerCase()&&this.setupDQ(e)}))}),!customElements.get("remex-select")){var script=document.createElement("script")
;const e=document.querySelector('meta[name="x-cpl"]')?.getAttribute("content")||"1.0.0";script.src=`/cdn/${e}/microfronts/remex-select/index.min.js`,script.async=!0,document.head.appendChild(script)}Number.prototype.toFixedIntelligent=function(e,t){let i=this.toString(),n=i.match(/(\d+\.\d+)e([+-]\d+)/);if(!i.includes("."))return e&&(i=`${i}.${"0".repeat(e??2)}`),t&&i.split(".")[1].length>t&&(i=i.slice(0,t+i.split(".")[0].length+1)),i;let[s,a]=i.split("."),o=0,r="";for(let t=0;t=(e??2))break}let l=s+"."+r;for(;l.endsWith("0");)l=l.slice(0,-1);if(l.endsWith(".")&&(l=`${l}.00`),null!==n){let e=parseFloat(l),t=parseInt(n[2]);if(t<0)i="0."+"0".repeat(Math.abs(t)-1)+e.toString().replace(".","");else{let n=e.toString().split("."),s=n[0],a=n[1]||"",o=t;i=a.length>o?s+a.slice(0,o)+"."+a.slice(o):s+a+"0".repeat(o-a.length)}l=i.slice(0,-1)}return e&&!l.includes(".")&&(l=`${l}.${"0".repeat(e)}`),
t&&l.split(".")[1].length>t&&(l=l.slice(0,t+l.split(".")[0].length+1)),l}}