1import{n as e}from"./rolldown-runtime-DF2fYuay.js";import{m as t,p as n}from"./sentry-DkqdJPas.js";import{p as r,t as i}from"./react-BsqGp9vZ.js";import{T as a,dt as o,ft as s,gt as c,ht as l,mt as u,ut as d,w as f}from"./ui-BrKP0ZMB.js";var p=/^[\w!#$%&'*.^`|~+-]+$/,m=(e,t,n={})=>{if(!p.test(e))throw Error(`Invalid cookie name`);let r=`${e}=${t}`;if(e.startsWith(`__Secure-`)&&!n.secure)throw Error(`__Secure- Cookie must have Secure attributes`);if(e.startsWith(`__Host-`)){if(!n.secure)throw Error(`__Host- Cookie must have Secure attributes`);if(n.path!==`/`)throw Error(`__Host- Cookie must have Path attributes with "/"`);if(n.domain)throw Error(`__Host- Cookie must not have Domain attributes`)}for(let e of[`domain`,`path`])if(n[e]&&/[;\r\n]/.test(n[e]))throw Error(`${e} must not contain ";", "\\r", or "\\n"`);if(n&&typeof n.maxAge==`number`&&n.maxAge>=0){if(n.maxAge>3456e4)throw Error(`Cookies Max-Age SHOULD NOT be greater than 400 days (34560000 seconds) in duration.`);r+=`; Max-Age=${n.maxAge|0}`}if(n.domain&&n.prefix!==`host`&&(r+=`; Domain=${n.domain}`),n.path&&(r+=`; Path=${n.path}`),n.expires){if(n.expires.getTime()-Date.now()>3456e7)throw Error(`Cookies Expires SHOULD NOT be greater than 400 days (34560000 seconds) in the future.`);r+=`; Expires=${n.expires.toUTCString()}`}if(n.httpOnly&&(r+=`; HttpOnly`),n.secure&&(r+=`; Secure`),n.sameSite&&(r+=`; SameSite=${n.sameSite.charAt(0).toUpperCase()+n.sameSite.slice(1)}`),n.priority&&(r+=`; Priority=${n.priority.charAt(0).toUpperCase()+n.priority.slice(1)}`),n.partitioned){if(!n.secure)throw Error(`Partitioned Cookie must have Secure attributes`);r+=`; Partitioned`}return r},h=(e,t,n)=>(t=encodeURIComponent(t),m(e,t,n)),g=(e,t)=>(e=e.replace(/\/+$/,``),e+=`/`,t=t.replace(/^\/+/,``),e+t),_=(e,t)=>{for(let[n,r]of Object.entries(t)){let t=RegExp(`/:`+n+`(?:{[^/]+})?\\??`);e=e.replace(t,r?`/${r}`:``)}return e},v=e=>{let t=new URLSearchParams;for(let[n,r]of Object.entries(e))if(r!==void 0)if(Array.isArray(r))for(let e of r)t.append(n,e);else t.set(n,r);return t},y=(e,t)=>{switch(t){case`ws`:return e.replace(/^http/,`ws`);case`http`:return e.replace(/^ws/,`http`)}},b=e=>/^https?:\/\/[^\/]+?\/index(?=\?|$)/.test(e)?e.replace(/\/index(?=\?|$)/,`/`):e.replace(/\/index(?=\?|$)/,``);function x(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function S(e,t){if(!x(e)&&!x(t))return t;let n={...e};for(let e in t){let r=t[e];x(n[e])&&x(r)?n[e]=S(n[e],r):n[e]=r}return n}var C=(e,t)=>new Proxy(()=>{},{get(n,r){if(!(typeof r!=`string`||r===`then`))return C(e,[...t,r])},apply(n,r,i){return e({path:t,args:i})}}),w=class{url;method;buildSearchParams;queryParams=void 0;pathParams={};rBody;cType=void 0;constructor(e,t,n){this.url=e,this.method=t,this.buildSearchParams=n.buildSearchParams}fetch=async(e,t)=>{if(e){if(e.query&&(this.queryParams=this.buildSearchParams(e.query)),e.form){let t=new FormData;for(let[n,r]of Object.entries(e.form))if(r!==void 0)if(Array.isArray(r))for(let e of r)t.append(n,e);else t.append(n,r);this.rBody=t}e.json&&(this.rBody=JSON.stringify(e.json),this.cType=`application/json`),e.param&&(this.pathParams=e.param)}let n=this.method.toUpperCase(),r={...e?.header,...typeof t?.headers==`function`?await t.headers():t?.headers};if(e?.cookie){let t=[];for(let[n,r]of Object.entries(e.cookie))t.push(h(n,r,{path:`/`}));r.Cookie=t.join(`,`)}this.cType&&(r[`Content-Type`]=this.cType);let i=new Headers(r??void 0),a=this.url;a=b(a),a=_(a,this.pathParams),this.queryParams&&(a=a+`?`+this.queryParams.toString()),n=this.method.toUpperCase();let o=!(n===`GET`||n===`HEAD`);return(t?.fetch||fetch)(a,{body:o?this.rBody:void 0,method:n,headers:i,...t?.init})}},T=(e,t)=>C(function n(r){let i=t?.buildSearchParams??v,a=[...r.path],o=a.slice(-3).reverse();if(o[0]===`toString`)return o[1]===`name`?o[2]||``:n.toString();if(o[0]===`valueOf`)return o[1]===`name`?o[2]||``:n;let s=``;if(/^\$/.test(o[0])){let e=a.pop();e&&(s=e.replace(/^\$/,``))}let c=g(e,a.join(`/`));if(s===`url`||s===`path`){let t=c;return r.args[0]&&(r.args[0].param&&(t=_(c,r.args[0].param)),r.args[0].query&&(t=t+`?`+i(r.args[0].query).toString())),t=b(t),s===`url`?new URL(t):t.slice(e.replace(/\/+$/,``).length).replace(/^\/?/,`/`)}if(s===`ws`){let e=y(r.args[0]&&r.args[0].param?_(c,r.args[0].param):c,`ws`),n=new URL(e),i=r.args[0]?.query;
1return i&&Object.entries(i).forEach(([e,t])=>{Array.isArray(t)?t.forEach(t=>n.searchParams.append(e,t)):n.searchParams.set(e,t)}),((...e)=>t?.webSocket!==void 0&&typeof t.webSocket==`function`?t.webSocket(...e):new WebSocket(...e))(n.toString())}let l=new w(c,s,{buildSearchParams:i});if(s){t??={};let e=S(t,{...r.args[1]});return l.fetch(r.args[0],e)}return l},[]),E=e(r(),1),D=``,O=T(D,{init:{credentials:`include`}}),k=class extends Error{constructor(e,t,n){super(t),this.status=e,this.body=n}};function A(e,t,n,r){return t===`write`?{format:`text`,value:e,type:`write`}:n&&n.length>0?{format:`text`,value:e,type:`mcq`,optionFormat:r??`text`,distractors:n}:{format:`text`,value:e,type:`show`}}async function j(e){let t=await e.json().catch(()=>({}));return new k(e.status,t.error??`HTTP ${e.status}`,t)}var M={lessons:{list:async()=>{let e=await O.api.lessons.$get();if(!e.ok)throw await j(e);return e.json()},get:async e=>{let t=await O.api.lessons[`:id`].$get({param:{id:e}});if(!t.ok)throw await j(t);return t.json()},create:async e=>{let t=await O.api.lessons.$post({json:e});if(!t.ok)throw await j(t);return t.json()},update:async(e,t)=>{let n=await O.api.lessons[`:id`].$put({param:{id:e},json:t});if(!n.ok)throw await j(n);return n.json()},delete:async e=>{let t=await O.api.lessons[`:id`].$delete({param:{id:e}});if(!t.ok)throw await j(t);return t.json()},createQuestion:async(e,t)=>{let{content:n,answer:r,mirror:i,answerType:a,distractors:o,optionFormat:s,presentationType:c,answerPresentationType:l,ttsLanguage:u,answerTtsLanguage:d}=t,f={question:{format:`text`,value:n},answer:A(r,a,o,s),mirror:i,presentationType:c,answerPresentationType:l,ttsLanguage:u,answerTtsLanguage:d},p=await fetch(`${D}/api/lessons/${e}/questions`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify(f)});if(!p.ok)throw await j(p);return p.json()},updateQuestion:async(e,t,n)=>{let{content:r,answer:i,mirror:a,answerType:o,distractors:s,optionFormat:c,presentationType:l,answerPresentationType:u,ttsLanguage:d,answerTtsLanguage:f}=n,p={question:{format:`text`,value:r},answer:A(i,o,s,c),mirror:a,presentationType:l,answerPresentationType:u,ttsLanguage:d,answerTtsLanguage:f},m=await fetch(`${D}/api/lessons/${e}/questions/${t}`,{method:`PUT`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify(p)});if(!m.ok)throw await j(m);return m.json()},deleteQuestion:async(e,t)=>{let n=await O.api.lessons[`:id`].questions[`:qid`].$delete({param:{id:e,qid:t}});if(!n.ok)throw await j(n);return n.json()},importCsv:async(e,t)=>{let n=await fetch(`${D}/api/lessons/${e}/import-csv`,{method:`POST`,credentials:`include`,body:t,headers:{"Content-Type":`text/plain`}});if(!n.ok)throw await j(n);return n.json()},startFlashcardGeneration:async(e,t,n)=>{let r=new FormData;r.set(`image`,t),n&&r.set(`instructions`,n);let i=await fetch(`${D}/api/lessons/${e}/generate-flashcards`,{method:`POST`,credentials:`include`,body:r});if(!i.ok)throw await j(i);return i.json()},getActiveFlashcardJob:async e=>{let t=await fetch(`${D}/api/lessons/${e}/generate-flashcards/active`,{credentials:`include`});if(t.status===404)return null;if(!t.ok)throw await j(t);return t.json()},pollFlashcardJob:async(e,t)=>{let n=await fetch(`${D}/api/lessons/${e}/generate-flashcards/${t}`,{credentials:`include`});if(!n.ok)throw await j(n);return n.json()},cancelFlashcardJob:async(e,t)=>{let n=await fetch(`${D}/api/lessons/${e}/generate-flashcards/${t}`,{method:`DELETE`,credentials:`include`});if(!n.ok)throw await j(n);return n.json()},confirmFlashcards:async(e,t,n)=>{let r=await fetch(`${D}/api/lessons/${e}/generate-flashcards/${t}/confirm`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({cards:n})});if(!r.ok)throw await j(r);return r.json()},dueCards:async(e,t=!1)=>{let n=await O.api.lessons[`:id`][`due-cards`].$get({param:{id:e},query:t?{all:`true`}:{}});if(!n.ok)throw await j(n);return n.json()},enroll:async e=>{let t=await O.api.lessons[`:id`].enroll.$post({param:{id:e}});if(!t.ok)throw await j(t);return t.json()},unenroll:async e=>
1{let t=await O.api.lessons[`:id`].enroll.$delete({param:{id:e}});if(!t.ok)throw await j(t);return t.json()},setMuted:async(e,t)=>{let n=await O.api.lessons[`:id`].mute.$patch({param:{id:e},json:{muted:t}});if(!n.ok)throw await j(n);return n.json()}},share:{create:async e=>{let t=await O.api.lessons[`:id`].share.$post({param:{id:e}});if(!t.ok)throw await j(t);return t.json()},list:async e=>{let t=await O.api.lessons[`:id`][`share-links`].$get({param:{id:e}});if(!t.ok)throw await j(t);return t.json()},revoke:async e=>{let t=await O.api[`share-links`][`:id`].$delete({param:{id:e}});if(!t.ok)throw await j(t);return t.json()},getInfo:async e=>{let t=await O.api.share[`:token`].$get({param:{token:e}});if(!t.ok)throw await j(t);return t.json()},join:async e=>{let t=await O.api.share[`:token`].join.$post({param:{token:e}});if(!t.ok)throw await j(t);return t.json()},members:async e=>{let t=await O.api.lessons[`:id`].members.$get({param:{id:e}});if(!t.ok)throw await j(t);return t.json()},updateMember:async(e,t,n)=>{let r=await O.api.lessons[`:id`].members[`:userId`].$patch({param:{i
1d:e,userId:t},json:{accessLevel:n}});if(!r.ok)throw await j(r);return r.json()},removeMember:async(e,t)=>{let n=await O.api.lessons[`:id`].members[`:userId`].$delete({param:{id:e,userId:t}});if(!n.ok)throw await j(n);return n.json()}},dueCards:{list:async()=>{let e=await O.api[`due-cards`].$get();if(!e.ok)throw await j(e);return e.json()}},entitlements:{list:async()=>{let e=await O.api.entitlements.$get();if(!e.ok)throw await j(e);return e.json()}},reviews:{submit:async(e,t)=>{let n=await O.api.reviews.$post({json:{questionId:e,rating:t}});if(!n.ok)throw await j(n);return n.json()}},tts:{preview:async(e,t)=>{let n=await fetch(`${D}/api/tts/preview`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:e,language:t})});if(!n.ok)throw await j(n);return n.arrayBuffer()}}},N=`1.6.2`;function P(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,{code:e,message:t,toString:()=>e}]))}function ee(){let e=Object.getOwnPropertyDescriptor(Error,`stackTraceLimit`);return e===void 0?Object.isExtensible(Error):Object.prototype.hasOwnProperty.call(e,`writable`)?e.writable:e.set!==void 0}function te(e){let t=e.split(` 2 at `);return t.length<=1?e:(t.splice(1,1),t.join(` 3 at `))}function ne(e,t){class n extends e{#e;constructor(...e){if(ee()){let t=Error.stackTraceLimit;Error.stackTraceLimit=0,super(...e),Error.stackTraceLimit=t}else super(...e);let t=Error().stack;t&&(this.#e=te(t.replace(/^Error/,this.name)))}get errorStack(){return this.#e}}return Object.defineProperty(n.prototype,`constructor`,{get(){return t},enumerable:!1,configurable:!0}),n}var re={OK:200,CREATED:201,ACCEPTED:202,NO_CONTENT:204,MULTIPLE_CHOICES:300,MOVED_PERMANENTLY:301,FOUND:302,SEE_OTHER:303,NOT_MODIFIED:304,TEMPORARY_REDIRECT:307,BAD_REQUEST:400,UNAUTHORIZED:401,PAYMENT_REQUIRED:402,FORBIDDEN:403,NOT_FOUND:404,METHOD_NOT_ALLOWED:405,NOT_ACCEPTABLE:406,PROXY_AUTHENTICATION_REQUIRED:407,REQUEST_TIMEOUT:408,CONFLICT:409,GONE:410,LENGTH_REQUIRED:411,PRECONDITION_FAILED:412,PAYLOAD_TOO_LARGE:413,URI_TOO_LONG:414,UNSUPPORTED_MEDIA_TYPE:415,RANGE_NOT_SATISFIABLE:416,EXPECTATION_FAILED:417,"I'M_A_TEAPOT":418,MISDIRECTED_REQUEST:421,UNPROCESSABLE_ENTITY:422,LOCKED:423,FAILED_DEPENDENCY:424,TOO_EARLY:425,UPGRADE_REQUIRED:426,PRECONDITION_REQUIRED:428,TOO_MANY_REQUESTS:429,REQUEST_HEADER_FIELDS_TOO_LARGE:431,UNAVAILABLE_FOR_LEGAL_REASONS:451,INTERNAL_SERVER_ERROR:500,NOT_IMPLEMENTED:501,BAD_GATEWAY:502,SERVICE_UNAVAILABLE:503,GATEWAY_TIMEOUT:504,HTTP_VERSION_NOT_SUPPORTED:505,VARIANT_ALSO_NEGOTIATES:506,INSUFFICIENT_STORAGE:507,LOOP_DETECTED:508,NOT_EXTENDED:510,NETWORK_AUTHENTICATION_REQUIRED:511};ne(class extends Error{constructor(e=`INTERNAL_SERVER_ERROR`,t=void 0,n={},r=typeof e==`number`?e:re[e]){super(t?.message,t?.cause?{cause:t.cause}:void 0),this.status=e,this.body=t,this.headers=n,this.statusCode=r,this.name=`APIError`,this.status=e,this.headers=n,this.statusCode=r,this.body=t}},Error);var F=class extends Error{constructor(e,t){super(e,t),this.name=`BetterAuthError`,this.message=e,this.stack=``}},ie=P({OTP_EXPIRED:`OTP expired`,INVALID_OTP:`Invalid OTP`,TOO_MANY_ATTEMPTS:`Too many attempts`}),ae=()=>({id:`email-otp`,version:N,$InferServerPlugin:{},atomListeners:[{matcher:e=>e===`/email-otp/verify-email`||e===`/sign-in/email-otp`||e===`/email-otp/request-email-change`,signal:`$sessionSignal`}],$ERROR_CODES:ie}),I=[],L=0,R=4,oe=0,se=e=>{let t=[],n={get(){return n.lc||n.listen(()=>{})(),n.value},lc:0,listen(e){return n.lc=t.push(e),()=>{for(let t=L+R;t<I.length;)I[t]===e?I.splice(t,R):t+=R;let r=t.indexOf(e);~r&&(t.splice(r,1),--n.lc||n.off())}},notify(e,r){oe++;let i=!I.length;for(let i of t)I.push(i,n.value,e,r);if(i){for(L=0;L<I.length;L+=R)I[L](I[L+1],I[L+2],I[L+3]);I.length=0}},off(){},set(e){let t=n.value;t!==e&&(n.value=e,n.notify(t))},subscribe(e){let t=n.listen(e);return e(n.value),t},value:e};return n},ce=5,z=6,B=10,le=(e,t,n,r)=>(e.events=e.events||{},e.events[n+B]||(e.events[n+B]=r(t=>{e.events[n].reduceRight((e,t)=>(t(e),e),{shared:{},...t})})),e.events[n]=e.events[n]||[],e.events[n].push(t),()=>{let r=e.events[n],i=r.indexOf(t);r.splice(i,1),r.length||(delete e.events[n],e.events[n+B](),delete e.events[n+B])}),ue=1e3,de=(e,t)=>le(e,n=>{let r=t(n);r&&e.events[z].push(r)},ce,t=>{let n=e.listen;e.listen=(...r)=>(!e.lc&&!e.active&&(e.active=!0,t()),n(...r));let r=e.off;return e.events[z]=[],e.off=()=>{r(),setTimeout(()=>
3{if(e.active&&!e.lc){e.active=!1;for(let t of e.events[z])t();e.events[z]=[]}},ue)},()=>{e.listen=n,e.off=r}});function fe(e,t,n){let r=new Set(t).add(void 0);return e.listen((e,t,i)=>{r.has(i)&&n(e,t,i)})}var pe=()=>typeof window>`u`,me=(e,t,n,r)=>{let i=se({data:null,error:null,isPending:!0,isRefetching:!1,refetch:e=>a(e)}),a=async e=>new Promise(a=>{let o=typeof r==`function`?r({data:i.get().data,error:i.get().error,isPending:i.get().isPending}):r;n(t,{...o,query:{...o?.query,...e?.query},async onSuccess(e){i.set({data:e.data,error:null,isPending:!1,isRefetching:!1,refetch:i.value.refetch}),await o?.onSuccess?.(e)},async onError(e){let{request:t}=e,n=typeof t.retry==`number`?t.retry:t.retry?.attempts,r=t.retryAttempt||0;if(n&&r<n)return;let a=e.error.status===401;i.set({error:e.error,data:a?null:i.get().data,isPending:!1,isRefetching:!1,refetch:i.value.refetch}),await o?.onError?.(e)},async onRequest(e){let t=i.get();i.set({isPending:t.data===null,data:t.data,error:null,isRefetching:!0,refetch:i.value.refetch}),await o?.onRequest?.(e)}}).catch(e=>{i.set({error:e,data:i.get().data,isPending:!1,isRefetching:!1,refetch:i.value.refetch})}).finally(()=>{a(void 0)})});e=Array.isArray(e)?e:[e];let o=!1;for(let t of e)t.subscribe(async()=>{pe()||(o?await a():de(i,()=>{let e=setTimeout(async()=>{o||=(await a(),!0)},0);return()=>{i.off(),t.off(),clearTimeout(e)}}))});return i},V=Object.create(null),H=e=>({}),U=new Proxy(V,{get(e,t){return H()[t]??V[t]},has(e,t){return t in H()||t in V},set(e,t,n){let r=H(!0);return r[t]=n,!0},deleteProperty(e,t){if(!t)return!1;let n=H(!0);return delete n[t],!0},ownKeys(){let e=H(!0);return Object.keys(e)}});function W(e,t){return typeof process<`u`?{}[e]??t:typeof Deno<`u`?Deno.env.get(e)??t:typeof Bun<`u`?Bun.env[e]??t:t}Object.freeze({get BETTER_AUTH_SECRET(){return W(`BETTER_AUTH_SECRET`)},get AUTH_SECRET(){return W(`AUTH_SECRET`)},get BETTER_AUTH_TELEMETRY(){return W(`BETTER_AUTH_TELEMETRY`)},get BETTER_AUTH_TELEMETRY_ID(){return W(`BETTER_AUTH_TELEMETRY_ID`)},get NODE_ENV(){return W(`NODE_ENV`,`development`)},get PACKAGE_VERSION(){return W(`PACKAGE_VERSION`,`0.0.0`)},get BETTER_AUTH_TELEMETRY_ENDPOINT(){return W(`BETTER_AUTH_TELEMETRY_ENDPOINT`,``)}});function he(e){try{return(new URL(e).pathname.replace(/\/+$/,``)||`/`)!==`/`}catch{throw new F(`Invalid base URL: ${e}. Please provide a valid base URL.`)}}function ge(e){try{let t=new URL(e);if(t.protocol!==`http:`&&t.protocol!==`https:`)throw new F(`Invalid base URL: ${e}. URL must include 'http://' or 'https://'`)}catch(t){throw t instanceof F?t:new F(`Invalid base URL: ${e}. Please provide a valid base URL.`,{cause:t})}}function G(e,t=`/api/auth`){if(ge(e),he(e))return e;let n=e.replace(/\/+$/,``);return!t||t===`/`?n:(t=t.startsWith(`/`)?t:`/${t}`,`${n}${t}`)}function _e(e,t){return!e||e.trim()===``?!1:t===`proto`?e===`http`||e===`https`:t===`host`?[/\.\./,/\0/,/[\s]/,/^[.]/,/[<>'"]/,/javascript:/i,/file:/i,/data:/i].some(t=>t.test(e))?!1:/^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*(:[0-9]{1,5})?$/.test(e)||/^(\d{1,3}\.){3}\d{1,3}(:[0-9]{1,5})?$/.test(e)||/^\[[0-9a-fA-F:]+\](:[0-9]{1,5})?$/.test(e)||/^localhost(:[0-9]{1,5})?$/i.test(e):!1}function ve(e,t,n,r,i){if(e)return G(e,t);if(r!==!1){let e=U.BETTER_AUTH_URL||U.NEXT_PUBLIC_BETTER_AUTH_URL||U.PUBLIC_BETTER_AUTH_URL||U.NUXT_PUBLIC_BETTER_AUTH_URL||U.NUXT_PUBLIC_AUTH_URL||(U.BASE_URL===`/`?void 0:U.BASE_URL);if(e)return G(e,t)}let a=n?.headers.get(`x-forwarded-host`),o=n?.headers.get(`x-forwarded-proto`);if(a&&o&&i&&_e(o,`proto`)&&_e(a,`host`))try{return G(`${o}://${a}`,t)}catch{}if(n){let e=ye(n.url);if(!e)throw new F(`Could not get origin from request. Please provide a valid base URL.`);return G(e,t)}if(typeof window<`u`&&window.location)return G(window.location.origin,t)}function ye(e){try{let t=new URL(e);return t.origin===`null`?null:t.origin}catch{return null}}var be={proto:/"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,constructor:/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,protoShort:/"__proto__"\s*:/,constructorShort:/"constructor"\s*:/},xe=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/,Se={true:!0,false:!1,null:null,undefined:void 0,nan:NaN,infinity:1/0,"-infinity":-1/0},Ce=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,7}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;function we(e){return e instanceof Date&&!isNaN(e.getTime())}function Te(e){let t=Ce.exec(e);if(!t)return null;let[,n,r,i,a,o,s,c,l,u,d]=t,f=new Date(Date.UTC(parseInt(n,10),parseInt(r,10)-1,parseInt(i,10),parseInt(a,10),parseInt(o,10),parseInt(s,10),c?parseInt(c.padEnd(3,`0`),10):0));if(l){let e=(parseInt(u,10)*60+parseInt(d,10))*(l===`+`?-1:1);f.setUTCMinutes(f.getUTCMinutes()+e)}return we(f)?f:null}function Ee(e,t={}){let{strict:n=!1,warnings:r=!1,reviver:i,parseDates:a=!0}=t;if(typeof e!=`string`)return e;let o=e.trim();if(o.length>0&&o[0]===`"`&&o.endsWith(`"`)&&!o.slice(1,-1).includes(`"`))return o.slice(1,-1);let s=o.toLowerCase();if(s.length<=9&&s in Se)return Se[s];if(!xe.test(o)){if(n)throw SyntaxError(`[better-json] Invalid JSON`);return e}if(Object.entries(be).some(([e,t])=>{let n=t.test(o);return n&&r&&console.warn(`[better-json] Detected potential prototype pollution attempt using ${e} pattern`),n})&&n)throw Error(`[better-json] Potential prototype pollution attempt detected`);try{return JSON.parse(o,(e,t)=>{if(e===`__proto__`||e===`constructor`&&t&&typeof t==`object`&&`prototype`in t){r&&console.warn(`[better-json] Dropping "${e}" key to prevent prototype pollution`);return}if(a&&typeof t==`string`){let e=Te(t);if(e)return e}return i?i(e,t):t})}catch(t){if(n)throw t;return e}}function De(e,t={strict:!0}){return Ee(e,t)}var Oe={id:`redirect`,name:`Redirect`,hooks:{onSuccess(e){if(e.data?.url&&e.data?.redirect&&typeof window<`u`&&window.location&&window.location)try{window.location.href=e.data.url}catch{}}}},ke=Symbol.for(`better-auth:broadcast-channel`),Ae=()=>Math.floor(Date.now()/1e3),je=class{listeners=new Set;name;constructor(e=`better-auth.message`){this.name=e}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}post(e){if(!(typeof window>`u`))try{localStorage.setItem(this.name,JSON.stringify({...e,timestamp:Ae()}))}catch{}}setup(){if(typeof window>`u`||window.addEventListener===void 0)return()=>{};let e=e=>{if(e.key!==this.name)return;let t=JSON.parse(e.newValue??`{}`);
3t?.event!==`session`||!t?.data||this.listeners.forEach(e=>e(t))};return window.addEventListener(`storage`,e),()=>{window.removeEventListener(`storage`,e)}}};function Me(e=`better-auth.message`){return globalThis[ke]||(globalThis[ke]=new je(e)),globalThis[ke]}var Ne=Symbol.for(`better-auth:focus-manager`),Pe=class{listeners=new Set;subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}setFocused(e){this.listeners.forEach(t=>t(e))}setup(){if(typeof window>`u`||typeof document>`u`||window.addEventListener===void 0)return()=>{};let e=()=>{document.visibilityState===`visible`&&this.setFocused(!0)};return document.addEventListener(`visibilitychange`,e,!1),()=>{document.removeEventListener(`visibilitychange`,e,!1)}}};function Fe(){return globalThis[Ne]||(globalThis[Ne]=new Pe),globalThis[Ne]}var Ie=Symbol.for(`better-auth:online-manager`),Le=class{listeners=new Set;isOnline=typeof navigator<`u`?navigator.onLine:!0;subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}setOnline(e){this.isOnline=e,this.listeners.forEach(t=>t(e))}setup(){if(typeof window>`u`||window.addEventListener===void 0)return()=>{};let e=()=>this.setOnline(!0),t=()=>this.setOnline(!1);return window.addEventListener(`online`,e,!1),window.addEventListener(`offline`,t,!1),()=>{window.removeEventListener(`online`,e,!1),window.removeEventListener(`offline`,t,!1)}}};function Re(){return globalThis[Ie]||(globalThis[Ie]=new Le),globalThis[Ie]}var K=()=>Math.floor(Date.now()/1e3);function ze(e){return typeof e==`object`&&e&&`data`in e&&`error`in e?e:{data:e,error:null}}var Be=5;function Ve(e){let{sessionAtom:t,sessionSignal:n,$fetch:r,options:i={}}=e,a=i.sessionOptions?.refetchInterval??0,o=i.sessionOptions?.refetchOnWindowFocus??!0,s=i.sessionOptions?.refetchWhenOffline??!1,c={lastSync:0,lastSessionRequest:0,cachedSession:void 0},l=()=>s||Re().isOnline,u=e=>{if(!l())return;if(e?.event===`storage`){c.lastSync=K(),n.set(!n.get());return}let i=t.get(),a=()=>{c.lastSessionRequest=K(),r(`/get-session`).then(async e=>{let{data:a,error:o}=ze(e);if(a?.needsRefresh)try{let e=await r(`/get-session`,{method:`POST`});({data:a,error:o}=ze(e))}catch{}let s=a?.session&&a?.user?a:null;t.set({...i,data:s,error:o}),c.lastSync=K(),n.set(!n.get())}).catch(()=>{})};if(e?.event===`poll`){a();return}if(e?.event===`visibilitychange`){if(K()-c.lastSessionRequest<Be)return;c.lastSessionRequest=K()}if(e?.event===`visibilitychange`){a();return}(i?.data===null||i?.data===void 0)&&(c.lastSync=K(),n.set(!n.get()))},d=e=>{Me().post({event:`session`,data:{trigger:e},clientId:Math.random().toString(36).substring(7)})},f=()=>{a&&a>0&&(c.pollInterval=setInterval(()=>{t.get()?.data&&u({event:`poll`})},a*1e3))},p=()=>{c.unsubscribeBroadcast=Me().subscribe(()=>{u({event:`storage`})})},m=()=>{o&&(c.unsubscribeFocus=Fe().subscribe(()=>{u({event:`visibilitychange`})}))},h=()=>{c.unsubscribeOnline=Re().subscribe(e=>{e&&u({event:`visibilitychange`})})};return{init:()=>{f(),p(),m(),h(),Me().setup(),Fe().setup(),Re().setup()},cleanup:()=>{c.pollInterval&&=(clearInterval(c.pollInterval),void 0),c.unsubscribeBroadcast&&=(c.unsubscribeBroadcast(),void 0),c.unsubscribeFocus&&=(c.unsubscribeFocus(),void 0),c.unsubscribeOnline&&=(c.unsubscribeOnline(),void 0),c.lastSync=0,c.lastSessionRequest=0,c.cachedSession=void 0},triggerRefetch:u,broadcastSessionUpdate:d}}function He(e,t){let n=se(!1),r=me(n,`/get-session`,e,{method:`GET`}),i=()=>{};return de(r,()=>{let a=Ve({sessionAtom:r,sessionSignal:n,$fetch:e,options:t});return a.init(),i=a.broadcastSessionUpdate,()=>{a.cleanup()}}),{session:r,$sessionSignal:n,broadcastSessionUpdate:e=>i(e)}}function Ue(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t!==null&&t!==Object.prototype&&Object.getPrototypeOf(t)!==null||Symbol.iterator in e?!1:Symbol.toStringTag in e?Object.prototype.toString.call(e)===`[object Module]`:!0}function We(e,t,n=`.`,r){if(!Ue(t))return We(e,{},n,r);let i={...t};for(let t of Object.keys(e)){if(t===`__proto__`||t===`constructor`)continue;let a=e[t];a!=null&&(r&&r(i,t,a,n)||(Array.isArray(a)&&Array.isArray(i[t])?i[t]=[...a,...i[t]]:Ue(a)&&Ue(i[t])?i[t]=We(a,i[t],(n?`${n}.`:``)+t.toString(),r):i[t]=a))}return i}function Ge(e){return(...t)=>t.reduce((t,n)=>We(t,n,``,e),{})}var Ke=Ge(),qe=Object.defineProperty,Je=Object.defineProperties,Ye=Object.getOwnPropertyDescriptors,Xe=Object.getOwnPropertySymbols,Ze=Object.prototype.hasOwnProperty,Qe=Object.prototype.propertyIsEnumerable,$e=(e,t,n
3)=>t in e?qe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,q=(e,t)=>{for(var n in t||={})Ze.call(t,n)&&$e(e,n,t[n]);if(Xe)for(var n of Xe(t))Qe.call(t,n)&&$e(e,n,t[n]);return e},J=(e,t)=>Je(e,Ye(t)),et=class extends Error{constructor(e,t,n){super(t||e.toString(),{cause:n}),this.status=e,this.statusText=t,this.error=n,Error.captureStackTrace(this,this.constructor)}},tt=async(e,t)=>{let n=t||{},r={onRequest:[t?.onRequest],onResponse:[t?.onResponse],onSuccess:[t?.onSuccess],onError:[t?.onError],onRetry:[t?.onRetry]};if(!t||!t?.plugins)return{url:e,options:n,hooks:r};for(let i of t?.plugins||[]){if(i.init){let r=await i.init?.call(i,e.toString(),t);n=r.options||n,e=r.url}r.onRequest.push(i.hooks?.onRequest),r.onResponse.push(i.hooks?.onResponse),r.onSuccess.push(i.hooks?.onSuccess),r.onError.push(i.hooks?.onError),r.onRetry.push(i.hooks?.onRetry)}return{url:e,options:n,hooks:r}},nt=class{constructor(e){this.options=e}shouldAttemptRetry(e,t){return this.options.shouldRetry?Promise.resolve(e<this.options.attempts&&this.options.shouldRetry(t)):Promise.resolve(e<this.options.attempts)}getDelay(){return this.options.delay}},rt=class{constructor(e){this.options=e}shouldAttemptRetry(e,t){return this.options.shouldRetry?Promise.resolve(e<this.options.attempts&&this.options.shouldRetry(t)):Promise.resolve(e<this.options.attempts)}getDelay(e){return Math.min(this.options.maxDelay,this.options.baseDelay*2**e)}};function it(e){if(typeof e==`number`)return new nt({type:`linear`,attempts:e,delay:1e3});switch(e.type){case`linear`:return new nt(e);case`exponential`:return new rt(e);default:throw Error(`Invalid retry strategy`)}}var at=async e=>{let t={},n=async e=>typeof e==`function`?await e():e;if(e?.auth){if(e.auth.type===`Bearer`){let r=await n(e.auth.token);if(!r)return t;t.authorization=`Bearer ${r}`}else if(e.auth.type===`Basic`){let[r,i]=await Promise.all([n(e.auth.username),n(e.auth.password)]);if(!r||!i)return t;t.authorization=`Basic ${btoa(`${r}:${i}`)}`}else if(e.auth.type===`Custom`){let[r,i]=await Promise.all([n(e.auth.prefix),n(e.auth.value)]);if(!i)return t;t.authorization=`${r??``} ${i}`}}return t},ot=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function st(e){let t=e.headers.get(`content-type`),n=new Set([`image/svg`,`application/xml`,`application/xhtml`,`application/html`]);if(!t)return`json`;let r=t.split(`;`).shift()||``;return ot.test(r)?`json`:n.has(r)||r.startsWith(`text/`)?`text`:`blob`}function ct(e){try{return JSON.parse(e),!0}catch{return!1}}function lt(e){if(e===void 0)return!1;let t=typeof e;return t===`string`||t===`number`||t===`boolean`||t===null?!0:t===`object`?Array.isArray(e)?!0:e.buffer?!1:e.constructor&&e.constructor.name===`Object`||typeof e.toJSON==`function`:!1}function ut(e){try{return JSON.parse(e)}catch{return e}}function dt(e){return typeof e==`function`}function ft(e){if(e?.customFetchImpl)return e.customFetchImpl;if(typeof globalThis<`u`&&dt(globalThis.fetch))return globalThis.fetch;if(typeof window<`u`&&dt(window.fetch))return window.fetch;throw Error(`No fetch implementation found`)}async function pt(e){let t=new Headers(e?.headers),n=await at(e);for(let[e,r]of Object.entries(n||{}))t.set(e,r);if(!t.has(`content-type`)){let n=mt(e?.body);n&&t.set(`content-type`,n)}return t}function mt(e){return lt(e)?`application/json`:null}function ht(e){if(!e?.body)return null;let t=new Headers(e?.headers);if(lt(e.body)&&!t.has(`content-type`)){for(let[t,n]of Object.entries(e?.body))n instanceof Date&&(e.body[t]=n.toISOString());return JSON.stringify(e.body)}return t.has(`content-type`)&&t.get(`content-type`)===`application/x-www-form-urlencoded`&<(e.body)?new URLSearchParams(e.body).toString():e.body}function gt(e,t){if(t?.method)return t.method.toUpperCase();if(e.startsWith(`@`)){let n=e.split(`@`)[1]?.split(`/`)[0];return yt.includes(n)?n.toUpperCase():t?.body?`POST`:`GET`}return t?.body?`POST`:`GET`}function _t(e,t){let n;return!e?.signal&&e?.timeout&&(n=setTimeout(()=>t?.abort(),e?.timeout)),{abortTimeout:n,clearTimeout:()=>{n&&clearTimeout(n)}}}var vt=class e extends Error{constructor(t,n){super(n||JSON.stringify(t,null,2)),this.issues=t,Object.setPrototypeOf(this,e.prototype)}};async function Y(e,t){let n=await e[`~standard`].validate(t);if(n.issues)throw new vt(n.issues);return n.value}var yt=[`get`,`post`,`put`,`patch`,`delete`],bt=e=>({id:`apply-schema`,name:`Apply Schema`,version:`1.0.0`,async init(t,n){let r=e.plugins?.find(e=>
3e.schema?.config?t.startsWith(e.schema.config.baseURL||``)||t.startsWith(e.schema.config.prefix||``):!1)?.schema||e.schema;if(r){let e=t;r.config?.prefix&&e.startsWith(r.config.prefix)&&(e=e.replace(r.config.prefix,``),r.config.baseURL&&(t=t.replace(r.config.prefix,r.config.baseURL))),r.config?.baseURL&&e.startsWith(r.config.baseURL)&&(e=e.replace(r.config.baseURL,``));let i=r.schema[e];if(i){let e=J(q({},n),{method:i.method,output:i.output});return n?.disableValidation||(e=J(q({},e),{body:i.input?await Y(i.input,n?.body):n?.body,params:i.params?await Y(i.params,n?.params):n?.params,query:i.query?await Y(i.query,n?.query):n?.query})),{url:t,options:e}}}return{url:t,options:n}}}),xt=e=>{async function t(t,n){let r=J(q(q({},e),n),{plugins:[...e?.plugins||[],bt(e||{}),...n?.plugins||[]]});if(e?.catchAllError)try{return await Ct(t,r)}catch(e){return{data:null,error:{status:500,statusText:`Fetch Error`,message:`Fetch related error. Captured by catchAllError option. See error property for more details.`,error:e}}}return await Ct(t,r)}return t};function St(e,t){let{baseURL:n,params:r,query:i}=t||{query:{},params:{},baseURL:``},a=e.startsWith(`http`)?e.split(`/`).slice(0,3).join(`/`):n||``;if(e.startsWith(`@`)){let t=e.toString().split(`@`)[1].split(`/`)[0];yt.includes(t)&&(e=e.replace(`@${t}/`,`/`))}a.endsWith(`/`)||(a+=`/`);let[o,s]=e.replace(a,``).split(`?`),c=new URLSearchParams(s);for(let[e,t]of Object.entries(i||{})){if(t==null)continue;let n;if(typeof t==`string`)n=t;else if(Array.isArray(t)){for(let n of t)c.append(e,n);continue}else n=JSON.stringify(t);c.set(e,n)}if(r)if(Array.isArray(r)){let e=o.split(`/`).filter(e=>e.startsWith(`:`));for(let[t,n]of e.entries()){let e=r[t];o=o.replace(n,e)}}else for(let[e,t]of Object.entries(r))o=o.replace(`:${e}`,String(t));o=o.split(`/`).map(encodeURIComponent).join(`/`),o.startsWith(`/`)&&(o=o.slice(1));let l=c.toString();return l=l.length>0?`?${l}`.replace(/\+/g,`%20`):``,a.startsWith(`http`)?new URL(`${o}${l}`,a):`${a}${o}${l}`}var Ct=async(e,t)=>{let{hooks:n,url:r,options:i}=await tt(e,t),a=ft(i),o=new AbortController,s=i.signal??o.signal,c=St(r,i),l=ht(i),u=await pt(i),d=gt(r,i),f=J(q({},i),{url:c,headers:u,body:l,method:d,signal:s});for(let e of n.onRequest)if(e){let t=await e(f);typeof t==`object`&&t&&(f=t)}(`pipeTo`in f&&typeof f.pipeTo==`function`||typeof t?.body?.pipe==`function`)&&(`duplex`in f||(f.duplex=`half`));let{clearTimeout:p}=_t(i,o),m=await a(f.url,f);p();let h={response:m,request:f};for(let e of n.onResponse)if(e){let n=await e(J(q({},h),{response:t?.hookOptions?.cloneResponse?m.clone():m}));n instanceof Response?m=n:typeof n==`object`&&n&&(m=n.response)}if(m.ok){if(f.method===`HEAD`)return{data:``,error:null};let e=st(m),r={data:null,response:m,request:f};if(e===`json`||e===`text`){let e=await m.text();r.data=await(f.jsonParser??ut)(e)}else r.data=await m[e]();f?.output&&f.output&&!f.disableValidation&&(r.data=await Y(f.output,r.data));for(let e of n.onSuccess)e&&await e(J(q({},r),{response:t?.hookOptions?.cloneResponse?m.clone():m}));return t?.throw?r.data:{data:r.data,error:null}}let g=t?.jsonParser??ut,_=await m.text(),v=ct(_),y=v?await g(_):null,b={response:m,responseText:_,request:f,error:J(q({},y),{status:m.status,statusText:m.statusText})};for(let e of n.onError)e&&await e(J(q({},b),{response:t?.hookOptions?.cloneResponse?m.clone():m}));if(t?.retry){let r=it(t.retry),i=t.retryAttempt??0;if(await r.shouldAttemptRetry(i,m)){for(let e of n.onRetry)e&&await e(h);let a=r.getDelay(i);return await new Promise(e=>setTimeout(e,a)),await Ct(e,J(q({},t),{retryAttempt:i+1}))}}if(t?.throw)throw new et(m.status,m.statusText,v?y:_);return{data:null,error:J(q({},y),{status:m.status,statusText:m.statusText})}},wt=e=>{if(typeof process>`u`)return;let t=e??`/api/auth`;if({}.NEXT_PUBLIC_AUTH_URL)return{}.NEXT_PUBLIC_AUTH_URL;if(typeof window>`u`){if({}.NEXTAUTH_URL)try{return{}.NEXTAUTH_URL}catch{}if({}.VERCEL_URL)try{let e={}.VERCEL_URL.startsWith(`http`)?``:`https://`;return`${new URL(`${e}${{}.VERCEL_URL}`).origin}${t}`}catch{}}},Tt=(e,t)=>{let n=`credentials`in Request.prototype,r=ve(e?.baseURL,e?.basePath,void 0,t)??wt(e?.basePath)??`/api/auth`,i=e?.plugins?.flatMap(e=>e.fetchPlugins).filter(e=>e!==void 0)||[],a={id:`lifecycle-hooks`,name:`lifecycle-hooks`,hooks:{onSuccess:e?.fetchOptions?.onSuccess,onError:e?.fetchOptions?.onError,onRequest:e?.fetchOptions?.onRequest,onResponse:e?.fetchOptions?.onResponse}},{onSuccess:o,onError:s,onRequest:c,onResponse:l,...u}=e?.fetchOptions||{},d=xt({baseURL:r,...n?{credentials:`include`}:{},method:`GET`,jsonParser(e){return e?De(e,{strict:!1}):null},customFetchImpl:fetch,...u,plugins:[a,...u.plugins||[],...e?.disableDefaultFetchPlugins?[]:[Oe],...i]}),{$sessionSignal:f,session:p,broadcastSessionUpdate:m}=He(d,e),h=e?.plugins||[],g={},_={$sessionSignal:f,session:p}
3,v={"/sign-out":`POST`,"/revoke-sessions":`POST`,"/revoke-other-sessions":`POST`,"/delete-user":`POST`},y=[{signal:`$sessionSignal`,matcher(e){return e===`/sign-out`||e===`/update-user`||e===`/update-session`||e===`/sign-up/email`||e===`/sign-in/email`||e===`/delete-user`||e===`/verify-email`||e===`/revoke-sessions`||e===`/revoke-session`||e===`/change-email`},callback(e){e===`/sign-out`?m(`signout`):(e===`/update-user`||e===`/update-session`)&&m(`updateUser`)}}];for(let e of h)e.getAtoms&&Object.assign(_,e.getAtoms?.(d)),e.pathMethods&&Object.assign(v,e.pathMethods),e.atomListeners&&y.push(...e.atomListeners);let b={notify:e=>{_[e].set(!_[e].get())},listen:(e,t)=>{_[e].subscribe(t)},atoms:_};for(let t of h)t.getActions&&(g=Ke(t.getActions?.(d,b,e)??{},g));return{get baseURL(){return r},pluginsActions:g,pluginsAtoms:_,pluginPathMethods:v,atomListeners:y,$fetch:d,$store:b}};function Et(e){return typeof e==`object`&&!!e&&`get`in e&&typeof e.get==`function`&&`lc`in e&&typeof e.lc==`number`}function Dt(e,t,n){let r=t[e],{fetchOptions:i,query:a,...o}=n||{};return r||(i?.method?i.method:o&&Object.keys(o).length>0?`POST`:`GET`)}function Ot(e,t,n,r,i){function a(o=[]){return new Proxy(function(){},{get(t,n){if(typeof n!=`string`||n===`then`||n===`catch`||n===`finally`)return;let r=[...o,n],i=e;for(let e of r)if(i&&typeof i==`object`&&e in i)i=i[e];else{i=void 0;break}return typeof i==`function`||Et(i)?i:a(r)},apply:async(e,a,s)=>{let c=`/`+o.map(e=>e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)).join(`/`),l=s[0]||{},u=s[1]||{},{query:d,fetchOptions:f,...p}=l,m={...u,...f},h=Dt(c,n,l);return await t(c,{...m,body:h===`GET`?void 0:{...p,...m?.body||{}},query:d||m?.query,method:h,async onSuccess(e){if(await m?.onSuccess?.(e),!i||m.disableSignal)return;let t=i.filter(e=>e.matcher(c));if(!t.length)return;let n=new Set;for(let e of t){let t=r[e.signal];if(!t)return;if(n.has(e.signal))continue;n.add(e.signal);let i=t.get();setTimeout(()=>{t.set(!i)},10),e.callback?.(c)}}})}})}return a()}function kt(e,t={}){let n=(0,E.useRef)(e.get()),{keys:r,deps:i=[e,r]}=t,a=(0,E.useCallback)(t=>{let i=e=>{n.current!==e&&(n.current=e,t())};return i(e.value),r?.length?fe(e,r,i):e.listen(i)},i),o=()=>n.current;return(0,E.useSyncExternalStore)(a,o,o)}function At(e){return e.charAt(0).toUpperCase()+e.slice(1)}function jt(e){return`use${At(e)}`}function Mt(e){let{pluginPathMethods:t,pluginsActions:n,pluginsAtoms:r,$fetch:i,$store:a,atomListeners:o}=Tt(e),s={};for(let[e,t]of Object.entries(r))s[jt(e)]=()=>kt(t);return Ot({...n,...s,$fetch:i,$store:a},i,t,r,o)}var X=Mt({baseURL:``,plugins:[ae()]}),{signOut:Nt,useSession:Pt}=X;function Ft(e){return e.replace(/\s+([?!;:])/g,`â¯$1`).replace(/\s+([.,])/g,`$1`).replace(/([«])\s+/g,`$1â¯`).replace(/\s+([»)])/g,`â¯$1`).replace(/([(])\s+/g,`$1`).replace(/\s+([)])/g,`$1`).replace(/ {2,}/g,` `)}var It,Lt,Rt;function zt(e,t,n,r,i,a){var o,s,c,l,u,d,f,p=Symbol.metadata||Symbol.for(`Symbol.metadata`),m=Object.defineProperty,h=Object.create,g=[h(null),h(null)],_=t.length;function v(t,n,r){return function(i,a){n&&(a=i,i=e);for(var o=0;o<t.length;o++)a=t[o].apply(i,r?[a]:[]);return r?a:i}}function y(e,t,n,r){if(typeof e!=`function`&&(r||e!==void 0))throw TypeError(t+` must `+(n||`be`)+` a function`+(r?``:` or undefined`));return e}function b(e,t,n,r,i,a,c,l,u,d,f){function p(e){if(!f(e))throw TypeError(`Attempted to access private element on non-instance`)}var h=[].concat(t[0]),_=t[3],b=!c,x=i===1,S=i===3,C=i===4,w=i===2;function T(t,n,r){return function(i,a){return n&&(a=i,i=e),r&&r(i),E[t].call(i,a)}}if(!b){var E={},D=[],O=S?`get`:C||x?`set`:`value`;if(u?(d||x?E={get:Ht(function(){return _(this)},r,`get`),set:function(e){t[4](this,e)}}:E[O]=_,d||Ht(E[O],r,w?``:O)):d||(E=Object.getOwnPropertyDescriptor(e,r)),!d&&!u){if((s=g[+l][r])&&(s^i)!==7)throw Error(`Decorating two elements with the same name (`+E[O].name+`) is not supported yet`);g[+l][r]=i<3?1:i}}for(var k=e,A=h.length-1;A>=0;A-=n?2:1){var j=y(h[A],`A decorator`,`be`,!0),M=n?h[A-1]:void 0,N={},P={kind:[`field`,`accessor`,`method`,`getter`,`setter`,`class`][i],name:r,metadata:o,addInitializer:function(e,t){if(e.v)throw TypeError(`attempted to call addInitializer after decoration was finished`);y(t,`An initializer`,`be`,!0),a.push(t)}.bind(null,N)};if(b)s=j.call(M,k,P),N.v=1,y(s,`class decorators`,`return`)&&(k=s);else if(P.static=l,P.private=u,s=P.access={has:u?f.bind():function(e){return r in e}},C||(s.get=u?w?function(e){return p(e),E.value}:T(`get`,0,p):function(e){return e[r]}),w||S||(s.set=u?T(`set`,0,p):function(e,t){e[r]=t}),k=j.call(M,x?{get:E.get,set:E.set}:E[O],P),N.v=1,x){if(typeof k==`object`&&k)(s=y(k.get,`accessor.get`))&&(E.get=s),(s=y(k.set,`accessor.set`))&&(E.set=s),(s=y(k.init,`accessor.init`))&&D.unshift(s);else if(k!==void 0)throw TypeError(`accessor decorators must return an object with get, set, or init properties or undefined`)}else y(k,(d?`field`:`method`)+` decorators`,`return`)&&(d?D.unshift(k):E[O]=k)}return i<2&&c.push(v(D,l,1),v(a,l,0)),d||b||(u?x?c.splice(-1,0,T(`get`,l),T(`set`,l)):c.push(w?E[O]:y.call.bind(E[O])):m(e,r,E)),k}function x(e){return m(e,p,{configurable:!0,enumerable:!0,value:o})}return a!==void 0&&(o=a[p]),o=h(o??null),u=[],d=function(e){e&&u.push(v(e))},f=function(t,r){for(var a=0;a<n.length;a++){var o=n[a],s=o[1],d=7&s;if((8&s)==t&&!d==r){var f=o[2],p=!!o[3],m=16&s;b(t?e:e.prototype,o,m,p?`#`+f:Bt(f),d,d<2?[]:t?l||=[]:c||=[],u,!!t,p,r,t&&p?function(t){return Ut(t)===e}:i)}}},f(8,0),f(0,0),f(8,1),f(0,1),d(c),d(l),s=u,_||x(e),{e:s,get c(){var n=[];return _&&[x(e=b(e,[t],r,e.name,5,n)),v(n,1)]}}}function Bt(e){var t=Vt(e,`string`);return typeof t==`symbol`?t:t+``}function Vt(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ht(e,t,n){typeof t==`symbol`&&(t=(t=t.description)?`[`+t+`]`:``);try{Object.defineProperty(e,`name`,{configurable:!0,value:n?n+` `+t:t})}catch{}return e}function Ut(e){if(Object(e)!==e)throw TypeError(`right-hand side of 'in' should be an object, got `+(e===null?`null`:typeof e));return e}function Wt(e){if(!e)return;let t=e.split(`/`).slice(-2)[0];return t&&/^[a-z]{2}$/.test(t)?t:void 0}var Z=class e{static{[Lt,Rt,It]=zt(this,[],[[u,1,`raw`],[s,3,`content`],[s,3,`type`],[s,3,`order`],[s,3,`lessonId`],[s,3,`mirrorOfId`],[s,3,`isMirror`],[s,3,`audioUrl`],[s,3,`ttsLanguage`],[s,3,`presentationType`],[s,3,`answerPresentationType`],[s,3,`answerAudioUrl`],[s,3,`answerTtsLanguage`],[s,3,`answer`],[s,3,`answerType`],[s,3,`mcqOptions`],[s,3,`displayContent`],[s,3,`displayAnswer`],[o,2,`update`]]).e}static map=new Map;static getOrCreate(t){let n=e.map.get(t.id);if(n)return n.update(t),n;let r=new e(t);return e.map.set(t.id,r),r}static clear(){e.map.clear()}id=void It(this);#e=Lt(this);get raw(){return this.#e}set raw(e){this.#e=e}get content(){let e=this.raw.question;return e?.format===`text`?e.value:``}get type(){return this.raw.answer?.type===`mcq`?`mcq`:`flashcard`}get order(){return this.raw.order}get lessonId(){return`lessonId`in this.raw?this.raw.lessonId:void 0}get mirrorOfId(){return this.raw.mirrorOfId??null}get isMirror(){return this.mirrorOfId!==null}get audioUrl(){let e=this.raw.question;return e?.format===`text`&&`type`in e&&e.type===`audio`&&e.audioKey?`/api/audio/${e.audioKey}`:null}get ttsLanguage(){let e=this.raw.question;if(e?.format===`text`&&`type`in e&&e.type===`audio`)return e.ttsLanguage??Wt(e.audioKey)}get presentationType(){let e=this.raw.question;return e?.format===`text`&&`type`in e&&e.type===`audio`?`audio`:`text`}get answerPresentationType(){return this.raw.answer?.type===`audio`?`audio`:`text`}get answerAudioUrl(){let e=this.raw.answer;if(e?.type===`audio`){let t=e.audioKey;return t?`/api/audio/${t}`:null}return null}get answerTtsLanguage(){let e=this.raw.answer;if(e?.type===`audio`){let t=e;return t.ttsLanguage??Wt(t.audioKey)}}get answer(){return this.raw.answer?.value??``}get answerType(){return this.raw.answer?.type??`show`}get mcqOptions(){let e=this.raw.answer;return e?.type===`mcq`?[{value:e.value,audioKey:e.audioKey,ttsLanguage:e.ttsLanguage},...e.distractors]:null}get displayContent(){return Ft(this.content)}get displayAnswer(){return Ft(this.answer)}constructor(e){Rt(this),this.id=e.id,this.raw=e}update(e){this.raw=e}},Gt,Kt,qt,Jt,Yt,Xt,Zt;function Qt(e,t,n,r,i,a){var o,s,c,l,u,d,f,p=Symbol.metadata||Symbol.for(`Symbol.metadata`),m=Object.defineProperty,h=Object.create,g=[h(null),h(null)],_=t.length;function v(t,n,r){return function(i,a){n&&(a=i,i=e);for(var o=0;o<t.length;o++)a=t[o].apply(i,r?[a]:[]);return r?a:i}}function y(e,t,n,r){if(typeof e!=`function`&&(r||e!==void 0))throw TypeError(t+` must `+(n||`be`)+` a function`+(r?``:` or undefined`));return e}function b(e,t,n,r,i,a,c,l,u,d,f){function p(e){if(!f(e))throw TypeError(`Attempted to access private element on non-instance`)}var h=[].concat(t[0]),_=t[3],b=!c,x=i===1,S=i===3,C=i===4,w=i===2;function T(t,n,r){return function(i,a){return n&&(a=i,i=e),r&&r(i),E[t].call(i,a)}}if(!b){var E={},D=[],O=S?`get`:C||x?`set`:`value`;if(u?(d||x?E={get:tn(function(){return _(this)},r,`get`),set:function(e){t[4](this,e)}}:E[O]=_,d||tn(E[O],r,w?``:O)):d||(E=Object.getOwnPropertyDescriptor(e,r)),!d&&!u){if((s=g[+l][r])&&(s^i)!==7)throw Error(`Decorating two elements with the same name (`+E[O].name+`) is not supported yet`);g[+l][r]=i<3?1:i}}for(var k=e,A=h.length-1;A>=0;A-=n?2:1){var j=y(h[A],`A decorator`,`be`,!0),M=n?h[A-1]:void 0,N={},P={kind:[`field`,`accessor`,`method`,`getter`,`setter`,`class`][i],name:r,metadata:o,addInitializer:function(e,t){if(e.v)throw TypeError(`attempted to call addInitializer after decoration was finished`);y(t,`An initializer`,`be`,!0),a.push(t)}.bind(null,N)};if(b)s=j.call(M,k,P),N.v=1,y(s,`class decorators`,`return`)&&(k=s);else if(P.static=l,P.private=u,s=P.access={has:u?f.bind():function(e){return r in e}},C||(s.get=u?w?function(e){return p(e),E.value}:T(`get`,0,p):function(e){return e[r]}),w||S||(s.set=u?T(`set`,0,p):function(e,t){e[r]=t}),k=j.call(M,x?{get:E.get,set:E.set}:E[O],P),N.v=1,x){if(typeof k==`object`&&k)(s=y(k.get,`accessor.get`))&&(E.get=s),(s=y(k.set,`accessor.set`))&&(E.set=s),(s=y(k.init,`accessor.init`))&&D.unshift(s);else if(k!==void 0)throw TypeError(`accessor decorators must return an object with get, set, or init properties or undefined`)}else y(k,(d?`field`:`method`)+` decorators`,`return`)&&(d?D.unshift(k):E[O]=k)}return i<2&&c.push(v(D,l,1),v(a,l,0)),d||b||(u?x?c.splice(-1,0,T(`get`,l),T(`set`,l)):c.push(w?E[O]:y.call.bind(E[O])):m(e,r,E)),k}function x(e){return m(e,p,{configurable:!0,enumerable:!0,value:o})}return a!==void 0&&(o=a[p]),o=h(o??null),u=[],d=function(e){e&&u.push(v(e))},f=function(t,r){for(var a=0;a<n.length;a++){var o=n[a],s=o[1],d=7&s;if((8&s)==t&&!d==r){var f=o[2],p=!!o[3],m=16&s;b(t?e:e.prototype,o,m,p?`#`+f:$t(f),d,d<2?[]:t?l||=[]:c||=[],u,!!t,p,r,t&&p?function(t){return nn(t)===e}:i)}}},f(8,0),f(0,0),f(8,1),f(0,1),d(c),d(l),s=u,_||x(e),{e:s,get c(){var n=[];return _&&[x(e=b(e,[t],r,e.name,5,n)),v(n,1)]}}}function $t(e){var t=en(e,`string`);return typeof t==`symbol`?t:t+``}function en(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function tn(e,t,n){typeof t==`symbol`&&(t=(t=t.description)?`[`+t+`]`:``);try{Object.defineProperty(e,`name`,{configurable:!0,value:n?n+` `+t:t})}catch{}return e}function nn(e){if(Object(e)!==e)throw TypeError(`right-hand side of 'in' should be an object, got `+(e===null?`null`:typeof e));return e}var Q=class e{static{[Kt,qt,Jt,Yt,Xt,Zt,Gt]=Qt(this,[],[[u,1,`raw`],[u,1,`questions`],[u,1,`questionsLoaded`],[s,3,`title`],[s,3,`description`],[s,3,`isPublic`],[s,3,`accessLevel`],[s,3,`questionCount`],[s,3,`dueCount`],[s,3,`nextDue`],[s,3,`createdAt`],[s,3,`updatedAt`],[s,3,`mutedAt`],[s,3,`isOwner`],[s,3,`canWrite`],[s,3,`isMuted`],[o,2,`update`]]).e}static map=new Map;static getOrCreate(t){let n=e.map.get(t.id);if(n)return n.update(t),n;let r=new e(t);return e.map.set(t.id,r),r}static clear(){e.map.clear()}id=void Gt(this);#e=Kt(this);get raw(){return this.#e}set raw(e){this.#e=e}#t=(qt(this),Jt(this,[]));get questions(){return this.#t}set questions(e){this.#t=e}#n=(Yt(this),Xt(this,!1));get questionsLoaded(){return this.#n}set questionsLoaded(e){this.#n=e}get title(){return this.raw.title}set title(e){this.raw={...this.raw,title:e}}get description(){return this.raw.description}get isPublic(){return this.raw.isPublic}get accessLevel(){return this.raw.accessLevel}get questionCount(){return`questionCount`in this.raw?this.raw.questionCount:0}get dueCount(){return`dueCount`in this.raw?this.raw.dueCount:0}get nextDue(){return`nextDue`in this.raw?this.raw.nextDue:null}get createdAt(){return this.raw.createdAt}get updatedAt(){return this.raw.updatedAt}get mutedAt(){return this.raw.mutedAt??null}get isOwner(){return this.accessLevel===`owner`}get canWrite(){return this.accessLevel===`owner`||this.accessLevel===`readwrite`}get isMuted(){return this.mutedAt!==null}constructor(e){Zt(this),this.id=e.id,this.raw=e,this.hydrateQuestions(e)}update(e){this.raw=e,this.hydrateQuestions(e)}hydrateQuestions(e){`questions`in e&&(this.questions=e.questions.map(e=>Z.getOrCreate(e)),this.questionsLoaded=!0)}};function rn(){Z.clear(),Q.clear()}var an,on,sn,cn,ln,un,dn,fn,pn;function mn(e,t,n,r,i,a){var o,s,c,l,u,d,f,p=Symbol.metadata||Symbol.for(`Symbol.metadata`),m=Object.defineProperty,h=Object.create,g=[h(null),h(null)],_=t.length;function v(t,n,r){return function(i,a){n&&(a=i,i=e);for(var o=0;o<t.length;o++)a=t[o].apply(i,r?[a]:[]);return r?a:i}}function y(e,t,n,r){if(typeof e!=`function`&&(r||e!==void 0))throw TypeError(t+` must `+(n||`be`)+` a function`+(r?``:` or undefined`));return e}function b(e,t,n,r,i,a,c,l,u,d,f){function p(e){if(!f(e))throw TypeError(`Attempted to access private element on non-instance`)}var h=[].concat(t[0]),_=t[3],b=!c,x=i===1,S=i===3,C=i===4,w=i===2;function T(t,n,r){return function(i,a){return n&&(a=i,i=e),r&&r(i),E[t].call(i,a)}}if(!b){var E={},D=[],O=S?`get`:C||x?`set`:`value`;if(u?(d||x?E={get:_n(function(){return _(this)},r,`get`),set:function(e){t[4](this,e)}}:E[O]=_,d||_n(E[O],r,w?``:O)):d||(E=Object.getOwnPropertyDescriptor(e,r)),!d&&!u){if((s=g[+l][r])&&(s^i)!==7)throw Error(`Decorating two elements with the same name (`+E[O].name+`) is not supported yet`);g[+l][r]=i<3?1:i}}for(var k=e,A=h.length-1;A>=0;A-=n?2:1){var j=y(h[A],`A decorator`,`be`,!0),M=n?h[A-1]:void 0,N={},P={kind:[`field`,`accessor`,`method`,`getter`,`setter`,`class`][i],name:r,metadata:o,addInitializer:function(e,t){if(e.v)throw TypeError(`attempted to call addInitializer after decoration was finished`);y(t,`An initializer`,`be`,!0),a.push(t)}.bind(null,N)};if(b)s=j.call(M,k,P),N.v=1,y(s,`class decorators`,`return`)&&(k=s);else if(P.static=l,P.private=u,s=P.access={has:u?f.bind():function(e){return r in e}},C||(s.get=u?w?function(e){return p(e),E.value}:T(`get`,0,p):function(e){return e[r]}),w||S||(s.set=u?T(`set`,0,p):function(e,t){e[r]=t}),k=j.call(M,x?{get:E.get,set:E.set}:E[O],P),N.v=1,x){if(typeof k==`object`&&k)(s=y(k.get,`accessor.get`))&&(E.get=s),(s=y(k.set,`accessor.set`))&&(E.set=s),(s=y(k.init,`accessor.init`))&&D.unshift(s);else if(k!==void 0)throw TypeError(`accessor decorators must return an object with get, set, or init properties or undefined`)}else y(k,(d?`field`:`method`)+` decorators`,`return`)&&(d?D.unshift(k):E[O]=k)}return i<2&&c.push(v(D,l,1),v(a,l,0)),d||b||(u?x?c.splice(-1,0,T(`get`,l),T(`set`,l)):c.push(w?E[O]:y.call.bind(E[O])):m(e,r,E)),k}function x(e){return m(e,p,{configurable:!0,enumerable:!0,value:o})}return a!==void 0&&(o=a[p]),o=h(o??null),u=[],d=function(e){e&&u.push(v(e))},f=function(t,r){for(var a=0;a<n.length;a++){var o=n[a],s=o[1],d=7&s;if((8&s)==t&&!d==r){var f=o[2],p=!!o[3],m=16&s;b(t?e:e.prototype,o,m,p?`#`+f:hn(f),d,d<2?[]:t?l||=[]:c||=[],u,!!t,p,r,t&&p?function(t){return vn(t)===e}:i)}}},f(8,0),f(0,0),f(8,1),f(0,1),d(c),d(l),s=u,_||x(e),{e:s,get c(){var n=[];return _&&[x(e=b(e,[t],r,e.name,5,n)),v(n,1)]}}}function hn(e){var t=gn(e,`string`);return typeof t
3==`symbol`?t:t+``}function gn(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function _n(e,t,n){typeof t==`symbol`&&(t=(t=t.description)?`[`+t+`]`:``);try{Object.defineProperty(e,`name`,{configurable:!0,value:n?n+` `+t:t})}catch{}return e}function vn(e){if(Object(e)!==e)throw TypeError(`right-hand side of 'in' should be an object, got `+(e===null?`null`:typeof e));return e}var yn=class{static{[on,sn,cn,ln,un,dn,fn,pn,an]=mn(this,[],[[u,1,`session`],[u,1,`loading`],[u,1,`error`],[u,1,`entitlements`],[s,3,`isAuthenticated`],[o,2,`hasEntitlement`],[o,2,`setSession`],[o,2,`fetchEntitlements`],[o,2,`setError`],[o,2,`clearError`],[o,2,`fetchSessionIfNeeded`],[o,2,`fetchSession`],[o,2,`sendOtp`],[o,2,`verifyOtp`],[o,2,`updateName`],[o,2,`signOut`]]).e}#e=(an(this),on(this,null));get session(){return this.#e}set session(e){this.#e=e}#t=(sn(this),cn(this,!0));get loading(){return this.#t}set loading(e){this.#t=e}#n=(ln(this),un(this,``));get error(){return this.#n}set error(e){this.#n=e}#r=(dn(this),fn(this,[]));get entitlements(){return this.#r}set entitlements(e){this.#r=e}constructor(e){this.root=e,pn(this)}get isAuthenticated(){return this.session!==null}hasEntitlement(e){return this.entitlements.includes(e)}setSession(e){this.session=e,this.loading=!1,e?(this.root.tracker.identifyUser(e.user.id),this.fetchEntitlements()):this.entitlements=[]}async fetchEntitlements(){try{let e=await M.entitlements.list();l(()=>{this.entitlements=e})}catch(e){n(e)}}setError(e){this.error=e}clearError(){this.error=``}async fetchSessionIfNeeded(){if(!(!this.loading||this.session!==null))return this.fetchSession()}async fetchSession(){this.loading=!0;try{let{data:e}=await X.getSession();l(()=>{this.setSession(e)})}catch(e){n(e),l(()=>{this.setSession(null)})}}async sendOtp(e){this.clearError();let{error:t}=await X.emailOtp.sendVerificationOtp({email:e,type:`sign-in`});if(t){n(Error(`sendOtp failed: ${t.message??`unknown`}`));let e=t.status===429?`Trop de demandes, réessaie dans quelques minutes`:t.message??`Erreur d'envoi du code`;throw l(()=>{this.setError(e)}),t}}async verifyOtp(e,t){this.clearError();let{data:r,error:i}
3=await X.signIn.emailOtp({email:e,otp:t});if(i){n(Error(`verifyOtp failed: ${i.message??`unknown`}`));let e=i.message===`invalid_otp`||i.status===400?`Code invalide ou expiré`:i.message??`Erreur de validation`;throw l(()=>{this.setError(e)}),i}let a=r;return l(()=>{this.setSession(a)}),!a.user.name||a.user.name.length===0}async updateName(e){let{error:t}=await X.updateUser({name:e});if(t)throw n(Error(`updateUser failed: ${t.message??`unknown`}`)),t;l(()=>{this.session&&={...this.session,user:{...this.session.user,name:e}}})}async signOut(){await X.signOut(),l(()=>{this.setSession(null),rn()})}},bn,xn,Sn,Cn,wn,Tn,En,Dn,On;function kn(e,t,n,r,i,a){var o,s,c,l,u,d,f,p=Symbol.metadata||Symbol.for(`Symbol.metadata`),m=Object.defineProperty,h=Object.create,g=[h(null),h(null)],_=t.length;function v(t,n,r){return function(i,a){n&&(a=i,i=e);for(var o=0;o<t.length;o++)a=t[o].apply(i,r?[a]:[]);return r?a:i}}function y(e,t,n,r){if(typeof e!=`function`&&(r||e!==void 0))throw TypeError(t+` must `+(n||`be`)+` a function`+(r?``:` or undefined`));return e}function b(e,t,n,r,i,a,c,l,u,d,f){function p(e){if(!f(e))throw TypeError(`Attempted to access private element on non-instance`)}var h=[].concat(t[0]),_=t[3],b=!c,x=i===1,S=i===3,C=i===4,w=i===2;function T(t,n,r){return function(i,a){return n&&(a=i,i=e),r&&r(i),E[t].call(i,a)}}if(!b){var E={},D=[],O=S?`get`:C||x?`set`:`value`;if(u?(d||x?E={get:Mn(function(){return _(this)},r,`get`),set:function(e){t[4](this,e)}}:E[O]=_,d||Mn(E[O],r,w?``:O)):d||(E=Object.getOwnPropertyDescriptor(e,r)),!d&&!u){if((s=g[+l][r])&&(s^i)!==7)throw Error(`Decorating two elements with the same name (`+E[O].name+`) is not supported yet`);g[+l][r]=i<3?1:i}}for(var k=e,A=h.length-1;A>=0;A-=n?2:1){var j=y(h[A],`A decorator`,`be`,!0),M=n?h[A-1]:void 0,N={},P={kind:[`field`,`accessor`,`method`,`getter`,`setter`,`class`][i],name:r,metadata:o,addInitializer:function(e,t){if(e.v)throw TypeError(`attempted to call addInitializer after decoration was finished`);y(t,`An initializer`,`be`,!0),a.push(t)}.bind(null,N)};if(b)s=j.call(M,k,P),N.v=1,y(s,`class decorators`,`return`)&&(k=s);else if(P.static=l,P.private=u,s=P.access={has:u?f.bind():function(e){return r in e}},C||(s.get=u?w?function(e){return p(e),E.value}:T(`get`,0,p):function(e){return e[r]}),w||S||(s.set=u?T(`set`,0,p):function(e,t){e[r]=t}),k=j.call(M,x?{get:E.get,set:E.set}:E[O],P),N.v=1,x){if(typeof k==`object`&&k)(s=y(k.get,`accessor.get`))&&(E.get=s),(s=y(k.set,`accessor.set`))&&(E.set=s),(s=y(k.init,`accessor.init`))&&D.unshift(s);else if(k!==void 0)throw TypeError(`accessor decorators must return an object with get, set, or init properties or undefined`)}else y(k,(d?`field`:`method`)+` decorators`,`return`)&&(d?D.unshift(k):E[O]=k)}return i<2&&c.push(v(D,l,1),v(a,l,0)),d||b||(u?x?c.splice(-1,0,T(`get`,l),T(`set`,l)):c.push(w?E[O]:y.call.bind(E[O])):m(e,r,E)),k}function x(e){return m(e,p,{configurable:!0,enumerable:!0,value:o})}return a!==void 0&&(o=a[p]),o=h(o??null),u=[],d=function(e){e&&u.push(v(e))},f=function(t,r){for(var a=0;a<n.length;a++){var o=n[a],s=o[1],d=7&s;if((8&s)==t&&!d==r){var f=o[2],p=!!o[3],m=16&s;b(t?e:e.prototype,o,m,p?`#`+f:An(f),d,d<2?[]:t?l||=[]:c||=[],u,!!t,p,r,t&&p?function(t){return Nn(t)===e}:i)}}},f(8,0),f(0,0),f(8,1),f(0,1),d(c),d(l),s=u,_||x(e),{e:s,get c(){var n=[];return _&&[x(e=b(e,[t],r,e.name,5,n)),v(n,1)]}}}function An(e){var t=jn(e,`string`);return typeof t==`symbol`?t:t+``}function jn(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Mn(e,t,n){typeof t==`symbol`&&(t=(t=t.description)?`[`+t+`]`:``);try{Object.defineProperty(e,`name`,{configurable:!0,value:n?n+` `+t:t})}catch{}return e}function Nn(e){if(Object(e)!==e)throw TypeError(`right-hand side of 'in' should be an object, got `+(e===null?`null`:typeof e));return e}var Pn=class{static{[xn,Sn,Cn,wn,Tn,En,Dn,On,bn]=kn(this,[],[[u,1,`info`],[u,1,`error`],[u,1,`loading`],[u,1,`joining`],[o,2,`fetchInfo`],[o,2,`setMissingToken`],[o,2,`join`],[o,2,`reset`]]).e}#e=(bn(this),xn(this,null));get info(){return this.#e}set info(e){this.#e=e}#t=(Sn(this),Cn(this,null));get error(){return this.#t}set error(e){this.#t=e}#n=(wn(this),Tn(this,!0));get loading(){return this.#n}set loading(e){this.#n=e}#r=(En(this),Dn(this,!1));get joining(){return this.#r}set joining(e){this.#r=e}constructor(e){this.root=e,On(this)}async fetchInfo(e){this.loading=!0,this.error=null;try{let t=await M.share.getInfo(e);l(()=>{this.info=t})}catch(e){l(()=>{this.error=e instanceof Error?e.message:`Lien invalide ou expiré`})}finally{l(()=>{this.loading=!1})}}setMissingToken(){this.error=`Lien de partage invalide.`,this.loading=!1}async join(e){this.joining=!0,this.error=null;try{let t=await M.share.join(e);return this.root.tracker.trackLessonStarted(),{status:`joined`,lessonId:t.lessonId}}catch(e){return e instanceof k&&e.status===409&&e.body?.lessonId?{status:`already_enrolled`,lessonId:e.body.lessonId}:(l(()=>{this.error=e instanceof Error?e.message:`Erreur`}),null)}finally{l(()=>{this.joining=!1})}}reset(){this.info=null,this.error=null,this.loading=!0,this.joining=!1}},Fn=/(\$\$[\s\S]*?\$\$|\$[^$\n]*?\$)/g;function In(e){if(!e)return[];let t=[],n=0;for(let r of e.matchAll(Fn)){let i=r.index;i>n&&t.push({type:`text`,value:e.slice(n,i)});let a=r[0];a.startsWith(`$$`)?t.push({type:`formula`,value:a.slice(2,-2),display:`block`}):t.push({type:`formula`,value:a.slice(1,-1),display:`inline`}),n=i+a.length}return n<e.length&&t.push({type:`text`,value:e.slice(n)}),t}function Ln(e){return In(e).some(e=>e.type===`formula`)}function Rn(e,n){let{presentationType:r,answerPresentationType:i}=e,a=!1,o=!1;r===`audio`&&Ln(e.content)&&(t(`[${n.caller}
3] Card has audio presentationType with LaTeX content`,{level:`warning`,extra:{cardId:n.cardId}}),r=`text`,a=!0),i===`audio`&&Ln(e.answer)&&(t(`[${n.caller}] Card has audio answerPresentationType with LaTeX answer`,{level:`warning`,extra:{cardId:n.cardId}}),i=`text`,o=!0);let s=null;return a&&o?s=`Le mode audio a été désactivé pour la question et la réponse car elles contiennent des formules mathématiques. Enregistrez pour corriger.`:a?s=`Le mode audio a été désactivé car la question contient des formules mathématiques. Enregistrez pour corriger.`:o&&(s=`Le mode audio de la réponse a été désactivé car la réponse contient des formules mathématiques. Enregistrez pour corriger.`),{presentationType:r,answerPresentationType:i,warning:s}}var zn,Bn,Vn,Hn,Un,Wn,Gn,Kn,qn,Jn,Yn,Xn,Zn,Qn,$n,er,tr,nr,rr,ir,ar,or,sr,cr,lr,ur,dr,fr,pr,mr,hr,gr,_r,vr,yr,br,xr,Sr,Cr,wr,Tr,Er,Dr,Or,kr,Ar,jr;function Mr(e,t,n,r,i,a){var o,s,c,l,u,d,f,p=Symbol.metadata||Symbol.for(`Symbol.metadata`),m=Object.defineProperty,h=Object.create,g=[h(null),h(null)],_=t.length;function v(t,n,r){return function(i,a){n&&(a=i,i=e);for(var o=0;o<t.length;o++)a=t[o].apply(i,r?[a]:[]);return r?a:i}}function y(e,t,n,r){if(typeof e!=`function`&&(r||e!==void 0))throw TypeError(t+` must `+(n||`be`)+` a function`+(r?``:` or undefined`));return e}function b(e,t,n,r,i,a,c,l,u,d,f){function p(e){if(!f(e))throw TypeError(`Attempted to access private element on non-instance`)}var h=[].concat(t[0]),_=t[3],b=!c,x=i===1,S=i===3,C=i===4,w=i===2;function T(t,n,r){return function(i,a){return n&&(a=i,i=e),r&&r(i),E[t].call(i,a)}}if(!b){var E={},D=[],O=S?`get`:C||x?`set`:`value`;if(u?(d||x?E={get:Fr(function(){return _(this)},r,`get`),set:function(e){t[4](this,e)}}:E[O]=_,d||Fr(E[O],r,w?``:O)):d||(E=Object.getOwnPropertyDescriptor(e,r)),!d&&!u){if((s=g[+l][r])&&(s^i)!==7)throw Error(`Decorating two elements with the same name (`+E[O].name+`) is not supported yet`);g[+l][r]=i<3?1:i}}for(var k=e,A=h.length-1;A>=0;A-=n?2:1){var j=y(h[A],`A decorator`,`be`,!0),M=n?h[A-1]:void 0,N={},P={kind:[`field`,`accessor`,`method`,`getter`,`setter`,`class`][i],name:r,metadata:o,addInitializer:function(e,t){if(e.v)throw TypeError(`attempted to call addInitializer after decoration was finished`);y(t,`An initializer`,`be`,!0),a.push(t)}.bind(null,N)};if(b)s=j.call(M,k,P),N.v=1,y(s,`class decorators`,`return`)&&(k=s);else if(P.static=l,P.private=u,s=P.access={has:u?f.bind():function(e){return r in e}},C||(s.get=u?w?function(e){return p(e),E.value}:T(`get`,0,p):function(e){return e[r]}),w||S||(s.set=u?T(`set`,0,p):function(e,t){e[r]=t}),k=j.call(M,x?{get:E.get,set:E.set}:E[O],P),N.v=1,x){if(typeof k==`object`&&k)(s=y(k.get,`accessor.get`))&&(E.get=s),(s=y(k.set,`accessor.set`))&&(E.set=s),(s=y(k.init,`accessor.init`))&&D.unshift(s);else if(k!==void 0)throw TypeError(`accessor decorators must return an object with get, set, or init properties or undefined`)}else y(k,(d?`field`:`method`)+` decorators`,`return`)&&(d?D.unshift(k):E[O]=k)}return i<2&&c.push(v(D,l,1),v(a,l,0)),d||b||(u?x?c.splice(-1,0,T(`get`,l),T(`set`,l)):c.push(w?E[O]:y.call.bind(E[O])):m(e,r,E)),k}function x(e){return m(e,p,{configurable:!0,enumerable:!0,value:o})}return a!==void 0&&(o=a[p]),o=h(o??null),u=[],d=function(e){e&&u.push(v(e))},f=function(t,r){for(var a=0;a<n.length;a++){var o=n[a],s=o[1],d=7&s;if((8&s)==t&&!d==r){var f=o[2],p=!!o[3],m=16&s;b(t?e:e.prototype,o,m,p?`#`+f:Nr(f),d,d<2?[]:t?l||=[]:c||=[],u,!!t,p,r,t&&p?function(t){return Ir(t)===e}:i)}}},f(8,0),f(0,0),f(8,1),f(0,1),d(c),d(l),s=u,_||x(e),{e:s,get c(){var n=[];return _&&[x(e=b(e,[t],r,e.name,5,n)),v(n,1)]}}}function Nr(e){var t=Pr(e,`string`);return typeof t==`symbol`?t:t+``}function Pr(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Fr(e,t,n){typeof t==`symbol`&&(t=(t=t.description)?`[`+t+`]`:``);try{Object.defineProperty(e,`name`,{configurable:!0,value:n?n+` `+t:t})}catch{}return e}function Ir(e){if(Object(e)!==e)throw TypeError(`right-hand side of 'in' should be an object, got `+(e===null?`null`:typeof e));return e}var Lr=class{static{[Bn,Vn,Hn,Un,Wn,Gn,Kn,qn,Jn,Yn,Xn,Zn,Qn,$n,er,tr,nr,rr,ir,ar,or,sr,cr,lr,ur,dr,fr,pr,mr,hr,gr,_r,vr,yr,br,xr,Sr,Cr,wr,Tr,Er,Dr,Or,kr,Ar,jr,zn]=Mr(this,[],[[u,1,`content`],[u,1,`answer`],[u,1,`writeMode`],[u,1,`mcqMode`],[u,1,`distractors`],[s,3,`distractorCount`],[u,1,`optionFormat`],[u,1,`presentationType`],[u,1,`answerPresentationType`],[u,1,`ttsLanguage`],[u,1,`answerTtsLanguage`],[u,1,`error`],[o,0,`setContent`],[o,0,`setAnswer`],[o,0,`setWriteMode`],[o,0,`setMcqMode`],[o,0,`addDistractor`],[o,0,`removeDistractor`],[o,0,`updateDistractor`],[o,0,`setOptionFormat`],[o,0,`setPresentationType`],[o,0,`setAnswerPresentationType`],[o,0,`setTtsLanguage`],[o,0,`setAnswerTtsLanguage`],[o,2,`resetContent`],[o,2,`reset`],[o,2,`loadFromQuestion`]]).e}constructor(){jr(this)}#e=(zn(this),Bn(this,``));get content(){return this.#e}set content(e){this.#e=e}#t=(Vn(this),Hn(this,``));get answer(){return this.#t}set answer(e){this.#t=e}#n=(Un(this),Wn(this,!1));get writeMode(){return this.#n}set writeMode(e){this.#n=e}#r=(Gn(this),Kn(this,!1));get mcqMode(){return this.#r}set mcqMode(e){this.#r=e}#i=(qn(this),Jn(this,[]));get distractors(){return this.#i}set distractors(e){this.#i=e}get distractorCount(){return this.distractors.length}#a=(Yn(this),Xn(this,`text`));get optionFormat(){return this.#a}set optionFormat(e){this.#a=e}#o=(Zn(this),Qn(this,`text`));get presentationType(){return this.#o}set presentationType(e){this.#o=e}#s=($n(this),er(this,`text`));get answerPresentationType(){return this.#s}set answerPresentationType(e){this.#s=e}#c=(tr(this),nr(this,`fr`));
3get ttsLanguage(){return this.#c}set ttsLanguage(e){this.#c=e}#l=(rr(this),ir(this,`fr`));get answerTtsLanguage(){return this.#l}set answerTtsLanguage(e){this.#l=e}#u=(ar(this),or(this,null));get error(){return this.#u}set error(e){this.#u=e}setContent=(sr(this),cr(this,e=>{this.presentationType===`audio`&&this.content===this.answer&&(this.answer=e),this.content=e,this.error=null}));setAnswer=(lr(this),ur(this,e=>{this.answer=e,this.error=null}));setWriteMode=(dr(this),fr(this,e=>{this.writeMode=e,this.error=null}));setMcqMode=(pr(this),mr(this,e=>{this.mcqMode=e,e&&(this.writeMode=!1,this.answerPresentationType=`text`),this.error=null}));addDistractor=(hr(this),gr(this,()=>{this.distractors=[...this.distractors,{value:``}]}));removeDistractor=(_r(this),vr(this,e=>{if(e<0||e>=this.distractors.length){t(`[FlashcardFormStore] removeDistractor: index out of bounds`,{level:`warning`,extra:{index:e,count:this.distractors.length}});return}this.distractors=this.distractors.filter((t,n)=>n!==e)}));updateDistractor=(yr(this),br(this,(e,n)=>{if(e<0||e>=this.distractors.length){t(`[FlashcardFormStore] updateDistractor: index out of bounds`,{level:`warning`,extra:{index:e,count:this.distractors.length}});return}this.distractors=this.distractors.map((t,r)=>r===e?{...t,value:n}:t)}));setOptionFormat=(xr(this),Sr(this,e=>{this.optionFormat=e}));setPresentationType=(Cr(this),wr(this,e=>{this.presentationType=e}));setAnswerPresentationType=(Tr(this),Er(this,e=>{this.answerPresentationType=e,e===`audio`&&!this.answer.trim()&&(this.answer=this.content)}));setTtsLanguage=(Dr(this),Or(this,e=>{this.ttsLanguage=e}));setAnswerTtsLanguage=(kr(this),Ar(this,e=>{this.answerTtsLanguage=e}));resetContent(){this.content=``,this.answer=``,this.writeMode=!1,this.mcqMode=!1,this.distractors=[],this.error=null}reset(){this.resetContent(),this.presentationType=`text`,this.answerPresentationType=`text`,this.optionFormat=`text`,this.ttsLanguage=`fr`,this.answerTtsLanguage=`fr`}loadFromQuestion(e){let n=e.answerType===`mcq`;if(this.mcqMode=n,n&&e.mcqOptions){this.distractors=e.mcqOptions.slice(1);let n=e.raw.answer;(!n||n.type!==`mcq`||!n.optionFormat)&&t(`[FlashcardFormStore.loadFromQuestion] MCQ card has missing optionFormat`,{level:`warning`,extra:{cardId:e.id}}),this.optionFormat=n?.type===`mcq`?n.optionFormat:`text`}else this.distractors=[],this.optionFormat=`text`}toApiPayload(){return this.mcqMode&&this.distractorCount>0?{distractors:this.distractors.map(e=>({...e})),optionFormat:this.optionFormat}:(this.mcqMode&&t(`[FlashcardFormStore.toApiPayload] mcqMode=true sans distracteur â dégradation vers show`,{level:`warning`}),this.writeMode?{answerType:`write`}:{presentationType:this.presentationType,answerPresentationType:this.answerPresentationType,ttsLanguage:this.presentationType===`audio`?this.ttsLanguage:void 0,answerTtsLanguage:this.answerPresentationType===`audio`?this.answerTtsLanguage:void 0})}},Rr,zr,Br,Vr,Hr,Ur,Wr,Gr,Kr,qr,Jr,Yr,Xr,Zr,Qr,$r,ei,ti,ni,ri,ii,ai,oi,si,ci,li,ui,di,fi,pi,mi,hi,gi,_i,vi,yi,bi,xi,Si,Ci,wi,Ti,Ei,Di,Oi,ki,Ai,ji,Mi,Ni,Pi,Fi,Ii,Li,Ri,zi,Bi,Vi,Hi;function Ui(e,t,n,r,i,a){var o,s,c,l,u,d,f,p=Symbol.metadata||Symbol.for(`Symbol.metadata`),m=Object.defineProperty,h=Object.create,g=[h(null),h(null)],_=t.length;function v(t,n,r){return function(i,a){n&&(a=i,i=e);for(var o=0;o<t.length;o++)a=t[o].apply(i,r?[a]:[]);return r?a:i}}function y(e,t,n,r){if(typeof e!=`function`&&(r||e!==void 0))throw TypeError(t+` must `+(n||`be`)+` a function`+(r?``:` or undefined`));return e}function b(e,t,n,r,i,a,c,l,u,d,f){function p(e){if(!f(e))throw TypeError(`Attempted to access private element on non-instance`)}var h=[].concat(t[0]),_=t[3],b=!c,x=i===1,S=i===3,C=i===4,w=i===2;function T(t,n,r){return function(i,a){return n&&(a=i,i=e),r&&r(i),E[t].call(i,a)}}if(!b){var E={},D=[],O=S?`get`:C||x?`set`:`value`;if(u?(d||x?E={get:Ki(function(){return _(this)},r,`get`),set:function(e){t[4](this,e)}}:E[O]=_,d||Ki(E[O],r,w?``:O)):d||(E=Object.getOwnPropertyDescriptor(e,r)),!d&&!u){if((s=g[+l][r])&&(s^i)!==7)throw Error(`Decorating two elements with the same name (`+E[O].name+`) is not supported yet`);g[+l][r]=i<3?1:i}}for(var k=e,A=h.length-1;A>=0;A-=n?2:1){var j=y(h[A],`A decorator`,`be`,!0),M=n?h[A-1]:void 0,N={},P={kind:[`field`,`accessor`,`method`,`getter`,`setter`,`class`][i],name:r,metadata:o,addInitializer:function(e,t){if(e.v)throw TypeError(`attempted to call addInitializer after decoration was finished`);y(t,`An initializer`,`be`,!0),a.push(t)}.bind(null,N)};if(b)s=j.call(M,k,P),N.v=1,y(s,`class decorators`,`return`)&&(k=s);else if(P.static=l,P.private=u,s=P.access={has:u?f.bind():function(e){return r in e}},C||(s.get=u?w?function(e){return p(e),E.value}:T(`get`,0,p):function(e){return e[r]}),w||S||(s.set=u?T(`set`,0,p):function(e,t){e[r]=t}),k=j.call(M,x?{get:E.get,set:E.set}:E[O],P),N.v=1,x){if(typeof k==`object`&&k)(s=y(k.get,`accessor.get`))&&(E.get=s),(s=y(k.set,`accessor.set`))&&(E.set=s),(s=y(k.init,`accessor.init`))&&D.unshift(s);else if(k!==void 0)throw TypeError(`accessor decorators must return an object with get, set, or init properties or undefined`)}else y(k,(d?`field`:`method`)+` decorators`,`return`)&&(d?D.unshift(k):E[O]=k)}return i<2&&c.push(v(D,l,1),v(a,l,0)),d||b||(u?x?c.splice(-1,0,T(`get`,l),T(`set`,l)):c.push(w?E[O]:y.call.bind(E[O])):m(e,r,E)),k}function x(e){return m(e,p,{configurable:!0,enumerable:!0,value:o})}return a!==void 0&&(o=a[p]),o=h(o??null),u=[],d=function(e){e&&u.push(v(e))},f=function(t,r){for(var a=0;a<n.length;a++){var o=n[a],s=o[1],d=7&s;if((8&s)==t&&!d==r){var f=o[2],p=!!o[3],m=16&s;b(t?e:e.prototype,o,m,p?`#`+f:Wi(f),d,d<2?[]:t?l||=[]:c||=[],u,!!t,p,r,t&&p?function(t){return qi(t)===e}:i)}}},f(8,0),f(0,0),f(8,1),f(0,1),d(c),d(l),s=u,_||x(e),{e:s,get c(){var n=[];return _&&[x(e=b(e,[t],r,e.name,5,n)),v(n,1)]}}}function Wi(e){var t=Gi(e,`string`);return typeof t==`symbol`?t:t+``}function Gi(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ki(e,t,n){typeof t==`symbol`&&(t=(t=t.description)?`[`+t+`]`:``);try{Object.defineProperty(e,`name`,{configurable:!0,value:n?n+` `+t:t})}catch{}return e}function qi(e){if(Object(e)!==e)throw TypeError(`right-hand side of 'in' should be an object, got `+(e===null?`null`:typeof e));return e}var Ji=class{static{[zr,Br,Vr,Hr,Ur,Wr,Gr,Kr,qr,Jr,Yr,Xr,Zr,Qr,$r,ei,ti,ni,ri,ii,ai,oi,si,ci,li,ui,di,fi,pi,mi,hi,gi,_i,vi,yi,bi,xi,Si,Ci,wi,Ti,Ei,Di,Oi,ki,Ai,ji,Mi,Ni,Pi,Fi,Ii,Li,Ri,zi,Bi,Vi,Hi,Rr]=Ui(this,[],[[u,1,`lesson`],[u,1,`formMirror`],[u,1,`loading`],[u,1,`error`],[u,1,`editingQuestionId`],[u,1,`editMirror`],[u,1,`pendingDeleteQuestionId`],[u,1,`deleteError`],[u,1,`pendingUnenroll`],[u,1,`shareLinks`],[u,1,`members`],[u,1,`shareError`],[u,1,`showShareDialog`],[u,1,`copiedLinkId`],[u,1,`editingTitle`],[u,1,`editTitleValue`],[u,1,`titleError`],[u,1,`aiShowForm`],[u,1,`aiInstructions`],[u,1,`aiFileSelected`],[u,1,`aiGenerating`],[u,1,`aiStep`],[u,1,`aiJobId`],[u,1,`aiProposals`],[u,1,`aiError`],[u,1,`addMode`],[u,1,`addingProposals`],[u,1,`savingQuestion`],[s,3,`questions`],[s,3,`lastNonMirrorQuestion`],[s,3,`isOwner`],[s,3,`canWrite`],[s,3,`editAudioUrl`],[s,3,`editAnswerAudioUrl`],[o,2,`initCreateForm`],[o,2,`setFormMirror`],[o,0,`setEditMirror`],[o,2,`setAddMode`],[o,2,`startEditing`],[o,2,`cancelEditing`],[o,2,`startEditingTitle`],[o,2,`setEditTitleValue`],[o,2,`cancelEditingTitle`],[o,2,`fetchLesson`],[o,2,`saveTitle`],[o,2,`createQuestion`],[o,2,`saveQuestion`],[o,2,`setPendingDeleteQuestionId`],[o,2,`confirmDeleteQuestion`],[o,2,`setPendingUnenroll`],[o,2,`unenroll`],[o,2,`setShowShareDialog`],[o,2,`setCopiedLinkId`],[o,2,`copyShareLink`],[o,2,`fetchShareLinks`],[o,2,`fetchMembers`],[o,2,`createShareLink`],[o,2,`revokeShareLink`],[o,2,`updateMemberAccess`],[o,2,`removeMember`],[o,2,`setAiShowForm`],[o,2,`setAiInstructions`],[o,2,`setAiFileSelected`],[o,2,`generateFromForm`],[o,2,`generateFlashcards`],[o,2,`toggleProposal`],[o,2,`editProposal`],[o,2,`toggleProposalMirror`],[o,2,`setProposalMirror`],[o,2,`setProposalWriteMode`],[o,2,`setProposalPresentationType`],[o,2,`setProposalTtsLanguage`],[o,2,`setProposalAnswerPresentationType`],[o,2,`setProposalAnswerTtsLanguage`],[s,3,`selectedProposalCount`],[o,2,`addSelectedProposals`],[o,2,`cancelAiJob`],[o,2,`clearAiState`],[o,2,`importCsv`],[o,2,`openShareFromList`],[o,2,`reset`]]).e}#e=(Rr(this),zr(this,null));get lesson(){return this.#e}set lesson(e){this.#e=e}#t=(Br(this),Vr(this,!1));get formMirror(){return this.#t}set formMirror(e){this.#t=e}#n=(Hr(this),Ur(this,!1));get loading(){return this.#n}set loading(e){this.#n=e}#r=(Wr(this),Gr(this,null));get error(){return this.#r}set error(e){this.#r=e}#i=(Kr(this),qr(this,null));get editingQuestionId(){return this.#i}set editingQuestionId(e){this.#i=e}#a=(Jr(this),Yr(this,!1));get editMirror(){return this.#a}set editMirror(e){this.#a=e}#o=(Xr(this),Zr(this,null));get pendingDeleteQuestionId(){return this.#o}set pendingDeleteQuestionId(e){this.#o=e}#s=(Qr(this),$r(this,null));get deleteError(){return this.#s}set deleteError(e){this.#s=e}#c=(ei(this),ti(this,!1));get pendingUnenroll(){return this.#c}set pendingUnenroll(e){this.#c=e}#l=(ni(this),ri(this,[]));get shareLinks(){return this.#l}set shareLinks(e){this.#l=e}#u=(ii(this),ai(this,[]));get members(){return this.#u}set members(e){this.#u=e}#d=(oi(this),si(this,null));get shareError(){return this.#d}set shareError(e){this.#d=e}#f=(ci(this),li(this,!1));get showShareDialog(){return this.#f}set showShareDialog(e){this.#f=e}#p=(ui(this),di(this,null));get copiedLinkId(){return this.#p}set copiedLinkId(e){this.#p=e}#m=(fi(this),pi(this,!1));get editingTitle(){return this.#m}set editingTitle(e){this.#m=e}#h=(mi(this),hi(this,``));get editTitleValue(){return this.#h}set editTitleValue(e){this.#h=e}#g=(gi(this),_i(this,null));get titleError(){return this.#g}set titleError(e){this.#g=e}#_=(vi(this),yi(this,!1));get aiShowForm(){return this.#_}set aiShowForm(e){this.#_=e}#v=(bi(this),xi(this,``));get aiInstructions(){return this.#v}set aiInstructions(e){this.#v=e}#y=(Si(this),Ci(this,!1));get aiFileSelected(){return this.#y}set aiFileSelected(e){this.#y=e}#b=(wi(this),Ti(this,!1));
3get aiGenerating(){return this.#b}set aiGenerating(e){this.#b=e}#x=(Ei(this),Di(this,null));get aiStep(){return this.#x}set aiStep(e){this.#x=e}#S=(Oi(this),ki(this,null));get aiJobId(){return this.#S}set aiJobId(e){this.#S=e}#C=(Ai(this),ji(this,[]));get aiProposals(){return this.#C}set aiProposals(e){this.#C=e}#w=(Mi(this),Ni(this,null));get aiError(){return this.#w}set aiError(e){this.#w=e}#T=(Pi(this),Fi(this,null));get addMode(){return this.#T}set addMode(e){this.#T=e}#E=(Ii(this),Li(this,!1));get addingProposals(){return this.#E}set addingProposals(e){this.#E=e}#D=(Ri(this),zi(this,!1));get savingQuestion(){return this.#D}set savingQuestion(e){this.#D=e}createForm=(Bi(this),new Lr);editForm=new Lr;constructor(e){this.root=e,Hi(this)}get questions(){return this.lesson?.questions??[]}get lastNonMirrorQuestion(){return[...this.questions].filter(e=>!e.isMirror).toSorted((e,t)=>t.order-e.order)[0]}get isOwner(){return this.lesson?.isOwner??!1}get canWrite(){return this.lesson?.canWrite??!1}get editAudioUrl(){return this.editingQuestionId?this.questions.find(e=>e.id===this.editingQuestionId)?.audioUrl??null:null}get editAnswerAudioUrl(){return this.editingQuestionId?this.questions.find(e=>e.id===this.editingQuestionId)?.answerAudioUrl??null:null}initCreateForm(){let e=this.lastNonMirrorQuestion;this.createForm.writeMode=e?.answerType===`write`,this.createForm.presentationType=e?.presentationType??`text`,this.createForm.answerPresentationType=e?.answerPresentationType??`text`,this.createForm.ttsLanguage=e?.ttsLanguage??`fr`,this.createForm.answerTtsLanguage=e?.answerTtsLanguage??`fr`}setFormMirror(e){this.formMirror=e}setEditMirror=Vi(this,e=>{this.editMirror=e});setAddMode(e){this.addMode=e}startEditing(e){let t=this.questions.find(t=>t.id===e);if(!t){this.editForm.error=`Cette fiche n'existe plus. Rechargez la page.`;return}let n=this.questions.some(t=>t.mirrorOfId===e);this.editingQuestionId=e,this.editMirror=n,this.editForm.content=t.content,this.editForm.answer=t.answer,this.editForm.writeMode=t.answerType===`write`,this.editForm.loadFromQuestion(t);let r=Rn({content:t.content,answer:t.answer,presentationType:t.presentationType,answerPresentationType:t.answerPresentationType},{caller:`LessonDetailStore.startEditing`,cardId:e});this.editForm.presentationType=r.presentationType,this.editForm.answerPresentationType=r.answerPresentationType,this.editForm.ttsLanguage=t.ttsLanguage??`fr`,this.editForm.answerTtsLanguage=t.answerTtsLanguage??`fr`,this.editForm.error=r.warning}cancelEditing(){this.editingQuestionId=null,this.editMirror=!1,this.editForm.reset()}startEditingTitle(){this.lesson&&(this.editingTitle=!0,this.editTitleValue=this.lesson.title,this.titleError=null)}setEditTitleValue(e){this.editTitleValue=e,this.titleError=null}cancelEditingTitle(){this.editingTitle=!1,this.editTitleValue=``,this.titleError=null}async fetchLesson(e){this.loading=!0,this.error=null;try{let t=await M.lessons.get(e);l(()=>{this.lesson=Q.getOrCreate(t)}),await this.resumeActiveJob(e)}catch(e){n(e),l(()=>{this.error=e instanceof Error?e.message:`Erreur de chargement`})}finally{l(()=>{this.loading=!1})}}async saveTitle(){if(!this.lesson||!this.editingTitle)return;let e=this.editTitleValue.trim();if(!e){this.editingTitle=!1,this.editTitleValue=``;return}if(e===this.lesson.title){this.editingTitle=!1,this.editTitleValue=``;return}try{await M.lessons.update(this.lesson.id,{title:e}),l(()=>{this.lesson.title=e,this.editingTitle=!1,this.editTitleValue=``,this.titleError=null})}catch(e){n(e),l(()=>{this.titleError=e instanceof Error?e.message:`Erreur de mise à jour`,this.editingTitle=!1,this.editTitleValue=``})}}async createQuestion(){if(!this.lesson)return!1;let e=this.lesson.id,t=this.createForm.content.trim(),r=this.createForm.answer.trim();if(!t||!r)return this.error=`La question et la réponse sont obligatoires.`,!1;this.savingQuestion=!0;let i=!1;try{(await M.lessons.createQuestion(e,{content:t,answer:r,mirror:this.formMirror||void 0,...this.createForm.toApiPayload()})).audioGenerationFailed&&(i=!0)}catch(e){return n(e),l(()=>{this.error=e instanceof Error?e.message:`Erreur de création`,this.savingQuestion=!1}),!1}try{let t=await M.lessons.get(e);l(()=>{Q.getOrCreate(t),this.createForm.resetContent(),this.formMirror=!1,this.error=i?`Carte sauvegardée. La génération audio a échoué â réessayez depuis l'édition.`:null,this.addMode=null,this.savingQuestion=!1})}catch(e){n(e),l(()=>{this.createForm.resetContent(),this.formMirror=!1,this.error=i?`Carte sauvegardée. La génération audio a échoué â réessayez depuis l'édition.`:null,this.addMode=null,this.savingQuestion=!1})}return!0}async saveQuestion(){if(!this.lesson||!this.editingQuestionId)return;let e=this.lesson.id,t=this.editingQuestionId,r=this.editForm.content.trim(),i=this.editForm.answer.trim();if(!r||!i){this.editForm.error=`La question et la réponse sont obligatoires.`;return}this.savingQuestion=!0;let a=!1;try{(await M.lessons.updateQuestion(e,t,{content:r,answer:i,mirror:this.editMirror,...this.editForm.toApiPayload()})).audioGenerationFailed&&(a=!0)}catch(e){n(e),l(()=>{this.editForm.error=e instanceof Error?e.message:`Erreur de mise à jour`,this.savingQuestion=!1});return}let o=a?`Carte sauvegardée. La génération audio a échoué.`:null;try{let t=await M.lessons.get(e);l(()=>{Q.getOrCreate(t),this.editingQuestionId=null,this.editMirror=!1,this.editForm.reset(),this.error=o,this.savingQuestion=!1})}catch(e){n(e),l(()=>{this.editingQuestionId=null,this.editMirror=!1,this.editForm.reset(),this.error=o,this.savingQuestion=!1})}}setPendingDeleteQuestionId(e){this.pendingDeleteQuestionId=e,this.deleteError=null}async confirmDeleteQuestion(){if(!this.lesson||!this.pendingDeleteQuestionId)return;let e=this.lesson.id,t=this.pendingDeleteQuestionId;this.deleteError=null;try{await M.lessons.deleteQuestion(e,t),l(()=>{this.lesson.questions=this.lesson.questions.filter(e=>e.id!==t&&e.mirrorOfId!==t)})}catch(e){n(e),l(()=>{this.deleteError=e instanceof Error?e.message:`Erreur de suppression`})}finally{l(()=>{this.pendingDeleteQuestionId=null})}}setPendingUnenroll(e){this.pendingUnenroll=e}async unenroll(){if(!this.lesson)return!1;try{return await M.lessons.unenroll(this.lesson.id),this.root.tracker.trackLessonLeft(),!0}catch(e){return n(e),l(()=>{this.error=e instanceof Error?e.message:`Erreur lors de la désinscription`}),!1}finally{l(()=>{this.pendingUnenroll=!1})}}setShowShareDialog(e){this.showShareDialog=e,e&&this.lesson&&(this.shareError=null,this.copiedLinkId=null,this.shareLinks=[],this.members=[],this.loadShareData())}async loadShareData(){if(!this.lesson)return;let[e,t]=await Promise.allSettled([M.share.list(this.lesson.id),M.share.members(this.lesson.id)]);l(()=>{e.status===`fulfilled`&&(this.shareLinks=e.value),t.status===`fulfilled`&&(this.members=t.value);let r=[];e.status===`rejected`&&(n(e.reason),r.push(e.reason instanceof Error?e.reason.message:`Erreur de chargement des liens`)),t.status===`rejected`&&(n(t.reason),r.push(t.reason instanceof Error?t.reason.message:`Erreur de chargement des membres`)),r.length>0&&(this.shareError=r.join(`. `))})}setCopiedLinkId(e){this.copiedLinkId=e}async copyShareLink(e,t){try{await navigator.clipboard.writeText(t),l(()=>{this.copiedLinkId=e}),setTimeout(()=>{l(()=>{this.copiedLinkId===e&&(this.copiedLinkId=null)})},2e3)}catch(e){n(e),l(()=>{this.shareError=`Impossible de copier le lien. Sélectionnez-le manuellement.`})}}async fetchShareLinks(){if(this.lesson)try{let e=await M.share.list(this.lesson.id);l(()=>{this.shareLinks=e})}catch(e){n(e),l(()=>{this.shareError=e instanceof Error?e.message:`Erreur de chargement des liens`})}}async fetchMembers(){if(this.lesson)try{let e=await M.share.members(this.lesson.id);l(()=>{this.members=e})}catch(e){n(e),l(()=>{this.shareError=e instanceof Error?e.message:`Erreur de chargement des membres`})}}async createShareLink(){if(this.lesson)try{let e=await M.share.create(this.lesson.id);l(()=>{this.shareLinks.push(e),this.shareError=null}),this.root.tracker.trackShareLinkCreated(e.accessLevel===`readwrite`?`write`:`read`)}catch(e){n(e),l(()=>{this.shareError=e instanceof Error?e.message:`Erreur de création du lien`})}}async revokeShareLink(e){try{await M.share.revoke(e),l(()=>{this.shareLinks=this.shareLinks.filter(t=>t.id!==e)})}catch(e){n(e),l(()=>{this.shareError=e instanceof Error?e.message:`Erreur de révocation`})}}async updateMemberAccess(e,t){if(this.lesson)try{await M.share.updateMember(this.lesson.id,e,t),l(()=>{let n=this.members.find(t=>t.userId===e);n&&(n.accessLevel=t)})}catch(e){n(e),l(()=>{this.shareError=e instanceof Error?e.message:`Erreur de modification`})}}async removeMember(e){if(this.lesson)try{await M.share.removeMember(this.lesson.id,e),l(()=>{this.members=this.members.filter(t=>t.userId!==e)})}catch(e){n(e),l(()=>{this.shareError=e instanceof Error?e.message:`Erreur de retrait du membre`})}}setAiShowForm(e){this.aiShowForm=e}setAiInstructions(e){this.aiInstructions=e}setAiFileSelected(e){this.aiFileSelected=e}async resumeActiveJob(e){let t;try{t=await M.lessons.getActiveFlashcardJob(e)}catch(e){e instanceof k&&e.status===403||n(e);return}if(t){if(l(()=>{this.aiShowForm=!0,this.aiJobId=t.jobId}),t.status===`complete`){l(()=>{this.aiProposals=(t.cards??[]).map((e,t)=>({id:`ai-${Date.now()}-${t}`,content:e.content,answer:e.answer,mirror:e.mirror??!1,selected:!0,writeMode:!1,presentationType:e.presentationType??`text`,ttsLanguage:e.ttsLanguage,answerPresentationType:e.answerPresentationType,answerTtsLanguage:e.answerTtsLanguage})),this.aiProposals.length===0&&(this.aiError=`Aucune carte n'a pu être générée à partir de cette image.`)});return}l(()=>{this.aiGenerating=!0,(t.status===`extracting`||t.status===`generating`)&&(this.aiStep=t.status)}),this.pollFlashcardJob(e,t.jobId).then(e=>{l(()=>{this.aiProposals=e.map((e,t)=>({id:`ai-${Date.now()}-${t}`,content:e.content,answer:e.answer,mirror:e.mirror??!1,selected:!0,writeMode:!1,presentationType:e.presentationType??`text`,ttsLanguage:e.ttsLanguage,answerPresentationType:e.answerPresentationType,answerTtsLanguage:e.answerTtsLanguage})),e.length===0&&(this.aiError=`Aucune carte n'a pu être générée à partir de cette image.`)})}).catch(e=>{n(e),l(()=>{this.aiError=e instanceof Error?e.message:`Erreur lors de la génération`})}).finally(()=>{l(()=>{this.aiGenerating=!1,this.aiStep=null})})}}async generateFromForm(e){return this.generateFlashcards(e,this.aiInstructions||void 0)}async generateFlashcards(e,t){if(!this.lesson)return;let r=this.lesson.id;this.aiGenerating=!0,this.aiStep=null,this.aiJobId=null,this.aiError=null,this.aiProposals=[];try{let{jobId:n}=await M.lessons.startFlashcardGeneration(r,e,t);l(()=>{this.aiJobId=n});let i=await this.pollFlashcardJob(r,n);l(()=>{this.aiProposals=i.map((e,t)=>({id:`ai-${Date.now()}-${t}`,content:e.content,answer:e.answer,mirror:e.mirror??!1,selected:!0,writeMode:!1,presentationType:e.presentationType??`text`,ttsLanguage:e.ttsLanguage,answerPresentationType:e.answerPresentationType,answerTtsLanguage:e.answerTtsLanguage})),i.length===0&&(this.aiError=`Aucune carte n'a pu être générée à partir de cette image.`)})}catch(e){n(e),l(()=>{e instanceof k?e.status===429?this.aiError=`Trop de requêtes. Veuillez patienter avant de réessayer.`:e.status===409?this.aiError=`Une génération est déjà en cours pour cette leçon.`:this.aiError=e.message:this.aiError=e instanceof Error?e.message:`Erreur lors de la génération`})}finally{l(()=>{this.aiGenerating=!1,this.aiStep=null})}}async pollFlashcardJob(e,t){for(let n=0;n<150;n++){await new Promise(e=>setTimeout(e,2e3));let n=await M.lessons.pollFlashcardJob(e,t);if(l(()=>{(n.status===`extracting`||n.status===`generating`)&&(this.aiStep=n.status)}),n.status===`complete`)return n.cards??[];if(n.status===`error`)throw Error(n.message??`La génération a échoué, veuillez réessayer.`);if(n.status===`done`)throw Error(`La génération a expiré. Les cartes ont été ajoutées automatiquement à la leçon.`)}throw Error(`La génération a pris trop de temps. Veuillez réessayer.`)}
3toggleProposal(e){e>=0&&e<this.aiProposals.length&&(this.aiProposals[e].selected=!this.aiProposals[e].selected)}editProposal(e,t,n){e>=0&&e<this.aiProposals.length&&(this.aiProposals[e][t]=n)}toggleProposalMirror(e){e>=0&&e<this.aiProposals.length&&(this.aiProposals[e].mirror=!this.aiProposals[e].mirror)}setProposalMirror(e,t){e>=0&&e<this.aiProposals.length&&(this.aiProposals[e].mirror=t)}setProposalWriteMode(e,t){e>=0&&e<this.aiProposals.length&&(this.aiProposals[e].writeMode=t)}setProposalPresentationType(e,t){e>=0&&e<this.aiProposals.length&&(this.aiProposals[e].presentationType=t)}setProposalTtsLanguage(e,t){e>=0&&e<this.aiProposals.length&&(this.aiProposals[e].ttsLanguage=t)}setProposalAnswerPresentationType(e,t){e>=0&&e<this.aiProposals.length&&(this.aiProposals[e].answerPresentationType=t===`audio`?`audio`:void 0)}setProposalAnswerTtsLanguage(e,t){e>=0&&e<this.aiProposals.length&&(this.aiProposals[e].answerTtsLanguage=t)}get selectedProposalCount(){return this.aiProposals.filter(e=>e.selected).length}async addSelectedProposals(){if(!this.lesson||!this.aiJobId||this.addingProposals)return;let e=this.lesson.id,t=this.aiJobId,r=this.aiProposals.filter(e=>e.selected).map(e=>({content:e.content,answer:e.answer,mirror:e.mirror||void 0,answerType:e.writeMode?`write`:void 0,presentationType:!e.writeMode&&e.presentationType===`audio`?`audio`:void 0,ttsLanguage:!e.writeMode&&e.presentationType===`audio`?e.ttsLanguage:void 0,answerPresentationType:!e.writeMode&&e.answerPresentationType===`audio`?`audio`:void 0,answerTtsLanguage:!e.writeMode&&e.answerPresentationType===`audio`?e.answerTtsLanguage:void 0}));this.addingProposals=!0;let i=!1;try{i=(await M.lessons.confirmFlashcards(e,t,r)).audioGenerationFailed??!1}catch(e){n(e),l(()=>{e instanceof k?this.aiError=e.status===429?`Trop de requêtes. Veuillez patienter avant de réessayer.`:e.message:this.aiError=e instanceof Error?e.message:`Erreur lors de l'ajout des cartes`});return}finally{l(()=>{this.addingProposals=!1})}let a=i?`Cartes ajoutées. La génération audio a échoué pour certaines cartes â réessayez depuis l'édition.`:null;try{let t=await M.lessons.get(e);l(()=>{Q.getOrCreate(t),this.clearAiState(),this.error=a})}catch(e){n(e),l(()=>{this.clearAiState(),this.aiError=`Cartes ajoutées. Erreur de rechargement â actualisez la page pour voir vos cartes.`})}}async cancelAiJob(){let e=this.aiJobId,t=this.lesson?.id,r=this.aiProposals.length>0;if(this.clearAiState(),!(!e||!t||!r))try{if((await M.lessons.cancelFlashcardJob(t,e)).alreadyConfirmed){let e=await M.lessons.get(t);l(()=>Q.getOrCreate(e))}}catch(r){n(r,{extra:{jobId:e,lessonId:t}})}}clearAiState(){this.aiShowForm=!1,this.aiInstructions=``,this.aiFileSelected=!1,this.aiGenerating=!1,this.aiStep=null,this.aiJobId=null,this.aiProposals=[],this.aiError=null,this.addMode=null}async importCsv(e){if(!this.lesson)return!1;let t=this.lesson.id;try{let r=await M.lessons.importCsv(t,e);this.root.tracker.trackLessonImported(`csv`,r.imported);try{let e=await M.lessons.get(t);l(()=>{Q.getOrCreate(e)})}catch(e){n(e)}return!0}catch(e){return n(e),l(()=>{this.error=e instanceof Error?e.message:`Erreur lors de l'import`}),!1}}openShareFromList(e){this.lesson=e,this.setShowShareDialog(!0)}reset(){this.lesson=null,this.formMirror=!1,this.loading=!1,this.error=null,this.editingQuestionId=null,this.editMirror=!1,this.pendingDeleteQuestionId=null,this.deleteError=null,this.pendingUnenroll=!1,this.shareLinks=[],this.members=[],this.shareError=null,this.showShareDialog=!1,this.copiedLinkId=null,this.editingTitle=!1,this.editTitleValue=``,this.titleError=null,this.savingQuestion=!1,this.createForm.reset(),this.editForm.reset(),this.clearAiState(),this.addingProposals=!1}},Yi,Xi,Zi,Qi,$i,ea,ta,na,ra,ia,aa,oa,sa;function ca(e,t,n,r,i,a){var o,s,c,l,u,d,f,p=Symbol.metadata||Symbol.for(`Symbol.metadata`),m=Object.defineProperty,h=Object.create,g=[h(null),h(null)],_=t.length;function v(t,n,r){return function(i,a){n&&(a=i,i=e);for(var o=0;o<t.length;o++)a=t[o].apply(i,r?[a]:[]);return r?a:i}}function y(e,t,n,r){if(typeof e!=`function`&&(r||e!==void 0))throw TypeError(t+` must `+(n||`be`)+` a function`+(r?``:` or undefined`));return e}function b(e,t,n,r,i,a,c,l,u,d,f){function p(e){if(!f(e))throw TypeError(`Attempted to access private element on non-instance`)}var h=[].concat(t[0]),_=t[3],b=!c,x=i===1,S=i===3,C=i===4,w=i===2;function T(t,n,r){return function(i,a){return n&&(a=i,i=e),r&&r(i),E[t].call(i,a)}}if(!b){var E={},D=[],O=S?`get`:C||x?`set`:`value`;if(u?(d||x?E={get:da(function(){return _(this)},r,`get`),set:function(e){t[4](this,e)}}:E[O]=_,d||da(E[O],r,w?``:O)):d||(E=Object.getOwnPropertyDescriptor(e,r)),!d&&!u){if((s=g[+l][r])&&(s^i)!==7)throw Error(`Decorating two elements with the same name (`+E[O].name+`) is not supported yet`);g[+l][r]=i<3?1:i}}for(var k=e,A=h.length-1;A>=0;A-=n?2:1){var j=y(h[A],`A decorator`,`be`,!0),M=n?h[A-1]:void 0,N={},P={kind:[`field`,`accessor`,`method`,`getter`,`setter`,`class`][i],name:r,metadata:o,addInitializer:function(e,t){if(e.v)throw TypeError(`attempted to call addInitializer after decoration was finished`);y(t,`An initializer`,`be`,!0),a.push(t)}.bind(null,N)};if(b)s=j.call(M,k,P),N.v=1,y(s,`class decorators`,`return`)&&(k=s);else if(P.static=l,P.private=u,s=P.access={has:u?f.bind():function(e){return r in e}},C||(s.get=u?w?function(e){return p(e),E.value}:T(`get`,0,p):function(e){return e[r]}),w||S||(s.set=u?T(`set`,0,p):function(e,t){e[r]=t}),k=j.call(M,x?{get:E.get,set:E.set}:E[O],P),N.v=1,x){if(typeof k==`object`&&k)(s=y(k.get,`accessor.get`))&&(E.get=s),(s=y(k.set,`accessor.set`))&&(E.set=s),(s=y(k.init,`accessor.init`))&&D.unshift(s);else if(k!==void 0)throw TypeError(`accessor decorators must return an object with get, set, or init properties or undefined`)}else y(k,(d?`field`:`method`)+` decorators`,`return`)&&(d?D.unshift(k):E[O]=k)}return i<2&&c.push(v(D,l,1),v(a,l,0)),d||b||(u?x?c.splice(-1,0,T(`get`,l),T(`set`,l)):c.push(w?E[O]:y.call.bind(E[O])):m(e,r,E)),k}function x(e){return m(e,p,{configurable:!0,enumerable:!0,value:o})}return a!==void 0&&(o=a[p]),o=h(o??null),u=[],d=function(e){e&&u.push(v(e))},f=function(t,r){for(var a=0;a<n.length;a++){var o=n[a],s=o[1],d=7&s;if((8&s)==t&&!d==r){var f=o[2],p=!!o[3],m=16&s;b(t?e:e.prototype,o,m,p?`#`+f:la(f),d,d<2?[]:t?l||=[]:c||=[],u,!!t,p,r,t&&p?function(t){return fa(t)===e}:i)}}},f(8,0),f(0,0),f(8,1),f(0,1),d(c),d(l),s=u,_||x(e),{e:s,get c(){var n=[];return _&&[x(e=b(e,[t],r,e.name,5,n)),v(n,1)]}}}function la(e){var t=ua(e,`string`);return typeof t==`symbol`?t:t+``}function ua(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}
3function da(e,t,n){typeof t==`symbol`&&(t=(t=t.description)?`[`+t+`]`:``);try{Object.defineProperty(e,`name`,{configurable:!0,value:n?n+` `+t:t})}catch{}return e}function fa(e){if(Object(e)!==e)throw TypeError(`right-hand side of 'in' should be an object, got `+(e===null?`null`:typeof e));return e}var pa=3e4,ma=class{static{[Xi,Zi,Qi,$i,ea,ta,na,ra,ia,aa,oa,sa,Yi]=ca(this,[],[[u,1,`lessons`],[u,1,`loading`],[u,1,`error`],[u,1,`newTitle`],[u,1,`pendingDeleteId`],[u,1,`tick`],[o,2,`startAutoRefresh`],[o,2,`incrementTick`],[s,3,`ownedLessons`],[s,3,`enrolledLessons`],[s,3,`totalDueCount`],[s,3,`activeLessons`],[s,3,`mutedLessons`],[s,3,`activeOwnedLessons`],[s,3,`activeEnrolledLessons`],[o,2,`setNewTitle`],[o,2,`fetchLessons`],[o,2,`createLesson`],[o,2,`setPendingDeleteId`],[o,2,`toggleMute`],[o,2,`confirmDelete`]]).e}#e=(Yi(this),Xi(this,[]));get lessons(){return this.#e}set lessons(e){this.#e=e}#t=(Zi(this),Qi(this,!1));get loading(){return this.#t}set loading(e){this.#t=e}#n=($i(this),ea(this,null));get error(){return this.#n}set error(e){this.#n=e}#r=(ta(this),na(this,``));get newTitle(){return this.#r}set newTitle(e){this.#r=e}#i=(ra(this),ia(this,null));get pendingDeleteId(){return this.#i}set pendingDeleteId(e){this.#i=e}#a=(aa(this),oa(this,0));get tick(){return this.#a}set tick(e){this.#a=e}refreshInterval=(sa(this),null);constructor(e){this.root=e}startAutoRefresh(){this.stopAutoRefresh(),this.refreshInterval=setInterval(()=>{this.incrementTick();let e=Date.now();c(()=>this.lessons.some(t=>t.nextDue&&new Date(t.nextDue).getTime()<=e))&&this.fetchLessons()},pa)}stopAutoRefresh(){this.refreshInterval!==null&&(clearInterval(this.refreshInterval),this.refreshInterval=null)}incrementTick(){this.tick++}get ownedLessons(){return this.lessons.filter(e=>e.accessLevel===`owner`)}get enrolledLessons(){return this.lessons.filter(e=>e.accessLevel!==`owner`)}get totalDueCount(){return this.activeLessons.reduce((e,t)=>e+t.dueCount,0)}get activeLessons(){return this.lessons.filter(e=>!e.isMuted)}get mutedLessons(){return this.lessons.filter(e=>e.isMuted)}get activeOwnedLessons(){return this.activeLessons.filter(e=>e.accessLevel===`owner`)}get activeEnrolledLessons(){return this.activeLessons.filter(e=>e.accessLevel!==`owner`)}setNewTitle(e){this.newTitle=e}async fetchLessons(){this.loading=!0,this.error=null;try{let e=await M.lessons.list();l(()=>{this.lessons=e.map(e=>Q.getOrCreate(e))})}catch(e){l(()=>{this.error=e instanceof Error?e.message:`Erreur de chargement`})}finally{l(()=>{this.loading=!1})}}async createLesson(){let e=this.newTitle.trim();if(!e)return this.error=`Le titre est obligatoire.`,null;this.error=null;try{let t=await M.lessons.create({title:e});return l(()=>{this.lessons.unshift(Q.getOrCreate(t)),this.newTitle=``,this.root.tracker.trackLessonCreated(0,`flashcard`)}),t.id}catch(e){return l(()=>{this.error=e instanceof Error?e.message:`Erreur de création`}),null}}setPendingDeleteId(e){this.pendingDeleteId=e}async toggleMute(e,t){let r=this.lessons.find(t=>t.id===e);if(r)try{let{mutedAt:n}=await M.lessons.setMuted(e,t);r.update({...r.raw,mutedAt:n})}catch(r){n(r,{extra:{lessonId:e,muted:t}}),l(()=>{this.error=r instanceof Error?r.message:`Erreur de mise en pause`})}}async confirmDelete(){if(!this.pendingDeleteId)return;let e=this.pendingDeleteId;try{await M.lessons.delete(e),l(()=>{this.lessons=this.lessons.filter(t=>t.id!==e)})}catch(e){l(()=>{this.error=e instanceof Error?e.message:`Erreur de suppression`})}finally{l(()=>{this.pendingDeleteId=null})}}},ha,ga,_a,va,ya,ba,xa,Sa,Ca,wa,Ta,Ea,Da,Oa,ka;function Aa(e,t,n,r,i,a){var o,s,c,l,u,d,f,p=Symbol.metadata||Symbol.for(`Symbol.metadata`),m=Object.defineProperty,h=Object.create,g=[h(null),h(null)],_=t.length;function v(t,n,r){return function(i,a){n&&(a=i,i=e);for(var o=0;o<t.length;o++)a=t[o].apply(i,r?[a]:[]);return r?a:i}}function y(e,t,n,r){if(typeof e!=`function`&&(r||e!==void 0))throw TypeError(t+` must `+(n||`be`)+` a function`+(r?``:` or undefined`));return e}function b(e,t,n,r,i,a,c,l,u,d,f){function p(e){if(!f(e))throw TypeError(`Attempted to access private element on non-instance`)}var h=[].concat(t[0]),_=t[3],b=!c,x=i===1,S=i===3,C=i===4,w=i===2;function T(t,n,r){return function(i,a){return n&&(a=i,i=e),r&&r(i),E[t].call(i,a)}}if(!b){var E={},D=[],O=S?`get`:C||x?`set`:`value`;if(u?(d||x?E={get:Na(function(){return _(this)},r,`get`),set:function(e){t[4](this,e)}}:E[O]=_,d||Na(E[O],r,w?``:O)):d||(E=Object.getOwnPropertyDescriptor(e,r)),!d&&!u){if((s=g[+l][r])&&(s^i)!==7)throw Error(`Decorating two elements with the same name (`+E[O].name+`) is not supported yet`);g[+l][r]=i<3?1:i}}for(var k=e,A=h.length-1;A>=0;A-=n?2:1){var j=y(h[A],`A decorator`,`be`,!0),M=n?h[A-1]:void 0,N={},P={kind:[`field`,`accessor`,`method`,`getter`,`setter`,`class`][i],name:r,metadata:o,addInitializer:function(e,t){if(e.v)throw TypeError(`attempted to call addInitializer after decoration was finished`);y(t,`An initializer`,`be`,!0),a.push(t)}.bind(null,N)};if(b)s=j.call(M,k,P),N.v=1,y(s,`class decorators`,`return`)&&(k=s);else if(P.static=l,P.private=u,s=P.access={has:u?f.bind():function(e){return r in e}},C||(s.get=u?w?function(e){return p(e),E.value}:T(`get`,0,p):function(e){return e[r]}),w||S||(s.set=u?T(`set`,0,p):function(e,t){e[r]=t}),k=j.call(M,x?{get:E.get,set:E.set}:E[O],P),N.v=1,x){if(typeof k==`object`&&k)(s=y(k.get,`accessor.get`))&&(E.get=s),(s=y(k.set,`accessor.set`))&&(E.set=s),(s=y(k.init,`accessor.init`))&&D.unshift(s);else if(k!==void 0)throw TypeError(`accessor decorators must return an object with get, set, or init properties or undefined`)}else y(k,(d?`field`:`method`)+` decorators`,`return`)&&(d?D.unshift(k):E[O]=k)}return i<2&&c.push(v(D,l,1),v(a,l,0)),d||b||(u?x?c.splice(-1,0,T(`get`,l),T(`set`,l)):c.push(w?E[O]:y.call.bind(E[O])):m(e,r,E)),k}function x(e){return m(e,p,{configurable:!0,enumerable:!0,value:o})}return a!==void 0&&(o=a[p]),o=h(o??null),u=[],d=function(e){e&&u.push(v(e))},f=function(t,r){for(var a=0;a<n.length;a++){var o=n[a],s=o[1],d=7&s;if((8&s)==t&&!d==r){var f=o[2],p=!!o[3],m=16&s;b(t?e:e.prototype,o,m,p?`#`+f:ja(f),d,d<2?[]:t?l||=[]:c||=[],u,!!t,p,r,t&&p?function(t){return Pa(t)===e}:i)}}},f(8,0),f(0,0),f(8,1),f(0,1),d(c),d(l),s=u,_||x(e),{e:s,get c(){var n=[];return _&&[x(e=b(e,[t],r,e.name,5,n)),v(n,1)]}}}function ja(e){var t=Ma(e,`string`);return typeof t==`symbol`?t:t+``}function Ma(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Na(e,t,n){typeof t==`symbol`&&(t=(t=t.description)?`[`+t+`]`:``);try{Object.defineProperty(e,`name`,{configurable:!0,value:n?n+` `+t:t})}catch{}return e}function Pa(e){if(Object(e)!==e)throw TypeError(`right-hand side of 'in' should be an object, got `+(e===null?`null`:typeof e));return e}var Fa=`memoire_revision_count`,Ia=336*60*60*1e3,La=3,Ra=5e3,za=class{static{[ga,_a,va,ya,ba,xa,Sa,Ca,wa,Ta,Ea,Da,Oa,ka,ha]=Aa(this,[],[[u,1,`notificationsEnabled`],[u,1,`loading`],[u,1,`browserPermission`],[u,1,`promptDismissedAt`],[u,1,`enableError`],[u,1,`toggling`],[u,1,`resubscribeDismissed`],[o,2,`load`],[o,2,`toggle`],[o,2,`enable`],[s,3,`isResubscribePrompt`],[s,3,`shouldShowNotificationPrompt`],[o,2,`incrementRevisionCount`],[o,2,`resetSessionFlag`],[o,2,`dismissPrompt`],[o,2,`activateNotifications`],[o,2,`dismissResubscribePrompt`],[o,2,`disable`]]).e}#e=(ha(this),ga(this,!1));get notificationsEnabled(){return this.#e}set notificationsEnabled(e){this.#e=e}#t=(_a(this),va(this,!0));get loading(){return this.#t}set loading(e){this.#t=e}#n=(ya(this),ba(this,`default`));get browserPermission(){return this.#n}set browserPermission(e){this.#n=e}#r=(xa(this),Sa(this,null));get promptDismissedAt(){return this.#r}set promptDismissedAt(e){this.#r=e}#i=(Ca(this),wa(this,null));get enableError(){return this.#i}set enableError(e){this.#i=e}#a=(Ta(this),Ea(this,!1));get toggling(){return this.#a}set toggling(e){this.#a=e}#o=(Da(this),Oa(this,!1));get resubscribeDismissed(){return this.#o}set resubscribeDismissed(e){this.#o=e}sessionCounted=(ka(this),!1);constructor(e){this.root=e}async load(){this.loading=!0,this.browserPermission=typeof Notification<`u`?Notification.permission:`denied`;let e=!1,t=this.browserPermission;try{let t=await fetch(`/api/push/notification-state`);if(t.ok){let n=await t.json();l(()=>{this.notificationsEnabled=n.enabled,this.promptDismissedAt=n.promptDismissedAt?new Date(n.promptDismissedAt):null,e=n.enabled})}}catch(e){n(e)}finally{l(()=>{this.loading=!1})}
3e&&t===`granted`&&await this.ensurePushSubscription()}async toggle(){this.toggling=!0;try{this.notificationsEnabled?await this.disable():await this.enable()}finally{l(()=>{this.toggling=!1})}}async enable(){if(!(typeof Notification>`u`)){if(this.enableError=null,Notification.permission===`default`){let e=await Notification.requestPermission();if(l(()=>{this.browserPermission=e}),e===`denied`){d.error(`Notifications bloquées. Autorisez-les dans les paramètres de votre navigateur.`);return}if(e!==`granted`)return}else if(Notification.permission===`denied`){d.error(`Notifications bloquées. Autorisez-les dans les paramètres de votre navigateur.`);return}try{if(!(`serviceWorker`in navigator))throw Error(`Les notifications push ne sont pas supportées par ce navigateur`);let e=await Promise.race([navigator.serviceWorker.ready,new Promise((e,t)=>setTimeout(()=>t(Error(`Service worker indisponible`)),Ra))]),t=await fetch(`/api/push/vapid-key`);if(!t.ok)throw Error(`Impossible de récupérer la clé push`);let{key:n}=await t.json(),r=(await e.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:n})).toJSON();if(!(await fetch(`/api/push/subscribe`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({endpoint:r.endpoint,keys:r.keys})})).ok)throw Error(`Impossible d'enregistrer l'abonnement`);let i=Intl.DateTimeFormat().resolvedOptions().timeZone;if(!(await fetch(`/api/push/notification-state`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({enabled:!0,timezone:i})})).ok)throw Error(`Impossible d'activer les notifications`);l(()=>{this.notificationsEnabled=!0}),d.success(`Notifications activées !`)}catch(e){let t=e instanceof Error?e.message:`Erreur lors de l'activation des notifications`;l(()=>{this.enableError=t}),d.error(t)}}}get isResubscribePrompt(){return this.notificationsEnabled&&this.browserPermission===`default`}get shouldShowNotificationPrompt(){return this.loading?!1:this.isResubscribePrompt&&!this.resubscribeDismissed?!0:!(this.notificationsEnabled||typeof Notification<`u`&&Notification.permission===`denied`||Number(localStorage.getItem(Fa)??`0`)<La||this.promptDismissedAt&&Date.now()-this.promptDismissedAt.getTime()<Ia)}incrementRevisionCount(){if(this.sessionCounted)return;this.sessionCounted=!0;let e=Number(localStorage.getItem(Fa)??`0`);localStorage.setItem(Fa,String(e+1))}resetSessionFlag(){this.sessionCounted=!1}async dismissPrompt(){l(()=>{this.promptDismissedAt=new Date});try{let e=await fetch(`/api/push/prompt-dismissed`,{method:`POST`});if(!e.ok)throw Error(`prompt-dismissed returned ${e.status}`)}catch(e){n(e)}}async activateNotifications(){this.toggling=!0;try{await this.enable()}finally{l(()=>{this.toggling=!1})}}dismissResubscribePrompt(){this.resubscribeDismissed=!0}async ensurePushSubscription(){try{if(!(`serviceWorker`in navigator))return;let e=await Promise.race([navigator.serviceWorker.ready,new Promise((e,t)=>setTimeout(()=>t(Error(`Service worker indisponible`)),Ra))]);await e.pushManager.getSubscription()||await this.subscribePushOnBrowser(e)}catch(e){n(e)}}async subscribePushOnBrowser(e){let t=await fetch(`/api/push/vapid-key`);if(!t.ok)throw Error(`VAPID key fetch failed: ${t.status}`);let{key:n}=await t.json(),r=(await e.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:n})).toJSON(),i=await fetch(`/api/push/subscribe`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({endpoint:r.endpoint,keys:r.keys})});if(!i.ok)throw Error(`Push subscribe POST failed: ${i.status}`)}async disable(){try{let e=await(await Promise.race([navigator.serviceWorker.ready,new Promise((e,t)=>setTimeout(()=>t(Error(`Service worker indisponible`)),Ra))])).pushManager.getSubscription();if(e){if(!(await fetch(`/api/push/subscribe`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({endpoint:e.endpoint})})).ok)throw Error(`Impossible de supprimer l'abonnement`);await e.unsubscribe()}if(!(await fetch(`/api/push/notification-state`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({enabled:!1})})).ok)throw Error(`Impossible de désactiver les notifications`);l(()=>{this.notificationsEnabled=!1}),d.success(`Notifications désactivées`)}catch(e){n(e);let t=e instanceof Error?e.message:`Erreur lors de la désactivation des notifications`;d.error(t)}}},Ba,Va,Ha,Ua,Wa,Ga,Ka,qa,Ja,Ya,Xa,Za,Qa,$a,eo,to,no,ro,io,ao,oo,so,co,lo,uo,fo,po,mo,ho,go,_o,vo,yo,bo,xo,So,Co,wo,To,Eo,Do,Oo,ko;function Ao(e,t,n,r,i,a){var o,s,c,l,u,d,f,p=Symbol.metadata||Symbol.for(`Symbol.metadata`),m=Object.defineProperty,h=Object.create,g=[h(null),h(null)],_=t.length;function v(t,n,r){return function(i,a){n&&(a=i,i=e);for(var o=0;o<t.length;o++)a=t[o].apply(i,r?[a]:[]);return r?a:i}}function y(e,t,n,r){if(typeof e!=`function`&&(r||e!==void 0))throw TypeError(t+` must `+(n||`be`)+` a function`+(r?``:` or undefined`));return e}function b(e,t,n,r,i,a,c,l,u,d,f){function p(e){if(!f(e))throw TypeError(`Attempted to access private element on non-instance`)}var h=[].concat(t[0]),_=t[3],b=!c,x=i===1,S=i===3,C=i===4,w=i===2;function T(t,n,r){return function(i,a){return n&&(a=i,i=e),r&&r(i),E[t].call(i,a)}}if(!b){var E={},D=[],O=S?`get`:C||x?`set`:`value`;if(u?(d||x?E={get:No(function(){return _(this)},r,`get`),set:function(e){t[4](this,e)}}:E[O]=_,d||No(E[O],r,w?``:O)):d||(E=Object.getOwnPropertyDescriptor(e,r)),!d&&!u){if((s=g[+l][r])&&(s^i)!==7)throw Error(`Decorating two elements with the same name (`+E[O].name+`) is not supported yet`);g[+l][r]=i<3?1:i}}for(var k=e,A=h.length-1;A>=0;A-=n?2:1){var j=y(h[A],`A decorator`,`be`,!0),M=n?h[A-1]:void 0,N={},P={kind:[`field`,`accessor`,`method`,`getter`,`setter`,`class`][i],name:r,metadata:o,addInitializer:function(e,t){if(e.v)throw TypeError(`attempted to call addInitializer after decoration was finished`);y(t,`An initializer`,`be`,!0),a.push(t)}.bind(null,N)};if(b)s=j.call(M,k,P),N.v=1,y(s,`class decorators`,`return`)&&(k=s);else if(P.static=l,P.private=u,s=P.access={has:u?f.bind():function(e){return r in e}},C||(s.get=u?w?function(e){return p(e),E.value}:T(`get`,0,p):function(e){return e[r]}),w||S||(s.set=u?T(`set`,0,p):function(e,t){e[r]=t}),k=j.call(M,x?{get:E.get,set:E.set}:E[O],P),N.v=1,x){if(typeof k==`object`&&k)(s=y(k.get,`accessor.get`))&&(E.get=s),(s=y(k.set,`accessor.set`))&&(E.set=s),(s=y(k.init,`accessor.init`))&&D.unshift(s);else if(k!==void 0)throw TypeError(`accessor decorators must return an object with get, set, or init properties or undefined`)}else y(k,(d?`field`:`method`)+` decorators`,`return`)&&(d?D.unshift(k):E[O]=k)}return i<2&&c.push(v(D,l,1),v(a,l,0)),d||b||(u?x?c.splice(-1,0,T(`get`,l),T(`set`,l)):c.push(w?E[O]:y.call.bind(E[O])):m(e,r,E)),k}function x(e){return m(e,p,{configurable:!0,enumerable:!0,value:o})}return a!==void 0&&(o=a[p]),o=h(o??null),u=[],d=function(e){e&&u.push(v(e))},f=function(t,r){for(var a=0;a<n.length;a++){var o=n[a],s=o[1],d=7&s;if((8&s)==t&&!d==r){var f=o[2],p=!!o[3],m=16&s;b(t?e:e.prototype,o,m,p?`#`+f:jo(f),d,d<2?[]:t?l||=[]:c||=[],u,!!t,p,r,t&&p?function(t){return Po(t)===e}:i)}}},f(8,0),f(0,0),f(8,1),f(0,1),d(c),d(l),s=u,_||x(e),{e:s,get c(){var n=[];return _&&[x(e=b(e,[t],r,e.name,5,n)),v(n,1)]}}}function jo(e){var t=Mo(e,`string`);return typeof t==`symbol`?t:t+``}function Mo(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function No(e,t,n){typeof t==`symbol`&&(t=(t=t.description)?`[`+t+`]`:``);try{Object.defineProperty(e,`name`,{configurable:!0,value:n?n+` `+t:t})}catch{}return e}function Po(e){if(Object(e)!==e)throw TypeError(`right-hand side of 'in' should be an object, got `+(e===null?`null`:typeof e));return e}function $(e){let t=[...e];for(let e=t.length-1;e>0;e--){let n=Math.floor(Math.random()*(e+1));[t[e],t[n]]=[t[n],t[e]]}return t}var Fo=class{static{[Va,Ha,Ua,Wa,Ga,Ka,qa,Ja,Ya,Xa,Za,Qa,$a,eo,to,no,ro,io,ao,oo,so,co,lo,uo,fo,po,mo,ho,go,_o,vo,yo,bo,xo,So,Co,wo,To,Eo,Do,Oo,ko,Ba]=Ao(this,[],[[u,1,`dueCards`],[u,1,`currentIndex`],[u,1,`showAnswer`],[u,1,`loading`],[u,1,`error`],[u,1,`ratingCounts`],[u,1,`lesson`],[u,1,`failedCards`],[u,1,`multiLesson`],[u,1,`reviewedCardIds`],[u,1,`preserveSession`],[u,1,`writeInput`],[u,1,`skipped`],[u,1,`submittingRating`],[u,1,`editingQuestionId`],[u,1,`editIsMirror`],[u,1,`savingQuestion`],[u,1,`selectedMCQOptionIndex`],[u,1,`shuffledMCQOptions`],[u,1,`sessionStartedAt`],[s,3,`canWrite`],[s,3,`sessionTotal`],[s,3,`currentCard`],[s,3,`isFinished`],[s,3,`isEmpty`],[o,2,`fetchIfNeeded`],[o,2,`fetchDueCards`],[o,2,`fetchAllDueCards`],[o,2,`revealAnswer`],[o,0,`setWriteInput`],[o,2,`submitWriteAnswer`],[o,2,`skipWriteCard`],[o,2,`submitRating`],[o,2,`startNextRoundIfNeeded`],[o,2,`setPreserveSession`],[s,3,`isMCQCorrect`],[o,2,`selectMCQOption`],[o,2,`refreshShuffledOptions`],[s,3,`editAudioUrl`],[s,3,`editAnswerAudioUrl`],[o,2,`startEditingQuestion`],[o,2,`cancelEditing`],[o,2,`saveQuestion`],[o,2,`restart`],[o,2,`reset`],[o,2,`resetSession`]]).e}#e=(Ba(this),Va(this,[]));get dueCards(){return this.#e}set dueCards(e){this.#e=e}#t=(Ha(this),Ua(this,0));get currentIndex(){return this.#t}set currentIndex(e){this.#t=e}#n=(Wa(this),Ga(this,!1));get showAnswer(){return this.#n}set showAnswer(e){this.#n=e}#r=(Ka(this),qa(this,!1));get loading(){return this.#r}set loading(e){this.#r=e}#i=(Ja(this),Ya(this,null));get error(){return this.#i}set error(e){this.#i=e}#a=(Xa(this),Za(this,{1:0,2:0,3:0,4:0}));get ratingCounts(){return this.#a}set ratingCounts(e){this.#a=e}#o=(Qa(this),$a(this,null));get lesson(){return this.#o}set lesson(e){this.#o=e}#s=(eo(this),to(this,[]));get failedCards(){return this.#s}set failedCards(e){this.#s=e}#c=(no(this),ro(this,!1));get multiLesson(){return this.#c}set multiLesson(e){this.#c=e}#l=(io(this),ao(this,new Set));get reviewedCardIds(){return this.#l}set reviewedCardIds(e){this.#l=e}#u=(oo(this),so(this,!1));get preserveSession(){return this.#u}set preserveSession(e){this.#u=e}#d=(co(this),lo(this,``));get writeInput(){return this.#d}set writeInput(e){this.#d=e}#f=(uo(this),fo(this,!1));get skipped(){return this.#f}set skipped(e){this.#f=e}
3#p=(po(this),mo(this,!1));get submittingRating(){return this.#p}set submittingRating(e){this.#p=e}#m=(ho(this),go(this,null));get editingQuestionId(){return this.#m}set editingQuestionId(e){this.#m=e}#h=(_o(this),vo(this,!1));get editIsMirror(){return this.#h}set editIsMirror(e){this.#h=e}#g=(yo(this),bo(this,!1));get savingQuestion(){return this.#g}set savingQuestion(e){this.#g=e}#_=(xo(this),So(this,null));get selectedMCQOptionIndex(){return this.#_}set selectedMCQOptionIndex(e){this.#_=e}#v=(Co(this),wo(this,null));get shuffledMCQOptions(){return this.#v}set shuffledMCQOptions(e){this.#v=e}#y=(To(this),Eo(this,null));get sessionStartedAt(){return this.#y}set sessionStartedAt(e){this.#y=e}editForm=(Do(this),new Lr);constructor(e){this.root=e,ko(this)}get canWrite(){return this.lesson?.canWrite??!1}get sessionTotal(){return this.reviewedCardIds.size}get currentCard(){return this.dueCards[this.currentIndex]??null}get isFinished(){return this.dueCards.length>0&&this.currentIndex>=this.dueCards.length&&this.failedCards.length===0}get isEmpty(){let e=this.multiLesson||this.lesson!==null;return!this.loading&&e&&this.dueCards.length===0}fetchIfNeeded(e,t=!1){this.dueCards.length>0||(e?this.fetchDueCards(e,t):this.fetchAllDueCards())}async fetchDueCards(e,t=!1){if(!this.loading){this.loading=!0,this.error=null;try{let[n,r]=await Promise.all([M.lessons.dueCards(e,t),M.lessons.get(e)]);l(()=>{this.dueCards=$(n.map(e=>Z.getOrCreate(e))),this.lesson=Q.getOrCreate(r),this.refreshShuffledOptions(),this.sessionStartedAt=Date.now(),this.root.tracker.trackReviewSessionStarted(`lesson`,this.dueCards.length)})}catch(e){n(e),l(()=>{this.error=e instanceof Error?e.message:`Erreur inconnue`})}finally{l(()=>{this.loading=!1})}}}async fetchAllDueCards(){if(!this.loading){this.loading=!0,this.error=null,this.multiLesson=!0;try{let e=await M.dueCards.list();l(()=>{this.dueCards=$(e.map(e=>Z.getOrCreate(e))),this.refreshShuffledOptions(),this.sessionStartedAt=Date.now(),this.root.tracker.trackReviewSessionStarted(`home`,this.dueCards.length)})}catch(e){n(e),l(()=>{this.error=e instanceof Error?e.message:`Erreur inconnue`})}finally{l(()=>{this.loading=!1})}}}revealAnswer(){this.showAnswer=!0}setWriteInput=Oo(this,e=>{this.writeInput=e.target.value});submitWriteAnswer(){this.writeInput.trim()&&(this.showAnswer=!0)}skipWriteCard(){this.writeInput=``,this.skipped=!0,this.showAnswer=!0}async submitRating(e){if(!this.showAnswer||this.submittingRating)return;let t=this.currentCard;if(t){this.submittingRating=!0;try{await M.reviews.submit(t.id,e),l(()=>{if(this.ratingCounts={...this.ratingCounts,[e]:this.ratingCounts[e]+1},this.reviewedCardIds=new Set([...this.reviewedCardIds,t.id]),e===1&&(this.failedCards=[...this.failedCards,t]),this.writeInput=``,this.skipped=!1,this.currentIndex++,this.showAnswer=!1,this.startNextRoundIfNeeded(),this.refreshShuffledOptions(),this.root.tracker.trackCardReviewed(e,t.type??`flashcard`),this.isFinished&&this.sessionStartedAt!==null){let e=Math.round((Date.now()-this.sessionStartedAt)/1e3);this.root.tracker.trackReviewSessionCompleted(this.reviewedCardIds.size,e),this.sessionStartedAt=null}})}catch(e){n(e),l(()=>{this.error=e instanceof Error?e.message:`Erreur inconnue`})}finally{l(()=>{this.submittingRating=!1})}}}startNextRoundIfNeeded(){this.currentIndex>=this.dueCards.length&&this.failedCards.length>0&&(this.dueCards=$(this.failedCards),this.failedCards=[],this.currentIndex=0)}setPreserveSession(e){this.preserveSession=e}get isMCQCorrect(){if(this.selectedMCQOptionIndex===null||!this.shuffledMCQOptions)return null;let e=this.shuffledMCQOptions[this.selectedMCQOptionIndex];return e?e.value===this.currentCard?.answer:null}selectMCQOption(e){this.selectedMCQOptionIndex=e,this.showAnswer=!0}refreshShuffledOptions(){let e=this.currentCard;e?.answerType===`mcq`?e.mcqOptions?this.shuffledMCQOptions=$(e.mcqOptions):(t(`[RevisionStore.refreshShuffledOptions] MCQ card has no mcqOptions`,{level:`warning`,extra:{cardId:e.id}}),this.shuffledMCQOptions=null):this.shuffledMCQOptions=null,this.selectedMCQOptionIndex=null}get editAudioUrl(){return this.editingQuestionId?this.dueCards.find(e=>e.id===this.editingQuestionId)?.audioUrl??null:null}get editAnswerAudioUrl(){return this.editingQuestionId?this.dueCards.find(e=>e.id===this.editingQuestionId)?.answerAudioUrl??null:null}startEditingQuestion(){let e=this.currentCard;if(!e)return;this.editingQuestionId=e.id,this.editIsMirror=e.isMirror,this.editForm.content=e.content,this.editForm.answer=e.answer,this.editForm.writeMode=e.answerType===`write`,this.editForm.loadFromQuestion(e);let t=Rn({content:e.content,answer:e.answer,presentationType:e.presentationType,answerPresentationType:e.answerPresentationType},{caller:`RevisionStore.startEditingQuestion`,cardId:e.id});this.editForm.presentationType=t.presentationType,this.editForm.answerPresentationType=t.answerPresentationType,this.editForm.ttsLanguage=e.ttsLanguage??`fr`,this.editForm.answerTtsLanguage=e.answerTtsLanguage??`fr`,this.editForm.error=t.warning}cancelEditing(){this.editingQuestionId=null,this.editIsMirror=!1,this.editForm.reset()}async saveQuestion(){if(!this.editingQuestionId)return;
3let e=this.editForm.content.trim(),r=this.editForm.answer.trim();if(!e||!r){this.editForm.error=`La question et la réponse sont obligatoires.`;return}let i=this.dueCards.find(e=>e.id===this.editingQuestionId);if(!i){t(`[RevisionStore.saveQuestion] Card not found: ${this.editingQuestionId}`),this.editForm.error=`Cette carte n'est plus disponible. Annulez et réessayez.`;return}let a=i.lessonId??this.lesson?.id;if(!a){t(`[RevisionStore.saveQuestion] No lessonId for card: ${this.editingQuestionId}`),this.editForm.error=`Impossible de déterminer la leçon. Annulez et réessayez.`;return}let o=i.isMirror&&i.mirrorOfId?i.mirrorOfId:i.id,s=i.isMirror?r:e,c=i.isMirror?e:r;this.savingQuestion=!0;try{let e=await M.lessons.updateQuestion(a,o,{content:s,answer:c,...this.editForm.toApiPayload()});l(()=>{Z.getOrCreate(e);let n=i.isMirror?i:this.dueCards.find(e=>e.mirrorOfId===i.id)??null;if(n){let e=c,r=s,i=n.raw.answer;i?.type===`mcq`?t(`saveQuestion: mirror card has MCQ answer type â skipping local update`,{level:`warning`,extra:{mirrorCardId:n.id}}):n.update({...n.raw,question:{format:`text`,value:e},answer:{format:`text`,type:i?.type??`show`,value:r}})}this.editingQuestionId=null,this.editForm.reset(),e.audioGenerationFailed&&(this.error=`Carte sauvegardée. La génération audio a échoué.`)})}catch(e){n(e),l(()=>{this.editForm.error=e instanceof Error?e.message:`Erreur de mise à jour`})}finally{l(()=>{this.savingQuestion=!1})}}async restart(){let e=this.lesson?.id,r=this.multiLesson;try{this.resetSession(),r?await this.fetchAllDueCards():e?await this.fetchDueCards(e,!0):(t(`[RevisionStore.restart] Cannot restart: no lesson ID and not multi-lesson mode`),l(()=>{this.error=`Impossible de relancer la révision. Retournez à la liste des leçons.`}))}catch(e){n(e),l(()=>{this.error=e instanceof Error?e.message:`Erreur inconnue`})}}reset(){if(this.cancelEditing(),this.preserveSession){this.preserveSession=!1;return}this.writeInput=``,this.skipped=!1,this.submittingRating=!1,this.dueCards=[],this.currentIndex=0,this.showAnswer=!1,this.loading=!1,this.error=null,this.ratingCounts={1:0,2:0,3:0,4:0},this.lesson=null,this.failedCards=[],this.multiLesson=!1,this.reviewedCardIds=new Set,this.shuffledMCQOptions=null,this.selectedMCQOptionIndex=null,this.sessionStartedAt=null}resetSession(){this.cancelEditing(),this.writeInput=``,this.skipped=!1,this.submittingRating=!1,this.dueCards=[],this.currentIndex=0,this.showAnswer=!1,this.loading=!1,this.error=null,this.ratingCounts={1:0,2:0,3:0,4:0},this.failedCards=[],this.reviewedCardIds=new Set,this.shuffledMCQOptions=null,this.selectedMCQOptionIndex=null,this.sessionStartedAt=null}},Io=class{track(e,t){try{window.umami?.track(e,t)}catch(r){n(r,{extra:{event:e,data:t}})}}trackLessonCreated(e,t){this.track(`lesson_created`,{question_count:e,type:t})}trackLessonStarted(){this.track(`lesson_started`)}trackLessonLeft(){this.track(`lesson_left`)}trackLessonImported(e,t){this.track(`lesson_imported`,{format:e,count:t})}trackReviewSessionStarted(e,t){this.track(`review_session_started`,{source:e,card_count:t})}trackCardReviewed(e,t){this.track(`card_reviewed`,{rating:e,card_type:t})}trackReviewSessionCompleted(e,t){this.track(`review_session_completed`,{card_count:e,duration_s:t})}trackShareLinkCreated(e){this.track(`share_link_created`,{access_level:e})}trackUserRegistered(){this.track(`user_registered`)}identifyUser(e){try{window.umami?.identify(e)}catch(t){n(t,{extra:{userId:e}})}}},Lo=class{tracker;auth;lessons;lessonDetail;revision;join;preferences;constructor(){this.tracker=new Io,this.auth=new yn(this),this.lessons=new ma(this),this.lessonDetail=new Ji(this),this.revision=new Fo(this),this.join=new Pn(this),this.preferences=new za(this)}},Ro=i(),zo=(0,E.createContext)(null);function Bo({children:e}){let[t]=(0,E.useState)(()=>new Lo);return(0,Ro.jsx)(zo.Provider,{value:t,children:e})}function Vo(){let e=(0,E.useContext)(zo);if(!e)throw Error(`useStore must be used within StoreProvider`);return e}function Ho(...e){return f(a(e))}export{In as a,Ln as i,Bo as n,Ft as o,Vo as r,M as s,Ho as 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.