1import{r as e,j as s,k as a}from"./vendor-react-D50HaH0L.js";import{u as t,d as i,e as n,k as r,p as l,q as o,s as d,t as c,S as m,v as u,w as x}from"./AuthenticatedShell-COwCdMpr.js";import{u as h}from"./useDocumentTitle-Bi0eP6OD.js";import{E as f}from"./empty-state-C5xwVkXC.js";import{p as g,f as j,a as p,M as v,k as N,B as y,C as w}from"./index-DlLXTx5i.js";import{A as b,a as k,b as z}from"./alert-DmwRzgzU.js";import{_ as S,$ as C,a0 as P}from"./vendor-radix-DGSsoRrR.js";import{S as E}from"./section-action-bar-CVUXyQKz.js";import{B as _}from"./badge-tjrN-hzu.js";import{C as F}from"./checkbox-FZ744XVI.js";import{S as $}from"./scroll-area-DYknsg9S.js";import{P as D}from"./PageShell-D8HOkqVh.js";import{A,b as M,c as T,d as R,e as q,f as K,g as L,h as O}from"./alert-dialog-D6ATpb5Q.js";import{w as Q,d as V,Z as I,I as B,a8 as U,T as W}from"./vendor-icons-Dw-Q461N.js";import"./vendor-firebase-BdWIMCz7.js";import"./input-D9I0l-TH.js";import"./vendor-utils-BeLtu-UY.js";const Y=g("inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground",{variants:{variant:{default:"bg-transparent",outline:"border border-input bg-transparent hover:bg-accent hover:text-accent-foreground"},size:{default:"h-10 px-3",sm:"h-9 px-2.5",lg:"h-11 px-5"}},defaultVariants:{variant:"default",size:"default"}});e.forwardRef(({className:e,variant:a,size:t,...i},n)=>s.jsx(S,{ref:n,className:j(Y({variant:a,size:t,className:e})),...i})).displayName=S.displayName;const H=e.createContext({size:"default",variant:"default"}),Z=e.forwardRef(({className:e,variant:a,size:t,children:i,...n},r)=>s.jsx(C,{ref:r,className:j("flex items-center justify-center gap-1",e),...n,children:s.jsx(H.Provider,{value:{variant:a,size:t},children:i})}));Z.displayName=C.displayName;const G=e.forwardRef(({className:a,children:t,variant:i,size:n,...r},l)=>{const o=e.useContext(H);return s.jsx(P,{ref:l,className:j(Y({variant:o.variant||i,size:o.size||n}),a),...r,children:t})});function J(e){const s=e.metadata?.url;if(!("string"!=typeof(a=s)||0===a.length||"/"!==a[0]||a.length>=2&&("/"===a[1]||"\\"===a[1])||/[\x00-\x20\x7f]/.test(a)))return s;var a;if(e.type?.startsWith("cases.")){const s=e.metadata?.case_id;if("string"==typeof s&&s)return`/cases/${s}`}return null}function X(e){const s=e.metadata?.ctaLabel;return"string"==typeof s&&s.trim()?s.trim():e.type?.startsWith("cases.")?"View case":"View"}G.displayName=P.displayName;const ee=()=>{h("Notifications");const g=a(),{user:S,isAuthReady:C}=t(),P=p(),{toast:Y}=v(),{formatRelativeDate:H}=i(),[ee,se]=e.useState(new Set),[ae,te]=e.useState(null),[ie,ne]=e.useState("all"),[re,le]=e.useState(1),[oe,de]=e.useState(!1),[ce,me]=e.useState(null),[ue,xe]=e.useState(null),[he,fe]=e.useState({}),{selectedOrgId:ge,isError:je,isLoading:pe,refetchOrganizations:ve}=n();e.useEffect(()=>{se(new Set),te(null),le(1),fe({}),de(!1),me(null),xe(null)},[ge]);const{data:Ne,isLoading:ye,isError:we,refetch:be}=N({queryKey:["notifications",ge,ie,re,he[re],S?.uid],queryFn:async()=>{if(!ge)return null;const e={status:ie,page:String(re),page_size:String(25)};return re>1&&he[re]&&(e.cursor=he[re]),x(ge,e)},enabled:!!ge&&C,staleTime:3e4}),ke=Ne,ze=pe||ye,Se=r({mutationFn:async e=>{if(!ge)throw new Error("No organization");return l(ge,e)},onSuccess:()=>{P.invalidateQueries({queryKey:["notifications"]}),se(new Set)},onError:e=>{Y({title:"Error",description:e.message||"Failed to mark as read",variant:"destructive"})}}),Ce=r({mutationFn:async e=>{if(!ge)throw new Error("No organization");return o(ge,e)},onSuccess:()=>{P.invalidateQueries({queryKey:["notifications"]}),se(new Set)},onError:e=>{Y({title:"Error",description:e.message||"Failed to mark as unread",variant:"destructive"})}}),Pe=r({mutationFn:async e=>{if(!ge)throw new Error("No organization");return d(ge,e)},onSuccess:e=>{P.invalidateQueries({queryKey:["notifications"]}),se(new Set),e&&0!==e.updated?Y({title:"Deleted",description:`${e.updated} notification${1===e.updated?"":"s"} deleted successfully`}):Y({title:"Nothing to delete",description:"Those notifications were already removed or no longer belong to this organization. The list has been refreshed."})},onError:e=>{Y({title:"Error",description:e.message||"Failed to delete",variant:"destructive"})}}),Ee=r({mutationFn:async()=>
1{if(!ge)throw new Error("No organization");return c(ge)},onSuccess:()=>{P.invalidateQueries({queryKey:["notifications"]}),se(new Set)},onError:e=>{Y({title:"Error",description:e.message||"Failed to mark all as read",variant:"destructive"})}}),_e=ke?.items||[],Fe=ke?.unread_count||0,$e=(e,a)=>{const t=a?"text-muted-foreground":"";switch(e){case"info":return s.jsx(B,{className:`h-5 w-5 ${a?t:"text-primary"}`});case"warning":return s.jsx(W,{className:`h-5 w-5 ${a?t:"text-warning"}`});case"success":return s.jsx(U,{className:`h-5 w-5 ${a?t:"text-success"}`});case"error":return s.jsx(V,{className:`h-5 w-5 ${a?t:"text-destructive"}`});default:return s.jsx(B,{className:`h-5 w-5 ${t}`})}},De=e=>{e.is_read?Ce.mutate([e.id]):Se.mutate([e.id])},Ae=H,Me=Se.isPending||Ce.isPending||Ee.isPending||Pe.isPending;return s.jsxs(D,{bodyClassName:"space-y-6",header:s.jsxs("div",{className:"space-y-2",children:[s.jsx("h1",{className:"text-4xl font-bold tracking-tight",children:"Notifications"}),s.jsx("p",{className:"text-base text-muted-foreground",children:"Stay updated with the latest activity and important alerts"})]}),children:[s.jsxs("div",{className:"space-y-6",children:[s.jsx("div",{className:"max-w-3xl",children:s.jsxs(E,{status:s.jsxs(Z,{type:"single",value:ie,onValueChange:e=>{e&&(ne(e),le(1),fe({}),se(new Set))},className:"gap-0 bg-muted p-1 rounded-lg",children:[s.jsx(G,{value:"all",className:"flex items-center gap-2 rounded-md data-[state=on]:bg-background data-[state=on]:text-foreground data-[state=on]:shadow-sm",children:"All"}),s.jsxs(G,{value:"unread",className:"flex items-center gap-2 rounded-md data-[state=on]:bg-background data-[state=on]:text-foreground data-[state=on]:shadow-sm",children:["Unread",Fe>0&&s.jsx(_,{className:"h-5 px-2 bg-primary/10 text-primary",children:Fe})]}),s.jsx(G,{value:"read",className:"rounded-md data-[state=on]:bg-background data-[state=on]:text-foreground data-[state=on]:shadow-sm",children:"Read"})]}),children:[ee.size>0&&s.jsxs(s.Fragment,{children:[Array.from(ee).some(e=>!_e.find(s=>s.id===e)?.is_read)&&s.jsxs(y,{variant:"outline",size:"sm",onClick:()=>{ee.size>0&&Se.mutate(Array.from(ee))},disabled:Me,children:[Se.isPending&&s.jsx(Q,{className:"mr-2 h-4 w-4 animate-spin"}),"Mark read (",ee.size,")"]}),Array.from(ee).some(e=>_e.find(s=>s.id===e)?.is_read)&&s.jsxs(y,{variant:"outline",size:"sm",onClick:()=>{ee.size>0&&Ce.mutate(Array.from(ee))},disabled:Me,children:[Ce.isPending&&s.jsx(Q,{className:"mr-2 h-4 w-4 animate-spin"}),"Mark unread (",ee.size,")"]}),s.jsxs(y,{variant:"destructive",size:"sm",onClick:()=>{ee.size>0&&(xe(ge),de(!0))},disabled:Me,children:[Pe.isPending&&s.jsx(Q,{className:"mr-2 h-4 w-4 animate-spin"}),"Delete (",ee.size,")"]})]}),0===ee.size&&Fe>0&&s.jsxs(y,{variant:"outline",size:"sm",onClick:()=>Ee.mutate(),disabled:Me,children:[Ee.isPending&&s.jsx(Q,{className:"mr-2 h-4 w-4 animate-spin"}),"Mark all read"]})]})}),s.jsx("div",{className:"max-w-3xl",children:_e.length>0&&s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(F,{checked:_e.length>0&&ee.size===_e.length,onCheckedChange:()=>{ee.size===_e.length?se(new Set):se(new Set(_e.map(e=>e.id)))},disabled:Me}),s.jsx("span",{className:"text-sm text-muted-foreground",children:"Select all"})]})}),je&&s.jsxs(b,{variant:"destructive",className:"max-w-3xl",children:[s.jsx(V,{className:"h-4 w-4"}),s.jsx(k,{children:"Failed to load organization"}),s.jsxs(z,{className:"flex flex-wrap items-center justify-between gap-3",children:[s.jsx("span",{children:"Unable to fetch your organization details. Please try again."}),s.jsx(y,{size:"sm",variant:"outline",onClick:()=>ve(),children:"Retry"})]})]}),!je&&ze&&s.jsx("div",{className:"max-w-3xl space-y-2",children:[1,2,3,4,5].map(e=>s.jsx(m,{className:"h-24 w-full rounded-lg"},e))}),!je&&!ze&&we&&s.jsxs(b,{variant:"destructive",className:"max-w-3xl",children:[s.jsx(V,{className:"h-4 w-4"}),s.jsx(k,{children:"Failed to load notifications"}),s.jsxs(z,{className:"flex flex-wrap items-center justify-between gap-3",children:[s.jsx("span",{children:"Something went wrong loading your notifications. Please try again."}),s.jsx(y,{size:"sm",variant:"outline",onClick:()=>be(),children:"Retry"})]})]}),je||ze||we||0!==_e.length?!je&&!ze&&!we&&s.jsx("div",{className:"flex flex-col",children:s.jsx($,{className:"pr-4",children:s.jsx("div",{className:"space-y-0 max-w-3xl",children:_e.map((e,a)=>{const t=ae===e.id,i=e.message.length>150;return s.jsxs("div",{children:[s.jsx("div",{className:j("group relative p-4 min-h-[110px] transition-all cursor-pointer",!e.is_read&&"bg-muted/50 border-l-4 border-l-muted-foreground"),onClick:()=>De(e),onMouseEnter:()=>te(e.id),onMouseLeave:()=>te(null),onKeyDown:s=>{"Enter"!==s.key&&" "!==s.key||(s.preventDefault(),De(e))},role:"button",tabIndex:0,"aria-label":`${e.is_read?"Mark as unread":"Mark as read"}: ${e.title}`,children:s.jsxs("div",{className:"flex gap-4 h-full",children:[s.jsx("div",{className:"flex-shrink-0 flex items-start",children:s.jsx("div",{onClick:e=>e.stopPropagation(),className:"mt-1",children:s.jsx(F,{checked:ee.has(e.id),onCheckedChange:()=>{return s=e.id,void se(e=>{const a=new Set(e);return a.has(s)?a.delete(s):a.add(s),a});var s},disabled:Me,"aria-label":`Select notification: ${e.title}`})})}),s.jsx("div",{className:"flex-shrink-0 mt-1",children:$e(e.severity,e.is_read)}),s.jsxs("div",{className:"flex-1 space-y-2 flex flex-col",children:[s.jsx("div",{className:"flex items-start justify-between gap-4",children:s.jsxs("div",{className:"space-y-1 flex-1",children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsx("h3",{className:j("text-base flex-1",e.is_read?"font-normal text-muted-foreground":"font-bold text-foreground"),children:e.title}),s.jsx("div",{className:"opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity",onClick:e=>e.stopPropagation(),children:s.jsx(y,{variant:"ghost",size:"sm",onClick:()=>(e=>{xe(ge),me(e)})(e),disabled:Me,className:"h-8 px-2 text-destructive font-bold hover:bg-destructive hover:text-destructive-foreground",children:"Delete"})})]}),s.jsxs("div",{className:"relative",children:[s.jsx("p",{className:j("text-sm text-muted-foreground transition-all",!t&&i&&"line-clamp-2"),children:e.message}),i&&!t&&s.jsx("div",{className:"flex justify-start mt-1",children:s.jsx("span",{className:"text-xs text-primary hover:underline cursor-pointer",children:"Hover to show more"})})]}),J(e)&&s.jsx("div",{className:"mt-1",onClick:e=>e.stopPropagation(),children:s.jsxs(y,{variant:"link",size:"sm",className:"h-auto p-0 text-xs",onClick:()=>(e=>{const s=J(e);s&&(e.is_read||Se.mutate([e.id]),g(s))})(e),children:[X(e)," ","â"]})})]})}),s.jsx("div",{className:"flex justify-end mt-auto",children:s.jsx("span",{className:"text-xs text-muted-foreground",children:Ae(e.created_at)})})]})]})}),a<_e.length-1&&s.jsx(u,{})]},e.id)})})})}):s.jsx(w,{className:"max-w-3xl",children:s.jsx(f,{icon:I,title:"No notifications",description:"unread"===ie?"You're all caught up!":"read"===ie?"No read notifications yet":"You don't have any notifications yet"})}),ke&&ke.total>25&&s.jsxs("div",{className:"flex items-center justify-between max-w-3xl mt-4",children:[s.jsxs("p",{className:"text-sm text-muted-foreground",children:["Page ",re," of ",Math.
1ceil(ke.total/25)," (",ke.total," total)"]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(y,{variant:"outline",size:"sm",onClick:()=>{le(e=>Math.max(1,e-1)),se(new Set)},disabled:re<=1||ze,children:"Previous"}),s.jsx(y,{variant:"outline",size:"sm",onClick:()=>{ke.next_cursor&&fe(e=>({...e,[re+1]:ke.next_cursor})),le(e=>e+1),se(new Set)},disabled:25*re>=ke.total||ze,children:"Next"})]})]})]}),s.jsx(A,{open:oe,onOpenChange:de,children:s.jsxs(M,{children:[s.jsxs(T,{children:[s.jsx(R,{children:"Delete notifications"}),s.jsxs(q,{children:["This will delete ",ee.size," notification",1!==ee.size?"s":"",". This action cannot be undone."]})]}),s.jsxs(K,{children:[s.jsx(L,{children:"Cancel"}),s.jsx(O,{onClick:()=>{if(ue!==ge)return de(!1),void xe(null);Pe.mutate(Array.from(ee)),de(!1),xe(null)},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})}),s.jsx(A,{open:null!==ce,onOpenChange:e=>{e||me(null)},children:s.jsxs(M,{children:[s.jsxs(T,{children:[s.jsx(R,{children:"Delete notification"}),s.jsx(q,{children:ce?s.jsxs(s.Fragment,{children:["This will delete â",ce.title,"â. This action cannot be undone."]}):"This action cannot be undone."})]}),s.jsxs(K,{children:[s.jsx(L,{children:"Cancel"}),s.jsx(O,{onClick:()=>{if(ce){if(ue!==ge)return me(null),void xe(null);Pe.mutate([ce.id]),me(null),xe(null)}},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})})]})};export{ee 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.