PageSourceSearch

https://www.ucan.vn/assets/Flashcards-ChXaLzXJ.js

js ucan.vn collected 2026-09-24 13:37:15 UTC 90,910 bytes, 3 lines download raw bytes

1import{j as e,ae as Ct,af as St,ag as zt,ah as Tt,ai as $t,aj as _t,ak as Mt,al as Et,r as a,I as $e,am as At,an as Lt,x as ts,ao as as,ap as Ye,ad as Os,aq as _e,ab as He,k as ns,ar as Be,a8 as Ot,E as Rt,aa as Je,as as Rs,at as Dt,au as Bt,av as Ze,b as Ue,aw as ps,ax as Ds,ay as Wt,t as es,az as ws,aA as Bs,aB as Ft,aC as It,aD as qt,A as ks,aE as Kt,aF as Ws}from"./react-vendor-bcN6ZJx6.js";import{j as Ce,k as Fs,l as Is,n as qs,B as v,I as ss,C as ie,t as P,f as ce,o as Ut,u as Vt,D as Ks,p as Us,q as Vs,r as Hs,v as Xs,w as Ps,L as Ve,x as Ht,T as Xt,i as Cs}from"./index-C8TfN4cr.js";import{F as Gs,u as Pt,C as Gt,a as Qt,b as Yt,A as Jt}from"./useNotebooks-Dr3rJxWF.js";import{P as is}from"./progress-BdsqlISq.js";import{T as Qs}from"./textarea-XZpQlx6O.js";import{u as ls,A as Xe}from"./AudioButton-JKbMlK08.js";import{t as ke}from"./vocabulary-parser-BKp6oOoh.js";import{p as Ss}from"./audio-utils-CymXYr94.js";import{u as Ys,G as Zt}from"./types-DA7h2ogz.js";import{u as ea}from"./useFlashcardProgress-D0OmEBmS.js";import{u as Ns}from"./useTopics-t-JE6OYC.js";import{S as zs,a as Ts,b as $s,c as _s,d as Ne,e as sa,f as Ms}from"./select-DMkThb18.js";import{A as ta,m as aa}from"./animation-vendor-Bv7-tU3_.js";import"./ui-vendor-BA32w1ww.js";import"./supabase-vendor-DNBNrwrO.js";import"./separator-CQXm8LCX.js";function na({...s}){return e.jsx(Ct,{"data-slot":"alert-dialog",...s})}function ia({...s}){return e.jsx(Mt,{"data-slot":"alert-dialog-portal",...s})}function la({className:s,...l}){return e.jsx(Et,{"data-slot":"alert-dialog-overlay",className:Ce("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",s),...l})}function ra({className:s,...l}){return e.jsxs(ia,{children:[e.jsx(la,{}),e.jsx(St,{"data-slot":"alert-dialog-content",className:Ce("bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",s),...l})]})}function ca({className:s,...l}){return e.jsx("div",{"data-slot":"alert-dialog-header",className:Ce("flex flex-col gap-2 text-center sm:text-left",s),...l})}function oa({className:s,...l}){return e.jsx("div",{"data-slot":"alert-dialog-footer",className:Ce("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",s),...l})}function da({className:s,...l}){return e.jsx(zt,{"data-slot":"alert-dialog-title",className:Ce("text-lg font-semibold",s),...l})}function xa({className:s,...l}){return e.jsx(Tt,{"data-slot":"alert-dialog-description",className:Ce("text-gray-600 text-sm",s),...l})}function ma({className:s,...l}){return e.jsx(_t,{className:Ce(Fs(),s),...l})}function ha({className:s,...l}){return e.jsx($t,{className:Ce(Fs({variant:"outline"}),s),...l})}function ua({open:s,onOpenChange:l,title:g,description:m,confirmText:h="Xác nhận",cancelText:N="Hủy",variant:T="default",onConfirm:k,onCancel:z}){return e.jsx(na,{open:s,onOpenChange:l,children:e.jsxs(ra,{children:[e.jsxs(ca,{children:[e.jsx(da,{children:g}),m&&e.jsx(xa,{children:m})]}),e.jsxs(oa,{children:[e.jsx(ha,{onClick:()=>{z==null||z()},children:N}),e.jsx(ma,{onClick:()=>{T==="destructive"?Is("warning"):qs(),k()},className:T==="destructive"?"bg-destructive text-white hover:bg-destructive/90":void 0,children:h})]})]})})}function Js(){const[s,l]=a.useState({open:!1,title:""}),g=a.useCallback(k=>new Promise(z=>{l({...k,open:!0,resolve:z})}),[]),m=a.useCallback(()=>{var k;(k=s.resolve)==null||k.call(s,!0),l(z=>({...z,open:!1}))},[s.resolve]),h=a.useCallback(()=>{var k;(k=s.resolve)==null||k.call(s,!1),l(z=>({...z,open:!1}))},[s.resolve]),N=a.useCallback(k=>{var z;k||((z=s.resolve)==null||z.call(s,!1),l(A=>({...A,open:!1})))},[s.resolve]),T=a.useMemo(()=>e.jsx(ua,{open:s.open,onOpenChange:N,title:s.title,description:s.description,confirmText:s.confirmText,cancelText:s.cancelText,variant:s.variant,onConfirm:m,onCancel:h}),[s.open,s.title,s.description,s.confirmText,s.cancelText,s.variant,m,h,N]);return{confirm:g,ConfirmDialogComponent:T}}const Es=50;function ga({notebook:s,words:l,masteredCards:g,learningCards:m,progressData:h,onClose:N,onRemoveWord:T,onToggleMastered:k,onToggleLearning:z,onOpenFlashcardView:A,onStartQuiz:f,onUpdateNotebook:w,onSearchVocabulary:p,onAddWordToNotebook:J,isPremium:n}){const{play:y,isLoading:u}=ls(),[c,_]=a.useState(""),[W,q]=a.useState(null),[Q,O]=a.useState(!1),[Z,R]=a.use
1State(!1),[I,K]=a.useState(s.name),[i,b]=a.useState(s.description||""),[se,D]=a.useState([]),[ae,F]=a.useState(!1),[ee,Y]=a.useState(new Set),[o,L]=a.useState("all"),B=a.useRef(void 0),{confirm:M,ConfirmDialogComponent:V}=Js(),E=a.useMemo(()=>n?l:l.slice(0,Es),[l,n]),H=a.useMemo(()=>n?[]:l.slice(Es),[l,n]),X=a.useMemo(()=>{let t=E;return o==="mastered"?t=t.filter(x=>g.includes(x.id)):o==="learning"?t=t.filter(x=>m.includes(x.id)&&!g.includes(x.id)):o==="new"&&(t=t.filter(x=>!g.includes(x.id)&&!m.includes(x.id))),c&&(t=t.filter(x=>x.word.toLowerCase().includes(c.toLowerCase())||x.translation.toLowerCase().includes(c.toLowerCase())||x.definition.toLowerCase().includes(c.toLowerCase()))),t},[E,c,o,g,m]),ve=a.useCallback(()=>{if(o!=="all")return X.map(G=>G.id);const t=new Date,x=[],S=[],j=[];for(const G of E){const U=h==null?void 0:h[G.id];if(!U||!U.next_review_at)S.push(G.id);else{const le=new Date(U.next_review_at);if(le<=t){const xe=t.getTime()-le.getTime();x.push({id:G.id,urgency:xe})}else j.push(G.id)}}return x.sort((G,U)=>U.urgency-G.urgency),[...x.map(G=>G.id),...S,...j]},[E,h,o,X]);a.useEffect(()=>(B.current&&clearTimeout(B.current),c&&c.trim().length>=1&&X.length===0&&p?(F(!0),B.current=setTimeout(async()=>{try{const t=await p(c.trim()),x=new Set(s.word_ids.map(String)),S=t.map(j=>ke(j)).filter(j=>!x.has(j.id));D(S)}catch(t){console.error("Vocabulary search error:",t),D([])}finally{F(!1)}},400)):(D([]),F(!1)),()=>{B.current&&clearTimeout(B.current)}),[c,X.length,p,s.word_ids]);const re=async t=>{if(J){Y(x=>new Set(x).add(t.id));try{await J(s.id,t.id)&&(P.success(`Đã thêm "${t.word}" vào sổ!`),D(S=>S.filter(j=>j.id!==t.id)))}catch(x){console.error("Error adding word to notebook:",x),P.error("Không thể thêm từ vào sổ")}finally{Y(x=>{const S=new Set(x);return S.delete(t.id),S})}}},me=E.filter(t=>g.includes(t.id)).length,fe=E.filter(t=>m.includes(t.id)).length,be=E.length>0?me/E.length*100:0,ue=t=>{q(t),O(!0)},Se=async()=>{if(w)try{await w(s.id,{name:I,description:i}),R(!1)}catch(t){console.error("Error updating notebook:",t)}},d=()=>{K(s.name),b(s.description||""),R(!1)};return e.jsxs("div",{className:"fixed inset-0 bg-background z-50 overflow-y-auto",children:[e.jsxs("div",{className:"min-h-screen",children:[e.jsx("div",{className:"sticky top-0 z-20 bg-background/95 backdrop-blur-sm border-b safe-top",children:e.jsxs("div",{className:"container mx-auto px-4 sm:px-6 lg:px-12 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 mb-4",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx(v,{variant:"ghost",size:"icon",onClick:N,className:"rounded-full flex-shrink-0",children:e.jsx($e,{size:24})}),e.jsx("div",{className:"flex-1 min-w-0",children:Z?e.jsxs("div",{className:"space-y-2",children:[e.jsx(ss,{value:I,onChange:t=>K(t.target.value),placeholder:"Tên sổ từ vựng",className:"text-xl font-bold"}),e.jsx(Qs,{value:i,onChange:t=>b(t.target.value),placeholder:"Mô tả (không bắt buộc)",className:"text-sm resize-none",rows:2})]}):e.jsxs(e.Fragment,{children:[e.jsx("h1",{className:"text-xl sm:text-2xl font-bold truncate",children:s.name}),s.description&&e.jsx("p",{className:"text-sm text-gray-600 truncate",children:s.description})]})})]}),e.jsx("div",{className:"flex items-center gap-2 flex-shrink-0",children:Z?e.jsxs(e.Fragment,{children:[e.jsxs(v,{variant:"ghost",size:"sm",onClick:d,className:"gap-1.5",children:[e.jsx($e,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Hủy"})]}),e.jsxs(v,{variant:"default",size:"sm",onClick:Se,className:"gap-1.5",children:[e.jsx(At,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Lưu"})]})]}):e.jsxs(e.Fragment,{children:[w&&e.jsxs(v,{variant:"ghost",size:"sm",onClick:()=>R(!0),className:"gap-1.5",children:[e.jsx(Lt,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Sửa"})]}),e.jsxs(v,{variant:"outline",size:"sm",onClick:()=>f(ve()),className:"gap-1.5",children:[e.jsx(ts,{className:"w-4 h-4"}
1),e.jsx("span",{className:"hidden sm:inline",children:"Quiz"})]}),e.jsxs(v,{variant:"outline",size:"sm",onClick:()=>A(ve()),className:"gap-1.5",children:[e.jsx(as,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Flashcard"})]})]})})]}),e.jsx(ie,{className:"p-4 bg-gradient-to-r from-primary/10 to-accent/10 border-2",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:"Tiến Độ Học"}),e.jsxs("span",{className:"text-sm font-bold",children:[me,"/",E.length," từ",!n&&H.length>0?` (+${H.length} 🔒)`:""]})]}),e.jsx(is,{value:be,className:"h-3"}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 sm:gap-4 mt-2",children:[e.jsxs("button",{className:`text-center rounded-lg py-1.5 transition-all ${o==="mastered"?"bg-primary/15 ring-2 ring-primary/40":"hover:bg-primary/5"}`,onClick:()=>L(t=>t==="mastered"?"all":"mastered"),children:[e.jsx("div",{className:"text-xl sm:text-2xl font-bold text-primary",children:me}),e.jsx("div",{className:"text-xs text-gray-600",children:"Đã thuộc"})]}),e.jsxs("button",{className:`text-center rounded-lg py-1.5 transition-all ${o==="learning"?"bg-accent/15 ring-2 ring-accent/40":"hover:bg-accent/5"}`,onClick:()=>L(t=>t==="learning"?"all":"learning"),children:[e.jsx("div",{className:"text-xl sm:text-2xl font-bold text-accent",children:fe}),e.jsx("div",{className:"text-xs text-gray-600",children:"Đang học"})]}),e.jsxs("button",{className:`text-center rounded-lg py-1.5 transition-all ${o==="new"?"bg-muted ring-2 ring-border":"hover:bg-muted/50"}`,onClick:()=>L(t=>t==="new"?"all":"new"),children:[e.jsx("div",{className:"text-xl sm:text-2xl font-bold text-gray-600",children:E.length-me-fe}),e.jsx("div",{className:"text-xs text-gray-600",children:"Chưa học"})]})]})]})}),e.jsxs("div",{className:"relative mt-4",children:[e.jsx(Ye,{size:20,className:"absolute left-4 top-1/2 -translate-y-1/2 text-gray-600"}),e.jsx(ss,{placeholder:p?"Tìm từ trong sổ hoặc tra từ mới...":"Tìm từ trong sổ...",value:c,onChange:t=>_(t.target.value),className:"pl-12 pr-12 h-11 bg-background"}),c&&e.jsx(v,{size:"icon",variant:"ghost",className:"absolute right-2 top-1/2 -translate-y-1/2 h-7 w-7 rounded-full",onClick:()=>_(""),children:e.jsx($e,{size:16})})]})]})}),e.jsxs("div",{className:"container mx-auto px-4 sm:px-6 lg:px-12 py-6 pb-24",children:[X.length>0&&e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4",children:X.map(t=>{var le,xe;const x=h==null?void 0:h[t.id],S=(x==null?void 0:x.mastery_level)??0,j=Math.round(S/5*100),G=g.includes(t.id),U=m.includes(t.id);return e.jsx(ie,{className:"p-4 hover:shadow-md transition-all bg-card cursor-pointer",onClick:()=>ue(t),children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("h4",{className:"text-xl font-bold text-success flex-1",children:t.word}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsxs("div",{className:"text-xs text-gray-600",children:[j,"%"]}),e.jsx("div",{className:"w-12 h-1 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-success transition-all",style:{width:`${j}%`}})})]}),e.jsx(v,{variant:"ghost",size:"icon",className:"h-8 w-8 transition-colors text-destructive hover:text-destructive hover:bg-destructive/10",onClick:async ge=>{ge.stopPropagation(),await M({title:`Xóa "${t.word}"?`,description:"Từ này sẽ bị xóa khỏi sổ từ vựng.",confirmText:"Xóa",variant:"destructive"})&&T(t.id)},children:e.jsx(Os,{size:16})})]})]}),e.jsx("p",{className:"text-sm text-gray-600 italic",children:t.partOfSpeech||"phr.v"}),t.pronunciation&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Xe,{isLoading:u(t.audioUrl,t.word),onClick:ge=>{ge.stopPropagation(),y(t.word,t.audioUrl)},size:16}),e.jsx("span",{className:"text-xs text-gray-600",children:t.pronunciation})]}),e.jsx("p",{className:"text-sm leading-relaxed",children:((le=t.customMeaning)==null?void 0:le.meaning_en)||t.definition}),e.jsxs("div",{className:"flex items-start gap-2 pt-2 border-t",children:[e.jsx("div",{className:"w-5 h-5 rounded bg-red-500 flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx(_e,{size:12,weight:"fill",className:"text-yellow-400"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("span",{className:"text-sm font-medium",children:"Vietnamese:"}),e.jsx("span",{className:"text-sm ml-1",children:((xe=t.customMeaning)==null?void 0:xe.meaning_vi)||t.translation})]})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsxs(v,{variant:"outline",size:"sm",className:`flex-1 gap-1 ${U?"border-warning text-warning bg-warning/10":""}`,onClick:ge=>{ge.stopPropagation(),z(t.id)},children:[e.jsx(He,{size:16,weight:U?"fill":"regular"}),e.jsx("span",{className:"text-xs",children:"Đang học"})]}),e.jsxs(v,{variant:"outline",size:"sm",className:`flex-1 gap-1 ${G?"border-success text-success bg-success/10":""}`,onClick:ge=>{ge.stopPropagation(),k(t.id)},children:[e.jsx(ns,{size:16,weight:G?"fill":"regular"}),e.jsx("span",{className:"text-xs",children:"Đã thuộc"})]})]})]})},t.id)})}),!n&&H.length>0&&o==="all"&&!c&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 mt-6 mb-3",children:[e.jsx(Be,{size:16,className:"text-amber-500"}),e.jsxs("span",{className:"text-sm font-medium text-amber-600",children:["+",H.length," từ bị khóa — nâng cấp Premium để mở khóa"]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4 opacity-40 pointer-events-none select-none",children:H.slice(0,6).map(t=>e.jsx(ie,{className:"p-4 bg-card relative overflow-hidden",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("h4",{className:"text-xl font-bold text-success flex-1",children:t.word}),e.jsx(Be,{size:16,className:"text-amber-500 flex-shrink-0 mt-1"})]}),e.jsx("p",{className:"text-sm text-gray-600 italic",children:t.partOfSpeech||"phr.v"}),e.jsx("p",{className:"text-sm leading-relaxed line-clamp-2",children:t.definition})]})},t.id))})]}),X.length===0&&H.length===0&&!c&&o==="all"&&e.jsx(ie,{className:"p-12",children:e.jsxs("div",{className:"text-center text-gray-600",children:[e.jsx(Ot,{size:48,className:"mx-auto mb-4 opacity-50"}),e.jsx("p",{className:"text-lg font-medium",children:"Sổ từ vựng này chưa có từ nào"}),e.jsx("p",{className:"text-sm mt-2",children:"Thêm từ vào sổ để bắt đầu học"})]})}),c&&X.length===0&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-600",children:[e.jsx(Ye,{size:16}),e.jsxs("span",{children:['Không tìm thấy "',e.jsx("strong",{children:c}),'" trong sổ.']})]}),ae&&e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto"}),e.jsx("p",{className:"text-sm text-gray-600",children:"Đang tìm trong kho từ vựng..."})]})}),!ae&&se.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Rt,{size:18,className:"text-primary"}),e.jsxs("h3",{className:"text-sm font-semibold text-primary",children:["Kết quả từ kho từ vựng (",se.length,")"]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4",children:se.map(t=>e.jsx(ie,{className:"p-4 hover:shadow-md transition-all bg-card cursor-pointer border-dashed border-primary/30",onClick:()=>ue(t),children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("h4",{className:"text-xl font-bold text-success flex-1",children:t.word}),e.jsxs(v,{variant:"default",size:"sm",className:"gap-1.5 flex-shrink-0",disabled:ee.has(t.id),onClick:x=>{x.stopPropagation(),re(t)},children:[ee.has(t.id)?e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-white"}):e.jsx(Je,{size:16,weight:"bold"}),e.jsx("span",{className:"text-xs",children:"Thêm"})]})]}),e.jsx("p",{className:"text-sm text-gray-600 italic",children:t.partOfSpeech||"n."}),t.pronunciation&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Xe,{isLoading:u(t.audioUrl,t.word),onClick:x=>{x.stopPropagation(),y(t.word,t.audioUrl)},size:16}),e.jsx("span",{className:"text-xs text-gray-600",children:t.pronunciation})]}),e.jsx("p",{className:"text-sm leading-relaxed",children:t.definition}),e.jsxs("div",{className:"flex items-start gap-2 pt-2 border-t",children:[e.jsx("div",{className:"w-5 h-5 rounded bg-red-500 flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx(_e,{size:12,weight:"fill",className:"text-yellow-400"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("span",{className:"text-sm font-medium",children:"Vietnamese:"}),e.jsx("span",{className:"text-sm ml-1",children:t.translation})]})]})]})},t.id))})]}),!ae&&se.length===0&&p&&e.jsx(ie,{className:"p-8",children:e.jsxs("div",{className:"text-center text-gray-600",children:[e.jsx(Ye,{size:40,className:"mx-auto mb-3 opacity-50"}),e.jsx("p",{className:"text-sm",children:"Không tìm thấy từ vựng nào phù hợp"}),e.jsx("p",{className:"text-xs mt-1",children:"Thử tìm với từ khóa khác"})]})})]})]})]}),e.jsx(Gs,{flashcard:W,open:Q,onOpenChange:O,isMastered:W?g.includes(W.id):!1,onSwipeLeft:()=>{W&&g.includes(W.id)&&k(W.id)},onSwipeRight:()=>{W&&!g.includes(W.id)&&k(W.id)}}),V]})}const fa=Array.from({length:20},(s,l)=>({left:(l*37+13)%100,top:(l*23+7)%60,delay:l*.1%2,duration:1+l*.05%1,size:24+l*3%24,colorClass:["text-yellow-400","text-pink-400","text-blue-400","text-green-400","text-purple-400"][l%5]})),pa=Array.from({length:15},(s,l)=>({left:(l*41+19)%100,top:(l*29+11)%70,delay:l*.1%1.5,duration:.5+l*.03%.5,size:16+l*2%16,colorClass:["text-yellow-300","text-orange-400","text-red-400","text-cyan-400"][l%4]})),ja=a.memo(function({totalWords:l,onRestart:g,onFinish:m}){return e.jsxs("div",{className:"fixed inset-0 bg-background/95 backdrop-blur-sm z-[60] flex items-center justify-center",children:[e.jsxs("div",{className:"absolute inset-0 overflow-hidden pointer-events-none",children:[fa.map((h,N)=>e.jsx("div",{className:"absolute animate-ping",style:{left:`${h.left}%`,top:`${h.top}%`,animationDelay:`${h.delay}s`,animationDuration:`${h.duration}s`},children:e.jsx(Rs,{size:h.size,weight:"fill",className:h.colorClass})},N)),pa.map((h,N)=>e.jsx("div",{className:"absolute animate-bounce",style:{left:`${h.left}%`,top:`${h.top}%`,animationDelay:`${h.delay}s`,animationDuration:`${h.duration}s`},children:e.jsx(_e,{size:h.size,weight:"fill",className:h.colorClass})},`star-${N}`))]}),e.jsxs("div",{className:"relative z-10 text-center space-y-6 p-8 max-w-md mx-4",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"w-24 h-24 rounded-full bg-gradient-to-br from-yellow-400 to-grass-30 flex items-center justify-center animate-pulse shadow-2xl",children:e.jsx(ts,{size:48,weight:"fill",className:"text-white"})})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-3xl font-bold text-foreground",children:"🎉 Đã ôn xong!"}),e.jsxs("p",{className:"text-lg text-gray-600",children:["Bạn đã hoàn thành ôn tập ",l," từ vựng"]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 justify-center pt-4",children:[e.jsxs(v,{variant:"outline",size:"lg",onClick:g,className:"gap-2",children:[e.jsx(as,{size:20}),"Ôn lại từ đầu"]}),e.jsxs(v,{size:"lg",onClick:m,className:"gap-2 bg-gradient-to-r from-grass-9 to-grass-10 hover:from-grass-10 hover:to-grass-11",children:[e.jsx(ns,{size:20,weight:"fill"}),"Hoàn tất"]})]})]})]})}),Na=a.memo(function({cards:l,cardIndex:g,flipped:m,masteredCards:h,title:N,isLoggedIn:T,onClose:k,onFlip:z,onPrevious:A,onNext:f,onMarkLearning:w,onMarkMastered:p,onAdvanceOrComplete:J,onOpenDetail:n}){var I,K;const{play:y,isLoading:u}=ls(),c=l[g],_=i=>{if(!(c!=null&&c.word))return i;const b=c.word,se=b.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),D=`${se}(?:s|es|ed|d|ing|er|est|ly|ment|ness|tion|ful|less|able|ible)?`;let ae=`\\b(${D})\\b`;if(/[^aeiou]y$/i.test(b)){const Y=se.slice(0,-1);ae=`\\b(${D}|${Y}(?:ied|ies|ier|iest))\\b`}else if(/e$/i.test(b)){const Y=se.slice(0,-1);ae=`\\b(${D}|${Y}(?:ing|ed|er|est|ation))\\b`}const F=new RegExp(ae,"gi"),ee=i.split(F);return ee.length===1?i:ee.map((Y,o)=>F.test(Y)?(F.lastIndex=0,e.jsx("strong",{className:"font-black text-foreground",children:Y},o)):Y)},W=l.length,q=(h||[]).filter(i=>l.some(b=>b.id===i)).length,Q=g===0,O=g===W-1;a.useEffect(()=>{if(c){Ss(c.audioUrl);for(let i=1;i<=2;i++){const b=l[g+i];b!=null&&b.audioUrl&&Ss(b.audioUrl)}}},[g,l,c]);const Z=async()=>
1{if(qs(),T)try{await w(c.id)?P.success("Đã chuyển từ đã thuộc về đang học! 📚"):P.success("Đã thêm vào đang học! 📚")}catch(i){console.error("Error updating flashcard progress:",i)}J(O)},R=async()=>{if(Is("success"),T)try{await p(c.id),P.success("Đã đánh dấu thành thạo! 🎉")}catch(i){console.error("Error updating flashcard progress:",i)}J(O)};return e.jsxs("div",{className:"fixed inset-0 bg-background/95 backdrop-blur-sm z-[60] flex flex-col safe-top overflow-hidden",children:[e.jsx("div",{className:"flex-shrink-0 container mx-auto px-4 sm:px-6 lg:px-12 py-4",children:e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(v,{variant:"ghost",size:"icon",onClick:k,className:"rounded-full",children:e.jsx($e,{size:24})}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-xl font-bold",children:["Flashcard - ",N]}),e.jsxs("p",{className:"text-sm text-gray-600",children:[g+1," / ",W]})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(ce,{variant:"outline",children:[q," / ",W," đã thuộc"]})})]})}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto flex flex-col items-center justify-center py-4 pb-32",children:e.jsx("div",{className:"w-full max-w-xl px-4 flex-1 flex flex-col justify-center min-h-[400px]",children:e.jsx("div",{className:"relative w-full h-[60vh] min-h-[400px] max-h-[520px] cursor-pointer shrink-0",style:{perspective:"1000px"},onClick:()=>{Ut(),z()},children:e.jsxs("div",{className:"relative w-full h-full transition-transform duration-500",style:{transformStyle:"preserve-3d",transform:m?"rotateY(180deg)":"rotateY(0deg)"},children:[e.jsx(ie,{className:"absolute inset-0 backface-hidden flex items-center justify-center p-8 bg-gradient-to-br from-primary/10 to-accent/20 border-2",style:{backfaceVisibility:"hidden"},children:e.jsxs("div",{className:"w-full space-y-6 text-center",children:[e.jsx("h3",{className:"text-[46px] font-bold text-foreground",children:c.word}),c.pronunciation&&e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx(Xe,{isLoading:u(c.audioUrl,c.word),onClick:i=>{i.stopPropagation(),y(c.word,c.audioUrl)},size:20,buttonClassName:"h-8 w-8"}),e.jsx("span",{className:"text-sm text-gray-600",children:c.pronunciation})]}),c.imageUrl&&e.jsx("div",{className:"mx-auto w-32 h-32 rounded-xl overflow-hidden border bg-muted/30 shadow-sm",children:e.jsx("img",{src:c.imageUrl,alt:c.word,className:"w-full h-full object-cover"})}),e.jsx("p",{className:"text-sm text-gray-600",children:"Nhấn để xem nghĩa"})]})}),e.jsxs(ie,{className:"absolute inset-0 backface-hidden flex items-center justify-center p-8 bg-gradient-to-br from-accent/10 to-secondary/20 border-2",style:{transform:"rotateY(180deg)",backfaceVisibility:"hidden"},children:[n&&e.jsx(v,{variant:"ghost",size:"icon",onClick:i=>{i.stopPropagation(),n(c.id)},className:"absolute top-3 right-3 h-7 w-7 rounded-full text-muted-foreground hover:text-primary hover:bg-primary/10 z-10",title:"Xem chi tiết",children:e.jsx(Dt,{className:"w-4 h-4"})}),e.jsxs("div",{className:"w-full space-y-4 overflow-y-auto max-h-full",children:[e.jsxs("div",{className:"text-center space-y-2",children:[c.partOfSpeech&&e.jsx("span",{className:"inline-block px-2.5 py-0.5 text-xs font-medium rounded-full bg-primary/10 text-primary border border-primary/20",children:c.partOfSpeech}),e.jsx("p",{className:"text-3xl font-bold text-primary",children:((I=c.customMeaning)==null?void 0:I.meaning_vi)||c.translation}),e.jsx("p",{className:"text-lg text-gray-600",children:((K=c.customMeaning)==null?void 0:K.meaning_en)||c.definition})]}),c.examples&&c.examples.length>0&&(()=>{var ae,F,ee,Y;const i=(ae=c.customMeaning)==null?void 0:ae.example_en,b=(F=c.customMeaning)==null?void 0:F.example_vi;if(i||b){const o=(i==null?void 0:i.split(`
2`).filter(Boolean))||[],L=(b==null?void 0:b.split(`
3`).filter(Boolean))||[],B=Math.max(o.length,L.length,1);return e.jsxs("div",{className:"space-y-2 pt-4 border-t",children:[e.jsx("h4",{className:"font-semibold text-center",children:"Ví dụ:"}),Array.from({length:Math.min(B,2)}).map((M,V)=>e.jsxs("div",{className:"space-y-1",children:[o[V]&&e.jsx("p",{className:"text-sm text-gray-600 italic line-clamp-3",children:_(o[V])}),L[V]&&e.jsx("p",{className:"text-sm text-gray-600/70 line-clamp-2",children:L[V]})]},V))]})}const D=(((ee=c.definition)==null?void 0:ee.length)||0)+(((Y=c.translation)==null?void 0:Y.length)||0)>80?1:2;return e.jsxs("div",{className:"space-y-2 pt-4 border-t",children:[e.jsx("h4",{className:"font-semibold text-center",children:"Ví dụ:"}),c.examples.slice(0,D).map((o,L)=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm text-gray-600 italic line-clamp-3",children:_(o.sentence||o.english||"")}),e.jsx("p",{className:"text-sm text-gray-600/70 line-clamp-2",children:o.translation||o.vietnamese})]},L))]})})(),e.jsx("p",{className:"text-sm text-gray-600 text-center",children:"Nhấn để quay lại"})]})]})]})})})}),e.jsx("div",{className:"absolute bottom-0 left-0 right-0 border-t bg-background/95 backdrop-blur-sm safe-area-bottom z-10",children:e.jsx("div",{className:"container mx-auto px-4 sm:px-6 lg:px-12 py-3 sm:py-4 pb-4",children:e.jsxs("div",{className:"flex items-center justify-between gap-2 sm:gap-4 max-w-2xl mx-auto",children:[e.jsxs(v,{variant:"outline",size:"lg",onClick:A,disabled:Q,className:"flex-shrink-0 sm:flex-1 sm:max-w-[200px] px-3 sm:px-6",children:[e.jsx("span",{className:"hidden sm:inline",children:"← Trước"}),e.jsx("span",{className:"sm:hidden",children:"←"})]}),e.jsxs("div",{className:"flex gap-2 flex-1 justify-center",children:[e.jsxs(v,{variant:"outline",size:"lg",onClick:Z,className:"bg-warning/10 border-warning hover:bg-warning/20 flex-1 sm:flex-none px-3 sm:px-6",children:[e.jsx(He,{size:20,weight:"fill",className:"mr-1 sm:mr-2"}),e.jsx("span",{className:"text-xs sm:text-sm",children:"Đang học"})]}),e.jsxs(v,{variant:"outline",size:"lg",onClick:R,className:"bg-success/10 border-success hover:bg-success/20 flex-1 sm:flex-none px-3 sm:px-6",children:[e.jsx(ns,{size:20,weight:"fill",className:"mr-1 sm:mr-2"}),e.jsx("span",{className:"text-xs sm:text-sm",children:"Đã thuộc"})]})]}),e.jsxs(v,{variant:"outline",size:"lg",onClick:f,disabled:O,className:"flex-shrink-0 sm:flex-1 sm:max-w-[200px] px-3 sm:px-6",children:[e.jsx("span",{className:"hidden sm:inline",children:"Sau →"}),e.jsx("span",{className:"sm:hidden",children:"→"})]})]})})})]})});function va(){const{user:s}=Vt(),{updateProgress:l,resetToLearning:g,getDueWords:m,getEarlyReviewWords:h,earlyReview:N,getMasteredCards:T,getLearningCards:k,loading:z,progress:A,masteredCards:f,learningCards:w}=ea(),{notebooks:p,createNotebook:J,addWordToNotebook:n,addWordsToNotebook:y,removeWordFromNotebook:u,deleteNotebook:c,updateNotebook:_,loadNotebookWords:W,notebookVersion:q,loading:Q}=Pt(),{topics:O,topicTree:Z,parentTopics:R,topicsWithWords:I,loading:K,loadTopicWords:i,getChildTopics:b,getTopicLevel:se}=Ns(),[D,ae]=a.useState(new Map),[F,ee]=a.useState(null),[Y,o]=a.use
3State(null),[L,B]=a.useState(null),[M,V]=a.useState("all"),{words:E,loading:H,totalCount:X,searchWords:ve,appendWords:re,loadWordsByIds:me}=Ys(M==="all"?void 0:M),[fe,be]=a.useState([]),[ue,Se]=a.useState(!1),[d,t]=a.useState(0),[x,S]=a.useState(!1),[j,G]=a.useState(""),[U,le]=a.useState(null),[xe,ge]=a.useState(!1),[Me,We]=a.useState(!1),[rs,Te]=a.useState(0),[Ee,Fe]=a.useState(null),[Ae,cs]=a.useState(null),[Ie,os]=a.useState(!1),[Le,ds]=a.useState(null),[ye,C]=a.useState(15),[te,ze]=a.useState(1),[Oe,xs]=a.useState("toeic-1"),[et,vs]=a.useState(0),[ms,st]=a.useState(null),[tt,at]=a.useState(!1),[nt,ys]=a.useState(0),oe=a.useMemo(()=>{if(E.length>0){const r=E[0];console.log("🔍 [DEBUG] First vocabulary row keys:",Object.keys(r)),console.log("🔍 [DEBUG] First row difficulty:",r.difficulty,"| word:",r.word)}return E.map(r=>{const $=ke(r);return!$.cefr&&r.difficulty&&console.warn("⚠️ [DEBUG] cefr not set despite difficulty:",r.difficulty,r.word),$})},[E]),pe=a.useMemo(()=>Ae&&(p||[]).find(r=>r.id===Ae)||null,[Ae,p]),[hs,us]=a.useState([]);a.useEffect(()=>{if(!pe||pe.word_ids.length===0){us([]);return}W(pe.id).then(r=>{const $=r.map(de=>ke(de));us($),r.length>0&&re(r)}).catch(r=>{console.error("Failed to load notebook words:",r),us([])})},[pe==null?void 0:pe.id,pe==null?void 0:pe.word_ids.length,q,W,re]),a.useEffect(()=>{if(!p||p.length===0||E.length===0)return;const r=new Set(E.map(he=>String(he.id))),$=p.flatMap(he=>he.word_ids||[]),de=[...new Set($)].filter(he=>!r.has(String(he)));de.length!==0&&(console.log(`📖 Loading ${de.length} missing words for notebook counts...`),me(de).then(he=>{he.length>0&&re(he)}))},[p,E,me,re]);const qe=a.useMemo(()=>{if(!p||p.length===0)return[];const r=p.flatMap($=>$.word_ids||[]);return[...new Set(r)]},[p]),it=a.useMemo(()=>{const r=qe.length,$=qe.filter(ne=>(f||[]).includes(ne)).length,de=qe.filter(ne=>(w||[]).includes(ne)).length,he=r-$-de;return{total:r,mastered:$,learning:de,notLearned:he}},[qe,f,w]),we=oe[d||0],lt=a.useMemo(()=>U&&oe.find(r=>r.id===U)||null,[U,oe]),rt=a.useMemo(()=>I.length>0?I.map(r=>r.name):Array.from(new Set(oe.map(r=>r.topic).filter(r=>r!=null&&r!==""))),[I,oe]),Re=a.useMemo(()=>Ee?Ee.cards:pe?hs:M==="all"?oe:oe.filter(r=>r.topic===M),[Ee,M,pe,hs,oe]),ct=Math.ceil(Re.length/(ye||15)),De=a.useMemo(()=>{const r=(te-1)*(ye||15),$=r+(ye||15);return Re.slice(r,$)},[Re,te,ye]),bs=a.useMemo(()=>new Map(oe.map(r=>[r.id,r])),[oe]),ot=a.useMemo(()=>{if(!j||j.trim().length===0)return[];const r=j.toLowerCase();if(fe.length>0)return fe.map(ne=>{const je=bs.get(ne.id);return je||ke(ne)});const $=oe.filter(ne=>ne.word.toLowerCase().includes(r)||ne.translation.toLowerCase().includes(r)||ne.definition.toLowerCase().includes(r)),de=ne=>{const je=ne.word.toLowerCase(),Pe=ne.translation.toLowerCase(),Ge=ne.definition.toLowerCase();return je===r?0:je.startsWith(r)?1:je.includes(r)?2:Pe.includes(r)?3:Ge.includes(r)?4:5};return $.sort((ne,je)=>{const Pe=de(ne),Ge=de(je);return Pe!==Ge?Pe-Ge:ne.word.toLowerCase().localeCompare(je.word.toLowerCase())})},[j,oe,fe,bs]);a.useEffect(()=>{if(!j||j.length<1){be([]);return}const r=setTimeout(async()=>{Se(!0);try{const $=await ve(j);be($),$.length>0&&re($)}catch($){console.error("Async search error:",$)}finally{Se(!1)}},500);return()=>clearTimeout(r)},[j,ve,re]);const dt=oe.length>0?(f||[]).length/oe.length*100:0,xt=a.useMemo(()=>{const r={};return oe.forEach($=>{r[$.topic]||(r[$.topic]={total:0,mastered:0,learning:0}),r[$.topic].total++,(f||[]).includes($.id)?r[$.topic].mastered++:(w||[]).includes($.id)&&r[$.topic].learning++}),r},[oe,f,w]);a.useEffect(()=>{window.scrollTo({top:0,behavior:"instant"})},[]),a.useEffect(()=>{ze(1)},[M,ye]),a.useEffect(()=>{Me&&Te(0)},[Me]),a.useEffect(()=>{(async()=>{if(!s)return;const $=await h(50,ms);vs($.length)})()},[s,h,ms]),a.useEffect(()=>{(async()=>{if(!s)return;const $=await m(50);ys($.length)})()},[s,m]);const Ke=a.useCallback(()=>{S(!1),t((r=0)=>(r+1)%De.length)}
3,[De.length]),mt=a.useCallback(()=>{S(!1),t((r=0)=>(r-1+De.length)%De.length)},[De.length]),ht=a.useCallback(async()=>{if(we){if(!f.includes(we.id)&&s)try{await l(we.id,!0),P.success("Đã đánh dấu thành thạo! 🎉")}catch(r){console.error("Error updating flashcard progress:",r)}Ke()}},[we,f,s,l,Ke]),ut=a.useCallback(async()=>{if(we){if(!w.includes(we.id)&&s)try{await l(we.id,!1),P.success("Đã thêm vào danh sách đang học! 📚")}catch(r){console.error("Error updating flashcard progress:",r)}Ke()}},[we,w,s,l,Ke]),gt=a.useCallback(()=>{S(r=>!r)},[]),ft=a.useCallback(r=>{le(r),ge(!0)},[]),pt=a.useCallback(()=>{ge(!1),le(null)},[]),jt=a.useCallback((r,$)=>{r&&$&&Fe({cards:r,title:$}),We(!0),Te(0)},[]),Nt=a.useCallback(()=>{We(!1),S(!1),Fe(null)},[]),vt=a.useCallback(()=>{S(!1),Te(r=>Math.min(Re.length-1,r+1))},[Re.length]),yt=a.useCallback(()=>{S(!1),Te(r=>Math.max(0,r-1))},[]),bt=a.useCallback(r=>{cs(r)},[]),wt=a.useCallback(async r=>{const $=D.get(r);if($)return $;ee(r);try{const de=await i(r),he=de.map(ne=>ke(ne));return ae(ne=>{const je=new Map(ne);return je.set(r,he),je}),de.length>0&&re(de),he}catch(de){return console.error("Failed to load topic words:",de),[]}finally{ee(null)}},[D,i,re]),kt=a.useCallback(r=>D.get(r)||[],[D]);return{user:s,vocabularyLoading:H,progressLoading:z,notebooksLoading:Q,isSearching:ue,mockFlashcards:oe,filteredCards:De,filteredByTopic:Re,searchFilteredCards:ot,currentCard:we,selectedFlashcard:lt,topics:rt,categoryStats:xt,progress:dt,flashcardProgressData:A,totalPages:ct,vocabularyTotalCount:X,dbTopics:O,dbTopicTree:Z,dbParentTopics:R,dbTopicsWithWords:I,topicsLoading:K,topicWordsLoading:F,loadWordsForTopic:wt,getTopicWords:kt,getChildTopics:b,getTopicLevel:se,selectedParentTopic:Y,setSelectedParentTopic:o,selectedLevel2Topic:L,setSelectedLevel2Topic:B,notebooks:p,selectedNotebook:pe,selectedNotebookWords:hs,selectedNotebookId:Ae,allNotebookWordIds:qe,notebookLearningStats:it,selectNotebook:bt,createNotebook:J,addWordToNotebook:n,addWordsToNotebook:y,removeWordFromNotebook:u,deleteNotebook:c,updateNotebook:_,masteredCards:f,learningCards:w,updateProgress:l,resetToLearning:g,getDueWords:m,getEarlyReviewWords:h,earlyReview:N,getMasteredCards:T,getLearningCards:k,currentIndex:d,setCurrentIndex:t,flipped:x,setFlipped:S,toggleFlip:gt,searchQuery:j,setSearchQuery:G,selectedCard:U,setSelectedCard:le,
3isModalOpen:xe,setIsModalOpen:ge,openCardModal:ft,closeCardModal:pt,showFlashcardView:Me,setShowFlashcardView:We,flashcardIndex:rs,setFlashcardIndex:Te,flashcardViewData:Ee,setFlashcardViewData:Fe,openFlashcardView:jt,closeFlashcardView:Nt,nextFlashcard:vt,prevFlashcard:yt,showCompletionCelebration:Ie,setShowCompletionCelebration:os,selectedTopic:M,setSelectedTopic:V,selectedCategory:Le,setSelectedCategory:ds,displayCount:ye,setDisplayCount:C,currentPage:te,setCurrentPage:ze,selectedFlashcardSet:Oe,setSelectedFlashcardSet:xs,earlyReviewCount:et,setEarlyReviewCount:vs,earlyReviewDays:ms,setEarlyReviewDays:st,showEarlyReviewSettings:tt,setShowEarlyReviewSettings:at,dueWordCount:nt,setDueWordCount:ys,handleNext:Ke,handlePrevious:mt,handleMastered:ht,handleLearning:ut}}function ya({searchQuery:s,setSearchQuery:l,isSearching:g,searchFilteredCards:m,masteredCards:h,learningCards:N,notebooks:T,createNotebook:k,addWordToNotebook:z,setSelectedCard:A,setIsModalOpen:f}){const{play:w,isLoading:p}=ls(),J=a.useRef(null);return a.useEffect(()=>{function n(y){const u=y.target;u instanceof HTMLElement&&u.closest('[data-radix-portal], [role="dialog"], [data-radix-dialog-overlay]')||J.current&&!J.current.contains(u)&&s&&l("")}if(s)return document.addEventListener("mousedown",n),()=>{document.removeEventListener("mousedown",n)}},[s,l]),e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"bg-muted/30 border-b",children:e.jsx("div",{className:"container mx-auto px-4 sm:px-6 lg:px-12 py-6",children:e.jsx("div",{className:"max-w-2xl mx-auto space-y-3",children:e.jsxs("div",{className:"relative",children:[e.jsx(Ye,{size:20,className:`absolute left-4 top-1/2 -translate-y-1/2 text-gray-600 transition-all ${s?"animate-pulse text-primary":""}`}),e.jsx(ss,{placeholder:"Tra từ ...",value:s,onChange:n=>l(n.target.value),className:"pl-12 pr-24 h-12 text-base bg-background rounded-full border-2 focus-visible:ring-offset-0"}),e.jsxs("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-1",children:[s&&e.jsx(v,{size:"icon",variant:"ghost",className:"rounded-full h-8 w-8",onClick:()=>l(""),children:e.jsx($e,{size:18})}),e.jsx(v,{size:"icon",variant:"ghost",className:"rounded-full h-8 w-8",children:e.jsx(Bt,{size:20})})]})]})})})}),s&&e.jsx("div",{className:"container mx-auto px-4 sm:px-6 lg:px-12 py-6",children:e.jsx("div",{className:"max-w-7xl mx-auto",ref:J,children:e.jsx(ie,{className:"p-0 overflow-hidden border-2 shadow-xl",children:e.jsxs("div",{className:"max-h-[calc(100vh-200px)] overflow-y-auto",children:[g&&m.length===0&&e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto"}),e.jsx("p",{className:"text-sm text-gray-600",children:"Đang tìm kiếm..."})]})}),g&&m.length>0&&e.jsxs("div",{className:"flex items-center gap-2 px-4 sm:px-6 py-2 bg-muted/20 border-b text-xs text-muted-foreground",children:[e.jsx("div",{className:"animate-spin rounded-full h-3 w-3 border-b-2 border-primary"}),e.jsx("span",{children:"Đang cập nhật kết quả..."})]}),m.map(n=>{const y=(h||[]).includes(n.id),u=(N||[]).includes(n.id);return e.jsx("div",{className:"border-b last:border-b-0 hover:bg-muted/30 transition-colors",children:e.jsxs("div",{className:"px-4 sm:px-6 py-5 space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex flex-col items-center gap-1",children:y?e.jsx(ns,{size:20,weight:"fill",className:"text-success"}):u?e.jsx(He,{size:20,weight:"fill",className:"text-warning"}):e.jsx("div",{className:"w-5 h-5 rounded-full border-2 border-muted-foreground/30"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-lg font-bold text-success mb-1",children:n.word}),(n.partOfSpeech||n.pronunciation)&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap mb-2",children:[n.partOfSpeech&&e.jsx(ce,{variant:"outline",className:"bg-purple-50 text-purple-700 border-purple-200 text-xs px-2 py-0.5 font-medium italic",children:n.partOfSpeech}),n.pronunciation&&e.jsxs(e.Fragment,{children:[e.jsx(ce,{variant:"secondary",className:"bg-grass-4 text-foreground border border-grass-6 text-xs px-2 py-0.5 font-semibold",children:"NAmE"}),e.jsx(Xe,{isLoading:p(n.audioUrl,n.word),onClick:c=>{c.stopPropagation(),w(n.word,n.audioUrl)},size:16,iconWeight:"regular"}),e.jsx("span",{className:"text-sm text-foreground",children:n.pronunciation})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ce,{className:`${n.cefr==="A1"||n.cefr==="A2"?"bg-grass-4 text-foreground border-grass-6":n.cefr==="B1"?"bg-yellow-100 text-yellow-800 border-yellow-300":n.cefr==="B2"?"bg-grass-4 text-foreground border-grass-6":n.cefr==="C1"||n.cefr==="C2"?"bg-red-100 text-red-800 border-red-300":"bg-gray-100 text-gray-600 border-gray-300"} border font-semibold px-2 py-0.5 text-xs flex-shrink-0`,children:n.cefr||"—"}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:n.definition})]})]})]}),e.jsxs("div",{className:"pl-8 space-y-2",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("div",{className:"w-5 h-5 rounded bg-red-500 flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx(_e,{size:12,weight:"fill",className:"text-yellow-400"})}),e.jsx("div",{className:"flex-1",children:e.jsxs("div",{className:"flex items-center flex-wrap gap-2",children:[e.jsx("span",{className:"text-sm",children:n.translation}),n.vietnameseMeanings&&n.vietnameseMeanings.length>1&&e.jsxs(Gt,{className:"contents",children:[e.jsx(Qt,{asChild:!0,children:e.jsxs(v,{variant:"ghost",className:"text-xs text-gray-600 hover:text-foreground h-auto p-0 px-2 py-0.5 border border-border/50 gap-1",onClick:c=>c.stopPropagation(),children:["Nghĩa khác",e.jsx(Ze,{size:12,className:"transition-transform data-[state=open]:rotate-180"})]})}),e.jsx(Yt,{className:"w-full",children:e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:n.vietnameseMeanings.slice(1).map((c,_)=>e.jsx(ce,{variant:"outline",className:"text-xs bg-muted/50 hover:bg-muted cursor-pointer",onClick:W=>{W.stopPropagation(),A(n.id),f(!0)},children:c},_))})})]})]})})]}),n.examples&&n.examples.length>0&&e.jsxs("div",{className:"space-y-1.5 pt-2",children:[e.jsx("h4",{className:"text-xs font-semibold text-foreground",children:"Ví dụ"}),n.examples.slice(0,2).map((c,_)=>e.jsxs("div",{className:"flex items-start gap-1.5 text-sm",children:[e.jsx("span",{className:"text-gray-600 mt-0.5",children:"•"}),e.jsx("div",{className:"flex-1",children:e.jsx("p",{className:"text-foreground
3/90",children:c.sentence.split(new RegExp(`(${n.word})`,"gi")).map((W,q)=>W.toLowerCase()===n.word.toLowerCase()?e.jsx("span",{className:"text-success font-semibold underline",children:W},q):e.jsx("span",{children:W},q))})})]},_))]}),n.synonyms&&n.synonyms.length>0&&e.jsxs("div",{className:"pt-2",children:[e.jsx("h4",{className:"text-xs font-semibold text-foreground mb-1",children:"Từ đồng nghĩa"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:n.synonyms.slice(0,4).map((c,_)=>e.jsx(ce,{variant:"outline",className:"text-xs",children:c},_))})]}),n.antonyms&&n.antonyms.length>0&&e.jsxs("div",{className:"pt-2",children:[e.jsx("h4",{className:"text-xs font-semibold text-foreground mb-1",children:"Từ trái nghĩa"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:n.antonyms.slice(0,4).map((c,_)=>e.jsx(ce,{variant:"outline",className:"text-xs",children:c},_))})]}),e.jsxs("div",{className:"flex items-center gap-4 pt-1",children:[e.jsx(Jt,{wordId:n.id,wordText:n.word,notebooks:T,onCreateNotebook:k,onAddWordToNotebook:z}),e.jsxs(v,{variant:"link",className:"text-success gap-1 h-auto p-0 text-xs",onClick:()=>{A(n.id),f(!0)},children:["Xem chi tiết",e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"12",height:"12",fill:"currentColor",viewBox:"0 0 256 256",children:e.jsx("path",{d:"M184.49,136.49l-80,80a12,12,0,0,1-17-17L159,128,87.51,56.49a12,12,0,1,1,17-17l80,80A12,12,0,0,1,184.49,136.49Z"})})]})]})]})]})},n.id)}),!g&&m.length===0&&e.jsx("p",{className:"text-center text-gray-600 py-12 text-sm",children:"Không tìm thấy từ vựng nào"})]})})})})]})}function ba({onStartQuiz:s,isPremium:l=!1}){const[g,m]=Ue.useState(!1),[h,N]=Ue.useState("all"),[T,k]=Ue.useState(10),[z,A]=Ue.useState("classic"),{topicTree:f,loading:w}=Ns(),p=n=>{if(n==="all")return"Tất cả";for(const y of f){if(y.id===n)return y.name_vi||y.name;for(const u of y.children){if(u.id===n)return u.name_vi||u.name;for(const c of u.children)if(c.id===n)return c.name_vi||c.name}}return"Tất cả"},J=()=>{s({topic:h==="all"?"all":p(h),topicId:h==="all"?void 0:h,questionCount:T,questionTypes:[],gameMode:z}),m(!1)};return e.jsxs(Ks,{open:g,onOpenChange:m,children:[e.jsx(Us,{asChild:!0,children:e.jsxs(v,{className:"h-11 w-11 p-0 sm:w-auto sm:h-auto sm:px-4 sm:py-2 sm:gap-2 sm:flex-1",size:"lg",children:[e.jsx(ps,{className:"w-5 h-5 shrink-0"}),e.jsx("span",{className:"hidden sm:inline",children:"Tuỳ Chỉnh Quiz"})]})}),e.jsxs(Vs,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(Hs,{children:[e.jsxs(Xs,{className:"text-2xl flex items-center gap-2",children:[e.jsx(ps,{className:"w-6 h-6 text-primary"}),"Cài Đặt Quiz"]}),e.jsx(Ps,{children:"Tuỳ chỉnh quiz theo nhu cầu học tập của bạn"})]}),e.jsxs("div",{className:"space-y-6 py-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(Ve,{htmlFor:"topic",className:"text-base font-semibold",children:"Chủ Đề"}),e.jsxs(zs,{value:h,onValueChange:N,children:[e.jsx(Ts,{id:"topic",className:"h-11 w-full",children:e.jsx($s,{placeholder:"Chọn chủ đề"})}),e.jsxs(_s,{className:"max-h-[40vh] z-[10002] max-w-[calc(100vw-3rem)] overflow-y-auto touch-pan-y",position:"popper",side:"bottom",align:"start",children:[e.jsx(Ne,{value:"all",children:"Tất cả chủ đề"}),w?e.jsx(Ne,{value:"_loading",disabled:!0,children:"Đang tải..."}):f.map(n=>e.jsxs(sa,{children:[e.jsxs(Ms,{className:"font-semibold text-foreground",children:[n.name_vi||n.name,n.total_word_count>0&&e.jsxs("span",{className:"text-muted-foreground font-normal ml-1",children:["(",n.total_word_count," từ)"]})]}),n.word_count>0&&e.jsxs(Ne,{value:n.id,children:[n.name_vi||n.name," (",n.word_count," từ)"]}),n.children.map(y=>e.jsxs(Ue.Fragment,{children:[y.word_count>0?e.jsxs(Ne,{value:y.id,className:"pl-4",children:[y.name_vi||y.name," (",y.word_count," từ)"]}):y.total_word_count>0&&y.children&&y.children.length>0?e.jsx(Ms,{className:"pl-4 text-xs text-muted-foreground",children:y.name_vi||y.name}):null,(y.children||[]).filter(u=>u.word_count>0).map((u,c)=>{const _=!l&&c>=3;return e.jsx(Ne,{value:u.id,className:`pl-6 ${_?"opacity-50":""}`,disabled:_,children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[_&&e.jsx(Be,{size:12,weight:"fill",className:"text-amber-500 flex-shrink-0"}),u.name_vi||u.name," (",u.word_count," từ)"]})},u.id)})]},y.id))]},n.id))]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(Ve,{htmlFor:"count",className:"text-base font-semibold",children:"Số Câu Hỏi"}),e.jsxs(zs,{value:T.toString(),onValueChange:n=>k(parseInt(n)),children:[e.jsx(Ts,{id:"count",className:"h-11 w-full",children:e.jsx($s,{placeholder:"Số câu hỏi"})}),e.jsxs(_s,{className:"z-[10002]",children:[e.jsx(Ne,{value:"5",children:"5 câu"}),e.jsx(Ne,{value:"10",children:"10 câu"}),e.jsx(Ne,{value:"15",children:"15 câu"}),e.jsx(Ne,{value:"20",children:"20 câu"}),e.jsx(Ne,{value:"30",children:"30 câu"}),e.jsx(Ne,{value:"50",children:"50 câu"})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(Ve,{className:"text-base font-semibold",children:"Dạng Bài"}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:Zt.map(n=>e.jsx(ie,{className:`p-4 cursor-pointer transition-all hover:shadow-md ${z===n.id?"border-2 border-primary bg-primary/5 shadow-md":"border-2 border-transparent"}`,onClick:()=>A(n.id),children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx(n.icon,{className:`w-6 h-6 ${n.iconColor}`,weight:"duotone"}),z===n.id&&e.jsx(ce,{variant:"default",className:"text-[10px] px-1.5 py-0",children:"Đã chọn"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground text-sm",children:n.titleVi}),e.jsx("div",{className:"text-[11px] text-muted-foreground mt-0.5 leading-relaxed",children:n.description})]})]})},n.id))})]}),e.jsxs("div",{className:"flex gap-3 pt-4",children:[e.jsx(v,{variant:"outline",onClick:()=>m(!1),className:"flex-1",children:"Huỷ"}),e.jsxs(v,{onClick:J,className:"flex-1 gap-2",children:[e.jsx(Ds,{className:"w-4 h-4"}),"Bắt Đầu Quiz"]})]})]})]})]})}function js({trigger:s,onCreateNotebook:l}){const[g,m]=a.useState(!1),[h,N]=a.useState(""),[T,k]=a.useState(""),[z,A]=a.useState(!1),f=async()=>
3{if(!h.trim()){P.error("Vui lòng nhập tên sổ từ vựng");return}A(!0);try{await l(h.trim(),T.trim()||void 0),N(""),k(""),m(!1)}catch(p){console.error("Error creating notebook:",p)}finally{A(!1)}},w=p=>{p||(N(""),k("")),m(p)};return e.jsxs(Ks,{open:g,onOpenChange:w,children:[e.jsx(Us,{asChild:!0,children:s||e.jsxs(v,{size:"sm",variant:"outline",className:"gap-2",children:[e.jsx(Je,{size:16}),"Tạo sổ mới"]})}),e.jsxs(Vs,{className:"sm:max-w-[500px]",children:[e.jsxs(Hs,{children:[e.jsxs(Xs,{className:"flex items-center gap-2",children:[e.jsx(Wt,{size:24,weight:"duotone",className:"text-primary"}),"Tạo sổ từ vựng mới"]}),e.jsx(Ps,{children:"Tạo sổ từ vựng để tổ chức và quản lý các từ bạn muốn học"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Ve,{htmlFor:"notebook-name",children:["Tên sổ từ vựng ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ss,{id:"notebook-name",placeholder:"Ví dụ: Từ vựng Business, TOEIC Part 5, Idioms...",value:h,onChange:p=>N(p.target.value),onKeyDown:p=>{p.key==="Enter"&&!p.shiftKey&&(p.preventDefault(),f())},autoFocus:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ve,{htmlFor:"notebook-description",children:"Mô tả (tùy chọn)"}),e.jsx(Qs,{id:"notebook-description",placeholder:"Mô tả ngắn về sổ từ vựng này...",value:T,onChange:p=>k(p.target.value),rows:3,className:"resize-none"})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx(v,{type:"button",variant:"outline",className:"flex-1",onClick:()=>w(!1),disabled:z,children:"Hủy"}),e.jsxs(v,{type:"button",className:"flex-1 gap-2",onClick:f,disabled:z||!h.trim(),children:[e.jsx(Je,{size:18,weight:"bold"}),z?"Đang tạo...":"Tạo sổ"]})]})]})]})]})}const wa=50,ka=3;function Ca({stats:s,mockFlashcards:l,masteredCards:g,learningCards:m,notebooks:h,isPremium:N=!1,onNavigate:T,setFlashcardViewData:k,setShowFlashcardView:z,setFlashcardIndex:A,onCardClick:f}){const w=(s==null?void 0:s.mastered)??0,p=(s==null?void 0:s.learning)??0,J=(s==null?void 0:s.notLearned)??0,n=(s==null?void 0:s.total)??0,y=n>0?w/(n||1)*100:0,[u,c]=a.useState(null),{play:_,isLoading:W}=ls(),q=a.useMemo(()=>{if(!h||h.length===0)return[];const i=N?h:h.slice(0,ka);return[...new Set(i.flatMap(b=>N?b.word_ids||[]:(b.word_ids||[]).slice(0,wa)))]},[h,N]),Q=a.useCallback(i=>{if(!l)return[];const b=g||[],se=m||[];let D;switch(i){case"mastered":D=q.filter(F=>b.includes(F));break;case"learning":D=q.filter(F=>se.includes(F));break;case"notLearned":D=q.filter(F=>!b.includes(F)&&!se.includes(F));break}const ae=new Set(D);return l.filter(F=>ae.has(F.id))},[l,g,m,q]),O=a.useMemo(()=>u?Q(u):[],[u,Q]),Z={mastered:"Đã thuộc",learning:"Đang học",notLearned:"Chưa học"},R=i=>{l&&c(b=>b===i?null:i)},I=()=>{if(!(!O.length||!k||!z||!A)){if(!N&&T){T("premium");return}k({cards:O,title:Z[u]}),A(0),z(!0)}},K=()=>{if(!(!O.length||!T)){if(!N){T("premium");return}T("vocab-quiz",{questionCount:Math.min(O.length,20),wordIds:O.map(i=>i.id)})}};return e.jsx(ie,{className:"p-4 sm:p-6 bg-gradient-to-r from-primary/10 to-accent/10 border-2",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:"Tiến Độ Học (Sổ Tay)"}),e.jsxs("span",{className:"text-sm font-bold",children:[w,"/",n," từ"]})]}),e.jsx(is,{value:y,className:"h-3"}),e.jsx("div",{className:"grid grid-cols-3 gap-2 sm:gap-4 mt-4",children:[{key:"mastered",value:w,color:"text-primary",bgActive:"bg-primary/10 ring-2 ring-primary/30"},{key:"learning",value:p,color:"text-accent",bgActive:"bg-accent/10 ring-2 ring-accent/30"},{key:"notLearned",value:J,color:"text-gray-600",bgActive:"bg-gray-100 ring-2 ring-gray-300 dark:bg-gray-800 dark:ring-gray-600"}].map(i=>{const b=u===i.key;return e.jsxs("button",{onClick:()=>i.value>0&&R(i.key),disabled:i.value===0,className:`text-center rounded-xl p-2 transition-all ${i.value>0?"cursor-pointer hover:bg-muted/50 active:scale-95":"cursor-default opacity-60"} ${b?i.bgActive:""}`,children:[e.jsx("div",{className:`text-xl sm:text-2xl font-bold ${i.color}`,children:i.value}),e.jsxs("div",{className:"text-xs text-gray-600 flex items-center justify-center gap-0.5",children:[Z[i.key],i.value>
30&&e.jsx(Ze,{size:10,className:`transition-transform ${b?"rotate-180":""}`})]})]},i.key)})}),e.jsx(ta,{children:u&&O.length>0&&e.jsx(aa.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"overflow-hidden",children:e.jsxs("div",{className:"pt-3 border-t space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:[Z[u]," · ",O.length," từ"]}),e.jsxs("div",{className:"flex items-center gap-1",children:[T&&O.length>=4&&e.jsxs(v,{variant:"ghost",size:"sm",className:`h-7 px-2 gap-1 text-xs ${N?"":"opacity-60"}`,onClick:K,children:[e.jsx(ts,{size:14,weight:"duotone"}),"Quiz",!N&&e.jsx(es,{size:12,weight:"fill",className:"text-yellow-500"})]}),k&&e.jsxs(v,{variant:"ghost",size:"sm",className:`h-7 px-2 gap-1 text-xs ${N?"":"opacity-60"}`,onClick:I,children:[e.jsx(as,{size:14,weight:"duotone"}),"Flashcard",!N&&e.jsx(es,{size:12,weight:"fill",className:"text-yellow-500"})]})]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-3 max-h-[34rem] overflow-y-auto pr-1",children:O.map(i=>e.jsx(ie,{className:"p-4 hover:shadow-md transition-all bg-card cursor-pointer",onClick:()=>{if(f)f(i);else if(k&&z&&A){const b=O.findIndex(se=>se.id===i.id);k({cards:O,title:Z[u]}),A(b>=0?b:0),z(!0)}},children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("h4",{className:"text-xl font-bold text-success flex-1",children:i.word}),e.jsxs("div",{className:"flex flex-col items-end gap-1 flex-shrink-0",children:[e.jsx("div",{className:"text-xs text-gray-600",children:u==="mastered"?"100%":u==="learning"?"50%":"0%"}),e.jsx("div",{className:"w-12 h-1 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-success transition-all",style:{width:u==="mastered"?"100%":u==="learning"?"50%":"0%"}})})]})]}),e.jsx("p",{className:"text-sm text-gray-600 italic",children:i.partOfSpeech||""}),i.pronunciation&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Xe,{isLoading:W(i.audioUrl,i.word),onClick:b=>{b.stopPropagation(),_(i.word,i.audioUrl)},size:16}),e.jsx("span",{className:"text-xs text-gray-600",children:i.pronunciation})]}),e.jsx("p",{className:"text-sm leading-relaxed line-clamp-2",children:i.definition}),e.jsxs("div",{className:"flex items-start gap-2 pt-2 border-t",children:[e.jsx("div",{className:"w-5 h-5 rounded bg-red-500 flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx(_e,{size:12,weight:"fill",className:"text-yellow-400"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("span",{className:"text-sm font-medium",children:"Vietnamese:"}),e.jsx("span",{className:"text-sm ml-1",children:i.translation})]})]})]})},i.id))})]})})}),n===0&&e.jsx("p",{className:"text-xs text-gray-500 text-center mt-2",children:"💡 Thêm từ vào Sổ Tay để theo dõi tiến độ học tập"})]})})}const As=3,Qe=50;function Sa({onNavigate:s,user:l,isPremium:g=!1,mockFlashcards:m,masteredCards:h,learningCards:N,notebooks:T,notebookLearningStats:k,selectedNotebookId:z,selectedNotebook:A,selectedNotebookWords:f,selectNotebook:w,createNotebook:p,deleteNotebook:J,setSelectedTopic:n,setFlashcardViewData:y,setShowFlashcardView:u,setFlashcardIndex:c,setFlipped:_,onCardClick:W,earlyReviewCount:q,earlyReviewDays:Q,setEarlyReviewDays:O,showEarlyReviewSettings:Z,setShowEarlyReviewSettings:R,getDueWords:I,getEarlyReviewWords:K,dueWordCount:i,loadWordsByIds:b}){const{confirm:se,ConfirmDialogComponent:D}=Js(),{topicsWithWords:ae,loadTopicWords:F}=Ns(),[ee,Y]=a.useState(!1);return e.jsxs("div",{className:"space-y-6",children:[e.jsx(Ca,{stats:k,mockFlashcards:m,masteredCards:h,learningCards:N,notebooks:T,isPremium:g,onNavigate:s,setFlashcardViewData:y,setShowFlashcardView:u,setFlashcardIndex:c,onCardClick:W}),l&&i>0&&e.jsx(ie,{className:"p-4 sm:p-6 bg-gradient-to-br from-red-50 to-orange-50 dark:from-red-950/30 dark:to-orange-950/30 border-2 border-red-300 dark:border-red-700",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-14 h-14 roun
3ded-full bg-red-100 dark:bg-red-900/50 flex items-center justify-center flex-shrink-0",children:e.jsx(He,{size:28,weight:"fill",className:"text-red-600 dark:text-red-400"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("h3",{className:"font-bold text-lg",children:"Ôn từ tới hạn"})}),e.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1 flex items-center gap-1.5 flex-wrap",children:["Có ",e.jsxs(ce,{variant:"destructive",className:"text-xs px-1.5 py-0",children:[i," từ"]})," cần ôn tập hôm nay. Hãy ôn ngay để không quên!"]})]}),e.jsxs(v,{size:"lg",variant:"destructive",className:"flex-shrink-0",onClick:async()=>{try{const o=await I(20);if(o.length===0){P.info("Không có từ nào cần ôn tập lúc này! ✅");return}const L=o.map(V=>V.word_id),M=(await b(L)).map(V=>ke(V));if(M.length===0){P.info("Không tìm thấy dữ liệu từ vựng!");return}y({cards:M,title:`Ôn từ tới hạn (${M.length} từ)`}),c(0),u(!0),_(!1),P.success(`Đã tải ${M.length} từ cần ôn tập! 📖`)}catch(o){console.error("Error loading due words:",o),P.error("Không thể tải từ cần ôn tập")}},children:[e.jsx(ws,{className:"mr-2",size:20,weight:"fill"}),"Ôn ngay"]})]})}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx(ie,{className:"p-4 sm:p-6 bg-gradient-to-br from-grass-3 to-grass-3 border-2 border-grass-5 cursor-pointer hover:shadow-lg transition-all group",children:e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx("div",{className:"mx-auto w-16 h-16 rounded-full bg-amber-100 flex items-center justify-center group-hover:scale-110 transition-transform",children:e.jsx(_e,{size:32,weight:"duotone",className:"text-amber-600"})}),e.jsx("h3",{className:"font-bold text-lg",children:"Từ Đặc Sắc"}),e.jsx("p",{className:"text-sm text-gray-600",children:"Xem và học các từ vựng quan trọng với flashcard tương tác"}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs(v,{className:"w-full",size:"lg",variant:"outline",disabled:ee,onClick:async()=>{if(l){const o=Array.from(new Set((T||[]).slice(0,g?void 0:As).flatMap(M=>g?M.word_ids:M.word_ids.slice(0,Qe))));if(o.length===0){P.info("Sổ tay chưa có từ nào! Hãy thêm từ vào sổ tay trước. 📝");return}const L=m.filter(M=>o.includes(String(M.id)));if(L.length===0){P.info("Không tìm thấy từ nào trong sổ tay! 📝");return}const B=[...L].sort(()=>Math.random()-.5).slice(0,20);y({cards:B,title:`Từ đặc sắc - Sổ tay (${B.length} từ)`}),c(0),u(!0),_(!1),P.success(`Đã tải ${B.length} từ từ sổ tay! 📚`)}else{if(ee)return;const o=ae.filter(B=>B.word_count>=5);if(o.length===0){P.info("Chưa có chủ đề nào! Vui lòng thử lại sau.");return}const L=o[Math.floor(Math.random()*o.length)];Y(!0);try{const B=await F(L.id);if(B.length===0){P.info("Không tìm thấy từ nào trong chủ đề này!");return}const V=[...B.map(H=>ke(H))].sort(()=>Math.random()-.5).slice(0,20),E=L.name_vi||L.name;y({cards:V,title:`Từ đặc sắc - ${E} (${V.length} từ)`}),c(0),u(!0),_(!1),P.success(`Đã tải ${V.length} từ chủ đề "${E}"! 📚`)}catch(B){console.error("Failed to load random topic words:",B),P.error("Không thể tải từ vựng. Vui lòng thử lại!")}finally{Y(!1)}}},children:[e.jsx(ws,{className:"mr-2",size:20,weight:"fill"}),"Xem Flashcard"]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(v,{className:"flex-1",size:"lg",variant:"outline",disabled:q===0,onClick:async()=>{if(!l){P.error("Bạn cần đăng nhập để ôn sớm");return}if(q===0){P.info("Chưa có từ nào có thể ôn sớm! ⏰");return}try{const o=await K(20,Q);if(o.length===0){P.info("Chưa có từ nào có thể ôn sớm! ⏰");return}const L=o.map(V=>V.word_id),M=(await b(L)).map(V=>ke(V));y({cards:M,title:`Ôn Sớm (${M.length} từ)${Q?` - ${Q} ngày`:""}`}),c(0),u(!0),_(!1),P.success(`Đã tải ${M.length} từ ôn sớm! ⏰`)}catch(o){console.error("Error loading early review words:",o),P.error("Không thể tải từ ôn sớm")}},children:[e.jsx(He,{className:"mr-2",size:20,weight:"fill"}),"Ôn Sớm ",q>0?`(${q} từ)`:"(0 từ)"]}),e.jsx(v,{variant:"outline",size:"icon",className:"h-11 w-11",onClick:()=>R(!Z),children:e.jsx(ps,{size:20})})]}),Z&&e.jsxs("div",{className:"p-3 rounded-lg border bg-muted/30 space-y-3",children:[e.jsx("p",{className:"text-xs text-gray-600 font-medium",children:"Cài đặt Ôn Sớm"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(v,{variant:Q===null?"default":"outline",size:"sm",onClick:async()=>{O(null)},children:"Mặc định"}),[1,2,3,5,7].map(o=>e.jsxs(v,{variant:Q===o?"default":"outline",size:"sm",onClick:async()=>{O(o)},children:[o," ngày"]},o))]}),e.jsx("p",{className:"text-xs text-gray-600",children:Q===null?"Mặc định: Ôn khi đã qua 10-30% thời gian interval":`Ôn từ sẽ đến hạn trong ${Q} ngày tới`})]})]})]})]})}),e.jsx(ie,{className:"p-4 sm:p-6 bg-gradient-to-br from-primary/5 to-accent/5 border-2 border-primary/20",children:e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx("div",{className:"mx-auto w-16 h-16 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx(Rs,{size:32,weight:"duotone",className:"text-primary"})}),e.jsx("h3",{className:"font-bold text-lg",children:"Bài Tập Tương Tác"}),e.jsx("p",{className:"text-sm text-gray-600",children:"Luyện tập với các bài tập tương tác để ghi nhớ từ vựng tốt hơn"}),e.jsxs("div",{className:"flex gap-2 items-stretch",children:[e.jsxs(v,{className:"flex-[2] h-11",size:"lg",onClick:()=>s("vocab-quiz"),children:[e.jsx(Ds,{className:"mr-2",size:20,weight:"fill"}),"Bắt Đầu Nhanh"]}),e.jsx(ba,{isPremium:g,onStartQuiz:o=>{s("vocab-quiz",o)}})]})]})})]}),!z&&e.jsxs(ie,{className:"p-4 sm:p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"font-semibold",children:"Sổ tay của tôi"}),e.jsx(js,{onCreateNotebook:p})]}),(T||[]).length===0?e.jsxs("div",{className:"text-center py-8 text-gray-600",children:[e.jsx(Bs,{size:48,className:"mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"Chưa có sổ từ vựng nào"}),e.jsx("p",{className:"text-sm mt-2",children:"Tạo sổ mới để bắt đầu thu thập từ vựng"})]}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:(T||[]).map((o,L)=>{const B=!g&&L>=As,M=!g&&o.word_ids.length>Qe,V=!g&&!B?o.word_ids.slice(0,Qe):o.word_ids,H=m.filter(X=>V.includes(String(X.id))).filter(X=>(h||[]).includes(X.id)).length;return e.jsxs("div",{className:`border rounded-lg p-4 transition-all relative group ${B?"opacity-60 cursor-not-allowed bg-muted border-dashed":"hover:shadow-md cursor-pointer bg-card hover:bg-accent/5"}`,onClick:()=>
3{if(B){P.error("Sổ tay này bị khoá. Nâng cấp Premium để mở khoá tất cả sổ tay! 🔒");return}w(o.id),n("all")},children:[B&&e.jsx("div",{className:"absolute inset-0 rounded-lg flex items-center justify-center z-20",children:e.jsxs("div",{className:"flex items-center gap-1.5 bg-background/90 border border-amber-300 rounded-full px-3 py-1.5 shadow-sm",children:[e.jsx(Be,{size:14,weight:"fill",className:"text-amber-500"}),e.jsx("span",{className:"text-xs font-medium text-amber-700",children:"Premium"})]})}),e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsx("h4",{className:`font-semibold truncate flex-1 ${B?"text-muted-foreground":""}`,children:o.name}),B?e.jsx(ce,{variant:"secondary",className:"text-xs",children:o.word_ids.length}):e.jsxs("div",{className:"flex items-center gap-0 md:opacity-0 md:group-hover:opacity-100 transition-opacity",children:[e.jsx("span",{className:"text-xs font-medium px-2 py-0.5 rounded-l-md bg-secondary text-secondary-foreground",children:o.word_ids.length}),e.jsx("button",{className:"flex items-center justify-center px-1.5 py-1 rounded-r-md text-destructive hover:bg-destructive/10 transition-colors bg-secondary",onClick:async X=>{X.stopPropagation(),await se({title:`Xóa sổ tay "${o.name}"?`,description:"Hành động này không thể hoàn tác. Tất cả từ vựng trong sổ sẽ bị xóa.",confirmText:"Xóa",variant:"destructive"})&&J(o.id)},children:e.jsx(Os,{size:13})})]})]}),o.description&&e.jsx("p",{className:"text-xs text-gray-600 line-clamp-2 mb-3",children:o.description}),e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsxs("span",{className:"text-gray-600",children:[H,"/",V.length," đã thuộc",M&&!B&&e.jsxs("span",{className:"text-amber-500 ml-1",children:["(+",o.word_ids.length-Qe," 🔒)"]})]}),e.jsxs("span",{className:"text-gray-600",children:[Math.round(H/(V.length||1)*100),"%"]})]})]},o.id)})})]}),z&&A&&e.jsxs(ie,{className:"p-4 sm:p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>w(null),className:"h-8 w-8",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",fill:"currentColor",viewBox:"0 0 256 256",children:e.jsx("path",{d:"M165.66,202.34a8,8,0,0,1-11.32,11.32l-80-80a8,8,0,0,1,0-11.32l80-80a8,8,0,0,1,11.32,11.32L91.31,128Z"})})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg",children:A.name}),A.description&&e.jsx("p",{className:"text-xs text-gray-600",children:A.description})]})]}),e.jsxs(ce,{variant:"secondary",className:"text-sm",children:[f.length," từ"]})]}),e.jsx(ie,{className:"p-4 mb-4 bg-gradient-to-r from-primary/10 to-accent/10 border-2",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:"Tiến Độ Học"}),e.jsxs("span",{className:"text-sm font-bold",children:[f.filter(o=>(h||[]).includes(o.id)).length,"/",f.length," từ"]})]}),e.jsx(is,{value:f.length>0?f.filter(o=>(h||[]).includes(o.id)).length/f.length*100:0,className:"h-3"}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 sm:gap-4 mt-2",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-xl sm:text-2xl font-bold text-primary",children:f.filter(o=>(h||[]).includes(o.id)).length}),e.jsx("div",{className:"text-xs text-gray-600",children:"Đã thuộc"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-xl sm:text-2xl font-bold text-accent",children:f.filter(o=>(N||[]).includes(o.id)).length}),e.jsx("div",{className:"text-xs text-gray-600",children:"Đang học"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-xl sm:text-2xl font-bold text-gray-600",children:f.length-f.filter(o=>(h||[]).includes(o.id)).length-f.filter(o=>(N||[]).includes(o.id)).length}),e.jsx("div",{className:"text-xs text-gray-600",children:"Chưa học"})]})]})]})})]}),D]})}function Zs({className:s,...l}){return e.jsx(Ft,{"data-slot":"checkbox",className:Ce("peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",s),...l,children:e.jsx(It,{"data-slot":"checkbox-indicator",className:"flex items-center justify-center text-current transition-none",children:e.jsx(qt,{className:"size-3.5"})})})}function za({card:s,masteredCards:l,learningCards:g,onClick:m,selectionMode:h,isSelected:N,onToggleSelect:T}){var f,w;
3const k=(l||[]).includes(s.id),z=(g||[]).includes(s.id),A=k?100:z?50:0;return e.jsxs("div",{className:"border rounded-xl p-4 hover:shadow-md transition-all bg-card hover:bg-accent/5 cursor-pointer",onClick:m,children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsx("h4",{className:"text-lg font-bold text-success flex-1",children:s.word}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("div",{className:"flex flex-col items-end gap-0.5",children:[e.jsxs("div",{className:"text-[10px] text-gray-500",children:[A,"%"]}),e.jsx("div",{className:"w-10 h-1 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-success transition-all",style:{width:`${A}%`}})})]}),h&&e.jsx("div",{className:"cursor-pointer flex-shrink-0",onClick:p=>{p.stopPropagation(),T==null||T(s.id)},children:e.jsx(Zs,{checked:N,className:"h-5 w-5 border-2"})})]})]}),e.jsx("p",{className:"text-xs text-gray-500 italic mb-1",children:s.partOfSpeech||"n/a"}),e.jsx("p",{className:"text-sm leading-relaxed line-clamp-2 mb-2",children:((f=s.customMeaning)==null?void 0:f.meaning_en)||s.definition}),e.jsxs("div",{className:"flex items-start gap-1.5 pt-2 border-t",children:[e.jsx(_e,{className:"text-amber-500 flex-shrink-0 mt-0.5",size:14}),e.jsx("span",{className:"text-sm text-gray-700 line-clamp-1",children:((w=s.customMeaning)==null?void 0:w.meaning_vi)||s.translation})]})]})}const gs=6,fs=3;function Ta({onNavigate:s,isPremium:l=!1,mockFlashcards:g,masteredCards:m,learningCards:h,notebooks:N,selectedNotebookId:T,selectNotebook:k,setSelectedTopic:z,setSelectedCard:A,setIsModalOpen:f,setFlashcardViewData:w,setShowFlashcardView:p,setFlashcardIndex:J,selectedCategory:n,setSelectedCategory:y,dbParentTopics:u,dbTopicsWithWords:c,topicsLoading:_,topicWordsLoading:W,loadWordsForTopic:q,getTopicWords:Q,getChildTopics:O,getTopicLevel:Z,selectedParentTopic:R,setSelectedParentTopic:I,selectedLevel2Topic:K,setSelectedLevel2Topic:i,createNotebook:b,addWordsToNotebook:se}){const[D,ae]=a.useState(!1),[F,ee]=a.useState(!1),Y=a.useRef(null),[o,L]=a.useState(!1),[B,M]=a.useState(0);a.useEffect(()=>{const d=Y.current;if(!d||F){L(!1);return}const t=requestAnimationFrame(()=>{const x=d.scrollHeight>d.clientHeight+2;if(L(x),x){const S=d.getBoundingClientRect();let j=0;Array.from(d.children).forEach(G=>{G.getBoundingClientRect().top>=S.bottom-1&&j++}),M(j)}else M(0)});return()=>cancelAnimationFrame(t)},[u,F]);const[V,E]=a.useState(!1),[H,X]=a.useState(new Set),[ve,re]=a.useState(!1),me=d=>{X(t=>{const x=new Set(t);return x.has(d)?x.delete(d):x.add(d),x})},fe=d=>{X(t=>{const x=new Set(t);return d.forEach(S=>x.add(S.id)),x})},be=d=>{X(t=>{const x=new Set(t);return d.forEach(S=>x.delete(S.id)),x})},ue=()=>{X(new Set),re(!1),E(!1)},Se=async d=>{const t=Array.from(H);if(t.length===0)return;(await se(d,t,n||K||void 0)).added>0&&ue()};return e.jsxs("div",{className:"space-y-4 relative",children:[e.jsxs(ie,{className:"p-4 sm:p-6",children:[e.jsx("h3",{className:"font-semibold mb-0",children:"Lọc theo chủ đề"}),_?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto"}),e.jsx("p",{className:"text-sm text-gray-600",children:"Đang tải chủ đề..."})]})}):u.length===0?e.jsxs("div",{className:"text-center py-8 text-gray-600",children:[e.jsx(ks,{size:48,className:"mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"Chưa có chủ đề nào"}),e.jsx("p",{className:"text-sm mt-2",children:"Dữ liệu phân loại chủ đề sẽ sớm được cập nhật"})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 mb-2 font-medium uppercase tracking-wide",children:"Bộ từ vựng"}),R?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"hidden sm:flex gap-2 overflow-x-auto pb-2 scrollbar-hide -mx-1 px-1",children:u.map(d=>e.jsxs(v,{variant:R===d.id?"default":"outline",size:"sm",className:`flex-shrink-0 rounded-full px-4 gap-1.5 ${R===d.id?"bg-primary text-primary-foreground":""}`,onClick:()=>{R===d.id?I(null):I(d.id),i(null),y(null)},children:[d.icon&&e.jsx("span",{children:d.icon}),d.name,e.jsx(ce,{variant:"secondary",className:`ml-0.5 text-xs ${R===d.id?"bg-background/20":""}`,children:d.total_word_count})]},d.id))}),e.jsxs("div",{className:"sm:hidden",children:[e.jsx("div",{ref:Y,className:`flex gap-2 pb-2 -mx-1 px-1 flex-wrap ${F?"":"max-h-[7.25rem] overflow-hidden"}`,children:u.map(d=>e.jsxs(v,{variant:R===d.id?"default":"outline",size:"sm",className:`flex-shrink-0 rounded-full px-4 gap-1.5 ${R===d.id?"bg-primary text-primary-foreground":""}`,onClick:()=>{R===d.id?I(null):I(d.id),i(null),y(null)},children:[d.icon&&e.jsx("span",{children:d.icon}),d.name,e.jsx(ce,{variant:"secondary",className:`ml-0.5 text-xs ${R===d.id?"bg-background/20":""}`,children:d.total_word_count})]},d.id))}),(o||F)&&e.jsxs(v,{variant:"ghost",size:"sm",className:"w-full text-xs text-gray-500 hover:text-primary gap-1 mt-1",onClick:()=>ee(!F),children:[e.jsx(Ze,{size:14,className:`transition-transform ${F?"rotate-180":""}`}),F?"Thu gọn":`Xem thêm ${B} chủ đề`]})]})]}):e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-3",children:u.map(d=>e.jsxs("button",{className:"flex flex-col items-center gap-2 p-4 sm:p-5 rounded-xl border-2 border-border bg-card hover:border-primary/40 hover:bg-accent/5 transition-all text-center cursor-pointer",onClick:()=>{I(d.id),i(null),y(null)},children:[e.jsx(Kt,{size:32,weight:"duotone",className:"text-primary"}),e.jsx("span",{className:"font-medium text-sm sm:text-base leading-tight",children:d.name}),e.jsxs(ce,{variant:"secondary",className:"text-xs",children:[d.total_word_count," từ"]})]},d.id))})]}),R&&(()=>{const d=O(R);if(d.length===0)return null;const t=u.find(x=>x.id===R);return e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 mb-2 font-medium uppercase tracking-wide",children:(t==null?void 0:t.name)||"Nhóm"}),e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-2 scrollbar-hide -mx-1 px-1 flex-wrap",children:d.map(x=>{const S=K===x.id;return e.jsxs(v,{variant:S?"default":"outline",size:"sm",className:`flex-shrink-0 rounded-full px-3 text-xs gap-1 ${S?"bg-primary text-primary-foreground":""}`,onClick:()=>{i(S?null:x.id),y(null),ae(!1)},children:[x.name,x.total_word_count>0&&e.jsx(ce,{variant:"secondary",className:`text-[10px] px-1.5 ${S?"bg-background/20":""}`,children:x.total_word_count})]},x.id)})})]})})(),K&&(()=>{const d=O(K),t=c.find(j=>j.id===K);if(d.length===0){const j=Q(K),G=W===K,U=j.filter(xe=>m==null?void 0:m.includes(xe.id)).length,le=j.length>0?Math.round(U/j.length*100):0;return j.length===0&&!G&&q(K),e.jsx(Ls,{topicName:(t==null?void 0:t.name)||"",topicNameEn:(t==null?void 0:t.name_vi)||void 0,topicId:K,cachedWords:j,isLoading:G,masteredInTopic:U,masteryPercentage:le,masteredCards:m,learningCards:h,isPremium:l,loadWordsForTopic:q,onNavigate:s,setSelectedCard:A,setIsModalOpen:f,setFlashcardViewData:w,setShowFlashcardView:p,setFlashcardIndex:J,selectionMode:V,setSelectionMode:E,selectedWordIds:
3H,toggleWordSelection:me,selectAllWords:fe,deselectAllWords:be,clearSelection:ue})}const x=d.length>gs,S=D?d:d.slice(0,gs);return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("p",{className:"text-xs text-gray-500 font-medium uppercase tracking-wide",children:(t==null?void 0:t.name)||"Chủ đề"}),e.jsxs("span",{className:"text-xs text-gray-400",children:[d.length," chủ đề"]})]}),e.jsx("div",{className:"hidden sm:flex gap-2 pb-2 -mx-1 px-1 flex-wrap",children:d.map((j,G)=>{const U=n===j.id,le=!l&&G>=fs;return e.jsxs(v,{variant:U?"default":"outline",size:"sm",className:`flex-shrink-0 rounded-full px-3 text-xs gap-1 ${U?"bg-primary text-primary-foreground":""}`,onClick:async()=>{U?y(null):(y(j.id),Q(j.id).length===0&&await q(j.id))},children:[le&&e.jsx(Be,{size:12,weight:"fill",className:"text-amber-500"}),j.name,j.word_count>0&&e.jsx(ce,{variant:"secondary",className:`text-[10px] px-1.5 ${U?"bg-background/20":""}`,children:j.word_count})]},j.id)})}),e.jsxs("div",{className:"sm:hidden",children:[e.jsx("div",{className:"flex gap-2 pb-2 -mx-1 px-1 flex-wrap",children:S.map((j,G)=>{const U=n===j.id,le=!l&&G>=fs;return e.jsxs(v,{variant:U?"default":"outline",size:"sm",className:`flex-shrink-0 rounded-full px-3 text-xs gap-1 ${U?"bg-primary text-primary-foreground":""}`,onClick:async()=>{U?y(null):(y(j.id),Q(j.id).length===0&&await q(j.id))},children:[le&&e.jsx(Be,{size:12,weight:"fill",className:"text-amber-500"}),j.name,j.word_count>0&&e.jsx(ce,{variant:"secondary",className:`text-[10px] px-1.5 ${U?"bg-background/20":""}`,children:j.word_count})]},j.id)})}),x&&e.jsxs(v,{variant:"ghost",size:"sm",className:"w-full text-xs text-gray-500 hover:text-primary gap-1 mt-1",onClick:()=>ae(!D),children:[e.jsx(Ze,{size:14,className:`transition-transform ${D?"rotate-180":""}`}),D?"Thu gọn":`Xem thêm ${d.length-gs} chủ đề`]})]})]})})(),n&&(()=>{const d=Q(n),t=W===n,x=c.find(xe=>xe.id===n),S=d.filter(xe=>m==null?void 0:m.includes(xe.id)).length,j=d.length>0?Math.round(S/d.length*100):0,U=(K?O(K):[]).findIndex(xe=>xe.id===n),le=!l&&U>=fs;return e.jsx(Ls,{topicName:(x==null?void 0:x.name)||"",topicNameEn:(x==null?void 0:x.name_vi)||void 0,topicId:n,cachedWords:d,isLoading:t,masteredInTopic:S,masteryPercentage:j,masteredCards:m,learningCards:h,isPremium:l,isQuizLocked:le,loadWordsForTopic:q,onNavigate:s,setSelectedCard:A,setIsModalOpen:f,setFlashcardViewData:w,setShowFlashcardView:p,setFlashcardIndex:J,selectionMode:V,setSelectionMode:E,selectedWordIds:H,toggleWordSelection:me,selectAllWords:fe,deselectAllWords:be,clearSelection:ue})})(),!R&&e.jsxs("div",{className:"text-center py-8 text-gray-500",children:[e.jsx(ks,{size:40,className:"mx-auto mb-3 opacity-40"}),e.jsx("p",{className:"text-sm",children:"Chọn một bộ từ vựng để bắt đầu"})]}),R&&!K&&O(R).length>0&&e.jsx("div",{className:"text-center py-6 text-gray-500",children:e.jsx("p",{className:"text-sm",children:"Chọn một nhóm để xem chủ đề"})}),K&&!n&&O(K).length>0&&e.jsx("div",{className:"text-center py-6 text-gray-500",children:e.jsx("p",{className:"text-sm",children:"Chọn một chủ đề để xem từ vựng"})})]})]}),H.size>0&&e.jsx(ie,{className:"sticky bottom-24 sm:bottom-4 z-40 bg-background/95 backdrop-blur-sm border-2 border-primary/30 shadow-2xl animate-in slide-in-from-bottom-4 p-3 sm:p-4 mb-2",children:ve?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium",children:["Thêm ",H.size," từ vào sổ tay:"]}),e.jsx(v,{size:"sm",variant:"ghost",onClick:()=>re(!1),children:e.jsx($e,{size:16})})]}),(N||[]).length===0?e.jsxs("div",{className:"flex items-center gap-3 py-2",children:[e.jsx("p",{className:"text-sm text-gray-600",children:"Chưa có sổ tay nào."}),e.jsx(js,{onCreateNotebook:async(d,t)=>{const x=Array.from(H),S=await b(d,t,x);return S&&ue(),S}})]}):e.jsxs("div",{className:"flex gap-2 overflow-x-auto pb-1 scrollbar-hide -mx-1 px-1",children:[N.map(d=>e.jsxs(v,{variant:"outline",size:"sm",className:"flex-shrink-0 rounded-full px-4 gap-1.5 hover:bg-primary/10 hover:border-primary",onClick:()=>Se(d.id),children:[e.jsx(Bs,{size:14}),d.name,e.jsx(ce,{variant:"secondary",className:"text-[10px] px-1.5",children:d.word_ids.length})]},d.id)),e.jsx(js,{onCreateNotebook:async(d,t)=>{const x=Array.from(H),S=await b(d,t,x);return S&&ue(),S}})]})]}):e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(Ws,{size:20,weight:"fill",className:"text-primary flex-shrink-0"}),e.jsxs("span",{className:"text-sm font-medium truncate",children:["Đã chọn ",e.jsx("strong",{children:H.size})," từ"]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs(v,{size:"sm",onClick:()=>re(!0),className:"gap-1.5",children:[e.jsx(Je,{size:16}),e.jsx("span",{className:"hidden sm:inline",children:"Thêm vào sổ tay"}),e.jsx("span",{className:"sm:hidden",children:"Thêm"})]}),e.jsxs(v,{size:"sm",variant:"ghost",onClick:ue,className:"gap-1",children:[e.jsx($e,{size:16}),e.jsx("span",{className:"hidden sm:inline",children:"Bỏ chọn"})]})]})]})})]})}function Ls({topicName:s,topicNameEn:l,topicId:g,cachedWords:m,isLoading:h,masteredInTopic:N,masteryPercentage:T,masteredCards:k,learningCards:z,isPremium:A=!1,isQuizLocked:f=!1,loadWordsForTopic:w,onNavigate:p,setSelectedCard:J,setIsModalOpen:n,setFlashcardViewData:y,setShowFlashcardView:u,setFlashcardIndex:c,selectionMode:_,setSelectionMode:W,selectedWordIds:q,toggleWordSelection:Q,selectAllWords:O,deselectAllWords:Z,clearSelection:R}){const I=m.length>0&&m.every(i=>q.has(i.id)),K=m.some(i=>q.has(i.id));return e.jsxs("div",{className:"border-t pt-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-base",children:s}),l&&e.jsx("p",{className:"text-xs text-gray-500",children:l})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(v,{variant:_?"default":"outline",size:"sm",className:"h-8 gap-1.5 text-xs ",onClick:()=>{_?R():W(!0)},children:[e.jsx(Ws,{size:16}),e.jsx("span",{className:"hidden sm:inline",children:"Chọn"})]}),e.jsxs(v,{variant:"outline",size:"sm",className:`h-8 gap-1.5 text-xs ${f?"opacity-60":""}`,onClick:async()=>
3{if(f){p("premium");return}const i=m.length>0?m:await w(g);i.length>0&&p("vocab-quiz",{questionCount:Math.min(i.length,10),questionTypes:["multiple-choice-definition","fill-in-blank"],wordIds:i.map(b=>b.id),topicId:g})},children:[e.jsx(ts,{size:16}),"Quiz",f&&e.jsx(es,{size:12,weight:"fill",className:"text-yellow-500"})]}),e.jsxs(v,{variant:"outline",size:"sm",className:`h-8 gap-1.5 text-xs ${f?"opacity-60":""}`,onClick:async()=>{if(f){p("premium");return}const i=m.length>0?m:await w(g);i.length>0&&(y({cards:i,title:s}),u(!0),c(0))},children:[e.jsx(as,{size:16}),"Flashcard",f&&e.jsx(es,{size:12,weight:"fill",className:"text-yellow-500"})]})]})]}),h?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-b-2 border-primary mx-auto"}),e.jsx("p",{className:"text-sm text-gray-500",children:"Đang tải từ vựng..."})]})}):m.length===0?e.jsx("p",{className:"text-center text-gray-500 py-6 text-sm",children:"Chưa có từ vựng trong chủ đề này"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-gray-600",children:"Tiến độ"}),e.jsxs("span",{className:"font-medium",children:[N,"/",m.length," từ đã thuộc"]})]}),e.jsx(is,{value:T,className:"h-2"})]}),_&&e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{role:"button",tabIndex:0,className:"inline-flex items-center h-8 gap-1.5 text-xs text-primary hover:text-primary/80 cursor-pointer select-none rounded-md px-3 hover:bg-accent transition-colors",onClick:()=>{I?Z(m):O(m)},onKeyDown:i=>{(i.key==="Enter"||i.key===" ")&&(i.preventDefault(),I?Z(m):O(m))},children:[e.jsx(Zs,{checked:I?!0:K?"indeterminate":!1,className:"pointer-events-none"}),I?"Bỏ chọn tất cả":`Chọn tất cả ${m.length} từ`]}),K&&e.jsxs("span",{className:"text-xs text-gray-500",children:[m.filter(i=>q.has(i.id)).length," từ đã chọn"]})]}),e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-3",children:m.map(i=>{const b=q.has(i.id);return e.jsx("div",{children:e.jsx("div",{className:`transition-all rounded-xl ${_&&b?"ring-2 ring-primary ring-offset-1":""}`,children:e.jsx(za,{card:i,masteredCards:k,learningCards:z,selectionMode:_,isSelected:b,onToggleSelect:Q,onClick:()=>{_?Q(i.id):(J(i.id),n(!0))}})})},i.id)})})]})]})}function Va({onNavigate:s,initialWordIds:l,initialTab:g}){const[m,h]=a.useState(g||"words");a.useEffect(()=>{g&&g!==m&&h(g)},[g]);const{user:N,mockFlashcards:T,filteredByTopic:k,searchFilteredCards:z,selectedFlashcard:A,notebooks:f,selectedNotebook:w,selectedNotebookWords:p,selectedNotebookId:J,notebookLearningStats:n,selectNotebook:y,createNotebook:u,addWordToNotebook:c,addWordsToNotebook:_,removeWordFromNotebook:W,deleteNotebook:q,updateNotebook:Q,flashcardProgressData:O,masteredCards:Z,learningCards:R,updateProgress:I,resetToLearning:K,getDueWords:i,getEarlyReviewWords:b,flipped:se,setFlipped:D,searchQuery:ae,setSearchQuery:F,selectedCard:ee,setSelectedCard:Y,isModalOpen:o,setIsModalOpen:L,showFlashcardView:B,setShowFlashcardView:M,flashcardIndex:V,setFlashcardIndex:E,flashcardViewData:H,setFlashcardViewData:X,showCompletionCelebration:ve,setShowCompletionCelebration:re,selectedTopic:me,setSelectedTopic:fe,selectedCategory:be,setSelectedCategory:ue,earlyReviewCount:Se,earlyReviewDays:d,setEarlyReviewDays:t,showEarlyReviewSettings:x,setShowEarlyReviewSettings:S,dueWordCount:j,isSearching:G,dbParentTopics:U,dbTopicsWithWords:le,topicsLoading:xe,topicWordsLoading:ge,loadWordsForTopic:Me,getTopicWords:We,getChildTopics:rs,getTopicLevel:Te,selectedParentTopic:Ee,setSelectedParentTopic:Fe,selectedLevel2Topic:Ae,setSelectedLevel2Topic:cs}=va(),{loadWordsByIds:Ie,searchWords:os}=Ys(),{isPremium:Le}=Ht(N==null?void 0:N.id),ds=a.useMemo(()=>A||(!ee||!(H!=null&&H.cards)?null:H.cards.find(C=>C.id===ee)||null),[A,ee,H]),ye=a.useRef(null);return a.useEffect(()=>{!l||l.length===0||ye.current&&JSON.stringify(ye.current)===JSON.stringify(l)||(ye.current=l,(async()=>{try{const C=await Ie(l);if(C.length>0){const te=C.map(ze=>ke(ze));X({cards:te,title:"Từ hay quên nhất"}),E(0),M(!0)}}catch(C){console.error("Failed to load initial word IDs for review:",C)}})())},[l,Ie,X,E,M]),e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(ya,{searchQuery:ae,setSearchQuery:F,isSearching:G,searchFilteredCards:z,masteredCards:Z,learningCards:R,notebooks:f,createNotebook:u,addWordToNotebook:c,setSelectedCard:Y,setIsModalOpen:L}),e.jsx("div",{className:"container mx-auto px-4 sm:px-6 lg:px-12 py-8 sm:py-12",children:e.jsx("div",{className:"max-w-7xl mx-auto 
3space-y-6",children:e.jsxs(Xt,{value:m,onValueChange:h,className:"w-full",children:[e.jsx(Cs,{value:"words",children:e.jsx(Sa,{onNavigate:s,user:N,isPremium:Le,mockFlashcards:T,masteredCards:Z,learningCards:R,notebooks:f,notebookLearningStats:n,selectedNotebookId:J,selectedNotebook:w,selectedNotebookWords:p,selectNotebook:y,createNotebook:u,deleteNotebook:q,setSelectedTopic:fe,setFlashcardViewData:X,setShowFlashcardView:M,setFlashcardIndex:E,setFlipped:D,onCardClick:C=>{Y(C.id),L(!0)},earlyReviewCount:Se,earlyReviewDays:d,setEarlyReviewDays:t,showEarlyReviewSettings:x,setShowEarlyReviewSettings:S,getDueWords:i,getEarlyReviewWords:b,dueWordCount:j,loadWordsByIds:Ie})}),e.jsx(Cs,{value:"categories",className:"space-y-4",children:e.jsx(Ta,{onNavigate:s,isPremium:Le,mockFlashcards:T,masteredCards:Z,learningCards:R,notebooks:f,selectedNotebookId:J,selectNotebook:y,setSelectedTopic:fe,setSelectedCard:Y,setIsModalOpen:L,setFlashcardViewData:X,setShowFlashcardView:M,setFlashcardIndex:E,selectedCategory:be,setSelectedCategory:ue,dbParentTopics:U,dbTopicsWithWords:le,topicsLoading:xe,topicWordsLoading:ge,loadWordsForTopic:Me,getTopicWords:We,getChildTopics:rs,getTopicLevel:Te,selectedParentTopic:Ee,setSelectedParentTopic:Fe,selectedLevel2Topic:Ae,setSelectedLevel2Topic:cs,createNotebook:u,addWordsToNotebook:_})})]})})}),w&&e.jsx(ga,{notebook:w,words:p,masteredCards:Z||[],learningCards:R||[],progressData:O,onClose:()=>y(null),onRemoveWord:async C=>{w&&await W(w.id,C)},onToggleMastered:async C=>{if(N)try{await I(C,!0),P.success("Đã cập nhật trạng thái! ✅")}catch(te){console.error("Error updating flashcard progress:",te)}},onToggleLearning:async C=>{if(N)try{await I(C,!1),P.success("Đã cập nhật trạng thái! ✅")}catch(te){console.error("Error updating flashcard progress:",te)}},onOpenFlashcardView:C=>{if(C&&C.length>0){const te=C.map(ze=>p.find(Oe=>Oe.id===ze)).filter(Boolean);te.length>0&&X({cards:te,title:(w==null?void 0:w.name)||"Sổ từ vựng"})}M(!0),E(0)},onStartQuiz:C=>{const te=p.map(xs=>xs.id),ze=Le?te:te.slice(0,50),Oe=C&&C.length>0?C:ze;y(null),s("vocab-quiz",{questionCount:Math.min(Oe.length,10),wordIds:Oe})},onUpdateNotebook:async(C,te)=>{await Q(C,te)},onSearchVocabulary:os,onAddWordToNotebook:c,isPremium:Le}),e.jsx(Gs,{flashcard:ds,open:o,onOpenChange:C=>{L(C)},isMastered:(Z||[]).includes(ee||""),notebooks:f,onCreateNotebook:u,onAddWordToNotebook:c,onSwipeLeft:async()=>{if(ee&&N)try{await I(ee,!1),P.success("Đã thêm vào đang học! 📚")}catch(C){console.error("Error updating flashcard progress:",C)}L(!1)},onSwipeRight:async()=>{if(ee&&N)try{await I(ee,!0),P.success("Đã đánh dấu thành thạo! 🎉")}catch(C){console.error("Error updating flashcard progress:",C)}L(!1)}}),B&&k.length>0&&e.jsx(Na,{cards:k,cardIndex:V,flipped:se,masteredCards:Z||[],title:H?H.title:w?w.name:me==="all"?"Tất cả":me.charAt(0).toUpperCase()+me.slice(1),isLoggedIn:!!N,onClose:()=>{M(!1),D(!1),X(null)},onFlip:()=>D(!se),onPrevious:()=>{D(!1),E(C=>Math.max(0,C-1))},onNext:()=>{D(!1),E(C=>Math.min(k.length-1,C+1))},onMarkLearning:async C=>{const te=await K(C);return te||await I(C,!1),te},onMarkMastered:async C=>{await I(C,!0)},onAdvanceOrComplete:C=>{D(!1),C?re(!0):E(te=>te+1)},onOpenDetail:C=>{Y(C),L(!0)}}),ve&&e.jsx(ja,{totalWords:k.length,onRestart:()=>{re(!1),E(0)},onFinish:()=>{re(!1),M(!1),E(0),X(null)}})]})}export{Va as Flashcards};

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.