1import{r,j as e,w as p,I as w,t as N,q as _,p as y,E as f,a5 as z,H as P,a1 as D}from"./index-CfXbMZ_V.js";import{S as A,a as L,b as M,c as W,d as R}from"./select-BB6bDIs2.js";import{D as I,a as q,b as B,c as V}from"./dialog-D3H816yE.js";import{D as $}from"./DatePicker-BMW8z_sN.js";import{T as U}from"./textarea-D5CbgVJ9.js";import{u as G,P as J}from"./PullToRefresh-C8cDB-N-.js";import{P as S}from"./pencil-DCKB3rA6.js";import"./index-BU0D2mz3.js";import"./chevron-left-BFeklwt6.js";const K={work_date:new Date().toISOString().split("T")[0],hours:"",tasks:"",notes:""};function Q({open:g,onOpenChange:o,onSaved:j,editEntry:a}){const[d,x]=r.useState(a?{...a,hours:String(a.hours)}:{...K}),[h,c]=r.useState(!1),i=(t,l)=>x(u=>({...u,[t]:l})),b=async t=>{t.preventDefault(),c(!0);const l={...d,hours:parseFloat(d.hours)||0};a?await y.entities.HomeOfficeEntry.update(a.id,l):await y.entities.HomeOfficeEntry.create(l),c(!1),j(),o(!1)};return e.jsx(I,{open:g,onOpenChange:o,children:e.jsxs(q,{className:"sm:max-w-md",children:[e.jsx(B,{children:e.jsx(V,{className:"font-heading",children:a?"Edit Entry":"Add Home Office Entry"})}),e.jsxs("form",{onSubmit:b,className:"space-y-4 mt-2",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(p,{children:"Date *"}),e.jsx($,{value:d.work_date,onChange:t=>i("work_date",t)})]}),e.jsxs("div",{children:[e.jsx(p,{children:"Hours Worked *"}),e.jsx(w,{type:"number",step:"0.25",min:"0.25",max:"24",value:d.hours,onChange:t=>i("hours",t.target.value),required:!0,placeholder:"e.g. 7.5"})]})]}),e.jsxs("div",{children:[e.jsx(p,{children:"Tasks / Work Done"}),e.jsx(w,{value:d.tasks,onChange:t=>i("tasks",t.target.value),placeholder:"e.g. Client reports, emails, BAS preparation"})]}),e.jsxs("div",{children:[e.jsx(p,{children:"Notes"}),e.jsx(U,{value:d.notes,onChange:t=>i("notes",t.target.value),placeholder:"Optional notes...",rows:2})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[e.jsx(N,{type:"button",variant:"ghost",onClick:()=>o(!1),children:"Cancel"}),e.jsx(N,{type:"submit",disabled:h,children:h?e.jsxs(e.Fragment,{children:[e.jsx(_,{size:16,className:"animate-spin mr-2"}),"Saving..."]}):a?"Update":"Add Entry"})]})]})]})})}function ie(){const[g,o]=r.useState([]),[j,a]=r.useState(!0),[d,x]=r.useState(!1),[h,c]=r.useState(null),[i,b]=r.useState(String(new Date().getFullYear())),t=r.useRef(null),l=r.useCallback(async()=>{a(!0);const s=await y.entities.HomeOfficeEntry.list("-work_date",500);o(s),a(!1)},[]);r.useEffect(()=>{l()},[l]);const u=async s=>{await y.entities.HomeOfficeEntry.delete(s),o(n=>n.filter(F=>F.id!==s))},k=s=>{c(s),x(!0)},Y=()=>{c(null),x(!0)},{pulling:H,pullY:C}=G(l,72,t),E=[...new Set([String(new Date().getFullYear()),...g.map(s=>f(s.work_date).format("YYYY"))])].sort((s,n)=>n-s),m=g.filter(s=>f(s.work_date).format("YYYY")===i),v=m.reduce((s,n)=>s+(n.hours||0),0),T=m.length,O=v*.7;return e.jsxs("div",{ref:t,className:"space-y-6",children:[e.jsx(J,{pulling:H,pullY:C}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-heading font-bold text-gray-900 dark:text-gray-100",children:"Home Office Log"}),e.jsx("p",{className:"text-sm text-gray-400 mt-0.5",children:"Track hours worked from home for tax deductions"})]}),e.jsxs(N,{onClick:Y,className:"gap-2 shrink-0",children:[e.jsx(z,{size:16})," Add Entry"]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Year:"}),e.jsxs(A,{value:i,onValueChange:b,children:[e.jsx(L,{className:"w-32",children:e.jsx(M,{})}),e.jsx(W,{children:E.map(s=>e.jsx(R,{value:s,children:s},s))})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"bg-white dark:bg-gray-900 rounded-xl border border-gray-100 dark:border-gray-800 p-5",children:[e.jsx("p",{className:"text-xs text-gray-400 font-medium mb-1",children:"Total Hours"}),e.jsxs("p",{className:"text-2xl font-heading font-bold text-gray-900 dark:text-gray-100",children:[v.toFixed(1)," hrs"]})]}),e.jsxs("div",{className:"bg-white dark:bg-gray-900 rounded-xl border border-gray-100 dark:border-gray-800 p-5",children:[e.jsx("p",{className:"text-xs text-gray-400 font-medium mb-1",children:"Days Logged"}),e.jsxs("p",{className:"text-2xl font-heading font-bold text-gray-900 dark:text-gray-100",children:[T," days"]})]}),e.jsxs("div",{className:"bg-white dark:bg-gray-900 rounded-xl border border-gray-100 dark:border-gray-800 p-5",children:[e.jsx("p",{className:"text-xs text-gray-400 font-medium mb-1",children:"Est. Deduction (70¢/hr)"}),e.jsxs("p",{className:"text-2xl font-heading font-bold text-primary",children:["$",O.toFixed(2)]}),e.jsx("p",{className:"text-xs text-gray-400 mt-1",children:"ATO fixed rate method"})]})]}),j?e.jsx("div",{className:"flex items-center justify-center h-40",children:e.jsx("div",{className:"w-7 h-7 border-2 border-gray-200 border-t-gray-800 rounded-full animate-spin"})}):m.length===0?e.jsxs("div",{className:"text-center py-16 bg-white dark:bg-gray-900 rounded-xl border border-gray-100 dark:border-gray-800",children:[e.jsx("div",{className:"w-14 h-14 bg-gray-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(P,{size:24,className:"text-gray-400"})}),e.jsxs("p",{className:"text-gray-500 dark:text-gray-400 font-medium",children:["No entries for ",i]}),e.jsx("p",{className:"text-gray-400 text-sm mt-1",children:"Add your first home office entry."})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"sm:hidden space-y-2",children:m.map(s=>e.jsxs("div",{className:"bg-white dark:bg-gray-900 rounded-xl border border-gray-100 dark:border-gray-800 p-3 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm font-medium text-gray-800 dark:text-gray-200 whitespace-nowrap",children:f(s.work_date).format("DD MMM YYYY")}),e.jsxs("span",{className:"text-sm font-bold text-gray-800 dark:text-gray-200 tabular-nums",children:[s.hours," hrs"]})]}),s.tasks&&e.jsx("p",{className:"text-xs text-gray-600 dark:text-gray-400 truncate",children:s.tasks}),s.notes&&e.jsx("p",{className:"text-xs text-gray-400 truncate",children:s.notes}),e.jsxs("div",{className:"flex items-center gap-1 pt-1",children:[e.jsx("button",{onClick:()=>k(s),className:"flex items-center justify-center rounded hover:bg-gray-100 text-gray-400 hover:text-gray-600 dark:text-gray-400",style:{minHeight:36,minWidth:36},children:e.jsx(S,{size:13})}),e.jsx("button",{onClick:()=>u(s.id),className:"flex items-center justify-center rounded hover:bg-red-50 text-gray-400 hover:text-red-500",style:{minHeight:36,minWidth:36},children:e.jsx(D,{size:13})})]})]},s.id))}),e.jsx("div",{className:"hidden sm:block bg-white dark:bg-gray-900 rounded-xl border border-gray-100 dark:border-gray-800 overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-100 dark:border-gray-800 text-left",children:[e.jsx("th",{className:"px-4 py-3 text-xs font-medium text-gray-400 uppercase tracking-wide",children:"Date"}),e.jsx("th",{className:"px-4 py-3 text-xs font-medium text-gray-400 uppercase tracking-wide",children:"Hours"}),e.jsx("th",{className:"px-4 py-3 text-xs font-medium text-gray-400 uppercase tracking-wide",children:"Tasks"}),e.jsx("th",{className:"px-4 py-3 text-xs font-medium text-gray-400 uppercase tracking-wide",children:"Notes"}),e.jsx("th",{className:"px-4 py-3"})]})}),e.jsx("tbody",{children:m.map((s,n)=>e.jsxs("tr",{className:`border-b border-gray-50 hover:bg-gray-50/50 group ${n%2===0?"":"bg-gray-50/30"}`,children:[e.jsx("td",{className:"px-4 py-3 text-gray-600 dark:text-gray-400 whitespace-nowrap",children:f(s.work_date).format("DD MMM YYYY")}),e.jsxs("td",{className:"px-4 py-3 font-medium text-gray-800 dark:text-gray-200 tabular-nums",children:[s.hours," hrs"]}),e.jsx("td",{className:"px-4 py-3 text-gray-600 dark:text-gray-400 max-w-[240px] truncate",children:s.tasks||"â"}),e.jsx("td",{className:"px-4 py-3 text-gray-400 max-w-[180px] truncate",children:s.notes||"â"}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>k(s),className:"flex items-center justify-center rounded hover:bg-gray-100 text-gray-400 hover:text-gray-600 dark:text-gray-400",style:{minHeight:44,minWidth:44},children:e.jsx(S,{size:13})}),e.jsx("button",{onClick:()=>u(s.id),className:"flex items-center justify-center rounded hover:bg-red-50 text-gray-400 hover:text-red-500",style:{minHeight:44,minWidth:44},children:e.jsx(D,{size:13})})]})})]},s.id))})]})})})]}),d&&e.jsx(Q,{open:d,onOpenChange:s=>{x(s),s||c(null)},onSaved:l,editEntry:h})]})}export{ie 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.