1import{u as W,r as g,j as e}from"./vendor-react-zwv87yMD.js";import{a as ye}from"./vendor-query-DYq8g7OI.js";import{p as be}from"./payroll-CkTcIQY8.js";import{u as je}from"./authStore-Bv6p2Ne2.js";import{u as ve}from"./useOrgTimezone-C1UagyKl.js";import{b as we,c as Ne,d as ke,e as Se,f as Ce,h as Te,i as Pe,j as Ae,k as De,l as Re,m as Le,n as Ee,o as Fe,p as Be,q as K,r as xe}from"./wage-receipts-CroFQ--9.js";import{c as J}from"./api-client-wl3SCNAO.js";import{u as Ie}from"./SignatureCapture-BFsHWfr8.js";import{T as $e,a as Me,b as Q,c as Z}from"./tabs-Dd8Qm6LV.js";import{B as E}from"./button-DlBDuKbo.js";import{S as We,L as Ge}from"./i18n-CwjSIy0a.js";import{p as Ue,o as He}from"./vendor-icons-bLSWzydc.js";import"./vendor-charts-CtrTLS4K.js";import"./vendor-i18n-BdYkS11p.js";import"./vendor-ui-CfDMlrKu.js";import"./vendor-pdf-DQuePnfN.js";import"./vendor-state-ByI9XJey.js";import"./vendor-editor-C_dhmuey.js";import"./employeeAuthStore-lYSKMuhw.js";import"./input-C9cRIRX4.js";import"./utils-BXSzAfFa.js";import"./label-CSUA9GMO.js";import"./signatureImage-rQ9wtwg0.js";function le(r){return`$${(r/100).toFixed(2)}`}function oe({field:r,sortField:n,sortDirection:a}){return n!==r?e.jsx("svg",{className:"w-4 h-4 text-muted-foreground/50",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 16V4m0 0L3 8m4-4l4 4m6 0v12m0 0l4-4m-4 4l-4-4"})}):a==="asc"?e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})}):e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}function de(r){return r.employeeSignedAt&&r.employerSignedAt?4:r.employeeSignedAt?3:r.signingTokenSentAt&&!r.employeeSignedAt?r.signingTokenExpiresAt&&new Date(r.signingTokenExpiresAt)<new Date?1:2:0}function ce({receipt:r}){const{t:n}=W("wageReceipt"),a=!!r.employeeSignedAt,o=!!r.employerSignedAt,y=!!r.signingTokenSentAt&&!a,h=y&&r.signingTokenExpiresAt&&new Date(r.signingTokenExpiresAt)<new Date;return a&&o?e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400",children:n("status.fullySigned")}):a?e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-400",children:n("status.employeeSigned")}):h?e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400",children:n("status.linkExpired")}):y?e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-400",children:n("status.awaitingSignature")}):e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-slate-100 text-slate-800 dark:bg-slate-900/30 dark:text-slate-400",children:n("status.notSent")})}function Oe({signingUrl:r,onClose:n}){const{t:a}=W("wageReceipt");return g.useEffect(()=>{const o=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=o}},[]),g.useEffect(()=>{const o=y=>{y.key==="Escape"&&n()};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[n]),e.jsx("div",{className:"fixed inset-0 z-50 bg-black/50 flex items-center justify-center p-2 sm:p-4",onClick:o=>{o.target===o.currentTarget&&n()},children:e.jsxs("div",{className:"bg-white rounded-xl shadow-2xl w-full h-full max-w-2xl max-h-[95vh] flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b bg-slate-50",children:[e.jsx("h3",{className:"font-semibold text-slate-700",children:a("signingModal.title")}),e.jsx("button",{onClick:n,className:"p-2 hover:bg-slate-200 rounded-lg text-slate-500",children:"â"})]}),e.jsx("iframe",{src:r,className:"flex-1 w-full border-0",title:a("signingModal.iframeTitle")})]})})}function me({receiptId:r,onOpenSigning:n}){const{t:a}=W("wageReceipt"),o=xe(),y=async()=>{var h,k;try{const{signingUrl:f}=await o.mutateAsync(r);n(f)}catch(f){alert(((k=(h=f.response)==null?void 0:h.data)==null?void 0:k.message)||a("errors.generateLinkFailed"))}};return e.jsx("button",{onClick:y,disabled:o.isPending,className:"min-h-[44px] sm:min-h-0 px-2 py-2 sm:px-0 sm:py-0 text-xs sm:text-sm font-medium sm:font-normal text-emerald-600 hover:underline border border-emerald-600/30 sm:border-0 rounded-lg sm:rounded-none hover:bg-emerald-50 sm:hover:bg-transparent dark:hover:bg-emerald-900/20 sm:dark:hover:bg-transparent",children:o.isPending?"...":a("actions.sign")})}function ue({receiptId:r}){const{t:n}=W("wageReceipt"),a=xe(),[o,y]=g.useState(!1),h=async()=>{var k,f,j;try{if(typeof ClipboardItem<"u"&&((k=navigator.clipboard)!=null&&k.write)){const v=a.mutateAsync(r).then(({signingUrl:u})=>new Blob([u],{type:"text/plain"}));await navigator.clipboard.write([new ClipboardItem({"text/plain":v})])}else{const{signingUrl:v}=await a.mutateAsync(r);await navigator.clipboard.writeText(v)}y(!0),setTimeout(()=>y(!1),2e3)}catch(v){alert(((j=(f=v.response)==null?void 0:f.data)==null?void 0:j.message)||n("errors.generateLinkFailed"))}};return e.jsx("button",{onClick:h,disabled:a.isPending,className:"min-h-[44px] sm:min-h-0 px-2 py-2 sm:px-0 sm:py-0 text-xs sm:text-sm font-medium sm:font-normal text-amber-600 hover:underline border border-amber-600/30 sm:border-0 rounded-lg sm:rounded-none hover:bg-amber-50 sm:hover:bg-transparent dark:hover:bg-amber-900/20 sm:dark:hover:bg-transparent",children:a.isPending?"...":n(o?"actions.copied":"actions.copyLink")})}function ze({templates:r}){const{t:n}=W("wageReceipt"),{currentOrganizationId:a}=je(),[o,y]=g.useState(""),[h,k]=g.useState(!1),[f,j]=g.useState(null),[v,u]=g.useState(null),[S,G]=g.useState(!1),[T,q]=g.useState("employee"),[R,F]=g.useState("asc"),[b,I]=g.useState(!1),[z,$]=g.useState(null),U=t=>{T===t?F(R==="asc"?"desc":"asc"):(q(t),F("asc"))},{data:P=[]}=ye({queryKey:["payroll-periods",a],queryFn:()=>be.getPeriods(),enabled:!!a,staleTime:300*1e3,gcTime:900*1e3});g.useEffect(()=>{if(P.length===0){o&&y("");return}(!o||!P.find(t=>
1t.id===o))&&y(P[0].id)},[P,o]);const{data:i=[],isLoading:c,refetch:w}=Ne(o?{payrollPeriodId:o}:void 0);g.useEffect(()=>{const t=l=>{l.data==="wage-receipt-signed"&&($(null),w())};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[w]);const N=ke(),A=Se(),D=Ce(),s=Te(),p=Pe(),H=Ae(),L=r.find(t=>t.isDefault)||r[0],Y=async()=>{if(o){k(!0);try{const t=await N.mutateAsync({payrollPeriodId:o,templateId:L==null?void 0:L.id});w();const l=[n("toast.generated",{count:t.generated})];t.skipped>0&&l.push(n("toast.skipped",{count:t.skipped})),t.failed>0&&(l.push(n("toast.failed",{count:t.failed})),console.error("Receipt generation errors:",t.errors)),(t.generated>0||t.failed>0)&&alert(l.join(" "))}catch{alert(n("errors.generateReceiptsFailed"))}finally{k(!1)}}},X=async t=>{const l=window.open("","_blank");if(!l){try{const m=await K(t),d=URL.createObjectURL(m),x=document.createElement("a");x.href=d,x.download=`wage-receipt-${t}.pdf`,document.body.appendChild(x),x.click(),document.body.removeChild(x),setTimeout(()=>URL.revokeObjectURL(d),1e3)}catch(m){console.error("Failed to load PDF:",m),alert(n("errors.loadPdfFailed"))}return}l.document.write(` 2 <html> 3 <head><title>${n("pdfWindow.loadingTitle")}</title></head> 4 <body style="display:flex;align-items:center;justify-content:center;height:100vh;margin:0;font-family:system-ui,sans-serif;"> 5 <div style="text-align:center;"> 6 <div style="border:3px solid #e5e7eb;border-top-color:#3b82f6;border-radius:50%;width:40px;height:40px;animation:spin 1s linear infinite;margin:0 auto 16px;"></div> 7 <p style="color:#6b7280;">${n("pdfWindow.loadingText")}</p> 8 </div> 9 <style>@keyframes spin{to{transform:rotate(360deg)}}</style> 10 </body> 11 </html> 12 `);try{const m=await K(t),d=URL.createObjectURL(m);l.location.href=d,setTimeout(()=>URL.revokeObjectURL(d),3e4)}catch(m){console.error("Failed to load PDF:",m),l.document.body.innerHTML=` 13 <div style="display:flex;align-items:center;justify-content:center;height:100vh;margin:0;font-family:system-ui,sans-serif;"> 14 <div style="text-align:center;"> 15 <p style="color:#dc2626;font-weight:500;">${n("pdfWindow.errorTitle")}</p> 16 <p style="color:#6b7280;margin-top:8px;">${n("pdfWindow.errorText")}</p> 17 </div> 18 </div> 19 `}},B=typeof navigator<"u"&&!!navigator.share&&!!navigator.canShare,_=async(t,l)=>{var m;try{const d=await K(t),x=`wage-receipt-${(l==null?void 0:l.replace(/\s+/g,"-"))||t}.pdf`,C=new File([d],x,{type:"application/pdf"});navigator.share&&((m=navigator.canShare)!=null&&m.call(navigator,{files:[C]}))&&await navigator.share({files:[C],title:x})}catch(d){(d==null?void 0:d.name)!=="AbortError"&&console.error("Failed to share PDF:",d)}},ee=g.useMemo(()=>i.filter(t=>t.employeeSignedAt||t.employerSignedAt).length,[i]),he=async()=>{var l,m;if(!o)return;const t=ee>0?n("confirm.deleteAllSigned",{signedCount:ee,total:i.length}):n("confirm.deleteAll",{count:i.length});if(confirm(t))try{const d=await D.mutateAsync(o);alert(n("toast.deletedReceipts",{count:d.deleted}))}catch(d){console.error("Failed to delete receipts:",d),alert(((m=(l=d.response)==null?void 0:l.data)==null?void 0:m.message)||n("errors.deleteReceiptsFailed"))}},te=async(t,l,m)=>{const d=m?n("confirm.deleteSigned",{name:l}):n("confirm.deleteOne",{name:l});if(confirm(d))try{await A.mutateAsync(t)}catch(x){console.error("Failed to delete receipt:",x),alert(n("errors.deleteReceiptFailed"))}},se=async t=>{var C,M;const l=t.employee?`${t.employee.lastName}, ${t.employee.firstName}`:n("common.thisEmployee"),m=!!t.employeeSignedAt,d=!!t.employerSignedAt;let x;if(m&&d?x=n("confirm.regenerateBothSigned",{name:l}):m?x=n("confirm.regenerateEmployeeSigned",{name:l}):d?x=n("confirm.regenerateEmployerSigned",{name:l}):x=n("confirm.regenerate",{name:l}),!!confirm(x)){u(t.id);try{await A.mutateAsync(t.id),await s.mutateAsync({payrollPeriodId:t.payrollPeriodId,employeeId:t.employeeId,templateId:t.templateId||(L==null?void 0:L.id)}),alert(n("toast.regenerated",{name:l}))}catch(O){console.error("Failed to regenerate receipt:",O),alert(((M=(C=O.response)==null?void 0:C.data)==null?void 0:M.message)||n("errors.regenerateFailed"))}finally{u(null)}}},ne=async t=>{var l,m;j(t);try{await p.mutateAsync({id:t,dto:{channel:"EMAIL"}}),w(),alert(n("toast.linkSent"))}catch(d){console.error("Failed to send signing link:",d),alert(((m=(l=d.response)==null?void 0:l.data)==null?void 0:m.message)||n("errors.sendLinkFailed"))}finally{j(null)}},V=g.useMemo(()=>i.filter(t=>!t.employeeSignedAt),[i]),ae=V.length,re=g.useMemo(()=>({totalHours:i.reduce((t,l)=>{var m,d;return t+(((d=(m=l.receiptData)==null?void 0:m.hours)==null?void 0:d.total)||0)},0),totalGrossPay:i.reduce((t,l)=>{var m,d;return t+(((d=(m=l.receiptData)==null?void 0:m.totals)==null?void 0:d.grossPay)||0)},0)}),[i]),ie=g.useMemo(()=>[...i].sort((t,l)=>{var d,x,C,M;let m=0;switch(T){case"employee":{const O=t.employee?`${t.employee.lastName} ${t.employee.firstName}`:((x=(d=t.receiptData)==null?void 0:d.employee)==null?void 0:x.name)||"",fe=l.employee?`${l.employee.lastName} ${l.employee.firstName}`:((M=(C=l.receiptData)==null?void 0:C.employee)==null?void 0:M.name)||"";m=O.localeCompare(fe);break}case"status":m=de(t)-de(l);break}return R==="asc"?m:-m}),[i,T,R]),pe=async()=>
19{if(V.length===0){alert(n("toast.allSigned"));return}if(confirm(n("confirm.batchSend",{count:V.length}))){G(!0);try{const t=await H.mutateAsync({receiptIds:V.map(l=>l.id),channel:"EMAIL"});w(),alert(n("toast.batchSent",{sent:t.sent,skipped:t.skipped})),t.errors.length>0&&console.warn("Some errors occurred:",t.errors)}catch(t){console.error("Failed to send signing links:",t),alert(n("errors.sendLinksFailed"))}finally{G(!1)}}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"bg-card border rounded-lg p-3 sm:p-4",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:flex-wrap sm:items-end gap-3 sm:gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0 sm:min-w-[200px]",children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:n("filters.payrollPeriod")}),e.jsxs("select",{value:o,onChange:t=>y(t.target.value),className:"w-full px-3 py-2.5 sm:py-2 bg-background border rounded-md focus:outline-none focus:ring-2 focus:ring-primary text-sm min-h-[44px] sm:min-h-0",children:[e.jsx("option",{value:"",children:n("filters.selectPeriod")}),P.map(t=>e.jsxs("option",{value:t.id,children:[J(t.startDate)," - ",J(t.endDate),t.isProcessed?" â":""]},t.id))]})]}),o&&e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsx(E,{onClick:Y,disabled:h||!L,className:"flex-1 sm:flex-none min-h-[44px] sm:min-h-0",children:n(h?"actions.generating":"actions.generate")}),i.length>0&&ae>0&&e.jsx(E,{variant:"outline",onClick:pe,disabled:S,className:"flex-1 sm:flex-none min-h-[44px] sm:min-h-0",children:S?n("actions.sending"):e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"hidden sm:inline",children:[n("actions.sendForSignatures")," "]}),"(",ae,")"]})}),i.length>0&&e.jsx(E,{variant:"destructive",onClick:he,disabled:D.isPending,className:"min-h-[44px] sm:min-h-0",children:D.isPending?n("actions.deleting"):e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"hidden sm:inline",children:[n("actions.deleteAll")," "]}),"(",i.length,")"]})})]})]}),o&&!L&&e.jsx("p",{className:"mt-3 sm:mt-4 text-sm text-amber-600 dark:text-amber-400",children:n("messages.noTemplateConfigured")})]}),o&&e.jsx("div",{className:"sm:hidden space-y-3",children:c?e.jsx("div",{className:"px-4 py-8 text-center text-muted-foreground",children:n("messages.loadingReceipts")}):i.length===0?e.jsx("div",{className:"px-4 py-8 text-center text-muted-foreground",children:n("messages.noReceipts")}):ie.map(t=>{var l,m,d,x,C;return e.jsxs("div",{className:"bg-card border rounded-lg p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-sm truncate",children:t.employee?`${t.employee.lastName}, ${t.employee.firstName}`:((m=(l=t.receiptData)==null?void 0:l.employee)==null?void 0:m.name)||n("common.unknown")}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-0.5",children:[((C=(x=(d=t.receiptData)==null?void 0:d.hours)==null?void 0:x.total)==null?void 0:C.toFixed(2))||"0.00","h"]})]}),e.jsx(ce,{receipt:t})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsx("button",{onClick:()=>X(t.id),className:"min-h-[44px] px-2 py-2 text-xs font-medium text-primary border border-primary/30 rounded-lg hover:bg-primary/5",children:n("actions.view")}),B&&e.jsx("button",{onClick:()=>_(t.id,t.employee?`${t.employee.firstName}-${t.employee.lastName}`:void 0),className:"min-h-[44px] px-2 py-2 text-xs font-medium text-blue-600 border border-blue-600/30 rounded-lg hover:bg-blue-50 dark:hover:bg-blue-900/20",children:n("actions.share")}),!t.employeeSignedAt&&e.jsx(me,{receiptId:t.id,onOpenSigning:$}),!t.employeeSignedAt&&e.jsx("button",{onClick:()=>ne(t.id),disabled:f===t.id,className:"min-h-[44px] px-2 py-2 text-xs font-medium text-purple-600 border border-purple-600/30 rounded-lg hover:bg-purple-50 dark:hover:bg-purple-900/20 disabled:opacity-50",children:f===t.id?"...":t.signingTokenSentAt?n("actions.resend"):n("actions.send")}),!t.employeeSignedAt&&e.jsx(ue,{receiptId:t.id}),e.jsx("button",{onClick:()=>se(t),disabled:v===t.id,className:"min-h-[44px] px-2 py-2 text-xs font-medium text-blue-600 border border-blue-600/30 rounded-lg hover:bg-blue-50 dark:hover:bg-blue-900/20 disabled:opacity-50",children:v===t.id?"...":n("actions.regen")}),e.jsx("button",{onClick:()=>te(t.id,t.employee?`${t.employee.lastName}, ${t.employee.firstName}`:n("common.thisEmployee"),!!(t.employeeSignedAt||t.employerSignedAt)),disabled:A.isPending,className:"min-h-[44px] px-2 py-2 text-xs font-medium text-destructive border border-destructive/30 rounded-lg hover:bg-destructive/5 disabled:opacity-50",children:n("actions.delete")})]})]},t.id)})}),o&&e.jsx("div",{className:"hidden sm:block bg-card border rounded-lg overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/50",children:[e.jsx("th",{className:"px-4 py-3 text-left text-sm font-medium",children:e.jsxs("button",{onClick:()=>U("employee"),className:"flex items-center gap-1 hover:text-primary transition-colors",children:[n("table.employee"),e.jsx(oe,{field:"employee",sortField:T,sortDirection:R})]})}),e.jsx("th",{className:"px-4 py-3 text-right text-sm font-medium",children:n("table.hours")}),e.jsx("th",{className:"px-4 py-3 text-right text-sm font-medium hidden md:table-cell",children:e.jsxs("div",{className:"flex items-center gap-1 justify-end",children:[n("table.grossPay"),e.jsx("button",{onClick:()=>I(!b),className:"p-0.5 rounded hover:bg-slate-200 transition-colors text-slate-400 hover:text-slate-600",title:n(b?"table.hideGrossPay":"table.showGrossPay"),children:b?e.jsx(Ue,{className:"h-3.5 w-3.5"}):e.jsx(He,{className:"h-3.5 w-3.5"})})]})}),e.jsx("th",{className:"px-4 py-3 text-center text-sm font-medium",children:e.jsxs("button",{onClick:()=>U("status"),className:"flex items-center gap-1 hover:text-primary transition-colors mx-auto",children:[n("table.status"),e.jsx(oe,{field:"status",sortField:T,sortDirection:R})]})}),e.jsx("th",{className:"px-4 py-3 text-left text-sm font-medium hidden lg:table-cell",children:n("table.generated")}),e.jsx("th",{className:"px-4 py-3 text-right text-sm font-medium",children:n("table.actions")})]})}),e.jsx("tbody",{children:c?e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"px-4 py-8 text-center text-muted-foreground",children:n("messages.loadingReceipts")})}):i.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"px-4 py-8 text-center text-muted-foreground",children:n("messages.noReceipts")})}):ie.map(t=>{var l,m,d,x,C,M,O;return e.jsxs("tr",{className:"border-b last:border-0 hover:bg-muted/30",children:[e.jsx("td",{className:"px-4 py-3 text-sm",children:t.employee?`${t.employee.lastName}, ${t.employee.firstName}`:((m=(l=t.receiptData)==null?void 0:l.employee)==null?void 0:m.name)||n("common.unknown")}),e.jsx("td",{className:"px-4 py-3 text-sm text-right",children:((C=(x=(d=t.receiptData)==null?void 0:d.hours)==null?void 0:x.total)==null?void 0:C.toFixed(2))||"0.00"}),e.jsx("td",{className:"px-4 py-3 text-sm text-right font-medium hidden md:table-cell",children:b?le(((O=(M=t.receiptData)==null?void 0:M.totals)==null?void 0:O.grossPay)||0):e.jsx("span",{className:"text-slate-400",children:"â¢â¢â¢â¢"})}),e.jsx("td",{className:"px-4 py-3 text-center",children:e.jsx(ce,{receipt:t})}),e.jsx("td",{className:"px-4 py-3 text-sm text-muted-foreground hidden lg:table-cell",children:J(t.generatedAt)}),e.jsx("td",{className:"px-4 py-3 text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2 flex-wrap",children:[e.jsx("button",{onClick:()=>X(t.id),className:"text-sm text-primary hover:underline",children:n("actions.view")}),B&&e.jsx("button",{onClick:()=>_(t.id,t.employee?`${t.employee.firstName}-${t.employee.lastName}`:void 0),className:"text-sm text-blue-600 hover:underline",children:n("actions.share")}),!t.employeeSignedAt&&e.jsx(me,{receiptId:t.id,onOpenSigning:$}),!t.employeeSignedAt&&e.jsx("button",{onClick:()=>ne(t.id),disabled:f===t.id,className:"text-sm text-purple-600 hover:underline disabled:opacity-50 disabled:cursor-not-allowed",children:f===t.id?"...":t.signingTokenSentAt?n("actions.resend"):n("actions.send")}),!t.employeeSignedAt&&e.jsx(ue,{receiptId:t.id}),e.jsx("button",{onClick:()=>se(t),disabled:v===t.id,className:"text-sm text-blue-600 hover:underline disabled:opacity-50 disabled:cursor-not-allowed",children:v===t.id?"...":n("actions.regenerate")}),e.jsx("button",{onClick:()=>te(t.id,t.employee?`${t.employee.lastName}, ${t.employee.firstName}`:n("common.thisEmployee"),!!(t.employeeSignedAt||t.employerSignedAt)),disabled:A.isPending,className:"text-sm text-destructive hover:underline disabled:opacity-50 disabled:cursor-not-allowed",children:n("actions.delete")})]})})]},t.id)})})]})})}),i.length>0&&e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"bg-card border rounded-lg p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:n("summary.totalReceipts")}),e.jsx("div",{className:"text-2xl font-bold mt-1",children:i.length})]}),e.jsxs("div",{className:"bg-card border rounded-lg p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:n("summary.totalHours")}),e.jsx("div",{className:"text-2xl font-bold mt-1",children:re.totalHours.toFixed(2)})]}),e.jsxs("div",{className:"bg-card border rounded-lg p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:n("summary.totalGrossPay")}),e.jsx("div",{className:"text-2xl font-bold mt-1",children:b?le(re.totalGrossPay):e.jsx("span",{className:"text-slate-400",children:"â¢â¢â¢â¢"})})]})]}),z&&e.jsx(Oe,{signingUrl:z,onClose:()=>{$(null),w()}})]})}const ge=We.map(r=>({value:r,label:Ge[r]}));function qe({templates:r,onRefresh:n}){var D;const{t:a}=W("wageReceipt"),o=r.find(s=>
19s.isDefault)||r[0],[y,h]=g.useState((o==null?void 0:o.id)||null),[k,f]=g.useState(!1),j=k?null:r.find(s=>s.id===y),v=s=>({name:(s==null?void 0:s.name)||"",description:(s==null?void 0:s.description)||"",headerText:(s==null?void 0:s.headerText)||"",language:(s==null?void 0:s.primaryLanguage)||"en",showCompanyLogo:(s==null?void 0:s.showCompanyLogo)??!0,showDailyHours:(s==null?void 0:s.showDailyHours)??!0,showClockTimes:(s==null?void 0:s.showClockTimes)??!0,showBreakTimes:(s==null?void 0:s.showBreakTimes)??!0,showPayrollNotes:(s==null?void 0:s.showPayrollNotes)??!0,requireSignature:(s==null?void 0:s.requireSignature)??!0,customText:(s==null?void 0:s.signaturePrompt)||"",signaturePromptEn:(s==null?void 0:s.signaturePromptEn)||"",signaturePromptEs:(s==null?void 0:s.signaturePromptEs)||""}),[u,S]=g.useState(v(j)),[G,T]=g.useState(!1),[q,R]=g.useState(!1),[F,b]=g.useState(null),I=De(),z=Re(),$=Le(),U=s=>{const p=r.find(H=>H.id===s);h(s),f(!1),S(v(p)),b(null)},P=g.useCallback(s=>{S(p=>({...p,[s.target.name]:s.target.value}))},[]),i=g.useCallback(s=>{S(p=>({...p,[s.target.name]:s.target.checked}))},[]),c=g.useCallback(s=>{s.target.value.length<=5e3&&S(p=>({...p,[s.target.name]:s.target.value}))},[]),w=()=>{f(!0),h(null),S(v(null)),b(null)},N=async(s,p)=>{var X;const H=r.find(B=>B.id===s),L=((X=H==null?void 0:H._count)==null?void 0:X.employees)||0;let Y=a("template.confirmDelete",{name:p});if(L>0&&(Y+=` 20 21${a("template.confirmDeleteAssigned",{count:L})}`),!!confirm(Y)){R(!0);try{if(await $.mutateAsync(s),y===s){const B=r.filter(_=>_.id!==s);B.length>0?U(B[0].id):w()}n(),b({type:"success",text:a("template.deleteSuccess")})}catch(B){console.error("Failed to delete template:",B),b({type:"error",text:a("template.deleteFailed")})}finally{R(!1)}}},A=async()=>{if(!u.name.trim()){b({type:"error",text:a("template.nameRequired")});return}T(!0),b(null);try{const s={name:u.name,description:u.description||void 0,headerText:u.headerText||void 0,stateCode:"CA",primaryLanguage:u.language,showCompanyLogo:u.showCompanyLogo,showDailyHours:u.showDailyHours,showClockTimes:u.showClockTimes,showBreakTimes:u.showBreakTimes,showPayrollNotes:u.showPayrollNotes,requireSignature:u.requireSignature,signaturePrompt:u.customText||void 0,signaturePromptEn:u.signaturePromptEn||void 0,signaturePromptEs:u.signaturePromptEs||void 0,isDefault:r.length===0||(j==null?void 0:j.isDefault)||!1};if(j)await z.mutateAsync({id:j.id,dto:s}),b({type:"success",text:a("template.updateSuccess")});else{const p=await I.mutateAsync(s);h(p.id),f(!1),b({type:"success",text:a("template.createSuccess")})}n()}catch(s){console.error("Failed to save template:",s),b({type:"error",text:a("template.saveFailed")})}finally{T(!1)}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"bg-card border rounded-lg p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:a("template.yourTemplates")}
21),e.jsx(E,{variant:k?"secondary":"outline",size:"sm",onClick:w,children:a("template.createNew")})]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:a("template.description")}),r.length===0?e.jsx("p",{className:"text-sm text-muted-foreground italic py-4 text-center border rounded-lg",children:a("template.noTemplates")}):e.jsx("div",{className:"space-y-2",children:r.map(s=>{var p;return e.jsxs("div",{className:`flex items-center justify-between p-3 rounded-lg border transition-colors ${!k&&y===s.id?"border-primary bg-primary/5":"border-border"}`,children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:s.name}),s.isDefault&&e.jsx("span",{className:"px-2 py-0.5 text-xs rounded-full bg-primary/10 text-primary",children:a("template.defaultBadge")}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s.primaryLanguage==="en"?a("template.langEnglish"):s.primaryLanguage==="es"?a("template.langSpanish"):a("template.langChinese")})]}),s.description&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:s.description})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:a("template.employeesAssigned",{count:((p=s._count)==null?void 0:p.employees)||0})}),e.jsx(E,{variant:"outline",size:"sm",onClick:()=>U(s.id),children:a("actions.edit")}),e.jsx(E,{variant:"outline",size:"sm",onClick:()=>N(s.id,s.name),disabled:q||s.isDefault,className:"text-red-600 hover:text-red-700 hover:bg-red-50 dark:hover:bg-red-950/30",children:a("actions.delete")})]})]},s.id)})})]}),e.jsxs("div",{className:"bg-card border rounded-lg p-6",children:[e.jsx("h3",{className:"text-lg font-semibold mb-6",children:a(j?"template.editTemplate":"template.createNewTemplate")}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:a("template.nameLabel")}),e.jsx("input",{type:"text",name:"name",value:u.name,onChange:P,className:"w-full px-3 py-2 bg-background border rounded-md focus:outline-none focus:ring-2 focus:ring-primary",placeholder:a("template.namePlaceholder")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:a("template.languageLabel")}),e.jsx("select",{name:"language",value:u.language,onChange:P,className:"w-full px-3 py-2 bg-background border rounded-md focus:outline-none focus:ring-2 focus:ring-primary",children:ge.map(s=>e.jsx("option",{value:s.value,children:s.label},s.value))}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:a("template.languageHelp")})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:a("template.descriptionLabel")}),e.jsx("textarea",{name:"description",value:u.description,onChange:P,className:"w-full px-3 py-2 bg-background border rounded-md focus:outline-none focus:ring-2 focus:ring-primary resize-none",rows:2,placeholder:a("template.descriptionPlaceholder")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:a("template.descriptionHelp")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:a("template.receiptTitleLabel")}),e.jsx("input",{type:"text",name:"headerText",value:u.headerText,onChange:P,className:"w-full px-3 py-2 bg-background border rounded-md focus:outline-none focus:ring-2 focus:ring-primary",placeholder:a("template.receiptTitlePlaceholder"),maxLength:200}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:a("template.receiptTitleHelp")})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold mb-3",children:a("template.displayOptions")}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("label",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",name:"showCompanyLogo",checked:u.showCompanyLogo,onChange:i,className:"w-4 h-4 rounded border-gray-300 text-primary focus:ring-primary"}),e.jsx("span",{className:"text-sm",children:a("template.showCompanyLogo")})]}),e.jsxs("label",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",name:"showDailyHours",checked:u.showDailyHours,onChange:i,className:"w-4 h-4 rounded border-gray-300 text-primary focus:ring-primary"}),e.jsx("span",{className:"text-sm",children:a("template.showDailyHours")})]}),u.showDailyHours&&e.jsxs("div",{className:"ml-7 space-y-3",children:[e.jsxs("label",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",name:"showClockTimes",checked:u.showClockTimes,onChange:i,className:"w-4 h-4 rounded border-gray-300 text-primary focus:ring-primary"}),e.jsx("span",{className:"text-sm",children:a("template.showClockTimes")})]}),e.jsxs("label",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",name:"showBreakTimes",checked:u.showBreakTimes,onChange:i,className:"w-4 h-4 rounded border-gray-300 text-primary focus:ring-primary"}),e.jsx("span",{className:"text-sm",children:a("template.showBreakTimes")})]})]}),e.jsxs("label",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",name:"showPayrollNotes",checked:u.showPayrollNotes,onChange:i,className:"w-4 h-4 rounded border-gray-300 text-primary focus:ring-primary"}),e.jsx("span",{className:"text-sm",children:a("template.showPayrollNotes")})]}),e.jsxs("label",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",name:"requireSignature",checked:u.requireSignature,onChange:i,className:"w-4 h-4 rounded border-gray-300 text-primary focus:ring-primary"}),e.jsx("span",{className:"text-sm",children:a("template.requireSignature")})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-sm font-semibold",children:a("template.acknowledgmentText")}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-2",children:a("template.acknowledgmentHelp")}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{className:"block text-sm font-medium",children:((D=ge.find(s=>
21s.value===u.language))==null?void 0:D.label)||a("template.langEnglish")}),e.jsx("span",{className:`text-xs ${u.signaturePromptEn.length>5e3?"text-red-500":"text-muted-foreground"}`,children:a("template.characterCount",{length:u.signaturePromptEn.length})})]}),e.jsx("textarea",{name:"signaturePromptEn",value:u.signaturePromptEn,onChange:c,className:"w-full px-3 py-2 bg-background border rounded-md focus:outline-none focus:ring-2 focus:ring-primary resize-none",rows:5,placeholder:a("template.acknowledgmentPlaceholder")})]})]}),e.jsxs("div",{className:"flex items-center gap-4 pt-4 border-t",children:[e.jsx(E,{onClick:A,disabled:G,children:a(G?"actions.saving":j?"template.updateTemplate":"template.createTemplate")}),F&&e.jsx("span",{className:`text-sm ${F.type==="success"?"text-green-600 dark:text-green-400":"text-red-600 dark:text-red-400"}`,children:F.text})]})]})]})]})}function Xe(){const{t:r}=W("wageReceipt"),n=ve(),a=g.useRef(null),[o,y]=g.useState(!1),[h,k]=g.useState("drawn"),[f,j]=g.useState(""),[v,u]=g.useState(!1),{data:S,isLoading:G}=Ee(),T=Fe(),q=Be();g.useEffect(()=>{const i=a.current;if(i&&h==="drawn"){const c=i.getContext("2d");c&&(c.fillStyle="white",c.fillRect(0,0,i.width,i.height),c.strokeStyle="#1e40af",c.lineWidth=2,c.lineCap="round",c.lineJoin="round")}},[h]);const R=i=>{y(!0);const c=a.current;if(!c)return;const w=c.getContext("2d");if(!w)return;const N=c.getBoundingClientRect(),A=c.width/N.width,D=c.height/N.height;let s,p;"touches"in i?(s=(i.touches[0].clientX-N.left)*A,p=(i.touches[0].clientY-N.top)*D):(s=(i.clientX-N.left)*A,p=(i.clientY-N.top)*D),w.beginPath(),w.moveTo(s,p)},F=i=>{if(!o)return;const c=a.current;if(!c)return;const w=c.getContext("2d");if(!w)return;const N=c.getBoundingClientRect(),A=c.width/N.width,D=c.height/N.height;let s,p;"touches"in i?(i.preventDefault(),s=(i.touches[0].clientX-N.left)*A,p=(i.touches[0].clientY-N.top)*D):(s=(i.clientX-N.left)*A,p=(i.clientY-N.top)*D),w.lineTo(s,p),w.stroke(),u(!0)},b=()=>{y(!1)},I=()=>{const i=a.current;if(i){const c=i.getContext("2d");c&&(c.fillStyle="white",c.fillRect(0,0,i.width,i.height))}u(!1),j("")},z=()=>{if(h==="drawn"){if(!v)return null;const i=a.current;return i?i.toDataURL("image/png"):null}else{if(!f.trim())return null;const i=document.createElement("canvas");i.width=400,i.height=100;const c=i.getContext("2d");return c?(c.fillStyle="white",c.fillRect(0,0,i.width,i.height),c.fillStyle="#1e40af",c.font='italic 36px "Dancing Script", "Brush Script MT", cursive',c.textAlign="center",c.textBaseline="middle",c.fillText(f,200,50),i.toDataURL("image/png")):null}},$=async()=>{const i=z();if(i)try{await T.mutateAsync({signature:i,signatureType:h,typedName:h==="typed"?f:void 0}),alert(r("signature.saveSuccess"))}catch(c){console.error("Failed to save signature:",c),alert(r("signature.saveFailed"))}},U=async()=>{if(confirm(r("signature.confirmDelete")))try{await q.mutateAsync(),I(),alert(r("signature.deleteSuccess"))}catch(i){console.error("Failed to delete signature:",i),alert(r("signature.deleteFailed"))}},P=h==="drawn"&&v||h==="typed"&&f.trim().length>=2;return G?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-2 border-primary border-t-transparent"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"bg-card border rounded-lg p-6",children:[e.jsx("h2",{className:"text-lg font-semibold mb-2",children:r("signature.title")}),e.jsx("p",{className:"text-sm text-muted-foreground mb-6",children:r("signature.description")}),(S==null?void 0:S.signature)&&e.jsxs("div",{className:"mb-6 p-4 bg-muted/50 rounded-lg",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-sm font-medium",children:r("signature.currentSaved")}),e.jsx(E,{variant:"destructive",size:"sm",onClick:U,children:r("actions.delete")})]}),e.jsx("div",{className:"bg-white rounded border p-4 flex justify-center",children:e.jsx("img",{src:S.signature,alt:r("signature.imageAlt"),className:"max-h-20"})}),S.signatureSetAt&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:[r("signature.savedOn")," ",new Date(S.signatureSetAt).toLocaleDateString(void 0,{timeZone:n})]})]}),e.jsxs("div",{className:"flex gap-2 mb-4",children:[e.jsx("button",{onClick:()=>{k("drawn"),I()}
21,className:`flex-1 py-2 px-4 rounded-lg font-medium transition-colors ${h==="drawn"?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground hover:bg-muted/80"}`,children:r("signature.drawSignature")}),e.jsx("button",{onClick:()=>{k("typed"),I()},className:`flex-1 py-2 px-4 rounded-lg font-medium transition-colors ${h==="typed"?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground hover:bg-muted/80"}`,children:r("signature.typeSignature")})]}),h==="drawn"?e.jsxs("div",{className:"space-y-2",children:[e.jsx("canvas",{ref:a,width:500,height:150,className:"w-full border-2 border-dashed border-muted-foreground/30 rounded-lg bg-white cursor-crosshair touch-none",onMouseDown:R,onMouseMove:F,onMouseUp:b,onMouseLeave:b,onTouchStart:R,onTouchMove:F,onTouchEnd:b}),e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:r("signature.drawHint")})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsx("input",{type:"text",value:f,onChange:i=>j(i.target.value),placeholder:r("signature.typePlaceholder"),className:"w-full px-4 py-3 border rounded-lg bg-background focus:outline-none focus:ring-2 focus:ring-primary text-center",style:{fontFamily:'"Dancing Script", "Brush Script MT", cursive',fontSize:"24px"}}),f&&e.jsx("div",{className:"p-4 border rounded-lg bg-white",children:e.jsx("p",{className:"text-center",style:{fontFamily:'"Dancing Script", "Brush Script MT", cursive',fontSize:"32px",color:"#1e40af"},children:f})})]}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsx(E,{variant:"outline",onClick:I,children:r("actions.clear")}),e.jsx(E,{onClick:$,disabled:!P||T.isPending,children:T.isPending?r("actions.saving"):r("signature.saveSignature")})]})]}),e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 rounded-lg p-4",children:[e.jsx("h3",{className:"font-medium text-blue-900 dark:text-blue-100 mb-1",children:r("signature.howItWorks")}),e.jsxs("ul",{className:"text-sm text-blue-800 dark:text-blue-200 space-y-1 list-disc list-inside",children:[e.jsx("li",{children:r("signature.howItWorksItem1")}),e.jsx("li",{children:r("signature.howItWorksItem2")}),e.jsx("li",{children:r("signature.howItWorksItem3")})]})]})]})}function pt(){const{t:r}=W("wageReceipt");Ie();const[n,a]=g.useState("receipts"),{data:o=[],refetch:y}=we();return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:r("header.title")}),e.jsx("p",{className:"text-muted-foreground mt-1",children:r("header.subtitle")})]}),e.jsxs($e,{value:n,onValueChange:a,children:[e.jsxs(Me,{children:[e.jsx(Q,{value:"receipts",children:r("tabs.receipts")}),e.jsxs(Q,{value:"template",children:[r("tabs.template"),o.length===0&&e.jsx("span",{className:"ml-2 inline-flex items-center justify-center w-2 h-2 bg-amber-500 rounded-full"})]}),e.jsx(Q,{value:"signature",children:r("tabs.signature")})]}),e.jsx(Z,{value:"receipts",children:e.jsx(ze,{templates:o})}),e.jsx(Z,{value:"template",children:e.jsx(qe,{templates:o,onRefresh:y})}),e.jsx(Z,{value:"signature",children:e.jsx(Xe,{})})]})]})}export{pt as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.