PageSourceSearch

https://aicommand-free.web.app/assets/TasksPage-Diuv4EYs.js

js aicommand-free.web.app collected 2026-10-03 12:16:23 UTC 33,135 bytes, 1 lines download raw bytes

1import{j as e}from"./query-CkjDa6TK.js";import{u as he,a as x}from"./react-DkkCGPT4.js";import{u as We}from"./forms-xixe_uvK.js";import{r as Se,s as Ie,b9 as _e,b8 as ke,b6 as Be,bv as Ae,q as j,V as pe,au as Me,aA as re,w as ze,F as de,n as Fe,bV as Pe,E as ue,o as Re,I as Le,y as G,g as E,Z as Ce,aZ as Ue,af as K,z as J,ae as ne,an as ce,H as ge,a_ as fe,aj as me,h as He,A as qe,bf as be,W as je,ag as Oe,b7 as Ke,m as Ve,p as V,b4 as Ge,b3 as Je}from"./index-BYV5a2iT.js";import{a as Ze}from"./selectors-Spb6nPS1.js";import{P as Qe}from"./page-header-C-HmtJTI.js";import{D as Ye}from"./data-table-CO8YB0hO.js";import{M as Xe}from"./MemberSelect-BA-s8Rog.js";import{f as es}from"./confetti-CgkQzud_.js";import{K as ss}from"./kanban-RW6usBNd.js";import{L as ts}from"./list-DFhUKxrD.js";import{C as Te}from"./circle-CbOrgW9Q.js";import{G as rs}from"./grip-vertical-BIULX2-y.js";import{R as ns}from"./rotate-ccw-B03aJoRq.js";import{U as as}from"./user-nxWDl_hy.js";import"./dates-DnM1ZkOD.js";import"./differenceInDays-CA1b8ME3.js";import"./sliders-horizontal-CoHD_5Il.js";const is=[{label:"🔥 Member Win-Back",title:"Retention Win-Back: Check in on absent member",description:"Call or WhatsApp member to check in on their routine and offer a complimentary 15-min refresh session.",priority:"high",relatedType:"member"},{label:"🌟 7-Day Onboarding",title:"First-Week Check-in: Gym orientation & progress review",description:"Welcome new member, ask about soreness/routine, and introduce them to floor trainers.",priority:"medium",relatedType:"member"},{label:"💳 Payment Dues",title:"Payment Follow-up: Settle outstanding dues",description:"Contact member regarding pending invoice balance to avoid interruption in access.",priority:"high",relatedType:"invoice"},{label:"🏋️ PT Goal Review",title:"PT Assessment: Review workout plan & body measurements",description:"Evaluate strength progress, review PR logs, and calibrate weekly training target.",priority:"medium",relatedType:"member"},{label:"🔧 Equipment Maintenance",title:"Equipment Maintenance / Safety Check",description:"Inspect cable machines, dumbbells, and cardio equipment for regular servicing.",priority:"low",relatedType:"other"}];function Ds(){var ye;const{state:n,branchName:c,can:g}=Se(),S=he(),m=n.meta.activeBranchId,N=Ie(),U=_e(),I=ke(),k=((ye=n.organisation)==null?void 0:ye.name)||"GymLoop",[$,B]=x.useState(!1),[o,y]=x.useState(null),[h,w]=x.useState(null),[f,p]=x.useState(null),[M,C]=x.useState("kanban"),[a,W]=x.useState(""),[v,A]=x.useState("all"),[T,ae]=x.useState("all"),[H,t]=x.use
1State("all"),[z,F]=x.useState(null),[q,_]=x.useState(null),Q=Be({branchId:m!=="all"?m:void 0,pageSize:500}),D=Ae(!0),b=x.useMemo(()=>{var s;return((s=Q.data)==null?void 0:s.data)??[]},[Q.data]),ie=x.useMemo(()=>Ze(n,m),[n,m]),R=x.useMemo(()=>new Map(ie.map(s=>[s.memberId,s])),[ie]),oe=s=>D.userName(s),Y=s=>D.memberName(s),i=s=>{const r=(s.title||"").toLowerCase(),u=(s.description||"").toLowerCase();return r.includes("retention")||r.includes("win-back")||r.includes("absent")||u.includes("win-back")?"retention":r.includes("lead")||r.includes("trial")||s.relatedType==="lead"?"leads":r.includes("payment")||r.includes("due")||r.includes("invoice")||s.relatedType==="invoice"?"billing":r.includes("pt")||r.includes("trainer")||r.includes("workout")?"pt":"general"},X=x.useMemo(()=>{const s=b.filter(d=>d.status!=="done"&&d.status!=="completed"),r=s.filter(d=>i(d)==="retention"),u=s.filter(d=>d.priority==="high"),l=new Date().toISOString().slice(0,10),P=s.filter(d=>d.dueDate&&d.dueDate.slice(0,10)<=l),L=b.filter(d=>d.status==="done"||d.status==="completed");return{totalActive:s.length,retentionAlerts:r.length,highPriority:u.length,dueTodayOrOverdue:P.length,completed:L.length}},[b]),ee=x.useMemo(()=>b.filter(s=>{if(m!=="all"&&s.branchId&&s.branchId!==m||v!=="all"&&i(s)!==v||T==="unassigned"&&s.assigneeId||T!=="all"&&T!=="unassigned"&&s.assigneeId!==T||H!=="all"&&s.priority!==H)return!1;if(a.trim()){const r=a.toLowerCase(),u=(s.title||"").toLowerCase().includes(r),l=(s.description||"").toLowerCase().includes(r),P=s.relatedId?Y(s.relatedId).toLowerCase().includes(r):!1,L=s.assigneeId?oe(s.assigneeId).toLowerCase().includes(r):!1;if(!u&&!l&&!P&&!L)return!1}return!0}),[b,m,v,T,H,a,D]),Z=x.useMemo(()=>({open:ee.filter(s=>s.status==="open"||!s.status),in_progress:ee.filter(s=>s.status==="in_progress"),done:ee.filter(s=>s.status==="done"||s.status==="completed")}),[ee]),se=(s,r)=>{const u=b.find(l=>(l.id||l._id)===s);u&&(u.status===r||r==="open"&&(!u.status||u.status==="open")||I.mutate({id:s,patch:{status:r}},{onSuccess:()=>{r==="done"?(es(),N.success("Task marked as completed! 🎉",u.title)):N.success(`Moved to ${J(r)}`)},onError:l=>N.error("Failed to move task",l.message)}))},le=s=>{let r="open";s.status==="open"||!s.status?r="in_progress":s.status==="in_progress"?r="done":(s.status==="done"||s.status==="completed")&&(r="open"),se(s.id,r)},te=s=>{var Ne;const r=(Ne=D.members)==null?void 0:Ne.find(we=>String(we.id??we._id)===String(s.relatedId)),u=r!=null&&r.phone?r.phone.replace(/[^\d]/g,""):"",l=(r==null?void 0:r.fullName)||Y(s.relatedId)||"there",P=s.branchId?c(s.branchId):"",L=P?`${k} (${P})`:k,d=i(s);let O="";d==="retention"?O=`Hey ${l}! 👋 Reaching out from ${L} to check in on how your workouts are going. We noticed we missed you recently! Would you like our coaches to set aside a complimentary 15-min routine refresh to get you back in the groove? Reply YES to book your slot! 💪🔥`:d==="billing"?O=`Hi ${l}, this is a gentle note from ${L} regarding your pending membership balance. Please let us know if you have any questions or would like to settle it at the front desk. Thank you! 🙏`:d==="leads"?O=`Hi ${l}! Thanks for your interest in ${L}! Would you like to schedule your trial pass or come in for a quick walkthrough of the space? We would love to show you around! 🏋️`:O=`Hi ${l}, reaching out from ${L} regarding your fitness journey. Let us know how we can best support you! 💪`;const ve=encodeURIComponent(O),$e=u?`https://wa.me/${u}?text=${ve}`:`https://wa.me/?text=${ve}`;window.open($e,"_blank")},Ee=[{key:"status",header:"",render:s=>e.jsx("button",{onClick:r=>{r.stopPropagation(),le(s)},className:"text-muted-foreground hover:text-primary transition-colors mt-0.5",title:"Click to advance status",children:s.status==="done"||s.status==="completed"?e.jsx(ue,{className:"h-5 w-5 text-success fill-success/10"}):s.status==="in_progress"?e.jsx(Ce,{className:"h-5 w-5 text-warning fill-warning/20"}):e.jsx(Te,{className:"h-5 w-5 hover:text-primary"})})},{key:"title",header:"Task & Details",sortable:!0,accessor:s=>s.title,render:s=>{var L,d;const r=i(s),l=s.relatedType==="member"&&s.relatedId?Y(s.relatedId):null,P=`TSK-${String(s.id||s._id).slice(-4).toUpperCase()}`;return e.jsxs("div",{className:"space-y-1 py-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-mono text-[10px] text-muted-foreground bg-muted px-1 py-0.5 rounded font-semibold",children:P}),e.jsx("button",{onClick:()=>p(s),className:E("font-semibold text-sm hover:underline text-left",s.status==="done"&&"line-through text-muted-foreground"),children:s.title}),r==="retention"&&e.jsxs(K,{tone:"warning",className:"text-[10px] py-0 px-1.5 flex items-center gap-1",children:[e.jsx(de,{className:"h-3 w-3 text-amber-500 fill-amber-500"})," Retention Alert"]})]}),s.description&&e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2 max-w-xl",children:s.description}),l&&e.jsxs("div",{className:"flex items-center gap-2 pt-0.5 flex-wrap",children:[e.jsxs("button",{onClick:O=>{O.stopPropagation(),S(`/app/members/${s.relatedId}`)},className:"inline-flex items-center gap-1 text-[11px] text-primary hover:underline font-medium",children:[e.jsx(as,{className:"h-3 w-3"})," ",l," ",e.jsx(ce,{className:"h-2.5 w-2.5"})]}),s.relatedType==="member"&&R.has(s.relatedId)&&e.jsxs("button",{type:"button",onClick:O=>{O.stopPropagation(),S("/app/at-risk")},className:"inline-flex items-center gap-1 rounded-full bg-rose-500/10 px-2 py-0.5 text-[10px] font-semibold text-rose-600 hover:bg-rose-500/20 dark:text-rose-400 transition-colors",title:`At-Risk Member (Score: ${(L=R.get(s.relatedId))==null?void 0:L.score}/100) — Click to view in At-Risk Hub`,children:[e.jsx(ge,{className:"h-3 w-3 text-rose-500"}),"At-Risk · ",(d=R.get(s.relatedId))==null?void 0:d.score]}),e.jsxs("button",{onClick:O=>{O.stopPropagation(),te(s)},className:"inline-flex items-center gap-1 text-[11px] text-success hover:underline font-medium",children:[e.jsx(fe,{className:"h-3 w-3"})," WhatsApp"]})]})]})}},{key:"assignee",header:"Owner",render:s=>{const r=oe(s.assigneeId);return e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx(ne,{name:r!=="—"?r:"Unassigned",size:24}),e.jsx("span",{className:"text-muted-foreground",children:r!=="—"?r:"Unassigned"})]})}},{key:"priority",header:"Priority",render:s=>e.jsx(K,{tone:s.priority==="high"?"danger":s.priority==="medium"?"warning":"neutral",children:J(s.priority)})},{key:"dueDate",header:"Due Date",sortable:!0,accessor:s=>s.dueDate??"",render:s=>{if(!s.dueDate)return e.jsx("span",{className:"text-xs text-muted-foreground",children:"—"});const r=new Date().toISOString().slice(0,10),u=s.dueDate.slice(0,10),l=u<r&&s.status!=="done",P=u===r&&s.status!=="done";return e.jsxs("span",{className:E("text-xs font-medium",l?"text-danger font-semibold":P?"text-warning font-semibold":"text-muted-foreground"),children:[l?"⚠️ Overdue · ":P?"Due Today · ":"",me(s.dueDate)]})}},{key:"actions",header:"",align:"right",render:s=>e.jsxs("div",{className:"flex justify-end gap-1",children:[e.jsx(j,{size:"sm",variant:"ghost",onClick:()=>p(s),children:"View"}),e.jsx(j,{size:"sm",variant:"ghost",onClick:()=>y(s),children:e.jsx(be,{className:"h-3.5 w-3.5"})}),g("members:update")&&e.jsx(j,{size:"sm",variant:"ghost",className:"text-danger",onClick:()=>w(s),children:e.jsx(je,{className:"h-3.5 w-3.5"})})]})}];return e.jsxs("div",{className:"space-y-6",children:[e.jsx(Qe,{title:"Tasks & Team Board",description:"Jira-style task management, behavioral retention win-backs, and staff follow-ups.",actions:g("members:view")&&e.jsxs(j,{onClick:()=>B(!0),className:"shadow-sm",children:[e.jsx(pe,{className:"h-4 w-4 mr-1.5"})," Create Task"]})}),e.jsx(Me,{error:Q.error}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-5",children:[e.jsx(re,{label:"Active Tasks",value:X.totalActive,icon:ze,tone:"info"}),e.jsx(re,{label:"Retention Alerts",value:X.retentionAlerts,icon:de,tone:"danger"}),e.jsx(re,{label:"High Priority",value:X.highPriority,icon:Fe,tone:"warning"}),e.jsx(re,{label:"Due / Overdue",value:X.dueTodayOrOverdue,icon:Pe,tone:"danger"}),e.jsx(re,{label:"Completed",value:X.completed,icon:ue,tone:"success"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center justify-between gap-3",children:[e.jsxs("div",{className:"relative flex-1 max-w-md",children:[e.jsx(Re,{className:"absolute left-3 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(Le,{value:a,onChange:s=>W(s.target.value),placeholder:"Search tasks, members, or coaches…",className:"pl-9 text-xs"})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap justify-end",children:[e.jsxs(G,{value:T,onChange:s=>ae(s.target.value),className:"text-xs h-9 w-auto",children:[e.jsx("option",{value:"all",children:"All Assignees"}),e.jsx("option",{value:"unassigned",children:"Unassigned"}),D.users.map(s=>e.jsx("option",{value:s.id,children:s.name},s.id))]}),e.jsxs(G,{value:H,onChange:s=>t(s.target.value),className:"text-xs h-9 w-auto",children:[e.jsx("option",{value:"all",children:"All Priorities"}),e.jsx("option",{value:"high",children:"High Priority 🔥"}),e.jsx("option",{value:"medium",children:"Medium Priority"}),e.jsx("option",{value:"low",children:"Low Priority"})]}),e.jsxs("div",{className:"flex items-center rounded-lg border border-border bg-muted/40 p-0.5",children:[e.jsxs("button",{onClick:()=>C("kanban"),className:E("flex items-center gap-1.5 px-2.5 py-1 text-xs font-medium rounded-md transition-colors",M==="kanban"?"bg-background shadow-xs text-foreground font-semibold":"text-muted-foreground hover:text-foreground"),children:[e.jsx(ss,{className:"h-3.5 w-3.5"})," Jira Board"]}),e.jsxs("button",{onClick:()=>C("list"),className:E("flex items-center gap-1.5 px-2.5 py-1 text-xs font-medium rounded-md transition-colors",M==="list"?"bg-background shadow-xs text-foreground font-semibold":"text-muted-foreground hover:text-foreground"),children:[e.jsx(ts,{className:"h-3.5 w-3.5"})," List"]})]})]})]}),e.jsx("div",{className:"flex items-center gap-1.5 overflow-x-auto pb-1 text-xs scrollbar-none",children:[{id:"all",label:"All Tasks",count:b.length},{id:"retention",label:"🔥 Retention Win-Backs",count:b.filter(s=>i(s)==="retention").length},{id:"leads",label:"🎯 Leads & Trials",count:b.filter(s=>i(s)==="leads").length},{id:"billing",label:"💳 Payment Dues",count:b.filter(s=>i(s)==="billing").length},{id:"pt",label:"🏋️ PT & Workouts",count:b.filter(s=>i(s)==="pt").length},{id:"general",label:"📋 Operations",count:b.filter(s=>i(s)==="general").length}].map(s=>e.jsxs("button",{onClick:()=>A(s.id),className:E("px-3 py-1.5 rounded-full font-medium transition-colors shrink-0 flex items-center gap-1.5 border",v===s.id?"bg-primary text-primary-foreground border-primary shadow-xs":"bg-card border-border/80 text-muted-foreground hover:bg-muted hover:text-foreground"),children:[e.jsx("span",{children:s.label}),e.jsx("span",{className:E("px-1.5 py-0.2 rounded-full text-[10px]",v===s.id?"bg-primary-foreground
1/20 text-primary-foreground":"bg-muted text-muted-foreground"),children:s.count})]},s.id))})]}),M==="kanban"?e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-5 items-start",children:[e.jsx(xe,{columnKey:"open",title:"To Do",icon:Te,count:Z.open.length,tone:"neutral",tasks:Z.open,lookups:D,gymName:k,branchName:c,draggingTaskId:z,dragOverColumn:q,onDragStart:s=>F(s),onDragEnd:()=>{F(null),_(null)},onDragOverCol:s=>_(s),onDropTask:se,onAdvance:le,onSelectTask:p,onEdit:y,onDelete:w,onWhatsApp:te,canDelete:g("members:update"),getCategory:i,onQuickCreate:()=>B(!0),atRiskMap:R}),e.jsx(xe,{columnKey:"in_progress",title:"In Progress",icon:Ce,count:Z.in_progress.length,tone:"warning",tasks:Z.in_progress,lookups:D,gymName:k,branchName:c,draggingTaskId:z,dragOverColumn:q,onDragStart:s=>F(s),onDragEnd:()=>{F(null),_(null)},onDragOverCol:s=>_(s),onDropTask:se,onAdvance:le,onSelectTask:p,onEdit:y,onDelete:w,onWhatsApp:te,canDelete:g("members:update"),getCategory:i,atRiskMap:R}),e.jsx(xe,{columnKey:"done",title:"Completed",icon:ue,count:Z.done.length,tone:"success",tasks:Z.done,lookups:D,gymName:k,branchName:c,draggingTaskId:z,dragOverColumn:q,onDragStart:s=>F(s),onDragEnd:()=>{F(null),_(null)},onDragOverCol:s=>_(s),onDropTask:se,onAdvance:le,onSelectTask:p,onEdit:y,onDelete:w,onWhatsApp:te,canDelete:g("members:update"),getCategory:i,atRiskMap:R})]}):e.jsx(Ye,{rows:ee,columns:Ee,getRowId:s=>s.id,loading:Q.isLoading,searchKeys:s=>`${s.title} ${s.description}`,emptyTitle:"No tasks matching criteria — you're all caught up! 🎉"}),f&&e.jsx(os,{task:f,lookups:D,gymName:k,branchName:c,onClose:()=>p(null),onEdit:()=>{y(f),p(null)},onDelete:()=>{w(f),p(null)},onStatusChange:s=>{se(f.id,s),p(r=>r?{...r,status:s}:null)},onWhatsApp:()=>te(f),canDelete:g("members:update"),getCategory:i,atRiskMap:R}),$&&e.jsx(De,{onClose:()=>B(!1)}),o&&e.jsx(De,{task:o,onClose:()=>y(null)}),e.jsx(Ue,{open:!!h,destructive:!0,onClose:()=>w(null),title:"Delete task",message:`Are you sure you want to delete "${(h==null?void 0:h.title)??"this task"}"?`,confirmLabel:"Delete",onConfirm:()=>{h&&U.mutate(h.id,{onSuccess:()=>N.success("Task deleted"),onError:s=>N.error("Failed to delete",s.message)}),w(null)}})]})}function xe({columnKey:n,title:c,icon:g,count:S,tone:m,tasks:N,lookups:U,gymName:I,branchName:k,draggingTaskId:$,dragOverColumn:B,onDragStart:o,onDragEnd:y,onDragOverCol:h,onDropTask:w,onAdvance:f,onSelectTask:p,onEdit:M,onDelete:C,onWhatsApp:a,canDelete:W,getCategory:v,onQuickCreate:A,atRiskMap:T}){const ae=he(),H=B===n;return e.jsxs("div",{onDragOver:t=>{t.preventDefault(),t.dataTransfer.dropEffect="move",h(n)},onDragLeave:t=>{t.currentTarget.contains(t.relatedTarget)},onDrop:t=>{t.preventDefault();const z=t.dataTransfer.getData("text/plain")||$;z&&w(z,n),y()},className:E("rounded-xl border transition-all duration-200 p-3 space-y-3 min-h-[560px] flex flex-col",H?"border-primary/80 bg-primary/5 ring-2 ring-primary/20 shadow-md":"border-border/80 bg-muted/25"),children:[e.jsxs("div",{className:"flex items-center justify-between px-1 pb-1",children:[e.jsxs("div",{className:"flex items-center gap-2 font-semibold text-xs uppercase tracking-wider text-foreground",children:[e.jsx(g,{className:E("h-4 w-4",m==="warning"?"text-warning":m==="success"?"text-success":"text-muted-foreground")}),e.jsx("span",{children:c})]}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsx(K,{tone:m,children:S})})]}),H&&$&&e.jsxs("div",{className:"h-10 rounded-lg border-2 border-dashed border-primary/60 bg-primary/10 flex items-center justify-center text-xs font-semibold text-primary animate-pulse",children:["Drop here to move to ",c]}),e.jsx("div",{className:"space-y-2.5 flex-1",children:N.length===0&&!H?e.jsxs("div",{className:"h-40 flex flex-col items-center justify-center text-center p-4 border border-dashed border-border rounded-xl text-muted-foreground text-xs space-y-2",children:[e.jsxs("span",{className:"opacity-80",children:["No issues in ",c]}),A&&e.jsxs(j,{size:"sm",variant:"ghost",className:"h-7 text-xs text-primary",onClick:A,children:[e.jsx(pe,{className:"h-3 w-3 mr-1"})," Create Task"]})]}):N.map(t=>{const z=v(t),F=z==="retention",q=U.userName(t.assigneeId),_=t.relatedType==="member"&&t.relatedId?U.memberName(t.relatedId):null,D=t.relatedType==="member"&&t.relatedId&&(T==null?void 0:T.has(t.relatedId))?T==null?void 0:T.get(t.relatedId):null,b=new Date().toISOString().slice(0,10),ie=t.dueDate&&t.dueDate.slice(0,10)<b&&t.status!=="done",R=t.dueDate&&t.dueDate.slice(0,10)===b&&t.status!=="done",oe=`TSK-${String(t.id||t._id).slice(-4).toUpperCase()}`,Y=$===(t.id||t._id);return e.jsxs("div",{draggable:!0,onDragStart:i=>{i.dataTransfer.setData("text/plain",t.id||t._id),i.dataTransfer.effectAllowed="move",o(t.id||t._id)},onDragEnd:y,className:E("group relative rounded-xl border bg-card p-3.5 shadow-xs transition-all cursor-grab active:cursor-grabbing hover:shadow-md space-y-2.5 select-none",Y&&"opacity-40 scale-95 border-dashed border-primary",F?"border-amber-500/40 dark:border-amber-500/30":"border-border",t.status==="done"&&"opacity-80 bg-card/60"),
1children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"cursor-grab text-muted-foreground/40 group-hover:text-muted-foreground transition-colors",children:e.jsx(rs,{className:"h-3.5 w-3.5 -ml-1"})}),e.jsx("span",{className:"font-mono text-[10px] text-muted-foreground bg-muted px-1.5 py-0.5 rounded font-semibold tracking-wider",children:oe}),F?e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] font-semibold text-amber-600 dark:text-amber-400 bg-amber-500/10 px-1.5 py-0.2 rounded",children:[e.jsx(de,{className:"h-3 w-3 fill-amber-500 text-amber-500"})," Win-Back"]}):e.jsx(K,{tone:"outline",className:"text-[10px] py-0 px-1.5",children:J(z)})]}),e.jsx(K,{tone:t.priority==="high"?"danger":t.priority==="medium"?"warning":"neutral",className:"text-[10px] py-0 px-1.5",children:J(t.priority)})]}),e.jsxs("div",{onClick:()=>p(t),className:"cursor-pointer space-y-1",children:[e.jsx("h4",{className:E("text-sm font-semibold text-foreground leading-snug group-hover:text-primary transition-colors",t.status==="done"&&"line-through text-muted-foreground"),children:t.title}),t.description&&e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2 leading-relaxed",children:t.description})]}),_&&e.jsxs("div",{className:"flex items-center justify-between border-t border-border/50 pt-2 text-xs flex-wrap gap-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0 max-w-[200px]",children:[e.jsxs("button",{onClick:i=>{i.stopPropagation(),ae(`/app/members/${t.relatedId}`)},className:"inline-flex items-center gap-1.5 text-primary hover:underline font-medium truncate",children:[e.jsx(ne,{name:_,size:18}),e.jsx("span",{className:"truncate",children:_}),e.jsx(ce,{className:"h-2.5 w-2.5 shrink-0 text-muted-foreground"})]}),D&&e.jsxs("button",{type:"button",onClick:i=>{i.stopPropagation(),ae("/app/at-risk")},className:"inline-flex items-center gap-1 rounded-full bg-rose-500/10 px-1.5 py-0.2 text-[9px] font-semibold text-rose-600 hover:bg-rose-500/20 dark:text-rose-400 shrink-0 transition-colors",title:`At-Risk Member (Score: ${D.score}/100) — Click to open At-Risk Hub`,children:[e.jsx(ge,{className:"h-2.5 w-2.5"}),"Risk ",D.score]})]}),e.jsxs("button",{onClick:i=>{i.stopPropagation(),a(t)},className:"inline-flex items-center gap-1 text-[11px] font-semibold text-success hover:underline shrink-0 bg-success/10 hover:bg-success/20 px-2 py-0.5 rounded transition-colors",title:"Send personalized WhatsApp check-in with gym name",children:[e.jsx(fe,{className:"h-3 w-3"})," WhatsApp"]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-1 border-t border-border/50 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1.5 truncate max-w-[120px]",children:[e.jsx(ne,{name:q!=="—"?q:"Unassigned",size:20}),e.jsx("span",{className:"truncate text-[11px]",children:q!=="—"?q:"Unassigned"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[t.dueDate&&e.jsxs("span",{className:E("text-[11px] flex items-center gap-1",ie?"text-danger font-semibold":R?"text-warning font-semibold":"text-muted-foreground"),children:[e.jsx(Pe,{className:"h-3 w-3"}),me(t.dueDate)]}),e.jsx(j,{size:"sm",variant:"outline",className:"h-6 text-[11px] px-1.5 ml-1",onClick:i=>{i.stopPropagation(),f(t)},title:t.status==="done"?"Reopen":"Advance status",children:t.status==="done"?e.jsx(ns,{className:"h-3 w-3"}):t.status==="in_progress"?e.jsx(He,{className:"h-3 w-3 text-success"}):e.jsx(qe,{className:"h-3 w-3"})}),e.jsx(j,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:i=>{i.stopPropagation(),M(t)},children:e.jsx(be,{className:"h-3 w-3"})}),W&&e.jsx(j,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-danger",onClick:i=>{i.stopPropagation(),C(t)},children:e.jsx(je,{className:"h-3 w-3"})})]})]})]},t.id)})}),A&&e.jsxs("button",{onClick:A,className:"w-full flex items-center justify-center gap-1 py-1.5 text-xs text-muted-foreground hover:text-foreground hover:bg-background/80 rounded-lg border border-transparent hover:border-border transition-all",children:[e.jsx(pe,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:"Create Task"})]})]})}function os({task:n,lookups:c,gymName:g,branchName:S,onClose:m,onEdit:N,onDelete:U,onStatusChange:I,onWhatsApp:k,canDelete:$,getCategory:B,atRiskMap:o}){var v;const y=he(),h=B(n),w=h==="retention",f=c.userName(n.assigneeId),p=n.relatedType==="member"&&n.relatedId?c.memberName(n.relatedId):null,C=n.relatedType==="member"&&n.relatedId&&(o==null?void 0:o.has(n.relatedId))?o==null?void 0:o.get(n.relatedId):null,a=(v=c.members)==null?void 0:v.find(A=>String(A.id??A._id)===String(n.relatedId)),W=`TSK-${String(n.id||n._id).slice(-4).toUpperCase()}`;return e.jsx(Oe,{open:!0,onClose:m,title:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-mono text-xs bg-muted px-2 py-0.5 rounded font-semibold text-muted-foreground",children:W}),e.jsx("span",{children:"Task Details"})]}),footer:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("div",{className:"flex items-center gap-2",children:$&&e.jsxs(j,{size:"sm",variant:"ghost",className:"text-danger",onClick:U,children:[e.jsx(je,{className:"h-4 w-4 mr-1.5"})," Delete"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(j,{variant:"outline",onClick:N,children:[e.jsx(be,{className:"h-3.5 w-3.5 mr-1.5"})," Edit Task"]}),e.jsx(j,{variant:"ghost",onClick:m,children:"Close"})]})]}),children:e.jsxs("div",{className:"space-y-5 text-left",children:[C&&e.jsxs("div",{className:"rounded-xl border border-rose-500/30 bg-rose-500/10 p-3.5 flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx(ge,{className:"h-5 w-5 text-rose-500 shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs font-bold text-rose-600 dar
1k:text-rose-400",children:["At-Risk Member (Score: ",C.score,"/100)"]}),e.jsxs(K,{tone:C.riskLevel==="high"?"danger":"warning",className:"text-[10px] py-0 px-1.5 font-semibold",children:[J(C.riskLevel)," Risk"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:C.reasons.join(" · ")})]})]}),e.jsxs(j,{size:"sm",variant:"outline",className:"shrink-0 h-7 text-xs border-rose-500/30 text-rose-600 hover:bg-rose-500/10",onClick:()=>{m(),y("/app/at-risk")},children:["Open At-Risk Hub ",e.jsx(ce,{className:"h-3 w-3 ml-1"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[w?e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-semibold text-amber-600 dark:text-amber-400 bg-amber-500/10 px-2.5 py-1 rounded",children:[e.jsx(de,{className:"h-3.5 w-3.5 fill-amber-500 text-amber-500"})," Behavioral Retention Alert"]}):e.jsx(K,{tone:"outline",children:J(h)}),e.jsxs(K,{tone:n.priority==="high"?"danger":n.priority==="medium"?"warning":"neutral",children:[J(n.priority)," Priority"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[e.jsx("span",{className:"text-muted-foreground font-medium",children:"Status:"}),e.jsxs(G,{value:n.status||"open",onChange:A=>I(A.target.value),className:"h-8 text-xs font-semibold",children:[e.jsx("option",{value:"open",children:"To Do (Open)"}),e.jsx("option",{value:"in_progress",children:"⚡ In Progress"}),e.jsx("option",{value:"done",children:"✅ Completed"})]})]})]}),e.jsx("h3",{className:"text-base font-bold text-foreground leading-snug",children:n.title})]}),e.jsxs("div",{className:"space-y-1.5 rounded-xl border border-border bg-muted/20 p-3.5 text-xs",children:[e.jsx("span",{className:"font-semibold text-muted-foreground uppercase tracking-wider text-[10px]",children:"Description & Action Notes"}),e.jsx("p",{className:"text-foreground leading-relaxed whitespace-pre-line text-xs",children:n.description||"No additional details provided."})]}),p&&e.jsxs("div",{className:"rounded-xl border border-border/80 bg-card p-3.5 space-y-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[11px] font-semibold text-muted-foreground uppercase tracking-wider",children:"Linked Member"}),e.jsxs("button",{onClick:()=>y(`/app/members/${n.relatedId}`),className:"inline-flex items-center gap-1 text-xs text-primary hover:underline font-medium",children:["View Full Profile ",e.jsx(ce,{className:"h-3 w-3"})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(ne,{name:p,src:a==null?void 0:a.photoUrl,size:36}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-sm text-foreground",children:p}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(a==null?void 0:a.phone)||"No phone recorded"})]})]}),e.jsxs(j,{size:"sm",onClick:k,className:"bg-emerald-600 hover:bg-emerald-700 text-white shadow-xs text-xs h-8",children:[e.jsx(fe,{className:"h-3.5 w-3.5 mr-1.5"})," WhatsApp (",g,")"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-xs pt-1 border-t border-border",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-muted-foreground",children:"Assignee / Coach"}),e.jsxs("div",{className:"flex items-center gap-2 font-medium text-foreground",children:[e.jsx(ne,{name:f!=="—"?f:"Unassigned",size:22}),e.jsx("span",{children:f!=="—"?f:"Unassigned"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-muted-foreground",children:"Branch"}),e.jsx("p",{className:"font-medium text-foreground",children:n.branchId?S(n.branchId):"All Branches"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-muted-foreground",children:"Due Date"}),e.jsx("p",{className:"font-medium text-foreground",children:n.dueDate?me(n.dueDate):"No due date"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-muted-foreground",children:"Created"}),e.jsx("p",{className:"font-medium text-foreground",children:n.createdAt?me(n.createdAt):"Recently"})]})]})]})})}function De({task:n,onClose:c}){var M,C;const{state:g}=Se(),S=Ie(),m=Ke(),N=ke(),U=Ae(!0),I=!!n,k=g.meta.activeBranchId==="all"?((M=g.branches[0])==null?void 0:M.id)??"":g.meta.activeBranchId,[$,B]=x.useState((n==null?void 0:n.relatedId)||""),{register:o,handleSubmit:y,setValue:h,formState:{errors:w}}
1=We({defaultValues:I?{title:n.title,description:n.description,assigneeId:n.assigneeId,priority:n.priority,branchId:n.branchId,dueDate:n.dueDate?String(n.dueDate).slice(0,10):"",status:n.status,relatedType:n.relatedType||"member"}:{priority:"medium",status:"open",branchId:k,dueDate:new Date().toISOString().slice(0,10),relatedType:"member"}}),f=a=>{h("title",a.title),h("description",a.description),h("priority",a.priority),h("relatedType",a.relatedType)},p=a=>{const W={...a,dueDate:a.dueDate?new Date(a.dueDate).toISOString():void 0,branchId:a.branchId||void 0,assigneeId:a.assigneeId||void 0,relatedId:$||void 0};I?N.mutate({id:n.id,patch:W},{onSuccess:()=>{S.success("Task updated",a.title),c()},onError:v=>S.error("Failed to update task",v.message)}):m.mutate(W,{onSuccess:()=>{S.success("Task created",a.title),c()},onError:v=>S.error("Failed to create task",v.message)})};return e.jsx(Oe,{open:!0,onClose:c,title:I?"Edit Task":"Create New Task",footer:e.jsxs(e.Fragment,{children:[e.jsx(j,{variant:"ghost",onClick:c,children:"Cancel"}),e.jsx(j,{type:"submit",form:"task-form",loading:m.isPending||N.isPending,children:I?"Save Changes":"Create Task"})]}),children:e.jsxs("form",{id:"task-form",onSubmit:y(p),className:"space-y-4",children:[!I&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{className:"text-xs font-semibold text-muted-foreground flex items-center gap-1",children:[e.jsx(Ve,{className:"h-3 w-3 text-amber-500"})," Quick Templates:"]}),e.jsx("div",{className:"flex gap-1.5 overflow-x-auto pb-1 text-xs",children:is.map((a,W)=>e.jsx("button",{type:"button",onClick:()=>f(a),className:"px-2.5 py-1 rounded-full border border-border bg-muted/40 hover:bg-muted text-[11px] font-medium text-foreground transition-colors shrink-0",children:a.label},W))})]}),e.jsx(V,{label:"Task Title",required:!0,error:(C=w.title)==null?void 0:C.message,children:e.jsx(Le,{...o("title",{required:"Title is required"}),placeholder:"e.g. Call Alex regarding win-back offer"})}),e.jsx(V,{label:"Description & Next Steps",children:e.jsx(Ge,{...o("description"),rows:3,placeholder:"Context, conversation notes, or WhatsApp copy…"})}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-foreground",children:"Linked Member (Optional)"}),e.jsx(Xe,{value:$,onChange:B,placeholder:"Search and attach member profile…"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(V,{label:"Assignee / Coach",children:e.jsxs(G,{...o("assigneeId"),children:[e.jsx("option",{value:"",children:"Unassigned"}),U.users.map(a=>e.jsx("option",{value:a.id,children:a.name},a.id))]})}),e.jsx(V,{label:"Priority",children:e.jsxs(G,{...o("priority"),children:[e.jsx("option",{value:"low",children:"Low Priority"}),e.jsx("option",{value:"medium",children:"Medium Priority"}),e.jsx("option",{value:"high",children:"High Priority 🔥"})]})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(V,{label:"Branch",children:e.jsxs(G,{...o("branchId"),children:[e.jsx("option",{value:"",children:"All Branches"}),g.branches.map(a=>e.jsx("option",{value:a.id,children:a.name},a.id))]})}),e.jsx(V,{label:"Due Date",children:e.jsx(Je,{...o("dueDate"),placeholder:"Select due date"})})]}),I&&e.jsx(V,{label:"Status",children:e.jsxs(G,{...o("status"),children:[e.jsx("option",{value:"open",children:"To Do (Open)"}),e.jsx("option",{value:"in_progress",children:"In Progress"}),e.jsx("option",{value:"done",children:"Completed (Done)"}),e.jsx("option",{value:"cancelled",children:"Cancelled"})]})})]})})}export{Ds as TasksPage};

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.