import{a as x,j as e}from"./vendor-query-Brcc40-Y.js";import{A as h}from"./vendor-utils-ui5PHgZB.js";import{F as v,B as u,i as y,G as b,H as j,D as N}from"./index-tN-ddyeb.js";import{S as k}from"./Skeleton-DGpeJz1z.js";function w(i){var a;if(i instanceof h){const s=(a=i.response)==null?void 0:a.data;if(Array.isArray(s==null?void 0:s.message))return s.message[0];if(typeof(s==null?void 0:s.message)=="string")return s.message}return i instanceof Error?i.message:"Could not invite member. Please try again."}function L({groupId:i,className:a,onSuccess:s}){const[r,c]=x.useState(""),[t,n]=x.useState(null),[d,o]=x.useState(!1),m=v(i);function p(l){l.preventDefault(),r.trim()&&(n(null),o(!1),m.mutate(r.trim().toLowerCase(),{onSuccess:f=>{c(""),n(f),s==null||s()}}))}async function g(){var l;if((l=t==null?void 0:t.invite)!=null&&l.inviteUrl)try{await navigator.clipboard.writeText(t.invite.inviteUrl),o(!0),setTimeout(()=>o(!1),2e3)}catch{}}return e.jsxs("div",{className:y("space-y-2",a),children:[e.jsxs("form",{onSubmit:p,className:"flex gap-2",children:[e.jsx("input",{type:"email",value:r,onChange:l=>{c(l.target.value),n(null)},placeholder:"friend@example.com",className:`flex-1 rounded-xl border border-bg-overlay bg-bg-elevated px-4 py-2.5 text-sm text-ink placeholder-ink-faint
                     focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/30 transition-all`,required:!0,"aria-label":"Member email"}),e.jsx(u,{type:"submit",size:"sm",loading:m.isPending,children:"Invite"})]}),e.jsx("p",{className:"text-xs text-ink-muted",children:"Invite by email — they'll join if they already have Divyourday, or get a link to sign up."}),(t==null?void 0:t.type)==="member"&&e.jsx("p",{className:"text-sm text-success bg-success-subtle rounded-xl px-3 py-2",children:t.message}),(t==null?void 0:t.type)==="invite"&&t.invite&&e.jsxs("div",{className:"rounded-xl bg-success-subtle px-3 py-3 space-y-2",children:[e.jsx("p",{className:"text-sm text-success",children:t.message}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("input",{readOnly:!0,value:t.invite.inviteUrl,className:"flex-1 min-w-0 rounded-lg border border-bg-overlay bg-bg-elevated px-3 py-1.5 text-xs text-ink truncate"}),e.jsx(u,{type:"button",size:"sm",variant:"secondary",onClick:g,children:d?"Copied":"Copy link"})]}),e.jsx("p",{className:"text-xs text-ink-muted",children:"Share this link so they can create an account and join the group."})]}),m.isError&&e.jsx("p",{className:"text-sm text-danger bg-danger-subtle rounded-xl px-3 py-2",children:w(m.error)})]})}function A({groupId:i}){const{data:a,isLoading:s}=b(i),r=j(i),c=N();async function t(n,d){await c({title:"Cancel invite?",message:`The invite to ${d} will be cancelled. They won’t be able to use the join link.`,confirmLabel:"Cancel invite",variant:"danger"})&&r.mutate(n)}return s?e.jsx("div",{className:"space-y-2",children:e.jsx(k,{className:"h-10 w-full rounded-xl"})}):a!=null&&a.length?e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-xs font-semibold text-ink-muted uppercase tracking-wider",children:"Pending invites"}),e.jsx("ul",{className:"space-y-1",children:a.map(n=>e.jsxs("li",{className:"flex items-center gap-3 rounded-xl p-2 hover:bg-bg-elevated transition-all",children:[e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-full bg-warning/15 text-warning text-xs font-semibold flex-shrink-0",children:"?"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-ink truncate",children:n.email}),e.jsxs("p",{className:"text-xs text-ink-muted",children:["Expires ",new Date(n.expiresAt).toLocaleDateString()]})]}),e.jsx(u,{type:"button",size:"sm",variant:"ghost",className:"text-danger hover:text-danger",loading:r.isPending,onClick:()=>t(n.id,n.email),children:"Cancel"})]},n.id))})]}):null}export{L as I,A as P};
