1import{r as o,j as e}from"./vendor-CIikcnY8.js";import{u as zt,r as wt,j as Ra,b as xe,d as za,E as la,l as Fa,F as Wa,A as Me,G as Ba,f as At,H as Fs,J as Ka,K as os,L as kt,M as js,N as Jt,O as ms,B as Be,Q as Ha,R as Ua,T as vt,m as Ws,t as Bs,U as Ks,P as V,S as tt,w as Qe,V as Pt,X as Rt,Y as ys,n as cs,Z as dt,_ as Hs,$ as _a,D as St,a0 as Ga,a1 as Us,a2 as qa,a3 as Qt,a4 as Va,a5 as Ya,a6 as ot,a7 as Ja,a8 as Qa,a9 as Za,aa as Xa,c as en,ab as tn,W as ks,ac as Lt,ad as sn,ae as an,v as _s,af as nn,ag as ln,ah as rn,ai as on,e as cn,i as dn}from"./index-CGFDy_im.js";import{R as ra,N as un}from"./NewTask-CjEkpOij.js";import{p as hn,M as pn,a as Zt,I as Gs,P as Xt,b as ia,c as oa,d as mn}from"./marks-4yZDxGID.js";import{P as bt,a as ct,p as fs,b as ca,c as fn}from"./priority-B-jcXK3z.js";import{l as gn,u as jn,s as qs,a as yn,b as kn}from"./Columns-hFsGuIft.js";import{r as xt}from"./rhythm-BAoaQXXZ.js";import{N as Nn,P as bn}from"./PlannerView-DjbF7sVf.js";import{R as Pe,A as gs,h as es,g as da,a as ua,b as ha,C as Vs}from"./bits-CxfvXRFo.js";import{f as xn,a as wn,F as pa,b as ma}from"./FileViewer-BEHlPJ7a.js";import{r as ds,u as fa,w as vn,U as ga,R as Sn}from"./RichText-B-l_x1Z2.js";import{u as In,M as Cn}from"./MentionMenu-_LkEDqRp.js";import{w as Dn}from"./history-DpyTbjEV.js";import"./mentions-Z6-aGvF_.js";const $t=["when","who","author","dept","project","zone","group","time","priority"],On={when:[170,230],who:[130,170],author:[130,170],dept:[110,200],project:[110,200],zone:[110,190],group:[110,190],time:[80,110],priority:[100,140]},En={min:64,max:720},Ys={min:160,max:1200,usual:320};function Tn(c,i){const[g,j]=On[c];return i?`${i}px`:`minmax(${g}px, ${j}px)`}const us={when:"Dates",who:"Who does it",author:"Who set it",dept:"Department",project:"Project",zone:"Zone of responsibility",group:"Task group",time:"Time in work",priority:"Priority"},$n={once:["when","who","project","group"],recurring:["when","who","dept"],holder:["when","who","zone","group"],mine:["when","who","author","project"]},Vt=6,Mt=8;function Mn(c,i,g){const j=g.height-c.bottom-Vt-Mt,w=c.top-Vt-Mt,M=i.height>j&&w>j,U=Math.max(0,M?w:j);return{top:M?Math.max(Mt,c.top-Vt-Math.min(i.height,U)):c.bottom+Vt,left:Math.max(Mt,Math.min(c.left,g.width-i.width-Mt)),maxHeight:U}}function Ns({children:c,onClose:i}){const g=o.useRef(null),[j,w]=o.useState(null);return o.useLayoutEffect(()=>{const M=g.current,U=M?.parentElement;if(!M||!U)return;const h=()=>{const v=Mn(U.getBoundingClientRect(),{width:M.offsetWidth,height:M.scrollHeight},{width:window.innerWidth,height:window.innerHeight});w(T=>T&&T.top===v.top&&T.left===v.left&&T.maxHeight===v.maxHeight?T:v)};h(),window.addEventListener("scroll",h,!0),window.addEventListener("resize",h);const E=typeof ResizeObserver>"u"?null:new ResizeObserver(h);return E&&Array.from(M.children).forEach(v=>E.observe(v)),()=>{window.removeEventListener("scroll",h,!0),window.removeEventListener("resize",h),E?.disconnect()}},[]),o.useEffect(()=>{const M=h=>{const E=h.target;g.current?.parentElement?.contains(E)||E instanceof Element&&E.closest(".pick-menu, .cal")||i()},U=h=>{h.key==="Escape"&&i()};return document.addEventListener("mousedown",M,!0),window.addEventListener("keydown",U,!0),()=>{document.removeEventListener("mousedown",M,!0),window.removeEventListener("keydown",U,!0)}},[i]),e.jsx("span",{className:"rule-pop",ref:g,style:j?{top:j.top,left:j.left,maxHeight:j.maxHeight}:{visibility:"hidden"},children:c})}const ja=["ð","ð","â¤ï¸","ð¥","ð","ð","ð","â
","â","ð","ð¤","ð","ð","ð®","ð¢","ð","ð¯","â¡"],An="orgami:task-chat-width",Pn={min:320,max:760,step:16},Yt=c=>c.byName||c.byEmail||"â",Js=c=>c.trim().slice(0,1).toUpperCase()||"?",hs=c=>Ba(c.mime),Ln=()=>e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"M15.5 7.5v9a4.5 4.5 0 0 1-9 0V6a3 3 0 0 1 6 0v10a1.5 1.5 0 0 1-3 0V7.5"})}),Rn=()=>e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M12 20h9"}),e.jsx("path",{d:"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4z"})]}),zn=()=>e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M3 6h18"}),e.jsx("path",{d:"M8 6V4a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v2"}),e.jsx("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"})]}),ps=({filled:c=!1})=>e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:c?"currentColor":"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M9 3.5h6l-1 5.5 3.5 3.5v2h-11v-2L10 9z"}),e.jsx("path",{d:"M12 14.5V21"})]}),Qs=({size:c=14})=>e.jsxs("svg",{width:c,height:c,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M8.5 14.5a4.5 4.5 0 0 0 7 0"}),e.jsx("path",{d:"M9 9.5h.01M15 9.5h.01"})]}),Fn=()=>e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M5 12h14"}),e.jsx("path",{d:"m13 6 6 6-6 6"})]}),Wn=[...ja,"ð","ð","ð","ð","ð
","ð¬","ð´","ð¥³","ð¡","ð¤","ð","ð","ðª","ð¤·","ð¡","ð","ð","â°","ð
","ð","ð§","ð¬","â","â"];function Zs({list:c,label:i,onPick:g,onClose:j}){return o.useEffect(()=>{const w=M=>{M.key==="Escape"&&M.stopPropagation()};return window.addEventListener("keydown",w,!0),()=>window.removeEventListener("keydown",w,!0)},[]),e.jsx(Ns,{onClose:j,children:e.jsx("span",{className:"emoji-grid",role:"listbox","aria-label":i,children:c.map(w=>e.jsx("button",{type:"button",role:"option","aria-selected":!1,className:"emoji-one",onClick:()=>g(w),children:w}
1,w))})})}function Bn({taskId:c,me:i,people:g,events:j=[],onUndo:w,say:M,version:U}){const h=zt(),E=wt(i,"comments.create"),v=wt(i,"comments.update"),T=wt(i,"comments.delete"),[b,G]=o.useState(null),[_,pe]=o.useState([]),ee=o.useRef(0),A=o.useRef(Promise.resolve()),fe=o.useRef(0),Z=o.useRef(new Map),[$e,l]=o.useState(!1),Y=o.useRef(null),[W,r]=o.useState([]),P=`chat:${c}`,[te,K]=o.useState(()=>ds(P)??""),[le,re]=o.useState(null),[Se,oe]=o.useState(null),[we,Ie]=o.useState([]),[Ke,qe]=o.useState(!1),[L,ie]=o.useState(null),[y,a]=o.useState("all"),[J,x]=o.useState(null),[q,Q]=o.useState(!1),[Le,Ve]=o.useState(null),ke=o.useRef(null),ut=o.useRef(null),He=Ra({storageKey:An,range:Pn,side:"left",inside:!0}),{uploads:ge,inFlight:ht,track:ce}=fa(),Ze=In({box:ke,value:te,onChange:n=>K(n),place:"above",people:g}),se=o.useRef(c);se.current=c;const Re=o.useRef(c);o.useEffect(()=>{Re.current!==c||le||vn(P,te)},[te,le,c,P]),o.useEffect(()=>{Re.current!==c&&(Re.current=c,re(null),K(ds(`chat:${c}`)??""),pe([]))},[c]),o.useEffect(()=>{const n=Y.current;n&&_.length&&(n.scrollTop=n.scrollHeight)},[_.length]);const R=()=>{re(null),K(ds(P)??"")},z=o.useMemo(()=>{const n=new Map;for(const N of[...b??[],..._]){const f=N.byUser??N.byEmail??"â";n.has(f)||n.set(f,n.size%2===1)}return n},[b,_]),ze=n=>z.get(n.byUser??n.byEmail??"â")===!0,B=o.useMemo(()=>{const n=(b??[]).map(f=>({at:new Date(f.at).getTime(),msg:f}));for(const f of j)n.push({at:new Date(`${f.at}T12:00:00Z`).getTime(),run:f});for(const f of W)n.push({at:new Date(f.at).getTime(),did:f});n.sort((f,s)=>f.at-s.at);const N=n.length?n[n.length-1].at:0;for(const f of _){const s=Z.current.get(f.id);(b??[]).some(k=>k.byUser===f.byUser&&k.body===f.body&&!s?.has(k.id))||n.push({at:Math.max(N,new Date(f.at).getTime()),msg:f})}return n},[b,j,W,_]),ne=o.useMemo(()=>i.personId?g.find(n=>n.id===i.personId)??null:null,[i.personId,g]);async function je(n){const N=[...n??[]];if(!N.length||!E)return;const f=c,s=N.filter(ae=>!ht(ae)),u=N.filter(ae=>ht(ae));u.length&&oe(h("Already on its way: {name}",{name:u.map(ae=>ae.name).join(", ")}));const k=await Promise.all(s.map(ae=>ce(ae,()=>xe.uploadTaskFile(f,ae)).then($=>({up:$,no:null}),$=>({up:null,no:`${ae.name} â ${h($.message)}`})))),D=k.map(ae=>ae.up).filter(ae=>ae!==null);if(se.current!==f){for(const ae of D)xe.dropTaskFile(f,ae.id).catch(()=>{});return}D.length&&Ie(ae=>[...ae,...D]);const X=k.map(ae=>ae.no).filter(Boolean);(X.length||!u.length)&&oe(X.length?X.join("; "):null)}function Ne(n){Ie(N=>N.filter(f=>f.id!==n.id)),xe.dropTaskFile(c,n.id).catch(()=>{})}const Ce=o.useRef([]);Ce.current=we,o.useEffect(()=>()=>{for(const n of Ce.current)xe.dropTaskFile(c,n.id).catch(()=>{});Ie([])},[c]);const De=o.useCallback((n=!0)=>{xe.taskComments(c).then(G,N=>!n&&oe(h(N.message))),xe.taskEvents(c).then(r,()=>{})},[c]);o.useEffect(()=>{G(null),De(!1)},[c,De]),za(()=>De()),o.useEffect(()=>{Fs(c);const n=la("task",s=>{s.taskId===c&&De()}),N=window.setInterval(()=>{!document.hidden&&!Ka()&&De()},6e4),f=()=>!document.hidden&&De();return document.addEventListener("visibilitychange",f),()=>{Fs(null),n(),window.clearInterval(N),document.removeEventListener("visibilitychange",f)}},[c,De]),o.useEffect(()=>{U&&De()},[U,De]),o.useEffect(()=>{const n=ke.current;n&&(n.style.height="auto",n.style.height=`${Math.min(n.scrollHeight+2,200)}px`)},[te]);function Ye(){const n=te.trim();if(le){n&&!$e&&pt(le,n);return}if(!n&&!we.length)return;const N=c,f=we,s={id:`tmp-${++fe.current}`,taskId:N,body:n,byUser:i.id,byEmail:i.email,byName:ne?.fullName||i.name||null,byPerson:i.personId??null,byPhoto:ne?.photoVersion??null,at:new Date().toISOString(),editedAt:null,files:f,pinnedAt:null,reactions:[]};Z.current.set(s.id,new Set((b??[]).map(k=>k.id))),pe(k=>[...k,s]),Ie([]),K(""),oe(null),a("all");const u=async()=>{try{const k=await xe.addTaskComment(N,n,f.map(D=>D.id));se.current===N&&G(D=>(D??[]).some(X=>X.id===k.id)?D:[...D??[],k])}catch(k){se.current===N&&(K(D=>D.trim()?`${n} 2${D}`:n),Ie(D=>[...f,...D]),S(k))}finally{ee.current-=1,Z.current.delete(s.id),pe(k=>k.filter(D=>D.id!==s.id))}};ee.current+=1,A.current=ee.current>1?A.current.then(u):u()}async function pt(n,N){const f=(b??[]).find(s=>s.id===n)?.body;l(!0),de(n,s=>({...s,body:N}));try{const s=await xe.editTaskComment(c,n,N);de(n,u=>({...s,files:u.files,reactions:u.reactions})),R(),oe(null)}catch(s){f!==void 0&&de(n,u=>({...u,body:f})),S(s)}finally{l(!1)}}async function st(n){if(await At(h("Delete this message?"),{okLabel:"Delete",danger:!0}))try{await xe.deleteTaskComment(c,n.id),G(N=>(N??[]).filter(f=>
2f.id!==n.id))}catch(N){oe(h(N instanceof Error?N.message:"Something went wrong"))}}const de=(n,N)=>G(f=>(f??[]).map(s=>s.id===n?N(s):s)),S=n=>oe(h(n instanceof Error?n.message:"Something went wrong"));async function Oe(n){const N=n.pinnedAt??null;de(n.id,f=>({...f,pinnedAt:N?null:new Date().toISOString()}));try{const f=await xe.pinTaskComment(c,n.id,!N);de(n.id,s=>({...s,pinnedAt:f.pinnedAt??null})),oe(null)}catch(f){de(n.id,s=>({...s,pinnedAt:N})),S(f)}}const lt=ne?.fullName||i.name||i.email;async function ue(n,N){const f=n.reactions??[],s=f.find(k=>k.emoji===N),u=s?.mine?f.map(k=>k.emoji===N?{...k,count:k.count-1,mine:!1,by:k.by.filter(D=>D!==lt)}:k).filter(k=>k.count>0):s?f.map(k=>k.emoji===N?{...k,count:k.count+1,mine:!0,by:[...k.by,lt]}:k):[...f,{emoji:N,count:1,mine:!0,by:[lt]}];de(n.id,k=>({...k,reactions:u}));try{const k=await xe.reactTaskComment(c,n.id,N);de(n.id,D=>({...D,reactions:k.reactions??[]})),oe(null)}catch(k){de(n.id,D=>({...D,reactions:f})),S(k)}}function It(n){const N=ke.current,f=N?.selectionStart??te.length,s=N?.selectionEnd??f;K(te.slice(0,f)+n+te.slice(s)),Q(!1),requestAnimationFrame(()=>{N?.focus(),N?.setSelectionRange(f+n.length,f+n.length)})}function me(n){a("all"),Ve(n)}o.useEffect(()=>{if(!Le||y!=="all")return;document.getElementById(`msg-${Le}`)?.scrollIntoView?.({block:"center"});const n=window.setTimeout(()=>Ve(null),1600);return()=>window.clearTimeout(n)},[Le,y]);const Ee=(b??[]).filter(n=>n.pinnedAt),be=Fa(h.lang),at=n=>new Date(n).toLocaleTimeString(be,{hour:"2-digit",minute:"2-digit"}),Fe=n=>new Date(n).toLocaleString(be,{dateStyle:"medium",timeStyle:"short"}),Ct=n=>{const N=new Date(n),f=N.getFullYear()===new Date().getFullYear()?{day:"numeric",month:"long"}:{dateStyle:"long"};return N.toLocaleDateString(be,f)},ve=n=>n.byPerson?e.jsx(Me,{person:{id:n.byPerson,fullName:Yt(n),photoVersion:n.byPhoto},size:32,className:"chat-face",title:Yt(n)}):e.jsx("span",{className:`chat-ava ${n.byUser===i.id?"mine":""}`,"aria-hidden":"true",children:Js(Yt(n))}),Dt=n=>{const N=n.filter(hs),f=n.filter(s=>!hs(s));return e.jsxs(e.Fragment,{children:[N.length>0&&e.jsx("div",{className:"chat-shots",children:N.map(s=>e.jsx("button",{type:"button",className:"chat-shot",title:s.name||h("Open"),onClick:()=>ie(s),children:e.jsx("img",{src:xe.taskFileUrl(c,s.id),alt:s.name,loading:"lazy"})},s.id))}),f.length>0&&e.jsx("div",{className:"chat-files",children:f.map(s=>e.jsx(ma,{taskId:c,file:s,onOpen:ie},s.id))})]})},rt=(n,N,f=!1)=>{const s=n.byUser===i.id,u=!f&&ze(n),k=n.reactions??[],D=n.id.startsWith("tmp-");return e.jsxs("li",{id:f||D?void 0:`msg-${n.id}`,className:`chat-msg ${u?"right":"left"} ${N?"run":""} ${n.pinnedAt?"pinned":""} ${!f&&Le===n.id?"lit":""} ${D?"sending":""}`,children:[N?e.jsx("span",{className:"chat-gutter","aria-hidden":"true"}):ve(n),e.jsxs("div",{className:"chat-bubble",children:[!N&&e.jsxs("strong",{className:"chat-who",children:[Yt(n),s&&e.jsxs("span",{className:"chat-you",children:[" · ",h("you")]})]}),n.body&&e.jsx("p",{className:"chat-body",children:e.jsx(Cn,{text:n.body})}),n.files.length>0&&Dt(n.files),k.length>0&&e.jsx("span",{className:"chat-reactions",children:k.map(X=>e.jsxs("button",{type:"button",className:`chat-reaction ${X.mine?"mine":""}`,"aria-pressed":X.mine,disabled:!E,title:X.by.join(", "),onClick:()=>ue(n,X.emoji),children:[e.jsx("span",{"aria-hidden":"true",children:X.emoji}),e.jsx("span",{className:"chat-reaction-n",children:X.count})]},X.emoji))}),e.jsxs("span",{className:"chat-when",title:Fe(n.at),children:[n.pinnedAt&&!f&&e.jsx("span",{className:"chat-pin-mark",title:h("Pinned"),children:e.jsx(ps,{filled:!0})}),D?h("sendingâ¦"):f?Fe(n.at):at(n.at),n.editedAt&&` · ${h("edited")}`]})]}),!D&&(E||s&&(v||T))&&e.jsxs("span",{className:`chat-acts ${J===n.id?"open":""}`,children:[E&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"chat-pick",children:[e.jsx("button",{type:"button",className:"chat-act",title:h("React"),"aria-label":h("React"),"aria-expanded":J===n.id,onClick:()=>x(J===n.id?null:n.id),children:e.jsx(Qs,{})}),J===n.id&&e.jsx(Zs,{list:ja,label:h("React"),onPick:X=>{x(null),ue(n,X)},onClose:()=>x(null)})]}),e.jsx("button",{type:"button",className:`chat-act ${n.pinnedAt?"on":""}`,"aria-pressed":!!n.pinnedAt,title:h(n.pinnedAt?"Unpin the message":"Pin the message"),"aria-label":h(n.pinnedAt?"Unpin the message":"Pin the message"),onClick:()=>Oe(n),children:e.jsx(ps,{filled:!!n.pinnedAt})})]}),f&&e.jsx("button",{type:"button",className:"chat-act",title:h("Show in the discussion"),"aria-label":h("Show in the discussion"),onClick:()=>me(n.id),children:e.jsx(Fn,{})}),!f&&s&&v&&e.jsx("button",{type:"button",className:"chat-act",title:h("edit"),"aria-label":h("edit"),onClick:()=>{re(n.id),K(n.body),window.setTimeout(()=>
2ke.current?.focus(),0)},children:e.jsx(Rn,{})}),!f&&s&&T&&e.jsx("button",{type:"button",className:"chat-act danger",title:h("delete"),"aria-label":h("delete"),onClick:()=>st(n),children:e.jsx(zn,{})})]})]})};return e.jsxs("section",{ref:He.ref,className:"chat-card","data-help":"task-chat",style:He.width!=null?{"--chat-w":`${He.width}px`}:void 0,children:[He.edge,e.jsxs("header",{className:"chat-card-head",role:"tablist","aria-label":h("Discussion"),children:[e.jsxs("button",{type:"button",role:"tab","aria-selected":y==="all",className:`chat-tab ${y==="all"?"on":""}`,onClick:()=>a("all"),children:[h("Discussion"),b&&b.length+_.length>0&&e.jsx("span",{className:"chat-count",children:b.length+_.length})]}),e.jsxs("button",{type:"button",role:"tab","aria-selected":y==="pinned",className:`chat-tab ${y==="pinned"?"on":""}`,onClick:()=>a("pinned"),children:[e.jsx(ps,{}),h("Pinned"),Ee.length>0&&e.jsx("span",{className:"chat-count",children:Ee.length})]})]}),e.jsxs("div",{className:"chat-card-body",ref:Y,children:[Se&&e.jsx("p",{className:"error",children:Se}),b===null&&e.jsx(Wa,{lines:3,className:"chat-skel"}),y==="all"&&b?.length===0&&_.length===0&&e.jsx("p",{className:"hint",children:h("Nothing said yet.")}),y==="pinned"&&b!==null&&Ee.length===0&&e.jsx("p",{className:"hint",children:h("Nothing is pinned yet. The pin beside a message
2keeps it here.")}),y==="pinned"&&e.jsx("ul",{className:"chat-list chat-pinned",children:Ee.map(n=>e.jsx(o.Fragment,{children:rt(n,!1,!0)},n.id))}),e.jsx("ul",{className:"chat-list",hidden:y!=="all",children:B.map((n,N)=>{const f=B[N-1],s=new Date(n.at).toDateString(),k=(!f||new Date(f.at).toDateString()!==s)&&e.jsx("li",{className:"chat-day",children:e.jsx("span",{children:Ct(new Date(n.at).toISOString())})},`d${n.at}`);if("did"in n){const $=n.did;return e.jsxs(o.Fragment,{children:[k,e.jsxs("li",{className:"chat-event",children:[$.byPerson?e.jsx(Me,{person:{id:$.byPerson,fullName:$.byName??"",photoVersion:$.byPhoto},size:20,className:"chat-face"}):e.jsx("span",{className:"chat-event-mark","aria-hidden":"true"}),e.jsxs("span",{className:"chat-event-text",children:[$.byName&&e.jsx("strong",{children:$.byName})," ",M($)]}),e.jsx("span",{className:"chat-when",title:Fe($.at),children:at($.at)})]})]},`e${$.id}`)}if("run"in n){const $=n.run;return e.jsxs(o.Fragment,{children:[k,e.jsxs("li",{className:`chat-event ${$.state}`,children:[$.byPerson?e.jsx(Me,{person:{id:$.byPerson,fullName:$.by??"",photoVersion:$.byPhoto},size:20,className:"chat-face"}):e.jsx("span",{className:`run ${$.state}`,"aria-hidden":"true"}),e.jsxs("span",{className:"chat-event-text",children:[$.by&&e.jsx("strong",{children:$.by})," ",$.state==="done"?h("marked it done"):h("skipped it")," · ",$.on]}),e.jsx("span",{className:"chat-when",title:Fe(`${$.at}T12:00:00Z`),children:$.at.split("-").reverse().join(".")}),w&&e.jsx("button",{type:"button",className:"link",onClick:()=>w($.on),children:h("take back")})]})]},`r${$.on}`)}const D=n.msg,X=f&&"msg"in f?f.msg:null,ae=!!X&&X.byUser===D.byUser&&new Date(D.at).getTime()-new Date(X.at).getTime()<10*6e4;return e.jsxs(o.Fragment,{children:[k,rt(D,ae)]},D.id)})})]}),(E||le)&&e.jsxs("div",{className:`chat-compose ${Ke?"dropping":""}`,"data-hotkey-scope":!0,onDragOver:n=>{E&&(n.preventDefault(),qe(!0))},onDragLeave:()=>qe(!1),onDrop:n=>{n.preventDefault(),qe(!1),je(n.dataTransfer.files)},children:[e.jsxs("div",{className:"chat-compose-side",children:[ne?e.jsx(Me,{person:ne,size:32,className:"chat-face",title:ne.fullName}):e.jsx("span",{className:"chat-ava mine","aria-hidden":"true",children:Js(i.name||i.email)}),E&&!le&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"chat-clip",title:h("Attach a file"),"aria-label":h("Attach a file"),onClick:()=>ut.current?.click(),children:e.jsx(Ln,{})}),e.jsx("input",{ref:ut,type:"file",multiple:!0,hidden:!0,onChange:n=>{je(n.target.files),n.target.value=""}})]}),e.jsxs("span",{className:"chat-pick",children:[e.jsx("button",{type:"button",className:"chat-clip",title:h("Emoji"),"aria-label":h("Emoji"),"aria-expanded":q,onClick:()=>Q(n=>!n),children:e.jsx(Qs,{size:16})}),q&&e.jsx(Zs,{list:Wn,label:h("Emoji"),onPick:It,onClose:()=>Q(!1)})]})]}),e.jsxs("div",{className:"chat-compose-main",children:[e.jsx(ga,{files:ge}),we.length>0&&e.jsx("div",{className:"chat-pending",children:we.map(n=>hs(n)?e.jsxs("span",{className:"chat-shot",children:[e.jsx("img",{src:xe.taskFileUrl(c,n.id),alt:n.name}),e.jsx("button",{type:"button",className:"shot-x",title:h("Remove"),"aria-label":h("Remove"),onClick:()=>Ne(n),children:"Ã"})]},n.id):e.jsxs("span",{className:"chat-file pending",children:[e.jsx("span",{className:"chat-file-ext","aria-hidden":"true",children:xn(n)}),e.jsxs("span",{className:"chat-file-main",children:[e.jsx("span",{className:"chat-file-name",children:n.name||h("File")}),e.jsx("span",{className:"hint",children:wn(n.size)})]}),e.jsx("button",{type:"button",className:"shot-x",title:h("Remove"),"aria-label":h("Remove"),onClick:()=>Ne(n),children:"Ã"})]},n.id))}),e.jsx("textarea",{ref:ke,rows:1,value:te,"data-hotkey":"keep",placeholder:h(le?"Change the messageâ¦":"Write something, or drop a fileâ¦"),onChange:n=>{K(n.target.value),Ze.onType(n.target.value,n.target.selectionStart)},onPaste:n=>{E&&!le&&n.clipboardData.files.length&&(n.preventDefault(),je(n.clipboardData.files))},onKeyDown:n=>{Ze.onKeyDown(n)||(n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),Ye()),n.key==="Escape"&&le&&R())}}),Ze.menu,e.jsx("div",{className:"chat-compose-foot",children:e.jsxs("span",{className:"chat-acts",children:[le&&e.jsx("button",{type:"button",className:"btn small",onClick:R,children:h("Cancel")}),e.jsx("button",{type:"button",className:"btn small primary","data-hotkey":le?"save submit":"submit",disabled:!te.trim()&&!we.length||$e,onClick:Ye,children:h(le?"Save":"Send")})]})})]})]}),L&&e.jsx(pa,{taskId:c,file:L,onClose:()=>ie(null)})]})}function Kn({task:c,all:i,groups:g,actions:j,onOpen:w,departments:M,companies:U,people:h,projects:E,tools:v,goals:T,onOpenHolder:b,onOpenDept:G,onOpenPerson:_,back:pe,onAddZone:ee,me:A,refresh:fe,onBack:Z,onDelete:$e}){const l=zt(),[Y,W]=o.useState(null),[r,P]=o.useState(!1),[te,K]=o.useState(""),le=o.useRef(!1),[re,Se]=o.useState(""),[oe,we]=o.useState(!1),Ie=o.useRef(null),[Ke,qe]=o.useState(null),[L,ie]=o.useState(!1),y=!!Y&&Y.id===c.id&&Date.parse(Y.updatedAt)>Date.parse(c.updatedAt),a=Y?.id===c.id?y?{...c,...Y}:{...c,details:Y.details,checks:Y.checks,files:Y.files,links:Y.links,runs:Y.runs}
2:c,J=[c.updatedAt,fe,c.state,c.title,c.hasDetails,(c.assigneeIds??[]).join(","),c.dueOn,c.groupIds.join(","),c.tags.join(","),c.areaIds.join(","),c.people.length,c.checksTotal,c.checksDone,c.filesTotal,c.subtasks,c.nextDue,c.projectId,c.toolId,c.departmentId].join("|"),[x,q]=o.useState(()=>os(c.effortDays)),[Q,Le]=o.useState(()=>c.effortDays!=null?String(kt(c.effortDays,os(c.effortDays))):"");o.useEffect(()=>{const s=a.effortDays,u=s==null||kt(s,x)>=.01?x:os(s);q(u),Le(s!=null?String(kt(s,u)):"")},[a.id,a.effortDays]);function Ve(){const s=Q.trim().replace(",","."),u=s?Number(s):null,k=u!=null&&Number.isFinite(u)&&u>0?Xa(u,x):null;k!==(a.effortDays??null)&&B({effortDays:k}),Le(k!=null?String(kt(k,x)):"")}const[ke,ut]=o.useState(0);o.useEffect(()=>la("task",s=>{s.taskId===c.id&&ut(u=>u+1)}),[c.id]),o.useEffect(()=>{let s=!0;return xe.task(c.id).then(u=>s&&W(u),()=>{}),()=>{s=!1}},[c.id,J,ke]);const He=i.filter(s=>s.parentId===a.id),ge=a.parentId?i.find(s=>s.id===a.parentId)??null:null,ht=[...new Set(i.flatMap(s=>s.tags))].sort();o.useEffect(()=>{const s=u=>{u.key==="Escape"&&!Za(u.target)&&Z()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[Z]);const ce=new Map(h.map(s=>[s.id,s])),Ze=js(h,M,U),se=[...E,...v],Re=s=>s&&U.find(u=>u.id===s)?.name||"",R=a.departmentId?M.find(s=>s.id===a.departmentId):null,z=a.projectId||a.toolId?se.find(s=>s.id===(a.projectId??a.toolId)):null,ze=z?.parentId?se.find(s=>s.id===z.parentId):null,B=s=>j.patch(a.id,s),ne=a.kind==="recurring",je=a.assigneeIds??[],Ne=je.length===1?ce.get(je[0])??null:null,Ce=Jt(A,a),De=!!A.personId&&je.includes(A.personId),Ye=a.authorId?ce.get(a.authorId)??null:null,pt=ms(A,a),st=z?g.filter(s=>s.projectId===z.id||s.toolId===z.id):[],de=wt(A,"tasks.create")&&!a.readOnly,S=Be(A,a.kind,"update")&&!a.readOnly,Oe=Be(A,a.kind,"delete")&&!a.readOnly,lt=!a.readOnly&&Ha(A,a),ue=S&&Be(A,a.kind,"private"),It=Be(A,a.kind,"create")&&!a.readOnly,me=s=>Be(A,s.kind,"update")&&!s.readOnly&&!a.readOnly,Ee=hn(a,i),be=Ee?[...new Set([...a.authorId?[a.authorId]:[],...je])].map(s=>ce.get(s)).filter(s=>!!s):[],[at,Fe]=o.useState(!1),Ct=!!z&&!!ee&&wt(A,v.some(s=>s.id===z.id)?"tools.update":"projects.update"),ve=s=>[...s.dataTransfer.types].includes("Files"),{uploads:Dt,inFlight:rt,track:n}=fa(),N=s=>rt(s)?Promise.resolve():n(s,()=>j.addFile(a.id,s)),f=s=>!!s.target.closest?.(".chat-compose, .rich");return e.jsxs("div",{className:`task-page ${L?"dropping":""}`,"data-drop":l("Drop the file to keep it on the task"),onDragOver:s=>{if(!(!S||!ve(s))){if(f(s))return ie(!1);s.preventDefault(),s.dataTransfer.dropEffect="copy",ie(!0)}},onDragLeave:s=>{s.currentTarget.contains(s.relatedTarget)||ie(!1)},onDrop:async s=>{if(ie(!1),!S||s.defaultPrevented||f(s))return;const u=[...s.dataTransfer.files];if(u.length){s.preventDefault();for(const k of u)await N(k)}},children:[e.jsxs("div",{className:"task-page-main",children:[e.jsx(ga,{files:Dt,className:"task-uploading"}),e.jsxs("div",{className:"task-page-head",children:[e.jsxs("button",{type:"button",className:"back-link",onClick:Z,children:["â ",pe?l("Back to {where}",{where:pe.label}):l(ne?"Back to the recurring ones":"Back to the tasks")]}),e.jsx("span",{className:`task-kind ${ne?"recurring":""}`,children:l(ne?"Recurring task":"Task")}),pt.map(s=>e.jsx("span",{className:`task-role ${s}`,children:l(Ua[s])},s)),e.jsxs("div",{className:"task-page-actions","data-help":"task-actions",children:[e.jsx("button",{type:"button",className:"btn small",onClick:async()=>{const s=window.location.origin+vt({tab:ne?"recurring":"tasks",taskId:a.id});try{await navigator.clipboard.writeText(s),we(!0),window.setTimeout(()=>we(!1),2e3)}catch{window.prompt(l("Copy the link"),s)}},children:l(oe?"Link copied":"Share")}),It&&e.jsx("button",{type:"button",className:"btn small",disabled:at,title:l("A new task with the same description, people, dates, tags and checklist. Subtasks, files, comments and time are not copied."),onClick:async()=>{Fe(!0);const s=await j.copy(a.id,{checks:S});Fe(!1),s&&w(s.id)},children:at?"â¦":l("Copy")}),S?e.jsx("button",{type:"button",className:`btn small ${a.aiReads?"":"on"}`,title:a.aiReads?l("The assistant reads this task. Press to close it."):l("Closed from the assistant: it neither reads nor changes this task. Press to open it."),onClick:()=>B({aiReads:!a.aiReads}),children:a.aiReads?l("Assistant sees it"):l("Hidden from the assistant")}):!a.aiReads&&e.jsx("span",{className:"hint",children:l("Hidden from the assistant")}),lt?e.jsx("button",{type:"button",className:`btn small ${a.isPrivate?"on":""}`,"aria-pressed":!!a.isPrivate,title:l("Only its author, its assignees and its guests see a private task â not even the administrator"),onClick:()=>B({isPrivate:!a.isPrivate}),children:a.isPrivate?l("Make open"):l("Make private")}):null,Oe&&e.jsx("button",{type:"button",className:"btn small danger",onClick:$e,children:l("Delete")})]})]}),(z||R)&&e.jsxs("nav",{className:"crumbs","aria-label":l("Where this is"),children:[z&&e.jsxs(e.Fragment,{children:[ze&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"link","data-ctx":`holder:${ze.id}`,onClick:()=>b(ze.id),children:ze.name}),e.jsx("span",{className:"crumb-sep","aria-hidden":"true",children:"âº"})]}),e.jsx("button",{type:"button",className:"link","data-ctx":`holder:${z.id}`,onClick:()=>b(z.id),children:z.name})]}),z&&R&&e.jsx("span",{className:"crumb-sep","aria-hidden":"true",children:"·"}),R&&e.jsxs("span",{className:"crumb-dept",children:[Re(R.companyId)," · ",e.jsx("button",{type:"button",className:"link","data-ctx":`department:${R.id}`,onClick:()=>G(R.id),children:R.name})]})]}),Ee&&e.jsxs("div",{className:`private-banner ${Ee.from}`,role:"note",children:[e.jsx("span",{className:"private-banner-icon","aria-hidden":"true",children:e.jsx(pn,{})}),e.jsxs("div",{className:"private-banner-text",children:[e.jsx("strong",{children:l("Private task")}),Ee.from==="own"?e.jsx("span",{children:l("Only its author, its assignees and its guests see it â not its department, not the head, not those pulled in, not the administrator.")}):e.jsxs("span",{children:[l("Private with the task it belongs to:")," ",e.jsx("button",{type:"button",className:"link","data-ctx":`task:${Ee.parent.id}`,onClick:()=>w(Ee.parent.id),children:Ee.parent.title})]})]}),be.length>0&&e.jsx("span",{className:"private-banner-who",title:l("Who sees it"),children:be.map(s=>e.jsx(Me,{person:s,size:22,title:s.fullName},s.id))})]}),e.jsx(Ws,{className:"task-page-title",oneClick:!0,readOnly:!S,value:a.title,placeholder:l("The task"),onCommit:s=>s.trim()&&B({title:s.trim()})}),e.jsxs("div",{className:"task-props access-lists",children:[e.jsx(Bs,{kind:"tasks",id:a.id,people:h,editable:ue,className:"prop",labelClassName:"prop-label"},a.id),ue&&e.jsx(Bs,{list:"hidden",kind:"tasks",id:a.id,people:h,onIt:[...je,...a.people.map(s=>s.personId)],self:A.personId,editable:!0,className:"prop",labelClassName:"prop-label"},`h-${a.id}`)]}
2),(a.parentId||S&&!ne)&&e.jsx("div",{className:"task-nesting","data-help":"task-parent",children:a.parentId?e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"task-nesting-says",children:[e.jsx(Zt,{})," ",l("Subtask of")]}),ge?e.jsx("a",{className:"task-title",href:vt({tab:ge.kind==="recurring"?"recurring":"tasks",taskId:ge.id}),onClick:s=>{s.metaKey||s.ctrlKey||s.shiftKey||s.altKey||s.button!==0||(s.preventDefault(),w(ge.id))},children:ge.title}):e.jsx("span",{className:"hint",children:l("a task you do not see")}),S&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"ghost-btn",onClick:async()=>{const s=await Ks(l,i,a);s&&B({parentId:s})},children:l("Move under another taskâ¦")}),e.jsx("button",{type:"button",className:"ghost-btn",onClick:()=>B({parentId:null}),children:l("Make it a task of its own")})]})]}):e.jsxs("button",{type:"button",className:"ghost-btn",onClick:async()=>{const s=await Ks(l,i,a);s&&B({parentId:s})},children:[e.jsx(Zt,{})," ",l("Make it a subtaskâ¦")]})}),e.jsxs("div",{className:"task-props",children:[e.jsxs("div",{className:"prop","data-help":"task-state",children:[e.jsx("span",{className:"prop-label",children:l("State")}),e.jsx("span",{className:"prop-value",children:S?e.jsx(V,{className:`task-state ${a.state}`,value:a.state,options:Pt(l,ne,Rt(A,a,Ze)),onChange:s=>ne&&s==="done"?j.done(a.id):B({state:s}),children:e.jsxs("span",{className:"state-chip",children:[e.jsx(tt,{state:a.state}),l(Qe[a.state])]})}):e.jsx(Pe,{className:`task-state ${a.state}`,children:e.jsxs("span",{className:"state-chip",children:[e.jsx(tt,{state:a.state}),l(Qe[a.state])]})})})]}),e.jsxs("div",{className:"prop",children:[e.jsx("span",{className:"prop-label",children:l("Priority")}),e.jsx("span",{className:"prop-value",children:S?e.jsx(V,{className:"task-pick",value:a.priority??"",options:()=>fs(l),onChange:s=>B({priority:ca(s)}),children:e.jsxs("span",{className:`prio-chip ${a.priority?"":"muted"}`,children:[e.jsx(bt,{priority:a.priority}),l(a.priority?ct[a.priority]:"No priority")]})}):e.jsx(Pe,{className:"task-pick",children:e.jsxs("span",{className:`prio-chip ${a.priority?"":"muted"}`,children:[e.jsx(bt,{priority:a.priority}),l(a.priority?ct[a.priority]:"No priority")]})})})]}),!ne&&e.jsxs("div",{className:"prop",children:[e.jsx("span",{className:"prop-label","data-help":"task-time",children:l("Time in work")}),e.jsxs("span",{className:"prop-value",children:[a.workedMs>0||a.workStartedAt?e.jsx(ys,{task:a}):e.jsx("span",{className:"muted",children:l("The clock has not started")}),S&&a.state!=="done"&&e.jsxs("button",{type:"button",className:`time-btn ${a.workStartedAt?"on":""}`,title:a.workStartedAt?l("Hold the clock â the task stays in work"):a.state==="in_progress"?l("Pick the clock up again"):l("Take it into work â the clock starts"),onClick:()=>a.state==="in_progress"?j.timer(a.id,!a.workStartedAt):B({state:"in_progress"}),children:[e.jsx("span",{"aria-hidden":"true",children:a.workStartedAt?"â¸":"â¶"}),a.workStartedAt?l("Pause"):a.state==="in_progress"&&a.workedMs>0?l("Carry on"):l("Start")]}),a.effortDays!=null&&(a.workedMs>0||a.workStartedAt)&&e.jsx("span",{className:"hint",children:l("of {n} estimated",{n:cs(a.effortDays,l)})}),S&&a.workedMs>0&&!a.workStartedAt&&e.jsx("button",{type:"button",className:"ghost-btn small",title:l("Correct the time by hand"),onClick:async()=>{const s=await dt(l("How much time was really spent?"),{value:cs(a.workedMs/(Hs*36e5),l),placeholder:l("for example: 3Ñ 20м"),okLabel:"Save"});if(s===null)return;const u=_a(s);u!=null&&B({workedMs:Math.round(u*Hs*36e5)})},children:l("Correct")})]})]}),ne&&e.jsxs("div",{className:"prop",children:[e.jsx("span",{className:"prop-label",children:l("How often")}),e.jsxs("span",{className:"prop-value rule-anchor",children:[S?e.jsx("button",{type:"button",className:`task-rule ${r?"on":""}`,onClick:()=>P(s=>!s),children:xt(a,l.lang)}):e.jsx("span",{className:"task-rule",children:xt(a,l.lang)}),S&&r&&e.jsx(Ns,{onClose:()=>P(!1),children:e.jsx(ra,{rule:a,onChange:B,onClose:()=>P(!1)})})]})]}),ne&&a.missed.length>0&&e.jsxs("div",{className:"prop missed-prop",children:[e.jsx("span",{className:"prop-label",children:l("Missed")}),e.jsxs("span",{className:"prop-value",children:[e.jsx("span",{className:`missed-count ${a.missed.length>=3?"many":""}`,children:l("{n} times in a row",{n:a.missed.length})}),e.jsxs("span",{className:"missed-list",children:[a.missed.slice(0,8).map(s=>e.jsxs("span",{className:"missed-day",children:[s.slice(5).split("-").reverse().join("."),S&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",title:l("Mark this one done"),onClick:()=>j.done(a.id,"done",s),children:"â"}),e.jsx("button",{type:"button",title:l("Skip this one"),onClick:()=>j.done(a.id,"skipped",s),children:"Ã"})]})]},s)),a.missed.length>8&&e.jsx("span",{className:"hint",children:l("and {n} more",{n:a.missed.length-8})})]})]})]}),e.jsxs("div",{className:"prop",children:[e.jsx("span",{className:"prop-label","data-help":"task-dates",children:l(ne?"Next time":"Dates")}),e.jsx("span",{className:"prop-value",children:ne?e.jsxs("span",{className:a.late?"task-due late":"",children:[a.nextDue,a.late&&` · ${l("overdue")}`,a.streak>1&&e.jsxs("span",{className:"task-streak",children:[" Ã",a.streak]})]}):e.jsxs("span",{className:"task-span",children:[e.jsx(St,{value:a.startsOn,readOnly:!S,onChange:s=>B({startsOn:s}),placeholder:l("Start"),title:l("From when it is worked on")}),e.jsx("span",{className:"task-span-arrow","aria-hidden":"true",children:"â"}),e.jsx(St,{value:a.dueOn,late:a.late,readOnly:!S,onChange:s=>B({dueOn:s}),placeholder:l("Due"),title:l("By when it must be done")}),a.startsOn&&a.dueOn&&e.jsx("span",{className:"hint",children:l("{n} days",{n:Ga(a.startsOn,a.dueOn)})})]})})]}),e.jsxs("div",{className:"prop",children:[e.jsx("span",{className:"prop-label","data-help":"task-estimate",children:l("Time estimate")}),e.jsx("span",{className:"prop-value",children:S?e.jsxs("span",{className:"estimate",children:[e.jsx("input",{className:"estimate-n",inputMode:"decimal",value:Q,placeholder:"â",onChange:s=>Le(s.target.value),onBlur:()=>Ve(),onKeyDown:s=>{s.key==="Enter"&&s.target.blur(),s.key==="Escape"&&Le(a.effortDays!=null?String(kt(a.effortDays,x)):"")}}),e.jsx(V,{className:"estimate-unit",value:x,options:qa.map(s=>({value:s,label:l(Us[s])})),onChange:s=>{const u=s;q(u),a.effortDays!=null&&Le(String(kt(a.effortDays,u)))},children:e.jsx("span",{children:l(Us[x])})})]}):e.jsx("span",{className:a.effortDays!=null?"":"muted",children:a.effortDays!=null?cs(a.effortDays,l):l("Empty")})})]}),e.jsxs("div",{className:"prop",children:[e.jsx("span",{className:"prop-label",children:l("Goal")}),e.jsx("span",{className:"prop-value",children:(()=>{const s=a.goalId&&T.find(u=>u.id===a.goalId)?e.jsx("span",{className:"chip-value",children:T.find(u=>u.id===a.goalId).title}):e.jsx("span",{className:"muted",children:l("Empty")});return S?e.jsx(V,{className:"task-pick",value:a.goalId??"",searchPlaceholder:l("Searchâ¦"),options:[{value:"",label:l("â none â")},...T.map(u=>({value:u.id,label:u.title,sub:u.endsOn.split("-").reverse().join(".")}))],onChange:u=>B({goalId:u||null}),children:s}):e.jsx(Pe,{className:"task-pick",children:s})})()})]}),e.jsxs("div",{className:"prop",children:[e.jsx("span",{className:"prop-label","data-help":"task-author",children:l("Who set it")}),e.jsx("span",{className:"prop-value",children:Ye?e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",className:"task-author","data-ctx":`person:${Ye.id}`,title:l("Open the card"),onClick:()=>_(Ye.id),children:[e.jsx(Me,{person:Ye,size:20}),e.jsx("span",{className:"task-author-name",children:Ye.fullName})]}),Qt(A,a)&&e.jsx("span",{className:"you-mark",children:l("that is you")}),a.authorLeft&&e.jsx("span",{className:"hint",children:l("The author no longer works here")})]}):e.jsx("span",{className:"muted",children:l(a.authorLeft?"The author no longer works here":"Author unknown")})})]}),e.jsxs("div",{className:"prop",children:[e.jsx("span",{className:"prop-label","data-help":"task-who",children:l("Who does it")}),e.jsxs("span",{className:"prop-value",children:[e.jsx(gs,{ids:je,people:h,options:es(a.projectId??a.toolId,se,h),names:!0,readOnly:!S||!Ce,title:S&&!Ce?l("Only the one who set the task changes who does it"):void 0,onChange:s=>B({assigneeIds:s})}),Ne&&e.jsx("button",{type:"button",className:"icon-open",title:l("Open the card"),"aria-label":l("Open the card"),onClick:()=>_(Ne.id),children:e.jsx(Gs,{})}),S&&A.personId&&!De&&e.jsx("button",{type:"button",className:"ghost-btn",onClick:()=>A.personId&&B({assigneeIds:[...je,A.personId]}),children:l("Take it")}),S&&!Ce&&Va(A,a)&&e.jsx("button",{type:"button",className:"ghost-btn",onClick:()=>B({assigneeIds:je.filter(s=>s!==A.personId)}),children:l("Take myself off")})]})]}),e.jsxs("div",{className:"prop",children:[e.jsx("span",{className:"prop-label",children:l("Who else")}),e.jsxs("span",{className:"prop-value",children:[S?e.jsx(V,{className:"task-pick",value:"",keepOpen:!0,searchPlaceholder:l("Search a personâ¦"),options:h.filter(s=>
2s.fullName&&!je.includes(s.id)).map(s=>({value:s.id,label:s.fullName,sub:s.title,icon:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`tick ${a.people.some(u=>u.personId===s.id)?"on":""}`,"aria-hidden":"true"}),e.jsx(Me,{person:s,size:22})]})})),onChange:s=>{const u=a.people.some(k=>k.personId===s);B({people:u?a.people.filter(k=>k.personId!==s):[...a.people,{personId:s,role:""}]})},children:a.people.length?e.jsx("span",{className:"task-who",children:a.people.map(s=>ce.get(s.personId)).filter(Boolean).map(s=>e.jsx(Me,{person:s,size:20,title:s.fullName},s.id))}):e.jsx("span",{className:"muted",children:l("Empty")})}):e.jsx(Pe,{className:"task-pick",children:a.people.length?e.jsx("span",{className:"task-who",children:a.people.map(s=>ce.get(s.personId)).filter(Boolean).map(s=>e.jsx(Me,{person:s,size:20,title:s.fullName},s.id))}):e.jsx("span",{className:"muted",children:l("Empty")})}),a.isPrivate&&a.people.length>0&&e.jsx("span",{className:"hint",children:l("Pulled in to a private task, they do not see it â only its author and assignees do")})]})]}),e.jsxs("div",{className:"prop",children:[e.jsx("span",{className:"prop-label",children:l("Department")}),e.jsx("span",{className:"prop-value",children:S?e.jsx(V,{className:"task-pick",value:a.departmentId??"",searchPlaceholder:l("Searchâ¦"),options:[{value:"",label:l("No department")},...M.map(s=>({value:s.id,label:s.name,sub:Re(s.companyId)}))],onChange:s=>B({departmentId:s||null}),children:e.jsx("span",{className:R?"":"muted",children:R?`${R.name}${Re(R.companyId)?` · ${Re(R.companyId)}`:""}`:l("Empty")})}):e.jsx(Pe,{className:"task-pick",children:e.jsx("span",{className:R?"":"muted",children:R?`${R.name}${Re(R.companyId)?` · ${Re(R.companyId)}`:""}`:l("Empty")})})})]}),e.jsxs("div",{className:"prop",children:[e.jsx("span",{className:"prop-label",children:l("Project")}),e.jsxs("span",{className:"prop-value",children:[S?e.jsx(V,{className:"task-pick",value:a.projectId??a.toolId??"",searchPlaceholder:l("Searchâ¦"),options:[{value:"",label:l("No project")},...se.map(s=>({value:s.id,label:s.name,sub:v.some(u=>u.id===s.id)?l("Tool"):l("Project")}))],onChange:s=>{const u=v.some(k=>k.id===s);B({projectId:s&&!u?s:null,toolId:s&&u?s:null})},children:e.jsx("span",{className:z?"":"muted",children:z?z.name:l("Empty")})}):e.jsx(Pe,{className:"task-pick",children:e.jsx("span",{className:z?"":"muted",children:z?z.name:l("Empty")})}),z&&e.jsx("button",{type:"button",className:"icon-open",title:l("Open"),"aria-label":l("Open"),onClick:()=>b(z.id),children:e.jsx(Gs,{})})]})]}),z&&e.jsxs("div",{className:"prop",children:[e.jsx("span",{className:"prop-label",children:l("Zone of responsibility")}),e.jsx("span",{className:"prop-value",children:S?e.jsx(V,{className:"task-pick",value:"",keepOpen:!0,searchPlaceholder:l("Searchâ¦"),options:[...z.areas.map(s=>({value:s.id,label:s.name,icon:e.jsx("span",{className:`tick ${a.areaIds.includes(s.id)?"on":""}`,"aria-hidden":"true"})})),...Ct?[{value:"+",label:l("New zoneâ¦"),divider:z.areas.length>0}]:[]],onChange:async s=>{if(s!=="+"){B({areaIds:a.areaIds.includes(s)?a.areaIds.filter(D=>D!==s):[...a.areaIds,s]});return}const u=await dt(l("New zone"),{placeholder:l("Zone name")});if(!u||!ee)return;const k=await ee(z.id,u);k&&B({areaIds:[...a.areaIds,k.id]})},children:a.areaIds.length?e.jsx("span",{className:"chip-value",children:a.areaIds.map(s=>z.areas.find(u=>u.id===s)?.name).filter(Boolean).join(", ")}):e.jsx("span",{className:"muted",children:z.areas.length?l("No zone"):l("no zones yet")})}):e.jsx(Pe,{className:"task-pick",children:a.areaIds.length?e.jsx("span",{className:"chip-value",children:a.areaIds.map(s=>z.areas.find(u=>u.id===s)?.name).filter(Boolean).join(", ")}):e.jsx("span",{className:"muted",children:z.areas.length?l("No zone"):l("no zones yet")})})})]}),z&&e.jsxs("div",{className:"prop",children:[e.jsx("span",{className:"prop-label",children:l("Task group")}),e.jsx("span",{className:"prop-value",children:S?e.jsx(V,{className:"task-pick",value:"",keepOpen:!0,searchPlaceholder:l("Searchâ¦"),options:da(l,st,a.groupIds,async s=>{const u=i.filter(D=>
2D.groupIds.includes(s.id)).length,k=u?l("Delete the group â{name}â? {n} tasks will stay, but outside it.",{name:s.name,n:u}):l("Delete the group â{name}â?",{name:s.name});await At(k,{okLabel:"Delete",danger:!0})&&j.removeGroup(s.id)}),onChange:async s=>{if(s!=="+"){B({groupIds:a.groupIds.includes(s)?a.groupIds.filter(X=>X!==s):[...a.groupIds,s]});return}const u=await dt(l("New group"),{placeholder:l("Group name")});if(!u)return;const k=v.some(X=>X.id===z.id),D=await j.addGroup({name:u,projectId:k?null:z.id,toolId:k?z.id:null});D&&B({groupIds:[...a.groupIds,D.id]})},children:a.groupIds.length?e.jsx("span",{className:"chip-value",children:a.groupIds.map(s=>st.find(u=>u.id===s)?.name).filter(Boolean).join(", ")}):e.jsx("span",{className:"muted",children:l("Outside a group")})}):e.jsx(Pe,{className:"task-pick",children:a.groupIds.length?e.jsx("span",{className:"chip-value",children:a.groupIds.map(s=>st.find(u=>u.id===s)?.name).filter(Boolean).join(", ")}):e.jsx("span",{className:"muted",children:l("Outside a group")})})})]}),e.jsxs("div",{className:"prop wide",children:[e.jsx("span",{className:"prop-label",children:l("Tags")}),e.jsx("span",{className:"prop-value",children:e.jsx(Ya,{tags:a.tags,suggestions:ht,readOnly:!S,onChange:s=>B({tags:s})})})]})]}),e.jsxs("div",{className:"task-sections",children:[e.jsxs("section",{className:"task-page-section wide",children:[e.jsx("h4",{children:l("Description")}),e.jsx(Sn,{value:a.details,readOnly:!S,clamp:340,draftKey:`task:${a.id}`,placeholder:l("What has to be done, in detailâ¦"),onCommit:s=>B({details:s}),onUpload:async s=>{const u=await xe.pinTaskFile(a.id,s);return xe.taskFileUrl(a.id,u.id)}})]}),e.jsxs("section",{className:"task-page-section wide","data-help":"task-subs",children:[e.jsxs("h4",{children:[l("Subtasks"),He.length>0&&e.jsx("span",{className:"hint",children:l("{done} of {all}",{done:He.filter(s=>s.state==="done").length,all:He.length})})]}),e.jsx("ul",{className:"subtask-list",children:He.map(s=>e.jsxs("li",{className:`subtask ${s.state==="done"?"is-done":""}`,"data-ctx":`task:${s.id}`,children:[me(s)?e.jsx(V,{className:`task-state ${s.state}`,value:s.state,options:Pt(l,!1,Rt(A,s,Ze)),onChange:u=>j.patch(s.id,{state:u}),children:e.jsxs("span",{className:"state-chip",children:[e.jsx(tt,{state:s.state}),l(Qe[s.state])]})}):e.jsx(Pe,{className:`task-state ${s.state}`,children:e.jsxs("span",{className:"state-chip",children:[e.jsx(tt,{state:s.state}),l(Qe[s.state])]})}),e.jsxs("a",{className:"task-title",href:vt({tab:"tasks",taskId:s.id}),onClick:u=>{u.metaKey||u.ctrlKey||u.shiftKey||u.altKey||u.button!==0||(u.preventDefault(),w(s.id))},children:[e.jsx(Xt,{task:s,all:i}),s.title]}),e.jsxs("span",{className:"subtask-side",children:[s.tags.map(u=>e.jsx("span",{className:`tag hue-${ot(u)}`,children:u},u)),e.jsx(gs,{ids:s.assigneeIds??[],people:h,options:es(s.projectId??s.toolId,se,h),max:2,readOnly:!me(s)||!Jt(A,s),empty:e.jsx("span",{className:"ava-empty","aria-hidden":"true"}),onChange:u=>j.patch(s.id,{assigneeIds:u})}),e.jsx(St,{value:s.dueOn,late:s.late,readOnly:!me(s),onChange:u=>j.patch(s.id,{dueOn:u})}),me(s)&&e.jsx("button",{type:"button",className:"icon-btn small subtask-out",title:l("Make it a task of its own"),"aria-label":l("Make it a task of its own"),onClick:()=>j.patch(s.id,{parentId:null}),children:"â"})]})]},s.id))}),de&&e.jsx("input",{className:"goal-step-add",value:te,placeholder:l("+ Subtask"),onChange:s=>K(s.target.value),onKeyDown:async s=>{if(s.key!=="Enter"||!te.trim()||le.current)return;le.current=!0;const u=await j.create({title:te.trim(),kind:"once",parentId:a.id,departmentId:a.departmentId,projectId:a.projectId,toolId:a.toolId,areaIds:a.areaIds});le.current=!1,u&&K("")}}),S&&Ja(i,a).some(s=>me(s))&&e.jsx("button",{type:"button",className:"ghost-btn subtask-take",onClick:async()=>{const s=await Qa(l,i.filter(u=>u.id===a.id||me(u)),a);s&&j.patch(s,{parentId:a.id})},children:l("Add an existing taskâ¦")})]}),e.jsxs("section",{className:"task-page-section","data-help":"task-checks",children:[e.jsxs("h4",{children:[l("Checklist"),a.checks.length>0&&e.jsx("span",{className:"hint",children:l("{done} of {all}",{done:a.checks.filter(s=>s.done).length,all:a.checks.length})})]}),a.checks.length>0&&e.jsx("ul",{className:"check-list",children:a.checks.map(s=>e.jsxs("li",{className:s.done?"is-done":"",children:[S?e.jsx("input",{type:"checkbox",checked:s.done,onChange:u=>j.patchCheck(a.id,s.id,{done:u.target.checked})}):e.jsx("span",{className:`tick ${s.done?"on":""}`,role:"img","aria-label":s.done?l("Done"):l("To do")}),e.jsx(Ws,{oneClick:!0,value:s.title,readOnly:!S,onCommit:u=>u&&j.patchCheck(a.id,s.id,{title:u})}),S&&e.jsx("button",{type:"button",className:"icon-btn small",title:l("Delete"),onClick:()=>j.removeCheck(a.id,s.id),children:"Ã"})]},s.id))}),S&&e.jsx("input",{className:"goal-step-add",value:re,placeholder:l("+ Checklist item"),onChange:s=>Se(s.target.value),onKeyDown:s=>{s.key!=="Enter"||!re.trim()||(j.addCheck(a.id,re.trim()),Se(""))}})]}),e.jsxs("section",{className:"task-page-section","data-help":"task-files",children:[e.jsxs("h4",{children:[l("Files"),a.files.length>0&&e.jsx("span",{className:"hint",children:a.files.length})]}),a.files.length>0&&e.jsx("ul",{className:"file-list",children:a.files.map(s=>e.jsxs("li",{children:[e.jsx(ma,{taskId:a.id,file:s,onOpen:qe}),S&&e.jsx("button",{type:"button",className:"icon-btn small",title:l("Delete"),onClick:()=>j.removeFile(a.id,s.id),children:"Ã"})]},s.id))}),!S&&a.files.length===0&&e.jsx("p",{className:"hint",children:"â"}),S&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"ghost-btn",onClick:()=>Ie.current?.click(),children:l("+ Attach file")}),e.jsx("input",{ref:Ie,type:"file",multiple:!0,hidden:!0,onChange:async s=>{for(const u of[...s.target.files??[]])await N(u);s.target.value=""}})]})]})]}),Ke&&e.jsx(pa,{taskId:a.id,file:Ke,onClose:()=>qe(null)})]}),e.jsx(Bn,{taskId:a.id,me:A,people:h,events:ne?[...a.runs].reverse():[],onUndo:S?s=>j.undo(a.id,s):void 0,version:J,say:Dn(l,{person:s=>ce.get(s)?.fullName??"",holder:s=>se.find(u=>u.id===s)?.name??"",dept:s=>M.find(u=>u.id===s)?.name??"",group:s=>g.find(u=>u.id===s)?.name??"",zone:s=>se.flatMap(u=>u.areas).find(u=>u.id===s)?.name??"",task:s=>
2i.find(u=>u.id===s)?.title??""})})]})}const Xs=()=>typeof IntersectionObserver<"u";function Hn({items:c,step:i=40,children:g}){const j=zt(),[w,M]=o.useState(()=>Xs()?i:1/0),U=Math.min(w,c.length),h=c.length-U,E=o.useRef(null);return o.useEffect(()=>{const v=E.current;if(!v||!h||!Xs())return;const T=new IntersectionObserver(b=>{b.some(G=>G.isIntersecting)&&M(G=>Math.min(c.length,G+i))},{rootMargin:"800px 0px"});return T.observe(v),()=>T.disconnect()},[h,c.length,i]),e.jsxs(e.Fragment,{children:[c.slice(0,U).map(g),h>0&&e.jsx("div",{className:"lazy-more",ref:E,children:e.jsx("button",{type:"button",className:"link",onClick:()=>M(v=>v+i),children:j("Show {n} more",{n:Math.min(h,i)})})})]})}function Un({rows:c,all:i,kidsOf:g,actions:j,kind:w,isRecurring:M,departmentId:U,holderId:h,tools:E,personById:v,org:T,unfolded:b,setUnfolded:G,onOpen:_,patch:pe}){const ee=zt(),A=g??(L=>i.filter(ie=>ie.parentId===L)),{me:fe,can:Z}=en(),$e=Be(fe,w,"create"),l=Z("tasks.create"),Y=L=>Be(fe,L.kind,"update"),W=o.useMemo(()=>[...v.values()],[v]),r=o.useMemo(()=>T??js(W),[T,W]),P=(L,ie)=>Y(L)&&(ie!=="done"||Rt(fe,L,r)),[te,K]=o.useState(null),[le,re]=o.useState(null),Se=te?i.find(L=>L.id===te):null,[oe,we]=o.useState(!1),Ie=o.useMemo(()=>Se&&Y(Se)?tn(Se,i):null,[Se,i]),Ke=()=>{K(null),we(!1),re(null)},qe=L=>{const ie=te;Ke(),ie&&(pe(ie,{parentId:L}),G(y=>new Set([...y,L])))};return e.jsx("div",{className:"board",children:ks.map(L=>{const ie=c.filter(y=>y.state===L);return e.jsxs("section",{className:`board-col ${le===L?"over":""}`,onDragOver:y=>{!Se||!(oe?Y(Se):P(Se,L))||(y.preventDefault(),re(L))},onDragLeave:()=>re(y=>y===L?null:y),onDrop:y=>{y.preventDefault(),re(null);const a=y.dataTransfer.getData("text/task")||te,J=a?i.find(q=>q.id===a):null,x=oe;if(Ke(),!!J){if(x&&J.parentId){Y(J)&&pe(J.id,{parentId:null,...J.state!==L&&J.kind==="once"&&P(J,L)?{state:L}:{}});return}J.state===L||!P(J,L)||(J.kind==="recurring"&&L==="done"?j.done(J.id):pe(J.id,{state:L}))}},children:[e.jsxs("header",{className:"board-head",children:[e.jsx(tt,{state:L,size:15}),ee(M&&L==="done"?"Done for this time round":Qe[L]),e.jsx("span",{className:"board-count",children:ie.length})]}),e.jsxs("div",{className:"board-cards",children:[e.jsx(Hn,{items:ie,children:y=>{const a=A(y.id),J=Y(y);return e.jsxs("article",{className:`card-task ${te===y.id?"lifted":""} ${y.late?"late":""}`,"data-ctx":`task:${y.id}`,draggable:J,onDragStart:x=>{J&&(x.dataTransfer.setData("text/task",y.id),x.dataTransfer.effectAllowed="move",we(!1),K(y.id))},onDragEnd:Ke,children:[Ie?.(y.id)&&e.jsx(Nn,{onNest:()=>qe(y.id)}),e.jsxs("a",{className:"task-title",href:vt({tab:y.kind==="recurring"?"recurring":"tasks",taskId:y.id}),onClick:x=>{x.metaKey||x.ctrlKey||x.shiftKey||x.altKey||x.button!==0||(x.preventDefault(),_(y.id))},children:[e.jsx(Xt,{task:y,all:i}),y.title]}),y.tags.length>0&&e.jsx("span",{className:"card-tags",children:y.tags.map(x=>e.jsx("span",{className:`tag hue-${ot(x)}`,children:x},x))}),e.jsxs("footer",{className:"card-foot",children:[e.jsxs("span",{className:"card-who",children:[e.jsx(ua,{author:y.authorId?v.get(y.authorId):null,assigneeIds:y.assigneeIds??[],mine:Qt(fe,y)}),e.jsx(ha,{ids:y.assigneeIds??[],people:W,size:20,empty:e.jsx("span",{className:"ava-empty","aria-hidden":"true"})})]}),a.length>0&&e.jsxs("button",{type:"button",className:"tmark card-kids-toggle",title:ee("Subtasks"),"aria-expanded":b.has(y.id),onClick:()=>G(x=>{const q=new Set(x);return q.has(y.id)?q.delete(y.id):q.add(y.id),q}),children:[e.jsx(Zt,{})," ",a.filter(x=>x.state==="done").length,"/",a.length]}),y.checksTotal>0&&e.jsxs("span",{className:"tmark",title:ee("Checklist"),children:[e.jsx(ia,{})," ",y.checksDone,"/",y.checksTotal]}),y.comments>0&&e.jsxs("span",{className:"tmark",title:ee("Discussion"),children:[e.jsx(oa,{})," ",y.comments]}),e.jsx(ys,{task:y,bare:!0}),e.jsx("span",{className:"card-when",children:y.kind==="recurring"?e.jsx("span",{className:`task-due ${y.late?"late":""}`,children:y.nextDue}):e.jsx(St,{value:y.dueOn,late:y.late,readOnly:!J,onChange:x=>pe(y.id,{dueOn:x})})})]}),(b.has(y.id)||a.length===0&&l)&&e.jsxs("div",{className:"card-kids",children:[b.has(y.id)&&a.map(x=>e.jsxs("span",{className:`card-kid ${x.state==="done"?"is-done":""} ${te===x.id?"lifted":""}`,"data-ctx":`task:${x.id}`,draggable:Y(x),onDragStart:q=>{q.stopPropagation(),Y(x)&&(q.dataTransfer.setData("text/task",x.id),q.dataTransfer.effectAllowed="move",we(!0),K(x.id))},onDragEnd:q=>{q.stopPropagation(),Ke()},children:[e.jsx("span",{title:ee(Qe[x.state]),children:e.jsx(tt,{state:x.state,size:12})}),e.jsxs("a",{className:"task-title",href:vt({tab:"tasks",taskId:x.id}),onClick:q=>{q.metaKey||q.ctrlKey||q.shiftKey||q.altKey||q.button!==0||(q.preventDefault(),_(x.id))},children:[e.jsx(Xt,{task:x,all:i}),x.title]})]},x.id)),l&&e.jsx(Vs,{label:"+ Subtask",onDone:x=>j.create({title:x,kind:"once",parentId:y.id,departmentId:y.departmentId,projectId:y.projectId,toolId:y.toolId}).then(()=>G(q=>new Set([...q,y.id])))})]})]},y.id)}}),ie.length===0&&e.jsx("p",{className:"hint board-empty",children:ee("Nothing here")}),$e&&e.jsx(Vs,{onDone:y=>j.create({title:y,kind:w,state:L,departmentId:U,projectId:h&&!E.some(a=>a.id===h)?h:null,toolId:h&&E.some(a=>a.id===h)?h:null})})]})]},L)})})}const _n=["list","board","planner"],Gn=["none","state","who","author","dept","pile","project","tool"],qn=["all","today","week","late","stalled"],Vn=["collapsed","expanded","separate"],Yn=[...sn,"none"],Ge={who:"all",q:"",closed:!1,group:"none",roles:[],when:"all",tags:[],shape:"list",subs:"collapsed",state:"all",priority:"all",holder:"all",area:"all",pile:"all"},Jn=["who","q","closed","group","part","when","tag","shape","subs","state","prio","in","zone","pile"],Nt=(c,i)=>i!==null&&c.includes(i)?i:void 0;function Qn(c){const i=new URLSearchParams(c),g={},j=fe=>{const Z=i.get(fe);return Z||void 0},w=j("who");w&&(g.who=w);const M=j("q");M&&(g.q=M),i.get("closed")==="1"&&(g.closed=!0);const U=Nt(Gn,i.get("group"));U&&(g.group=U);const h=Lt.filter(fe=>(i.get("part")??"").split(",").includes(fe));h.length&&(g.roles=h);const E=Nt(qn,i.get("when"));E&&(g.when=E);
2const v=i.getAll("tag").filter(Boolean);v.length&&(g.tags=v);const T=Nt(_n,i.get("shape"));T&&(g.shape=T);const b=Nt(Vn,i.get("subs"));b&&(g.subs=b);const G=Nt(ks,i.get("state"));G&&(g.state=G);const _=Nt(Yn,i.get("prio"));_&&(g.priority=_);const pe=j("in");pe&&(g.holder=pe);const ee=j("zone");ee&&(g.area=ee);const A=j("pile");return A&&(g.pile=A),g}function ya(c,i){const g=new URLSearchParams(c);for(const w of Jn)g.delete(w);i.who!==Ge.who&&g.set("who",i.who),i.q.trim()&&g.set("q",i.q.trim()),i.closed&&g.set("closed","1"),i.group!==Ge.group&&g.set("group",i.group),i.roles.length&&g.set("part",Lt.filter(w=>i.roles.includes(w)).join(",")),i.when!==Ge.when&&g.set("when",i.when);for(const w of i.tags)g.append("tag",w);i.shape!==Ge.shape&&g.set("shape",i.shape),i.subs!==Ge.subs&&g.set("subs",i.subs),i.state!==Ge.state&&g.set("state",i.state),i.priority!==Ge.priority&&g.set("prio",i.priority),i.holder!==Ge.holder&&g.set("in",i.holder),i.area!==Ge.area&&g.set("zone",i.area),i.pile!==Ge.pile&&g.set("pile",i.pile);const j=g.toString();return j?`?${j}`:""}const Zn=c=>ya(c,Ge),ea="*",Xn=2,el=350,tl=100,sl=20;function al(c){const i=c.trimStart();return i.startsWith(ea)?i.slice(ea.length).trim():null}const nl={on:!1,rank:null,note:""};function ll(c){const i=al(c),g=i!==null&&i.length>=Xn,[j,w]=o.useState(null),[M,U]=o.useState(null);return o.useEffect(()=>{if(i===null){w(null),U(null);return}if(!g)return;let h=!0;const E=setTimeout(()=>{xe.similarTasks(i,tl).then(v=>{h&&(w({text:i,rank:new Map(v.map((T,b)=>[T.id,b]))}),U(null))},v=>{h&&U({text:i,off:v instanceof an&&v.status===503})})},el);return()=>{h=!1,clearTimeout(E)}},[i,g]),i===null?nl:g?M?.text===i?{on:!0,rank:null,note:M.off?"The search by meaning is not set up here.":"The search by meaning did not answer â try again in a moment."}:j?{on:!0,rank:j.rank,note:j.text===i?"Nothing close in meaning in this list.":"Searching by meaningâ¦"}:{on:!0,rank:null,note:"Searching by meaningâ¦"}:{on:!0,rank:null,note:"Type what to look for after the asterisk: the search goes by meaning, not by the exact words."}}function rl(c){for(let i=c?.parentElement;i;i=i.parentElement){const{overflowY:g}=getComputedStyle(i);if(g==="auto"||g==="scroll")return i}return null}const il=40,ta=12;function sa(c,i){let g=0,j=c.length-1;for(;g<j;){const w=g+j+1>>1;c[w]<=i?g=w:j=w-1}return g}function ol(c){const i=c.length,[g,j]=o.useState(null),w=o.useMemo(()=>{const T=new Array(i+1);T[0]=0;for(let b=0;b<i;b++)T[b+1]=T[b]+c[b];return T},[c,i]),[M,U]=o.useState({start:0,end:Math.min(i,il)}),h=o.useRef(w);h.current=w,o.useLayoutEffect(()=>{const T=g;if(!T)return;const b=rl(T),G=()=>{const ee=h.current,A=ee.length-1;if(T.offsetHeight===0&&A>0){U(P=>P.start===0&&P.end===A?P:{start:0,end:A});return}const fe=T.getBoundingClientRect(),Z=b?fe.top-b.getBoundingClientRect().top:fe.top,$e=b?b.clientHeight:window.innerHeight,l=Math.max(0,-Z),Y=Math.max(l,$e-Z),W=Math.max(0,sa(ee,l)-ta),r=Math.min(A,sa(ee,Y)+1+ta);U(P=>P.start===W&&P.end===r?P:{start:W,end:r})};G();const _=b??window;_.addEventListener("scroll",G,{passive:!0}),window.addEventListener("resize",G);const pe=typeof ResizeObserver<"u"&&b?new ResizeObserver(G):null;return pe?.observe(b),()=>{_.removeEventListener("scroll",G),window.removeEventListener("resize",G),pe?.disconnect()}},[g,w]);const E=Math.min(M.start,i),v=Math.min(M.end,i);return{attach:j,start:E,end:v,padTop:w[E],padBottom:w[i]-w[v]}}const cl=()=>new Date().toISOString().slice(0,10),dl=c=>{const i=new Date;return i.setUTCDate(i.getUTCDate()+c),i.toISOString().slice(0,10)},ul=42,hl=31,aa=[];function na(c){const{pathname:i,search:g,hash:j}=window.location;if(new URLSearchParams(g).toString()!==new URLSearchParams(c).toString())try{window.history.replaceState(window.history.state,"",i+c+j)}catch{}}function Cl({kind:c,tasks:i,groups:g,actions:j,refresh:w,dept:M,onDept:U,openId:h,onOpen:E,departments:v,companies:T,people:b,projects:G,tools:_,goals:pe,onOpenHolder:ee,onOpenDept:A,onOpenPerson:fe,onlyMine:Z=!1,back:$e,holderId:l,onAddZone:Y,me:W}){const r=zt(),[P]=o.useState(()=>l?{}:Qn(window.location.search)),te=Object.keys(P).length>0,[K,le]=o.useState(M??"all"),[re,Se]=o.useState(P.who??"all"),[oe,we]=o.useState(P.q??""),[Ie,Ke]=o.useState(P.closed??!1),[qe,L]=o.useState(!1),[ie,y]=o.useState(!1),[a,J]=o.useState(null),[x,q]=o.useState(new Set),[Q,Le]=o.useState(P.group??"none"),Ve=l?"holder":Z?"mine":c,[ke,ut]=o.useState(()=>{if(P.roles)return new Set(P.roles);if(!Z||te)return new Set;try{const t=JSON.parse(localStorage.getItem("orgami.taskRoles.mine")??"[]");return new Set(Array.isArray(t)?Lt.filter(d=>t.includes(d)):[])}catch{return new Set}}),He=t=>ut(d=>{const p=new Set(d);return p.has(t)?p.delete(t):p.add(t),p});o.useEffect(()=>{if(Z)try{localStorage.setItem("orgami.taskRoles.mine",JSON.stringify([...ke]))}catch{}},[ke,Z]);const[ge,ht]=o.useState(P.when??"all"),[ce,Ze]=o.useState(P.tags??[]),[se,Re]=o.useState(()=>{if(P.shape)return P.shape;if(te)return"list";try{const t=localStorage.getItem(`orgami.taskShape.${l?"holder":c}`);return t==="board"||t==="planner"?t:"list"}catch{return"list"}});o.useEffect(()=>{try{localStorage.setItem(`orgami.taskShape.${l?"holder":c}`,se)}catch{}},[se,c,l]);
2const[R,z]=o.useState(P.subs??"collapsed"),[ze,B]=o.useState(null),[ne,je]=o.useState(null),[Ne,Ce]=o.useState(new Set),[De,Ye]=o.useState(new Set),pt=t=>Ce(d=>{const p=new Set(d);return p.has(t)?p.delete(t):p.add(t),p}),st=t=>Ze(d=>d.includes(t)?d.filter(p=>p!==t):[...d,t]),[de,S]=o.useState(P.state??"all"),[Oe,lt]=o.useState(P.priority??"all"),[ue,It]=o.useState(P.holder??"all"),[me,Ee]=o.useState(P.area??"all"),[be,at]=o.useState(P.pile??"all"),[Fe,Ct]=o.useState(()=>{try{const t=JSON.parse(localStorage.getItem(`orgami.taskCols.v2.${Ve}`)??"null");if(Array.isArray(t)&&t.length&&t.every(d=>$t.includes(d)))return t}catch{}return $n[Ve]});o.useEffect(()=>{try{localStorage.setItem(`orgami.taskCols.v2.${Ve}`,JSON.stringify(Fe))}catch{}},[Fe,Ve]);const ve=t=>Fe.includes(t)&&(l?t!=="project":t!=="zone"),Dt=$t.filter(t=>Fe.includes(t)&&(l?t!=="project":t!=="zone")),rt=`orgami.taskColWidths.v2.${Ve}`,[n,N]=o.useState(()=>gn(rt)),f=o.useRef(n),s=(t,d)=>{f.current=t,N(t),d&&kn(rt,t)},u=()=>{const t={};for(const d of Ut.current?.querySelectorAll(":scope > .trow.thead > .tcell[data-col]")??[])t[d.dataset.col??""]=Math.round(d.getBoundingClientRect().width);s({...t,...f.current},!1)},k=Object.keys(n).length>0,D=(t,d,p)=>e.jsx(yn,{side:"right",min:p.min,max:p.max,label:d,onStart:u,onDrag:F=>s({...f.current,[t]:F},!1),onKeep:F=>s({...f.current,[t]:F},!0),onReset:()=>s({},!0)}),X=Dt.map(t=>Tn(t,n[t])).join(" "),ae=k?{"--tname":`${n.name??Ys.usual}px`,"--trest":X}:{"--tcols":["78px","minmax(220px, 1fr)",X,"74px"].filter(Boolean).join(" ")},$=c==="recurring",bs=Be(W,c,"create"),mt=t=>Be(W,t.kind,"update"),ka=t=>Be(W,t.kind,"delete"),xs=Z?_s(W,"update"):Be(W,c,"update"),ws=Z?_s(W,"delete"):Be(W,c,"delete"),Ft=xs||ws,ft=t=>[...Ne].filter(d=>{const p=Je.get(d);return!!p&&t(p)});o.useEffect(()=>le(M??"all"),[M]);const Na=t=>{le(t),U(t==="all"||t==="none"?null:t)},nt=o.useMemo(()=>new Map(b.map(t=>[t.id,t])),[b]),ts=o.useMemo(()=>js(b,v,T),[b,v,T]),gt=o.useMemo(()=>[...G,..._],[G,_]),Ue=o.useMemo(()=>new Map(gt.map(t=>[t.id,t])),[gt]),Wt=o.useMemo(()=>new Map(v.map(t=>[t.id,t])),[v]),vs=o.useMemo(()=>new Map(T.map(t=>[t.id,t])),[T]),Je=o.useMemo(()=>new Map(i.map(t=>[t.id,t])),[i]),Ss=o.useMemo(()=>{const t=new Map;for(const d of i){if(!d.parentId)continue;const p=t.get(d.parentId);p?p.push(d):t.set(d.parentId,[d])}return t},[i]),Bt=o.useCallback(t=>Ss.get(t)??aa,[Ss]),Kt=o.useCallback(t=>t&&vs.get(t)?.name||"",[vs]),Is=o.useMemo(()=>{const t=new Map;for(const d of v)t.set(d.name,(t.get(d.name)??0)+1);return new Set([...t].filter(([,d])=>d>1).map(([d])=>d))},[v]),jt=o.useCallback(t=>{const d=t?Wt.get(t):null;return d?Is.has(d.name)?`${d.name} · ${Kt(d.companyId)}`:d.name:""},[Wt,Is,Kt]),it=o.useCallback(t=>t&&nt.get(t)?.fullName||"",[nt]),ba=t=>{let d=t?Wt.get(t):null;for(;d;){const p=d.headId?nt.get(d.headId):null;if(p)return p;d=d.parentId?Wt.get(d.parentId)??null:null}return null},xa=async t=>{const d=i.filter(F=>F.groupIds.includes(t.id)).length,p=d?r("Delete the group â{name}â? {n} tasks will stay, but outside it.",{name:t.name,n:d}):r("Delete the group â{name}â?",{name:t.name});await At(p,{okLabel:"Delete",danger:!0})&&j.removeGroup(t.id)},Xe=l?Ue.get(l)??null:ue!=="all"&&ue!=="none"?Ue.get(ue)??null:null,ss=o.useMemo(()=>Xe?g.filter(t=>t.projectId===Xe.id||t.toolId===Xe.id):[],[g,Xe]),Ht=o.useMemo(()=>[...new Set(i.filter(t=>t.kind===c).flatMap(t=>t.tags))].sort(),[i,c]),wa=o.useMemo(()=>new Set(i.filter(t=>t.parentId&&t.kind===c).map(t=>t.parentId)),[i,c]),va=t=>R==="expanded"?!0:x.has(t),yt=h&&Je.get(h)||null,Cs=l||yt?null:ya(window.location.search,{who:re,q:oe,closed:Ie,group:Q,roles:Lt.filter(t=>ke.has(t)),when:ge,tags:ce,shape:se,subs:R,state:de,priority:Oe,holder:ue,area:me,pile:be});o.useEffect(()=>{Cs!==null&&na(Cs)}),o.useEffect(()=>{if(!l)return()=>na(Zn(window.location.search))},[l]);const Ut=o.useRef(null),[as,Sa]=o.useState(null),Ds=()=>[...Ut.current?.querySelectorAll(".trow[data-row]")??[]];nn(["arrowdown","arrowup"],t=>{if(document.activeElement&&document.activeElement!==document.body||document.querySelector('[aria-modal="true"], .modal, .pick-menu'))return!1;const d=Ds();if(!d.length)return!1;d[t.key==="ArrowUp"?d.length-1:0].focus()}
2,{typing:!1,when:se==="list"&&!yt});const Os=ll(oe),{on:Ot,rank:Et}=Os,ns=Ot?"":oe.trim().toLowerCase(),Ia=o.useMemo(()=>{const t=i.filter(C=>!(!Z&&C.kind!==c||(K==="none"?C.departmentId:K!=="all"&&C.departmentId!==K)||re!=="all"&&!(C.assigneeIds??[]).includes(re)||ce.length&&!C.tags.some(Ae=>ce.includes(Ae))||l&&C.projectId!==l&&C.toolId!==l||!l&&(ue==="none"?C.projectId||C.toolId:ue!=="all"&&C.projectId!==ue&&C.toolId!==ue)||me!=="all"&&!(me==="none"?C.areaIds.length===0:C.areaIds.includes(me))||be!=="all"&&!(be==="none"?C.groupIds.length===0:C.groupIds.includes(be))||de!=="all"&&C.state!==de||Oe!=="all"&&(Oe==="none"?C.priority:C.priority!==Oe)||Z&&!ln(W,C)||ns&&!C.title.toLowerCase().includes(ns)||Ot&&!Et?.has(C.id))),d=ke.size?t.filter(C=>ms(W,C).some(Ae=>ke.has(Ae))):t,p=cl(),F=dl(7),O=C=>{if(ge==="all")return!0;if(ge==="late")return C.late;if(ge==="stalled")return C.notStarted;const Ae=C.nextDue;return Ae?ge==="today"?Ae<=p:Ae<=F:ge!=="today"&&ge!=="week"},ye=Ie||se==="board",m=C=>($?C:C.filter(Ae=>ye||dn(Ae.state))).filter(O),I=Et?m(d).sort((C,Ae)=>(Et.get(C.id)??0)-(Et.get(Ae.id)??0)).slice(0,sl):m(d),H={doing:0,set:0,pulled:0};for(const C of m(t))if(R==="separate"||!C.parentId)for(const Ae of ms(W,C))H[Ae]++;let Te=0,_e=0;for(const C of d)C.late&&Te++,C.notStarted&&_e++;const qt=R==="separate"||Ot?I:I.filter(C=>!C.parentId);return{shown:I,roleCount:H,late:Te,stalled:_e,unsorted:qt}},[i,Z,c,K,re,ce,l,ue,me,be,de,Oe,W,ns,Ot,Et,ke,ge,Ie,se,$,R]),{shown:Es,roleCount:Ts,late:_t,stalled:$s,unsorted:Ca}=Ia,Da=Lt.filter(t=>ke.has(t)||t==="set"||!!W.personId&&(t==="doing"||Ts[t]>0)),he=(t,d)=>j.patch(t,d),Ms=t=>j.done(t.id);async function Oa(t){return await At(r("Delete the task â{name}â?",{name:t.title}),{okLabel:"Delete",danger:!0})?(await j.remove(t.id),!0):!1}const Ea=o.useMemo(()=>({name:t=>t.title.toLowerCase(),state:t=>ks.indexOf(t.state),when:t=>t.kind==="recurring"?t.nextDue??"":t.dueOn??"",who:t=>it(t.assigneeIds?.[0]??null).toLowerCase(),author:t=>it(t.authorId).toLowerCase(),dept:t=>jt(t.departmentId).toLowerCase(),project:t=>(Ue.get(t.projectId??t.toolId??"")?.name??"").toLowerCase(),time:t=>rn(t),priority:t=>fn(t)}),[it,jt,Ue]),{sorted:We,by:ls,toggle:As}=jn(Ca,Ea),rs=o.useMemo(()=>{if(Q==="none")return[{key:"all",name:"",rows:We}];const t=p=>
2{if(Q==="who"){const F=(p.assigneeIds??[]).map(O=>it(O)).filter(Boolean);return F.length?F:[r("â nobody yet â")]}return[Q==="state"?r(Qe[p.state]):Q==="author"?it(p.authorId)||r("Author unknown"):Q==="pile"?p.groupIds.map(F=>g.find(O=>O.id===F)?.name).filter(Boolean).join(", ")||r("Outside a group"):Q==="project"?p.projectId?Ue.get(p.projectId)?.name??"":r("Outside any project"):Q==="tool"?p.toolId?Ue.get(p.toolId)?.name??"":r("Outside any tool"):p.departmentId?jt(p.departmentId):r("No department")]},d=new Map;for(const p of We)for(const F of t(p)){const O=d.get(F);O?O.push(p):d.set(F,[p])}return[...d.keys()].sort((p,F)=>p.localeCompare(F)).map(p=>({key:p,name:p,rows:d.get(p)}))},[We,Q,r,it,jt,Ue,g]),Ps=[{value:"all",label:r("All departments")},...v.map(t=>({value:t.id,label:t.name,sub:Kt(t.companyId)})),{value:"none",label:r("No department")}],Tt=K!=="all"&&K!=="none"?ba(K):null,[is,Ta]=o.useState({row:ul,head:hl}),Ls=o.useCallback(t=>{if(R==="separate")return 1;const d=(p,F)=>{const O=Bt(p.id);if(F>8||!O.length||!(R==="expanded"||x.has(p.id)))return 1;let ye=1;for(const m of O)ye+=d(m,F+1);return ye};return d(t,0)},[R,x,Bt]),Gt=o.useMemo(()=>{const t=[];for(const d of rs){Q!=="none"&&t.push({key:d.key,head:d.name,count:d.rows.length,task:null});for(const p of d.rows)t.push({key:d.key,head:null,count:0,task:p})}return t},[rs,Q]),$a=o.useMemo(()=>Gt.map(t=>t.task?is.row*Ls(t.task):is.head),[Gt,is,Ls]),et=ol($a),{attach:Rs}=et,Ma=o.useCallback(t=>{Ut.current=t,Rs(t)},[Rs]);o.useLayoutEffect(()=>{const t=Ut.current;if(!t)return;const p=[...t.querySelectorAll(".tgroup > .trow[data-row]")].find(O=>!O.querySelector(".tcell.kids"))?.offsetHeight||0,F=t.querySelector(".tgroup-head")?.offsetHeight||0;Ta(O=>{const ye={row:p||O.row,head:F||O.head};return ye.row===O.row&&ye.head===O.head?O:ye})});const Aa=o.useMemo(()=>{const t=[];for(const d of Gt.slice(et.start,et.end)){const p=t[t.length-1];d.head!==null?t.push({key:d.key,head:d.head,count:d.count,rows:[]}):p&&p.key===d.key?p.rows.push(d.task):t.push({key:d.key,head:null,count:0,rows:[d.task]})}return t},[Gt,et.start,et.end]),Pa=as&&Es.some(t=>t.id===as)?as:rs.find(t=>t.rows.length)?.rows[0]?.id??null,La=t=>{const d=t.target;if(t.ctrlKey||t.metaKey||t.altKey||!d.matches(".trow[data-row]"))return;const p=Ds(),F=p.indexOf(d),O=t.key==="ArrowDown"?F+1:t.key==="ArrowUp"?F-1:t.key==="Home"?0:t.key==="End"?p.length-1:null;O!==null?(t.preventDefault(),p[Math.max(0,Math.min(p.length-1,O))]?.focus()):t.key==="Enter"?(t.preventDefault(),E(d.dataset.row??null)):t.key===" "&&Ft&&d.dataset.row&&(t.preventDefault(),pt(d.dataset.row))},zs=(t,d=0)=>{const p=R==="separate"?aa:Bt(t.id),F=va(t.id),O=mt(t),ye=O&&!ls&&Q==="none"&&R!=="separate"&&!d;return e.jsxs("div",{className:`trow ${t.late?"late":""} ${t.notStarted?"stalled":""} ${t.state==="done"?"is-done":""} ${d?"child":""} ${ze===t.id?"lifted":""} ${ne===t.id?"drop-here":""}`,"data-row":t.id,"data-ctx":`task:${t.id}`,tabIndex:t.id===Pa?0:-1,onFocus:m=>{m.target===m.currentTarget&&Sa(t.id)},draggable:ye,onDragStart:m=>{ye&&(m.dataTransfer.setData("text/task",t.id),m.dataTransfer.effectAllowed="move",B(t.id))},onDragEnd:()=>{B(null),je(null)},onDragOver:m=>{!ye||!ze||ze===t.id||(m.preventDefault(),je(t.id))},onDragLeave:()=>je(m=>m===t.id?null:m),onDrop:m=>{if(!ye||!ze)return;m.preventDefault();const I=ze;if(B(null),je(null),I===t.id)return;const H=We.map(_e=>_e.id).filter(_e=>_e!==I),Te=H.indexOf(t.id);H.splice(Te<0?H.length:Te,0,I),j.reorder(H)},children:[e.jsxs("span",{className:"tcell tick",children:[Ft&&e.jsx("input",{type:"checkbox",className:"row-pick",checked:Ne.has(t.id),"aria-label":r("Select"),onChange:()=>pt(t.id)}),p.length>0?e.jsx("button",{type:"button",className:`twist ${F?"on":""}`,"aria-expanded":F,title:r(F?"Collapse":"Expand"),onClick:()=>q(m=>{const I=new Set(m);return I.has(t.id)?I.delete(t.id):I.add(t.id),I}),children:"â¸"}):e.jsx("span",{className:"twist empty","aria-hidden":"true"}),O?e.jsx(V,{className:`task-state state-only ${t.state}`,value:t.state,title:r(Qe[t.state]),options:()=>Pt(r,t.kind==="recurring",Rt(W,t,ts)),onChange:m=>t.kind==="recurring"&&m==="done"?Ms(t):he(t.id,{state:m}),children:e.jsx(tt,{state:t.state,size:15})}):e.jsx(Pe,{className:`task-state state-only ${t.state}`,title:r(Qe[t.state]),children:e.jsx(tt,{state:t.state,size:15})})]}),e.jsxs("span",{className:"tcell name",children:[e.jsx(Xt,{task:t,all:i}),t.priority&&t.priority!=="normal"&&e.jsx("span",{className:"tmark prio",t
2itle:r(ct[t.priority]),"aria-label":r(ct[t.priority]),children:e.jsx(bt,{priority:t.priority})}),e.jsx("a",{className:"task-title",href:vt({tab:t.kind==="recurring"?"recurring":"tasks",taskId:t.id}),title:r("Open the task"),onClick:m=>{m.metaKey||m.ctrlKey||m.shiftKey||m.altKey||m.button!==0||(m.preventDefault(),E(t.id))},children:t.title}),p.length>0&&e.jsxs("span",{className:"tmark",title:r("Subtasks"),children:[e.jsx(Zt,{})," ",p.filter(m=>m.state==="done").length,"/",p.length]}),t.hasDetails&&e.jsx("span",{className:"tmark",title:r("Has a description"),children:e.jsx(mn,{})}),t.checksTotal>0&&e.jsxs("span",{className:"tmark",title:r("Checklist"),children:[e.jsx(ia,{})," ",t.checksDone,"/",t.checksTotal]}),t.comments>0&&e.jsxs("span",{className:"tmark",title:r("Discussion"),children:[e.jsx(oa,{})," ",t.comments]}),R==="separate"&&t.parentId&&e.jsxs("span",{className:"hint work-parent",children:[" â³ ",Je.get(t.parentId)?.title??""]}),Z&&t.kind==="recurring"&&e.jsx("span",{className:"tchip",children:r("Recurring")}),(De.has(t.id)?t.tags:t.tags.slice(0,2)).map(m=>e.jsx("button",{type:"button",className:`tag hue-${ot(m)} ${ce.includes(m)?"picked":""}`,title:r("Show only this tag"),onClick:()=>st(m),children:m},m)),t.tags.length>2&&e.jsx("button",{type:"button",className:"tag more",title:De.has(t.id)?r("Hide"):t.tags.slice(2).join(", "),onClick:()=>Ye(m=>{const I=new Set(m);return I.has(t.id)?I.delete(t.id):I.add(t.id),I}),children:De.has(t.id)?"â":`+${t.tags.length-2}`}),O&&e.jsx(V,{className:"tag-add",value:"",keepOpen:!0,searchPlaceholder:r("Searchâ¦"),options:()=>[...Ht.map(m=>({value:m,label:m,icon:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`tick ${t.tags.includes(m)?"on":""}`,"aria-hidden":"true"}),e.jsx("span",{className:`tag-dot hue-${ot(m)}`,"aria-hidden":"true"})]})})),{value:"+",label:r("New tagâ¦")}],onChange:async m=>{if(m!=="+")return he(t.id,{tags:t.tags.includes(m)?t.tags.filter(H=>H!==m):[...t.tags,m]});const I=await dt(r("New tag"),{placeholder:r("Tag name"),okLabel:"Add"});I&&!t.tags.includes(I)&&he(t.id,{tags:[...t.tags,I]})},children:e.jsx("span",{className:"tag add",title:r("Add a tag"),children:r("+ tag")})})]}),ve("when")&&e.jsx("span",{className:"tcell when rule-anchor",children:t.kind==="recurring"?e.jsxs(e.Fragment,{children:[O?e.jsx("button",{type:"button",className:`task-rule ${a===t.id?"on":""}`,title:xt(t,r.lang),onClick:()=>J(a===t.id?null:t.id),children:xt(t,r.lang)}):e.jsx("span",{className:"task-rule",title:xt(t,r.lang),children:xt(t,r.lang)}),e.jsx("span",{className:`task-due ${t.late?"late":""}`,children:t.nextDue}),O&&a===t.id&&e.jsx(Ns,{onClose:()=>J(null),children:e.jsx(ra,{rule:t,onChange:m=>he(t.id,m),onClose:()=>J(null)})})]}):e.jsx(St,{value:t.dueOn,late:t.late,readOnly:!O,onChange:m=>he(t.id,{dueOn:m})})}),ve("who")&&e.jsxs("span",{className:"tcell who",children:[!ve("author")&&e.jsx(ua,{author:t.authorId?nt.get(t.authorId):null,assigneeIds:t.assigneeIds??[],mine:Qt(W,t)}),(()=>{const m=t.assigneeIds??[],I=m.length?nt.get(m[0]):void 0,H=I?m.length===1?e.jsxs("span",{className:"twho",children:[e.jsx(Me,{person:I,size:22}),e.jsx("span",{className:"twho-name",children:I.fullName})]}):e.jsxs("span",{className:"twho",title:m.map(Te=>it(Te)).filter(Boolean).join(", "),children:[e.jsx(ha,{ids:m,people:b,size:22,max:3}),e.jsx("span",{className:"twho-name",children:I.fullName})]}):e.jsxs("span",{className:"twho",children:[e.jsx("span",{className:"ava-empty","aria-hidden":"true"}),e.jsx("span",{className:"twho-name hint",children:r("Empty")})]});return e.jsx(gs,{ids:m,people:b,options:()=>es(t.projectId??t.toolId,gt,b),readOnly:!O||!Jt(W,t),onChange:Te=>he(t.id,{assigneeIds:Te}),children:H})})()]}),ve("author")&&e.jsx("span",{className:"tcell who",children:(()=>{const m=t.authorId?nt.get(t.authorId):null;return m?e.jsxs("span",{className:"twho",title:[m.fullName,m.title].filter(Boolean).join(" · "),children:[e.jsx(Me,{person:m,size:20}),e.jsx("span",{className:"twho-name",children:m.fullName}),Qt(W,t)&&e.jsx("span",{className:"you-mark",children:r("that is you")})]}):e.jsx("span",{className:"hint",title:r(t.authorLeft?"The author no longer works here":"Author unknown"),children:"â"})})()}),ve("dept")&&e.jsx("span",{className:"tcell where",children:t.departmentId?e.jsx("span",{className:"tchip","data-ctx":`department:${t.departmentId}`,title:jt(t.departmentId),children:jt(t.departmentId)}):e.jsx("span",{className:"hint",children:"â"})}),ve("zone")&&e.jsx("span",{className:"tcell where",children:(()=>{const m=Ue.get(t.projectId??t.toolId??"");return m?O?e.jsx(V,{className:"task-pick",value:"",keepOpen:!0,searchPlaceholder:r("Searchâ¦"),options:()=>[...m.areas.map(I=>({value:I.id,label:I.name,icon:e.jsx("span",{className:`tick ${t.areaIds.includes(I.id)?"on":""}`,"aria-hidden":"true"})})),...Y&&wt(W,_.some(I=>I.id===m.id)?"tools.update":"projects.update")?[{value:"+",label:r("New zoneâ¦"),divider:m.areas.length>0}]:[]],onChange:async I=>{if(I!=="+"){he(t.id,{areaIds:t.areaIds.includes(I)?t.areaIds.filter(_e=>_e!==I):[...t.areaIds,I]});return}const H=await dt(r("New zone"),{placeholder:r("Zone name")}
2);if(!H||!Y)return;const Te=await Y(m.id,H);Te&&he(t.id,{areaIds:[...t.areaIds,Te.id]})},children:t.areaIds.length?e.jsx("span",{className:"chip-value",children:t.areaIds.map(I=>m.areas.find(H=>H.id===I)?.name).filter(Boolean).join(", ")}):e.jsx("span",{className:"hint",children:m.areas.length?r("No zone"):r("no zones yet")})}):e.jsx(Pe,{className:"task-pick",children:t.areaIds.length?e.jsx("span",{className:"chip-value",children:t.areaIds.map(I=>m.areas.find(H=>H.id===I)?.name).filter(Boolean).join(", ")}):e.jsx("span",{className:"hint",children:m.areas.length?r("No zone"):r("no zones yet")})}):e.jsx("span",{className:"hint",children:"â"})})()}),ve("project")&&e.jsx("span",{className:"tcell where",children:t.projectId||t.toolId?e.jsx("button",{type:"button",className:"tchip project","data-ctx":`holder:${t.projectId??t.toolId}`,onClick:()=>ee(t.projectId??t.toolId),children:Ue.get(t.projectId??t.toolId)?.name??""}):e.jsx("span",{className:"hint",children:"â"})}),!t.aiReads&&e.jsx("span",{className:"tcell shut",title:r("Hidden from the assistant"),"aria-label":r("Hidden from the assistant"),children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{x:"5",y:"10.5",width:"14",height:"9.5",rx:"2"}),e.jsx("path",{d:"M8.5 10.5V8a3.5 3.5 0 0 1 7 0v2.5"})]})}),ve("group")&&e.jsx("span",{className:"tcell where",children:(()=>{const m=Ue.get(t.projectId??t.toolId??"");if(!m)return e.jsx("span",{className:"hint",children:"â"});const I=g.filter(H=>H.projectId===m.id||H.toolId===m.id);return O?e.jsx(V,{className:"task-pick",value:"",keepOpen:!0,searchPlaceholder:r("Searchâ¦"),options:()=>da(r,I,t.groupIds,H=>xa(H)),onChange:async H=>{if(H!=="+"){he(t.id,{groupIds:t.groupIds.includes(H)?t.groupIds.filter(C=>C!==H):[...t.groupIds,H]});return}const Te=await dt(r("New group"),{placeholder:r("Group name")});if(!Te)return;const _e=_.some(C=>C.id===m.id),qt=await j.addGroup({name:Te,projectId:_e?null:m.id,toolId:_e?m.id:null});qt&&he(t.id,{groupIds:[...t.groupIds,qt.id]})},children:t.groupIds.length?e.jsxs("span",{className:"chip-value",children:[I.find(H=>H.id===t.groupIds[0])?.name??"",t.groupIds.length>1?` +${t.groupIds.length-1}`:""]}):e.jsx("span",{className:"hint",children:r("Outside a group")})}):e.jsx(Pe,{className:"task-pick",children:t.groupIds.length?e.jsxs("span",{className:"chip-value",children:[I.find(H=>H.id===t.groupIds[0])?.name??"",t.groupIds.length>1?` +${t.groupIds.length-1}`:""]}):e.jsx("span",{className:"hint",children:r("Outside a group")})})})()}),ve("time")&&e.jsx("span",{className:"tcell time",children:e.jsx(ys,{task:t})}),ve("priority")&&e.jsx("span",{className:"tcell priority",children:O?e.jsx(V,{className:"task-pick",value:t.priority??"",options:()=>fs(r),onChange:m=>he(t.id,{priority:ca(m)}),children:t.priority?e.jsxs("span",{className:"chip-value prio-chip",children:[e.jsx(bt,{priority:t.priority}),r(ct[t.priority])]}):e.jsx("span",{className:"hint",children:"â"})}):t.priority?e.jsx(Pe,{className:"task-pick",children:e.jsxs("span",{className:"chip-value prio-chip",children:[e.jsx(bt,{priority:t.priority}),r(ct[t.priority])]})}):e.jsx("span",{className:"hint",children:"â"})}),e.jsx("span",{className:"tcell acts"}),F&&e.jsx("span",{className:"tcell kids",children:p.map(m=>zs(m,d+1))})]},t.id)};return yt?e.jsx(Kn,{task:yt,refresh:w,all:i,groups:g,actions:j,onOpen:E,departments:v,companies:T,people:b,projects:G,tools:_,goals:pe,onOpenHolder:ee,onOpenDept:A,onOpenPerson:fe,me:W,onAddZone:Y,back:$e,onBack:()=>$e?$e.go():E(null),onDelete:async()=>{await Oa(yt)&&($e?$e.go():E(null))}},yt.id):e.jsxs("div",{className:"tasks-view",children:[e.jsxs("header",{className:"tasks-head",children:[$&&e.jsx("div",{className:"tabs","data-help":"task-when",role:"tablist","aria-label":r("When"),children:["all","today","week","late","stalled"].map(t=>e.jsxs("button",{type:"button",role:"tab","aria-selected":ge===t,className:ge===t?"on":"",onClick:()=>ht(t),children:[r(t==="all"?"All":t==="today"?"Today":t==="week"?"Next 7 days":t==="late"?"Overdue":"Not started"),t==="late"&&_t>0&&e.jsx("span",{className:"count",children:_t}),t==="stalled"&&$s>0&&e.jsx("span",{className:"count",children:$s})]},t))}),e.jsx("div",{className:"seg shape-seg","data-help":"task-shape",children:["list","board","planner"].map(t=>e.jsx("button",{type:"button",className:se===t?"on":"",onClick:()=>Re(t),children:r(t==="list"?"List":t==="board"?"Kanban":"Planner")},t))}),e.jsx("div",{className:"role-filter",role:"group","aria-label":r("My part"),"data-help":"task-mine",children:Da.map(t=>e.jsxs("button",{type:"button",className:`chip-toggle role-${t} ${ke.has(t)?"on":""}`,"aria-pressed":ke.has(t),onClick:()=>He(t),children:[r(on[t]),e.jsx("span",{className:"chip-n",children:Ts[t]})]},t))}),e.jsx(V,{className:"team-filter",mark:"task-dept",value:K,options:Ps,onChange:Na,searchPlaceholder:r("Searchâ¦"),children:e.jsx("span",{className:K==="all"?"muted":"",children:Ps.find(t=>t.value===K)?.label})}),!l&&e.jsx(V,{className:"team-filter",value:ue,searchPlaceholder:r("Searchâ¦"),options:[{value:"all",label:r("Any project")},{value:"none",label:r("Outside any project")},...gt.map(t=>({value:t.id,label:t.name,sub:_.some(d=>d.id===t.id)?r("Tool"):r("Project")}))],onChange:t=>{It(t),Ee("all"),at("all")},children:e.jsx("span",{className:ue==="all"?"muted":"",children:ue==="all"?r("Any project"):ue==="none"?r("Outside any project"):Ue.get(ue)?.name??""})}),Xe&&Xe.areas.length>0&&e.jsx(V,{className:"team-filter",value:me,searchPlaceholder:r("Searchâ¦"),options:[{value:"all",label:r("Any zone")},{value:"none",label:r("No zone")},...Xe.areas.map(t=>({value:t.id,label:t.name}))],onChange:Ee,children:e.jsx("span",{className:me==="all"?"muted":"",children:me==="all"?r("Any zone"):me==="none"?r("No zone"):Xe.areas.find(t=>
2t.id===me)?.name??""})}),Xe&&ss.length>0&&e.jsx(V,{className:"team-filter",value:be,options:[{value:"all",label:r("Any group")},{value:"none",label:r("Outside a group")},...ss.map(t=>({value:t.id,label:t.name}))],onChange:at,children:e.jsx("span",{className:be==="all"?"muted":"",children:be==="all"?r("Any group"):be==="none"?r("Outside a group"):ss.find(t=>t.id===be)?.name??""})}),e.jsx(V,{className:"team-filter",value:re,options:[{value:"all",label:r("Anyone")},...b.filter(t=>t.fullName).map(t=>({value:t.id,label:t.fullName,sub:t.title,icon:e.jsx(Me,{person:t,size:22})}))],onChange:Se,searchPlaceholder:r("Search a personâ¦"),children:e.jsx("span",{className:re==="all"?"muted":"",children:re==="all"?r("Anyone"):nt.get(re)?.fullName??""})}),Ht.length>0&&e.jsx(V,{className:"team-filter",value:"",keepOpen:!0,options:[{value:"",label:r("Any tag"),icon:e.jsx("span",{className:`tick ${ce.length?"":"on"}`,"aria-hidden":"true"})},...Ht.map(t=>({value:t,label:t,icon:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`tick ${ce.includes(t)?"on":""}`,"aria-hidden":"true"}),e.jsx("span",{className:`tag-dot hue-${ot(t)}`,"aria-hidden":"true"})]})}))],onChange:t=>t?st(t):Ze([]),searchPlaceholder:r("Searchâ¦"),children:ce.length===0?e.jsx("span",{className:"muted",children:r("Any tag")}):e.jsxs("span",{className:"tag-picked",children:[ce.slice(0,2).map(t=>e.jsx("span",{className:`tag hue-${ot(t)}`,children:t},t)),ce.length>2&&e.jsxs("span",{className:"hint",children:["+",ce.length-2]})]})}),e.jsx("input",{className:"team-search","data-find":!0,"data-help":"task-search",value:oe,onChange:t=>we(t.target.value),onKeyDown:cn(oe,()=>we("")),placeholder:r("Search the tasksâ¦")}),e.jsx(V,{className:"team-filter",value:Q,options:[{value:"none",label:r("No grouping")},{value:"state",label:r("State")},{value:"who",label:r("Who does it")},{value:"author",label:r("Who set it")},{value:"dept",label:r("Department")},{value:"pile",label:r("Task group")},{value:"project",label:r("Project")},{value:"tool",label:r("Tool")}],onChange:t=>Le(t),children:e.jsxs("span",{className:Q==="none"?"muted":"",children:[r("Group"),":"," ",r(Q==="none"?"No grouping":Q==="state"?"State":Q==="who"?"Who does it":Q==="author"?"Who set it":Q==="pile"?"Task group":Q==="project"?"Project":Q==="tool"?"Tool":"Department")]})}),!$&&e.jsx(V,{className:"team-filter",value:de,options:[{value:"all",label:r("Any state")},...Pt(r,!1)],onChange:t=>S(t),children:de==="all"?e.jsx("span",{className:"muted",children:r("Any state")}):e.jsxs("span",{className:"state-chip",children:[e.jsx(tt,{state:de}),r(Qe[de])]})}),e.jsx(V,{className:"team-filter",value:Oe,options:()=>[{value:"all",label:r("Any priority")},...fs(r).map(t=>t.value?t:{...t,value:"none"})],onChange:t=>lt(t),children:Oe==="all"?e.jsx("span",{className:"muted",children:r("Any priority")}):e.jsxs("span",{className:"prio-chip",children:[e.jsx(bt,{priority:Oe==="none"?null:Oe}),r(Oe==="none"?"No priority":ct[Oe])]})}),!$&&se!=="board"&&e.jsx("button",{type:"button",className:`chip-toggle ${Ie?"on":""}`,onClick:()=>Ke(t=>!t),children:r("Closed")}),wa.size>0&&e.jsx(V,{className:"team-filter",value:R,options:[{value:"collapsed",label:r("Collapsed")},{value:"expanded",label:r("Expanded")},{value:"separate",label:r("Separate")}],onChange:t=>z(t),children:e.jsxs("span",{className:R==="collapsed"?"muted":"",children:[r("Subtasks"),": ",r(R==="collapsed"?"Collapsed":R==="expanded"?"Expanded":"Separate")]})}),e.jsx(V,{className:"team-filter",value:"",keepOpen:!0,options:$t.filter(t=>l?t!=="project":t!=="zone").map(t=>({value:t,label:r(t==="when"&&$?"How often":us[t]),icon:e.jsx("span",{className:`tick ${ve(t)?"on":""}`,"aria-hidden":"true"})})),onChange:t=>Ct(d=>d.includes(t)?d.filter(p=>p!==t):$t.filter(p=>d.includes(p)||p===t)),children:e.jsx("span",{className:"muted",children:r("Columns")})}),e.jsxs("span",{className:"tasks-head-right",children:[e.jsx("span",{className:"hint tasks-summary",children:_t>0?e.jsx("span",{className:"gap warn",children:r("{n} overdue",{n:_t})}):r("nothing overdue")}),Tt&&e.jsxs("button",{type:"button",className:"owner-line","data-ctx":`person:${Tt.id}`,onClick:()=>fe(Tt.id),title:r("Open the card"),children:[e.jsx(Me,{person:Tt,size:22}),e.jsxs("span",{className:"owner-text",children:[e.jsx("span",{className:"owner-name",children:Tt.fullName}),e.jsx("span",{className:"hint",children:r("answers for this department's tasks")})]})]}),bs&&e.jsx("button",{type:"button",className:"btn primary tasks-new","data-help":"task-new","data-hotkey":"new",title:`${r("New task")} · Alt+N`,disabled:ie,onClick:()=>L(!0),children:r("+ Task")})]})]}),bs&&qe&&e.jsx(un,{kind:c,holderId:l,departmentId:K!=="all"&&K!=="none"?K:null,departments:v,companies:T,people:b,holders:gt,tools:_,onClose:()=>L(!1),onCreate:async(t,d)=>{y(!0);const p=await j.create(t,d);return y(!1),p?(L(!1),E(p.id),p):null}}),Ft&&Ne.size>0&&e.jsxs("div",{className:"bulk-bar",children:[e.jsx("span",{className:"bulk-n",children:r("{n} picked",{n:Ne.size})}),xs&&e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"team-filter",value:"",options:()=>Pt(r,$,[...Ne].every(t=>{const d=Je.get(t);return!d||Rt(W,d,ts)})),onChange:t=>{for(const d of ft(mt)){const p=Je.get(d);p?.kind==="recurring"&&t==="done"?Ms(p):he(d,{state:t})}Ce(new Set)},children:e.jsx("span",{children:r("State")})}),e.jsx(V,{className:"team-filter",value:"",searchPlaceholder:r("Search a personâ¦"),options:[{value:"",label:r("â nobody yet â")},...(es(l,gt,b)??b).filter(t=>t.fullName&&!t.plannedOut).map(t=>({value:t.id,label:t.fullName,sub:t.title,icon:e.jsx(Me,{person:t,size:22})}))],onChange:t=>{for(const d of ft(mt)){const p=Je.get(d);p&&!Jt(W,p)||he(d,{assigneeIds:t?[t]:[]})}Ce(new Set)},children:e.jsx("span",{children:r("Who does it")})}),e.jsx(St,{value:null,placeholder:r("Due"),title:r("Move the deadline of everything picked"),onChange:t=>{for(const d of ft(mt))he(d,{dueOn:t});Ce(new Set)}}),e.jsx(V,{className:"team-filter",value:"",searchPlaceholder:r("Searchâ¦"),options:[{value:"",label:r("No department")},...v.map(t=>({value:t.id,label:t.name,sub:Kt(t.companyId)}))],onChange:t=>{for(const d of ft(mt))he(d,{departmentId:t||null});Ce(new Set)},children:e.jsx("span",{children:r("Department")})}),e.jsx(V,{className:"team-filter",value:"",keepOpen:!0,searchPlaceholder:r("Searchâ¦"),options:()=>[...Ht.map(t=>{const d=[...Ne].every(F=>Je.get(F)?.tags.includes(t)),p=!d&&[...Ne].some(F=>Je.get(F)?.tags.includes(t));return{value:t,label:t,sub:p?r("on some of them"):void 0,icon:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`tick ${d?"on":p?"some":""}`,"aria-hidden":"true"}),e.jsx("span",{className:`tag-dot hue-${ot(t)}`,"aria-hidden":"true"})]})}}),{value:"+",label:r("New tagâ¦")}],onChange:async t=>{let d=t;if(t==="+"){const O=await dt(r("New tag"),{placeholder:r("Tag name"),okLabel:"Add"});if(!O)return;d=O}const p=ft(mt),F=p.every(O=>Je.get(O)?.tags.includes(d));for(const O of p){const ye=Je.get(O);ye&&(F?he(O,{tags:ye.tags.filter(m=>m!==d)}):ye.tags.includes(d)||he(O,{tags:[...ye.tags,d]}))}},children:e.jsx("span",{children:r("Tags")})})]}),ws&&e.jsx("button",{type:"button",className:"ghost-btn danger",onClick:async()=>{await At(r("Delete {n} tasks?",{n:Ne.size}),{okLabel:"Delete",danger:!0})&&(await j.removeMany(ft(ka)),Ce(new Set))},children:r("Delete")}),e.jsx("button",{type:"button",className:"link",onClick:()=>Ce(new Set),children:r("Clear")})]}),se==="planner"?e.jsx(bn,{tasks:Es,people:b,holders:[...G,..._],departments:v,me:W,holderId:l,onOpenTask:E,search:!1,onMove:(t,d)=>he(t,d),onNest:(t,d)=>he(t,{parentId:d})}):se==="board"?e.jsx(Un,{rows:We,all:i,kidsOf:Bt,actions:j,kind:c,isRecurring:$,departmentId:K!=="all"&&K!=="none"?K:null,holderId:l,tools:_,personById:nt,org:ts,unfolded:x,setUnfolded:q,onOpen:E,patch:he}):e.jsxs("div",{className:`ttable ${k?"cols-set":""}`,ref:Ma,onKeyDown:La,style:ae,children:[e.jsxs("div",{className:"trow thead",children:[e.jsx("span",{className:"tcell tick",children:Ft&&e.jsx("input",{type:"checkbox",className:"row-pick",checked:We.length>0&&We.every(t=>Ne.has(t.id)),ref:t=>{t&&(t.indeterminate=We.some(d=>Ne.has(d.id))&&!We.every(d=>Ne.has(d.id)))},"aria-label":r("Select all"),onChange:t=>Ce(t.target.checked?new Set(We.map(d=>d.id)):new Set)})}),e.jsxs("span",{className:"tcell name","data-col":"name",children:[e.jsxs("button",{type:"button",className:"tsort",onClick:()=>As("name"),children:[r("Task"),qs(ls,"name")]}),e.jsx("span",{className:"tcount",children:We.length}),D("name",r("Task"),Ys)]}),$t.filter(t=>ve(t)&&(l?t!=="project":t!=="zone")).map(t=>e.jsxs("span",{className:`tcell ${t==="dept"||t==="project"?"where":t}`,"data-col":t,children:[e.jsxs("button",{type:"button",className:"tsort",onClick:()=>As(t),children:[r(t==="when"&&$?"How often":us[t]),qs(ls,t)]}),D(t,r(t==="when"&&$?"How often":us[t]),En)]},t)),e.jsx("span",{className:"tcell acts"})]}),et.padTop>0&&e.jsx("div",{className:"tpad",style:{height:et.padTop},"aria-hidden":"true"}),Aa.map(t=>e.jsxs("div",{className:"tgroup",children:[t.head!==null&&e.jsxs("div",{className:"tgroup-head",children:[t.head,e.jsx("span",{className:"tcount",children:t.count})]}),t.rows.map(d=>zs(d))]},t.key)),et.padBottom>0&&e.jsx("div",{className:"tpad",style:{height:et.padBottom},"aria-hidden":"true"}),We.length===0&&e.jsx("p",{className:"hint pad",children:Z&&!W.personId?r("This account is not linked to anyone on the map yet â put its corporate email on that person's card."):r(Ot?Os.note:"Nothing here yet.")})]})]})}export{Cl as TasksView};
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.