import{d as e}from"./p-DGOUAxVN.js";import{getEnvelopesZip as t,downloadBlob as s,rescale as a}from"@verdocs/js-sdk";import{a as n}from"./p-17OorOnH.js";const o=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 c=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 r=(e,t,s,n)=>{var r,i;let{x:d=0,y:l=0,width:u=o(t.type),height:p=c(t.type),settings:x}=t;const m=t.type==="signature"||t.type==="initial";const f=!m?u:(r=x===null||x===void 0?void 0:x.canvasWidth)!==null&&r!==void 0?r:u;const b=!m?p:(i=x===null||x===void 0?void 0:x.canvasHeight)!==null&&i!==void 0?i:p;e.style.width=`${f}px`;e.style.height=`${b}px`;e.style.position="absolute";e.style.left=`${a(s,d)}px`;e.style.bottom=`${a(n,l)}px`;e.style.transform=`scale(${s}, ${n})`};const i=(e,t,s)=>{let{x:n=0,y:r=0,width:i=o(e.type),height:d=c(e.type)}=e;return{zIndex:"100",width:`${i}px`,height:`${d}px`,position:"absolute",left:`${a(t,n)}px`,bottom:`${a(s,r)}px`,transform:`scale(${t}, ${s})`}};const d=e=>`verdocs-doc-fld-${e.name}`;const l=e=>{const t=d(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 u=(e,t,s,a,n=1)=>{var o,c;const{disabled:i=false,editable:l=false,draggable:u=false,done:p=false}=a;const x=document.getElementById(s.containerId+"-controls");if(!x){return}switch(t.type){case"radio":case"checkbox":case"attachment":case"date":case"dropdown":case"initial":case"payment":case"signature":case"timestamp":case"textarea":case"textbox":{const a=d(t);const m=document.getElementById(a);if(m){m.field=t;m.done=p;r(m,t,s.xScale,s.yScale);return m}let{type:f}=t;if(f==="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){f="textarea"}}const b=document.createElement(`verdocs-field-${f}`);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(i){b.setAttribute("tabindex",-1);b.setAttribute("disabled",true)}else{b.setAttribute("tabindex",n)}b.setAttribute("editable",l);b.setAttribute("draggable",u);b.setAttribute("done",p);r(b,t,s.xScale,s.yScale);x.appendChild(b);return b}default:console.log("[PREVIEW] Skipping unsupported field type",t);return null}};const p=(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 x=e=>{e.style.transform=e.style.transform.split(")")[0]+")"};const m=async(a,o)=>{const c=e.format(o.length===1?new Date(o[0].updated_at):new Date,n);const r=o.length===1?`${o[0].name} - ${c}.zip`:`Verdocs-Envelopes-${c}`;console.log("Downloading envelopes as ZIP",o,r);const i=await t(a,o.map((e=>e.id)));s(i.data,r)};const f=(e,t)=>{let s=0;return function(...a){clearTimeout(s);s=setTimeout((()=>e.apply(this,a)),t)}};const b=(e,t="16px Arial")=>{const s=document.createElement("canvas");const a=s.getContext("2d");a.font=t;return a.measureText(e).width};const h=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}`};const $=(e,t,s,n)=>{const o=document.getElementById(e.containerId+"-controls");if(!o){return}const c=document.createElement("verdocs-flag");c.variant=n.variant;c.label=n.label;c.showSkip=n.showSkip;if(n.id){c.setAttribute("id",n.id)}c.classList.add("verdocs-flag-instance");if(n.onSkip){c.addEventListener("skip",n.onSkip)}if(n.onClick){c.addEventListener("flagClick",n.onClick)}c.style.position="absolute";c.style.left="calc(100% - 14px)";const r=a(e.yScale,t);const i=a(e.yScale,s);const d=r+i;c.style.bottom=`${d}px`;o.appendChild(c);return c};const g=e=>{if(!e)return"";const t={signature:"Signature",initial:"Initials",date:"Date",textbox:"Text Field",checkbox:"Checkbox",radio:"Radio Button",dropdown:"Dropdown",attachment:"Attachment",payment:"Payment"};const s=t[e.type]||"Field";if(e.required){return`Required ${s}*`}return`Optional ${s}`};export{u as a,g as b,h as c,c as d,b as e,i as f,d as g,p as h,x as i,r as j,o as k,$ as r,m as s,f as t,l as u};
//# sourceMappingURL=p-BCwFpXpV.js.map