1import{j as e}from"./vendor-data-DCtgzbKT.js";import{r as o,L as $}from"./vendor-react-BwNDMrvh.js";import{u as G,m as J,S as K,B as w,I as O,g,h as f,i as j,j as v,k as l,s as x}from"./index-3Ez0DFQC.js";import{T as Q}from"./textarea-Das7cdLS.js";import{C as L,a as W,c as X,b as I}from"./card-CEGQz7Vu.js";import{B as p}from"./badge-CXbBCu-Y.js";import{C as Y}from"./checkbox-Da4afo4d.js";import{D as Z}from"./orgStructure-CMU7w-bZ.js";import{A as ee}from"./arrow-left-BAaKf3Q0.js";import{P as E}from"./plus-Ch8zrERB.js";import{L as B}from"./loader-circle-ByJsuUbS.js";import{T as se}from"./trash-2-DM0io4JH.js";import"./vendor-motion-DK0uh8A6.js";const y=Z.find(n=>n.key==="administration"),k=(y==null?void 0:y.subRoles)??[],R={open:{label:"Open",tone:"bg-secondary text-secondary-foreground"},in_progress:{label:"In progress",tone:"bg-primary/15 text-primary"},done:{label:"Done",tone:"bg-accent/20 text-accent-foreground"}};function he(){var D;const{user:n}=G(),{toast:d}=J(),[h,V]=o.useState([]),[q,C]=o.useState(!0),[S,T]=o.useState(!1),[N,F]=o.useState("all"),[_,M]=o.useState("all"),[t,c]=o.useState({title:"",description:"",assigned_role:((D=k[0])==null?void 0:D.value)??"platform_ops",due_at:""});async function m(){C(!0);const{data:s,error:a}=await x.from("admin_tasks").select("*").order("status",{ascending:!0}).order("created_at",{ascending:!1});a&&d({title:"Couldn't load tasks",description:a.message,variant:"destructive"}),V(s??[]),C(!1)}o.useEffect(()=>{m()},[]);async function P(){if(!t.title.trim())return;T(!0);const{error:s}=await x.from("admin_tasks").insert({title:t.title.trim(),description:t.description.trim()||null,assigned_role:t.assigned_role,due_at:t.due_at||null,created_by:(n==null?void 0:n.id)??null});if(T(!1),s){d({title:"Couldn't create task",description:s.message,variant:"destructive"});return}c({...t,title:"",description:"",due_at:""}),d({title:"Task added"}),m()}async function z(s,a){const r=a?{status:"done",completed_at:new Date().toISOString(),completed_by:(n==null?void 0:n.id)??null}:{status:"open",completed_at:null,completed_by:null},{error:i}=await x.from("admin_tasks").update(r).eq("id",s.id);if(i){d({title:"Couldn't update",description:i.message,variant:"destructive"});return}m()}async function H(s,a){const r=a==="done"?{status:a,completed_at:new Date().toISOString(),completed_by:(n==null?void 0:n.id)??null}:{status:a,completed_at:null,completed_by:null},{error:i}=await x.from("admin_tasks").update(r).eq("id",s.id);i&&d({title:"Couldn't update",description:i.message,variant:"destructive"}),m()}async function U(s){if(!confirm("Delete this task? (super admin only)"))return;const{error:a}=await x.from("admin_tasks").delete().eq("id",s);if(a){d({title:"Couldn't delete",description:a.message,variant:"destructive"});return}m()}const A=h.filter(s=>(N==="all"||s.status===N)&&(_==="all"||s.assigned_role===_)),b={open:h.filter(s=>s.status==="open").length,in_progress:h.filter(s=>s.status==="in_progress").length,done:h.filter(s=>s.status==="done").length};return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(K,{title:"Admin Tasks â Atomik",description:"Administration team task tracker",canonicalUrl:"https://atomik.lovable.app/admin/tasks"}),e.jsxs("div",{className:"container mx-auto px-4 py-8 max-w-5xl",children:[e.jsx(w,{asChild:!0,variant:"ghost",size:"sm",className:"mb-4",children:e.jsxs($,{to:"/admin",children:[e.jsx(ee,{className:"w-4 h-4 mr-1"}),"Back to Admin"]})}),e.jsxs("header",{className:"mb-6",children:[e.jsx("h1",{className:"font-heading text-3xl font-bold",children:"Administration Tasks"}),e.jsx("p",{className:"text-muted-foreground text-sm mt-1",children:"Track what the admin desks are doing. Tick the box when a task is done â the platform stamps the time and who finished it."}),e.jsxs("div",{className:"flex flex-wrap gap-2 mt-3",children:[e.jsxs(p,{variant:"secondary",children:["Open: ",b.open]}),e.jsxs(p,{className:"bg-primary/15 text-primary hover:bg-primary/20",children:["In progress: ",b.in_progress]}),e.jsxs(p,{className:"bg-accent/20 text-accent-foreground hover:bg-accent/30",children:["Done: ",b.done]})]})]}),e.jsxs(L,{className:"mb-6",children:[e.jsx(W,{children:e.jsxs(X,{className:"text-lg flex items-center gap-2",children:[e.jsx(E,{className:"w-4 h-4"}),"Add task"]})}),e.jsxs(I,{className:"space-y-3",children:[e.jsx(O,{placeholder:"Task title",value:t.title,onChange:s=>c({...t,title:s.target.value})}),e.jsx(Q,{placeholder:"Optional details",value:t.description,onChange:s=>c({...t,description:s.target.value}),rows:2}),e.jsxs("div",{className:"grid sm:grid-cols-2 gap-3",children:[e.jsxs(g,{value:t.assigned_role,onValueChange:s=>c({...t,assigned_role:s}),children:[e.jsx(f,{children:e.jsx(j,{placeholder:"Assign to desk"})}),e.jsx(v,{children:k.map(s=>e.jsx(l,{value:s.value,children:s.label},s.value))})]}),e.jsx(O,{type:"datetime-local",value:t.due_at,onChange:s=>c({...t,due_at:s.target.value})})]}),e.jsxs(w,{onClick:P,disabled:S||!t.title.trim(),children:[S?e.jsx(B,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(E,{className:"w-4 h-4 mr-2"}),"Create task"]})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 mb-4",children:[e.jsxs(g,{value:N,onValueChange:s=>F(s),children:[e.jsx(f,{className:"w-40",children:e.jsx(j,{})}),e.jsxs(v,{children:[e.jsx(l,{value:"all",children:"All statuses"}),e.jsx(l,{value:"open",children:"Open"}),e.jsx(l,{value:"in_progress",children:"In progress"}),e.jsx(l,{value:"done",children:"Done"})]})]}),e.jsxs(g,{value:_,onValueChange:M,children:[e.jsx(f,{className:"w-56",children:e.jsx(j,{})}),e.jsxs(v,{children:[e.jsx(l,{value:"all",children:"All desks"}),k.map(s=>e.jsx(l,{value:s.value,children:s.label},s.value))]})]})]}),q?e.jsxs("div",{className:"text-center text-muted-foreground py-12",children:[e.jsx(B,{className:"w-5 h-5 inline mr-2 animate-spin"}),"Loading tasksâ¦"]}):A.length===0?e.jsx("div",{className:"text-center text-muted-foreground py-12 border border-dashed rounded-lg",children:"No tasks match your filters yet."}):e.jsx("ul",{className:"space-y-2",children:A.map(s=>{var i;const a=((i=k.find(u=>u.value===s.assigned_role))==null?void 0:i.label)??s.assigned_role,r=s.status==="done";return e.jsx("li",{children:e.jsx(L,{className:r?"opacity-70":"",children:e.jsxs(I,{className:"p-4 flex items-start gap-3",children:[e.jsx(Y,{checked:r,onCheckedChange:u=>z(s,!!u),"aria-label":r?"Mark task open":"Mark task done",className:"mt-1"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2 flex-wrap",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:`font-medium ${r?"line-through text-muted-foreground":""}`,children:s.title}),s.description&&e.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:s.description})]}),e.jsx(p,{className:R[s.status].tone,children:R[s.status].label})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-2 text-xs text-muted-foreground",children:[e.jsx(p,{variant:"outline",children:a}),s.due_at&&e.jsxs("span",{children:["Due ",new Date(s.due_at).toLocaleStr
1ing()]}),s.completed_at&&e.jsxs("span",{className:"text-accent",children:["â Completed ",new Date(s.completed_at).toLocaleString()]}),e.jsxs("span",{className:"ml-auto flex items-center gap-2",children:[e.jsxs(g,{value:s.status,onValueChange:u=>H(s,u),children:[e.jsx(f,{className:"h-7 w-32 text-xs",children:e.jsx(j,{})}),e.jsxs(v,{children:[e.jsx(l,{value:"open",children:"Open"}),e.jsx(l,{value:"in_progress",children:"In progress"}),e.jsx(l,{value:"done",children:"Done"})]})]}),e.jsx(w,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:()=>U(s.id),"aria-label":"Delete task",children:e.jsx(se,{className:"w-3.5 h-3.5"})})]})]})]})]})})},s.id)})})]})]})}export{he as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.