1import{r as d,b as S,j as e,d as D,C,M as T,L as W,A as B,Q as I,w as R,ah as F,a as Q,ai as U,af as Y}from"./index-DCEGk7me.js";import{C as _}from"./check-BkYJlLIr.js";const A={off:"Off",immediate:"Straight away",daily:"Daily summary",weekly:"Weekly summary"},N={critical:{label:"Critical",className:"bg-destructive/10 text-destructive border-destructive/30"},action:{label:"Needs action",className:"bg-amber-500/10 text-amber-700 dark:text-amber-400 border-amber-500/30"},info:{label:"For info",className:"bg-muted text-muted-foreground border-border"}},$={critical:"May be turned off, never delayed: it skips quiet hours and cannot be batched into a summary.",action:"Something to do, safely batchable â a daily or weekly summary is a real choice here.",info:"Good to know. In the app by default; email is opt-in."},E=Array.from({length:24},(t,i)=>i),H=t=>Math.floor((t||0)/60),w="rounded-xl border border-border/60 bg-card shadow-soft p-5 space-y-3";function K(){const[t,i]=d.useState(!0),[c,u]=d.useState(!1),[m,h]=d.useState(null),[g,a]=d.useState(!1),[r,v]=d.useState(null),[y,M]=d.useState("mine"),b=d.useCallback(async()=>{var n,s;i(!0);try{const l=await S.get("/api/notifications/preferences"),o=l&&l.data;if(!o||!Array.isArray(o.categories)||!Array.isArray(o.events))throw new Error("The notification settings service returned an unexpected response.");v(o),h(null)}catch(l){h(((s=(n=l==null?void 0:l.response)==null?void 0:n.data)==null?void 0:s.message)||l.message),v(null)}finally{i(!1)}},[]);d.useEffect(()=>{b()},[b]);const q=()=>{a(!0),setTimeout(()=>a(!1),2e3)},j=async(n,s={})=>{var l,o;u(!0);try{const x=y==="workspace"?"/api/notifications/preferences/workspace":"/api/notifications/preferences";await S.patch(x,{events:n,...s}),await b(),q()}catch(x){h(((o=(l=x==null?void 0:x.response)==null?void 0:l.data)==null?void 0:o.message)||x.message)}finally{u(!1)}},L=d.useMemo(()=>!r||!Array.isArray(r.categories)||!Array.isArray(r.events)?[]:r.categories.map(n=>({...n,events:r.events.filter(s=>s.category===n.id)})).filter(n=>n.events.length),[r]),f=y==="workspace";return e.jsxs(e.Fragment,{children:[e.jsx(G,{canEditWorkspace:!!(r!=null&&r.canEditWorkspace),scope:y,setScope:M,saving:c,saved:g}),e.jsxs("div",{className:"flex flex-col lg:flex-row gap-4 items-start",children:[e.jsxs("div",{className:"flex-1 min-w-0
1w-full space-y-4",children:[t&&!r&&e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(D,{})}),!t&&!r&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive",children:[e.jsx(C,{className:"mt-px h-4 w-4 shrink-0"}),e.jsx("span",{children:m||"Notification settings could not be loaded."})]}),r&&f&&e.jsxs("div",{className:"rounded-md border border-amber-500/40 bg-amber-500/10 p-3 text-xs text-amber-700 dark:text-amber-400",children:["You are editing what ",e.jsx("strong",{children:"everyone in this workspace"})," gets by default. Anyone who has already set their own preference for an event keeps it â this only changes the default they inherit."]}),r&&L.map(n=>e.jsxs("div",{className:w,children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold",children:n.label}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n.description})]}),e.jsx("div",{className:"divide-y divide-border/60",children:n.events.map(s=>{const o=(f?s.tenantSet:s.userSet).email===null,x=f?s.tenantSet.email??s.defaults.email:s.effective.email,k=N[s.severity]||N.info,O=s.deferrable?["off","immediate","daily","weekly"]:["off","immediate"];return e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3 py-3",children:[e.jsxs("div",{className:"min-w-[16rem] flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:s.label}),e.jsx("span",{className:`rounded border px-1.5 py-px text-[10px] uppercase tracking-wide ${k.className}`,children:k.label})]}),e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:s.description}),!s.deferrable&&e.jsx("p",{className:"mt-1 text-[11px] text-muted-foreground",children:"Cannot be batched â it is only worth sending while it still matters."}),!f&&o&&e.jsxs("p",{className:"mt-1 text-[11px] text-muted-foreground",children:["Following the workspace default (",A[s.effective.email],")."]}),!f&&!o&&e.jsx("button",{type:"button",onClick:()=>j({[s.id]:{email:null,inApp:null}}),className:"mt-1 text-[11px] text-primary hover:underline",children:"Follow the workspace default instead"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(T,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("select",{className:"rounded-md border bg-background px-2 py-1 text-sm",value:x,onChange:p=>j({[s.id]:{email:p.target.value}}),children:O.map(p=>e.jsx("option",{value:p,children:A[p]},p))})]})]},s.id)})})]},n.id)),r&&m&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive",children:[e.jsx(C,{className:"mt-px h-4 w-4 shrink-0"})," ",e.jsx("span",{children:m})]})]}),r&&e.jsxs("aside",{className:"w-full lg:w-80 flex-none space-y-4 lg:sticky lg:top-20 lg:max-h-[calc(100vh-6rem)] lg:overflow-y-auto",children:[e.jsx(P,{data:r,editingWorkspace:f,patch:j}),e.jsx(V,{})]})]})]})}function G({canEditWorkspace:t,scope:i,setScope:c,saving:u,saved:m}){return e.jsxs("div",{className:"flex items-center justify-between mb-6 flex-wrap gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(W,{to:"/settings",className:"rounded-lg border border-border p-1.5 text-muted-foreground hover:bg-accent hover:text-foreground","aria-label":"Back to settings",children:e.jsx(B,{className:"h-4 w-4"})}),e.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[e.jsx(I,{className:"w-6 h-6"})," Notifications"]}),u&&e.jsx(R,{className:"h-4 w-4 animate-spin text-muted-foreground"}),m&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-emerald-600",children:[e.jsx(_,{className:"h-3 w-3"})," Saved"]})]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1 max-w-3xl",children:"Everything that can cost you money or stop working quietly is already on. This page is for turning things down â you will still see everything in the app, whatever you choose here."})]}),t&&e.jsxs("div",{className:"inline-flex rounded-lg border p-0.5 text-sm",children:[e.jsxs("button",{type:"button",onClick:()=>c("mine"),className:`inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 ${i==="mine"?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,children:[e.jsx(F,{className:"h-3.5 w-3.5"})," Mine"]}),e.jsxs("button",{type:"button",onClick:()=>c("workspace"),className:`inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 ${i==="workspace"?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,children:[e.jsx(Q,{className:"h-3.5 w-3.5"})," Workspace default"]})]})]})}
1function P({data:t,editingWorkspace:i,patch:c}){var u,m,h,g;return e.jsxs("div",{className:w,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(U,{className:"w-5 h-5 text-link"}),e.jsx("h3",{className:"text-base font-semibold",children:"Quiet hours"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Hold non-urgent email until the morning. Critical alerts still come through â if you do not want waking for those, turn the event off outright rather than relying on this."}),i?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Quiet hours are personal. Switch to ",e.jsx("strong",{children:"Mine"})," to change yours."]}):e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm",children:[e.jsxs("label",{className:"flex items-center gap-1.5",children:[e.jsx("input",{type:"checkbox",checked:!!((u=t.quietHours)!=null&&u.enabled),onChange:a=>c({},{quietHours:{...t.quietHours||{},enabled:a.target.checked}})}),"Enabled"]}),e.jsx("span",{className:"text-muted-foreground",children:"from"}),e.jsx("select",{className:"rounded-md border bg-background px-2 py-1",value:H(((m=t.quietHours)==null?void 0:m.startMinute)??1200),onChange:a=>c({},{quietHours:{...t.quietHours||{},startMinute:Number(a.target.value)*60}}),children:E.map(a=>e.jsxs("option",{value:a,children:[String(a).padStart(2,"0"),":00"]},a))}),e.jsx("span",{className:"text-muted-foreground",children:"to"}),e.jsx("select",{className:"rounded-md border bg-background px-2 py-1",value:H(((h=t.quietHours)==null?void 0:h.endMinute)??480),onChange:a=>c({},{quietHours:{...t.quietHours||{},endMinute:Number(a.target.value)*60}}),children:E.map(a=>e.jsxs("option",{value:a,children:[String(a).padStart(2,"0"),":00"]},a))}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",((g=t.quietHours)==null?void 0:g.timezone)||"UTC",")"]})]})]})}function V(){return e.jsxs("div",{className:w,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{className:"w-5 h-5 text-link"}),e.jsx("h3",{className:"text-base font-semibold",children:"How delivery is decided"})]}),e.jsxs("ol",{className:"list-decimal space-y-1.5 pl-5 text-xs text-muted-foreground",children:[e.jsxs("li",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Your choice"})," for an event, if you made one."]}),e.jsxs("li",{children:["Otherwise the ",e.jsx("span",{className:"font-medium text-foreground",children:"workspace default"})," an admin set."]}),e.jsxs("li",{children:["Otherwise the ",e.jsx("span",{className:"font-medium text-foreground",children:"built-in default"})," â on for anything costly or silent, off for the noisy."]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'Each event resolves on its own, so changing one never touches another. "Off" always means off.'}),e.jsx("ul",{className:"space-y-2.5",children:Object.entries(N).map(([t,i])=>e.jsxs("li",{className:"space-y-1",children:[e.jsx("span",{className:`inline-flex rounded border px-1.5 py-px text-[10px] uppercase tracking-wide ${i.className}`,children:i.label}),e.jsx("p",{className:"text-xs text-muted-foreground",children:$[t]})]},t))}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[e.jsx("span",{className:"font-medium text-foreground",children:"Straight away · Daily summary · Weekly summary"})," set the email cadence. In-app notifications are always immediate."]})]})}export{K 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.