PageSourceSearch

https://socialnarratives.ai/assets/Library-DHnE0DR-.js

js socialnarratives.ai collected 2026-10-05 15:08:25 UTC 47,368 bytes, 1 lines download raw bytes

1import{j as e,ap as Jt,a0 as Xt,m as q,P as vt,Y as es,an as ts,aq as ss,B as me,i as rs,z as k,u as as,c as is,ar as os}from"./ui-vendor-XNsX7NFl.js";import{u as Ge,a as l}from"./i18n-BCZ_8xSB.js";import{B as Y,u as ls,J as wt,a2 as ce,a3 as ct,a4 as ut,a5 as ns,Q as mt,a6 as ft,V as ds,S as cs,a7 as Ie,a8 as us,t as G,_ as kt,a9 as ms,aa as fs,ab as gs,ac as hs,ad as xs,ae as bs,af as ps,ag as ys,ah as vs,ai as ws}from"./index-Dg7geK91.js";import{P as ks}from"./PullToRefresh-CBBurnpR.js";import{w as Ye}from"./offlineStoryService-D7MOJvdI.js";import{q as gt,f as ht,j as js,l as Ns,h as xt,w as Cs}from"./firebase-db-Csu2kn54.js";import{A as Ss}from"./AsyncErrorState-hWN8PH73.js";import{E as re}from"./EmptyState-DiCukgUt.js";import{S as jt,a as ye,g as Nt}from"./storyUtils-BbI5tRcI.js";import{C as Bs}from"./ChildPickerList-C5d6pwaO.js";import{u as As}from"./useStickyActionBar-BD2H8ZW2.js";import{b as Ds,g as Es,L as Ts}from"./react-router-oAHNt2ka.js";import"./firebase-auth-BWbhO1CC.js";import"./capacitor-DQeCf45c.js";import"./StateAction-LWPd75gj.js";import"./StateHeading-D9MlYpnP.js";const Is=({t:r,searchQuery:a,onSearchChange:j,isFiltersOpen:u,onToggleFilters:y,activeFilterCount:C,canUseSelection:h,hasDisplayedBooks:p,isSelectionMode:m,onToggleSelectionMode:E,sortBy:D,onSortChange:v,heroes:N,showHeroFilters:x,heroFilter:w,onHeroChange:z,selectedCategory:V,onCategoryChange:U,onClearAllFilters:T})=>e.jsxs("section",{className:"mb-5 sm:mb-6","aria-label":r("filters.panel",{defaultValue:"Story filters"}),children:[e.jsxs("div",{className:"flex items-stretch gap-2",children:[e.jsxs("div",{className:"relative min-w-0 flex-1",children:[e.jsx("input",{type:"search",placeholder:r("search.placeholder"),"aria-label":r("search.placeholder"),value:a,onChange:b=>j(b.target.value),className:"min-h-[48px] w-full rounded-full border border-gray-300 bg-white py-2 pl-10 pr-12 text-ink outline-none transition-colors placeholder:text-slate-500 focus:border-sage-500 focus:ring-2 focus:ring-sage-200 dark:border-dim-border dark:bg-dim-surface dark:text-dim-text dark:placeholder:text-dim-text-muted"}),e.jsx(Jt,{"aria-hidden":"true",className:"pointer-events-none absolute left-3 top-1/2 h-5 w-5 -translate-y-1/2 text-slate-500 dark:text-dim-text-muted"}),a&&e.jsx("button",{type:"button",onClick:()=>j(""),"aria-label":r("search.clear",{defaultValue:"Clear search"}),className:"absolute right-1 top-1/2 flex min-h-[44px] min-w-[44px] -translate-y-1/2 items-center justify-center rounded-full text-xl leading-none text-slate-500 transition-colors hover:bg-slate-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 dark:text-dim-text-secondary dark:hover:bg-dim-elevated",children:e.jsx("span",{"aria-hidden":"true",children:"×"})})]}),e.jsxs("button",{type:"button","aria-expanded":u,"aria-controls":"library-filter-panel",onClick:y,className:"flex min-h-[48px] shrink-0 items-center justify-center gap-2 rounded-full border border-sage-200 bg-white px-3 text-sm font-bold text-sage-700 transition-colors hover:bg-sage-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 dark:border-sage-700 dark:bg-dim-surface dark:text-sage-300 md:hidden",children:[r("filters.button",{defaultValue:"Filters"}),e.jsx("span",{"aria-hidden":"true",className:"flex min-h-5 min-w-5 items-center justify-center rounded-full bg-sage-100 px-1 text-xs font-black text-sage-800 dark:bg-sage-900 dark:text-sage-200",children:C})]})]}),h&&p&&e.jsx(Y,{size:"sm",variant:m?"secondary":"outline","aria-pressed":m,onClick:E,leftIcon:e.jsx(Xt,{className:"h-4 w-4","aria-hidden":"true"}),className:"mt-2 min-h-[48px] whitespace-nowrap",children:m?r("select.exit","Done"):r("select.enter","Select")}),e.jsxs("div",{id:"library-filter-panel",className:`${u?"block":"hidden"} mt-3 space-y-3 rounded-xl border border-gray-200 bg-white p-3 dark:border-dim-border dark:bg-dim-surface md:block`,children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3",children:[e.jsx("label",{className:"text-sm font-bold text-slate-700 dark:text-dim-text",htmlFor:"library-sort",children:r("sort.label","Sort by")}),e.jsxs("select",{id:"library-sort",value:D,onChange:b=>v(b.target.value),className:"min-h-[48px] w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-ink outline-none focus:border-sage-500 focus:ring-2 focus:ring-sage-200 dark:border-dim-border dark:bg-dim-elevated dark:text-dim-text sm:w-56",children:[e.jsx("option",{value:"newest",children:r("sort.newest","Newest first")}
1),e.jsx("option",{value:"oldest",children:r("sort.oldest","Oldest first")}),e.jsx("option",{value:"recentlyRead",children:r("sort.recentlyRead","Recently read")}),e.jsx("option",{value:"titleAsc",children:r("sort.titleAsc","Title (A→Z)")}),e.jsx("option",{value:"titleDesc",children:r("sort.titleDesc","Title (Z→A)")})]})]}),x&&N.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{className:"block text-sm font-bold text-slate-700 dark:text-dim-text",children:r("filters.heroLabel","For:")}),e.jsxs("div",{className:"flex flex-nowrap gap-2 overflow-x-auto pb-1 no-scrollbar md:flex-wrap md:overflow-visible",children:[e.jsx("button",{type:"button",onClick:()=>z("all"),className:`min-h-[44px] shrink-0 rounded-full px-3 text-sm font-bold transition-all focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 ${w==="all"?"bg-sage-600 text-white shadow-sm":"border border-gray-200 bg-white text-gray-600 hover:bg-gray-50 dark:border-dim-border dark:bg-dim-surface dark:text-dim-text-secondary dark:hover:bg-dim-elevated"}`,"aria-pressed":w==="all",children:r("filters.allHeroes","Everyone")}),N.map(b=>{const B=w===b.id;return e.jsxs("button",{type:"button",onClick:()=>z(b.id),"aria-pressed":B,className:`flex min-h-[44px] shrink-0 items-center gap-2 rounded-full pl-1 pr-3 text-sm font-bold transition-all focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 ${B?"bg-sage-600 text-white shadow-sm":"border border-gray-200 bg-white text-gray-600 hover:bg-gray-50 dark:border-dim-border dark:bg-dim-surface dark:text-dim-text-secondary dark:hover:bg-dim-elevated"}`,children:[b.imageUrl?e.jsx("img",{src:b.imageUrl,alt:"","aria-hidden":"true",className:"h-8 w-8 rounded-full object-cover"}):e.jsx("span",{className:"flex h-8 w-8 items-center justify-center rounded-full bg-sage-200 text-xs text-sage-900 dark:bg-sage-800 dark:text-sage-100","aria-hidden":"true",children:b.name?.[0]||"?"}),e.jsx("span",{className:"max-w-[8rem] truncate",children:b.name})]},b.id)})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{className:"block text-sm font-bold text-slate-700 dark:text-dim-text",children:r("filters.categoryLabel",{defaultValue:"Category"})}),e.jsx("div",{className:"flex flex-nowrap gap-2 overflow-x-auto pb-1 no-scrollbar md:flex-wrap md:overflow-visible",children:jt.map(b=>e.jsx("button",{type:"button",onClick:()=>U(b.id),"aria-pressed":V===b.id,className:`min-h-[44px] shrink-0 rounded-full px-3 text-sm font-bold transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 ${V===b.id?"bg-sage-600 text-white shadow-sm":"border border-gray-200 bg-white text-gray-600 hover:bg-gray-50 dark:border-dim-border dark:bg-dim-surface dark:text-dim-text-secondary dark:hover:bg-dim-elevated"}`,children:r(b.labelKey)},b.id))})]})]}),C>0&&e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-2 rounded-lg bg-sage-50 px-3 py-2 text-sm text-sage-800 dark:bg-sage-900/30 dark:text-sage-200",role:"status",children:[e.jsx("span",{className:"font-bold",children:r("filters.activeCount",{count:C,defaultValue:"{{count}} active filters"})}),e.jsx("button",{type:"button",onClick:T,className:"min-h-[44px] rounded-full px-3 font-bold text-sage-700 underline decoration-sage-300 underline-offset-2 transition-colors hover:text-sage-900 focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 dark:text-sage-300 dark:hover:text-sage-100",children:r("filters.clearAll",{defaultValue:"Clear all"})})]})]}),Ls={hidden:{opacity:0,y:20},visible:{opacity:1,y:0}},bt={hidden:{opacity:0},visible:{opacity:1,transition:{staggerChildren:.05}}},Ct={hidden:{opacity:0,y:20,scale:.95},visible:{opacity:1,y:0,scale:1}},Fe=r=>r?typeof r=="string"?new Date(r).getTime()||null:typeof r=="number"?r:typeof r.toMillis=="function"?r.toMillis():typeof r.seconds=="number"?r.seconds*1e3:null:null,St=(r,a)=>{const j=Fe(r);if(!j)return null;try{return new Intl.DateTimeFormat(a||void 0,{dateStyle:"medium"}).format(new Date(j))}catch{return new Date(j).toLocaleDateString(a||void 0,{month:"short",day:"numeric",year:"numeric"})}},Fs=({child:r,t:a})=>e.jsxs("span",{"data-testid":"library-card-child",className:"inline-flex max-w-full items-center gap-1.5 rounded-full border border-slate-200 bg-white py-0.5 pl-0.5 pr-2.5 text-xs font-bold text-slate-700 dark:border-dim-border dark:bg-dim-surface dark:text-dim-text-secondary",children:[r.imageUrl?e.jsx("img",{src:r.imageUrl,alt:"",className:"h-5 w-5 shrink-0 rounded-full object-cover"}):e.jsx("span",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-slate-200 text-xs dar
1k:bg-dim-elevated","aria-hidden":"true",children:r.name[0]}),e.jsx("span",{className:"truncate",children:a("card.forChild",{name:r.name})})]}),Rs={secondary:"bg-slate-100 text-slate-700 hover:bg-slate-200 dark:bg-dim-elevated dark:text-dim-text dark:hover:bg-dim-border",ghost:"text-gray-600 hover:bg-gray-100 dark:text-dim-text-secondary dark:hover:bg-dim-elevated",outline:"border-2 border-sage-200 bg-white text-sage-700 hover:bg-sage-50 dark:border-sage-700 dark:bg-dim-surface dark:text-sage-300 dark:hover:bg-dim-elevated",destructive:"bg-red-700 text-white shadow-sm hover:bg-red-800"},ue=({variant:r,className:a="",children:j,...u})=>e.jsx("button",{type:"button",className:`inline-flex min-h-[44px] min-w-0 items-center justify-center whitespace-normal rounded-full px-2 text-center text-[13px] font-bold leading-tight transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 sm:px-3 sm:text-sm lg:px-4 dark:focus-visible:ring-offset-dim-surface ${Rs[r]||""} ${a}`.trim(),...u,children:j}),pt=({message:r,undoLabel:a,onUndo:j})=>e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx("span",{children:r}),e.jsx("button",{type:"button",onClick:j,className:"min-h-[44px] shrink-0 rounded-lg px-3 font-bold underline underline-offset-2 whitespace-nowrap text-sage-700 focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 dark:text-sage-300",children:a})]}),Os=({book:r,isLast:a,enableAnimation:j=!0,onToggleFavorite:u,onDuplicate:y,isFavoritePending:C=!1,index:h=0,isSelectionMode:p=!1,isSelected:m=!1,onToggleSelect:E,child:D=null})=>{const{t:v,i18n:N}=Ge("library"),x=wt(),[w,z]=l.useState(!1),[V,U]=l.useState(!1),b=(Array.isArray(r.pages)?r.pages:[])[0]||{},B=ye(r.title)||v("untitledStory","Untitled Story"),Re=()=>{E?.(r)},Oe=S=>{p&&(S.key==="Enter"||S.key===" ")&&(S.preventDefault(),E?.(r))},W=S=>{S.stopPropagation(),z(!0),setTimeout(()=>z(!1),300),u(S,r)},ae=async S=>{if(S.stopPropagation(),!(V||!y)){U(!0);try{await y(r)}finally{U(!1)}}},K=r.generationParams?.category||"",ve=Nt(K),I=jt.find(S=>S.id===ve),f=I?I.labelKey:"tabs.books",Z=St(r.createdAt,N?.resolvedLanguage||N?.language);return e.jsxs(q.div,{ref:a?S=>a(S):null,onClick:p?Re:void 0,variants:j&&!x?Ct:void 0,initial:j&&!x?"hidden":!1,animate:j&&!x?"visible":void 0,transition:j&&!x?{duration:.3,delay:h*.05,ease:"easeOut"}:{duration:0},whileHover:x?void 0:{y:-4,boxShadow:"0 12px 40px rgba(0,0,0,0.1)"},whileTap:x?void 0:{scale:.98},role:p?"button":void 0,tabIndex:p?0:void 0,"aria-pressed":p?m:void 0,"aria-label":p?v("select.cardLabel","Select {{title}}",{title:G(B)}):void 0,onKeyDown:p?Oe:void 0,className:`p-4 md:p-4 pb-2 md:pb-3 rounded-2xl shadow-sm cursor-pointer border group relative overflow-visible bg-white dark:bg-dim-surface ${p?"focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500":""} ${m?"border-sage-500 ring-2 ring-sage-500":"border-gray-100 dark:border-dim-border hover:border-sage-200 dark:hover:border-sage-700"}`,children:[!p&&e.jsx(Ts,{to:`/story/${r.id}/${kt(B)}`,state:{returnPath:"/library"},"aria-label":G(B),className:"absolute inset-0 z-[1] rounded-2xl focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 focus-visible:ring-offset-2 dark:focus-visible:ring-offset-dim-surface"}),e.jsxs("div",{className:`aspect-[4/3] rounded-xl mb-3 ${b.color||"bg-slate-100"} flex items-center justify-center text-4xl overflow-hidden relative group-hover:shadow-sm transition-all`,children:[r.coverImageUrl||b.imageUrl?e.jsx("img",{src:r.coverImageUrl||b.imageUrl,alt:G(B),loading:"lazy",className:"w-full h-full object-cover object-top transition-transform duration-500 group-hover:scale-105"}):e.jsx("span",{className:"text-gray-300",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1,stroke:"currentColor",className:"w-12 h-12",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 6.042A8.967 8.967 0 006 3.75c-1.052 0-2.062.18-3 .512v14.25A8.987 8.987 0 016 18c2.305 0 4.408.867 6 2.292m0-14.25a8.966 8.966 0 016-2.292c1.052 0 2.062.18 3 .512v14.25A8.987 8.987 0 0018 18a8.967 8.967 0 00-6 2.292m0-14.25v14.25"})})}),p&&e.jsx("span",{"aria-hidden":"true",className:`absolute top-2 right-2 z-10 flex h-8 w-8 items-center justify-center rounded-full border-2 shadow-sm ${m?"border-sage-600 bg-sage-600 text-white":"border-gray-300 bg-white/90 text-transparent"}`,children:e.jsx(is,{className:"h-5 w-5"})}),!p&&e.jsx(q.button,{onClick:W,"aria-label":r.favorite?v("actions.unfavorite","Remove from favorites"):v("actions.favorite","Add to favorites"),disabled:C,className:"absolute top-2 right-2 z-10 flex h-12 w-12 items-center justify-center rounded-full bg-white/90 shadow-sm backdrop-blur-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 disabled:opacity-60 disabled:cursor-wait",whileTap:x?void 0:{scale:.95},animate:!x&&w?{scale:[1,1.15,1]}:{},transition:x?{duration:0}:{duration:.3},children:e.jsx(q.svg,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:r.favorite?"currentColor":"none",stroke:"currentColor",strokeWidth:2,className:`w-5 h-5 ${r.favorite?"text-red-600":"text-slate-500"}`,animate:!x&&w&&r.favorite?{scale:[1,1.2,1]}:{},children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21 8.25c0-2.485-2.099-4.5-4.688-4.5-1.935 0-3.597 1.126-4.312 2.733-.715-1.607-2.377-2.733-4.313-2.733C5.1 3.75 3 5.765 3 8.25c0 7.22 9 12 9 12s9-4.78 9-12z"})})}),!p&&y&&e.jsx(q.button,{onClick:ae,"aria-label":v("actions.duplicate","Duplicate story"),title:v("actions.duplicate","Duplicate story"),disabled:V,className:"absolute top-2 left-2 z-10 flex h-11 w-11 items-center justify-center rounded-full bg-white/90 shadow-sm backdrop-blur-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 disabled:opacity-60 disabled:cursor-wait",whileTap:x?void 0:{scale:.95},children:e.jsx(os,{className:"w-5 h-5 text-slate-700","aria-hidden":"true"})})]}),e.jsx("div",{className:"flex justify-between items-start gap-2 mb-1",children:e.jsx("h3",{className:"text-lg font-['Quicksand'] font-bold truncate text-gray-800 dark:text-dim-text flex-1",children:G(B)})}),e.jsxs("div",{className:"flex flex-wrap justify-between items-center gap-2 mt-1",children:[D?.name&&e.jsx(Fs,{child:D,t:v}),Z&&e.jsx("p",{className:"text-xs font-medium text-gray-600 dark:text-dim-text-secondary",children:v("card.made",{date:Z})}),f&&f!=="tabs.books"&&e.jsx("span",{className:"ml-auto text-xs font-bold px-2 py-0.5 bg-slate-100 dar
1k:bg-dim-elevated text-slate-600 dark:text-dim-text-secondary rounded-md border border-slate-200 dark:border-dim-border",children:v(f)})]}),r.ratings&&Object.values(r.ratings).some(S=>S?.sentiment==="helped")&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[e.jsx("span",{"aria-hidden":"true",className:"inline-flex rounded-full bg-white p-0.5 ring-1 ring-black/5",children:e.jsx("img",{src:"/assets/feedback/helped.png",alt:"",className:"block w-4 h-4 rounded-full"})}),e.jsx("span",{className:"text-xs font-bold uppercase tracking-wider text-sage-700 dark:text-sage-300",children:v("actions.helped",{ns:"common",defaultValue:"Helped"})})]})]})},Us=({book:r,onRestore:a,onDeleteForever:j})=>{const{t:u}=Ge("library"),[y,C]=l.useState(!1),[h,p]=l.useState(!1),E=(Array.isArray(r.pages)?r.pages:[])[0]||{},D=ye(r.title)||u("untitledStory","Untitled Story"),v=Fe(r.deletedAt);let N=u("trash.deletedUnknown","Deleted");if(v){const w=Math.floor((Date.now()-v)/864e5);N=w<=0?u("trash.deletedToday","Deleted today"):u("trash.deletedDaysAgo","Deleted {{count}} days ago",{count:w})}const x=async w=>{p(!0);try{await w(r)}finally{p(!1),C(!1)}};return e.jsxs("div",{className:"p-4 pb-3 rounded-2xl shadow-sm border bg-white dark:bg-dim-surface border-gray-100 dark:border-dim-border",children:[e.jsx("div",{className:`aspect-[4/3] rounded-xl mb-3 ${E.color||"bg-slate-100"} flex items-center justify-center overflow-hidden opacity-60`,children:r.coverImageUrl||E.imageUrl?e.jsx("img",{src:r.coverImageUrl||E.imageUrl,alt:G(D),loading:"lazy",className:"w-full h-full object-cover object-top"}):e.jsx(me,{className:"w-12 h-12 text-gray-300","aria-hidden":"true"})}),e.jsx("h3",{className:"text-lg font-['Quicksand'] font-bold truncate text-gray-800 dark:text-dim-text",children:G(D)}),e.jsx("p",{className:"text-xs font-medium text-slate-600 dark:text-dim-text-secondary mb-3",children:N}),y?e.jsxs("div",{className:"rounded-lg bg-red-50 dark:bg-red-900/20 p-2",children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-wider text-red-700 dark:text-red-300 mb-1",children:u("trash.confirmDelete","Delete forever?")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Y,{size:"sm",variant:"destructive",disabled:h,onClick:()=>x(j),className:"flex-1",children:u("trash.confirmYes","Yes, delete")}),e.jsx(Y,{size:"sm",variant:"secondary",disabled:h,onClick:()=>C(!1),className:"flex-1",children:u("trash.cancel","Cancel")})]})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Y,{size:"sm",variant:"secondary",disabled:h,onClick:()=>x(a),className:"flex-1",children:u("trash.restore","Restore")}),e.jsx(Y,{size:"sm",variant:"destructive",disabled:h,onClick:()=>C(!0),className:"flex-1",children:u("trash.deleteForever","Delete forever")})]})]})},Ms=({t:r,isSignedIn:a,activeTab:j,heroFilter:u,heroes:y,hasSearchOrCategory:C,onCreate:h,onOpenSample:p,onShowAllStories:m,onShowStoriesTab:E,onClearFilters:D})=>{const v=e.jsx(vt,{className:"h-5 w-5","aria-hidden":"true"}),N={label:r("empty.trySample","Try a sample story"),onClick:p,icon:e.jsx(me,{className:"h-5 w-5","aria-hidden":"true"})};if(C)return e.jsx(re,{variant:"no-results",title:r("empty.noSearchResults"),message:r("empty.noSearchResultsDesc","Try a shorter search or clear the filters to see more stories."),onClear:D});if(!a)return e.jsx(re,{title:r("empty.title"),message:r("empty.guestMessage"),icon:me,action:{label:r("empty.startCreating"),to:"/create",icon:v},secondaryAction:N});if(u!=="all"){const x=y.find(w=>w.id===u)?.name||r("filters.thisHero","this child");return e.jsx(re,{title:r("empty.noStoriesForHero","No stories for {{name}} yet",{name:x}),message:r("empty.noStoriesForHeroDesc","Start a story tailored to {{name}} or browse everything in your library.",{name:x}),icon:me,action:{label:r("empty.createForHero","Create story for {{name}}",{name:x}),onClick:()=>h({heroId:u}),icon:v},secondaryAction:{label:r("empty.showAllStories","Show all stories"),onClick:m}})}return j==="favorites"?e.jsx(re,{title:r("empty.noFavorites"),message:r("empty.noFavoritesDesc","Tap the heart on a story to keep it here for quick access."),icon:as,secondaryAction:{label:r("videos.browseStories","Browse your stories"),onClick:E}}):e.jsx(re,{title:r("empty.noBooks"),message:r("empty.noBooksDesc","Start with a familiar routine or upcoming event. Your first story can be simple."),icon:me,action:{label:r("empty.createFirst"),onClick:()=>h(),icon:v},secondaryAction:N})},yt={creations:null,favorites:null,videos:null},Le={throwOnError:!0},se=(r,a)=>Number.isFinite(r)?Math.max(0,r+a):r,Ps=r=>({userId:r?.id??null,isSignedIn:!!r}),zs=({hasLoaded:r,storyCount:a,creationsCount:j,activeFilterCount:u,loadError:y})=>r&&a===0&&!(j>0)&&u===0&&!y;function rr({showFavoritesOnly:r=!1}){const{t:a,i18n:j}=Ge("library"),{user:u}=ls(),{userId:y,isSignedIn:C}=Ps(u),h=wt(),[p,m]=l.useState([]),[E,D]=l.useState([]),[v,N]=l.useState(!0),[x,w]=l.useState(!1),[z,V]=l.useState(!1),[U,T]=l.useState(null),[b,B]=l.useState(null),[Re,Oe]=l.useState(0),W=Ds(),ae=l.useRef(),K=12,[ve,I]=l.useState(null),[f,Z]=l.useState("creations"),[S,Ue]=l.useState(""),[J,Me]=l.useState("all"),[ie,We]=l.useState("newest"),[Bt,At]=l.useState(!1),[oe,R]=l.useState(yt),[Ze,fe]=l.useState(!1),we=l.useRef(!1),[Je,Xe]=l.useState(()=>new Set),[_,ke]=l.useState(!1),[ge,he]=l.useState(()=>new Set),[M,le]=l.useState(!1),[je,Ne]=l.useState(!1),et=l.useRef(null);As(et,_);const[tt,Pe]=l.useState([]),[ze,st]=l.useState(!1),[$e,Dt]=Es(),L=$e.get("userId"),P=$e.get("hero")||"all",$=!!(L&&u?.isAdmin),Ce=$?L:u?.id||null,O=Ce?`user:${Ce}`:"guest",Q=l.useRef(O),He=l.useRef(0),[Se,rt]=l.useState([]),at=l.useRef(null),Ve=l.useRef({}),[it,Et]=l.useState({left:!1,right:!1}),X=l.useCallback(()=>{const t=at.current;if(!t)return;const s=t.scrollWidth-t.clientWidth,i={left:s>1&&t.scrollLeft>1,right:s>1&&t.scrollLeft<s-1};Et(o=>o.left===i.left&&o.right===i.right?o:i)},[]);l.useLayoutEffect(()=>{Q.current!==O&&(Q.current=O,He.current+=1,m([]),D([]),I(null),N(!0),fe(!1),T(null),B(null),R(yt),rt([]),he(new Set),ke(!1),V(!1),w(!0))},[O]);const Be=l.useCallback(async(t=!1)=>
1{if(x||!v&&!t)return;const s=O;w(!0);try{if(f==="favorites"||f==="trash"){w(!1);return}const i=Ce;if(!i){w(!1);return}if(f==="videos"){w(!1);return}const o=await ce(i,ve,K,{throwOnError:!0});if(Q.current!==O)return;const n=o.books||[],d=o.lastDoc;n.length<K&&N(!1),m(c=>[...c,...n]),I(d),T(null),B(null)}catch(i){if(Q.current!==s)return;console.error("Error loading more books:",i),T(i),B("pagination"),N(!1)}finally{Q.current===s&&w(!1)}},[ve,x,v,f,Ce,O]),ne=l.useCallback(async()=>{const t=++He.current,s=()=>t===He.current&&Q.current===O;try{if($){w(!0),m([]),I(null),N(!0);const i=await ce(L,null,K,{throwOnError:!0});if(!s())return;const o=i.books||[];m(o),I(i.lastDoc),N(o.length===K);const n=await ct(L,{throwOnError:!0}).catch(()=>null);if(!s())return;R(d=>({...d,creations:n})),T(null),B(null),D([])}else if(C){w(!0);const[i,o,n]=await Promise.all([ct(y,Le),ut(y,Le),ns(y,Le)].map(c=>c.catch(()=>null)));if(!s())return;if(R({creations:i,favorites:o,videos:n}),f==="favorites"||f==="trash"||ie!=="newest"||P!=="all"){const c=await ce(y,null,null,{throwOnError:!0});if(!s())return;m(c),I(null),N(!1),fe(!0),Ye(c)}else{I(null),N(!0),fe(!1);const c=await ce(y,null,K,{throwOnError:!0});if(!s())return;const g=c.books||[];m(g),I(c.lastDoc),N(g.length===K),Ye(g)}T(null),B(null);try{const c=gt(ht(mt,"users",y,"videos"),js("createdAt","desc"),Ns(100)),g=await xt(c);if(!s())return;const A=g.docs.map(H=>({id:H.id,...H.data()}));D(A)}catch(c){console.error("Error fetching videos:",c)}}else{const i=await ce(null);if(!s())return;m(i),I(null),N(!1),fe(!0),D([]),R({creations:i.filter(o=>!o.deleted).length,favorites:i.filter(o=>!o.deleted&&o.favorite).length,videos:0}),T(null),B(null)}}catch(i){if(!s())return;console.error("Error fetching books:",i),T(i),B("collection")}finally{s()&&(w(!1),V(!0))}},[C,y,L,f,ie,P,$,O]);l.useEffect(()=>{ne()},[ne]);const Ae=S.trim()!==""||J!=="all";l.useEffect(()=>{!Ae&&b==="filter"&&(T(null),B(null))},[Ae,b]),l.useEffect(()=>{if(!Ae||Ze||we.current||!C||$)return;let t=!1;const s=O;return we.current=!0,w(!0),(async()=>{try{const i=await ce(y,null,null,{throwOnError:!0});if(t||Q.current!==s)return;const o=Array.isArray(i)?i:i?.books||[];m(o),I(null),N(!1),fe(!0),T(null),B(null),Ye(o)}catch(i){if(t||Q.current!==s)return;console.error("Error fetching books:",i),T(i),B("filter")}finally{we.current=!1,t||w(!1)}})(),()=>{t=!0,we.current=!1}},[Ae,Ze,C,y,L,Re,$,O]);const Tt=l.useCallback(()=>{if(b==="pagination"){N(!0),Be(!0);return}if(b==="filter"){Oe(t=>t+1);return}ne()},[ne,b,Be]);l.useEffect(()=>{let t=!1;return(async()=>{if(!(!C||$))try{const i=ht(mt,"users",y,"avatars"),o=gt(i,Cs("type","==","child")),n=await xt(o);if(t)return;rt(n.docs.map(d=>({id:d.id,...d.data()})))}catch(i){console.error("Library: failed to load heroes",i)}})(),()=>{t=!0}},[C,y,$]),l.useEffect(()=>{if(!C||$){Pe([]);return}Pe(ft()||[])},[C,$]);const It=async()=>{if(!(!u||ze)){st(!0);try{const t=await ms(u.id)||{migrated:0,failed:0};Pe(ft()||[]),t.migrated===0?k.error(a("guestMigration.failed","Could not add your stories. They're still saved on this device.")):t.failed>0?k(a("guestMigration.partial","Added {{migrated}} stories. {{failed}} are still saved on this device.",{migrated:t.migrated,failed:t.failed})):k.success(a("guestMigration.allDone","Added {{count}} stories to your library",{count:t.migrated})),await ne()}catch(t){console.error("Error migrating guest books:",t),k.error(a("guestMigration.failed","Could not add your stories. They're still saved on this device."))}finally{st(!1)}}},Lt=async t=>{try{await fs(t.id),m(s=>s.map(i=>i.id===t.id?{...i,deleted:!1,deletedAt:null}:i)),R(s=>({...s,creations:se(s.creations,1),favorites:t.favorite?se(s.favorites,1):s.favorites})),k.success(a("trash.restored","Story restored"))}catch(s){console.error("Error restoring book:",s),k.error(a("trash.restoreFailed","Could not restore story"))}},Ft=async t=>{try{await gs(t.id),m(s=>s.filter(i=>i.id!==t.id)),k.success(a("trash.deletedForever","Story deleted forever"))}catch(s){console.error("Error deleting book:",s),k.error(a("trash.deleteFailed","Could not delete story"))}},De=t=>{const s=new URLSearchParams($e);t==="all"?s.delete("hero"):s.set("hero",t),Dt(s,{replace:!0})},Rt=()=>{Ue(""),We("newest"),Me("all"),De("all")},Ot=async(t,s)=>{if(t.stopPropagation(),Je.has(s.id))return;const i=!s.favorite;Xe(o=>new Set(o).add(s.id)),m(o=>o.map(n=>n.id===s.id?{...n,favorite:i}:n));try{await hs(s.id,{favorite:i}),R(o=>({...o,favorites:se(o.favorites,i?1:-1)}))}catch(o){console.error("Error updating book:",o),m(n=>n.map(d=>d.id===s.id?{...d,favorite:!i}:d)),k.error(a("actions.favoriteFailed","Could not update favorite"))}finally{Xe(o=>{const n=new Set(o);return n.delete(s.id),n})}},Ut=async t=>{if(!u)return;let s;try{s=await xs(t.id,u.id,u.name||null)}catch(o){console.error("Error duplicating book:",o),k.error(a("actions.duplicateFailed","Could not duplicate story"));return}m(o=>[s,...o]),R(o=>({...o,creations:se(o.creations,1)}
1));const i=async o=>{k.dismiss(o);try{await ws(s.id,t.id),m(n=>n.filter(d=>d.id!==s.id)),R(n=>({...n,creations:se(n.creations,-1)}))}catch(n){console.error("Error undoing duplicate:",n),k.error(a("actions.undoDuplicateFailed","Could not remove the copy"))}};k(o=>e.jsx(pt,{message:a("actions.duplicated","Story duplicated"),undoLabel:a("select.undo","Undo"),onUndo:()=>i(o.id)}),{duration:8e3})},Ke=p.filter(t=>!t.deleted),xe=p.filter(t=>t.deleted).sort((t,s)=>(Fe(s.deletedAt)||0)-(Fe(t.deletedAt)||0)),Mt=xe.length>0||f==="trash",ee=[{id:"creations",label:a("tabs.books"),count:oe.creations},{id:"favorites",label:a("tabs.favorites"),count:oe.favorites},{id:"videos",label:a("tabs.videos"),count:oe.videos},...Mt?[{id:"trash",label:a("trash.tab","Trash"),count:xe.length}]:[]],Pt=ee.map(t=>`${t.id}:${t.label}`).join("|");l.useEffect(()=>{if(X(),!(typeof window>"u"))return window.addEventListener("resize",X),()=>window.removeEventListener("resize",X)},[Pt,X]);const ot=l.useRef(!1);l.useEffect(()=>{if(!ot.current){ot.current=!0;return}Ve.current[f]?.scrollIntoView?.({block:"nearest",inline:"nearest",behavior:h?"auto":"smooth"}),X()},[f,h,X]);const zt=f==="creations"||f==="favorites",lt=[S.trim()!=="",ie!=="newest",J!=="all",P!=="all"].filter(Boolean).length,$t=zs({hasLoaded:z,storyCount:Ke.length,creationsCount:oe.creations,activeFilterCount:lt,loadError:U}),Ee=Ke.filter(t=>{const s=ds(S).toLowerCase(),i=ye(t.title).toLowerCase().includes(s),n=(Array.isArray(t.pages)?t.pages:[]).some(A=>ye(A.text).toLowerCase().includes(s)),d=!S||i||n;let c=!0;if(J!=="all"){const A=t.generationParams?.category||"";c=Nt(A)===J}let g=!0;return P!=="all"&&(g=t.heroId===P||t.childId===P),d&&c&&g});let F=Ee;r?F=Ee.filter(t=>t.favorite):f==="favorites"?F=Ee.filter(t=>t.favorite):F=Ee;const de=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,Te=t=>(ye(t.title)||"").toLowerCase();F=[...F].sort((t,s)=>{switch(ie){case"oldest":return de(t.createdAt)-de(s.createdAt);case"recentlyRead":return de(s.lastRead)-de(t.lastRead);case"titleAsc":return Te(t).localeCompare(Te(s));case"titleDesc":return Te(s).localeCompare(Te(t));default:return de(s.createdAt)-de(t.createdAt)}});const Ht=!!u&&!L&&(f==="creations"||f==="favorites"),be=ge.size,te=l.useCallback(()=>{ke(!1),he(new Set),Ne(!1)},[]);l.useEffect(()=>{he(t=>t.size===0?t:new Set)},[f,ie,P,S,J]),l.useEffect(()=>{(f==="videos"||f==="trash")&&ke(!1)},[f]),l.useEffect(()=>{if(!_)return;const t=s=>{s.key==="Escape"&&(je?Ne(!1):te())};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[_,je,te]);const Vt=l.useCallback(t=>{he(s=>{const i=new Set(s);return i.has(t.id)?i.delete(t.id):i.add(t.id),i})},[]),Kt=()=>{he(new Set(F.map(t=>t.id)))},_e=l.useCallback(async()=>{if(C)try{const t=await ut(y,Le);R(s=>({...s,favorites:t}))}catch(t){console.error("Error refreshing favorite count:",t)}},[C,y]),nt=async t=>{const s=Array.from(ge);if(s.length===0||M)return;const i=new Set(s),o=new Map(p.map(n=>[n.id,!!n.favorite]));le(!0),m(n=>n.map(d=>i.has(d.id)?{...d,favorite:t}:d));try{const{failed:n}=await bs(s,t);if(n.length>0){const d=new Set(n);m(c=>c.map(g=>d.has(g.id)?{...g,favorite:o.get(g.id)??g.favorite}:g)),k.error(a("select.bulkPartialFailure","Could not update {{count}} stories",{count:n.length}))}else k.success(t?a("select.bulkFavorited","Added {{count}} stories to favorites",{count:s.length}):a("select.bulkUnfavorited","Removed {{count}} stories from favorites",{count:s.length}));await _e()}catch(n){console.error("Error bulk updating favorites:",n),m(d=>d.map(c=>i.has(c.id)?{...c,favorite:o.get(c.id)??c.favorite}:c)),k.error(a("select.bulkPartialFailure","Could not update {{count}} stories",{count:s.length}))}finally{le(!1),te()}},pe=l.useMemo(()=>Se.filter(t=>t?.name),[Se]),_t=l.useMemo(()=>new Map(pe.map(t=>[t.id,t])),[pe]),Qt=pe.length>=2&&P==="all",Qe=pe.length>0,qt=async t=>{const s=Array.from(ge);if(!(s.length===0||M||!t?.id)){le(!0),Ne(!1);try{const i=await Promise.allSettled(s.map(d=>ps(d,t.id))),o=s.filter((d,c)=>i[c].status==="fulfilled"),n=s.length-o.length;if(o.length>0){const d=new Set(o);m(c=>c.map(g=>{if(!d.has(g.id))return g;const{childId:A,...H}=g;return{...H,heroId:t.id}}))}n>0?(i.forEach(d=>{d.status==="rejected"&&console.error("Error setting the child for a story:",d.reason)}),k.error(a("select.bulkPartialFailure","Could not update {{count}} stories",{count:n}))):k.success(a("select.bulkSetChild",{count:o.length,name:t.name}))}finally{le(!1),te()}}},Yt=async()=>{const t=Array.from(ge);if(t.length===0||M)return;const s=new Set(t),i=new Date().toISOString();le(!0),m(o=>o.map(n=>s.has(n.id)?{...n,deleted:!0,deletedAt:i}:n));try{const{succeeded:o,failed:n}=await ys(t);if(n.length>0){const d=new Set(n);m(c=>c.map(g=>d.has(g.id)?{...g,deleted:!1,deletedAt:null}:g)),k.error(a("select.bulkTrashFailed","Could not delete {{count}} stories",{count:n.length}))}if(o.length>0){const d=new Set(o);R(g=>({...g,creations:se(g.creations,-o.length)})),await _e();const c=async g=>{k.dismiss(g);try{await vs(o),m(A=>A.map(H=>d.has(H.id)?{...H,deleted:!1,deletedAt:null}:H)),R(A=>({...A,creations:se(A.creations,o.length)})),await _e(),k.success(a("select.restored","Stories restored"))}catch(A){console.error("Error restoring books:",A),k.error(a("select.restoreFailed","Could not restore stories"))}};k(g=>e.jsx(pt,{message:a("select.bulkTrashed","Moved {{count}} stories to Trash",{count:o.length}),undoLabel:a("select.undo","Undo"),onUndo:()=>c(g.id)}),{duration:8e3})}}catch(o){console.error("Error bulk deleting books:",o),m(n=>n.map(d=>s.has(d.id)?{...d,deleted:!1,deletedAt:null}:d)),k.error(a("select.bulkTrashFailed","Could not delete {{count}} stories",{count:t.length}))}finally{le(!1),te()}},Gt=l.useCallback(t=>
1{x||(ae.current&&ae.current.disconnect(),ae.current=new IntersectionObserver(s=>{s[0].isIntersecting&&v&&Be()}),t&&ae.current.observe(t))},[x,v,Be]),dt=z&&!(U&&b==="collection"),qe=dt&&Number.isFinite(oe.creations)?oe.creations:null,Wt=!u&&z&&Ke.length>0,Zt=t=>{const i={ArrowRight:1,ArrowLeft:-1,Home:"first",End:"last"}[t.key];if(i===void 0)return;t.preventDefault();const o=Math.max(0,ee.findIndex(c=>c.id===f));let n;i==="first"?n=0:i==="last"?n=ee.length-1:n=(o+i+ee.length)%ee.length;const d=ee[n];Z(d.id),Ve.current[d.id]?.focus()};return e.jsx(ks,{onRefresh:ne,className:"min-h-screen",children:e.jsxs("div",{className:"min-h-screen p-4 transition-colors duration-200 sm:p-6 md:p-8 dark:bg-dim-deep",children:[e.jsx(cs,{title:a("seo.title"),description:a("seo.description"),canonicalPath:"/library",noIndex:!0}),e.jsxs("div",{className:"max-w-7xl mx-auto",children:[e.jsxs(q.div,{className:"mb-4 flex flex-wrap items-center justify-between gap-3 sm:mb-5 md:mb-6",variants:h?void 0:Ls,initial:h?!1:"hidden",animate:h?void 0:"visible",transition:h?{duration:0}:{duration:.15},children:[e.jsx("h1",{className:"flex min-w-0 items-center gap-2 text-2xl font-['Quicksand'] font-bold text-ink sm:text-3xl dark:text-dim-text",children:L?e.jsx("span",{children:a("viewingUserLibrary")}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"truncate font-['Quicksand']",children:a("title")}),qe!==null&&e.jsxs("span",{"data-testid":"library-total-count",className:"shrink-0 rounded-full bg-sage-100 px-3 py-1 text-base font-bold text-sage-700 sm:text-lg dark:bg-dim-elevated dark:text-sage-300",children:[e.jsx("span",{"aria-hidden":"true",children:qe}),e.jsx("span",{className:"sr-only",children:a("storyCount",{count:qe})})]})]})}),!L&&e.jsx(Y,{onClick:()=>W("/create"),size:"sm",leftIcon:e.jsx(vt,{className:"h-5 w-5 shrink-0","aria-hidden":"true"}),className:"min-h-[48px] max-w-full whitespace-normal px-4 text-center",children:a("createNewStory")})]}),e.jsxs("div",{className:"relative mb-5 -mx-4 sm:mx-0 md:mb-6",children:[e.jsx("div",{ref:at,onScroll:X,className:"overflow-x-auto no-scrollbar scroll-px-10 px-4 sm:px-0",children:e.jsx("div",{role:"tablist","aria-label":a("tabs.label"),className:"flex w-max min-w-full gap-1 rounded-xl border border-gray-200 bg-white p-1 shadow-inner transition-colors dark:border-dim-border dark:bg-dim-surface",children:ee.map(t=>{const s=f===t.id,i=t.id==="trash"||dt&&Number.isFinite(t.count);return e.jsxs("button",{ref:o=>{Ve.current[t.id]=o},type:"button",role:"tab",id:`library-tab-${t.id}`,"aria-selected":s,"aria-controls":"library-tabpanel",tabIndex:s?0:-1,onClick:()=>Z(t.id),onKeyDown:Zt,className:`flex min-h-[44px] flex-1 shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-lg px-3 py-2 text-sm font-bold sm:px-4 transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 ${s?"bg-sage-600 text-white shadow-sm dark:bg-sage-300 dark:text-ink":"text-gray-600 hover:bg-gray-50 dark:text-dim-text-secondary dark:hover:bg-dim-elevated"}`,children:[e.jsx("span",{children:t.label}),i&&e.jsx("span",{"data-testid":`library-tab-count-${t.id}`,className:`min-w-[1.25rem] rounded-full px-1.5 py-0.5 text-center text-xs font-black ${s?"bg-white text-sage-800 dark:bg-dim-deep dark:text-sage-200":"bg-gray-100 text-gray-600 dark:bg-dim-elevated dark:text-dim-text-secondary"}`,children:t.count})]},t.id)})})}),it.right&&e.jsx("span",{"aria-hidden":"true","data-testid":"library-tabs-fade",className:"pointer-events-none absolute inset-y-0 right-0 w-10 bg-gradient-to-l from-cream to-transparent dark:from-dim-deep"}),it.left&&e.jsx("span",{"aria-hidden":"true",className:"pointer-events-none absolute inset-y-0 left-0 w-10 bg-gradient-to-r from-cream to-transparent dark:from-dim-deep"})]}),Wt&&e.jsxs("div",{"data-testid":"library-guest-device-banner",className:"mb-5 flex flex-col gap-3 rounded-2xl border border-sage-200 bg-sage-50 px-4 py-3 sm:mb-6 sm:flex-row sm:items-center dark:border-sage-800 dark:bg-dim-surface",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-3",children:[e.jsx("span",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-white text-sage-700 dark:bg-dim-elevated dark:text-sage-300","aria-hidden":"true",children:e.jsx(es,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-bold text-ink dark:text-dim-text",children:a("guestDevice.title")}
1),e.jsx("p",{className:"text-sm text-slate-600 dark:text-dim-text-secondary",children:a("guestDevice.body")})]})]}),e.jsx(Y,{size:"sm",className:"min-h-[44px] shrink-0",onClick:()=>W("/login",{state:{mode:"signup",intent:"story",returnTo:"/library"}}),children:a("guestDevice.cta")})]}),u&&!L&&tt.length>0&&e.jsxs("div",{className:"mb-5 flex flex-col gap-3 rounded-2xl border border-sage-200 bg-sage-50 px-4 py-3 dark:border-sage-800 dark:bg-sage-900/30 sm:mb-6 sm:flex-row sm:items-center",children:[e.jsx("p",{className:"flex-1 text-sm font-bold text-sage-800 dark:text-sage-200",children:a("guestMigration.message","You have {{count}} stories created before signing in",{count:tt.length})}),e.jsx(Y,{size:"sm",onClick:It,loading:ze,className:"whitespace-nowrap",children:ze?a("guestMigration.working","Adding..."):a("guestMigration.action","Add them to your library")})]}),e.jsxs("div",{role:"tabpanel",id:"library-tabpanel","aria-labelledby":`library-tab-${f}`,children:[zt&&!$t&&!(U&&p.length===0)&&e.jsx(Is,{t:a,searchQuery:S,onSearchChange:Ue,isFiltersOpen:Bt,onToggleFilters:()=>At(t=>!t),activeFilterCount:lt,canUseSelection:Ht,hasDisplayedBooks:F.length>0,isSelectionMode:_,onToggleSelectionMode:()=>_?te():ke(!0),sortBy:ie,onSortChange:We,heroes:Se,showHeroFilters:!L,heroFilter:P,onHeroChange:De,selectedCategory:J,onCategoryChange:Me,onClearAllFilters:Rt}),U&&e.jsx(Ss,{onRetry:Tt,isRetrying:x,compact:p.length>0,className:"mb-6"}),U&&(f==="trash"?xe.length===0:F.length===0)?null:f==="trash"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mb-4 text-sm text-slate-600 dark:text-dim-text-secondary",children:a("trash.notice","Items in Trash are deleted forever after 30 days.")}),xe.length===0?e.jsx(re,{title:a("trash.empty","Trash is empty"),message:a("trash.emptyDesc","Stories you delete land here for 30 days before they are gone for good."),icon:ts,tone:"slate"}):e.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 sm:gap-6 lg:grid-cols-3",children:xe.map(t=>e.jsx(Us,{book:t,onRestore:Lt,onDeleteForever:Ft},t.id))})]}):x&&p.length===0?e.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 sm:gap-6 lg:grid-cols-3","aria-busy":"true",children:Array.from({length:6}).map((t,s)=>e.jsxs("div",{className:"p-4 md:p-4 pb-2 md:pb-3 rounded-2xl shadow-sm border bg-white dark:bg-dim-surface border-gray-100 dark:border-dim-border",children:[e.jsx(Ie,{className:"aspect-[4/3] mb-3",rounded:"rounded-xl"}),e.jsx(Ie,{className:"h-5 w-3/4 mb-2"}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx(Ie,{className:"h-3 w-20"}),e.jsx(Ie,{className:"h-3 w-14"})]})]},s))}):F.length===0&&f!=="videos"?e.jsx(Ms,{t:a,isSignedIn:!!u,activeTab:f,heroFilter:P,heroes:Se,hasSearchOrCategory:!!S.trim()||J!=="all",onCreate:t=>W("/create",t?{state:t}:void 0),onOpenSample:()=>W(`/story/${us}`),onShowAllStories:()=>De("all"),onShowStoriesTab:()=>Z("creations"),onClearFilters:()=>{Ue(""),Me("all"),De("all")}}):e.jsx(e.Fragment,{children:f==="videos"?e.jsx(q.div,{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 sm:gap-6 lg:grid-cols-3",variants:h?void 0:bt,initial:h?!1:"hidden",animate:h?void 0:"visible",children:E.length===0?e.jsx(re,{className:"col-span-full",title:a("videos.noVideos"),message:a("videos.noVideosDesc"),icon:ss,secondaryAction:{label:a("videos.browseStories","Browse your stories"),onClick:()=>Z("creations"),icon:e.jsx(me,{className:"h-5 w-5","aria-hidden":"true"})}}):E.map((t,s)=>{const i=new Date(t.expiresAt)<new Date,o=new Date,n=new Date(t.expiresAt),d=Math.max(0,Math.floor((n-o)/(1e3*60*60))),c=p.find(A=>A.id===t.bookId),g=!!t.bookId&&!(c&&c.deleted);return e.jsxs(q.div,{className:"bg-white dark:bg-dim-surface p-6 rounded-2xl shadow-md border border-gray-100 dark:border-dim-border group",variants:h?void 0:Ct,transition:h?{duration:0}:{delay:s*.05},whileHover:h?void 0:{y:-4,boxShadow:"0 12px 40px rgba(0,0,0,0.1)"},whileTap:h?void 0:{scale:.98},children:[e.jsxs("div",{className:"aspect-[16/9] rounded-xl mb-4 bg-gray-100 overflow-hidden relative",children:[t.coverImageUrl?e.jsx("img",{src:t.coverImageUrl,alt:"",className:"w-full h-full object-cover opacity-80"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center text-gray-300",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",className:"w-16 h-16",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15.75 10.5l4.72-4.72a.75.75 0 011.28.53v11.38a.75.75 0 01-1.28.53l-4.72-4.72M4.5 18.75h9a2.25 2.25 0 002.25-2.25v-9a2.25 2.25 0 00-2.25-2.25h-9A2.25 2.25 0 002.25 7.5v9a2.25 2.25 0 002.25 2.25z"})})}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/20 group-hover:bg-black/10 transition-colors",children:e.jsx("div",{className:"w-12 h-12 rounded-full bg-white/90 flex items-center justify-center shadow-lg text-sage-700",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"
1currentColor",className:"w-6 h-6 ml-1",children:e.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})})}),i&&e.jsx("div",{className:"absolute inset-0 bg-gray-900/70 flex items-center justify-center backdrop-blur-sm z-10",children:e.jsx("span",{className:"text-white font-bold px-3 py-1 bg-slate-800/90 rounded-full text-sm",children:a("videos.expired")})})]}),e.jsx("h3",{className:"text-lg font-bold text-gray-800 dark:text-dim-text mb-1 truncate",children:G(t.bookTitle)}),e.jsxs("div",{className:"flex justify-between items-center gap-2 text-sm text-slate-600 dark:text-dim-text-secondary mb-4",children:[e.jsx("span",{children:St(t.createdAt,j?.resolvedLanguage||j?.language)}),!i&&e.jsxs("span",{className:"inline-flex items-center gap-1 font-medium",children:[e.jsx(rs,{className:"h-4 w-4","aria-hidden":"true"}),a("videos.expiresIn")," ",d,a("videos.hours")]})]}),e.jsx("div",{className:"flex gap-2",children:i?g?e.jsx("button",{type:"button",onClick:()=>{k(a("videos.createAgainHint",'Open the story menu and choose "Create video" to make a new one.')),W(`/story/${t.bookId}/${kt(G(t.bookTitle||""))}`,{state:{returnPath:"/library"}})},className:"min-h-[44px] flex-1 rounded-lg bg-sage-100 py-2 text-center text-sm font-bold text-sage-800 transition-colors hover:bg-sage-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 dark:bg-dim-elevated dark:text-sage-200",children:a("videos.createAgain","Create again")}):e.jsx("p",{className:"flex-1 text-center text-sm text-slate-600 dark:text-dim-text-secondary py-2",children:a("videos.videoExpired")}):e.jsx(e.Fragment,{children:e.jsx("a",{href:t.downloadUrl,target:"_blank",rel:"noopener noreferrer",className:"flex min-h-[44px] flex-1 items-center justify-center rounded-lg bg-sage-100 py-2 text-center text-sm font-bold text-sage-800 transition-colors hover:bg-sage-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-sage-500 dark:bg-dim-elevated dark:text-sage-200",children:a("videos.watchDownload")})})})]},t.id)})}):e.jsxs(e.Fragment,{children:[e.jsx(q.div,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2 sm:gap-6 lg:grid-cols-3 ${_?Qe?"pb-56 sm:pb-44 lg:pb-28":"pb-44 lg:pb-28":""}`,variants:h?void 0:bt,initial:h?!1:"hidden",animate:h?void 0:"visible",children:F.map((t,s)=>e.jsx(Os,{book:t,index:s,isLast:s===F.length-1?Gt:null,onToggleFavorite:Ot,isFavoritePending:Je.has(t.id),onDuplicate:u&&!L?Ut:null,isSelectionMode:_,isSelected:ge.has(t.id),onToggleSelect:Vt,child:Qt&&_t.get(t.heroId||t.childId)||null},t.id))}),x&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-4 border-sage-500 border-t-transparent"}),e.jsx("p",{className:"text-gray-500 mt-2",children:a("loading.more")})]}),!v&&F.length>0&&e.jsx("div",{className:"text-center py-8",children:e.jsx("p",{className:"text-gray-500",children:a("loading.endReached")})})]})})]}),_&&e.jsx("div",{ref:et,className:"fixed inset-x-0 bottom-[var(--mobile-bottom-nav-offset)] z-[60] px-3 lg:bottom-0 lg:px-4 lg:pb-4",children:e.jsxs("div",{"data-testid":"library-bulk-bar",className:"relative mx-auto max-w-7xl rounded-2xl border border-gray-200 bg-white/95 px-3 py-3 shadow-xl backdrop-blur sm:px-4 lg:flex lg:items-center lg:justify-between lg:gap-2 dark:border-dim-border dark:bg-dim-surface/95",children:[je&&e.jsxs("div",{role:"dialog","aria-labelledby":"library-set-child-title","data-testid":"library-child-picker",className:"absolute bottom-full right-0 mb-2 w-72 max-w-[calc(100vw-1.5rem)] rounded-2xl border border-gray-200 bg-white p-3 shadow-xl dark:border-dim-border dark:bg-dim-elevated",children:[e.jsx("p",{id:"library-set-child-title",className:"mb-2 px-1 font-['Quicksand'] text-sm font-bold text-ink dark:text-dim-text",children:a("select.setChildTitle")}),e.jsx(Bs,{heroes:pe,onSelect:qt,disabled:M})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 lg:contents",children:[e.jsx("p",{className:"min-w-0 text-sm font-bold text-ink dark:text-dim-text lg:mr-auto",role:"status",children:a("select.selectedCount","{{count}} selected",{count:be})}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2 lg:order-last",children:[e.jsx(ue,{variant:"secondary",onClick:Kt,disabled:M,children:a("select.selectAll","Select all")}),e.jsx(ue,{variant:"ghost",onClick:te,disabled:M,children:a("select.cancel","Cancel")})]})]}),e.jsxs("div",{className:`mt-2 grid gap-2 lg:mt-0 lg:flex lg:items-center ${Qe?"grid-cols-2 sm:grid-cols-4":"grid-cols-3"}`,children:[e.jsx(ue,{variant:"outline",disabled:be===0||M,onClick:()=>nt(!0),children:a("select.favorite","Favorite")}),e.jsx(ue,{variant:"outline",disabled:be===0||M,onClick:()=>nt(!1),children:a("select.unfavorite","Unfavorite")}),Qe&&e.jsx(ue,{variant:"outline",disabled:be===0||M,"aria-expanded":je,"aria-haspopup":"dialog",onClick:()=>Ne(t=>!t),children:a("select.setChild")}),e.jsx(ue,{variant:"destructive",disabled:be===0||M,onClick:Yt,children:a("select.moveToTrash","Move to Trash")})]})]})})]})]})})}export{rr 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.