import{j as e}from"./query-vendor-CZu0EHPe.js";import{u as O,r as o}from"./react-vendor-0bvDbF03.js";import{e as U,u as z,f as R,I as H,S as J,m as M,W as Q,y as q,ag as K,B as E,K as _,k as G,E as b,J as c}from"./index-B2Fv47c7.js";import{I as X}from"./input-BqhnYLUV.js";import{A as Y,a as Z,b as ee,c as se,d as te,e as re,f as ae,g as oe}from"./alert-dialog-xu5sPaOP.js";import{c as ne,p as le}from"./azure-speech-service-BhVBDGDq.js";import{C as ie,a as ce,b as de}from"./collapsible-d6hd6Isu.js";import{B as me}from"./BreadcrumbNavigation-DIdPk2xo.js";import{U as xe}from"./UpgradeButton-2hv6YKEF.js";import{u as S}from"./i18n-vendor-Bg2yf_Zw.js";import{S as pe}from"./search-ByBguehr.js";import{V as ue}from"./volume-2-DVHhAqP4.js";import{T as he}from"./trash-2-DaCUQjlf.js";import"./supabase-vendor-CNV44oIa.js";import"./helmet-vendor-NlTFkN97.js";import"./index-BE8bkHKe.js";function Te(){const{t}=S("vocabulary"),{t:y}=S("navbar"),{getLocalizedPath:d}=U(),p=O(),{user:n,isLoading:u}=z(),{userType:W,isLoading:N}=R(),h=!!n&&W==="free",[m,v]=o.useState([]),[w,g]=o.useState([]),[L,k]=o.useState(!0),[l,A]=o.useState(""),[i,f]=o.useState(null),[C,T]=o.useState(new Set),[D,V]=o.useState(!1);o.useEffect(()=>{!u&&!n&&p(d("/login"))},[u,n,p,t,d]),o.useEffect(()=>{if(!n)return;(async()=>{try{if(k(!0),!N&&h&&!D){const a=await b.pruneForFreeUser();V(!0),a>0&&c.info(t("toast.vocabPruned",{count:a}),{description:t("toast.vocabPrunedDescription"),duration:6e3})}const r=await b.getVocabulary();v(r),g(r)}catch(r){console.error("Error loading vocabulary:",r),c.error(t("toast.loadError"),{description:t("toast.loadErrorDescription")})}finally{k(!1)}})()},[n,t,h,D,N]),o.useEffect(()=>{if(l.trim()==="")g(m);else{const s=l.toLowerCase(),r=m.filter(a=>a.word.toLowerCase().includes(s)||a.originalWord.toLowerCase().includes(s));g(r)}},[l,m]);const P=async()=>{if(i)try{await b.deleteWord(i.id)?v(r=>r.filter(a=>a.id!==i.id)):c.error(t("toast.deleteError"),{description:t("toast.deleteErrorDescription")})}catch(s){console.error("Error deleting word:",s),c.error(t("toast.deleteError"),{description:t("toast.deleteErrorDescription")})}finally{f(null)}},B=async(s,r)=>{const a=ne();try{await le(s,a)}catch(x){console.error("Error playing pronunciation:",x),c.error(t("toast.pronunciationError"),{description:t("toast.pronunciationErrorDescription")})}},$=s=>{T(r=>{const a=new Set(r);return a.has(s)?a.delete(s):a.add(s),a})},F=(s,r)=>{const a=new RegExp(`\\b(${r})\\b`,"gi");return s.split(a).map((j,I)=>j.toLowerCase()===r.toLowerCase()?e.jsx("mark",{className:"bg-primary/20 font-semibold",children:j},I):j)};return u||L?e.jsx("div",{className:"container pt-4 pb-6 md:pt-6 md:pb-8 flex items-center justify-center min-h-[50vh]",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(H,{className:"h-6 w-6 animate-spin"}),e.jsx("span",{children:t("loading")})]})}):n?e.jsxs(e.Fragment,{children:[e.jsx(J,{title:t("meta.title"),description:t("meta.description")}),e.jsx("div",{className:"min-h-screen bg-page-surface",children:e.jsxs("div",{className:"container pt-4 pb-6 md:pt-6 md:pb-8",children:[e.jsx(me,{items:[{name:y("home"),path:"/"},{name:y("vocabulary"),path:"/vocabulary"}]}),e.jsx("div",{className:"mb-8",children:e.jsxs("div",{className:"flex flex-col lg:flex-row items-center justify-center gap-3 md:gap-6 lg:gap-8",children:[e.jsx("div",{className:"w-32 h-32 lg:w-44 lg:h-44 flex-shrink-0",children:e.jsx(M.div,{animate:{y:[0,-8,0]},transition:{duration:3,repeat:1/0,ease:"easeInOut"},children:e.jsx("img",{src:"https://cdn.storysparkle.org/ui_elements/Hero%20Icons/Vocabulary.webp",alt:"Vocabulary Notebook",className:"w-full h-full object-contain drop-shadow-2xl"})})}),e.jsxs("div",{className:"flex flex-col items-center lg:items-start text-center lg:text-left",children:[e.jsx("h1",{className:"text-[22px] lg:text-[32px] font-bold mb-4 text-ink",children:t("pageTitle")}),e.jsx("p",{className:"text-sm lg:text-xl text-nature-forest",children:t("pageSubtitle")}),e.jsx(Q,{slug:"how-read-along-works",className:"mt-3"})]})]})}),h&&m.length>=20&&e.jsxs("div",{className:"page-card p-5 mb-8 max-w-2xl mx-auto flex flex-col sm:flex-row items-center gap-4",children:[e.jsx("p",{className:"text-sm text-nature-honey-ink font-medium flex-1 text-center sm:text-left",children:t("limitWarning")}),e.jsx(xe,{size:"sm"})]}),e.jsx("div",{className:"page-card p-6 mb-8 max-w-2xl mx-auto",children:e.jsxs("div",{className:"relative",children:[e.jsx(pe,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-nature-forest/60 h-5 w-5"}),e.jsx(X,{type:"text",placeholder:t("searchPlaceholder"),value:l,onChange:s=>A(s.target.value),className:"pl-10 pr-4 py-3 text-base border-gray-300 focus:border-nature-forest focus:ring-nature-forest"})]})}),w.length===0?e.jsxs("div",{className:"page-card max-w-md mx-auto p-6 text-center",children:[e.jsx("h2",{className:"text-lg font-bold text-ink",children:t(l?"searchResults.noMatches":"emptyNotebook.title")}),!l&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mt-2 text-sm text-nature-forest",children:t("emptyNotebook.description")}),e.jsx("div",{className:"mt-5 flex justify-center",children:e.jsx(q,{variant:"primary",to:d("/stories"),leftIcon:e.jsx(K,{}),children:t("emptyNotebook.browseButton")})})]})]}):e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:w.map(s=>e.jsxs("div",{className:"page-card overflow-hidden",children:[e.jsx("div",{className:"flex flex-col space-y-1.5 p-6 pb-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsx("div",{className:"flex-1",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(E,{variant:"ghost",size:"icon",onClick:()=>B(s.word,s.pronunciation),className:"h-8 w-8 text-nature-forest hover:bg-nature-forest/10 hover:text-nature-forest",children:e.jsx(ue,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-semibold leading-none tracking-tight text-ink",children:s.originalWord}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["/",s.pronunciation,"/"]})]})]})}),e.jsx(E,{variant:"ghost",size:"icon",onClick:()=>f(s),className:"h-8 w-8 text-nature-red hover:bg-nature-red/10 hover:text-nature-red",children:e.jsx(he,{className:"h-4 w-4"})})]})}),e.jsx("div",{className:"p-6 pt-0 space-y-3",children:s.occurrences.map((r,a)=>e.jsx(ie,{open:C.has(`${s.id}-${a}`),onOpenChange:()=>$(`${s.id}-${a}`),children:e.jsxs("div",{className:"border border-nature-forest/20 rounded-lg p-4 space-y-3",children:[e.jsx(ce,{asChild:!0,children:e.jsxs("div",{className:"flex items-start gap-3 cursor-pointer hover:bg-nature-forest/5 -m-4 p-4 rounded-lg transition-colors",children:[r.storyThumbnail&&e.jsx("img",{src:r.storyThumbnail,alt:r.storyTitle||"Story",className:"w-16 h-16 object-cover rounded flex-shrink-0",onClick:x=>{x.stopPropagation(),p(d(`/story/${r.storyId}`))}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1",children:[e.jsx("p",{className:"text-sm font-medium text-nature-forest truncate",children:r.storyTitle||"Story"}),C.has(`${s.id}-${a}`)?e.jsx(_,{className:"h-4 w-4 flex-shrink-0"}):e.jsx(G,{className:"h-4 w-4 flex-shrink-0"})]}),e.jsxs("p",{className:"text-sm text-muted-foreground italic line-clamp-2",children:['"',F(r.sentence,s.word),'"']})]})]})}),e.jsx(de,{className:"space-y-2",children:e.jsx("div",{className:"pt-2 border-t border-nature-forest/20",children:e.jsxs("p",{className:"text-sm text-ink",children:[e.jsx("span",{className:"font-semibold",children:r.contextualMeaning}),r.partOfSpeech&&e.jsxs("span",{className:"text-muted-foreground ml-2",children:["(",r.partOfSpeech,")"]})]})})})]})},r.id))})]},s.id))}),e.jsx(Y,{open:!!i,onOpenChange:s=>!s&&f(null),children:e.jsxs(Z,{children:[e.jsxs(ee,{children:[e.jsx(se,{children:t("deleteDialog.title")}),e.jsx(te,{children:t("deleteDialog.description",{word:i?.originalWord})})]}),e.jsxs(re,{children:[e.jsx(ae,{children:t("deleteDialog.cancel")}),e.jsx(oe,{onClick:P,className:"bg-nature-red text-white hover:bg-nature-red/90",children:t("deleteDialog.delete")})]})]})})]})})]}):null}export{Te as default};