1import{u as ge,r as l,j as t}from"./vendor-react-zwv87yMD.js";import{a as J,b as w}from"./vendor-query-DYq8g7OI.js";import{e as he}from"./employees-BPFguWOi.js";import{t as g}from"./time-entries-EFguVi-E.js";import{s as be}from"./employeeAuthStore-lYSKMuhw.js";import{C as fe}from"./CameraCapture-ipu8v8bE.js";import{u as pe}from"./authStore-Bv6p2Ne2.js";import{u as ke}from"./useOrgTimezone-C1UagyKl.js";import{f as V,a as ve}from"./timezoneFormatters-Lg56xFv0.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"./api-client-wl3SCNAO.js";import"./i18n-CwjSIy0a.js";import"./vendor-icons-bLSWzydc.js";function ze(){var Q,H,U;const{t:O}=ge("common"),{currentOrganizationId:h}=pe(),j=ke(),[i,d]=l.useState("select"),[n,T]=l.useState(null),[a,x]=l.useState(""),[F,c]=l.useState(""),[M,L]=l.useState(""),[r,u]=l.useState(null),[$,X]=l.useState(!1),[D,Y]=l.useState(new Date),[b,Z]=l.useState(window.innerWidth>window.innerHeight),[N,P]=l.useState(null),[_,C]=l.useState(null),{data:ee=[]}=J({queryKey:["employees",h],queryFn:he.getAll,enabled:!!h}),{data:E}=J({queryKey:["settings",h],queryFn:be.getSettings,enabled:!!h}),te=ee.filter(e=>e.isActive),re=(E==null?void 0:E.requirePhotoOnClock)==="ALL",S=te.filter(e=>`${e.firstName} ${e.lastName}`.toLowerCase().includes(M.toLowerCase())),m=l.useCallback(()=>{d("select"),T(null),x(""),c(""),L(""),u(null),P(null),C(null)},[]);l.useEffect(()=>{m()},[h,m]);const B=w({mutationFn:g.clockIn,onSuccess:e=>{u({isClockedIn:!0,currentEntry:e,isOnBreak:!1,currentBreak:null,totalBreakMinutes:0}),d("status"),c(""),setTimeout(()=>m(),5e3)},onError:e=>{var s,o;c(((o=(s=e.response)==null?void 0:s.data)==null?void 0:o.message)||"Failed to clock in"),x("")}}),I=w({mutationFn:g.clockOut,onSuccess:e=>{u({isClockedIn:!1,currentEntry:e||null,isOnBreak:!1,currentBreak:null,totalBreakMinutes:(e==null?void 0:e.breakDuration)||0}),d("status"),c(""),setTimeout(()=>m(),5e3)},onError:e=>{var s,o;c(((o=(s=e.response)==null?void 0:s.data)==null?void 0:o.message)||"Failed to clock out"),x("")}}),A=w({mutationFn:g.startBreak,onSuccess:e=>{var s;u({isClockedIn:!0,currentEntry:e,isOnBreak:!0,currentBreak:((s=e.breaks)==null?void 0:s[e.breaks.length-1])||null,totalBreakMinutes:e.breakDuration||0}),d("status"),c(""),setTimeout(()=>m(),3e3)},onError:e=>{var s,o;c(((o=(s=e.response)==null?void 0:s.data)==null?void 0:o.message)||"Failed to start break"),x("")}}),z=w({mutationFn:g.endBreak,onSuccess:e=>{u({isClockedIn:!0,currentEntry:e,isOnBreak:!1,currentBreak:null,totalBreakMinutes:e.breakDuration||0}),d("status"),c(""),setTimeout(()=>m(),3e3)},onError:e=>{var s,o;c(((o=(s=e.response)==null?void 0:s.data)==null?void 0:o.message)||"Failed to end break"),x("")}});l.useEffect(()=>{const e=setInterval(()=>Y(new Date),1e3);return()=>clearInterval(e)},[]),l.useEffect(()=>{const e=()=>{Z(window.innerWidth>window.innerHeight)};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),l.useEffect(()=>{const e=()=>{X(!!document.fullscreenElement)};return document.addEventListener("fullscreenchange",e),()=>document.removeEventListener("fullscreenchange",e)},[]),l.useEffect(()=>{let e;const s=()=>{clearTimeout(e),e=setTimeout(()=>{i!=="status"&&m()},6e4)};return window.addEventListener("touchstart",s),window.addEventListener("click",s),window.addEventListener("keydown",s),s(),()=>{clearTimeout(e),window.removeEventListener("touchstart",s),window.removeEventListener("click",s),window.removeEventListener("keydown",s)}},[i,m]),l.useEffect(()=>{n&&i==="pin"&&g.getStatus(n.id).then(e=>{u(e)})},[n,i]),l.useEffect(()=>{if(r!=null&&r.isClockedIn&&i==="pin"){const e=setInterval(()=>{n&&g.getStatus(n.id).then(s=>{u(s)})},1e3);return()=>clearInterval(e)}},[r==null?void 0:r.isClockedIn,i,n]);const se=()=>{var e,s,o;document.fullscreenElement?(o=document.exitFullscreen)==null||o.call(document):(s=(e=document.documentElement).requestFullscreen)==null||s.call(e)},ne=e=>{T(e),d("pin"),c(""),x("")},W=e=>{a.length<4&&x(a+e)},oe=()=>{x(a.slice(0,-1))},q=e=>{if(!n||a.length!==4){c("Please enter a 4-digit PIN");return}if(e!=="break"&&re&&!N){C("clock"),d("camera");return}const s={employeeId:n.id,pin:a,...N&&{photo:N}};if(e==="break"){r!=null&&r.isOnBreak?z.mutate(s):A.mutate(s);return}if(r!=null&&r.isClockedIn){if(r.isOnBreak)return;I.mutate(s)}else B.mutate(s)},le=e=>{if(P(e),d("pin"),_&&n&&a.length===4){const s={employeeId:n.id,pin:a,photo:e};r!=null&&r.isClockedIn?r.isOnBreak||I.mutate(s):B.mutate(s)}},ie=()=>{C(null),d("pin")},k=e=>V(e,j),ae=()=>V(D,j),ce=()=>ve(D,j,{weekday:"long",month:"long",day:"numeric",year:void 0}),de=()=>{var G;if(!((G=r==null?void 0:r.currentEntry)!=null&&G.clockIn))return"";const e=new Date(r.currentEntry.clockIn),o=new Date().getTime()-e.getTime(),f=(r.totalBreakMinutes||0)*60*1e3,p=o-f,xe=Math.floor(p/(1e3*60*60)),ue=Math.floor(p%(1e3*60*60)/(1e3*60));return`${xe}h ${ue}m`},me=()=>{var p;if(!(r!=null&&r.isOnBreak)||!((p=r==null?void 0:r.currentBreak)!=null&&p.start))return"";const e=new Date(r.currentBreak.start),o=new Date().getTime()-e.getTime(),y=Math.floor(o/(1e3*60)),f=Math.floor(o%(1e3*60)/1e3);return`${y}m ${f}s`},v=B.isPending||I.isPending||A.isPending||z.isPending,R=e=>`${e.firstName[0]}${e.lastName[0]}`.toUpperCase(),K=e=>{const s=[{bg:"bg-blue-500",light:"bg-blue-100 hover:bg-blue-200 border-blue-300",text:"text-blue-900"},{bg:"bg-green-500",light:"bg-green-100 hover:bg-green-200 border-green-300",text:"text-green-900"},{bg:"bg-purple-500",light:"bg-purple-100 hover:bg-purple-200 border-purple-300",text:"text-purple-900"},{bg:"bg-orange-500",light:"bg-orange-100 hover:bg-orange-200 border-orange-300",text:"text-orange-900"},{bg:"bg-pink-500",light:"bg-pink-100 hover:bg-pink-200 border-pink-300",text:"text-pink-900"},{bg:"bg-cyan-500",light:"bg-cyan-100 hover:bg-cyan-200 border-cyan-300",text:"text-cyan-900"},{bg:"bg-indigo-500",light:"bg-indigo-100 hover:bg-indigo-200 border-indigo-300",text:"text-indigo-900"},{bg:"bg-teal-500",light:"bg-teal-100 hover:bg-teal-200 border-teal-300",text:"text-teal-900"},{bg:"bg-rose-500",light:"bg-rose-100 hover:bg-rose-200 border-rose-300",text:"text-rose-900"},{bg:"bg-amber-500",light:"bg-amber-100 hover:bg-amber-200 border-amber-300",text:"text-amber-900"}],o=e.split("").reduce((y,f)=>y+f.charCodeAt(0),0);return s[o%s.length]};return t.jsxs("div",{className:"h-screen bg-gradient-to-br from-primary/10 to-accent/10 flex items-center justify-center p-2 sm:p-4 overflow-hidden select-none",children:[t.jsxs("div",{className:"bg-card border rounded-2xl shadow-2xl w-full max-w-5xl h-full max-h-[98vh] flex flex-col overflow-hidden",children:[t.jsxs("div",{className:"bg-primary text-primary-foreground px-4 sm:px-6 py-3 sm:py-4 flex-shrink-0",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"text-3xl sm:text-4xl font-bold tabular-nums",children:ae()}
1),t.jsx("div",{className:"text-primary-foreground/70 text-sm sm:text-base hidden sm:block",children:ce()})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("h1",{className:"text-xl sm:text-2xl font-bold",children:"Time Clock"}),t.jsx("button",{onClick:se,className:"p-2 hover:bg-primary-foreground/10 rounded-lg transition-colors touch-manipulation",title:$?"Exit Fullscreen":"Enter Kiosk Mode",children:$?t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("polyline",{points:"4 14 10 14 10 20"}),t.jsx("polyline",{points:"20 10 14 10 14 4"}),t.jsx("line",{x1:"14",y1:"10",x2:"21",y2:"3"}),t.jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]}):t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("polyline",{points:"15 3 21 3 21 9"}),t.jsx("polyline",{points:"9 21 3 21 3 15"}),t.jsx("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),t.jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})})]})]}),t.jsxs("div",{className:"text-primary-foreground/80 mt-1 text-sm sm:text-base text-center sm:text-left",children:[i==="select"&&"Select your name to continue",i==="pin"&&"Enter your 4-digit PIN",i==="camera"&&"Take a photo to verify your identity",i==="status"&&"All set!"]})]}),t.jsxs("div",{className:"flex-1 overflow-y-auto p-3 sm:p-6",children:[i==="select"&&t.jsxs("div",{className:"flex flex-col h-full gap-3 sm:gap-4",children:[t.jsx("input",{type:"text",placeholder:"Search by name...",value:M,onChange:e=>L(e.target.value),className:"w-full px-4 py-3 sm:py-4 border-2 rounded-xl focus:outline-none focus:ring-2 focus:ring-primary text-lg sm:text-xl flex-shrink-0",autoFocus:!0}),t.jsx("div",{className:`grid gap-2 sm:gap-3 overflow-y-auto flex-1 content-start ${b?"grid-cols-3 sm:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6":"grid-cols-2 sm:grid-cols-3 lg:grid-cols-4"}`,children:S.map(e=>{const s=K(e.firstName+e.lastName);return t.jsxs("button",{onClick:()=>ne(e),className:`p-3 sm:p-4 border-2 rounded-xl active:scale-95 transition-all text-center touch-manipulation h-[100px] sm:h-[120px] flex flex-col items-center justify-center gap-2 ${s.light} ${s.text}`,children:[t.jsx("div",{className:`w-10 h-10 sm:w-12 sm:h-12 rounded-full ${s.bg} flex items-center justify-center text-white font-bold text-sm sm:text-base`,children:R(e)}),t.jsxs("div",{className:"font-semibold text-sm sm:text-base leading-tight",children:[e.nickname||e.firstName," ",e.lastName[0],"."]})]},e.id)})}),S.length===0&&t.jsx("div",{className:"text-center py-8 text-muted-foreground text-lg",children:"No employees found. Try a different search."})]}),i==="pin"&&n&&t.jsxs("div",{className:`flex h-full ${b?"flex-row gap-6 items-center justify-center":"flex-col gap-4 justify-center"}`,children:[t.jsxs("div",{className:`flex flex-col items-center gap-3 ${b?"w-1/3":""}`,children:[t.jsx("div",{className:`w-16 h-16 sm:w-20 sm:h-20 rounded-full ${K(n.firstName+n.lastName).bg} flex items-center justify-center text-white font-bold text-2xl sm:text-3xl`,children:R(n)}),t.jsxs("div",{className:"text-xl sm:text-2xl font-bold text-center",children:[n.nickname||n.firstName," ",n.lastName]}),(r==null?void 0:r.isClockedIn)&&t.jsxs("div",{className:`px-4 py-2 rounded-lg text-sm sm:text-base font-medium ${r.isOnBreak?"bg-orange-100 dark:bg-orange-900/30 text-orange-800 dark:text-orange-200":"bg-green-100 dark:bg-green-900/30 text-green-800 dark:text-green-200"}`,children:[r.isOnBreak?"On Break":"Working"," ⢠",r.isOnBreak?me():de(),r.totalBreakMinutes>0&&!r.isOnBreak&&t.jsxs("span",{className:"ml-2 opacity-75",children:["(",r.totalBreakMinutes,"m break)"]})]}),F&&t.jsx("div",{className:"p-3 rounded-lg bg-destructive/10 border border-destructive/20 text-destructive text-sm max-w-xs text-center",children:F})]}),t.jsxs("div",{className:`flex ${b?"flex-row gap-4":"flex-col gap-4"} items-center justify-center`,children:[t.jsxs("div",{className:"flex flex-col gap-3 sm:gap-4 items-center",children:[t.jsx("div",{className:"flex justify-center gap-2 sm:gap-3",children:[0,1,2,3].map(e=>t.jsx("div",{className:`w-12 h-12 sm:w-14 sm:h-14 border-2 rounded-xl flex items-center justify-center text-2xl sm:text-3xl font-bold transition-all ${a[e]?"border-primary bg-primary/10":"border-muted"}`,children:a[e]?"â¢":""},e))}),t.jsxs("div",{className:"grid grid-cols-3 gap-2 sm:gap-3",children:[[1,2,3,4,5,6,7,8,9].map(e=>t.jsx("button",{onClick:()=>W(e.toString()),disabled:a.length>=4,className:"w-16 h-16 sm:w-20 sm:h-20 text-2xl sm:text-3xl font-bold border-2 rounded-xl hover:border-primary hover:bg-primary/10 active:bg-primary/20 active:scale-95 disabled:opacity-50 disabled:cursor-not-allowed transition-all touch-manipulation",children:e},e)),t.jsx("button",{onClick:()=>m(),className:"w-16 h-16 sm:w-20 sm:h-20 text-xs sm:text-sm font-medium border-2 rounded-xl hover:border-destructive hover:bg-destructive/10 active:bg-destructive/20 active:scale-95 transition-all touch-manipulation text-destructive",children:"Cancel"}),t.jsx("button",{onClick:()=>W("0"),disabled:a.length>=4,className:"w-16 h-16 sm:w-20 sm:h-20 text-2xl sm:text-3xl font-bold border-2 rounded-xl hover:border-primary hover:bg-primary/10 active:bg-primary/20 active:scale-95 disabled:opacity-50 disabled:cursor-not-allowed transition-all touch-manipulation",children:"0"}),t.jsx("button",{onClick:oe,className:"w-16 h-16 sm:w-20 sm:h-20 text-xl sm:text-2xl font-medium border-2 rounded-xl hover:border-primary hover:bg-primary/10 active:bg-primary/20 active:scale-95 transition-all touch-manipulation",children:"â"})]})]}),t.jsxs("div",{className:`flex flex-col gap-3 ${b?"w-48":"w-full max-w-xs"}`,children:[(r==null?void 0:r.isClockedIn)&&t.jsx("button",{onClick:()=>q("break"),disabled:a.length!==4||v,className:`w-full py-4 sm:py-5 rounded-xl text-lg sm:text-xl font-bold disabled:opacity-50 disabled:cursor-not-allowed transition-all touch-manipulation active:scale-95 ${r.isOnBreak?"bg-green-600 text-white hover:bg-green-700 active:bg-green-800":"bg-orange-500 text-white hover:bg-orange-600 active:bg-orange-700"}`,children:v?"Processing...":r.isOnBreak?"End Break":"Start Break"}),t.jsx("button",{onClick:()=>q("clock"),disabled:a.length!==4||v||!!(r!=null&&r.isOnBreak),className:"w-full py-4 sm:py-5 bg-primary text-primary-foreground rounded-xl text-lg sm:text-xl font-bold hover:bg-primary/90 active:bg-primary/80 active:scale-95 disabled:opacity-50 disabled:cursor-not-allowed transition-all touch-manipulation",children:v?"Processing...":r!=null&&r.isClockedIn?"Clock Out":"Clock In"})]})]})]}),i==="status"&&n&&r&&t.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center space-y-6",children:[t.jsx("div",{className:`text-7xl sm:text-8xl mb-2 ${r.isClockedIn?"":"animate-bounce"}`,children:r.isClockedIn?r.isOnBreak?"â":"â":"ð"}),t.jsxs("div",{children:[t.jsx("div",{className:"text-3xl sm:text-4xl font-bold mb-2",children:r.isClockedIn?r.isOnBreak?"Break Started!":r.totalBreakMinutes>0?"Break Ended!":"Clocked In!":"Clocked Out!"}),t.jsxs("div",{className:"text-xl sm:text-2xl text-muted-foreground",children:[n.nickname||n.firstName," ",n.lastName]})]}),t.jsx("div",{className:"p-6 sm:p-8 bg-accent/20 rounded-2xl min-w-[280px] sm:min-w-[320px]",children:r.isClockedIn?r.isOnBreak?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"text-sm text-muted-foreground mb-1",children:"Break started"}),t.jsx("div",{className:"text-4xl sm:text-5xl font-bold",children:k(((H=r.currentBreak)==null?void 0:H.start)||new Date().toISOString())}),t.jsx("div",{className:"mt-4 text-lg text-muted-foreground",children:"Enjoy your break!"})]}):r.totalBreakMinutes>0?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"text-sm text-muted-foreground mb-1",children:"Back to work"}),t.jsx("div",{className:"text-4xl sm:text-5xl font-bold",children:k(new Date().toISOString())}),t.jsxs("div",{className:"mt-4 text-lg text-muted-foreground",children:["Break time: ",r.totalBreakMinutes," min"]})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"text-sm text-muted-foreground mb-1",children:"Started at"}),t.jsx("div",{className:"text-4xl sm:text-5xl font-bold",children:k(((U=r.currentEntry)==null?void 0:U.clockIn)||new Date().toISOString())})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"text-sm text-muted-foreground mb-1",children:"Finished at"}),t.jsx("div",{className:"text-4xl sm:text-5xl font-bold",children:k(((Q=r.currentEntry)==null?void 0:Q.clockOut)||new Date().toISOString())}),r.currentEntry&&r.currentEntry.hoursWorked!==void 0&&r.currentEntry.hoursWorked!==null&&t.jsxs("div",{className:"mt-4 space-y-2",children:[t.jsxs("div",{className:"text-2xl sm:text-3xl font-semibold text-green-600 dark:text-green-400",children:[Number(r.currentEntry.hoursWorked).toFixed(2)," hours"]}),(r.currentEntry.breakDuration||0)>0&&t.jsxs("div",{className:"text-lg text-muted-foreground",children:[r.currentEntry.breakDuration," min break"]})]})]})}),t.jsx("p",{className:"text-muted-foreground animate-pulse",children:"Returning to start screen..."})]})]})]}),i==="camera"&&t.jsx(fe,{onCapture:le,onCancel:ie,title:r!=null&&r.isClockedIn?O("camera.photo.titleClockOut"):O("camera.photo.titleClockIn")})]})}export{ze 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.