import{j as e}from"./query-vendor-CZu0EHPe.js";import{u as Ye,r as h,L as Je}from"./react-vendor-0bvDbF03.js";import{c as Ve,e as $e,h as Ne,B as Pe,X as We,y as K,I as Z,at as Se,au as we,av as ke,aw as Ce,ax as Te,ab as ce,ac as le,ad as oe,ai as Xe,L as Ae,bw as he,g as Qe,J as D,s as ee,j as qe,i as Ze,u as es,f as ss,S as ts,G as rs,m as as,W as ns}from"./index-DEpNou_V.js";import{g as Ue,c as q}from"./story-generation-service-DxYZjUUA.js";import{T as cs}from"./textarea-FcV43nro.js";import{C as j,a as Y,b as J,e as ls,c as y}from"./card-BSpjaxcF.js";import{u as z}from"./i18n-vendor-Bg2yf_Zw.js";import{C as _e,a as os}from"./copy-BXtTtgia.js";import{S as is}from"./search-gqQGlNPa.js";import{C as Le}from"./chart-column-CsPR31wL.js";import{r as ds,B as ue,s as xs,R as Ie,T as Ee,o as Re}from"./generateCategoricalChart-ELqk-5Je.js";import{X as fe,Y as pe,C as De}from"./YAxis--g0EP5S3.js";import{g as ms,S as hs,a as us}from"./sesl-badge-utils-BvAx6z8X.js";import{S as G}from"./skeleton-QFJGP4Cz.js";import{C as fs,A as ps,d as gs,e as Be}from"./sesl-client-DajWxuf6.js";import{A as js}from"./arrow-right-O6kqU-KY.js";import{B as ys}from"./BreadcrumbNavigation-Bg8Iidj6.js";import{S as vs}from"./ShareCard-B3ZCfK-0.js";import{H as Ns}from"./helmet-vendor-NlTFkN97.js";import{R as bs}from"./refresh-ccw-Zn8lilYE.js";import"./supabase-vendor-CNV44oIa.js";/**
 * @license lucide-react v0.554.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ss=[["path",{d:"M16 5h6",key:"1vod17"}],["path",{d:"M19 2v6",key:"4bpg5p"}],["path",{d:"M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5",key:"1ue2ih"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}]],ws=Ve("image-plus",Ss);/**
 * @license lucide-react v0.554.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ks=[["path",{d:"m18 14 4 4-4 4",key:"10pe0f"}],["path",{d:"m18 2 4 4-4 4",key:"pucp1d"}],["path",{d:"M2 18h1.973a4 4 0 0 0 3.3-1.7l5.454-8.6a4 4 0 0 1 3.3-1.7H22",key:"1ailkh"}],["path",{d:"M2 6h1.972a4 4 0 0 1 3.6 2.2",key:"km57vx"}],["path",{d:"M22 18h-6.041a4 4 0 0 1-3.3-1.8l-.359-.45",key:"os18l9"}]],Cs=Ve("shuffle",ks),W="textCheckerDraft",Ge=1,Ts=24*60*60*1e3,be=()=>typeof window<"u",Oe=s=>{if(be())try{if(!s.text?.trim()&&!s.ageBand&&!s.cefrLevel){localStorage.removeItem(W);return}const a={v:Ge,savedAt:Date.now(),data:s};localStorage.setItem(W,JSON.stringify(a))}catch(a){console.warn("[textCheckerDraft] save failed:",a)}},As=()=>{if(!be())return null;try{const s=localStorage.getItem(W);if(!s)return null;const a=JSON.parse(s);return!a||a.v!==Ge||typeof a.savedAt!="number"||Date.now()-a.savedAt>Ts?(localStorage.removeItem(W),null):a.data||null}catch(s){return console.warn("[textCheckerDraft] load failed:",s),null}},Me=()=>{if(be())try{localStorage.removeItem(W)}catch{}};function _s({onAnalyze:s,isAnalyzing:a,ageRanges:l,isAuthenticated:o,generationLimit:t,limitLoading:b,analysisComplete:i,isSampleLoaded:r,onSampleLoaded:m,service:k="text_checker",initialText:d="",initialAgeBand:f="",initialCefrLevel:x=""}){const _=Ye(),{t:c}=z(["text-checker","generation"]),{getLocalizedPath:u}=$e(),[w,L]=h.useState(d),[I,p]=h.useState(f),[B,V]=h.useState(x),[$,X]=h.useState(!1),[O,E]=h.useState(!1),R=h.useRef(null),se=w.trim()?w.trim().split(/\s+/).length:0,P=se>500;h.useEffect(()=>{if(i||r)return;const n=setTimeout(()=>{Oe({text:w,ageBand:I,cefrLevel:B})},400);return()=>clearTimeout(n)},[w,I,B,i,r]);const U=()=>{Oe({text:w,ageBand:I,cefrLevel:B})},ie=n=>{r||L(n)},de=n=>{p(n);const N=he(n);V(N||"")},xe=n=>{V(n);const N=Qe(n);N&&N!=="Unknown"&&p(N)},te=async()=>{if(!o){U(),sessionStorage.setItem("pendingAuthRedirect",u("/text-checker")),D.error(c("signUpSampleToast")),_(u("/login"),{state:{redirectTo:u("/text-checker")}});return}X(!0);try{const{count:n}=await ee.from("stories").select("id",{count:"exact",head:!0}).gte("word_count",200).lte("word_count",400),N=Math.min(n||1,200),S=Math.floor(Math.random()*N),{data:C,error:T}=await ee.from("stories").select("text, age_range, cefr_level").gte("word_count",200).lte("word_count",400).range(S,S).limit(1).single();if(T||!C)throw new Error("Could not fetch a sample story");const M=C.text.split(/\s+/),Q=M.length>500?M.slice(0,500).join(" "):C.text;L(Q),m?.();let F="";if(C.age_range){const re=l.find(ae=>ae.age_band===C.age_range);if(re){F=re.age_band,p(F);const ae=he(F);V(ae||"")}}F&&s(Q,F,C.cefr_level||null)}catch(n){console.error(n),D.error(c("sampleError"))}finally{X(!1)}},me=async n=>{const N=n.target.files?.[0];if(N){if(!o){U(),sessionStorage.setItem("pendingAuthRedirect",u("/text-checker")),_(u("/login"),{state:{redirectTo:u("/text-checker")}});return}if(N.size>10*1024*1024){D.error(c("imageSizeError"));return}E(!0);try{const S=new FileReader,C=new Promise((F,re)=>{S.onload=()=>{const He=S.result.split(",")[1];F(He)},S.onerror=re});S.readAsDataURL(N);const T=await C,{data:M,error:Q}=await ee.functions.invoke("ocr-extract-text",{body:{imageBase64:T,mimeType:N.type}});if(Q)throw Q;if(M?.error)throw new Error(M.error);L(M.text||"")}catch(S){console.error("OCR error:",S),D.error(S.message||c("ocrError"))}finally{E(!1),R.current&&(R.current.value="")}}},v=()=>{if(!o){U(),sessionStorage.setItem("pendingAuthRedirect",u("/text-checker")),_(u("/login"),{state:{redirectTo:u("/text-checker")}});return}if(t&&!t.can_generate){D.error(t.message||c("limitReached")),t.user_type==="free"&&_(u("/subscription"));return}!w.trim()||!I||P||s(w.trim(),I)},g=Object.entries(Ne).map(([n,N])=>({value:n,label:N.label})),A=a||i||o&&(!w.trim()||!I||P)||o&&t!==null&&!t.can_generate;return e.jsxs(j,{children:[e.jsxs(Y,{children:[e.jsx(J,{className:"text-xl text-ink",children:c("cardTitle")}),e.jsx(ls,{children:c("cardDescription")})]}),e.jsxs(y,{className:"space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(cs,{value:w,onChange:n=>ie(n.target.value),placeholder:c("placeholder"),className:"min-h-[180px] text-base resize-y",disabled:O||r||i}),w&&!r&&!i&&e.jsx(Pe,{variant:"ghost",size:"icon",className:"absolute top-2 right-2 h-6 w-6 text-muted-foreground hover:text-ink",onClick:()=>L(""),children:e.jsx(We,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{className:`text-sm ${P?"text-destructive font-medium":"text-muted-foreground"}`,children:c("wordCount",{count:se})}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(K,{variant:"learn",size:"pillSm",onClick:()=>{if(!o){U(),sessionStorage.setItem("pendingAuthRedirect",u("/text-checker")),_(u("/login"),{state:{redirectTo:u("/text-checker")}});return}R.current?.click()},disabled:O||i,leftIcon:O?e.jsx(Z,{className:"animate-spin"}):e.jsx(ws,{}),children:c(O?"extracting":"uploadImage")}),e.jsx(K,{variant:"learn",size:"pillSm",onClick:te,disabled:$||i,leftIcon:$?e.jsx(Z,{className:"animate-spin"}):e.jsx(Cs,{}),children:c($?"choosingStory":"trySample")})]})]}),e.jsx("input",{type:"file",ref:R,className:"hidden",accept:"image/*",onChange:me}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:c("ageRangeLabel")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1",children:e.jsxs(Se,{value:I,onValueChange:de,disabled:i,children:[e.jsx(we,{children:e.jsx(ke,{placeholder:c("selectAge")})}),e.jsx(Ce,{children:l.map(n=>e.jsx(Te,{value:n.age_band,children:c("ages",{band:n.age_band})},n.age_band))})]})}),e.jsxs(ce,{children:[e.jsx(le,{asChild:!0,children:e.jsx(_e,{className:"h-4 w-4 text-muted-foreground cursor-help flex-shrink-0"})}),e.jsx(oe,{side:"top",className:"max-w-[240px]",children:c("ageTooltip")})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:c("cefrLabel")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1",children:e.jsxs(Se,{value:B,onValueChange:xe,disabled:i,children:[e.jsx(we,{children:e.jsx(ke,{placeholder:c("selectCefr")})}),e.jsx(Ce,{children:g.map(n=>e.jsx(Te,{value:n.value,children:n.label},n.value))})]})}),e.jsxs(ce,{children:[e.jsx(le,{asChild:!0,children:e.jsx(_e,{className:"h-4 w-4 text-muted-foreground cursor-help flex-shrink-0"})}),e.jsx(oe,{side:"top",className:"max-w-[240px]",children:c("cefrTooltip")})]})]})]})]}),o&&!b&&t&&e.jsx(j,{className:`${t.can_generate?"bg-nature-forest/10 border-nature-forest/30":"bg-nature-red/10 border-nature-red/30"}`,children:e.jsxs(y,{className:"pt-4 pb-4",children:[e.jsx("p",{className:`text-sm ${t.can_generate?"text-nature-forest":"text-nature-red"}`,children:Ue(t,c,k)}),!t.can_generate&&t.user_type==="free"&&e.jsx("div",{className:"mt-3",children:e.jsx(K,{variant:"premium",size:"pillSm",onClick:()=>_(u("/subscription")),leftIcon:e.jsx(Xe,{}),children:c("upgradeNow")})})]})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(K,{variant:"learn",onClick:v,disabled:A,className:"w-full sm:w-auto",leftIcon:a?e.jsx(Z,{className:"animate-spin"}):o?t&&!t.can_generate?e.jsx(Ae,{}):e.jsx(is,{}):e.jsx(Ae,{}),children:a?c("analysing"):o?t&&!t.can_generate?c("limitReached"):c(i?"analysisCompleteButton":"analyseButton"):c("signUpToAnalyse")})})]})]})}var Fe=ds({chartName:"BarChart",GraphicalChild:ue,defaultTooltipEventType:"axis",validateTooltipEventTypes:["axis","item"],axisComponents:[{axisType:"xAxis",AxisComp:fe},{axisType:"yAxis",AxisComp:pe}],formatAxisMap:xs});const Ls={Vocabulary:"var(--nature-forest)","Sentence Complexity":"var(--nature-purple)","Story Understanding":"var(--nature-honey-ink)","Reading Flow":"var(--nature-coral)"},Is={Vocabulary:"vocabulary","Sentence Complexity":"sentenceComplexity","Story Understanding":"storyUnderstanding","Reading Flow":"readingFlow"};function ge(s){return Object.entries({Vocabulary:["Vocabulary Complexity","ESL-Specific"],"Sentence Complexity":["Grammar & Syntax"],"Story Understanding":["Narrative Structure","Semantic & Conceptual"],"Reading Flow":["Cohesion & Discourse","Phonological","Cognitive Load","Visual & Typographical"]}).map(([l,o])=>{const t=[];for(const i of o){const r=s.find(m=>m.name===i);r&&typeof r.score=="number"&&t.push(r.score)}const b=t.length>0?t.reduce((i,r)=>i+r,0)/t.length:0;return{name:l,score:Math.round(b*10)/10,color:Ls[l]||"var(--nature-forest)"}})}const ne={fill:"hsl(var(--muted-foreground))"},H="hsl(var(--border))",Ke={borderRadius:"12px",fontSize:"13px",background:"hsl(var(--card))",border:"1px solid rgb(var(--nature-forest-rgb) / 0.25)",boxShadow:"0 4px 12px rgb(0 0 0 / 0.08)",color:"var(--ink)"};function je({scores:s,title:a,vertical:l=!1,maxDomain:o}){const{t}=z("text-checker");if(!s||s.length===0)return null;const b=(d,f=!1)=>{const x=Is[d];return x?t(`dimensions.${x}${f?"Short":""}`):d},i=a??t("skillDimensions"),r=t("scoreLabel"),m=o??Math.max(10,Math.ceil(Math.max(...s.map(d=>d.score))/10)*10);if(l){const d=s.map(f=>({...f,shortName:b(f.name,!0)}));return e.jsxs(j,{children:[e.jsx(Y,{className:"pb-2",children:e.jsxs(J,{className:"text-base flex items-center gap-2 text-ink",children:[e.jsx(Le,{className:"h-4 w-4 text-nature-coral"}),i]})}),e.jsx(y,{children:e.jsx(Ie,{width:"100%",height:200,children:e.jsxs(Fe,{data:d,margin:{top:5,right:10,left:10,bottom:5},children:[e.jsx(De,{strokeDasharray:"3 3",vertical:!1,stroke:H}),e.jsx(fe,{dataKey:"shortName",interval:0,tick:{...ne,fontSize:10},tickLine:!1,axisLine:{stroke:H}}),e.jsx(pe,{domain:[0,m],tick:{...ne,fontSize:11},tickLine:!1,axisLine:{stroke:H}}),e.jsx(Ee,{formatter:f=>[`${f.toFixed(1)}`,r],cursor:{fill:"rgb(var(--nature-forest-rgb) / 0.06)"},contentStyle:Ke}),e.jsx(ue,{dataKey:"score",radius:[6,6,0,0],animationDuration:800,children:d.map((f,x)=>e.jsx(Re,{fill:f.color},x))})]})})})]})}const k=s.map(d=>({...d,label:b(d.name)}));return e.jsxs(j,{children:[e.jsx(Y,{className:"pb-2",children:e.jsxs(J,{className:"text-base flex items-center gap-2 text-ink",children:[e.jsx(Le,{className:"h-4 w-4 text-nature-coral"}),i]})}),e.jsxs(y,{children:[e.jsx(Ie,{width:"100%",height:180,children:e.jsxs(Fe,{data:k,layout:"vertical",margin:{top:0,right:20,left:0,bottom:0},children:[e.jsx(De,{strokeDasharray:"3 3",horizontal:!1,stroke:H}),e.jsx(fe,{type:"number",domain:[0,m],tick:{...ne,fontSize:12},tickLine:!1,axisLine:{stroke:H}}),e.jsx(pe,{type:"category",dataKey:"label",width:160,interval:0,tick:{...ne,fontSize:11},tickLine:!1,axisLine:{stroke:H}}),e.jsx(Ee,{formatter:d=>[`${d.toFixed(1)}`,r],cursor:{fill:"rgb(var(--nature-forest-rgb) / 0.06)"},contentStyle:Ke}),e.jsx(ue,{dataKey:"score",radius:[0,6,6,0],animationDuration:800,children:k.map((d,f)=>e.jsx(Re,{fill:d.color},f))})]})}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:t("dimensionsFootnote")})]})]})}const Es={very_easy:"veryEasy",easy:"easy",medium:"medium",hard:"hard",very_hard:"veryHard"};function ye({score:s,showTagline:a=!0}){const{t:l}=z("text-checker"),o=ms(s);return e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-2xl font-bold text-ink",children:l("seslScore",{score:Math.round(s)})}),e.jsx("div",{className:"flex flex-wrap gap-2",children:hs.map(t=>{const b=t.labelKey===o,i=us(t.labelKey),r=Es[t.labelKey]||t.labelKey;return e.jsx("span",{className:`px-3 py-1 rounded-full text-xs font-medium border transition-all ${b?`${i}`:"border-border text-muted-foreground bg-transparent"}`,children:l(r)},t.labelKey)})}),a&&e.jsx("p",{className:"text-sm text-muted-foreground mt-3",children:l("seslTagline")})]})}const Rs={A1:"cefrA1",A2:"cefrA2",B1:"cefrB1",B2:"cefrB2",C1:"cefrC1",C2:"cefrC2"};function ve({level:s}){const{t:a}=z("text-checker");return e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-2xl font-bold text-ink",children:s?a("cefrLevel",{level:s}):a("cefrLevelEmpty")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:qe.map(l=>{const o=s===l,t=Ne[l],b=Rs[l];return e.jsx("span",{className:`px-3 py-1 rounded-full text-xs font-medium border transition-all ${o?`${t.classes} border-transparent`:"border-border text-muted-foreground bg-transparent"}`,children:a(b)},l)})}),e.jsx("p",{className:"text-xs text-muted-foreground italic",children:a("cefrDisclaimer")})]})}const ze=["A1","A2","B1","B2","C1","C2"];function Ds(s,a){if(!s)return"match";const l=ze.indexOf(s),o=ze.indexOf(a);return l===-1||o===-1?"match":l>o?"too_hard":l<o?"too_easy":"match"}function Bs({seslScore:s,categoryScores:a,cefrLevel:l,targetCefrLevel:o,targetAgeBand:t,isAdjusting:b,onAdjust:i,adjustComplete:r}){const{t:m}=z("text-checker"),k=ge(a),d=Ds(l,o),f=b||!!r;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(j,{children:e.jsx(y,{className:"pt-6",children:e.jsx(ye,{score:s})})}),e.jsx(j,{children:e.jsx(y,{className:"pt-6",children:e.jsx(ve,{level:l})})})]}),e.jsx(je,{scores:k}),d==="match"&&e.jsx(j,{className:"border-nature-forest/40 bg-nature-forest/10",children:e.jsx(y,{className:"pt-6",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(fs,{className:"h-6 w-6 text-nature-forest mt-0.5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-nature-forest text-lg",children:m("verdictMatch")}),e.jsx("p",{className:"text-nature-forest mt-1",children:m("verdictMatchDesc",{band:t})})]})]})})}),d==="too_hard"&&e.jsx(j,{className:"border-nature-honey-ink/40 bg-nature-honey",children:e.jsx(y,{className:"pt-6",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-nature-honey-ink text-lg",children:m("verdictTooHard")}),e.jsx("p",{className:"text-nature-honey-ink mt-1",children:m("verdictTooHardDesc",{band:t})})]}),e.jsxs(ce,{children:[e.jsx(le,{asChild:!0,children:e.jsx("span",{tabIndex:0,className:"self-start",children:e.jsx(K,{variant:"learn",onClick:()=>i("simplify"),disabled:f,leftIcon:b?e.jsx(Z,{className:"animate-spin"}):e.jsx(ps,{}),children:m("makeEasier")})})}),e.jsx(oe,{className:"max-w-[260px]",children:m("simplifyTooltip")})]})]})})}),d==="too_easy"&&e.jsx(j,{className:"border-nature-coral/40 bg-nature-coral/10",children:e.jsx(y,{className:"pt-6",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-nature-coral text-lg",children:m("verdictTooEasy")}),e.jsx("p",{className:"text-ink mt-1",children:m("verdictTooEasyDesc",{band:t})})]}),e.jsxs(ce,{children:[e.jsx(le,{asChild:!0,children:e.jsx("span",{tabIndex:0,className:"self-start",children:e.jsx(K,{variant:"learn",onClick:()=>i("advance"),disabled:f,leftIcon:b?e.jsx(Z,{className:"animate-spin"}):e.jsx(gs,{}),children:m("makeAdvanced")})})}),e.jsx(oe,{className:"max-w-[260px]",children:m("advanceTooltip")})]})]})})})]})}function Os(){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(j,{children:e.jsx(y,{className:"pt-6",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(G,{className:"h-8 w-40"}),e.jsx("div",{className:"flex gap-2",children:Array.from({length:5}).map((s,a)=>e.jsx(G,{className:"h-7 w-20 rounded-full"},a))})]})})}),e.jsx(j,{children:e.jsx(y,{className:"pt-6",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(G,{className:"h-8 w-40"}),e.jsx("div",{className:"flex gap-2",children:Array.from({length:6}).map((s,a)=>e.jsx(G,{className:"h-7 w-20 rounded-full"},a))})]})})})]}),e.jsx(j,{children:e.jsx(y,{className:"pt-6",children:e.jsx(G,{className:"h-[180px] w-full"})})}),e.jsx(j,{children:e.jsx(y,{className:"pt-6",children:e.jsx(G,{className:"h-16 w-full"})})})]})}function Ms({originalText:s,adjustedText:a,originalSeslScore:l,originalCategoryScores:o,originalCefrLevel:t,newSeslScore:b,newCategoryScores:i,newCefrLevel:r,prompt:m,isAdmin:k}){const[d,f]=h.useState(!1),{t:x}=z("text-checker"),_=ge(o),c=ge(i),u=Math.max(10,Math.ceil(Math.max(..._.map(L=>L.score),...c.map(L=>L.score))/10)*10),w=async()=>{await navigator.clipboard.writeText(a),f(!0),setTimeout(()=>f(!1),2e3)};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-semibold text-ink flex items-center gap-2",children:[e.jsx(js,{className:"h-5 w-5 text-nature-coral"}),x("adjustedText")]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs(j,{children:[e.jsx(Y,{className:"pb-2",children:e.jsx(J,{className:"text-sm text-muted-foreground",children:x("original")})}),e.jsx(y,{children:e.jsx("p",{className:"text-sm leading-relaxed whitespace-pre-wrap max-h-[300px] overflow-y-auto",children:s})})]}),e.jsxs(j,{className:"border-nature-coral/40",children:[e.jsxs(Y,{className:"pb-2 flex flex-row items-center justify-between",children:[e.jsx(J,{className:"text-sm text-nature-coral",children:x("adjusted")}),e.jsxs(Pe,{variant:"ghost",size:"sm",onClick:w,className:"h-7 px-2",children:[d?e.jsx(Ze,{className:"h-3.5 w-3.5 text-nature-forest"}):e.jsx(os,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"ml-1 text-xs",children:x(d?"copied":"copy")})]})]}),e.jsx(y,{children:e.jsx("p",{className:"text-sm leading-relaxed whitespace-pre-wrap max-h-[300px] overflow-y-auto",children:a})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(j,{children:e.jsxs(y,{className:"pt-6",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2 uppercase tracking-wide font-medium",children:x("original")}),e.jsx(ye,{score:l})]})}),e.jsx(j,{className:"border-nature-coral/40",children:e.jsxs(y,{className:"pt-6",children:[e.jsx("p",{className:"text-xs text-nature-coral mb-2 uppercase tracking-wide font-medium",children:x("adjusted")}),e.jsx(ye,{score:b})]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(je,{scores:_,title:x("originalDimensions"),vertical:!0,maxDomain:u}),e.jsx(je,{scores:c,title:x("adjustedDimensions"),vertical:!0,maxDomain:u})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(j,{children:e.jsxs(y,{className:"pt-6",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2 uppercase tracking-wide font-medium",children:x("original")}),e.jsx(ve,{level:t})]})}),e.jsx(j,{className:"border-nature-coral/40",children:e.jsxs(y,{className:"pt-6",children:[e.jsx("p",{className:"text-xs text-nature-coral mb-2 uppercase tracking-wide font-medium",children:x("adjusted")}),e.jsx(ve,{level:r})]})})]}),k&&m&&e.jsxs(j,{className:"border-dashed border-muted-foreground/30",children:[e.jsx(Y,{className:"pb-2",children:e.jsx(J,{className:"text-xs text-muted-foreground uppercase tracking-wide",children:x("adminPrompt")})}),e.jsx(y,{children:e.jsx("pre",{className:"text-xs text-muted-foreground whitespace-pre-wrap bg-muted/50 p-3 rounded-md overflow-auto max-h-[200px]",children:m})})]})]})}const nt=()=>{const{user:s,isLoading:a}=es(),{userType:l,isAuthenticated:o,isLoading:t}=ss(),[b,i]=h.useState([]),{t:r}=z(["text-checker","generation"]),{getLocalizedPath:m}=$e(),k=h.useRef(As()),d=h.useRef(!1);h.useEffect(()=>{if(d.current)return;d.current=!0;const v=k.current;v&&(v.text||v.ageBand)&&D.success(r("draftRestored"))},[r]);const[f,x]=h.useState(null),[_,c]=h.useState(!1),[u,w]=h.useState(!1),[L,I]=h.useState(!1),[p,B]=h.useState(null),[V,$]=h.useState(!1),[X,O]=h.useState(!1),[E,R]=h.useState(null),[se,P]=h.useState(!1);h.useEffect(()=>{(async()=>{if(s?.id)try{c(!0);const g=await q(s.id,"text_checker");x(g)}catch(g){console.error("Error checking generation limit:",g)}finally{c(!1)}})()},[s?.id]),h.useEffect(()=>{const v=Object.entries(Ne).map(([g,A])=>({age_band:A.ageBand,cefr_level:g}));i(v)},[]);const U=()=>{P(!0)},ie=async(v,g,A)=>{w(!0),B(null),R(null),I(!1),O(!1);try{const n=await Be(v),N=n.categoryScores.map(T=>({name:T.name,score:T.score}));let S=A??null;if(!S){const{data:T,error:M}=await ee.functions.invoke("classify-cefr-level",{body:{storyText:v}});!M&&T?.success&&(S=T.cefrLevel)}const C=he(g)||"B1";if(B({seslScore:n.rawScore,categoryScores:N,cefrLevel:S,targetCefrLevel:C,targetAgeBand:g,originalText:v}),s?.id)try{const T=await q(s.id,"text_checker");x(T)}catch(T){console.error("Error refreshing generation limit:",T)}I(!0),Me()}catch(n){console.error("Analysis error:",n),D.error(r("analysisError"))}finally{w(!1)}},de=async v=>{if(p){$(!0),R(null);try{const{data:g,error:A}=await ee.functions.invoke("adjust-text-level",{body:{text:p.originalText,targetCefrLevel:p.targetCefrLevel,direction:v}});if(A)throw A;if(g?.error)throw new Error(g.error);const n=g.adjustedText,N=await Be(n),S=N.categoryScores.map(C=>({name:C.name,score:C.score}));R({adjustedText:n,seslScore:N.rawScore,categoryScores:S,cefrLevel:p.targetCefrLevel,prompt:g.prompt||""}),O(!0)}catch(g){console.error("Adjust error:",g);const A=s?.id?await q(s.id,"text_checker").catch(()=>null):null;A&&!A.can_generate?D.error(Ue(A,r,"text_checker")):D.error(g.message||r("adjustError"))}finally{$(!1),s?.id&&q(s.id,"text_checker").then(x).catch(g=>console.error("Error refreshing limit:",g))}}},xe=()=>{B(null),R(null),I(!1),O(!1),P(!1),Me(),window.scrollTo({top:0,behavior:"smooth"}),s?.id&&q(s.id,"text_checker").then(x).catch(v=>console.error("Error refreshing limit:",v))},te=l==="admin",me={"@context":"https://schema.org","@type":"WebApplication",name:r("pageTitle"),description:r("seoDescription"),url:`https://storysparkle.org${m("/text-checker")}`,applicationCategory:"EducationalApplication",operatingSystem:"Any",isAccessibleForFree:!0,offers:{"@type":"Offer",price:"0",priceCurrency:"USD"},provider:{"@type":"Organization",name:"StorySparkle",url:"https://storysparkle.org"}};return e.jsxs("div",{className:"min-h-screen bg-page-surface",children:[e.jsx(ts,{title:r("seoTitle"),description:r("seoDescription"),keywords:r("seoKeywords",{defaultValue:""})||void 0}),e.jsxs(Ns,{children:[e.jsx("script",{type:"application/ld+json",children:JSON.stringify(me)}),e.jsx("script",{type:"application/ld+json",children:JSON.stringify({"@context":"https://schema.org","@type":"FAQPage",mainEntity:r("faq.items",{returnObjects:!0,defaultValue:[]}).map(v=>({"@type":"Question",name:v.q,acceptedAnswer:{"@type":"Answer",text:v.a}}))})})]}),e.jsx(rs,{}),e.jsxs("div",{className:"container py-6 space-y-8",children:[e.jsx(ys,{}),e.jsx("div",{className:"mb-8",children:e.jsxs("div",{className:"flex flex-col lg:flex-row items-center justify-center gap-3 md:gap-6 lg:gap-8",children:[e.jsx("div",{className:"w-32 h-32 lg:w-44 lg:h-44 flex-shrink-0",children:e.jsx(as.div,{animate:{y:[0,-8,0]},transition:{duration:3,repeat:1/0,ease:"easeInOut"},children:e.jsx("img",{src:"https://cdn.storysparkle.org/ui_elements/Hero%20Icons/TextChecker.webp",alt:"Text Checker",className:"w-full h-full object-contain drop-shadow-2xl"})})}),e.jsxs("div",{className:"flex flex-col items-center md:items-start text-center md:text-left",children:[e.jsx("h1",{className:"text-[22px] lg:text-[32px] font-bold text-ink",children:r("pageTitle")}),e.jsx("p",{className:"text-sm lg:text-xl text-nature-forest mt-3",children:r("pageSubtitle")}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-center gap-x-5 gap-y-2 md:justify-start",children:[e.jsx(Je,{to:m("/research"),className:"inline-block text-sm text-nature-forest hover:text-nature-forest/80 hover:underline font-medium",children:r("learnMore")}),e.jsx(ns,{slug:"check-a-text-level"})]})]})]})}),e.jsx(_s,{onAnalyze:ie,isAnalyzing:u,ageRanges:b,isAuthenticated:o,generationLimit:f,limitLoading:_,analysisComplete:L,isSampleLoaded:se,onSampleLoaded:U,service:"text_checker",initialText:k.current?.text||"",initialAgeBand:k.current?.ageBand||"",initialCefrLevel:k.current?.cefrLevel||""}),u&&e.jsx(Os,{}),p&&!u&&e.jsx(Bs,{seslScore:p.seslScore,categoryScores:p.categoryScores,cefrLevel:p.cefrLevel,targetCefrLevel:p.targetCefrLevel,targetAgeBand:p.targetAgeBand,isAdjusting:V,onAdjust:de,isAdmin:te,adjustComplete:X}),E&&p&&e.jsx(Ms,{originalText:p.originalText,adjustedText:E.adjustedText,originalSeslScore:p.seslScore,originalCategoryScores:p.categoryScores,originalCefrLevel:p.cefrLevel,newSeslScore:E.seslScore,newCategoryScores:E.categoryScores,newCefrLevel:E.cefrLevel,prompt:E.prompt,isAdmin:te}),L&&(X||p&&!E&&!V)&&e.jsx("div",{className:"flex justify-center",children:e.jsx(K,{variant:"primary",onClick:xe,leftIcon:e.jsx(bs,{}),children:r("analyseAnother")})}),e.jsx(vs,{heading:r("sharing.title"),subheading:r("sharing.description"),title:r("pageTitle"),description:r("seoDescription")})]})]})};export{nt as default};