import{i as v}from"./tld-extra-fields-DqBnP-rv.js";import{g,r as k}from"./api-DZ3cXm1m.js";(function(){const n=window.domainExtraFields;if(!n||!n.definitions||Object.keys(n.definitions).length===0)return;const s=document.getElementById("extraFieldsForm");if(!s)return;const p=n.definitions,c=n.translations||{};function u(){const t={};return s.querySelectorAll("[data-extra-field]").forEach(e=>{const i=e.getAttribute("data-extra-field");e.type==="checkbox"?t[i]=e.checked?"1":"":e.type==="radio"?e.checked?t[i]=e.value:i in t||(t[i]=""):t[i]=(e.value||"").trim()}),t}function d(){const t=u();s.querySelectorAll(".extra-field-row").forEach(e=>{const i=e.getAttribute("data-field-key"),a=p[i];a&&(e.style.display=v(a,t)?"":"none")})}s.querySelectorAll("[data-extra-field]").forEach(t=>{t.addEventListener("change",d),t.addEventListener("input",d)}),d();async function h(t,e,i=null){const a=o=>{const y={method:e,headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Bearer ${o}`,"X-Requested-With":"XMLHttpRequest"}};return i!==null&&(y.body=JSON.stringify(i)),y};let l=await fetch(t,a(g()));if(l.status===401){const o=await k();o&&(l=await fetch(t,a(o)))}return l}function f(t,e=!0){typeof window.Toastify=="function"?window.Toastify({text:t,duration:3e3,gravity:"top",position:"right",style:{background:e?"#28a745":"#dc3545"}}).showToast():alert(t)}const r=document.getElementById("saveExtraFieldsBtn");r&&r.addEventListener("click",async()=>{if(!r.disabled){r.disabled=!0;try{const t=await h(n.routes.update,"PUT",{additional_fields:u()}),e=await t.json().catch(()=>({}));if(!t.ok){const i=e!=null&&e.errors?Object.values(e.errors).flat()[0]:(e==null?void 0:e.message)||c.save_error||"Error";f(i,!1);return}f(c.saved||"Saved",!0)}catch{f(c.save_error||"Error",!1)}finally{r.disabled=!1}}})})();
