(()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.apiFetch;var n=e.n(t);function o(e,t){const n=e.closest(".field-wrap");if(!n)return;const o=n.querySelector(".rcf7-file-error-container");o&&(o.innerHTML=t?`<p>${t}</p>`:"",o.style.display=t?"block":"none",t&&setTimeout((()=>{o.innerHTML="",o.style.display="none"}),5e3))}async function a(e,t){const o=`${window.cf7rData.endpoints.downloadFile}?file_key=${e}&entry_post_id=${t}`,a=await n()({path:o,method:"GET",parse:!1});if(!a.ok){let e=`HTTP error! status: ${a.status}`;try{e=(await a.json()).message||e}catch(t){e=a.statusText||e}throw new Error(e)}return{blob:await a.blob()}}async function r(e,t,n){console.error(`${n} failed:`,e);let a=e?.message||window.cf7rData?.labels?.error||"An unknown error occurred";if(e instanceof Response)try{a=(await e.clone().json()).message||a}catch(t){console.error("Failed to parse error response body:",t),a=e.statusText||a}else"string"==typeof e&&(a=e);o(t,`${window.cf7rData?.labels?.error||"Error"}: ${a}`)}document.addEventListener("DOMContentLoaded",(function(){!function(){const e=document.querySelector(".wrap:has(.cf7r-meta-filter)  .wp-heading-inline");if(!e)return;const t=document.createElement("button");t.className="button button-primary cf7r-btn-export",t.textContent=window.cf7rData?.labels.export;let o="cf7r-export.csv";t.onclick=()=>{const e=new URLSearchParams(window.location.search);let t=window.cf7rData.endpoints.export;e.toString()&&(t+="?"+e.toString()),n()({path:t,method:"GET",parse:!1}).then((e=>{const t=e.headers.get("Content-Disposition");return o=t?t.split("filename=")[1].replace(/"/g,""):o,e.blob()})).then((e=>{const t=window.URL.createObjectURL(e),n=document.createElement("a");n.style.display="none",n.href=t,n.download=o,document.body.appendChild(n),n.click(),window.URL.revokeObjectURL(t),document.body.removeChild(n)})).catch((e=>{console.error("Export failed:",e)}))},e.insertAdjacentElement("afterend",t)}(),document.querySelectorAll("#wpcf7r_leads .field-wrap:not(:has(.rcf7-file-download-container)) label").forEach((e=>{!function(e){const t=document.createElement("button");t.className="rcf-7-copy-field button button-link",t.type="button",t.title=window.cf7rData?.labels.copy;const n=document.createElement("span");n.className="dashicons dashicons-clipboard",t.appendChild(n),t.onclick=function(e){e.preventDefault();const t=this.closest(".field-wrap");if(!t)return;const o=t.querySelector("input, textarea, select")?.value||"";navigator.clipboard.writeText(o).then((()=>{n.className="dashicons dashicons-yes",setTimeout((()=>{n.className="dashicons dashicons-clipboard"}),1e3)})).catch((e=>{console.error("Failed to copy text: ",e)}))},e.appendChild(t)}(e)})),function(){const e=document.querySelector("#post_ID")?.value;e&&document.querySelectorAll("button.rcf7-download-btn").forEach((t=>{const n=t.dataset.fileKey,c=t.dataset.fileType,i=t.dataset.fileName;if(c&&["png","jpeg","jpg","gif","webp","svg","bmp"].includes(c.toLowerCase())){const c=document.createElement("button");c.className="rcf7-preview-btn button button-secondary",c.textContent=window.cf7rData?.labels?.preview||"Preview",c.style.marginLeft="5px",c.addEventListener("click",(async i=>{var l;i.preventDefault(),o(c,"");const s=t.closest(".field-wrap")?.querySelector(".rcf7-file-preview-container");if(!s)return;const d=s.querySelector(".rcf7-image-preview");if(d)return d.remove(),void(c.textContent=window.cf7rData?.labels?.preview||"Preview");c.textContent=`${null!==(l=window.cf7rData?.labels?.closePreview)&&void 0!==l?l:"Loading"}...`,c.disabled=!0;try{const{blob:t}=await a(n,e),o=document.createElement("div");o.className="rcf7-image-preview",o.style.marginTop="10px";const r=document.createElement("img");r.src=URL.createObjectURL(t),r.style.maxWidth="100%",r.style.maxHeight="300px",r.onload=()=>URL.revokeObjectURL(r.src),o.appendChild(r),s.innerHTML="",s.appendChild(o),c.textContent=window.cf7rData?.labels?.closePreview||"Close Preview"}catch(e){await r(e,c,"Preview"),c.textContent=window.cf7rData?.labels?.preview||"Preview"}finally{c.disabled=!1}})),t.insertAdjacentElement("afterend",c)}c&&n&&t.addEventListener("click",(async c=>{c.preventDefault(),o(t,"");const l=t.textContent;t.textContent="Downloading...",t.disabled=!0;try{const{blob:t}=await a(n,e),o=window.URL.createObjectURL(t),r=document.createElement("a");r.style.display="none",r.href=o,r.download=i,document.body.appendChild(r),r.click(),window.URL.revokeObjectURL(o),document.body.removeChild(r)}catch(e){await r(e,t,"Download")}finally{t.textContent=l,t.disabled=!1}}))}))}()}))})();