document.addEventListener("DOMContentLoaded",function(){const u=window.tldEditData||{},a=u.defaultCurrencyId!==void 0?u.defaultCurrencyId:null,E=u.minRenderYear!==void 0?u.minRenderYear:1,v=u.maxRenderYear!==void 0?u.maxRenderYear:10,s=document.getElementById("adaptivePricingSwitch"),l=document.querySelector("#pricingTable tbody"),d=document.getElementById("otherFeesTable");function m(){if(l)for(let n=E;n<=v;n++){const e=l.querySelectorAll('tr.currency-row[data-year-row="'+n+'"]'),i=l.querySelector('td.year-group-label[data-year-label-for="'+n+'"]');if(!i)continue;let r=0;e.forEach(t=>{!t.classList.contains("hidden-currency")&&t.style.display!=="none"&&r++}),r>0?(i.setAttribute("rowspan",r),i.style.display=""):i.style.display="none"}}function S(n){l&&l.querySelectorAll("tr.currency-row").forEach(e=>{const i=e.dataset.currencyId,r=e.querySelector("td.year-group-label");n?i!=a?(e.classList.add("hidden-currency"),e.querySelectorAll(".price-input, .price-active-toggle").forEach(t=>{t.disabled=!0}),r&&(r.style.display="none")):(e.classList.remove("hidden-currency"),e.querySelectorAll(".price-input-group").forEach(t=>{const c=t.querySelector(".price-active-toggle"),o=t.querySelector(".price-input");c&&(c.disabled=!1),o&&c&&(o.disabled=!c.checked)}),r&&(r.style.display="")):(e.classList.remove("hidden-currency"),e.querySelectorAll(".price-input-group").forEach(t=>{const c=t.querySelector(".price-active-toggle"),o=t.querySelector(".price-input");c&&(c.disabled=!1),o&&c&&(o.disabled=!c.checked)}),r&&(r.style.display=""))}),d&&(d.querySelectorAll("thead th.currency-header-cell").forEach(e=>{n&&e.dataset.currencyId!=a?e.style.display="none":e.style.display=""}),d.querySelectorAll("tbody td.currency-data-cell").forEach(e=>{const i=e.dataset.currencyId;n?i!=a?(e.style.display="none",e.querySelectorAll(".price-input, .price-active-toggle").forEach(r=>{r.disabled=!0})):(e.style.display="",e.querySelectorAll(".price-input-group").forEach(r=>{const t=r.querySelector(".price-active-toggle"),c=r.querySelector(".price-input");t&&(t.disabled=!1),c&&t&&(c.disabled=!t.checked)})):(e.style.display="",e.querySelectorAll(".price-input-group").forEach(r=>{const t=r.querySelector(".price-active-toggle"),c=r.querySelector(".price-input");t&&(t.disabled=!1),c&&t&&(c.disabled=!t.checked)}))})),m()}function I(n,e,i,r){return n.querySelector(`input[name="pricing[${e}][${i}][${r}][amount]"]`)}function A(n,e,i){return n.querySelector(`input[name="pricing_other[${e}][${i}][amount]"]`)}function L(){var i;if(!s||!s.checked||!a)return;const n=u.currencyRates||{},e=((i=n[a])==null?void 0:i.rate)||1;if(l)for(let r=E;r<=v;r++)["register","transfer","renew"].forEach(t=>{const c=I(l,a,r,t);if(!c||!c.value)return;const o=parseFloat(c.value);isNaN(o)||Object.keys(n).forEach(g=>{var Y;if(g==a)return;const q=((Y=n[g])==null?void 0:Y.rate)||1,b=o/e*q,h=I(l,g,r,t);h&&(h.value=b.toFixed(2))})});d&&["grace","redemption","whois"].forEach(r=>{const t=A(d,a,r);if(!t||!t.value)return;const c=parseFloat(t.value);isNaN(c)||Object.keys(n).forEach(o=>{var h;if(o==a)return;const g=((h=n[o])==null?void 0:h.rate)||1,q=c/e*g,b=A(d,o,r);b&&(b.value=q.toFixed(2))})})}a&&(l&&l.querySelectorAll(`tr.currency-row[data-currency-id="${a}"] .price-input`).forEach(n=>{n.addEventListener("input",L)}),d&&d.querySelectorAll(`td.currency-data-cell[data-currency-id="${a}"] .price-input`).forEach(n=>{n.addEventListener("input",L)})),s&&a!==null?(s.addEventListener("change",function(){S(this.checked)}),S(s.checked)):s&&a===null&&(s.disabled=!0);const f=document.getElementById("min_years_for_registration"),y=document.getElementById("max_years_for_registration");function p(){if(!f||!y||!l)return;const n=parseInt(f.value,10)||E,e=parseInt(y.value,10)||v;for(let i=E;i<=v;i++)l.querySelectorAll('tr.currency-row[data-year-row="'+i+'"]').forEach(t=>{i>=n&&i<=e?t.style.display="":t.style.display="none"});s?S(s.checked):m()}f&&y&&(f.addEventListener("change",p),f.addEventListener("input",p),y.addEventListener("change",p),y.addEventListener("input",p),p()),document.querySelectorAll(".price-active-toggle").forEach(n=>{n.addEventListener("change",function(){const e=this.closest(".price-input-group").querySelector(".price-input");e&&(this.disabled||(e.disabled=!this.checked))})}),m()});
