PageSourceSearch

https://alsak.ru/assets/TasksView-piSHN2t0.js

js alsak.ru collected 2026-10-02 11:43:09 UTC 85,876 bytes, 2 lines download raw bytes

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