import{d as e}from"./p-dzBXqXlK.js";import{getEnvelopesZip as t,downloadBlob as s,getEnvelopeFile as a,rescale as n}from"@verdocs/js-sdk";import{F as o}from"./p-dqxNbm_b.js";const c=e=>{switch(e){case"textarea":return 150;case"textbox":return 150;case"timestamp":return 105;case"date":return 75;case"dropdown":return 85;case"attachment":case"payment":return 24;case"radio":case"checkbox":return 14;case"signature":case"initial":return 71}return 150};const r=e=>{switch(e){case"textarea":return 41;case"textbox":return 15;case"timestamp":return 15;case"date":return 15;case"dropdown":return 20;case"attachment":case"payment":return 24;case"radio":case"checkbox":return 14;case"signature":case"initial":return 36}return 50};const i=(e,t,s,a)=>{let{x:o=0,y:i=0,width:d=c(t.type),height:u=r(t.type)}=t;e.style.width=`${d}px`;e.style.height=`${u}px`;e.style.position="absolute";e.style.left=`${n(s,o)}px`;e.style.bottom=`${n(a,i)}px`;e.style.transform=`scale(${s}, ${a})`};const d=(e,t,s)=>{let{x:a=0,y:o=0,width:i=c(e.type),height:d=r(e.type)}=e;return{zIndex:"100",width:`${i}px`,height:`${d}px`,position:"absolute",left:`${n(t,a)}px`,bottom:`${n(s,o)}px`,transform:`scale(${t}, ${s})`}};const u=e=>`verdocs-doc-fld-${e.name}`;const l=e=>{const t=u(e);const s=document.getElementById(t);if(s){s.field=e;s.roleindex=e;s.setAttribute("id",t);s.setAttribute("disabled",true);s.setAttribute("disabled",false)}};const p=(e,t,s,a,n=1)=>{var o,c;const{disabled:r=false,editable:d=false,draggable:l=false,done:p=false}=a;const f=document.getElementById(s.containerId+"-controls");if(!f){console.log("[renderDocumentField] No controls DIV found",s.containerId+"-controls",s);return}switch(t.type){case"attachment":case"date":case"dropdown":case"initial":case"payment":case"signature":case"timestamp":case"textarea":case"textbox":{const a=u(t);const m=document.getElementById(a);if(m){i(m,t,s.xScale,s.yScale);return m}let{type:x}=t;if(x==="textbox"){if(((o=t["setting"])===null||o===void 0?void 0:o.leading)>0||((c=t["settings"])===null||c===void 0?void 0:c.leading)>0){x="textarea"}}const b=document.createElement(`verdocs-field-${x}`);b.field=t;b.setAttribute("id",a);b.setAttribute("fieldname",t.name);b.setAttribute("source",e);b.setAttribute("sourceid","template_id"in t?t.template_id:t.envelope_id);if(r){b.setAttribute("tabindex",-1);b.setAttribute("disabled",true)}else{b.setAttribute("tabIndex",n)}b.setAttribute("editable",d);b.setAttribute("draggable",l);b.setAttribute("done",p);i(b,t,s.xScale,s.yScale);f.appendChild(b);return b}case"checkbox":{const a=u(t);const n=document.getElementById(a);if(n){i(n,t,s.xScale,s.yScale);return n}const o=document.createElement(`verdocs-field-checkbox`);o.field=t;o.setAttribute("id",a);o.setAttribute("option",0);o.setAttribute("source",e);o.setAttribute("sourceid","template_id"in t?t.template_id:t.envelope_id);if(r){o.setAttribute("disabled",true)}if(p){o.setAttribute("done",true)}if(d){o.setAttribute("editable",true)}if(l){o.setAttribute("draggable",true)}i(o,t,s.xScale,s.yScale);f.appendChild(o);return o}case"radio":{const a=u(t);const n=document.getElementById(a);if(n){i(n,t,s.xScale,s.yScale);return n}const o=document.createElement(`verdocs-field-radio`);o.field=t;o.setAttribute("id",a);o.setAttribute("option",0);o.setAttribute("source",e);o.setAttribute("sourceid","template_id"in t?t.template_id:t.envelope_id);if(r){o.setAttribute("disabled",true)}if(p){o.setAttribute("done",true)}if(d){o.setAttribute("editable",true)}if(l){o.setAttribute("draggable",true)}i(o,t,s.xScale,s.yScale);f.appendChild(o);return o}default:console.log("[PREVIEW] Skipping unsupported field type",t);return null}};const f=(e,t,s)=>{const a=e.style.transform||"";const n=`${t}(${s})`;if(a.includes(t)){e.style.transform=a.replace(new RegExp(`${t}\\(.+?\\)`),n)}else{e.style.transform=a+" "+n}};const m=e=>{e.style.transform=e.style.transform.split(")")[0]+")"};const x=async(t,n,c)=>{const r=e.format(new Date(n.updated_at),o);const i=`${n.name} - ${r}.pdf`;const d=await a(t,c);s(d,i)};const b=async(a,n)=>{const c=e.format(n.length===1?new Date(n[0].updated_at):new Date,o);const r=n.length===1?`${n[0].name} - ${c}.zip`:`Verdocs-Envelopes-${c}`;console.log("Downloading envelopes as ZIP",n,r);const i=await t(a,n.map((e=>e.id)));s(i.data,r)};const $=(e,t)=>{let s=0;return function(...a){clearTimeout(s);s=setTimeout((()=>e.apply(this,a)),t)}};const h=(e,t="16px Arial")=>{const s=document.createElement("canvas");const a=s.getContext("2d");a.font=t;return a.measureText(e).width};const g=e=>{let t=(e||"").trim();if(!t||t.startsWith("+")){return t}t=t.replace(/[^0-9]/g,"");t=t.replace(/^0/g,"");return`+1${t}`};export{x as a,h as b,d as c,g as d,f as e,m as f,u as g,i as h,r as i,c as j,p as r,b as s,$ as t,l as u};
//# sourceMappingURL=p-BBOZ2ZHI.js.map