1import{cr as O,z as D,u as I,cw as U,r as i,j as e}from"./index-BVpny5eT.js";import{Z as _,_ as H}from"./api-CQKVmx9j.js";import{b as M}from"./rooms-CIt7vEoI.js";import"./ProfileNameTrigger-BwlTTwP1.js";function J(t){if(!t)return null;const a=new Date(t);return Number.isNaN(a.getTime())?null:a.toLocaleString(void 0,{weekday:"long",day:"numeric",month:"long",hour:"numeric",minute:"2-digit"})}function w(t){return t.joined?"joined":t.request==="pending"?"pending":t.request==="approved"?"approved":t.request==="declined"?"declined":"pick"}const Z={joined:"you are in",pending:"waiting on them",approved:"let in",declined:"not this time",full:"full"};function N({kicker:t,title:a,children:l}){return e.jsx("div",{className:"rooms rooms--standalone rm-invite rm-host",children:e.jsxs("div",{className:"rm-invite-box rm-host-box",children:[e.jsx("div",{className:"rm-invite-brand",children:"Gemphere"}),e.jsx("div",{className:"rm-invite-kicker",children:t}),e.jsx("h1",{className:"rm-invite-title",children:a}),l]})})}function Y({mark:t,tone:a,name:l,meta:x,line:o,state:s,picked:h,onToggle:g}){const p=e.jsxs(e.Fragment,{children:[e.jsx(M,{mark:t,tone:a,size:"sm"}),e.jsxs("span",{className:"rm-host-row-who",children:[e.jsx("b",{children:l}),e.jsx("span",{children:x}),e.jsx("span",{children:o})]}),s==="pick"?e.jsx("span",{className:`rm-host-tick${h?" is-on":""}`,"aria-hidden":"true",children:h?"â":""}):e.jsx("span",{className:`rm-host-state rm-host-state--${s}`,children:Z[s]})]});return s!=="pick"?e.jsx("li",{className:"rm-host-row is-done",children:p}):e.jsx("li",{children:e.jsx("button",{type:"button",className:`rm-host-row${h?" is-picked":""}`,onClick:g,"aria-pressed":h,children:p})})}function X(){var F,A;const{code:t=""}=O(),a=D(),{user:l}=I(),{openLogin:x}=U(),o=l==null?void 0:l.accessToken,[s,h]=i.useState(null),[g,p]=i.useState(""),[b,$]=i.useState(!0),[c,S]=i.useState(new Set),[T,C]=i.useState(!1),[E,L]=i.useState(""),[v,P]=i.useState(null),k=i.useCallback(()=>{let n=!0;return $(!0),_(t,o).then(r=>{n&&(h(r),p(""))}).catch(r=>{n&&p(r instanceof Error?r.message:"That code did not work")}).finally(()=>n&&$(!1)),()=>{n=!1}},[t,o]);i.useEffect(k,[k]);const z=i.useCallback(n=>{S(r=>{const u=new Set(r);return u.has(n)?u.delete(n):u.add(n),u})},[]),R=i.useCallback(async()=>{if(!o){x({redirectTo:`/host/${encodeURIComponent(t)}`});return}C(!0),L("");try{const n=[...c].map(u=>{const[B,G]=u.split(":");return{kind:B,id:Number(G)}}),r=await H(o,t,n);P(r.asked),S(new Set),k()}catch(n){L(n instanceof Error?n.message:"Could not send that")}finally{C(!1)}},[o,t,c,x,k]),d=(s==null?void 0:s.events)??[],m=(s==null?void 0:s.leagues)??[],q=!b&&!g&&!d.length&&!m.length,f=((A=(F=s==null?void 0:s.host)==null?void 0:F.name)==null?void 0:A.trim())||"",j=f.split(/\s+/)[0]||"the organizer",y=i.useMemo(()=>[...d,...m].filter(n=>!n.joined&&n.request==="pending").length,[d,m]);return b&&!s?e.jsx(N,{kicker:"organizer",title:"Looking it upâ¦",children:null}):g?e.jsxs(N,{kicker:"organizer",title:"That code does not open anything.",children:[e.jsxs("p",{className:"rm-invite-line",children:[g,". Check the link you were sent, or ask whoever gave you the code to show it again."]}),e.jsx("button",{type:"button",className:"rm-btn rm-btn--out",onClick:()=>a("/rooms"),children:"Go to your rooms"})]}):e.jsxs(N,{kicker:f?`${f} is hosting`:"organizer",title:q?"Nothing open right now.":"Pick what you want to be in.",children:[(s==null?void 0:s.host)&&e.jsxs("div",{className:"rm-invite-host",children:[e.jsx(M,{mark:s.host.mark,tone:s.host.tone,size:"sm"}),e.jsx("span",{children:s.host.name})]}),(s==null?void 0:s.isYou)&&e.jsx("p",{className:"rm-invite-note",children:"This is your own code, seen the way somebody who scans it sees it. Requests land in your rooms."}),q?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"rm-invite-line",children:[j," has not opened anything you can join yet. The code keeps working â try it again when they have."]}),e.jsx("button",{type:"button",className:"rm-btn rm-btn--out",onClick:()=>a("/rooms"),children:"Go to your rooms"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"rm-invite-line",children:["Everything ",j," runs is here. Choose the ones you want and they decide who comes in â nothing is joined until they say yes."]}),d.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rm-host-head",children:[e.jsx("span",{children:"Events"}),e.jsx("span",{children:d.length})]}),e.jsx("ul",{className:"rm-host-list",children:d.map(n=>{const r=J(n.startsAt);return e.jsx(Y,{mark:n.title.slice(0,2).toUpperCase(),tone:n.state==="live"?"e":"b",name:n.title,meta:[r,n.venue].filter(
1Boolean).join(" · ")||"Time and place to be confirmed",line:`${n.going} ${n.going===1?"person":"people"} on the list`,state:w(n),picked:c.has(`event:${n.id}`),onToggle:()=>z(`event:${n.id}`)},`event-${n.id}`)})})]}),m.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rm-host-head",children:[e.jsx("span",{children:"Leagues"}),e.jsx("span",{children:m.length})]}),e.jsx("ul",{className:"rm-host-list",children:m.map(n=>e.jsx(Y,{mark:n.mark,tone:n.tone,name:n.name,meta:`${n.seats} of ${n.maxMembers} seats taken`,line:n.full?"Full":n.isOpen?"Open â everyone in it can already open doors for each other":`Opens at ${n.minMembers}`,state:n.full&&w(n)==="pick"?"full":w(n),picked:c.has(`league:${n.id}`),onToggle:()=>z(`league:${n.id}`)},`league-${n.id}`))})]}),v!==null&&e.jsx("p",{className:"rm-invite-note",children:v===0?"Nothing new to ask for â you had already asked for those.":`Asked for ${v} â ${j} will let you know. You do not need to keep this page open.`}),E&&e.jsx("div",{className:"rm-invite-err",children:E}),e.jsx("button",{type:"button",className:"rm-btn",disabled:T||!!o&&c.size===0,onClick:()=>void R(),children:T?"Sendingâ¦":o?c.size===0?"Pick at least one":`Ask to join ${c.size}`:"Sign in to ask"}),o?y>0?e.jsxs("p",{className:"rm-invite-note",children:[y," ",y===1?"request is":"requests are"," with ",j,". You will see the room in your own rooms the moment they say yes."]}):e.jsxs("p",{className:"rm-invite-note",children:[j," sees your name and decides. Your target list stays private either way â only the person who can reach something is ever told."]}):e.jsx("p",{className:"rm-invite-note",children:"You will come straight back here after signing in."})]})]})}export{X 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.