1import{P as o,j as e,ad as k,T as h,al as g,aJ as x,W as j,V as J,B as y,aT as _,bv as $,bw as U,bs as E,cU as q,bD as K,by as Q,ci as X,ik as Z,bJ as ee,am as z,ea as ae,d1 as te,b0 as se,a as ne}from"./vendor-DRQg1ZAU.js";import{hj as le,at as f,hk as N,hl as L,hm as P,a6 as re,hn as ie,ho as oe,v as de}from"./index-DUkk2-Lr.js";import{N as ce,e as he,g as A,s as ue,d as me,r as pe,a as xe}from"./challengeStats-DyRn02kS.js";import{C as ge,p as fe}from"./ChallengeWidgetCard-BqLMRKPq.js";const be=360,M=n=>n.format("YYYY-MM-DD"),ye=n=>{for(let a=1;a<=366;a+=1){const d=n.add(a,"day");if(L(d))return d}return null},je=n=>{const a={},d=Math.max(0,n.dayNumber);for(let l=1;l<=d;l+=1)l===4||l===9||(a[n.run.startDate.add(l-1,"day").format("YYYYMMDD")]=1700);return{leaderboard:{dailyWordsTotal:a,longestStreak:28},bingoCard:{completedChallenges:Math.min(25,Math.round(d*.6)),totalBingos:Math.floor(d/9)},goal:n.run.challengeId==="novel"?ce:3e4,now:n.run.startDate.add(Math.max(0,d-1),"day")}};function ve({challengeId:n}){const a=o.useMemo(()=>le(n),[n]),d=o.useMemo(()=>{const s=a.endDate.subtract(1,"day");return[{label:"Today",date:f()},{label:"Day before it opens",date:N(a).subtract(1,"day")},{label:"Widget opens",date:N(a)},{label:"Day 1",date:a.startDate},{label:"Mid-run",date:a.startDate.add(17,"day")},{label:"Final 3 days",date:s.subtract(2,"day")},{label:"Last day",date:s},{label:"Day after",date:a.endDate}]},[a.runId]),[l,u]=o.useState(()=>M(a.startDate.add(17,"day"))),i=o.useMemo(()=>{const s=f(l);return s.isValid()?L(s.startOf("day")):null},[l]),p=o.useMemo(()=>{const s=f(l);return i||!s.isValid()?null:ye(s.startOf("day"))},[l,!!i]);return e.jsxs(k,{sx:{p:2,mb:3},children:[e.jsx(h,{variant:"h6",mb:.5,children:"Dashboard widget preview"}),e.jsx(h,{variant:"body2",color:"text.secondary",mb:2,children:"The dashboard shows at most one challenge, and only inside its lead-in â a month for the novel challenge, a fortnight for the others. Pick a date to see what a writer would get on it."}),e.jsxs(g,{direction:"row",flexWrap:"wrap",gap:1,alignItems:"center",mb:2,children:[e.jsx(x,{type:"date",size:"small",label:"Pretend it is",value:l,onChange:s=>u(s.target.value),InputLabelProps:{shrink:!0}}),d.map(s=>e.jsx(j,{size:"small",variant:l===M(s.date)?"contained":"outlined",color:"inherit",onClick:()=>u(M(s.date)),children:s.label},s.label))]}),i?e.jsxs(e.Fragment,{children:[e.jsxs(h,{variant:"body2",color:"text.secondary",mb:1.5,children:["Showing ",e.jsx("strong",{children:P(i.run.challengeId).name})," ","(",i.run.runId,") · phase ",e.jsx("strong",{children:i.phase}),i.run.challengeId!==n&&" â a different challenge than the one selected above, because that is the one a writer would actually be shown","."]}),e.jsxs(g,{direction:"row",flexWrap:"wrap",gap:2,alignItems:"flex-start",children:[e.jsx(I,{label:"Not joined",widget:i,optedIn:!1}),e.jsx(I,{label:"Joined",widget:i,optedIn:!0}),e.jsx(I,{label:"Collapsed",widget:i,optedIn:!0,startCollapsed:!0})]})]}):e.jsxs(J,{severity:"info",children:["Nothing would show on ",f(l).format("MMM D, YYYY")," â the dashboard closes up around it.",p?` The next writer to see one sees it on ${p.format("MMM D, YYYY")}.`:""]})]})}function I({label:n,widget:a,optedIn:d,startCollapsed:l}){const[u,i]=o.useState(!!l);return e.jsxs(y,{width:be,maxWidth:"100%",children:[e.jsx(h,{variant:"overline",color:"text.secondary",display:"block",mb:.5,children:n}),e.jsx(ge,{widget:a,optedIn:d,stats:d&&fe(a)?je(a):null,collapsed:u,onToggleCollapsed:()=>i(p=>!p),onJoin:()=>{}})]})}const De=["team","solo","multiplayer","monster","community"],w=()=>({name:"",description:"",date:f().format("YYYY-MM-DDTHH:mm"),durationMinutes:30,type:"team",link:"",daily:!1}),Ce=n=>{var a;return{id:n.id,name:n.name||"",description:n.description||"",date:(a=n.date)!=null&&a.toDate?f(n.date.toDate()).format("YYYY-MM-DDTHH:mm"):f().format("YYYY-MM-DDTHH:mm"),durationMinutes:n.durationMinutes??30,type:n.type||"team",link:n.link||"",daily:n.daily||!1}};function Me({open:n,value:a,busy:d,onChange:l,onClose:u,onSave:i}){const p=!!a.id;return e.jsxs(_,{open:n,onClose:u,maxWidth:"sm",fullWidth:!0,children:[e.jsx($,{children:p?"Edit event":"Add an event"}),e.jsx(U,{children:e.jsxs(g,{spacing:2,mt:1,children:[e.jsxs(g,{direction:"row",flexWrap:"wrap",gap:2,children:[e.jsx(x,{size:"small",label:"Name",autoFocus:!0,value:a.name,onChange:s=>l({...a,name:s.target.value}),sx:{flex:"1 1 240px"}}),e.jsx(x,{select:!0,size:"small",label:"Type",value:a.type,onCh
1ange:s=>l({...a,type:s.target.value}),sx:{minWidth:160},children:De.map(s=>e.jsx(E,{value:s,children:s},s))})]}),e.jsxs(g,{direction:"row",flexWrap:"wrap",gap:2,alignItems:"center",children:[e.jsx(x,{size:"small",type:"datetime-local",label:"Starts",InputLabelProps:{shrink:!0},value:a.date,onChange:s=>l({...a,date:s.target.value})}),e.jsx(x,{size:"small",type:"number",label:"Minutes",value:a.durationMinutes,onChange:s=>l({...a,durationMinutes:Number(s.target.value)}),sx:{width:120}}),e.jsx(q,{control:e.jsx(K,{checked:a.daily,onChange:s=>l({...a,daily:s.target.checked})}),label:"Repeats daily"})]}),e.jsx(x,{size:"small",label:"Description",value:a.description,onChange:s=>l({...a,description:s.target.value})}),e.jsx(x,{size:"small",label:"Link (optional)",value:a.link,onChange:s=>l({...a,link:s.target.value})})]})}),e.jsxs(Q,{children:[e.jsx(j,{onClick:u,children:"Cancel"}),e.jsx(j,{variant:"contained",disableElevation:!0,disabled:d||!a.name.trim(),onClick:i,children:p?"Save changes":"Add event"})]})]})}function Ye(){var W;const n=X(re),[a,d]=o.useState("novel"),[l,u]=o.useState(""),[i,p]=o.useState(null),[s,Y]=o.useState([]),[c,v]=o.useState(w()),[R,D]=o.useState(!1),[S,C]=o.useState(!1),b=o.useMemo(()=>ie(a),[a]),r=o.useMemo(()=>b.find(t=>t.runId===l)||b[0],[b,l]);o.useEffect(()=>{const t=b[0];t&&!b.some(m=>m.runId===l)&&u(t.runId)},[b]),o.useEffect(()=>{if(!r)return;let t=!1;return Promise.all([he(r),A(r.runId)]).then(([m,G])=>{t||(p(m),Y(G))}),()=>{t=!0}},[r==null?void 0:r.runId]);const T=async()=>{r&&Y(await A(r.runId))},O=()=>{v(w()),D(!0)},B=t=>{v(Ce(t)),D(!0)},H=async()=>{if(!r||!c.name.trim())return;const t=!!c.id;C(!0);const m=await ue(r.runId,{id:c.id||de(),name:c.name.trim(),description:c.description.trim()||void 0,date:ne.fromDate(f(c.date).toDate()),durationMinutes:Number(c.durationMinutes)||void 0,type:c.type,link:c.link.trim()||void 0,daily:c.daily},t);C(!1),m&&(D(!1),v(w()),await T()),n({open:!0,message:m?t?"Event updated":"Event added":"Could not save the event",severity:m?"success":"error"})},V=async t=>{r&&(await me(r.runId,t),await T())},F=async()=>{if(!r)return;C(!0);const t=await pe({run:r,scope:"participants",prop:xe(r.challengeId,r.month)});C(!1),n({open:!0,message:`Rebuilt the top ${t.length}`,severity:"success"})};return e.jsxs(y,{display:"flex",flexDirection:"column",gap:2,children:[e.jsx(h,{variant:"h5",mb:2,children:"Challenges"}),e.jsxs(k,{sx:{p:2},children:[e.jsxs(g,{direction:"row",flexWrap:"wrap",gap:2,alignItems:"center",children:[e.jsx(x,{select:!0,size:"small",label:"Challenge",value:a,onChange:t=>d(t.target.value),sx:{minWidth:200},children:oe().map(t=>e.jsx(E,{value:t,children:P(t).name},t))}),e.jsx(x,{select:!0,size:"small",label:"Run",value:(r==null?void 0:r.runId)||"",onChange:t=>u(t.target.value),sx:{minWidth:200},children:b.map(t=>e.jsx(E,{value:t.runId,children:t.shortLabel},t.runId))}),e.jsx(y,{flexGrow:1}),e.jsxs(h,{variant:"body2",color:"text.secondary",children:[(i==null?void 0:i.participantCount)??0," participants ·"," ",((W=i==null?void 0:i.topParticipants)==null?void 0:W.length)??0," cached"]}),e.jsx(j,{size:"small",startIcon:e.jsx(Z,{}),disabled:S,onClick:F,children:"Rebuild top 50"})]}),e.jsx(h,{variant:"caption",color:"text.secondary",display:"block",mt:1,children:"Runs come from CHALLENGE_CONFIG.months in packages/static-data/src/challenges.ts â change the months there to move a challenge."})]}),e.jsxs(k,{sx:{p:2},children:[e.jsxs(g,{direction:"row",alignItems:"center",gap:2,children:[e.jsxs(h,{variant:"overline",children:["Schedule · ",r==null?void 0:r.shortLabel]}),e.jsx(y,{flexGrow:1}),e.jsx(j,{size:"small",variant:"contained",disableElevation:!0,startIcon:e.jsx(ee,{}),disabled:!r,onClick:O,children:"Add event"})]}),s.length===0?e.jsx(h,{variant:"body2",color:"text.secondary",mt:1,children:"No events for this run yet."}):e.jsx(g,{mt:1,divider:e.jsx(se,{}),children:s.map(t=>{var m;return e.jsxs(g,{direction:"row",alignItems:"center",gap:2,py:1,children:[e.jsxs(y,{flexGrow:1,minWidth:0,children:[e.jsx(h,{sx:{fontWeight:700},children:t.name}),e.jsxs(h,{variant:"caption",color:"text.secondary",children:[t.daily?"Daily · "
1:"",(m=t.date)!=null&&m.toDate?f(t.date.toDate()).format("MMM D, h:mm A"):"No date",t.durationMinutes?` · ${t.durationMinutes} min`:"",` · ${t.type}`]})]}),e.jsx(z,{size:"small",onClick:()=>B(t),children:e.jsx(ae,{fontSize:"small"})}),e.jsx(z,{size:"small",onClick:()=>V(t.id),children:e.jsx(te,{fontSize:"small"})})]},t.id)})})]}),e.jsx(ve,{challengeId:a}),e.jsx(Me,{open:R,value:c,busy:S,onChange:v,onClose:()=>D(!1),onSave:H})]})}export{Ye 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.