function h(){const r=document.querySelector("[data-edit-attach-type]"),f=document.querySelectorAll("[data-edit-media-pane]");function a(){const e=r?r.value:"none";f.forEach(t=>{const n=t.getAttribute("data-edit-media-pane")===e;t.classList.toggle("hidden",!n),n||t.querySelectorAll('input[type="file"]').forEach(c=>{c.value=""})})}r&&(r.addEventListener("change",a),a());const i=document.getElementById("cc-btn-list"),l=document.getElementById("cc-btn-add");function o(){return i?i.querySelectorAll(".cc-btn-row"):[]}function s(){l&&l.classList.toggle("hidden",o().length>=3)}function u(e){const t=e.querySelector(".cc-cta-type");if(!t)return;const n=e.querySelector(".cc-cta-url"),c=e.querySelector(".cc-cta-value"),p=t.value==="visit_website";n&&n.classList.toggle("hidden",!p),c&&(c.classList.toggle("hidden",p),c.placeholder=t.value==="call_phone"?"+15551234567":"PROMO50")}function d(e){u(e),e.querySelector(".cc-cta-type")?.addEventListener("change",()=>u(e)),e.querySelector("[data-cc-remove]")?.addEventListener("click",()=>{e.remove(),g(),s()})}function g(){o().forEach((e,t)=>{e.querySelectorAll("select, input").forEach(n=>{const c=n.getAttribute("name");c&&n.setAttribute("name",c.replace(/custom_buttons\[\d+\]/,`custom_buttons[${t}]`))})})}i&&(o().forEach(d),s()),l&&l.addEventListener("click",()=>{if(o().length>=3)return;const e=o().length,t=document.createElement("div");t.className="cc-btn-row grid grid-cols-[130px_1fr_1fr_28px] gap-1.5 items-center",t.setAttribute("data-kind","cta"),t.innerHTML=`<select name="custom_buttons[${e}][type]" class="cc-cta-type w-full px-2 py-2 border border-paper-200 rounded-lg bg-white text-[12px] focus:outline-none focus:border-wa-deep focus:ring-4 focus:ring-wa-deep/10"><option value="visit_website">Visit website</option><option value="copy_code">Copy code</option><option value="call_phone">Call phone</option></select><input type="text" name="custom_buttons[${e}][text]" maxlength="25" placeholder="Button text" class="cc-cta-text w-full px-3 py-2 border border-paper-200 rounded-lg bg-white text-[12.5px] focus:outline-none focus:border-wa-deep focus:ring-4 focus:ring-wa-deep/10"><input type="text" name="custom_buttons[${e}][url]" placeholder="https://..." class="cc-cta-url w-full px-3 py-2 border border-paper-200 rounded-lg bg-white text-[12.5px] focus:outline-none focus:border-wa-deep focus:ring-4 focus:ring-wa-deep/10"><input type="text" name="custom_buttons[${e}][value]" placeholder="PROMO50" class="cc-cta-value w-full px-3 py-2 border border-paper-200 rounded-lg bg-white text-[12.5px] focus:outline-none focus:border-wa-deep focus:ring-4 focus:ring-wa-deep/10 hidden"><span class="w-7 h-7 rounded-[7px] inline-flex items-center justify-center text-ink-500 cursor-pointer transition hover:bg-[#FFEDE8] hover:text-accent-coral" data-cc-remove title="Remove"><svg viewBox="0 0 16 16" class="w-3.5 h-3.5" fill="none" stroke="currentColor" stroke-width="1.8"><path d="M4 4l8 8M12 4l-8 8"/></svg></span>`,i.appendChild(t),d(t),s()})}export{h as default};
