1import{c as pe,r as h,j as e,an as ee,D as K,b as te,ae as Ee,S as De,ac as qe,s as mt,F as G,z as he,E as z,L as Z,p as S,q as T,x as xt,y as re,a5 as Q,a8 as ut,l as gt,a1 as Ie,I as ne,t as F,u as Le,w as P,n as Pe,a4 as W,X as pt,af as ht,ag as ft,R as ge,i as bt,ad as yt,C as Be,k as jt,ao as vt,ap as Nt,al as wt,a6 as ce,ak as _t,aa as kt}from"./index-CfXbMZ_V.js";import{D as fe,a as be,b as ye,c as je,d as Je,e as Ct}from"./dialog-D3H816yE.js";import{P as St}from"./pencil-DCKB3rA6.js";import{F as $e}from"./file-down-CwIzu-yz.js";import{C as ze}from"./calendar-plus-lHv3_wRd.js";import{A as se}from"./archive-restore-C_Z0fNFm.js";import{C as ve}from"./circle-check-big-9H_erV8K.js";import{A as Dt}from"./AmlStatusControl-DRatYjXx.js";import{S as ae}from"./StatusBadge-C2JqdlP4.js";import{T as Ve}from"./trending-up-BFx2g5_7.js";import{C as $t}from"./circle-alert-DPw7Scbn.js";import{S as zt}from"./square-check-big-CiiUU5TQ.js";import{S as Ne}from"./send-D6RIih1c.js";import{V as Mt}from"./video-BHeo1eCQ.js";import{M as Tt}
1from"./map-pin-pShnOXr4.js";import{T as Ot}from"./textarea-D5CbgVJ9.js";import{F as Rt}from"./FieldPlacer-BUB7kVg_.js";import{F as Ft}from"./file-up-BL4RO41y.js";import{P as Yt,i as Me}from"./DocumentPreviewer-DCJvCjIY.js";import{D as At,a as Et,b as qt,c as Te,O as It,A as Lt}from"./dropdown-menu-CeNaQjL1.js";import{C as He}from"./circle-x-DL4QWNIP.js";import{C as Ue}from"./clock-DmU1_sat.js";import{S as Pt}from"./save-DxI-RWzE.js";import{S as Bt,a as Jt,b as Vt,c as Ht,d as Oe}from"./select-BB6bDIs2.js";import{F as Ut}from"./filter-DGGByJCs.js";import{R as Gt}from"./rotate-cw-CPY9HMVJ.js";import{T as Kt}from"./trending-down-_wkW26nB.js";import{L as Wt}from"./landmark-DwXwZzZr.js";import{N as Ge}from"./NewJobDialog-9PFKl-1B.js";import{C as Xt}from"./circle-BeOP31Vt.js";import{C as Zt}from"./ClientProfileEditor-BgIeq8DY.js";import{F as Qt}from"./FinleyCopilotDock-DhThWcBO.js";import{C as es}from"./chevron-left-BFeklwt6.js";import"./shield-alert-5vZM3RqD.js";import"./PdfPages-B6NKBVjR.js";import"./download-oHmw96Dk.js";import"./index-BU0D2mz3.js";import"./index-vyFHw5G3.js";import"./key-round-CiAhBO_A.js";import"./info-CA90EpkY.js";import"./dollar-sign-DSCUPVwl.js";import"./calendar-range-_it7bbsU.js";import"./zap-BSTqYc_A.js";/** 2 * @license lucide-react v0.475.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 ts=[["path",{d:"m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z",key:"1fy3hk"}]],ss=pe("Bookmark",ts);/** 7 * @license lucide-react v0.475.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const as=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]],rs=pe("Ellipsis",as);/** 12 * @license lucide-react v0.475.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const ns=[["path",{d:"M16 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V8Z",key:"qazsjp"}],["path",{d:"M15 3v4a2 2 0 0 0 2 2h4",key:"40519r"}]],is=pe("StickyNote",ns),Re=["bg-blue-500","bg-emerald-500","bg-violet-500","bg-amber-500","bg-rose-500","bg-cyan-500","bg-indigo-500","bg-teal-500"];function ls(t){return(t||"?").trim().split(/\s+/).map(r=>r[0]).slice(0,2).join("").toUpperCase()||"?"}function os(t){let r=0;for(let m=0;m<(t||"").length;m++)r=r*31+t.charCodeAt(m)>>>0;return Re[r%Re.length]}function de(t){if(!t)return"grey";const r=t.toLowerCase();return["active","verified","completed","lodged","approved","signed","confirmed"].includes(r)?"green":["archived","inactive","cancelled","expired"].includes(r)?"grey":["flagged","overdue","rejected","requires action","needs resubmission","no show"].includes(r)?"red":"orange"}const cs={green:"bg-emerald-50 text-emerald-700 border-emerald-200",orange:"bg-amber-50 text-amber-700 border-amber-200",red:"bg-rose-50 text-rose-700 border-rose-200",grey:"bg-slate-100 text-slate-500 border-slate-200"},ds={green:"bg-emerald-500",orange:"bg-amber-500",red:"bg-rose-500",grey:"bg-slate-400"};function me({label:t,tone:r,icon:m}){return e.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] font-semibold px-2 py-0.5 rounded-full border ${cs[r]}`,children:[m?e.jsx(m,{size:11}):e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${ds[r]}`}),t]})}function ms({client:t,activeJob:r,tabs:m,tab:l,setTab:v,onAction:_,onMore:b}){const[x,c]=h.useState(!1),o=h.useRef(null);h.useEffect(()=>{const a=n=>{o.current&&!o.current.contains(n.target)&&c(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[]);const N=t.kyc_completed?"Verified":t.aml_status==="Flagged"?"Requires Action":"Pending",d=t.aml_status||"Pending",u=t.archived?"Archived":"Active",i=[{key:"edit",label:"Edit",icon:St,show:"always"},{key:"newJob",label:"New Job",icon:ee,show:"always"},{key:"requestDocs",label:"Request Docs",icon:$e,show:"md"},{key:"requestSig",label:"Request Signature",icon:K,show:"lg"},{key:"message",label:"Message",icon:te,show:"md"},{key:"book",label:"Book",icon:ze,show:"lg"}],s=a=>a==="always"?"inline-flex":a==="md"?"hidden sm:inline-flex":"hidden lg:inline-flex";return e.jsxs("div",{className:"sticky top-0 z-30 bg-white/95 dar
16k:bg-gray-900/95 backdrop-blur border-b border-gray-100 dark:border-gray-800",children:[e.jsxs("div",{className:"px-4 pt-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[t.avatar_url?e.jsx("img",{src:t.avatar_url,alt:"",className:"w-12 h-12 rounded-xl object-cover shrink-0"}):e.jsx("div",{className:`w-12 h-12 rounded-xl flex items-center justify-center text-white font-bold text-base shrink-0 ${os(t.full_name)}`,children:ls(t.full_name)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h1",{className:"text-lg font-bold text-gray-900 dark:text-gray-100 truncate leading-tight",children:t.full_name}),e.jsx("span",{className:"text-[11px] font-medium px-2 py-0.5 rounded-full bg-slate-100 text-slate-600",children:t.client_type||"Individual"}),t.id&&e.jsxs("span",{className:"text-[11px] text-gray-400 font-mono",children:["#",t.id.slice(-6).toUpperCase()]})]}),e.jsxs("p",{className:"text-xs text-gray-500 mt-0.5 truncate",children:[t.assigned_accountant?`ð¤ ${t.assigned_accountant}`:"Unassigned",t.office_name?` · ð¢ ${t.office_name}`:""]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[i.map(a=>{const n=a.icon;return e.jsxs("button",{onClick:()=>_(a.key),title:a.label,className:`${s(a.show)} items-center gap-1.5 h-9 px-3 rounded-lg text-xs font-semibold text-gray-700 dark:text-gray-200 bg-gray-50 dark:bg-gray-800 hover:bg-emerald-50 hover:text-emerald-700 border border-gray-100 dark:border-gray-700 transition-colors`,children:[e.jsx(n,{size:14})," ",e.jsx("span",{className:"hidden xl:inline",children:a.label})]},a.key)}),e.jsxs("div",{ref:o,className:"relative",children:[e.jsxs("button",{onClick:()=>c(a=>!a),title:"More",className:"inline-flex items-center gap-1 h-9 px-3 rounded-lg text-xs font-semibold text-gray-700 dark:text-gray-200 bg-gray-50 dark:bg-gray-800 hover:bg-gray-100 border border-gray-100 dark:border-gray-700",children:[e.jsx(rs,{size:14})," ",e.jsx(Ee,{size:12})]}),x&&e.jsxs("div",{className:"absolute right-0 mt-1 w-52 bg-white dark:bg-gray-900 rounded-xl shadow-xl border border-gray-100 dark:border-gray-800 py-1 z-50",children:[e.jsxs("button",{onClick:()=>{c(!1),b("requestVerification")},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-50 text-left",children:[e.jsx(De,{size:15,className:"text-emerald-600"})," Request Verification"]}),e.jsxs("button",{onClick:()=>{c(!1),b("requestDocs")},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-50 text-left sm:hidden",children:[e.jsx($e,{size:15,className:"text-blue-600"})," Request Documents"]}),e.jsxs("button",{onClick:()=>{c(!1),b("requestSig")},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-50 text-left lg:hidden",children:[e.jsx(K,{size:15,className:"text-violet-600"})," Request Signature"]}),e.jsxs("button",{onClick:()=>{c(!1),b("message")},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-50 text-left sm:hidden",children:[e.jsx(te,{size:15,className:"text-cyan-600"})," Send Message"]}),e.jsxs("button",{onClick:()=>{c(!1),b("book")},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-50 text-left lg:hidden",children:[e.jsx(ze,{size:15,className:"text-cyan-600"})," Book Appointment"]}),e.jsx("div",{className:"border-t border-gray-100 dark:border-gray-800 my-1"}),t.archived?e.jsxs("button",{onClick:()=>{c(!1),b("restore")},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-50 text-left",children:[e.jsx(se,{size:15,className:"text-emerald-600"})," Restore Client"]}):e.jsxs("button",{onClick:()=>{c(!1),b("archive")},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-rose-600 hover:bg-rose-50 text-left",children:[e.jsx(qe,{size:15})," Archive Client"]})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap mt-2.5",children:[e.jsx(me,{label:u,tone:de(u)}
16),e.jsx(me,{label:`KYC ${N}`,tone:de(N),icon:mt}),e.jsx(me,{label:`AML ${d}`,tone:de(d),icon:De}),r&&e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[11px] font-medium px-2 py-0.5 rounded-full bg-blue-50 text-blue-700 border border-blue-200",children:[e.jsx(ee,{size:11})," ",r.label]})]})]}),e.jsx("div",{className:"mt-2 overflow-x-auto no-scrollbar",children:e.jsx("div",{className:"flex gap-1 px-4 pb-1 min-w-max",children:m.map(a=>e.jsxs("button",{onClick:()=>v(a.key),className:`whitespace-nowrap text-sm font-semibold px-3.5 py-2 rounded-t-lg border-b-2 transition-colors ${l===a.key?"text-emerald-700 border-emerald-600":"text-gray-500 border-transparent hover:text-gray-800"}`,children:[a.label,a.count!=null&&e.jsx("span",{className:`ml-1.5 text-[10px] px-1.5 py-0.5 rounded-full ${l===a.key?"bg-emerald-100 text-emerald-700":"bg-gray-100 text-gray-500"}`,children:a.count})]},a.key))})})]})}const Fe={green:"text-emerald-600 bg-emerald-50",orange:"text-amber-600 bg-amber-50",red:"text-rose-600 bg-rose-50",blue:"text-blue-600 bg-blue-50",grey:"text-slate-500 bg-slate-100"};function xs(t,r){return t>0&&r==="red"?"red":t>0&&r==="orange"?"orange":t>0&&r==="green"?"green":"blue"}function us({kpis:t={},onTab:r}){const m=[{label:"Active Jobs",value:t.activeJobs,tab:"jobs",tone:"blue",sub:"in progress"},{label:"Completed Jobs",value:t.completedJobs,tab:"jobs",tone:"green",sub:"lodged/done"},{label:"Outstanding Docs",value:t.outstandingDocs,tab:"documents",alert:"orange",sub:"pending review"},{label:"Pending Signatures",value:t.pendingSigs,tab:"signatures",alert:"orange",sub:"awaiting sign"},{label:"Unread Messages",value:t.unreadMessages,tab:"messages",alert:"blue",sub:"from client"},{label:"Outstanding Balance",value:t.balance,tab:"jobs",alert:t.balance>0?"red":"green",sub:"to collect",isMoney:!0}];return e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 xl:grid-cols-6 gap-3",children:m.map(l=>{const v=l.tone||xs(l.value,l.alert);return e.jsxs("button",{onClick:()=>r==null?void 0:r(l.tab),className:"text-left bg-white dark:bg-gray-900 border border-gray-100 dark:border-gray-800 rounded-xl p-3 hover:border-emerald-300 hover:shadow-sm transition-all active:scale-[0.98]",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:`text-lg font-bold tabular-nums ${Fe[v].split(" ")[0]}`,children:[l.isMoney?"$":"",l.isMoney?Number(l.value||0).toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:0}):l.value??0]}),e.jsx("span",{className:`w-7 h-7 rounded-lg flex items-center justify-center text-[10px] font-bold ${Fe[v]}`,children:l.value>0?"â¢":""})]}),e.jsx("p",{className:"text-[11px] font-medium text-gray-700 dark:text-gray-300 mt-1 truncate",children:l.label}),e.jsx("p",{className:"text-[10px] text-gray-400 truncate",children:l.sub})]},l.label)})})}function Y({label:t,value:r,full:m=!1}){return e.jsxs("div",{className:m?"sm:col-span-2 py-1.5":"py-1.5",children:[e.jsx("p",{className:"text-[11px] font-medium text-gray-400 uppercase tracking-wide leading-none",children:t}),e.jsx("p",{className:"text-sm font-semibold text-gray-900 mt-1 break-words",children:r||r===0?r:"â"})]})}const A={document:G,signature:K,job:ee,message:te,booking:he,complete:ve},E={document:"bg-amber-50 text-amber-600",signature:"bg-emerald-50 text-emerald-600",job:"bg-blue-50 text-blue-600",message:"bg-cyan-50 text-cyan-600",booking:"bg-violet-50 text-violet-600",complete:"bg-emerald-50 text-emerald-600"};function gs(t){const r=t?z(t):null;return!r||!r.isValid()?"Earlier":r.isSame(z(),"day")?"Today":r.isSame(z().subtract(1,"day"),"day")?"Yesterday":r.format("D MMM")}function Ke({client:t,documents:r=[],jobs:m=[],signatures:l=[],messages:v=[],appointments:_=[],onTab:b,limit:x=50}){const c=(t==null?void 0:t.full_name)||"Client",o=[];r.forEach(i=>{o.push({id:"doc-"+i.id,type:"document",text:`uploaded ${i.file_name||"a document"}`,ts:i.upload_date||i.created_date,tab:"documents",Icon:A.document,color:E.document})}),l.forEach(i=>{i.status==="signed"?o.push({id:"sig-"+i.id,type:"signature",text:`signed ${i.title||"a document"}`,ts:i.signed_at||i.updated_date,tab:"signatures",Icon:A.signature,color:E.signature}):i.status==="pending"&&o.push({id:"sigp-"+i.id,type:"signature",text:`signature requested: ${i.title||"document"}`,ts:i.requested_date||i.created_date,tab:"signatures",Icon:A.signature,color:E.signature})}),m.forEach(i=>
16{i.status==="Lodged"&&i.lodged_at&&o.push({id:"jl-"+i.id,type:"job",text:`lodged ${i.title||"tax return"}`,ts:i.lodged_at,route:`/staff/jobs/${i.id}`,Icon:A.job,color:E.job}),i.status==="Completed"&&i.completed_at&&o.push({id:"jc-"+i.id,type:"complete",text:`completed ${i.title||"job"}`,ts:i.completed_at,route:`/staff/jobs/${i.id}`,Icon:A.complete,color:E.complete}),i.last_activity_date&&o.push({id:"ja-"+i.id,type:"job",text:`${i.title||"job"} moved to ${i.status}`,ts:i.last_activity_date,route:`/staff/jobs/${i.id}`,Icon:A.job,color:E.job})}),v.forEach(i=>{i.sender_role==="client"&&o.push({id:"msg-"+i.id,type:"message",text:`sent a message: ${(i.content||"").slice(0,50)}`,ts:i.created_date,tab:"messages",Icon:A.message,color:E.message})}),_.forEach(i=>{i.status==="Completed"?o.push({id:"apc-"+i.id,type:"booking",text:`booking completed: ${i.appointment_type||"appointment"}`,ts:i.appointment_date,tab:"bookings",Icon:A.booking,color:E.booking}):i.status!=="Cancelled"&&o.push({id:"aps-"+i.id,type:"booking",text:`booking scheduled: ${i.appointment_type||"appointment"}`,ts:i.appointment_date,tab:"bookings",Icon:A.booking,color:E.booking})}),o.sort((i,s)=>new Date(s.ts||0).getTime()-new Date(i.ts||0).getTime());const N=o.slice(0,x),d=[],u={};return N.forEach(i=>{const s=gs(i.ts);u[s]||(u[s]={label:s,items:[]},d.push(u[s])),u[s].items.push(i)}),N.length===0?e.jsx("p",{className:"text-xs text-gray-400 py-6 text-center",children:"No recent activity"}):e.jsx("div",{className:"space-y-3",children:d.map(i=>e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wide text-gray-400 mb-1.5",children:i.label}),e.jsx("div",{className:"space-y-0.5",children:i.items.map(s=>{const a=s.Icon,n=e.jsxs("div",{className:"flex items-center gap-2.5 -mx-1 px-1 py-1.5 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-800",children:[e.jsx("div",{className:`w-7 h-7 rounded-lg flex items-center justify-center shrink-0 ${s.color}`,children:e.jsx(a,{size:14})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-xs text-gray-700 dark:text-gray-300 truncate",children:[e.jsx("span",{className:"font-medium text-gray-900 dark:text-gray-100",children:c})," ",s.text]}),e.jsx("p",{className:"text-[10px] text-gray-400",children:s.ts?z(s.ts).format("D MMM, h:mm a"):""})]})]});return s.route?e.jsx(Z,{to:s.route,children:n},s.id):e.jsx("button",{onClick:()=>b==null?void 0:b(s.tab),className:"w-full text-left",children:n},s.id)})})]},i.label))})}function ps({client:t}){const[r,m]=h.useState(null),[l,v]=h.useState(!0);if(h.useEffect(()=>{if(!(t!=null&&t.id)){v(!1);return}let a=!0;return(async()=>{try{const n=await S.functions.invoke("manageOnboarding",{action:"list_for_client",client_id:t.id}),g=(n==null?void 0:n.data)||n,y=(g==null?void 0:g.instances)||[];a&&m(y[0]||null)}catch{a&&m(null)}finally{a&&v(!1)}})(),()=>{a=!1}},[t==null?void 0:t.id]),l)return e.jsxs("div",{className:"bg-white dark:bg-gray-900 border border-gray-100 dark:border-gray-800 rounded-xl p-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100 mb-2",children:"Onboarding"}),e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(T,{className:"w-5 h-5 text-gray-300 animate-spin"})})]});if(!r)return null;const{percent:_,completed:b,total:x,outstandingCount:c,outstanding:o}=xt(r),N=r.status==="completed"||(r.progress||0)>=100,d=o.filter(a=>a.type==="document"),u=o.filter(a=>a.type==="engagement_letter"||a.type==="authority"),i=o.some(a=>a.type==="kyc"||a.type==="kyc_selfie")?"Incomplete":"Verified",s=N?"bg-emerald-50 text-emerald-700 border-emerald-200":c>0?"bg-amber-50 text-amber-700 border-amber-200":"bg-blue-50 text-blue-700 border-blue-200";return e.jsxs("div",{className:"flex-1 min-w-0 bg-white dark:bg-gray-900 border border-gray-100 dark:border-gray-800 rounded-xl p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:"Onboarding"}),e.jsx("span",{className:`text-xs font-semibold px-2 py-0.5 rounded-full border ${s}`,children:N?"Complete":c>0?`${c} outstanding`:"In progress"})]}),e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("div",{className:"flex-1 h-2.5 bg-gray-100 dark:bg-gray-800 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-gradient-to-r from-emerald-400 to-emerald-600 rounded-full transition-all",style:{width:`${_}%`}})}),e.jsxs("span",{className:"text-xs font-bold text-gray-700 dark:text-gray-300 shrink-0",children:[_,"%"]})]}),e.jsxs("p",{className:"text-xs text-gray-400 mb-3",children:[b," of ",x," steps completed"]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-lg p-2.5",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wide text-gray-400",children:"Missing Docs"}),e.jsx("p",{className:"text-sm font-bold text-gray-800 dark:text-gray-200",children:d.length}),d.length>0&&e.jsxs("ul",{className:"mt-1 space-y-0.5",children:[d.slice(0,2).map((a,n)=>e.jsxs("li",{className:"text-[10px] text-gray-500 truncate",children:["⢠",a.label.replace("Upload ","")]},n)),d.length>2&&e.jsxs("li",{className:"text-[10px] text-gray-400",children:["+",d.length-2," more"]})]})]}),e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-lg p-2.5",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wide text-gray-400",children:"Missing Sigs"}),e.jsx("p",{className:"text-sm font-bold text-gray-800 dark:text-gray-200",children:u.length}),u.length>0&&e.jsx("ul",{className:"mt-1 space-y-0.5",children:u.slice(0,2).map((a,n)=>e.jsxs("li",{className:"text-[10px] text-gray-500 truncate",children:["⢠",a.label]},n))})]})]}),e.jsxs("div",{className:"mt-2 flex items-center justify-between bg-gray-50 dark:bg-gray-800 rounded-lg p-2.5",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-wide text-gray-400",children:"Identity Verification"}),e.jsx("span",{className:`text-xs font-semibold ${i==="Verified"?"text-emerald-600":"text-amber-600"}`,children:i})]}),!N&&c>0&&e.jsxs(Z,{to:`/staff/clients/${t.id}`,className:"mt-3 flex items-center justify-center gap-1 w-full py-2 bg-emerald-600 text-white rounded-lg text-xs font-semibold hover:bg-emerald-700",children:["View Outstanding Details ",e.jsx(re,{size:13})]})]})}function hs({client:t}){var N;const[r,m]=h.useState(null),[l,v]=h.useState(!0),[_,b]=h.useState(null);h.useEffect(()=>{if(!(t!=null&&t.id))return;let d=!1;return(async()=>{try{const u=await S.functions.invoke("loadTaxReadiness",{target_client_id:t.id}),i=(u==null?void 0:u.data)||u;if(d)return;if(i!=null&&i.error)throw new Error(i.error);m(i)}catch(u){d||b(u.message||"Failed to load")}finally{d||v(!1)}})(),()=>{d=!0}},[t==null?void 0:t.id]);const x=(r==null?void 0:r.percentage)??0,c=(r==null?void 0:r.outstanding)??[],o=x===100;return e.jsxs("div",{className:"bg-white dark:bg-gray-900 border border-gray-100 dark:border-gray-800 rounded-xl p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ve,{size:16,className:"text-blue-500"}),e.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:"Tax Readiness"})]}),l?e.jsx(T,{size:14,className:"animate-spin text-gray-400"}):e.jsxs("span",{className:`text-lg font-bold ${o?"text-emerald-600":"text-blue-600"}`,children:[x,"%"]})]}),l?e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(T,{className:"w-5 h-5 animate-spin text-gray-300"})}):_?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-400 py-2",children:[e.jsx($t,{size:13})," Unable to load readiness"]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-2 rounded-full bg-gray-100 dark:bg-gray-800 overflow-hidden mb-3",children:e.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${o?"bg-emerald-500":"bg-gradient-to-r from-blue-600 to-cyan-400"}`,style:{width:`${x}%`}})}),o?e.jsx("p",{className:"text-xs text-emerald-600 font-medium py-1",children:"ð Tax Ready â this client has everything required."}):c.length>0?e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("p",{className:"text-xs text-gray-400 mb-1",children:[c.length," outstanding:"]}),c.slice(0,5).map(d=>e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-400 shrink-0"}),e.jsx("span",{className:"text-gray-600 dark:text-gray-300 truncate flex-1",children:d.label})]},d.id)),c.length>5&&e.jsxs("p",{className:"text-xs text-gray-400 pl-3.5",children:["+",c.length-5," more"]})]}):null,((N=r==null?void 0:r.waiting_on_accountant)==null?void 0:N.length)>0&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-gray-100 dark:border-gray-800",children:[e.jsx("p",{className:"text-xs font-semibold text-gray-500 mb-1.5",children:"Waiting on you:"}),r.waiting_on_accountant.slice(0,3).map((d,u)=>e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:[e.jsx(re,{size:12,className:"text-blue-400"}),e.jsx("span",{className:"truncate",children:d.label})]},u))]})]})]})}function I({title:t,action:r,children:m,className:l=""}){return e.jsxs("div",{className:`bg-white dark:bg-gray-900 border border-gray-100 dark:border-gray-800 rounded-xl p-4 ${l}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:t}),r]}),m]})}function V({text:t}){return e.jsx("p",{className:"text-xs text-gray-400 py-3 text-center",children:t})}function fs({client:t,documents:r=[],jobs:m=[],tasks:l=[],messages:v=[],appointments:_=[],signatures:b=[],onTab:x,onAction:c,onClientUpdated:o}){const N=m.filter(n=>!n.archived&&n.status!=="Completed"),d=(l||[]).filter(n=>n.status!=="Completed"),u=[...r].sort((n,g)=>new Date(g.upload_date||g.created_date||0)-new Date(n.upload_date||n.created_date||0)).slice(0,5),i=[...v].sort((n,g)=>new Date(g.created_date||0)-new Date(n.created_date||0)).slice(0,5),s=new Date().toISOString().split("T")[0],a=[..._].filter(n=>n.status!=="Cancelled"&&n.appointment_date&&n.appointment_date>=s).sort((n,g)=>(n.appointment_date+"").localeCompare(g.appointment_date+"")).slice(0,5);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[e.jsxs(I,{title:"Personal Information",action:e.jsx("button",{onClick:()=>c("edit"),className:"text-xs text-emerald-600 font-medium",children:"Edit"}),children:[e.jsxs("div",{className:"grid grid-cols-2 gap-x-4",children:[e.jsx(Y,{label:"Date of Birth",value:t.date_of_birth?z(t.date_of_birth).format("D MMM YYYY"):""}),e.jsx(Y,{label:"TFN",value:t.tax_file_number}),e.jsx(Y,{label:"Occupation",value:t.occupation}),e.jsx(Y,{label:"Mobile",value:t.mobile}),e.jsx(Y,{label:"Address",value:t.residential_address,full:!0}),e.jsx(Y,{label:"Email",value:t.email,full:!0}),e.jsx(Y,{label:"MFA Enabled",value:t.mfa_enabled?"Yes":"No"}),t.client_type==="Business"&&e.jsx(Y,{label:"Source of Funds",value:t.source_of_funds,full:!0})]}),e.jsx("div",{className:"mt-3 pt-3 border-t border-gray-100",children:e.jsx(Dt,{client:t,onUpdated:(n,g)=>o==null?void 0:o(g)})})]}),e.jsx(I,{title:"Current Jobs",className:"lg:col-span-2",action:e.jsxs("button",{onClick:()=>c("newJob"),disabled:t.archived,className:"inline-flex items-center gap-1 text-xs font-semibold text-white bg-emerald-600 hover:bg-emerald-700 px-2.5 py-1.5 rounded-lg disabled:opacity-50",children:[e.jsx(Q,{size:13})," New Job"]}),children:N.length===0?e.jsx(V,{text:"No active jobs â start a new engagement"}):e.jsx("div",{className:"space-y-2",children:N.map(n=>e.jsxs(Z,{to:`/staff/jobs/${n.id}`,className:"flex items-center gap-3 -mx-1 px-2 py-2 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-800",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-blue-50 flex items-center justify-center shrink-0",children:e.jsx(ee,{size:16,className:"text-blue-600"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100 truncate",children:n.title||n.job_type}),e.jsxs("p",{className:"text-xs text-gray-500 truncate",children:[n.financial_year||n.reporting_period||""," ",n.assigned_accountant?`· ${n.assigned_accountant}`:""," ",n.priority?`· ${n.priority} priority`:""]})]}),e.jsx(ae,{status:n.status,small:!0}),e.jsx(re,{size:16,className:"text-gray-300 shrink-0"})]},n.id))})})]}),e.jsx(I,{title:"Bank Details",action:e.jsx("button",{onClick:()=>c("edit"),className:"text-xs text-emerald-600 font-medium",children:"Edit"}),children:t.bank_account_name||t.bank_name||t.bank_bsb||t.bank_account_number?e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-x-4",children:[e.jsx(Y,{label:"Account Name",value:t.bank_account_name}),e.jsx(Y,{label:"Bank",value:t.bank_name}),e.jsx(Y,{label:"BSB",value:t.bank_bsb}),e.jsx(Y,{label:"Account Number",value:t.bank_account_number})]}):e.jsx(V,{text:"No bank details recorded â click Edit to add"})}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[e.jsx(I,{title:"Recent Activity",children:e.jsx(Ke,{client:t,documents:r,jobs:m,signatures:b,messages:v,appointments:_,onTab:x,limit:8})}),e.jsx(I,{title:"Outstanding Tasks",action:e.jsx("span",{className:"text-xs text-gray-400",children:d.length}),children:d.length===0?e.jsx(V,{text:"No outstanding tasks"}):e.jsx("div",{className:"space-y-2",children:d.slice(0,6).map(n=>e.jsxs("div",{className:"flex items-center gap-2.5 -mx-1 px-1 py-1.5 rounded-lg hover:bg-gray-50",children:[e.jsx(zt,{size:15,className:"text-amber-500 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-gray-800 dark:text-gray-200 truncate",children:n.title}),e.jsxs("p",{className:"text-xs text-gray-400",children:[n.due_date?`Due ${z(n.due_date).format("D MMM")}`:"No due date",n.priority?` · ${n.priority}`:""]})]})]},n.id))})}),e.jsx(I,{title:"Recent Documents",action:e.jsx("button",{onClick:()=>x("documents"),className:"text-xs text-emerald-600 font-medium",children:"View all"}),children:u.length===0?e.jsx(V,{text:"No documents yet"}):e.jsx("div",{className:"space-y-2",children:u.map(n=>e.jsxs("a",{href:n.file_url,target:"_blank",rel:"noreferrer",className:"flex items-center gap-2.5 -mx-1 px-1 py-1.5 rounded-lg hover:bg-gray-50",children:[e.jsx(G,{size:15,className:"text-gray-400 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-gray-800 dark:text-gray-200 truncate",children:n.file_name||"Document"}),e.jsxs("p",{className:"text-xs text-gray-400",children:[n.upload_date?z(n.upload_date).format("D MMM YYYY"):"",n.category?` · ${n.category}`:""]})]})]},n.id))})})]}),e.jsxs("div",{className:"flex flex-col lg:flex-row gap-4",children:[e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx(hs,{client:t})}),e.jsx(ps,{client:t})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsx(I,{title:"Recent Messages",action:e.jsx("button",{onClick:()=>x("messages"),className:"text-xs text-emerald-600 font-medium",children:"View all"}),children:i.length===0?e.jsx(V,{text:"No messages yet"}):e.jsx("div",{className:"space-y-2",children:i.map(n=>e.jsxs("button",{onClick:()=>x("messages"),className:"w-full flex items-start gap-2.5 -mx-1 px-1 py-1.5 rounded-lg hover:bg-gray-50 text-left",children:[e.jsx(te,{size:15,className:`mt-0.5 shrink-0 ${n.sender_role==="client"?"text-cyan-500":"text-gray-400"}`}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm text-gray-700 dark:text-gray-300 line-clamp-2",children:n.content}),e.jsxs("p",{className:"text-xs text-gray-400",children:[n.sender_name||(n.sender_role==="client"?"Client":"You")," · ",n.created_date?z(n.created_date).format("D MMM, h:mm a"):""]})]})]},n.id))})}),e.jsx(I,{title:"Upcoming Bookings",action:e.jsx("button",{onClick:()=>c("book"),className:"text-xs text-emerald-600 font-medium",children:"Book"}),children:a.length===0?e.jsx(V,{text:"No upcoming bookings"}):e.jsx("div",{className:"space-y-2",children:a.map(n=>e.jsxs("div",{className:"flex items-center gap-2.5 -
16mx-1 px-1 py-1.5 rounded-lg hover:bg-gray-50",children:[e.jsx(he,{size:15,className:"text-violet-500 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-gray-800 dark:text-gray-200 truncate",children:n.appointment_type||"Appointment"}),e.jsxs("p",{className:"text-xs text-gray-400",children:[n.appointment_date?z(n.appointment_date).format("D MMM YYYY"):"",n.appointment_time?` ${n.appointment_time}`:"",n.location?` · ${n.location}`:""]})]}),e.jsx(ae,{status:n.status,small:!0})]},n.id))})})]})]})}function bs({client:t,messages:r=[],onSent:m}){const[l,v]=h.useState(null),[_,b]=h.useState(""),[x,c]=h.useState(!1),o=h.useRef(null);h.useEffect(()=>{S.auth.me().then(v).catch(()=>{})},[]),h.useEffect(()=>{o.current&&(o.current.scrollTop=o.current.scrollHeight)},[r.length]);const N=async()=>{const u=_.trim();if(!(!u||!t.user_id)){c(!0);try{const i=(l==null?void 0:l.role)==="admin"||(l==null?void 0:l.role)==="super_admin"?"admin":"franchisee",s=(l==null?void 0:l.full_name)||(l==null?void 0:l.email)||"Your accountant",a=await S.entities.Message.create({client_id:t.id,owner_user_id:t.user_id,sender_id:l==null?void 0:l.id,sender_name:s,sender_role:i,content:u,organisation_id:t.organisation_id||t.company_id,office_id:t.office_id,is_read:!0});try{await S.entities.Notification.create({target_email:(t.email||"").toLowerCase().trim(),actor_name:s,type:"accountant_message",title:`New message from ${s}`,body:u.length>120?u.slice(0,120)+"â¦":u,client_id:t.id,audience:"client",is_read:!1})}catch{}try{const n=`${window.location.origin}/portal/messages`,g=`<div style="font-family:Arial,sans-serif;max-width:560px;margin:0 auto;color:#1f2937"><div style="background:linear-gradient(90deg,#1d4ed8,#06b6d4);padding:24px;border-radius:12px 12px 0 0;text-align:center"><h1 style="color:#fff;margin:0;font-size:22px">TaxEase360</h1><p style="color:#dbeafe;margin:4px 0 0;font-size:13px">New message</p></div><div style="padding:24px;border:1px solid #e5e7eb;border-top:none;border-radius:0 0 12px 12px"><p style="margin:0 0 12px">Hi ${t.full_name||""},</p><p style="margin:0 0 12px"><strong>${s}</strong> sent you a message:</p><div style="background:#f9fafb;border:1px solid #e5e7eb;border-radius:10px;padding:14px;margin:0 0 16px;color:#374151;font-size:14px;line-height:1.5">${u.replace(/</g,"<")}</div><a href="${n}" style="display:inline-block;background:#1d4ed8;color:#fff;text-decoration:none;padding:14px 28px;border-radius:10px;font-weight:bold;font-size:15px">Reply in Client Portal</a><p style="margin:16px 0 0;font-size:12px;color:#9ca3af">You received this notification from TaxEase360.</p></div></div>`;await S.functions.invoke("sendExternalEmail",{to:t.email,subject:`New message from ${s}`,from_name:s,html:g})}catch{}m==null||m(a),b("")}finally{c(!1)}}},d=[...r].sort((u,i)=>new Date(u.created_date||0)-new Date(i.created_date||0));return e.jsxs("div",{className:"bg-white dark:bg-gray-900 border border-gray-100 dark:border-gray-800 rounded-xl flex flex-col",style:{height:"60vh"},children:[e.jsx("div",{ref:o,className:"flex-1 overflow-y-auto p-4 space-y-3",children:d.length===0?e.jsx("p",{className:"text-sm text-gray-400 text-center py-10",children:"No messages yet â start the conversation"}):d.map(u=>{const i=u.sender_role!=="client";return e.jsx("div",{className:`flex ${i?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[75%] rounded-2xl px-3.5 py-2 ${i?"bg-emerald-600 text-white":"bg-gray-100 dark:bg-gray-800 text-gray-800 dark:text-gray-100"}`,children:[e.jsx("p",{className:"text-sm whitespace-pre-wrap break-words",children:u.content}),e.jsxs("p",{className:`text-[10px] mt-0.5 ${i?"text-emerald-100":"text-gray-400"}`,children:[u.sender_name||(i?"You":"Client")," · ",u.created_date?z(u.created_date).format("D MMM, h:mm a"):""]})]})},u.id)})}),e.jsxs("div",{className:"border-t border-gray-100 dark:border-gray-800 p-3 flex items-center gap-2",children:[e.jsx("textarea",{value:_,onChange:u=>b(u.target.value),onKeyDown:u=>{u.key==="Enter"&&!u.shiftKey&&(u.preventDefault(),N())},rows:1,placeholder:"Type a messageâ¦",className:"flex-1 resize-none text-sm border border-gray-200 dark:border-gray-700 rounded-xl px-3 py-2.5 bg-gray-50 dark:bg-gray-800 focus:outline-none focus:ring-2 focus:ring-emerald-500/40"}),e.jsx("button",{onClick:N,disabled:x||!_.trim(),className:"w-10 h-10 rounded-xl bg-emerald-600 text-white flex items-center justify-center disabled:opacity-40 shrink-0",children:x?e.jsx(T,{size:16,className:"animate-spin"}):e.jsx(Ne,{size:16})})]})]})}function ys({client:t,appointments:r=[],onBook:m}){const l=[...r].sort((c,o)=>new Date(o.appointment_date||0)-new Date(c.appointment_date||0)),v=new Date().toISOString().split("T")[0],_=l.filter(c=>c.appointment_date&&c.appointment_date>=v&&c.status!=="Cancelled"),b=l.filter(c=>!_.includes(c)),x=({a:c})=>e.jsxs("div",{className:"flex items-center gap-3 -mx-1 px-2 py-2.5 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-800",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-violet-50 flex items-center justify-center shrink-0",children:e.jsx(he,{size:17,className:"text-violet-600"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100 truncate",children:c.appointment_type||"Appointment"}),e.jsxs("p",{className:"text-xs text-gray-500 truncate flex items-center gap-1.5",children:[c.appointment_date?z(c.appointment_date).format("D MMM YYYY"):"â",c.appointment_time?` · ${c.appointment_time}`:"",c.is_online?e.jsxs("span",{className:"inline-flex items-center gap-0.5",children:[e.jsx(Mt,{size:11})," Online"]}):c.location?e.jsxs("span",{className:"inline-flex items-center gap-0.5",children:[e.jsx(Tt,{size:11})," ",c.location]}):null]})]}),e.jsx(ae,{status:c.status,small:!0})]});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-sm text-gray-500",children:[r.length," booking(s)"]}),e.jsxs("button",{onClick:m,className:"inline-flex items-center gap-1 text-xs font-semibold text-white bg-emerald-600 hover:bg-emerald-700 px-2.5 py-1.5 rounded-lg",children:[e.jsx(Q,{size:13})," Book Appointment"]})]}),e.jsxs("div",{className:"bg-white dark:bg-gray-900 border border-gray-100 dark:border-gray-800 rounded-xl p-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100 mb-2",children:"Upcoming"}),_.length===0?e.jsx("p",{className:"text-xs text-gray-400 py-3 text-center",children:"No upcoming bookings"}):e.jsx("div",{className:"space-y-1",children:_.map(c=>e.jsx(x,{a:c},c.id))})]}),b.length>0&&e.jsxs("div",{className:"bg-white dark:bg-gray-900 border border-gray-100 dark:border-gray-800 rounded-xl p-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100 mb-2",children:"History"}),e.jsx("div",{className:"space-y-1",children:b.map(c=>e.jsx(x,{a:c},c.id))})]})]})}const js={draft:"bg-gray-100 text-gray-600",sent:"bg-blue-100 text-blue-700",viewed:"bg-amber-100 text-amber-700",started:"bg-amber-100 text-amber-700",in_progress:"bg-amber-100 text-amber-700",submitted:"bg-emerald-100 text-emerald-700",signed:"bg-emerald-100 text-emerald-700",completed:"bg-emerald-100 text-emerald-700",expired:"bg-rose-100 text-rose-700",cancelled:"bg-slate-100 text-slate-500"};function vs({forms:t=[],onSend:r}){const m=[...t].sort((l,v)=>new Date(v.created_date||0)-new Date(l.created_date||0));return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-sm text-gray-500",children:[t.length," form(s)"]}),e.jsxs("button",{onClick:r,className:"inline-flex items-center gap-1 text-xs font-semibold text-white bg-emerald-600 hover:bg-emerald-700 px-2.5 py-1.5 rounded-lg",children:[e.jsx(Ne,{size:13})," Send Form"]})]}),e.jsx("div",{className:"bg-white dark:bg-gray-900 border border-gray-100 dark:border-gray-800 rounded-xl divide-y divide-gray-50 dark:divide-gray-800",children:m.length===0?e.jsx("p",{className:"text-sm text-gray-400 py-10 text-center",children:"No forms sent to this client yet"}):m.map(l=>e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-rose-50 flex items-center justify-center shrink-0",children:e.jsx(ut,{size:16,className:"text-rose-600"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100 truncate",children:l.title||l.template_name||"Form"}),e.jsxs("p",{className:"text-xs text-gray-500 truncate",children:["Sent ",l.sent_at?z(l.sent_at).format("D MMM YYYY"):l.created_date?z(l.created_date).format("D MMM YYYY"):"â",l.submitted_at?` · Submitted ${z(l.submitted_at).format("D MMM")}`:""]})]}),e.jsx("span",{className:`text-[11px] font-semibold px-2 py-0.5 rounded-full ${js[l.status]||"bg-gray-100 text-gray-600"}`,children:l.status}),e.jsx(re,{size:16,className:"text-gray-300 shrink-0"})]},l.id))})]})}function Ns(){return"f_"+Math.random().toString(36).slice(2,9)}function ws({fields:t,onApply:r}){const[m,l]=h.useState([]),[v,_]=h.useState(!0),[b,x]=h.useState(""),[c,o]=h.useState(!1),N=async()=>{_(!0);try{const s=await S.auth.me(),a=await S.entities.FieldTemplate.filter({created_by_email:s.email},"-created_date",50);l(a)}catch{l([])}finally{_(!1)}};h.useEffect(()=>{N()},[]);const d=async()=>
16{if(!(!b.trim()||t.length===0)){o(!0);try{const s=await S.auth.me();await S.entities.FieldTemplate.create({name:b.trim(),fields:t.map(({id:a,...n})=>n),created_by_email:s.email,created_by_name:s.full_name||s.email}),x(""),await N()}finally{o(!1)}}},u=s=>{r(s.fields.map(a=>({...a,id:Ns()})))},i=async s=>{await S.entities.FieldTemplate.delete(s.id),l(a=>a.filter(n=>n.id!==s.id))};return e.jsxs("div",{className:"rounded-2xl border border-gray-200 bg-gray-50/60 p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-gray-700",children:[e.jsx(gt,{size:15}),e.jsx("span",{className:"text-xs font-semibold",children:"Field templates"})]}),v?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-400",children:[e.jsx(T,{size:12,className:"animate-spin"})," Loading templatesâ¦"]}):m.length===0?e.jsx("p",{className:"text-[11px] text-gray-400",children:"No saved templates yet. Place fields below, then save them to reuse on future documents."}):e.jsx("div",{className:"flex flex-wrap gap-2",children:m.map(s=>{var a;return e.jsxs("div",{className:"flex items-center gap-1 bg-white border border-gray-200 rounded-lg pl-2 pr-1 py-1",children:[e.jsxs("button",{onClick:()=>u(s),className:"flex items-center gap-1.5 text-xs font-medium text-gray-700 hover:text-emerald-700",style:{minHeight:32},"aria-label":`Apply template ${s.name}`,children:[e.jsx(ss,{size:12,className:"text-emerald-600"}),s.name,e.jsxs("span",{className:"text-[10px] text-gray-400",children:["(",((a=s.fields)==null?void 0:a.length)||0,")"]})]}),e.jsx("button",{onClick:()=>i(s),className:"w-6 h-6 rounded-md text-gray-400 hover:text-red-600 hover:bg-red-50 flex items-center justify-center","aria-label":`Delete template ${s.name}`,children:e.jsx(Ie,{size:12})})]},s.id)})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ne,{value:b,onChange:s=>x(s.target.value),placeholder:"Template name (e.g. Engagement letter)",className:"h-9 text-xs"}),e.jsxs(F,{onClick:d,disabled:c||!b.trim()||t.length===0,size:"sm",variant:"outline",className:"shrink-0",children:[c?e.jsx(T,{size:14,className:"animate-spin"}):e.jsx(Q,{size:14}),"Save"]})]}),t.length>0&&e.jsxs("p",{className:"text-[11px] text-gray-400",children:["Saving stores the ",t.length," field",t.length===1?"":"s"," currently on this document as a reusable group."]})]})}function _s(){return Math.random().toString(36).slice(2)+Date.now().toString(36)+Math.random().toString(36).slice(2)}function ks({client:t}){const r=Le(),[m,l]=h.useState(""),[v,_]=h.useState(""),[b,x]=h.useState(""),[c,o]=h.useState(""),[N,d]=h.useState([]),[u,i]=h.useState(!1),[s,a]=h.useState(!1),[n,g]=h.useState(!1),[y,$]=h.useState(!1),[O,f]=h.useState(!1),w=async k=>{if(k){i(!0);try{const{file_url:D}=await S.integrations.Core.UploadFile({file:k});x(D),o(k.name),d([])}finally{i(!1)}}},M=k=>{var B,q;k.preventDefault(),$(!1);const D=(q=(B=k.dataTransfer)==null?void 0:B.files)==null?void 0:q[0];D&&w(D)},R=async()=>{if(!(!b||!m||N.length===0)){a(!0);try{const k=await S.auth.me(),D=_s();await S.entities.SignatureRequest.create({client_id:t.id,client_name:t.full_name,client_email:t.email,accountant_email:k.email,accountant_name:k.full_name||k.email,title:m,message:v,document_url:b,document_name:c,fields:N,status:"pending",token:D,requested_date:new Date().toISOString().split("T")[0]});try{await S.functions.invoke("ensureSignatureJob",{client_id:t.id,signature_title:m})}catch{}const B=`${window.location.origin}/sign/${D}`;try{await S.entities.Notification.create({target_email:(t.email||"").toLowerCase().trim(),actor_name:k.full_name||k.email,type:"signature_requested",title:"Document to sign",body:`${k.full_name||"Your accountant"} requested your signature on "${m}"`,client_id:t.id,audience:"client",is_read:!1})}catch{}try{await S.functions.invoke("sendExternalEmail",{to:t.email,subject:`Document to sign: ${m}`,from_name:k.full_name||"TaxEase360",html:`<p>Hi ${t.full_name||""},</p><p><b>${k.full_name||"Your accountant"}</b> has requested your signature on <b>${m}</b>.</p>${v?`<p>${v}</p>`:""}<p>Please review and sign here:<br/><a href="${B}">${B}</a></p><p style="color:#888;font-size:12px">This link is private to you. Do not share it.</p>`})}catch{}g(!0),setTimeout(()=>r(`/staff/clients/${t.id}`),1800)}finally{a(!1),n||f(!1)}}},j=()=>{!b||!m||N.length===0||(f(!0),R())};return n?e.jsxs("div",{className:"flex flex-col items-center gap-3 py-12 text-center",children:[e.jsx(ve,{size:40,className:"text-emerald-600"}),e.jsx("p",{className:"text-sm font-semibold text-gray-900",children:"Signature request sent"}),e.jsxs("p",{className:"text-xs text-gray-500",children:[t.full_name," received an email link to review and sign."]})]}):e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"bg-emerald-50 border border-emerald-100 rounded-2xl p-4",children:[e.jsxs("p",{className:"text-sm font-semibold text-emerald-900 flex items-center gap-2",children:[e.jsx(K,{size:16})," Upload a document for ",t.full_name," to sign"]}),e.jsx("p",{className:"text-xs text-emerald-700 mt-1",children:"Drag signature, date, and other fields onto the document so the client knows exactly where to sign."})]}),e.jsxs("div",{children:[e.jsx(P,{children:"Document title"}),e.jsx(ne,{value:m,onChange:k=>l(k.target.value),placeholder:"e.g. Tax return engagement letter",className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(P,{children:"Message to client (optional)"}
16),e.jsx(Ot,{value:v,onChange:k=>_(k.target.value),placeholder:"Please review and signâ¦",className:"mt-1",rows:2})]}),e.jsxs("div",{children:[e.jsx(P,{children:"Document (PDF or image)"}),e.jsxs("div",{onDragOver:k=>{k.preventDefault(),$(!0)},onDragLeave:()=>$(!1),onDrop:M,className:`mt-1 flex flex-col items-center gap-2 p-5 border-2 border-dashed rounded-xl cursor-pointer transition-colors ${y?"border-blue-500 bg-blue-50":"border-gray-200 hover:border-blue-400"}`,children:[u?e.jsx(T,{size:22,className:"text-blue-600 animate-spin"}):b?e.jsxs(e.Fragment,{children:[e.jsx(K,{size:22,className:"text-emerald-600"}),e.jsx("span",{className:"text-xs font-medium text-gray-700 truncate max-w-full",children:c}),e.jsx("span",{className:"text-xs text-blue-600",children:"Drag a file here or tap to replace"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ft,{size:22,className:"text-gray-400"}),e.jsx("span",{className:"text-xs font-medium text-gray-600",children:"Drag & drop a document here, or tap to browse"}),e.jsx("span",{className:"text-[11px] text-gray-400",children:"PDF, PNG, JPG"})]}),e.jsx("label",{className:"cursor-pointer",children:e.jsx("input",{type:"file",className:"hidden",accept:".pdf,image/*",onChange:k=>w(k.target.files[0]),disabled:u})})]})]}),b&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{children:"Place fields on the document"}),!O&&e.jsx(ws,{fields:N,onApply:k=>d(D=>[...D,...k])}),e.jsx(Rt,{docUrl:b,docName:c,fields:N,onChange:d,locked:O}),!O&&e.jsxs("p",{className:"text-[11px] text-gray-400",children:[N.length," field",N.length===1?"":"s"," placed. Drag placed fields to reposition; tap the â to remove."]})]}),e.jsxs(F,{onClick:j,disabled:s||O||!b||!m||N.length===0,className:"w-full bg-emerald-700 hover:bg-emerald-800",style:{minHeight:48},children:[s?e.jsx(T,{size:16,className:"animate-spin mr-2"}):e.jsx(Pe,{size:16,className:"mr-2"}),s?"Finalizingâ¦":`Finalize and Send${N.length?` (${N.length})`:""}`]})]})}const Ye={pending:{label:"Pending",style:"bg-amber-100 text-amber-700",Icon:Ue},signed:{label:"Signed",style:"bg-emerald-100 text-emerald-700",Icon:ve},declined:{label:"Declined",style:"bg-rose-100 text-rose-700",Icon:He}};function Cs({client:t,signatures:r=[],autoCompose:m=!1,onChanged:l}){const{toast:v}=W(),[_,b]=h.useState(m),[x,c]=h.useState(null),[o,N]=h.useState(null),d=[...r].sort((s,a)=>new Date(a.requested_date||a.created_date||0)-new Date(s.requested_date||s.created_date||0)),u=async s=>{c(s.id);try{const a=new Date().toISOString();await S.entities.SignatureRequest.update(s.id,{revoked:!0,expires_at:a}),v({title:"Request revoked",description:"Recipients can no longer sign this document."}),l==null||l()}catch(a){v({title:"Failed to revoke",description:a.message,variant:"destructive"})}finally{c(null)}},i=async s=>{c(s.id);try{await S.entities.SignatureRequest.delete(s.id),N(null),v({title:"Request deleted"}),l==null||l()}catch(a){v({title:"Failed to delete",description:a.message,variant:"destructive"})}finally{c(null)}};return _?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900",children:"New signature request"}),e.jsxs("button",{onClick:()=>b(!1),className:"inline-flex items-center gap-1 text-xs text-gray-500 hover:text-gray-800",children:[e.jsx(pt,{size:14})," Cancel"]})]}),e.jsx(ks,{client:t})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-sm text-gray-500",children:[r.length," request(s)"]}),e.jsxs("button",{onClick:()=>b(!0),className:"inline-flex items-center gap-1 text-xs font-semibold text-white bg-emerald-600 hover:bg-emerald-700 px-2.5 py-1.5 rounded-lg",children:[e.jsx(Q,{size:13})," Request Signature"]})]}),e.jsx("div",{className:"bg-white dark:bg-gray-900 border border-gray-100 dark:border-gray-800 rounded-xl divide-y divide-gray-50 dark:divide-gray-800",children:d.length===0?e.jsx("p",{className:"text-sm text-gray-400 py-10 text-center",children:"No signature requests yet"}):d.map(s=>{const a=Ye[s.status]||Ye.pending,n=a.Icon,g=s.status==="pending"&&!s.revoked,y=o===s.id;return e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-violet-50 flex items-center justify-center shrink-0",children:e.jsx(K,{size:16,className:"text-violet-600"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100 truncate",children:s.title||"Document"}),e.jsxs("p",{className:"text-xs text-gray-500 truncate",children:["Requested ",s.requested_date?z(s.requested_date).format("D MMM YYYY"):"â",s.signed_by_name?` · Signed by ${s.signed_by_name}`:"",s.revoked?" · Revoked":""]}),s.status==="signed"&&s.signed_document_url&&e.jsx("div",{className:"mt-1.5",children:e.jsx(Yt,{url:s.signed_document_url,name:`${s.title||"Document"} (signed)`,className:"text-xs"})})]}),y?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>i(s),disabled:x===s.id,className:"text-xs font-semibold text-white bg-rose-600 rounded-lg px-2.5 py-1.5 disabled:opacity-50",style:{minHeight:32},children:x===s.id?e.jsx(T,{size:12,className:"animate-spin"}):"Delete"}),e.jsx("button",{onClick:()=>N(null),className:"text-xs font-semibold text-gray-600 bg-gray-100 rounded-lg px-2.5 py-1.5",style:{minHeight:32},children:"Keep"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] font-semibold px-2 py-0.5 rounded-full ${a.style} ${s.revoked?"opacity-60":""}`,children:[e.jsx(n,{size:11})," ",s.revoked?"Revoked":a.label]}),e.jsxs(At,{children:[e.jsx(Et,{asChild:!0,children:e.jsx("button",{type:"button",className:"p-1.5 rounded-md text-gray-500 hover:bg-gray-100 hover:text-gray-800","aria-label":"More actions",style:{minHeight:32,minWidth:32},children:e.jsx(ht,{size:15})})}),e.jsxs(qt,{align:"end",className:"w-40",children:[g&&e.jsxs(Te,{onClick:()=>u(s),disabled:x===s.id,children:[x===s.id?e.jsx(T,{size:14,className:"animate-spin"}):e.jsx(ft,{size:14})," Revoke"]}),e.jsxs(Te,{onClick:()=>N(s.id),disabled:x===s.id,className:"text-rose-600",children:[e.jsx(Ie,{size:14})," Delete"]})]})]})]})]},s.id)})})]})}function Ss({client:t,onClientUpdated:r}){const[m,l]=h.useState(t.notes||""),[v,_]=h.useState(!1),{toast:b}=W(),x=async()=>{_(!0);try{await S.functions.invoke("updateClientProfile",{client_id:t.id,patch:{notes:m}}),r==null||r({notes:m}),b({title:"Notes saved"})}catch(c){b({variant:"destructive",title:"Could not save notes",description:c.message})}finally{_(!1)}};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-gray-900 dark:text-gray-100",children:[e.jsx(is,{size:16,className:"text-amber-500"})," Client Notes"]}),e.jsx("textarea",{value:m,onChange:c=>l(c.target.value),rows:10,placeholder:"Add internal notes about this client â visible to your firm, not to the clientâ¦",className:"w-full text-sm border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900 rounded-xl px-3 py-3 resize-none focus:outline-none focus:ring-2 focus:ring-emerald-500/40"}),e.jsx("div",{className:"flex justify-end",children:e.jsxs("button",{onClick:x,disabled:v||m===(t.notes||""),className:"inline-flex items-center gap-1.5 text-xs font-semibold text-white bg-emerald-600 hover:bg-emerald-700 px-3.5 py-2 rounded-lg disabled:opacity-50",children:[v?e.jsx(T,{size:14,className:"animate-spin"}):e.jsx(Pt,{size:14})," Save notes"]})})]})}const xe=["Tax Returns","Tax Receipts","Work Related Expenses","Rental Property Documents","Business Documents","ID Documents","AML Documents","Bank Statements","Logbook Records","Other"],Ds={"Pending Review":"bg-
16amber-50 text-amber-700",Approved:"bg-emerald-50 text-emerald-700",Rejected:"bg-rose-50 text-rose-700","Needs Resubmission":"bg-orange-50 text-orange-700"};function $s({client:t,documents:r,receipts:m=[],onReviewed:l}){var O;const[v,_]=h.useState(""),[b,x]=h.useState("All"),[c,o]=h.useState(null),[N,d]=h.useState(""),[u,i]=h.useState(null),{toast:s}=W(),a=async(f,w)=>{var M;i(f.id);try{const R=await S.functions.invoke("staffReviewDocument",{document_id:f.id,status:w,notes:N||f.notes||""}),j=((M=(R==null?void 0:R.data)??R)==null?void 0:M.document)||{...f,status:w,notes:N||f.notes};l==null||l(j),o(null),d(""),s({title:`Marked as ${w}`})}catch(R){s({title:"Failed to update",description:R.message,variant:"destructive"})}finally{i(null)}},n=t.selfie_with_id_url||((O=r.find(f=>f.file_name==="selfie"))==null?void 0:O.file_url),g=r.filter(f=>{const w=!v||(f.file_name||"").toLowerCase().includes(v.toLowerCase())||(f.notes||"").toLowerCase().includes(v.toLowerCase()),M=b==="All"||f.category===b;return w&&M}),y=xe.filter(f=>g.some(w=>w.category===f)).map(f=>({category:f,items:g.filter(w=>w.category===f)})),$=g.filter(f=>!xe.includes(f.category));return $.length&&y.push({category:"Other",items:$}),e.jsxs("div",{className:"space-y-5",children:[n&&e.jsxs("div",{className:"bg-white border border-gray-100 rounded-2xl p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("p",{className:"text-xs text-gray-500 font-medium",children:"Selfie with ID"}),e.jsx("a",{href:n,target:"_blank",rel:"noreferrer",className:"text-xs text-blue-600 font-medium",children:"Open"})]}),e.jsx("img",{src:n,alt:"Selfie with ID",className:"w-full max-w-[240px] rounded-xl border border-gray-100"})]}),m.length>0&&e.jsxs("div",{className:"bg-white border border-gray-100 rounded-2xl p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h2",{className:"text-sm font-semibold text-gray-900",children:"Receipts"}),e.jsxs("span",{className:"text-xs text-gray-400",children:[m.length," total"]})]}),e.jsx("div",{className:"space-y-2",children:m.map(f=>e.jsxs("div",{className:"flex items-center gap-3 py-2 border-b border-gray-50 last:border-0",children:[f.file_url?Me(f.file_url)?e.jsx("a",{href:f.file_url,target:"_blank",rel:"noreferrer",className:"shrink-0 w-11 h-11 rounded-lg overflow-hidden border border-gray-100","aria-label":`Open ${f.supplier||"receipt"}`,children:e.jsx("img",{src:f.file_url,alt:f.supplier||"Receipt",className:"w-full h-full object-cover"})}):e.jsx("a",{href:f.file_url,target:"_blank",rel:"noreferrer",className:"shrink-0 w-11 h-11 rounded-lg bg-gray-50 flex items-center justify-center","aria-label":`Open ${f.supplier||"receipt"}`,children:e.jsx(ge,{size:16,className:"text-gray-400"})}):e.jsx("div",{className:"w-11 h-11 rounded-lg bg-gray-50 flex items-center justify-center shrink-0",children:e.jsx(ge,{size:16,className:"text-gray-300"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-gray-800 truncate",children:f.supplier||f.description||"Receipt"}),e.jsxs("p",{className:"text-xs text-gray-400",children:[f.receipt_date?z(f.receipt_date).format("D MMM YYYY"):"â",f.category?` ⢠${f.category}`:"",f.status?` ⢠${f.status}`:""]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[f.amount!=null&&e.jsxs("span",{className:"text-sm font-semibold text-gray-900 tabular-nums",children:["$",(f.amount||0).toFixed(2)]}),f.file_url&&e.jsx("a",{href:f.file_url,target:"_blank",rel:"noreferrer",className:"text-xs text-blue-600 font-medium",children:"Open"})]})]},f.id))})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(bt,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"}),e.jsx(ne,{value:v,onChange:f=>_(f.target.value),placeholder:"Search documentsâ¦",className:"pl-9"})]}),e.jsxs(Bt,{value:b,onValueChange:x,children:[e.jsxs(Jt,{className:"w-full",children:[e.jsx(Ut,{size:14,className:"mr-2 text-gray-400"}),e.jsx(Vt,{placeholder:"Category"})]}),e.jsxs(Ht,{children:[e.jsx(Oe,{value:"All",children:"All categories"}),xe.map(f=>e.jsx(Oe,{value:f,children:f},f))]})]})]}),g.length===0?e.jsxs("div",{className:"flex flex-col items-center gap-3 py-12 text-center",children:[e.jsx("div",{className:"w-14 h-14 roun
16ded-full bg-gray-100 flex items-center justify-center",children:e.jsx(G,{size:26,className:"text-gray-400"})}),e.jsx("p",{className:"text-sm font-semibold text-gray-800",children:"No documents"}),e.jsx("p",{className:"text-xs text-gray-500 max-w-xs",children:"This client hasn't uploaded any documents in this category yet."})]}):y.map(f=>e.jsxs("div",{className:"bg-white border border-gray-100 rounded-2xl p-4",children:[e.jsxs("h3",{className:"text-sm font-semibold text-gray-800 mb-3",children:[f.category," ",e.jsxs("span",{className:"text-gray-400 font-normal",children:["(",f.items.length,")"]})]}),e.jsx("div",{className:"space-y-2",children:f.items.map(w=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3 py-2 border-b border-gray-50 last:border-0",children:[w.file_url?Me(w.file_url)?e.jsx("a",{href:w.file_url,target:"_blank",rel:"noreferrer",className:"shrink-0 w-11 h-11 rounded-lg overflow-hidden border border-gray-100","aria-label":`Open ${w.file_name||"document"}`,children:e.jsx("img",{src:w.file_url,alt:w.file_name||"Document",className:"w-full h-full object-cover"})}):e.jsx("a",{href:w.file_url,target:"_blank",rel:"noreferrer",className:"shrink-0 w-11 h-11 rounded-lg bg-gray-50 flex items-center justify-center","aria-label":`Open ${w.file_name||"document"}`,children:e.jsx(G,{size:16,className:"text-gray-400"})}):e.jsx("div",{className:"w-11 h-11 rounded-lg bg-gray-50 flex items-center justify-center shrink-0",children:e.jsx(G,{size:16,className:"text-gray-300"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-gray-800 truncate",children:w.file_name||"Document"}),e.jsxs("p",{className:"text-xs text-gray-400",children:[w.upload_date?z(w.upload_date).format("D MMM YYYY"):"â",w.uploaded_by?` ⢠${w.uploaded_by}`:"",w.reviewed_by?` ⢠Reviewed by ${w.reviewed_by}`:""]}),w.notes&&e.jsx("p",{className:"text-xs text-gray-500 mt-0.5 truncate",children:w.notes})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[w.status&&e.jsx("span",{className:`text-[11px] px-2 py-0.5 rounded-full font-medium ${Ds[w.status]||"bg-gray-100 text-gray-600"}`,children:w.status}),e.jsxs("button",{onClick:()=>{o(c===w.id?null:w.id),d("")},className:"text-[11px] font-semibold text-slate-600 bg-slate-100 rounded-full px-2.5 py-1 flex items-center gap-1",style:{minHeight:28},children:["Review ",c===w.id?e.jsx(yt,{size:12}):e.jsx(Ee,{size:12})]})]})]}),c===w.id&&e.jsxs("div",{className:"mt-2 ml-14 mb-2 bg-slate-50 rounded-xl p-3 space-y-2",children:[e.jsx("textarea",{value:N,onChange:M=>d(M.target.value),placeholder:"Add a note (optional â shown to client)â¦",className:"w-full text-xs border border-gray-200 rounded-lg px-2.5 py-2 resize-none bg-white text-gray-800",rows:2}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:()=>a(w,"Approved"),disabled:u===w.id,className:"flex-1 flex items-center justify-center gap-1 text-xs font-semibold text-emerald-700 bg-emerald-100 rounded-lg py-2 disabled:opacity-50",style:{minHeight:34},children:[e.jsx(Be,{size:14})," Approve"]}),e.jsxs("button",{onClick:()=>a(w,"Needs Resubmission"),disabled:u===w.id,className:"flex-1 flex items-center justify-center gap-1 text-xs font-semibold text-orange-700 bg-orange-100 rounded-lg py-2 disabled:opacity-50",style:{minHeight:34},children:[e.jsx(Gt,{size:14})," Resubmit"]}),e.jsxs("button",{onClick:()=>a(w,"Rejected"),disabled:u===w.id,className:"flex-1 flex items-center justify-center gap-1 text-xs font-semibold text-rose-700 bg-rose-100 rounded-lg py-2 disabled:opacity-50",style:{minHeight:34},children:[e.jsx(He,{size:14})," Reject"]})]})]})]},w.id))})]},f.category))]})}function zs({receipts:t,diary:r,trips:m,income:l,bas:v}){const _=t.reduce((g,y)=>g+(y.amount||0),0),b=t.reduce((g,y)=>g+(y.gst||0),0),x=r.reduce((g,y)=>g+(y.amount||0),0),c=m.filter(g=>g.trip_type==="Business").reduce((g,y)=>g+(y.distance||0),0),o=l.reduce((g,y)=>g+(y.amount||0),0);l.reduce((g,y)=>g+(y.gst_collected||0),0);const N=v.filter(g=>g.txn_type==="expense").reduce((g,y)=>g+(y.amount||0),0),d=_+x+N,u=o-d,i={};t.forEach(g=>{const y=g.category||"Uncategorised";i[y]=(i[y]||0)+(g.amount||0)}),r.forEach(g=>{const y=g.category||"Other";i[y]=(i[y]||0)+(g.amount||0)});const s={};l.forEach(g=>{var $;const y=g.income_date?z(g.income_date).format("MMM YYYY"):null;y&&(s[y]={...s[y]||{income:0,expense:0},income:((($=s[y])==null?void 0:$.income)||0)+(g.amount||0)})}),t.forEach(g=>{var $;const y=g.receipt_date?z(g.receipt_date).format("MMM YYYY"):null;y&&(s[y]={...s[y]||{income:0,expense:0}
16,expense:((($=s[y])==null?void 0:$.expense)||0)+(g.amount||0)})});const a=Object.entries(s).sort((g,y)=>z(g[0],"MMM YYYY").valueOf()-z(y[0],"MMM YYYY").valueOf()),n=Math.max(1,...Object.values(i));return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:`rounded-2xl p-5 text-white ${u>=0?"bg-gradient-to-r from-emerald-600 to-teal-500":"bg-gradient-to-r from-rose-600 to-rose-500"}`,children:[e.jsx("p",{className:"text-white/80 text-xs",children:"Estimated net position"}),e.jsxs("p",{className:"text-3xl font-bold mt-1",children:[u>=0?"+":"","$",u.toFixed(2)]}),e.jsxs("p",{className:"text-white/80 text-xs mt-1",children:[o.toFixed(0)," income â ",d.toFixed(0)," expenses"]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(H,{icon:Ve,label:"Total income",value:`$${o.toFixed(2)}`,sub:`${l.length} entries`,color:"text-emerald-700"}),e.jsx(H,{icon:Kt,label:"Total expenses",value:`$${d.toFixed(2)}`,sub:`${t.length+r.length+v.length} entries`,color:"text-rose-700"}),e.jsx(H,{icon:ge,label:"Receipts",value:`$${_.toFixed(2)}`,sub:`GST $${b.toFixed(2)}`,color:"text-blue-700"}),e.jsx(H,{icon:Wt,label:"BAS expenses",value:`$${N.toFixed(2)}`,sub:`${v.filter(g=>g.txn_type==="expense").length} txn`,color:"text-emerald-700"}),e.jsx(H,{icon:jt,label:"Business km",value:c.toFixed(0),sub:`${m.length} trips`,color:"text-indigo-700"}),e.jsx(H,{icon:vt,label:"Diary",value:`$${x.toFixed(2)}`,sub:`${r.length} entries`,color:"text-purple-700"})]}),Object.keys(i).length>0&&e.jsxs("div",{className:"bg-white border border-gray-100 rounded-2xl p-5",children:[e.jsx("h2",{className:"text-sm font-semibold text-gray-800 mb-3",children:"Expense breakdown by category"}),e.jsx("div",{className:"space-y-2.5",children:Object.entries(i).sort((g,y)=>y[1]-g[1]).map(([g,y])=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[e.jsx("span",{className:"text-gray-600",children:g}),e.jsxs("span",{className:"font-semibold text-gray-900",children:["$",y.toFixed(2)]})]}),e.jsx("div",{className:"h-1.5 bg-gray-100 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-blue-500 rounded-full",style:{width:`${y/n*100}%`}})})]},g))})]}),a.length>0&&e.jsxs("div",{className:"bg-white border border-gray-100 rounded-2xl p-5",children:[e.jsx("h2",{className:"text-sm font-semibold text-gray-800 mb-3",children:"Monthly income vs expenses"}),e.jsx("div",{className:"space-y-2",children:a.map(([g,y])=>{const $=Math.max(1,...a.flatMap(O=>[Math.abs(O[1].income),Math.abs(O[1].expense)]));return e.jsxs("div",{className:"text-xs",children:[e.jsxs("div",{className:"flex justify-between mb-1",children:[e.jsx("span",{className:"text-gray-600 font-medium",children:g}),e.jsxs("span",{className:y.income-y.expense>=0?"text-emerald-700 font-semibold":"text-rose-700 font-semibold",children:[y.income-y.expense>=0?"+":"","$",(y.income-y.expense).toFixed(0)]})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("div",{className:"h-1.5 bg-gray-100 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-emerald-500 rounded-full",style:{width:`${y.income/$*100}%`}})}),e.jsx("div",{className:"h-1.5 bg-gray-100 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-rose-400 rounded-full",style:{width:`${y.expense/$*100}%`}})})]})]},g)})})]})]})}function H({icon:t,label:r,value:m,sub:l,color:v}){return e.jsxs("div",{className:"bg-white border border-gray-100 rounded-2xl p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx(t,{size:16,className:v}),e.jsx("span",{className:"text-xs text-gray-500 font-medium",children:r})]}),e.jsx("p",{className:"text-lg font-bold text-gray-900",children:m}),l&&e.jsx("p",{className:"text-xs text-gray-400 mt-0.5",children:l})]})}function Ae(t){if(!t)return"â";const r=new Date(t);return isNaN(r)?"â":r.toLocaleDateString("en-AU",{day:"numeric",month:"short",year:"numeric"})}function U({label:t,value:r}){return e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-gray-400 leading-none",children:t}),e.jsx("p",{className:"text-gray-600 font-medium truncate",children:r})]})}function Ms({client:t}){const[r,m]=h.useState([]),[l,v]=h.useState(!0),[_,b]=h.useState(!1),[x,c]=h.useState(null),[o,N]=h.useState(""),[d,u]=h.useState(!1),[i,s]=h.useState(null),{toast:a}=W(),n=async()=>{var j;v(!0);try{const k=await S.functions.invoke("manageJobs",{action:"listForClient",client_id:t.id});m(((j=k==null?void 0:k.data)==null?void 0:j.jobs)||[])}catch(k){a({title:"Could not load jobs",description:k.message,variant:"destructive"})}finally{v(!1)}};h.useEffect(()=>{n()},[t.id]);const g=j=>{const k=/FY(\d{4})/i.exec(j||"");return k?`FY${parseInt(k[1],10)+1}`:"FY2027"},y=j=>{c(j),N(g(j.financial_year))},$=async()=>
16{if(x){u(!0);try{await S.functions.invoke("manageJobs",{action:"duplicate",job_id:x.id,financial_year:o}),a({title:"Job duplicated"}),c(null),n()}catch(j){a({title:"Could not duplicate",description:j.message,variant:"destructive"})}finally{u(!1)}}},O=async j=>{s(j.id);try{await S.functions.invoke("manageJobs",{action:"archive",job_ids:[j.id]}),m(k=>k.map(D=>D.id===j.id?{...D,archived:!0}:D)),a({title:"Job archived"})}catch(k){a({title:"Failed",description:k.message,variant:"destructive"})}finally{s(null)}},f=async j=>{s(j.id);try{await S.functions.invoke("manageJobs",{action:"restore",job_id:j.id}),m(k=>k.map(D=>D.id===j.id?{...D,archived:!1}:D)),a({title:"Job restored"})}catch(k){a({title:"Failed",description:k.message,variant:"destructive"})}finally{s(null)}},w=r.filter(j=>!j.archived),M=r.filter(j=>j.archived),R=({j})=>e.jsxs("div",{className:`bg-white border border-gray-100 rounded-xl p-3.5 shadow-sm ${j.archived?"opacity-60":""}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(Z,{to:`/staff/jobs/${j.id}`,className:"text-sm font-bold text-gray-900 hover:text-emerald-700 truncate block",children:j.title}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-1",children:[e.jsx(ae,{status:j.status,small:!0}),j.review_required&&e.jsx("span",{className:"text-[10px] font-medium px-2 py-0.5 rounded-full bg-amber-100 text-amber-700",children:"Review type"}),j.archived&&e.jsx("span",{className:"text-[10px] font-medium px-2 py-0.5 rounded-full bg-slate-200 text-slate-600",children:"Archived"})]})]}),e.jsxs(Z,{to:`/staff/jobs/${j.id}`,className:"shrink-0 flex items-center gap-1 text-xs font-semibold text-emerald-700 hover:underline",children:["Open ",e.jsx(Nt,{size:12})]})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-x-3 gap-y-1 mt-2.5 text-[11px]",children:[e.jsx(U,{label:"Financial Year",value:j.financial_year||j.reporting_period||"â"}),e.jsx(U,{label:"Assigned",value:j.assigned_accountant||"â"}),e.jsx(U,{label:"Priority",value:j.priority||"â"}),e.jsx(U,{label:"Office",value:j.office_name||"â"}),e.jsx(U,{label:"Created",value:Ae(j.created_date)}),e.jsx(U,{label:"Completed",value:j.completed_at?Ae(j.completed_at):"â"})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsxs(F,{variant:"outline",size:"sm",onClick:()=>y(j),className:"h-7 text-xs",children:[e.jsx(wt,{size:12})," Duplicate"]}),j.archived?e.jsxs(F,{variant:"ghost",size:"sm",onClick:()=>f(j),disabled:i===j.id,className:"h-7 text-xs text-gray-500",children:[e.jsx(se,{size:12})," Restore"]}):e.jsxs(F,{variant:"ghost",size:"sm",onClick:()=>O(j),disabled:i===j.id,className:"h-7 text-xs text-gray-500",children:[e.jsx(qe,{size:12})," Archive"]})]})]});return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-sm text-gray-500",children:[r.length," job(s) â full history"]}),e.jsxs(F,{onClick:()=>b(!0),disabled:t.archived,className:"bg-emerald-600 hover:bg-emerald-700 h-8 text-xs",children:[e.jsx(Q,{size:14})," New Job"]})]}),t.archived&&e.jsx("div",{className:"text-xs bg-slate-100 text-slate-600 rounded-lg px-3 py-2",children:"This client is archived. Restore the client to create new jobs â existing job history is preserved below."}),l?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(T,{size:20,className:"text-gray-400 animate-spin"})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[w.map(j=>e.jsx(R,{j},j.id)),w.length===0&&M.length===0&&e.jsx("p",{className:"text-center text-sm text-gray-400 py-8",children:"No jobs yet â create the first engagement for this client."})]}),M.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-gray-400 uppercase tracking-wide mt-4 mb-2",children:"Archived / past"}),e.jsx("div",{className:"space-y-2",children:M.map(j=>e.jsx(R,{j},j.id))})]})]}),e.jsx(Ge,{open:_,onOpenChange:b,onCreated:n,presetClientId:t.id}),e.jsx(fe,{open:!!x,onOpenChange:j=>!j&&c(null),children:e.jsxs(be,{className:"max-w-sm",children:[e.jsx(ye,{children:e.jsx(je,{children:"Duplicate job"})}),e.jsxs("p",{className:"text-sm text-gray-600",children:["Create a new ",x==null?void 0:x.job_type," for a new period. Status starts at New."]}),e.jsxs("div",{children:[e.jsx(P,{className:"text-xs text-gray-500",children:"Financial year / period"}),e.jsx(ne,{value:o,onChange:j=>N(j.target.value),className:"mt-1"})]}),e.jsxs(Je,{children:[e.jsx(F,{variant:"outline",onClick:()=>c(null),disabled:d,children:"Cancel"}),e.jsx(F,{onClick:$,disabled:d,className:"bg-emerald-600 hover:bg-emerald-700",children:d?e.jsx(T,{size:16,className:"animate-spin"}):"Duplicate"})]})]})})]})}function Ts({client:t}){var i,s;const{toast:r}=W(),[m,l]=h.useState([]),[v,_]=h.useState(!0),[b,x]=h.useState(!1),[c,o]=h.useState(!1),N=async()=>{var a;_(!0);try{const n=await S.functions.invoke("manageOnboarding",{action:"list_for_client",client_id:t.id});l(((a=n==null?void 0:n.data)==null?void 0:a.instances)||[])}catch{l([])}_(!1)};h.useEffect(()=>{N()},[t.id]);const d=async a=>{x(!0);try{await S.functions.invoke("manageOnboarding",{action:"send_invitation",instance_id:a.id}),r({title:"Invitation sent"}),N()}finally{x(!1)}},u=m.find(a=>a.status!=="completed"&&a.status!=="expired");return v?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(T,{className:"w-6 h-6 text-gray-300 animate-spin"})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900",children:"Onboarding"}),!u&&e.jsxs(F,{size:"sm",onClick:()=>o(!0),className:"bg-emerald-600 hover:bg-emerald-700",children:[e.jsx(ce,{size:14})," Start onboarding"]})]}),!u&&m.length===0&&e.jsxs("div",{className:"text-center py-10 bg-gray-50 rounded-2xl border border-dashed border-gray-200",children:[e.jsx(ce,{size:26,className:"mx-auto text-gray-300"}),e.jsx("p",{className:"text-sm text-gray-500 mt-2",children:"No onboarding started for this client yet."}),e.jsxs(F,{size:"sm",onClick:()=>o(!0),className:"mt-3 bg-emerald-600 hover:bg-emerald-700",children:[e.jsx(ce,{size:14})," Start onboarding"]})]}),u&&e.jsxs("div",{className:"bg-white border border-gray-100 rounded-2xl p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900",children:u.template_name}),e.jsxs("p",{className:"text-xs text-gray-400",children:[u.client_type," · ",((i=u.services)==null?void 0:i.join(", "))||"no services"]})]}),e.jsx("span",{className:`text-xs font-medium px-2 py-1 rounded-full ${u.status==="completed"?"bg-emerald-100 text-emerald-700":u.status==="invited"?"bg-blue-100 text-blue-700":"bg-amber-100 text-amber-700"}`,children:u.status})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between text-xs text-gray-500 mb-1",children:[e.jsx("span",{children:"Progress"}),e.jsxs("span",{className:"font-semibold text-emerald-600",children:[u.progress||0,"%"]})]}),e.jsx("div",{className:"h-2 bg-gray-100 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-emerald-500",style:{width:`${u.progress||0}%`}})})]}),e.jsx("div",{className:"grid grid-cols-2 gap-1.5",children:(((s=u.template_snapshot)==null?void 0:s.steps)||[]).map(a=>{var g;const n=(g=(u.step_states||[]).find(y=>y.step_id===a.id))==null?void 0:g.status;return e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-gray-600",children:[n==="completed"?e.jsx(Be,{size:13,className:"text-emerald-500"}):e.jsx(Xt,{size:13,className:"text-gray-300"})," ",a.title]},a.id)})}),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsxs(F,{size:"sm",variant:"outline",disabled:b,onClick:()=>d(u),children:[e.jsx(Ne,{size:13})," Resend invitation"]}),e.jsx("span",{className:"text-xs text-gray-400",children:u.invitation_sent_at?`Invited ${new Date(u.invitation_sent_at).toLocaleDateString()}`:"Not yet invited"})]})]}),m.length>0&&e.jsxs("div",{className:"bg-white border border-gray-100 rounded-2xl p-4",children:[e.jsxs("p",{className:"text-xs font-semibold text-gray-500 mb-2 flex items-center gap-1.5",children:[e.jsx(G,{size:13})," History"]}),e.jsx("div",{className:"space-y-2",children:m.map(a=>e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-gray-600",children:a.template_name}),e.jsxs("span",{className:"text-gray-400 flex items-center gap-1",children:[e.jsx(Ue,{size:12})," ",new Date(a.created_date).toLocaleDateString()," · ",a.progress||0,"%"]})]},a.id))})]}),e.jsx(It,{client:t,open:c,onOpenChange:o,onDone:N})]})}const ue=["ID Documents","AML Documents","Bank Statements","Tax Receipts","Work Related Expenses","Rental Property Documents","Business Documents","Logbook Records","Tax Returns","Other"];function Os({open:t,onOpenChange:r,onSubmit:m,clientName:l}){const[v,_]=h.useState(ue[0]),[b,x]=h.useState(""),[c,o]=h.useState(!1),N=async()=>{o(!0);try{await m({category:v,message:b}),r(!1),x(""),_(ue[0])}finally{o(!1)}};return e.jsx(fe,{open:t,onOpenChange:r,children:e.jsxs(be,{children:[e.jsxs(ye,{children:[e.jsxs(je,{children:["Request documents from ",l||"client"]}),e.jsx(Ct,{children:"The client will receive an in-app notification and email asking them to upload the requested documents."})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(P,{className:"mb-1.5 block",children:"Document type"}
16),e.jsx("select",{value:v,onChange:d=>_(d.target.value),className:"h-9 w-full text-sm border border-input bg-card rounded-md px-3 py-2",children:ue.map(d=>e.jsx("option",{value:d,children:d},d))})]}),e.jsxs("div",{children:[e.jsx(P,{className:"mb-1.5 block",children:"Message (optional)"}),e.jsx("textarea",{value:b,onChange:d=>x(d.target.value),rows:4,placeholder:"Add any specific instructions for the client...",className:"w-full text-sm border border-input bg-card rounded-md px-3 py-2 resize-none"})]})]}),e.jsxs(Je,{children:[e.jsx(F,{variant:"ghost",onClick:()=>r(!1),disabled:c,children:"Cancel"}),e.jsx(F,{onClick:N,disabled:c,children:c?"Sending...":"Send request"})]})]})})}function wa(){const{clientId:t}=_t(),r=Le(),{toast:m}=W(),[l]=kt(),v=l.get("tab"),[_,b]=h.useState({loading:!0,access:!1}),[x,c]=h.useState(null),[o,N]=h.useState({}),[d,u]=h.useState(null),i={details:"overview",sign:"signatures",summary:"summary"},[s,a]=h.useState(i[v]||v||"overview"),[n,g]=h.useState(!1),[y,$]=h.useState(!1),[O,f]=h.useState(!1),[w,M]=h.useState(!1),[R,j]=h.useState(!1),[k,D]=h.useState(!1),[B,q]=h.useState(!1),[we,We]=h.useState(!1),Xe=(p,C)=>{p==="request_documents"?f(!0):p==="request_signature"?(D(!0),a("signatures")):p==="generate_tax_summary"||p==="compare_fy"?a("summary"):p==="open_job"?r(C!=null&&C.job_id?`/staff/jobs/${C.job_id}`:"/staff/workflow"):m({title:"Finley suggestion noted"})},Ze=[{key:"overview",label:"Overview"},{key:"jobs",label:"Jobs",count:(o.jobs||[]).filter(p=>!p.archived&&p.status!=="Completed").length},{key:"documents",label:"Documents",count:(o.documents||[]).length},{key:"signatures",label:"Signatures",count:(o.signatures||[]).filter(p=>p.status==="pending").length},{key:"forms",label:"Forms",count:(o.forms||[]).length},{key:"messages",label:"Messages",count:(o.messages||[]).filter(p=>!p.is_read&&p.sender_role==="client").length},{key:"bookings",label:"Bookings",count:(o.appointments||[]).filter(p=>p.status!=="Cancelled"&&p.appointment_date>=new Date().toISOString().split("T")[0]).length},{key:"summary",label:"Tax Summary"},{key:"activity",label:"Activity"},{key:"onboarding",label:"Onboarding"},{key:"notes",label:"Notes"}],ie=async()=>{b({loading:!0,access:!1});try{const p=await S.functions.invoke("staffClientData",{client_id:t}),C=(p==null?void 0:p.data)??p;c(C.client),N({receipts:C.receipts||[],documents:C.documents||[],diary:C.diary||[],trips:C.trips||[],income:C.income||[],bas:C.bas||[],jobs:C.jobs||[],messages:C.messages||[],appointments:C.appointments||[],signatures:C.signatures||[],forms:C.forms||[],tasks:C.tasks||[]}),b({loading:!1,access:!0})}catch{b({loading:!1,access:!1})}};if(h.useEffect(()=>{ie(),S.auth.me().then(u).catch(()=>{})},[t]),_.loading)return e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(T,{className:"w-7 h-7 text-gray-400 animate-spin"})});if(!_.access)return e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 px-6 text-center",children:[e.jsx("div",{className:"w-14 h-14 bg-gray-100 rounded-full flex items-center justify-center mb-4",children:e.jsx(Pe,{className:"text-gray-400",size:24})}),e.jsx("h2",{className:"text-lg font-bold text-gray-900",children:"No access"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"This client hasn't shared their records with you yet."}),e.jsx("button",{onClick:()=>r("/staff/clients"),className:"mt-6 px-5 py-2.5 bg-gray-900 text-white rounded-xl text-sm font-medium",children:"Back to clients"})]});const X=p=>c(C=>({...C,...p})),le=p=>{X(p),N(C=>({...C}))},oe=(o.jobs||[]).filter(p=>!p.archived&&p.status!=="Completed"),Qe=(o.jobs||[]).filter(p=>p.status==="Completed"),et=(o.messages||[]).filter(p=>!p.is_read&&p.sender_role==="client"),tt=(o.documents||[]).filter(p=>p.status==="Pending Review"),st=(o.signatures||[]).filter(p=>p.status==="pending"),at=oe.reduce((p,C)=>p+Math.max(0,(C.amount_invoiced||0)-(C.amount_paid||0)),0),J=oe[0],_e=J?`${J.financial_year||J.reporting_period||""} ${J.title||J.job_type} â ${J.status}`.trim():null,rt={activeJobs:oe.length,completedJobs:Qe.length,outstandingDocs:tt.length,pendingSigs:st.length,unreadMessages:et.length,balance:at},ke=p=>{p==="edit"?g(!0):p==="newJob"?$(!0):p==="requestDocs"?f(!0):p==="requestSig"?(D(!0),a("signatures")):p==="message"?a("messages"):p==="book"&&r("/staff/appointments")},nt=p=>{p==="requestVerification"?it():p==="requestDocs"?f(!0):p==="requestSig"?(D(!0),a("signatures")):p==="message"?a("messages"):p==="book"?r("/staff/appointments"):p==="archive"?M(!0):p==="restore"&&Ce()},it=async()=>{q(!0);try{await S.functions.invoke("updateClientProfile",{client_id:x.id,patch:{status:"Verification Pending"}});try{await S.entities.Notification.create({target_email:(x.email||"").toLowerCase().trim(),actor_name:(d==null?void 0:d.full_name)||(d==null?void 0:d.email)||"Your accountant",type:"client_message",audience:"client",title:"Verification requested",body:"Your accountant has requested you complete identity verification.",client_id:x.id,is_read:!1})}catch{}X({status:"Verification Pending"}),m({title:"Verification request sent"})}catch(p){m({variant:"destructive",title:"Could not send request",description:p.message})}finally{q(!1)}},lt=async()=>{j(!0);try{await S.functions.invoke("updateClientProfile",{client_id:x.id,patch:{archived:!0,archived_at:new Date().toISOString()}}),X({archived:!0,archived_at:new Date().toISOString()}),M(!1),m({title:"Client archived"})}catch(p){m({variant:"destructive",title:"Could not archive",description:p.message})}finally{j(!1)}},Ce=async()=>{try{await S.functions.invoke("updateClientProfile",{client_id:x.id,patch:{archived:!1,archived_at:null}}),X({archived:!1,archived_at:null}),m({title:"Client restored"})}catch(p){m({variant:"destructive",title:"Could not restore",description:p.message})}},ot=async({category:p,message:C})=>{try{await S.functions.invoke("updateClientProfile",{client_id:x.id,patch:{status:"Documents Requested"}});try{await S.entities.DocumentRequest.create({client_id:x.id,client_email:x.email,client_name:x.full_name,accountant_email:(d==null?void 0:d.email)||"",accountant_name:(d==null?void 0:d.full_name)||"",company_id:x.company_id||"",category:p,message:C||"",status:"pending"})}catch{}try{await S.entities.Notification.create({target_email:(x.email||"").toLowerCase().trim(),actor_name:(d==null?void 0:d.full_name)||(d==null?void 0:d.email)||"Your accountant",type:"document_requested",audie
16nce:"client",title:"Documents requested",body:`Please upload: ${p}.${C?` ${C}`:""}`,client_id:x.id,is_read:!1})}catch{}try{const L=`${window.location.origin}/portal/documents`,Se=(d==null?void 0:d.full_name)||(d==null?void 0:d.email)||"Your accountant",ct=C?`<p style="margin:0 0 12px">${C.replace(/</g,"<")}</p>`:"",dt=`<div style="font-family:Arial,sans-serif;max-width:560px;margin:0 auto;color:#1f2937"><div style="background:linear-gradient(90deg,#1d4ed8,#06b6d4);padding:24px;border-radius:12px 12px 0 0;text-align:center"><h1 style="color:#fff;margin:0;font-size:22px">TaxEase360</h1><p style="color:#dbeafe;margin:4px 0 0;font-size:13px">Documents requested</p></div><div style="padding:24px;border:1px solid #e5e7eb;border-top:none;border-radius:0 0 12px 12px"><p style="margin:0 0 12px">Hi ${x.full_name||""},</p><p style="margin:0 0 12px"><strong>${Se}</strong> has requested you upload <strong>${p}</strong>.</p>${ct}<a href="${L}" style="display:inline-block;background:#1d4ed8;color:#fff;text-decoration:none;padding:14px 28px;border-radius:10px;font-weight:bold;font-size:15px">Upload Documents</a><p style="margin:16px 0 0;font-size:12px;color:#9ca3af">You received this notification from TaxEase360.</p></div></div>`;await S.functions.invoke("sendExternalEmail",{to:x.email,subject:`Documents requested: ${p}`,from_name:Se,html:dt})}catch{}X({status:"Documents Requested"}),m({title:"Document request sent"})}catch(L){m({variant:"destructive",title:"Could not send request",description:L.message})}};return e.jsxs("div",{className:"pb-24",children:[e.jsxs("button",{onClick:()=>r("/staff/clients"),className:"flex items-center gap-1 text-sm text-gray-500 hover:text-gray-800 px-4 pt-3",children:[e.jsx(es,{size:18})," Clients"]}),x.archived&&e.jsxs("div",{className:"mx-4 mt-3 flex items-center justify-between gap-3 rounded-xl border border-amber-200 bg-amber-50 px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(se,{size:18,className:"text-amber-600 shrink-0"}),e.jsx("span",{className:"font-semibold text-amber-800",children:"This client is archived"}),e.jsx("span",{className:"text-amber-600 hidden sm:inline",children:"â they're hidden from the active workflow board."})]}),e.jsxs("button",{onClick:Ce,className:"inline-flex items-center gap-1.5 h-8 px-4 rounded-lg text-sm font-semibold text-white bg-amber-600 hover:bg-amber-700 transition-colors shrink-0",children:[e.jsx(se,{size:15})," Unarchive"]})]}),e.jsx(ms,{client:x,activeJob:_e?{label:_e}:null,tabs:Ze,tab:s,setTab:p=>{D(!1),a(p)},onAction:ke,onMore:nt}),e.jsxs("div",{className:`px-4 pt-4 space-y-4 transition-all ${we?"lg:pr-[420px]":""}`,children:[e.jsx(us,{kpis:rt,onTab:a}),s==="overview"&&e.jsx(fs,{client:x,documents:o.documents,jobs:o.jobs,tasks:o.tasks,messages:o.messages,appointments:o.appointments,signatures:o.signatures,onTab:a,onAction:ke,onClientUpdated:le}),s==="jobs"&&e.jsx(Ms,{client:x}),s==="documents"&&e.jsx($s,{client:x,documents:o.documents,receipts:o.receipts,onReviewed:p=>N(C=>({...C,documents:C.documents.map(L=>L.id===p.id?{...L,...p}:L)}))}),s==="signatures"&&e.jsx(Cs,{client:x,signatures:o.signatures,autoCompose:k,onChanged:ie},k?"compose":"list"),s==="forms"&&e.jsx(vs,{forms:o.forms,onSend:()=>r("/staff/forms")}),s==="messages"&&e.jsx(bs,{client:x,messages:o.messages,onSent:p=>N(C=>({...C,messages:[...C.messages,p]}))}),s==="bookings"&&e.jsx(ys,{client:x,appointments:o.appointments,onBook:()=>r("/staff/appointments")}),s==="summary"&&e.jsx(zs,{receipts:o.receipts,diary:o.diary,trips:o.trips,income:o.income,bas:o.bas}),s==="activity"&&e.jsxs("div",{className:"bg-white dark:bg-gray-900 border border-gray-100 dark:border-gray-800 rounded-xl p-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100 mb-3",children:"Activity Timeline"}),e.jsx(Ke,{client:x,documents:o.documents,jobs:o.jobs,signatures:o.signatures,messages:o.messages,appointments:o.appointments,onTab:a,limit:100})]}),s==="onboarding"&&e.jsx(Ts,{client:x}),s==="notes"&&e.jsx(Ss,{client:x,onClientUpdated:le})]}),e.jsx(fe,{open:n,onOpenChange:g,children:e.jsxs(be,{className:"bg-card border-border text-foreground max-w-lg max-h-[90vh] overflow-y-auto",children:[e.jsx(ye,{children:e.jsxs(je,{children:["Edit client â ",x.full_name]})}),e.jsx(Zt,{client:x,role:"accountant",onUpdated:p=>{le(p),g(!1)},onCancel:()=>g(!1)})]})}),e.jsx(Ge,{open:y,onOpenChange:$,onCreated:()=>{$(!1),ie()},presetClientId:x.id}),e.jsx(Os,{open:O,onOpenChange:f,onSubmit:ot,clientName:x.full_name}),e.jsx(Lt,{client:x,open:w,onOpenChange:M,onConfirm:lt,busy:R}),e.jsx(Qt,{open:we,onOpenChange:We,client:x,onAction:Xe})]})}
16export{wa 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.