1import{Z as M,r as w,j as e}from"./vendor-CGb3fyhz.js";import{u as q}from"./tanstack-CQjmdu51.js";import{C as h,a as u,b as H,c as Q}from"./card-B7H4po1A.js";import{B as o,I as R,c as S,y as U,X as V,Y as J,Z,_ as D}from"./index-CEVAfBHH.js";import{S as K}from"./skeleton-CX_X8VfR.js";import{T as X,a as G,b as A,c as l,d as O,e as d}from"./table-B9Qp0PPi.js";import{aH as P,P as k,d as W,B as ee,n as se,T as ae,z as te,aI as y,J as re,aJ as ne,a9 as ie,D as ce}from"./lucide-Bd2YFRao.js";import"./radix-DKVS-WnT.js";const T={draft:"bg-gray-100 text-gray-800 dark:bg-gray-800 dark:text-gray-300",in_progress:"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300",pending_review:"bg-amber-100 text-amber-800 dark:bg-amber-900 dark:text-amber-300",completed:"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300"},le={draft:"Draft",in_progress:"In Progress",pending_review:"Pending Review",completed:"Completed"};function g(i){return i?new Intl.NumberFormat("en-CA",{style:"currency",currency:"CAD",minimumFractionDigits:0,maximumFractionDigits:0}).format(i):"$0"}function de(i){return new Date(i).toLocaleDateString("en-CA",{year:"numeric",month:"short",day:"numeric"})}function fe(){const[,i]=M(),[f,F]=w.useState(""),[j,L]=w.useState("createdAt"),[B,C]=w.useState("desc"),{data:r,isLoading:E,error:z}=q({queryKey:["/api/property-owner/canadian-cca-studies"]}),b=(r||[]).filter(s=>{var t,a,n,c;return((a=(t=s.property)==null?void 0:t.propertyName)==null?void 0:a.toLowerCase().includes(f.toLowerCase()))||((c=(n=s.property)==null?void 0:n.propertyAddress)==null?void 0:c.toLowerCase().includes(f.toLowerCase()))}).sort((s,t)=>{var n,c,m,x;let a=0;return j==="createdAt"?a=new Date(s.createdAt).getTime()-new Date(t.createdAt).getTime():j==="propertyName"?a=(((n=s.property)==null?void 0:n.propertyName)||"").localeCompare(((c=t.property)==null?void 0:c.propertyName)||""):j==="purchasePrice"&&(a=parseFloat(((m=s.property)==null?void 0:m.purchasePrice)||"0")-parseFloat(((x=t.property)==null?void 0:x.purchasePrice)||"0")),B==="desc"?-a:a}),N=s=>{j===s?C(t=>t==="asc"?"desc":"asc"):(L(s),C("desc"))},I=(r==null?void 0:r.length)||0,Y=(r==null?void 0:r.filter(s=>s.status==="completed").length)||0,_=(r==null?void 0:r.reduce((s,t)=>{var a;return s+parseFloat(((a=t.property)==null?void 0:a.purchasePrice)||"0")},0))||0,$=(r==null?void 0:r.reduce((s,t)=>{var a,n;return s+(((n=(a=t.qtoData)==null?void 0:a.calculatedSavings)==null?void 0:n.firstYearSavings)||0)},0))||0;return e.jsxs("div",{className:"container max-w-7xl py-8 space-y-6","data-testid":"canadian-cca-dashboard",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-red-100 dark:bg-red-900/30",children:e.jsx(P,{className:"h-6 w-6 text-red-600"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-semibold",children:"Canadian CCA Studies"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Capital Cost Allowance depreciation studies for Canadian properties"})]})]}),e.jsxs(o,{onClick:()=>i("/property-owner/create-purchase-price-study?country=CA"),"data-testid":"button-new-study",children:[e.jsx(k,{className:"h-4 w-4 mr-2"}),"New Study"]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsx(h,{children:e.jsx(u,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Total Studies"}),e.jsx("p",{className:"text-2xl font-bold",children:I})]}),e.jsx(W,{className:"h-8 w-8 text-muted-foreground/50"})]})})}),e.jsx(h,{children:e.jsx(u,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Completed"}),e.jsx("p",{className:"text-2xl font-bold text-green-600",children:Y})]}),e.jsx(ee,{className:"h-8 w-8 text-green-600/50"})]})})}),e.jsx(h,{children:e.jsx(u,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Total Property Value"}),e.jsx("p",{className:"text-2xl font-bold",children:g(_)})]}
1),e.jsx(se,{className:"h-8 w-8 text-muted-foreground/50"})]})})}),e.jsx(h,{children:e.jsx(u,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Est. First Year Savings"}),e.jsx("p",{className:"text-2xl font-bold text-primary",children:g($)})]}),e.jsx(ae,{className:"h-8 w-8 text-primary/50"})]})})})]}),e.jsxs(h,{children:[e.jsx(H,{children:e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[e.jsx(Q,{children:"Your Studies"}),e.jsxs("div",{className:"relative w-64",children:[e.jsx(te,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(R,{placeholder:"Search studies...",value:f,onChange:s=>F(s.target.value),className:"pl-9","data-testid":"input-search-studies"})]})]})}),e.jsx(u,{children:E?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(s=>e.jsx(K,{className:"h-16 w-full"},s))}):z?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"Failed to load studies. Please try again."}):b.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(P,{className:"h-12 w-12 mx-auto text-muted-foreground/50 mb-4"}),e.jsx("h3",{className:"font-medium mb-2",children:"No Canadian CCA Studies Yet"}),e.jsx("p",{className:"text-muted-foreground text-sm mb-4",children:"Create your first Canadian Capital Cost Allowance study to start optimizing your tax savings."}),e.jsxs(o,{onClick:()=>i("/property-owner/create-purchase-price-study?country=CA"),children:[e.jsx(k,{className:"h-4 w-4 mr-2"}),"Create Study"]})]}):e.jsxs(X,{children:[e.jsx(G,{children:e.jsxs(A,{children:[e.jsx(l,{children:e.jsxs(o,{variant:"ghost",size:"sm",onClick:()=>N("propertyName"),className:"h-auto p-0 font-medium",children:["Property",e.jsx(y,{className:"h-3 w-3 ml-1"})]})}),e.jsx(l,{children:"Province"}),e.jsx(l,{children:"Status"}),e.jsx(l,{className:"text-right",children:e.jsxs(o,{variant:"ghost",size:"sm",onClick:()=>N("purchasePrice"),className:"h-auto p-0 font-medium",children:["Purchase Price",e.jsx(y,{className:"h-3 w-3 ml-1"})]})}),e.jsx(l,{className:"text-right",children:"Est. Savings"}),e.jsx(l,{children:e.jsxs(o,{variant:"ghost",size:"sm",onClick:()=>N("createdAt"),className:"h-auto p-0 font-medium",children:["Created",e.jsx(y,{className:"h-3 w-3 ml-1"})]})}),e.jsx(l,{className:"w-10"})]})}),e.jsx(O,{children:b.map(s=>{var t,a,n,c,m,x,v;return e.jsxs(A,{className:"cursor-pointer",onClick:()=>i(`/property-owner/cca-studies/${s.id}`),"data-testid":`study-row-${s.id}`,children:[e.jsx(d,{children:e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:((t=s.property)==null?void 0:t.propertyName)||"Untitled Study"}),e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(re,{className:"h-3 w-3"}),((a=s.property)==null?void 0:a.propertyAddress)||"No address"]})]})}),e.jsx(d,{children:e.jsx(S,{variant:"outline",children:((c=(n=s.qtoData)==null?void 0:n.canadianData)==null?void 0:c.province)||"N/A"})}),e.jsx(d,{children:e.jsx(S,{className:U("font-normal",T[s.status]||T.draft),children:le[s.status]||"Draft"})}),e.jsx(d,{className:"text-right font-medium",children:g(parseFloat(((m=s.property)==null?void 0:m.purchasePrice)||"0"))}),e.jsx(d,{className:"text-right",children:e.jsx("span",{className:"text-green-600 font-medium",children:g(((v=(x=s.qtoData)==null?void 0:x.calculatedSavings)==null?void 0:v.firstYearSavings)||0)})}),e.jsx(d,{className:"text-muted-foreground text-sm",children:de(s.createdAt)}),e.jsx(d,{children:e.jsxs(V,{children:[e.jsx(J,{asChild:!0,onClick:p=>p.stopPropagation(),children:e.jsx(o,{variant:"ghost",size:"icon","data-testid":`study-menu-${s.id}`,children:e.jsx(ne,{className:"h-4 w-4"})})}),e.jsxs(Z,{align:"end",children:[e.jsxs(D,{onClick:p=>{p.stopPropagation(),i(`/property-owner/cca-studies/${s.id}`)},children:[e.jsx(ie,{className:"h-4 w-4 mr-2"}),"View Study"]}),e.jsxs(D,{onClick:p=>{p.stopPropagation(),window.open(`/api/property-owner/canadian-cca-studies/${s.id}/generate-audit-binder`,"_blank")},children:[e.jsx(ce,{className:"h-4 w-4 mr-2"}),"Download Audit Binder"]})]})]})})]},s.id)})})]})})]})]})}export{fe 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.