import{u as P,r,j as e,t as n,L as I}from"./index-uuPZ7Tsn.js";import{c,u as S,a as p,b as f,C as E,d as O,e as $,f as A,g as K,h as L}from"./api-DnTBmEaP.js";const Q=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],z=c("chevron-right",Q);const B=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],H=c("plus",B);const D=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]],G=c("user-plus",D);const R=[["path",{d:"M19 7V4a1 1 0 0 0-1-1H5a2 2 0 0 0 0 4h15a1 1 0 0 1 1 1v4h-3a2 2 0 0 0 0 4h3a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1",key:"18etb6"}],["path",{d:"M3 5v14a2 2 0 0 0 2 2h15a1 1 0 0 0 1-1v-4",key:"xoc0q4"}]],U=c("wallet",R);function V(){const a=P(),{data:l=[]}=S({queryKey:["children"],queryFn:K}),{data:h=[]}=S({queryKey:["tasks"],queryFn:L}),[_,o]=r.useState(!1),[u,g]=r.useState(""),[b,y]=r.useState(""),[d,j]=r.useState(""),[q,i]=r.useState(!1),[N,v]=r.useState(""),x=()=>{a.invalidateQueries({queryKey:["children"]}),a.invalidateQueries({queryKey:["tasks"]})},k=p({mutationFn:$,onSuccess:()=>{x(),n.success("Opgave oprettet"),o(!1),g(""),y(""),j("")},onError:t=>n.error(t.message)}),C=p({mutationFn:t=>A(t),onSuccess:()=>{x(),n.success("Barn tilføjet"),i(!1),v("")},onError:t=>n.error(t.message)}),w=p({mutationFn:O,onSuccess:()=>{x(),n.success("Godkendt – beløb tilføjet 💰")},onError:t=>n.error(t.message)}),M=t=>h.filter(s=>s.child_id===t&&!s.approved).length,m=h.filter(t=>!t.approved),T=t=>{t.preventDefault();const s=parseInt(b,10);if(!u.trim()||!d||isNaN(s)||s<0){n.error("Udfyld alle felter");return}k.mutate({title:u.trim(),amount:s,child_id:d})};return e.jsxs("div",{className:"mx-auto max-w-md min-h-screen bg-background pb-32",children:[e.jsxs("header",{className:"px-5 pt-10 pb-6",children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight text-foreground",children:"Pligter & Lommepenge"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Tryk på et barn for at se detaljer"})]}),e.jsxs("section",{className:"px-5 space-y-3",children:[l.map(t=>e.jsx(W,{child:t,taskCount:M(t.id)},t.id)),e.jsxs("button",{onClick:()=>i(!0),className:"w-full rounded-3xl p-5 border-2 border-dashed border-border text-muted-foreground font-semibold flex items-center justify-center gap-2 active:scale-[0.98] transition",children:[e.jsx(G,{className:"w-5 h-5"}),"Tilføj barn"]})]}),e.jsxs("section",{className:"px-5 mt-8",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"Opgaver at godkende"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:m.length})]}),m.length===0?e.jsx("div",{className:"rounded-2xl border border-border bg-card p-6 text-center text-sm text-muted-foreground",children:"Ingen opgaver lige nu 🎉"}):e.jsx("ul",{className:"space-y-2",children:m.map(t=>{const s=l.find(F=>F.id===t.child_id);return e.jsxs("li",{className:"rounded-2xl bg-card border border-border p-4 flex items-center gap-3",children:[e.jsx("div",{className:"w-2 h-12 rounded-full",style:{background:s?f(s.name):"var(--primary)"}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-semibold text-foreground truncate",children:t.title}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[s?.name," · ",t.amount," kr."]})]}),e.jsxs("button",{onClick:()=>w.mutate(t),disabled:w.isPending,className:"bg-accent text-accent-foreground font-semibold px-4 py-2.5 rounded-xl flex items-center gap-1 active:scale-95 transition",children:[e.jsx(E,{className:"w-5 h-5"}),"Godkend"]})]},t.id)})})]}),e.jsxs("button",{onClick:()=>o(!0),className:"fixed bottom-6 left-1/2 -translate-x-1/2 bg-primary text-primary-foreground font-semibold px-6 py-4 rounded-full shadow-lg flex items-center gap-2 active:scale-95 transition",children:[e.jsx(H,{className:"w-6 h-6"}),"Ny opgave"]}),_&&e.jsx("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-end sm:items-center justify-center",onClick:()=>o(!1),children:e.jsxs("form",{onClick:t=>t.stopPropagation(),onSubmit:T,className:"w-full max-w-md bg-card rounded-t-3xl sm:rounded-3xl p-6 space-y-4",children:[e.jsx("h3",{className:"text-xl font-bold text-foreground",children:"Ny opgave"}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-foreground",children:"Titel"}),e.jsx("input",{value:u,onChange:t=>g(t.target.value),placeholder:"F.eks. Støvsug stuen",autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1,className:"mt-1 w-full bg-secondary text-foreground px-4 py-3 rounded-xl text-base outline-none focus:ring-2 focus:ring-ring"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-foreground",children:"Beløb (kr.)"}),e.jsx("input",{value:b,onChange:t=>y(t.target.value.replace(/[^0-9]/g,"")),inputMode:"numeric",placeholder:"20",className:"mt-1 w-full bg-secondary text-foreground px-4 py-3 rounded-xl text-base outline-none focus:ring-2 focus:ring-ring"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-foreground",children:"Barn"}),e.jsx("div",{className:"mt-2 grid grid-cols-3 gap-2",children:l.map(t=>e.jsx("button",{type:"button",onClick:()=>j(t.id),className:`py-3 px-2 rounded-xl font-semibold text-sm border-2 transition truncate ${d===t.id?"border-transparent text-white":"border-border bg-secondary text-foreground"}`,style:d===t.id?{background:f(t.name)}:void 0,children:t.name},t.id))})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>o(!1),className:"flex-1 py-3.5 rounded-xl bg-secondary text-secondary-foreground font-semibold",children:"Annullér"}),e.jsx("button",{type:"submit",disabled:k.isPending,className:"flex-1 py-3.5 rounded-xl bg-primary text-primary-foreground font-semibold",children:"Opret"})]})]})}),q&&e.jsx("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-end sm:items-center justify-center",onClick:()=>i(!1),children:e.jsxs("form",{onClick:t=>t.stopPropagation(),onSubmit:t=>{t.preventDefault();const s=N.trim();if(!s){n.error("Skriv et navn");return}C.mutate(s)},className:"w-full max-w-md bg-card rounded-t-3xl sm:rounded-3xl p-6 space-y-4",children:[e.jsx("h3",{className:"text-xl font-bold text-foreground",children:"Tilføj barn"}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-foreground",children:"Navn"}),e.jsx("input",{value:N,onChange:t=>v(t.target.value),placeholder:"F.eks. Emma",autoFocus:!0,className:"mt-1 w-full bg-secondary text-foreground px-4 py-3 rounded-xl text-base outline-none focus:ring-2 focus:ring-ring"})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>i(!1),className:"flex-1 py-3.5 rounded-xl bg-secondary text-secondary-foreground font-semibold",children:"Annullér"}),e.jsx("button",{type:"submit",disabled:C.isPending,className:"flex-1 py-3.5 rounded-xl bg-primary text-primary-foreground font-semibold",children:"Tilføj"})]})]})})]})}function W({child:a,taskCount:l}){return e.jsxs(I,{to:"/child/$childId",params:{childId:a.id},className:"block rounded-3xl p-5 text-white shadow-sm active:scale-[0.98] transition",style:{background:f(a.name)},children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-2xl font-bold truncate",children:a.name}),e.jsxs("div",{className:"flex items-center gap-1 opacity-80",children:[e.jsx(U,{className:"w-6 h-6"}),e.jsx(z,{className:"w-5 h-5"})]})]}),e.jsxs("div",{className:"mt-4 flex items-end justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs opacity-80 uppercase tracking-wide",children:"Saldo"}),e.jsxs("p",{className:"text-3xl font-bold",children:[a.balance," kr."]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-xs opacity-80 uppercase tracking-wide",children:"Åbne opgaver"}),e.jsx("p",{className:"text-2xl font-semibold",children:l})]})]})]})}function Y(){return e.jsx(V,{})}export{Y as component};
