1import{c as ke,K as le,r as a,k as e,aq as de,aO as Ce,M as o,ar as oe,as as ce,at as he,au as ue,ay as v,az as E,ak as Z,aB as me,L as g,J as De,bf as Se,ap as h,b as Ee,bg as Me,bh as Te,bi as _e,bj as ee,Q as Pe,N as P,an as A,bl as se,a7 as U,a8 as z,a9 as B,aP as Fe,ab as H,aa as te,aD as Oe,aE as Le,aF as ae,aG as y,aH as We,aI as b,bn as Ae,aK as Ue,bm as ze,ae as Be,af as He,ag as Re,ah as qe,ai as Ie,aL as Ke}from"./index-BDKYMiQv.js";import{b as xe,E as re,e as $e,a as Ve,L as Ye,C as Ge,c as Je,M as Qe}from"./MonthlyTimesheetDialog-DIJQDNl-.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const Xe=ke("Key",[["path",{d:"m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4",key:"g0fldk"}],["path",{d:"m21 2-9.6 9.6",key:"1j0ho8"}],["circle",{cx:"7.5",cy:"15.5",r:"5.5",key:"yqb3hr"}]]);function Ze(n,m){return xe(n,-m)}const es=()=>{const{toast:n}=le(),[m,p]=a.useState(!1),[N,f]=a.useState(!1),[d,r]=a.useState(!1),[k,x]=a.useState(!1),[j,C]=a.useState(""),[D,M]=a.useState(""),S=()=>{C(""),M(""),r(!1),x(!1)},w=async()=>{if(!j||!D){n({title:"Missing Fields",description:"Please fill in both password fields.",variant:"destructive"});return}if(j.length<8){n({title:"Password Too Short",description:"Password must be at least 8 characters long.",variant:"destructive"});return}if(j!==D){n({title:"Passwords Don't Match",description:"Please ensure both passwords are identical.",variant:"destructive"});return}f(!0);try{const{error:l}=await g.auth.updateUser({password:j});if(l)throw l;n({title:"Password Changed",description:"Your password has been updated successfully."}),p(!1),S()}catch(l){n({title:"Error",description:l.message||"Failed to change password.",variant:"destructive"})}finally{f(!1)}};return e.jsxs(de,{open:m,onOpenChange:l=>{p(l),l||S()},children:[e.jsx(Ce,{asChild:!0,children:e.jsxs(o,{variant:"outline",children:[e.jsx(Xe,{className:"w-4 h-4 mr-2"}),"Change Password"]})}),e.jsxs(oe,{children:[e.jsxs(ce,{children:[e.jsx(he,{children:"Change Password"}),e.jsx(ue,{children:"Enter a new password for your account. Use at least 8 characters."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{children:[e.jsx(v,{htmlFor:"new-password",children:"New Password"}),e.jsxs("div",{className:"relative mt-1",children:[e.jsx(E,{id:"new-password",type:d?"text":"password",value:j,onChange:l=>C(l.target.value),placeholder:"Enter new password",className:"pr-10"}),e.jsx("button",{type:"button",onClick:()=>r(!d),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:d?e.jsx(re,{className:"w-4 h-4"}):e.jsx(Z,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{children:[e.jsx(v,{htmlFor:"confirm-password",children:"Confirm Password"}),e.jsxs("div",{className:"relative mt-1",children:[e.jsx(E,{id:"confirm-password",type:k?"text":"password",value:D,onChange:l=>M(l.target.value),placeholder:"Confirm new password",className:"pr-10"}),e.jsx("button",{type:"button",onClick:()=>x(!k),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:k?e.jsx(re,{className:"w-4 h-4"}):e.jsx(Z,{className:"w-4 h-4"})})]})]})]}),e.jsxs(me,{children:[e.jsx(o,{variant:"outline",onClick:()=>p(!1),disabled:N,children:"Cancel"}),e.jsx(o,{onClick:w,disabled:N,children:N?"Updating...":"Update Password"})]})]})]})},ie={draft:"bg-muted text-muted-foreground",submitted:"bg-blue-500",approved:"bg-green-500",rejected:"bg-red-500"},ne=[{value:"regular",label:"Regular Work"},{value:"overtime",label:"Overtime"},{value:"meeting",label:"Meeting"},{value:"training",label:"Training"},{value:"leave",label:"Leave"}],as=()=>{const{user:n,isEmployee:m,isLoading:p,signOut:N}=De(),f=Se(),{toast:d}=le(),[r,k]=a.useState(null),[x,j]=a.useState([]),[C,D]=a.useState([]),[M,S]=a.useState(!0),[w,l]=a.useState(new Date),[je,T]=a.useState(!1),[R,q]=a.useState(h(new Date,"yyyy-MM-dd")),[F,I]=a.useState("8"),[K,$]=a.useState(""),[V,Y]=a.useState("regular"),[G,J]=a.useState("");a.useEffect(()=>{p||(n?m||(d({title:"Access Denied",description:"You don't have employee access.",variant:"destructive"}),f("/")):f("/auth"))},[n,m,p,f,d]),a.useEffect(()=>{n&&m&&O()},[n,m]);const O=async()=>
6{if(n){S(!0);try{const{data:s,error:t}=await g.from("employees").select("id, name, position, department, hire_date").eq("user_id",n.id).single();if(t)throw t;k(s);const{data:u,error:c}=await g.from("timesheet_entries").select("*").eq("employee_id",s.id).order("work_date",{ascending:!1});if(c)throw c;j(u||[]);const{data:i,error:_}=await g.from("documents").select("id, name, description, file_url, file_size, file_type, created_at").eq("is_public",!0).order("created_at",{ascending:!1});if(_)throw _;D(i||[])}catch{d({title:"Error",description:"Failed to load data.",variant:"destructive"})}finally{S(!1)}}},pe=async()=>{await N(),f("/")},fe=async()=>{if(!r||!F){d({title:"Missing Fields",description:"Please fill in required fields.",variant:"destructive"});return}try{const{error:s}=await g.from("timesheet_entries").insert({employee_id:r.id,work_date:R,hours_worked:parseFloat(F),project:K||null,activity_type:V,description:G||null,status:"draft"});if(s)throw s;d({title:"Entry Created",description:"Your timesheet entry has been saved as draft."}),T(!1),ve(),O()}catch{d({title:"Error",description:"Failed to create entry.",variant:"destructive"})}},ge=async s=>{try{const{error:t}=await g.from("timesheet_entries").update({status:"submitted",submitted_at:new Date().toISOString()}).eq("id",s);if(t)throw t;j(u=>u.map(c=>c.id===s?{...c,status:"submitted",submitted_at:new Date().toISOString()}:c)),d({title:"Submitted",description:"Entry has been submitted for approval."})}catch{d({title:"Error",description:"Failed to submit entry.",variant:"destructive"})}},ve=()=>{q(h(new Date,"yyyy-MM-dd")),I("8"),$(""),Y("regular"),J("")},we=async s=>{try{const{data:t,error:u}=await g.storage.from("documents").download(s.file_url);if(u)throw u;const c=URL.createObjectURL(t),i=document.createElement("a");i.href=c,i.download=s.name,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(c)}catch{d({title:"Download Failed",description:"Failed to download document.",variant:"destructive"})}},ye=s=>s?s<1024?`${s} B`:s<1024*1024?`${(s/1024).toFixed(1)} KB`:`${(s/(1024*1024)).toFixed(1)} MB`:"Unknown",L=Ee(w,{weekStartsOn:1}),Q=$e(w,{weekStartsOn:1}),be=Array.from({length:7},(s,t)=>Ve(L,t)),X=x.filter(s=>{const t=new Date(s.work_date);return t>=L&&t<=Q}),Ne=X.reduce((s,t)=>s+t.hours_worked,0),W=x.filter(s=>s.status==="draft").length;return p||M?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:e.jsx("div",{className:"text-muted-foreground",children:"Loading..."})}):m?e.jsxs("div",{className:"min-h-screen flex flex-col bg-background",children:[e.jsx(Me,{}),e.jsx("main",{className:"flex-1 pt-24 pb-16",children:e.jsxs("div",{className:"container mx-auto px-4",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center md:justify-between gap-4 mb-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold text-foreground",children:"Employee Portal"}),e.jsxs("p",{className:"text-muted-foreground",children:["Welcome, ",r==null?void 0:r.name," ⢠",r==null?void 0:r.position]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(es,{}),e.jsxs(o,{variant:"destructive",onClick:pe,children:[e.jsx(Ye,{className:"w-4 h-4 mr-2"}),"Sign Out"]})]})]}),e.jsxs(Te,{defaultValue:"timesheet",className:"space-y-6",children:[e.jsxs(_e,{children:[e.jsxs(ee,{value:"timesheet",className:"flex items-center gap-2",children:[e.jsx(Pe,{className:"w-4 h-4"}),"Timesheet",W>0&&e.jsx(P,{variant:"secondary",className:"ml-1",children:W})]}),e.jsxs(ee,{value:"documents",className:"flex items-center gap-2",children:[e.jsx(A,{className:"w-4 h-4"}),"Documents"]})]}),e.jsxs(se,{value:"timesheet",className:"space-y-6",children:[e.jsxs(U,{children:[e.jsx(z,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(o,{variant:"outline",size:"icon",onClick:()=>l(Ze(w,1)),children:e.jsx(Ge,{className:"w-4 h-4"})}),e.jsxs(B,{children:[h(L,"MMM d")," - ",h(Q,"MMM d, yyyy")]}),e.jsx(o,{variant:"outline",size:"icon",onClick:()=>l(xe(w,1)),children:e.jsx(Je,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Week Total"}),e.jsxs("p",{className:"text-2xl font-bold",children:[Ne,"h"]})]}),e.jsx(Qe,{employees:r?[r]:[],preselectedEmployeeId:r==null?void 0:r.id,onComplete:O,triggerButton:e.jsxs(o,{variant:"outline",children:[e.jsx(A,{className:"w-4 h-4 mr-2"}),"Sign Monthly Timesheet"]})}),e.jsxs(o,{onClick:()=>T(!0),children:[e.jsx(Fe,{className:"w-4 h-4 mr-2"}),"Add Entry"]})]})]})}),e.jsx(H,{children:e.jsx("div",{className:"grid grid-cols-7 gap-2",children:be.map(s=>{const t=X.filter(i=>i.work_date===h(s,"yyyy-MM-dd")),u=t.reduce((i,_)=>i+_.hours_worked,0),c=h(s,"yyyy-MM-dd")===h(new Date,"yyyy-MM-dd");return e.jsxs("div",{className:`p-3 rounded-lg border ${c?"border-primary bg-primary/5":""}`,children:[e.jsx("p",{className:"text-sm font-medium",children:h(s,"EEE")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:h(s,"MMM d")}),e.jsxs("p",{className:"text-lg font-bold mt-2",children:[u,"h"]}),t.map(i=>e.jsxs(P,{className:`mt-1 text-xs ${ie[i.status]}
6`,children:[i.hours_worked,"h"]},i.id))]},s.toISOString())})})})]}),e.jsxs(U,{children:[e.jsxs(z,{children:[e.jsx(B,{children:"All Entries"}),e.jsxs(te,{children:[x.length," total entries ⢠",W," drafts pending submission"]})]}),e.jsx(H,{children:x.length===0?e.jsx("div",{className:"py-8 text-center text-muted-foreground",children:"No timesheet entries yet. Create your first entry."}):e.jsxs(Oe,{children:[e.jsx(Le,{children:e.jsxs(ae,{children:[e.jsx(y,{children:"Date"}),e.jsx(y,{children:"Hours"}),e.jsx(y,{children:"Project"}),e.jsx(y,{children:"Type"}),e.jsx(y,{children:"Status"}),e.jsx(y,{children:"Action"})]})}),e.jsx(We,{children:x.map(s=>{var t;return e.jsxs(ae,{children:[e.jsx(b,{children:h(new Date(s.work_date),"MMM d, yyyy")}),e.jsxs(b,{className:"font-medium",children:[s.hours_worked,"h"]}),e.jsx(b,{children:s.project||e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsx(b,{children:e.jsx(P,{variant:"outline",children:(t=ne.find(u=>u.value===s.activity_type))==null?void 0:t.label})}),e.jsx(b,{children:e.jsx(P,{className:ie[s.status],children:s.status})}),e.jsxs(b,{children:[s.status==="draft"&&e.jsxs(o,{size:"sm",variant:"outline",onClick:()=>ge(s.id),children:[e.jsx(Ae,{className:"w-4 h-4 mr-1"}),"Submit"]}),s.status==="rejected"&&s.admin_notes&&e.jsx("span",{className:"text-sm text-destructive",children:s.admin_notes})]})]},s.id)})})]})})]})]}),e.jsx(se,{value:"documents",children:e.jsxs(U,{children:[e.jsxs(z,{children:[e.jsx(B,{children:"Shared Documents"}),e.jsx(te,{children:"Access company documents and resources"})]}),e.jsx(H,{children:C.length===0?e.jsx("div",{className:"py-8 text-center text-muted-foreground",children:"No documents available."}):e.jsx("div",{className:"space-y-2",children:C.map(s=>e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg border hover:bg-muted/50",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(A,{className:"w-8 h-8 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:s.name}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[ye(s.file_size)," â¢"," ",h(new Date(s.created_at),"MMM d, yyyy")]}),s.description&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:s.description})]})]}),e.jsxs(o,{variant:"outline",size:"sm",onClick:()=>we(s),children:[e.jsx(Ue,{className:"w-4 h-4 mr-2"}),"Download"]})]},s.id))})})]})})]})]})}),e.jsx(ze,{}),e.jsx(de,{open:je,onOpenChange:T,children:e.jsxs(oe,{children:[e.jsxs(ce,{children:[e.jsx(he,{children:"Add Timesheet Entry"}),e.jsx(ue,{children:"Log your work hours for approval."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(v,{children:"Work Date *"}),e.jsx(E,{type:"date",value:R,onChange:s=>q(s.target.value),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(v,{children:"Hours Worked *"}),e.jsx(E,{type:"number",step:"0.5",min:"0",max:"24",value:F,onChange:s=>I(s.target.value),className:"mt-1"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(v,{children:"Project"}),e.jsx(E,{value:K,onChange:s=>$(s.target.value),placeholder:"Project name",className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(v,{children:"Activity Type"}),e.jsxs(Be,{value:V,onValueChange:Y,children:[e.jsx(He,{className:"mt-1",children:e.jsx(Re,{})}),e.jsx(qe,{children:ne.map(s=>e.jsx(Ie,{value:s.value,children:s.label},s.value))})]})]})]}),e.jsxs("div",{children:[e.jsx(v,{children:"Description"}),e.jsx(Ke,{value:G,onChange:s=>J(s.target.value),placeholder:"What did you work on?",rows:3,className:"mt-1"})]})]}),e.jsxs(me,{children:[e.jsx(o,{variant:"outline",onClick:()=>T(!1),children:"Cancel"}),e.jsx(o,{onClick:fe,children:"Save as Draft"})]})]})})]}):null};export{as 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.