PageSourceSearch

https://ireadify.com/_next/static/chunks/pages/book/[id]-32d8b2acab813db9.js

js ireadify.com collected 2026-09-28 12:28:58 UTC 156,899 bytes, 1 lines download raw bytes

1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7826],{32539:function(e,t,r){(window.__NEXT_P=window.__NEXT_P||[]).push(["/book/[id]",function(){return r(89717)}])},31085:function(e,t,r){"use strict";r.d(t,{VW:function(){return s},aD:function(){return n}});var s="\n  query ListRatings(\n    $filter: ModelRatingFilterInput\n    $limit: Int\n    $nextToken: String\n  ) {\n    listRatings(filter: $filter, limit: $limit, nextToken: $nextToken) {\n      items {\n        id\n        email\n        bookId\n        isRated\n        myRating\n        createdAt\n        updatedAt\n      }\n      nextToken\n    }\n  }\n",n="\n  query SearchRatings(\n    $filter: SearchableRatingFilterInput\n    $sort: SearchableRatingSortInput\n    $limit: Int\n    $nextToken: String\n    $from: Int\n  ) {\n    searchRatings(\n      filter: $filter\n      sort: $sort\n      limit: $limit\n      nextToken: $nextToken\n      from: $from\n    ) {\n      items {\n        id\n        email\n        bookId\n        books {\n          id\n          title\n          description\n          image\n          ageId\n          region\n          isbn\n          narrator\n          status\n          createdAt\n          updatedAt\n          isDeleted\n          book\n          bookType\n          authorName\n          authorId\n          duration\n          languageId\n        }\n        isRated\n        myRating\n        createdAt\n        updatedAt\n      }\n      nextToken\n      total\n    }\n  }\n"},16494:function(e,t,r){"use strict";var s=r(85893);r(67294);t.Z=function(){return(0,s.jsx)("div",{className:"animate-pulse fixed top-0 left-0 right-0 bottom-0 w-full h-screen z-50 overflow-hidden opacity-75 flex flex-col items-center justify-center",children:(0,s.jsx)("img",{src:"/img/loader/e3b7eccfc4e1132329e6e2639e95b447.gif",alt:"Loading..."})})}},4287:function(e,t,r){"use strict";r.d(t,{EF:function(){return o},ZP:function(){return m},fr:function(){return i}});var s=r(828),n=r(29815),a=r(85893),l=r(94325),i=["wordMatching","fillInBlanks","vocabularyQuiz"],o=["storySequencing"],c=(0,n.Z)(i).concat((0,n.Z)(o)),d={wordMatching:{name:"Word Matching",icon:"\ud83d\udd17"},fillInBlanks:{name:"Fill in the Blanks",icon:"\ud83d\udcdd"},vocabularyQuiz:{name:"Vocabulary Quiz",icon:"\ud83e\udde0"},storySequencing:{name:"Sequence Quest",icon:"\ud83d\udcd6"}};function u(e){var t=e.title,r=e.items,s=e.variant,n=e.answerLabel,l=void 0===n?"Student answer":n;if(!(null===r||void 0===r?void 0:r.length))return null;var i="missed"===s,o=i?"bg-red-50 border-red-200":"bg-green-50 border-green-200",c=i?"text-red-800":"text-green-800",d=i?"bg-white border-red-100":"bg-white border-green-100";return(0,a.jsxs)("div",{className:"rounded-xl p-4 sm:p-5 border ".concat(o),children:[(0,a.jsxs)("h4",{className:"text-base font-semibold mb-3 ".concat(c),children:[t," (",r.length,")"]}),(0,a.jsx)("ul",{className:"space-y-3 ".concat(i?"max-h-56":"max-h-44"," overflow-y-auto"),children:r.map((function(e,t){var r;return(0,a.jsxs)("li",{className:"rounded-lg p-3 border text-sm ".concat(d),children:[e.word&&(0,a.jsx)("div",{className:"font-semibold text-gray-800",children:e.word}),e.question&&(0,a.jsx)("div",{className:"text-gray-600 mt-1 line-clamp-3",children:e.question}),(null===(r=e.metadata)||void 0===r?void 0:r.tryNumber)&&(0,a.jsxs)("div",{className:"text-xs text-gray-500 mt-1",children:["Attempt ",e.metadata.tryNumber,e.metadata.maxTries?" of ".concat(e.metadata.maxTries):"",null!=e.metadata.score?" \xb7 ".concat(e.metadata.score,"%"):""]}),i?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"mt-2 text-red-700",children:[l,": ",e.studentAnswer||"(none)"]}),(0,a.jsxs)("div",{className:"text-green-700 font-medium",children:["Correct: ",e.correctAnswer]})]}):(0,a.jsxs)("div",{className:"mt-1 text-gray-700",children:[(0,a.jsx)("span",{className:"font-medium text-green-800",children:e.correctAnswer}),e.studentAnswer&&e.studentAnswer!==e.correctAnswer&&(0,a.jsxs)("span",{className:"text-gray-600",children:[" \u2014 ",e.studentAnswer]})]})]},"".concat(s,"-").concat(t))}))})]})}function m(e){var t=e.analytics,r=e.gameResult,n=void 0===r?null:r,i=e.defaultExpanded,o=void 0===i||i,m=e.showSummary,x=void 0===m||m,h=e.showPerGameBreakdown,g=void 0===h||h,p=e.showOnlyTab,f=void 0===p?null:p,b=e.studentLabel,v=void 0===b?"Student":b,j=e.gameKeys,w=void 0===j?c:j,y=(null===w||void 0===w?void 0:w.length)?w:c,N=null!==t&&void 0!==t?t:n?l.A.getAnswerAnalytics(n):null,k=n?y.flatMap((function(e){return l.A.getMissedWords(n,e)})):N?y.flatMap((function(e){var t;return(null===(t=N[e])||void 0===t?void 0:t.incorrectAnswers)||[]})):[],C=n?y.flatMap((function(e){return l.A.getCorrectWords(n,e)})):N?y.flatMap((function(e){var t;return(null===(t=N[e])||void 0===t?void 0:t.correctAnswers)||[]})):[],S=C.length+k.length,A=S>0?Math.round(C.length/S*100):null,L=C.length,R=k.length,M="Your"===v?"Your answer":"Student answer";if(!(k.length>0||C.length>0)&&!N)return(0,a.jsx)("div",{className:"rounded-xl bg-gray-50 border border-gray-200 p-6 text-center text-gray-600 text-sm",children:"No detailed answer data for this session. The student may have completed games before answer tracking was enabled."});var T="correct"!==f,D="missed"!==f;return(0,a.jsxs)("div",{className:"space-y-5",children:[x&&(0,a.jsxs)("div",{className:"grid grid-cols-3 gap-2 sm:gap-3",children:[(0,a.jsxs)("div",{className:"text-center bg-green-50 rounded-xl p-3 sm:p-4 border border-green-200",children:[(0,a.jsx)("div",{className:"text-xl sm:text-2xl font-bold text-green-600",children:L}),(0,a.jsx)("div",{className:"text-xs sm:text-sm text-gray-600",children:"Correct"})]}),(0,a.jsxs)("div",{className:"text-center bg-red-50 rounded-xl p-3 sm:p-4 border border-red-200",children:[(0,a.jsx)("div",{className:"text-xl sm:text-2xl font-bold text-red-600",children:R}),(0,a.jsx)("div",{className:"text-xs sm:text-sm text-gray-600",children:"Missed"})]}),(0,a.jsxs)("div",{className:"text-center bg-amber-50 rounded-xl p-3 sm:p-4 border border-amber-200",children:[(0,a.jsx)("div",{className:"text-xl sm:text-2xl font-bold text-amber-600",children:null!=A?"".concat(A,"%"):"\u2014"}),(0,a.jsx)("div",{className:"text-xs sm:text-sm text-gray-600",children:"Accuracy"})]})]}),g&&N&&(0,a.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-2",children:Object.entries(d).filter((function(e){var t=(0,s.Z)(e,1)[0];return y.includes(t)})).map((function(e){var t,r=(0,s.Z)(e,2),n=r[0],l=r[1],i=N[n];return(null===i||void 0===i?void 0:i.totalAttempts)?(0,a.jsxs)("div",{className:"bg-white rounded-lg border border-gray-200 px-3 py-2 text-xs",children:[(0,a.jsx)("span",{className:"mr-1",children:l.icon}),(0,a.jsx)("span",{className:"font-medium text-gray-800",children:l.name}),(0,a.jsxs)("span",{className:"float-right font-semibold text-purple-700",children:[null!==(t=i.accuracy)&&void 0!==t?t:0,"%"]}),(0,a.jsxs)("div",{className:"text-gray-500 mt-0.5",children:[i.totalCorrect,"/",i.totalAttempts," correct"]})]},n):null}))}),o&&(0,a.jsxs)("div",{className:f?"":"space-y-4",children:[T&&(0,a.jsx)(u,{title:f?"Missed (".concat(k.length,")"):"Missed",items:k,variant:"missed",answerLabel:M}),D&&(0,a.jsx)(u,{title:f?"Correct (".concat(C.length,")"):"Correct",items:C,variant:"correct",answerLabel:M}),f&&T&&0===k.length&&(0,a.jsx)("p",{className:"text-sm text-gray-500 text-center py-6",children:"No missed answers \u2014 great job!"}),f&&D&&0===C.length&&(0,a.jsx)("p",{className:"text-sm text-gray-500 text-center py-6",children:"No correct answers recorded."})]})]})}},46044:function(e,t,r){"use strict";var s=r(85893),n=r(41664),a=r.n(n);t.Z=function(e){var t=e.message;return(0,s.jsx)("div",{className:"max-w-screen-2xl mx-auto md:p-14 p-8",children:(0,s.jsx)("div",{className:"container mx-auto p-6 flex flex-wrap content-center justify-center ",children:(0,s.jsxs)("div",{className:"grid justify-items-center",children:[(0,s.jsx)("img",{src:"/img/others/404.png",width:"200",height:"200",alt:"Page Not Found"}),(0,s.jsx)("h4",{className:"text-center text-purple-light font-sans font-semibold mb-2",children:"Oops."}),(0,s.jsx)("p",{className:"text-center text-subtitle1 text-gray-light mb-8 font-serif",children:t}),(0,s.jsx)(a(),{href:"/",className:"rounded w-full my-4 inline-flex justify-center border-2 shadow-sm px-11 py-2 bg-gradient-to-r from-purple-bright to-purple-bright text-small4 font-semibold text-white hover:from-purple-light hover:to-blue-bright focus:outline-none focus:ring-1 focus:ring-offset-1 focus:ring-red-100 sm:ml-3 sm:w-auto 
1sm:text-small4 font-sans",children:"Back to home"})]})})})}},79903:function(e,t){"use strict";t.Z={paypalClientId:"ATuZOyPro6YDC8DuUAlryH0lqKzczAwBYdc8H570qdgchcFoQHZh08WNks4pXQ9ERBTRAULlQA4SSuWa",paypalPlanIdWithTrial:"P-4RG2711469335204VMBFUSQA",paypalPlanIdWithoutTrial:"P-4RG2711469335204VMBFUSQA",paypalAnnualPlanId:"P-4CT412845N5008725NDMSZIA",ireader:{url:"https://read.ireadify.com/ltigateway.htm",consumerKey:"bd2e37cdc25c42a0cc8397951afc8cf1",secretKey:"770a8908cbd043bdcb4a4e6aff6c75de",lisPersonContactEmailPrimary:"[email protected]"}}},89717:function(e,t,r){"use strict";r.r(t),r.d(t,{default:function(){return Ne}});var s=r(47568),n=r(26042),a=r(69396),l=r(70655),i=r(85893),o=r(67294),c=r(11163),d=r(38901),u=r(10552),m=r(44541),x=r(13155),h=r(828),g=r(41664),p=r.n(g),f=r(65964),b=r(39356),v=r(54143),j=r(76624),w=r(36659),y=r(94325),N=r(36209),k=r(87132),C=r(14924),S=r(29815),A=r(62174),L=(0,o.forwardRef)((function(e,t){var r=e.data,s=e.onComplete,l=(0,o.useState)(null),c=l[0],d=l[1],u=(0,o.useState)(null),m=u[0],x=u[1],h=(0,o.useState)([]),g=h[0],p=h[1],f=(0,o.useState)(0),b=f[0],v=f[1],j=(0,o.useState)(0),w=j[0],y=j[1],N=(0,o.useState)([]),k=N[0],C=N[1],L=(0,o.useState)(Date.now()),R=L[0],M=L[1],T=(0,o.useState)({show:!1,correct:!1,message:""}),D=T[0],B=T[1],I=(0,o.useState)([]),Z=I[0],z=I[1],W=(0,o.useState)([]),E=W[0],P=W[1],_=(0,o.useState)(!1),q=_[0],V=_[1];(0,o.useImperativeHandle)(t,(function(){return{getCurrentScore:function(){var e,t=(null===r||void 0===r||null===(e=r.words)||void 0===e?void 0:e.length)||0,s=Math.max(1,w),n=t>0?Math.round(b/s*100):0;return console.log("\ud83d\udcca Partial score: ".concat(b," matches, ").concat(s," attempts = ").concat(n,"%")),Math.min(n,100)},getCurrentTimeSpent:function(){return Math.round((Date.now()-R)/1e3)},getAttemptLog:function(){return k},getGameDetail:function(){return{attempts:k,analytics:(0,A.mK)(k)}}}})),(0,o.useEffect)((function(){var e=(0,S.Z)((null===r||void 0===r?void 0:r.words)||[]),t=(0,S.Z)((null===r||void 0===r?void 0:r.words)||[]).map((function(e){return{word:e.word,meaning:e.meaning,definition:e.meaning}}));z(H(e)),P(H(t)),M(Date.now())}),[r]);var H=function(e){for(var t=(0,S.Z)(e),r=t.length-1;r>0;r--){var s,n=Math.floor(Math.random()*(r+1));s=[t[n],t[r]],t[r]=s[0],t[n]=s[1]}return t},U=function(e,t){var r=e.word===t.word,n=function(e,t,r){var s=t.meaning||t.definition||"";return{word:e.word,question:'Match "'.concat(e.word,'" to its meaning'),correctAnswer:e.meaning||e.definition||"",studentAnswer:s,isCorrect:r,gameType:A.HC.wordMatching,timestamp:(new Date).toISOString(),metadata:{selectedWord:e.word,selectedMeaning:s,pairedWord:t.word}}}(e,t,r);y((function(e){return e+1})),C((function(e){var t=(0,S.Z)(e).concat([n]);return r&&g.length+1===Z.length&&(V(!0),setTimeout((function(){var e=Math.round((Date.now()-R)/1e3),r=Math.round((b+1)/Z.length*100);s(r,e,{attempts:t,analytics:(0,A.mK)(t)})}),1500)),t})),r?(p((function(t){return(0,S.Z)(t).concat([e])})),v((function(e){return e+1})),d(null),x(null),F(!0,'Great! "'.concat(e.word,'" means "').concat(t.meaning||t.definition,'"'))):(F(!1,'Try again! "'.concat(e.word,"\" doesn't match that definition.")),d(null),x(null))},F=function(e,t){B({show:!0,correct:e,message:t}),setTimeout((function(){B({show:!1,correct:!1,message:""})}),2e3)},O=function(e){return g.some((function(t){return t.word===e.word}))},G=function(e,t){return O(e)?"bg-green-100 border-green-500 text-green-800 cursor-not-allowed":(null===c||void 0===c?void 0:c.index)===t?"bg-blue-100 border-blue-500 text-blue-800":"bg-white border-gray-300 text-gray-800 hover:bg-gray-50 cursor-pointer"},Y=function(e,t){return O(e)?"bg-green-100 border-green-500 text-green-800 cursor-not-allowed":(null===m||void 0===m?void 0:m.index)===t?"bg-purple-100 border-purple-500 text-purple-800":"bg-white border-gray-300 text-gray-800 hover:bg-gray-50 cursor-pointer"};return(0,i.jsxs)("div",{className:"max-w-6xl mx-auto p-6",children:[(0,i.jsxs)("div",{className:"mb-6",children:[(0,i.jsx)("h3",{className:"text-2xl font-bold text-gray-800 mb-2",children:"Word Matching"}),(0,i.jsx)("p",{className:"text-gray-600 mb-4",children:(null===r||void 0===r?void 0:r.instructions)||"Match each word to its correct meaning from the story"}),(0,i.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,i.jsxs)("div",{className:"text-sm text-gray-600",children:["Progress: ",g.length," of ",Z.length," matches"]}),(0,i.jsxs)("div",{className:"text-sm text-gray-600",children:["Score: ",b," | Attempts: ",w]})]}),(0,i.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-2 mb-6",children:(0,i.jsx)("div",{className:"bg-gradient-to-r from-blue-500 to-purple-500 h-2 rounded-full transition-all duration-300",style:{width:"".concat(g.length/Z.length*100,"%")}})})]}),(0,i.jsx)("div",{className:"bg-blue-50 border-l-4 border-blue-400 p-4 mb-6 rounded",children:(0,i.jsxs)("div",{className:"flex items-center",children:[(0,i.jsx)("div",{className:"text-blue-600 mr-3",children:(0,i.jsx)("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z",clipRule:"evenodd"})})}),(0,i.jsx)("div",{children:(0,i.jsxs)("p",{className:"text-blue-800 text-sm",children:[(0,i.jsx)("strong",{children:"How to play:"})," Click on a word, then click on its matching definition.",c?" Now click on the correct definition!":" Start by clicking any word!"]})})]})}),(0,i.jsxs)("div",{className:"grid md:grid-cols-2 gap-8",children:[(0,i.jsxs)("div",{children:[(0,i.jsx)("h4",{className:"text-lg font-semibold text-gray-700 mb-4 text-center",children:"Words from the Story"}),(0,i.jsx)("div",{className:"space-y-3",children:Z.map((function(e,t){return(0,i.jsxs)("div",{onClick:function(){return function(e,t){g.some((function(t){return t.word===e.word}))||(d((0,a.Z)((0,n.Z)({},e),{index:t})),x(null))}(e,t)},className:"p-4 border-2 rounded-lg transition-all duration-200 transform hover:scale-105 ".concat(G(e,t)),children:[(0,i.jsx)("div",{className:"font-semibold text-lg",children:e.word}),e.context&&(0,i.jsxs)("div",{className:"text-sm text-gray-600 mt-2 italic",children:['"',e.context,'"']}),O(e)&&(0,i.jsxs)("div",{className:"flex items-center mt-2 text-green-600",children:[(0,i.jsx)("svg",{className:"w-4 h-4 mr-1",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})}),(0,i.jsx)("span",{className:"text-sm font-medium",children:"Matched!"})]})]},"word-".concat(t))}))})]}),(0,i.jsxs)("div",{children:[(0,i.jsx)("h4",{className:"text-lg font-semibold text-gray-700 mb-4 text-center",children:"Meanings"}),(0,i.jsx)("div",{className:"space-y-3",children:E.map((function(e,t){return(0,i.jsxs)("div",{onClick:function(){return function(e,t){g.some((function(t){return t.word===e.word}))||(x((0,a.Z)((0,n.Z)({},e),{index:t})),c&&U(c,e))}(e,t)},className:"p-4 border-2 rounded-lg transition-all duration-200 transform hover:scale-105 ".concat(Y(e,t)),children:[(0,i.jsx)("div",{className:"text-lg",children:e.meaning||e.definition}),O(e)&&(0,i.jsxs)("div",{className:"flex items-center mt-2 text-green-600",children:[(0,i.jsx)("svg",{className:"w-4 h-4 mr-1",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})}),(0,i.jsxs)("span",{className:"text-sm font-medium",children:['Matched with "',e.word,'"!']})]})]},"def-".concat(t))}))})]})]}),D.show&&(0,i.jsx)("div",{className:"fixed top-4 right-4 max-w-sm p-4 rounded-lg shadow-lg z-50 ".concat(D.correct?"bg-green-500 text-white":"bg-red-500 text-white"),children:(0,i.jsxs)("div",{className:"flex items-center",children:[(0,i.jsx)("div",{className:"mr-3",children:D.correct?(0,i.jsx)("svg",{className:"w-6 h-6",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})}):(0,i.jsx)("svg",{className:"w-6 h-6",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})}),(0,i.jsx)("div",{className:"text-sm font-medium",children:D.message})]})}),q&&(0,i.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-[10002]",children:(0,i.jsxs)("div",{className:"bg-white rounded-xl p-8 max-w-md w-full mx-4 text-center",children:[(0,i.jsx)("div",{className:"text-6xl mb-4",children:"\ud83c\udf89"}),(0,i.jsx)("h3",{className:"text-2xl font-bold text-gray-800 mb
1-2",children:"Excellent Work!"}),(0,i.jsxs)("p",{className:"text-gray-600 mb-4",children:["You matched all the words correctly! Final Score: ",Math.round(b/Z.length*100),"%"]}),(0,i.jsx)("div",{className:"animate-pulse text-purple-600",children:"Loading next challenge..."})]})})]})}));L.displayName="WordMatchingGame";var R=L;function M(e){var t=String(null!==e&&void 0!==e?e:"").trim(),r=t.match(/^[A-D][\.\)\:\-]\s*(.+)$/i);return r?r[1].trim():t}function T(e,t){var r,s=String(null!==e&&void 0!==e?e:"").trim();return s?/^[A-D]$/i.test(s)?M(null!==(r=t[s.toUpperCase().charCodeAt(0)-65])&&void 0!==r?r:s):M(s):s}function D(e,t){return String(null!==e&&void 0!==e?e:"").trim().toLowerCase()===String(null!==t&&void 0!==t?t:"").trim().toLowerCase()}function B(e){if(!e)return e;var t,r,s=function(e){if(Array.isArray(e))return e.map((function(e){return M(e)})).filter(Boolean);if(e&&"object"===typeof e){var t,r=["A","B","C","D"].filter((function(t){return null!=e[t]||null!=e[t.toLowerCase()]}));return r.length>0?r.map((function(r){return M(null!==(t=e[r])&&void 0!==t?t:e[r.toLowerCase()])})):Object.values(e).map((function(e){return M(e)})).filter(Boolean)}return"string"===typeof e?e.split(/[,;|]/).map((function(e){return M(e)})).filter(Boolean):[]}(e.options);if(0===s.length)return(0,a.Z)((0,n.Z)({},e),{sentence:null!==(r=null!==(t=e.sentence)&&void 0!==t?t:e.question)&&void 0!==r?r:"",options:[]});var l=T(e.correctAnswer,s);if(!s.some((function(e){return D(e,l)}))){var i=M(e.correctAnswer);i&&s.some((function(e){return D(e,i)}))&&(l=i)}var o,c,d=function(e,t){for(var r=T(t,e),s=(0,S.Z)(e),n=s.length-1;n>0;n--){var a,l=Math.floor(Math.random()*(n+1));a=[s[l],s[n]],s[n]=a[0],s[l]=a[1]}return{options:s,correctAnswer:r}}(s,l),u=d.options,m=d.correctAnswer;return(0,a.Z)((0,n.Z)({},e),{sentence:null!==(c=null!==(o=e.sentence)&&void 0!==o?o:e.question)&&void 0!==c?c:"",options:u,correctAnswer:m})}var I=(0,o.forwardRef)((function(e,t){var r,s,l,c=e.data,d=e.onComplete,u=(0,o.useState)(0),m=u[0],x=u[1],h=(0,o.useState)(null),g=h[0],p=h[1],f=(0,o.useState)([]),b=f[0],v=f[1],j=(0,o.useState)(0),w=j[0],y=j[1],N=(0,o.useState)(Date.now()),k=N[0],C=N[1],L=(0,o.useState)({show:!1,correct:!1,message:""}),R=L[0],M=L[1],T=(0,o.useState)(!1),I=T[0],Z=T[1],z=(0,o.useState)(!1),W=z[0],E=z[1],P=(0,o.useMemo)((function(){var e;return(null===(e=function(e){var t;return(null===e||void 0===e||null===(t=e.questions)||void 0===t?void 0:t.length)?(0,a.Z)((0,n.Z)({},e),{questions:e.questions.map(B)}):e}(c))||void 0===e?void 0:e.questions)||[]}),[c]),_=function(e){return P.map((function(t,r){var s,n,a,l,i=e[r];return{word:null!==(s=t.word)&&void 0!==s?s:null,question:null!==(a=null!==(n=t.sentence)&&void 0!==n?n:t.question)&&void 0!==a?a:"",correctAnswer:t.correctAnswer,studentAnswer:null!==(l=null===i||void 0===i?void 0:i.selected)&&void 0!==l?l:null,isCorrect:!!(null===i||void 0===i?void 0:i.correct),gameType:A.HC.fillInBlanks,timestamp:(new Date).toISOString()}}))};(0,o.useImperativeHandle)(t,(function(){return{getCurrentScore:function(){var e=Math.max(1,m+(null!==g?1:0)),t=Math.round(w/e*100);return console.log("\ud83d\udcca Partial score: ".concat(w,"/").concat(e," = ").concat(t,"%")),t},getCurrentTimeSpent:function(){return Math.round((Date.now()-k)/1e3)},getAttemptLog:function(){return _(b)},getGameDetail:function(){var e=_(b);return{attempts:e,analytics:(0,A.mK)(e)}}}})),(0,o.useEffect)((function(){C(Date.now())}),[]);var q=function(e,t){M({show:!0,correct:e,message:t}),setTimeout((function(){M({show:!1,correct:!1,message:""})}),3500)},V=function(e){if(null===g&&!W)return"bg-white border-gray-300 text-gray-800 hover:bg-blue-50 hover:border-blue-300 cursor-pointer";var t=P[m],r=t.options[e];return g===e?D(r,t.correctAnswer)?"bg-green-100 border-green-500 text-green-800 cursor-not-allowed":"bg-red-100 border-red-500 text-red-800 cursor-not-allowed":D(r,t.correctAnswer)?"bg-green-100 border-green-500 text-green-800 cursor-not-allowed":"bg-gray-100 border-gray-300 text-gray-500 cursor-not-allowed"};return 0===P.length?(0,i.jsxs)("div",{className:"text-center p-8",children:[(0,i.jsx)("div",{className:"text-red-500 mb-4",children:(0,i.jsx)("svg",{className:"w-12 h-12 mx-auto",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})}),(0,i.jsx)("h3",{className:"text-lg font-semibold text-gray-800 mb
1-2",children:"No Questions Available"}),(0,i.jsx)("p",{className:"text-gray-600",children:"Unable to generate fill-in-the-blank questions from this book."})]}):(0,i.jsxs)("div",{className:"max-w-4xl mx-auto p-6",children:[(0,i.jsxs)("div",{className:"mb-8",children:[(0,i.jsx)("h3",{className:"text-2xl font-bold text-gray-800 mb-2",children:"Fill in the Blanks"}),(0,i.jsx)("p",{className:"text-gray-600 mb-4",children:(null===c||void 0===c?void 0:c.instructions)||"Complete each sentence with the best word from the story"}),(0,i.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,i.jsxs)("div",{className:"text-sm text-gray-600",children:["Question ",m+1," of ",P.length]}),(0,i.jsxs)("div",{className:"text-sm text-gray-600",children:["Score: ",w," / ",P.length]})]}),(0,i.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-3",children:(0,i.jsx)("div",{className:"bg-gradient-to-r from-blue-500 to-green-500 h-3 rounded-full transition-all duration-300",style:{width:"".concat(m/P.length*100,"%")}})})]}),(0,i.jsxs)("div",{className:"bg-white rounded-xl border border-gray-200 shadow-lg overflow-hidden",children:[(0,i.jsx)("div",{className:"py-8 bg-gradient-to-br from-blue-50 to-indigo-50 border-b border-gray-100",children:function(e){var t=function(e){if(!e||"string"!==typeof e)return null;var t=e.match(RegExp("^(.*?)(_{2,})(.*)$","s"));return t?[t[1],t[3]]:null}(e);if(!t)return(0,i.jsx)("p",{className:"text-xl text-gray-800 text-center px-4",children:e});var r=W&&null!==g?P[m].options[g]:"";return(0,i.jsx)("div",{className:"max-w-4xl mx-auto px-4",children:(0,i.jsx)("div",{className:"bg-gradient-to-br from-slate-50 to-slate-100 rounded-2xl p-8 border border-slate-200 shadow-sm",children:(0,i.jsxs)("div",{className:"text-center space-y-6",children:[(0,i.jsx)("div",{className:"text-xl md:text-2xl leading-relaxed text-gray-800 font-medium",style:{textDecoration:"none"},children:(0,i.jsxs)("div",{className:"flex flex-wrap items-center justify-center gap-4",style:{textDecorationLine:"none"},children:[(0,i.jsx)("span",{className:"text-slate-700",style:{textDecoration:"none"},children:t[0].trim()}),(0,i.jsx)("div",{className:"inline-block",children:(0,i.jsx)("div",{className:"\n                                        px-8 py-4 rounded-2xl font-bold text-xl transition-all duration-300 min-w-[160px] text-center border-2\n                                        ".concat(W&&null!==g?"bg-gradient-to-r from-blue-500 to-blue-600 text-white shadow-xl border-blue-600 transform scale-110":"bg-gradient-to-br from-blue-50 to-blue-100 text-blue-600 border-blue-300 shadow-lg hover:shadow-xl hover:from-blue-100 hover:to-blue-150","\n                                    "),children:(0,i.jsx)("span",{className:"block",style:{textDecoration:"none !important",textDecorationLine:"none !important"},children:r||"?"})})}),(0,i.jsx)("span",{className:"text-slate-700",style:{textDecoration:"none"},children:t[1].trim()})]})}),(0,i.jsx)("div",{className:"text-sm text-slate-500 italic",children:W?"Answer revealed!":"Choose the best word to complete the sentence"})]})})})}(P[m].sentence)}),(0,i.jsx)("div",{className:"p-8",children:(0,i.jsx)("div",{className:"grid gap-4 md:grid-cols-2",children:P[m].options.map((function(e,t){return(0,i.jsx)("button",{type:"button",onClick:function(){return function(e){if(null===g&&!W){var t=P[m],r=t.options[e],s=D(r,t.correctAnswer);p(e),s?(y((function(e){return e+1})),q(!0,'Correct! "'.concat(r,'" fits perfectly in this sentence.'))):q(!1,'Not quite. The correct answer is "'.concat(t.correctAnswer,'".'));var n=(0,S.Z)(b);n[m]={selected:r,correct:s,correctAnswer:t.correctAnswer},v(n),E(!0),setTimeout((function(){m<P.length-1?(x(m+1),p(null),E(!1)):(Z(!0),setTimeout((function(){var e=Math.round((Date.now()-k)/1e3),t=n.filter((function(e){return null===e||void 0===e?void 0:e.correct})).length,r=Math.round(t/P.length*100),s=_(n);d(r,e,{attempts:s,analytics:(0,A.mK)(s)})}),1500))}),4e3)}}(t)},disabled:null!==g,className:"p-4 rounded-lg border-2 transition-all duration-200 transform hover:scale-105 text-left font-medium ".concat(V(t)),children:(0,i.jsxs)("div",{className:"flex items-center",children:[(0,i.jsx)("div",{className:"w-8 h-8 rounded-full border-2 border-current flex items-center justify-center mr-4 text-sm font-bold",children:String.fromCharCode(65+t)}),(0,i.jsx)("div",{children:e})]})},t)}))})}),W&&(0,i.jsx)("div",{className:"mx-8 mb-6 p-6 rounded-lg bg-gradient-to-r from-gray-50 to-gray-100 border-l-4 border-blue-400 shadow-sm",children:(0,i.jsxs)("div",{className:"flex items-start ".concat((null===(r=b[m])||void 0===r?void 0:r.correct)?"text-green-700":"text-orange-700"),
1children:[(0,i.jsx)("div",{className:"mr-3 mt-1 p-1 rounded-full bg-white shadow-sm",children:(null===(s=b[m])||void 0===s?void 0:s.correct)?(0,i.jsx)("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})}):(0,i.jsx)("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})}),(0,i.jsx)("div",{className:"text-base font-medium leading-relaxed",children:(null===(l=b[m])||void 0===l?void 0:l.correct)?'Excellent! "'.concat(P[m].correctAnswer,'" is the perfect word for this context.'):'The correct answer is "'.concat(P[m].correctAnswer,'". This word fits the meaning of the sentence from the story.')})]})}),W&&m<P.length-1&&(0,i.jsxs)("div",{className:"mx-8 pb-6 text-center text-gray-600",children:[(0,i.jsx)("div",{className:"animate-pulse mb-2",children:"Next question in a moment..."}),(0,i.jsx)("div",{className:"text-xs text-gray-500",children:"Take time to read the explanation above"})]})]}),R.show&&(0,i.jsx)("div",{className:"fixed top-4 right-4 max-w-sm p-4 rounded-lg shadow-lg z-50 ".concat(R.correct?"bg-green-500 text-white":"bg-red-500 text-white"),children:(0,i.jsxs)("div",{className:"flex items-center",children:[(0,i.jsx)("div",{className:"mr-3",children:R.correct?(0,i.jsx)("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})}):(0,i.jsx)("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})}),(0,i.jsx)("div",{children:R.message})]})}),I&&(0,i.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-[10002]",children:(0,i.jsxs)("div",{className:"bg-white rounded-xl p-8 max-w-md w-full mx-4 text-center",children:[(0,i.jsx)("div",{className:"text-6xl mb-4",children:"\ud83d\udcdd"}),(0,i.jsx)("h3",{className:"text-2xl font-bold text-gray-800 mb-2",children:"Sentences Complete!"}),(0,i.jsxs)("p",{className:"text-gray-600 mb-4",children:["You've finished all the fill-in-the-blank questions! Final Score: ",Math.round(w/P.length*100),"%"]}),(0,i.jsx)("div",{className:"animate-pulse text-blue-600",children:"Moving to next game..."})]})})]})}));I.displayName="FillInBlanksGame";var Z=I,z=(0,o.forwardRef)((function(e,t){var r,s,n,a,l,c,d,u=e.data,m=e.onComplete,x=(0,o.useState)(0),h=x[0],g=x[1],p=(0,o.useState)(null),f=p[0],b=p[1],v=(0,o.useState)([]),j=v[0],w=v[1],y=(0,o.useState)(0),N=y[0],k=y[1],C=(0,o.useState)(Date.now()),L=C[0],R=C[1],M=(0,o.useState)({show:!1,correct:!1,message:""}),T=M[0],D=M[1],B=(0,o.useState)(!1),I=B[0],Z=B[1],z=(0,o.useState)(!1),W=z[0],E=z[1],P=(0,o.useState)(30),_=P[0],q=P[1],V=(0,o.useState)(!0),H=V[0],U=V[1],F=(null===u||void 0===u?void 0:u.questions)||[],O=function(e){return F.map((function(t,r){var s,n,a,l=e[r];return{word:null!==(n=t.word)&&void 0!==n?n:null,question:(null===(s=t.question)||void 0===s?void 0:s.replace(/\\'/g,"'"))||t.question||"",correctAnswer:t.correctAnswer,studentAnswer:(null===l||void 0===l?void 0:l.timedOut)?null:null!==(a=null===l||void 0===l?void 0:l.selected)&&void 0!==a?a:null,isCorrect:!!(null===l||void 0===l?void 0:l.correct),gameType:A.HC.vocabularyQuiz,timestamp:(new Date).toISOString(),metadata:{options:t.options,timedOut:!!(null===l||void 0===l?void 0:l.timedOut)}}}))};(0,o.useImperativeHandle)(t,(function(){return{getCurrentScore:function(){var e=Math.max(1,h+(null!==f?1:0)),t=Math.round(N/e*100);return console.log("\ud83d\udcca Partial score: ".concat(N,"/").concat(e," = ").concat(t,"%")),t},getCurrentTimeSpent:function(){return Math.round((Date.now()-L)/1e3)},getAttemptLog:function(){return O(j)},getGameDetail:function(){var e=O(j);return{attempts:e,analytics:(0,A.mK)(e)}}}})),(0,o.useEffect)((function(){R(Date.now())}),[]),(0,o.useEffect)((function(){if(H&&!W&&null===f){var e=setInterval((function(){q((function(e){return e<=1?(G(),0):e-1}))}),1e3);return function(){return clearInterval(e)}}}),[h,H,W,f]);var G=function(){b(-1);var e=F[h].correctAnswer;Q(!1,"Time's up! The correct answer was \"".concat(e,'".'));var t=(0,S.Z)(j);t[h]={selected:null,correct:!1,correctAnswer:e,timedOut:!0},w(t),E(!0),U(!1),setTimeout((function(){Y(t)}),3e3)},Y=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:j;h<F.length-1?(g(h+1),b(null),E(!1),q(30),U(!0)):(Z(!0),setTimeout((function(){var t=Math.round((Date.now()-L)/1e3),r=Math.round(N/F.length*100),s=O(e);m(r,t,{attempts:s,analytics:(0,A.mK)(s)})}),2e3))},Q=function(e,t){D({show:!0,correct:e,message:t}),setTimeout((function(){D({show:!1,correct:!1,message:""})}),3e3)},$=function(e){if(null===f&&!W)return"bg-white border-gray-300 text-gray-800 hover:bg-purple-50 hover:border-purple-300 cursor-pointer";var t=F[h],r=t.options[e];return f===e?r===t.correctAnswer?"bg-green-100 border-green-500 text-green-800 cursor-not-allowed":"bg-red-100 border-red-500 text-red-800 cursor-not-allowed":r===t.correctAnswer?"bg-green-100 border-green-500 text-green-800 cursor-not-allowed":"bg-gray-100 border-gray-300 text-gray-500 cursor-not-allowed"};return 0===F.length?(0,i.jsxs)("div",{className:"text-center p-8",children:[(0,i.jsx)("div",{className:"text-red-500 mb-4",children:(0,i.jsx)("svg",{className:"w-12 h-12 mx-auto",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})}),(0,i.jsx)("h3",{className:"text-lg font-semibold text-gray-800 mb
1-2",children:"No Questions Available"}),(0,i.jsx)("p",{className:"text-gray-600",children:"Unable to generate vocabulary quiz questions from this book."})]}):(0,i.jsxs)("div",{className:"max-w-4xl mx-auto p-6",children:[(0,i.jsxs)("div",{className:"mb-8",children:[(0,i.jsx)("h3",{className:"text-2xl font-bold text-gray-800 mb-2",children:"Vocabulary Quiz"}),(0,i.jsx)("p",{className:"text-gray-600 mb-4",children:(null===u||void 0===u?void 0:u.instructions)||"Choose the best answer based on how words are used in the story"}),(0,i.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,i.jsxs)("div",{className:"text-sm text-gray-600",children:["Question ",h+1," of ",F.length]}),(0,i.jsxs)("div",{className:"text-sm text-gray-600",children:["Score: ",N," / ",F.length]}),(0,i.jsx)("div",{className:"text-lg font-bold ".concat(_>20?"text-green-600":_>10?"text-yellow-600":"text-red-600"),children:H&&!W&&null===f?(0,i.jsxs)("div",{className:"flex items-center",children:[(0,i.jsx)("svg",{className:"w-5 h-5 mr-1",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm1-12a1 1 0 10-2 0v4a1 1 0 00.293.707l2.828 2.829a1 1 0 101.415-1.415L11 9.586V6z",clipRule:"evenodd"})}),_,"s"]}):"\u23f8\ufe0f"})]}),(0,i.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-3",children:(0,i.jsx)("div",{className:"bg-gradient-to-r from-purple-500 to-pink-500 h-3 rounded-full transition-all duration-300",style:{width:"".concat(h/F.length*100,"%")}})})]}),(0,i.jsxs)("div",{className:"bg-white rounded-xl border border-gray-200 shadow-lg p-8",children:[(null===(r=F[h])||void 0===r?void 0:r.context)&&(0,i.jsx)("div",{className:"bg-purple-50 border-l-4 border-purple-400 p-4 mb-6 rounded",children:(0,i.jsxs)("p",{className:"text-purple-800 text-sm",children:[(0,i.jsx)("strong",{children:"Context from story:"})," ",F[h].context]})}),(0,i.jsxs)("div",{className:"text-center mb-8",children:[(null===(s=F[h])||void 0===s?void 0:s.word)&&(0,i.jsxs)("div",{className:"bg-gradient-to-r from-purple-100 to-blue-100 rounded-lg p-4 mb-4 border border-purple-200",children:[(0,i.jsx)("div",{className:"text-sm text-purple-600 font-medium mb-1",children:"Vocabulary Word:"}),(0,i.jsx)("div",{className:"text-xl font-bold text-purple-800",children:F[h].word})]}),(0,i.jsx)("h4",{className:"text-2xl font-semibold text-gray-800 mb-4",children:(null===(n=F[h].question)||void 0===n?void 0:n.replace(/\\'/g,"'"))||F[h].question}),H&&!W&&null===f&&(0,i.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-2 mb-4",children:(0,i.jsx)("div",{className:"h-2 rounded-full transition-all duration-1000 ".concat(_>20?"bg-green-500":_>10?"bg-yellow-500":"bg-red-500"),style:{width:"".concat(_/30*100,"%")}})})]}),(0,i.jsx)("div",{className:"grid gap-4 md:grid-cols-2",children:F[h].options.map((function(e,t){return(0,i.jsx)("button",{onClick:function(){return function(e){if(null===f&&!W){b(e),U(!1);var t=F[h],r=t.options[e],s=r===t.correctAnswer;s?(k(N+1),Q(!0,"Excellent! That's the correct meaning based on the story context.")):Q(!1,'Not quite. The correct answer is "'.concat(t.correctAnswer,'".'));var n=(0,S.Z)(j);n[h]={selected:r,correct:s,correctAnswer:t.correctAnswer},w(n),E(!0),setTimeout((function(){Y(n)}),3e3)}}(t)},disabled:null!==f,className:"p-6 rounded-lg border-2 transition-all duration-200 transform hover:scale-105 text-left font-medium ".concat($(t)),children:(0,i.jsxs)("div",{className:"flex items-center",children:[(0,i.jsx)("div",{className:"w-8 h-8 rounded-full border-2 border-current flex items-center justify-center mr-4 text-sm font-bold",children:String.fromCharCode(65+t)}),(0,i.jsx)("div",{children:e})]})},t)}))}),W&&(0,i.jsx)("div",{className:"mt-6 p-4 rounded-lg bg-gray-50 border",children:(0,i.jsxs)("div",{className:"flex items-start ".concat((null===(a=j[h])||void 0===a?void 0:a.correct)?"text-green-700":"text-red-700"),children:[(0,i.jsx)("div",{className:"mr-2 mt-1",children:(null===(l=j[h])||void 0===l?void 0:l.correct)?(0,i.jsx)("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})}):(0,i.jsx)("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})}),(0,i.jsx)("div",{className:"text-sm",children:(null===(c=j[h])||void 0===c?void 0:c.correct)?'Perfect! Based on the story context, "'.concat(j[h].correctAnswer,'" is indeed the right meaning.'):(null===(d=j[h])||void 0===d?void 0:d.timedOut)?'Time ran out! The correct answer was "'.concat(j[h].correctAnswer,'". Try to read faster next time!'):'The correct answer is "'.concat(j[h].correctAnswer,'". This meaning fits better with how the word is used in the story.')})]})}),W&&h<F.length-1&&(0,i.jsx)("div",{className:"mt-4 text-center text-gray-600",children:(0,i.jsx)("div",{className:"animate-pulse",children:"Preparing next question..."})})]}),T.show&&(0,i.jsx)("div",{className:"fixed top-4 right-4 max-w-sm p-4 rounded-lg shadow-lg z-50 ".concat(T.correct?"bg-green-500 text-white":"bg-red-500 text-white"),children:(0,i.jsxs)("div",{className:"flex items-center",children:[(0,i.jsx)("div",{className:"mr-3",children:T.correct?(0,i.jsx)("svg",{className:"w-6 h-6",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})}):(0,i.jsx)("svg",{className:"w-6 h-6",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})}),(0,i.jsx)("div",{className:"text-sm font-medium",children:T.message})]})}),I&&(0,i.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-[10002]",children:(0,i.jsxs)("div",{className:"bg-white rounded-xl p-8 max-w-md w-full mx-4 text-center",children:[(0,i.jsx)("div",{className:"text-6xl mb-4",children:"\ud83e\udde0"}),(0,i.jsx)("h3",{className:"text-2xl font-bold text-gray-800 mb
1-2",children:"Quiz Complete!"}),(0,i.jsxs)("p",{className:"text-gray-600 mb-4",children:["You've finished the vocabulary quiz! Final Score: ",Math.round(N/F.length*100),"%"]}),(0,i.jsx)("div",{className:"animate-pulse text-purple-600",children:"Calculating final results..."})]})})]})}));z.displayName="VocabularyQuizGame";var W=z,E=r(82222),P=r(4287),_=function(e){var t=e.gameResults,r=e.bookTitle,s=e.onClose,n=e.onSaveComplete,a=function(e){var t=Math.floor(e/60),r=e%60;return t>0?"".concat(t,"m ").concat(r,"s"):"".concat(r,"s")},l=(0,o.useState)(!0),c=l[0],d=l[1],u=(0,o.useState)(!1),m=u[0],x=u[1],g=(0,o.useState)(!1),p=g[0],f=g[1];(0,o.useEffect)((function(){return document.body.style.overflow="hidden",function(){document.body.style.overflow="unset"}}),[]);var b=function(){document.body.style.overflow="unset",s()},v=t.totalGames||0,j=t.totalGamesAttempted||3,w=t.individual?Math.round(Object.values(t.individual).reduce((function(e,t){return e+(t.skipped?0:t.score)}),0)/(v||1)):t.averageScore||0,y=t.totalTime||0,N=a(y),k=t.analytics,C=!!k,S={wordMatching:{name:"Word Matching",icon:"\ud83d\udd17",color:"bg-blue-500",description:"Connected words with meanings"},fillInBlanks:{name:"Fill in the Blanks",icon:"\ud83d\udcdd",color:"bg-green-500",description:"Completed story sentences"},vocabularyQuiz:{name:"Vocabulary Quiz",icon:"\ud83e\udde0",color:"bg-purple-500",description:"Answered context questions"},storySequencing:{name:"Sequence Quest",icon:"\ud83d\udd52",color:"bg-purple-500",description:"Comprehension check \u2014 story order"}},A=[];return t.achievements&&t.achievements.length>0?(console.log("\ud83c\udfc5 Raw achievements from gameResults:",t.achievements),A=t.achievements.map((function(e){if(console.log("\ud83d\udd0d Processing achievement:",e,"Type:","undefined"===typeof e?"undefined":(0,E.Z)(e)),"string"!==typeof e)return"object"===typeof e&&e.icon&&e.title?(console.log("\u2705 Achievement already in correct format:",e),e):(console.log("\u26a0\ufe0f Unexpected achievement format, using fallback:",e),{icon:"\ud83c\udfc6",title:"Achievement",description:"Well done!",color:"text-yellow-600 bg-yellow-100"});try{var t=JSON.parse(e);return console.log("\u2705 Parsed achievement:",t),t}catch(r){return console.log("\u26a0\ufe0f Failed to parse, creating fallback for:",e),{icon:"\ud83c\udfc6",title:e.replace(/[{}]/g,""),description:"Achievement earned!",color:"text-yellow-600 bg-yellow-100"}}}))):(console.log("\ud83d\udcca No achievements in gameResults, calculating fresh ones"),A=function(e){var t=[],r=e.individual&&Object.values(e.individual).filter((function(e){return!e.skipped})).length||1,s=e.individual?Math.round(Object.values(e.individual).reduce((function(e,t){return e+(t.skipped?0:t.score)}),0)/r):e.averageScore||0;if(s>=90?t.push({title:"Vocabulary Master!",description:"Scored 90% or higher",icon:"\ud83c\udfc6",color:"text-yellow-600 bg-yellow-100"}):s>=75?t.push({title:"Word Expert",description:"Scored 75% or higher",icon:"\ud83c\udf1f",color:"text-purple-600 bg-purple-100"}):s>=50&&t.push({title:"Good Progress",description:"Keep practicing!",icon:"\ud83d\udc4d",color:"text-green-600 bg-green-100"}),e.totalTime&&(e.totalTime<180?t.push({title:"Lightning Fast!",description:"Completed in under 3 minutes",icon:"\ud83d\ude80",color:"text-red-600 bg-red-100"}):e.totalTime<300&&t.push({title:"Speed Reader!",description:"Completed in under 5 minutes",icon:"\u26a1",color:"text-blue-600 bg-blue-100"})),e.individual){var n=Object.values(e.individual).filter((function(e){return e.score>=100})).length;n>0&&t.push({title:n===r?"Perfect Score!":"Flawless Game",description:n===r?"100% on all games!":"Perfect score on ".concat(n," game").concat(n>1?"s":""),icon:"\ud83d\udcaf",color:"text-red-600 bg-red-100"})}return t}(t)),console.log("\ud83c\udfc5 Final achievements for display:",A),(0,o.useEffect)((function(){var e=setTimeout((function(){d(!1),x(!0),n&&n(t)}),2e3);return function(){return clearTimeout(e)}}),[t,n]),c?(0,i.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-[10001]",children:(0,i.jsxs)("div",{className:"bg-white rounded-xl p-8 max-w-md w-full mx-4 text-center",children:[(0,i.jsxs)("div",{className:"relative mb-6",children:[(0,i.jsx)("div",{className:"animate-spin rounded-full h-16 w-16 border-b-2 border-purple-600 mx-auto"}),(0,i.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,i.jsx)("span",{className:"text-2xl",children:"\ud83d\udcbe"})})]}),(0,i.jsx)("h3",{className:"text-xl font-semibold text-gray-800 mb
1-2",children:"Saving Your Results"}),(0,i.jsx)("p",{className:"text-gray-600",children:"Recording your vocabulary progress..."})]})}):(0,i.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-[10001] p-2 sm:p-4",children:(0,i.jsxs)("div",{className:"bg-white rounded-xl shadow-2xl w-full max-w-4xl max-h-[95vh] overflow-hidden mx-2 sm:mx-4 flex flex-col",children:[(0,i.jsxs)("div",{className:"bg-gradient-to-r from-green-500 via-blue-500 to-purple-600 text-white p-4 sm:p-6 flex-shrink-0 relative",children:[(0,i.jsx)("button",{onClick:b,className:"absolute top-4 right-4 text-white hover:text-gray-200 transition-colors","aria-label":"Close",children:(0,i.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,i.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),(0,i.jsxs)("div",{className:"text-center",children:[(0,i.jsx)("div",{className:"text-4xl sm:text-6xl mb-2",children:"\ud83c\udf89"}),(0,i.jsx)("h2",{className:"text-xl sm:text-3xl font-bold mb-2",children:"Congratulations!"}),(0,i.jsxs)("p",{className:"text-green-100 text-sm sm:text-base px-2",children:["You've completed all vocabulary games for \"",r,'"']}),m&&(0,i.jsxs)("div",{className:"mt-2 flex items-center justify-center text-green-200",children:[(0,i.jsx)("svg",{className:"w-4 h-4 sm:w-5 sm:h-5 mr-2",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})}),(0,i.jsx)("span",{className:"text-xs sm:text-sm font-medium",children:"Progress Saved!"})]})]})]}),(0,i.jsx)("div",{className:"flex-1 overflow-y-auto",children:(0,i.jsxs)("div",{className:"p-4 sm:p-6 pb-6 sm:pb-8",children:[(0,i.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4 sm:gap-6 mb-6 sm:mb-8",children:[(0,i.jsxs)("div",{className:"text-center bg-gradient-to-br from-blue-50 to-purple-50 rounded-xl p-4 sm:p-6 border border-blue-200",children:[(0,i.jsx)("div",{className:"text-3xl sm:text-4xl mb-2",children:"\ud83c\udfc6"}),(0,i.jsxs)("div",{className:"text-2xl sm:text-3xl font-bold text-blue-600 mb-1",children:[w,"%"]}),(0,i.jsx)("div",{className:"text-gray-600 font-medium text-sm sm:text-base",children:"Overall Score"})]}),(0,i.jsxs)("div",{className:"text-center bg-gradient-to-br from-green-50 to-blue-50 rounded-xl p-4 sm:p-6 border border-green-200",children:[(0,i.jsx)("div",{className:"text-3xl sm:text-4xl mb-2",children:"\u23f1\ufe0f"}),(0,i.jsx)("div",{className:"text-2xl sm:text-3xl font-bold text-green-600 mb-1",children:N}),(0,i.jsx)("div",{className:"text-gray-600 font-medium text-sm sm:text-base",children:"Time Spent"})]}),(0,i.jsxs)("div",{className:"text-center bg-gradient-to-br from-purple-50 to-pink-50 rounded-xl p-4 sm:p-6 border border-purple-200",children:[(0,i.jsx)("div",{className:"text-3xl sm:text-4xl mb-2",children:"\ud83c\udfae"}),(0,i.jsx)("div",{className:"text-2xl sm:text-3xl font-bold text-purple-600 mb-1",children:v}),(0,i.jsx)("div",{className:"text-gray-600 font-medium text-sm sm:text-base",children:"Games Completed"}),j>v&&(0,i.jsxs)("div",{className:"text-xs text-gray-500 mt-1",children:[j-v," skipped"]})]})]}),(C||t.gameData)&&(0,i.jsx)("div",{className:"mb-6 sm:mb-8",children:(0,i.jsx)(P.ZP,{analytics:k,gameResult:t.gameData?{gameData:t.gameData}:t,studentLabel:"Your"})}),A.length>0&&(0,i.jsxs)("div",{className:"mb-6 sm:mb-8",children:[(0,i.jsx)("h3",{className:"text-lg sm:text-xl font-semibold text-gray-800 mb-3 sm:mb-4 text-center",children:"\ud83c\udfc5 Achievements Earned"}),(0,i.jsx)("div",{className:"grid gap-3 sm:gap-4 grid-cols-1 sm:grid-cols-2 lg:grid-cols-3",children:A.map((function(e,t){return(0,i.jsxs)("div",{className:"".concat(e.color||"text-yellow-600 bg-yellow-100"," rounded-lg p-3 sm:p-4 text-center border"),children:[(0,i.jsx)("div",{className:"text-xl sm:text-2xl mb-2",children:e.icon||"\ud83c\udfc6"}),(0,i.jsx)("div",{className:"font-semibold mb-1 text-sm sm:text-base",children:e.title||"Achievement"}),(0,i.jsx)("div",{className:"text-xs sm:text-sm opacity-80",children:e.description||"Well done!"})]},t)}))})]}),(0,i.jsx)("div",{className:"text-center mb-4 sm:mb-6",children:(0,i.jsxs)("button",{onClick:function(){return f(!p)},className:"inline-flex items-center px-3 sm:px-4 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 transition-colors text-sm sm:text-base",children:[(0,i.jsx)("span",{className:"mr-2",children:p?"\ud83d\udc41\ufe0f Hide Details":"\ud83d\udcca Show Game Details"}),(0,i.jsx)("svg",{className:"w-4 h-4 transform transition-transform ".concat(p?"rotate-180":""),fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z",clipRule:"evenodd"})})]})}),p&&t.individual&&(0,i.jsxs)("div",{className:"bg-gray-50 rounded-xl p-4 sm:p-6 mb-4 sm:mb-6",children:[(0,i.jsx)("h4",{className:"text-base sm:text-lg font-semibold text-gray-800 mb
1-3 sm:mb-4",children:"Individual Game Results"}),(0,i.jsx)("div",{className:"space-y-3 sm:space-y-4",children:Object.entries(t.individual).map((function(e){var t=(0,h.Z)(e,2),r=t[0],s=t[1],n=S[r];if(!n)return null;var l=s.skipped;s.completed&&s.skipped;return(0,i.jsx)("div",{className:"bg-white rounded-lg p-3 sm:p-4 border ".concat(l?"border-gray-300 bg-gray-50":"border-gray-200"),children:(0,i.jsxs)("div",{className:"flex items-center justify-between",children:[(0,i.jsxs)("div",{className:"flex items-center min-w-0 flex-1",children:[(0,i.jsx)("span",{className:"text-xl sm:text-2xl mr-2 sm:mr-3 flex-shrink-0 ".concat(l?"grayscale opacity-50":""),children:n.icon}),(0,i.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,i.jsx)("div",{className:"font-semibold text-sm sm:text-base truncate ".concat(l?"text-gray-500":"text-gray-800"),children:n.name}),(0,i.jsx)("div",{className:"text-xs sm:text-sm truncate ".concat(l?"text-gray-400":"text-gray-600"),children:l?s.partial?"Partially completed (skipped)":"Game was skipped":n.description})]})]}),(0,i.jsxs)("div",{className:"text-right flex-shrink-0 ml-2",children:[l?(0,i.jsx)("div",{className:"space-y-1",children:s.partial&&s.score>0?(0,i.jsxs)("div",{className:"inline-flex items-center px-2 sm:px-3 py-1 rounded-full text-xs sm:text-sm font-medium bg-orange-400 text-white",children:[s.score,"% (partial)"]}):(0,i.jsx)("div",{className:"inline-flex items-center px-2 sm:px-3 py-1 rounded-full text-xs sm:text-sm font-medium bg-gray-400 text-white",children:"Skipped"})}):(0,i.jsxs)("div",{className:"inline-flex items-center px-2 sm:px-3 py-1 rounded-full text-xs sm:text-sm font-medium ".concat(n.color," text-white"),children:[s.score,"%"]}),(0,i.jsx)("div",{className:"text-xs text-gray-500 mt-1",children:l?s.timeSpent>0?a(s.timeSpent):"--":a(s.timeSpent)})]})]})},r)}))})]}),(0,i.jsx)("div",{className:"flex justify-center px-2",children:(0,i.jsx)("button",{onClick:b,className:"px-6 sm:px-8 py-3 bg-purple-600 text-white rounded-lg font-medium hover:bg-purple-700 transition-colors shadow-lg hover:shadow-xl transform hover:scale-105 text-sm sm:text-base",children:"\ud83c\udfaf Continue Reading"})}),(0,i.jsx)("div",{className:"text-center mt-4 sm:mt-6 p-3 sm:p-4 bg-blue-50 rounded-lg border border-blue-200 mx-2",children:(0,i.jsx)("p",{className:"text-blue-800 font-medium text-sm sm:text-base",children:"\ud83c\udf1f Great job expanding your vocabulary! Keep reading to discover new words and improve your language skills."})})]})})]})})},q=function(e){var t=e.gameResults,r=e.bookTitle,s=e.onClose,n=(e.onPlayAgain,function(e){if(!e)return"0s";var t=Math.floor(e/60),r=e%60;return t>0?"".concat(t,"m ").concat(r,"s"):"".concat(r,"s")}),a=(0,o.useState)(!1),l=a[0],c=a[1];(0,o.useEffect)((function(){return document.body.style.overflow="hidden",function(){document.body.style.overflow="unset"}}),[]);var d=function(){document.body.style.overflow="unset",s()},u=t.averageScore||0,m=t.totalTime||0,x=n(m),g=function(e){if(!e)return"Unknown date";var t=new Date(e),r=new Date-t,s=Math.floor(r/864e5),n=Math.floor(r/36e5),a=Math.floor(r/6e4);return a<1?"Just now":n<1?"".concat(a," minute").concat(a>1?"s":""," ago"):s<1?"".concat(n," hour").concat(n>1?"s":""," ago"):1===s?"Yesterday":s<7?"".concat(s," days ago"):t.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}(t.completedAt),p={wordMatching:{name:"Word Matching",icon:"\ud83d\udd17",color:"bg-blue-500",description:"Connected words with meanings"},fillInBlanks:{name:"Fill in the Blanks",icon:"\ud83d\udcdd",color:"bg-green-500",description:"Completed story sentences"},vocabularyQuiz:{name:"Vocabulary Quiz",icon:"\ud83e\udde0",color:"bg-purple-500",description:"Answered context questions"},storySequencing:{name:"Sequence Quest",icon:"\ud83d\udcd6",color:"bg-indigo-500",description:"Completed the Sequence Quest"}};return(0,i.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-[10001] p-2 sm:p-4",children:(0,i.jsxs)("div",{className:"bg-white rounded-xl shadow-2xl w-full max-w-4xl max-h-[95vh] overflow-hidden mx-2 sm:mx-4 flex flex-col",children:[(0,i.jsxs)("div",{className:"bg-gradient-to-r from-orange-500 via-purple-500 to-blue-600 text-white p-4 sm:p-6 flex-shrink-0 relative",children:[(0,i.jsx)("button",{onClick:d,className:"absolute top-4 right-4 text-white hover:text-gray-200 transition-colors","aria-label":"Close",children:(0,i.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,i.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),(0,i.jsxs)("div",{className:"text-center",children:[(0,i.jsx)("div",{className:"text-4xl sm:text-6xl mb-2",children:"\ud83d\udcda"}),(0,i.jsx)("h2",{className:"text-xl sm:text-3xl font-bold mb-2",children:"Previous Results"}),(0,i.jsxs)("p",{className:"text-orange-100 text-sm sm:text-base px-2",children:["You've already completed vocabulary games for \"",r,'"']}),(0,i.jsx)("div",{className:"mt-2 text-orange-200 text-xs sm:text-sm",children:("Just now"===g||g.includes("minute")||g.includes("hour"),"Completed ".concat(g))})]})]}),(0,i.jsx)("div",{className:"flex-1 overflow-y-auto",children:(0,i.jsxs)("div",{className:"p-4 sm:p-6 pb-6 sm:pb-8",children:[(0,i.jsx)("div",{className:"bg-yellow-50 border-l-4 border-yellow-400 p-4 mb-6 rounded",children:(0,i.jsxs)("div",{className:"flex items-center",children:[(0,i.jsx)("div",{className:"text-2xl mr-3",children:"\ud83c\udfaf"}),(0,i.jsxs)("div",{children:[(0,i.jsx)("h3",{className:"text-yellow-800 font-semibold",children:"One Challenge Per Book"}),(0,i.jsx)("p",{className:"text-yellow-700 text-sm",children:"You can only complete the vocabulary challenge once for each book. Here are your previous results!"})]})]})}),(0,i.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4 sm:gap-6 mb-6 sm:mb-8",children:[(0,i.jsxs)("div",{className:"text-center bg-gradient-to-br from-blue-50 to-purple-50 rounded-xl p-4 sm:p-6 border border-blue-200",children:[(0,i.jsx)("div",{className:"text-3xl sm:text-4xl mb-2",children:"\ud83c\udfc6"}),(0,i.jsxs)("div",{className:"text-2xl sm:text-3xl font-bold text-blue-600 mb-1",children:[u,"%"]}),(0,i.jsx)("div",{className:"text-gray-600 font-medium text-sm sm:text-base",children:"Your Score"})]}),(0,i.jsxs)("div",{className:"text-center bg-gradient-to-br from-green-50 to-blue-50 rounded-xl p-4 sm:p-6 border border-green-200",children:[(0,i.jsx)("div",{className:"text-3xl sm:text-4xl mb-2",children:"\u23f1\ufe0f"}),(0,i.jsx)("div",{className:"text-2xl sm:text-3xl font-bold text-green-600 mb-1",children:x}),(0,i.jsx)("div",{className:"text-gray-600 font-medium text-sm sm:text-base",children:"Time Taken"})]}),(0,i.jsxs)("div",{className:"text-center bg-gradient-to-br from-purple-50 to-pink-50 rounded-xl p-4 sm:p-6 border border-purple-200",children:[(0,i.jsx)("div",{className:"text-3xl sm:text-4xl mb-2",children:"\ud83d\udcc5"}),(0,i.jsx)("div",{className:"text-lg sm:text-xl font-bold text-purple-600 mb-1",children:g}),(0,i.jsx)("div",{className:"text-gray-600 font-medium text-sm sm:text-base",children:("Just now"===g||g.includes("minute")||g.includes("hour")||"Yesterday"===g||g.includes("days ago"),"Completed")})]})]}),(t.analytics||t.gameData)&&(0,i.jsx)("div",{className:"mb-6 sm:mb-8",children:(0,i.jsx)(P.ZP,{analytics:t.analytics,gameResult:t.gameData?{gameData:t.gameData}:void 0,studentLabel:"Your"})}),t.achievements&&t.achievements.length>0&&(0,i.jsxs)("div",{className:"mb-6 sm:mb-8",children:[(0,i.jsx)("h3",{className:"text-lg sm:text-xl font-semibold text-gray-800 mb
1-3 sm:mb-4 text-center",children:"\ud83c\udfc5 Your Achievements"}),(0,i.jsx)("div",{className:"grid gap-3 sm:gap-4 grid-cols-1 sm:grid-cols-2 lg:grid-cols-3",children:t.achievements.map((function(e,t){var r;if("string"===typeof e&&e.startsWith("{"))try{r=JSON.parse(e)}catch(s){console.log("Failed to parse achievement JSON:",e),r={icon:e.split(" ")[0]||"\ud83c\udfc5",title:e.replace(/^[\w\s]*/,"").trim()||e,description:"Achievement unlocked!"}}else r="object"===typeof e&&e.icon?e:"string"===typeof e?{icon:e.split(" ")[0]||"\ud83c\udfc5",title:e.replace(/^[\w\s]*/,"").trim()||e,description:"Achievement unlocked!"}:{icon:"\ud83c\udfc5",title:"Achievement Unlocked",description:"Great job!"};return(0,i.jsxs)("div",{className:"bg-gradient-to-br from-yellow-50 to-orange-50 rounded-lg p-3 sm:p-4 text-center border border-yellow-200",children:[(0,i.jsx)("div",{className:"text-xl sm:text-2xl mb-2",children:r.icon}),(0,i.jsx)("div",{className:"font-semibold mb-1 text-sm sm:text-base text-yellow-800",children:r.title}),(0,i.jsx)("div",{className:"text-xs sm:text-sm text-yellow-600",children:r.description})]},t)}))})]}),(0,i.jsx)("div",{className:"text-center mb-4 sm:mb-6",children:(0,i.jsxs)("button",{onClick:function(){return c(!l)},className:"inline-flex items-center px-3 sm:px-4 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 transition-colors text-sm sm:text-base",children:[(0,i.jsx)("span",{className:"mr-2",children:l?"\ud83d\udc41\ufe0f Hide Details":"\ud83d\udcca Show Game Details"}),(0,i.jsx)("svg",{className:"w-4 h-4 transform transition-transform ".concat(l?"rotate-180":""),fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z",clipRule:"evenodd"})})]})}),l&&(t.gameResults||t.individual||t.individualScores)&&(0,i.jsxs)("div",{className:"bg-gray-50 rounded-xl p-4 sm:p-6 mb-4 sm:mb-6",children:[(0,i.jsx)("h4",{className:"text-base sm:text-lg font-semibold text-gray-800 mb-3 sm:mb-4",children:"Individual Game Results"}),(0,i.jsx)("div",{className:"space-y-3 sm:space-y-4",children:Object.entries(t.gameResults||t.individual||t.individualScores||{}).map((function(e){var t=(0,h.Z)(e,2),r=t[0],s=t[1],a=p[r];if(!a)return null;var l=!0===s.skipped;return!0===s.completed&&!l||l||s.timeSpent&&0!==s.timeSpent?(0,i.jsx)("div",{className:"bg-white rounded-lg p-3 sm:p-4 border ".concat(l?"border-gray-300 bg-gray-50":"border-gray-200"),children:(0,i.jsxs)("div",{className:"flex items-center justify-between",children:[(0,i.jsxs)("div",{className:"flex items-center min-w-0 flex-1",children:[(0,i.jsx)("span",{className:"text-xl sm:text-2xl mr-2 sm:mr-3 flex-shrink-0 ".concat(l?"grayscale opacity-50":""),children:a.icon}),(0,i.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,i.jsxs)("div",{className:"flex items-center gap-2",children:[(0,i.jsx)("div",{className:"font-semibold text-sm sm:text-base truncate ".concat(l?"text-gray-500":"text-gray-800"),children:a.name}),l&&(0,i.jsx)("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-yellow-200 text-yellow-800 border border-yellow-300",children:"Skipped"})]}),(0,i.jsx)("div",{className:"text-xs sm:text-sm truncate ".concat(l?"text-gray-400":"text-gray-600"),children:l?s.partial?"Partially completed (skipped)":"Game was skipped":a.description})]})]}),(0,i.jsxs)("div",{className:"text-right flex-shrink-0 ml-2",children:[l?(0,i.jsx)("div",{className:"space-y-1",children:s.partial&&s.score>0?(0,i.jsxs)("div",{className:"inline-flex items-center px-2 sm:px-3 py-1 rounded-full text-xs sm:text-sm font-medium bg-orange-400 text-white",children:[s.score,"% (partial)"]}):(0,i.jsx)("div",{className:"inline-flex items-center px-2 sm:px-3 py-1 rounded-full text-xs sm:text-sm font-medium bg-gray-400 text-white",children:"Skipped"})}):(0,i.jsxs)("div",{className:"inline-flex items-center px-2 sm:px-3 py-1 rounded-full text-xs sm:text-sm font-medium ".concat(a.color," text-white"),children:[s.score||0,"%"]}),(0,i.jsx)("div",{className:"text-xs text-gray-500 mt-1",children:l?s.timeSpent>0?n(s.timeSpent):"--":n(s.timeSpent||0)})]})]})},r):null}))})]}),(0,i.jsx)("div",{className:"flex justify-center px-2",children:(0,i.jsx)("button",{onClick:d,className:"px-6 sm:px-8 py-3 bg-blue-600 text-white rounded-lg font-medium hover:bg-blue-700 transition-colors shadow-lg hover:shadow-xl transform hover:scale-105 text-sm sm:text-base",children:"\ud83d\udcd6 Back to Reading"})}),(0,i.jsx)("div",{className:"text-center mt-4 sm:mt-6 p-3 sm:p-4 bg-blue-50 rounded-lg border border-blue-200 mx-2",children:(0,i.jsx)("p",{className:"text-blue-800 font-medium text-sm sm:text-base",children:"\ud83c\udf1f Great work! Try reading other books to discover new vocabulary challenges."})})]})})]})})},V=["wordMatching","fillInBlanks","vocabularyQuiz"],H=["Word Matching","Fill in the Blanks","Vocabulary Quiz"],U=function(e){var t=e.bookId,r=e.bookTitle,c=e.bookContent,u=e.onComplete,m=e.onClose,x=(0,o.useState)(null),h=x[0],g=x[1],p=(0,o.useState)(null),f=p[0],b=p[1],v=(0,o.useState)(!0),j=v[0],w=v[1],N=(0,o.useState)(null),k=N[0],S=N[1],L=(0,o.useState)(0),M=L[0],T=L[1],D=(0,o.useState)({}),B=D[0],I=D[1],z=(0,o.useState)({}),E=z[0],P=z[1],U=(0,o.useState)(!1),F=U[0],O=U[1],G=(0,o.useState)(null),Y=G[0],Q=G[1],$=(0,o.useState)(!1),K=$[0],J=$[1],X=(0,o.useState)(null),ee=X[0],te=X[1],re=(0,o.useState)(null),se=re[0],ne=re[1],ae=(0,o.useState)(!1),le=ae[0],ie=ae[1],oe={wordMatching:(0,o.useRef)(),fillInBlanks:(0,o.useRef)(),vocabularyQuiz:(0,o.useRef)()};(0,o.useEffect)((function(){return ce(),document.body.style.overflow="hidden",function(){document.body.style.overflow="unset"}}),[]),(0,o.useEffect)((function(){h&&de()}),[h]);var ce=function(){var e=(0,s.Z)((function(){var e,t;return(0,l.__generator)(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,d.g.currentAuthenticatedUser()];case 1:return e=r.sent(),g(e),[3,3];case 2:return t=r.sent(),console.error("Error getting current user:",t),S("Authentication required"),w(!1),[3,3];case 3:return[2]}}
1))}));return function(){return e.apply(this,arguments)}}(),de=function(){var e=(0,s.Z)((function(){var e,r,s,n,a;return(0,l.__generator)(this,(function(l){switch(l.label){case 0:return l.trys.push([0,5,,7]),w(!0),S(null),s=(null===h||void 0===h||null===(e=h.attributes)||void 0===e?void 0:e.sub)||(null===h||void 0===h||null===(r=h.attributes)||void 0===r?void 0:r.email)||(null===h||void 0===h?void 0:h.username)||"anonymous",[4,y.A.checkCompletion(t,s)];case 1:return(n=l.sent()).completed?(te(n.results),J(!0),w(!1),[3,4]):[3,2];case 2:return[4,ue()];case 3:l.sent(),l.label=4;case 4:return[3,7];case 5:return a=l.sent(),console.error("Error checking completion status:",a),[4,ue()];case 6:return l.sent(),[3,7];case 7:return[2]}}))}));return function(){return e.apply(this,arguments)}}(),ue=function(){var e=(0,s.Z)((function(){var e,s,n,a,i,o,d,u;return(0,l.__generator)(this,(function(l){switch(l.label){case 0:return l.trys.push([0,9,10,11]),w(!0),S(null),s="","string"!==typeof c?[3,1]:(s=c.substring(0,4e3),[3,7]);case 1:if(!c||"function"!==typeof c.then)return[3,6];l.label=2;case 2:return l.trys.push([2,4,,5]),[4,c];case 3:return n=l.sent(),s=n&&"string"===typeof n?n.substring(0,4e3):"Generate vocabulary games for the book: ".concat(r),[3,5];case 4:return l.sent(),s="Generate vocabulary games for the book: ".concat(r),[3,5];case 5:return[3,7];case 6:s=c&&"object"===typeof c?JSON.stringify(c).substring(0,4e3):"Generate vocabulary games for the book: ".concat(r),l.label=7;case 7:return[4,y.A.generateGames(s,r,t,(null===h||void 0===h||null===(e=h.attributes)||void 0===e?void 0:e.age)||8,!1)];case 8:if(!(a=l.sent()).success||!a.games)throw new Error(a.error||"Failed to generate games");return o=a.games,Array.isArray(a.games)&&(o={wordMatching:a.games[0],fillInBlanks:a.games[1],vocabularyQuiz:a.games[2]}),b(o),d=a.source||(null===(i=a.metadata)||void 0===i?void 0:i.source)||"unknown",ne(d),ie("mock-fallback"===d),[3,11];case 9:return u=l.sent(),console.error("Error generating games:",u),S(u.message||"Error loading games"),[3,11];case 10:return w(!1),[7];case 11:return[2]}}
1))}));return function(){return e.apply(this,arguments)}}(),me=function(e,s){var n=Object.values(e).reduce((function(e,t){return e+t.score}),0),a=Object.values(e).filter((function(e){return e.completed&&!e.skipped})).length,l=a>0?Math.round(n/a):0,i=Object.values(e).reduce((function(e,t){return e+t.timeSpent}),0);return{individual:e,analytics:(0,A.ZS)(s),totalTime:i,totalGames:a,totalGamesAttempted:V.length,averageScore:l,bookId:t,bookTitle:r,completedAt:(new Date).toISOString()}},xe=function(e,t,r){var s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,l=(null===s||void 0===s?void 0:s.analytics)||(0,A.i3)(),i=(0,a.Z)((0,n.Z)({},E),(0,C.Z)({},e,l)),o=(0,a.Z)((0,n.Z)({},B),(0,C.Z)({},e,{score:t,timeSpent:r,completed:!0,skipped:!1,completedAt:(new Date).toISOString()}));P(i),I(o),he(o),M<V.length-1?T(M+1):(Q(me(o,i)),O(!0))},he=function(){var e=(0,s.Z)((function(){var e,t,r,s;return(0,l.__generator)(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),r=(null===h||void 0===h||null===(e=h.attributes)||void 0===e?void 0:e.sub)||(null===h||void 0===h||null===(t=h.attributes)||void 0===t?void 0:t.email)||(null===h||void 0===h?void 0:h.username)||"anonymous",[4,y.A.getProgress(r)];case 1:return n.sent(),[3,3];case 2:return s=n.sent(),console.error("Failed to save progress:",s),[3,3];case 3:return[2]}}
1))}));return function(){return e.apply(this,arguments)}}(),ge=function(){var e=(0,s.Z)((function(e){var s,n,a,i;return(0,l.__generator)(this,(function(l){switch(l.label){case 0:return l.trys.push([0,2,,3]),a={bookId:t,bookTitle:r,userId:(null===h||void 0===h||null===(s=h.attributes)||void 0===s?void 0:s.sub)||(null===h||void 0===h||null===(n=h.attributes)||void 0===n?void 0:n.email)||(null===h||void 0===h?void 0:h.username)||"anonymous",gameResults:e,totalTime:e.totalTime,averageScore:e.averageScore,individualScores:e.individual,completedAt:e.completedAt,gamesCompleted:e.totalGames||0,analytics:{timeSpent:e.totalTime,gamesCompleted:e.totalGames||0,gamesSkipped:(e.totalGamesAttempted||V.length)-(e.totalGames||0),totalGamesAttempted:e.totalGamesAttempted||V.length,difficulty:"beginner"},metadata:{sessionId:"vocab_session_".concat(Date.now()),gamesVersion:"1.0.0",aiProvider:"anthropic-claude"}},[4,y.A.saveResults(a)];case 1:return[2,l.sent()];case 2:return i=l.sent(),console.error("Failed to save final results:",i),[2,null];case 3:return[2]}}
1))}));return function(t){return e.apply(this,arguments)}}(),pe=function(){var e=(0,s.Z)((function(e){return(0,l.__generator)(this,(function(t){switch(t.label){case 0:return[4,ge(e)];case 1:return t.sent(),[2]}}))}));return function(t){return e.apply(this,arguments)}}(),fe=function(){document.body.style.overflow="unset",m()},be=function(){var e=(0,s.Z)((function(){return(0,l.__generator)(this,(function(e){switch(e.label){case 0:return T(0),I({}),P({}),O(!1),Q(null),[4,ue()];case 1:return e.sent(),[2]}}))}));return function(){return e.apply(this,arguments)}}();return j?(0,i.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-[10001]",children:(0,i.jsx)("div",{className:"bg-white rounded-xl p-8 max-w-md w-full mx-4",children:(0,i.jsxs)("div",{className:"text-center",children:[(0,i.jsxs)("div",{className:"relative",children:[(0,i.jsx)("div",{className:"animate-spin rounded-full h-16 w-16 border-b-2 border-purple-600 mx-auto mb-4"}),(0,i.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,i.jsx)("span",{className:"text-2xl",children:"\ud83c\udfae"})})]}),(0,i.jsx)("h3",{className:"text-xl font-semibold text-gray-800 mb-2",children:"Creating Your Vocabulary Games"}),(0,i.jsxs)("p",{className:"text-gray-600 mb-2",children:["Analyzing \u201c",r,"\u201d to create personalized challenges\u2026"]})]})})}):k?(0,i.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-[10001]",children:(0,i.jsxs)("div",{className:"bg-white rounded-xl p-8 max-w-md w-full mx-4 text-center",children:[(0,i.jsx)("h3",{className:"text-xl font-semibold text-gray-800 mb-2",children:"Oops! Something went wrong"}),(0,i.jsx)("p",{className:"text-gray-600 mb-4 text-sm",children:k}),(0,i.jsxs)("div",{className:"flex gap-3",children:[(0,i.jsx)("button",{type:"button",onClick:ue,className:"flex-1 bg-purple-600 text-white py-2 px-4 rounded-lg hover:bg-purple-700 transition-colors",children:"Try Again"}),(0,i.jsx)("button",{type:"button",onClick:fe,className:"flex-1 bg-gray-300 text-gray-700 py-2 px-4 rounded-lg hover:bg-gray-400 transition-colors",children:"Close"})]})]})}):K&&ee?(0,i.jsx)(q,{gameResults:ee,bookTitle:r,onClose:m}):F&&Y?(0,i.jsx)(_,{gameResults:Y,bookTitle:r,onClose:function(){document.body.style.overflow="unset",u&&Y&&u(Y.averageScore,Y),m()},onSaveComplete:pe}):(0,i.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-[10001] p-4",children:(0,i.jsxs)("div",{className:"bg-white rounded-xl shadow-2xl max-w-6xl w-full max-h-[95vh] overflow-hidden",children:[(0,i.jsxs)("div",{className:"bg-gradient-to-r from-purple-600 via-blue-600 to-indigo-600 text-white p-6",children:[(0,i.jsxs)("div",{className:"flex justify-between items-center",children:[(0,i.jsxs)("div",{children:[(0,i.jsxs)("div",{className:"flex items-center gap-3 mb-1",children:[(0,i.jsx)("h2",{className:"text-2xl font-bold",children:"Vocabulary Challenge"}),"mock-fallback"===se&&(0,i.jsx)("span",{className:"bg-yellow-400 text-yellow-900 text-xs px-2 py-1 rounded-full font-semibold",children:"Using Practice Games"}),"claude-api"===se&&(0,i.jsx)("span",{className:"bg-green-400 text-green-900 text-xs px-2 py-1 rounded-full font-semibold",children:"AI-Generated"})]}),(0,i.jsxs)("p",{className:"text-purple-100",children:["From \u201c",r,"\u201d"]})]}),(0,i.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,i.jsx)("button",{type:"button",onClick:be,className:"text-white hover:text-purple-100 text-sm bg-white bg-opacity-20 hover:bg-opacity-30 px-4 py-2 rounded-lg transition-colors flex items-center gap-2",children:"Regenerate Challenge"}),(0,i.jsx)("button",{type:"button",onClick:function(){var e=V[M],t=0,r=0,s=(0,A.i3)();try{var l,i=null===(l=oe[e])||void 0===l?void 0:l.current;i&&(t=i.getCurrentScore()||0,r=i.getCurrentTimeSpent()||0,i.getGameDetail&&(s=i.getGameDetail().analytics||s))}catch(d){console.log("Could not get partial progress for ".concat(e,":"),d)}if(window.confirm("Are you sure you want to skip this game? ".concat(t>0?"Your current progress (".concat(t,"%) will be saved."):"You won't get points for it."))){var o=(0,a.Z)((0,n.Z)({},B),(0,C.Z)({},e,{score:t,timeSpent:r,completed:!1,skipped:!0,partial:!0,completedAt:(new Date).toISOString()})),c=(0,a.Z)((0,n.Z)({},E),(0,C.Z)({},e,s));P(c),I(o),he(o),M<V.length-1?T(M+1):(Q(me(o,c)),O(!0))}},className:"text-white hover:text-purple-100 text-sm bg-white bg-opacity-20 hover:bg-opacity-30 px-4 py-2 rounded-lg transition-colors",children:"Skip Game"}),(0,i.jsx)("button",{type:"button",onClick:fe,className:"text-white hover:text-gray-200",children:(0,i.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,i.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})})]})]}),le&&(0,i.jsxs)("div",{className:"bg-yellow-50 border-l-4 border-yellow-400 p-3 mx-4 mt-3 rounded",children:[(0,i.jsx)("p",{className:"text-sm font-medium text-yellow-800",children:"Using Practice Games"}),(0,i.jsx)("p",{className:"text-xs text-yellow-700 mt-1",children:"Click Regenerate to try fresh AI-powered questions based on this book."})]}),(0,i.jsxs)("div",{className:"mt-4",children:[(0,i.jsxs)("div",{className:"flex justify-between text-sm mb-2",children:[(0,i.jsxs)("span",{children:["Game ",M+1," of ",V.length,": ",H[M]]}),(0,i.jsxs)("span",{children:[Math.round(M/V.length*100),"% Complete"]})]}),(0,i.jsx)("div",{className:"w-full bg-purple-300 rounded-full h-3",children:(0,i.jsx)("div",{className:"bg-white h-3 rounded-full transition-all duration-500",style:{width:"".concat(M/V.length*100,"%")}})}),(0,i.jsx)("div",{className:"flex justify-between mt-3",children:V.map((function(e,t){var r,s;return(0,i.jsxs)("div",{className:"flex items-center text-xs",children:[(0,i.jsx)("div",{className:"w-3 h-3 rounded-full mr-1 ".concat((null===(r=B[e])||void 0===r?void 0:r.completed)?"bg-green-400":t===M?"bg-yellow-400 animate-pulse":"bg-white bg-opacity-50")}),(0,i.jsxs)("span",{className:"text-purple-100",children:[H[t],(null===(s=B[e])||void 0===s?void 0:s.completed)&&(0,i.jsx)("span",{className:"ml-1",children:"\u2713"})]})]},e)}))})]})]}),(0,i.jsx)("div",{className:"overflow-y-auto max-h-[calc(95vh-200px)]",children:f&&(0,i.jsxs)(i.Fragment,{children:[0===M&&(0,i.jsx)(R,{ref:oe.wordMatching,data:f.wordMatching,onComplete:function(e,t,r){return xe("wordMatching",e,t,r)}}),1===M&&(0,i.jsx)(Z,{ref:oe.fillInBlanks,data:f.fillInBlanks,onComplete:function(e,t,r){return xe("fillInBlanks",e,t,r)}}),2===M&&(0,i.jsx)(W,{ref:oe.vocabularyQuiz,data:f.vocabularyQuiz,onComplete:function(e,t,r){return xe("vocabularyQuiz",e,t,r)}})]})})]})})},F=r(4195),O=function(e){var t=e.book,r=e.isOpen,n=e.onClose,a=e.onEditWriting,c=e.onWritingDeleted,u=(0,o.useState)([]),m=u[0],x=u[1],h=(0,o.useState)(!0),g=h[0],p=h[1],f=(0,o.useState)(null),v=f[0],j=f[1],w=(0,o.useState)(!1),y=w[0],N=w[1],k=(0,o.useState)(null),C=k[0],S=k[1],A=(0,o.useState)(!1),L=A[0],R=A[1];(0,o.useEffect)((function(){r&&(D(),T())}),[r,t]);var M,T=function(){var e=(0,s.Z)((function(){var e,t,r;return(0,l.__generator)(this,(function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),[4,d.g.currentAuthenticatedUser()];case 1:return e=s.sent(),t=e.attributes["custom:usertype"],R("student"===t),[3,3];case 2:return r=s.sent(),console.error("Error checking user type:",r),R(!1),[3,3];case 3:return[2]}}
1))}));return function(){return e.apply(this,arguments)}}(),D=function(){var e=(0,s.Z)((function(){var e,r,s,n;return(0,l.__generator)(this,(function(a){switch(a.label){case 0:p(!0),a.label=1;case 1:return a.trys.push([1,4,,5]),[4,d.g.currentAuthenticatedUser()];case 2:return e=a.sent(),r=e.attributes.email,[4,(0,b.NC)(t.id,r)];case 3:return s=a.sent(),x(s),s.length>0?j(s[0]):j(null),[3,5];case 4:return n=a.sent(),console.error("Error loading writings:",n),x([]),[3,5];case 5:return p(!1),[2]}}))}));return function(){return e.apply(this,arguments)}}(),B=function(e){console.log("Delete button clicked for writing ID:",e),e?(S(e),N(!0)):console.error("No writing ID provided for deletion")},I=function(){var e=(0,s.Z)((function(){var e,t,r;return(0,l.__generator)(this,(function(s){switch(s.label){case 0:if(console.log("Confirming delete for writing ID:",C),!C)return console.error("No writing ID to delete"),[2];s.label=1;case 1:return s.trys.push([1,3,,4]),[4,(0,b.hC)(C)];case 2:return e=s.sent(),console.log("Delete result:",e),e?(t=m.filter((function(e){return e.id!==C})),x(t),v&&v.id===C&&j(t.length>0?t[0]:null),N(!1),S(null),c&&c(),console.log("Writing deleted successfully")):(console.error("Failed to delete writing - API returned false"),alert("Failed to delete writing. Please try again.")),[3,4];case 3:return r=s.sent(),console.error("Error deleting writing:",r),alert("An error occurred while deleting the writing. Please try again."),[3,4];case 4:return[2]}}
1))}));return function(){return e.apply(this,arguments)}}(),Z=function(e){return e&&e.trim()?e.trim().split(/\s+/).length:0},z=function(e){return new Date(e).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})};return r?(0,i.jsxs)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:[(0,i.jsxs)("div",{className:"bg-white rounded-xl shadow-xl max-w-6xl w-full mx-4 max-h-[90vh] overflow-hidden",children:[(0,i.jsx)("div",{className:"bg-gradient-to-r from-purple-600 to-blue-600 text-white p-6",children:(0,i.jsxs)("div",{className:"flex justify-between items-center",children:[(0,i.jsxs)("div",{children:[(0,i.jsx)("h2",{className:"text-2xl font-bold",children:"My Writings"}),(0,i.jsxs)("p",{className:"text-purple-100 mt-1",children:['"',t.title,'"']})]}),(0,i.jsx)("button",{onClick:n,className:"text-white hover:text-gray-200 transition-colors",children:(0,i.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,i.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})})]})}),g?(0,i.jsxs)("div",{className:"p-8 text-center",children:[(0,i.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-purple-600 mx-auto"}),(0,i.jsx)("p",{className:"mt-4 text-gray-600",children:"Loading your writings..."})]}):0===m.length?(0,i.jsxs)("div",{className:"p-8 text-center",children:[(0,i.jsx)("div",{className:"text-gray-400 mb-4",children:(0,i.jsx)("svg",{className:"w-16 h-16 mx-auto",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4zm2 6a1 1 0 011-1h6a1 1 0 110 2H7a1 1 0 01-1-1zm1 3a1 1 0 100 2h6a1 1 0 100-2H7z",clipRule:"evenodd"})})}),(0,i.jsx)("h3",{className:"text-lg font-semibold text-gray-800 mb-2",children:"No writings found"}),(0,i.jsx)("p",{className:"text-gray-600 mb-4",children:"You haven't written anything for this book yet."}),(0,i.jsx)("button",{onClick:function(){n(),a()},className:"bg-purple-600 text-white px-6 py-2 rounded-lg hover:bg-purple-700 transition-colors",children:"Start Writing"})]}):(0,i.jsxs)("div",{className:"flex h-[calc(90vh-100px)]",children:[(0,i.jsxs)("div",{className:"w-1/3 border-r border-gray-200 overflow-y-auto",children:[(0,i.jsx)("div",{className:"p-4 border-b border-gray-200 bg-gray-50",children:(0,i.jsxs)("h3",{className:"font-semibold text-gray-800",children:["Your Writings (",m.length,")"]})}),m.map((function(e,t){return(0,i.jsx)("div",{className:"relative group p-4 border-b border-gray-100 cursor-pointer transition-colors ".concat(v&&v.id===e.id?"bg-purple-50 border-l-4 border-l-purple-600":"hover:bg-gray-50"),onClick:function(){return j(e)},children:(0,i.jsxs)("div",{className:"flex justify-between items-start",children:[(0,i.jsxs)("div",{className:"flex-1 pr-2",children:[(0,i.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,i.jsxs)("p",{className:"text-xs text-purple-600 font-medium",children:["Writing #",m.length-t]}),(0,i.jsx)("p",{className:"text-xs text-gray-500",children:z(e.updatedAt)})]}),(0,i.jsxs)("p",{className:"text-sm text-gray-800 line-clamp-3 leading-relaxed",children:[e.content.substring(0,120),"..."]}),(0,i.jsxs)("p",{className:"text-xs text-gray-500 mt-2",children:[Z(e.content)," words"]})]}),!L&&(0,i.jsx)("button",{onClick:function(t){t.stopPropagation(),B(e.id)},className:"opacity-0 group-hover:opacity-100 transition-opacity p-1 text-gray-400 hover:text-red-600 hover:bg-red-50 rounded",title:"Delete this writing",children:(0,i.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,i.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})},e.id)}))]}),(0,i.jsx)("div",{className:"flex-1 flex flex-col",children:v?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{className:"p-4 border-b border-gray-200 bg-gray-50",children:(0,i.jsxs)("div",{className:"flex justify-between items-start",children:[(0,i.jsxs)("div",{children:[(0,i.jsx)("h3",{className:"font-semibold text-gray-800",children:"Writing Details"}),(0,i.jsxs)("p",{className:"text-sm text-gray-600 mt-1",children:["Created: ",z(v.createdAt)]}),v.createdAt!==v.updatedAt&&(0,i.jsxs)("p",{className:"text-sm text-gray-600",children:["Last updated: ",z(v.updatedAt)]})]}),(0,i.jsxs)("div",{className:"flex space-x-2",children:[(0,i.jsxs)("button",{onClick:function(){return a(v)},className:"bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 transition-colors flex items-center",children:[(0,i.jsx)("svg",{className:"w-4 h-4 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,i.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})}),"Edit"]}),!L&&(0,i.jsxs)("button",{onClick:function(){return B(v.id)},className:"bg-red-500 text-white hover:bg-red-600 px-4 py-2 rounded-lg transition-colors flex items-center font-medium",title:"Delete this writing",children:[(0,i.jsx)("svg",{className:"w-4 h-4 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,i.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),"Delete"]})]})]})}),(0,i.jsxs)("div",{className:"p-4 border-b border-gray-200 bg-blue-50",children:[(0,i.jsx)("h4",{className:"font-medium text-gray-800 mb
1-2",children:"Writing Prompt:"}),(0,i.jsx)("p",{className:"text-sm text-blue-800 italic",children:(M=v.promptIndex,['Continue the story from where "'.concat(t.title,'" ended. What happens next to the main characters?'),'Write about a new character who could be friends with someone from "'.concat(t.title,'". How would they meet?'),'Imagine you are one of the characters in "'.concat(t.title,'". Write about your favorite scene from their perspective.'),'Create a different ending for "'.concat(t.title,"\". How would you change the story's conclusion?"),'Write a letter from one character in "'.concat(t.title,'" to another character, sharing their thoughts about the adventure.')][M]||"Custom prompt")})]}),(0,i.jsx)("div",{className:"flex-1 p-4 overflow-y-auto",children:(0,i.jsx)("div",{className:"prose max-w-none",children:(0,i.jsx)("div",{className:"whitespace-pre-wrap text-gray-800 leading-relaxed",children:v.content})})}),(0,i.jsx)("div",{className:"p-4 border-t border-gray-200 bg-gray-50",children:(0,i.jsxs)("div",{className:"flex justify-between text-sm text-gray-600",children:[(0,i.jsxs)("span",{children:["Words: ",Z(v.content)]}),(0,i.jsxs)("span",{children:["Characters: ",v.content.length]})]})})]}):(0,i.jsx)("div",{className:"flex-1 flex items-center justify-center text-gray-500",children:(0,i.jsx)("p",{children:"Select a writing to view details"})})})]})]}),y&&(0,i.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-60 flex items-center justify-center z-[70]",style:{zIndex:9999},children:(0,i.jsx)("div",{className:"bg-white rounded-xl shadow-2xl p-6 max-w-md mx-4 border border-gray-200",children:(0,i.jsxs)("div",{className:"text-center",children:[(0,i.jsx)("div",{className:"mx-auto flex items-center justify-center h-12 w-12 rounded-full bg-red-100 mb-4",children:(0,i.jsx)("svg",{className:"h-6 w-6 text-red-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,i.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L3.732 16c-.77.833.192 2.5 1.732 2.5z"})})}),(0,i.jsx)("h3",{className:"text-lg font-bold text-gray-900 mb-2",children:"Delete Writing"}),(0,i.jsx)("p",{className:"text-gray-600 mb-6 text-sm",children:"Are you sure you want to delete this writing? This action cannot be undone and the writing will be permanently removed."}),(0,i.jsxs)("div",{className:"flex justify-center space-x-3",children:[(0,i.jsx)("button",{onClick:function(){console.log("Delete cancelled"),N(!1),S(null)},className:"px-4 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 transition-colors font-medium",children:"Cancel"}),(0,i.jsxs)("button",{onClick:I,className:"px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 transition-colors font-medium flex items-center",children:[(0,i.jsx)("svg",{className:"w-4 h-4 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,i.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),"Yes, Delete"]})]})]})})})]}):null},G=r(40730),Y=function(){var e=(0,s.Z)((function(e){var t,r,s,n,a,i,o,c,d=arguments;return(0,l.__generator)(this,(function(l){switch(l.label){case 0:return t=d.length>1&&void 0!==d[1]?d[1]:null,r=e.title||"this story",s=e.summary||e.description||"",n=e.genre||"",a=e.bookType||"",i=s,e.content&&(i=e.content),o=Array.isArray(e.ageRanges)&&e.ageRanges.length>0?e.ageRanges[0]:t,[4,(0,w.RA)(r,i,20,o,n,a)];case 1:return c=l.sent(),[2,c.sort((function(){return Math.random()-.5})).slice(0,5)]}}))}));return function(t){return e.apply(this,arguments)}}(),Q=(function(){var e=(0,s.Z)((function(e,t){return(0,l.__generator)(this,(function(t){return[2,Y(e)]}))}))}(),r(79868)),$=["Continue the adventure from where","Write about a day in the life","Imagine you could add a new character","Create an alternative ending for","Write a letter from one character","If you could visit the world of"];function K(e){var t=0,r=!0,s=!1,n=void 0;try{for(var a,l=function(){var e=a.value;$.some((function(t){return e.startsWith(t)}))&&t++},i=e[Symbol.iterator]();!(r=(a=i.next()).done);r=!0)l()}catch(o){s=!0,n=o}finally{try{r||null==i.return||i.return()}finally{if(s)throw n}}return t>=3}var J=function(e){var t=e.book,r=e.onClose,a=e.onBack,u=void 0===a?null:a,m=e.editingWriting,x=void 0===m?null:m,h=e.forceNewWriting,g
1=void 0!==h&&h,p=(0,o.useState)([]),f=p[0],v=p[1],j=(0,o.useState)(null),w=j[0],y=j[1],N=(0,o.useState)({}),k=N[0],S=N[1],A=(0,o.useState)(""),L=A[0],R=A[1],M=(0,o.useState)(!0),T=M[0],D=M[1],B=(0,o.useState)(!1),I=B[0],Z=B[1],z=(0,o.useState)(""),W=z[0],E=z[1],P=(0,o.useState)(null),_=P[0],q=P[1],V=(0,o.useState)(!1),H=V[0],U=V[1],F=(0,o.useState)("new"),O=F[0],G=F[1];(0,c.useRouter)();(0,o.useEffect)((function(){if(J(),x){var e,t=null!==(e=x.promptIndex)&&void 0!==e?e:0,r=x.content||"";q(x),S((0,C.Z)({},t,r)),R(r),y(t),U(!1),G("update")}else g?(q(null),S({}),R(""),y(0),U(!0),G("new")):X();return document.body.style.overflow="hidden",function(){document.body.style.overflow="unset"}}),[t,x,g]);var $,J=function(){var e=(0,s.Z)((function(){var e,r,s;return(0,l.__generator)(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),e=Array.isArray(t.ageRanges)&&t.ageRanges.length>0?t.ageRanges[0]:null,[4,Y(t,e)];case 1:return r=n.sent(),v(r),[3,3];case 2:return s=n.sent(),console.error("Error loading prompts:",s),v(ee(t)),[3,3];case 3:return D(!1),[2]}}))}));return function(){return e.apply(this,arguments)}}(),X=function(){var e=(0,s.Z)((function(){var e,r,s,n;return(0,l.__generator)(this,(function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),[4,d.g.currentAuthenticatedUser()];case 1:return e=a.sent(),r=e.attributes.email,[4,(0,b._I)(t.id,r)];case 2:return(s=a.sent())?(q(s),S({}),R(""),y(0),U(!0),G("new")):(q(null),S({}),R(""),y(0),U(!0),G("new")),[3,4];case 3:return n=a.sent(),console.error("Error loading existing writing:",n),[3,4];case 4:return[2]}}
1))}));return function(){return e.apply(this,arguments)}}(),ee=function(e){var t=e.title||"this story";e.genre;return['Continue the story from where "'.concat(t,'" ended. What happens next to the main characters?'),'Write about a new character who could be friends with someone from "'.concat(t,'". How would they meet?'),'Imagine you are one of the characters in "'.concat(t,'". Write about your favorite scene from their perspective.'),'Create a different ending for "'.concat(t,"\". How would you change the story's conclusion?"),'Write a letter from one character in "'.concat(t,'" to another character, sharing their thoughts about the adventure.')]},te=function(){var e=(0,s.Z)((function(){var e,r,s,n,a,i,o=arguments;return(0,l.__generator)(this,(function(l){switch(l.label){case 0:if(e=o.length>0&&void 0!==o[0]?o[0]:O,!L.trim())return E("Please write something before saving."),[2];Z(!0),G(e),l.label=1;case 1:return l.trys.push([1,7,,8]),[4,d.g.currentAuthenticatedUser()];case 2:return r=l.sent(),s=r.attributes.email,n=f[w]||"General writing prompt",console.log("\ud83d\udcdd Saving with prompt:",{promptText:n,selectedPrompt:w,totalPrompts:f.length}),"update"===e&&_&&x?[4,(0,b.bx)(t.id,s,{id:x.id,content:L,prompt:n,promptIndex:w,title:x.title,reviewStatus:Q.jU.AWAITING_REVIEW,feedbackSeenAt:null,lastModified:(new Date).toISOString()},!0)]:[3,4];case 3:return a=l.sent(),E("Your writing has been updated successfully!"),[3,6];case 4:return[4,(0,b.bx)(t.id,s,{content:L,prompt:n,promptIndex:w,title:"".concat(t.title," - Writing ").concat((new Date).toLocaleDateString()),reviewStatus:Q.jU.AWAITING_REVIEW,lastModified:(new Date).toISOString()})];case 5:a=l.sent(),E("Your new writing has been saved! All previous writings are preserved."),l.label=6;case 6:return q(a),U(!1),setTimeout((function(){return E("")}),4e3),[3,8];case 7:return i=l.sent(),console.error("Error saving writing:",i),E("Error saving your writing. Please try again."),[3,8];case 8:return Z(!1),[2]}}))}));return function(){return e.apply(this,arguments)}}();return T?(0,i.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-[10001]",children:(0,i.jsx)("div",{className:"bg-white rounded-xl shadow-xl max-w-4xl w-full mx-4 h-64 flex items-center justify-center",children:(0,i.jsxs)("div",{className:"text-center",children:[(0,i.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-purple-600 mx-auto"}),(0,i.jsx)("p",{className:"mt-4 text-gray-600",children:"Loading writing prompts..."})]})})}):(0,i.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-[10001] p-2 sm:p-4",children:(0,i.jsxs)("div",{className:"bg-white rounded-xl shadow-xl w-full max-w-7xl h-[95vh] sm:h-[90vh] overflow-hidden flex flex-col",children:[(0,i.jsx)("div",{className:"bg-gradient-to-r from-purple-600 via-blue-600 to-indigo-600 text-white p-3 sm:p-4 lg:p-6 flex-shrink-0",children:(0,i.jsxs)("div",{className:"flex justify-between items-center",children:[(0,i.jsxs)("div",{className:"flex items-center space-x-3",children:[u&&(0,i.jsx)("button",{onClick:u,className:"text-white hover:text-purple-200 transition-colors p-1 rounded-lg hover:bg-white hover:bg-opacity-20",title:"Back to My Writings",children:(0,i.jsx)("svg",{className:"w-5 h-5 lg:w-6 lg:h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,i.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M15 19l-7-7 7-7"})})}),(0,i.jsxs)("div",{children:[(0,i.jsx)("h2",{className:"text-lg sm:text-xl lg:text-2xl font-bold",children:x?"\u270f\ufe0f Edit Writing":"\u2728 Writing Prompts"}),(0,i.jsxs)("div",{className:"flex items-center mt-1",children:[(0,i.jsxs)("p",{className:"text-purple-100 text-sm lg:text-base",children:['Based on "',t.title,'"']}),_&&!H&&(0,i.jsxs)("span",{className:"ml-3 bg-green-500 bg-opacity-20 text-green-100 px-2 py-1 rounded-full text-xs flex items-center",children:[(0,i.jsx)("svg",{className:"w-3 h-3 mr-1",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})}),"Previously saved"]}),H&&(0,i.jsx)("span",{className:"ml-3 bg-blue-500 bg-opacity-20 text-blue-100 px-2 py-1 rounded-full text-xs",children:"New writing"})]})]})]}),(0,i.jsxs)("div",{className:"flex items-center space-x-2",children:[_&&!H&&(0,i.jsx)("button",{onClick:function(){S({}),R(""),y(0),U(!0),E("")},className:"bg-white bg-opacity-20 hover:bg-opacity-30 text-white px-2 py-1 lg:px-3 lg:py-2 rounded-lg text-xs lg:text-sm transition-colors whitespace-nowrap",children:"+ New"}),(0,i.jsx)("button",{onClick:r,className:"text-white hover:text-purple-200 text-xl lg:text-2xl font-bold w-8 h-8 flex items-center justify-center",children:"\xd7"})]})]})}),(0,i.jsxs)("div",{className:"flex flex-col lg:flex-row flex-1 overflow-hidden",children:[(0,i.jsxs)("div",{className:"lg:w-1/2 p-3 sm:p-4 lg:p-6 border-b lg:border-b-0 lg:border-r border-gray-200 flex flex-col",children:[(0,i.jsx)("h3",{className:"text-base sm:text-lg lg:text-xl font-semibold text-gray-800 mb
1-3 lg:mb-4 flex-shrink-0",children:"\ud83d\udcdd Choose a Writing Prompt"}),(0,i.jsx)("div",{className:"flex-1 overflow-y-auto space-y-2 lg:space-y-3 min-h-0",children:f.map((function(e,t){return(0,i.jsx)("div",{onClick:function(){return function(e){var t,r=(0,n.Z)({},k);null!=w&&(r[w]=L),S(r),y(e),R(null!==(t=r[e])&&void 0!==t?t:""),E("")}(t)},className:"p-3 lg:p-4 rounded-lg border-2 cursor-pointer transition-all ".concat(w===t?"border-purple-500 bg-purple-50 shadow-md":"border-gray-200 bg-gray-50 hover:border-purple-300 hover:bg-purple-25"),children:(0,i.jsxs)("div",{className:"flex items-start space-x-2 lg:space-x-3",children:[(0,i.jsx)("span",{className:"text-xs lg:text-sm font-semibold px-2 py-1 rounded flex-shrink-0 ".concat(w===t?"bg-purple-200 text-purple-800":"bg-gray-200 text-gray-600"),children:t+1}),(0,i.jsx)("p",{className:"text-xs lg:text-sm leading-relaxed ".concat(w===t?"text-purple-800":"text-gray-700"),children:e})]})},t)}))})]}),(0,i.jsxs)("div",{className:"lg:w-1/2 p-3 sm:p-4 lg:p-6 flex flex-col flex-1 min-h-0",children:[(0,i.jsxs)("div",{className:"flex flex-col lg:flex-row lg:justify-between lg:items-center mb-3 lg:mb-4 space-y-2 lg:space-y-0 flex-shrink-0",children:[(0,i.jsx)("h3",{className:"text-base sm:text-lg lg:text-xl font-semibold text-gray-800",children:"\ud83d\udd8a\ufe0f Your Writing"}),(0,i.jsx)("div",{className:"flex flex-col sm:flex-row space-y-2 sm:space-y-0 sm:space-x-2",children:x?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("button",{onClick:function(){return te("update")},disabled:I,className:"bg-gradient-to-r from-blue-500 to-blue-600 text-white px-3 py-2 rounded-lg text-sm font-semibold hover:from-blue-600 hover:to-blue-700 disabled:opacity-50 transition-all whitespace-nowrap",children:I&&"update"===O?"Updating...":"\ud83d\udcdd Update"}),(0,i.jsx)("button",{onClick:function(){return te("new")},disabled:I,className:"bg-gradient-to-r from-green-500 to-green-600 text-white px-3 py-2 rounded-lg text-sm font-semibold hover:from-green-600 hover:to-green-700 disabled:opacity-50 transition-all whitespace-nowrap",children:I&&"new"===O?"Saving...":"\ud83d\udcbe Save New"})]}):(0,i.jsx)("button",{onClick:function(){return te("new")},disabled:I,className:"bg-gradient-to-r from-green-500 to-green-600 text-white px-4 py-2 rounded-lg text-sm font-semibold hover:from-green-600 hover:to-green-700 disabled:opacity-50 transition-all whitespace-nowrap",children:I?"Saving...":"\ud83d\udcbe Save"})})]}),_&&!H&&(0,i.jsx)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-3 mb-3",children:(0,i.jsxs)("div",{className:"flex items-start",children:[(0,i.jsx)("svg",{className:"w-4 h-4 text-blue-600 mr-2 mt-0.5 flex-shrink-0",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z",clipRule:"evenodd"})}),(0,i.jsxs)("p",{className:"text-xs lg:text-sm text-blue-800",children:[(0,i.jsx)("strong",{children:"Note:"}),' Saving will create a new writing and preserve all your previous writings. Use "My Writings" button to view all your writings for this book.']})]})}),null!==w&&(0,i.jsxs)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-3 mb-3",children:[(0,i.jsx)("p",{className:"text-xs lg:text-sm text-blue-800 font-medium",children:"Current Prompt:"}),(0,i.jsx)("p",{className:"text-xs lg:text-sm text-blue-700 mt-1",children:f[w]})]}),W&&(0,i.jsx)("div",{className:"mb-3 p-3 rounded-lg text-sm ".concat(W.includes("Error")?"bg-red-50 border border-red-200 text-red-700":W.includes("successfully")?"bg-green-50 border border-green-200 text-green-700":"bg-yellow-50 border border-yellow-200 text-yellow-700"),children:W}),(0,i.jsxs)("div",{className:"flex-1 min-h-0 flex flex-col",children:[(0,i.jsx)("textarea",{value:L,onChange:function(e){return R(e.target.value)},placeholder:null!==w?"Start writing your story here...":"Please select a prompt above to begin writing.",className:"w-full flex-1 p-3 lg:p-4 border border-gray-300 rounded-lg resize-none focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent text-sm lg:text-base",style:{minHeight:"200px"}}),(0,i.jsxs)("div",{className:"mt-2 flex justify-between text-xs lg:text-sm text-gray-500",children:[(0,i.jsxs)("span",{children:["Words: ",($=L,$&&$.trim()?$.trim().split(/\s+/).length:0)]}),(0,i.jsxs)("span",{children:["Characters: ",L.length]})]})]})]})]}),K(f)&&(0,i.jsx)("div",{style:{margin:"10px 0",color:"#888",fontSize:"0.95em"},children:"If you see repeated or generic prompts, try refreshing the page for more variety!"})]})})},X=function(e){var t=e.open,r=e.title,s=void 0===r?"Sequence Quest":r,n=e.message,a=void 0===n?"\ud83c\udf89 You've finished reading this book!\n\nThe Sequence Quest is still waiting for you.Would you like to complete it now?":n,l=e.onPlay,o=e.onDismiss;return t?(0,i.jsx)("div",{className:"fixed inset-0 z-[10050] flex items-center justify-center p-4 bg-black/60",role:"dialog","aria-modal":"true","aria-labelledby":"story-sequence-invite-title",onClick:o,children:(0,i.jsxs)("div",{className:"bg-white rounded-2xl shadow-xl max-w-sm w-full p-6 text-center",onClick:function(e){return e.stopPropagation()},children:[(0,i.jsx)("div",{className:"mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-purple-100 text-2xl","aria-hidden":"true",children:"\ud83d\udd52"}),(0,i.jsx)("h2",{id:"story-sequence-invite-title",className:"text-lg font-semibold text-gray-900 mb-2",children:s}),(0,i.jsx)("p",{className:"text-sm text-gray-600 mb-6 whitespace-pre-line",children:a}),(0,i.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,i.jsx)("button",{type:"button",className:"w-full bg-gradient-to-r from-purple-bright to-blue-bright hover:from-purple-light hover:to-blue-bright text-white font-medium py-2.5 px-4 roun
1ded-lg shadow-md transition-all duration-200",onClick:l,children:"Yes, play now"}),(0,i.jsx)("button",{type:"button",className:"w-full bg-gray-100 hover:bg-gray-200 text-gray-700 font-medium py-2.5 px-4 rounded-lg transition-colors",onClick:o,children:"Not now"})]})]})}):null},ee=function(e){var t=e.open,r=e.title,s=void 0===r?"Comprehension Check":r,n=e.message,a=void 0===n?"\ud83c\udf89 You've finished reading this book!\n\nWould you like to complete the Comprehension Check now?":n,l=e.onPlay,o=e.onDismiss;return t?(0,i.jsx)("div",{className:"fixed inset-0 z-[10050] flex items-center justify-center p-4 bg-black/60",role:"dialog","aria-modal":"true","aria-labelledby":"book-comprehension-invite-title",onClick:o,children:(0,i.jsxs)("div",{className:"bg-white rounded-2xl shadow-xl max-w-sm w-full p-6 text-center",onClick:function(e){return e.stopPropagation()},children:[(0,i.jsx)("div",{className:"mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-purple-100 text-2xl","aria-hidden":"true",children:"\ud83e\udde0"}),(0,i.jsx)("h2",{id:"book-comprehension-invite-title",className:"text-lg font-semibold text-gray-900 mb-2",children:s}),(0,i.jsx)("p",{className:"text-sm text-gray-600 mb-6 whitespace-pre-line",children:a}),(0,i.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,i.jsx)("button",{type:"button",className:"w-full bg-gradient-to-r from-purple-bright to-purple-light hover:from-purple-light hover:to-blue-bright text-white font-medium py-2.5 px-4 rounded-lg shadow-md transition-all duration-200",onClick:l,children:"Yes, start now"}),(0,i.jsx)("button",{type:"button",className:"w-full bg-gray-100 hover:bg-gray-200 text-gray-700 font-medium py-2.5 px-4 rounded-lg transition-colors",onClick:o,children:"Not now"})]})]})}):null},te=function(e){var t=e.bookDetails,r=e.checkBookType,c=e.changeAudioPlayerStatus,u=e.totalRatingsForBook,m=e.averageRating,g=(0,o.useContext)(f.f),C=g.trackData,S=g.setTrackDataDetails,A=(g.saveTrackDetails,(0,o.useState)(!1)),L=A[0],R=A[1],M=(0,o.useState)(!1),T=M[0],D=M[1],B=(0,o.useState)(!1),I=B[0],Z=B[1],z=(0,o.useState)(!1),W=(z[0],z[1]),E=(0,o.useState)(null),P=E[0],_=E[1],q=(0,o.useState)(!1),V=q[0],H=q[1],G=(0,o.useState)({loading:!0,isAssigned:!1,readingComplete:!1,storyTimelineCompleted:!1,storyTimelineScore:null,comprehensionCompleted:!1,comprehensionScore:null}),Y=G[0],Q=G[1],$=(0,o.useState)(!1),K=$[0],te=$[1],re=(0,o.useState)(!1),se=re[0],ne=re[1],ae=(0,o.useState)(!1),le=ae[0],ie=ae[1],oe=(0,o.useState)(!1),ce=oe[0],de=oe[1],ue=Y.loading,me=Y.isAssigned,xe=Y.readingComplete,he=Y.storyTimelineCompleted,ge=Y.comprehensionCompleted,pe=r===x.bookType.EPUB||r===x.bookType.READALOUD;(0,o.useEffect)((function(){fe()}),[t]),(0,o.useEffect)((function(){be()}),[t]),(0,o.useEffect)((function(){!ue&&me&&xe&&!he&&ne(!0)}),[ue,me,xe,he]),(0,o.useEffect)((function(){ue||me||!xe||ge||de(!0)}),[ue,me,xe,ge]);var fe=function(){var e=(0,s.Z)((function(){var e,r,s,n;return(0,l.__generator)(this,(function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),[4,d.g.currentAuthenticatedUser()];case 1:return e=a.sent(),r=e.attributes.email,[4,(0,b._I)(t.id,r)];case 2:return s=a.sent(),W(!!s),[3,4];case 3:return n=a.sent(),console.error("Error checking for existing writing:",n),W(!1),[3,4];case 4:return[2]}}
1))}));return function(){return e.apply(this,arguments)}}(),be=function(){var e=(0,s.Z)((function(){var e,r,s,i,o,c,u,m,x,g,p,f,b,w,k,C,S=arguments;return(0,l.__generator)(this,(function(l){switch(l.label){case 0:e=S.length>0&&void 0!==S[0]?S[0]:{},r=e.silent,void 0!==r&&r||Q((function(e){return(0,a.Z)((0,n.Z)({},e),{loading:!0})})),l.label=1;case 1:return l.trys.push([1,7,,8]),[4,d.g.currentAuthenticatedUser()];case 2:return i=l.sent(),o=i.attributes.email,c=i.attributes.sub||o,"student"===i.attributes["custom:usertype"]?[4,(0,v.g)(t.id,o)]:(Q({loading:!1,isAssigned:!1,readingComplete:!1,storyTimelineCompleted:!1,storyTimelineScore:null,comprehensionCompleted:!1,comprehensionScore:null}),[2]);case 3:return l.sent()?[3,5]:[4,Promise.all([(0,j.J)(o,t.id),N.f.checkCompletion(t.id,c)])];case 4:return m=h.Z.apply(void 0,[l.sent(),2]),x=m[0],g=m[1],Q({loading:!1,isAssigned:!1,readingComplete:x,storyTimelineCompleted:!1,storyTimelineScore:null,comprehensionCompleted:g.completed,comprehensionScore:null!==(p=null===(u=g.results)||void 0===u?void 0:u.percentage)&&void 0!==p?p:null}),[2];case 5:return[4,Promise.all([(0,j.J)(o,t.id),y.A.checkStoryTimelineCompletion(t.id,c)])];case 6:return f=h.Z.apply(void 0,[l.sent(),2]),b=f[0],w=f[1],Q({loading:!1,isAssigned:!0,readingComplete:b,storyTimelineCompleted:w.completed,storyTimelineScore:null!==(k=null===(s=w.results)||void 0===s?void 0:s.score)&&void 0!==k?k:null,comprehensionCompleted:!1,comprehensionScore:null}),[3,8];case 7:return C=l.sent(),console.error("Error checking assignment status:",C),Q({loading:!1,isAssigned:!1,readingComplete:!1,storyTimelineCompleted:!1,storyTimelineScore:null,comprehensionCompleted:!1,comprehensionScore:null}),[3,8];case 8:return[2]}}
1))}));return function(){return e.apply(this,arguments)}}(),ve=function(){var e=(0,s.Z)((function(){var e,t;return(0,l.__generator)(this,(function(r){switch(r.label){case 0:return c(),e=new Date,t=(0,a.Z)((0,n.Z)({},C),{startTime:e}),localStorage.setItem("startTime",e),localStorage.setItem("trackedData",JSON.stringify(C)),[4,S(t,!0)];case 1:return r.sent(),[2]}}))}));return function(){return e.apply(this,arguments)}}(),je=function(){var e=(0,s.Z)((function(e){return(0,l.__generator)(this,(function(t){try{console.log("Vocabulary games completed!",e),Z(!1)}catch(r){console.error("Error saving vocabulary game progress:",r)}return[2]}))}));return function(t){return e.apply(this,arguments)}}();return(0,i.jsxs)("div",{children:[(0,i.jsx)("div",{className:"md:h-px py-2 md:py-16 bg-transparent",children:(0,i.jsx)("div",{className:"container mx-auto px-6",children:(0,i.jsx)("div",{className:"sm:flex sm:mt-8 ",children:(0,i.jsx)("div",{className:"sm:w-full sm:px-8 flex flex-col md:flex-row justify-center md:justify-between",children:(0,i.jsxs)("div",{className:"mt-0 md:mt-16 grid grid-cols-1 md:grid-cols-2 gap-2 md:gap-4 w-full",children:[(0,i.jsxs)("div",{className:"mx-0 tb:mx-4 md:ml-16 md:mr-32 grid justify-items-center",children:[(0,i.jsx)("div",{className:"animate-fade-in",children:(0,i.jsxs)("div",{className:"relative h-80 w-56 rounded-2xl overflow-hidden shadow-xl flex justify-center group hover:shadow-2xl transition-all duration-300 hover:scale-105 bg-gradient-to-br from-pink-400 to-purple-400",children:[(0,i.jsx)("img",{className:"rounded-2xl align-middle border-none object-cover h-full w-full group-hover:scale-110 transition-transform duration-500",src:t.image,alt:t.title}),(0,i.jsx)("div",{className:"absolute inset-0 bg-gradient-to-t from-black/40 via-transparent to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-300"})]})}),(0,i.jsxs)("div",{className:"flex justify-center mb-4 md:mb-0",children:[r===x.bookType.AUDIO?(0,i.jsx)("div",{className:"rounded-full h-14 w-14 flex items-center justify-center bg-gradient-to-br from-red-400 to-red-500 shadow-lg mr-4",children:(0,i.jsxs)("svg",{width:"36",height:"37",viewBox:"0 0 36 37",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,i.jsx)("path",{d:"M4.50098 27.8379V18.8379C4.50098 15.2575 5.92329 11.8237 8.45503 9.29195C10.9868 6.76021 14.4206 5.33789 18.001 5.33789C21.5814 5.33789 25.0152 6.76021 27.5469 9.29195C30.0787 11.8237 31.501 15.2575 31.501 18.8379V27.8379",stroke:"#DB3B3E",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),(0,i.jsx)("path",{d:"M31.501 29.3379C31.501 30.1335 31.1849 30.8966 30.6223 31.4592C30.0597 32.0218 29.2966 32.3379 28.501 32.3379H27.001C26.2053 32.3379 25.4423 32.0218 24.8797 31.4592C24.317 30.8966 24.001 30.1335 24.001 29.3379V24.8379C24.001 24.0422 24.317 23.2792 24.8797 22.7166C25.4423 22.154 26.2053 21.8379 27.001 21.8379H31.501V29.3379ZM4.50098 29.3379C4.50098 30.1335 4.81705 30.8966 5.37966 31.4592C5.94227 32.0218 6.70533 32.3379 7.50098 32.3379H9.00098C9.79663 32.3379 10.5597 32.0218 11.1223 31.4592C11.6849 30.8966 12.001 30.1335 12.001 29.3379V24.8379C12.001 24.0422 11.6849 23.2792 11.1223 22.7166C10.5597 22.154 9.79663 21.8379 9.00098 21.8379H4.50098V29.3379Z",stroke:"#DB3B3E",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})}):(0,i.jsx)("div",{className:"rounded-full h-14 w-14 flex items-center justify-center bg-gradient-to-br from-blue-300 to-blue-400 shadow-lg mr-4",children:(0,i.jsxs)("svg",{width:"36",height:"37",viewBox:"0 0 36 37",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,i.jsx)("path",{d:"M4.50098 27.8379V18.8379C4.50098 15.2575 5.92329 11.8237 8.45503 9.29195C10.9868 6.76021 14.4206 5.33789 18.001 5.33789C21.5814 5.33789 25.0152 6.76021 27.5469 9.29195C30.0787 11.8237 31.501 15.2575 31.501 18.8379V27.8379",stroke:"#1e40af",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),(0,i.jsx)("path",{d:"M31.501 29.3379C31.501 30.1335 31.1849 30.8966 30.6223 31.4592C30.0597 32.0218 29.2966 32.3379 28.501 32.3379H27.001C26.2053 32.3379 25.4423 32.0218 24.8797 31.4592C24.317 30.8966 24.001 30.1335 24.001 29.3379V24.8379C24.001 24.0422 24.317 23.2792 24.8797 22.7166C25.4423 22.154 26.2053 21.8379 27.001 21.8379H31.501V29.3379ZM4.50098 29.3379C4.50098 30.1335 4.81705 30.8966 5.37966 31.4592C5.94227 32.0218 6.70533 32.3379 7.50098 32.3379H9.00098C9.79663 32.3379 10.5597 32.0218 11.1223 31.4592C11.6849 30.8966 12.001 30.1335 12.001 29.3379V24.8379C12.001 24.0422 11.6849 23.2792 11.1223 22.7166C10.5597 22.154 9.79663 21.8379 9.00098 21.8379H4.50098V29.3379Z",stroke:"#1e40af",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r===x.bookType.EPUB?(0,i.jsx)("div",{className:"rounded-full h-14 w-14 flex items-center justify-center bg-gradient-to-br from-red-400 to-red-500 shadow-lg mr-4",children:(0,i.jsx)("svg",{width:"36",height:"37",viewBox:"0 0 36 37",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,i.jsxs)("g",{opacity:"0.8",children:[(0,i.jsx)("path",{d:"M3.00098 5.33789H12.001C13.5923 5.33789 15.1184 5.97003 16.2436 7.09525C17.3688 8.22047 18.001 9.74659 18.001 11.3379V32.3379C18.001 31.1444 17.5269 29.9998 16.683 29.1559C15.839 28.312 14.6945 27.8379 13.501 27.8379H3.00098V5.33789Z",stroke:"#DB3B3E",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),(0,i.jsx)("path",{d:"M33.001 5.33789H24.001C22.4097 5.33789 20.8836 5.97003 19.7583 7.09525C18.6331 8.22047 18.001 9.74659 18.001 11.3379V32.3379C18.001 31.1444 18.4751 29.9998 19.319 29.1559C20.1629 28.312 21.3075 27.8379 22.501 27.8379H33.001V5.33789Z",stroke:"#DB3B3E",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})})}):(0,i.jsx)("div",{className:"rounded-full h-14 w-14 flex items-center justify-center bg-gradient-to-br from-blue-300 to-blue-400 shadow-lg mr-4",children:(0,i.jsx)("svg",{width:"36",height:"37",viewBox:"0 0 36 37",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,i.jsxs)("g",{opacity:"0.8",children:[(0,i.jsx)("path",{d:"M3.00098 5.33789H12.001C13.5923 5.33789 15.1184 5.97003 16.2436 7.09525C17.3688 8.22047 18.001 9.74659 18.001 11.3379V32.3379C18.001 31.1444 17.5269 29.9998 16.683 29.1559C15.839 28.312 14.6945 27.8379 13.501 27.8379H3.00098V5.33789Z",stroke:"#0f172a",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),(0,i.jsx)("path",{d:"M33.001 5.33789H24.001C22.4097 5.33789 20.8836 5.97003 19.7583 7.09525C18.6331 8.22047 18.001 9.74659 18.001 11.3379V32.3379C18.001 31.1444 18.4751 29.9998 19.319 29.1559C20.1629 28.312 21.3075 27.8379 22.501 27.8379H33.001V5.33789Z",stroke:"#0f172a",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})})}),r===x.bookType.READALOUD?(0,i.jsx)("div",{className:"rounded-full h-14 w-14 flex items-center justify-center bg-gradient-to-br from-red-400 to-red-500 shadow-lg mr-4",children:(0,i.jsxs)("svg",{width:"31",height:"34",viewBox:"0 0 31 34",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,i.jsx)("path",{d:"M25.95 1.44002C26.27 0.91002 26.95 0.740021 27.48 1.06002H27.49L27.5 1.07002C27.56 1.11002 27.61 1.14002 27.67 1.18002C27.77 1.25002 27.92 1.36002 28.08 1.50002C28.41 1.78002 28.84 2.19002 29.27 2.75002C30.14 3.88002 30.99 5.60002 30.99 7.96002C30.99 10.32 30.14 12.05 29.27 13.17C28.84 13.73 28.41 14.14 28.08 14.42C27.91 14.56 27.73 14.7 27.54 14.82L27.5 14.85L27.49 14.86C27.49 14.86 27.49 14.86 26.91 13.91L27.48 14.87C26.94 15.17 26.26 14.99 25.96 14.45C25.67 13.94 25.83 13.28 26.33 12.96L26.34 12.95L26.4 12.91C26.49 12.85 26.58 12.78 26.66 12.71C26.89 12.52 27.2 12.23 27.51 11.82C28.13 11.01 28.76 9.76002 28.76 7.96002C28.76 6.16002 28.13 4.91002 27.51 4.10002C27.26 3.77002 26.97 3.47002 26.66 3.21002C26.56 3.12002 26.45 3.04002 26.34 2.97002L26.33 2.96002C25.81 2.65002 25.64 1.97002 25.95 1.44002Z",fill:"#DB3B3E"}),(0,i.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M13.53 0.900391C9.63 0.900391 6.47 4.06039 6.47 7.96039C6.47 11.8604 9.63 15.0204 13.53 15.0204C17.43 15.0204 20.59 
111.8604 20.59 7.96039C20.59 4.06039 17.43 0.900391 13.53 0.900391ZM8.7 7.97039C8.7 5.30039 10.86 3.14039 13.53 3.14039C16.2 3.14039 18.36 5.30039 18.36 7.97039C18.36 10.6404 16.2 12.8004 13.53 12.8004C10.86 12.8004 8.7 10.6404 8.7 7.97039ZM13.38 17.0404C9.84 17.0404 6.58 17.8404 4.17 19.2004C1.79 20.5404 0 22.5704 0 25.0704V25.2304C0 27.0104 -2.38419e-07 29.2404 1.95 30.8304C2.91 31.6104 4.26 32.1704 6.08 32.5404C7.9 32.9104 10.28 33.1004 13.38 33.1004C16.48 33.1004 18.86 32.9104 20.68 32.5404C22.5 32.1704 23.85 31.6104 24.81 30.8304C26.77 29.2404 26.76 27.0104 26.76 25.2304V25.0704C26.76 22.5704 24.97 20.5404 22.59 19.2004C20.18 17.8404 16.92 17.0404 13.38 17.0404ZM2.75 25.0704C2.75 23.8004 3.67 22.4304 5.67 21.3104C7.63 20.2104 10.4 19.4904 13.54 19.4904C16.67 19.4904 19.45 20.2104 21.4 21.3104C23.39 22.4304 24.32 23.8004 24.32 25.0704C24.32 27.0104 24.26 28.1104 23.24 28.9404C22.69 29.3904 21.77 29.8304 20.19 30.1504C18.62 30.4704 16.47 30.6504 13.53 30.6504C10.59 30.6504 8.44 30.4604 6.87 30.1504C5.29 29.8304 4.37 29.3904 3.82 28.9504C2.81 28.1104 2.75 27.0104 2.75 25.0704Z",fill:"#DB3B3E"}),(0,i.jsx)("path",{d:"M24.51 4.04049C23.98 3.72049 23.3 3.89049 22.98 4.42049L23.35 5.94049L23.36 5.95049C23.52 6.07049 23.67 6.22049 23.8 6.38049C24.14 6.84049 24.33 7.40049 24.31 7.97049C24.31 8.72049 24.05 9.23049 23.8 9.56049C23.67 9.72049 23.53 9.87049 23.36 9.99049L23.35 10.0005C22.82 10.3205 22.66 11.0105 22.98 11.5305C23.3 12.0605 23.99 12.2205 24.51 11.9005L24.52 11.8905L24.55 11.8705L24.63 11.8105C24.98 11.5605 25.29 11.2505 25.55 10.9105C26.2 10.0605 26.54 9.03049 26.53 7.96049C26.54 6.90049 26.2 5.86049 25.56 5.01049C25.3 4.67049 24.98 4.37049 24.64 4.11049C24.61 4.09049 24.59 4.07049 24.56 4.05049L24.53 4.03049L24.51 4.04049C24.51 4.04049 24.51 4.04049 23.94 5.00049C23.94 4.99049 24.51 4.04049 24.51 4.04049Z",fill:"#DB3B3E"})]})}):(0,i.jsx)("div",{className:"rounded-full h-14 w-14 flex items-center justify-center bg-gradient-to-br from-blue-300 to-blue-400 shadow-lg",children:(0,i.jsx)("svg",{width:"31",height:"34",viewBox:"0 0 31 34",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,i.jsxs)("g",{opacity:"0.8",children:[(0,i.jsx)("path",{d:"M25.95 1.44002C26.27 0.91002 26.95 0.740021 27.48 1.06002H27.49L27.5 1.07002C27.56 1.11002 27.61 1.14002 27.67 1.18002C27.77 1.25002 27.92 1.36002 28.08 1.50002C28.41 1.78002 28.84 2.19002 29.27 2.75002C30.14 3.88002 30.99 5.60002 30.99 7.96002C30.99 10.32 30.14 12.05 29.27 13.17C28.84 13.73 28.41 14.14 28.08 14.42C27.91 14.56 27.73 14.7 27.54 14.82L27.5 14.85L27.49 14.86C27.49 14.86 27.49 14.86 26.91 13.91L27.48 14.87C26.94 15.17 26.26 14.99 25.96 14.45C25.67 13.94 25.83 13.28 26.33 12.96L26.34 12.95L26.4 12.91C26.49 12.85 26.58 12.78 26.66 12.71C26.89 12.52 27.2 12.23 27.51 11.82C28.13 11.01 28.76 9.76002 28.76 7.96002C28.76 6.16002 28.13 4.91002 27.51 4.10002C27.26 3.77002 26.97 3.47002 26.66 3.21002C26.56 3.12002 26.45 3.04002 26.34 2.97002L26.33 2.96002C25.81 2.65002 25.64 1.97002 25.95 1.44002Z",fill:"#1e40af"}),(0,i.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M13.53 0.900391C9.63 0.900391 6.47 4.06039 6.47 7.96039C6.47 11.8604 9.63 15.0204 13.53 15.0204C17.43 15.0204 20.59 11.8604 20.59 7.96039C20.59 4.06039 17.43 0.900391 13.53 0.900391ZM8.7 7.97039C8.7 5.30039 10.86 3.14039 13.53 3.14039C16.2 3.14039 18.36 5.30039 18.36 7.97039C18.36 10.6404 16.2 12.8004 13.53 12.8004C10.86 12.8004 8.7 10.6404 8.7 7.97039ZM13.38 17.0404C9.84 17.0404 6.58 17.8404 4.17 19.2004C1.79 20.5404 0 22.5704 0 25.0704V25.2304C0 27.0104 -2.38419e-07 29.2404 1.95 30.8304C2.91 31.6104 4.26 32.1704 6.08 32.5404C7.9 32.9104 10.28 33.1004 13.38 33.1004C16.48 33.1004 18.86 32.9104 20.68 32.5404C22.5 32.1704 23.85 31.6104 24.81 30.8304C26.77 29.2404 26.76 27.0104 26.76 25.2304V25.
10704C26.76 22.5704 24.97 20.5404 22.59 19.2004C20.18 17.8404 16.92 17.0404 13.38 17.0404ZM2.75 25.0704C2.75 23.8004 3.67 22.4304 5.67 21.3104C7.63 20.2104 10.4 19.4904 13.54 19.4904C16.67 19.4904 19.45 20.2104 21.4 21.3104C23.39 22.4304 24.32 23.8004 24.32 25.0704C24.32 27.0104 24.26 28.1104 23.24 28.9404C22.69 29.3904 21.77 29.8304 20.19 30.1504C18.62 30.4704 16.47 30.6504 13.53 30.6504C10.59 30.6504 8.44 30.4604 6.87 30.1504C5.29 29.8304 4.37 29.3904 3.82 28.9504C2.81 28.1104 2.75 27.0104 2.75 25.0704Z",fill:"#1e40af"}),(0,i.jsx)("path",{d:"M24.51 4.04049C23.98 3.72049 23.3 3.89049 22.98 4.42049L23.35 5.94049L23.36 5.95049C23.52 6.07049 23.67 6.22049 23.8 6.38049C24.14 6.84049 24.33 7.40049 24.31 7.97049C24.31 8.72049 24.05 9.23049 23.8 9.56049C23.67 9.72049 23.53 9.87049 23.36 9.99049L23.35 10.0005C22.82 10.3205 22.66 11.0105 22.98 11.5305C23.3 12.0605 23.99 12.2205 24.51 11.9005L24.52 11.8905L24.55 11.8705L24.63 11.8105C24.98 11.5605 25.29 11.2505 25.55 10.9105C26.2 10.0605 26.54 9.03049 26.53 7.96049C26.54 6.90049 26.2 5.86049 25.56 5.01049C25.3 4.67049 24.98 4.37049 24.64 4.11049C24.61 4.09049 24.59 4.07049 24.56 4.05049L24.53 4.03049L24.51 4.04049C24.51 4.04049 24.51 4.04049 23.94 5.00049C23.94 4.99049 24.51 4.04049 24.51 4.04049Z",fill:"#1e40af"})]})})})]})]}),(0,i.jsx)("div",{className:"mb-10 md:mb-0 flex justify-center",children:(0,i.jsxs)("div",{className:"w-full min-w-0",children:[(0,i.jsx)(p(),{href:"/author/".concat(t.authorId),legacyBehavior:!0,children:(0,i.jsx)("p",{className:"cursor-pointer text-small2 font-medium text-blue-900 font-serif",children:t.authorName})}),(0,i.jsx)("p",{className:"text-8xl font-bold text-blue-900 font-serif mt-2",children:t.title}),(0,i.jsx)("div",{className:"bg-white rounded-lg p-4 shadow-sm mt-6 max-w-2xl border border-gray-100",children:(0,i.jsxs)("div",{className:"grid grid-cols-2 gap-4 md:gap-6",children:[(0,i.jsxs)("div",{className:"flex items-center gap-3",children:[(0,i.jsx)("div",{className:"w-12 h-12 rounded-full bg-yellow-100 flex items-center justify-center flex-shrink-0",children:(0,i.jsx)("svg",{width:"20",height:"20",viewBox:"0 0 22 22",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,i.jsx)("path",{d:"M11.001 1.33789L14.091 7.59789L21.001 8.60789L16.001 13.4779L17.181 20.3579L11.001 17.1079L4.82098 20.3579L6.00098 13.4779L1.00098 8.60789L7.91098 7.59789L11.001 1.33789Z",fill:"#FCD34D",stroke:"#F59E0B",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,i.jsxs)("div",{children:[(0,i.jsx)("p",{className:"text-xs text-gray-600 font-medium",children:"Community Rating"}),(0,i.jsxs)("div",{className:"flex items-baseline gap-1 mt-1",children:[(0,i.jsx)("p",{className:"text-lg font-bold text-blue-900",children:u>=1?Math.round(10*m)/10:"No"}),(0,i.jsx)("p",{className:"text-xs text-gray-600",children:u>=1?1===m?"star":"stars":"ratings"})]}),u>=1&&(0,i.jsxs)("p",{className:"text-xs text-gray-500 mt-0.5",children:[u," ",1===u?"rating":"ratings"]})]})]}),(0,i.jsxs)("div",{className:"flex items-center gap-3",children:[(0,i.jsx)("div",{className:"w-12 h-12 rounded-full bg-purple-100 flex items-center justify-center flex-shrink-0",children:(0,i.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,i.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"#9333EA",strokeWidth:"2"}),(0,i.jsx)("path",{d:"M12 6V12L16 14",stroke:"#9333EA",strokeWidth:"2",strokeLinecap:"round"})]})}),(0,i.jsxs)("div",{children:[(0,i.jsx)("p",{className:"text-xs text-gray-600 font-medium",children:"Time to Read"}),(0,i.jsx)("p",{className:"text-lg font-bold text-blue-900 mt-1",children:function(e){var t=e/60,r=Math.floor(t),s=60*(t-r);return r+"h "+Math.round(s)+"m"}(t.duration)})]})]})]})}),(0,i.jsx)("div",{className:"flex flex-col gap-3 my-4 md:my-8 max-w-4xl",children:(0,i.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3",children:[(0,i.jsx)("div",{onClick:ve,className:"flex-1 min-w-0",children:r===x.bookType.AUDIO?(0,i.jsxs)("button",{className:"w-full bg-gradient-to-r from-purple-600 to-purple-700 hover:from-purple-500 hover:to-purple-600 text-white font-medium py-3 px-4 roun
1ded-lg shadow-md transform hover:scale-105 transition-all duration-200 flex items-center justify-center space-x-2",children:[(0,i.jsx)("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M9.383 3.076A1 1 0 0110 4v12a1 1 0 01-1.617.824L4.383 13H2a1 1 0 01-1-1V8a1 1 0 011-1h2.383l4-3.824a1 1 0 011.617-.824zM14.657 2.929a1 1 0 011.414 0A9.972 9.972 0 0119 10a9.972 9.972 0 01-2.929 7.071 1 1 0 01-1.414-1.414A7.971 7.971 0 0017 10c0-2.21-.894-4.208-2.343-5.657a1 1 0 010-1.414z",clipRule:"evenodd"})}),(0,i.jsx)("span",{className:"truncate",children:"Listen"})]}):r===x.bookType.EPUB?(0,i.jsxs)("button",{className:"w-full bg-gradient-to-r from-purple-600 to-purple-700 hover:from-purple-500 hover:to-purple-600 text-white font-medium py-3 px-4 rounded-lg shadow-md transform hover:scale-105 transition-all duration-200 flex items-center justify-center space-x-2",children:[(0,i.jsx)("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4z",clipRule:"evenodd"})}),(0,i.jsx)("span",{className:"truncate",children:"Read"})]}):(0,i.jsxs)("button",{className:"w-full bg-gradient-to-r from-purple-600 to-purple-700 hover:from-purple-500 hover:to-purple-600 text-white font-medium py-3 px-4 rounded-lg shadow-md transform hover:scale-105 transition-all duration-200 flex items-center justify-center space-x-2",children:[(0,i.jsxs)("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 20 20",children:[(0,i.jsx)("path",{fillRule:"evenodd",d:"M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4z",clipRule:"evenodd"}),(0,i.jsx)("path",{d:"M9.383 3.076A1 1 0 0110 4v12a1 1 0 01-1.617.824L4.383 13H2a1 1 0 01-1-1V8a1 1 0 011-1h2.383l4-3.824a1 1 0 011.617-.824z"})]}),(0,i.jsx)("span",{className:"truncate",children:"Read Aloud"})]})}),pe&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{onClick:function(){H(!0),_(null),R(!0)},className:"flex-1 min-w-0",children:(0,i.jsxs)("button",{className:"w-full bg-gradient-to-r from-blue-500 to-blue-600 hover:from-blue-400 hover:to-blue-500 text-white font-medium py-3 px-4 rounded-lg shadow-md transform hover:scale-105 transition-all duration-200 flex items-center justify-center space-x-2",children:[(0,i.jsx)("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{d:"M13.586 3.586a2 2 0 112.828 2.828l-.793.793-2.828-2.828.793-.793zM11.379 5.793L3 14.172V17h2.828l8.38-8.379-2.83-2.828z"})}),(0,i.jsx)("span",{className:"truncate",children:"Write New"})]})}),(0,i.jsx)("div",{onClick:function(){return Z(!0)},className:"flex-1 min-w-0",children:(0,i.jsxs)("button",{className:"w-full bg-gradient-to-r from-orange-500 to-yellow-500 hover:from-orange-400 hover:to-yellow-400 text-white font-medium py-3 px-4 rounded-lg shadow-md transform hover:scale-105 transition-all duration-200 flex items-center justify-center space-x-2",children:[(0,i.jsx)("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 20 20",children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M11.3 1.046A1 1 0 0112 2v5h4a1 1 0 01.82 1.573l-7 10A1 1 0 018 18v-5H4a1 1 0 01-.82-1.573l7-10a1 1 0 011.12-.38z",clipRule:"evenodd"})}),(0,i.jsx)("span",{className:"truncate",children:"Challenge"})]})})]})]})}),(0,i.jsx)("div",{className:"bg-gradient-to-br from-purple-100 to-pink-100 rounded-2xl p-6 mt-6 max-w-md shadow-md border border-purple-200",children:(0,i.jsxs)("div",{className:"space-y-4",children:[(0,i.jsxs)("div",{className:"pb-4 border-b border-purple-200",children:[(0,i.jsx)("p",{className:"text-sm font-bold text-purple-900 mb-2",children:"\ud83d\udcf1 Type"}),(0,i.jsx)("p",{className:"text-base font-semibold text-gray-700",children:r===x.bookType.AUDIO?"\ud83c\udfa7 Audiobook":"\ud83d\udcd6 Ebook"})]}),(0,i.jsxs)("div",{children:[(0,i.jsx)("p",{className:"text-sm font-bold text-purple-900 mb-3",children:"\ud83d\udc6a Age Range"}),(0,i.jsx)("div",{className:"flex flex-wrap gap-2",children:t.ageRanges&&t.ageRanges.map((function(e,t){return(0,i.jsx)("span",{className:"inline-block bg-gradient-to-r from-purple-400 to-pink-400 text-white font-bold px-3 py-1 rounded-full text-xs shadow-md",children:e},t)}))})]})]})})]})})]})})})})}),(0,i.jsx)("div",{className:"bg-transparent pb-30 flex",children:(0,i.jsx)("div",{className:"container mx-auto px-4 md:px-6",children:(0,i.jsxs)("div",{className:"py-12",children:[(0,i.jsxs)("div",{className:"mb-8 animate-fade-in",children:[(0,i.jsx)("h2",{className:"text-3xl md:text-4xl font-bold text-transparent bg-clip-text bg-gradient-to-r from-purple-600 to-blue-600 mb-2",children:"\ud83d\udcd6 Story Summary"}),(0,i.jsx)("p",{className:"text-blue-700 text-base md:text-lg",children:"What's this book all about?"})]}),(0,i.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-8 mb-12",children:[(0,i.jsx)("div",{children:(0,i.jsx)("div",{className:"bg-white/70 backdrop-blur-sm rounded-2xl p-6 md:p-8 shadow-md border border-purple-200 animate-fade-in h-full",style:{animationDelay:"0.1s"},children:(0,i.jsx)("div",{className:"prose prose-sm md:prose-base max-w-none",children:(0,i.jsx)("p",{className:"text-gray-700 leading-relaxed text-base md:text-lg whitespace-pre-wrap",children:t.description})})})}),(0,i.jsx)("div",{children:(0,i.jsxs)("div",{className:"bg-gradient-to-br from-purple-100 to-pink-100 rounded-2xl p-6 md:p-8 shadow-md border border-purple-200 animate-fade-in h-full",style:{animationDelay:"0.2s"},children:[(0,i.jsx)("h3",{className:"text-xl font-bold text-purple-900 mb-6",children:"\ud83d\udcda Book Details"}),(0,i.jsxs)("div",{className:"space-y-5",children:[(0,i.jsxs)("div",{className:"pb-4 border-b border-purple-200",children:[(0,i.jsx)("p",{className:"text-sm font-bold text-purple-900 mb-2",children:"\ud83c\udf0d Language"}),(0,i.jsx)("p",{className:"text-base text-gray-700",children:t.languages&&t.languages.name})]}),(0,i.jsxs)("div",{className:"pb-4 border-b border-purple-200",children:[(0,i.jsx)("p",{className:"text-sm font-bold text-purple-900 mb-2",children:"\ud83d\uddfa\ufe0f Region"}),(0,i.jsx)("p",{className:"text-base text-gray-700",children:t.regi
1on})]}),t.genre&&(0,i.jsxs)("div",{className:"pb-4 border-b border-purple-200",children:[(0,i.jsx)("p",{className:"text-sm font-bold text-purple-900 mb-2",children:"\ud83c\udfad Genre"}),(0,i.jsx)("p",{className:"text-base text-gray-700",children:t.genre})]}),r===x.bookType.AUDIO&&(0,i.jsxs)("div",{className:"pb-4 border-b border-purple-200",children:[(0,i.jsx)("p",{className:"text-sm font-bold text-purple-900 mb-2",children:"\ud83c\udfa4 Narrator"}),(0,i.jsx)("p",{className:"text-base text-gray-700",children:t.narrator})]}),(0,i.jsxs)("div",{children:[(0,i.jsx)("p",{className:"text-sm font-bold text-purple-900 mb-3",children:"\ud83d\udc6a Age Range"}),(0,i.jsx)("div",{className:"flex flex-wrap gap-2",children:t.ageRanges&&t.ageRanges.map((function(e,t){return(0,i.jsx)("span",{className:"bg-gradient-to-r from-purple-400 to-pink-400 text-white text-xs md:text-sm font-bold px-4 py-2 rounded-full shadow-md",children:e},t)}))})]})]})]})})]})]})})}),L&&(0,i.jsx)(J,{book:t,isOpen:L,editingWriting:P,forceNewWriting:V,onBack:P?function(){_(null),R(!1),D(!0)}:null,onClose:function(){R(!1),_(null),H(!1),fe()}}),T&&(0,i.jsx)(O,{book:t,isOpen:T,onClose:function(){return D(!1)},onEditWriting:function(e){_(e),D(!1),R(!0)},onWritingDeleted:function(){fe()}}),I&&(0,i.jsx)(U,{bookId:t.id,bookTitle:t.title,bookContent:(0,w.Yl)(t),onComplete:je,onClose:function(){return Z(!1)}}),(0,i.jsx)(X,{open:se,message:"\ud83c\udf89 You've finished reading this book!\n\nThe Sequence Quest is still waiting for you. Would you like to complete it now?",onPlay:function(){ne(!1),te(!0)},onDismiss:function(){return ne(!1)}}),K&&xe&&me&&(0,i.jsx)(k.Z,{bookId:t.id,bookTitle:t.title,bookAgeRanges:t.ageRanges,bookContent:(0,w.Yl)(t),onComplete:function(){be({silent:!0}),ne(!1)},onClose:function(){te(!1),be()}}),(0,i.jsx)(ee,{open:ce,message:"\ud83c\udf89 You've finished reading this book!\n\nWould you like to complete the Comprehension Check now?",onPlay:function(){de(!1),ie(!0)},onDismiss:function(){return de(!1)}}),le&&xe&&!me&&(0,i.jsx)(F.Z,{bookId:t.id,bookTitle:t.title,bookCover:t.image,bookAgeRanges:t.ageRanges,bookContent:(0,w.Yl)(t),source:N.f.SOURCE_LIBRARY,onComplete:function(){be({silent:!0}),de(!1)},onClose:function(){ie(!1),be()}})]})},re=r(30381),se=r.n(re),ne=r(96352),ae=(r(10374),function(e){var t=e.bookMedia,r=e.changeAudioPlayerStatus,s=e.bookDetails,l=e.ratingsExists,d=e.changeRatingsPopUpStatus,u=(0,o.useContext)(f.f),m=u.trackData,x=u.setTrackDataDetails,h=u.saveTrackDetails,g=(0,c.useRouter)();(0,o.useEffect)((function(){var e=function(e){r();var t=new Date,s=se()(t),l=se()(m.startTime),i=s.diff(l,"seconds"),o=(0,a.Z)((0,n.Z)({},m),{endTime:t,currenttotalTime:i});h(o),x(o,!1)};return g.events.on("routeChangeStart",e),function(){g.events.off("routeChangeStart",e)}}));var p=(0,i.jsx)("div",{className:"",children:(0,i.jsx)("img",{className:"h-8 w-8",src:"/img/player/play.svg",width:"50",height:"50",alt:"play"})}),b=(0,i.jsx)("div",{className:"",children:(0,i.jsx)("img",{className:"h-8 w-8",src:"/img/player/pause.svg",width:"50",height:"50",alt:"pause"})}),v=(0,i.jsx)("div",{className:"",children:(0,i.jsx)("img",{className:"h-6 w-6",src:"/img/player/rewind.svg",width:"50",height:"50",alt:"rewind"})}),j=(0,i.jsx)("div",{className:"",children:(0,i.jsx)("img",{className:"h-6 w-6",src:"/img/player/fwd.svg",width:"50",height:"50",alt:"forward"})}),w=(0,i.jsx)("div",{className:"",children:(0,i.jsx)("img",{className:"h-5 w-5",src:"/img/player/repeat.svg",width:"50",height:"50",alt:"loop"})}),y=(0,i.jsx)("div",{className:"",children:(0,i.jsx)("img",{className:"h-5 w-5",src:"/img/player/minus.svg",width:"50",height:"50",alt:"loop-off"})}),N=(0,i.jsx)("div",{className:"",children:(0,i.jsx)("img",{className:"h-5 w-5",src:"/img/player/volume.svg",width:"50",height:"50",alt:"volume"})}),k=(0,i.jsx)("div",{className:"",children:(0,i.jsx)("img",{className:"h-5 w-5",src:"/img/player/muted.svg",width:"50",height:"50",alt:"mute"})}),C=(0,i.jsxs)("div",{className:"flex m-2 p-1 ml-3 mb-8 justify-around content-center ",children:[(0,i.jsx)("div",{className:"h-20 w-20 justify-center mt-2",children:(0,i.jsx)("img",{className:"rounded-xl",src:s.image,width:80,height:60,alt:"image"})}),(0,i.jsxs)("div",{className:"justify-center content-center ml-5 mt-2 w-full pt-2",children:[(0,i.jsx)("p",{className:"inline font-sans align-middle text-xl font-bold text-white w-full mt-2",children:s.title}),(0,i.jsxs)("p",{className:" font-sans align-middle text-sm font-semibold text-white",children:["By: ",s.authorName]})]})]}),S=(0,i.jsx)("div",{children:(0,i.jsx)("p",{className:"font-sans text-xs font-semibold text-white",children:s.narrator?"Narrated by "+s.narrator:null})});
1return(0,i.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,i.jsxs)("div",{className:"flex flex-col items-center justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,i.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,i.jsx)("div",{className:"absolute inset-0 bg-gray-light opacity-75"})}),(0,i.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"\u200b"}),(0,i.jsxs)("div",{className:"inline-block w-full content-center align-bottom items-center justify-center bg-about-banner bg-cover bg-no-repeat bg-center rounded-md text-center overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",role:"dialog","aria-modal":"true","aria-labelledby":"modal-headline",children:[(0,i.jsx)("div",{onClick:function(){r();var e=new Date,t=se()(e),s=se()(m.startTime),i=t.diff(s,"seconds"),o=(0,a.Z)((0,n.Z)({},m),{endTime:e,currenttotalTime:i});h(o),x(o,!1),l||d()},className:"modal-close self-center text-center absolute p-1 w-0 h-10 top-0 right-0 cursor-pointer flex flex-col items-center mt-4 mr-4 text-white text-bold z-50 order-none flex-grow-0",children:(0,i.jsx)("svg",{className:"fill-current text-gray",xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18",children:(0,i.jsx)("path",{d:"M14.53 4.53l-1.06-1.06L9 7.94 4.53 3.47 3.47 4.53 7.94 9l-4.47 4.47 1.06 1.06L9 10.06l4.47 4.47 1.06-1.06L10.06 9z"})})}),(0,i.jsx)("div",{className:"flex flex-col items-center mt-1",children:(0,i.jsx)("div",{className:"flex flex-col items-center w-full p-0 static md:w-4/5 h-4/5 left-36 inset-y-20 flex-none order-1 self-center flex-grow-0 my-5 mx-2.5",children:(0,i.jsx)(ne.Z,{src:t,layout:"stacked-reverse",autoPlay:!0,header:C,footer:S,customIcons:{play:p,pause:b,rewind:v,forward:j,loop:w,loopOff:y,volume:N,volumeMute:k}})})})]})]})})}),le=function(e){var t=e.recomendedBooks,r=e.onFavoriteClick,s=e.onNullFavoriteClick;return(0,i.jsx)("div",{className:"bg-gradient-to-br from-blue-50 via-purple-50 to-pink-50 pb-20 flex",children:(0,i.jsx)("div",{className:"container mx-auto px-4 md:px-6",children:(0,i.jsxs)("div",{className:"py-10",children:[(0,i.jsxs)("div",{className:"mb-8 animate-fade-in",children:[(0,i.jsx)("h2",{className:"text-3xl md:text-4xl font-bold text-transparent bg-clip-text bg-gradient-to-r from-purple-600 to-blue-600",children:"You Might Like"}),(0,i.jsx)("p",{className:"text-blue-700 text-base md:text-lg mt-2",children:"Similar books picked just for you"})]}),(0,i.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6 gap-4 mb-12",children:t.map((function(e,t){return(0,i.jsx)(p(),{href:"/book/".concat(e.id),children:(0,i.jsxs)("div",{className:"group h-full cursor-pointer animate-fade-in",style:{animationDelay:"".concat(50*t,"ms")},children:[(0,i.jsxs)("div",{className:"relative h-64 rounded-2xl overflow-hidden shadow-lg transition-all duration-500 hover:shadow-2xl hover:scale-105 hover:-rotate-2 bg-gradient-to-br from-pink-400 to-purple-400 hover:shadow-purple-400/50",children:[(0,i.jsx)("img",{className:"w-full h-full object-cover group-hover:scale-125 transition-transform duration-500",src:e.image,alt:e.title,loading:"lazy"}),(0,i.jsx)("div",{className:"absolute inset-0 bg-gradient-to-t from-black/90 via-black/40 to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-500"}),(0,i.jsxs)("div",{className:"absolute top-2 left-2 right-2 flex items-center justify-between transform group-hover:translate-y-0 transition-transform duration-500",children:[(0,i.jsx)("button",{onClick:function(t){t.preventDefault(),null===e.favorite?s(e.id):r(e.id,e.favorite.id,e.favorite.isLiked)},className:"backdrop-blur-md p-2 rounded-full transition-all duration-300 hover:scale-110 hover:animate-bounce bg-white/60 hover:bg-red-400/80",children:e.favorite&&e.favorite.isLiked?(0,i.jsx)("span",{className:"text-lg",children:"\u2764\ufe0f"}):(0,i.jsx)("span",{className:"text-lg",children:"\ud83e\udd0d"})}),null===e.averageRating?(0,i.jsxs)("div",{className:"flex items-center gap-1 backdrop-blur-md px-2 py-1 rounded-full font-bold transition-all duration-300 bg-white/60",children:[(0,i.jsx)("span",{className:"text-sm",children:"\u2b50"}),(0,i.jsx)("span",{className:"text-xs font-bold text-yellow-700",children:"New"})]}):(0,i.jsxs)("div",{className:"flex items-center gap-1 backdrop-blur-md px-2 py-1 rounded-full font-bold transition-all duration-300 bg-white/60",children:[(0,i.jsx)("span",{className:"text-sm",children:"\u2b50"}),(0,i.jsx)("span",{className:"text-xs font-bold text-yellow-700",children:Math.round(10*e.averageRating)/10})]})]}),(0,i.jsx)("div",{className:"absolute bottom-2 left-2 flex items-center gap-2",children:(0,i.jsxs)("div",{className:"flex items-center gap-1 backdrop-blur-md px-2 py-1 rounded-full font-bold text-white transition-all duration-300 bg-white/60 hover:bg-white/80",children:[(0,i.jsx)("span",{className:"text-sm",children:e.bookType===x.bookType.AUDIO?"\ud83d\udd0a":e.bookType===x.bookType.EPUB?"\ud83d\udcd6":"\ud83d\udcda"}),(0,i.jsx)("span",{className:"text-xs font-bold",children:e.bookType===x.bookType.AUDIO?"Audio":e.bookType===x.bookType.EPUB?"eBook":"Read Aloud"})]})})]}),(0,i.jsxs)("div",{className:"mt-4 space-y-1",children:[(0,i.jsx)("h3",{className:"text-base font-bold group-hover:text-lg line-clamp-2 transition-all duration-300 text-blue-900 group-hover:text-purple-600",children:e.title}),(0,i.jsxs)("p",{className:"text-sm group-hover:text-base transition-all duration-300 text-purple-600 hover:text-purple-800",children:["by ",e.authorName]})]})]})},e.id)}))})]})})})},ie=r(60357),oe=r.n(ie),ce=(r(79903),r(54586),r(91569)),de=r(31085),ue=r(86824),me=function(){return(0,i.jsx)("div",{className:"md:h-px py-2 md:py-16 bg-book-detail
1s bg-cover bg-no-repeat bg-center",children:(0,i.jsx)("div",{className:"container mx-auto px-6",children:(0,i.jsx)("div",{className:"sm:flex sm:mt-8 ",children:(0,i.jsx)("div",{className:"animate-pulse sm:w-full sm:px-8 flex flex-col md:flex-row justify-center md:justify-between",children:(0,i.jsxs)("div",{className:"mt-0 md:mt-16 grid grid-cols-1 md:grid-cols-2 gap-2 md:gap-4",children:[(0,i.jsxs)("div",{className:"mx-0 tb:mx-4 md:ml-16 md:mr-32 grid justify-items-center",children:[(0,i.jsx)("div",{className:"h-96 w-64 px-4 md:px-0 sm:shadow-sm md:shadow-xl flex justify-center mb-4 md:mb-10",children:(0,i.jsx)("div",{className:"shadow-inner rounded align-middle border-none bg-white opacity-20 h-96 w-64"})}),(0,i.jsxs)("div",{className:"flex justify-center mb-4 md:mb-0",children:[(0,i.jsx)("div",{className:"rounded-full bg-white opacity-20 h-14 w-14 flex items-center justify-center mr-4"}),(0,i.jsx)("div",{className:"rounded-full bg-white opacity-20 h-14 w-14 flex items-center justify-center mr-4"})]})]}),(0,i.jsx)("div",{className:"mb-10 md:mb-0 flex justify-center",children:(0,i.jsxs)("div",{children:[(0,i.jsx)("div",{className:"h-6 bg-white opacity-20 rounded w-32"}),(0,i.jsx)("div",{className:"h-10 bg-white opacity-20 rounded w-44 mt-2"}),(0,i.jsx)("div",{className:"cursor-pointer flex-row inline-flex items-center mt-4",children:(0,i.jsx)("div",{className:"h-6 bg-white opacity-20 rounded w-36"})}),(0,i.jsx)("div",{children:(0,i.jsx)("div",{className:"h-6 bg-white opacity-20 rounded w-32"})}),(0,i.jsx)("div",{className:"cursor-pointer flex-col inline-flex items-center mt-10",children:(0,i.jsx)("div",{className:"cursor-pointer rounded-full bg-white opacity-20 h-14 w-14 flex items-center justify-center"})}),(0,i.jsx)("div",{className:"cursor-pointer flex-col inline-flex ml-5 items-center",children:(0,i.jsx)("div",{className:" cursor-pointer rounded-full bg-white opacity-20 h-14 w-14 flex items-center justify-center "})}),(0,i.jsx)("div",{className:"cursor-pointer justify-start flex my-4 md:my-10",children:(0,i.jsx)("div",{className:"rounded shadow-sm cursor-pointer bg-white opacity-20 h-12 w-40 flex items-center justify-center "})}),(0,i.jsx)("div",{className:"cursor-pointer justify-start flex md:my-10",children:(0,i.jsx)("div",{className:"rounded shadow-sm cursor-pointer bg-white opacity-20 h-12 w-48 flex items-center justify-center "})})]})})]})})})})})},xe=r(98713),he=r(16494),ge=r(59697),pe=r(46044),fe=(r(42283),r(78230),r(99469)),be=function(e){var t=e.bookItemId,r=e.changeRatingsPopUpStatus,n=((0,c.useRouter)().query.redirect,(0,o.useState)(0)),a=n[0],x=n[1],h=(0,o.useState)(t),g=h[0],p=(h[1],(0,o.useState)(!1)),f=p[0],b=p[1],v=function(){x(0),r()},j=function(){var e=(0,s.Z)((function(e){var t,s,n;return(0,l.__generator)(this,(function(a){switch(a.label){case 0:if(0===e)return alert("Please select a rating"),[2];b(!0),a.label=1;case 1:return a.trys.push([1,3,4,5]),t=d.g.user.attributes.email,s={isRated:!0,bookId:g,email:t,myRating:e},[4,u.b.graphql((0,m.wT)("\n  mutation CreateRating(\n    $input: CreateRatingInput!\n    $condition: ModelRatingConditionInput\n  ) {\n    createRating(input: $input, condition: $condition) {\n      id\n      email\n      bookId\n      books {\n        id\n        title\n        description\n        image\n        ageId\n        region\n        isbn\n        narrator\n        status\n        createdAt\n        updatedAt\n        isDeleted\n        book\n        bookType\n        authorName\n        authorId\n        duration\n        authors {\n          id\n          name\n          description\n          status\n          createdAt\n          updatedAt\n          image\n          isDeleted\n        }\n        languageId\n        languages {\n          id\n          name\n          status\n          createdAt\n          updatedAt\n        }\n      }\n      isRated\n      myRating\n      createdAt\n      updatedAt\n    }\n  }\n",{input:s}))];case 2:return a.sent(),x(0),r(),window.location.reload(),[3,5];case 3:return n=a.sent(),console.error("Error submitting rating:",n),alert("Error submitting rating. Please try again."),[3,5];case 4:return b(!1),[7];case 5:return[2]}}
1))}));return function(t){return e.apply(this,arguments)}}(),w=function(){return(0,i.jsx)("svg",{className:"cursor-pointer transition-transform hover:scale-110",width:"32",height:"32",viewBox:"0 0 24 25",fill:"#FFD700",xmlns:"http://www.w3.org/2000/svg",children:(0,i.jsx)("path",{d:"M11 1L14.09 7.26L21 8.27L16 13.14L17.18 20.02L11 16.77L4.82 20.02L6 13.14L1 8.27L7.91 7.26L11 1Z",stroke:"#FFA500",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})},y=function(){return(0,i.jsx)("svg",{className:"cursor-pointer transition-transform hover:scale-110",width:"32",height:"32",viewBox:"0 0 24 25",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,i.jsx)("path",{d:"M11 1L14.09 7.26L21 8.27L16 13.14L17.18 20.02L11 16.77L4.82 20.02L6 13.14L1 8.27L7.91 7.26L11 1Z",stroke:"#D1D5DB",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})};return(0,i.jsx)("div",{className:"fixed z-50 inset-0 overflow-y-auto bg-black/50 backdrop-blur-sm flex items-center justify-center p-4 animate-fadeIn",children:(0,i.jsxs)("div",{className:"jsx-9ded3e5a74f79fae relative bg-white rounded-2xl shadow-2xl max-w-md w-full p-8 transform transition-all",children:[(0,i.jsx)("button",{onClick:v,"aria-label":"Close",className:"jsx-9ded3e5a74f79fae absolute top-4 right-4 p-2 hover:bg-gray-100 rounded-full transition-colors",children:(0,i.jsx)("svg",{fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",className:"jsx-9ded3e5a74f79fae w-6 h-6 text-gray-500",children:(0,i.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12",className:"jsx-9ded3e5a74f79fae"})})}),(0,i.jsxs)("div",{className:"jsx-9ded3e5a74f79fae text-center mb-8",children:[(0,i.jsx)("h2",{className:"jsx-9ded3e5a74f79fae text-3xl font-bold bg-gradient-to-r from-purple-600 to-blue-600 bg-clip-text text-transparent mb-2",children:"\u2b50 Rate This Book"}),(0,i.jsx)("p",{className:"jsx-9ded3e5a74f79fae text-gray-600 text-base",children:"What did you think about this book?"})]}),(0,i.jsx)("div",{className:"jsx-9ded3e5a74f79fae flex justify-center gap-4 mb-10",children:(0,i.jsx)(fe.Z,{emptySymbol:(0,i.jsx)(y,{className:"jsx-9ded3e5a74f79fae"}),fullSymbol:(0,i.jsx)(w,{className:"jsx-9ded3e5a74f79fae"}),onChange:function(e){return x(e)},stop:5,initialRating:a})}),a>0&&(0,i.jsx)("div",{className:"jsx-9ded3e5a74f79fae text-center mb-8 animate-fadeIn",children:(0,i.jsxs)("p",{className:"jsx-9ded3e5a74f79fae text-lg font-semibold text-gray-700",children:[1===a&&"Not my favorite \ud83d\ude1e",2===a&&"Could be better \ud83d\ude10",3===a&&"It was good! \ud83d\ude0a",4===a&&"Really enjoyed it! \ud83d\ude04",5===a&&"Absolutely loved it! \ud83e\udd29"]})}),(0,i.jsxs)("div",{className:"jsx-9ded3e5a74f79fae flex gap-3",children:[(0,i.jsx)("button",{onClick:function(){return j(a)},disabled:f||0===a,className:"jsx-9ded3e5a74f79fae flex-1 bg-gradient-to-r from-purple-600 to-blue-600 hover:from-purple-700 hover:to-blue-700 disabled:from-gray-400 disabled:to-gray-400 text-white font-bold py-3 px-6 rounded-xl transition-all transform hover:scale-105 active:scale-95 disabled:cursor-not-allowed disabled:scale-100 flex items-center justify-center gap-2",children:f?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",className:"jsx-9ded3e5a74f79fae animate-spin h-5 w-5",children:[(0,i.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4",className:"jsx-9ded3e5a74f79fae opacity-25"}),(0,i.jsx)("path",{fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z",className:"jsx-9ded3e5a74f79fae opacity-75"})]}),"Submitting..."]}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("span",{className:"jsx-9ded3e5a74f79fae",children:"Submit Rating"}),(0,i.jsx)("svg",{fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",className:"jsx-9ded3e5a74f79fae w-5 h-5",children:(0,i.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M13 7l5 5m0 0l-5 5m5-5H6",className:"jsx-9ded3e5a74f79fae"})})]})}),(0,i.jsx)("button",{onClick:v,disabled:f,className:"jsx-9ded3e5a74f79fae flex-1 bg-gray-100 hover:bg-gray-200 disabled:bg-gray-100 text-gray-700 font-semibold py-3 px-6 rounded-xl transition-all hover:scale-105 active:scale-95 disabled:scale-100",children:"Maybe Later"})]}),(0,i.jsx)("div",{className:"jsx-9ded3e5a74f79fae mt-6 pt-6 border-t border-gray-200",children:(0,i.jsx)("p",{className:"jsx-9ded3e5a74f79fae text-center text-sm text-gray-500",children:"\ud83d\udca1 Your rating helps other readers discover great books!"})}),(0,i.jsx)(oe(),{id:"9ded3e5a74f79fae",children:"@-webkit-keyframes fadeIn{from{opacity:0;-webkit-transform:scale(.95);transform:scale(.95)}to{opacity:1;-webkit-transform:scale(1);transform:scale(1)}}@-moz-keyframes fadeIn{from{opacity:0;-moz-transform:scale(.95);transform:scale(.95)}to{opacity:1;-moz-transform:scale(1);transform:scale(1)}}@-o-keyframes fadeIn{from{opacity:0;-o-transform:scale(.95);transform:scale(.95)}to{opacity:1;-o-transform:scale(1);transform:scale(1)}}@keyframes fadeIn{from{opacity:0;-webkit-transform:scale(.95);-moz-transform:scale(.95);-o-transform:scale(.95);transform:scale(.95)}to{opacity:1;-webkit-transform:scale(1);-moz-transform:scale(1);-o-transform:scale(1);transform:scale(1)}}.animate-fadeIn.jsx-9ded3e5a74f79fae{-webkit-animation:fadeIn.3s ease-in-out;-moz-animation:fadeIn.3s ease-in-out;-o-animation:fadeIn.3s ease-in-out;animation:fadeIn.3s ease-in-out}"})]})})},ve=r(58197),je=r(24278),we=r(3538),ye=function(e){var t=e.id,r=e.ratingsExists,s=(e.myRatings,e.bookMedia,e.changeAudioPlayerStatus,e.changeRatingsPopUpStatus,(0,c.useRouter)()),n=(0,o.useContext)(f.f),a=n.setRatingsExists,l=n.setBookOpenedFromComponent;return(0,o.useEffect)((function(){a(r),l(!0),s.push("/reader/".concat(t,"?fromBook=1"))}),[]),(0,i.jsx)(i.Fragment,{})},Ne=function(){var e=(0,c.useRouter)(),t=e.query.id,r=(0,o.useContext)(G.V),h=r.setUserDetails,g=r.changeLoginFormStatus,p=(0,o.useContext)(f.f),b=p.setTrackDataDetail
1s,v=p.setAnalytics,j=p.showRatingsModal,w=(p.setShowRatingsModal,(0,o.useState)(null)),y=w[0],N=w[1],k=(0,o.useState)(!1),C=k[0],S=k[1],A=(0,o.useState)(!1),L=A[0],R=A[1],M=(0,o.useState)(!0),T=M[0],D=M[1],B=(0,o.useState)(!0),I=B[0],Z=B[1],z=(0,o.useState)(""),W=z[0],E=z[1],P=(0,o.useState)(!1),_=P[0],q=P[1],V=(0,o.useState)(!1),H=V[0],U=V[1],F=(0,o.useState)([]),O=F[0],Y=F[1],Q=(0,o.useState)(!0),$=Q[0],K=Q[1],J=(0,o.useState)(!1),X=J[0],ee=J[1],re=(0,o.useState)(""),se=re[0],ne=re[1],ie=(0,o.useState)(""),oe=ie[0],fe=ie[1],Ne=(0,o.useState)(""),ke=Ne[0],Ce=Ne[1],Se=(0,o.useState)(!1),Ae=Se[0],Le=Se[1],Re=(0,o.useState)(),Me=Re[0],Te=Re[1],De=(0,o.useState)(0),Be=De[0],Ie=De[1];(0,o.useEffect)((function(){U(j)}),[j]),(0,o.useEffect)((function(){var r=function(){var r=(0,s.Z)((function(){var r,s,n,a,i,o,c,u,m,p,f,b,v;return(0,l.__generator)(this,(function(l){switch(l.label){case 0:return l.trys.push([0,20,,26]),[4,d.g.currentAuthenticatedUser()];case 1:return r=l.sent(),h(r),(s=r.signInUserSession.accessToken.payload["cognito:groups"])&&s.includes(x.userRole.admin)?(e.push("/admin/author"),[3,19]):[3,2];case 2:return s&&(s.includes(x.userRole.school)||s.includes(x.userRole.teacher))?(Z(!1),(n=t)&&_e(n),[3,19]):[3,3];case 3:return"student"!==d.g.user.attributes["custom:usertype"]?[3,7]:[4,ze()];case 4:return(a=l.sent())&&null!=a.expiryDate?[3,6]:[4,e.push("/subscription/school")];case 5:return l.sent(),[2];case 6:return i=new Date(a.expiryDate),o=new Date,i<o?e.push("/subscription/school"):(Z(!1),(c=t)&&_e(c)),[3,19];case 7:return[4,Ze()];case 8:return(u=l.sent())?[3,10]:[4,e.push("/subscription")];case 9:return l.sent(),[2];case 10:return(0,ve.ek)(u)?[4,(0,ve.Vb)(d.g.user.attributes.email)]:[3,14];case 11:return l.sent().length>=1?[4,e.push("/subscription")]:[3,13];case 12:return l.sent(),[2];case 13:return Z(!1),(m=t)&&_e(m,!0),[2];case 14:return u.nextBillingDate?[3,16]:[4,e.push("/subscription")];case 15:return l.sent(),[2];case 16:return p=new Date(u.nextBillingDate),f=new Date,!u.isActive&&p<f?[4,e.push("/subscription")]:[3,18];case 17:return l.sent(),[3,19];case 18:Z(!1),(b=t)&&_e(b),l.label=19;case 19:return[3,26];case 20:v=l.sent(),console.log("Book page auth error:",v),l.label=21;case 21:return l.trys.push([21,23,,25]),[4,d.g.currentAuthenticatedUser()];case 22:return l.sent()?(Z(!1),[2]):[3,25];case 23:return l.sent(),[4,e.push("/?redirect=book/"+t)];case 24:return l.sent(),g(),[3,25];case 25:return[3,26];case 26:return[2]}}
1))}));return function(){return r.apply(this,arguments)}}();r()}),[t]);var Ze=function(){var e=(0,s.Z)((function(){return(0,l.__generator)(this,(function(e){return[2,(0,ve.mh)(d.g.user.attributes.email)]}))}));return function(){return e.apply(this,arguments)}}(),ze=function(){var e=(0,s.Z)((function(){return(0,l.__generator)(this,(function(e){return[2,(0,je.Tp)(d.g.user.attributes["custom:code"])]}))}));return function(){return e.apply(this,arguments)}}(),We=function(){q(!_)},Ee=function(){U(!H)},Pe=function(){var e=(0,s.Z)((function(e,t){var r,s;return(0,l.__generator)(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,u.b.graphql((0,m.wT)(de.aD,{filter:{and:[{bookId:{eq:e}},{email:{eq:t}}]},limit:1}))];case 1:return(r=n.sent()).data.searchRatings.items.length>0?[2,r.data.searchRatings.items[0]]:[2,null];case 2:return s=n.sent(),console.error("Error fetching rating:",s),[2,null];case 3:return[2]}}))}));return function(t,r){return e.apply(this,arguments)}}(),_e=function(){var e=(0,s.Z)((function(e){var t,r,s,i,o,c,h,g,p,f,j,w,y=arguments;return(0,l.__generator)(this,(function(l){switch(l.label){case 0:t=y.length>1&&void 0!==y[1]?y[1]:null,l.label=1;case 1:return l.trys.push([1,13,,14]),[4,u.b.graphql((0,m.wT)(ce.v9,{id:e},{}))];case 2:return(r=l.sent()).data.getBook.bookType!==x.bookType.EPUB&&r.data.getBook.bookType!==x.bookType.READALOUD||N((function(){return r.data.getBook.book})),null==t||!0!==r.data.getBook.isLocked?[3,3]:(ee(!0),ne("Subscribe to unlock book."),[3,12]);case 3:return null!==r.data.getBook&&!1!==r.data.getBook.status&&r.data.getBook.isDeleted!==x.isDeleted.yes?[3,4]:(ee(!0),ne("Book not found."),[3,12]);case 4:return S(r.data.getBook.bookType),R(r.data.getBook),E(r.data.getBook.book),fe(r.data.getBook.id),s=r.data.getBook,i=d.g.user.attributes.email,[4,Pe(e,i)];case 5:return(o=l.sent())?(s.rating=o,o.myRating?(Te(o.myRating),Le(!0)):Le(!1)):Le(!1),[4,(0,ge.N9)()];case 6:return c=l.sent(),(0,ge.Ru)(c,{id:{eq:r.data.getBook.id},status:{eq:!0}}).forEach((function(e){var t,r=0;e.averageRating=null,((null===(t=e.ratings)||void 0===t?void 0:t.items)||[]).forEach((function(e){r+=e.myRating})),r>0&&(e.averageRating=r/e.ratings.items.length,Ie(e.averageRating),Ce(e.ratings.items.length))})),[4,(0,we.T0)(d.g.user.attributes.email,e)];case 7:return(h=l.sent())?(b(h),v(h.id),localStorage.setItem("analyticsId",h.id),g={id:h.id,updatedAt:new Date},[4,u.b.graphql((0,m.wT)(xe.lk,{input:g}))]):[3,9];case 8:return l.sent(),[3,11];case 9:return p=null,"student"!==d.g.user.attributes["custom:usertype"]&&"school"!==d.g.user.attributes["custom:usertype"]&&"teacher"!==d.g.user.attributes["custom:usertype"]||(p={schoolCode:d.g.user.attributes["custom:code"]}),f=(0,a.Z)((0,n.Z)({email:d.g.user.attributes.email,firstName:d.g.user.attributes["custom:first_name"],lastName:d.g.user.attributes["custom:last_name"],bookId:e,videoId:"null"},p),{totalTime:0,openedDate:new Date}),b(f),[4,u.b.graphql((0,m.wT)(xe.ZH,{input:f}))];case 10:j=l.sent(),v(j.data.createAnalytics.id),localStorage.setItem("analyticsId",j.data.createAnalytics.id),l.label=11;case 11:D(!1),He(e,r.data.getBook),l.label=12;case 12:return[3,14];case 13:return w=l.sent(),console.log(w),[3,14];case 14:return[2]}}
1))}));return function(t){return e.apply(this,arguments)}}(),qe=function(){var e=(0,s.Z)((function(e,t,r){var s,n,a,i;return(0,l.__generator)(this,(function(l){switch(l.label){case 0:return s=!r,-1!==(n=O.findIndex((function(t){return t.id===e})))&&((a=O.slice())[n].favorite.isLiked=s,Y(a)),i={id:t,isLiked:s},[4,u.b.graphql((0,m.wT)(xe.d3,{input:i}))];case 1:return l.sent(),[2]}}))}));return function(t,r,s){return e.apply(this,arguments)}}(),Ve=function(){var e=(0,s.Z)((function(e){var t,r,s,n,a;return(0,l.__generator)(this,(function(l){switch(l.label){case 0:return t=d.g.user.attributes.email,r={isLiked:!0,bookId:e,email:t},[4,u.b.graphql((0,m.wT)(xe.G9,{input:r}))];case 1:return s=l.sent(),-1!==(n=O.findIndex((function(t){return t.id===e})))&&((a=O.slice())[n].favorite=s.data.createFavoriteBook,Y(a)),[2]}}))}));return function(t){return e.apply(this,arguments)}}(),He=function(){var e=(0,s.Z)((function(e,t){var r,s,n,a,i,o,c;return(0,l.__generator)(this,(function(l){switch(l.label){case 0:return l.trys.push([0,3,,4]),[4,(0,ge.N9)()];case 1:return r=l.sent(),s=t.ageRanges||[],n=function(e){for(var t,r,s=e.length;0!==s;)t=Math.floor(Math.random()*s),r=e[--s],e[s]=e[t],e[t]=r;return e}(n=(0,ge.Ru)(r,{id:{ne:e},status:{eq:!0}}).filter((function(e){return Array.isArray(e.ageRanges)&&e.ageRanges.some((function(e){return s.includes(e)}))}))),a=d.g.user.attributes.email,[4,u.b.graphql((0,m.wT)(ce.jF,{filter:{email:{eq:a}}}))];case 2:return i=l.sent(),o=i.data.listFavoriteBooks.items,n.forEac
1h((function(e){e.favorite=null,o.forEach((function(t){e.id===t.bookId&&(e.favorite=t)}))})),n.forEach((function(e){var t,r=0;e.averageRating=null;var s=(null===(t=e.ratings)||void 0===t?void 0:t.items)||[];s.forEach((function(e){r+=e.myRating})),r>0&&(e.averageRating=r/s.length)})),Y(n.slice(0,5)),K(!1),[3,4];case 3:return c=l.sent(),console.log(c),[3,4];case 4:return[2]}}))}));return function(t,r){return e.apply(this,arguments)}}();return(0,i.jsx)(i.Fragment,{children:I?(0,i.jsx)(he.Z,{}):(0,i.jsx)(ue.Z,{children:(0,i.jsxs)("div",{className:"min-h-screen bg-gradient-to-br from-purple-bright via-blue-bright to-pink-500 transition-colors duration-500",children:[X?(0,i.jsx)(pe.Z,{message:se}):T?(0,i.jsx)(me,{}):(0,i.jsxs)("main",{className:"",children:[(0,i.jsx)(te,{averageRating:Be,bookDetails:L,totalRatingsForBook:ke,myRatings:Me,changeAudioPlayerStatus:We,checkBookType:C}),x.bookType.AUDIO===L.bookType?_?(0,i.jsx)("div",{children:(0,i.jsx)(ae,{bookDetails:L,ratingsExists:Ae,myRatings:Me,bookMedia:W,changeAudioPlayerStatus:We,changeRatingsPopUpStatus:Ee})}):null:_?(0,i.jsx)("div",{children:(0,i.jsx)(ye,{id:t,bookUrl:y,ratingsExists:Ae,myRatings:Me,bookMedia:W,changeAudioPlayerStatus:We,changeRatingsPopUpStatus:Ee})}):null,H?(0,i.jsx)(be,{changeRatingsPopUpStatus:Ee,bookItemId:oe}):null]}),(0,i.jsx)("div",{children:$?null:(0,i.jsx)(le,{recomendedBooks:O,onFavoriteClick:qe,onNullFavoriteClick:Ve})})]})})})}}},function(e){e.O(0,[3714,1664,3456,7966,7982,2693,6817,2354,8876,3616,9424,9356,1531,8197,6849,6824,4325,9140,5489,9774,2888,179],(function(){return t=32539,e(e.s=t);var t}));var t=e.O();_N_E=t}]);

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.