(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6043],{10677:(e,t,a)=>{"use strict";a.d(t,{default:()=>n});var c=a(95155),s=a(12115);function n(){let[e,t]=(0,s.useState)([]),[a,n]=(0,s.useState)("");return(0,s.useEffect)(()=>{n(localStorage.getItem("madarx.activeProjectId")||""),fetch("/api/projects").then(e=>e.json()).then(e=>t(e.projects||[])).catch(()=>{})},[]),(0,c.jsx)("div",{className:"project-switcher","data-project-switcher":!0,children:(0,c.jsxs)("select",{value:a,onChange:e=>{var t;n(t=e.target.value),t?localStorage.setItem("madarx.activeProjectId",t):localStorage.removeItem("madarx.activeProjectId"),window.dispatchEvent(new CustomEvent("madarx:project-change",{detail:{project_id:t||null}}))},"aria-label":"Active project",children:[(0,c.jsx)("option",{value:"",children:"All projects"}),e.map(e=>(0,c.jsx)("option",{value:e.id,children:e.name},e.id))]})})}},12674:(e,t,a)=>{"use strict";a.d(t,{default:()=>n});var c=a(95155),s=a(12115);function n(e){let{taskId:t,initial:a}=e,[n,i]=s.useState(a||[]),[l,o]=s.useState(""),[d,r]=s.useState(!1);async function h(){let e=l.trim();if(e&&!d){r(!0);try{let a=await fetch("/api/tasks/".concat(t,"/checklist"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({label:e})});if(a.ok){let e=await a.json();i(t=>[...t,e.item]),o("")}}finally{r(!1)}}}async function u(e){let a=!e.done;i(t=>t.map(t=>t.id===e.id?{...t,done:a,done_at:a?new Date().toISOString():null}:t)),await fetch("/api/tasks/".concat(t,"/checklist/").concat(e.id),{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({done:a})})}async function p(e){i(t=>t.filter(t=>t.id!==e.id)),await fetch("/api/tasks/".concat(t,"/checklist/").concat(e.id),{method:"DELETE"})}return(0,c.jsxs)("div",{className:"task-checklist",children:[0===n.length?(0,c.jsx)("p",{className:"task-mute",children:"No checklist items yet."}):(0,c.jsx)("ul",{className:"task-checklist-list",children:n.map(e=>(0,c.jsxs)("li",{className:e.done?"done":"",children:[(0,c.jsxs)("label",{children:[(0,c.jsx)("input",{type:"checkbox",checked:!!e.done,onChange:()=>u(e)}),(0,c.jsx)("span",{children:e.label})]}),(0,c.jsx)("button",{type:"button",className:"task-checklist-remove","aria-label":"Remove ".concat(e.label),onClick:()=>p(e),children:"\xd7"})]},e.id))}),(0,c.jsxs)("div",{className:"task-checklist-add",children:[(0,c.jsx)("input",{type:"text",value:l,onChange:e=>o(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),h())},placeholder:"Add a checklist item",disabled:d}),(0,c.jsx)("button",{type:"button",className:"admin-button secondary",onClick:h,disabled:d||!l.trim(),children:"Add"})]})]})}},68064:(e,t,a)=>{Promise.resolve().then(a.bind(a,10677)),Promise.resolve().then(a.bind(a,12674))}},e=>{e.O(0,[8441,1255,7358],()=>e(e.s=68064)),_N_E=e.O()}]);