PageSourceSearch

https://socialnarratives.ai/assets/Dashboard-4mckxn7F.js

js socialnarratives.ai collected 2026-10-05 15:08:29 UTC 53,990 bytes, 1 lines download raw bytes

1import{j as e,m as g,c as pe,X as Ze,U as et,p as tt,as as ue,B as H,aU as st,e as at,f as rt,g as De,L as Ie,aV as it,P as nt,aW as ot,$ as lt,aO as J,l as X,aX as dt,G as ct,y as Te,am as Be}from"./ui-vendor-XNsX7NFl.js";import{a as h,u as p,T as Pe}from"./i18n-BCZ_8xSB.js";import{u as xe,J as S,B as ke,a7 as x,_ as he,P as mt,d as ut,E as xt,z as ht,ak as Ee,D as gt,b0 as bt,aF as ft,bx as pt,by as kt,a3 as vt,Q as yt,bv as jt,bz as Nt,bA as wt,S as St,a8 as Ct}from"./index-Dg7geK91.js";import{b as $e,L as ve}from"./react-router-oAHNt2ka.js";import{P as At}from"./PullToRefresh-CBBurnpR.js";import{A as Rt}from"./AsyncErrorState-hWN8PH73.js";import{S as $}from"./SectionHeader-Csp1tLNZ.js";import{g as Dt,m as It,a as Tt}from"./moodWords-BbDtDjY2.js";import{b as Bt}from"./boardTemplates-CVuX0EEq.js";import{h as Pt}from"./packAvailability-CbMDVbWF.js";import{u as Et}from"./usePlatform-jw2ahvaa.js";import{f as $t,q as Lt,l as _t,j as Ut,h as Mt}from"./firebase-db-Csu2kn54.js";import{a as Ft}from"./offlineStoryService-D7MOJvdI.js";import{b as Le,g as _e,c as Ot}from"./scheduleStorageService-z2SbfB12.js";import{g as Kt,a as Wt}from"./boardStorageService-Bkc8ROiN.js";import"./firebase-auth-BWbhO1CC.js";import"./capacitor-DQeCf45c.js";import"./StateHeading-D9MlYpnP.js";import"./emotionConstants-B6UviN0Q.js";import"./stripeConfig-X3dkQhO0.js";import"./plainText-9F6VL9GP.js";import"./offlineScheduleService-CIGpnk33.js";function Ue({hasHero:t=!1,hasStory:a=!1,hasSchedule:s=!1}){const{user:r,updateProfile:i}=xe(),n=h.useMemo(()=>[{id:"hero",completed:t,icon:"👤",path:"/characters"},{id:"story",completed:a,icon:"📖",path:"/create"},{id:"schedule",completed:s,icon:"📅",path:"/schedules/create"}],[t,a,s]),l=n.filter(C=>C.completed).length,o=n.length,d=l===o,c=r?.onboarding?.dismissed===!0,b=!c&&!d,m=h.useCallback(async()=>{!r||!i||await i({onboarding:{...r.onboarding,dismissed:!0,dismissedAt:new Date().toISOString()}})},[r,i]);return{steps:n,completedCount:l,totalCount:o,allComplete:d,shouldShow:b,isDismissed:c,dismiss:m}}function Yt({hasHero:t,hasStory:a,hasSchedule:s}){const{t:r}=p("dashboard"),i=$e(),n=S(),{steps:l,completedCount:o,totalCount:d,allComplete:c,shouldShow:b,isDismissed:m,dismiss:C}=Ue({hasHero:t,hasStory:a,hasSchedule:s}),k=l.find(u=>!u.completed),L=o/d*100,R=u=>r(`onboarding.steps.${u.id}.title`),D=k?R(k):"",f=u=>{const j=l.slice(0,u).find(v=>!v.completed);return j?R(j):D};return m||!b&&!c?null:c?e.jsx(g.div,{initial:n?!1:{opacity:0,y:-20},animate:n?void 0:{opacity:1,y:0},exit:n?void 0:{opacity:0,y:-20},"data-testid":"onboarding-checklist",className:"mb-6 rounded-xl border border-sage-200 bg-sage-50 p-5 dark:border-sage-800 dark:bg-dim-surface",children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex h-14 w-14 shrink-0 items-center justify-center rounded-xl bg-white text-sage-700 shadow-sm dark:bg-dim-elevated dark:text-sage-300","aria-hidden":"true",children:e.jsx(pe,{className:"h-7 w-7"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-ink dark:text-dim-text font-['Quicksand']",children:r("onboarding.allComplete")}),e.jsx("p",{className:"text-sm text-slate-600 dark:text-dim-text-secondary",children:r("onboarding.readyToGo")})]})]}),e.jsx(ke,{onClick:C,variant:"primary",size:"sm",children:r("onboarding.keepExploring")})]})}):e.jsxs(g.div,{initial:n?!1:{opacity:0,y:-20},animate:n?void 0:{opacity:1,y:0},"data-testid":"onboarding-checklist",className:"mb-6 rounded-xl border border-slate-100 bg-white p-5 shadow-sm dark:border-dim-border dark:bg-dim-surface sm:p-6",children:[e.jsxs("div",{className:"mb-4 flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-ink dark:text-dim-text font-['Quicksand']",children:r("onboarding.title")}),e.jsx("p",{className:"mt-1 text-sm text-slate-600 dark:text-dim-text-secondary",children:r("onboarding.progress",{completed:o,total:d})}),e.jsx("p",{className:"mt-2 max-w-2xl text-sm text-slate-600 dar
1k:text-dim-text-secondary",children:r("onboarding.intro","Set up the basics in three small steps. Each one makes stories and schedules feel more personal.")})]}),e.jsx("button",{onClick:C,className:"touch-target flex shrink-0 items-center justify-center rounded-full text-slate-500 transition-colors hover:bg-slate-100 hover:text-slate-600 focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 dark:text-dim-text-secondary dark:hover:bg-dim-border dark:hover:text-dim-text","aria-label":r("onboarding.dismiss"),children:e.jsx(Ze,{className:"w-5 h-5","aria-hidden":"true"})})]}),e.jsx("div",{className:"w-full bg-slate-100 dark:bg-dim-border rounded-full h-2 mb-6",children:e.jsx(g.div,{initial:n?!1:{width:0},animate:{width:`${L}%`},className:"bg-sage-600 dark:bg-sage-300 h-2 rounded-full",transition:n?{duration:0}:{duration:.5,ease:"easeOut"}})}),k&&e.jsx("div",{className:"mb-5 rounded-xl border border-sage-200 bg-sage-50 p-4 dark:border-sage-700 dark:bg-sage-900/20",children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-white text-sage-700 shadow-sm dark:bg-dim-elevated dark:text-sage-300",children:e.jsx(et,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-wide text-sage-700 dark:text-sage-300",children:r("onboarding.nextStep","Suggested next step")}),e.jsx("h3",{className:"font-bold text-ink dark:text-dim-text",children:r("onboarding.nextStepHeading",{step:D,defaultValue:"Start with {{step}}"})}),e.jsx("p",{className:"mt-1 text-sm text-slate-600 dark:text-dim-text-secondary",children:r(`onboarding.steps.${k.id}.example`,k.id==="hero"?"Start with one child or student. You can add more later.":k.id==="story"?"Try a familiar moment first, like bedtime, dentist visits, or sharing turns.":"Start with a short routine of three to five steps.")})]})]}),e.jsx(ke,{onClick:()=>i(k.path),size:"sm",rightIcon:e.jsx(tt,{className:"h-4 w-4","aria-hidden":"true"}),className:"w-full sm:w-auto",children:r("onboarding.startNext","Start this step")})]})}),e.jsx("div",{className:"space-y-3",children:l.map((u,j)=>{const v=k?.id===u.id,I=!u.completed&&!v?f(j):"";return e.jsxs("div",{"aria-current":v?"step":void 0,className:`flex flex-col gap-4 roun
1ded-xl border p-4 transition-all sm:flex-row sm:items-center ${u.completed?"border-sage-200 bg-sage-50 dark:border-sage-700 dark:bg-sage-900/20":v?"border-sage-200 bg-white ring-1 ring-sage-100 dark:border-sage-700 dark:bg-dim-elevated dark:ring-sage-900/40":"border-slate-100 bg-slate-50 dark:border-dim-border dark:bg-dim-border/50"}`,children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-4",children:[e.jsx("div",{className:`flex h-11 w-11 shrink-0 items-center justify-center rounded-lg ${u.completed?"bg-sage-600 text-white":"bg-white text-slate-600 shadow-sm dark:bg-dim-elevated dark:text-dim-text-secondary"}`,children:u.completed?e.jsx(pe,{className:"w-5 h-5","aria-hidden":"true"}):e.jsx("span",{className:"text-lg font-bold",children:j+1})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h3",{className:`font-bold ${u.completed?"text-sage-700 dark:text-sage-300":"text-slate-700 dark:text-dim-text"}`,children:r(`onboarding.steps.${u.id}.title`)}),e.jsx("p",{className:`text-sm ${u.completed?"text-sage-700 dark:text-sage-300":"text-slate-600 dark:text-dim-text-secondary"}`,children:r(`onboarding.steps.${u.id}.description`)})]})]}),v&&e.jsx("span",{className:"flex min-h-[40px] shrink-0 items-center rounded-full bg-sage-100 px-3 text-sm font-bold text-sage-700 dark:bg-sage-900/40 dark:text-sage-300",children:r("onboarding.currentStep","Current step")}),!u.completed&&!v&&e.jsx("span",{className:"flex min-h-[40px] shrink-0 items-center rounded-full bg-slate-100 px-3 text-sm font-bold text-slate-600 dark:bg-dim-elevated dark:text-dim-text-secondary",children:r("onboarding.afterStep",{step:I,defaultValue:"After {{step}}"})}),u.completed&&e.jsx("span",{className:"flex min-h-[40px] shrink-0 items-center text-sm font-bold text-sage-700 dark:text-sage-300",children:r("onboarding.done")})]},u.id)})})]})}function Gt({onAddChild:t,onReadSample:a,onDismiss:s}){const{t:r}=p("dashboard");return e.jsxs("section",{"data-testid":"first-run-panel","aria-labelledby":"first-run-title",className:"mb-6 rounded-xl border border-sage-200 bg-white p-5 shadow-sm sm:p-6 dark:border-sage-800 dark:bg-dim-surface",children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-wide text-sage-700 dark:text-sage-300",children:r("firstRun.eyebrow")}),e.jsx("h2",{id:"first-run-title",className:"mt-1 font-['Quicksand'] text-xl font-bold text-slate-900 sm:text-2xl dark:text-dim-text",children:r("firstRun.title")}),e.jsx("p",{className:"mt-2 max-w-2xl text-sm text-slate-600 sm:text-base dark:text-dim-text-secondary",children:r("firstRun.body")}),e.jsxs("div",{className:"mt-5 flex flex-col gap-3 sm:flex-row sm:items-center",children:[e.jsxs("button",{type:"button",onClick:t,className:"inline-flex min-h-[48px] items-center justify-center gap-2 rounded-lg bg-sage-600 px-5 text-base font-bold text-white shadow-sm transition-colors hover:bg-sage-700 focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 focus-visible:ring-offset-2 dark:focus-visible:ring-offset-dim-surface",children:[e.jsx(ue,{className:"h-5 w-5","aria-hidden":"true"}),r("firstRun.primary")]}),e.jsxs("button",{type:"button",onClick:a,className:"inline-flex min-h-[48px] items-center justify-center gap-2 rounded-lg border border-sage-200 bg-white px-5 text-base font-bold text-sage-700 transition-colors hover:bg-sage-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 focus-visible:ring-offset-2 dark:border-sage-700 dark:bg-dim-surface dark:text-sage-300 dark:hover:bg-sage-900/30 dark:focus-visible:ring-offset-dim-surface",children:[e.jsx(H,{className:"h-5 w-5","aria-hidden":"true"}),r("firstRun.secondary")]}),s&&e.jsx("button",{type:"button",onClick:s,className:"min-h-[44px] rounded-lg px-3 text-sm font-bold text-slate-600 underline-offset-2 hover:underline focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 sm:ml-auto dark:text-dim-text-secondary",children:r("firstRun.hideGuide")})]})]})}function qt(t){return t<12?"greeting.morning":t<18?"greeting.afternoon":"greeting.evening"}function ge(t,a){(t.key==="Enter"||t.key===" ")&&(t.preventDefault(),a())}function Me(t){const a=t?.items||[],s=a.length,r=a.filter(n=>n.completed).length,i=s>0?Math.round(r/s*100):0;return{completed:r,total:s,percent:i}}function Ht(t){return(t?.docs||[]).map(s=>({id:s.id,...s.data()})).filter(s=>s.type==="child").slice(0,10)}const Vt={story:{card:"border-sage-200 bg-sage-50/80 dark:border-sage-800 dark:bg-sage-900/25",icon:"bg-sage-100 text-sage-700 dark:bg-sage-900/40 dark:text-sage-300",button:"bg-sage-600 text-white hover:bg-sage-700 focus-visible:ring-sage-500"},schedule:{card:"border-slate-200 bg-slate-50/90 dark:border-slate-700 dark:bg-slate-900/40",icon:"bg-slate-200 text-slate-700 dark:bg-slate-800 dark:text-slate-200",button:"bg-slate-800 text-white hover:bg-slate-900 focus-visible:ring-slate-500 dark:bg-slate-200 dark:text-slate-900 dark:hover:bg-white"},balanced:{card:"border-honey-100 bg-honey-50 dark:border-dim-border dark:bg-dim-surface",icon:"bg-honey-100 text-honey-700 dark:bg-dim-elevated dark:text-sun",button:"bg-sage-600 text-white hover:bg-sage-700 focus-visible:ring-sage-500"}},zt={hidden:{opacity:0,y:8},visible:{opacity:1,y:0}};function Qt({stats:t,t:a}){const s=t?.totalBooks,r=t?.totalSchedules;return!Number.isFinite(s)||!Number.isFinite(r)||s===0&&r===0?null:e.jsxs("p",{className:"text-slate-600 dar
1k:text-dim-text-secondary","data-testid":"dashboard-stats-summary",children:[e.jsx(Pe,{t:a,i18nKey:"stats.summary",values:{stories:a("stats.storyCount",{count:s}),schedules:a("stats.scheduleCount",{count:r})},components:{bold:e.jsx("span",{className:"font-bold text-ink dark:text-dim-text"})}})," ",a("stats.readyForAdventure")]})}const Jt=({userName:t,isLoadingData:a,stats:s})=>{const{t:r}=p("dashboard"),i=S(),n=qt(new Date().getHours());return e.jsxs(g.div,{className:"mb-5 sm:mb-8",initial:i?!1:"hidden",animate:i?void 0:"visible",variants:i?void 0:zt,transition:i?{duration:0}:{duration:.15},children:[e.jsxs("h1",{className:"mb-2 text-2xl font-bold font-['Quicksand'] text-ink sm:text-3xl md:text-4xl dark:text-dim-text",children:[e.jsx(Pe,{t:r,i18nKey:"greetingWithName",values:{greeting:r(n),name:t.split(" ")[0]},components:{name:e.jsx("span",{className:"text-sage-600 dark:text-sage-300"})}}),e.jsx(g.span,{className:"inline-block ml-2","aria-hidden":"true",animate:i?void 0:{rotate:[0,14,-8,14,-4,10,0]},transition:i?{duration:0}:{duration:1.5,delay:.3},children:"👋"})]}),a?e.jsx("div",{className:"text-slate-600 dark:text-dim-text-secondary",children:e.jsx(x,{className:"h-4 w-72 max-w-full mt-1 inline-block align-middle",label:r("stats.loading")})}):e.jsx(Qt,{stats:s,t:r})]})},Xt={hidden:{opacity:0,y:8},visible:{opacity:1,y:0}};function Zt({actionId:t,text:a,isLoadingData:s,loadingLabel:r}){return s?e.jsx("span",{"data-testid":`quick-action-count-${t}`,className:"mt-1 flex justify-center",children:e.jsx(x,{className:"h-3.5 w-8",label:r})}):a?e.jsx("span",{"data-testid":`quick-action-count-${t}`,className:"mt-1 block text-xs font-bold text-slate-600 dark:text-dim-text-secondary",children:a}):null}function es({onNavigate:t,stats:a,isLoadingData:s}){const{t:r}=p("dashboard"),i=S(),n=[{id:"create-story",label:r("quickActions.createStory"),description:r("quickActions.createStoryDesc"),path:"/create",Icon:st,className:"bg-sage-600 text-white hover:bg-sage-700"},{id:"create-schedule",label:r("quickActions.createSchedule"),description:r("quickActions.createScheduleDesc"),path:"/schedules/create",Icon:at,className:"bg-slate-700 text-white hover:bg-slate-800"}],l=[{id:"library",label:r("quickActions.myLibrary"),countKey:"stats.storyCount",count:a?.totalBooks,path:"/library",Icon:rt,iconClassName:"bg-sage-100 text-sage-700 dark:bg-dim-elevated dark:text-sage-300"},{id:"schedules",label:r("quickActions.mySchedules"),countKey:"stats.scheduleCount",count:a?.totalSchedules,path:"/schedules",Icon:De,iconClassName:"bg-slate-200 text-slate-700 dark:bg-dim-elevated dark:text-slate-200"},{id:"boards",label:r("quickActions.myBoards"),countKey:"stats.boardCount",count:a?.totalBoards,path:"/boards",Icon:Ie,iconClassName:"bg-slate-100 text-slate-700 dark:bg-dim-elevated dark:text-slate-200"}];return e.jsxs(g.section,{initial:i?!1:"hidden",animate:i?void 0:"visible",variants:i?void 0:Xt,transition:{duration:.15},children:[e.jsx("div",{className:"grid grid-cols-2 gap-3 sm:gap-4",children:n.map(o=>e.jsxs("button",{type:"button","aria-label":o.label,onClick:()=>t(o.path),className:`min-h-[96px] min-w-0 rounded-xl p-3 text-left shadow-sm transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 focus-visible:ring-offset-2 sm:p-4 dark:focus-visible:ring-offset-dim-deep ${o.className}`,children:[e.jsx("span",{"aria-hidden":"true","data-testid":`quick-action-icon-${o.id}`,className:"flex h-9 w-9 items-center justify-center rounded-lg bg-white/20",children:e.jsx(o.Icon,{className:"h-5 w-5"})}),e.jsx("span",{className:"mt-2 block break-words font-['Quicksand'] text-sm font-bold sm:text-base",children:o.label}),e.jsx("span",{className:"mt-1 block text-xs leading-snug text-white/90",children:o.description})]},o.id))}),e.jsx("div",{className:"mt-3 grid grid-cols-3 gap-2 sm:mt-4 sm:gap-3",children:l.map(o=>e.jsxs("button",{type:"button","aria-label":o.label,onClick:()=>t(o.path),className:"min-h-[80px] min-w-0 rounded-xl border border-slate-100 bg-white p-2 text-center shadow-sm transition-colors hover:bg-sage-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 focus-visible:ring-offset-2 sm:p-3 dark:border-dim-border dark:bg-dim-surface dark:hover:bg-dim-elevated dark:focus-visible:ring-offset-dim-deep",children:[e.jsx("span",{"aria-hidden":"true","data-testid":`quick-action-icon-${o.id}`,className:`mx-auto flex h-8 w-8 items-center justify-center rounded-lg ${o.iconClassName}`,children:e.jsx(o.Icon,{className:"h-4 w-4"})}),e.jsx("span",{className:"mt-1 block break-words text-xs font-bold leading-tight text-ink dark:text-dim-text",children:o.label}),e.jsx(Zt,{actionId:o.id,text:Number.isFinite(o.count)?r(o.countKey,{count:o.count}):null,isLoadingData:s,loadingLabel:r("stats.loadingCount")})]},o.id))})]})}const ts={hidden:{opacity:0,y:8},visible:{opacity:1,y:0}},ss=["flex","flex","flex","hidden sm:flex","hidden sm:flex"],as=({characters:t,isLoadingData:a,loadFailed:s=!1,onNavigate:r,compact:i=!1})=>{const{t:n}=p("dashboard"),l=S(),o=t.length===0;return!a&&s&&o?null:e.jsxs(g.section,{"aria-labelledby":"dashboard-heroes-title",className:"bg-white dark:bg-dim-surface rounded-xl p-4 border border-slate-100 dar
1k:border-dim-border shadow-sm",initial:l?!1:"hidden",animate:l?void 0:"visible",variants:l?void 0:ts,transition:l?{duration:0}:{duration:.15},children:[e.jsx($,{id:"dashboard-heroes-title",title:n("heroes.title"),icon:it,tone:"honey",action:!a&&!o?{label:n("heroes.manageAll"),to:"/characters",ariaLabel:n("heroes.manageAllLabel")}:void 0}),a?e.jsx("div",{className:"flex gap-4 overflow-x-hidden pb-4","aria-hidden":"true",children:ss.map((d,c)=>e.jsxs("div",{"data-testid":"hero-skeleton-pill",className:`${d} w-24 flex-shrink-0 flex-col items-center gap-2`,children:[e.jsx(x,{className:"h-20 w-20",rounded:"rounded-full"}),e.jsx(x,{className:"h-3 w-16"})]},c))}):o&&i?e.jsx("p",{"data-testid":"heroes-compact-empty",className:"text-sm text-slate-600 dark:text-dim-text-secondary",children:n("heroes.compactEmpty")}):o?e.jsxs("button",{type:"button",onClick:()=>r("/characters"),className:"flex w-full flex-col items-center justify-center rounded-xl border-2 border-dashed border-sage-200 bg-white p-8 text-center transition-colors hover:border-sage-500 hover:bg-sage-50/50 focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 dark:border-dim-border dark:bg-dim-surface dark:hover:bg-dim-elevated",children:[e.jsx("span",{className:"mb-3 flex h-14 w-14 items-center justify-center rounded-2xl bg-sage-50 text-sage-700 dark:bg-dim-elevated dark:text-sage-300","aria-hidden":"true",children:e.jsx(ue,{className:"h-7 w-7",strokeWidth:1.75})}),e.jsx("h3",{className:"font-bold text-lg mb-1 text-ink dark:text-dim-text",children:n("heroes.createFirst")}),e.jsx("p",{className:"text-sm max-w-xs text-slate-600 dark:text-dim-text-secondary",children:n("heroes.createFirstDesc")})]}):e.jsxs("div",{className:"flex gap-4 overflow-x-auto pb-4 scrollbar-hide",children:[e.jsxs("button",{type:"button",onClick:()=>r("/characters"),className:"flex min-h-[120px] w-24 flex-shrink-0 flex-col items-center justify-center gap-2 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 group",children:[e.jsx("span",{className:"w-20 h-20 rounded-full border-2 border-dashed flex items-center justify-center transition-colors border-slate-300 dark:border-dim-border group-hover:border-sage-500 dark:group-hover:border-sage-400 bg-white dark:bg-dim-elevated",children:e.jsx(nt,{className:"h-6 w-6 text-slate-500 group-hover:text-sage-600 dark:text-dim-text-muted dark:group-hover:text-sage-300","aria-hidden":"true"})}),e.jsx("span",{className:"text-xs font-bold text-slate-600 dark:text-dim-text-secondary",children:n("heroes.addNew")})]}),t.map(d=>e.jsxs("div",{className:"flex-shrink-0 w-24 flex flex-col items-center gap-2",children:[e.jsx("button",{type:"button",className:"h-20 w-20 overflow-hidden rounded-full border-2 border-transparent shadow-sm transition-colors hover:border-sage-500 focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 focus-visible:ring-offset-2 dark:focus-visible:ring-offset-dim-surface",onClick:()=>r(`/child/${d.id}`),"aria-label":n("heroes.openProfile",{name:d.name}),children:e.jsx("img",{src:d.imageUrl,alt:"",className:"w-full h-full object-cover"})}),e.jsx("span",{className:"text-xs font-bold truncate w-full text-center text-slate-700 dark:text-dim-text",children:d.name})]},d.id))]})]})},rs={hidden:{opacity:0,y:8},visible:{opacity:1,y:0}},le=7,is=Array(le).fill(null),Fe="bg-slate-100 dark:bg-dim-border",ns="min-w-0 p-5 rounded-2xl bg-white dark:bg-dim-surface border border-slate-100 dark:border-dim-border shadow-sm",w={stories:{number:"text-sage-700 dark:text-sage-300",tile:"bg-sage-50 text-sage-700 dark:bg-dim-elevated dark:text-sage-300",bar:"bg-sage-600 dark:bg-sage-300"},tasks:{number:"text-slate-700 dark:text-slate-300",tile:"bg-slate-100 text-slate-700 dark:bg-dim-elevated dark:text-slate-300",bar:"bg-slate-600 dark:bg-slate-300"},mood:{number:"text-honey-700 dark:text-sun",word:"text-ink dark:text-sun"},activity:{number:"text-sage-700 dark:text-sage-300",tile:"bg-sage-50 text-sage-700 dark:bg-dim-elevated dark:text-sage-300",bar:"bg-sage-500 dark:bg-sage-300"}},os=t=>Number.isFinite(t)?Math.min(Math.max(Math.round(t),0),100):0,E=t=>Number.isFinite(t)?t:0,ye=t=>Number.isFinite(t)&&t>0,ls=(t,a)=>
1{const s=It(a);return s?t(`progress.moodWords.${s}`):"—"},ds=t=>Array.isArray(t)?t:is,cs=t=>Number.isFinite(t)&&t!==0?Dt(t):Fe,ms=t=>Array.isArray(t)&&t.length===le?t.map(a=>({date:a?.date,active:a?.active===!0})):Array.from({length:le},()=>({date:void 0,active:!1})),Z=({children:t,testId:a})=>e.jsx("div",{className:ns,"data-testid":a,children:t}),de=({icon:t,className:a})=>{const s=t;return e.jsx("span",{className:`flex h-9 w-9 items-center justify-center rounded-lg ${a}`,"aria-hidden":"true",children:e.jsx(s,{className:"h-5 w-5"})})},je=({icon:t,accent:a,heading:s,caption:r,rate:i,reduceMotion:n,testId:l})=>{const o=os(i);return e.jsxs(Z,{testId:l,children:[e.jsx("div",{className:"flex items-center justify-between mb-3",children:e.jsx(de,{icon:t,className:a.tile})}),e.jsx("h3",{className:"font-bold text-ink dark:text-dim-text mb-1",children:s}),e.jsx("p",{className:`text-lg font-bold mb-3 ${a.number}`,children:r}),e.jsx("div",{className:"h-2 bg-slate-100 dark:bg-dim-border rounded-full overflow-hidden",role:"progressbar","aria-label":s,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":o,children:e.jsx(g.div,{className:`h-full rounded-full ${a.bar}`,initial:n?!1:{width:0},animate:{width:`${o}%`},transition:n?{duration:0}:{duration:.6,ease:[.2,0,0,1]}})})]})},us="—",Oe=({heading:t,leading:a,numberClass:s,testId:r,t:i})=>e.jsxs(Z,{testId:r,children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[a,e.jsx("span",{className:`text-2xl font-bold ${s}`,"data-testid":`${r}-total`,children:e.jsx("span",{"aria-hidden":"true",children:us})})]}),e.jsx("h3",{className:"font-bold text-ink dark:text-dim-text mb-1",children:t}),e.jsx("p",{className:"text-sm text-slate-600 dark:text-dim-text-secondary",children:i("progress.unavailable")})]}),xs=({emotionStats:t,heading:a,caption:s,t:r})=>{const i=e.jsx("span",{className:"text-2xl","data-testid":"mood-emoji","aria-hidden":"true",children:t?.averageEmoji||"😊"});if(!t)return e.jsx(Oe,{heading:a,leading:i,numberClass:w.mood.number,testId:"mood-tile",t:r});const n=ds(t.trend);return e.jsxs(Z,{testId:"mood-tile",children:[e.jsx("div",{className:"flex items-center justify-between mb-3",children:i}),e.jsx("h3",{className:"font-bold text-ink dark:text-dim-text mb-1",children:a}),e.jsx("p",{className:`text-lg font-bold ${w.mood.word}`,"data-testid":"mood-word",children:ls(r,t.average)}),e.jsx("p",{className:"text-sm text-slate-600 dark:text-dim-text-secondary mb-3",children:s}),e.jsx("div",{className:"flex gap-1","aria-hidden":"true",children:n.map((l,o)=>e.jsx("div",{className:`flex-1 h-2 rounded-full ${cs(l?.average)}`,title:l?.date},o))})]})},hs=({recentActivity:t,heading:a,t:s})=>{if(!t)return e.jsx(Oe,{heading:a,leading:e.jsx(de,{icon:J,className:w.activity.tile}),numberClass:w.activity.number,testId:"activity-tile",t:s});const r=t.summary,i=E(r?.storiesRead),n=E(r?.schedulesUsed),l=i+n,o=ms(t.days),d=o.filter(c=>c.active).length;return e.jsxs(Z,{testId:"activity-tile",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("span",{"data-testid":"activity-icon",children:e.jsx(de,{icon:J,className:w.activity.tile})}),e.jsx("span",{className:`text-2xl font-bold ${w.activity.number}`,"data-testid":"activity-total",children:l})]}),e.jsx("h3",{className:"font-bold text-ink dark:text-dim-text mb-1",children:a}),e.jsx("p",{className:"text-sm text-slate-600 dark:text-dim-text-secondary mb-3",children:s("progress.activityCaption",{stories:s("stats.storyCount",{count:i}),schedules:s("stats.scheduleCount",{count:n})})}),e.jsx("p",{className:"sr-only","data-testid":"activity-days-label",children:s("progress.activeDays",{count:d})}),e.jsx("div",{className:"flex gap-1","aria-hidden":"true",children:o.map((c,b)=>e.jsx("div",{"data-testid":"activity-day","data-active":c.active?"true":"false",className:`flex-1 h-2 rounded-full ${c.active?w.activity.bar:Fe}`},c.date||b))})]})},gs=({progressData:t,emotionStats:a,recentActivity:s,stats:r,childCount:i=0})=>{const{t:n}=p("dashboard"),l=S(),o=ye(r?.totalBooks)||ye(r?.totalSchedules);return t&&o?e.jsxs(g.section,{"aria-labelledby":"dashboard-progress-title",initial:l?!1:"hidden",animate:l?void 0:"visible",variants:l?void 0:rs,transition:{duration:.15},children:[e.jsx($,{id:"dashboard-progress-title",title:n("progress.title"),icon:ot,description:i>=2?n("progress.allChildren"):void 0}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(je,{icon:H,accent:w.stories,heading:n("progress.storiesRead"),caption:n("progress.storiesOf",{completed:E(t.stories?.completedStories),total:E(t.stories?.totalStories)}),rate:t.stories?.completionRate,reduceMotion:l,testId:"stories-tile"}),e.jsx(je,{icon:lt,accent:w.tasks,heading:n("progress.tasksCompleted"),caption:n("progress.tasksOf",{completed:E(t.schedules?.itemsCompleted),total:E(t.schedules?.itemsTotal)}),rate:t.schedules?.itemCompletionRate,reduceMotion:l,testId:"tasks-tile"}),e.jsx(xs,{emotionStats:a,heading:n("progress.weeklyMood"),caption:n("progress.checkInCount",{count:E(a?.count)}),t:n}),e.jsx(hs,{recentActivity:s,heading:n("progress.thisWeek"),t:n})]})]}):null},bs={hidden:{opacity:0,y:8},visible:{opacity:1,y:0}},fs={daily_routine:"recentSchedules.routine",task_sequence:"recentSchedules.task"},ps=({schedules:t,isLoadingData:a,onNavigate:s})=>{const{t:r}=p("dashboard"),i=S();return a?e.jsxs("section",{"aria-hidden":"true",className:"bg-white dark:bg-dim-surface rounded-2xl p-4 border border-slate-100 dar
1k:border-dim-border shadow-sm",children:[e.jsx(x,{className:"h-6 w-44 mb-4"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:Array.from({length:3}).map((n,l)=>e.jsxs("div",{className:"p-4 rounded-2xl bg-slate-50 dark:bg-dim-elevated border border-slate-100 dark:border-dim-border space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx(x,{className:"h-7 w-7",rounded:"rounded-full"}),e.jsx(x,{className:"h-4 w-16",rounded:"rounded-full"})]}),e.jsx(x,{className:"h-4 w-3/4"}),e.jsx(x,{className:"h-2 w-full",rounded:"rounded-full"})]},l))})]}):t.length===0?null:e.jsxs(g.section,{"aria-labelledby":"dashboard-recent-schedules",className:"bg-white dark:bg-dim-surface rounded-2xl p-4 border border-slate-100 dark:border-dim-border shadow-sm",initial:i?!1:"hidden",animate:i?void 0:"visible",variants:i?void 0:bs,transition:{duration:.15},children:[e.jsx($,{id:"dashboard-recent-schedules",title:r("recentSchedules.title"),icon:De,tone:"slate",action:{label:r("recentSchedules.viewAll"),to:"/schedules",ariaLabel:r("recentSchedules.viewAllLabel")}}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:t.map(n=>{const{total:l,percent:o}=Me(n);return e.jsxs("div",{role:"button",tabIndex:0,"aria-label":r("recentSchedules.open",{title:n.title,defaultValue:`Open schedule ${n.title}`}),onClick:()=>s(`/schedules/${n.id}`),onKeyDown:d=>ge(d,()=>s(`/schedules/${n.id}`)),className:"min-w-0 p-4 rounded-2xl bg-slate-50 dark:bg-dim-elevated border border-slate-100 dark:border-dim-border cursor-pointer transition-shadow hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-slate-500 focus-visible:ring-offset-2 dark:focus-visible:ring-offset-dim-surface",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2 mb-3",children:[e.jsx("span",{className:"text-2xl","aria-hidden":"true",children:n.items?.[0]?.emoji||"📋"}),e.jsx("span",{className:"text-xs font-bold px-2 py-0.5 rounded-full bg-slate-200 text-slate-700 dark:bg-dim-surface dark:text-slate-200",children:r(fs[n.type]||"recentSchedules.transition")})]}),e.jsx("h3",{className:"font-bold text-ink dark:text-dim-text mb-1 truncate",children:n.title}),e.jsx("p",{className:"text-xs text-slate-600 dark:text-dim-text-secondary mb-3",children:r("recentSchedules.itemCount",{count:l})}),e.jsx("div",{className:"h-1.5 bg-slate-200 dark:bg-dim-border rounded-full overflow-hidden","aria-hidden":"true",children:e.jsx(g.div,{className:"h-full bg-slate-600 dark:bg-slate-300 rounded-full",initial:i?!1:{width:0},animate:{width:`${o}%`},transition:i?{duration:0}:{duration:.6,ease:[.2,0,0,1]}})}),e.jsx("p",{className:"text-xs text-slate-600 dark:text-dim-text-secondary mt-1",children:r("recentSchedules.percentDone",{percent:o})})]},n.id)})})]})};function ks({boards:t=[],isLoadingData:a,onNavigate:s}){const{t:r}=p("dashboard");return a?e.jsxs("section",{"aria-hidden":"true",children:[e.jsx(x,{className:"mb-4 h-6 w-36"}),e.jsx("div",{className:"grid gap-3 sm:grid-cols-3",children:Array.from({length:3}).map((i,n)=>e.jsx(x,{className:"h-28",rounded:"rounded-xl"},n))})]}):t.length?e.jsxs("section",{"aria-labelledby":"dashboard-recent-boards",children:[e.jsx($,{id:"dashboard-recent-boards",title:r("recentBoards.title"),icon:Ie,tone:"slate",action:{label:r("recentBoards.viewAll"),to:"/boards",ariaLabel:r("recentBoards.viewAllLabel")}}),e.jsx("div",{className:"grid gap-3 sm:grid-cols-3",children:t.map(i=>e.jsxs("button",{type:"button",onClick:()=>s(`/boards/${i.id}`),"aria-label":r("recentBoards.open",{title:i.title}),className:"min-w-0 rounded-xl border border-slate-100 bg-white p-4 text-left shadow-sm transition-shadow hover:shadow-md focus:outline-none focus-visible:ring-2 focus-visible:ring-slate-500 focus-visible:ring-offset-2 dark:border-dim-border dark:bg-dim-surface dark:focus-visible:ring-offset-dim-deep",children:[e.jsx("span",{className:"mb-3 block text-2xl","aria-hidden":"true",children:Bt[i.type]?.icon||"📋"}),e.jsx("span",{className:"block truncate font-bold text-ink dark:text-dim-text",children:i.title}),e.jsx("span",{className:"mt-1 block text-xs text-slate-600 dar
1k:text-dim-text-secondary",children:r("recentBoards.items",{count:i.items?.length||0})})]},i.id))})]}):null}const vs={hidden:{opacity:0,y:8},visible:{opacity:1,y:0}};function ys({action:t,onNavigate:a}){const s=S(),r=t.icon,i=Vt[t.tone];return e.jsx(g.section,{className:`rounded-lg border p-4 shadow-sm ${i.card}`,initial:s?!1:"hidden",animate:s?void 0:"visible",variants:s?void 0:vs,transition:s?{duration:0}:{duration:.15},children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[e.jsx("span",{className:`flex h-11 w-11 flex-shrink-0 items-center justify-center rounded-lg ${i.icon}`,"aria-hidden":"true",children:e.jsx(r,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-wide text-slate-600 dark:text-dim-text-secondary",children:t.label}),e.jsx("h2",{className:"mt-1 text-lg font-bold text-ink dark:text-dim-text",children:t.title}),e.jsx("p",{className:"mt-1 text-sm text-slate-600 dark:text-dim-text-secondary",children:t.description})]})]}),e.jsxs("button",{type:"button",onClick:()=>a(t.path),className:`inline-flex min-h-[44px] flex-shrink-0 items-center justify-center gap-2 rounded-lg px-4 text-sm font-bold transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 dark:focus-visible:ring-offset-dim-deep ${i.button}`,children:[t.button,e.jsx(X,{className:"h-4 w-4","aria-hidden":"true"})]})]})})}function js({onOpen:t,motionProps:a={}}){const{t:s}=p("dashboard");return e.jsx(g.section,{className:"rounded-lg border border-sage-200 bg-sage-50/80 p-4 shadow-sm dark:border-sage-800 dark:bg-sage-900/25",...a,children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[e.jsx("span",{className:"flex h-11 w-11 flex-shrink-0 items-center justify-center rounded-lg bg-sage-100 text-sage-700 dark:bg-sage-900/40 dark:text-sage-300","aria-hidden":"true",children:e.jsx(H,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-lg font-bold text-ink dark:text-dim-text",children:s("sample.title")}),e.jsx("p",{className:"mt-1 text-sm text-slate-600 dark:text-dim-text-secondary",children:s("sample.body")})]})]}),e.jsxs("button",{type:"button",onClick:t,className:"inline-flex min-h-[44px] flex-shrink-0 items-center justify-center gap-2 rounded-lg bg-sage-600 px-4 text-sm font-bold text-white transition-colors hover:bg-sage-700 focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 focus-visible:ring-offset-2 dark:focus-visible:ring-offset-dim-deep",children:[s("sample.cta"),e.jsx(X,{className:"h-4 w-4","aria-hidden":"true"})]})]})})}function Ns(){return e.jsxs("section",{"aria-hidden":"true",children:[e.jsx(x,{className:"h-6 w-40 mb-4"}),e.jsx("div",{className:"rounded-3xl overflow-hidden border bg-white dark:bg-dim-surface border-slate-100 dark:border-dim-border",children:e.jsxs("div",{className:"flex flex-col sm:flex-row",children:[e.jsx(x,{className:"sm:w-48 h-48 sm:h-48",rounded:"rounded-none"}),e.jsxs("div",{className:"p-6 flex flex-col justify-center flex-1 gap-3",children:[e.jsx(x,{className:"h-3 w-24"}),e.jsx(x,{className:"h-6 w-3/4"}),e.jsx(x,{className:"h-3 w-full"}),e.jsx(x,{className:"h-3 w-1/2"})]})]})})]})}const ws=t=>t.coverImageUrl||t.pages?.[0]?.imageUrl||null;function Ss({book:t,isLoadingData:a,onNavigate:s,motionProps:r={}}){const{t:i}=p("dashboard"),n=S();if(a)return e.jsx(Ns,{});if(!t)return null;const l=()=>s(`/story/${t.id}/${he(t.title)}`),o=ws(t);return e.jsxs(g.section,{"aria-labelledby":"dashboard-jump-back-in",...r,children:[e.jsx($,{id:"dashboard-jump-back-in",title:i("jumpBackIn.title"),icon:dt}),e.jsx(g.div,{role:"button",tabIndex:0,"aria-label":i("jumpBackIn.resume",{title:t.title,defaultValue:`Resume reading ${t.title}`}),onClick:l,onKeyDown:d=>ge(d,l),className:"relative overflow-hidden rounded-3xl cursor-pointer group shadow-sm hover:shadow-md transition-shadow border bg-white dark:bg-dim-surface border-slate-100 dar
1k:border-dim-border focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 focus-visible:ring-offset-2 dark:focus-visible:ring-offset-dim-deep",whileHover:n?void 0:{y:-2},children:e.jsxs("div",{className:"flex flex-col sm:flex-row",children:[e.jsx("div",{className:"sm:w-48 h-48 sm:h-auto relative overflow-hidden",children:o?e.jsx("img",{src:o,alt:t.title,className:"w-full h-full object-cover"}):e.jsx("div",{className:`w-full h-full ${t.pages?.[0]?.color||"bg-sage-100 dark:bg-dim-elevated"}`})}),e.jsxs("div",{className:"min-w-0 p-6 flex flex-col justify-center flex-1",children:[e.jsx("span",{className:"text-xs font-bold text-sage-700 dark:text-sage-300 uppercase tracking-wider mb-2",children:i("jumpBackIn.lastOpened")}),e.jsx("h3",{className:"text-2xl font-bold mb-2 break-words text-ink dark:text-dim-text",children:t.title}),e.jsx("p",{className:"line-clamp-2 text-sm mb-4 text-slate-600 dark:text-dim-text-secondary",children:t.pages?.[0]?.text||i("jumpBackIn.defaultDescription")}),e.jsxs("div",{className:"flex items-center text-sm font-bold text-sage-700 dark:text-sage-300",children:[i("jumpBackIn.continueReading"),e.jsx(X,{className:"ml-1 h-4 w-4","aria-hidden":"true"})]})]})]})})]})}function Cs(){return e.jsxs("section",{"aria-hidden":"true",className:"bg-white dark:bg-dim-surface rounded-2xl p-4 border border-slate-100 dark:border-dim-border shadow-sm",children:[e.jsx(x,{className:"h-5 w-32 mb-3"}),e.jsx("div",{className:"space-y-3",children:Array.from({length:4}).map((t,a)=>e.jsxs("div",{className:"p-2 rounded-xl flex items-center gap-3",children:[e.jsx(x,{className:"w-12 h-12",rounded:"rounded-lg"}),e.jsx(x,{className:"h-3 w-32"})]},a))})]})}function As({books:t,isLoadingData:a,onNavigate:s}){const{t:r}=p("dashboard");return a?e.jsx(Cs,{}):t.length?e.jsxs("section",{"aria-labelledby":"dashboard-from-explore",className:"bg-white dark:bg-dim-surface rounded-2xl p-4 border border-slate-100 dark:border-dim-border shadow-sm",children:[e.jsx($,{id:"dashboard-from-explore",title:r("community.title"),icon:ct,action:{label:r("community.exploreMore"),to:"/explore",ariaLabel:r("community.exploreMoreLabel")}}),e.jsx("div",{className:"space-y-1",children:t.map(i=>{const n=()=>s(`/story/${i.id}/${he(i.title)}`),l=i.coverImageUrl||i.pages?.[0]?.imageUrl;return e.jsxs("div",{role:"button",tabIndex:0,"aria-label":r("community.openStory",{title:i.title,defaultValue:`Open story ${i.title}`}),onClick:n,onKeyDown:o=>ge(o,n),className:"flex min-h-[56px] cursor-pointer items-center gap-3 rounded-xl p-2 transition-colors hover:bg-sage-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 dark:hover:bg-dim-elevated",children:[e.jsx("div",{className:"w-12 h-12 rounded-lg overflow-hidden flex-shrink-0 bg-slate-100 dark:bg-dim-elevated",children:l?e.jsx("img",{src:l,className:"w-full h-full object-cover",alt:""}):null}),e.jsx("div",{className:"min-w-0",children:e.jsx("h3",{className:"font-bold text-sm truncate text-ink dark:text-dim-text",children:i.title})})]},i.id)})})]}):null}function Rs({onNavigate:t,variants:a}){const{t:s}=p("dashboard");return e.jsxs(g.section,{"data-testid":"dashboard-upsell","aria-labelledby":"dashboard-upsell-title",className:"rounded-2xl bg-sage-600 p-5 shadow-sm dark:shadow-none",variants:a,children:[e.jsxs("div",{className:"mb-2 flex items-center gap-3",children:[e.jsx("span",{className:"flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-xl bg-honey-100 text-ink","aria-hidden":"true","data-testid":"upsell-accent",children:e.jsx(Te,{className:"h-5 w-5"})}),e.jsx("h3",{id:"dashboard-upsell-title",className:"font-bold text-white",children:s("upsell.title")})]}),e.jsx("p",{className:"mb-4 text-sm text-white",children:s("upsell.description",{credits:mt.Family})}),e.jsxs("button",{type:"button",onClick:()=>t("/pricing?plan=family"),className:"flex min-h-[44px] w-full items-center justify-center gap-2 rounded-xl bg-white py-2.5 text-sm font-bold text-sage-800 shadow-sm transition-colors hover:bg-sage-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-offset-2 focus-visible:ring-offset-sage-600",children:[s("upsell.button"),e.jsx(X,{className:"h-4 w-4","aria-hidden":"true"})]})]})}const Ds="/pricing#credits";function Is(t,{isNative:a=!1,packsAvailable:s=!1}={}){return t.unlimited?null:t.planKey==="free"?"plans":!a&&s?"credits":null}const Ts=Ee.breakdown.pages,Ne="flex min-h-[44px] w-full items-center justify-center rounded-xl px-4 py-2.5 text-sm font-bold transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 focus-visible:ring-offset-2 dark:focus-visible:ring-offset-dim-surface",ce=(t,a)=>{try{return new Intl.NumberFormat(a||"en").format(t)}catch{return String(t)}};function Bs({tc:t,balance:a,language:s}){return a.welcomeOnly&&a.aboutStories>0?t("balance.welcome",{count:a.aboutStories,credits:ce(a.available,s)}):a.available>=bt?t("balance.aboutStories",{count:a.aboutStories}):a.available>0?t("balance.aboutPictures",{count:a.available}):t("balance.none")}function Ps({user:t,isNative:a=!1,showPlansAction:s=!0}){const{t:r,i18n:i}=p(["credits","common"]),n=i?.language||"en";if(!t)return null;const l=ut(t),o=Is(l,{isNative:a,packsAvailable:Pt()});return e.jsxs("section",{"aria-labelledby":"dashboard-credits-title",className:"rounded-2xl border border-slate-100 bg-white p-4 shadow-sm dark:border-dim-border dark:bg-dim-surface","data-testid":"dashboard-credits",children:[e.jsx($,{id:"dashboard-credits-title",level:2,title:r("balance.title"),icon:Te,action:{label:r("purchase.seeCredits"),to:xt},className:"mb-3"}),e.jsx("div",{"aria-live":"polite",children:l.unlimited?e.jsx("p",{className:"font-['Quicksand'] text-xl font-bold text-ink dark:text-dim-text",children:r("balance.admin")}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"flex items-baseline gap-2",children:[e.jsx("span",{className:"font-['Quicksand'] text-3xl font-bold tabular-nums text-ink dark:text-dim-text",children:ce(l.available,n)})," ",e.jsx("span",{className:"text-base font-semibold text-slate-600 dar
1k:text-dim-text-secondary",children:r("balance.unitWord",{count:l.available})})]}),e.jsx("p",{className:"mt-1 text-sm text-slate-700 dark:text-dim-text-secondary",children:e.jsx(Bs,{tc:r,balance:l,language:n})}),l.nextGrant&&e.jsx("p",{className:"mt-1 text-sm text-slate-700 dark:text-dim-text-secondary",children:r("balance.nextGrant",{amount:ce(l.nextGrant.amount,n),date:ht(l.nextGrant.at,n)})}),l.isLow&&!l.isEmpty&&e.jsx("p",{className:"mt-3 rounded-xl border border-honey-100 bg-honey-50 px-3 py-2 text-sm font-semibold text-ink dark:border-dim-border dark:bg-dim-elevated dark:text-sun","data-testid":"dashboard-credits-low",children:r("balance.low",{pages:Ts,max:Ee.max})})]})}),e.jsx("p",{className:"mt-3 text-sm text-slate-600 dark:text-dim-text-secondary",children:r("balance.emojiFree")}),o==="plans"&&s&&e.jsx(ve,{to:gt,className:`${Ne} mt-4 bg-sage-600 text-white hover:bg-sage-700`,children:r("notEnough.seePlans")}),o==="credits"&&e.jsx(ve,{to:Ds,className:`${Ne} mt-4 border-2 border-sage-200 bg-white text-sage-800 hover:bg-sage-50 dark:border-sage-700 dark:bg-dim-surface dark:text-sage-200 dark:hover:bg-dim-elevated`,children:r("notEnough.addCredits")})]})}const G=t=>t?typeof t=="string"?new Date(t).getTime()||0:typeof t=="number"?t:typeof t.toMillis=="function"?t.toMillis():typeof t.seconds=="number"?t.seconds*1e3:0:0,Es={completedStories:0,totalStories:0,completionRate:0},$s={completedSchedules:0,totalSchedules:0,completionRate:0,itemsCompleted:0,itemsTotal:0,itemCompletionRate:0},Ls=async(t,{throwOnError:a=!1}={})=>{try{const[s,r]=await Promise.all([ft(t,{throwOnError:a}),_s(t,{throwOnError:a})]);return{stories:s,schedules:r,overall:{totalItems:s.totalStories+r.totalSchedules,completedItems:s.completedStories+r.completedSchedules,overallRate:Us(s,r)}}}catch(s){if(console.error("Error getting progress stats:",s),a)throw s;return{stories:{...Es},schedules:{completedSchedules:0,totalSchedules:0,completionRate:0},overall:{totalItems:0,completedItems:0,overallRate:0}}}},_s=async(t,{throwOnError:a=!1}={})=>{try{const s=await Le(t,{throwOnError:a}),r=await _e(t,null,100,{throwOnError:a}),i=r.schedules||r||[];let n=0,l=0,o=0;return i.forEach(d=>{const c=d.items||[],b=c.filter(m=>m.completed).length;l+=b,o+=c.length,c.length>0&&b===c.length&&n++}),{completedSchedules:n,totalSchedules:s,completionRate:s>0?Math.round(n/s*100):0,itemsCompleted:l,itemsTotal:o,itemCompletionRate:o>0?Math.round(l/o*100):0}}catch(s){if(console.error("Error getting schedule progress stats:",s),a)throw s;return{...$s}}},Us=(t,a)=>{const s=t.totalStories+a.totalSchedules,r=t.completedStories+a.completedSchedules;return s===0?0:Math.round(r/s*100)},me=7,Ke=t=>new Date(t.getFullYear(),t.getMonth(),t.getDate()),we=t=>{const a=String(t.getMonth()+1).padStart(2,"0"),s=String(t.getDate()).padStart(2,"0");return`${t.getFullYear()}-${a}-${s}`},Ms=(t=new Date)=>{const a=Ke(t);return a.setDate(a.getDate()-(me-1)),a.getTime()},Se=(t=[],a=new Date)=>{const s=Ke(a),r=Array.from({length:me},(n,l)=>{const o=new Date(s);return o.setDate(s.getDate()-(me-1-l)),{date:we(o),active:!1,count:0}}),i=new Map(r.map((n,l)=>[n.date,l]));return t.forEach(n=>{const l=G(n);if(!l)return;const o=i.get(we(new Date(l)));o!==void 0&&(r[o].active=!0,r[o].count+=1)}),r},Fs=t=>Number.isFinite(t)?t:0,We=t=>t.reduce((a,s)=>a+(s.items||[]).filter(r=>r.completed).length,0),Os=async(t,{throwOnError:a=!1,now:s=new Date}={})=>{try{const[r,i]=await Promise.all([pt(t,{throwOnError:a}),Ks(t,{throwOnError:a})]),n=Ms(s),l=m=>G(m)>=n,o=(r.readDates??(r.recentBooks||[]).map(m=>m.lastRead)).filter(l),d=(i.recentSchedulesInWindow??i.recentSchedules??[]).filter(m=>l(m.lastUsed)),c=o.length,b=d.length;return{stories:r,schedules:i,days:Se([...o,...d.map(m=>m.lastUsed)],s),summary:{totalActivity:c+b,storiesRead:c,storiesCompleted:Fs(r.storiesCompleted),schedulesUsed:b,tasksCompleted:We(d)}}}catch(r){if(console.error("Error getting recent activity:",r),a)throw r;return{stories:{storiesRead:0,storiesCompleted:0,recentBooks:[],readDates:[]},schedules:{schedulesUsed:0,tasksCompleted:0,recentSchedules:[]},days:Se([],s),summary:{totalActivity:0,storiesRead:0,storiesCompleted:0,schedulesUsed:0,tasksCompleted:0}}}},Ks=async(t,{throwOnError:a=!1}={})=>{try{const s=new Date;s.setDate(s.getDate()-7);const r=s.getTime(),i=await _e(t,null,50,{throwOnError:a}),l=(i.schedules||i||[]).filter(o=>o.lastUsed&&G(o.lastUsed)>=r).sort((o,d)=>G(d.lastUsed)-G(o.lastUsed));return{schedulesUsed:l.length,tasksCompleted:We(l),recentSchedules:l.slice(0,5),recentSchedulesInWindow:l}}catch(s){if(console.error("Error getting recent schedule activity:",s),a)throw s;return{schedulesUsed:0,tasksCompleted:0,recentSchedules:[],recentSchedulesInWindow:[]}}},Ws=new Set(["community"]),P={throwOnError:!0},y=t=>{let a;try{a=Promise.resolve(t())}catch(s){a=Promise.reject(s)}return a.then(s=>({ok:!0,value:s}),s=>(console.error("Dashboard data load (partial) failed:",s),{ok:!1}))};function Ys(){const{user:t,loading:a}=xe(),s=t?t.id??"":null,[r,i]=h.useState(null),[n,l]=h.useState([]),[o,d]=h.useState([]),[c,b]=h.useState([]),[m,C]=h.useState([]),[k,L]=h.useState(null),[R,D]=h.useState(null),[f,u]=h.useState(null),[j,v]=h.useState(null),[I,ee]=h.useState({}),[V,T]=h.useState(!0),[O,_]=h.useState(!1),U=h.useRef(void 0),z=h.useRef(0),M=h.useCallback(async()=>
1{if(s===null)return;const K=++z.current,W=()=>K===z.current,B=U.current!==s;B?T(!0):_(!0);const Q=()=>{if(!s)return Promise.resolve({docs:[]});const F=$t(yt,"users",s,"avatars"),ae=Lt(F,Ut("createdAt","desc"),_t(20));return Mt(ae)},se=()=>s?jt(null,4,P):Promise.resolve({books:[]});try{const[F,ae,Ye,Ge,qe,re,ie,ne,He,Ve,ze]=await Promise.all([y(()=>kt(s,P)),y(Q),y(se),y(()=>Ot(s,3,P)),y(()=>Kt(s,3)),y(()=>Wt(s)),y(()=>vt(s,P)),y(()=>Le(s,P)),y(()=>Ls(s,P)),y(()=>Os(s,P)),y(()=>Tt(s,7))]);if(!W())return;const Y={},A=(N,be,fe,Qe,Je=Xe=>Xe)=>{if(be.ok){fe(Je(be.value));return}Y[N]=!0,B&&fe(Qe)};A("recentBook",F,i,null),F.ok&&F.value&&Ft(F.value),A("characters",ae,b,[],Ht),A("community",Ye,C,[],N=>N?.books||[]),A("recentSchedules",Ge,l,[],N=>N||[]),A("recentBoards",qe,d,[],N=>N||[]),A("progress",He,D,null),A("activity",Ve,u,null),A("emotions",ze,v,null),ie.ok||(Y.books=!0),ne.ok||(Y.schedules=!0),re.ok||(Y.boards=!0),ie.ok&&ne.ok?L(N=>({totalBooks:ie.value,totalSchedules:ne.value,totalBoards:re.ok?re.value:B?null:N?.totalBoards??null})):B&&L(null),ee(Y),U.current=s}finally{W()&&(T(!1),_(!1))}},[s]);h.useEffect(()=>{a||M()},[a,M]);const te=Object.keys(I).some(K=>!Ws.has(K));return{recentBook:r,recentSchedules:n,recentBoards:o,myCharacters:c,communityPicks:m,stats:k,progressData:R,recentActivity:f,emotionStats:j,loadErrors:I,hasCoreError:te,isLoadingData:V,isRefreshing:O,reload:M}}function Gs({isLoadingData:t,myCharacters:a,stats:s,recentSchedules:r,recentBook:i,recentActivity:n,t:l}={}){if(t)return null;const o=qs({myCharacters:a,stats:s,recentSchedules:r});return Vs(o,l)||Js(o.recentSchedules,l)||ea(i,l)||sa(o.stats,l)||ra(n,l)}function qs({myCharacters:t,stats:a,recentSchedules:s}){return{myCharacters:Ce(t),stats:Hs(a),recentSchedules:Ce(s)}}function Ce(t){return Array.isArray(t)?t:[]}function Hs(t){return{totalBooks:q(t?.totalBooks),totalSchedules:q(t?.totalSchedules)}}function q(t){return Number.isFinite(t)?t:0}function Vs({myCharacters:t,stats:a},s){return zs(t,a)?Qs(s):null}function zs(t,{totalBooks:a,totalSchedules:s}){return t.length===0&&a===0&&s===0}function Qs(t){return{icon:ue,tone:"story",label:t("progressAction.nextUp"),title:t("progressAction.createHero"),description:t("progressAction.createHeroDesc"),button:t("progressAction.createHeroButton"),path:"/characters"}}function Js(t,a){const s=t.find(Xs);return s?Zs(s,a):null}function Xs(t){const a=t?.items;return Array.isArray(a)&&a.length>0&&a.every(s=>s&&typeof s=="object")&&a.some(s=>!s.completed)}function Zs(t,a){const{completed:s,total:r}=Me(t);return{icon:J,tone:"schedule",label:a("progressAction.nextUp"),title:a("progressAction.continueSchedule",{title:t.title}),description:a("progressAction.continueScheduleDesc",{completed:s,total:r,count:r}),button:a("progressAction.openSchedule"),path:`/schedules/${t.id}`}}function ea(t,a){return t?ta(t,a):null}function ta(t,a){return{icon:H,tone:"story",label:a("progressAction.nextUp"),title:a("progressAction.continueStory",{title:t.title}),description:a("progressAction.continueStoryDesc"),button:a("progressAction.openStory"),path:`/story/${t.id}/${he(t.title)}`}}function sa({totalBooks:t,totalSchedules:a},s){return t>0&&a===0?aa(s):a>0&&t===0||t===0&&a===0?Ae(s):null}function aa(t){return{icon:J,tone:"schedule",label:t("progressAction.nextUp"),title:t("progressAction.createSchedule"),description:t("progressAction.createScheduleDesc"),button:t("progressAction.createScheduleButton"),path:"/schedules/create"}}function Ae(t){return{icon:H,tone:"story",label:t("progressAction.nextUp"),title:t("progressAction.createStory"),description:t("progressAction.createStoryDesc"),button:t("progressAction.createStoryButton"),path:"/create"}}function ra(t,a){const{totalActivity:s,storiesRead:r,tasksCompleted:i}=ia(t);return s>0?na(r,i,a):oa(a)}function ia(t){const a=t?.summary;return{totalActivity:q(a?.totalActivity),storiesRead:q(a?.storiesRead),tasksCompleted:q(a?.tasksCompleted)}}function na(t,a,s){return{icon:Be,tone:"balanced",label:s("progressAction.keepGoing"),title:s("progressAction.buildOnProgress"),description:s("progressAction.buildOnProgressDesc",{stories:t,tasks:a}),button:s("progressAction.openLibrary"),path:"/library"}}function oa(t){return{icon:Be,tone:"balanced",label:t("progressAction.restartWeek"),title:t("progressAction.smallWin"),description:t("progressAction.smallWinDesc"),button:t("progressAction.openLibrary"),path:"/library"}}const oe={hidden:{opacity:0,y:8},visible:{opacity:1,y:0}},Re={duration:.15,ease:[.2,0,0,1]},la=({isReady:t,shouldShow:a,steps:s})=>!t||!a?null:s.find(r=>!r.completed)?.id||null,da=({isLoadingData:t,stats:a,loadErrors:s,myCharacters:r})=>{const i=!t&&a!==null&&!s.books&&!s.schedules,n=!t&&!s.characters,l=n?r.length:0;return{countsKnown:i,onboardingKnown:i&&n,childCount:l}},Ba=()=>{const{t}=p("dashboard"),{user:a,loading:s}=xe(),r=$e(),i=S(),{isNative:n}=Et(),{recentBook:l,recentSchedules:o,recentBoards:d,myCharacters:c,communityPicks:b,stats:m,progressData:C,recentActivity:k,emotionStats:L,loadErrors:R,hasCoreError:D,isLoadingData:f,isRefreshing:u,reload:j}=Ys(),{countsKnown:v,onboardingKnown:I,childCount:ee}=da({isLoadingData:f,stats:m,loadErrors:R,myCharacters:c}),V=v?m:null,T={hasHero:c.length>0,hasStory:(m?.totalBooks??0)>0,hasSchedule:(m?.totalSchedules??0)>0},O=Ue(T);
1if(s||!a)return e.jsx(Nt,{fullScreen:!1});const _=Gs({isLoadingData:f||D,myCharacters:c,stats:m,recentSchedules:o,recentBook:l,recentActivity:k,t}),U=la({isReady:I,...O}),z=O.steps.find(se=>se.id===U)?.path,M=U==="hero"&&!T.hasStory&&!T.hasSchedule,te=!!_&&_.path!==z,K=v&&m.totalBooks===0&&!M,W=()=>r(`/story/${Ct}`),B=wt(a?.tier),Q=i?{initial:!1}:{initial:"hidden",animate:"visible",variants:oe,transition:Re};return e.jsx(At,{onRefresh:j,className:"min-h-screen",children:e.jsxs("div",{className:"min-h-screen p-4 transition-colors duration-200 sm:p-6 md:p-10 dark:bg-dim-deep",children:[e.jsx(St,{title:t("nav:links.dashboard"),noIndex:!0}),e.jsxs("div",{className:"max-w-6xl mx-auto",children:[e.jsx(Jt,{userName:a.name,isLoadingData:f,stats:V}),!f&&D&&e.jsx(Rt,{compact:!0,title:t("loadError.title"),message:t("loadError.message"),onRetry:j,isRetrying:u,className:"mb-5 sm:mb-6"}),I&&(M?e.jsx(Gt,{onAddChild:()=>r("/characters"),onReadSample:W,onDismiss:O.dismiss}):e.jsx(Yt,{...T})),e.jsxs("div",{className:"grid grid-cols-1 gap-5 sm:gap-6 lg:grid-cols-3 lg:gap-8",children:[e.jsxs("div",{className:"min-w-0 space-y-5 sm:space-y-6 lg:col-span-2 lg:space-y-8",children:[te&&e.jsx(ys,{action:_,onNavigate:r}),e.jsx(es,{onNavigate:r,stats:m,isLoadingData:f}),K&&e.jsx(js,{onOpen:W,motionProps:Q}),e.jsx(as,{characters:c,isLoadingData:f,loadFailed:!!R.characters,onNavigate:r,compact:!!U}),e.jsx(Ss,{book:l,isLoadingData:f,onNavigate:r,motionProps:Q}),e.jsx(gs,{progressData:C,emotionStats:L,recentActivity:k,stats:V,childCount:ee}),e.jsx(ps,{schedules:o,isLoadingData:f,onNavigate:r}),e.jsx(ks,{boards:d,isLoadingData:f,onNavigate:r})]}),e.jsxs(g.div,{className:"min-w-0 space-y-6 self-start",initial:i?!1:"hidden",animate:i?void 0:"visible",transition:Re,variants:i?void 0:oe,children:[e.jsx(Ps,{user:a,isNative:n,showPlansAction:!B}),e.jsx(As,{books:b,isLoadingData:f,onNavigate:r}),B&&e.jsx(Rs,{onNavigate:r,variants:i?void 0:oe})]})]})]})]})})};export{Ba 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.