import{_ as J,r as c,c as G,o as K,ac as U,a as d,g as n,b as t,j as v,k as m,t as i,i as q,d as y,w as f,e as g,F as p,aT as I,ae as X,aU as Q,aV as Z,af as ee,aR as te}from"./index-QAlcqU00.js";import{F as se}from"./FPInput-D5RURom0.js";import{F as ae}from"./FPBadge-DvOitM1C.js";const le={class:"digital-signature"},oe={class:"flex items-center justify-between mb-4"},ie={key:0,class:"flex items-center text-sm text-green-600"},ne={key:0,class:"mb-6"},re={class:"border border-gray-200 rounded-lg p-4 bg-gray-50"},de={class:"flex items-start justify-between"},ue={class:"flex-1"},ce={class:"mb-4"},ve=["src"],me={class:"grid grid-cols-1 md:grid-cols-3 gap-4 text-sm"},ge={class:"text-gray-600"},fe={class:"text-xs text-gray-500"},be={class:"text-gray-600"},xe={class:"text-xs text-gray-500"},ye={class:"text-gray-600"},pe={class:"text-xs text-gray-500"},he={key:0,class:"mt-4"},we={class:"text-gray-600 text-sm mt-1"},ke={class:"ml-4 flex flex-col space-y-2"},_e={key:1,class:"space-y-4"},Ce={class:"signature-canvas-container"},De={class:"flex items-center justify-between"},Se={class:"flex space-x-2"},Be={class:"flex items-center space-x-2"},Ve={class:"flex items-center space-x-2"},Me={class:"flex space-x-2"},Ne={key:2,class:"mt-8"},Te={class:"space-y-2"},je={class:"flex items-center justify-between"},Ae={class:"flex items-center space-x-3"},Pe=["src"],ze={class:"text-sm font-medium text-gray-900"},He={class:"text-xs text-gray-500"},Re={key:3,class:"mt-6"},Fe={class:"flex items-center justify-between mb-2"},M=600,N=200,Le={__name:"DigitalSignature",props:{modelValue:{type:Object,default:()=>({signatureData:null,signedBy:null,signedAt:null,comments:"",ipAddress:null,userAgent:null})},currentUser:{type:Object,required:!0},disabled:{type:Boolean,default:!1},allowReSign:{type:Boolean,default:!0},signatureHistory:{type:Array,default:()=>[]}},emits:["update:modelValue","signature-saved"],setup(h,{emit:Ue}){const b=h,o=c({...b.modelValue}),x=c(!b.modelValue.signatureData),C=c(b.modelValue.comments||""),D=c(null),S=c(!1),w=c(!1),B=c(3),V=c("#000000");let a=null;G(()=>w.value&&!b.disabled);const j=()=>{D.value&&(a=D.value.getContext("2d"),a.lineCap="round",a.lineJoin="round",a.strokeStyle=V.value,a.lineWidth=B.value,a.fillStyle="white",a.fillRect(0,0,M,N))},A=s=>{const e=D.value.getBoundingClientRect(),k=M/e.width,u=N/e.height;let r,l;return s.touches&&s.touches.length>0?(r=s.touches[0].clientX,l=s.touches[0].clientY):(r=s.clientX,l=s.clientY),{x:(r-e.left)*k,y:(l-e.top)*u}},P=s=>{if(b.disabled)return;s.preventDefault(),S.value=!0;const e=A(s);a.beginPath(),a.moveTo(e.x,e.y)},z=s=>{if(!S.value||b.disabled)return;s.preventDefault();const e=A(s);a.lineTo(e.x,e.y),a.stroke(),w.value=!0},T=s=>{S.value&&(s.preventDefault(),S.value=!1,a.closePath())},H=()=>{a&&(a.fillStyle="white",a.fillRect(0,0,M,N),w.value=!1)},Y=()=>{a&&(a.lineWidth=parseInt(B.value))},$=()=>{a&&(a.strokeStyle=V.value)},E=()=>{x.value=!0,C.value=o.value.comments||"",U(()=>{j(),H()})},O=()=>{x.value=!1,C.value=o.value.comments||""},R=s=>s?new Date(s).toLocaleString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:!0}):"Not signed",W=s=>{if(!s)return"";const e=new Date(s),u=new Date-e,r=Math.floor(u/(1e3*60)),l=Math.floor(u/(1e3*60*60)),_=Math.floor(u/(1e3*60*60*24));return r<60?`${r} minutes ago`:l<24?`${l} hours ago`:`${_} days ago`};return K(()=>{x.value&&U(()=>{j()})}),(s,e)=>{var k,u,r;return n(),d("div",le,[t("div",oe,[e[4]||(e[4]=t("div",null,[t("h3",{class:"text-lg font-medium text-gray-900"},"Digital Signature"),t("p",{class:"text-sm text-gray-600"},"Required for work order completion")],-1)),o.value.signatureData?(n(),d("div",ie,e[3]||(e[3]=[t("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M5 13l4 4L19 7"})],-1),m(" Signed ",-1)]))):v("",!0)]),o.value.signatureData&&!x.value?(n(),d("div",ne,[t("div",re,[t("div",de,[t("div",ue,[t("div",ce,[t("img",{src:o.value.signatureData,alt:"Digital Signature",class:"max-w-full h-auto border border-gray-300 rounded bg-white",style:{"max-height":"150px"}},null,8,ve)]),t("div",me,[t("div",null,[e[5]||(e[5]=t("div",{class:"font-medium text-gray-900"},"Signed By",-1)),t("div",ge,i((k=o.value.signedBy)==null?void 0:k.firstName)+" "+i((u=o.value.signedBy)==null?void 0:u.lastName),1),t("div",fe,i((r=o.value.signedBy)==null?void 0:r.email),1)]),t("div",null,[e[6]||(e[6]=t("div",{class:"font-medium text-gray-900"},"Date & Time",-1)),t("div",be,i(R(o.value.signedAt)),1),t("div",xe,i(W(o.value.signedAt)),1)]),t("div",null,[e[7]||(e[7]=t("div",{class:"font-medium text-gray-900"},"IP Address",-1)),t("div",ye,i(o.value.ipAddress||"Not recorded"),1),t("div",pe,i(o.value.userAgent?"Browser tracked":"No tracking"),1)])]),o.value.comments?(n(),d("div",he,[e[8]||(e[8]=t("div",{class:"font-medium text-gray-900 text-sm"},"Comments",-1)),t("div",we,i(o.value.comments),1)])):v("",!0)]),t("div",ke,[!h.disabled&&h.allowReSign?(n(),q(g(p),{key:0,variant:"outline",size:"sm",onClick:E},{default:f(()=>e[9]||(e[9]=[m(" Re-sign ",-1)])),_:1,__:[9]})):v("",!0),y(g(p),{variant:"outline",size:"sm",onClick:s.handleDownloadSignature},{default:f(()=>e[10]||(e[10]=[m(" Download ",-1)])),_:1,__:[10]},8,["onClick"])])])])])):v("",!0),!o.value.signatureData||x.value?(n(),d("div",_e,[e[18]||(e[18]=I('

How to sign

  • Use your mouse or finger to draw your signature in the box below
  • Make sure your signature is clear and readable
  • Click "Clear" to start over if needed
  • Add optional comments about the work completion
',1)),t("div",Ce,[t("canvas",{ref_key:"signatureCanvas",ref:D,class:"signature-canvas border-2 border-gray-300 rounded-lg bg-white cursor-crosshair",width:"600",height:"200",onMousedown:P,onMousemove:z,onMouseup:T,onMouseleave:T,onTouchstart:P,onTouchmove:z,onTouchend:T},null,544),t("div",{class:"mt-2 text-xs text-gray-500 text-center"},i(M)+"x"+i(N)+" pixels • Click and drag to sign ")]),t("div",De,[t("div",Se,[y(g(p),{variant:"outline",size:"sm",onClick:H,disabled:!w.value},{default:f(()=>e[11]||(e[11]=[t("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})],-1),m(" Clear ",-1)])),_:1,__:[11]},8,["disabled"]),t("div",Be,[e[13]||(e[13]=t("label",{class:"text-sm text-gray-600"},"Pen Size:",-1)),X(t("select",{"onUpdate:modelValue":e[0]||(e[0]=l=>B.value=l),class:"text-sm border border-gray-300 rounded px-2 py-1",onChange:Y},e[12]||(e[12]=[t("option",{value:"2"},"Fine",-1),t("option",{value:"3"},"Normal",-1),t("option",{value:"4"},"Thick",-1)]),544),[[Q,B.value]])]),t("div",Ve,[e[14]||(e[14]=t("label",{class:"text-sm text-gray-600"},"Color:",-1)),X(t("input",{"onUpdate:modelValue":e[1]||(e[1]=l=>V.value=l),type:"color",class:"w-8 h-8 border border-gray-300 rounded cursor-pointer",onChange:$},null,544),[[Z,V.value]])])]),t("div",Me,[x.value&&o.value.signatureData?(n(),q(g(p),{key:0,variant:"outline",onClick:O},{default:f(()=>e[15]||(e[15]=[m(" Cancel ",-1)])),_:1,__:[15]})):v("",!0),y(g(p),{variant:"primary",onClick:s.handleSaveSignature,disabled:!w.value||h.disabled||s.loading},{default:f(()=>e[16]||(e[16]=[t("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M5 13l4 4L19 7"})],-1),m(" Save Signature ",-1)])),_:1,__:[16]},8,["onClick","disabled"])])]),t("div",null,[e[17]||(e[17]=t("label",{class:"block text-sm font-medium text-gray-700 mb-2"}," Comments (Optional) ",-1)),y(g(se),{modelValue:C.value,"onUpdate:modelValue":e[2]||(e[2]=l=>C.value=l),type:"textarea",rows:"3",placeholder:"Add any comments about the work completion...",disabled:h.disabled},null,8,["modelValue","disabled"])]),e[19]||(e[19]=I('

Legal Notice

By providing your digital signature, you acknowledge that the work described in this work order has been completed according to specifications and requirements. This signature has the same legal effect as a handwritten signature.

',1))])):v("",!0),s.effectiveSignatureHistory.length>0?(n(),d("div",Ne,[e[20]||(e[20]=t("h4",{class:"text-sm font-medium text-gray-900 mb-3"},"Signature History",-1)),t("div",Te,[(n(!0),d(ee,null,te(s.effectiveSignatureHistory,(l,_)=>{var F,L;return n(),d("div",{key:l.id||_,class:"p-3 border border-gray-200 rounded-lg bg-gray-50"},[t("div",je,[t("div",Ae,[t("img",{src:l.signatureData,alt:"Historical Signature",class:"w-16 h-8 border border-gray-300 rounded bg-white"},null,8,Pe),t("div",null,[t("div",ze,i((F=l.signedBy)==null?void 0:F.firstName)+" "+i((L=l.signedBy)==null?void 0:L.lastName),1),t("div",He,i(R(l.signedAt)),1)])]),y(g(ae),{variant:"secondary",size:"sm"},{default:f(()=>[m(i(_===0?"Previous":`${_+1} versions ago`),1)]),_:2},1024)])])}),128))])])):v("",!0),s.enableValidation&&s.signatureExists?(n(),d("div",Re,[t("div",Fe,[e[22]||(e[22]=t("h4",{class:"text-sm font-medium text-gray-900"},"Signature Validation",-1)),y(g(p),{variant:"outline",size:"sm",onClick:s.handleValidateSignature,disabled:s.loading},{default:f(()=>e[21]||(e[21]=[m(" Validate ",-1)])),_:1,__:[21]},8,["onClick","disabled"])])])):v("",!0)])}}},Ye=J(Le,[["__scopeId","data-v-31ea104b"]]);export{Ye as D};