import{j as e,a as g}from"./vendor-query-Brcc40-Y.js";import{u as v,b,s as h}from"./vendor-form-BQNAly2Z.js";import{r as p,x as N,t as y,I as k,B as u,f,y as w,z as L,D as j,E as G,A as S}from"./index-tN-ddyeb.js";import{T as D,S as d}from"./Skeleton-DGpeJz1z.js";import{B as P}from"./Badge-CnBuGwnc.js";import{I as R,P as z}from"./PendingInvitesList-NJPOzwUK.js";import{d as I,u as M}from"./vendor-react-DP6BW_9B.js";import"./vendor-utils-ui5PHgZB.js";import"./vendor-zustand-CVDiRiMG.js";const T=b({name:h().min(2).max(60),description:h().max(200).optional()});function A({groupId:s}){var l;const{data:a,isLoading:r}=p(s),n=N(s),{register:i,handleSubmit:o,reset:t,formState:{errors:m,isDirty:x}}=v({resolver:y(T)});return g.useEffect(()=>{a&&t({name:a.name,description:a.description??""})},[a,t]),r?e.jsxs("div",{className:"card p-5 space-y-4",children:[e.jsx(d,{className:"h-4 w-24"}),e.jsx(d,{className:"h-11 rounded-xl"}),e.jsx(d,{className:"h-20 rounded-xl"})]}):e.jsxs("div",{className:"card p-5 space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink-muted uppercase tracking-wider",children:"Group info"}),e.jsxs("form",{onSubmit:o(c=>n.mutateAsync(c)),className:"space-y-4",children:[e.jsx(k,{label:"Group name",error:(l=m.name)==null?void 0:l.message,...i("name")}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium text-ink",children:"Description"}),e.jsx("textarea",{rows:2,className:`w-full rounded-xl border border-bg-overlay bg-bg-elevated px-4 py-3 text-sm text-ink placeholder-ink-faint
                       focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/30 resize-none transition-all`,...i("description")})]}),n.isSuccess&&e.jsx("p",{className:"text-sm text-success bg-success-subtle rounded-xl p-3",children:"Saved successfully"}),e.jsx(u,{type:"submit",size:"sm",loading:n.isPending,disabled:!x,children:"Save changes"})]})]})}function B({member:s,groupId:a,myRole:r,myId:n}){const i=G(a),o=j(),t=s.userId===n,m=r==="admin"&&!t;async function x(){await o({title:`Remove ${s.name}?`,message:"They will lose access to this group’s expenses and balances.",confirmLabel:"Remove member",variant:"danger"})&&i.mutate(s.userId)}return e.jsxs("div",{className:"flex items-center gap-3 rounded-xl p-2 hover:bg-bg-elevated transition-all",children:[e.jsx(S,{name:s.name,src:s.avatarUrl,size:"sm"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-sm font-medium text-ink truncate",children:[s.name," ",t&&e.jsx("span",{className:"text-ink-muted",children:"(you)"})]}),e.jsx("p",{className:"text-xs text-ink-muted truncate",children:s.email})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[s.role==="admin"&&e.jsx(P,{variant:"primary",size:"sm",children:"Admin"}),m&&e.jsx("button",{onClick:x,disabled:i.isPending,className:"text-xs text-danger hover:text-danger transition-colors disabled:opacity-50",children:"Remove"})]})]})}function C({groupId:s}){var o;const{data:a,isLoading:r}=p(s),n=f(t=>t.user),i=((o=a==null?void 0:a.members.find(t=>t.userId===(n==null?void 0:n.id)))==null?void 0:o.role)??"member";return e.jsxs("div",{className:"card p-5 space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink-muted uppercase tracking-wider",children:"Members"}),i==="admin"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(R,{groupId:s}),e.jsx(z,{groupId:s})]}),r?e.jsx("div",{className:"space-y-2",children:[1,2].map(t=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(d,{className:"h-8 w-8 rounded-full"}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx(d,{className:"h-3.5 w-1/2"}),e.jsx(d,{className:"h-3 w-1/3"})]})]},t))}):e.jsx("div",{className:"space-y-1",children:a==null?void 0:a.members.map(t=>e.jsx(B,{member:t,groupId:s,myRole:i,myId:(n==null?void 0:n.id)??""},t.userId))})]})}function E({groupId:s}){var l;const{data:a}=p(s),r=f(c=>c.user),n=w(),i=L(),o=j(),t=((l=a==null?void 0:a.members.find(c=>c.userId===(r==null?void 0:r.id)))==null?void 0:l.role)==="admin";async function m(){await o({title:"Leave this group?",message:"You will lose access to this group’s expenses and balances.",confirmLabel:"Leave group",variant:"danger"})&&i.mutate(s)}async function x(){await o({title:"Delete this group?",message:"This permanently removes the group and all its expenses. This cannot be undone.",confirmLabel:"Delete group",variant:"danger"})&&n.mutate(s)}return e.jsxs("div",{className:"card border-danger/20 p-5 space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-danger uppercase tracking-wider",children:"Danger zone"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-ink",children:"Leave group"}),e.jsx("p",{className:"text-xs text-ink-muted mt-0.5",children:"You will lose access to this group's expenses."})]}),e.jsx(u,{variant:"danger",size:"sm",loading:i.isPending,onClick:m,children:"Leave"})]}),t&&e.jsxs("div",{className:"flex items-start justify-between gap-4 pt-3 border-t border-bg-overlay",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-ink",children:"Delete group"}),e.jsx("p",{className:"text-xs text-ink-muted mt-0.5",children:"Permanently removes the group and all its data."})]}),e.jsx(u,{variant:"danger",size:"sm",loading:n.isPending,onClick:x,children:"Delete"})]})]})]})}function K(){const{id:s}=I(),a=M();return e.jsxs("div",{className:"flex flex-col",children:[e.jsx(D,{title:"Group settings",actions:e.jsxs("button",{onClick:()=>a(`/groups/${s}`),className:"flex items-center gap-1.5 text-sm text-ink-muted hover:text-ink transition-colors",children:[e.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})}),"Back"]})}),e.jsxs("div",{className:"mx-auto w-full max-w-lg space-y-4 p-4 lg:p-6 animate-fade-in",children:[e.jsx(A,{groupId:s}),e.jsx(C,{groupId:s}),e.jsx(E,{groupId:s})]})]})}export{K as default};
