1import{j as e}from"./ui-BcZpBtGC.js";import{r as l}from"./vendor-CbTYwD9p.js";import{E as B,C as p,a as j,H as O,m as x,k as P,e as y,g as b,h as R,T as G,o as J,a2 as K,a3 as Q,a4 as S,a5 as C,B as _,ad as E,s as h}from"./index-D4z10nuM.js";import{T as k,a as M,b as g,c as i,d as L,e as n}from"./table-BNsqH6tu.js";import{d as A}from"./reportExport-XisCb4l-.js";import{d as W}from"./router-C21RS5Se.js";import{T as X}from"./triangle-alert-CPsavpTR.js";import{E as Y}from"./eye-DHwVhvdt.js";import{T as Z}from"./trending-down-BgsDNpCw.js";import{D as ee}from"./dollar-sign-CkLyGziu.js";import{f as v}from"./format-BE36S-lJ.js";import{i as se}from"./isPast-DfR6HMHj.js";import"./formatters-Dsb8yaw-.js";import"./jspdf.plugin.autotable-DwhxRVu1.js";import"./constants-DQX8fu4l.js";import"./startOfYear-CRigkeXM.js";const fe=()=>{const{accessToken:f}=W(),[r,F]=l.useState(null),[c,$]=l.useState([]),[u,U]=l.useState([]),[V,d]=l.useState(!0),[w,o]=l.useState(null);l.useEffect(()=>{(async()=>{if(!f){o("Invalid access link"),d(!1);return}try{const{data:a,error:z}=await h.from("cpa_shares").select("*").eq("access_token",f).single();if(z||!a){o("Share link not found or has been deleted"),d(!1);return}const t=a;if(!t.is_active){o("This share link has been revoked"),d(!1);return}if(se(new Date(t.expires_at))){o("This share link has expired"),d(!1);return}if(F(t),await h.from("cpa_access_logs").insert({share_id:t.id,action:"view",resource_accessed:"dashboard",user_agent:navigator.userAgent}),await h.from("cpa_shares").update({access_count:(t.access_count||0)+1,last_accessed_at:new Date().toISOString()}).eq("id",t.id),t.permissions.transactions){const{data:N}=await h.from("transactions").select("id, date, description, amount, category, type").eq("user_id",t.user_id).order("date",{ascending:!1}).limit(100);$(N||[])}if(t.permissions.deductions){const{data:N}=await h.from("deductions").select("id, category, amount, name, status, date").eq("user_id",t.user_id).order("created_at",{ascending:!1});U((N||[]).map(m=>({id:m.id,category:m.category,amount:m.amount,description:m.name||"",status:m.status})))}}catch(a){console.error("Error loading share data:",a),o("Failed to load shared data")}finally{d(!1)}})()},[f]);const I=()=>{c.length>0&&A(c,"transactions-export")},q=()=>{u.length>0&&A(u,"deductions-export")};if(V)return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-muted/30",children:e.jsxs("div",{className:"text-center",children:[e.jsx(B,{className:"h-12 w-12 animate-spin text-primary mx-auto mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:"Loading shared data..."})]})});if(w)return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-muted/30",children:e.jsx(p,{className:"max-w-md",children:e.jsxs(j,{className:"flex flex-col items-center py-12",children:[e.jsx(X,{className:"h-16 w-16 text-amber-500 mb-4"}),e.jsx("h2",{className:"text-xl font-bold mb-2",children:"Access Denied"}),e.jsx("p",{className:"text-muted-foreground text-center",children:w})]})})});if(!r)return null;const T=c.filter(s=>s.type==="income").reduce((s,a)=>s+Number(a.amount),0),D=c.filter(s=>s.type==="expense").reduce((s,a)=>s+Math.abs(Number(a.amount)),0),H=u.reduce((s,a)=>s+Number(a.amount),0);return e.jsxs("div",{className:"min-h-screen bg-muted/30",children:[e.jsx("div",{className:"bg-primary text-primary-foreground py-4 px-6",children:e.jsxs("div",{className:"container mx-auto flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(O,{className:"h-6 w-6"}),e.jsxs("div",{children:[e.jsx("h1",{className:"font-bold",children:"TaxGazel - CPA View"}),e.jsx("p",{className:"text-sm opacity-90",children:"Read-Only Access"})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(x,{variant:"secondary",className:"flex items-center gap-1",children:[e.jsx(Y,{className:"h-3 w-3"}),"View Only"]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(P,{className:"h-4 w-4"}),"Expires: ",v(new Date(r.expires_at),"MMM d, yyyy")]})]})]})}),e.jsxs("div",{className:"container mx-auto px-4 py-8 space-y-6",children:[e.jsxs(p,{children:[e.jsxs(y,{children:[e.jsx(b,{children:"Client Financial Overview"}),e.jsxs(R,{children:["Shared by client on ",v(new Date(r.created_at),"MMMM d, yyyy"),r.notes&&` ⢠Note: ${r.n
1otes}`]})]}),e.jsx(j,{children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-green-50 dark:bg-green-950/30 p-4 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(G,{className:"h-5 w-5 text-green-600"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Total Income"})]}),e.jsxs("p",{className:"text-2xl font-bold text-green-600",children:["$",T.toLocaleString("en-US",{minimumFractionDigits:2})]})]}),e.jsxs("div",{className:"bg-red-50 dark:bg-red-950/30 p-4 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Z,{className:"h-5 w-5 text-red-600"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Total Expenses"})]}),e.jsxs("p",{className:"text-2xl font-bold text-red-600",children:["$",D.toLocaleString("en-US",{minimumFractionDigits:2})]})]}),e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-950/30 p-4 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(ee,{className:"h-5 w-5 text-blue-600"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Net Income"})]}),e.jsxs("p",{className:"text-2xl font-bold text-blue-600",children:["$",(T-D).toLocaleString("en-US",{minimumFractionDigits:2})]})]}),e.jsxs("div",{className:"bg-purple-50 dark:bg-purple-950/30 p-4 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(J,{className:"h-5 w-5 text-purple-600"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Total Deductions"})]}),e.jsxs("p",{className:"text-2xl font-bold text-purple-600",children:["$",H.toLocaleString("en-US",{minimumFractionDigits:2})]})]})]})})]}),e.jsxs(K,{defaultValue:"transactions",className:"space-y-4",children:[e.jsxs(Q,{children:[r.permissions.transactions&&e.jsx(S,{value:"transactions",children:"Transactions"}),r.permissions.deductions&&e.jsx(S,{value:"deductions",children:"Deductions"})]}),r.permissions.transactions&&e.jsx(C,{value:"transactions",children:e.jsxs(p,{children:[e.jsxs(y,{className:"flex flex-row items-center justify-between",children:[e.jsx(b,{children:"Transaction History"}),e.jsxs(_,{variant:"outline",size:"sm",onClick:I,children:[e.jsx(E,{className:"h-4 w-4 mr-2"}),"Export CSV"]})]}),e.jsxs(j,{children:[e.jsxs(k,{children:[e.jsx(M,{children:e.jsxs(g,{children:[e.jsx(i,{children:"Date"}),e.jsx(i,{children:"Description"}),e.jsx(i,{children:"Category"}),e.jsx(i,{children:"Type"}),e.jsx(i,{className:"text-right",children:"Amount"})]})}),e.jsx(L,{children:c.slice(0,50).map(s=>e.jsxs(g,{children:[e.jsx(n,{children:v(new Date(s.date),"MMM d, yyyy")}),e.jsx(n,{children:s.description}),e.jsx(n,{children:e.jsx(x,{variant:"outline",children:s.category})}),e.jsx(n,{children:e.jsx(x,{variant:s.type==="income"?"default":"secondary",children:s.type})}),e.jsxs(n,{className:`text-right font-medium ${s.type==="income"?"text-green-600":"text-red-600"}`,children:[s.type==="income"?"+":"-","$",Math.abs(Number(s.amount)).toLocaleString("en-US",{minimumFractionDigits:2})]})]},s.id))})]}),c.length>50&&e.jsxs("p",{className:"text-sm text-muted-foreground text-center mt-4",children:["Showing 50 of ",c.length," transactions. Export CSV for full list."]})]})]})}),r.permissions.deductions&&e.jsx(C,{value:"deductions",children:e.jsxs(p,{children:[e.jsxs(y,{className:"flex flex-row items-center justify-between",children:[e.jsx(b,{children:"Tax Deductions"}),e.jsxs(_,{variant:"outline",size:"sm",onClick:q,children:[e.jsx(E,{className:"h-4 w-4 mr-2"}),"Export CSV"]})]}),e.jsx(j,{children:e.jsxs(k,{children:[e.jsx(M,{children:e.jsxs(g,{children:[e.jsx(i,{children:"Category"}),e.jsx(i,{children:"Description"}),e.jsx(i,{children:"Status"}),e.jsx(i,{className:"text-right",children:"Amount"})]})}),e.jsx(L,{children:u.map(s=>e.jsxs(g,{children:[e.jsx(n,{children:e.jsx(x,{variant:"outline",children:s.category})}),e.jsx(n,{children:s.description}),e.jsx(n,{children:e.jsx(x,{variant:s.status==="approved"?"default":"secondary",children:s.status})}),e.jsxs(n,{className:"text-right font-medium text-green-600",children:["$",Number(s.amount).toLocaleStr
1ing("en-US",{minimumFractionDigits:2})]})]},s.id))})]})})]})})]}),e.jsxs("div",{className:"text-center text-sm text-muted-foreground py-8",children:[e.jsx("p",{children:"This is a read-only view shared via TaxGazel"}),e.jsx("p",{children:"For questions, contact your client directly"})]})]})]})};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.