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 \n
\n \n ${this.showFlag?``:""}\n ${this.showCurrency?`${this.sourceCurrency}`:""}\n
\n
\n
`,target:`
\n \n
\n ${this.targetChoice?`\n ${this.targetChoice.map(((e,t)=>``)).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,'$1'),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='