@okhay-p/mivra 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -410,4 +410,4 @@ l0,-`+(t+144)+`c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,
410
410
  `}),n.push(e[r]);return t&&e.length>0&&n.push({type:`text`,value:`
411
411
  `}),n}function ZY(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function QY(e,t){let n=KY(e,t),r=n.one(e,void 0),i=UY(n),a=Array.isArray(r)?{type:`root`,children:r}:r||{type:`root`,children:[]};return i&&(`children`in a,a.children.push({type:`text`,value:`
412
412
  `},i)),a}function $Y(e,t){return e&&`run`in e?async function(n,r){let i=QY(n,{file:r,...t});await e.run(i,r)}:function(n,r){return QY(n,{file:r,...e||t})}}function eX(e){if(e)throw e}var tX=o(((e,t)=>{var n=Object.prototype.hasOwnProperty,r=Object.prototype.toString,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=function(e){return typeof Array.isArray==`function`?Array.isArray(e):r.call(e)===`[object Array]`},s=function(e){if(!e||r.call(e)!==`[object Object]`)return!1;var t=n.call(e,`constructor`),i=e.constructor&&e.constructor.prototype&&n.call(e.constructor.prototype,`isPrototypeOf`);if(e.constructor&&!t&&!i)return!1;for(var a in e);return a===void 0||n.call(e,a)},c=function(e,t){i&&t.name===`__proto__`?i(e,t.name,{enumerable:!0,configurable:!0,value:t.newValue,writable:!0}):e[t.name]=t.newValue},l=function(e,t){if(t===`__proto__`){if(!n.call(e,t))return;if(a)return a(e,t).value}return e[t]};t.exports=function e(){var t,n,r,i,a,u,d=arguments[0],f=1,p=arguments.length,m=!1;for(typeof d==`boolean`&&(m=d,d=arguments[1]||{},f=2),(d==null||typeof d!=`object`&&typeof d!=`function`)&&(d={});f<p;++f)if(t=arguments[f],t!=null)for(n in t)r=l(d,n),i=l(t,n),d!==i&&(m&&i&&(s(i)||(a=o(i)))?(a?(a=!1,u=r&&o(r)?r:[]):u=r&&s(r)?r:{},c(d,{name:n,newValue:e(m,u,i)})):i!==void 0&&c(d,{name:n,newValue:i}));return d}}));function nX(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function rX(){let e=[],t={run:n,use:r};return t;function n(...t){let n=-1,r=t.pop();if(typeof r!=`function`)throw TypeError(`Expected function as last argument, not `+r);i(null,...t);function i(a,...o){let s=e[++n],c=-1;if(a)r(a);else{for(;++c<t.length;)(o[c]===null||o[c]===void 0)&&(o[c]=t[c]);t=o,s?iX(s,i)(...o):r(null,...o)}}}function r(n){if(typeof n!=`function`)throw TypeError("Expected `middelware` to be a function, not "+n);return e.push(n),t}}function iX(e,t){let n;return r;function r(...t){let r=e.length>t.length,o;r&&t.push(i);try{o=e.apply(this,t)}catch(e){let t=e;if(r&&n)throw t;return i(t)}r||(o&&o.then&&typeof o.then==`function`?o.then(a,i):o instanceof Error?i(o):a(o))}function i(e,...r){n||(n=!0,t(e,...r))}function a(e){i(null,e)}}var aX={basename:oX,dirname:sX,extname:cX,join:lX,sep:`/`};function oX(e,t){if(t!==void 0&&typeof t!=`string`)throw TypeError(`"ext" argument must be a string`);fX(e);let n=0,r=-1,i=e.length,a;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else r<0&&(a=!0,r=i+1);return r<0?``:e.slice(n,r)}if(t===e)return``;let o=-1,s=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else o<0&&(a=!0,o=i+1),s>-1&&(e.codePointAt(i)===t.codePointAt(s--)?s<0&&(r=i):(s=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function sX(e){if(fX(e),e.length===0)return`.`;let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||=!0;return t<0?e.codePointAt(0)===47?`/`:`.`:t===1&&e.codePointAt(0)===47?`//`:e.slice(0,t)}function cX(e){fX(e);let t=e.length,n=-1,r=0,i=-1,a=0,o;for(;t--;){let s=e.codePointAt(t);if(s===47){if(o){r=t+1;break}}else n<0&&(o=!0,n=t+1),s===46?i<0?i=t:a!==1&&(a=1):i>-1&&(a=-1)}return i<0||n<0||a===0||a===1&&i===n-1&&i===r+1?``:e.slice(i,n)}function lX(...e){let t=-1,n;for(;++t<e.length;)fX(e[t]),e[t]&&(n=n===void 0?e[t]:n+`/`+e[t]);return n===void 0?`.`:uX(n)}function uX(e){fX(e);let t=e.codePointAt(0)===47,n=dX(e,!t);return n.length===0&&!t&&(n=`.`),n.length>0&&e.codePointAt(e.length-1)===47&&(n+=`/`),t?`/`+n:n}function dX(e,t){let n=``,r=0,i=-1,a=0,o=-1,s,c;for(;++o<=e.length;){if(o<e.length)s=e.codePointAt(o);else if(s===47)break;else s=47;if(s===47){if(i!==o-1&&a!==1){if(i!==o-1&&a===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(c=n.lastIndexOf(`/`),c!==n.length-1){c<0?(n=``,r=0):(n=n.slice(0,c),r=n.length-1-n.lastIndexOf(`/`)),i=o,a=0;continue}}else if(n.length>0){n=``,r=0,i=o,a=0;continue}}t&&(n=n.length>0?n+`/..`:`..`,r=2)}else n.length>0?n+=`/`+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1}i=o,a=0}else s===46&&a>-1?a++:a=-1}return n}function fX(e){if(typeof e!=`string`)throw TypeError(`Path must be a string. Received `+JSON.stringify(e))}var pX={cwd:mX};function mX(){return`/`}function hX(e){return!!(typeof e==`object`&&e&&`href`in e&&e.href&&`protocol`in e&&e.protocol&&e.auth===void 0)}function gX(e){if(typeof e==`string`)e=new URL(e);else if(!hX(e)){let t=TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code=`ERR_INVALID_ARG_TYPE`,t}if(e.protocol!==`file:`){let e=TypeError(`The URL must be of scheme file`);throw e.code=`ERR_INVALID_URL_SCHEME`,e}return _X(e)}function _X(e){if(e.hostname!==``){let e=TypeError(`File URL host must be "localhost" or empty on darwin`);throw e.code=`ERR_INVALID_FILE_URL_HOST`,e}let t=e.pathname,n=-1;for(;++n<t.length;)if(t.codePointAt(n)===37&&t.codePointAt(n+1)===50){let e=t.codePointAt(n+2);if(e===70||e===102){let e=TypeError(`File URL path must not include encoded / characters`);throw e.code=`ERR_INVALID_FILE_URL_PATH`,e}}return decodeURIComponent(t)}var vX=[`history`,`path`,`basename`,`stem`,`extname`,`dirname`],yX=class{constructor(e){let t;t=e?hX(e)?{path:e}:typeof e==`string`||CX(e)?{value:e}:e:{},this.cwd=`cwd`in t?``:pX.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let n=-1;for(;++n<vX.length;){let e=vX[n];e in t&&t[e]!==void 0&&t[e]!==null&&(this[e]=e===`history`?[...t[e]]:t[e])}let r;for(r in t)vX.includes(r)||(this[r]=t[r])}get basename(){return typeof this.path==`string`?aX.basename(this.path):void 0}set basename(e){xX(e,`basename`),bX(e,`basename`),this.path=aX.join(this.dirname||``,e)}get dirname(){return typeof this.path==`string`?aX.dirname(this.path):void 0}set dirname(e){SX(this.basename,`dirname`),this.path=aX.join(e||``,this.basename)}get extname(){return typeof this.path==`string`?aX.extname(this.path):void 0}set extname(e){if(bX(e,`extname`),SX(this.dirname,`extname`),e){if(e.codePointAt(0)!==46)throw Error("`extname` must start with `.`");if(e.includes(`.`,1))throw Error("`extname` cannot contain multiple dots")}this.path=aX.join(this.dirname,this.stem+(e||``))}get path(){return this.history[this.history.length-1]}set path(e){hX(e)&&(e=gX(e)),xX(e,`path`),this.path!==e&&this.history.push(e)}get stem(){return typeof this.path==`string`?aX.basename(this.path,this.extname):void 0}set stem(e){xX(e,`stem`),bX(e,`stem`),this.path=aX.join(this.dirname||``,e+(this.extname||``))}fail(e,t,n){let r=this.message(e,t,n);throw r.fatal=!0,r}info(e,t,n){let r=this.message(e,t,n);return r.fatal=void 0,r}message(e,t,n){let r=new pF(e,t,n);return this.path&&(r.name=this.path+`:`+r.name,r.file=this.path),r.fatal=!1,this.messages.push(r),r}toString(e){return this.value===void 0?``:typeof this.value==`string`?this.value:new TextDecoder(e||void 0).decode(this.value)}};function bX(e,t){if(e&&e.includes(aX.sep))throw Error("`"+t+"` cannot be a path: did not expect `"+aX.sep+"`")}function xX(e,t){if(!e)throw Error("`"+t+"` cannot be empty")}function SX(e,t){if(!e)throw Error("Setting `"+t+"` requires `path` to be set too")}function CX(e){return!!(e&&typeof e==`object`&&`byteLength`in e&&`byteOffset`in e)}var wX=(function(e){let t=this.constructor.prototype,n=t[e],r=function(){return n.apply(r,arguments)};return Object.setPrototypeOf(r,t),r}),TX=l(tX(),1),EX={}.hasOwnProperty,DX=new class e extends wX{constructor(){super(`copy`),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=rX()}copy(){let t=new e,n=-1;for(;++n<this.attachers.length;){let e=this.attachers[n];t.use(...e)}return t.data((0,TX.default)(!0,{},this.namespace)),t}data(e,t){return typeof e==`string`?arguments.length===2?(AX(`data`,this.frozen),this.namespace[e]=t,this):EX.call(this.namespace,e)&&this.namespace[e]||void 0:e?(AX(`data`,this.frozen),this.namespace=e,this):this.namespace}freeze(){if(this.frozen)return this;let e=this;for(;++this.freezeIndex<this.attachers.length;){let[t,...n]=this.attachers[this.freezeIndex];if(n[0]===!1)continue;n[0]===!0&&(n[0]=void 0);let r=t.call(e,...n);typeof r==`function`&&this.transformers.use(r)}return this.frozen=!0,this.freezeIndex=1/0,this}parse(e){this.freeze();let t=NX(e),n=this.parser||this.Parser;return OX(`parse`,n),n(String(t),t)}process(e,t){let n=this;return this.freeze(),OX(`process`,this.parser||this.Parser),kX(`process`,this.compiler||this.Compiler),t?r(void 0,t):new Promise(r);function r(r,i){let a=NX(e),o=n.parse(a);n.run(o,a,function(e,t,r){if(e||!t||!r)return s(e);let i=t,a=n.stringify(i,r);FX(a)?r.value=a:r.result=a,s(e,r)});function s(e,n){e||!n?i(e):r?r(n):t(void 0,n)}}}processSync(e){let t=!1,n;return this.freeze(),OX(`processSync`,this.parser||this.Parser),kX(`processSync`,this.compiler||this.Compiler),this.process(e,r),MX(`processSync`,`process`,t),n;function r(e,r){t=!0,eX(e),n=r}}run(e,t,n){jX(e),this.freeze();let r=this.transformers;return!n&&typeof t==`function`&&(n=t,t=void 0),n?i(void 0,n):new Promise(i);function i(i,a){let o=NX(t);r.run(e,o,s);function s(t,r,o){let s=r||e;t?a(t):i?i(s):n(void 0,s,o)}}}runSync(e,t){let n=!1,r;return this.run(e,t,i),MX(`runSync`,`run`,n),r;function i(e,t){eX(e),r=t,n=!0}}stringify(e,t){this.freeze();let n=NX(t),r=this.compiler||this.Compiler;return kX(`stringify`,r),jX(e),r(e,n)}use(e,...t){let n=this.attachers,r=this.namespace;if(AX(`use`,this.frozen),e!=null){if(typeof e==`function`)s(e,t);else if(typeof e==`object`)Array.isArray(e)?o(e):a(e);else throw TypeError("Expected usable value, not `"+e+"`")}return this;function i(e){if(typeof e==`function`)s(e,[]);else if(typeof e==`object`){if(Array.isArray(e)){let[t,...n]=e;s(t,n)}else a(e)}else throw TypeError("Expected usable value, not `"+e+"`")}function a(e){if(!(`plugins`in e)&&!(`settings`in e))throw Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");o(e.plugins),e.settings&&(r.settings=(0,TX.default)(!0,r.settings,e.settings))}function o(e){let t=-1;if(e!=null){if(Array.isArray(e))for(;++t<e.length;){let n=e[t];i(n)}else throw TypeError("Expected a list of plugins, not `"+e+"`")}}function s(e,t){let r=-1,i=-1;for(;++r<n.length;)if(n[r][0]===e){i=r;break}if(i===-1)n.push([e,...t]);else if(t.length>0){let[r,...a]=t,o=n[i][1];nX(o)&&nX(r)&&(r=(0,TX.default)(!0,o,r)),n[i]=[e,r,...a]}}}}().freeze();function OX(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `parser`")}function kX(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `compiler`")}function AX(e,t){if(t)throw Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function jX(e){if(!nX(e)||typeof e.type!=`string`)throw TypeError("Expected node, got `"+e+"`")}function MX(e,t,n){if(!n)throw Error("`"+e+"` finished async. Use `"+t+"` instead")}function NX(e){return PX(e)?e:new yX(e)}function PX(e){return!!(e&&typeof e==`object`&&`message`in e&&`messages`in e)}function FX(e){return typeof e==`string`||IX(e)}function IX(e){return!!(e&&typeof e==`object`&&`byteLength`in e&&`byteOffset`in e)}var LX=36,RX=92,zX=96,BX=32,VX=e=>e!==null&&e<-2,HX=e=>e===null||e<0||e===BX,UX=e=>e!==null&&e>=48&&e<=57;function WX(e,t,n){let r=0,i=0,a,o=null,s=t=>t===LX?(e.consume(t),r+=1,s):r>2||r===1&&HX(t)?n(t):(e.exit(`mathTextSequence`),c(t)),c=t=>{if(t===null||t===zX)return n(t);if(t===LX)return a=e.enter(`mathTextSequence`),i=0,d(t);if(t===BX||VX(t)){let n=t===BX?`space`:`lineEnding`;return e.enter(n),e.consume(t),e.exit(n),o=t,c}return e.enter(`mathTextData`),l(t)},l=t=>t===null||t===zX||t===BX||t===LX||VX(t)?(e.exit(`mathTextData`),c(t)):(e.consume(t),o=t,t===RX?u:l),u=t=>t!==LX&&t!==RX?l(t):(e.consume(t),o=t,l),d=s=>s===LX?(e.consume(s),i+=1,d):i===r?UX(s)||r===1&&HX(o)?n(s):(e.exit(`mathTextSequence`),e.exit(`mathText`),t(s)):r===1?n(s):(a.type=`mathTextData`,l(s));return t=>(e.enter(`mathText`),e.enter(`mathTextSequence`),s(t))}function GX(){for(let e of this.data().micromarkExtensions??[]){let t=e.text?.[LX];t&&(e.text[LX]={...t,tokenize:WX})}}var KX=/^(?:[ \t>]|[-*+][ \t]|\d{1,9}[.)][ \t])*\[(?:[^[\]\\]|\\[\s\S]){1,999}\]:/m,qX=/^ {0,3}<[a-z/!?]/im,JX=/^ {0,3}(?:[-*+]|\d{1,9}[.)])(?:[ \t]|$)/,YX=/^ {0,3}(`{3,}(?=[^`]*$)|~{3,})/,XX=/^ {0,3}(\$\$+)[^$]*$/,ZX=/^ {0,3}(`+|~+|\$+)[ \t]*$/;function*QX(e){let t=0;for(let n of e.matchAll(/\r\n?|\n/g)){let r=n.index+n[0].length;yield{text:e.slice(t,n.index),start:t,next:r},t=r}t<e.length&&(yield{text:e.slice(t),start:t,next:e.length})}function $X(e){if(KX.test(e)||qX.test(e))return[e];let t=[],n=0,r,i=!1,a=!1,o=!1,s=!1;for(let{text:c,start:l}of QX(e)){if(r&&i&&c.trim()!==``&&!/^\s/.test(c))break;if(r)r(c)&&(r=void 0);else if(c.trim()===``)a=!0;else{let u=JX.test(c);a&&!/^\s/.test(c)&&!(u&&o)&&!(s&&tZ.test(c))&&(t.push(e.slice(n,l)),n=l,o=!1),o||=u,s=/^\s/.test(c),a=!1,r=fZ(c),i=o&&/^\s/.test(c)}}return t.push(e.slice(n)),t}function eZ(e){let t=0;for(;e[t]===`$`;)t++;if(t<2||e.indexOf(`$`,t)!==-1)return;let n=t,r=e.length;for(;n<r&&(e[n]===` `||e[n]===` `);)n++;for(;r>n&&(e[r-1]===` `||e[r-1]===` `);)r--;return{fence:e.slice(0,t),rest:e.slice(n,r)}}var tZ=/^ {0,3}(?:>|(?:[-*+]|\d{1,9}[.)])(?:[ \t]|$))/,nZ=/^ {0,3}(?:#{1,6}(?:[ \t]|$)|(?:(?:\*[ \t]*){3,}|(?:-[ \t]*){3,}|(?:_[ \t]*){3,})$)/;function rZ(e){let t=iZ(e),n=new Map,r=0;for(let[i,a]of[...QX(e)].entries())n.set(r,a.start),r+=t[i].length;n.set(r,e.length);let i=$X(t.join(``));r=0;let a=[];for(let t of i){let o=n.get(r),s=n.get(r+=t.length);if(o===void 0||s===void 0)return i.map(e=>({text:e,source:e}));a.push({text:t,source:e.slice(o,s)})}return a}function iZ(e){let t=[...QX(e)].map(t=>({text:t.text,ending:e.slice(t.start+t.text.length,t.next)})),n=t.map(e=>e.text+e.ending);if(!e.includes(`$$`)||qX.test(e)||e.startsWith(``))return n;let r,i,a=sZ;for(let[e,{text:o,ending:s}]of t.entries()){let t=s||`
413
- `;if(r)r(o)&&(r=void 0);else if(i){let r=ZX.exec(o)?.[1];if(r?.[0]===`$`&&r.length>=i)i=void 0;else{let r=dZ(o,i);if(r&&uZ(lZ(a,o.slice(0,r.start)))){let a=o.slice(0,r.start),c=oZ(o.slice(r.end).trim());n[e]=(a.trim()?a+t:``)+o.slice(r.start,r.end)+(c?t+c:``)+s,i=void 0}else a=lZ(a,o)}}else if(/^[ \t]/.test(o)){if(YX.test(o.trimStart())||XX.test(o.trimStart()))break}else if(YX.test(o))r=fZ(o);else{let r=eZ(o);if(r){let{fence:o,rest:c}=r;i=o.length,a=c?lZ(sZ,c):sZ,c&&(n[e]=o+t+c+s)}}}return n}var aZ=new RegExp([tZ.source,nZ.source,"^(?:`{3}|~{3}|\\$\\$)",`^\\[(?:[^\\]\\\\]|\\\\.)*(?:\\]:|$)`,`^<(?![a-z][a-z\\d+.-]{1,31}:[^\\s<>]*>|[^\\s<>@]+@[^\\s<>]+>)[a-z/!?]`].join(`|`));function oZ(e){return aZ.test(e)?/^\d/.test(e)?e.replace(/^(\d+)/,`$1\\`):`\\${e}`:e}var sZ={depth:0,uncertain:!1},cZ=new Set([`verb`,`def`,`gdef`,`edef`,`xdef`,`let`,`futurelet`,`newcommand`,`renewcommand`,`providecommand`,`catcode`,`csname`,`expandafter`,`noexpand`,`includegraphics`]);function lZ(e,t){if(e.uncertain)return e;let n=e.depth;for(let e=0;e<t.length;e++){let r=t[e];if(r===`\\`){let r=e+1;for(;r<t.length&&/[a-zA-Z@]/.test(t[r]);)r++;let i=t.slice(e+1,r);if(cZ.has(i)||i.includes(`@`)||i.startsWith(`if`))return{depth:n,uncertain:!0};e=r>e+1?r-1:e+1}else if(r===`%`)return{depth:n,uncertain:!0};else r===`{`?n++:r===`}`&&(n=Math.max(0,n-1))}return{depth:n,uncertain:!1}}var uZ=e=>!e.uncertain&&e.depth===0;function dZ(e,t){for(let n=0;n<e.length;n++){if(e[n]===`\\`){n++;continue}if(e[n]!==`$`)continue;let r=n;for(;e[r]===`$`;)r++;if(r-n>=t)return{start:n,end:r};n=r-1}}function fZ(e){let t=YX.exec(e)?.[1]??XX.exec(e)?.[1];if(t)return e=>{let n=ZX.exec(e)?.[1];return n!==void 0&&n[0]===t[0]&&n.length>=t.length}}var pZ=5e4,mZ=32,hZ=200,gZ=/\[{33}/,_Z=/\*{1001}|_{1001}|~{1001}/,vZ=/^[ \t]*(?:(?:>|[-*+](?=[ \t])|\d{1,9}[.)](?=[ \t]))[ \t]*)+/,yZ=/>|[-*+]|\d{1,9}[.)]/g;function bZ(e){let t=[],n=0,r=0,i,a=(a,o)=>{let s=e.slice(n,a);t.push(e[n]===`$`?{kind:`math`,text:s}:{kind:`code`,text:s,code:e.slice(r,o)}),n=a,i=void 0};for(let o of QX(e))if(i)i(o.text)&&a(o.next,o.start);else{let a=/^\s/.test(o.text)?void 0:fZ(o.text);a&&(o.start>n&&t.push({kind:`prose`,text:e.slice(n,o.start)}),n=o.start,r=o.next,i=a)}return i?a(e.length,e.length):n<e.length&&t.push({kind:`prose`,text:e.slice(n)}),t}function xZ(e){return e.length>pZ?!0:KX.test(e)||qX.test(e)?SZ(e):bZ(e).some(e=>e.kind===`prose`&&SZ(e.text))}function SZ(e){for(let{text:t}of QX(e)){if(gZ.test(t)||_Z.test(t)||/^[ \t]*/.exec(t)[0].length>hZ)return!0;let e=vZ.exec(t)?.[0];if(e&&(e.match(yZ)?.length??0)>mZ)return!0}return!1}var CZ=[`http:`,`https:`,`mailto:`];function wZ(e){try{let t=new URL(e);return CZ.includes(t.protocol)?t.href:``}catch{return``}}function TZ(){return(e,t)=>{let n=String(t.value),r=e=>{for(let t of e.children??[]){let e=t.position?.start.offset;t.type===`inlineMath`&&e!==void 0&&n.startsWith(`$$`,e)&&(t.data={...t.data,hProperties:{...t.data?.hProperties,className:[`language-math`,`math-display`]}}),r(t)}};r(e)}}var EZ=[Zq,lJ,GX,TZ],DZ=DX().use(JJ).use(EZ).use($Y,{allowDangerousHtml:!0}),OZ=1e3,kZ=new Map;function AZ(e,t){let n=`${t?`D`:`I`}${e}`,r=kZ.get(n);if(r!==void 0)return kZ.delete(n),kZ.set(n,r),r;let i;try{i=tH.renderToString(e,{displayMode:t,trust:!1,strict:`ignore`,throwOnError:!1,errorColor:`var(--destructive)`})}catch{return}return kZ.set(n,i),kZ.size>OZ&&kZ.delete(kZ.keys().next().value),i}var jZ=e=>{let t=e.properties.className;return Array.isArray(t)?t.map(String):[]},MZ=e=>e?.type===`element`&&e.tagName===`code`&&jZ(e).includes(`language-math`),NZ=e=>e.children.map(e=>e.type===`text`?e.value:``).join(``);function PZ(e){let t=DZ.runSync(DZ.parse(e),e),n=[],r=(e,t)=>{let r=AZ(e,t);return r===void 0?{type:`element`,tagName:`span`,properties:{className:[`katex-error`]},children:[{type:`text`,value:e}]}:(n.push(r),{type:`element`,tagName:`span`,properties:{className:[`math-text-formula`],dataFormula:n.length-1},children:[]})};return iW(t,(e,t,n)=>{if(delete e.position,n&&t!==void 0){if(e.type===`raw`)n.children[t]={type:`text`,value:e.value};else if(e.type===`element`){if(e.tagName===`pre`&&e.children.length===1&&MZ(e.children[0]))return n.children[t]=r(NZ(e.children[0]).replace(/\n$/,``),!0),`skip`;if(MZ(e))return n.children[t]=r(NZ(e),jZ(e).includes(`math-display`)),`skip`;for(let[t,n]of Object.entries(WF))Object.hasOwn(e.properties,t)&&(n===null||n.includes(e.tagName))&&(e.properties[t]=wZ(String(e.properties[t]??``)))}}}),{tree:t,formulas:n}}var FZ=8e3,IZ=250,LZ=2e3,RZ=/\\(?:[gex]?def|let|futurelet|(?:re|provide)?newcommand|(?:re)?newenvironment)(?![a-zA-Z])/,zZ=300,BZ=class{entries=new Map;get(e){let t=this.entries.get(e);return t!==void 0&&(this.entries.delete(e),this.entries.set(e,t)),t}set(e,t){this.entries.delete(e),this.entries.set(e,t),this.entries.size>zZ&&this.entries.delete(this.entries.keys().next().value)}};function VZ(e){try{return PZ(e)}catch{return`plain`}}function HZ(){let e=new BZ,t=t=>{let n=e.get(t);return n===void 0&&e.set(t,n=VZ(t)),n};return{peek:t,render:async e=>t(e),dispose(){}}}function UZ(e,t={}){let{timeoutMs:n=FZ,cancelGraceMs:r=IZ,syncLimit:i=LZ}=t,a=new BZ,o=[],s,c,l=1,u=()=>{if(s)return s;let t=e();return t.onmessage=e=>{s===t&&c?.job.id===e.data.id&&f(e.data.block??`plain`)},t.onerror=()=>{s===t&&(c?m(`plain`):p())},s=t},d=(e,t)=>{e.signal.removeEventListener(`abort`,e.onAbort),e.resolve(e.signal.aborted?void 0:t)},f=e=>{let t=c;c=void 0,clearTimeout(t.deadline),clearTimeout(t.grace),e!==void 0&&a.set(t.job.text,e),d(t.job,e),h()},p=()=>{s?.terminate(),s=void 0},m=e=>{p(),f(e)},h=()=>{for(;!c&&o.length>0;){let e=o.shift(),t=a.get(e.text);if(t!==void 0)d(e,t);else{c={job:e,deadline:setTimeout(()=>m(`plain`),n)};try{u().postMessage({id:e.id,text:e.text})}catch{m(`plain`)}}}};return{peek(e){let t=a.get(e);if(t!==void 0||e.length>i||RZ.test(e))return t;let n=VZ(e);return a.set(e,n),n},dispose(){for(let e of o.splice(0))d(e,void 0);c?m(void 0):p()},render(e,t){return t.aborted?Promise.resolve(void 0):new Promise(n=>{let i={id:l++,text:e,signal:t,resolve:n,onAbort:()=>{let e=o.indexOf(i);e>=0?(o.splice(e,1),d(i,void 0)):c?.job===i&&c.grace===void 0&&(c.grace=setTimeout(()=>m(void 0),r))}};t.addEventListener(`abort`,i.onAbort),o.push(i),h()})}}}var WZ=(0,v.memo)(function({source:e,display:t}){let n=AZ(e,t);return n===void 0?(0,j.jsx)(`span`,{className:`katex-error`,children:e}):(0,j.jsx)(`span`,{className:`math-text-formula`,dangerouslySetInnerHTML:{__html:n}})});function GZ({block:e}){return(0,v.useMemo)(()=>xF(e.tree,{Fragment:v.Fragment,jsx:j.jsx,jsxs:j.jsxs,components:{a:({href:e,children:t})=>e?(0,j.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:t}):(0,j.jsx)(`span`,{children:t}),span:t=>{let n=t[`data-formula`];return n===void 0?(0,j.jsx)(`span`,{className:t.className,children:t.children}):(0,j.jsx)(`span`,{className:`math-text-formula`,dangerouslySetInnerHTML:{__html:e.formulas[Number(n)]??``}})},img:({alt:e})=>e?(0,j.jsx)(`span`,{children:e}):null,table:e=>(0,j.jsx)(`div`,{className:`math-text-scroll`,children:(0,j.jsx)(`table`,{children:e.children})}),h1:`h4`,h2:`h4`,h3:`h5`,h4:`h6`,h5:`h6`},passKeys:!0,ignoreInvalidStyle:!0}),[e])}function KZ({text:e}){return bZ(e).map((e,t)=>e.kind===`code`?(0,j.jsx)(`pre`,{children:(0,j.jsx)(`code`,{children:e.code})},t):(0,j.jsx)(`p`,{className:`math-text-literal`,children:e.text},t))}var qZ=class extends v.Component{state={};componentDidCatch(){this.setState({failedText:this.props.text})}render(){return this.state.failedText===this.props.text?(0,j.jsx)(KZ,{text:this.props.text}):this.props.children}},JZ;function YZ(){return JZ??=typeof Worker>`u`?HZ():UZ(()=>new Worker(new URL(`/assets/render.worker-BAfybD27.js`,``+import.meta.url),{type:`module`,name:`mivra-render`})),JZ}var XZ=(0,v.createContext)(void 0);function ZZ(e){let t=(0,v.useContext)(XZ)??YZ(),n=e===void 0?void 0:t.peek(e),[r,i]=(0,v.useState)(),a=(0,v.useRef)(void 0);(0,v.useEffect)(()=>{if(e===void 0||n!==void 0)return;let r=new AbortController;return t.render(e,r.signal).then(t=>{t!==void 0&&i({text:e,result:t})}),()=>r.abort()},[t,e,n]);let o=n??(r&&r.text===e?r.result:void 0);return(0,v.useEffect)(()=>{o!==void 0&&(a.current=o)}),e===void 0?void 0:o??a.current}var QZ=(0,v.memo)(function({text:e,source:t}){let n=(0,v.useMemo)(()=>xZ(e),[e]),r=ZZ(n?void 0:e);return n||r===void 0||r===`plain`?(0,j.jsx)(KZ,{text:t}):(0,j.jsx)(qZ,{text:t,children:(0,j.jsx)(GZ,{block:r})})}),$Z=2e4;function eQ(e,t){let n=0,r=0;for(;r<e.length&&(r===0||n<t);)n+=e[r++].text.length;return r}function tQ({text:e,className:t}){let n=(0,v.useDeferredValue)(e),r=(0,v.useMemo)(()=>rZ(n),[n]),[i,a]=(0,v.useState)($Z),o=eQ(r,i);return(0,v.useEffect)(()=>{if(o>=r.length)return;let e=r.slice(0,o).reduce((e,t)=>e+t.text.length,0),t=setTimeout(()=>a(t=>Math.max(t,e)+$Z),0);return()=>clearTimeout(t)},[o,r]),(0,j.jsx)(`div`,{className:t,children:r.slice(0,o).map((e,t)=>(0,j.jsx)(QZ,{text:e.text,source:e.source},t))})}function nQ({text:e,className:t}){let n=(0,v.useMemo)(()=>lA(e),[e]);return(0,j.jsx)(`span`,{className:`${t} math-text-literal`,children:n.map((e,t)=>`formula`in e?(0,j.jsx)(WZ,{source:e.formula,display:!1},t):e.text)})}function rQ({text:e,mode:t=`block`,className:n}){let r=n?`math-text ${n}`:`math-text`;return t===`math`?(0,j.jsx)(nQ,{text:e,className:r}):(0,j.jsx)(tQ,{text:e,className:r})}function iQ({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`card`,className:A(`flex flex-col gap-6 rounded-xl border bg-card py-6 text-card-foreground shadow-sm`,e),...t})}function aQ({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`card-content`,className:A(`px-6`,e),...t})}var oQ=1500,sQ={active:`bg-secondary ring-2 ring-inset ring-foreground`,done:`bg-success/15 ring-1 ring-inset ring-success`,muted:`bg-muted text-muted-foreground`},cQ={current:`bg-foreground text-background`,other:`bg-sunken text-muted-foreground ring-1 ring-inset ring-border-strong`};function lQ(e){let t=e-1,[n,r]=(0,v.useState)(0),[i,a]=(0,v.useState)(!1);(0,v.useEffect)(()=>{if(!i)return;if(n>=t){a(!1);return}let e=setTimeout(()=>r(e=>Math.min(e+1,t)),oQ);return()=>clearTimeout(e)},[i,n,t]);let o=e=>{a(!1),r(Math.max(0,Math.min(e,t)))};return{index:n,last:t,playing:i,go:o,togglePlay:()=>{if(i)return a(!1);n>=t&&r(0),a(!0)},onKeyDown:e=>{if(e.key===`ArrowLeft`)o(n-1);else if(e.key===`ArrowRight`)o(n+1);else return;e.preventDefault()}}}function uQ({children:e,label:t=`Formula, scrolls sideways`,className:n}){let r=(0,v.useRef)(null),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(!1),c=()=>{r.current&&a(r.current.scrollWidth>r.current.clientWidth)};return(0,v.useLayoutEffect)(c),(0,v.useEffect)(()=>{let e=new ResizeObserver(c);return e.observe(r.current),document.fonts.ready.then(c),()=>e.disconnect()},[]),(0,j.jsx)(`span`,{ref:r,className:A(`step-scroll block min-w-0 overflow-x-auto overflow-y-hidden`,n),"data-testid":`step-scroll`,...i?{role:`group`,"aria-label":t}:{},tabIndex:i?0:o?-1:void 0,onFocus:()=>s(!0),onBlur:e=>s(document.activeElement===e.currentTarget),onKeyDown:e=>{(e.key===`ArrowLeft`||e.key===`ArrowRight`)&&e.stopPropagation()},children:e})}function dQ({children:e}){return(0,j.jsx)(uQ,{children:(0,j.jsx)(`span`,{"aria-hidden":`true`,children:e})})}function fQ({stepper:e,play:t=!1,children:n}){let{index:r,last:i,playing:a,go:o,togglePlay:s}=e;if(i<=0)return null;let c=`bg-card dark:bg-card border-border-strong dark:border-border-strong hover:bg-sunken dark:hover:bg-sunken hover:text-foreground aria-disabled:cursor-not-allowed aria-disabled:opacity-45`;return(0,j.jsxs)(`div`,{"data-slot":`artifact-footer`,className:`bg-sunken/55 flex flex-wrap items-center gap-x-4 gap-y-2.5 rounded-b-xl border-t px-3.5 py-2.5`,children:[(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,j.jsxs)(M,{type:`button`,variant:`outline`,size:`sm`,className:c,onClick:()=>o(r-1),"aria-disabled":r===0,children:[(0,j.jsx)(Zm,{}),`Prev`]}),t&&(0,j.jsxs)(M,{type:`button`,size:`sm`,className:`min-w-20`,onClick:s,children:[a?(0,j.jsx)(Tg,{className:`fill-current`}):(0,j.jsx)(jg,{className:`fill-current`}),a?`Pause`:`Play`]}),(0,j.jsxs)(M,{type:`button`,variant:`outline`,size:`sm`,className:c,onClick:()=>o(r+1),"aria-disabled":r===i,children:[`Next`,(0,j.jsx)($m,{})]}),n]}),(0,j.jsxs)(`div`,{className:`ml-auto flex min-w-0 max-w-full items-center gap-3`,children:[(0,j.jsx)(`span`,{className:`flex min-w-0 gap-[3px]`,"aria-hidden":`true`,"data-testid":`step-pips`,children:i<24&&Array.from({length:i+1},(e,t)=>(0,j.jsx)(`i`,{className:A(`h-[3px] w-3 min-w-[2px] shrink rounded-full`,t<r?`bg-muted-foreground`:t===r?`bg-foreground`:`bg-border-strong`)},t))}),(0,j.jsxs)(`span`,{className:`text-muted-foreground font-mono text-xs whitespace-nowrap`,"aria-hidden":`true`,"data-testid":`step-counter`,children:[`Step `,r+1,` of `,i+1]})]})]})}function pQ({className:e,...t}){return(0,j.jsx)(iQ,{"data-artifact-card":``,className:A(`border-border-strong shadow-paper gap-0 py-0 whitespace-normal`,e),...t})}function mQ({kind:e,kindId:t,aside:n,children:r}){return(0,j.jsxs)(`div`,{"data-slot":`artifact-header`,className:`flex min-w-0 flex-wrap items-baseline gap-x-3.5 gap-y-1 border-b px-4 py-3 sm:px-5`,children:[(0,j.jsx)(`span`,{id:t,className:`text-accent-foreground shrink-0 font-mono text-[0.6875rem] leading-snug font-medium tracking-[0.09em] uppercase`,children:e}),r,n&&(0,j.jsx)(`span`,{className:`text-muted-foreground ml-auto font-mono text-[0.6875rem] leading-snug tracking-[0.09em] uppercase`,children:n})]})}function hQ({id:e,text:t}){return(0,j.jsx)(`h3`,{className:`font-heading min-w-0 flex-[1_1_12rem] text-[1.0625rem] leading-snug font-medium`,children:(0,j.jsx)(uQ,{children:(0,j.jsx)(`span`,{id:e,children:(0,j.jsx)(rQ,{text:t,mode:`math`})})})})}function gQ({className:e,...t}){return(0,j.jsx)(aQ,{className:A(`flex flex-col gap-3 px-4 py-4 sm:px-5 sm:py-5`,e),...t})}function _Q({index:e}){return(0,j.jsx)(`span`,{"aria-hidden":`true`,className:`border-border-strong text-muted-foreground grid size-6 shrink-0 place-items-center rounded-[6px] border font-mono text-[0.72rem] font-medium`,"data-testid":`option-key`,children:e<26?String.fromCharCode(65+e):``})}function vQ({code:e,lines:t}){let n=_A(e.source),r=new Set(t),i=(0,v.useRef)(null),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(!1),l=()=>{i.current&&o(i.current.scrollWidth>i.current.clientWidth)};return(0,v.useLayoutEffect)(l),(0,v.useEffect)(()=>{let e=new ResizeObserver(l);return e.observe(i.current),document.fonts.ready.then(l),()=>e.disconnect()},[]),(0,j.jsxs)(`div`,{className:`flex min-w-0 flex-col rounded-md border`,"data-testid":`code-pane`,children:[(0,j.jsx)(`div`,{className:`text-muted-foreground border-b px-3 py-1 font-mono text-xs`,"aria-hidden":`true`,children:e.language}),(0,j.jsx)(`div`,{ref:i,role:`region`,"aria-label":`Code, ${e.language}${a?`, scrolls sideways`:``}`,className:`min-w-0 overflow-x-auto py-2`,"data-testid":`code-scroll`,tabIndex:a?0:s?-1:void 0,onFocus:()=>c(!0),onBlur:e=>c(document.activeElement===e.currentTarget),onKeyDown:e=>{a&&(e.key===`ArrowLeft`||e.key===`ArrowRight`)&&e.stopPropagation()},children:(0,j.jsx)(`pre`,{className:`w-max min-w-full font-mono text-xs leading-relaxed [tab-size:4]`,children:(0,j.jsx)(`code`,{children:n.map((e,t)=>{let n=r.has(t+1);return(0,j.jsxs)(`span`,{className:A(`flex border-l-2 pr-3`,n?`bg-muted border-foreground text-foreground`:`border-transparent`),"data-testid":`code-line`,"data-active":n||void 0,"aria-current":n?`true`:void 0,children:[(0,j.jsx)(`span`,{className:`text-muted-foreground w-9 shrink-0 pr-3 text-right select-none`,children:t+1}),(0,j.jsx)(`span`,{className:`whitespace-pre`,children:e||` `}),n&&(0,j.jsx)(`span`,{className:`sr-only`,children:` (current line)`})]},t)})})})})]})}var yQ={active:``,done:`, done`,muted:`, ruled out`};function bQ(e,t){let n=e.values;for(let r of e.steps.slice(0,t+1))r.values&&(n=r.values);let r=e.steps[t];return{values:n,explanation:r?.explanation??``,pointers:r?.pointers??[],ranges:r?.ranges??[],variables:r?.variables??[],lines:r?.lines??[]}}function xQ(e,t){return e.length===t.length?t.flatMap((t,n)=>t===e[n]?[]:[` Index ${n} is now ${String(t)}.`]).join(``):` The sequence is now ${t.map(String).join(`, `)}.`}function SQ({view:e}){let{spec:t}=e,n=lQ(t.steps.length),r=(0,v.useId)(),i=(0,v.useId)(),a=bQ(t,n.index),o=(0,v.useRef)({index:n.index,from:a.values});o.current.index!==n.index&&(o.current={index:n.index,from:bQ(t,o.current.index).values});let s=a.values.length,c=a.ranges.filter(e=>e.start<=e.end&&e.end<s),l=a.pointers.filter(e=>e.index<s),u=t.code?_A(t.code.source):[],d=a.lines.filter(e=>e>=1&&e<=u.length),f=e=>{let t=c.find(t=>t.start<=e&&e<=t.end);return t?t.tone??`active`:void 0},p=(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`p`,{className:`sr-only`,"data-testid":`trace-description`,children:[`Values: `,a.values.map((e,t)=>`index ${t}: ${String(e)}`).join(`, `)]}),(0,j.jsx)(uQ,{label:`Values, scrolls sideways`,className:`pb-1`,children:(0,j.jsxs)(`span`,{"aria-hidden":`true`,className:`inline-grid w-max gap-1 wrap-normal`,style:{gridTemplateColumns:`repeat(${s}, minmax(2.5rem, max-content))`},children:[c.map((e,t)=>(0,j.jsx)(`span`,{className:A(`min-h-5 rounded-sm px-1 text-center text-xs font-medium`,sQ[e.tone??`active`]),style:{gridColumn:`${e.start+1} / ${e.end+2}`,gridRow:t+1},"data-testid":`trace-range`,children:e.label??` `},`range-${t}`)),a.values.map((e,t)=>{let n=f(t);return(0,j.jsxs)(`span`,{className:A(`bg-card border-border-strong relative grid h-11 place-items-center rounded-md border px-2 font-mono text-[0.95rem]`,n&&sQ[n]),style:{gridColumn:t+1,gridRow:c.length+1},"data-testid":`trace-cell`,children:[String(e),(0,j.jsx)(`span`,{className:`text-muted-foreground absolute right-1 bottom-0 text-[0.6rem]`,children:t})]},`cell-${t}`)}),Array.from({length:s},(e,t)=>{let n=l.filter(e=>e.index===t).map(e=>e.name);return n.length?(0,j.jsxs)(`span`,{className:`text-foreground text-center font-mono text-xs font-medium`,style:{gridColumn:t+1,gridRow:c.length+2},"data-testid":`trace-pointer`,children:[`↑ `,n.join(`, `)]},`pointers-${t}`):null})]})}),a.variables.length>0&&(0,j.jsx)(`dl`,{className:`flex flex-wrap gap-2`,"aria-hidden":`true`,children:a.variables.map((e,t)=>(0,j.jsxs)(`div`,{className:`border-border-strong bg-card flex max-w-full min-w-0 gap-1.5 rounded-md border px-2 py-0.5 font-mono text-xs wrap-anywhere`,children:[(0,j.jsx)(`dt`,{className:`min-w-0`,children:e.name}),(0,j.jsxs)(`dd`,{className:`min-w-0`,children:[`= `,String(e.value)]})]},t))}),(0,j.jsxs)(`div`,{"aria-live":`polite`,"aria-atomic":`true`,"data-testid":`trace-status`,children:[(0,j.jsxs)(`span`,{className:`sr-only`,children:[`Step `,n.index+1,` of `,n.last+1,`.`,` `]}),(0,j.jsx)(uQ,{children:(0,j.jsx)(rQ,{text:a.explanation,mode:`math`})}),(0,j.jsxs)(`span`,{className:`sr-only`,children:[xQ(o.current.from,a.values),l.map(e=>` ${e.name} points to index ${e.index}, value ${String(a.values[e.index])}.`),c.map(e=>` ${e.label?`${e.label} covers`:`Highlighted:`} indices ${e.start} through ${e.end}${yQ[e.tone??`active`]}.`),a.variables.map(e=>` ${e.name} = ${String(e.value)}.`),d.map(e=>` Code line ${e}: ${u[e-1].trim()||`blank`}.`)]})]})]});return(0,j.jsxs)(pQ,{role:`region`,"aria-labelledby":`${r} ${i}`,tabIndex:0,onKeyDown:n.onKeyDown,children:[(0,j.jsx)(mQ,{kind:`Algorithm trace`,kindId:i,children:(0,j.jsx)(hQ,{id:r,text:t.title})}),(0,j.jsx)(gQ,{children:t.code?(0,j.jsx)(`div`,{className:`@container`,children:(0,j.jsxs)(`div`,{className:`grid gap-3 @xl:grid-cols-2`,children:[(0,j.jsx)(vQ,{code:t.code,lines:d}),(0,j.jsx)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:p})]})}):p}),(0,j.jsx)(fQ,{stepper:n,play:!0})]})}var CQ=200;function wQ({output:e}){let t=(0,v.useRef)(null),[n,r]=(0,v.useState)({x:!1,y:!1}),[i,a]=(0,v.useState)(!1),o=()=>{let e=t.current;if(!e)return;let n={x:e.scrollWidth>e.clientWidth,y:e.scrollHeight>e.clientHeight};r(e=>e.x===n.x&&e.y===n.y?e:n)};(0,v.useLayoutEffect)(o),(0,v.useEffect)(()=>{let e=new ResizeObserver(o);return e.observe(t.current),document.fonts.ready.then(o),()=>e.disconnect()},[]);let s=n.x||n.y;return(0,j.jsxs)(`div`,{className:`flex min-w-0 flex-col rounded-md border`,"data-testid":`walkthrough-output`,children:[(0,j.jsx)(`div`,{className:`text-muted-foreground border-b px-3 py-1 font-mono text-xs`,children:`Output`}),(0,j.jsx)(`div`,{ref:t,role:`region`,"aria-label":`Output${s?`, scrolls`:``}`,className:`max-h-72 min-w-0 overflow-auto px-3 py-2`,"data-testid":`output-scroll`,tabIndex:s?0:i?-1:void 0,onFocus:()=>a(!0),onBlur:e=>a(document.activeElement===e.currentTarget),onKeyDown:e=>{n.x&&(e.key===`ArrowLeft`||e.key===`ArrowRight`)&&e.stopPropagation()},children:e===``?(0,j.jsx)(`p`,{className:`text-muted-foreground text-xs italic`,children:`No output yet`}):(0,j.jsx)(`pre`,{className:`w-max min-w-full font-mono text-xs leading-relaxed whitespace-pre [tab-size:4]`,"data-testid":`output-text`,children:e})})]})}function TQ({view:e}){let{spec:t}=e,n=lQ(t.steps.length),r=(0,v.useId)(),i=(0,v.useId)(),a=t.steps[n.index],o=_A(t.code.source),s=(a.lines??[]).filter(e=>e>=1&&e<=o.length),c=a.output===``?0:_A(a.output).length;return(0,j.jsxs)(pQ,{role:`region`,"aria-labelledby":`${r} ${i}`,tabIndex:0,onKeyDown:n.onKeyDown,children:[(0,j.jsx)(mQ,{kind:`Illustrated walkthrough`,kindId:i,children:(0,j.jsx)(hQ,{id:r,text:t.title})}),(0,j.jsxs)(gQ,{children:[(0,j.jsx)(`div`,{className:`@container`,children:(0,j.jsxs)(`div`,{className:`grid gap-3 @xl:grid-cols-2`,children:[(0,j.jsx)(vQ,{code:t.code,lines:s}),(0,j.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,j.jsxs)(`section`,{className:`flex min-w-0 flex-col rounded-md border`,"aria-label":`Variables`,"data-testid":`walkthrough-variables`,children:[(0,j.jsx)(`div`,{className:`text-muted-foreground border-b px-3 py-1 font-mono text-xs`,"aria-hidden":`true`,children:`Variables`}),(0,j.jsx)(`div`,{className:`px-3 py-2`,children:a.variables.length===0?(0,j.jsx)(`p`,{className:`text-muted-foreground text-xs italic`,children:`No variables at this step`}):(0,j.jsx)(`dl`,{className:`flex flex-col gap-1 font-mono text-xs`,children:a.variables.map(e=>(0,j.jsxs)(`div`,{className:`flex min-w-0 gap-1.5 wrap-anywhere`,"data-testid":`walkthrough-variable`,children:[(0,j.jsx)(`dt`,{className:`min-w-0`,children:e.name}),(0,j.jsxs)(`dd`,{className:`min-w-0`,children:[`= `,String(e.value)]})]},e.name))})})]}),(0,j.jsx)(wQ,{output:a.output})]})]})}),(0,j.jsxs)(`div`,{"aria-live":`polite`,"aria-atomic":`true`,"data-testid":`walkthrough-status`,className:`flex flex-col gap-1`,children:[(0,j.jsxs)(`span`,{className:`sr-only`,children:[`Step `,n.index+1,` of `,n.last+1,`.`,` `]}),a.label&&(0,j.jsxs)(`span`,{className:`text-muted-foreground font-mono text-xs`,"data-testid":`walkthrough-label`,children:[a.label,(0,j.jsx)(`span`,{className:`sr-only`,children:`.`})]}),(0,j.jsx)(uQ,{children:(0,j.jsx)(rQ,{text:a.explanation,mode:`math`})}),(0,j.jsxs)(`span`,{className:`sr-only`,children:[s.map(e=>` Code line ${e}: ${o[e-1].trim()||`blank`}.`),a.variables.length===0?` No variables.`:a.variables.map(e=>` ${e.name} = ${String(e.value)}.`),a.output===``?` No output yet.`:a.output.length<=CQ?` Output: ${a.output}`:` Output: ${c} ${c===1?`line`:`lines`}, in the output pane.`]})]})]}),(0,j.jsx)(fQ,{stepper:n,play:!0})]})}function EQ(e){let t=+this._x.call(null,e),n=+this._y.call(null,e);return DQ(this.cover(t,n),t,n,e)}function DQ(e,t,n,r){if(isNaN(t)||isNaN(n))return e;var i,a=e._root,o={data:r},s=e._x0,c=e._y0,l=e._x1,u=e._y1,d,f,p,m,h,g,_,v;if(!a)return e._root=o,e;for(;a.length;)if((h=t>=(d=(s+l)/2))?s=d:l=d,(g=n>=(f=(c+u)/2))?c=f:u=f,i=a,!(a=a[_=g<<1|h]))return i[_]=o,e;if(p=+e._x.call(null,a.data),m=+e._y.call(null,a.data),t===p&&n===m)return o.next=a,i?i[_]=o:e._root=o,e;do i=i?i[_]=[,,,,]:e._root=[,,,,],(h=t>=(d=(s+l)/2))?s=d:l=d,(g=n>=(f=(c+u)/2))?c=f:u=f;while((_=g<<1|h)==(v=(m>=f)<<1|p>=d));return i[v]=a,i[_]=o,e}function OQ(e){var t,n,r=e.length,i,a,o=Array(r),s=Array(r),c=1/0,l=1/0,u=-1/0,d=-1/0;for(n=0;n<r;++n)isNaN(i=+this._x.call(null,t=e[n]))||isNaN(a=+this._y.call(null,t))||(o[n]=i,s[n]=a,i<c&&(c=i),i>u&&(u=i),a<l&&(l=a),a>d&&(d=a));if(c>u||l>d)return this;for(this.cover(c,l).cover(u,d),n=0;n<r;++n)DQ(this,o[n],s[n],e[n]);return this}function kQ(e,t){if(isNaN(e=+e)||isNaN(t=+t))return this;var n=this._x0,r=this._y0,i=this._x1,a=this._y1;if(isNaN(n))i=(n=Math.floor(e))+1,a=(r=Math.floor(t))+1;else{for(var o=i-n||1,s=this._root,c,l;n>e||e>=i||r>t||t>=a;)switch(l=(t<r)<<1|e<n,c=[,,,,],c[l]=s,s=c,o*=2,l){case 0:i=n+o,a=r+o;break;case 1:n=i-o,a=r+o;break;case 2:i=n+o,r=a-o;break;case 3:n=i-o,r=a-o}this._root&&this._root.length&&(this._root=s)}return this._x0=n,this._y0=r,this._x1=i,this._y1=a,this}function AQ(){var e=[];return this.visit(function(t){if(!t.length)do e.push(t.data);while(t=t.next)}),e}function jQ(e){return arguments.length?this.cover(+e[0][0],+e[0][1]).cover(+e[1][0],+e[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]}function MQ(e,t,n,r,i){this.node=e,this.x0=t,this.y0=n,this.x1=r,this.y1=i}function NQ(e,t,n){var r,i=this._x0,a=this._y0,o,s,c,l,u=this._x1,d=this._y1,f=[],p=this._root,m,h;for(p&&f.push(new MQ(p,i,a,u,d)),n==null?n=1/0:(i=e-n,a=t-n,u=e+n,d=t+n,n*=n);m=f.pop();)if(!(!(p=m.node)||(o=m.x0)>u||(s=m.y0)>d||(c=m.x1)<i||(l=m.y1)<a)){if(p.length){var g=(o+c)/2,_=(s+l)/2;f.push(new MQ(p[3],g,_,c,l),new MQ(p[2],o,_,g,l),new MQ(p[1],g,s,c,_),new MQ(p[0],o,s,g,_)),(h=(t>=_)<<1|e>=g)&&(m=f[f.length-1],f[f.length-1]=f[f.length-1-h],f[f.length-1-h]=m)}else{var v=e-+this._x.call(null,p.data),y=t-+this._y.call(null,p.data),b=v*v+y*y;if(b<n){var x=Math.sqrt(n=b);i=e-x,a=t-x,u=e+x,d=t+x,r=p.data}}}return r}function PQ(e){if(isNaN(u=+this._x.call(null,e))||isNaN(d=+this._y.call(null,e)))return this;var t,n=this._root,r,i,a,o=this._x0,s=this._y0,c=this._x1,l=this._y1,u,d,f,p,m,h,g,_;if(!n)return this;if(n.length)for(;;){if((m=u>=(f=(o+c)/2))?o=f:c=f,(h=d>=(p=(s+l)/2))?s=p:l=p,t=n,!(n=n[g=h<<1|m]))return this;if(!n.length)break;(t[g+1&3]||t[g+2&3]||t[g+3&3])&&(r=t,_=g)}for(;n.data!==e;)if(i=n,!(n=n.next))return this;return(a=n.next)&&delete n.next,i?(a?i.next=a:delete i.next,this):t?(a?t[g]=a:delete t[g],(n=t[0]||t[1]||t[2]||t[3])&&n===(t[3]||t[2]||t[1]||t[0])&&!n.length&&(r?r[_]=n:this._root=n),this):(this._root=a,this)}function FQ(e){for(var t=0,n=e.length;t<n;++t)this.remove(e[t]);return this}function IQ(){return this._root}function LQ(){var e=0;return this.visit(function(t){if(!t.length)do++e;while(t=t.next)}),e}function RQ(e){var t=[],n,r=this._root,i,a,o,s,c;for(r&&t.push(new MQ(r,this._x0,this._y0,this._x1,this._y1));n=t.pop();)if(!e(r=n.node,a=n.x0,o=n.y0,s=n.x1,c=n.y1)&&r.length){var l=(a+s)/2,u=(o+c)/2;(i=r[3])&&t.push(new MQ(i,l,u,s,c)),(i=r[2])&&t.push(new MQ(i,a,u,l,c)),(i=r[1])&&t.push(new MQ(i,l,o,s,u)),(i=r[0])&&t.push(new MQ(i,a,o,l,u))}return this}function zQ(e){var t=[],n=[],r;for(this._root&&t.push(new MQ(this._root,this._x0,this._y0,this._x1,this._y1));r=t.pop();){var i=r.node;if(i.length){var a,o=r.x0,s=r.y0,c=r.x1,l=r.y1,u=(o+c)/2,d=(s+l)/2;(a=i[0])&&t.push(new MQ(a,o,s,u,d)),(a=i[1])&&t.push(new MQ(a,u,s,c,d)),(a=i[2])&&t.push(new MQ(a,o,d,u,l)),(a=i[3])&&t.push(new MQ(a,u,d,c,l))}n.push(r)}for(;r=n.pop();)e(r.node,r.x0,r.y0,r.x1,r.y1);return this}function BQ(e){return e[0]}function VQ(e){return arguments.length?(this._x=e,this):this._x}function HQ(e){return e[1]}function UQ(e){return arguments.length?(this._y=e,this):this._y}function WQ(e,t,n){var r=new GQ(t??BQ,n??HQ,NaN,NaN,NaN,NaN);return e==null?r:r.addAll(e)}function GQ(e,t,n,r,i,a){this._x=e,this._y=t,this._x0=n,this._y0=r,this._x1=i,this._y1=a,this._root=void 0}function KQ(e){for(var t={data:e.data},n=t;e=e.next;)n=n.next={data:e.data};return t}var qQ=WQ.prototype=GQ.prototype;qQ.copy=function(){var e=new GQ(this._x,this._y,this._x0,this._y0,this._x1,this._y1),t=this._root,n,r;if(!t)return e;if(!t.length)return e._root=KQ(t),e;for(n=[{source:t,target:e._root=[,,,,]}];t=n.pop();)for(var i=0;i<4;++i)(r=t.source[i])&&(r.length?n.push({source:r,target:t.target[i]=[,,,,]}):t.target[i]=KQ(r));return e},qQ.add=EQ,qQ.addAll=OQ,qQ.cover=kQ,qQ.data=AQ,qQ.extent=jQ,qQ.find=NQ,qQ.remove=PQ,qQ.removeAll=FQ,qQ.root=IQ,qQ.size=LQ,qQ.visit=RQ,qQ.visitAfter=zQ,qQ.x=VQ,qQ.y=UQ;function JQ(e){return function(){return e}}function YQ(e){return(e()-.5)*1e-6}function XQ(e){return e.x+e.vx}function ZQ(e){return e.y+e.vy}function QQ(e){var t,n,r,i=1,a=1;typeof e!=`function`&&(e=JQ(e==null?1:+e));function o(){for(var e,o=t.length,c,l,u,d,f,p,m=0;m<a;++m)for(c=WQ(t,XQ,ZQ).visitAfter(s),e=0;e<o;++e)l=t[e],f=n[l.index],p=f*f,u=l.x+l.vx,d=l.y+l.vy,c.visit(h);function h(e,t,n,a,o){var s=e.data,c=e.r,m=f+c;if(s){if(s.index>l.index){var h=u-s.x-s.vx,g=d-s.y-s.vy,_=h*h+g*g;_<m*m&&(h===0&&(h=YQ(r),_+=h*h),g===0&&(g=YQ(r),_+=g*g),_=(m-(_=Math.sqrt(_)))/_*i,l.vx+=(h*=_)*(m=(c*=c)/(p+c)),l.vy+=(g*=_)*m,s.vx-=h*(m=1-m),s.vy-=g*m)}}else return t>u+m||a<u-m||n>d+m||o<d-m}}function s(e){if(e.data)return e.r=n[e.data.index];for(var t=e.r=0;t<4;++t)e[t]&&e[t].r>e.r&&(e.r=e[t].r)}function c(){if(t){var r,i=t.length,a;for(n=Array(i),r=0;r<i;++r)a=t[r],n[a.index]=+e(a,r,t)}}return o.initialize=function(e,n){t=e,r=n,c()},o.iterations=function(e){return arguments.length?(a=+e,o):a},o.strength=function(e){return arguments.length?(i=+e,o):i},o.radius=function(t){return arguments.length?(e=typeof t==`function`?t:JQ(+t),c(),o):e},o}function $Q(e){return e.index}function e$(e,t){var n=e.get(t);if(!n)throw Error(`node not found: `+t);return n}function t$(e){var t=$Q,n=d,r,i=JQ(30),a,o,s,c,l,u=1;e??=[];function d(e){return 1/Math.min(s[e.source.index],s[e.target.index])}function f(t){for(var n=0,i=e.length;n<u;++n)for(var o=0,s,d,f,p,m,h,g;o<i;++o)s=e[o],d=s.source,f=s.target,p=f.x+f.vx-d.x-d.vx||YQ(l),m=f.y+f.vy-d.y-d.vy||YQ(l),h=Math.sqrt(p*p+m*m),h=(h-a[o])/h*t*r[o],p*=h,m*=h,f.vx-=p*(g=c[o]),f.vy-=m*g,d.vx+=p*(g=1-g),d.vy+=m*g}function p(){if(o){var n,i=o.length,l=e.length,u=new Map(o.map((e,n)=>[t(e,n,o),e])),d;for(n=0,s=Array(i);n<l;++n)d=e[n],d.index=n,typeof d.source!=`object`&&(d.source=e$(u,d.source)),typeof d.target!=`object`&&(d.target=e$(u,d.target)),s[d.source.index]=(s[d.source.index]||0)+1,s[d.target.index]=(s[d.target.index]||0)+1;for(n=0,c=Array(l);n<l;++n)d=e[n],c[n]=s[d.source.index]/(s[d.source.index]+s[d.target.index]);r=Array(l),m(),a=Array(l),h()}}function m(){if(o)for(var t=0,i=e.length;t<i;++t)r[t]=+n(e[t],t,e)}function h(){if(o)for(var t=0,n=e.length;t<n;++t)a[t]=+i(e[t],t,e)}return f.initialize=function(e,t){o=e,l=t,p()},f.links=function(t){return arguments.length?(e=t,p(),f):e},f.id=function(e){return arguments.length?(t=e,f):t},f.iterations=function(e){return arguments.length?(u=+e,f):u},f.strength=function(e){return arguments.length?(n=typeof e==`function`?e:JQ(+e),m(),f):n},f.distance=function(e){return arguments.length?(i=typeof e==`function`?e:JQ(+e),h(),f):i},f}var n$={value:()=>{}};function r$(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+``)||r in n||/[\s.]/.test(r))throw Error(`illegal type: `+r);n[r]=[]}return new i$(n)}function i$(e){this._=e}function a$(e,t){return e.trim().split(/^|\s+/).map(function(e){var n=``,r=e.indexOf(`.`);if(r>=0&&(n=e.slice(r+1),e=e.slice(0,r)),e&&!t.hasOwnProperty(e))throw Error(`unknown type: `+e);return{type:e,name:n}})}i$.prototype=r$.prototype={constructor:i$,on:function(e,t){var n=this._,r=a$(e+``,n),i,a=-1,o=r.length;if(arguments.length<2){for(;++a<o;)if((i=(e=r[a]).type)&&(i=o$(n[i],e.name)))return i}else{if(t!=null&&typeof t!=`function`)throw Error(`invalid callback: `+t);for(;++a<o;)if(i=(e=r[a]).type)n[i]=s$(n[i],e.name,t);else if(t==null)for(i in n)n[i]=s$(n[i],e.name,null);return this}},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new i$(e)},call:function(e,t){if((i=arguments.length-2)>0)for(var n=Array(i),r=0,i,a;r<i;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(a=this._[e],r=0,i=a.length;r<i;++r)a[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(var r=this._[e],i=0,a=r.length;i<a;++i)r[i].value.apply(t,n)}};function o$(e,t){for(var n=0,r=e.length,i;n<r;++n)if((i=e[n]).name===t)return i.value}function s$(e,t,n){for(var r=0,i=e.length;r<i;++r)if(e[r].name===t){e[r]=n$,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var c$=0,l$=0,u$=0,d$=1e3,f$,p$,m$=0,h$=0,g$=0,_$=typeof performance==`object`&&performance.now?performance:Date,v$=typeof window==`object`&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function y$(){return h$||=(v$(b$),_$.now()+g$)}function b$(){h$=0}function x$(){this._call=this._time=this._next=null}x$.prototype=S$.prototype={constructor:x$,restart:function(e,t,n){if(typeof e!=`function`)throw TypeError(`callback is not a function`);n=(n==null?y$():+n)+(t==null?0:+t),!this._next&&p$!==this&&(p$?p$._next=this:f$=this,p$=this),this._call=e,this._time=n,D$()},stop:function(){this._call&&(this._call=null,this._time=1/0,D$())}};function S$(e,t,n){var r=new x$;return r.restart(e,t,n),r}function C$(){y$(),++c$;for(var e=f$,t;e;)(t=h$-e._time)>=0&&e._call.call(void 0,t),e=e._next;--c$}function w$(){h$=(m$=_$.now())+g$,c$=l$=0;try{C$()}finally{c$=0,E$(),h$=0}}function T$(){var e=_$.now(),t=e-m$;t>d$&&(g$-=t,m$=e)}function E$(){for(var e,t=f$,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:f$=n);p$=e,D$(r)}function D$(e){c$||(l$&&=clearTimeout(l$),e-h$>24?(e<1/0&&(l$=setTimeout(w$,e-_$.now()-g$)),u$&&=clearInterval(u$)):(u$||=(m$=_$.now(),setInterval(T$,d$)),c$=1,v$(w$)))}var O$=1664525,k$=1013904223,A$=4294967296;function j$(){let e=1;return()=>(e=(O$*e+k$)%A$)/A$}function M$(e){return e.x}function N$(e){return e.y}var P$=10,F$=Math.PI*(3-Math.sqrt(5));function I$(e){var t,n=1,r=.001,i=1-r**(1/300),a=0,o=.6,s=new Map,c=S$(d),l=r$(`tick`,`end`),u=j$();e??=[];function d(){f(),l.call(`tick`,t),n<r&&(c.stop(),l.call(`end`,t))}function f(r){var c,l=e.length,u;r===void 0&&(r=1);for(var d=0;d<r;++d)for(n+=(a-n)*i,s.forEach(function(e){e(n)}),c=0;c<l;++c)u=e[c],u.fx==null?u.x+=u.vx*=o:(u.x=u.fx,u.vx=0),u.fy==null?u.y+=u.vy*=o:(u.y=u.fy,u.vy=0);return t}function p(){for(var t=0,n=e.length,r;t<n;++t){if(r=e[t],r.index=t,r.fx!=null&&(r.x=r.fx),r.fy!=null&&(r.y=r.fy),isNaN(r.x)||isNaN(r.y)){var i=P$*Math.sqrt(.5+t),a=t*F$;r.x=i*Math.cos(a),r.y=i*Math.sin(a)}(isNaN(r.vx)||isNaN(r.vy))&&(r.vx=r.vy=0)}}function m(t){return t.initialize&&t.initialize(e,u),t}return p(),t={tick:f,restart:function(){return c.restart(d),t},stop:function(){return c.stop(),t},nodes:function(n){return arguments.length?(e=n,p(),s.forEach(m),t):e},alpha:function(e){return arguments.length?(n=+e,t):n},alphaMin:function(e){return arguments.length?(r=+e,t):r},alphaDecay:function(e){return arguments.length?(i=+e,t):+i},alphaTarget:function(e){return arguments.length?(a=+e,t):a},velocityDecay:function(e){return arguments.length?(o=1-e,t):1-o},randomSource:function(e){return arguments.length?(u=e,s.forEach(m),t):u},force:function(e,n){return arguments.length>1?(n==null?s.delete(e):s.set(e,m(n)),t):s.get(e)},find:function(t,n,r){var i=0,a=e.length,o,s,c,l,u;for(r==null?r=1/0:r*=r,i=0;i<a;++i)l=e[i],o=t-l.x,s=n-l.y,c=o*o+s*s,c<r&&(u=l,r=c);return u},on:function(e,n){return arguments.length>1?(l.on(e,n),t):l.on(e)}}}function L$(){var e,t,n,r,i=JQ(-30),a,o=1,s=1/0,c=.81;function l(n){var i,a=e.length,o=WQ(e,M$,N$).visitAfter(d);for(r=n,i=0;i<a;++i)t=e[i],o.visit(f)}function u(){if(e){var t,n=e.length,r;for(a=Array(n),t=0;t<n;++t)r=e[t],a[r.index]=+i(r,t,e)}}function d(e){var t=0,n,r,i=0,o,s,c;if(e.length){for(o=s=c=0;c<4;++c)(n=e[c])&&(r=Math.abs(n.value))&&(t+=n.value,i+=r,o+=r*n.x,s+=r*n.y);e.x=o/i,e.y=s/i}else{n=e,n.x=n.data.x,n.y=n.data.y;do t+=a[n.data.index];while(n=n.next)}e.value=t}function f(e,i,l,u){if(!e.value)return!0;var d=e.x-t.x,f=e.y-t.y,p=u-i,m=d*d+f*f;if(p*p/c<m)return m<s&&(d===0&&(d=YQ(n),m+=d*d),f===0&&(f=YQ(n),m+=f*f),m<o&&(m=Math.sqrt(o*m)),t.vx+=d*e.value*r/m,t.vy+=f*e.value*r/m),!0;if(!(e.length||m>=s)){(e.data!==t||e.next)&&(d===0&&(d=YQ(n),m+=d*d),f===0&&(f=YQ(n),m+=f*f),m<o&&(m=Math.sqrt(o*m)));do e.data!==t&&(p=a[e.data.index]*r/m,t.vx+=d*p,t.vy+=f*p);while(e=e.next)}}return l.initialize=function(t,r){e=t,n=r,u()},l.strength=function(e){return arguments.length?(i=typeof e==`function`?e:JQ(+e),u(),l):i},l.distanceMin=function(e){return arguments.length?(o=e*e,l):Math.sqrt(o)},l.distanceMax=function(e){return arguments.length?(s=e*e,l):Math.sqrt(s)},l.theta=function(e){return arguments.length?(c=e*e,l):Math.sqrt(c)},l}function R$(e){var t=JQ(.1),n,r,i;typeof e!=`function`&&(e=JQ(e==null?0:+e));function a(e){for(var t=0,a=n.length,o;t<a;++t)o=n[t],o.vx+=(i[t]-o.x)*r[t]*e}function o(){if(n){var a,o=n.length;for(r=Array(o),i=Array(o),a=0;a<o;++a)r[a]=isNaN(i[a]=+e(n[a],a,n))?0:+t(n[a],a,n)}}return a.initialize=function(e){n=e,o()},a.strength=function(e){return arguments.length?(t=typeof e==`function`?e:JQ(+e),o(),a):t},a.x=function(t){return arguments.length?(e=typeof t==`function`?t:JQ(+t),o(),a):e},a}function z$(e){var t=JQ(.1),n,r,i;typeof e!=`function`&&(e=JQ(e==null?0:+e));function a(e){for(var t=0,a=n.length,o;t<a;++t)o=n[t],o.vy+=(i[t]-o.y)*r[t]*e}function o(){if(n){var a,o=n.length;for(r=Array(o),i=Array(o),a=0;a<o;++a)r[a]=isNaN(i[a]=+e(n[a],a,n))?0:+t(n[a],a,n)}}return a.initialize=function(e){n=e,o()},a.strength=function(e){return arguments.length?(t=typeof e==`function`?e:JQ(+e),o(),a):t},a.y=function(t){return arguments.length?(e=typeof t==`function`?t:JQ(+t),o(),a):e},a}function B$(e){var t=0,n=e.children,r=n&&n.length;if(!r)t=1;else for(;--r>=0;)t+=n[r].value;e.value=t}function V$(){return this.eachAfter(B$)}function H$(e,t){let n=-1;for(let r of this)e.call(t,r,++n,this);return this}function U$(e,t){for(var n=this,r=[n],i,a,o=-1;n=r.pop();)if(e.call(t,n,++o,this),i=n.children)for(a=i.length-1;a>=0;--a)r.push(i[a]);return this}function W$(e,t){for(var n=this,r=[n],i=[],a,o,s,c=-1;n=r.pop();)if(i.push(n),a=n.children)for(o=0,s=a.length;o<s;++o)r.push(a[o]);for(;n=i.pop();)e.call(t,n,++c,this);return this}function G$(e,t){let n=-1;for(let r of this)if(e.call(t,r,++n,this))return r}function K$(e){return this.eachAfter(function(t){for(var n=+e(t.data)||0,r=t.children,i=r&&r.length;--i>=0;)n+=r[i].value;t.value=n})}function q$(e){return this.eachBefore(function(t){t.children&&t.children.sort(e)})}function J$(e){for(var t=this,n=Y$(t,e),r=[t];t!==n;)t=t.parent,r.push(t);for(var i=r.length;e!==n;)r.splice(i,0,e),e=e.parent;return r}function Y$(e,t){if(e===t)return e;var n=e.ancestors(),r=t.ancestors(),i=null;for(e=n.pop(),t=r.pop();e===t;)i=e,e=n.pop(),t=r.pop();return i}function X$(){for(var e=this,t=[e];e=e.parent;)t.push(e);return t}function Z$(){return Array.from(this)}function Q$(){var e=[];return this.eachBefore(function(t){t.children||e.push(t)}),e}function $$(){var e=this,t=[];return e.each(function(n){n!==e&&t.push({source:n.parent,target:n})}),t}function*e1(){var e=this,t,n=[e],r,i,a;do for(t=n.reverse(),n=[];e=t.pop();)if(yield e,r=e.children)for(i=0,a=r.length;i<a;++i)n.push(r[i]);while(n.length)}function t1(e,t){e instanceof Map?(e=[void 0,e],t===void 0&&(t=i1)):t===void 0&&(t=r1);for(var n=new s1(e),r,i=[n],a,o,s,c;r=i.pop();)if((o=t(r.data))&&(c=(o=Array.from(o)).length))for(r.children=o,s=c-1;s>=0;--s)i.push(a=o[s]=new s1(o[s])),a.parent=r,a.depth=r.depth+1;return n.eachBefore(o1)}function n1(){return t1(this).eachBefore(a1)}function r1(e){return e.children}function i1(e){return Array.isArray(e)?e[1]:null}function a1(e){e.data.value!==void 0&&(e.value=e.data.value),e.data=e.data.data}function o1(e){var t=0;do e.height=t;while((e=e.parent)&&e.height<++t)}function s1(e){this.data=e,this.depth=this.height=0,this.parent=null}s1.prototype=t1.prototype={constructor:s1,count:V$,each:H$,eachAfter:W$,eachBefore:U$,find:G$,sum:K$,sort:q$,path:J$,ancestors:X$,descendants:Z$,leaves:Q$,links:$$,copy:n1,[Symbol.iterator]:e1};function c1(e,t){return e.parent===t.parent?1:2}function l1(e){var t=e.children;return t?t[0]:e.t}function u1(e){var t=e.children;return t?t[t.length-1]:e.t}function d1(e,t,n){var r=n/(t.i-e.i);t.c-=r,t.s+=n,e.c+=r,t.z+=n,t.m+=n}function f1(e){for(var t=0,n=0,r=e.children,i=r.length,a;--i>=0;)a=r[i],a.z+=t,a.m+=t,t+=a.s+(n+=a.c)}function p1(e,t,n){return e.a.parent===t.parent?e.a:n}function m1(e,t){this._=e,this.parent=null,this.children=null,this.A=null,this.a=this,this.z=0,this.m=0,this.c=0,this.s=0,this.t=null,this.i=t}m1.prototype=Object.create(s1.prototype);function h1(e){for(var t=new m1(e,0),n,r=[t],i,a,o,s;n=r.pop();)if(a=n._.children)for(n.children=Array(s=a.length),o=s-1;o>=0;--o)r.push(i=n.children[o]=new m1(a[o],o)),i.parent=n;return(t.parent=new m1(null,0)).children=[t],t}function g1(){var e=c1,t=1,n=1,r=null;function i(i){var s=h1(i);if(s.eachAfter(a),s.parent.m=-s.z,s.eachBefore(o),r)i.eachBefore(c);else{var l=i,u=i,d=i;i.eachBefore(function(e){e.x<l.x&&(l=e),e.x>u.x&&(u=e),e.depth>d.depth&&(d=e)});var f=l===u?1:e(l,u)/2,p=f-l.x,m=t/(u.x+f+p),h=n/(d.depth||1);i.eachBefore(function(e){e.x=(e.x+p)*m,e.y=e.depth*h})}return i}function a(t){var n=t.children,r=t.parent.children,i=t.i?r[t.i-1]:null;if(n){f1(t);var a=(n[0].z+n[n.length-1].z)/2;i?(t.z=i.z+e(t._,i._),t.m=t.z-a):t.z=a}else i&&(t.z=i.z+e(t._,i._));t.parent.A=s(t,i,t.parent.A||r[0])}function o(e){e._.x=e.z+e.parent.m,e.m+=e.parent.m}function s(t,n,r){if(n){for(var i=t,a=t,o=n,s=i.parent.children[0],c=i.m,l=a.m,u=o.m,d=s.m,f;o=u1(o),i=l1(i),o&&i;)s=l1(s),a=u1(a),a.a=t,f=o.z+u-i.z-c+e(o._,i._),f>0&&(d1(p1(o,t,r),t,f),c+=f,l+=f),u+=o.m,c+=i.m,d+=s.m,l+=a.m;o&&!u1(a)&&(a.t=o,a.m+=u-l),i&&!l1(s)&&(s.t=i,s.m+=c-d,r=t)}return r}function c(e){e.x*=t,e.y=e.depth*n}return i.separation=function(t){return arguments.length?(e=t,i):e},i.size=function(e){return arguments.length?(r=!1,t=+e[0],n=+e[1],i):r?null:[t,n]},i.nodeSize=function(e){return arguments.length?(r=!0,t=+e[0],n=+e[1],i):r?[t,n]:null},i}var _1=7.8,v1=/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\u3000-\u303F\uFF01-\uFF60]/gu,y1=30,b1=18,x1=72,S1=18,C1=30,w1=1500,T1=15,E1=28,D1=34,O1=30,k1=16,A1=.6,j1=9,M1=4.5,N1=8,P1=18,F1=4,I1=[.5,.4,.6,.3,.7,.22,.78],L1=6,R1=150;function z1(e){let t=e=>e.length*_1+(e.match(v1)?.length??0)*5.2,n=0,r=0;for(let i of e.matchAll(/\$([^$]+)\$/g)){n+=t(e.slice(r,i.index));let a=i[1].replace(/\\(?:text|mathrm|mathbf|mathbb|mathit)\b/g,``).replace(/\\[a-zA-Z]+|\\[^a-zA-Z]/g,`x`).replace(/[_^{}\s]/g,``);n+=Math.min(a.length,12)*13*1.1+4,r=i.index+i[0].length}return n+t(e.slice(r))}var B1=e=>e.weight===void 0?e.label:String(e.weight),V1=e=>(e?z1(e):0)+8;function H1(e,t){let n=Math.max(...[...e.values()].map(e=>e.width)),r=t1(t.root,e=>t.children.get(e));g1().nodeSize([n+S1,x1]).separation(()=>1)(r),r.each(t=>Object.assign(e.get(t.data),{x:t.x,y:t.y}))}function U1(e,t,n){let r=new Map(e.edges.map(e=>[e.to,e.side])),i=Math.max(...[...t.values()].map(e=>e.width)),a=Math.max(0,...e.edges.map(e=>V1(B1(e)))),o=Math.max((i+S1)/2,a+F1),s=new Map,c=(e,i,a)=>{let l=n.children.get(e),u=t.get(e),d;if(l.some(e=>r.get(e))){let t=l.find(e=>r.get(e)===`left`),n=l.find(e=>r.get(e)===`right`),o=t===void 0?a:c(t,i+1,a);s.set(e,o),d=n===void 0?o+1:c(n,i+1,o+1)}else{d=l.reduce((e,t,n)=>c(t,i+1,e+ +(n>0)),a);let t=l[0],n=l.at(-1);s.set(e,t===void 0||n===void 0?a:(s.get(t)+s.get(n))/2),d=Math.max(d,a+1)}return Object.assign(u,{x:s.get(e)*o,y:i*x1}),d};c(n.root,0,0)}var W1=e=>t=>{let n=w1*Math.min(1,T1/e.length);for(let r=0;r<e.length;r++){let i=e[r];for(let a=r+1;a<e.length;a++){let r=e[a],o=r.x-i.x,s=r.y-i.y,c=o*o+s*s||1,l=i.radius+r.radius+E1,u=n*t/c+(c<l*l?(l/Math.sqrt(c)-1)*.25:0);i.vx-=o*u,i.vy-=s*u,r.vx+=o*u,r.vy+=s*u}}};function G1(e,t){let n=e.nodes.map(({id:e})=>({id:e,radius:t.get(e).width/2})),r=new Map;for(let{from:t,to:n}of e.edges)t!==n&&r.set(JSON.stringify([t,n].sort()),{source:t,target:n});let i=new Map(n.map(e=>[e.id,e])),a=[...r.values()].map(({source:e,target:t})=>[i.get(e),i.get(t)]),o=()=>{for(let[e,t]of a){let r=t.x-e.x,i=t.y-e.y,a=r*r+i*i||1;for(let o of n){if(o===e||o===t)continue;let n=Math.max(0,Math.min(1,((o.x-e.x)*r+(o.y-e.y)*i)/a)),s=o.x-e.x-n*r,c=o.y-e.y-n*i,l=Math.hypot(s,c),u=Math.max(0,o.radius+12-l)*.5;if(u===0)continue;let d=l>.001?s/l:-i/(Math.hypot(r,i)||1),f=l>.001?c/l:r/(Math.hypot(r,i)||1);o.vx+=d*u,o.vy+=f*u,e.vx-=d*u*(1-n),e.vy-=f*u*(1-n),t.vx-=d*u*n,t.vy-=f*u*n}}},s=t$([...r.values()]).id(e=>e.id).distance(e=>C1+e.source.radius+e.target.radius);I$(n).stop().alphaDecay(1-.001**(1/R1)).force(`link`,s).force(`repel`,W1(n)).force(`edgeClearance`,o).force(`x`,R$().strength(.05)).force(`y`,z$().strength(.05)).tick(R1);for(let e of n)Object.assign(t.get(e.id),{x:e.x,y:e.y})}function K1(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*i)/(r*r+i*i||1)));return Math.hypot(e.x-t.x-a*r,e.y-t.y-a*i)}function q1(e,t,n){let r=new Map,i=(e,t)=>JSON.stringify([e,t].sort());for(let t of e.edges)r.set(i(t.from,t.to),(r.get(i(t.from,t.to))??0)+1);let a=()=>{let n=1;for(let a of e.edges){let o=t.get(a.from),s=t.get(a.to),c=r.get(i(a.from,a.to));for(let[r,i]of t){if(r===a.from||r===a.to)continue;let t=a.from===a.to?Math.hypot(i.x-o.x,i.y-o.y):K1(i,o,s),l=(a.from===a.to?o.width/2+O1+(c-1)*k1:(c-1)*D1/2)+(e.directed?M1:0);n=Math.max(n,(i.width/2+6.1+l)/Math.max(t,1e-4))}}return n},o=a();if(!n&&o>3){let n=Math.max(80,...[...t.values()].map(e=>e.width))*t.size/Math.PI;e.nodes.forEach(({id:e},r)=>{let i=2*Math.PI*r/t.size-Math.PI/2;Object.assign(t.get(e),{x:Math.cos(i)*n,y:Math.sin(i)*n})}),o=a()}if(o>1)for(let e of t.values())e.x*=o,e.y*=o;if(!n&&o>1){let e=[...t.values()],n=1/0,r=0;for(let t=0;t<36;t++){let i=t*Math.PI/36,a=e.map(e=>e.x*Math.cos(i)-e.y*Math.sin(i)),o=Math.max(...a.map((t,n)=>t+e[n].width/2))-Math.min(...a.map((t,n)=>t-e[n].width/2));o<n-.01&&(n=o,r=i)}for(let t of e){let{x:e,y:n}=t;t.x=e*Math.cos(r)-n*Math.sin(r),t.y=e*Math.sin(r)+n*Math.cos(r)}}}function J1(e,t){let n=e.height/2,r=Math.max(Math.abs(t.x-e.x)-(e.width/2-n),0),i=t.y-e.y;return r*r+i*i<=n*n}function Y1(e,t,n){for(let r=0;r<14;r++){let r=(e+t)/2;n(r)?e=r:t=r}return e}var X1=(e,t,n)=>e+(t-e)*n,Z1=(e,t,n)=>({x:X1(e.x,t.x,n),y:X1(e.y,t.y,n)}),Q1=(e,t,n)=>r=>Z1(Z1(e,t,r),Z1(t,n,r),r),$1=(e,t,n,r)=>i=>Z1(Q1(e,t,n)(i),Q1(t,n,r)(i),i);function e0(e,t,n,r,i){let a=J1(t,e(.5))?.5:Y1(0,.5,n=>J1(t,e(n))),o=J1(n,e(.5))?.5:Y1(1,.5,t=>J1(n,e(t))),s=e(o),c=i?Y1(o,a,t=>Math.hypot(e(t).x-s.x,e(t).y-s.y)<j1):o,l=Array.from({length:r+1},(t,n)=>e(X1(a,c,n/r)));if(!i)return{points:l};let u=e(c),d=Math.hypot(s.x-u.x,s.y-u.y)||1,f={x:(u.y-s.y)/d*M1,y:(s.x-u.x)/d*M1};return{points:l,arrow:[s,{x:u.x+f.x,y:u.y+f.y},{x:u.x-f.x,y:u.y-f.y}]}}function t0(e,t,n){return Y1(0,e.width+e.height,r=>J1(e,{x:e.x+t*r,y:e.y+n*r}))}var n0=(e,t)=>Math.abs(e.x-t.x)<(e.width+t.width)/2&&Math.abs(e.y-t.y)<(e.height+t.height)/2,r0=e=>Math.round(e*100)/100,i0=(e,t)=>e.map(e=>`${r0(e.x+t.x)},${r0(e.y+t.y)}`);function a0(e){let t=new Map(e.nodes.map(e=>[e.id,{x:0,y:0,width:Math.max(y1,z1(e.label??e.id)+b1),height:y1}])),n=e.kind===`tree`?aj(e):void 0;n?e.edges.some(e=>e.side)?U1(e,t,n):H1(t,n):G1(e,t),q1(e,t,!!n);let r=[...t.values()],i={x:r.reduce((e,t)=>e+t.x,0)/r.length,y:r.reduce((e,t)=>e+t.y,0)/r.length},a=new Map(e.nodes.map((e,t)=>[e.id,t])),o=(e,t)=>a.get(e)<=a.get(t)?`${a.get(e)}:${a.get(t)}`:`${a.get(t)}:${a.get(e)}`,s=new Map;for(let{from:t,to:n}of e.edges)s.set(o(t,n),(s.get(o(t,n))??0)+1);let c=new Map,l=e.edges.map(n=>{let r=o(n.from,n.to),l=c.get(r)??0;c.set(r,l+1);let u=t.get(n.from),d=t.get(n.to);if(n.from===n.to){let t=Math.hypot(u.x-i.x,u.y-i.y)>1?Math.atan2(u.y-i.y,u.x-i.x):-Math.PI/2,n=(t0(u,Math.cos(t),Math.sin(t))+O1+l*k1)/(.75*Math.cos(A1)),r=e=>({x:u.x+Math.cos(e)*n,y:u.y+Math.sin(e)*n}),a=$1(u,r(t-A1),r(t+A1),u);return{...e0(a,u,u,24,e.directed),curve:a}}let f=s.get(r),[p,m]=a.get(n.from)<=a.get(n.to)?[u,d]:[d,u],h=Math.hypot(m.x-p.x,m.y-p.y)||1,g=(l-(f-1)/2)*D1*2,_=Z1(u,d,.5),v=Q1(u,{x:_.x+(p.y-m.y)/h*g,y:_.y+(m.x-p.x)/h*g},d);return{...e0(v,u,d,f>1?16:1,e.directed),curve:v}}),u=[...r],d=l.map((t,n)=>{let r=B1(e.edges[n]),i={width:V1(r),height:P1},a=I1.map(e=>({...t.curve(e),...i}));if(!r)return a[0];let o=a.map(e=>u.filter(t=>n0(t,e)).length),s=a[o.indexOf(Math.min(...o))],c=Array.from({length:L1},(e,t)=>t+1).flatMap(e=>{let[t,n]=[e*(i.height+F1),e*(i.width+F1)];return[{...a[0],y:a[0].y-t},{...a[0],y:a[0].y+t},{...a[0],x:a[0].x-n},{...a[0],x:a[0].x+n}]}),l=Math.min(...o)===0||e.edges[n].weight!==void 0?s:c.find(e=>!u.some(t=>n0(t,e)))??s;return u.push(l),l}),f=[...r,...d.filter((t,n)=>B1(e.edges[n]))];for(let e of l)f.push(...e.points.map(e=>({...e,width:0,height:0})));let p=Math.min(...f.map(e=>e.x-e.width/2))-N1,m=Math.min(...f.map(e=>e.y-e.height/2))-N1,h=Math.max(...f.map(e=>e.x+e.width/2))+N1,g=Math.max(...f.map(e=>e.y+e.height/2))+N1,_={x:-p,y:-m};return{mode:n?`tree`:`general`,width:Math.ceil(h-p),height:Math.ceil(g-m),nodes:e.nodes.map(({id:e})=>{let n=t.get(e);return{id:e,x:r0(n.x+_.x),y:r0(n.y+_.y),width:n.width,height:n.height}}),edges:l.map((e,t)=>({path:`M${i0(e.points,_).join(`L`)}`,...e.arrow?{arrow:i0(e.arrow,_).join(` `)}:{},label:{x:r0(d[t].x+_.x),y:r0(d[t].y+_.y),width:d[t].width,height:d[t].height}}))}}var o0=11/13,s0={x:2,y:4},c0=.5,l0=e=>`${e/13}em`,u0={active:`border-foreground border-[3px] bg-muted font-semibold`,done:`border-success border-2 bg-[color-mix(in_oklab,var(--success)_15%,var(--card))]`,muted:`border-muted-foreground/50 bg-muted text-muted-foreground border-dashed`},d0={active:{stroke:`stroke-foreground`,fill:`fill-foreground`,width:3.5},done:{stroke:`stroke-success`,fill:`fill-success`,width:2.5},muted:{stroke:`stroke-muted-foreground/50`,fill:`fill-muted-foreground/50`,width:1.25,dash:`4 4`}},f0={active:`font-semibold`,done:`text-success`,muted:`text-muted-foreground`},p0={active:`active`,done:`done`,muted:`ruled out`};function m0(e,t){let n=e.steps?.[t],r=ij(e),i=new Map;for(let e of n?.nodeStates??[])i.set(e.id,e.tone??`active`);let a=new Map;for(let e of n?.edgeStates??[]){let t=r(e);`index`in t&&a.set(t.index,e.tone??`active`)}return{explanation:n?.explanation??``,nodes:i,edges:a,variables:n?.variables??[]}}function h0({labelKey:e,width:t,height:n,truncated:r,children:i}){return(0,j.jsxs)(`span`,{className:`relative block overflow-hidden`,style:{width:l0(t),height:l0(n)},"data-label-clip":e,"data-truncated":r?`true`:void 0,children:[(0,j.jsx)(`span`,{className:A(`grid size-full items-center`,r?`justify-items-start mask-r-from-[calc(100%-1.4em)] mask-r-to-[calc(100%-0.8em)]`:`justify-items-center`),children:(0,j.jsx)(`span`,{className:`w-max whitespace-nowrap`,"data-label-content":!0,children:i})}),r&&(0,j.jsx)(`span`,{className:`absolute inset-y-0 right-0 grid place-items-center`,"data-testid":`graph-label-cut`,children:`…`})]})}function g0({view:e}){let{spec:t}=e,n=t.steps??[],r=lQ(n.length),i=JSON.stringify([t.directed,t.kind,t.nodes,t.edges]),a=(0,v.useMemo)(()=>a0(t),[i]),o=(0,v.useRef)(null);(0,v.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=a.mode===`tree`?a.nodes.reduce((e,t)=>t.y<e.y?t:e):void 0;e.scrollLeft=t?t.x*e.scrollWidth/a.width-e.clientWidth/2:(e.scrollWidth-e.clientWidth)/2,e.scrollTop=t?0:(e.scrollHeight-e.clientHeight)/2},[a]);let[s,c]=(0,v.useState)(!1);(0,v.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=()=>c(e.scrollWidth>e.clientWidth||e.scrollHeight>e.clientHeight);if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[a]);let l=(0,v.useRef)(null),[u,d]=(0,v.useState)(new Set);(0,v.useLayoutEffect)(()=>{let e=()=>{let e=[...l.current?.querySelectorAll(`[data-label-clip]`)??[]].filter(e=>{let t=e.getBoundingClientRect(),n=e.querySelector(`[data-label-content]`),r=[...n.querySelectorAll(`.katex-html .strut`)].map(e=>e.getBoundingClientRect().height),i=r.length>0?Math.max(...r):n.getBoundingClientRect().height;return n.getBoundingClientRect().width>t.width+c0||i>t.height+c0}).map(e=>e.dataset.labelClip);d(t=>t.size===e.length&&e.every(e=>t.has(e))?t:new Set(e))};e();let t=!0;document.fonts.ready.then(()=>{t&&e()}),document.fonts.addEventListener?.(`loadingdone`,e);let n=typeof ResizeObserver>`u`?void 0:new ResizeObserver(e);return l.current&&n?.observe(l.current),()=>{t=!1,document.fonts.removeEventListener?.(`loadingdone`,e),n?.disconnect()}},[i]);let f=new Map(t.nodes.flatMap((e,t)=>u.has(`n-${e.id}`)?[[e.id,`[${t+1}]`]]:[])),p=e=>{o.current?.contains(e.target)||r.onKeyDown(e)},m=m0(t,r.index),h=n.length>0,g=(e,t)=>`${e/t*100}%`,_=(0,v.useId)(),y=(0,v.useId)();return(0,j.jsxs)(pQ,{role:`region`,"aria-labelledby":`${_} ${y}`,tabIndex:h?0:void 0,onKeyDown:h?p:void 0,children:[(0,j.jsx)(mQ,{kind:t.directed?`Directed graph`:`Graph`,kindId:y,children:(0,j.jsx)(hQ,{id:_,text:t.title})}),(0,j.jsxs)(gQ,{children:[(0,j.jsx)(x0,{spec:t}),(0,j.jsx)(`div`,{ref:o,className:`focus-visible:ring-ring/50 max-h-[36rem] overflow-auto rounded-sm outline-none focus-visible:ring-[3px]`,"data-testid":`graph-scroll`,...s?{tabIndex:0,role:`group`,"aria-label":`Scrollable graph drawing`}:{},children:(0,j.jsxs)(`div`,{ref:l,className:`@container relative mx-auto w-full`,style:{maxWidth:a.width,minWidth:a.width*o0,aspectRatio:`${a.width} / ${a.height}`},"aria-hidden":`true`,"data-testid":`graph-canvas`,"data-layout":a.mode,children:[(0,j.jsx)(`svg`,{viewBox:`0 0 ${a.width} ${a.height}`,className:`absolute inset-0 size-full`,fill:`none`,children:a.edges.map((e,t)=>{let n=m.edges.get(t),r=n?d0[n]:{stroke:`stroke-muted-foreground`,fill:`fill-muted-foreground`,width:1.5,dash:void 0};return(0,j.jsxs)(`g`,{"data-testid":`graph-edge`,"data-tone":n,children:[(0,j.jsx)(`path`,{d:e.path,className:r.stroke,strokeWidth:r.width,strokeDasharray:r.dash,strokeLinecap:`round`}),e.arrow&&(0,j.jsx)(`polygon`,{points:e.arrow,className:r.fill,"data-testid":`graph-arrow`})]},t)})}),(0,j.jsxs)(`div`,{className:`absolute inset-0 font-mono leading-none`,style:{fontSize:`calc(13 * 100cqw / ${a.width})`},children:[t.edges.map((e,t)=>{let n=B1(e),r=a.edges[t].label,i=m.edges.get(t);return n===void 0?null:(0,j.jsx)(`span`,{className:A(`bg-card absolute -translate-x-1/2 -translate-y-1/2 rounded-sm [&_.katex]:text-[1.1em]!`,i&&f0[i]),style:{left:g(r.x,a.width),top:g(r.y,a.height)},"data-testid":`graph-edge-label`,children:(0,j.jsx)(h0,{labelKey:`e-${t}`,width:r.width,height:r.height,truncated:u.has(`e-${t}`),children:e.weight===void 0?(0,j.jsx)(rQ,{text:n,mode:`math`}):n})},t)}),a.nodes.map((e,n)=>{let r=m.nodes.get(e.id);return(0,j.jsxs)(`div`,{className:A(`absolute grid -translate-x-1/2 -translate-y-1/2 place-items-center rounded-full border`,r?u0[r]:`border-muted-foreground bg-card`),style:{left:g(e.x,a.width),top:g(e.y,a.height),width:g(e.width,a.width),height:g(e.height,a.height)},"data-testid":`graph-node`,"data-node":e.id,"data-tone":r,children:[(0,j.jsx)(h0,{labelKey:`n-${e.id}`,width:e.width-s0.x,height:e.height-s0.y,truncated:u.has(`n-${e.id}`),children:(0,j.jsx)(`span`,{className:f.has(e.id)?`invisible`:void 0,children:(0,j.jsx)(rQ,{text:t.nodes[n].label??e.id,mode:`math`})})}),f.has(e.id)&&(0,j.jsx)(`span`,{className:`bg-card absolute rounded-sm px-1`,"data-node-key":f.get(e.id),children:f.get(e.id)}),r===`done`&&(0,j.jsx)(`span`,{className:`bg-success text-card absolute -top-[0.35em] -right-[0.35em] grid size-[1.05em] place-items-center rounded-full`,children:(0,j.jsx)(qm,{className:`size-[0.8em]`,strokeWidth:3.5})})]},e.id)})]})]})}),(0,j.jsx)(_0,{spec:t,truncated:u,nodeKeys:f}),m.variables.length>0&&(0,j.jsx)(`dl`,{className:`flex flex-wrap gap-2`,"aria-hidden":h?!0:void 0,children:m.variables.map((e,t)=>(0,j.jsxs)(`div`,{className:`border-border-strong bg-card flex max-w-full min-w-0 gap-1.5 rounded-md border px-2 py-0.5 font-mono text-xs wrap-anywhere`,children:[(0,j.jsx)(`dt`,{className:`min-w-0`,children:e.name}),(0,j.jsxs)(`dd`,{className:`min-w-0`,children:[`= `,String(e.value)]})]},t))}),h&&(0,j.jsx)(j.Fragment,{children:(0,j.jsx)(b0,{spec:t,state:m,step:r.index+1,of:n.length})})]}),h&&(0,j.jsx)(fQ,{stepper:r,play:!0})]})}function _0({spec:e,truncated:t,nodeKeys:n}){if(t.size===0)return null;let r=e.directed?`→`:`–`;return(0,j.jsxs)(`div`,{className:`flex flex-col gap-1 text-xs`,"data-testid":`graph-overflow`,children:[(0,j.jsx)(`p`,{"aria-hidden":`true`,className:`text-muted-foreground`,children:`… Cut short in the drawing:`}),e.nodes.map(r=>t.has(`n-${r.id}`)?(0,j.jsxs)(dQ,{children:[(0,j.jsxs)(`span`,{className:`font-medium`,children:[`Node `,n.get(r.id),`:`]}),` `,(0,j.jsx)(v0,{spec:e,id:r.id})]},r.id):null),e.edges.map((i,a)=>t.has(`e-${a}`)?(0,j.jsxs)(dQ,{children:[(0,j.jsxs)(`span`,{className:`font-medium`,children:[`Edge `,n.get(i.from)??(0,j.jsx)(v0,{spec:e,id:i.from}),` `,r,` `,n.get(i.to)??(0,j.jsx)(v0,{spec:e,id:i.to}),`:`]}),` `,i.weight===void 0?(0,j.jsx)(rQ,{text:i.label,mode:`math`}):i.weight]},a):null)]})}function v0({spec:e,id:t}){return(0,j.jsx)(rQ,{text:e.nodes.find(e=>e.id===t)?.label??t,mode:`math`})}function y0({spec:e,index:t}){let n=e.edges[t];return(0,j.jsxs)(j.Fragment,{children:[n.from===n.to?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(v0,{spec:e,id:n.from}),` to itself`]}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(v0,{spec:e,id:n.from}),` `,e.directed?`to`:`and`,` `,(0,j.jsx)(v0,{spec:e,id:n.to})]}),n.side&&`, ${n.side} child`,n.weight!==void 0&&`, weight ${n.weight}`,n.label!==void 0&&(0,j.jsxs)(j.Fragment,{children:[`, labelled `,(0,j.jsx)(rQ,{text:n.label,mode:`math`})]})]})}function b0({spec:e,state:t,step:n,of:r}){return(0,j.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"aria-atomic":`true`,"data-testid":`graph-status`,children:[(0,j.jsxs)(`p`,{className:`sr-only`,children:[`Step `,n,` of `,r,`.`]}),(0,j.jsx)(`div`,{"data-testid":`graph-explanation`,children:(0,j.jsx)(uQ,{children:(0,j.jsx)(rQ,{text:t.explanation,mode:`math`})})}),(0,j.jsxs)(`ul`,{className:`sr-only`,children:[[...t.nodes].map(([t,n])=>(0,j.jsxs)(`li`,{children:[`Node `,(0,j.jsx)(v0,{spec:e,id:t}),` is `,p0[n],`.`]},`n-${t}`)),[...t.edges].map(([t,n])=>(0,j.jsxs)(`li`,{children:[`Edge `,(0,j.jsx)(y0,{spec:e,index:t}),` is `,p0[n],`.`]},`e-${t}`)),t.variables.map((e,t)=>(0,j.jsxs)(`li`,{children:[e.name,` = `,String(e.value),`.`]},`v-${t}`))]})]})}function x0({spec:e}){let t=e.nodes.length,n=e.edges.length;return(0,j.jsxs)(`ul`,{className:`sr-only`,"data-testid":`graph-description`,children:[(0,j.jsxs)(`li`,{children:[e.directed?`Directed`:`Undirected`,` graph with `,t,` `,t===1?`node`:`nodes`,` and `,n,` `,n===1?`edge`:`edges`,`.`]}),(0,j.jsxs)(`li`,{children:[`Nodes:`,` `,e.nodes.map((t,n)=>(0,j.jsxs)(`span`,{children:[n>0&&`, `,(0,j.jsx)(v0,{spec:e,id:t.id})]},t.id))]}),e.edges.map((t,n)=>(0,j.jsxs)(`li`,{children:[`Edge: `,(0,j.jsx)(y0,{spec:e,index:n})]},`e-${n}`))]})}function S0({className:e,...t}){return(0,j.jsx)(`textarea`,{"data-slot":`textarea`,className:A(`flex field-sizing-content min-h-16 w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:aria-invalid:ring-destructive/40`,e),...t})}function C0({view:e,replyInProgress:t,onUpdate:n,onRefresh:r}){let{spec:i,latestAttempt:a}=e,[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(),f=(0,v.useId)(),p=a!==void 0,m=p||t||c,h=a?.grade.result===`answered`&&`text`in a.answer?a.answer.text:void 0,g=async t=>{if(m)return;l(!0),d(void 0);let i=await KM(e.id,t);if(i.ok)return l(!1),n(i.view);d(i.error);try{await r()}catch{}finally{l(!1)}},_=o.trim();return(0,j.jsxs)(pQ,{role:`region`,"aria-label":`Anything else to add`,children:[(0,j.jsx)(mQ,{kind:`Placement`,aside:`Optional`}),(0,j.jsxs)(gQ,{className:`gap-4`,children:[(0,j.jsx)(`label`,{htmlFor:f,className:`font-heading text-[1.2rem] leading-snug font-medium text-pretty`,children:(0,j.jsx)(rQ,{text:i.question,mode:`math`})}),p?h===void 0?(0,j.jsx)(`p`,{className:`text-muted-foreground text-sm font-medium`,children:`Skipped.`}):(0,j.jsx)(`p`,{className:`bg-sunken rounded-md px-3 py-2 text-sm whitespace-pre-wrap wrap-anywhere`,children:h}):(0,j.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),_&&g({text:_})},children:[(0,j.jsx)(S0,{id:f,value:o,maxLength:PA,rows:3,placeholder:`For example: I know the basics, but I want to go deep on one part of it.`,"aria-describedby":`${f}-help`,disabled:m,onChange:e=>s(e.target.value)}),(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,j.jsx)(M,{type:`submit`,size:`sm`,disabled:m||!_,children:`Send`}),(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`sm`,className:`text-muted-foreground`,disabled:m,onClick:()=>void g({skipped:!0}),children:`Skip`}),(0,j.jsxs)(`span`,{id:`${f}-help`,className:`text-muted-foreground ml-auto text-xs`,children:[`Fine to leave blank · `,o.length,`/`,PA]})]})]}),(0,j.jsxs)(`div`,{"aria-live":`polite`,className:`flex flex-col gap-1 text-sm`,children:[!p&&t&&(0,j.jsx)(`p`,{className:`text-muted-foreground`,children:`Answer once the reply finishes.`}),u&&(0,j.jsx)(`p`,{className:`text-destructive`,children:u})]})]})]})}var w0=ce(`relative grid w-full grid-cols-[0_1fr] items-start gap-y-0.5 rounded-lg border px-4 py-3 text-sm has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] has-[>svg]:gap-x-3 [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current`,{variants:{variant:{default:`bg-card text-card-foreground`,destructive:`bg-card text-destructive *:data-[slot=alert-description]:text-destructive/90 [&>svg]:text-current`}},defaultVariants:{variant:`default`}});function T0({className:e,variant:t,...n}){return(0,j.jsx)(`div`,{"data-slot":`alert`,role:`alert`,className:A(w0({variant:t}),e),...n})}function E0({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`alert-title`,className:A(`col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight`,e),...t})}function D0({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`alert-description`,className:A(`col-start-2 grid justify-items-start gap-1 text-sm text-muted-foreground [&_p]:leading-relaxed`,e),...t})}function O0({view:e,replyInProgress:t,onUpdate:n,onRefresh:r}){let{spec:i,latestAttempt:a}=e,[o,s]=(0,v.useState)(),[c,l]=(0,v.useState)(),u=a!==void 0,d=u||t||o!==void 0,f=a?.answer.optionIndex,p=a?.grade,m=async t=>{if(d)return;s(t),l(void 0);let i=await WM(e.id,t);if(i.ok)return s(void 0),n(i.view);l(i.error);try{await r()}catch{}finally{s(void 0)}},h=e=>{if(p)return e===p.correctOptionIndex?`correct`:e===f?`incorrect`:void 0},g=e=>p?e===f?p.correct?`✓ Your answer, correct`:`✗ Your answer, incorrect`:e===p.correctOptionIndex?`✓ Correct answer`:null:null;return(0,j.jsxs)(pQ,{role:`region`,"aria-label":`Check: ${i.concept}`,children:[(0,j.jsx)(mQ,{kind:`Check`,aside:`Graded against an answer key`,children:(0,j.jsx)(`span`,{className:`text-muted-foreground min-w-0 text-sm font-semibold wrap-anywhere`,children:i.concept})}),(0,j.jsxs)(gQ,{className:`gap-4`,children:[(0,j.jsx)(`div`,{"data-slot":`check-question`,className:`font-heading text-[1.2rem] leading-snug font-medium text-pretty`,children:(0,j.jsx)(rQ,{text:i.question,mode:`math`})}),(0,j.jsx)(`div`,{className:`flex flex-col gap-2`,role:`group`,"aria-label":`Options`,children:i.options.map((e,t)=>{let n=h(t);return(0,j.jsxs)(M,{type:`button`,variant:`outline`,"data-result":n,className:A(`border-border-strong dark:border-border-strong bg-card dark:bg-card hover:bg-sunken dark:hover:bg-sunken h-auto flex-wrap justify-start gap-x-3 gap-y-1 rounded-[10px] px-3.5 py-2.5 text-left font-medium whitespace-normal`,u&&`disabled:opacity-100`,o===t&&`border-foreground dark:border-foreground`,n===`correct`&&`border-success bg-success/10 dark:border-success dark:bg-success/15`,n===`incorrect`&&`border-destructive bg-destructive/10 dark:border-destructive dark:bg-destructive/15`),disabled:d,onClick:()=>void m(t),children:[(0,j.jsx)(_Q,{index:t}),(0,j.jsx)(`span`,{className:`min-w-0 flex-[1_1_10rem] wrap-anywhere`,children:(0,j.jsx)(rQ,{text:e.text,mode:`math`})}),g(t)&&(0,j.jsx)(`span`,{className:A(`shrink-0 pl-9 text-sm font-semibold sm:pl-0`,n===`incorrect`?`text-destructive`:`text-success`),children:g(t)})]},t)})}),(0,j.jsxs)(`div`,{"aria-live":`polite`,className:`flex flex-col gap-2`,children:[!u&&t&&(0,j.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Answer once the reply finishes.`}),c&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,children:c}),p&&(0,j.jsxs)(T0,{className:`bg-sunken border-0 px-4 py-3`,children:[(0,j.jsx)(E0,{className:A(`font-heading text-[1.15rem] font-medium`,p.correct?`text-success`:`text-destructive`),children:p.correct?`Correct!`:`Not quite.`}),(0,j.jsxs)(D0,{className:`text-foreground`,children:[p.feedback&&(0,j.jsx)(`p`,{children:(0,j.jsx)(rQ,{text:p.feedback,mode:`math`})}),(0,j.jsx)(`p`,{children:(0,j.jsx)(rQ,{text:p.explanation,mode:`math`})})]})]})]})]})]})}var k0=e=>e===`unsure`?{unsure:!0}:e===`skipped`?{skipped:!0}:{optionIndex:e};function A0({view:e,replyInProgress:t,onUpdate:n,onRefresh:r}){let{spec:i,latestAttempt:a}=e,[o,s]=(0,v.useState)(),[c,l]=(0,v.useState)(),u=a!==void 0,d=u||t||o!==void 0,f=a?.grade,p=a?.answer,m=p&&`optionIndex`in p?p.optionIndex:void 0,h=async t=>{if(d)return;s(t),l(void 0);let i=await GM(e.id,k0(t));if(i.ok)return s(void 0),n(i.view);l(i.error);try{await r()}catch{}finally{s(void 0)}},g=e=>{if(f)return e===f.correctOptionIndex?`correct`:e===m?`incorrect`:void 0},_=f?.result===`correct`?`Correct.`:f?.result===`incorrect`?`Not quite.`:f?.result===`unsure`?`Marked as not sure.`:`Skipped.`;return(0,j.jsxs)(pQ,{role:`region`,"aria-label":`Placement question: ${i.concept}`,children:[(0,j.jsx)(mQ,{kind:`Placement`,children:(0,j.jsx)(`span`,{className:`text-muted-foreground min-w-0 text-sm font-semibold wrap-anywhere`,children:i.concept})}),(0,j.jsxs)(gQ,{className:`gap-4`,children:[(0,j.jsx)(`div`,{className:`font-heading text-[1.2rem] leading-snug font-medium text-pretty`,children:(0,j.jsx)(rQ,{text:i.question,mode:`math`})}),(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-2`,role:`group`,"aria-label":`Answers`,children:[i.options.map((e,t)=>{let n=g(t);return(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,"data-result":n,"aria-pressed":m===t,className:A(`border-border-strong dark:border-border-strong bg-card dark:bg-card hover:bg-sunken dark:hover:bg-sunken h-auto max-w-full rounded-[10px] px-3.5 py-2 text-left font-medium whitespace-normal wrap-anywhere`,u&&`disabled:opacity-100`,o===t&&`border-foreground dark:border-foreground`,n===`correct`&&`border-success bg-success/10 dark:border-success dark:bg-success/15`,n===`incorrect`&&`border-destructive bg-destructive/10 dark:border-destructive dark:bg-destructive/15`),disabled:d,onClick:()=>void h(t),children:(0,j.jsx)(rQ,{text:e.text,mode:`math`})},t)}),(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`sm`,"aria-pressed":f?.result===`unsure`,className:A(u&&`disabled:opacity-100`,f?.result===`unsure`&&`bg-muted`),disabled:d,onClick:()=>void h(`unsure`),children:`Not sure`}),(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`sm`,"aria-pressed":f?.result===`skipped`,className:A(`text-muted-foreground`,u&&`disabled:opacity-100`,f?.result===`skipped`&&`bg-muted`),disabled:d,onClick:()=>void h(`skipped`),children:`Skip`})]}),(0,j.jsxs)(`div`,{"aria-live":`polite`,className:`flex flex-col gap-1 text-sm`,children:[!u&&t&&(0,j.jsx)(`p`,{className:`text-muted-foreground`,children:`Answer once the reply finishes.`}),c&&(0,j.jsx)(`p`,{className:`text-destructive`,children:c}),f&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`p`,{className:A(`font-medium`,f.result===`correct`?`text-success`:f.result===`incorrect`?`text-destructive`:`text-muted-foreground`),children:_}),f.result!==`skipped`&&(0,j.jsx)(`p`,{className:`text-muted-foreground`,children:(0,j.jsx)(rQ,{text:f.explanation,mode:`math`})})]})]})]})]})}var j0=380,M0=100,N0={1:{width:j0,height:320,radius:M0,circles:[{x:190,y:148}],slots:{1:{x:190,y:148,width:136,rows:5},0:{x:318,y:278,width:106,rows:3}}},2:{width:j0,height:320,radius:M0,circles:[{x:135,y:148},{x:245,y:148}],slots:{1:{x:104,y:148,width:76,rows:5},2:{x:276,y:148,width:76,rows:5},3:{x:190,y:148,width:53,rows:3},0:{x:318,y:288,width:106,rows:2}}},3:{width:j0,height:410,radius:M0,circles:[{x:138,y:148},{x:242,y:148},{x:190,y:238}],slots:{1:{x:100,y:116,width:76,rows:2},2:{x:280,y:116,width:76,rows:2},4:{x:190,y:280,width:124,rows:2},3:{x:190,y:116,width:64,rows:1},5:{x:124,y:220,width:53,rows:1},6:{x:256,y:220,width:53,rows:1},7:{x:190,y:172,width:53,rows:2},0:{x:318,y:366,width:106,rows:3}}}},P0=16/(230/j0);function F0(e,t,n){let r=n/e.width;return{width:t.width*r,height:t.rows*P0*r}}var I0=.5,L0=(e,t)=>e.width<=t.width+I0&&e.height<=t.height+I0;function R0(e,t,n){return L0(t,e)?`contents`:L0(n,e)?`marker`:`arrow`}function z0(e){return Array.from({length:2**e},(e,t)=>t)}function B0({circles:e,radius:t},n){let r=[];return e.forEach((i,a)=>{let o=e=>({x:i.x+t*Math.cos(e),y:i.y+t*Math.sin(e)}),s=e.flatMap((e,n)=>{if(n===a)return[];let r=Math.atan2(e.y-i.y,e.x-i.x),o=Math.acos(Math.hypot(e.x-i.x,e.y-i.y)/(2*t));return[r-o,r+o]}),c=(s.length?s:[0,Math.PI]).map(e=>(e+2*Math.PI)%(2*Math.PI)).sort((e,t)=>e-t);c.forEach((i,s)=>{let l=s+1<c.length?c[s+1]:c[0]+2*Math.PI,u=o((i+l)/2);if(!e.every((e,r)=>r===a||Math.hypot(u.x-e.x,u.y-e.y)<t==!!(n&1<<r)))return;let d=l-i>Math.PI;r.push(n&1<<a?{from:o(i),to:o(l),large:d,sweep:1}:{from:o(l),to:o(i),large:d,sweep:0})})}),r}var V0=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y)<1e-6,H0=e=>String(Math.round(e*100)/100);function U0(e,t){let{radius:n,width:r,height:i}=e,a=B0(e,t),o=[];for(;a.length;){let e=a.shift(),t=`M${H0(e.from.x)} ${H0(e.from.y)}`,r=e;for(;r;){let{to:e,large:i,sweep:o}=r;t+=`A${n} ${n} 0 ${+!!i} ${o} ${H0(e.x)} ${H0(e.y)}`;let s=a.findIndex(t=>V0(t.from,e));r=s>=0?a.splice(s,1)[0]:void 0}o.push(`${t}Z`)}return t===0&&o.unshift(W0(r,i)),o.join(``)}var W0=(e,t)=>`M1 1H${e-1}V${t-1}H1Z`,G0={active:{word:`Focus`,tint:`fill-foreground/15`,pattern:`hatch`,line:`stroke-foreground`,outline:``},done:{word:`Done`,tint:`fill-success/20`,pattern:`dots`,line:`stroke-success`,outline:``},muted:{word:`Ruled out`,tint:`fill-muted-foreground/15`,pattern:``,line:`stroke-muted-foreground`,outline:`5 4`}};function K0(e,t){return e.sets.reduce((e,n,r)=>t.includes(n.id)?e|1<<r:e,0)}function q0(e,t){let n=e.steps?.[t],r=new Map;for(let t of n?.highlights??[])r.set(K0(e,t.in),t.tone??`active`);return{explanation:n?.explanation??``,tones:r,variables:n?.variables??[]}}function J0(e){return z0(e.sets.length).filter(t=>t!==0||e.universe!==void 0).sort((e,t)=>e===0?1:t===0?-1:e-t)}var Y0=e=>String(e);function X0({text:e}){return(0,j.jsx)(rQ,{text:e,mode:`math`})}function Z0({elements:e}){return e.map((e,t)=>(0,j.jsxs)(v.Fragment,{children:[t>0&&`, `,(0,j.jsx)(X0,{text:Y0(e)})]},t))}function Q0(e,t){return e.map((n,r)=>(0,j.jsxs)(v.Fragment,{children:[r>0&&(r===e.length-1?` ${t} `:`, `),n]},r))}function $0({spec:e,mask:t}){let n=e=>(0,j.jsx)(X0,{text:e.label},e.id),r=e.sets.filter((e,n)=>t&1<<n).map(n),i=e.sets.filter((e,n)=>!(t&1<<n)).map(n);return r.length===0?(0,j.jsxs)(j.Fragment,{children:[`outside `,Q0(i,`and`)]}):(0,j.jsxs)(j.Fragment,{children:[`in `,Q0(r,`and`),i.length>0&&(0,j.jsxs)(j.Fragment,{children:[`, not `,Q0(i,`or`)]})]})}var e2=e=>e.count??e.elements.length;function t2({total:e}){return(0,j.jsxs)(`span`,{className:`whitespace-nowrap`,children:[`n = `,e]})}function n2({region:e}){let t=e2(e);return e.elements.length===0?(0,j.jsx)(t2,{total:t}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(Z0,{elements:e.elements}),t!==e.elements.length&&(0,j.jsxs)(j.Fragment,{children:[` `,`(`,(0,j.jsx)(t2,{total:t}),`)`]})]})}function r2({slot:e,layout:t,children:n,...r}){let i=(e,t)=>`${e/t*100}%`;return(0,j.jsx)(`div`,{className:`absolute flex -translate-x-1/2 -translate-y-1/2 items-center justify-center text-center font-mono text-xs leading-4`,style:{left:i(e.x,t.width),top:i(e.y,t.height),width:i(e.width,t.width),height:i(e.rows*P0,t.height)},...r,children:(0,j.jsx)(`span`,{className:`bg-card/85 rounded-sm px-0.5`,children:n})})}function i2(e){let{width:t,height:n}=e.getBoundingClientRect();return{width:t+[...e.querySelectorAll(`.katex`)].reduce((e,t)=>e+Math.max(0,t.scrollWidth-t.clientWidth),0),height:n}}function a2(e){return[e,...e.querySelectorAll(`.katex`)].some(e=>e.scrollWidth>e.clientWidth)}function o2(e,t){let n=(0,v.useRef)(null),[r,i]=(0,v.useState)(new Map),[a,o]=(0,v.useState)([]);return(0,v.useLayoutEffect)(()=>{let r=n.current,a=0,s=()=>{if(a=r.getBoundingClientRect().width,a===0)return;let n=new Map;for(let i of J0(e)){let e=r.querySelector(`[data-probe="contents"][data-mask="${i}"] > span`),o=r.querySelector(`[data-probe="marker"][data-mask="${i}"] > span`);e&&o&&n.set(i,R0(F0(t,t.slots[i],a),i2(e),i2(o)))}i(e=>n.size===e.size&&[...n].every(([t,n])=>e.get(t)===n)?e:n);let s=[...r.querySelectorAll(`[data-label]`)].filter(a2).map(e=>e.dataset.label);o(e=>e.join()===s.join()?e:s)};s();let c=typeof ResizeObserver>`u`?void 0:new ResizeObserver(()=>{r.getBoundingClientRect().width!==a&&(0,It.flushSync)(s)});return c?.observe(r),document.fonts?.addEventListener(`loadingdone`,s),()=>{c?.disconnect(),document.fonts?.removeEventListener(`loadingdone`,s)}},[e,t]),[n,r,a]}var s2=[`Top left`,`Top right`,`Bottom left`];function c2(e,t){return e===0?{left:`2%`,top:`1.5%`,width:`45%`}:e===1?{right:`2%`,top:`1.5%`,width:`45%`,textAlign:`right`}:{left:`2%`,bottom:`1.5%`,width:t===3?`30%`:`45%`}}function l2({d:e,mask:t,tone:n,ids:r}){let i=n&&G0[n],a=`${r.clip}-${t}`;return(0,j.jsxs)(`g`,{"data-testid":`set-region`,"data-mask":t,"data-tone":n??`none`,children:[(0,j.jsx)(`path`,{d:e,fillRule:`evenodd`,className:i?i.tint:`fill-transparent`,"data-testid":`set-region-shape`}),i&&(0,j.jsxs)(j.Fragment,{children:[i.pattern&&(0,j.jsx)(`path`,{d:e,fillRule:`evenodd`,fill:`url(#${i.pattern===`hatch`?r.hatch:r.dots})`}),(0,j.jsx)(`clipPath`,{id:a,children:(0,j.jsx)(`path`,{d:e,clipRule:`evenodd`})}),(0,j.jsx)(`path`,{d:e,clipPath:`url(#${a})`,fill:`none`,strokeWidth:6,strokeDasharray:i.outline||void 0,className:i.line})]})]})}function u2({spec:e,layout:t,tones:n,fits:r,drawing:i}){let a=(0,v.useId)().replace(/[^a-zA-Z0-9_-]/g,``),o={hatch:`${a}-hatch`,dots:`${a}-dots`,clip:`${a}-clip`},{width:s,height:c,radius:l,circles:u,slots:d}=t,f=J0(e),p=new Map(e.regions.map(t=>[K0(e,t.in),t]));return(0,j.jsxs)(`div`,{ref:i,className:`relative mx-auto w-full max-w-md`,style:{aspectRatio:`${s} / ${c}`},"aria-hidden":`true`,inert:!0,"data-testid":`set-diagram`,children:[(0,j.jsxs)(`svg`,{viewBox:`0 0 ${s} ${c}`,className:`absolute inset-0 size-full`,children:[(0,j.jsxs)(`defs`,{children:[(0,j.jsx)(`pattern`,{id:o.hatch,patternUnits:`userSpaceOnUse`,width:`10`,height:`10`,patternTransform:`rotate(45)`,children:(0,j.jsx)(`line`,{x1:`0`,y1:`0`,x2:`0`,y2:`10`,strokeWidth:`2`,className:`stroke-foreground/45`})}),(0,j.jsx)(`pattern`,{id:o.dots,patternUnits:`userSpaceOnUse`,width:`10`,height:`10`,children:(0,j.jsx)(`circle`,{cx:`5`,cy:`5`,r:`1.6`,className:`fill-success/70`})})]}),f.map(e=>(0,j.jsx)(l2,{d:U0(t,e),mask:e,tone:n.get(e),ids:o},e)),e.universe!==void 0&&(0,j.jsx)(`rect`,{x:1,y:1,width:s-2,height:c-2,strokeWidth:`1.5`,className:`stroke-muted-foreground fill-none`,"data-testid":`set-universe`}),u.map((e,t)=>(0,j.jsx)(`circle`,{cx:e.x,cy:e.y,r:l,strokeWidth:`1.5`,className:`stroke-foreground/70 fill-none`,"data-testid":`set-circle`},t))]}),e.sets.map((t,n)=>(0,j.jsx)(`div`,{className:`absolute text-xs leading-4 font-medium`,style:c2(n,e.sets.length),"data-testid":`set-label`,"data-label":n,children:(0,j.jsx)(`span`,{className:`bg-card/85 rounded-sm px-0.5`,children:(0,j.jsx)(X0,{text:t.label})})},t.id)),e.universe!==void 0&&(0,j.jsx)(`div`,{className:`text-muted-foreground absolute bottom-[1.5%] left-1/2 w-[36%] -translate-x-1/2 text-center text-xs leading-4`,"data-testid":`set-universe-label`,"data-label":`universe`,children:(0,j.jsx)(`span`,{className:`bg-card/85 rounded-sm px-0.5`,children:(0,j.jsx)(X0,{text:e.universe})})}),f.map(e=>{let n=p.get(e);if(!n)return null;let i=r.get(e)??`contents`;return(0,j.jsx)(r2,{slot:d[e],layout:t,"data-testid":`set-elements`,"data-mask":e,"data-fit":i,children:e2(n)===0?`∅`:i===`contents`?(0,j.jsx)(n2,{region:n}):i===`marker`?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(t2,{total:e2(n)}),` ↓`]}):`↓`},e)}),(0,j.jsx)(`div`,{className:`invisible absolute inset-0 overflow-hidden`,children:f.map(e=>{let n=p.get(e);return!n||e2(n)===0?null:(0,j.jsxs)(v.Fragment,{children:[(0,j.jsx)(r2,{slot:d[e],layout:t,"data-probe":`contents`,"data-mask":e,children:(0,j.jsx)(n2,{region:n})}),(0,j.jsxs)(r2,{slot:d[e],layout:t,"data-probe":`marker`,"data-mask":e,children:[(0,j.jsx)(t2,{total:e2(n)}),` ↓`]})]},e)})})]})}function d2({view:e}){let{spec:t}=e,n=t.steps?.length??0,r=lQ(n),{index:i}=r,a=(0,v.useId)(),o=(0,v.useId)(),s=N0[t.sets.length],c=q0(t,i),l=J0(t),u=new Map(t.regions.map(e=>[K0(t,e.in),e])),d=l.filter(e=>c.tones.has(e)),[f,p,m]=o2(t,s),h=l.filter(e=>(p.get(e)??`contents`)!==`contents`);return(0,j.jsxs)(pQ,{role:`region`,"aria-labelledby":`${a} ${o}`,...n>0?{tabIndex:0,onKeyDown:r.onKeyDown}:{},children:[(0,j.jsx)(mQ,{kind:`Set diagram`,kindId:o,children:(0,j.jsx)(hQ,{id:a,text:t.title})}),(0,j.jsxs)(gQ,{children:[(0,j.jsxs)(`ul`,{className:`sr-only`,"data-testid":`set-description`,children:[t.sets.map(e=>(0,j.jsxs)(`li`,{children:[`Set: `,(0,j.jsx)(X0,{text:e.label})]},e.id)),t.universe!==void 0&&(0,j.jsxs)(`li`,{children:[`Universe: `,(0,j.jsx)(X0,{text:t.universe})]}),l.map(e=>{let n=u.get(e);if(!n)return null;let r=n.elements.length===0&&!n.count;return(0,j.jsxs)(`li`,{children:[(0,j.jsx)($0,{spec:t,mask:e}),`: `,r&&`empty`,(0,j.jsx)(Z0,{elements:n.elements}),n.count!==void 0&&n.count!==n.elements.length&&!r&&`${n.elements.length>0?`, `:``}${n.count} in total`]},e)})]}),(0,j.jsx)(u2,{spec:t,layout:s,tones:c.tones,fits:p,drawing:f}),(h.length>0||m.length>0)&&(0,j.jsxs)(`div`,{className:`flex flex-col gap-1 text-xs`,"data-testid":`set-overflow`,children:[(0,j.jsx)(`p`,{"aria-hidden":`true`,className:`text-muted-foreground`,children:`↓ Doesn't fit in the diagram:`}),m.map(e=>(0,j.jsxs)(dQ,{children:[(0,j.jsxs)(`span`,{className:`font-medium`,children:[e===`universe`?`Universe`:`${s2[Number(e)]} label`,`:`]}),` `,(0,j.jsx)(X0,{text:e===`universe`?t.universe:t.sets[Number(e)].label})]},e)),h.map(e=>(0,j.jsxs)(dQ,{children:[(0,j.jsxs)(`span`,{className:`font-medium`,children:[(0,j.jsx)($0,{spec:t,mask:e}),`:`]}),` `,(0,j.jsx)(`span`,{className:`font-mono`,children:(0,j.jsx)(n2,{region:u.get(e)})})]},e))]}),d.length>0&&(0,j.jsx)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-xs`,"data-testid":`set-key`,children:d.map(e=>{let n=c.tones.get(e);return(0,j.jsx)(`div`,{className:`max-w-full min-w-0`,"data-tone":n,children:(0,j.jsxs)(dQ,{children:[(0,j.jsxs)(`span`,{className:`font-medium`,children:[G0[n].word,`:`]}),` `,(0,j.jsx)($0,{spec:t,mask:e})]})},e)})}),c.variables.length>0&&(0,j.jsx)(`div`,{className:`flex flex-wrap gap-2`,"data-testid":`set-variables`,children:c.variables.map((e,t)=>(0,j.jsx)(`div`,{className:`border-border-strong bg-card max-w-full min-w-0 rounded-md border px-2 py-0.5 font-mono text-xs`,children:(0,j.jsxs)(dQ,{children:[(0,j.jsx)(X0,{text:e.name}),` = `,(0,j.jsx)(X0,{text:String(e.value)})]})},t))}),n>0&&(0,j.jsx)(j.Fragment,{children:(0,j.jsxs)(`div`,{"aria-live":`polite`,"aria-atomic":`true`,"data-testid":`set-announcement`,children:[(0,j.jsxs)(`span`,{className:`sr-only`,children:[`Step `,i+1,` of `,n,`:`,` `]}),(0,j.jsx)(`div`,{"data-testid":`set-explanation`,children:(0,j.jsx)(uQ,{children:(0,j.jsx)(rQ,{text:c.explanation,mode:`math`})})}),(0,j.jsxs)(`span`,{className:`sr-only`,children:[d.length===0&&`Nothing highlighted. `,d.map(e=>(0,j.jsxs)(v.Fragment,{children:[G0[c.tones.get(e)].word,`: `,(0,j.jsx)($0,{spec:t,mask:e}),`.`,` `]},e)),c.variables.map((e,t)=>(0,j.jsxs)(v.Fragment,{children:[(0,j.jsx)(X0,{text:e.name}),` = `,(0,j.jsx)(X0,{text:String(e.value)}),`.`,` `]},t))]})]})})]}),n>0&&(0,j.jsx)(fQ,{stepper:r,play:!0})]})}var f2={active:`Highlighted`,done:`Done`,muted:`Ruled out`};function p2(e,t){let n=e.rows.map(e=>[...e]);for(let r of e.steps?.slice(0,t+1)??[])for(let{row:e,column:t,value:i}of r.cells??[])n[e]&&t<n[e].length&&(n[e][t]=i);let r=e.steps?.[t];return{rows:n,explanation:r?.explanation,highlight:r?.highlight??[],changes:r?.cells??[]}}var m2=e=>typeof e==`boolean`?e?`T`:`F`:String(e),h2=({row:e,column:t})=>[e!==void 0&&`row ${e+1}`,t!==void 0&&`column ${t+1}`].filter(Boolean).join(`, `),g2=`wrap-normal!`;function _2({view:e}){let{spec:t}=e,n=lQ(t.steps?.length??1),r=p2(t,n.index),i=e=>{let t=r.highlight.findLast(e);return t&&(t.tone??`active`)},a=t.steps!==void 0,o=(0,v.useId)(),s=(0,v.useId)();return(0,j.jsxs)(pQ,{role:`region`,"aria-labelledby":`${o} ${s}`,...a?{tabIndex:0,onKeyDown:n.onKeyDown}:{},children:[(0,j.jsx)(mQ,{kind:`Table`,kindId:s,children:(0,j.jsx)(hQ,{id:o,text:t.title})}),(0,j.jsxs)(gQ,{children:[(0,j.jsx)(`div`,{className:`overflow-x-auto`,role:`group`,"aria-label":`Table contents, scrolls sideways`,tabIndex:0,"data-testid":`table-scroll`,onKeyDown:e=>{(e.key===`ArrowLeft`||e.key===`ArrowRight`)&&e.stopPropagation()},children:(0,j.jsxs)(`table`,{className:`mx-auto border-collapse text-sm`,children:[(0,j.jsx)(`caption`,{className:`sr-only`,children:(0,j.jsx)(rQ,{text:t.title,mode:`math`})}),(0,j.jsx)(`thead`,{children:(0,j.jsxs)(`tr`,{children:[t.rowHeaders&&(0,j.jsx)(`td`,{className:`border-b px-3 py-1.5`}),t.columns.map((e,t)=>{let n=i(e=>e.column===t&&e.row===void 0);return(0,j.jsx)(`th`,{scope:`col`,className:A(`border-b px-3 py-1.5 text-center font-medium`,n&&sQ[n]),children:(0,j.jsx)(rQ,{text:e,mode:`math`,className:g2})},t)})]})}),(0,j.jsx)(`tbody`,{children:r.rows.map((e,n)=>{let r=i(e=>e.row===n&&e.column===void 0),a=t.rowHeaders?.[n];return(0,j.jsxs)(`tr`,{className:`border-b last:border-b-0`,children:[a!==void 0&&(0,j.jsx)(`th`,{scope:`row`,className:A(`border-r px-3 py-1.5 text-center font-medium`,r&&sQ[r]),children:(0,j.jsx)(rQ,{text:a,mode:`math`,className:g2})}),e.map((e,t)=>{let r=i(e=>(e.row===void 0||e.row===n)&&(e.column===void 0||e.column===t));return(0,j.jsx)(`td`,{className:A(`px-3 py-1.5 text-center tabular-nums`,r&&sQ[r]),"data-tone":r,"data-testid":`table-cell`,children:(0,j.jsx)(rQ,{text:m2(e),mode:`math`,className:g2})},t)})]},n)})})]})}),a&&(0,j.jsxs)(`div`,{"aria-live":`polite`,"aria-atomic":`true`,"data-testid":`table-live`,children:[(0,j.jsxs)(`span`,{className:`sr-only`,children:[`Step `,n.index+1,` of `,n.last+1,`.`,` `]}),(0,j.jsx)(uQ,{children:(0,j.jsx)(rQ,{text:r.explanation??``,mode:`math`})}),(0,j.jsxs)(`span`,{className:`sr-only`,"data-testid":`table-description`,children:[r.highlight.map(e=>` ${f2[e.tone??`active`]}: ${h2(e)}.`),r.changes.map(e=>` Changed ${h2(e)} to ${m2(e.value)}.`)]})]})]}),(0,j.jsx)(fQ,{stepper:n,play:!0})]})}function v2({view:e}){let{spec:t}=e,n=lQ(t.steps.length),{index:r,last:i,go:a}=n,o=r===i,s=t.steps[r],c=(0,v.useId)(),l=(0,v.useId)();return(0,j.jsxs)(pQ,{role:`region`,"aria-labelledby":`${c} ${l}`,tabIndex:0,onKeyDown:n.onKeyDown,children:[(0,j.jsx)(mQ,{kind:`Worked steps`,kindId:l,children:(0,j.jsx)(hQ,{id:c,text:t.title})}),(0,j.jsxs)(gQ,{children:[t.goal&&(0,j.jsx)(`p`,{className:`bg-sunken rounded-lg px-3.5 py-2.5 leading-normal`,children:(0,j.jsxs)(uQ,{children:[(0,j.jsx)(`span`,{className:`font-semibold`,children:`Goal: `}),(0,j.jsx)(rQ,{text:t.goal,mode:`math`})]})}),(0,j.jsx)(`ol`,{className:`flex flex-col`,children:t.steps.slice(0,r+1).map((e,t)=>(0,j.jsxs)(`li`,{"aria-current":t===r?`step`:void 0,className:`group relative flex min-w-0 flex-col gap-0.5 border-t py-2.5 pl-9 first:border-t-0 first:pt-0.5 last:pb-0`,"data-testid":`worked-step`,children:[(0,j.jsx)(`span`,{"aria-hidden":`true`,className:A(`absolute top-2.5 left-0 grid size-6 place-items-center rounded-full font-mono text-[0.7rem] font-medium group-first:top-0.5`,t===r?cQ.current:cQ.other),"data-testid":`worked-step-number`,children:t+1}),e.label&&(0,j.jsx)(`p`,{className:`text-muted-foreground font-mono text-[0.6875rem] font-medium tracking-[0.06em] uppercase`,children:(0,j.jsx)(uQ,{children:(0,j.jsx)(rQ,{text:e.label,mode:`math`})})}),(0,j.jsx)(`div`,{className:`font-heading text-[1.0625rem] leading-normal`,children:(0,j.jsx)(uQ,{children:(0,j.jsx)(rQ,{text:e.statement,mode:`math`})})}),(0,j.jsx)(`p`,{className:`text-muted-foreground text-sm leading-snug`,children:(0,j.jsx)(uQ,{children:(0,j.jsx)(rQ,{text:e.justification,mode:`math`})})})]},t))}),(0,j.jsxs)(`div`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,"data-testid":`worked-status`,children:[`Step `,r+1,` of `,i+1,`.`,` `,s?.label&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(rQ,{text:s.label,mode:`math`}),`.`,` `]}),s&&(0,j.jsx)(rQ,{text:s.statement,mode:`math`}),` `,s&&(0,j.jsx)(rQ,{text:s.justification,mode:`math`})]})]}),(0,j.jsx)(fQ,{stepper:n,children:(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`sm`,className:`text-muted-foreground hover:text-foreground decoration-border-strong underline underline-offset-4 hover:bg-transparent dark:hover:bg-transparent`,onClick:()=>a(o?0:i),children:o?`Start over`:`Show all`})})]})}var y2={algorithm_trace:SQ,code_walkthrough:TQ,graph:g0,interview_context:C0,multiple_choice:O0,placement_question:A0,set_diagram:d2,table:_2,worked_steps:v2};function b2({data:e,replyInProgress:t,onUpdate:n,onRefresh:r}){let i=wM.safeParse(e);if(!i.success)return(0,j.jsx)(`div`,{className:`text-muted-foreground rounded-lg border border-dashed p-3 text-sm`,role:`note`,children:`Can't display this item.`});let a=i.data,o=y2[a.kind];return(0,j.jsx)(o,{view:a,replyInProgress:t,onUpdate:n,onRefresh:r})}function x2(e,t,n){return(e===`submitted`||e===`streaming`)&&t===n-1}function S2(e,t){return e.id&&t[e.id]||e.data}function C2(e){let t={};for(let n of e)for(let e of n.parts){if(e.type!==`data-artifact`)continue;let n=wM.safeParse(e.data);n.success&&(t[n.data.id]=n.data)}return t}var w2=e=>e?.kind===`multiple_choice`&&e.latestAttempt!==void 0;function T2(e,t){let n={...e};for(let[r,i]of Object.entries(t))(!w2(e[r])||w2(i))&&(n[r]=i);return n}var E2=ce(`inline-flex w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-full border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3`,{variants:{variant:{default:`bg-primary text-primary-foreground [a&]:hover:bg-primary/90`,secondary:`bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90`,destructive:`bg-destructive text-white focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40 [a&]:hover:bg-destructive/90`,outline:`border-border text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground`,ghost:`[a&]:hover:bg-accent [a&]:hover:text-accent-foreground`,link:`text-primary underline-offset-4 [a&]:hover:underline`}},defaultVariants:{variant:`default`}});function D2({className:e,variant:t=`default`,asChild:n=!1,...r}){let i=n?Gt:`span`;return(0,j.jsx)(i,{"data-slot":`badge`,"data-variant":t,className:A(E2({variant:t}),e),...r})}function O2({...e}){return(0,j.jsx)(wr,{"data-slot":`collapsible`,...e})}function k2({...e}){return(0,j.jsx)(Er,{"data-slot":`collapsible-trigger`,...e})}function A2({...e}){return(0,j.jsx)(Or,{"data-slot":`collapsible-content`,...e})}function j2({className:e,...t}){return(0,j.jsx)(Ed,{"data-slot":`label`,className:A(`flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50`,e),...t})}function M2({className:e,orientation:t=`horizontal`,decorative:n=!0,...r}){return(0,j.jsx)(Mp,{"data-slot":`separator`,decorative:n,orientation:t,className:A(`shrink-0 bg-border data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px`,e),...r})}var N2=ce(`group/field flex w-full gap-3 data-[invalid=true]:text-destructive`,{variants:{orientation:{vertical:[`flex-col [&>*]:w-full [&>.sr-only]:w-auto`],horizontal:[`flex-row items-center`,`[&>[data-slot=field-label]]:flex-auto`,`has-[>[data-slot=field-content]]:items-start has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px`],responsive:[`flex-col @md/field-group:flex-row @md/field-group:items-center [&>*]:w-full @md/field-group:[&>*]:w-auto [&>.sr-only]:w-auto`,`@md/field-group:[&>[data-slot=field-label]]:flex-auto`,`@md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px`]}},defaultVariants:{orientation:`vertical`}});function P2({className:e,orientation:t=`vertical`,...n}){return(0,j.jsx)(`div`,{role:`group`,"data-slot":`field`,"data-orientation":t,className:A(N2({orientation:t}),e),...n})}function F2({className:e,...t}){return(0,j.jsx)(j2,{"data-slot":`field-label`,className:A(`group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50`,`has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border [&>*]:data-[slot=field]:p-4`,`has-data-[state=checked]:border-primary has-data-[state=checked]:bg-primary/5 dark:has-data-[state=checked]:bg-primary/10`,e),...t})}function I2({className:e,...t}){return(0,j.jsx)(`p`,{"data-slot":`field-description`,className:A(`text-sm leading-normal font-normal text-muted-foreground group-has-[[data-orientation=horizontal]]/field:text-balance`,`last:mt-0 nth-last-2:-mt-1 [[data-variant=legend]+&]:-mt-1.5`,`[&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary`,e),...t})}function L2({className:e,children:t,errors:n,...r}){let i=(0,v.useMemo)(()=>{if(t)return t;if(!n?.length)return null;let e=[...new Map(n.map(e=>[e?.message,e])).values()];return e?.length==1?e[0]?.message:(0,j.jsx)(`ul`,{className:`ml-4 flex list-disc flex-col gap-1`,children:e.map((e,t)=>e?.message&&(0,j.jsx)(`li`,{children:e.message},t))})},[t,n]);return i?(0,j.jsx)(`div`,{role:`alert`,"data-slot":`field-error`,className:A(`text-sm font-normal text-destructive`,e),...r,children:i}):null}function R2({className:e,...t}){return(0,j.jsx)(rg,{role:`status`,"aria-label":`Loading`,className:A(`size-4 animate-spin motion-reduce:animate-none`,e),...t})}function z2({className:e,type:t,...n}){return(0,j.jsx)(`input`,{type:t,"data-slot":`input`,className:A(`h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none selection:bg-primary selection:text-primary-foreground file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:bg-input/30`,`focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50`,`aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40`,e),...n})}var B2=1,V2=.9,H2=.8,U2=.17,W2=.1,G2=.999,K2=.9999,q2=.99,J2=/[\\\/_+.#"@\[\(\{&]/,Y2=/[\\\/_+.#"@\[\(\{&]/g,X2=/[\s-]/,Z2=/[\s-]/g;function Q2(e,t,n,r,i,a,o){if(a===t.length)return i===e.length?B2:q2;var s=`${i},${a}`;if(o[s]!==void 0)return o[s];for(var c=r.charAt(a),l=n.indexOf(c,i),u=0,d,f,p,m;l>=0;)d=Q2(e,t,n,r,l+1,a+1,o),d>u&&(l===i?d*=B2:J2.test(e.charAt(l-1))?(d*=H2,p=e.slice(i,l-1).match(Y2),p&&i>0&&(d*=G2**+p.length)):X2.test(e.charAt(l-1))?(d*=V2,m=e.slice(i,l-1).match(Z2),m&&i>0&&(d*=G2**+m.length)):(d*=U2,i>0&&(d*=G2**+(l-i))),e.charAt(l)!==t.charAt(a)&&(d*=K2)),(d<W2&&n.charAt(l-1)===r.charAt(a+1)||r.charAt(a+1)===r.charAt(a)&&n.charAt(l-1)!==r.charAt(a))&&(f=Q2(e,t,n,r,l+1,a+2,o),f*W2>d&&(d=f*W2)),d>u&&(u=d),l=n.indexOf(c,l+1);return o[s]=u,u}function $2(e){return e.toLowerCase().replace(Z2,` `)}function e4(e,t,n){return e=n&&n.length>0?`${e+` `+n.join(` `)}`:e,Q2(e,t,$2(e),$2(t),0,0,{})}var t4=`[cmdk-group=""]`,n4=`[cmdk-group-items=""]`,r4=`[cmdk-group-heading=""]`,i4=`[cmdk-item=""]`,a4=`${i4}:not([aria-disabled="true"])`,o4=`cmdk-item-select`,s4=`data-value`,c4=(e,t,n)=>e4(e,t,n),l4=v.createContext(void 0),u4=()=>v.useContext(l4),d4=v.createContext(void 0),f4=()=>v.useContext(d4),p4=v.createContext(void 0),m4=v.forwardRef((e,t)=>{let n=O4(()=>({search:``,value:e.value??e.defaultValue??``,selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}})),r=O4(()=>new Set),i=O4(()=>new Map),a=O4(()=>new Map),o=O4(()=>new Set),s=E4(e),{label:c,children:l,value:u,onValueChange:d,filter:f,shouldFilter:p,loop:m,disablePointerSelection:h=!1,vimBindings:g=!0,..._}=e,y=gr(),b=gr(),x=gr(),S=v.useRef(null),C=j4();D4(()=>{if(u!==void 0){let e=u.trim();n.current.value=e,w.emit()}},[u]),D4(()=>{C(6,ne)},[]);let w=v.useMemo(()=>({subscribe:e=>(o.current.add(e),()=>o.current.delete(e)),snapshot:()=>n.current,setState:(e,t,r)=>{var i,a,o;if(!Object.is(n.current[e],t)){if(n.current[e]=t,e===`search`)te(),D(),C(1,ee);else if(e===`value`){if(document.activeElement.hasAttribute(`cmdk-input`)||document.activeElement.hasAttribute(`cmdk-root`)){let e=document.getElementById(x);e?e.focus():(i=document.getElementById(y))==null||i.focus()}if(C(7,()=>{n.current.selectedItemId=re()?.id,w.emit()}),r||C(5,ne),s.current?.value!==void 0){let e=t??``;(o=(a=s.current).onValueChange)==null||o.call(a,e);return}}w.emit()}},emit:()=>{o.current.forEach(e=>e())}}),[]),T=v.useMemo(()=>({value:(e,t,r)=>{t!==a.current.get(e)?.value&&(a.current.set(e,{value:t,keywords:r}),n.current.filtered.items.set(e,E(t,r)),C(2,()=>{D(),w.emit()}))},item:(e,t)=>(r.current.add(e),t&&(i.current.has(t)?i.current.get(t).add(e):i.current.set(t,new Set([e]))),C(3,()=>{te(),D(),n.current.value||ee(),w.emit()}),()=>{a.current.delete(e),r.current.delete(e),n.current.filtered.items.delete(e);let t=re();C(4,()=>{te(),t?.getAttribute(`id`)===e&&ee(),w.emit()})}),group:e=>(i.current.has(e)||i.current.set(e,new Set),()=>{a.current.delete(e),i.current.delete(e)}),filter:()=>s.current.shouldFilter,label:c||e[`aria-label`],getDisablePointerSelection:()=>s.current.disablePointerSelection,listId:y,inputId:x,labelId:b,listInnerRef:S}),[]);function E(e,t){let r=s.current?.filter??c4;return e?r(e,n.current.search,t):0}function D(){if(!n.current.search||s.current.shouldFilter===!1)return;let e=n.current.filtered.items,t=[];n.current.filtered.groups.forEach(n=>{let r=i.current.get(n),a=0;r.forEach(t=>{let n=e.get(t);a=Math.max(n,a)}),t.push([n,a])});let r=S.current;ie().sort((t,n)=>{let r=t.getAttribute(`id`),i=n.getAttribute(`id`);return(e.get(i)??0)-(e.get(r)??0)}).forEach(e=>{let t=e.closest(n4);t?t.appendChild(e.parentElement===t?e:e.closest(`${n4} > *`)):r.appendChild(e.parentElement===r?e:e.closest(`${n4} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{let t=S.current?.querySelector(`${t4}[${s4}="${encodeURIComponent(e[0])}"]`);t?.parentElement.appendChild(t)})}function ee(){let e=ie().find(e=>e.getAttribute(`aria-disabled`)!==`true`)?.getAttribute(s4);w.setState(`value`,e||void 0)}function te(){if(!n.current.search||s.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let e=0;for(let t of r.current){let r=E(a.current.get(t)?.value??``,a.current.get(t)?.keywords??[]);n.current.filtered.items.set(t,r),r>0&&e++}for(let[e,t]of i.current)for(let r of t)if(n.current.filtered.items.get(r)>0){n.current.filtered.groups.add(e);break}n.current.filtered.count=e}function ne(){var e;let t=re();t&&(t.parentElement?.firstChild===t&&((e=t.closest(t4)?.querySelector(r4))==null||e.scrollIntoView({block:`nearest`})),t.scrollIntoView({block:`nearest`}))}function re(){return S.current?.querySelector(`${i4}[aria-selected="true"]`)}function ie(){return Array.from(S.current?.querySelectorAll(a4)||[])}function ae(e){let t=ie()[e];t&&w.setState(`value`,t.getAttribute(s4))}function oe(e){var t;let n=re(),r=ie(),i=r.findIndex(e=>e===n),a=r[i+e];(t=s.current)!=null&&t.loop&&(a=i+e<0?r[r.length-1]:i+e===r.length?r[0]:r[i+e]),a&&w.setState(`value`,a.getAttribute(s4))}function se(e){let t=re()?.closest(t4),n;for(;t&&!n;)t=e>0?w4(t,t4):T4(t,t4),n=t?.querySelector(a4);n?w.setState(`value`,n.getAttribute(s4)):oe(e)}let O=()=>ae(ie().length-1),ce=e=>{e.preventDefault(),e.metaKey?O():e.altKey?se(1):oe(1)},le=e=>{e.preventDefault(),e.metaKey?ae(0):e.altKey?se(-1):oe(-1)};return v.createElement(un.div,{ref:t,tabIndex:-1,..._,"cmdk-root":``,onKeyDown:e=>{var t;(t=_.onKeyDown)==null||t.call(_,e);let n=e.nativeEvent.isComposing||e.keyCode===229;if(!(e.defaultPrevented||n))switch(e.key){case`n`:case`j`:g&&e.ctrlKey&&ce(e);break;case`ArrowDown`:ce(e);break;case`p`:case`k`:g&&e.ctrlKey&&le(e);break;case`ArrowUp`:le(e);break;case`Home`:e.preventDefault(),ae(0);break;case`End`:e.preventDefault(),O();break;case`Enter`:{e.preventDefault();let t=re();if(t){let e=new Event(o4);t.dispatchEvent(e)}}}}},v.createElement(`label`,{"cmdk-label":``,htmlFor:T.inputId,id:T.labelId,style:P4},c),N4(e,e=>v.createElement(d4.Provider,{value:w},v.createElement(l4.Provider,{value:T},e))))}),h4=v.forwardRef((e,t)=>{let n=gr(),r=v.useRef(null),i=v.useContext(p4),a=u4(),o=E4(e),s=o.current?.forceMount??i?.forceMount;D4(()=>{if(!s)return a.item(n,i?.id)},[s]);let c=A4(n,r,[e.value,e.children,r],e.keywords),l=f4(),u=k4(e=>e.value&&e.value===c.current),d=k4(e=>s||a.filter()===!1?!0:!e.search||e.filtered.items.get(n)>0);v.useEffect(()=>{let t=r.current;if(t&&!e.disabled)return t.addEventListener(o4,f),()=>t.removeEventListener(o4,f)},[d,e.onSelect,e.disabled]);function f(){var e,t;p(),(t=(e=o.current).onSelect)==null||t.call(e,c.current)}function p(){l.setState(`value`,c.current,!0)}if(!d)return null;let{disabled:m,value:h,onSelect:g,forceMount:_,keywords:y,...b}=e;return v.createElement(un.div,{ref:Bt(r,t),...b,id:n,"cmdk-item":``,role:`option`,"aria-disabled":!!m,"aria-selected":!!u,"data-disabled":!!m,"data-selected":!!u,onPointerMove:m||a.getDisablePointerSelection()?void 0:p,onClick:m?void 0:f},e.children)}),g4=v.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:i,...a}=e,o=gr(),s=v.useRef(null),c=v.useRef(null),l=gr(),u=u4(),d=k4(e=>i||u.filter()===!1?!0:!e.search||e.filtered.groups.has(o));D4(()=>u.group(o),[]),A4(o,s,[e.value,e.heading,c]);let f=v.useMemo(()=>({id:o,forceMount:i}),[i]);return v.createElement(un.div,{ref:Bt(s,t),...a,"cmdk-group":``,role:`presentation`,hidden:!d||void 0},n&&v.createElement(`div`,{ref:c,"cmdk-group-heading":``,"aria-hidden":!0,id:l},n),N4(e,e=>v.createElement(`div`,{"cmdk-group-items":``,role:`group`,"aria-labelledby":n?l:void 0},v.createElement(p4.Provider,{value:f},e))))}),_4=v.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,i=v.useRef(null),a=k4(e=>!e.search);return!n&&!a?null:v.createElement(un.div,{ref:Bt(i,t),...r,"cmdk-separator":``,role:`separator`})}),v4=v.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,i=e.value!=null,a=f4(),o=k4(e=>e.search),s=k4(e=>e.selectedItemId),c=u4();return v.useEffect(()=>{e.value!=null&&a.setState(`search`,e.value)},[e.value]),v.createElement(un.input,{ref:t,...r,"cmdk-input":``,autoComplete:`off`,autoCorrect:`off`,spellCheck:!1,"aria-autocomplete":`list`,role:`combobox`,"aria-expanded":!0,"aria-controls":c.listId,"aria-labelledby":c.labelId,"aria-activedescendant":s,id:c.inputId,type:`text`,value:i?e.value:o,onChange:e=>{i||a.setState(`search`,e.target.value),n?.(e.target.value)}})}),y4=v.forwardRef((e,t)=>{let{children:n,label:r=`Suggestions`,...i}=e,a=v.useRef(null),o=v.useRef(null),s=k4(e=>e.selectedItemId),c=u4();return v.useEffect(()=>{if(o.current&&a.current){let e=o.current,t=a.current,n,r=new ResizeObserver(()=>{n=requestAnimationFrame(()=>{let n=e.offsetHeight;t.style.setProperty(`--cmdk-list-height`,n.toFixed(1)+`px`)})});return r.observe(e),()=>{cancelAnimationFrame(n),r.unobserve(e)}}},[]),v.createElement(un.div,{ref:Bt(a,t),...i,"cmdk-list":``,role:`listbox`,tabIndex:-1,"aria-activedescendant":s,"aria-label":r,id:c.listId},N4(e,e=>v.createElement(`div`,{ref:Bt(o,c.listInnerRef),"cmdk-list-sizer":``},e)))}),b4=v.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:i,contentClassName:a,container:o,...s}=e;return v.createElement(eo,{open:n,onOpenChange:r},v.createElement(oo,{container:o},v.createElement(co,{"cmdk-overlay":``,className:i}),v.createElement(po,{"aria-label":e.label,"cmdk-dialog":``,className:a},v.createElement(m4,{ref:t,...s}))))}),x4=v.forwardRef((e,t)=>k4(e=>e.filtered.count===0)?v.createElement(un.div,{ref:t,...e,"cmdk-empty":``,role:`presentation`}):null),S4=v.forwardRef((e,t)=>{let{progress:n,children:r,label:i=`Loading...`,...a}=e;return v.createElement(un.div,{ref:t,...a,"cmdk-loading":``,role:`progressbar`,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i},N4(e,e=>v.createElement(`div`,{"aria-hidden":!0},e)))}),C4=Object.assign(m4,{List:y4,Item:h4,Input:v4,Group:g4,Separator:_4,Dialog:b4,Empty:x4,Loading:S4});function w4(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function T4(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function E4(e){let t=v.useRef(e);return D4(()=>{t.current=e}),t}var D4=typeof window>`u`?v.useEffect:v.useLayoutEffect;function O4(e){let t=v.useRef();return t.current===void 0&&(t.current=e()),t}function k4(e){let t=f4(),n=()=>e(t.snapshot());return v.useSyncExternalStore(t.subscribe,n,n)}function A4(e,t,n,r=[]){let i=v.useRef(),a=u4();return D4(()=>{var o;let s=(()=>{for(let e of n){if(typeof e==`string`)return e.trim();if(typeof e==`object`&&`current`in e)return e.current?e.current.textContent?.trim():i.current}})(),c=r.map(e=>e.trim());a.value(e,s,c),(o=t.current)==null||o.setAttribute(s4,s),i.current=s}),i}var j4=()=>{let[e,t]=v.useState(),n=O4(()=>new Map);return D4(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function M4(e){let t=e.type;return typeof t==`function`?t(e.props):`render`in t?t.render(e.props):e}function N4({asChild:e,children:t},n){return e&&v.isValidElement(t)?v.cloneElement(M4(t),{ref:t.ref},n(t.props.children)):n(t)}var P4={position:`absolute`,width:`1px`,height:`1px`,padding:`0`,margin:`-1px`,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,borderWidth:`0`};function F4({...e}){return(0,j.jsx)(eo,{"data-slot":`dialog`,...e})}function I4({...e}){return(0,j.jsx)(oo,{"data-slot":`dialog-portal`,...e})}function L4({className:e,...t}){return(0,j.jsx)(co,{"data-slot":`dialog-overlay`,className:A(`fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0`,e),...t})}function R4({className:e,children:t,showCloseButton:n=!0,...r}){return(0,j.jsxs)(I4,{"data-slot":`dialog-portal`,children:[(0,j.jsx)(L4,{}),(0,j.jsxs)(po,{"data-slot":`dialog-content`,className:A(`fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg`,e),...r,children:[t,n&&(0,j.jsxs)(bo,{"data-slot":`dialog-close`,className:`absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,children:[(0,j.jsx)(d_,{}),(0,j.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function z4({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`dialog-header`,className:A(`flex flex-col gap-2 text-center sm:text-left`,e),...t})}function B4({className:e,showCloseButton:t=!1,children:n,...r}){return(0,j.jsxs)(`div`,{"data-slot":`dialog-footer`,className:A(`flex flex-col-reverse gap-2 sm:flex-row sm:justify-end`,e),...r,children:[n,t&&(0,j.jsx)(bo,{asChild:!0,children:(0,j.jsx)(M,{variant:`outline`,children:`Close`})})]})}function V4({className:e,...t}){return(0,j.jsx)(_o,{"data-slot":`dialog-title`,className:A(`text-lg leading-none font-semibold`,e),...t})}function H4({className:e,...t}){return(0,j.jsx)(vo,{"data-slot":`dialog-description`,className:A(`text-sm text-muted-foreground`,e),...t})}function U4({className:e,...t}){return(0,j.jsx)(C4,{"data-slot":`command`,className:A(`flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground`,e),...t})}function W4({className:e,...t}){return(0,j.jsxs)(`div`,{"data-slot":`command-input-wrapper`,className:`flex h-9 items-center gap-2 border-b px-3`,children:[(0,j.jsx)(Lg,{className:`size-4 shrink-0 opacity-50`}),(0,j.jsx)(C4.Input,{"data-slot":`command-input`,className:A(`flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50`,e),...t})]})}function G4({className:e,...t}){return(0,j.jsx)(C4.List,{"data-slot":`command-list`,className:A(`max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto`,e),...t})}function K4({...e}){return(0,j.jsx)(C4.Empty,{"data-slot":`command-empty`,className:`py-6 text-center text-sm`,...e})}function q4({className:e,...t}){return(0,j.jsx)(C4.Group,{"data-slot":`command-group`,className:A(`overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground`,e),...t})}function J4({className:e,...t}){return(0,j.jsx)(C4.Item,{"data-slot":`command-item`,className:A(`relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground`,e),...t})}function Y4({...e}){return(0,j.jsx)(pd,{"data-slot":`dropdown-menu`,...e})}function X4({...e}){return(0,j.jsx)(hd,{"data-slot":`dropdown-menu-trigger`,...e})}function Z4({className:e,sideOffset:t=4,...n}){return(0,j.jsx)(gd,{children:(0,j.jsx)(vd,{"data-slot":`dropdown-menu-content`,sideOffset:t,className:A(`z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,e),...n})})}function Q4({className:e,inset:t,variant:n=`default`,...r}){return(0,j.jsx)(bd,{"data-slot":`dropdown-menu-item`,"data-inset":t,"data-variant":n,className:A(`relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!`,e),...r})}function $4({...e}){return(0,j.jsx)(xd,{"data-slot":`dropdown-menu-radio-group`,...e})}function e3({className:e,children:t,...n}){return(0,j.jsxs)(Sd,{"data-slot":`dropdown-menu-radio-item`,className:A(`relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,e),...n,children:[(0,j.jsx)(`span`,{className:`pointer-events-none absolute left-2 flex size-3.5 items-center justify-center`,children:(0,j.jsx)(Cd,{children:(0,j.jsx)(lh,{className:`size-2 fill-current`})})}),t]})}function t3({className:e,inset:t,...n}){return(0,j.jsx)(yd,{"data-slot":`dropdown-menu-label`,"data-inset":t,className:A(`px-2 py-1.5 text-sm font-medium data-[inset]:pl-8`,e),...n})}function n3({className:e,...t}){return(0,j.jsx)(wd,{"data-slot":`dropdown-menu-separator`,className:A(`-mx-1 my-1 h-px bg-border`,e),...t})}function r3({...e}){return(0,j.jsx)(Rd,{"data-slot":`popover`,...e})}function i3({...e}){return(0,j.jsx)(Bd,{"data-slot":`popover-trigger`,...e})}function a3({className:e,align:t=`center`,sideOffset:n=4,...r}){return(0,j.jsx)(Wd,{children:(0,j.jsx)(Kd,{"data-slot":`popover-content`,align:t,sideOffset:n,className:A(`z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,e),...r})})}function o3({className:e}){return(0,j.jsx)(`svg`,{viewBox:`0 0 21 21`,fill:`none`,"aria-hidden":`true`,focusable:`false`,className:A(`size-[21px] shrink-0`,e),children:(0,j.jsx)(`path`,{fill:`currentColor`,d:`M11.8102 19.1625C11.2327 19.1625 10.6841 19.0528 10.1643 18.8334C9.64459 18.6139 9.18259 18.3078 8.77834 17.9151C8.33944 18.0653 7.88322 18.1404 7.40967 18.1404C6.63582 18.1404 5.91972 17.9498 5.26137 17.5686C4.60302 17.1875 4.07172 16.6677 3.66747 16.0094C3.27477 15.351 3.07842 14.6176 3.07842 13.8091C3.07842 13.4742 3.12462 13.1103 3.21702 12.7176C2.75502 12.2903 2.39697 11.7994 2.14287 11.245C1.88877 10.679 1.76172 10.09 1.76172 9.47785C1.76172 8.85415 1.89454 8.25355 2.16019 7.67605C2.42584 7.09855 2.79544 6.6019 3.26899 6.1861C3.75409 5.75875 4.31427 5.46422 4.94952 5.30252C5.07657 4.64417 5.34222 4.05512 5.74647 3.53537C6.16227 3.00407 6.67047 2.58827 7.27107 2.28797C7.87167 1.98767 8.51269 1.83752 9.19414 1.83752C9.77164 1.83752 10.3203 1.94725 10.84 2.1667C11.3598 2.38615 11.8218 2.69222 12.226 3.08492C12.6649 2.93477 13.1211 2.8597 13.5947 2.8597C14.3685 2.8597 15.0846 3.05027 15.743 3.43142C16.4013 3.81257 16.9269 4.33232 17.3196 4.99067C17.7238 5.64902 17.9259 6.38245 17.9259 7.19095C17.9259 7.5259 17.8797 7.88973 17.7873 8.28242C18.2493 8.70977 18.6074 9.20643 18.8615 9.77238C19.1156 10.3268 19.2426 10.91 19.2426 11.5222C19.2426 12.1459 19.1098 12.7465 18.8442 13.324C18.5785 13.9015 18.2031 14.4039 17.718 14.8313C17.2445 15.2471 16.6901 15.5358 16.0548 15.6975C15.9278 16.3559 15.6564 16.9449 15.2406 17.4647C14.8363 17.996 14.3339 18.4118 13.7333 18.7121C13.1327 19.0124 12.4917 19.1625 11.8102 19.1625ZM7.53094 16.9969C8.10844 16.9969 8.61087 16.8756 9.03822 16.6331L12.2953 14.762C12.4108 14.6811 12.4686 14.5714 12.4686 14.4328V12.9429L8.27592 15.351C8.02182 15.5012 7.76772 15.5012 7.51362 15.351L4.23919 13.4626C4.23919 13.4973 4.23342 13.5377 4.22187 13.5839C4.22187 13.6301 4.22187 13.6994 4.22187 13.7918C4.22187 14.3808 4.36047 14.9237 4.63767 15.4203C4.92642 15.9054 5.32489 16.2866 5.83309 16.5638C6.34129 16.8525 6.90724 16.9969 7.53094 16.9969ZM7.70419 14.1729C7.77349 14.2076 7.83702 14.2249 7.89477 14.2249C7.95252 14.2249 8.01027 14.2076 8.06802 14.1729L9.36739 13.4279L5.19207 11.0024C4.93797 10.8523 4.81092 10.6271 4.81092 10.3268V6.56725C4.23342 6.82135 3.77142 7.21405 3.42492 7.74535C3.07842 8.2651 2.90517 8.8426 2.90517 9.47785C2.90517 10.0438 3.04954 10.5866 3.33829 11.1064C3.62704 11.6261 4.00242 12.0189 4.46442 12.2845L7.70419 14.1729ZM11.8102 18.0191C12.4224 18.0191 12.9768 17.8805 13.4734 17.6033C13.9701 17.3261 14.3628 16.9449 14.6515 16.4598C14.9403 15.9747 15.0846 15.4319 15.0846 14.8313V11.0891C15.0846 10.9505 15.0269 10.8465 14.9114 10.7772L13.5947 10.0149V14.8486C13.5947 15.1489 13.4676 15.3741 13.2135 15.5243L9.93912 17.4127C10.5051 17.817 11.1288 18.0191 11.8102 18.0191ZM12.4686 11.6781V9.32192L10.5108 8.21312L8.53579 9.32192V11.6781L10.5108 12.7869L12.4686 11.6781ZM7.40967 6.15145C7.40967 5.85115 7.53672 5.62592 7.79082 5.47577L11.0652 3.58735C10.4993 3.1831 9.87559 2.98097 9.19414 2.98097C8.58199 2.98097 8.02759 3.11957 7.53094 3.39677C7.03429 3.67397 6.64159 4.05512 6.35284 4.54022C6.07564 5.02532 5.93704 5.56817 5.93704 6.16878V9.89365C5.93704 10.0323 5.99479 10.142 6.11029 10.2228L7.40967 10.9851V6.15145ZM16.2108 14.4328C16.7883 14.1787 17.2445 13.786 17.5794 13.2547C17.9259 12.7234 18.0992 12.1459 18.0992 11.5222C18.0992 10.9562 17.9548 10.4134 17.6661 9.89365C17.3773 9.3739 17.0019 8.9812 16.5399 8.71555L13.3002 6.84445C13.2309 6.79825 13.1673 6.78092 13.1096 6.79248C13.0518 6.79248 12.9941 6.8098 12.9363 6.84445L11.637 7.5721L15.8296 10.0149C15.9567 10.0842 16.0491 10.1766 16.1068 10.2921C16.1761 10.3961 16.2108 10.5231 16.2108 10.6733V14.4328ZM12.7284 5.6317C12.9825 5.47 13.2366 5.47 13.4907 5.6317L16.7825 7.55477C16.7825 7.47393 16.7825 7.36997 16.7825 7.24292C16.7825 6.68852 16.6439 6.163 16.3667 5.66635C16.101 5.15815 15.7141 4.7539 15.2059 4.4536C14.7093 4.1533 14.1318 4.00315 13.4734 4.00315C12.8959 4.00315 12.3935 4.12442 11.9661 4.36697L8.70904 6.23808C8.59354 6.31892 8.53579 6.42865 8.53579 6.56725V8.0572L12.7284 5.6317Z`})})}function s3({busy:e,className:t,...n}){return(0,j.jsxs)(`button`,{type:`button`,"aria-busy":e||void 0,className:A(`inline-flex min-h-[45px] w-full max-w-[242px] items-center justify-center gap-3 rounded-[12px] px-5 py-3 text-[15px] font-medium`,`bg-black text-white hover:opacity-85 active:opacity-70 disabled:opacity-50 dark:bg-white dark:text-black`,`focus-visible:ring-ring/50 outline-none focus-visible:ring-[3px]`,t),...n,children:[(0,j.jsx)(o3,{}),e?`Opening ChatGPT…`:`Continue with ChatGPT`]})}function c3({className:e,primary:t=!1}){return(0,j.jsx)(M,{asChild:!0,size:t?`sm`:`xs`,variant:t?`default`:`link`,className:A(!t&&`h-auto p-0`,e),children:(0,j.jsxs)(`a`,{href:TM,target:`_blank`,rel:`noreferrer`,"aria-label":`Manage ChatGPT usage (opens in a new tab)`,children:[`Manage usage `,(0,j.jsx)(jh,{"aria-hidden":!0})]})})}function l3(){return(0,j.jsxs)(`span`,{className:`text-muted-foreground inline-flex items-center gap-1.5 text-xs`,"aria-live":`polite`,children:[(0,j.jsx)(o3,{className:`size-4`}),`Using ChatGPT plan`,(0,j.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,j.jsx)(c3,{})]})}function u3(){return(0,j.jsxs)(`div`,{role:`alert`,className:`flex flex-col gap-1 rounded-lg border p-3 text-sm`,children:[(0,j.jsxs)(`span`,{className:`text-muted-foreground inline-flex items-center gap-1.5 text-xs font-medium`,children:[(0,j.jsx)(o3,{className:`size-4`}),` ChatGPT`]}),(0,j.jsx)(`p`,{className:`font-semibold`,children:`Usage limit reached`}),(0,j.jsx)(`p`,{className:`text-muted-foreground`,children:`Review your plan or this app's limit in ChatGPT settings.`}),(0,j.jsx)(c3,{primary:!0,className:`mt-1 self-start`})]})}function d3(){let[e,t]=(0,v.useState)(!1),n=(0,v.useCallback)(()=>{LN().then(e=>{e.ok&&e.value.chatgpt?.welcome&&t(!0)})},[]);(0,v.useEffect)(()=>(n(),window.addEventListener(FN,n),()=>window.removeEventListener(FN,n)),[n]);let r=()=>{t(!1),WN()};return(0,j.jsx)(F4,{open:e,onOpenChange:e=>!e&&r(),children:(0,j.jsxs)(R4,{className:`sm:max-w-sm`,children:[(0,j.jsxs)(z4,{className:`items-center text-center sm:text-center`,children:[(0,j.jsx)(o3,{className:`text-foreground mb-2 size-[72px]`}),(0,j.jsx)(V4,{children:`You're using your ChatGPT plan`}),(0,j.jsx)(H4,{children:`Eligible usage in this app uses your ChatGPT plan. Manage usage in your ChatGPT settings.`})]}),(0,j.jsx)(B4,{className:`sm:justify-center`,children:(0,j.jsx)(M,{onClick:r,children:`Got it`})})]})})}var f3=50,p3={none:`None`,minimal:`Minimal`,low:`Low`,medium:`Medium`,high:`High`,xhigh:`Extra high`,max:`Max`},m3=`custom:`,h3=e=>e.startsWith(m3)&&e.indexOf(`/`)>7?e.slice(0,e.indexOf(`/`)):void 0,g3=e=>h3(e)?e.slice(e.indexOf(`/`)+1):e.slice(e.indexOf(`:`)+1);function _3(e,t=[]){if(h3(e))return g3(e);let n=t.find(t=>t.id===e)?.name;return n&&n!==e?n.replace(/^[^:]{1,40}:\s+/,``):e.replace(/^[a-z][a-z0-9-]*:/,``)}var v3={openrouter:`OpenRouter`,anthropic:`Anthropic`,openai:`OpenAI`,chatgpt:`ChatGPT`};function y3(e,t=[]){let n=h3(e);if(n)return t.find(e=>e.id===n)?.name??`Removed provider`;let r=e.slice(0,Math.max(0,e.indexOf(`:`)));return v3[r]??r}function b3(e,t=[],n=[]){let r=_3(e,t);return h3(e)?`${r} (${y3(e,n)})`:e.startsWith(`openrouter:`)||!(e.split(`:`)[0]in v3)?r:`${r} (${y3(e)})`}var x3={unverified:`not tested`,verified:`tested`,failed:`test failed`};function S3(e){if(!e)return;if(e.input===0&&e.output===0)return`free`;let t=e=>`$${e<1?e.toFixed(2):Number(e.toFixed(2))}`;return`${t(e.input)} in · ${t(e.output)} out per 1M tokens`}function C3(e,t){let n=t.toLowerCase().split(/\s+/).filter(Boolean);return e.filter(e=>{let t=`${e.name} ${e.id}`.toLowerCase();return n.every(e=>t.includes(e))})}function w3(){let[e,t]=(0,v.useState)(),[n,r]=(0,v.useState)(),i=(0,v.useCallback)(async()=>{let e=await wN();e.ok?t(e.value):r(e.error)},[]);return(0,v.useEffect)(()=>{i();let e=()=>void i();return window.addEventListener(FN,e),()=>window.removeEventListener(FN,e)},[i]),{view:e,error:n,refresh:i,choose:(0,v.useCallback)(async e=>{r(void 0);let n=await TN(e);if(!n.ok)return r(n.error);t(e=>e&&{...e,current:n.value,unavailable:null})},[]),togglePin:(0,v.useCallback)(async n=>{if(!e)return;r(void 0);let i=await EN(e.pinned.includes(n)?e.pinned.filter(e=>e!==n):[...e.pinned,n]);if(!i.ok)return r(i.error);t(e=>e&&{...e,pinned:i.value})},[e])}}function T3({model:e,selected:t,names:n}){let r=e.id.startsWith(`chatgpt:`)?`your ChatGPT plan`:e.verification?x3[e.verification]:S3(e.price);return(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(qm,{className:A(`mt-0.5 self-start`,t?`opacity-100`:`opacity-0`),"aria-hidden":!0}),(0,j.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[(0,j.jsx)(`span`,{className:`truncate`,children:e.name}),(0,j.jsxs)(`span`,{className:`text-muted-foreground truncate text-xs`,children:[y3(e.id,n),` · `,g3(e.id),r&&` · ${r}`]})]})]})}function E3({state:e,disabled:t,value:n,onChoose:r,unavailable:i,label:a=`Model`}){let{view:o,error:s,refresh:c,togglePin:l}=e,u=r??e.choose,d=n===void 0,f=o&&n?{...o,current:n,unavailable:i??null}:o,[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(``),_=(0,v.useMemo)(()=>new Map(f?.models.map(e=>[e.id,e])),[f]),y=(0,v.useMemo)(()=>{if(!f)return[];let e=e=>e.flatMap(e=>_.get(e)??[]);if(h.trim()){let e=C3(f.models,h),t=e.slice(0,f3),n=e.length>f3?`First ${f3} of ${e.length} matches`:void 0,r=[...new Set(t.map(e=>y3(e.id,f.providers)))];return r.length<2?[{heading:n,models:t}]:r.map((e,r)=>({heading:r===0&&n?`${n} · ${e}`:e,models:t.filter(t=>y3(t.id,f.providers)===e)}))}let t=new Set(f.pinned),n=new Set([...f.pinned,...f.recent]),r=f.models.filter(e=>e.id.startsWith(`chatgpt:`)),i=f.providers.filter(e=>!e.removed).map(e=>({heading:e.name,models:f.models.filter(t=>t.id.startsWith(`${e.id}/`)&&!n.has(t.id))})),a=[{heading:`Pinned`,models:e(f.pinned)},{heading:`Recent`,models:e(f.recent.filter(e=>!t.has(e)))},{heading:`ChatGPT plan`,models:r.filter(e=>!n.has(e.id))},...i,{heading:`Suggested`,models:e(f.suggested.filter(e=>!e.startsWith(`chatgpt:`)))}],o=new Set(a.flatMap(e=>e.models.map(e=>e.id))),s=_.get(f.current.model);return[...s&&!o.has(s.id)?[{heading:`Current`,models:[s]}]:[],...a].filter(e=>e.models.length>0)},[f,h,_]);if(!f)return s?(0,j.jsx)(`span`,{className:`text-destructive text-xs`,children:s}):null;let b=_.get(f.current.model),x=b3(f.current.model,f.models,f.providers),S=b?.reasoning?.efforts??[],C=b?.reasoning?.defaultEffort,w=f.pinned.includes(f.current.model),T=e=>{m(!1),g(``);let t=f.current.effort&&e.reasoning?.efforts.includes(f.current.effort)?f.current.effort:null;(e.id!==f.current.model||t!==f.current.effort)&&u({model:e.id,effort:t})};return(0,j.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1`,children:[(0,j.jsxs)(r3,{open:p,onOpenChange:e=>{m(e),e?c():g(``)},children:[(0,j.jsx)(i3,{asChild:!0,children:(0,j.jsxs)(M,{type:`button`,variant:`ghost`,size:`sm`,className:`text-muted-foreground max-w-64 min-w-0`,"aria-label":`${a}: ${x}. Change model`,disabled:t,children:[(0,j.jsx)(`span`,{className:`truncate`,children:x}),(0,j.jsx)(rh,{"aria-hidden":!0})]})}),(0,j.jsx)(a3,{className:`w-[min(28rem,calc(100vw-2rem))] p-0`,align:`start`,children:(0,j.jsxs)(U4,{shouldFilter:!1,label:`Choose a model`,children:[(0,j.jsx)(W4,{placeholder:`Search models…`,value:h,onValueChange:g}),(0,j.jsxs)(G4,{className:`max-h-80`,label:`Models`,children:[(0,j.jsx)(K4,{children:f.catalog===`unavailable`?`The model list couldn't be loaded.`:`No models match.`}),y.map((e,t)=>(0,j.jsx)(q4,{heading:e.heading,children:e.models.map(e=>(0,j.jsx)(J4,{value:e.id,onSelect:()=>T(e),className:`items-start`,children:(0,j.jsx)(T3,{model:e,selected:e.id===f.current.model,names:f.providers})},e.id))},e.heading??t))]}),f.catalog!==`fresh`&&(0,j.jsx)(`p`,{className:`text-muted-foreground border-t px-3 py-2 text-xs`,children:f.catalog===`stale`?`Couldn't refresh every provider's model list, so some of this is a saved copy.`:`Couldn't load the model list. Search covers only the default model.`})]})})]}),d&&(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground`,"aria-label":w?`Unpin ${x}`:`Pin ${x}`,"aria-pressed":w,title:w?`Unpin this model`:`Pin this model to the top of the list`,disabled:t,onClick:()=>void l(f.current.model),children:(0,j.jsx)(qg,{className:A(w&&`fill-current`),"aria-hidden":!0})}),S.length>0&&(0,j.jsxs)(Y4,{children:[(0,j.jsx)(X4,{asChild:!0,children:(0,j.jsxs)(M,{type:`button`,variant:`ghost`,size:`sm`,className:`text-muted-foreground`,disabled:t,"aria-label":`${d?`Reasoning effort`:`${a} reasoning effort`}: ${f.current.effort?p3[f.current.effort]:`the model's default`}. Change effort`,children:[f.current.effort?p3[f.current.effort]:`Default effort`,(0,j.jsx)(rh,{"aria-hidden":!0})]})}),(0,j.jsxs)(Z4,{align:`start`,children:[(0,j.jsx)(t3,{children:`Reasoning effort`}),(0,j.jsx)(n3,{}),(0,j.jsxs)($4,{value:f.current.effort??`default`,onValueChange:e=>void u({model:f.current.model,effort:e==="default"?null:e}),children:[(0,j.jsxs)(e3,{value:`default`,children:[`Default`,C?` (${p3[C]})`:``]}),S.map(e=>(0,j.jsx)(e3,{value:e,children:p3[e]},e))]})]})]}),d&&f.current.model.startsWith(`chatgpt:`)&&(0,j.jsx)(l3,{}),f.unavailable&&!s&&(0,j.jsx)(`span`,{role:`alert`,className:`text-destructive text-xs`,children:f.unavailable}),s&&(0,j.jsx)(`span`,{role:`alert`,className:`text-destructive text-xs`,children:s})]})}var D3=`text-muted-foreground font-mono text-[0.6875rem] leading-snug font-medium tracking-[0.09em] uppercase`,O3=`bg-card gap-0`,k3=`border-b px-5 py-4`,A3=`font-heading text-[1.35rem] leading-tight font-medium tracking-[-0.015em]`,j3=`bg-sunken inline-flex max-w-full flex-wrap gap-0.5 self-start rounded-lg border p-0.5`,M3=e=>A(`h-7 rounded-md px-2.5 text-[0.8125rem] font-medium hover:bg-transparent dark:hover:bg-transparent`,e?`bg-card text-foreground hover:bg-card dark:hover:bg-card shadow-xs`:`text-muted-foreground hover:text-foreground`);function N3({onStarted:e,onFreeChat:t}){let n=(0,v.useId)(),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(),l=w3();return(0,j.jsxs)(`form`,{onSubmit:async t=>{t.preventDefault();let n=r.trim();if(!n||a)return;o(!0),c(void 0);let i=await mN(n);if(o(!1),!i.ok)return c(i.error);e({session:i.value.session,goal:n})},className:`m-auto flex w-full max-w-xl flex-col gap-5 p-4 sm:p-6`,children:[(0,j.jsxs)(`div`,{className:`flex flex-col gap-2 text-center`,children:[(0,j.jsx)(`h2`,{className:`font-heading text-[2rem] leading-[1.08] font-normal tracking-[-0.024em] text-balance`,children:`What do you want to learn?`}),(0,j.jsx)(I2,{id:`${n}-description`,className:`text-center text-[0.95rem]`,children:`Mivra asks a few quick questions to see what you already know, then plans a course of short lessons.`})]}),(0,j.jsxs)(P2,{"data-invalid":!!s,className:`bg-card border-border-strong shadow-paper rounded-xl border p-4 sm:p-5`,children:[(0,j.jsx)(F2,{htmlFor:n,className:D3,children:`Learning goal`}),(0,j.jsxs)(`div`,{className:`flex gap-2 max-[360px]:flex-col`,children:[(0,j.jsx)(z2,{id:n,"aria-describedby":`${n}-description${s?` ${n}-error`:``}`,"aria-invalid":!!s,value:r,onChange:e=>i(e.target.value),maxLength:300,placeholder:`e.g. Calculus for machine learning`,className:`bg-card dark:bg-card h-10 text-base md:text-base`,autoFocus:!0}),(0,j.jsxs)(M,{type:`submit`,className:`h-10 px-5`,disabled:!r.trim()||a,children:[a&&(0,j.jsx)(R2,{"aria-hidden":`true`}),a?`Starting…`:`Start`]})]}),s&&(0,j.jsx)(L2,{id:`${n}-error`,role:`alert`,children:s})]}),(0,j.jsx)(`div`,{className:`flex justify-center`,children:(0,j.jsx)(E3,{state:l,disabled:a})}),(0,j.jsx)(M,{type:`button`,variant:`link`,className:`text-muted-foreground self-center`,onClick:t,children:`Or just chat`})]})}var P3={memory:`From memory`,test:`From the test`,guess:`Guessed`};function F3({course:e,children:t,onUndo:n}){let[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(),l=e.syllabus;return(0,j.jsxs)(O2,{open:r,onOpenChange:i,className:`bg-sunken/60 border-b`,"aria-label":`Course`,role:`region`,children:[(0,j.jsxs)(`div`,{className:`mx-auto flex max-w-3xl items-center gap-x-2 gap-y-1 px-4 py-2 text-sm max-sm:flex-wrap`,children:[(0,j.jsx)(Uh,{className:`text-muted-foreground size-4 shrink-0`,"aria-hidden":!0}),(0,j.jsx)(`span`,{className:`min-w-0 truncate font-medium max-sm:min-w-48`,children:e.goal}),(0,j.jsx)(D2,{variant:`outline`,className:`border-border-strong bg-card shrink-0 font-mono text-[0.6875rem] font-medium tracking-[0.06em] uppercase`,children:e.status===`interviewing`?`Placement interview`:e.status===`complete`?`Complete`:`In progress`}),l&&(0,j.jsx)(k2,{asChild:!0,children:(0,j.jsxs)(M,{variant:`ghost`,size:`sm`,className:`ml-auto shrink-0`,children:[`Syllabus · `,l.topics.length,` topics`,(0,j.jsx)(Ym,{className:A(`transition-transform`,r&&`rotate-180`),"aria-hidden":!0})]})}),t&&(0,j.jsx)(`div`,{className:A(`flex shrink-0 gap-2`,!l&&`ml-auto`),children:t})]}),l?.canUndo&&(0,j.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-wrap items-center gap-2 px-4 pb-2 text-sm`,role:`status`,children:[(0,j.jsxs)(`span`,{children:[`Mivra changed the plan: `,l.reason]}),n&&(0,j.jsx)(M,{variant:`outline`,size:`xs`,disabled:a,onClick:async()=>{o(!0),c(await n()),o(!1)},children:`Undo`}),s&&(0,j.jsx)(`span`,{className:`text-destructive`,children:s})]}),l&&(0,j.jsx)(A2,{children:(0,j.jsxs)(`div`,{className:`mx-auto flex max-h-[50svh] max-w-3xl flex-col gap-4 overflow-y-auto px-4 pt-1 pb-5`,children:[l.reason&&l.version>1&&(0,j.jsxs)(`p`,{className:`text-muted-foreground`,role:`status`,children:[`Version `,l.version,l.source===`adaptive`?` (changed by Mivra)`:``,`: `,l.reason]}),(0,j.jsx)(`ol`,{className:`bg-card border-border-strong shadow-paper flex flex-col rounded-xl border px-4 py-1`,"aria-label":`Syllabus topics`,children:l.topics.map((e,t)=>(0,j.jsxs)(`li`,{className:A(`flex gap-3 border-t py-3 first:border-t-0`,l.changedTopicIds.includes(e.id)&&`bg-sunken -mx-4 px-4`),children:[(0,j.jsx)(`span`,{"aria-hidden":`true`,className:`bg-sunken text-muted-foreground ring-border-strong mt-0.5 grid size-6 shrink-0 place-items-center rounded-full font-mono text-[0.7rem] font-medium ring-1 ring-inset`,children:t+1}),(0,j.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5 wrap-anywhere`,children:[(0,j.jsxs)(`p`,{className:`font-heading text-[1.0625rem] leading-snug font-medium`,children:[e.title,l.changedTopicIds.includes(e.id)&&(0,j.jsxs)(D2,{variant:`secondary`,className:`ml-2 align-middle`,children:[`Changed in v`,l.version]}),e.requestedByLearner&&(0,j.jsx)(D2,{variant:`secondary`,className:`ml-2 align-middle`,children:`You asked for this`})]}),(0,j.jsx)(`p`,{className:`text-muted-foreground`,children:e.summary}),(0,j.jsxs)(`p`,{className:`text-muted-foreground text-[0.8125rem] italic`,children:[`Why: `,e.reason]})]})]},e.id))}),l.known.length>0&&(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`p`,{className:A(`text-muted-foreground font-mono text-[0.6875rem] leading-snug font-medium tracking-[0.09em] uppercase`,`mb-2`),children:`What Mivra thinks you know`}),(0,j.jsx)(`ul`,{className:`flex flex-col`,"aria-label":`What Mivra thinks you know`,children:l.known.map((e,t)=>(0,j.jsxs)(`li`,{className:`flex flex-wrap items-baseline gap-x-2 border-t py-1.5 first:border-t-0 wrap-anywhere`,children:[(0,j.jsx)(`span`,{children:e.concept}),(0,j.jsx)(D2,{variant:`outline`,className:`text-xs`,children:P3[e.source]}),(0,j.jsx)(`span`,{className:`text-muted-foreground`,children:e.note})]},t))})]})]})})]})}var I3={sigma:Ug,calculator:zm,code:dh,terminal:t_,cpu:hh,database:_h,network:_g,shield:Vg,"flask-conical":Lh,atom:jm,dna:yh,leaf:$h,telescope:$g,globe:Vh,landmark:Yh,"book-open":Nm,"pen-tool":Dg,languages:Zh,music:Dh,palette:yg,camera:Vm,brain:Fm,users:a_,"chart-line":Gm,briefcase:Lm,scale:Fg,stethoscope:Yg,"heart-pulse":Gh,wrench:l_,dumbbell:Th};function L3({icon:e,...t}){let n=BA.safeParse(e),r=n.success?I3[n.data]:Uh;return(0,j.jsx)(r,{"data-icon":n.success?n.data:`graduation-cap`,...t})}function R3({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`skeleton`,className:A(`animate-pulse rounded-md bg-accent`,e),...t})}function z3(e){let[t,n]=(0,v.useState)(),[r,i]=(0,v.useState)(),a=(0,v.useRef)(void 0),o=(0,v.useCallback)(e=>{a.current=e.revision,n(e.lesson),i(void 0)},[]);return(0,v.useEffect)(()=>{let t=new AbortController;return a.current=void 0,n(void 0),(async()=>{let n=0;for(;!t.signal.aborted;){let r=await yN(e,a.current,t.signal);if(t.signal.aborted)return;if(r.ok){if(n=0,o(r.value),r.value.lesson.status===`finished`)return}else i(r.error),await new Promise(e=>setTimeout(e,Math.min(1e4,1e3*2**n++)))}})(),()=>t.abort()},[e,o]),{lesson:t,error:r,apply:o}}function B3(e){return e===`finished`?` (finished)`:e===`generating`?` (being written)`:e===`failed`?` (stopped)`:e?` (started)`:` (not started)`}function V3({lessons:e,selectedId:t,onSelect:n}){return(0,j.jsx)(`nav`,{"aria-label":`Lessons`,children:(0,j.jsx)(`ol`,{className:`flex flex-col gap-1 text-sm`,children:e.topics.map((e,r)=>{let i=e.lesson?.status;return(0,j.jsx)(`li`,{children:(0,j.jsxs)(`button`,{type:`button`,disabled:!e.lesson,"aria-current":e.lesson?.id===t?`page`:void 0,onClick:()=>e.lesson&&n(e.lesson.id),className:A(`flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left`,e.lesson?`hover:bg-accent`:`text-muted-foreground cursor-default`,e.lesson?.id===t&&`bg-accent font-medium`),children:[(0,j.jsx)(`span`,{className:`mt-0.5 shrink-0`,"aria-hidden":!0,children:i===`finished`?(0,j.jsx)(qm,{className:`text-success size-4`}):i===`generating`?(0,j.jsx)(R2,{"aria-hidden":`true`}):(0,j.jsx)(ah,{className:`size-4`})}),(0,j.jsxs)(`span`,{className:`min-w-0`,children:[r+1,`. `,e.title,(0,j.jsx)(`span`,{className:`sr-only`,children:B3(i)})]})]})},e.topicId)})})})}function H3({lessonId:e,nextTopic:t,onFinished:n,onStartNext:r,onExplain:i,onChange:a,onLoaded:o,onOpenSection:s,focusSectionId:c,courseComplete:l=!1}){let{lesson:u,error:d,apply:f}=z3(e),[p,m]=(0,v.useState)({}),[h,g]=(0,v.useState)(!1),[_,y]=(0,v.useState)(),b=(0,v.useRef)(o);b.current=o,(0,v.useEffect)(()=>{u&&b.current?.(u)},[u]);let x=!!u;if((0,v.useEffect)(()=>{if(!x||!c)return;let e=document.getElementById(`section-${c}`);e?.scrollIntoView({block:`start`}),e?.focus({preventScroll:!0})},[x,c]),!u)return d?(0,j.jsx)(`p`,{className:`text-destructive m-auto p-6`,children:d}):(0,j.jsxs)(`p`,{className:`text-muted-foreground m-auto flex items-center gap-2 p-6`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Loading the lesson…`]});let S=u.status===`generating`,C=u.status===`ready`,w=new Set(u.changedSectionIds),T=u.outline?u.outline.sections.slice(u.sections.length):[],E=async e=>{g(!0),y(void 0);let t=await e();return g(!1),t.ok?f(t.value):y(t.error),t.ok};return(0,j.jsxs)(`article`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-6 p-4 pb-16`,"aria-busy":S,"aria-labelledby":`lesson-title`,children:[(0,j.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[(0,j.jsxs)(`p`,{className:`text-muted-foreground text-sm`,children:[`Lesson `,u.position+1]}),(0,j.jsx)(`h2`,{id:`lesson-title`,className:`font-heading text-2xl font-semibold`,children:u.outline?.title??u.topicTitle}),u.status===`finished`&&(0,j.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Finished. This lesson won't change.`}),u.changeReason&&u.version&&u.version>1&&(0,j.jsxs)(`p`,{className:`text-muted-foreground text-sm`,role:`status`,children:[`Version `,u.version,`: `,u.changeReason]})]}),!u.outline&&S&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Planning the lesson…`]}),u.sections.map(t=>(0,j.jsxs)(`section`,{id:`section-${t.id}`,tabIndex:-1,"aria-label":t.title,"data-changed":w.has(t.id)||void 0,className:A(`group flex min-w-0 flex-col gap-2`,w.has(t.id)&&`bg-muted/60 -mx-3 rounded-lg px-3 py-2`),children:[(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,j.jsx)(`h3`,{className:`font-heading text-lg font-medium`,children:t.title}),w.has(t.id)&&(0,j.jsxs)(D2,{variant:`secondary`,children:[`Changed in v`,u.version]}),(i||a&&C)&&(0,j.jsxs)(`div`,{className:`ml-auto flex gap-1`,children:[i&&(0,j.jsxs)(M,{variant:`ghost`,size:`xs`,onClick:()=>i(t),"aria-label":`Explain: ${t.title}`,children:[(0,j.jsx)(sh,{"aria-hidden":!0}),` Explain`]}),a&&C&&(0,j.jsxs)(M,{variant:`ghost`,size:`xs`,onClick:()=>a(t),"aria-label":`Change: ${t.title}`,children:[(0,j.jsx)(kg,{"aria-hidden":!0}),` Change`]})]})]}),t.kind===`prose`?(0,j.jsxs)(j.Fragment,{children:[t.revisits.length>0&&(0,j.jsx)(`ul`,{className:`flex flex-wrap gap-2 text-sm`,"aria-label":`Revisits`,children:t.revisits.map(e=>(0,j.jsx)(`li`,{children:(0,j.jsxs)(M,{variant:`outline`,size:`xs`,onClick:()=>s?.(e.lessonId,e.sectionId),disabled:!s,children:[(0,j.jsx)(ph,{"aria-hidden":!0}),` `,e.lessonTitle,`: `,e.title]})},e.sectionId))}),(0,j.jsx)(rQ,{text:t.markdown})]}):(0,j.jsx)(b2,{data:t.artifact?.id?p[t.artifact.id]??t.artifact:t.artifact,replyInProgress:!1,onUpdate:e=>m(t=>T2(t,{[e.id]:e})),onRefresh:async()=>{let t=await yN(e);t.ok&&f(t.value)}})]},t.id)),S&&T.map((e,t)=>(0,j.jsxs)(`section`,{"aria-label":`${e.title} (being written)`,className:`flex flex-col gap-2`,children:[(0,j.jsx)(`h3`,{className:`font-heading text-muted-foreground text-lg font-medium`,children:e.title}),t===0?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Writing…`]}),(0,j.jsx)(R3,{className:`h-16 w-full`})]}):(0,j.jsx)(R3,{className:`h-4 w-1/3`})]},`pending-${t}`)),u.status===`failed`&&(0,j.jsxs)(T0,{variant:`destructive`,children:[(0,j.jsx)(E0,{children:u.error}),(0,j.jsxs)(D0,{children:[(0,j.jsxs)(`p`,{children:[`The sections above are kept. Mivra can carry on from here`,u.errorAction===`lesson-model`?` once the lesson model can be used`:``,`.`]}),(0,j.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:[u.errorAction===`lesson-model`&&(0,j.jsx)(M,{size:`sm`,variant:`outline`,onClick:()=>window.dispatchEvent(new Event(`mivra:open-settings`)),children:`Lesson model settings`}),(0,j.jsx)(M,{size:`sm`,disabled:h,onClick:()=>void E(()=>xN(e)),children:`Continue writing`})]})]})]}),(u.status===`ready`||u.status===`finished`)&&(0,j.jsxs)(`footer`,{className:`flex flex-col gap-3 border-t pt-4`,"aria-live":`polite`,children:[u.status===`ready`?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`p`,{className:`text-muted-foreground text-sm`,children:[u.checks.answered,` of `,u.checks.total,` checks answered.`,!u.canFinish&&` Answer every check to finish; your score doesn't matter.`]}),(0,j.jsx)(M,{className:`self-start`,disabled:!u.canFinish||h,onClick:async()=>{await E(()=>bN(e))&&n()},children:`Finish lesson`})]}):t?(0,j.jsxs)(M,{className:`self-start`,disabled:h,onClick:async()=>{g(!0),await r(t.id),g(!1)},children:[`Next lesson: `,t.title]}):l?(0,j.jsx)(`p`,{className:`font-medium`,children:`You've reached the end of the syllabus.`}):null,_&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,children:_})]}),d&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,children:d})]})}function U3({delayDuration:e=0,...t}){return(0,j.jsx)(Wp,{"data-slot":`tooltip-provider`,delayDuration:e,...t})}function W3({...e}){return(0,j.jsx)(Jp,{"data-slot":`tooltip`,...e})}function G3({...e}){return(0,j.jsx)(Xp,{"data-slot":`tooltip-trigger`,...e})}function K3({className:e,sideOffset:t=0,children:n,...r}){return(0,j.jsx)(em,{children:(0,j.jsxs)(nm,{"data-slot":`tooltip-content`,sideOffset:t,className:A(`z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95`,e),...r,children:[n,(0,j.jsx)(om,{className:`z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground`})]})})}var q3=`Only text is read: images and diagrams aren't, and formulas may come through garbled.`,J3=new Set;function Y3(e){let[t,n]=(0,v.useState)([]),[r,i]=(0,v.useState)(),[a,o]=(0,v.useState)(),s=(0,v.useRef)(e);s.current=e;let c=(0,v.useRef)(!0);(0,v.useEffect)(()=>(c.current=!0,()=>{c.current=!1}),[]),(0,v.useEffect)(()=>{n([]),i(void 0),o(void 0);let t=!1,r=()=>void tN(e).then(e=>{t||(e.ok?n(t=>[...e.value,...t.filter(t=>!e.value.some(e=>e.id===t.id))]):o(e.error))});r();let a=t=>{t===e&&r()};return J3.add(a),()=>{t=!0,J3.delete(a)}},[e]);let l=(0,v.useCallback)(async()=>{let t=await tN(e);c.current&&s.current===e&&(t.ok?n(e=>[...t.value,...e.filter(e=>!t.value.some(t=>t.id===e.id))]):o(t.error))},[e]);return{documents:t,uploading:r,error:a,upload:(0,v.useCallback)(async t=>{if(o(void 0),t.size>26214400)return o(`${t.name} is over the ${tM/1048576} MB limit.`);i(t.name);let r=await nN(e,t);if(c.current)s.current===e&&(i(void 0),r.ok?n(e=>[...e.filter(e=>e.id!==r.value.id),r.value]):o(r.error));else if(r.ok)for(let t of J3)t(e)},[e]),remove:(0,v.useCallback)(async t=>{o(void 0);let r=await rN(t);s.current===e&&(r.ok?n(e=>e.filter(e=>e.id!==t)):o(r.error))},[e]),refresh:l}}function X3({kind:e,pageCount:t,pagesWithText:n}){let r=`${t} ${e===`pptx`?`slide`:`page`}${t===1?``:`s`}`;return n<t?`${r}, ${n} with text`:r}function Z3({documents:{uploading:e,upload:t}}){let n=(0,v.useRef)(null);return(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`input`,{ref:n,type:`file`,accept:`.pdf,.pptx`,className:`hidden`,"data-testid":`document-input`,onChange:e=>{let n=e.target.files?.[0];e.target.value=``,n&&t(n)}}),(0,j.jsx)(U3,{delayDuration:400,children:(0,j.jsxs)(W3,{children:[(0,j.jsx)(G3,{asChild:!0,children:(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`Attach a PDF or PowerPoint file`,disabled:e!==void 0,onClick:()=>n.current?.click(),children:e===void 0?(0,j.jsx)(Cg,{"aria-hidden":`true`}):(0,j.jsx)(R2,{"aria-hidden":`true`})})}),(0,j.jsx)(K3,{children:`Attach a PDF or PowerPoint file`})]})})]})}function Q3({documents:{documents:e,uploading:t,error:n,remove:r},messageId:i}){let a=e.filter(e=>(e.messageId??void 0)===i);return i&&(t=void 0,n=void 0),a.length===0&&t===void 0&&!n?null:(0,j.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-col gap-1.5 px-3 pt-3 text-sm`,children:[a.length>0&&(0,j.jsx)(`ul`,{"aria-label":`Attached documents`,className:`flex flex-wrap gap-1.5`,children:a.map(e=>(0,j.jsxs)(`li`,{className:`bg-muted text-foreground flex max-w-full min-w-0 flex-wrap items-center gap-1.5 rounded-md border py-0.5 pr-0.5 pl-2`,children:[(0,j.jsx)(Fh,{className:`text-muted-foreground size-3.5 shrink-0`,"aria-hidden":!0}),(0,j.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.filename,children:e.filename}),(0,j.jsx)(`span`,{className:`text-muted-foreground shrink-0 text-xs`,children:X3(e)}),(0,j.jsx)(U3,{delayDuration:400,children:(0,j.jsxs)(W3,{children:[(0,j.jsx)(G3,{asChild:!0,children:(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`icon`,className:`size-6`,"aria-label":`Remove ${e.filename}`,onClick:()=>void r(e.id),children:(0,j.jsx)(d_,{"aria-hidden":`true`})})}),(0,j.jsx)(K3,{children:`Remove attachment`})]})})]},e.id))}),t!==void 0&&(0,j.jsxs)(`p`,{role:`status`,className:`text-muted-foreground flex min-w-0 items-center gap-2`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),(0,j.jsxs)(`span`,{className:`truncate`,children:[`Reading `,t,`…`]})]}),n&&(0,j.jsx)(`p`,{role:`alert`,className:`text-destructive wrap-anywhere`,children:n}),a.length>0&&!i&&(0,j.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:q3})]})}var $3=(0,v.createContext)(null),e6=()=>{let e=(0,v.useContext)($3);if(!e)throw Error(`ChainOfThought components must be used within ChainOfThought`);return e},t6=(0,v.memo)(({className:e,open:t,defaultOpen:n=!1,onOpenChange:r,children:i,...a})=>{let[o,s]=Qn({prop:t,defaultProp:n,onChange:r}),c=(0,v.useMemo)(()=>({isOpen:o}),[o]);return(0,j.jsx)($3.Provider,{value:c,children:(0,j.jsx)(O2,{asChild:!0,open:o,onOpenChange:s,children:(0,j.jsx)(`div`,{className:A(`not-prose min-w-0 max-w-prose space-y-4`,e),...a,children:i})})})}),n6=(0,v.memo)(({className:e,children:t,...n})=>{let{isOpen:r}=e6();return(0,j.jsxs)(k2,{className:A(`flex min-w-0 w-full items-center gap-2 rounded-sm text-muted-foreground text-sm hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,e),...n,children:[(0,j.jsx)(Fm,{"aria-hidden":`true`,className:`size-4 shrink-0`}),(0,j.jsx)(`span`,{className:`min-w-0 flex-1 text-left wrap-anywhere`,children:t??`Chain of Thought`}),(0,j.jsx)(Ym,{"aria-hidden":`true`,className:A(`size-4 shrink-0`,r?`rotate-180`:`rotate-0`)})]})}),r6=(0,v.memo)(({className:e,icon:t=xh,label:n,description:r,status:i=`complete`,children:a,...o})=>(0,j.jsxs)(`div`,{className:A(`flex min-w-0 gap-2 text-sm`,{complete:`text-muted-foreground`,active:`text-foreground`,pending:`text-muted-foreground/50`}[i],e),...o,children:[(0,j.jsxs)(`div`,{"aria-hidden":`true`,className:`relative mt-0.5 shrink-0`,children:[(0,j.jsx)(t,{className:`size-4`}),(0,j.jsx)(`div`,{className:`-mx-px absolute top-7 bottom-0 left-1/2 w-px bg-border`})]}),(0,j.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-2 wrap-anywhere`,children:[(0,j.jsx)(`div`,{children:n}),r&&(0,j.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:r}),a]})]})),i6=(0,v.memo)(({className:e,children:t,...n})=>(0,j.jsx)(A2,{className:A(`mt-2 min-w-0 space-y-3 text-foreground outline-none`,e),...n,children:t}));t6.displayName=`ChainOfThought`,n6.displayName=`ChainOfThoughtHeader`,r6.displayName=`ChainOfThoughtStep`,i6.displayName=`ChainOfThoughtContent`;function a6({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`empty`,className:A(`flex min-w-0 flex-1 flex-col items-center justify-center gap-6 rounded-lg border-dashed p-6 text-center text-balance md:p-12`,e),...t})}function o6({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`empty-header`,className:A(`flex max-w-sm flex-col items-center gap-2 text-center`,e),...t})}var s6=ce(`mb-2 flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0`,{variants:{variant:{default:`bg-transparent`,icon:`flex size-10 shrink-0 items-center justify-center rounded-lg bg-muted text-foreground [&_svg:not([class*='size-'])]:size-6`}},defaultVariants:{variant:`default`}});function c6({className:e,variant:t=`default`,...n}){return(0,j.jsx)(`div`,{"data-slot":`empty-icon`,"data-variant":t,className:A(s6({variant:t,className:e})),...n})}function l6({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`empty-title`,className:A(`text-lg font-medium tracking-tight`,e),...t})}function u6({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`empty-description`,className:A(`text-sm/relaxed text-muted-foreground [&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary`,e),...t})}function d6({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`empty-content`,className:A(`flex w-full max-w-sm min-w-0 flex-col items-center gap-4 text-sm text-balance`,e),...t})}function f6({...e}){return(0,j.jsx)(eo,{"data-slot":`sheet`,...e})}function p6({...e}){return(0,j.jsx)(oo,{"data-slot":`sheet-portal`,...e})}function m6({className:e,...t}){return(0,j.jsx)(co,{"data-slot":`sheet-overlay`,className:A(`fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0`,e),...t})}function h6({className:e,children:t,side:n=`right`,showCloseButton:r=!0,...i}){return(0,j.jsxs)(p6,{children:[(0,j.jsx)(m6,{}),(0,j.jsxs)(po,{"data-slot":`sheet-content`,className:A(`fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:animate-in data-[state=open]:duration-500`,n===`right`&&`inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm`,n===`left`&&`inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm`,n===`top`&&`inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top`,n===`bottom`&&`inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom`,e),...i,children:[t,r&&(0,j.jsxs)(bo,{className:`absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-secondary`,children:[(0,j.jsx)(d_,{className:`size-4`}),(0,j.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function g6({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`sheet-header`,className:A(`flex flex-col gap-1.5 p-4`,e),...t})}function _6({className:e,...t}){return(0,j.jsx)(_o,{"data-slot":`sheet-title`,className:A(`font-semibold text-foreground`,e),...t})}function v6({className:e,...t}){return(0,j.jsx)(vo,{"data-slot":`sheet-description`,className:A(`text-sm text-muted-foreground`,e),...t})}function y6({className:e,value:t,...n}){return(0,j.jsx)(cf,{"data-slot":`progress`,className:A(`relative h-2 w-full overflow-hidden rounded-full bg-primary/20`,e),...n,children:(0,j.jsx)(uf,{"data-slot":`progress-indicator`,className:`h-full w-full flex-1 bg-primary transition-all`,style:{transform:`translateX(-${100-(t||0)}%)`}})})}function b6(){let[e,t]=(0,v.useState)({step:`idle`}),n=async()=>{t({step:`busy`});let e=await eP();t(e.ok?{step:`done`,filename:e.filename}:{step:`error`,error:e.error})};return(0,j.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,j.jsxs)(M,{type:`button`,variant:`outline`,className:`self-start`,disabled:e.step===`busy`,onClick:()=>void n(),children:[e.step===`busy`?(0,j.jsx)(R2,{"aria-hidden":`true`}):(0,j.jsx)(Ch,{"aria-hidden":`true`}),`Export to Obsidian`]}),(0,j.jsx)(`p`,{className:`text-muted-foreground text-sm`,role:`status`,children:e.step===`done`?`Downloaded ${e.filename}. Unzip it into your vault: it adds a Mivra folder of concepts and memories that link to your notes.`:`Concepts and memories as linked notes, for your Obsidian vault. Your own notes aren't included.`}),e.step===`error`&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,children:e.error})]})}var x6=cM*4,S6=1048576;function C6(e){let t=(e.webkitRelativePath||e.name).split(`/`);return t.length<2?{folder:void 0,path:t[0]}:{folder:t[0],path:t.slice(1).join(`/`)}}function w6(e){let t,n=[],r=[],i=0,a=0;for(let o of Array.from(e)){let e=C6(o);t??=e.folder;let{path:s}=e;if(!s.split(`/`).some(e=>e.startsWith(`.`)||e===``)){if(!/\.md$/i.test(s))i++;else if(o.size>x6)r.push(s);else{if(n.length>=1e4)return{ok:!1,error:`This folder has more than ${sM.toLocaleString(`en`)} notes, more than one import can take.`};if(a+=o.size,a>67108864)return{ok:!1,error:`This folder's notes come to more than ${lM/S6} MB, more than one import can take.`};n.push({path:s,file:o})}}}return n.sort((e,t)=>e.path.localeCompare(t.path)),{ok:!0,folder:t,notes:n,tooLong:r,notMarkdown:i}}async function T6(e,t){let n=w6(e);if(!n.ok)return n;let{folder:r,notes:i,notMarkdown:a}=n,o=[...n.tooLong],s=[];t?.(0,i.length);for(let[e,{path:n,file:r}]of i.entries()){let a;try{a=await r.text()}catch{return{ok:!1,error:`Couldn't read ${n}. It may have been moved or deleted; choose the folder again.`}}a.length>1e6?o.push(n):s.push({path:n,text:a}),t?.(e+1,i.length)}return{ok:!0,vault:{folder:r,files:s,notMarkdown:a,tooLong:o}}}var E6=(e,t,n=`${t}s`)=>`${e.toLocaleString(`en`)} ${e===1?t:n}`,D6=1500,O6=e=>e.status===`queued`||e.status===`running`;function k6({open:e,onOpenChange:t,onOpenGraph:n}){let r=(0,v.useRef)(!1),[i,a]=(0,v.useState)(),[o,s]=(0,v.useState)(),[c,l]=(0,v.useState)({open:!1,key:0}),u=e=>l(t=>({open:!0,key:t.key+1,...e?{reimport:e}:{}}));(0,v.useEffect)(()=>{if(!e)return;let t=!1;return a(void 0),s(void 0),l(e=>({...e,open:!1})),iN().then(e=>{t||(e.ok?a(e.value):s(e.error))}),()=>{t=!0}},[e]);let d=({import:e})=>a((t=[])=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e]),f=(e,t)=>a(n=>n?.map(n=>n.id===e?{...n,distillation:t}:n)),p=!!i?.some(e=>O6(e.distillation));return(0,v.useEffect)(()=>{if(!e||!p)return;let t=!1,n=setInterval(()=>{iN().then(e=>{!t&&e.ok&&a(e.value)})},D6);return()=>{t=!0,clearInterval(n)}},[e,p]),(0,j.jsxs)(f6,{open:e,onOpenChange:t,children:[(0,j.jsxs)(h6,{className:`w-full overflow-y-auto sm:max-w-md`,onCloseAutoFocus:e=>{e.preventDefault(),r.current?(r.current=!1,document.querySelector(`[data-notes-graph-start]`)?.focus()):(document.querySelector(`[data-imports-trigger]`)??document.querySelector(`[data-sidebar="trigger"]`))?.focus()},children:[(0,j.jsxs)(g6,{children:[(0,j.jsx)(_6,{className:`font-heading`,children:`Imported notes`}),(0,j.jsx)(v6,{children:`Notes from your Obsidian vaults. They're read-only here: edit them in Obsidian, then re-import the vault.`})]}),(0,j.jsxs)(`div`,{className:`flex flex-col gap-4 px-4 pb-4`,"aria-live":`polite`,children:[i&&i.length>0&&(0,j.jsxs)(M,{type:`button`,className:`self-start`,onClick:()=>u(),children:[(0,j.jsx)(zh,{"aria-hidden":`true`}),`Import a vault`]}),i&&i.length>0&&(0,j.jsx)(b6,{}),o&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,children:o}),!i&&!o&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Loading imports…`]}),i?.length===0&&(0,j.jsxs)(a6,{className:`border p-6 md:p-6`,children:[(0,j.jsxs)(o6,{children:[(0,j.jsx)(c6,{variant:`icon`,children:(0,j.jsx)(tg,{"aria-hidden":`true`})}),(0,j.jsx)(l6,{children:`No vaults imported yet`}),(0,j.jsx)(u6,{children:`Import an Obsidian vault to bring its notes, links and tags into Mivra. Only Markdown notes are read.`})]}),(0,j.jsx)(d6,{children:(0,j.jsxs)(M,{type:`button`,onClick:()=>u(),children:[(0,j.jsx)(zh,{"aria-hidden":`true`}),`Import a vault`]})})]}),i&&i.length>0&&(0,j.jsx)(`ul`,{className:`flex flex-col gap-2`,"aria-label":`Imported vaults`,children:i.map(e=>(0,j.jsx)(A6,{entry:e,onReimport:()=>u(e),onGraph:n&&(()=>{r.current=!0,n(e.id),t(!1)}),onDelete:()=>a(t=>t?.filter(t=>t.id!==e.id)),onDistillation:t=>f(e.id,t)},e.id))})]})]}),(0,j.jsx)(P6,{open:c.open,onOpenChange:e=>{e||l(e=>({...e,open:!1}))},imports:i??[],...c.reimport?{reimport:c.reimport}:{},onImported:d},c.key)]})}function A6({entry:e,onReimport:t,onGraph:n,onDelete:r,onDistillation:i}){let[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(),d=async()=>{c(!0),u(void 0);let t=await aN(e.id);c(!1),t.ok?r():u(t.error)};return(0,j.jsxs)(`li`,{className:`flex flex-col gap-2 rounded-lg border p-3 text-sm wrap-anywhere`,"aria-label":e.name,children:[(0,j.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,j.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,j.jsxs)(`span`,{className:`text-muted-foreground text-xs`,children:[E6(e.noteCount,`note`),` · Updated `,new Date(e.updatedAt).toLocaleDateString()]})]}),(0,j.jsx)(j6,{entry:e,onChange:i}),a?(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,j.jsxs)(`span`,{className:`text-muted-foreground`,children:[`Delete this import and its `,E6(e.noteCount,`note`),`, with the concepts and memories drawn from them? Your vault itself isn't touched.`]}),(0,j.jsxs)(M,{type:`button`,variant:`destructive`,size:`sm`,disabled:s,onClick:()=>void d(),children:[s&&(0,j.jsx)(R2,{"aria-hidden":`true`}),`Yes, delete`]}),(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,disabled:s,onClick:()=>o(!1),children:`Keep`})]}):(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[n&&e.noteCount>0&&(0,j.jsxs)(M,{type:`button`,variant:`outline`,size:`sm`,onClick:n,children:[(0,j.jsx)(s_,{"aria-hidden":`true`}),`Graph`]}),(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,onClick:t,children:`Re-import`}),(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>o(!0),children:`Delete`})]}),l&&(0,j.jsx)(`p`,{className:`text-destructive`,role:`alert`,children:l})]})}function j6({entry:e,onChange:t}){let n=e.distillation,[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(),s=async n=>{i(!0),o(void 0);let r=await n(e.id);i(!1),r.ok?t(r.value):o(r.error)},c=`${E6(n.concepts,`concept`)} and ${E6(n.memories,`memory`,`memories`)} drawn from these notes`,l;if(O6(n)){let e=n.groups>0?Math.round(n.groupsDone/n.groups*100):0;l=(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),n.status===`queued`?`Waiting to read these notes for concepts…`:n.groups>0?`Reading notes for concepts… group ${Math.min(n.groupsDone+1,n.groups).toLocaleString(`en`)} of ${n.groups.toLocaleString(`en`)}`:`Reading notes for concepts…`]}),(0,j.jsx)(y6,{value:e,"aria-label":`Reading notes for concepts`}),(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,className:`self-start`,disabled:r,onClick:()=>void s(sN),children:`Cancel`})]})}else if(n.pendingNotes>0){let e=n.status===`failed`?`Reading notes for concepts stopped: ${n.error??`the model request failed.`}`:n.status===`cancelled`?`Cancelled. ${E6(n.pendingNotes,`note`)} not read for concepts yet.`:`${E6(n.pendingNotes,`note`)} not read for concepts yet.`;l=(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`p`,{className:n.status===`failed`?`text-destructive`:`text-muted-foreground`,children:e}),(n.concepts>0||n.memories>0)&&(0,j.jsxs)(`p`,{className:`text-muted-foreground`,children:[`So far: `,c,`.`]}),(0,j.jsxs)(M,{type:`button`,variant:`outline`,size:`sm`,className:`self-start`,disabled:r,onClick:()=>void s(oN),children:[r&&(0,j.jsx)(R2,{"aria-hidden":`true`}),n.status===`failed`?`Try again`:n.status===`cancelled`?`Resume`:`Read notes`]})]})}else if(n.concepts>0||n.memories>0)l=(0,j.jsxs)(`p`,{className:`text-muted-foreground`,children:[c[0].toUpperCase()+c.slice(1),`.`]});else return null;return(0,j.jsxs)(`div`,{className:`flex flex-col gap-2`,role:`group`,"aria-label":`Concepts from these notes`,children:[l,a&&(0,j.jsx)(`p`,{className:`text-destructive`,role:`alert`,children:a})]})}var M6=e=>e.replace(/\.zip$/i,``).trim(),N6=e=>(e.kind===`zip`?M6(e.file.name):e.vault.folder??``).slice(0,120);function P6({open:e,onOpenChange:t,imports:n,reimport:r,onImported:i}){let a=(0,v.useId)(),o=(0,v.useRef)(null),s=(0,v.useRef)(null),[c,l]=(0,v.useState)({step:`choose`}),[u,d]=(0,v.useState)(``),f=(0,v.useRef)(0);(0,v.useEffect)(()=>{e&&(f.current++,l({step:`choose`}),d(``))},[e]);let p=r??n.find(e=>e.name===u.trim()),m=p?{importId:p.id}:{name:u.trim()},h=async e=>{let t=++f.current;l({step:`reading`,read:0,total:0});let n=await T6(e,(e,n)=>{f.current===t&&l({step:`reading`,read:e,total:n})});if(f.current!==t)return;if(!n.ok)return l({step:`choose`,error:n.error});if(n.vault.files.length===0)return l({step:`choose`,error:`No Markdown notes were found in this folder. Choose the folder that holds your vault's notes.`});let r={kind:`folder`,vault:n.vault};d(N6(r)),l({step:`ready`,source:r})},g=e=>{f.current++;let t={kind:`zip`,file:e};d(N6(t)),l({step:`ready`,source:t})},_=async e=>{if(e.preventDefault(),c.step!==`ready`)return;let{source:t}=c,n=++f.current;l({step:`sending`,source:t});let r=t.kind===`zip`?await pN(m,t.file):await fN(m,t.vault.files);if(f.current===n){if(!r.ok)return l({step:`ready`,source:t,error:r.error});i(r.value),l({step:`done`,result:r.value,source:t,replaced:!!p})}},y=r?`Re-import ${r.name}`:`Import an Obsidian vault`;return(0,j.jsx)(F4,{open:e,onOpenChange:t,children:(0,j.jsxs)(R4,{className:`sm:max-w-lg`,children:[(0,j.jsxs)(z4,{children:[(0,j.jsx)(V4,{className:`font-heading wrap-anywhere`,children:y}),(0,j.jsx)(H4,{children:r?`Choose the same vault again. Changed notes are updated, new ones added, and notes that are gone from it removed.`:`Choose your vault's folder. Only Markdown notes are read; attachments and hidden folders such as .obsidian are left out.`})]}),(0,j.jsx)(`input`,{ref:o,type:`file`,multiple:!0,className:`hidden`,"data-testid":`vault-folder-input`,webkitdirectory:``,onChange:e=>{let t=e.target.files;t&&t.length>0&&h(t),e.target.value=``}}),(0,j.jsx)(`input`,{ref:s,type:`file`,accept:`.zip,application/zip`,className:`hidden`,"data-testid":`vault-zip-input`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&g(t)}}),c.step===`choose`&&(0,j.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,j.jsxs)(P2,{"data-invalid":!!c.error,children:[(0,j.jsxs)(M,{type:`button`,onClick:()=>o.current?.click(),children:[(0,j.jsx)(zh,{"aria-hidden":`true`}),`Choose vault folder`]}),c.error&&(0,j.jsx)(L2,{role:`alert`,children:c.error})]}),(0,j.jsxs)(`p`,{className:`text-muted-foreground text-sm`,children:[`Can't choose a folder on this device?`,` `,(0,j.jsx)(M,{type:`button`,variant:`link`,className:`h-auto p-0`,onClick:()=>s.current?.click(),children:`Upload a .zip instead`})]})]}),c.step===`reading`&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),c.total>0?`Reading notes… ${c.read.toLocaleString(`en`)} of ${c.total.toLocaleString(`en`)}`:`Looking through the folder…`]}),(c.step===`ready`||c.step===`sending`)&&(0,j.jsxs)(`form`,{onSubmit:_,className:`flex flex-col gap-4`,children:[(0,j.jsx)(F6,{source:c.source}),!r&&(0,j.jsxs)(P2,{"data-invalid":c.step===`ready`&&!!c.error,children:[(0,j.jsx)(F2,{htmlFor:a,children:`Import name`}),(0,j.jsx)(z2,{id:a,value:u,maxLength:120,disabled:c.step===`sending`,onChange:e=>d(e.target.value),"aria-describedby":`${a}-description`}),(0,j.jsx)(I2,{id:`${a}-description`,children:p?`An import called ${p.name} already exists, so this re-imports it: changed notes are updated and notes that are gone are removed.`:`Tells your imports apart. Import the same vault under this name again to update it.`})]}),c.step===`ready`&&c.error&&(0,j.jsx)(L2,{role:`alert`,className:`wrap-anywhere`,children:c.error}),c.step===`sending`&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),c.source.kind===`zip`?`Uploading and unpacking the zip…`:`Sending ${E6(c.source.vault.files.length,`note`)}…`]}),(0,j.jsxs)(B4,{children:[(0,j.jsx)(M,{type:`button`,variant:`outline`,disabled:c.step===`sending`,onClick:()=>l({step:`choose`}),children:`Choose again`}),(0,j.jsxs)(M,{type:`submit`,disabled:c.step===`sending`||!r&&!u.trim(),children:[c.step===`sending`&&(0,j.jsx)(R2,{"aria-hidden":`true`}),p?`Re-import`:`Import`]})]})]}),c.step===`done`&&(0,j.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,j.jsx)(L6,{result:c.result,source:c.source,replaced:c.replaced}),(0,j.jsx)(B4,{children:(0,j.jsx)(M,{type:`button`,onClick:()=>t(!1),children:`Done`})})]})]})})}function F6({source:e}){if(e.kind===`zip`)return(0,j.jsxs)(`p`,{className:`flex items-center gap-2 text-sm wrap-anywhere`,children:[(0,j.jsx)(Nh,{className:`text-muted-foreground size-4 shrink-0`,"aria-hidden":`true`}),e.file.name,` (`,(e.file.size/1048576).toFixed(1),` MB)`]});let{vault:t}=e,n=[t.notMarkdown>0&&E6(t.notMarkdown,`other file`),t.tooLong.length>0&&E6(t.tooLong.length,`note`)+` too long to import`].filter(Boolean);return(0,j.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[(0,j.jsxs)(`p`,{className:`flex items-center gap-2 wrap-anywhere`,children:[(0,j.jsx)(zh,{className:`text-muted-foreground size-4 shrink-0`,"aria-hidden":`true`}),E6(t.files.length,`note`),` found`,t.folder?` in ${t.folder}`:``]}),n.length>0&&(0,j.jsxs)(`p`,{className:`text-muted-foreground`,children:[`Left out: `,n.join(`, `),`.`]})]})}var I6={not_markdown:`not a note`,hidden:`hidden`,bad_path:`unsafe path`,duplicate:`duplicate`,too_long:`too long`,symlink:`link to another file`,generated:`exported by Mivra`};function L6({result:e,source:t,replaced:n}){let r=t.kind===`folder`?t.vault.tooLong:[],i=t.kind===`folder`?t.vault.notMarkdown:0,a=[...r.map(e=>({path:e,reason:`too_long`})),...e.skipped],o=e.skippedCount+r.length+i,s=[[`Added`,e.added],[`Updated`,e.updated],[`Removed`,e.removed],[`Unchanged`,e.unchanged]];return(0,j.jsxs)(`div`,{className:`flex flex-col gap-3 text-sm`,role:`status`,children:[(0,j.jsxs)(`p`,{className:`wrap-anywhere`,children:[n?`Re-imported`:`Imported`,` `,(0,j.jsx)(`span`,{className:`font-medium`,children:e.import.name}),`: `,E6(e.import.noteCount,`note`),` in all.`]}),(0,j.jsx)(`dl`,{className:`grid grid-cols-4 gap-2`,"aria-label":`What changed`,children:s.map(([e,t])=>(0,j.jsxs)(`div`,{className:`bg-muted flex flex-col rounded-md px-2 py-1.5`,children:[(0,j.jsx)(`dt`,{className:`text-muted-foreground text-xs`,children:e}),(0,j.jsx)(`dd`,{className:`font-medium tabular-nums`,children:t.toLocaleString(`en`)})]},e))}),o>0&&(0,j.jsxs)(`div`,{className:`text-muted-foreground flex flex-col gap-1`,children:[(0,j.jsxs)(`p`,{children:[`Skipped `,E6(o,`file`),i>0?`, including ${E6(i,`attachment or other file`,`attachments and other files`)}`:``,`.`]}),a.length>0&&(0,j.jsxs)(`ul`,{className:`list-disc pl-5 wrap-anywhere`,children:[a.slice(0,5).map(e=>(0,j.jsxs)(`li`,{children:[e.path,` (`,I6[e.reason],`)`]},`${e.path}:${e.reason}`)),a.length>5&&(0,j.jsx)(`li`,{children:`…`})]})]}),e.truncated&&(0,j.jsx)(`p`,{className:`text-muted-foreground`,children:`Some links or tags were left out: a note or the vault had more than Mivra keeps.`}),O6(e.import.distillation)&&(0,j.jsx)(`p`,{className:`text-muted-foreground`,children:`Mivra is now reading the new and changed notes for concepts and memories, using your model. Follow or cancel it in the list.`})]})}var R6=[{kind:`goal`,title:`Goals`},{kind:`preference`,title:`Preferences`},{kind:`misconception`,title:`Misconceptions`},{kind:`known`,title:`Known from your notes`}],z6=[{value:`all`,label:`All`},{value:`import`,label:`From notes`},{value:`other`,label:`From learning`}],B6=(e,t)=>e===`all`||e===`import`==(t.basis===`import`),V6=e=>e.basis===`import`?e.source?`From your note ${e.source.title}`:`From your notes`:e.basis===`wrong_answer`?`From a wrong answer`:`From chat`;function H6({open:e,onOpenChange:t}){let[n,r]=(0,v.useState)(),[i,a]=(0,v.useState)(),[o,s]=(0,v.useState)(`all`),c=n?.filter(e=>e.basis===`import`).length??0,l=n?.filter(e=>B6(o,e));return(0,v.useEffect)(()=>{if(!e)return;let t=!1;r(void 0),s(`all`);let n=()=>{a(void 0),ZM().then(e=>{t||(e.ok?r(e.value):a(e.error))})};return n(),window.addEventListener(`focus`,n),()=>{t=!0,window.removeEventListener(`focus`,n)}},[e]),(0,j.jsx)(f6,{open:e,onOpenChange:t,children:(0,j.jsxs)(h6,{className:A(`w-full overflow-y-auto sm:max-w-md`,O3),onCloseAutoFocus:e=>{e.preventDefault(),(document.querySelector(`[data-memory-trigger]`)??document.querySelector(`[data-sidebar="trigger"]`))?.focus()},children:[(0,j.jsxs)(g6,{className:k3,children:[(0,j.jsx)(_6,{className:A3,children:`Memory`}),(0,j.jsx)(v6,{children:`What Mivra has noted about you across sessions. It can be wrong, so correct or delete anything here.`})]}),(0,j.jsxs)(`div`,{className:`flex flex-col gap-5 px-5 py-5`,"aria-live":`polite`,children:[i&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,children:i}),!n&&!i&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Loading memories…`]}),n?.length===0&&(0,j.jsxs)(a6,{className:`bg-sunken/50 border border-dashed p-6 md:p-6`,children:[(0,j.jsxs)(o6,{children:[(0,j.jsx)(c6,{variant:`icon`,children:(0,j.jsx)(Fm,{"aria-hidden":`true`})}),(0,j.jsx)(l6,{children:`No memories yet`}),(0,j.jsx)(u6,{children:`Start a conversation or course. As you learn, Mivra can remember your goals, preferences and concepts to revisit.`})]}),(0,j.jsx)(d6,{children:(0,j.jsx)(M,{variant:`outline`,onClick:()=>t(!1),children:`Back to learning`})})]}),c>0&&(0,j.jsx)(U6,{filter:o,onFilter:s,count:c,onDeleted:()=>{r(e=>e?.filter(e=>e.basis!==`import`)),s(`all`)}}),l&&R6.map(({kind:e,title:t})=>{let n=l.filter(t=>t.kind===e);return n.length>0?(0,j.jsxs)(`section`,{className:`flex flex-col gap-1.5 [section+&]:border-t [section+&]:pt-4`,children:[(0,j.jsx)(`h2`,{className:`text-muted-foreground font-mono text-[0.6875rem] leading-snug font-medium tracking-[0.09em] uppercase`,children:t}),(0,j.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:n.map(e=>(0,j.jsx)(W6,{memory:e,onChange:e=>r(t=>t?.map(t=>t.id===e.id?e:t)),onDelete:()=>r(t=>t?.filter(t=>t.id!==e.id))},e.id))})]},e):null}),n&&n.length>0&&(0,j.jsx)(`div`,{className:`border-t pt-4`,children:(0,j.jsx)(b6,{})})]})]})})}function U6({filter:e,onFilter:t,count:n,onDeleted:r}){let[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(),u=async()=>{s(!0),l(void 0);let e=await eN();if(s(!1),!e.ok)return l(e.error);a(!1),r()};return(0,j.jsxs)(`div`,{className:`flex flex-col gap-2 text-sm`,children:[(0,j.jsx)(`div`,{className:j3,role:`group`,"aria-label":`Show memories`,children:z6.map(({value:n,label:r})=>(0,j.jsx)(M,{type:`button`,size:`sm`,variant:`ghost`,className:M3(e===n),"aria-pressed":e===n,onClick:()=>t(n),children:r},n))}),e===`import`&&(i?(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,j.jsxs)(`span`,{className:`text-muted-foreground`,children:[`Delete all `,n.toLocaleString(`en`),` memories drawn from your notes? Your notes stay imported.`]}),(0,j.jsxs)(M,{type:`button`,variant:`destructive`,size:`sm`,disabled:o,onClick:()=>void u(),children:[o&&(0,j.jsx)(R2,{"aria-hidden":`true`}),`Yes, delete all`]}),(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,disabled:o,onClick:()=>a(!1),children:`Keep`})]}):(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,className:`self-start`,onClick:()=>a(!0),children:`Delete all from notes`})),c&&(0,j.jsx)(`p`,{className:`text-destructive`,role:`alert`,children:c})]})}function W6({memory:e,onChange:t,onDelete:n}){let r=(0,v.useId)(),[i,a]=(0,v.useState)(`view`),[o,s]=(0,v.useState)(e.text??``),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(),f=async n=>{n.preventDefault(),l(!0),d(void 0);let r=await QM(e.id,o);if(l(!1),!r.ok)return d(r.error);t(r.value),a(`view`)},p=async()=>{l(!0),d(void 0);let t=await $M(e.id);l(!1),t.ok?n():d(t.error)};return(0,j.jsxs)(`li`,{className:`hover:bg-sunken focus-within:bg-sunken -mx-2.5 flex flex-col gap-1.5 rounded-lg px-2.5 py-2.5 text-[0.95rem] leading-snug wrap-anywhere transition-colors`,children:[i===`edit`?(0,j.jsxs)(`form`,{onSubmit:f,className:`flex flex-col gap-2`,children:[(0,j.jsxs)(P2,{"data-invalid":!!u,children:[(0,j.jsx)(F2,{htmlFor:r,children:`Memory text`}),(0,j.jsx)(S0,{id:r,"aria-describedby":`${r}-description${u?` ${r}-error`:``}`,"aria-invalid":!!u,value:o,maxLength:300,onChange:e=>s(e.target.value),autoFocus:!0}),(0,j.jsx)(I2,{id:`${r}-description`,children:`Correct what Mivra should remember. Up to 300 characters.`}),u&&(0,j.jsx)(L2,{id:`${r}-error`,role:`alert`,children:u})]}),(0,j.jsxs)(`div`,{className:`flex gap-2`,children:[(0,j.jsxs)(M,{type:`submit`,size:`sm`,disabled:c||!o.trim(),children:[c&&(0,j.jsx)(R2,{"aria-hidden":`true`}),c?`Saving…`:`Save`]}),(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{s(e.text??``),d(void 0),a(`view`)},children:`Cancel`})]})]}):(0,j.jsxs)(j.Fragment,{children:[e.held?(0,j.jsx)(`p`,{className:`text-muted-foreground italic`,children:`Hidden until you answer the check in that session.`}):(0,j.jsx)(`p`,{children:e.text}),(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[!e.held&&(0,j.jsx)(`span`,{className:`text-muted-foreground max-w-full truncate text-[0.8125rem]`,title:e.source?`${e.source.importName}: ${e.source.path}`:void 0,children:V6(e)}),e.editedAt&&(0,j.jsx)(D2,{variant:`outline`,children:`Edited by you`}),(0,j.jsx)(`span`,{className:`text-muted-foreground font-mono text-[0.72rem]`,children:new Date(e.createdAt).toLocaleDateString()})]}),i===`confirm-delete`?(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,j.jsx)(`span`,{className:`text-muted-foreground`,children:`Delete permanently?`}),(0,j.jsx)(M,{type:`button`,variant:`destructive`,size:`sm`,disabled:c,onClick:()=>void p(),children:`Yes, delete`}),(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>a(`view`),children:`Keep`})]}):(0,j.jsxs)(`div`,{className:`flex gap-1.5`,children:[!e.held&&(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 bg-card dark:bg-card border-border-strong dark:border-border-strong hover:bg-sunken dark:hover:bg-sunken`,onClick:()=>{s(e.text??``),a(`edit`)},children:`Edit`}),(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 bg-card dark:bg-card border-border-strong dark:border-border-strong hover:bg-sunken dark:hover:bg-sunken`,onClick:()=>a(`confirm-delete`),children:`Delete`})]})]}),u&&i!==`edit`&&(0,j.jsx)(`p`,{className:`text-destructive`,role:`alert`,children:u})]})}function G6({...e}){return(0,j.jsx)(If,{"data-slot":`select`,...e})}function K6({...e}){return(0,j.jsx)(Bf,{"data-slot":`select-value`,...e})}function q6({className:e,size:t=`default`,children:n,...r}){return(0,j.jsxs)(Rf,{"data-slot":`select-trigger`,"data-size":t,className:A(`flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground`,e),...r,children:[n,(0,j.jsx)(Vf,{asChild:!0,children:(0,j.jsx)(Ym,{className:`size-4 opacity-50`})})]})}function J6({className:e,children:t,position:n=`item-aligned`,align:r=`center`,...i}){return(0,j.jsx)(Wf,{children:(0,j.jsxs)(Kf,{"data-slot":`select-content`,className:A(`relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,n===`popper`&&`data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1`,e),position:n,align:r,...i,children:[(0,j.jsx)(X6,{}),(0,j.jsx)(ip,{className:A(`p-1`,n===`popper`&&`h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1`),children:t}),(0,j.jsx)(Z6,{})]})})}function Y6({className:e,children:t,...n}){return(0,j.jsxs)(up,{"data-slot":`select-item`,className:A(`relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2`,e),...n,children:[(0,j.jsx)(`span`,{"data-slot":`select-item-indicator`,className:`absolute right-2 flex size-3.5 items-center justify-center`,children:(0,j.jsx)(mp,{children:(0,j.jsx)(qm,{className:`size-4`})})}),(0,j.jsx)(fp,{children:t})]})}function X6({className:e,...t}){return(0,j.jsx)(gp,{"data-slot":`select-scroll-up-button`,className:A(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,j.jsx)(th,{className:`size-4`})})}function Z6({className:e,...t}){return(0,j.jsx)(vp,{"data-slot":`select-scroll-down-button`,className:A(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,j.jsx)(Ym,{className:`size-4`})})}var Q6=220,$6=70,e8=4e4,t8=40,n8=14;function r8(e=1){let t=e;return()=>(t=(t*1664525+1013904223)%4294967296,t/4294967296)}function i8(e,t){return e===`note`?5+Math.min(7,Math.sqrt(t)*1.4):e===`ghost`?4:5+Math.min(5,Math.sqrt(t))}function a8(e){let t=new Map(e.nodes.map((e,t)=>[e.id,t])),n=e.edges.flatMap(({from:e,to:n})=>{let r=t.get(e),i=t.get(n);return r===void 0||i===void 0||r===i?[]:[[r,i]]}),r=e.nodes.map(()=>0);for(let[e,t]of n)r[e]++,r[t]++;let i=e.nodes.map((e,t)=>({index:t,radius:i8(e.kind,r[t])}));if(i.length>0){let e=Math.min(1,60/i.length),t=Math.round(Math.min(Q6,Math.max($6,e8/i.length))),r=Math.round(t*.65);I$(i).stop().randomSource(r8()).alphaDecay(1-.001**(1/t)).force(`link`,t$(n.map(([e,t])=>({source:e,target:t}))).id(e=>e.index).distance(e=>26+e.source.radius+e.target.radius)).force(`charge`,L$().strength(-90-120*e).theta(.9).distanceMax(250)).force(`x`,R$().strength(.06)).force(`y`,z$().strength(.06)).tick(r).force(`collide`,QQ(e=>e.radius+n8).iterations(1)).tick(t-r)}let a=i.length>0?i.map(e=>e.x):[0],o=i.length>0?i.map(e=>e.y):[0],s=Math.min(...a)-t8,c=Math.min(...o)-t8,l=Math.max(...a)+t8-s,u=Math.max(...o)+t8+n8-c;return{width:Math.max(l,200),height:Math.max(u,160),nodes:i.map((t,n)=>({id:e.nodes[n].id,x:t.x-s,y:t.y-c,radius:t.radius})),edges:n}}var o8=`__all`,s8=1.25,c8=.1,l8=3,u8=1.6,d8=150,f8=14,p8=200,m8=(e,t,n=`${t}s`)=>`${e.toLocaleString(`en`)} ${e===1?t:n}`,h8=e=>Math.min(l8,Math.max(c8,e));function g8(e,t){let n=m8(t,`connection`);switch(e.kind){case`note`:return`${e.label}, note in ${e.path}, ${n}`;case`tag`:return`${e.label}, tag on ${m8(e.notes??0,`note`)}`;case`concept`:return`${e.label}, concept from ${m8(e.notes??0,`note`)}`;case`ghost`:return`${e.label}, unresolved link, no such note`}}var _8,v8=0;function y8(e){let[t,n]=(0,v.useState)();return(0,v.useEffect)(()=>{if(!e)return;let t=()=>n({view:e,layout:a8(e)});if(typeof Worker>`u`)return t();let r;try{r=_8??=new Worker(new URL(`/assets/notes-graph.worker-DaVQvftJ.js`,``+import.meta.url),{type:`module`,name:`mivra-graph-layout`})}catch{return t()}let i=++v8,a=!1,o=()=>{a=!0,r.removeEventListener(`message`,s),r.removeEventListener(`error`,c)},s=t=>{t.data.id===i&&(o(),n({view:e,layout:t.data.layout}))},c=()=>{o(),r.terminate(),_8===r&&(_8=void 0),t()};return r.addEventListener(`message`,s),r.addEventListener(`error`,c),r.postMessage({id:i,view:{nodes:e.nodes,edges:e.edges}}),()=>{a||(o(),r.terminate(),_8===r&&(_8=void 0))}},[e]),{drawn:t,pending:!!(e&&t?.view!==e)}}function b8({importId:e}){let[t,n]=(0,v.useState)(e);(0,v.useEffect)(()=>n(e),[e]);let[r,i]=(0,v.useState)([]);(0,v.useEffect)(()=>{iN().then(e=>e.ok&&i(e.value))},[]);let[a,o]=(0,v.useState)({mode:`auto`,depth:2}),[s,c]=(0,v.useState)({loading:!0});(0,v.useEffect)(()=>{let e=!1;return c(e=>({...e,loading:!0,error:void 0})),cN(t,a).then(t=>{e||c(t.ok?{view:t.value,loading:!1}:{error:t.error,loading:!1})}),()=>{e=!0}},[t,a]);let l=s.view,u=y8(l),[d,f]=(0,v.useState)(),[p,m]=(0,v.useState)();(0,v.useEffect)(()=>{l&&f(e=>e&&l.nodes.some(t=>t.id===e)?e:l.focus??void 0)},[l]);let h=e=>{n(e),o({mode:`auto`,depth:2}),f(void 0)},g=e=>{f(e),o(t=>({...t,focus:e,mode:l&&l.matchingNotes>500?`local`:t.mode}))},_=e=>{f(e.id),e.kind===`note`&&m(e.id)},y=r.find(e=>e.id===t)?.name,b=!!(l&&l.matchingNotes>500);return(0,j.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,"data-testid":`notes-graph`,children:[(0,j.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2 border-b p-3`,role:`toolbar`,"aria-label":`Graph filters`,children:[(0,j.jsx)(S8,{label:`Import`,value:t,onChange:h,options:(r.length>0?r:[{id:t,name:`This import`}]).map(e=>({value:e.id,text:e.name}))}),(0,j.jsx)(S8,{label:`Tag`,value:a.tag??o8,onChange:e=>o(t=>({...t,tag:e===o8?void 0:e})),options:[{value:o8,text:`All tags`},...x8(l?.tags.map(e=>({value:e.name,text:`#${e.name} (${e.notes})`}))??[],a.tag,e=>`#${e}`)]}),(0,j.jsx)(S8,{label:`Folder`,value:a.folder??o8,onChange:e=>o(t=>({...t,folder:e===o8?void 0:e})),options:[{value:o8,text:`All folders`},...x8(l?.folders.map(e=>({value:e.path,text:`${e.path} (${e.notes})`}))??[],a.folder,e=>e)]}),(0,j.jsx)(S8,{label:`Show`,value:a.mode===`local`||b?`local`:`auto`,onChange:e=>o(t=>({...t,mode:e})),options:[{value:`auto`,text:b?`Whole graph (over 500 notes)`:`Whole graph`,disabled:b},{value:`local`,text:`Around the selected note`}]}),(a.mode===`local`||b)&&(0,j.jsx)(S8,{label:`Reach`,value:String(a.depth),onChange:e=>o(t=>({...t,depth:Number(e)})),options:[1,2,3].map(e=>({value:String(e),text:m8(e,`hop`)}))}),(0,j.jsx)(C8,{importId:t,onPick:e=>g(e.id)})]}),(0,j.jsx)(w8,{view:l,loading:s.loading||u.pending,error:s.error,importName:y}),u.drawn&&(0,j.jsx)(O8,{view:u.drawn.view,layout:u.drawn.layout,selected:d,onSelect:f,onActivate:_}),(0,j.jsx)(A8,{noteId:p,onOpenChange:e=>!e&&m(void 0),onCentre:e=>{m(void 0),o(t=>({...t,mode:`local`,focus:e})),f(e)}})]})}function x8(e,t,n){return t&&!e.some(e=>e.value===t)?[{value:t,text:n(t)},...e]:e}function S8({label:e,value:t,onChange:n,options:r}){let i=(0,v.useId)();return(0,j.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,j.jsx)(`span`,{id:i,className:`text-muted-foreground text-xs`,children:e}),(0,j.jsxs)(G6,{value:t,onValueChange:n,children:[(0,j.jsx)(q6,{size:`sm`,"aria-labelledby":i,className:`max-w-56`,children:(0,j.jsx)(K6,{})}),(0,j.jsx)(J6,{position:`popper`,className:`max-h-80`,children:r.map(e=>(0,j.jsx)(Y6,{value:e.value,disabled:e.disabled,children:e.text},e.value))})]})]})}function C8({importId:e,onPick:t}){let[n,r]=(0,v.useState)(!1),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)([]);return(0,v.useEffect)(()=>{let t=i.trim();if(!t)return s([]);let n=!1,r=setTimeout(()=>{lN(e,t).then(e=>{!n&&e.ok&&s(e.value)})},p8);return()=>{n=!0,clearTimeout(r)}},[e,i]),(0,j.jsxs)(r3,{open:n,onOpenChange:r,children:[(0,j.jsx)(i3,{asChild:!0,children:(0,j.jsxs)(M,{type:`button`,variant:`outline`,size:`sm`,children:[(0,j.jsx)(Lg,{}),`Find a note`]})}),(0,j.jsx)(a3,{className:`w-80 p-0`,align:`start`,children:(0,j.jsxs)(U4,{shouldFilter:!1,children:[(0,j.jsx)(W4,{placeholder:`Title or path`,value:i,onValueChange:a,"aria-label":`Find a note by title or path`}),(0,j.jsxs)(G4,{children:[i.trim()&&(0,j.jsx)(K4,{children:`No note matches.`}),o.map(e=>(0,j.jsx)(J4,{value:e.id,onSelect:()=>{r(!1),a(``),t(e)},children:(0,j.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[(0,j.jsx)(`span`,{className:`truncate`,children:e.title}),(0,j.jsx)(`span`,{className:`text-muted-foreground truncate text-xs`,children:e.path})]})},e.id))]})]})})]})}function w8({view:e,loading:t,error:n,importName:r}){let i=``;if(e){let t=t=>e.nodes.filter(e=>e.kind===t).length,n=[m8(t(`note`),`note`),m8(t(`tag`),`tag`),m8(t(`concept`),`concept`),m8(t(`ghost`),`unresolved link`)],r=e.nodes.find(t=>t.id===e.focus),a=e.mode===`whole`?`Whole graph`:`Around ${r?.label??`the best-connected note`}, within ${m8(e.depth,`hop`)}`,o=e.matchingNotes===e.totalNotes?m8(e.totalNotes,`note`):`${m8(e.matchingNotes,`matching note`)} (${m8(e.totalNotes,`note`)} in all)`;i=`${a}: ${n.join(`, `)}, of ${o}.${e.truncated?` Only the nearest are drawn; filter or centre on a note to see others.`:``}`,e.matchingNotes===0&&(i=e.totalNotes===0?`This import has no notes.`:`No note matches these filters.`)}return(0,j.jsxs)(`div`,{className:`flex min-h-9 items-center gap-2 border-b px-3 py-1.5 text-sm`,children:[r&&(0,j.jsxs)(`span`,{className:`sr-only`,children:[r,`.`]}),(0,j.jsx)(`p`,{role:`status`,"aria-live":`polite`,className:A(`min-w-0 flex-1`,n?`text-destructive`:`text-muted-foreground`),"data-testid":`notes-graph-status`,children:n??i}),t&&(0,j.jsx)(R2,{"aria-label":`Loading the graph`}),(0,j.jsx)(T8,{})]})}function T8(){return(0,j.jsx)(`ul`,{className:`text-muted-foreground hidden shrink-0 items-center gap-3 text-xs sm:flex`,"aria-hidden":`true`,children:[[`note`,`Note`],[`concept`,`Concept`],[`tag`,`Tag`],[`ghost`,`Unresolved`]].map(([e,t])=>(0,j.jsxs)(`li`,{className:`flex items-center gap-1`,children:[(0,j.jsx)(`svg`,{viewBox:`-7 -7 14 14`,className:`size-3.5 overflow-visible`,children:(0,j.jsx)(E8,{kind:e,radius:5,emphasis:!1})}),t]},e))})}function E8({kind:e,radius:t,emphasis:n}){switch(e){case`note`:return(0,j.jsx)(`circle`,{r:t,className:n?`fill-foreground`:`fill-muted-foreground`});case`concept`:return(0,j.jsx)(`polygon`,{points:`0,${-t*1.2} ${t*1.2},0 0,${t*1.2} ${-t*1.2},0`,className:A(`stroke-foreground stroke-[1.5]`,n?`fill-foreground`:`fill-card`)});case`tag`:return(0,j.jsx)(`rect`,{x:-t,y:-t,width:t*2,height:t*2,rx:1.5,className:A(`stroke-muted-foreground stroke-[1.5]`,n?`fill-muted-foreground`:`fill-muted`)});case`ghost`:return(0,j.jsx)(`circle`,{r:t,className:A(`fill-card stroke-muted-foreground stroke-[1.5]`,n&&`stroke-foreground`),strokeDasharray:`2 2`})}}function D8(e,t,n){let[r,i]={ArrowRight:[1,0],ArrowLeft:[-1,0],ArrowDown:[0,1],ArrowUp:[0,-1]}[n]??[0,0];if(r===0&&i===0)return;let a=e.nodes[t],o,s=1/0;return e.nodes.forEach((e,n)=>{let c=e.x-a.x,l=e.y-a.y,u=c*r+l*i;if(n===t||u<=0)return;let d=u+Math.abs(c*i-l*r)*2;d<s&&(s=d,o=n)}),o}function O8({view:e,layout:t,selected:n,onSelect:r,onActivate:i}){let a=(0,v.useMemo)(()=>new Map(e.nodes.map((e,t)=>[e.id,t])),[e]),o=(0,v.useMemo)(()=>{let n=e.nodes.map(()=>new Set);for(let[e,r]of t.edges)n[e].add(r),n[r].add(e);return n},[e,t]),s=(0,v.useRef)(null),[c,l]=(0,v.useState)(1),u=()=>{let e=s.current;return!e||e.clientWidth===0?1:h8(Math.min(u8,e.clientWidth/t.width,e.clientHeight/t.height))},d=n===void 0?void 0:a.get(n),f=(e,n)=>{let r=s.current;if(!r)return;let i=e===void 0?void 0:t.nodes[e];r.scrollLeft=i?i.x*n-r.clientWidth/2:(t.width*n-r.clientWidth)/2,r.scrollTop=i?i.y*n-r.clientHeight/2:(t.height*n-r.clientHeight)/2};(0,v.useLayoutEffect)(()=>{let t=u();l(t),requestAnimationFrame(()=>f(e.focus?a.get(e.focus):void 0,t))},[t]);let p=e=>{let t=h8(e);l(t),requestAnimationFrame(()=>f(d,t))},[m,h]=(0,v.useState)(),g=m!==void 0&&m<e.nodes.length?m:d??0;(0,v.useEffect)(()=>h(void 0),[e]);let _=(0,v.useRef)(new Map),y=e=>{h(e);let t=_.current.get(e);t?.focus({preventScroll:!0}),t?.scrollIntoView?.({block:`nearest`,inline:`nearest`})},b=(i,o)=>{if(i.key===`Escape`){n!==void 0&&(i.stopPropagation(),r(void 0));return}if(i.key===`Home`){i.preventDefault(),y(e.focus?a.get(e.focus)??0:0);return}let s=D8(t,o,i.key);i.key.startsWith(`Arrow`)&&i.preventDefault(),s!==void 0&&y(s)},x=(0,v.useRef)(void 0),S=e=>{let t=s.current;t&&e.button===0&&!e.target.closest(`button`)&&(x.current={x:e.clientX,y:e.clientY,left:t.scrollLeft,top:t.scrollTop},e.currentTarget.setPointerCapture?.(e.pointerId))},C=e=>{let t=s.current;t&&x.current&&(t.scrollLeft=x.current.left-(e.clientX-x.current.x),t.scrollTop=x.current.top-(e.clientY-x.current.y))},w=()=>x.current=void 0,[T,E]=(0,v.useState)(),D=new Set;for(let e of[d,T,m])if(e!==void 0&&(D.add(e),e===d))for(let t of o[e]??[])D.add(t);let ee=e.nodes.length<=d8||c>=1.5,te=d!==void 0,ne=e=>Math.max(f8,e*2*c),re=(0,v.useId)(),ie=e.nodes[g];return e.nodes.length===0?(0,j.jsx)(`div`,{className:`flex-1`}):(0,j.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 flex-col`,children:[(0,j.jsx)(`div`,{ref:s,className:`bg-background flex min-h-64 flex-1 cursor-grab overflow-auto active:cursor-grabbing`,onPointerDown:S,onPointerMove:C,onPointerUp:w,onPointerCancel:w,"data-testid":`notes-graph-scroll`,children:(0,j.jsxs)(`div`,{className:`relative m-auto shrink-0`,style:{width:t.width*c,height:t.height*c},"data-testid":`notes-graph-canvas`,"data-zoom":c.toFixed(3),children:[(0,j.jsxs)(`svg`,{viewBox:`0 0 ${t.width} ${t.height}`,className:`absolute inset-0 size-full`,"aria-hidden":`true`,children:[(0,j.jsx)(`defs`,{children:(0,j.jsx)(`marker`,{id:`${re}-arrow`,viewBox:`0 0 10 10`,refX:`10`,refY:`5`,markerWidth:`6`,markerHeight:`6`,orient:`auto-start-reverse`,children:(0,j.jsx)(`path`,{d:`M 0 0 L 10 5 L 0 10 z`,className:`fill-muted-foreground`})})}),t.edges.map(([n,r],i)=>{let a=e.edges[i],o=t.nodes[n],s=t.nodes[r],c=d!==void 0&&(n===d||r===d),l=Math.hypot(s.x-o.x,s.y-o.y)||1,u=a.kind===`prerequisite`?s.radius+2:0;return(0,j.jsx)(`line`,{x1:o.x,y1:o.y,x2:s.x-(s.x-o.x)/l*u,y2:s.y-(s.y-o.y)/l*u,className:A(c?`stroke-foreground`:`stroke-muted-foreground`,te&&!c&&`opacity-25`),strokeOpacity:c?1:a.kind===`tag`||a.kind===`concept`?.45:.7,strokeWidth:c?1.6:1,strokeDasharray:a.kind===`tag`||a.kind===`concept`?`3 3`:void 0,markerEnd:a.kind===`prerequisite`?`url(#${re}-arrow)`:void 0,"data-testid":`notes-graph-edge`,"data-kind":a.kind},i)}),t.nodes.map((t,n)=>(0,j.jsxs)(`g`,{transform:`translate(${t.x} ${t.y})`,className:A(te&&!D.has(n)&&`opacity-35`),children:[(n===d||e.focus===t.id&&d===void 0)&&(0,j.jsx)(`circle`,{r:t.radius+4,className:`fill-none stroke-foreground stroke-[1.5]`}),(0,j.jsx)(E8,{kind:e.nodes[n].kind,radius:t.radius,emphasis:D.has(n)})]},t.id))]}),(0,j.jsx)(`div`,{className:`pointer-events-none absolute inset-0 text-[11px] leading-tight`,"aria-hidden":`true`,children:t.nodes.map((t,n)=>ee||D.has(n)||e.focus===t.id?(0,j.jsx)(`span`,{className:A(`bg-background/80 absolute max-w-40 -translate-x-1/2 truncate rounded-sm px-0.5`,D.has(n)?`text-foreground font-medium`:`text-muted-foreground`,e.nodes[n].kind===`ghost`&&`italic`,te&&!D.has(n)&&`opacity-50`),style:{left:t.x*c,top:t.y*c+t.radius*c+2},"data-testid":`notes-graph-label`,children:e.nodes[n].label},t.id):null)}),(0,j.jsx)(`div`,{role:`group`,"aria-label":`Notes graph. Arrow keys move between nodes by where they're drawn; Enter opens a note.`,"aria-describedby":re,className:`absolute inset-0`,children:t.nodes.map((t,n)=>{let r=e.nodes[n],a=ne(t.radius);return(0,j.jsx)(`button`,{ref:e=>{e?_.current.set(n,e):_.current.delete(n)},type:`button`,tabIndex:n===g?0:-1,"aria-label":g8(r,o[n].size),"aria-pressed":n===d,className:A(`focus-visible:ring-ring/60 absolute -translate-x-1/2 -translate-y-1/2 cursor-pointer rounded-full outline-none focus-visible:ring-[3px]`,n===d&&`z-10`),style:{left:t.x*c,top:t.y*c,width:a,height:a},onClick:()=>{h(n),i(r)},onFocus:()=>h(n),onKeyDown:e=>b(e,n),onPointerEnter:()=>E(n),onPointerLeave:()=>E(e=>e===n?void 0:e),"data-testid":`notes-graph-node`,"data-node":t.id,"data-kind":r.kind},t.id)})})]})}),(0,j.jsx)(`p`,{id:re,className:`sr-only`,"aria-live":`polite`,"data-testid":`notes-graph-neighbours`,children:ie&&m!==void 0?k8(e,o[g],ie):``}),(0,j.jsxs)(`div`,{className:`bg-card/90 absolute right-3 bottom-3 flex gap-1 rounded-md border p-1 shadow-xs`,role:`group`,"aria-label":`Zoom`,children:[(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`Zoom out`,onClick:()=>p(c/s8),disabled:c<=c8,children:(0,j.jsx)(dg,{})}),(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`Fit to the window`,onClick:()=>p(u()),children:(0,j.jsx)(ag,{})}),(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`Zoom in`,onClick:()=>p(c*s8),disabled:c>=l8,children:(0,j.jsx)(Ng,{})})]})]})}function k8(e,t,n){let r=[...t].map(t=>e.nodes[t]).map(e=>e.kind===`ghost`?`${e.label} (unresolved)`:e.label),i=r.slice(0,12),a=r.length-i.length;return r.length===0?`${n.label} connects to nothing drawn.`:`${n.label} connects to ${i.join(`, `)}${a>0?` and ${m8(a,`more`)}`:``}.`}function A8({noteId:e,onOpenChange:t,onCentre:n}){let[r,i]=(0,v.useState)();(0,v.useEffect)(()=>{if(!e)return;let t=!1;return i({id:e}),uN(e).then(n=>{t||i(n.ok?{id:e,view:n.value}:{id:e,error:n.error})}),()=>{t=!0}},[e]);let a=r?.view;return(0,j.jsx)(f6,{open:!!e,onOpenChange:t,children:(0,j.jsxs)(h6,{className:`w-full overflow-y-auto sm:max-w-xl`,"data-testid":`note-reader`,onCloseAutoFocus:e=>{let t=r&&document.querySelector(`[data-testid="notes-graph-node"][data-node="${CSS.escape(r.id)}"]`);t&&(e.preventDefault(),t.focus())},children:[(0,j.jsxs)(g6,{children:[(0,j.jsx)(_6,{className:`font-heading wrap-anywhere`,children:a?.title??`Note`}),(0,j.jsx)(v6,{className:`wrap-anywhere`,children:a?`${a.path} · read-only`:r?.error?`Couldn't open this note.`:`Loading…`})]}),(0,j.jsxs)(`div`,{className:`flex flex-col gap-3 px-4 pb-6`,children:[r?.error&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,children:r.error}),!a&&!r?.error&&(0,j.jsx)(R2,{"aria-label":`Loading the note`}),a&&(0,j.jsxs)(j.Fragment,{children:[(a.tags.length>0||a.aliases.length>0)&&(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[a.tags.map(e=>(0,j.jsxs)(D2,{variant:`secondary`,children:[`#`,e]},e)),a.aliases.length>0&&(0,j.jsxs)(`span`,{className:`text-muted-foreground text-xs`,children:[`Also called `,a.aliases.join(`, `)]})]}),(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,className:`self-start`,onClick:()=>n(a.id),children:`Show the graph around this note`}),(0,j.jsx)(`div`,{className:`text-sm leading-relaxed wrap-anywhere whitespace-pre-wrap`,"data-testid":`note-body`,children:a.body})]})]})]})})}function j8({custom:e,canEdit:t,onChange:n}){let[r,i]=(0,v.useState)(!1);return(0,j.jsxs)(`section`,{className:`flex flex-col gap-3`,"aria-labelledby":`custom-providers-heading`,children:[(0,j.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,j.jsx)(`h2`,{id:`custom-providers-heading`,className:`text-sm font-semibold`,children:`OpenAI-compatible providers`}),(0,j.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Any service with an OpenAI-compatible Chat Completions API, such as a local server or another provider. Compatibility varies: test each model before relying on it.`})]}),e.map(e=>(0,j.jsx)(F8,{provider:e,canEdit:t,onChange:n},e.id)),t&&(r?(0,j.jsx)(P8,{onDone:()=>i(!1),onChange:n}):(0,j.jsx)(M,{type:`button`,variant:`outline`,className:`self-start`,onClick:()=>i(!0),children:`Add an OpenAI-compatible provider`}))]})}var M8=`The API base, including any version prefix, such as https://api.example.com/v1 or http://127.0.0.1:11434/v1. Not the full /chat/completions address.`,N8=e=>[...new Set(e.split(/[\s,]+/).map(e=>e.trim()).filter(Boolean))];function P8({onDone:e,onChange:t}){let[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)();return(0,j.jsxs)(`form`,{onSubmit:async r=>{r.preventDefault(),d(!0),p(void 0);let a=await YN({name:n,baseUrl:i.trim()||null,...o.trim()?{key:o.trim()}:{},models:N8(c).map(e=>({id:e}))});if(!a.ok)return d(!1),p(a.error);t(a.value);let s=a.value.custom.at(-1);if(s?.baseUrl.value){let e=await QN(s.id);e.ok&&t(e.value)}d(!1),e()},className:`flex flex-col gap-3 rounded-lg border p-3`,"aria-label":`Add an OpenAI-compatible provider`,children:[(0,j.jsxs)(P2,{children:[(0,j.jsx)(F2,{htmlFor:`custom-new-name`,children:`Provider name`}),(0,j.jsx)(z2,{id:`custom-new-name`,value:n,onChange:e=>r(e.target.value),disabled:u,autoComplete:`off`,placeholder:`DeepSeek`})]}),(0,j.jsxs)(P2,{children:[(0,j.jsx)(F2,{htmlFor:`custom-new-url`,children:`API base URL`}),(0,j.jsx)(I2,{id:`custom-new-url-help`,children:M8}),(0,j.jsx)(z2,{id:`custom-new-url`,"aria-describedby":`custom-new-url-help`,value:i,onChange:e=>a(e.target.value),disabled:u,autoComplete:`off`,spellCheck:!1,inputMode:`url`,placeholder:`https://api.example.com/v1`})]}),(0,j.jsxs)(P2,{children:[(0,j.jsx)(F2,{htmlFor:`custom-new-key`,children:`API key`}),(0,j.jsx)(I2,{id:`custom-new-key-help`,children:`Kept on this computer and never shown again. Leave it empty for a local server that needs none.`}),(0,j.jsx)(z2,{id:`custom-new-key`,"aria-describedby":`custom-new-key-help`,type:`password`,value:o,onChange:e=>s(e.target.value),disabled:u,autoComplete:`off`,spellCheck:!1,placeholder:`Paste your API key`})]}),(0,j.jsxs)(P2,{children:[(0,j.jsx)(F2,{htmlFor:`custom-new-models`,children:`Model ids`}),(0,j.jsx)(I2,{id:`custom-new-models-help`,children:`One per line, as the provider names them. You can also pick from its list after saving.`}),(0,j.jsx)(S0,{id:`custom-new-models`,"aria-describedby":`custom-new-models-help`,value:c,onChange:e=>l(e.target.value),disabled:u,spellCheck:!1,rows:2,placeholder:`model-id`})]}),f&&(0,j.jsx)(L2,{children:f}),(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,j.jsxs)(M,{type:`submit`,disabled:u||!n.trim(),children:[u&&(0,j.jsx)(R2,{"aria-hidden":`true`}),`Save provider`]}),(0,j.jsx)(M,{type:`button`,variant:`ghost`,disabled:u,onClick:e,children:`Cancel`})]})]})}function F8({provider:e,canEdit:t,onChange:n}){let[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(),p=`custom-${e.id}`,m=async(e,t)=>{u(e),c(!0),f(void 0);let r=await t();return c(!1),r.ok?(n(r.value),!0):(f({kind:`error`,text:r.error}),!1)},h=t=>m(`Saving models…`,()=>XN(e.id,{models:t})),g=e.models.map(({id:e,contextLength:t,maxOutputTokens:n})=>({id:e,contextLength:t,maxOutputTokens:n})),_=e.baseUrl,y=_.value?`${_.value} · ${_.source===`env`?`from ${e.envNames.baseUrl}`:`saved`}`:`No API base URL. Set one here or with ${e.envNames.baseUrl}.`,b=e.key.source===`env`?`Key set by ${e.envNames.key}${e.key.hint?` · ends in ${e.key.hint}`:``}.`:e.key.source===`saved`?`Key saved${e.key.hint?` · ends in ${e.key.hint}`:``}.`:`No key.`;return(0,j.jsxs)(`section`,{className:`flex flex-col gap-3 rounded-lg border p-3`,"aria-labelledby":`${p}-name`,children:[(0,j.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,j.jsx)(`h3`,{id:`${p}-name`,className:`text-sm font-semibold wrap-anywhere`,children:e.name}),(0,j.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Chat Completions`})]}),(0,j.jsxs)(`div`,{className:`text-muted-foreground flex flex-col gap-0.5 text-xs wrap-anywhere`,children:[(0,j.jsx)(`p`,{children:y}),_.error&&(0,j.jsx)(`p`,{className:`text-destructive`,children:_.error}),(0,j.jsx)(`p`,{children:b})]}),r?(0,j.jsx)(I8,{provider:e,onDone:()=>i(!1),onChange:n}):t&&(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,j.jsx)(M,{size:`sm`,variant:`outline`,disabled:s,onClick:()=>i(!0),children:`Edit`}),_.source===`saved`&&_.env&&(0,j.jsxs)(M,{size:`sm`,variant:`outline`,disabled:s,onClick:()=>void m(`Resetting the URL…`,()=>XN(e.id,{baseUrl:null})),children:[`Use `,e.envNames.baseUrl]}),!a&&(0,j.jsx)(M,{size:`sm`,variant:`ghost`,className:`text-destructive`,disabled:s,onClick:()=>o(!0),children:`Remove provider`})]}),a&&(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-sm`,children:[(0,j.jsxs)(`span`,{className:`text-muted-foreground`,children:[`Remove `,e.name,` and its saved key? Replies it wrote stay in your sessions.`]}),(0,j.jsx)(M,{type:`button`,variant:`destructive`,size:`sm`,disabled:s,onClick:()=>void m(`Removing…`,()=>ZN(e.id)).then(e=>e&&o(!1)),children:`Yes, remove`}),(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,disabled:s,onClick:()=>o(!1),children:`Keep`})]}),(0,j.jsx)(R8,{provider:e,canEdit:t,busy:s,onRemove:e=>void h(g.filter(t=>t.id!==e)),onChange:n}),t&&(0,j.jsx)(z8,{provider:e,busy:s,onAdd:e=>h([...g,e])}),(0,j.jsx)(B8,{provider:e,busy:s,onRefresh:()=>void m(`Loading the provider's models…`,()=>QN(e.id))}),s&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` `,l]}),d&&(0,j.jsx)(`p`,{className:d.kind===`ok`?`text-success text-sm`:`text-destructive text-sm`,role:d.kind===`error`?`alert`:void 0,children:d.text})]})}function I8({provider:e,onDone:t,onChange:n}){let[r,i]=(0,v.useState)(e.name),[a,o]=(0,v.useState)(e.baseUrl.source===`saved`?e.baseUrl.value??``:``),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(!1),[d,f]=(0,v.useState)(),p=`custom-${e.id}-edit`,m=e.key.source===`env`,h=async r=>{u(!0),f(void 0);let i=await XN(e.id,r);if(u(!1),!i.ok)return f(i.error);n(i.value),t()};return(0,j.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),h({name:r,baseUrl:a.trim()||null,...s.trim()?{key:s.trim()}:{}})},className:`flex flex-col gap-3`,"aria-label":`Edit ${e.name}`,children:[(0,j.jsxs)(P2,{children:[(0,j.jsx)(F2,{htmlFor:`${p}-name`,children:`Provider name`}),(0,j.jsx)(z2,{id:`${p}-name`,value:r,onChange:e=>i(e.target.value),disabled:l,autoComplete:`off`})]}),(0,j.jsxs)(P2,{children:[(0,j.jsx)(F2,{htmlFor:`${p}-url`,children:`API base URL`}),(0,j.jsxs)(I2,{id:`${p}-url-help`,children:[M8,e.baseUrl.env?` Leave it empty to use ${e.envNames.baseUrl} (${e.baseUrl.env}).`:``,` A new URL or key clears earlier test results.`]}),(0,j.jsx)(z2,{id:`${p}-url`,"aria-describedby":`${p}-url-help`,value:a,onChange:e=>o(e.target.value),disabled:l,autoComplete:`off`,spellCheck:!1,inputMode:`url`,placeholder:e.baseUrl.env??`https://api.example.com/v1`})]}),!m&&(0,j.jsxs)(P2,{children:[(0,j.jsx)(F2,{htmlFor:`${p}-key`,children:`New API key`}),(0,j.jsx)(I2,{id:`${p}-key-help`,children:`Leave it empty to keep the current key.`}),(0,j.jsx)(z2,{id:`${p}-key`,"aria-describedby":`${p}-key-help`,type:`password`,value:s,onChange:e=>c(e.target.value),disabled:l,autoComplete:`off`,spellCheck:!1,placeholder:`Paste a new API key`})]}),d&&(0,j.jsx)(L2,{children:d}),(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,j.jsxs)(M,{type:`submit`,size:`sm`,disabled:l||!r.trim(),children:[l&&(0,j.jsx)(R2,{"aria-hidden":`true`}),`Save`]}),!m&&e.key.source===`saved`&&(0,j.jsx)(M,{type:`button`,size:`sm`,variant:`outline`,disabled:l,onClick:()=>void h({key:null}),children:`Remove saved key`}),(0,j.jsx)(M,{type:`button`,size:`sm`,variant:`ghost`,disabled:l,onClick:t,children:`Cancel`})]})]})}var L8={unverified:{text:`Not tested`,className:``},verified:{text:`Works`,className:`text-success`},failed:{text:`Test failed`,className:`text-destructive`}};function R8({provider:e,canEdit:t,busy:n,onRemove:r,onChange:i}){let[a,o]=(0,v.useState)(),[s,c]=(0,v.useState)({}),l=(0,v.useRef)(void 0);if((0,v.useEffect)(()=>()=>l.current?.abort(),[]),e.models.length===0)return(0,j.jsxs)(`p`,{className:`text-muted-foreground text-sm`,children:[`No models yet. Add a model id`,e.baseUrl.value?` or pick one from the provider's list`:``,`.`]});let u=async t=>{let n=new AbortController;l.current=n,o(t),c(e=>({...e,[t]:void 0}));let r=await $N(e.id,t,n.signal);if(o(void 0),n.signal.aborted)return c(e=>({...e,[t]:{kind:`error`,text:`Test cancelled.`}}));if(!r.ok)return c(e=>({...e,[t]:{kind:`error`,text:r.error}}));i(r.value.providers),c(e=>({...e,[t]:{kind:r.value.result.ok?`ok`:`error`,text:r.value.result.message}}))};return(0,j.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,j.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Test model sends a short request with a tool call, which may use a few tokens.`}),(0,j.jsx)(`ul`,{className:`flex flex-col gap-2`,"aria-label":`${e.name} models`,children:e.models.map(i=>{let o=L8[i.verification.status],c=s[i.id],d=[i.contextLength&&`${i.contextLength.toLocaleString()} context`,i.maxOutputTokens&&`${i.maxOutputTokens.toLocaleString()} max output`].filter(Boolean).join(` · `);return(0,j.jsxs)(`li`,{className:`flex flex-col gap-1 rounded-md border px-2 py-1.5 text-sm`,"aria-label":i.id,children:[(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,j.jsx)(`span`,{className:`min-w-0 flex-1 font-mono text-xs wrap-anywhere`,children:i.id}),(0,j.jsx)(D2,{variant:`outline`,className:o.className,children:o.text})]}),d&&(0,j.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:d}),!c&&i.verification.status===`failed`&&i.verification.message&&(0,j.jsx)(`span`,{className:`text-destructive text-xs`,children:i.verification.message}),(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[a===i.id?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`span`,{className:`text-muted-foreground flex items-center gap-1.5 text-xs`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Testing `,i.id,`…`]}),(0,j.jsx)(M,{size:`xs`,variant:`outline`,onClick:()=>l.current?.abort(),children:`Cancel test`})]}):(0,j.jsx)(M,{size:`xs`,variant:`outline`,disabled:n||a!==void 0||!e.baseUrl.value,onClick:()=>void u(i.id),"aria-label":`Test model ${i.id}`,children:`Test model`}),t&&(0,j.jsx)(M,{size:`xs`,variant:`ghost`,className:`text-destructive`,disabled:n||a===i.id,onClick:()=>r(i.id),"aria-label":`Remove model ${i.id}`,children:`Remove`})]}),c&&(0,j.jsx)(`span`,{className:c.kind===`ok`?`text-success text-xs`:`text-destructive text-xs`,role:`status`,children:c.text})]},i.id)})})]})}function z8({provider:e,busy:t,onAdd:n}){let[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(``),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(),d=`custom-${e.id}-add`,f=`${d}-suggestions`,p=new Set(e.models.map(e=>e.id)),m=e.discovery.ids.filter(e=>!p.has(e)),h=e=>e.trim()?Number(e.trim().replace(/[,_]/g,``)):null,g=e=>e===null||Number.isInteger(e)&&e>0;return(0,j.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault();let t=r.trim();if(t){if(u(void 0),!g(h(a))||!g(h(s)))return u(`Limits are whole numbers of tokens, such as 128000.`);await n({id:t,contextLength:h(a),maxOutputTokens:h(s)})&&(i(``),o(``),c(``))}},className:`flex flex-col gap-2`,"aria-label":`Add a model to ${e.name}`,children:[(0,j.jsxs)(P2,{children:[(0,j.jsx)(F2,{htmlFor:d,children:`Add a model id`}),(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,j.jsx)(z2,{id:d,className:`min-w-0 flex-[1_1_10rem] font-mono`,list:m.length?f:void 0,value:r,onChange:e=>i(e.target.value),disabled:t,autoComplete:`off`,spellCheck:!1,placeholder:m[0]??`model-id`}),(0,j.jsx)(M,{type:`submit`,size:`sm`,variant:`outline`,disabled:t||!r.trim(),children:`Add`})]}),m.length>0&&(0,j.jsx)(`datalist`,{id:f,children:m.slice(0,500).map(e=>(0,j.jsx)(`option`,{value:e},e))})]}),l&&(0,j.jsx)(L2,{children:l}),(0,j.jsxs)(`details`,{className:`text-sm`,children:[(0,j.jsx)(`summary`,{className:`text-muted-foreground cursor-pointer text-xs`,children:`Advanced: limits`}),(0,j.jsxs)(`div`,{className:`mt-2 flex flex-col gap-2`,children:[(0,j.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Only if you know them. Mivra doesn't guess a model's limits; the output limit caps each reply.`}),(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,j.jsxs)(P2,{className:`flex-[1_1_8rem]`,children:[(0,j.jsx)(F2,{htmlFor:`${d}-context`,children:`Context length`}),(0,j.jsx)(z2,{id:`${d}-context`,inputMode:`numeric`,value:a,onChange:e=>o(e.target.value),disabled:t,placeholder:`Unknown`})]}),(0,j.jsxs)(P2,{className:`flex-[1_1_8rem]`,children:[(0,j.jsx)(F2,{htmlFor:`${d}-output`,children:`Max output tokens`}),(0,j.jsx)(z2,{id:`${d}-output`,inputMode:`numeric`,value:s,onChange:e=>c(e.target.value),disabled:t,placeholder:`Provider default`})]})]})]})]})]})}function B8({provider:e,busy:t,onRefresh:n}){let r=e.discovery,i=r.fetchedAt?new Date(r.fetchedAt).toLocaleString():void 0,a=r.state===`fresh`?`The provider lists ${r.ids.length} ${r.ids.length===1?`model`:`models`}. Type in the field above to pick one.`:r.state===`stale`?`Showing the list from ${i}: ${r.error}`:r.state===`failed`?r.error:`Load the provider's own list of models, or enter ids by hand.`;return(0,j.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,j.jsx)(`p`,{className:r.state===`failed`||r.state===`stale`?`text-destructive text-xs`:`text-muted-foreground text-xs`,children:a}),(0,j.jsx)(M,{type:`button`,size:`sm`,variant:`outline`,className:`self-start`,disabled:t||!e.baseUrl.value,onClick:n,children:`Refresh models`})]})}var V8={openrouter:{env:`OPENROUTER_API_KEY`,keysUrl:`https://openrouter.ai/keys`,note:`One key reaches every model.`},anthropic:{env:`ANTHROPIC_API_KEY`,keysUrl:`https://console.anthropic.com/settings/keys`,note:`Claude models, directly.`},openai:{env:`OPENAI_API_KEY`,keysUrl:`https://platform.openai.com/api-keys`,note:`GPT models, directly.`}},H8=e=>e.providers.some(e=>e.source!==null)||!!e.chatgpt?.signedIn||e.custom.some(e=>e.baseUrl.value!==null);function U8({open:e,onOpenChange:t,firstRun:n=!1}){let[r,i]=(0,v.useState)(),[a,o]=(0,v.useState)();return(0,v.useEffect)(()=>{if(!e)return;let t=!1;return o(void 0),LN().then(e=>{t||(e.ok?i(e.value):o(e.error))}),()=>{t=!0}},[e]),(0,j.jsx)(f6,{open:e,onOpenChange:t,children:(0,j.jsxs)(h6,{className:`w-full overflow-y-auto sm:max-w-md`,onCloseAutoFocus:e=>{e.preventDefault(),(document.querySelector(`[data-providers-trigger]`)??document.querySelector(`[data-sidebar="trigger"]`))?.focus()},children:[(0,j.jsxs)(g6,{children:[(0,j.jsx)(_6,{className:`font-heading`,children:`Model providers`}),(0,j.jsx)(v6,{children:n&&r&&!H8(r)?`Mivra needs a model provider before it can teach: sign in with ChatGPT, or add an API key from one of these providers. OpenRouter is the simplest key: one key reaches every model.`:`How Mivra reaches models. Keys and sign-ins stay on this computer, and keys are never shown again after you save them.`})]}),(0,j.jsxs)(`div`,{className:`flex flex-col gap-4 px-4 pb-4`,"aria-live":`polite`,children:[a&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,role:`alert`,children:a}),!r&&!a&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Loading providers…`]}),r&&!r.canEdit&&(0,j.jsxs)(`p`,{className:`text-muted-foreground text-sm`,children:[`API keys can only be changed on the computer running Mivra. There, open this panel or run `,(0,j.jsx)(`code`,{children:`mivra auth set <provider>`}),`.`]}),r?.chatgpt&&(0,j.jsx)(K8,{chatgpt:r.chatgpt,canEdit:r.canEdit,onChange:i}),r?.providers.map(e=>(0,j.jsx)(W8,{provider:e,canEdit:r.canEdit,onChange:i},e.id)),r&&(0,j.jsx)(j8,{custom:r.custom,canEdit:r.canEdit,onChange:i})]})]})})}function W8({provider:e,canEdit:t,onChange:n}){let r=V8[e.id],[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(),m=`provider-key-${e.id}`,h=async()=>{d(`Checking the key…`),l(!0),p(void 0);let t=await KN(e.id);if(l(!1),!t.ok)return p({kind:`error`,text:t.error});p(t.value.ok?{kind:`ok`,text:`The key works.`}:{kind:`error`,text:t.value.message??`The key didn't work.`})},g=async t=>{if(t.preventDefault(),!o.trim())return;d(`Saving the key…`),l(!0),p(void 0);let r=await RN(e.id,o);if(l(!1),!r.ok)return p({kind:`error`,text:r.error});s(``),a(!1),n(r.value),await h()},_=async()=>{d(`Removing the key…`),l(!0),p(void 0);let t=await zN(e.id);if(l(!1),!t.ok)return p({kind:`error`,text:t.error});n(t.value)},y=t&&e.source!==`env`&&(e.source===null||i),b=e.hint?` · ends in ${e.hint}`:``;return(0,j.jsxs)(`section`,{className:`flex flex-col gap-2 rounded-lg border p-3`,"aria-labelledby":`${m}-name`,children:[(0,j.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,j.jsx)(`h2`,{id:`${m}-name`,className:`text-sm font-semibold`,children:e.label}),(0,j.jsxs)(`a`,{href:r.keysUrl,target:`_blank`,rel:`noreferrer`,className:`text-muted-foreground hover:text-foreground inline-flex items-center gap-1 text-xs underline-offset-2 hover:underline`,children:[`Get a key `,(0,j.jsx)(jh,{className:`size-3`,"aria-hidden":!0})]})]}),(0,j.jsx)(`p`,{id:`${m}-source`,className:`text-muted-foreground text-xs`,children:e.source===`env`?`Set by ${r.env}${b}. Change it there.`:e.source===`saved`?`Saved${b}.`:`Not set. ${r.note}`}),y?(0,j.jsx)(`form`,{onSubmit:g,children:(0,j.jsxs)(P2,{"data-invalid":f?.kind===`error`,children:[(0,j.jsxs)(F2,{htmlFor:m,children:[e.label,` API key`]}),(0,j.jsxs)(I2,{id:`${m}-description`,children:[`Paste a key from your `,e.label,` account.`]}),(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,j.jsx)(z2,{className:`min-w-0 flex-[1_1_10rem]`,"aria-describedby":`${m}-source ${m}-description${f?` ${m}-status`:``}`,"aria-invalid":f?.kind===`error`,id:m,type:`password`,autoComplete:`off`,spellCheck:!1,placeholder:`Paste your API key`,value:o,onChange:e=>s(e.target.value),disabled:c}),(0,j.jsx)(M,{type:`submit`,disabled:c||!o.trim(),children:c?`Saving…`:`Save`}),i&&(0,j.jsx)(M,{type:`button`,variant:`ghost`,disabled:c,onClick:()=>a(!1),children:`Cancel`})]}),f?.kind===`error`&&(0,j.jsx)(L2,{id:`${m}-status`,children:f.text})]})}):e.source!==null&&(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,j.jsx)(M,{size:`sm`,variant:`outline`,disabled:c,onClick:()=>void h(),children:`Check`}),t&&e.source===`saved`&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(M,{size:`sm`,variant:`outline`,disabled:c,onClick:()=>a(!0),children:`Replace`}),(0,j.jsx)(M,{size:`sm`,variant:`ghost`,className:`text-destructive`,disabled:c,onClick:()=>void _(),children:`Remove`})]})]}),c&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` `,u]}),f&&!(y&&f.kind===`error`)&&(0,j.jsx)(`p`,{id:`${m}-status`,className:f.kind===`ok`?`text-success text-sm`:`text-destructive text-sm`,children:f.text})]})}var G8=1500;function K8({chatgpt:e,canEdit:t,onChange:n}){let[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(``),[s,c]=(0,v.useState)(),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(),p=`provider-chatgpt`,m=t;(0,v.useEffect)(()=>{if(!e.pending)return;let t=setInterval(()=>{LN().then(e=>{e.ok&&!e.value.chatgpt?.pending&&(n(e.value),f(void 0),window.dispatchEvent(new Event(FN)))})},G8);return()=>clearInterval(t)},[e.pending,n]);let h=async(e,t)=>{o(e),i(!0),c(void 0);let n=await t();return i(!1),n.ok||c({kind:`error`,text:n.error}),n.ok?n.value:void 0},g=async(e=!1)=>{let t=window.open(`about:blank`,`_blank`),r=await h(`Opening ChatGPT…`,()=>BN(e));if(!r){t?.close();return}t?(t.opener=null,t.location.href=r.url):f(r.url);let i=await LN();i.ok&&n(i.value)},_=async e=>{if(e.preventDefault(),!l.trim())return;let t=await h(`Finishing sign-in…`,()=>VN(l));t&&(u(``),f(void 0),n(t))},y=async()=>{let e=await h(`Cancelling…`,HN);f(void 0),e&&n(e)},b=async()=>{let e=await h(`Disconnecting…`,UN);e&&n(e)},x=async()=>{let e=await h(`Checking the connection…`,GN);e&&c(e.ok?{kind:`ok`,text:`The connection works.`}:{kind:`error`,text:e.message??`The connection didn't work.`})},S=e.signedIn?`Replies from ChatGPT models use your ChatGPT plan, not an API key.`:e.pending?`Finish connecting in your browser.`:e.previous&&e.notice?`Reconnect to renew your ChatGPT connection.`:`Complete eligible AI requests in this app with usage included in your ChatGPT plan or credits balance.`;return(0,j.jsxs)(`section`,{className:`flex flex-col gap-2 rounded-lg border p-3`,"aria-labelledby":`${p}-name`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,j.jsxs)(`h2`,{id:`${p}-name`,className:`inline-flex items-center gap-1.5 text-sm font-semibold`,children:[(0,j.jsx)(o3,{className:`size-4`}),`ChatGPT`]}),e.signedIn&&(0,j.jsx)(D2,{variant:`secondary`,children:`Connected`})]}),e.signedIn?(0,j.jsxs)(`p`,{className:`text-sm`,children:[(0,j.jsx)(`span`,{className:`font-medium`,children:e.name??`Connected with ChatGPT`}),e.email&&(0,j.jsx)(`span`,{className:`text-muted-foreground block text-xs`,children:e.email})]}):!e.pending&&(0,j.jsx)(`p`,{className:`text-sm font-medium`,children:e.previous&&e.notice?`Reconnect to ChatGPT`:`Use your ChatGPT plan`}),(0,j.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:S}),e.notice&&!e.pending&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,role:`alert`,children:e.notice}),e.pending?(0,j.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Waiting for you to approve Mivra in the ChatGPT tab…`]}),d&&(0,j.jsx)(`a`,{href:d,target:`_blank`,rel:`noreferrer`,className:`text-sm underline underline-offset-2`,children:`Open the ChatGPT sign-in page`}),(0,j.jsx)(`form`,{onSubmit:_,children:(0,j.jsxs)(P2,{"data-invalid":s?.kind===`error`,children:[(0,j.jsx)(F2,{htmlFor:`${p}-address`,children:m?`Browser showing an error page?`:`Paste the address from the ChatGPT tab`}),(0,j.jsx)(I2,{id:`${p}-address-description`,children:m?`After approving, if the tab can't load, copy its whole address and paste it here.`:`This browser isn't on the computer running Mivra, so after you approve, the tab will show an error page. Copy its whole address and paste it here.`}),(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,j.jsx)(z2,{className:`min-w-0 flex-[1_1_10rem]`,id:`${p}-address`,"aria-describedby":`${p}-address-description${s?` ${p}-status`:``}`,"aria-invalid":s?.kind===`error`,autoComplete:`off`,spellCheck:!1,placeholder:`http://127.0.0.1:1455/auth/callback?code=…`,value:l,onChange:e=>u(e.target.value),disabled:r}),(0,j.jsx)(M,{type:`submit`,disabled:r||!l.trim(),children:`Finish`}),(0,j.jsx)(M,{type:`button`,variant:`ghost`,disabled:r,onClick:()=>void y(),children:`Cancel`})]}),s?.kind===`error`&&(0,j.jsx)(L2,{id:`${p}-status`,children:s.text})]})})]}):e.signedIn?(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,j.jsx)(c3,{primary:!0}),(0,j.jsx)(M,{size:`sm`,variant:`outline`,disabled:r,onClick:()=>void x(),children:`Check`}),(0,j.jsx)(M,{size:`sm`,variant:`ghost`,className:`text-destructive`,disabled:r,onClick:()=>void b(),children:`Disconnect`})]}):(0,j.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,j.jsx)(s3,{busy:r,disabled:r,onClick:()=>void g()}),e.previous&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex flex-wrap items-center gap-x-2 text-xs`,children:[`Signs in as `,e.previous,`.`,(0,j.jsx)(M,{size:`xs`,variant:`link`,className:`h-auto p-0`,disabled:r,onClick:()=>void g(!0),children:`Use a different account`})]})]}),r&&(e.signedIn||e.pending)&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` `,a]}),s&&!(e.pending&&s.kind===`error`)&&(0,j.jsx)(`p`,{id:`${p}-status`,className:s.kind===`ok`?`text-success text-sm`:`text-destructive text-sm`,children:s.text})]})}var q8={lesson:{title:`Lesson generation`,label:`Lesson model`,description:`Writes each lesson's outline and sections in the background.`}};function J8({open:e,onOpenChange:t}){return(0,j.jsx)(f6,{open:e,onOpenChange:t,children:(0,j.jsxs)(h6,{className:`w-full overflow-y-auto sm:max-w-md`,onCloseAutoFocus:e=>{e.preventDefault(),(document.querySelector(`[data-settings-trigger]`)??document.querySelector(`[data-sidebar="trigger"]`))?.focus()},children:[(0,j.jsxs)(g6,{children:[(0,j.jsx)(_6,{className:`font-heading`,children:`Settings`}),(0,j.jsx)(v6,{children:`Settings apply from the next reply or lesson; anything already being written keeps its model.`})]}),e&&(0,j.jsx)(Y8,{}),e&&(0,j.jsxs)(`section`,{"aria-labelledby":`settings-usage`,className:`flex flex-col gap-2 px-4 pb-4`,children:[(0,j.jsx)(`h3`,{id:`settings-usage`,className:`font-heading text-base font-medium`,children:`Usage`}),(0,j.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Tokens and costs of Mivra's model calls, custom prices and clearing the history are on the Usage page.`}),(0,j.jsx)(`div`,{children:(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>window.dispatchEvent(new Event(`mivra:open-usage`)),children:`Open Usage`})})]})]})})}function Y8(){let e=w3(),[t,n]=(0,v.useState)(),[r,i]=(0,v.useState)();(0,v.useEffect)(()=>{let e=!1;return DN().then(t=>{e||(t.ok?n(t.value):i(t.error))}),()=>{e=!0}},[]);let a=(0,v.useCallback)(e=>n(t=>t?.map(t=>t.id===e.id?e:t)),[]);return(0,j.jsxs)(`section`,{"aria-labelledby":`settings-models`,className:`flex flex-col gap-4 px-4 pb-4`,children:[(0,j.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,j.jsx)(`h3`,{id:`settings-models`,className:`font-heading text-base font-medium`,children:`Models`}),(0,j.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`The picker under the message box sets the main model, which chat and new syllabuses always use. A task uses the main model too, and follows it when it changes, unless you choose one for it here.`})]}),r&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,role:`alert`,children:r}),!t&&!r&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Loading…`]}),t?.map(t=>(0,j.jsx)(X8,{task:t,picker:e,onChange:a},t.id))]})}function X8({task:e,picker:t,onChange:n}){let{title:r,label:i,description:a}=q8[e.id],[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(),u=t.view,d=e=>b3(e.model,u?.models,u?.providers),f=async e=>{s(!0),l(void 0);let t=await e();s(!1),t.ok?n(t.value):l(t.error)};return(0,j.jsxs)(`div`,{role:`group`,"aria-labelledby":`task-${e.id}`,className:`flex flex-col gap-2 rounded-md border p-3`,children:[(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,j.jsx)(`h4`,{id:`task-${e.id}`,className:`text-sm font-medium`,children:r}),(0,j.jsx)(D2,{variant:e.override?`default`:`secondary`,children:e.override?`Own model`:`Uses main model`})]}),(0,j.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:a}),e.override?(0,j.jsx)(`p`,{className:`text-sm`,children:`Always uses the model below, whatever the main model is.`}):(0,j.jsxs)(`p`,{className:`text-sm`,children:[`Follows the main model, now `,d(e.effective),`. Choose a model below to use another one for this task.`]}),e.unavailable&&(0,j.jsxs)(T0,{variant:`destructive`,children:[(0,j.jsxs)(E0,{children:[d(e.effective),` can't be used for this task`]}),(0,j.jsxs)(D0,{children:[(0,j.jsx)(`p`,{children:e.unavailable}),(0,j.jsx)(`p`,{children:`Choose another model, or use the main model. Until then, this task fails rather than switching models.`})]})]}),(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,j.jsx)(E3,{state:t,disabled:o,label:i,value:e.effective,unavailable:null,onChoose:t=>void f(()=>ON(e.id,t))}),e.override&&(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,disabled:o,onClick:()=>void f(()=>kN(e.id)),children:`Use main model`})]}),c&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,role:`alert`,children:c})]})}var Z8=[{id:`7`,label:`7 days`,days:7},{id:`30`,label:`30 days`,days:30},{id:`90`,label:`90 days`,days:90},{id:`all`,label:`All time`,days:null}],Q8=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),$8=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1}),e5=e=>e===null?`Unknown`:Q8.format(e),t5=e=>e===null?`Unknown`:$8.format(e);function n5(e){return e===0?`$0.00`:e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}var r5=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function i5(e){let t=[];return e.reportedCost!==null&&t.push(`${n5(e.reportedCost)} reported`),e.estimatedCost!==null&&t.push(`≈${n5(e.estimatedCost)} estimated`),e.unknownCost>0&&t.push(`${r5(e.unknownCost,`call`)} unknown`),t.length>0?t.join(` + `):`None`}function a5({open:e,onOpenChange:t}){return(0,j.jsx)(f6,{open:e,onOpenChange:t,children:(0,j.jsxs)(h6,{className:A(`w-full overflow-y-auto sm:max-w-2xl`,O3),onCloseAutoFocus:e=>{e.preventDefault(),(document.querySelector(`[data-usage-trigger]`)??document.querySelector(`[data-sidebar="trigger"]`))?.focus()},children:[(0,j.jsxs)(g6,{className:k3,children:[(0,j.jsx)(_6,{className:A3,children:`Usage`}),(0,j.jsx)(v6,{children:`Tokens and costs from the model calls Mivra makes, counted from when usage tracking started on this computer. It isn't your whole account's usage and doesn't show any remaining allowance.`})]}),e&&(0,j.jsx)(o5,{})]})})}function o5(){let[e,t]=(0,v.useState)(`30`),[n,r]=(0,v.useState)(),[i,a]=(0,v.useState)(),[o,s]=(0,v.useState)(0),c=(0,v.useCallback)(()=>s(e=>e+1),[]);return(0,v.useEffect)(()=>{let t=!1,n=Z8.find(t=>t.id===e).days;return AN(n===null?null:new Date(Date.now()-n*24*60*60*1e3)).then(e=>{t||(e.ok?(r(e.value),a(void 0)):a(e.error))}),()=>{t=!0}},[e,o]),(0,j.jsxs)(`div`,{className:`flex flex-col gap-6 px-5 py-5`,children:[(0,j.jsx)(`div`,{role:`radiogroup`,"aria-label":`Date range`,className:j3,children:Z8.map(n=>(0,j.jsx)(M,{type:`button`,size:`sm`,role:`radio`,"aria-checked":e===n.id,variant:`ghost`,className:M3(e===n.id),onClick:()=>t(n.id),children:n.label},n.id))}),i&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,role:`alert`,children:i}),!n&&!i&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Loading…`]}),n&&(0,j.jsx)(s5,{view:n,onChanged:c})]})}function s5({view:e,onChanged:t}){let{totals:n,api:r,subscription:i}=e,a=n.calls===0;return(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:e.since?`Counting since ${new Date(e.since).toLocaleString()}.`:`Nothing recorded yet. Usage is counted from the next model call.`}),!a&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`section`,{"aria-label":`Totals`,className:`grid gap-x-6 gap-y-4 sm:grid-cols-3`,children:[(0,j.jsxs)(d5,{label:`Tokens`,value:t5(n.total),children:[(0,j.jsxs)(`span`,{children:[e5(n.input),` in · `,e5(n.output),` out`]}),n.cacheRead!==null&&(0,j.jsxs)(`span`,{children:[`of input, `,e5(n.cacheRead),` cached`]}),n.reasoning!==null&&(0,j.jsxs)(`span`,{children:[`of output, `,e5(n.reasoning),` reasoning`]}),n.unreported>0&&(0,j.jsxs)(`span`,{children:[r5(n.unreported,`call`),` didn't report tokens`]})]}),(0,j.jsxs)(d5,{label:`API spending`,value:r.calls===0?`None`:u5(r),children:[(0,j.jsx)(`span`,{children:r5(r.calls,`API call`)}),r.calls>0&&(0,j.jsx)(`span`,{children:i5(r)})]}),(0,j.jsxs)(d5,{label:`ChatGPT plan`,value:i.calls===0?`Not used`:t5(i.total),children:[i.calls>0&&(0,j.jsxs)(`span`,{children:[`tokens in `,r5(i.calls,`call`),`, billed to your plan`]}),(0,j.jsxs)(`span`,{children:[`Limits and plan usage: `,(0,j.jsx)(c3,{})]})]})]}),i.calls>0&&(0,j.jsx)(f5,{totals:i}),(n.incomplete>0||n.unreported>0)&&(0,j.jsxs)(`p`,{className:`text-muted-foreground text-sm`,children:[r5(n.incomplete,`call`),` failed or `,n.incomplete===1?`was`:`were`,` cancelled. Whatever tokens they reported are counted; calls that reported none are shown as unknown rather than free, since a provider may still bill them.`]}),(0,j.jsx)(p5,{days:e.days}),(0,j.jsx)(h5,{title:`By model`,rows:e.byModel.map(e=>({key:e.key,name:e.label,detail:e.providerLabel,totals:e,billing:e.billing}))}),(0,j.jsx)(h5,{title:`By provider`,rows:e.byProvider.map(e=>({key:e.key,name:e.label,totals:e,billing:e.billing}))}),(0,j.jsx)(h5,{title:`By activity`,rows:e.byKind.map(e=>({key:e.key,name:e.label,detail:c5[e.kind],totals:e}))}),(0,j.jsx)(h5,{title:`Recent runs`,note:`A run is one reply, continuation, lesson or test; each tool-call step is a separate call.`,rows:e.runs.map(e=>({key:e.key,name:e.session??`Model test`,detail:`${l5[e.kind]} · ${e.label} · ${new Date(e.startedAt).toLocaleString()}${e.status===`completed`?``:` · ${e.status}`}`,totals:e,billing:e.billing}))}),(0,j.jsx)(h5,{title:`Sessions`,rows:e.sessions.map(e=>({key:e.key,name:e.label,detail:e.deleted?`Its records are kept`:void 0,totals:e}))})]}),(0,j.jsx)(_5,{prices:e.prices,onChanged:t}),(0,j.jsx)(y5,{disabled:!e.since,onCleared:t})]})}var c5={chat:`Your messages and the tutor's replies, syllabus writing included`,continuation:`The tutor carrying on after you answer its checks`,lesson:`Background generation of lessons`,distillation:`Background reading of imported notes into concepts and memories`,test:`Test model under Model providers`},l5={chat:`Chat`,continuation:`Continuation`,lesson:`Lesson`,distillation:`Note reading`,test:`Test model`};function u5(e){let t=(e.reportedCost??0)+(e.estimatedCost??0);return e.reportedCost===null&&e.estimatedCost===null?`Unknown`:`${e.estimatedCost===null?``:`≈`}${n5(t)}${e.unknownCost>0?`+`:``}`}function d5({label:e,value:t,children:n}){return(0,j.jsxs)(`div`,{role:`group`,"aria-label":e,className:`flex min-w-0 flex-col gap-1`,children:[(0,j.jsx)(`span`,{className:D3,children:e}),(0,j.jsx)(`span`,{className:`font-heading text-[1.85rem] leading-tight font-normal tracking-[-0.02em] tabular-nums wrap-anywhere`,children:t}),(0,j.jsx)(`div`,{className:`text-muted-foreground flex flex-col text-[0.8125rem] leading-snug`,children:n})]})}function f5({totals:e}){let[t,n]=(0,v.useState)(!1);return(0,j.jsxs)(O2,{open:t,onOpenChange:n,className:`border-border-strong rounded-lg border`,children:[(0,j.jsx)(k2,{asChild:!0,children:(0,j.jsxs)(M,{type:`button`,variant:`ghost`,className:`w-full justify-between`,children:[`Estimated API equivalent`,(0,j.jsx)(Ym,{"aria-hidden":!0,className:A(`transition-transform`,t&&`rotate-180`)})]})}),(0,j.jsxs)(A2,{className:`flex flex-col gap-1 px-3 pb-3 text-sm`,children:[(0,j.jsx)(`p`,{className:`text-muted-foreground`,children:`What these tokens would cost at published API rates. This is not a charge or your subscription cost.`}),e.apiEquivalent===null?(0,j.jsx)(`p`,{className:`text-muted-foreground`,children:`None of these models has a published API price to compare with.`}):(0,j.jsxs)(`p`,{children:[(0,j.jsxs)(`span`,{className:`font-medium tabular-nums`,children:[`≈`,n5(e.apiEquivalent)]}),e.uncompared>0&&(0,j.jsxs)(`span`,{className:`text-muted-foreground`,children:[` for the calls with a published price; `,r5(e.uncompared,`call`),` had none to compare with.`]})]})]})]})}function p5({days:e}){if(e.length<2)return null;let t=e=>e.api+e.subscription,n=Math.max(1,...e.map(t));return(0,j.jsxs)(`section`,{"aria-labelledby":`usage-daily`,className:`flex flex-col gap-2`,children:[(0,j.jsx)(`h3`,{id:`usage-daily`,className:D3,children:`Tokens per day`}),(0,j.jsx)(`div`,{className:`border-border-strong flex h-28 items-end gap-0.5 border-b`,role:`list`,"aria-label":`Tokens per day`,children:e.map(e=>{let r=`${new Date(`${e.day}T00:00:00`).toLocaleDateString()}: ${Q8.format(t(e))} tokens in ${r5(e.calls,`call`)}`;return(0,j.jsx)(`div`,{role:`listitem`,"aria-label":r,title:r,className:`group flex h-full min-w-1 flex-1 items-end`,children:(0,j.jsx)(`div`,{className:`bg-muted-foreground/60 group-hover:bg-foreground w-full rounded-t-[3px]`,style:{height:`${Math.max(2,t(e)/n*100)}%`}})},e.day)})}),(0,j.jsxs)(`div`,{className:`text-muted-foreground flex justify-between gap-2 font-mono text-[0.72rem] tabular-nums`,children:[(0,j.jsx)(`span`,{children:new Date(`${e[0].day}T00:00:00`).toLocaleDateString()}),(0,j.jsxs)(`span`,{children:[`Peak `,t5(n)]}),(0,j.jsx)(`span`,{children:new Date(`${e.at(-1).day}T00:00:00`).toLocaleDateString()})]})]})}function m5(e){if(e.billing===`subscription`)return`ChatGPT plan`;let t=e.totals,n=i5(t);return e.billing===void 0&&(t.apiEquivalent!==null||t.uncompared>0)?n===`None`?`ChatGPT plan`:`${n} + ChatGPT plan`:n}function h5({title:e,note:t,rows:n}){if(n.length===0)return null;let r=`usage-${e.toLowerCase().replace(/\s+/g,`-`)}`;return(0,j.jsxs)(`section`,{"aria-labelledby":r,className:`flex flex-col gap-2`,children:[(0,j.jsx)(`h3`,{id:r,className:`font-heading text-[1.05rem] font-medium`,children:e}),t&&(0,j.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:t}),(0,j.jsx)(`div`,{className:`overflow-x-auto`,children:(0,j.jsxs)(`table`,{className:`w-full text-sm`,"aria-labelledby":r,children:[(0,j.jsx)(`thead`,{className:`text-muted-foreground text-left font-mono text-[0.6875rem] tracking-[0.09em] uppercase`,children:(0,j.jsxs)(`tr`,{children:[(0,j.jsx)(`th`,{scope:`col`,className:`pb-2 pr-2 font-medium`,children:`Name`}),(0,j.jsx)(`th`,{scope:`col`,className:`pb-2 pr-2 text-right font-medium`,children:`Tokens`}),(0,j.jsx)(`th`,{scope:`col`,className:`pb-2 pr-2 text-right font-medium`,children:`Calls`}),(0,j.jsx)(`th`,{scope:`col`,className:`pb-2 text-right font-medium`,children:`Cost`})]})}),(0,j.jsx)(`tbody`,{children:n.map(e=>(0,j.jsxs)(`tr`,{className:`border-t align-top`,children:[(0,j.jsxs)(`th`,{scope:`row`,className:`py-2.5 pr-2 text-left font-semibold`,children:[(0,j.jsx)(`span`,{className:`block break-words`,children:e.name}),e.detail&&(0,j.jsx)(`span`,{className:`text-muted-foreground block text-xs font-normal`,children:e.detail})]}),(0,j.jsxs)(`td`,{className:`py-2.5 pr-2 text-right font-mono text-[0.8125rem] tabular-nums`,children:[e5(e.totals.total),e.totals.unreported>0&&(0,j.jsxs)(`span`,{className:`text-muted-foreground block text-xs`,children:[`+`,e.totals.unreported,` unknown`]})]}),(0,j.jsx)(`td`,{className:`py-2.5 pr-2 text-right font-mono text-[0.8125rem] tabular-nums`,children:e.totals.calls}),(0,j.jsx)(`td`,{className:`py-2.5 text-right text-xs`,children:m5(e)})]},e.key))})]})})]})}var g5=[{key:`input`,label:`Input`},{key:`output`,label:`Output`},{key:`cacheRead`,label:`Cached input`}];function _5({prices:e,onChanged:t}){let[n,r]=(0,v.useState)(!1);return(0,j.jsxs)(O2,{open:n,onOpenChange:r,className:`border-border-strong rounded-lg border`,children:[(0,j.jsx)(k2,{asChild:!0,children:(0,j.jsxs)(M,{type:`button`,variant:`ghost`,className:`w-full justify-between`,children:[`Advanced: custom prices`,(0,j.jsx)(Ym,{"aria-hidden":!0,className:A(`transition-transform`,n&&`rotate-180`)})]})}),(0,j.jsxs)(A2,{className:`flex flex-col gap-3 px-3 pb-3`,children:[(0,j.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`US dollars per million tokens. A price you set wins over the published one for calls from now on; costs already recorded don't change. No model needs a price to work: without one its cost stays unknown.`}),e.length===0&&(0,j.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`No models yet.`}),e.map(e=>(0,j.jsx)(v5,{price:e,onChanged:t},e.model))]})]})}function v5({price:e,onChanged:t}){let n=t=>String(e.custom?.[t]??``),[r,i]=(0,v.useState)(()=>Object.fromEntries(g5.map(e=>[e.key,n(e.key)]))),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(),l=`price-${e.model.replace(/[^a-z0-9]/gi,`-`)}`,u=e.published?`Published: ${n5(e.published.input)} in, ${n5(e.published.output)} out`:`No published price`,d=async n=>{o(!0),c(void 0);let r=await MN(e.model,n);o(!1),r.ok?t():c(r.error)};return(0,j.jsxs)(`div`,{role:`group`,"aria-labelledby":l,className:`flex flex-col gap-2 border-t pt-3`,children:[(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,j.jsx)(`span`,{id:l,className:`text-sm font-medium break-all`,children:e.label}),(0,j.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,j.jsx)(D2,{variant:`secondary`,children:e.providerLabel}),e.custom&&(0,j.jsx)(D2,{children:`Custom price`})]})]}),(0,j.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:e.billing===`subscription`?`Billed to your ChatGPT plan. Its API comparison uses only published prices, so it has no price of your own. ${u}.`:`${u}.`}),e.billing!==`subscription`&&(0,j.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[g5.map(t=>(0,j.jsxs)(`label`,{className:`flex w-28 flex-col gap-1 text-xs`,children:[t.label,(0,j.jsx)(z2,{inputMode:`decimal`,value:r[t.key],disabled:a,"aria-label":`${t.label} price for ${e.label}, dollars per million tokens`,onChange:e=>i(n=>({...n,[t.key]:e.target.value}))})]},t.key)),(0,j.jsx)(M,{type:`button`,size:`sm`,disabled:a,onClick:()=>{let e=Number(r.input),t=Number(r.output);if(r.input===``||r.output===``||!Number.isFinite(e)||!Number.isFinite(t)||e<0||t<0){c(`Enter input and output prices of 0 or more.`);return}let n=r.cacheRead===``?void 0:Number(r.cacheRead);n!==void 0&&(!Number.isFinite(n)||n<0)?c(`The cached input price must be 0 or more, or empty.`):d({input:e,output:t,...n===void 0?{}:{cacheRead:n}})},children:`Save price`}),e.custom&&(0,j.jsx)(M,{type:`button`,size:`sm`,variant:`outline`,disabled:a,onClick:()=>void d(null),children:`Remove`})]}),s&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,role:`alert`,children:s})]})}function y5({disabled:e,onCleared:t}){let[n,r]=(0,v.useState)(!1),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(),c=async()=>{a(!0),s(void 0);let e=await jN();if(a(!1),!e.ok)return s(e.error);r(!1),t()};return(0,j.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,j.jsx)(`div`,{children:(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,disabled:e,onClick:()=>r(!0),children:`Clear usage history`})}),(0,j.jsx)(F4,{open:n,onOpenChange:r,children:(0,j.jsxs)(R4,{children:[(0,j.jsxs)(z4,{children:[(0,j.jsx)(V4,{children:`Clear usage history?`}),(0,j.jsx)(H4,{children:`This deletes Mivra's usage records. Your conversations, lessons and provider settings are kept. It doesn't reset any provider's billing or your plan's limits. Usage starts counting again from the next model call.`})]}),o&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,role:`alert`,children:o}),(0,j.jsxs)(B4,{children:[(0,j.jsx)(M,{type:`button`,variant:`outline`,onClick:()=>r(!1),children:`Cancel`}),(0,j.jsx)(M,{type:`button`,variant:`destructive`,disabled:i,onClick:()=>void c(),children:`Clear usage history`})]})]})})]})}var b5=768;function x5(){let[e,t]=v.useState(void 0);return v.useEffect(()=>{let e=window.matchMedia(`(max-width: 767px)`),n=()=>{t(window.innerWidth<b5)};return e.addEventListener(`change`,n),t(window.innerWidth<b5),()=>e.removeEventListener(`change`,n)},[]),!!e}var S5=`sidebar_state`,C5=604800,w5=`16rem`,T5=`18rem`,E5=`3rem`,D5=`b`,O5=v.createContext(null);function k5(){let e=v.useContext(O5);if(!e)throw Error(`useSidebar must be used within a SidebarProvider.`);return e}function A5({defaultOpen:e=!0,open:t,onOpenChange:n,className:r,style:i,children:a,...o}){let s=x5(),[c,l]=v.useState(!1),[u,d]=v.useState(e),f=t??u,p=v.useCallback(e=>{let t=typeof e==`function`?e(f):e;n?n(t):d(t),document.cookie=`${S5}=${t}; path=/; max-age=${C5}`},[n,f]),m=v.useCallback(()=>s?l(e=>!e):p(e=>!e),[s,p,l]);v.useEffect(()=>{let e=e=>{e.key===D5&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),m())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[m]);let h=f?`expanded`:`collapsed`,g=v.useMemo(()=>({state:h,open:f,setOpen:p,isMobile:s,openMobile:c,setOpenMobile:l,toggleSidebar:m}),[h,f,p,s,c,l,m]);return(0,j.jsx)(O5.Provider,{value:g,children:(0,j.jsx)(U3,{delayDuration:0,children:(0,j.jsx)(`div`,{"data-slot":`sidebar-wrapper`,style:{"--sidebar-width":w5,"--sidebar-width-icon":E5,...i},className:A(`group/sidebar-wrapper flex min-h-svh w-full has-data-[variant=inset]:bg-sidebar`,r),...o,children:a})})})}function j5({side:e=`left`,variant:t=`sidebar`,collapsible:n=`offcanvas`,className:r,children:i,...a}){let{isMobile:o,state:s,openMobile:c,setOpenMobile:l}=k5();return n===`none`?(0,j.jsx)(`div`,{"data-slot":`sidebar`,className:A(`flex h-full w-(--sidebar-width) flex-col bg-sidebar text-sidebar-foreground`,r),...a,children:i}):o?(0,j.jsx)(f6,{open:c,onOpenChange:l,...a,children:(0,j.jsxs)(h6,{"data-sidebar":`sidebar`,"data-slot":`sidebar`,"data-mobile":`true`,className:`w-(--sidebar-width) bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden`,style:{"--sidebar-width":T5},side:e,children:[(0,j.jsxs)(g6,{className:`sr-only`,children:[(0,j.jsx)(_6,{children:`Sidebar`}),(0,j.jsx)(v6,{children:`Displays the mobile sidebar.`})]}),(0,j.jsx)(`div`,{className:`flex h-full w-full flex-col`,children:i})]})}):(0,j.jsxs)(`div`,{className:`group peer hidden text-sidebar-foreground md:block`,"data-state":s,"data-collapsible":s===`collapsed`?n:``,"data-variant":t,"data-side":e,"data-slot":`sidebar`,children:[(0,j.jsx)(`div`,{"data-slot":`sidebar-gap`,className:A(`relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear`,`group-data-[collapsible=offcanvas]:w-0`,`group-data-[side=right]:rotate-180`,t===`floating`||t===`inset`?`group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]`:`group-data-[collapsible=icon]:w-(--sidebar-width-icon)`)}),(0,j.jsx)(`div`,{"data-slot":`sidebar-container`,className:A(`fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear md:flex`,e===`left`?`left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]`:`right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]`,t===`floating`||t===`inset`?`p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]`:`group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l`,r),...a,children:(0,j.jsx)(`div`,{"data-sidebar":`sidebar`,"data-slot":`sidebar-inner`,className:`flex h-full w-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:shadow-sm`,children:i})})]})}function M5({className:e,onClick:t,...n}){let{toggleSidebar:r}=k5();return(0,j.jsxs)(M,{"data-sidebar":`trigger`,"data-slot":`sidebar-trigger`,variant:`ghost`,size:`icon`,className:A(`size-7`,e),onClick:e=>{t?.(e),r()},...n,children:[(0,j.jsx)(xg,{}),(0,j.jsx)(`span`,{className:`sr-only`,children:`Toggle Sidebar`})]})}function N5({className:e,...t}){let{toggleSidebar:n}=k5();return(0,j.jsx)(`button`,{"data-sidebar":`rail`,"data-slot":`sidebar-rail`,"aria-label":`Toggle Sidebar`,tabIndex:-1,onClick:n,title:`Toggle Sidebar`,className:A(`absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border sm:flex`,`in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize`,`[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize`,`group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full hover:group-data-[collapsible=offcanvas]:bg-sidebar`,`[[data-side=left][data-collapsible=offcanvas]_&]:-right-2`,`[[data-side=right][data-collapsible=offcanvas]_&]:-left-2`,e),...t})}function P5({className:e,...t}){return(0,j.jsx)(`main`,{"data-slot":`sidebar-inset`,className:A(`relative flex w-full flex-1 flex-col bg-background`,`md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2`,e),...t})}function F5({className:e,...t}){return(0,j.jsx)(z2,{"data-slot":`sidebar-input`,"data-sidebar":`input`,className:A(`h-8 w-full bg-background shadow-none`,e),...t})}function I5({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`sidebar-header`,"data-sidebar":`header`,className:A(`flex flex-col gap-2 p-2`,e),...t})}function L5({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`sidebar-footer`,"data-sidebar":`footer`,className:A(`flex flex-col gap-2 p-2`,e),...t})}function R5({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`sidebar-content`,"data-sidebar":`content`,className:A(`flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden`,e),...t})}function z5({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`sidebar-group`,"data-sidebar":`group`,className:A(`relative flex w-full min-w-0 flex-col p-2`,e),...t})}function B5({className:e,asChild:t=!1,...n}){let r=t?Gt:`div`;return(0,j.jsx)(r,{"data-slot":`sidebar-group-label`,"data-sidebar":`group-label`,className:A(`flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground/70 ring-sidebar-ring outline-hidden transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0`,`group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0`,e),...n})}function V5({className:e,...t}){return(0,j.jsx)(`ul`,{"data-slot":`sidebar-menu`,"data-sidebar":`menu`,className:A(`flex w-full min-w-0 flex-col gap-1`,e),...t})}function H5({className:e,...t}){return(0,j.jsx)(`li`,{"data-slot":`sidebar-menu-item`,"data-sidebar":`menu-item`,className:A(`group/menu-item relative`,e),...t})}var U5=ce(`peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm ring-sidebar-ring outline-hidden transition-[width,height,padding] group-has-data-[sidebar=menu-action]/menu-item:pr-8 group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0`,{variants:{variant:{default:`hover:bg-sidebar-accent hover:text-sidebar-accent-foreground`,outline:`bg-background shadow-[0_0_0_1px_var(--sidebar-border)] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_var(--sidebar-accent)]`},size:{default:`h-8 text-sm`,sm:`h-7 text-xs`,lg:`h-12 text-sm group-data-[collapsible=icon]:p-0!`}},defaultVariants:{variant:`default`,size:`default`}});function W5({asChild:e=!1,isActive:t=!1,variant:n=`default`,size:r=`default`,tooltip:i,className:a,...o}){let s=e?Gt:`button`,{isMobile:c,state:l}=k5(),u=(0,j.jsx)(s,{"data-slot":`sidebar-menu-button`,"data-sidebar":`menu-button`,"data-size":r,"data-active":t,className:A(U5({variant:n,size:r}),a),...o});return i?(typeof i==`string`&&(i={children:i}),(0,j.jsxs)(W3,{children:[(0,j.jsx)(G3,{asChild:!0,children:u}),(0,j.jsx)(K3,{side:`right`,align:`center`,hidden:l!==`collapsed`||c,...i})]})):u}function G5({className:e,asChild:t=!1,showOnHover:n=!1,...r}){let i=t?Gt:`button`;return(0,j.jsx)(i,{"data-slot":`sidebar-menu-action`,"data-sidebar":`menu-action`,className:A(`absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground ring-sidebar-ring outline-hidden transition-transform peer-hover/menu-button:text-sidebar-accent-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0`,`after:absolute after:-inset-2 md:after:hidden`,`peer-data-[size=sm]/menu-button:top-1`,`peer-data-[size=default]/menu-button:top-1.5`,`peer-data-[size=lg]/menu-button:top-2.5`,`group-data-[collapsible=icon]:hidden`,n&&`group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 peer-data-[active=true]/menu-button:text-sidebar-accent-foreground data-[state=open]:opacity-100 md:opacity-0`,e),...r})}var K5=[{value:`system`,label:`System`,Icon:pg},{value:`light`,label:`Light`,Icon:Zg},{value:`dark`,label:`Dark`,Icon:hg}];function q5({choice:e,onChange:t}){let{label:n,Icon:r}=K5.find(t=>t.value===e)??K5[0];return(0,j.jsx)(V5,{children:(0,j.jsx)(H5,{children:(0,j.jsxs)(Y4,{children:[(0,j.jsx)(X4,{asChild:!0,children:(0,j.jsxs)(W5,{tooltip:`Theme`,"aria-label":`Theme: ${n}`,children:[(0,j.jsx)(r,{}),(0,j.jsx)(`span`,{children:n})]})}),(0,j.jsx)(Z4,{side:`top`,align:`start`,children:(0,j.jsx)($4,{value:e,onValueChange:e=>t(e),children:K5.map(({value:e,label:t,Icon:n})=>(0,j.jsxs)(e3,{value:e,children:[(0,j.jsx)(n,{}),t]},e))})})]})})})}var J5=`mivra-theme`,Y5=()=>window.matchMedia(`(prefers-color-scheme: dark)`);function X5(){try{let e=localStorage.getItem(J5);return e===`light`||e===`dark`?e:`system`}catch{return`system`}}function Z5(e){let t=e===`dark`||e===`system`&&Y5().matches;document.documentElement.classList.toggle(`dark`,t)}function Q5(){let[e,t]=(0,v.useState)(X5);return(0,v.useEffect)(()=>{Z5(e);try{e===`system`?localStorage.removeItem(J5):localStorage.setItem(J5,e)}catch{}if(e!==`system`)return;let t=Y5(),n=()=>Z5(`system`);return t.addEventListener(`change`,n),()=>t.removeEventListener(`change`,n)},[e]),[e,t]}function $5(e,t=new Date){let n=new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime(),r=new Date(t.getFullYear(),t.getMonth(),t.getDate()-7).getTime(),i=[{label:`Today`,sessions:[]},{label:`Previous 7 days`,sessions:[]},{label:`Older`,sessions:[]}];for(let t of e){let e=new Date(t.updatedAt).getTime();(e>=n?i[0]:e>=r?i[1]:i[2]).sessions.push(t)}return i.filter(e=>e.sessions.length>0)}function e7({...e}){return(0,j.jsx)(Oo,{"data-slot":`alert-dialog`,...e})}function t7({...e}){return(0,j.jsx)(ko,{"data-slot":`alert-dialog-portal`,...e})}function n7({className:e,...t}){return(0,j.jsx)(Ao,{"data-slot":`alert-dialog-overlay`,className:A(`fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0`,e),...t})}function r7({className:e,size:t=`default`,...n}){return(0,j.jsxs)(t7,{children:[(0,j.jsx)(n7,{}),(0,j.jsx)(No,{"data-slot":`alert-dialog-content`,"data-size":t,className:A(`group/alert-dialog-content fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 data-[size=sm]:max-w-xs data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[size=default]:sm:max-w-lg`,e),...n})]})}function i7({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`alert-dialog-header`,className:A(`grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-6 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]`,e),...t})}function a7({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`alert-dialog-footer`,className:A(`flex flex-col-reverse gap-2 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end`,e),...t})}function o7({className:e,...t}){return(0,j.jsx)(Po,{"data-slot":`alert-dialog-title`,className:A(`text-lg font-semibold sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2`,e),...t})}function s7({className:e,...t}){return(0,j.jsx)(Fo,{"data-slot":`alert-dialog-description`,className:A(`text-sm text-muted-foreground`,e),...t})}function c7({className:e,variant:t=`default`,size:n=`default`,...r}){return(0,j.jsx)(M,{variant:t,size:n,asChild:!0,children:(0,j.jsx)(Io,{"data-slot":`alert-dialog-action`,className:A(e),...r})})}function l7({className:e,variant:t=`outline`,size:n=`default`,...r}){return(0,j.jsx)(M,{variant:t,size:n,asChild:!0,children:(0,j.jsx)(Ro,{"data-slot":`alert-dialog-cancel`,className:A(e),...r})})}var u7=120;function d7({onRename:e,onDelete:t}){let n=(0,v.useRef)(!1);return(0,j.jsxs)(Y4,{children:[(0,j.jsx)(X4,{asChild:!0,children:(0,j.jsx)(G5,{showOnHover:!0,"aria-label":`Session actions`,children:(0,j.jsx)(kh,{})})}),(0,j.jsxs)(Z4,{side:`right`,align:`start`,onCloseAutoFocus:t=>{n.current&&(n.current=!1,t.preventDefault(),e())},children:[(0,j.jsxs)(Q4,{onSelect:()=>n.current=!0,children:[(0,j.jsx)(kg,{}),`Rename`]}),(0,j.jsxs)(Q4,{variant:`destructive`,onSelect:t,children:[(0,j.jsx)(r_,{}),`Delete`]})]})]})}function f7({session:e,onDone:t,onRenamed:n}){let[r,i]=(0,v.useState)(e.title),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(),l=(0,v.useRef)(null),u=(0,v.useRef)(!1);(0,v.useEffect)(()=>{l.current?.focus(),l.current?.select()},[]);let d=async()=>{if(u.current||a)return;let i=r.trim();if(!i||i===e.title)return u.current=!0,t();o(!0),c(void 0);let s=await qN(e.id,i);o(!1),s.ok?(u.current=!0,n(s.value),t()):(c(s.error),l.current?.focus())};return(0,j.jsxs)(`div`,{className:`px-0.5 py-0.5`,children:[(0,j.jsx)(F5,{ref:l,value:r,maxLength:u7,readOnly:a,"aria-label":`Title`,"aria-invalid":s?!0:void 0,"aria-describedby":s?`rename-error-${e.id}`:void 0,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),d()):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),u.current=!0,t())},onBlur:()=>void d()}),s&&(0,j.jsx)(`p`,{id:`rename-error-${e.id}`,className:`text-destructive px-1 pt-1 text-xs`,role:`alert`,children:s})]})}function p7({session:e,onClose:t,onDeleted:n}){let[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(),s=async()=>{if(!e)return;i(!0),o(void 0);let t=await JN(e.id);if(i(!1),!t.ok)return o(t.error);n(e)};return(0,j.jsx)(e7,{open:!!e,onOpenChange:e=>{e||r||(o(void 0),t())},children:(0,j.jsxs)(r7,{children:[(0,j.jsxs)(i7,{children:[(0,j.jsxs)(o7,{className:`font-heading wrap-anywhere`,children:[`Delete “`,e?.title,`”?`]}),(0,j.jsx)(s7,{children:e?.courseId?`This deletes the course with its syllabus, lessons and every lesson's chat. It can't be undone. What Mivra remembers about you is kept.`:`This deletes the session with its messages and attached documents. It can't be undone. What Mivra remembers about you is kept.`})]}),a&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,role:`alert`,children:a}),(0,j.jsxs)(a7,{children:[(0,j.jsx)(l7,{disabled:r,children:`Cancel`}),(0,j.jsxs)(c7,{variant:`destructive`,disabled:r,onClick:e=>{e.preventDefault(),s()},children:[r&&(0,j.jsx)(R2,{}),`Delete`]})]})]})})}function m7({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`input-group`,role:`group`,className:A(`group/input-group relative flex w-full items-center rounded-md border border-input shadow-xs transition-[color,box-shadow] outline-none dark:bg-input/30`,`h-9 min-w-0 has-[>textarea]:h-auto`,`has-[>[data-align=inline-start]]:[&>input]:pl-2`,`has-[>[data-align=inline-end]]:[&>input]:pr-2`,`has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>[data-align=block-start]]:[&>input]:pb-3`,`has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-end]]:[&>input]:pt-3`,`has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-[3px] has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50`,`has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-destructive/20 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40`,e),...t})}var h7=ce(`flex h-auto cursor-text items-center justify-center gap-2 py-1.5 text-sm font-medium text-muted-foreground select-none group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4`,{variants:{align:{"inline-start":`order-first pl-3 has-[>button]:ml-[-0.45rem] has-[>kbd]:ml-[-0.35rem]`,"inline-end":`order-last pr-3 has-[>button]:mr-[-0.45rem] has-[>kbd]:mr-[-0.35rem]`,"block-start":`order-first w-full justify-start px-3 pt-3 group-has-[>input]/input-group:pt-2.5 [.border-b]:pb-3`,"block-end":`order-last w-full justify-start px-3 pb-3 group-has-[>input]/input-group:pb-2.5 [.border-t]:pt-3`}},defaultVariants:{align:`inline-start`}});function g7({className:e,align:t=`inline-start`,...n}){return(0,j.jsx)(`div`,{role:`group`,"data-slot":`input-group-addon`,"data-align":t,className:A(h7({align:t}),e),onClick:e=>{e.target.closest(`button`)||e.currentTarget.parentElement?.querySelector(`[data-slot="input-group-control"]`)?.focus()},...n})}function _7({className:e,...t}){return(0,j.jsx)(z2,{"data-slot":`input-group-control`,className:A(`flex-1 rounded-none border-0 bg-transparent shadow-none focus-visible:ring-0 dark:bg-transparent`,e),...t})}function v7(){let[e,t]=(0,v.useState)([]),[n,r]=(0,v.useState)({kind:`start`}),i=n.kind===`session`?n.id:void 0,[a,o]=(0,v.useState)(),[s,c]=(0,v.useState)(),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(0),p=async()=>{try{let e=await HM.sessions.$get();if(!e.ok)return o(await UM(e));t(await e.json()),o(void 0)}catch{o(`Can't reach the Mivra server.`)}};(0,v.useEffect)(()=>{p()},[]);let m=()=>{r({kind:`draft`}),f(e=>e+1)},h=(e,n)=>{t(t=>[e,...t]),c({sessionId:e.id,...n}),r({kind:`session`,id:e.id})},g=({session:e,goal:t})=>h(e,{message:t}),_=(e,t)=>{u(``),h(e,t)},[y,b]=(0,v.useState)(),x=e=>{b(void 0),r(e)},S=e.find(e=>e.id===i),[C,w]=(0,v.useState)(),T=e=>{w(void 0),t(t=>t.filter(t=>t.id!==e.id)),s?.sessionId===e.id&&c(void 0),i===e.id&&r({kind:`start`})},[E,D]=Q5(),[ee,te]=(0,v.useState)(!1),[ne,re]=(0,v.useState)(!1),[ie,ae]=(0,v.useState)(!1),[oe,se]=(0,v.useState)(!1),[O,ce]=(0,v.useState)(!1);(0,v.useEffect)(()=>{let e=()=>se(!0),t=()=>{se(!1),ce(!0)};return window.addEventListener(PN,e),window.addEventListener(NN,t),()=>{window.removeEventListener(PN,e),window.removeEventListener(NN,t)}},[]);let[le,ue]=(0,v.useState)(!1);return(0,v.useEffect)(()=>{BM&&LN().then(e=>{e.ok&&!H8(e.value)&&(ue(!0),ae(!0))})},[]),(0,j.jsxs)(A5,{children:[(0,j.jsx)(b7,{sessions:e,activeId:i,theme:E,onThemeChange:D,drafting:n.kind===`draft`,onSelect:e=>x({kind:`session`,id:e}),onDelete:w,onRenamed:e=>t(t=>t.map(t=>t.id===e.id?{...t,title:e.title}:t)),onNew:()=>{b(void 0),m()},onNewCourse:()=>x({kind:`start`}),onOpenMemory:()=>te(!0),onOpenImports:()=>re(!0),onOpenProviders:()=>ae(!0),onOpenSettings:()=>se(!0),onOpenUsage:()=>ce(!0)}),(0,j.jsx)(H6,{open:ee,onOpenChange:te}),(0,j.jsx)(k6,{open:ne,onOpenChange:re,onOpenGraph:b}),(0,j.jsx)(U8,{open:ie,onOpenChange:ae,firstRun:le}),(0,j.jsx)(J8,{open:oe,onOpenChange:se}),(0,j.jsx)(a5,{open:O,onOpenChange:ce}),(0,j.jsx)(d3,{}),(0,j.jsx)(p7,{session:C,onClose:()=>w(void 0),onDeleted:T}),(0,j.jsxs)(P5,{className:`h-svh min-w-0 overflow-hidden`,children:[(0,j.jsxs)(`header`,{className:`flex h-13 shrink-0 items-center gap-2 border-b px-3`,children:[(0,j.jsx)(M5,{}),(0,j.jsx)(M2,{orientation:`vertical`,className:`mr-1 data-[orientation=vertical]:h-4`}),(0,j.jsx)(`h1`,{className:`truncate text-base font-medium outline-none`,tabIndex:y?-1:void 0,"data-notes-graph-start":y?``:void 0,children:y?`Notes graph`:S?.title??(n.kind===`draft`?`New session`:`Mivra`)})]}),BM?y?(0,j.jsx)(b8,{importId:y}):a?(0,j.jsx)(y7,{error:!0,children:a}):i?(0,j.jsx)(x7,{sessionId:i,course:!!S?.courseId,start:s?.sessionId===i?s:void 0,onStartUsed:()=>c(void 0),onReply:p},i):n.kind===`draft`?(0,j.jsx)(D7,{text:l,onTextChange:u,focus:d,onSaved:_}):(0,j.jsx)(N3,{onStarted:g,onFreeChat:m}):(0,j.jsx)(y7,{error:!0,children:`No API token found. Start the server, then reload this page.`})]})]})}function y7({error:e,children:t}){return(0,j.jsx)(`p`,{className:A(`m-auto p-6 text-center`,e?`text-destructive`:`text-muted-foreground`),children:t})}function b7({sessions:e,activeId:t,drafting:n,theme:r,onThemeChange:i,onSelect:a,onDelete:o,onRenamed:s,onNew:c,onNewCourse:l,onOpenMemory:u,onOpenImports:d,onOpenProviders:f,onOpenSettings:p,onOpenUsage:m}){let{isMobile:h,setOpenMobile:g}=k5(),[_,y]=(0,v.useState)(),b=e=>{y(void 0),requestAnimationFrame(()=>document.querySelector(`[data-session-id="${CSS.escape(e)}"]`)?.focus())},x=()=>{h&&g(!1)};return(0,j.jsxs)(j5,{collapsible:`icon`,children:[(0,j.jsxs)(I5,{children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2 p-1`,children:[(0,j.jsx)(`div`,{className:`bg-sidebar-primary text-sidebar-primary-foreground font-heading grid size-6 shrink-0 place-items-center rounded-md text-sm font-semibold`,children:`M`}),(0,j.jsx)(`span`,{className:`font-heading truncate text-base font-semibold group-data-[collapsible=icon]:hidden`,children:`Mivra`})]}),(0,j.jsxs)(V5,{children:[(0,j.jsx)(H5,{children:(0,j.jsxs)(W5,{variant:`outline`,tooltip:`New session`,isActive:n,onClick:()=>{c(),x()},children:[(0,j.jsx)(Ng,{}),(0,j.jsx)(`span`,{children:`New session`})]})}),(0,j.jsx)(H5,{children:(0,j.jsxs)(W5,{tooltip:`New course`,onClick:()=>{l(),x()},children:[(0,j.jsx)(Uh,{}),(0,j.jsx)(`span`,{children:`New course`})]})})]})]}),(0,j.jsx)(R5,{children:$5(e).map(e=>(0,j.jsxs)(z5,{children:[(0,j.jsx)(B5,{children:e.label}),(0,j.jsx)(V5,{children:e.sessions.map(e=>(0,j.jsx)(H5,{children:_===e.id?(0,j.jsx)(f7,{session:e,onRenamed:s,onDone:()=>b(e.id)}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(W5,{"data-session-id":e.id,isActive:e.id===t,tooltip:e.title,onClick:()=>{a(e.id),x()},children:[e.courseId?(0,j.jsx)(L3,{icon:e.icon,"aria-label":`Course`}):(0,j.jsx)(sg,{}),(0,j.jsx)(`span`,{children:e.title})]}),(0,j.jsx)(d7,{onRename:()=>y(e.id),onDelete:()=>o(e)})]})},e.id))})]},e.label))}),(0,j.jsxs)(L5,{children:[(0,j.jsxs)(V5,{children:[(0,j.jsx)(H5,{children:(0,j.jsxs)(W5,{tooltip:`Memory`,"data-memory-trigger":!0,onClick:()=>{u(),x()},children:[(0,j.jsx)(Fm,{}),(0,j.jsx)(`span`,{children:`Memory`})]})}),(0,j.jsx)(H5,{children:(0,j.jsxs)(W5,{tooltip:`Imported notes`,"data-imports-trigger":!0,onClick:()=>{d(),x()},children:[(0,j.jsx)(tg,{}),(0,j.jsx)(`span`,{children:`Imported notes`})]})}),(0,j.jsx)(H5,{children:(0,j.jsxs)(W5,{tooltip:`Model providers`,"data-providers-trigger":!0,onClick:()=>{f(),x()},children:[(0,j.jsx)(qh,{}),(0,j.jsx)(`span`,{children:`Model providers`})]})}),(0,j.jsx)(H5,{children:(0,j.jsxs)(W5,{tooltip:`Settings`,"data-settings-trigger":!0,onClick:()=>{p(),x()},children:[(0,j.jsx)(zg,{}),(0,j.jsx)(`span`,{children:`Settings`})]})}),(0,j.jsx)(H5,{children:(0,j.jsxs)(W5,{tooltip:`Usage`,"data-usage-trigger":!0,onClick:()=>{m(),x()},children:[(0,j.jsx)(Um,{}),(0,j.jsx)(`span`,{children:`Usage`})]})})]}),(0,j.jsx)(q5,{choice:r,onChange:i})]}),(0,j.jsx)(N5,{})]})}function x7({course:e,...t}){return e?(0,j.jsx)(S7,{...t}):(0,j.jsx)(C7,{...t})}function S7(e){let{sessionId:t}=e,[n,r]=(0,v.useState)(),[i,a]=(0,v.useState)(),[o,s]=(0,v.useState)(),[c,l]=(0,v.useState)(),[u,d]=(0,v.useState)(!1),f=(0,v.useRef)(0),p=()=>{f.current=performance.now(),d(!0)},[m,h]=(0,v.useState)(),[g,_]=(0,v.useState)(),[y,b]=(0,v.useState)(),x=(0,v.useRef)(void 0),S=(0,v.useRef)(e.onReply);S.current=e.onReply;let C=(0,v.useRef)(!1),w=(0,v.useCallback)(async()=>{let e=await hN(t);if(!e.ok)return h(e.error);if(r(e.value),C.current&&e.value.status!==`interviewing`&&S.current(),C.current=e.value.status===`interviewing`,e.value.status===`interviewing`)return;let n=await gN(e.value.id);n.ok&&a(n.value)},[t]);(0,v.useEffect)(()=>{w()},[w]);let T=async e=>{if(!n)return;let t=await vN(n.id,e);if(!t.ok)return h(t.error);s(t.value.lesson.id),await w()},E=o??i?.currentLessonId??void 0,D=i?.topics.find(e=>e.lesson&&e.lesson.id===i.currentLessonId&&e.lesson.status!==`finished`);(0,v.useEffect)(()=>{if(!E)return;let e=e=>{(e.ctrlKey||e.metaKey)&&!e.altKey&&e.key.toLowerCase()===`k`&&(e.preventDefault(),f.current=performance.now(),d(e=>!e))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[E]);let ee=(0,v.useRef)(0),te=(e,t)=>{_({text:e,send:t,nonce:++ee.current}),p()},ne=async e=>{if(!E)return`No lesson is open.`;let t=x.current?.lessonId===E&&y?.id===E&&y.sections.some(e=>e.id===x.current.section.id)?x.current.section:void 0,n=t??(y?.id===E?y.sections.at(-1):void 0),r=await SN(E,{messageId:e,afterSectionId:n?.id??null,title:t?`More on ${t.title}`.slice(0,120):`From the tutor`});if(!r.ok)return r.error;b(r.value.lesson)},re=n?.syllabus?.version,ie=y?.syllabusVersion;(0,v.useEffect)(()=>{ie&&re&&ie!==re&&w()},[ie,re,w]);let ae=y?.status,oe=y&&i?.topics.find(e=>e.lesson?.id===y.id)?.lesson?.status;(0,v.useEffect)(()=>{ae&&oe&&ae!==oe&&w()},[ae,oe,w]);let se=async()=>{if(!n?.syllabus)return;let e=await CN(n.id,n.syllabus.version);if(!e.ok)return e.error;await w()};if(m)return(0,j.jsx)(y7,{error:!0,children:m});if(!n)return null;let O=i?.topics.find(e=>e.topicId===i.nextTopicId);return E?(0,j.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,j.jsx)(F3,{course:n,onUndo:se,children:(0,j.jsxs)(M,{size:`sm`,variant:`outline`,onClick:p,"data-tutor-trigger":!0,children:[(0,j.jsx)(lg,{"aria-hidden":!0}),` Tutor`]})}),(0,j.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[i&&(0,j.jsx)(`aside`,{className:`hidden w-60 shrink-0 overflow-y-auto border-r p-3 md:block`,children:(0,j.jsx)(V3,{lessons:i,selectedId:E,onSelect:e=>{l(void 0),s(e)}})}),(0,j.jsxs)(`div`,{className:`min-w-0 flex-1 overflow-y-auto`,"data-testid":`lesson-scroll`,children:[i&&(0,j.jsxs)(`details`,{className:`border-b px-4 py-2 md:hidden`,children:[(0,j.jsx)(`summary`,{className:`cursor-pointer text-sm font-medium`,children:`Lessons`}),(0,j.jsx)(`div`,{className:`pt-2`,children:(0,j.jsx)(V3,{lessons:i,selectedId:E,onSelect:e=>{l(void 0),s(e)}})})]}),D&&E!==D.lesson.id&&(0,j.jsxs)(`div`,{className:`bg-muted mx-auto mt-4 flex max-w-3xl flex-wrap items-center gap-2 rounded-lg px-4 py-2 text-sm`,role:`status`,children:[(0,j.jsx)(`span`,{children:`You're looking at an earlier lesson.`}),(0,j.jsxs)(M,{size:`xs`,variant:`outline`,onClick:()=>{l(void 0),s(D.lesson.id)},children:[`Back to lesson `,i.topics.indexOf(D)+1,`: `,D.title]})]}),(0,j.jsx)(H3,{courseComplete:n.status===`complete`,lessonId:E,nextTopic:O&&{id:O.topicId,title:O.title},onFinished:()=>void w(),onStartNext:T,onLoaded:b,focusSectionId:c,onOpenSection:(e,t)=>{s(e),l(t)},onExplain:e=>{x.current={lessonId:E,section:e},te(`Explain "${e.title}"`,!0)},onChange:e=>{x.current=void 0,te(`Change "${e.title}": `,!1)}},E)]})]}),(0,j.jsx)(f6,{open:u,onOpenChange:d,children:(0,j.jsxs)(h6,{className:`flex w-full flex-col gap-0 p-0 sm:max-w-lg`,onPointerDownOutside:e=>{e.detail.originalEvent.timeStamp<f.current&&e.preventDefault()},children:[(0,j.jsxs)(g6,{className:`border-b`,children:[(0,j.jsx)(_6,{className:`font-heading`,children:`Tutor`}),(0,j.jsxs)(v6,{children:[`Ask anything and the lesson stays as it is, or ask for a change. `,(0,j.jsx)(`kbd`,{className:`text-xs`,children:`Ctrl K`}),` opens and closes this.`]})]}),(0,j.jsx)(C7,{...e,onSettled:w,lessonId:E,prompt:g,onPromptUsed:()=>_(void 0),foldThroughMessageId:n.interviewMessageId,placeholder:`Ask the tutor…`,onAddToLesson:y?.status===`ready`?ne:void 0})]})})]}):(0,j.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,j.jsx)(F3,{course:n,children:O&&(0,j.jsx)(M,{size:`sm`,onClick:()=>void T(O.topicId),children:`Start lesson 1`})}),(0,j.jsx)(C7,{...e,onSettled:w})]})}function C7({sessionId:e,onReply:t,...n}){let[r,i]=(0,v.useState)(),[a,o]=(0,v.useState)();return(0,v.useEffect)(()=>{JM(e).then(e=>e.ok?i(e.messages):o(e.error))},[e]),a?(0,j.jsxs)(y7,{error:!0,children:[`Couldn't load this session: `,a]}):r?(0,j.jsx)(w7,{sessionId:e,initialMessages:r,onReply:t,...n}):null}function w7({sessionId:e,initialMessages:t,start:n,onStartUsed:r,onReply:i,onSettled:a,lessonId:o,prompt:s,onPromptUsed:c,onAddToLesson:l,foldThroughMessageId:u,placeholder:d=`What do you want to learn?`}){let[f,p]=(0,v.useState)(!1),m=(0,v.useRef)(o);m.current=o;let[h,g]=(0,v.useState)(n?.input??``),_=Y3(e),y=w3(),b=(0,v.useRef)(_);b.current=_;let[x,S]=(0,v.useState)({}),C=w({initial:`instant`,resize:`instant`}),T=(0,v.useRef)(!1),E=(0,v.useRef)(null),[D,ee]=(0,v.useState)(),[te,ne]=(0,v.useState)(),re=(0,v.useRef)(void 0),ie=(0,v.useRef)(!1),ae=(0,v.useRef)(0),oe=(0,v.useRef)(!1),se=(0,v.useRef)(!1),O=(0,v.useRef)(!1),ce=(0,v.useRef)(0),le=(0,v.useRef)(!0),{messages:ue,sendMessage:de,setMessages:fe,status:pe,error:me,resumeStream:he,stop:ge}=oA({id:e,experimental_throttle:50,messages:t,transport:new Jk({api:`/api/sessions/${e}/chat`,headers:VM,prepareReconnectToStreamRequest:()=>({api:`/api/sessions/${e}/continuation`}),prepareSendMessagesRequest:({messages:e,body:t})=>({body:{...t,message:e.at(-1),...m.current?{lessonId:m.current}:{}}}),fetch:async(e,t)=>{let n=ce.current,r=await fetch(e,t);if(t?.method===`GET`){re.current=r.headers.get(`x-mivra-continuation-stop-id`)??void 0,ie.current=r.status===200,ie.current&&(O.current=!1),r.status===204&&await Ce(n),se.current=!1;let e=r.headers.get(`x-mivra-continuation-error`);if(e&&(ne(e),r.status===204))throw Error(e)}else r.ok&&await b.current.refresh();return r}}),onFinish:({message:t,isDisconnect:n})=>{oe.current||n||!le.current||(ie.current?(ie.current=!1,re.current=void 0,Ce(ce.current)):T.current&&JM(e).then(e=>{e.ok&&fe(n=>n.at(-1)?.id===t.id?e.messages:n)}),i())}}),_e=(0,v.useRef)(0);(0,v.useEffect)(()=>{s&&s.nonce!==_e.current&&(_e.current=s.nonce,c?.(),s.send&&!Se.current.busy?de({text:s.text},{body:{documentIds:[]}}):(g(s.text),requestAnimationFrame(()=>E.current?.focus())))},[s,de,c]);let ve=(0,v.useRef)(!1),{upload:ye}=_;(0,v.useEffect)(()=>{!n||ve.current||t.length>0||(ve.current=!0,r(),n.file&&ye(n.file),n.message&&de({text:n.message},{body:{documentIds:[]}}))},[n,t.length,r,de,ye]),(0,v.useEffect)(()=>{let e=C.scrollRef.current;if(!e)return;e.dataset.testid=`transcript`,e.tabIndex=0,e.setAttribute(`aria-label`,`Conversation messages`);let t,n=e=>{let n=e.touches[0];t=n?{x:n.clientX,y:n.clientY}:void 0},r=n=>{let r=n.touches[0];if(!t||!r||e.scrollTop<=0)return;let i=r.clientY-t.y;i>8&&i>Math.abs(r.clientX-t.x)&&C.stopScroll()},i=t=>{t.target===e&&([`ArrowUp`,`PageUp`,`Home`].includes(t.key)||t.key===` `&&t.shiftKey)&&C.stopScroll()};return e.addEventListener(`touchstart`,n,{passive:!0}),e.addEventListener(`touchmove`,r,{passive:!0}),e.addEventListener(`keydown`,i),()=>{e.removeEventListener(`touchstart`,n),e.removeEventListener(`touchmove`,r),e.removeEventListener(`keydown`,i)}},[C.scrollRef,C.stopScroll]),(0,v.useEffect)(()=>{let e=requestAnimationFrame(()=>{let e=C.scrollRef.current;e&&e.scrollHeight-e.clientHeight-e.scrollTop<=1&&C.scrollToBottom(`instant`)});return()=>cancelAnimationFrame(e)},[x,C.scrollRef,C.scrollToBottom]);let be=pe===`submitted`||pe===`streaming`,xe=(0,v.useRef)(a);xe.current=a,(0,v.useEffect)(()=>{be||xe.current?.()},[be,ue.length]);let Se=(0,v.useRef)({busy:be,resumeStream:he,stop:ge});Se.current={busy:be,resumeStream:he,stop:ge};async function Ce(t){let n=await JM(e);n.ok&&le.current&&ce.current===t&&fe(n.messages)}let we=async(e=!1)=>{if(se.current){e&&(O.current=!0);return}if(Se.current.busy&&!re.current)return;se.current=!0;let t=++ae.current,n=ce.current;try{if(re.current&&(oe.current=!0,await Se.current.stop(),oe.current=!1),!le.current||ce.current!==n)return;se.current=!0,T.current=!1,await Se.current.resumeStream()}finally{ae.current===t&&(se.current=!1,O.current&&le.current&&(O.current=!1,Te.current())),oe.current=!1}},Te=(0,v.useRef)(we);Te.current=we;let Ee=(0,v.useRef)(!!n?.message&&t.length===0);(0,v.useEffect)(()=>{le.current=!0;let e=()=>{document.visibilityState===`visible`&&Te.current()};return Ee.current||e(),window.addEventListener(`focus`,e),document.addEventListener(`visibilitychange`,e),()=>{le.current=!1,window.removeEventListener(`focus`,e),document.removeEventListener(`visibilitychange`,e)}},[]);let De=async()=>{let t=await JM(e);t.ok&&S(e=>T2(e,C2(t.messages))),we(!0)},Oe=async e=>{e.preventDefault();let t=h.trim();if(!t||be)return;T.current=!1,ee(void 0),ne(void 0),ce.current++,ae.current++,O.current=!1,oe.current=!0,await ge(),se.current=!1,oe.current=!1,ie.current=!1,re.current=void 0,C.scrollToBottom(`instant`);let n=_.documents.filter(e=>e.messageId===null).map(e=>e.id);de({text:t},{body:{documentIds:n}}),g(``)},ke=u?ue.findIndex(e=>e.id===u):-1;return(0,j.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,j.jsxs)(f_,{"aria-busy":be,instance:C,initial:`instant`,resize:`instant`,className:`min-h-0 min-w-0`,children:[(0,j.jsxs)(p_,{className:`relative mx-auto max-w-3xl gap-5 px-4 py-6 leading-relaxed`,scrollClassName:`overflow-y-auto overscroll-contain [scrollbar-gutter:auto]!`,onPointerDownCapture:e=>{e.target.closest(`button, input, [role=button]`)&&C.stopScroll()},onKeyDownCapture:e=>{e.key!==`Tab`&&e.target.closest(`button, input, [role=region]`)&&C.stopScroll()},children:[ue.length===0&&!be&&(0,j.jsx)(T7,{}),ke>=0&&!f&&(0,j.jsx)(M,{variant:`ghost`,size:`sm`,className:`text-muted-foreground self-center`,onClick:()=>p(!0),children:`Show the placement interview`}),ue.map((e,t)=>!f&&t<=ke?null:(0,j.jsxs)(`div`,{"data-message-id":e.id,"data-message-role":e.role,className:A(`flex min-w-0 flex-col gap-3`,e.role===`user`&&`bg-sunken text-foreground max-w-[min(80%,34rem)] self-end rounded-2xl rounded-br-sm px-4 py-2.5 leading-relaxed whitespace-pre-wrap wrap-anywhere`),children:[e.role===`user`&&(0,j.jsx)(Q3,{documents:_,messageId:e.id}),e.role===`assistant`&&e.parts.some(e=>e.type===`reasoning`&&e.text.length>0)&&(0,j.jsxs)(t6,{defaultOpen:!1,children:[(0,j.jsxs)(n6,{children:[`Thinking`,x2(pe,t,ue.length)&&e.parts.some(e=>e.type===`reasoning`&&e.state===`streaming`)&&(0,j.jsx)(`span`,{className:`ml-2 text-xs`,children:`In progress…`})]}),(0,j.jsx)(i6,{children:e.parts.map((e,n)=>e.type===`reasoning`&&(0,j.jsx)(r6,{label:(0,j.jsx)(`span`,{className:`whitespace-pre-wrap`,children:e.text}),status:x2(pe,t,ue.length)&&e.state===`streaming`?`active`:`complete`},n))})]}),e.parts.map((n,r)=>n.type===`text`?e.role===`user`?(0,j.jsx)(`p`,{children:n.text},r):(0,j.jsx)(rQ,{text:n.text},r):n.type===`data-artifact`?(0,j.jsx)(b2,{data:S2(n,x),replyInProgress:x2(pe,t,ue.length),onUpdate:e=>{S(t=>T2(t,{[e.id]:e})),we(!0)},onRefresh:De},n.id??r):null),e.role===`assistant`&&typeof e.metadata?.model==`string`&&(0,j.jsx)(`p`,{className:`text-muted-foreground text-xs`,"data-reply-model":!0,children:b3(e.metadata.model,y.view?.models,y.view?.providers)}),l&&e.role===`assistant`&&t>ke&&!x2(pe,t,ue.length)&&e.parts.some(e=>e.type===`text`&&e.text.trim())&&(0,j.jsx)(O7,{onAdd:()=>l(e.id)})]},e.id)),pe===`submitted`&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Thinking…`]}),D&&(0,j.jsx)(`p`,{className:`text-destructive`,children:D}),(me||te)&&((me?k7(me):te)===`ChatGPT usage limit reached. Review your plan or this app's limit in ChatGPT settings.`?(0,j.jsx)(u3,{}):(0,j.jsx)(`p`,{className:`text-destructive`,children:me?k7(me):te}))]}),(0,j.jsx)(m_,{"aria-label":`Scroll to bottom`,onClick:()=>void C.scrollToBottom(`instant`)})]}),(0,j.jsx)(E7,{documents:_,input:h,onInputChange:g,onSubmit:Oe,inputRef:E,placeholder:d,modelPicker:y,action:be?(0,j.jsx)(M,{type:`button`,variant:`secondary`,onClick:async t=>{let n=t.currentTarget,r=document.activeElement===n;try{if(T.current)return;T.current=!0;let t=re.current??ue.findLast(e=>e.role===`user`)?.id;if(!t)return;let i=await HM.sessions[`:id`].stop.$post({param:{id:e},json:{messageId:t}});i.ok&&r&&(document.activeElement===n||document.activeElement===document.body)&&E.current?.focus(),i.ok||(T.current=!1),i.ok||ee(`Couldn’t stop the reply. Try again.`)}catch{T.current=!1,ee(`Couldn’t stop the reply. Try again.`)}},children:`Stop`}):(0,j.jsx)(M,{type:`submit`,disabled:!h.trim(),children:`Send`})})]})}function T7(){return(0,j.jsx)(a6,{className:`my-auto`,children:(0,j.jsxs)(o6,{children:[(0,j.jsx)(c6,{variant:`icon`,children:(0,j.jsx)(lg,{"aria-hidden":`true`})}),(0,j.jsx)(l6,{children:`Start a conversation`}),(0,j.jsx)(u6,{children:`Ask a question, explore a concept or attach course notes to learn from.`})]})})}function E7({documents:e,input:t,onInputChange:n,onSubmit:r,inputRef:i,placeholder:a,modelPicker:o,action:s,disabled:c}){return(0,j.jsxs)(`form`,{onSubmit:r,className:`bg-background border-t`,children:[(0,j.jsx)(Q3,{documents:e}),(0,j.jsx)(`div`,{className:`mx-auto w-full max-w-3xl p-3`,children:(0,j.jsxs)(m7,{className:`bg-card dark:bg-card border-border-strong shadow-paper h-auto min-h-11 rounded-xl`,"aria-label":`Message composer`,children:[(0,j.jsx)(g7,{align:`inline-start`,children:(0,j.jsx)(Z3,{documents:e})}),(0,j.jsx)(_7,{ref:i,value:t,onChange:e=>n(e.target.value),placeholder:a,"aria-label":`Message`,readOnly:c,autoFocus:!0}),(0,j.jsx)(g7,{align:`inline-end`,children:s})]})}),(0,j.jsx)(`div`,{className:`mx-auto flex max-w-3xl px-3 pb-2`,children:(0,j.jsx)(E3,{state:o})})]})}function D7({text:e,onTextChange:t,focus:n,onSaved:r}){let i=w3(),a=(0,v.useRef)(null),[o,s]=(0,v.useState)(),[c,l]=(0,v.useState)();(0,v.useEffect)(()=>{a.current?.focus()},[n]);let u=async(e,t)=>{if(o)return;s({file:t}),l(void 0);let n=await XM();if(s(void 0),!n.ok)return l(n.error);r(n.value,e)},d={documents:[],uploading:o?.file,error:c,upload:t=>u({file:t,input:e},t.name),remove:async()=>{},refresh:async()=>{}};return(0,j.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,j.jsxs)(`div`,{className:`mx-auto flex min-h-0 w-full max-w-3xl flex-1 flex-col overflow-y-auto p-4`,children:[(0,j.jsx)(T7,{}),o&&!o.file&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Thinking…`]})]}),(0,j.jsx)(E7,{documents:d,input:e,onInputChange:t,onSubmit:t=>{t.preventDefault();let n=e.trim();n&&u({message:n})},inputRef:a,placeholder:`What do you want to learn?`,modelPicker:i,disabled:o!==void 0,action:(0,j.jsx)(M,{type:`submit`,disabled:!e.trim()||o!==void 0,children:`Send`})})]})}function O7({onAdd:e}){let[t,n]=(0,v.useState)(`idle`),[r,i]=(0,v.useState)();return(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,j.jsxs)(M,{variant:`outline`,size:`xs`,className:`self-start`,disabled:t!==`idle`,onClick:async()=>{n(`adding`),i(void 0);let t=await e();i(t),n(t?`idle`:`added`)},children:[(0,j.jsx)(Gg,{"aria-hidden":!0}),` `,t===`added`?`Added to lesson`:`Add to lesson`]}),r&&(0,j.jsx)(`span`,{className:`text-destructive text-xs`,children:r})]})}function k7(e){try{let t=JSON.parse(e.message);if(t.error)return t.error}catch{}return e.message}(0,ie.createRoot)(document.getElementById(`root`)).render((0,j.jsx)(v.StrictMode,{children:(0,j.jsx)(v7,{})}));
413
+ `;if(r)r(o)&&(r=void 0);else if(i){let r=ZX.exec(o)?.[1];if(r?.[0]===`$`&&r.length>=i)i=void 0;else{let r=dZ(o,i);if(r&&uZ(lZ(a,o.slice(0,r.start)))){let a=o.slice(0,r.start),c=oZ(o.slice(r.end).trim());n[e]=(a.trim()?a+t:``)+o.slice(r.start,r.end)+(c?t+c:``)+s,i=void 0}else a=lZ(a,o)}}else if(/^[ \t]/.test(o)){if(YX.test(o.trimStart())||XX.test(o.trimStart()))break}else if(YX.test(o))r=fZ(o);else{let r=eZ(o);if(r){let{fence:o,rest:c}=r;i=o.length,a=c?lZ(sZ,c):sZ,c&&(n[e]=o+t+c+s)}}}return n}var aZ=new RegExp([tZ.source,nZ.source,"^(?:`{3}|~{3}|\\$\\$)",`^\\[(?:[^\\]\\\\]|\\\\.)*(?:\\]:|$)`,`^<(?![a-z][a-z\\d+.-]{1,31}:[^\\s<>]*>|[^\\s<>@]+@[^\\s<>]+>)[a-z/!?]`].join(`|`));function oZ(e){return aZ.test(e)?/^\d/.test(e)?e.replace(/^(\d+)/,`$1\\`):`\\${e}`:e}var sZ={depth:0,uncertain:!1},cZ=new Set([`verb`,`def`,`gdef`,`edef`,`xdef`,`let`,`futurelet`,`newcommand`,`renewcommand`,`providecommand`,`catcode`,`csname`,`expandafter`,`noexpand`,`includegraphics`]);function lZ(e,t){if(e.uncertain)return e;let n=e.depth;for(let e=0;e<t.length;e++){let r=t[e];if(r===`\\`){let r=e+1;for(;r<t.length&&/[a-zA-Z@]/.test(t[r]);)r++;let i=t.slice(e+1,r);if(cZ.has(i)||i.includes(`@`)||i.startsWith(`if`))return{depth:n,uncertain:!0};e=r>e+1?r-1:e+1}else if(r===`%`)return{depth:n,uncertain:!0};else r===`{`?n++:r===`}`&&(n=Math.max(0,n-1))}return{depth:n,uncertain:!1}}var uZ=e=>!e.uncertain&&e.depth===0;function dZ(e,t){for(let n=0;n<e.length;n++){if(e[n]===`\\`){n++;continue}if(e[n]!==`$`)continue;let r=n;for(;e[r]===`$`;)r++;if(r-n>=t)return{start:n,end:r};n=r-1}}function fZ(e){let t=YX.exec(e)?.[1]??XX.exec(e)?.[1];if(t)return e=>{let n=ZX.exec(e)?.[1];return n!==void 0&&n[0]===t[0]&&n.length>=t.length}}var pZ=5e4,mZ=32,hZ=200,gZ=/\[{33}/,_Z=/\*{1001}|_{1001}|~{1001}/,vZ=/^[ \t]*(?:(?:>|[-*+](?=[ \t])|\d{1,9}[.)](?=[ \t]))[ \t]*)+/,yZ=/>|[-*+]|\d{1,9}[.)]/g;function bZ(e){let t=[],n=0,r=0,i,a=(a,o)=>{let s=e.slice(n,a);t.push(e[n]===`$`?{kind:`math`,text:s}:{kind:`code`,text:s,code:e.slice(r,o)}),n=a,i=void 0};for(let o of QX(e))if(i)i(o.text)&&a(o.next,o.start);else{let a=/^\s/.test(o.text)?void 0:fZ(o.text);a&&(o.start>n&&t.push({kind:`prose`,text:e.slice(n,o.start)}),n=o.start,r=o.next,i=a)}return i?a(e.length,e.length):n<e.length&&t.push({kind:`prose`,text:e.slice(n)}),t}function xZ(e){return e.length>pZ?!0:KX.test(e)||qX.test(e)?SZ(e):bZ(e).some(e=>e.kind===`prose`&&SZ(e.text))}function SZ(e){for(let{text:t}of QX(e)){if(gZ.test(t)||_Z.test(t)||/^[ \t]*/.exec(t)[0].length>hZ)return!0;let e=vZ.exec(t)?.[0];if(e&&(e.match(yZ)?.length??0)>mZ)return!0}return!1}var CZ=[`http:`,`https:`,`mailto:`];function wZ(e){try{let t=new URL(e);return CZ.includes(t.protocol)?t.href:``}catch{return``}}function TZ(){return(e,t)=>{let n=String(t.value),r=e=>{for(let t of e.children??[]){let e=t.position?.start.offset;t.type===`inlineMath`&&e!==void 0&&n.startsWith(`$$`,e)&&(t.data={...t.data,hProperties:{...t.data?.hProperties,className:[`language-math`,`math-display`]}}),r(t)}};r(e)}}var EZ=[Zq,lJ,GX,TZ],DZ=DX().use(JJ).use(EZ).use($Y,{allowDangerousHtml:!0}),OZ=1e3,kZ=new Map;function AZ(e,t){let n=`${t?`D`:`I`}${e}`,r=kZ.get(n);if(r!==void 0)return kZ.delete(n),kZ.set(n,r),r;let i;try{i=tH.renderToString(e,{displayMode:t,trust:!1,strict:`ignore`,throwOnError:!1,errorColor:`var(--destructive)`})}catch{return}return kZ.set(n,i),kZ.size>OZ&&kZ.delete(kZ.keys().next().value),i}var jZ=e=>{let t=e.properties.className;return Array.isArray(t)?t.map(String):[]},MZ=e=>e?.type===`element`&&e.tagName===`code`&&jZ(e).includes(`language-math`),NZ=e=>e.children.map(e=>e.type===`text`?e.value:``).join(``);function PZ(e){let t=DZ.runSync(DZ.parse(e),e),n=[],r=(e,t)=>{let r=AZ(e,t);return r===void 0?{type:`element`,tagName:`span`,properties:{className:[`katex-error`]},children:[{type:`text`,value:e}]}:(n.push(r),{type:`element`,tagName:`span`,properties:{className:[`math-text-formula`],dataFormula:n.length-1},children:[]})};return iW(t,(e,t,n)=>{if(delete e.position,n&&t!==void 0){if(e.type===`raw`)n.children[t]={type:`text`,value:e.value};else if(e.type===`element`){if(e.tagName===`pre`&&e.children.length===1&&MZ(e.children[0]))return n.children[t]=r(NZ(e.children[0]).replace(/\n$/,``),!0),`skip`;if(MZ(e))return n.children[t]=r(NZ(e),jZ(e).includes(`math-display`)),`skip`;for(let[t,n]of Object.entries(WF))Object.hasOwn(e.properties,t)&&(n===null||n.includes(e.tagName))&&(e.properties[t]=wZ(String(e.properties[t]??``)))}}}),{tree:t,formulas:n}}var FZ=8e3,IZ=250,LZ=2e3,RZ=/\\(?:[gex]?def|let|futurelet|(?:re|provide)?newcommand|(?:re)?newenvironment)(?![a-zA-Z])/,zZ=300,BZ=class{entries=new Map;get(e){let t=this.entries.get(e);return t!==void 0&&(this.entries.delete(e),this.entries.set(e,t)),t}set(e,t){this.entries.delete(e),this.entries.set(e,t),this.entries.size>zZ&&this.entries.delete(this.entries.keys().next().value)}};function VZ(e){try{return PZ(e)}catch{return`plain`}}function HZ(){let e=new BZ,t=t=>{let n=e.get(t);return n===void 0&&e.set(t,n=VZ(t)),n};return{peek:t,render:async e=>t(e),dispose(){}}}function UZ(e,t={}){let{timeoutMs:n=FZ,cancelGraceMs:r=IZ,syncLimit:i=LZ}=t,a=new BZ,o=[],s,c,l=1,u=()=>{if(s)return s;let t=e();return t.onmessage=e=>{s===t&&c?.job.id===e.data.id&&f(e.data.block??`plain`)},t.onerror=()=>{s===t&&(c?m(`plain`):p())},s=t},d=(e,t)=>{e.signal.removeEventListener(`abort`,e.onAbort),e.resolve(e.signal.aborted?void 0:t)},f=e=>{let t=c;c=void 0,clearTimeout(t.deadline),clearTimeout(t.grace),e!==void 0&&a.set(t.job.text,e),d(t.job,e),h()},p=()=>{s?.terminate(),s=void 0},m=e=>{p(),f(e)},h=()=>{for(;!c&&o.length>0;){let e=o.shift(),t=a.get(e.text);if(t!==void 0)d(e,t);else{c={job:e,deadline:setTimeout(()=>m(`plain`),n)};try{u().postMessage({id:e.id,text:e.text})}catch{m(`plain`)}}}};return{peek(e){let t=a.get(e);if(t!==void 0||e.length>i||RZ.test(e))return t;let n=VZ(e);return a.set(e,n),n},dispose(){for(let e of o.splice(0))d(e,void 0);c?m(void 0):p()},render(e,t){return t.aborted?Promise.resolve(void 0):new Promise(n=>{let i={id:l++,text:e,signal:t,resolve:n,onAbort:()=>{let e=o.indexOf(i);e>=0?(o.splice(e,1),d(i,void 0)):c?.job===i&&c.grace===void 0&&(c.grace=setTimeout(()=>m(void 0),r))}};t.addEventListener(`abort`,i.onAbort),o.push(i),h()})}}}var WZ=(0,v.memo)(function({source:e,display:t}){let n=AZ(e,t);return n===void 0?(0,j.jsx)(`span`,{className:`katex-error`,children:e}):(0,j.jsx)(`span`,{className:`math-text-formula`,dangerouslySetInnerHTML:{__html:n}})});function GZ({block:e}){return(0,v.useMemo)(()=>xF(e.tree,{Fragment:v.Fragment,jsx:j.jsx,jsxs:j.jsxs,components:{a:({href:e,children:t})=>e?(0,j.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:t}):(0,j.jsx)(`span`,{children:t}),span:t=>{let n=t[`data-formula`];return n===void 0?(0,j.jsx)(`span`,{className:t.className,children:t.children}):(0,j.jsx)(`span`,{className:`math-text-formula`,dangerouslySetInnerHTML:{__html:e.formulas[Number(n)]??``}})},img:({alt:e})=>e?(0,j.jsx)(`span`,{children:e}):null,table:e=>(0,j.jsx)(`div`,{className:`math-text-scroll`,children:(0,j.jsx)(`table`,{children:e.children})}),h1:`h4`,h2:`h4`,h3:`h5`,h4:`h6`,h5:`h6`},passKeys:!0,ignoreInvalidStyle:!0}),[e])}function KZ({text:e}){return bZ(e).map((e,t)=>e.kind===`code`?(0,j.jsx)(`pre`,{children:(0,j.jsx)(`code`,{children:e.code})},t):(0,j.jsx)(`p`,{className:`math-text-literal`,children:e.text},t))}var qZ=class extends v.Component{state={};componentDidCatch(){this.setState({failedText:this.props.text})}render(){return this.state.failedText===this.props.text?(0,j.jsx)(KZ,{text:this.props.text}):this.props.children}},JZ;function YZ(){return JZ??=typeof Worker>`u`?HZ():UZ(()=>new Worker(new URL(`/assets/render.worker-BAfybD27.js`,``+import.meta.url),{type:`module`,name:`mivra-render`})),JZ}var XZ=(0,v.createContext)(void 0);function ZZ(e){let t=(0,v.useContext)(XZ)??YZ(),n=e===void 0?void 0:t.peek(e),[r,i]=(0,v.useState)(),a=(0,v.useRef)(void 0);(0,v.useEffect)(()=>{if(e===void 0||n!==void 0)return;let r=new AbortController;return t.render(e,r.signal).then(t=>{t!==void 0&&i({text:e,result:t})}),()=>r.abort()},[t,e,n]);let o=n??(r&&r.text===e?r.result:void 0);return(0,v.useEffect)(()=>{o!==void 0&&(a.current=o)}),e===void 0?void 0:o??a.current}var QZ=(0,v.memo)(function({text:e,source:t}){let n=(0,v.useMemo)(()=>xZ(e),[e]),r=ZZ(n?void 0:e);return n||r===void 0||r===`plain`?(0,j.jsx)(KZ,{text:t}):(0,j.jsx)(qZ,{text:t,children:(0,j.jsx)(GZ,{block:r})})}),$Z=2e4;function eQ(e,t){let n=0,r=0;for(;r<e.length&&(r===0||n<t);)n+=e[r++].text.length;return r}function tQ({text:e,className:t}){let n=(0,v.useDeferredValue)(e),r=(0,v.useMemo)(()=>rZ(n),[n]),[i,a]=(0,v.useState)($Z),o=eQ(r,i);return(0,v.useEffect)(()=>{if(o>=r.length)return;let e=r.slice(0,o).reduce((e,t)=>e+t.text.length,0),t=setTimeout(()=>a(t=>Math.max(t,e)+$Z),0);return()=>clearTimeout(t)},[o,r]),(0,j.jsx)(`div`,{className:t,children:r.slice(0,o).map((e,t)=>(0,j.jsx)(QZ,{text:e.text,source:e.source},t))})}function nQ({text:e,className:t}){let n=(0,v.useMemo)(()=>lA(e),[e]);return(0,j.jsx)(`span`,{className:`${t} math-text-literal`,children:n.map((e,t)=>`formula`in e?(0,j.jsx)(WZ,{source:e.formula,display:!1},t):e.text)})}function rQ({text:e,mode:t=`block`,className:n}){let r=n?`math-text ${n}`:`math-text`;return t===`math`?(0,j.jsx)(nQ,{text:e,className:r}):(0,j.jsx)(tQ,{text:e,className:r})}function iQ({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`card`,className:A(`flex flex-col gap-6 rounded-xl border bg-card py-6 text-card-foreground shadow-sm`,e),...t})}function aQ({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`card-content`,className:A(`px-6`,e),...t})}var oQ=1500,sQ={active:`bg-secondary ring-2 ring-inset ring-foreground`,done:`bg-success/15 ring-1 ring-inset ring-success`,muted:`bg-muted text-muted-foreground`},cQ={current:`bg-foreground text-background`,other:`bg-sunken text-muted-foreground ring-1 ring-inset ring-border-strong`};function lQ(e){let t=e-1,[n,r]=(0,v.useState)(0),[i,a]=(0,v.useState)(!1);(0,v.useEffect)(()=>{if(!i)return;if(n>=t){a(!1);return}let e=setTimeout(()=>r(e=>Math.min(e+1,t)),oQ);return()=>clearTimeout(e)},[i,n,t]);let o=e=>{a(!1),r(Math.max(0,Math.min(e,t)))};return{index:n,last:t,playing:i,go:o,togglePlay:()=>{if(i)return a(!1);n>=t&&r(0),a(!0)},onKeyDown:e=>{if(e.key===`ArrowLeft`)o(n-1);else if(e.key===`ArrowRight`)o(n+1);else return;e.preventDefault()}}}function uQ({children:e,label:t=`Formula, scrolls sideways`,className:n}){let r=(0,v.useRef)(null),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(!1),c=()=>{r.current&&a(r.current.scrollWidth>r.current.clientWidth)};return(0,v.useLayoutEffect)(c),(0,v.useEffect)(()=>{let e=new ResizeObserver(c);return e.observe(r.current),document.fonts.ready.then(c),()=>e.disconnect()},[]),(0,j.jsx)(`span`,{ref:r,className:A(`step-scroll block min-w-0 overflow-x-auto overflow-y-hidden`,n),"data-testid":`step-scroll`,...i?{role:`group`,"aria-label":t}:{},tabIndex:i?0:o?-1:void 0,onFocus:()=>s(!0),onBlur:e=>s(document.activeElement===e.currentTarget),onKeyDown:e=>{(e.key===`ArrowLeft`||e.key===`ArrowRight`)&&e.stopPropagation()},children:e})}function dQ({children:e}){return(0,j.jsx)(uQ,{children:(0,j.jsx)(`span`,{"aria-hidden":`true`,children:e})})}function fQ({stepper:e,play:t=!1,children:n}){let{index:r,last:i,playing:a,go:o,togglePlay:s}=e;if(i<=0)return null;let c=`bg-card dark:bg-card border-border-strong dark:border-border-strong hover:bg-sunken dark:hover:bg-sunken hover:text-foreground aria-disabled:cursor-not-allowed aria-disabled:opacity-45`;return(0,j.jsxs)(`div`,{"data-slot":`artifact-footer`,className:`bg-sunken/55 flex flex-wrap items-center gap-x-4 gap-y-2.5 rounded-b-xl border-t px-3.5 py-2.5`,children:[(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,j.jsxs)(M,{type:`button`,variant:`outline`,size:`sm`,className:c,onClick:()=>o(r-1),"aria-disabled":r===0,children:[(0,j.jsx)(Zm,{}),`Prev`]}),t&&(0,j.jsxs)(M,{type:`button`,size:`sm`,className:`min-w-20`,onClick:s,children:[a?(0,j.jsx)(Tg,{className:`fill-current`}):(0,j.jsx)(jg,{className:`fill-current`}),a?`Pause`:`Play`]}),(0,j.jsxs)(M,{type:`button`,variant:`outline`,size:`sm`,className:c,onClick:()=>o(r+1),"aria-disabled":r===i,children:[`Next`,(0,j.jsx)($m,{})]}),n]}),(0,j.jsxs)(`div`,{className:`ml-auto flex min-w-0 max-w-full items-center gap-3`,children:[(0,j.jsx)(`span`,{className:`flex min-w-0 gap-[3px]`,"aria-hidden":`true`,"data-testid":`step-pips`,children:i<24&&Array.from({length:i+1},(e,t)=>(0,j.jsx)(`i`,{className:A(`h-[3px] w-3 min-w-[2px] shrink rounded-full`,t<r?`bg-muted-foreground`:t===r?`bg-foreground`:`bg-border-strong`)},t))}),(0,j.jsxs)(`span`,{className:`text-muted-foreground font-mono text-xs whitespace-nowrap`,"aria-hidden":`true`,"data-testid":`step-counter`,children:[`Step `,r+1,` of `,i+1]})]})]})}function pQ({className:e,...t}){return(0,j.jsx)(iQ,{"data-artifact-card":``,className:A(`border-border-strong shadow-paper gap-0 py-0 whitespace-normal`,e),...t})}function mQ({kind:e,kindId:t,aside:n,children:r}){return(0,j.jsxs)(`div`,{"data-slot":`artifact-header`,className:`flex min-w-0 flex-wrap items-baseline gap-x-3.5 gap-y-1 border-b px-4 py-3 sm:px-5`,children:[(0,j.jsx)(`span`,{id:t,className:`text-accent-foreground shrink-0 font-mono text-[0.6875rem] leading-snug font-medium tracking-[0.09em] uppercase`,children:e}),r,n&&(0,j.jsx)(`span`,{className:`text-muted-foreground ml-auto font-mono text-[0.6875rem] leading-snug tracking-[0.09em] uppercase`,children:n})]})}function hQ({id:e,text:t}){return(0,j.jsx)(`h3`,{className:`font-heading min-w-0 flex-[1_1_12rem] text-[1.0625rem] leading-snug font-medium`,children:(0,j.jsx)(uQ,{children:(0,j.jsx)(`span`,{id:e,children:(0,j.jsx)(rQ,{text:t,mode:`math`})})})})}function gQ({className:e,...t}){return(0,j.jsx)(aQ,{className:A(`flex flex-col gap-3 px-4 py-4 sm:px-5 sm:py-5`,e),...t})}function _Q({index:e}){return(0,j.jsx)(`span`,{"aria-hidden":`true`,className:`border-border-strong text-muted-foreground grid size-6 shrink-0 place-items-center rounded-[6px] border font-mono text-[0.72rem] font-medium`,"data-testid":`option-key`,children:e<26?String.fromCharCode(65+e):``})}function vQ({code:e,lines:t}){let n=_A(e.source),r=new Set(t),i=(0,v.useRef)(null),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(!1),l=()=>{i.current&&o(i.current.scrollWidth>i.current.clientWidth)};return(0,v.useLayoutEffect)(l),(0,v.useEffect)(()=>{let e=new ResizeObserver(l);return e.observe(i.current),document.fonts.ready.then(l),()=>e.disconnect()},[]),(0,j.jsxs)(`div`,{className:`flex min-w-0 flex-col rounded-md border`,"data-testid":`code-pane`,children:[(0,j.jsx)(`div`,{className:`text-muted-foreground border-b px-3 py-1 font-mono text-xs`,"aria-hidden":`true`,children:e.language}),(0,j.jsx)(`div`,{ref:i,role:`region`,"aria-label":`Code, ${e.language}${a?`, scrolls sideways`:``}`,className:`min-w-0 overflow-x-auto py-2`,"data-testid":`code-scroll`,tabIndex:a?0:s?-1:void 0,onFocus:()=>c(!0),onBlur:e=>c(document.activeElement===e.currentTarget),onKeyDown:e=>{a&&(e.key===`ArrowLeft`||e.key===`ArrowRight`)&&e.stopPropagation()},children:(0,j.jsx)(`pre`,{className:`w-max min-w-full font-mono text-xs leading-relaxed [tab-size:4]`,children:(0,j.jsx)(`code`,{children:n.map((e,t)=>{let n=r.has(t+1);return(0,j.jsxs)(`span`,{className:A(`flex border-l-2 pr-3`,n?`bg-muted border-foreground text-foreground`:`border-transparent`),"data-testid":`code-line`,"data-active":n||void 0,"aria-current":n?`true`:void 0,children:[(0,j.jsx)(`span`,{className:`text-muted-foreground w-9 shrink-0 pr-3 text-right select-none`,children:t+1}),(0,j.jsx)(`span`,{className:`whitespace-pre`,children:e||` `}),n&&(0,j.jsx)(`span`,{className:`sr-only`,children:` (current line)`})]},t)})})})})]})}var yQ={active:``,done:`, done`,muted:`, ruled out`};function bQ(e,t){let n=e.values;for(let r of e.steps.slice(0,t+1))r.values&&(n=r.values);let r=e.steps[t];return{values:n,explanation:r?.explanation??``,pointers:r?.pointers??[],ranges:r?.ranges??[],variables:r?.variables??[],lines:r?.lines??[]}}function xQ(e,t){return e.length===t.length?t.flatMap((t,n)=>t===e[n]?[]:[` Index ${n} is now ${String(t)}.`]).join(``):` The sequence is now ${t.map(String).join(`, `)}.`}function SQ({view:e}){let{spec:t}=e,n=lQ(t.steps.length),r=(0,v.useId)(),i=(0,v.useId)(),a=bQ(t,n.index),o=(0,v.useRef)({index:n.index,from:a.values});o.current.index!==n.index&&(o.current={index:n.index,from:bQ(t,o.current.index).values});let s=a.values.length,c=a.ranges.filter(e=>e.start<=e.end&&e.end<s),l=a.pointers.filter(e=>e.index<s),u=t.code?_A(t.code.source):[],d=a.lines.filter(e=>e>=1&&e<=u.length),f=e=>{let t=c.find(t=>t.start<=e&&e<=t.end);return t?t.tone??`active`:void 0},p=(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`p`,{className:`sr-only`,"data-testid":`trace-description`,children:[`Values: `,a.values.map((e,t)=>`index ${t}: ${String(e)}`).join(`, `)]}),(0,j.jsx)(uQ,{label:`Values, scrolls sideways`,className:`pb-1`,children:(0,j.jsxs)(`span`,{"aria-hidden":`true`,className:`inline-grid w-max gap-1 wrap-normal`,style:{gridTemplateColumns:`repeat(${s}, minmax(2.5rem, max-content))`},children:[c.map((e,t)=>(0,j.jsx)(`span`,{className:A(`min-h-5 rounded-sm px-1 text-center text-xs font-medium`,sQ[e.tone??`active`]),style:{gridColumn:`${e.start+1} / ${e.end+2}`,gridRow:t+1},"data-testid":`trace-range`,children:e.label??` `},`range-${t}`)),a.values.map((e,t)=>{let n=f(t);return(0,j.jsxs)(`span`,{className:A(`bg-card border-border-strong relative grid h-11 place-items-center rounded-md border px-2 font-mono text-[0.95rem]`,n&&sQ[n]),style:{gridColumn:t+1,gridRow:c.length+1},"data-testid":`trace-cell`,children:[String(e),(0,j.jsx)(`span`,{className:`text-muted-foreground absolute right-1 bottom-0 text-[0.6rem]`,children:t})]},`cell-${t}`)}),Array.from({length:s},(e,t)=>{let n=l.filter(e=>e.index===t).map(e=>e.name);return n.length?(0,j.jsxs)(`span`,{className:`text-foreground text-center font-mono text-xs font-medium`,style:{gridColumn:t+1,gridRow:c.length+2},"data-testid":`trace-pointer`,children:[`↑ `,n.join(`, `)]},`pointers-${t}`):null})]})}),a.variables.length>0&&(0,j.jsx)(`dl`,{className:`flex flex-wrap gap-2`,"aria-hidden":`true`,children:a.variables.map((e,t)=>(0,j.jsxs)(`div`,{className:`border-border-strong bg-card flex max-w-full min-w-0 gap-1.5 rounded-md border px-2 py-0.5 font-mono text-xs wrap-anywhere`,children:[(0,j.jsx)(`dt`,{className:`min-w-0`,children:e.name}),(0,j.jsxs)(`dd`,{className:`min-w-0`,children:[`= `,String(e.value)]})]},t))}),(0,j.jsxs)(`div`,{"aria-live":`polite`,"aria-atomic":`true`,"data-testid":`trace-status`,children:[(0,j.jsxs)(`span`,{className:`sr-only`,children:[`Step `,n.index+1,` of `,n.last+1,`.`,` `]}),(0,j.jsx)(uQ,{children:(0,j.jsx)(rQ,{text:a.explanation,mode:`math`})}),(0,j.jsxs)(`span`,{className:`sr-only`,children:[xQ(o.current.from,a.values),l.map(e=>` ${e.name} points to index ${e.index}, value ${String(a.values[e.index])}.`),c.map(e=>` ${e.label?`${e.label} covers`:`Highlighted:`} indices ${e.start} through ${e.end}${yQ[e.tone??`active`]}.`),a.variables.map(e=>` ${e.name} = ${String(e.value)}.`),d.map(e=>` Code line ${e}: ${u[e-1].trim()||`blank`}.`)]})]})]});return(0,j.jsxs)(pQ,{role:`region`,"aria-labelledby":`${r} ${i}`,tabIndex:0,onKeyDown:n.onKeyDown,children:[(0,j.jsx)(mQ,{kind:`Algorithm trace`,kindId:i,children:(0,j.jsx)(hQ,{id:r,text:t.title})}),(0,j.jsx)(gQ,{children:t.code?(0,j.jsx)(`div`,{className:`@container`,children:(0,j.jsxs)(`div`,{className:`grid gap-3 @xl:grid-cols-2`,children:[(0,j.jsx)(vQ,{code:t.code,lines:d}),(0,j.jsx)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:p})]})}):p}),(0,j.jsx)(fQ,{stepper:n,play:!0})]})}var CQ=200;function wQ({output:e}){let t=(0,v.useRef)(null),[n,r]=(0,v.useState)({x:!1,y:!1}),[i,a]=(0,v.useState)(!1),o=()=>{let e=t.current;if(!e)return;let n={x:e.scrollWidth>e.clientWidth,y:e.scrollHeight>e.clientHeight};r(e=>e.x===n.x&&e.y===n.y?e:n)};(0,v.useLayoutEffect)(o),(0,v.useEffect)(()=>{let e=new ResizeObserver(o);return e.observe(t.current),document.fonts.ready.then(o),()=>e.disconnect()},[]);let s=n.x||n.y;return(0,j.jsxs)(`div`,{className:`flex min-w-0 flex-col rounded-md border`,"data-testid":`walkthrough-output`,children:[(0,j.jsx)(`div`,{className:`text-muted-foreground border-b px-3 py-1 font-mono text-xs`,children:`Output`}),(0,j.jsx)(`div`,{ref:t,role:`region`,"aria-label":`Output${s?`, scrolls`:``}`,className:`max-h-72 min-w-0 overflow-auto px-3 py-2`,"data-testid":`output-scroll`,tabIndex:s?0:i?-1:void 0,onFocus:()=>a(!0),onBlur:e=>a(document.activeElement===e.currentTarget),onKeyDown:e=>{n.x&&(e.key===`ArrowLeft`||e.key===`ArrowRight`)&&e.stopPropagation()},children:e===``?(0,j.jsx)(`p`,{className:`text-muted-foreground text-xs italic`,children:`No output yet`}):(0,j.jsx)(`pre`,{className:`w-max min-w-full font-mono text-xs leading-relaxed whitespace-pre [tab-size:4]`,"data-testid":`output-text`,children:e})})]})}function TQ({view:e}){let{spec:t}=e,n=lQ(t.steps.length),r=(0,v.useId)(),i=(0,v.useId)(),a=t.steps[n.index],o=_A(t.code.source),s=(a.lines??[]).filter(e=>e>=1&&e<=o.length),c=a.output===``?0:_A(a.output).length;return(0,j.jsxs)(pQ,{role:`region`,"aria-labelledby":`${r} ${i}`,tabIndex:0,onKeyDown:n.onKeyDown,children:[(0,j.jsx)(mQ,{kind:`Illustrated walkthrough`,kindId:i,children:(0,j.jsx)(hQ,{id:r,text:t.title})}),(0,j.jsxs)(gQ,{children:[(0,j.jsx)(`div`,{className:`@container`,children:(0,j.jsxs)(`div`,{className:`grid gap-3 @xl:grid-cols-2`,children:[(0,j.jsx)(vQ,{code:t.code,lines:s}),(0,j.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,j.jsxs)(`section`,{className:`flex min-w-0 flex-col rounded-md border`,"aria-label":`Variables`,"data-testid":`walkthrough-variables`,children:[(0,j.jsx)(`div`,{className:`text-muted-foreground border-b px-3 py-1 font-mono text-xs`,"aria-hidden":`true`,children:`Variables`}),(0,j.jsx)(`div`,{className:`px-3 py-2`,children:a.variables.length===0?(0,j.jsx)(`p`,{className:`text-muted-foreground text-xs italic`,children:`No variables at this step`}):(0,j.jsx)(`dl`,{className:`flex flex-col gap-1 font-mono text-xs`,children:a.variables.map(e=>(0,j.jsxs)(`div`,{className:`flex min-w-0 gap-1.5 wrap-anywhere`,"data-testid":`walkthrough-variable`,children:[(0,j.jsx)(`dt`,{className:`min-w-0`,children:e.name}),(0,j.jsxs)(`dd`,{className:`min-w-0`,children:[`= `,String(e.value)]})]},e.name))})})]}),(0,j.jsx)(wQ,{output:a.output})]})]})}),(0,j.jsxs)(`div`,{"aria-live":`polite`,"aria-atomic":`true`,"data-testid":`walkthrough-status`,className:`flex flex-col gap-1`,children:[(0,j.jsxs)(`span`,{className:`sr-only`,children:[`Step `,n.index+1,` of `,n.last+1,`.`,` `]}),a.label&&(0,j.jsxs)(`span`,{className:`text-muted-foreground font-mono text-xs`,"data-testid":`walkthrough-label`,children:[a.label,(0,j.jsx)(`span`,{className:`sr-only`,children:`.`})]}),(0,j.jsx)(uQ,{children:(0,j.jsx)(rQ,{text:a.explanation,mode:`math`})}),(0,j.jsxs)(`span`,{className:`sr-only`,children:[s.map(e=>` Code line ${e}: ${o[e-1].trim()||`blank`}.`),a.variables.length===0?` No variables.`:a.variables.map(e=>` ${e.name} = ${String(e.value)}.`),a.output===``?` No output yet.`:a.output.length<=CQ?` Output: ${a.output}`:` Output: ${c} ${c===1?`line`:`lines`}, in the output pane.`]})]})]}),(0,j.jsx)(fQ,{stepper:n,play:!0})]})}function EQ(e){let t=+this._x.call(null,e),n=+this._y.call(null,e);return DQ(this.cover(t,n),t,n,e)}function DQ(e,t,n,r){if(isNaN(t)||isNaN(n))return e;var i,a=e._root,o={data:r},s=e._x0,c=e._y0,l=e._x1,u=e._y1,d,f,p,m,h,g,_,v;if(!a)return e._root=o,e;for(;a.length;)if((h=t>=(d=(s+l)/2))?s=d:l=d,(g=n>=(f=(c+u)/2))?c=f:u=f,i=a,!(a=a[_=g<<1|h]))return i[_]=o,e;if(p=+e._x.call(null,a.data),m=+e._y.call(null,a.data),t===p&&n===m)return o.next=a,i?i[_]=o:e._root=o,e;do i=i?i[_]=[,,,,]:e._root=[,,,,],(h=t>=(d=(s+l)/2))?s=d:l=d,(g=n>=(f=(c+u)/2))?c=f:u=f;while((_=g<<1|h)==(v=(m>=f)<<1|p>=d));return i[v]=a,i[_]=o,e}function OQ(e){var t,n,r=e.length,i,a,o=Array(r),s=Array(r),c=1/0,l=1/0,u=-1/0,d=-1/0;for(n=0;n<r;++n)isNaN(i=+this._x.call(null,t=e[n]))||isNaN(a=+this._y.call(null,t))||(o[n]=i,s[n]=a,i<c&&(c=i),i>u&&(u=i),a<l&&(l=a),a>d&&(d=a));if(c>u||l>d)return this;for(this.cover(c,l).cover(u,d),n=0;n<r;++n)DQ(this,o[n],s[n],e[n]);return this}function kQ(e,t){if(isNaN(e=+e)||isNaN(t=+t))return this;var n=this._x0,r=this._y0,i=this._x1,a=this._y1;if(isNaN(n))i=(n=Math.floor(e))+1,a=(r=Math.floor(t))+1;else{for(var o=i-n||1,s=this._root,c,l;n>e||e>=i||r>t||t>=a;)switch(l=(t<r)<<1|e<n,c=[,,,,],c[l]=s,s=c,o*=2,l){case 0:i=n+o,a=r+o;break;case 1:n=i-o,a=r+o;break;case 2:i=n+o,r=a-o;break;case 3:n=i-o,r=a-o}this._root&&this._root.length&&(this._root=s)}return this._x0=n,this._y0=r,this._x1=i,this._y1=a,this}function AQ(){var e=[];return this.visit(function(t){if(!t.length)do e.push(t.data);while(t=t.next)}),e}function jQ(e){return arguments.length?this.cover(+e[0][0],+e[0][1]).cover(+e[1][0],+e[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]}function MQ(e,t,n,r,i){this.node=e,this.x0=t,this.y0=n,this.x1=r,this.y1=i}function NQ(e,t,n){var r,i=this._x0,a=this._y0,o,s,c,l,u=this._x1,d=this._y1,f=[],p=this._root,m,h;for(p&&f.push(new MQ(p,i,a,u,d)),n==null?n=1/0:(i=e-n,a=t-n,u=e+n,d=t+n,n*=n);m=f.pop();)if(!(!(p=m.node)||(o=m.x0)>u||(s=m.y0)>d||(c=m.x1)<i||(l=m.y1)<a)){if(p.length){var g=(o+c)/2,_=(s+l)/2;f.push(new MQ(p[3],g,_,c,l),new MQ(p[2],o,_,g,l),new MQ(p[1],g,s,c,_),new MQ(p[0],o,s,g,_)),(h=(t>=_)<<1|e>=g)&&(m=f[f.length-1],f[f.length-1]=f[f.length-1-h],f[f.length-1-h]=m)}else{var v=e-+this._x.call(null,p.data),y=t-+this._y.call(null,p.data),b=v*v+y*y;if(b<n){var x=Math.sqrt(n=b);i=e-x,a=t-x,u=e+x,d=t+x,r=p.data}}}return r}function PQ(e){if(isNaN(u=+this._x.call(null,e))||isNaN(d=+this._y.call(null,e)))return this;var t,n=this._root,r,i,a,o=this._x0,s=this._y0,c=this._x1,l=this._y1,u,d,f,p,m,h,g,_;if(!n)return this;if(n.length)for(;;){if((m=u>=(f=(o+c)/2))?o=f:c=f,(h=d>=(p=(s+l)/2))?s=p:l=p,t=n,!(n=n[g=h<<1|m]))return this;if(!n.length)break;(t[g+1&3]||t[g+2&3]||t[g+3&3])&&(r=t,_=g)}for(;n.data!==e;)if(i=n,!(n=n.next))return this;return(a=n.next)&&delete n.next,i?(a?i.next=a:delete i.next,this):t?(a?t[g]=a:delete t[g],(n=t[0]||t[1]||t[2]||t[3])&&n===(t[3]||t[2]||t[1]||t[0])&&!n.length&&(r?r[_]=n:this._root=n),this):(this._root=a,this)}function FQ(e){for(var t=0,n=e.length;t<n;++t)this.remove(e[t]);return this}function IQ(){return this._root}function LQ(){var e=0;return this.visit(function(t){if(!t.length)do++e;while(t=t.next)}),e}function RQ(e){var t=[],n,r=this._root,i,a,o,s,c;for(r&&t.push(new MQ(r,this._x0,this._y0,this._x1,this._y1));n=t.pop();)if(!e(r=n.node,a=n.x0,o=n.y0,s=n.x1,c=n.y1)&&r.length){var l=(a+s)/2,u=(o+c)/2;(i=r[3])&&t.push(new MQ(i,l,u,s,c)),(i=r[2])&&t.push(new MQ(i,a,u,l,c)),(i=r[1])&&t.push(new MQ(i,l,o,s,u)),(i=r[0])&&t.push(new MQ(i,a,o,l,u))}return this}function zQ(e){var t=[],n=[],r;for(this._root&&t.push(new MQ(this._root,this._x0,this._y0,this._x1,this._y1));r=t.pop();){var i=r.node;if(i.length){var a,o=r.x0,s=r.y0,c=r.x1,l=r.y1,u=(o+c)/2,d=(s+l)/2;(a=i[0])&&t.push(new MQ(a,o,s,u,d)),(a=i[1])&&t.push(new MQ(a,u,s,c,d)),(a=i[2])&&t.push(new MQ(a,o,d,u,l)),(a=i[3])&&t.push(new MQ(a,u,d,c,l))}n.push(r)}for(;r=n.pop();)e(r.node,r.x0,r.y0,r.x1,r.y1);return this}function BQ(e){return e[0]}function VQ(e){return arguments.length?(this._x=e,this):this._x}function HQ(e){return e[1]}function UQ(e){return arguments.length?(this._y=e,this):this._y}function WQ(e,t,n){var r=new GQ(t??BQ,n??HQ,NaN,NaN,NaN,NaN);return e==null?r:r.addAll(e)}function GQ(e,t,n,r,i,a){this._x=e,this._y=t,this._x0=n,this._y0=r,this._x1=i,this._y1=a,this._root=void 0}function KQ(e){for(var t={data:e.data},n=t;e=e.next;)n=n.next={data:e.data};return t}var qQ=WQ.prototype=GQ.prototype;qQ.copy=function(){var e=new GQ(this._x,this._y,this._x0,this._y0,this._x1,this._y1),t=this._root,n,r;if(!t)return e;if(!t.length)return e._root=KQ(t),e;for(n=[{source:t,target:e._root=[,,,,]}];t=n.pop();)for(var i=0;i<4;++i)(r=t.source[i])&&(r.length?n.push({source:r,target:t.target[i]=[,,,,]}):t.target[i]=KQ(r));return e},qQ.add=EQ,qQ.addAll=OQ,qQ.cover=kQ,qQ.data=AQ,qQ.extent=jQ,qQ.find=NQ,qQ.remove=PQ,qQ.removeAll=FQ,qQ.root=IQ,qQ.size=LQ,qQ.visit=RQ,qQ.visitAfter=zQ,qQ.x=VQ,qQ.y=UQ;function JQ(e){return function(){return e}}function YQ(e){return(e()-.5)*1e-6}function XQ(e){return e.x+e.vx}function ZQ(e){return e.y+e.vy}function QQ(e){var t,n,r,i=1,a=1;typeof e!=`function`&&(e=JQ(e==null?1:+e));function o(){for(var e,o=t.length,c,l,u,d,f,p,m=0;m<a;++m)for(c=WQ(t,XQ,ZQ).visitAfter(s),e=0;e<o;++e)l=t[e],f=n[l.index],p=f*f,u=l.x+l.vx,d=l.y+l.vy,c.visit(h);function h(e,t,n,a,o){var s=e.data,c=e.r,m=f+c;if(s){if(s.index>l.index){var h=u-s.x-s.vx,g=d-s.y-s.vy,_=h*h+g*g;_<m*m&&(h===0&&(h=YQ(r),_+=h*h),g===0&&(g=YQ(r),_+=g*g),_=(m-(_=Math.sqrt(_)))/_*i,l.vx+=(h*=_)*(m=(c*=c)/(p+c)),l.vy+=(g*=_)*m,s.vx-=h*(m=1-m),s.vy-=g*m)}}else return t>u+m||a<u-m||n>d+m||o<d-m}}function s(e){if(e.data)return e.r=n[e.data.index];for(var t=e.r=0;t<4;++t)e[t]&&e[t].r>e.r&&(e.r=e[t].r)}function c(){if(t){var r,i=t.length,a;for(n=Array(i),r=0;r<i;++r)a=t[r],n[a.index]=+e(a,r,t)}}return o.initialize=function(e,n){t=e,r=n,c()},o.iterations=function(e){return arguments.length?(a=+e,o):a},o.strength=function(e){return arguments.length?(i=+e,o):i},o.radius=function(t){return arguments.length?(e=typeof t==`function`?t:JQ(+t),c(),o):e},o}function $Q(e){return e.index}function e$(e,t){var n=e.get(t);if(!n)throw Error(`node not found: `+t);return n}function t$(e){var t=$Q,n=d,r,i=JQ(30),a,o,s,c,l,u=1;e??=[];function d(e){return 1/Math.min(s[e.source.index],s[e.target.index])}function f(t){for(var n=0,i=e.length;n<u;++n)for(var o=0,s,d,f,p,m,h,g;o<i;++o)s=e[o],d=s.source,f=s.target,p=f.x+f.vx-d.x-d.vx||YQ(l),m=f.y+f.vy-d.y-d.vy||YQ(l),h=Math.sqrt(p*p+m*m),h=(h-a[o])/h*t*r[o],p*=h,m*=h,f.vx-=p*(g=c[o]),f.vy-=m*g,d.vx+=p*(g=1-g),d.vy+=m*g}function p(){if(o){var n,i=o.length,l=e.length,u=new Map(o.map((e,n)=>[t(e,n,o),e])),d;for(n=0,s=Array(i);n<l;++n)d=e[n],d.index=n,typeof d.source!=`object`&&(d.source=e$(u,d.source)),typeof d.target!=`object`&&(d.target=e$(u,d.target)),s[d.source.index]=(s[d.source.index]||0)+1,s[d.target.index]=(s[d.target.index]||0)+1;for(n=0,c=Array(l);n<l;++n)d=e[n],c[n]=s[d.source.index]/(s[d.source.index]+s[d.target.index]);r=Array(l),m(),a=Array(l),h()}}function m(){if(o)for(var t=0,i=e.length;t<i;++t)r[t]=+n(e[t],t,e)}function h(){if(o)for(var t=0,n=e.length;t<n;++t)a[t]=+i(e[t],t,e)}return f.initialize=function(e,t){o=e,l=t,p()},f.links=function(t){return arguments.length?(e=t,p(),f):e},f.id=function(e){return arguments.length?(t=e,f):t},f.iterations=function(e){return arguments.length?(u=+e,f):u},f.strength=function(e){return arguments.length?(n=typeof e==`function`?e:JQ(+e),m(),f):n},f.distance=function(e){return arguments.length?(i=typeof e==`function`?e:JQ(+e),h(),f):i},f}var n$={value:()=>{}};function r$(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+``)||r in n||/[\s.]/.test(r))throw Error(`illegal type: `+r);n[r]=[]}return new i$(n)}function i$(e){this._=e}function a$(e,t){return e.trim().split(/^|\s+/).map(function(e){var n=``,r=e.indexOf(`.`);if(r>=0&&(n=e.slice(r+1),e=e.slice(0,r)),e&&!t.hasOwnProperty(e))throw Error(`unknown type: `+e);return{type:e,name:n}})}i$.prototype=r$.prototype={constructor:i$,on:function(e,t){var n=this._,r=a$(e+``,n),i,a=-1,o=r.length;if(arguments.length<2){for(;++a<o;)if((i=(e=r[a]).type)&&(i=o$(n[i],e.name)))return i}else{if(t!=null&&typeof t!=`function`)throw Error(`invalid callback: `+t);for(;++a<o;)if(i=(e=r[a]).type)n[i]=s$(n[i],e.name,t);else if(t==null)for(i in n)n[i]=s$(n[i],e.name,null);return this}},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new i$(e)},call:function(e,t){if((i=arguments.length-2)>0)for(var n=Array(i),r=0,i,a;r<i;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(a=this._[e],r=0,i=a.length;r<i;++r)a[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(var r=this._[e],i=0,a=r.length;i<a;++i)r[i].value.apply(t,n)}};function o$(e,t){for(var n=0,r=e.length,i;n<r;++n)if((i=e[n]).name===t)return i.value}function s$(e,t,n){for(var r=0,i=e.length;r<i;++r)if(e[r].name===t){e[r]=n$,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var c$=0,l$=0,u$=0,d$=1e3,f$,p$,m$=0,h$=0,g$=0,_$=typeof performance==`object`&&performance.now?performance:Date,v$=typeof window==`object`&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function y$(){return h$||=(v$(b$),_$.now()+g$)}function b$(){h$=0}function x$(){this._call=this._time=this._next=null}x$.prototype=S$.prototype={constructor:x$,restart:function(e,t,n){if(typeof e!=`function`)throw TypeError(`callback is not a function`);n=(n==null?y$():+n)+(t==null?0:+t),!this._next&&p$!==this&&(p$?p$._next=this:f$=this,p$=this),this._call=e,this._time=n,D$()},stop:function(){this._call&&(this._call=null,this._time=1/0,D$())}};function S$(e,t,n){var r=new x$;return r.restart(e,t,n),r}function C$(){y$(),++c$;for(var e=f$,t;e;)(t=h$-e._time)>=0&&e._call.call(void 0,t),e=e._next;--c$}function w$(){h$=(m$=_$.now())+g$,c$=l$=0;try{C$()}finally{c$=0,E$(),h$=0}}function T$(){var e=_$.now(),t=e-m$;t>d$&&(g$-=t,m$=e)}function E$(){for(var e,t=f$,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:f$=n);p$=e,D$(r)}function D$(e){c$||(l$&&=clearTimeout(l$),e-h$>24?(e<1/0&&(l$=setTimeout(w$,e-_$.now()-g$)),u$&&=clearInterval(u$)):(u$||=(m$=_$.now(),setInterval(T$,d$)),c$=1,v$(w$)))}var O$=1664525,k$=1013904223,A$=4294967296;function j$(){let e=1;return()=>(e=(O$*e+k$)%A$)/A$}function M$(e){return e.x}function N$(e){return e.y}var P$=10,F$=Math.PI*(3-Math.sqrt(5));function I$(e){var t,n=1,r=.001,i=1-r**(1/300),a=0,o=.6,s=new Map,c=S$(d),l=r$(`tick`,`end`),u=j$();e??=[];function d(){f(),l.call(`tick`,t),n<r&&(c.stop(),l.call(`end`,t))}function f(r){var c,l=e.length,u;r===void 0&&(r=1);for(var d=0;d<r;++d)for(n+=(a-n)*i,s.forEach(function(e){e(n)}),c=0;c<l;++c)u=e[c],u.fx==null?u.x+=u.vx*=o:(u.x=u.fx,u.vx=0),u.fy==null?u.y+=u.vy*=o:(u.y=u.fy,u.vy=0);return t}function p(){for(var t=0,n=e.length,r;t<n;++t){if(r=e[t],r.index=t,r.fx!=null&&(r.x=r.fx),r.fy!=null&&(r.y=r.fy),isNaN(r.x)||isNaN(r.y)){var i=P$*Math.sqrt(.5+t),a=t*F$;r.x=i*Math.cos(a),r.y=i*Math.sin(a)}(isNaN(r.vx)||isNaN(r.vy))&&(r.vx=r.vy=0)}}function m(t){return t.initialize&&t.initialize(e,u),t}return p(),t={tick:f,restart:function(){return c.restart(d),t},stop:function(){return c.stop(),t},nodes:function(n){return arguments.length?(e=n,p(),s.forEach(m),t):e},alpha:function(e){return arguments.length?(n=+e,t):n},alphaMin:function(e){return arguments.length?(r=+e,t):r},alphaDecay:function(e){return arguments.length?(i=+e,t):+i},alphaTarget:function(e){return arguments.length?(a=+e,t):a},velocityDecay:function(e){return arguments.length?(o=1-e,t):1-o},randomSource:function(e){return arguments.length?(u=e,s.forEach(m),t):u},force:function(e,n){return arguments.length>1?(n==null?s.delete(e):s.set(e,m(n)),t):s.get(e)},find:function(t,n,r){var i=0,a=e.length,o,s,c,l,u;for(r==null?r=1/0:r*=r,i=0;i<a;++i)l=e[i],o=t-l.x,s=n-l.y,c=o*o+s*s,c<r&&(u=l,r=c);return u},on:function(e,n){return arguments.length>1?(l.on(e,n),t):l.on(e)}}}function L$(){var e,t,n,r,i=JQ(-30),a,o=1,s=1/0,c=.81;function l(n){var i,a=e.length,o=WQ(e,M$,N$).visitAfter(d);for(r=n,i=0;i<a;++i)t=e[i],o.visit(f)}function u(){if(e){var t,n=e.length,r;for(a=Array(n),t=0;t<n;++t)r=e[t],a[r.index]=+i(r,t,e)}}function d(e){var t=0,n,r,i=0,o,s,c;if(e.length){for(o=s=c=0;c<4;++c)(n=e[c])&&(r=Math.abs(n.value))&&(t+=n.value,i+=r,o+=r*n.x,s+=r*n.y);e.x=o/i,e.y=s/i}else{n=e,n.x=n.data.x,n.y=n.data.y;do t+=a[n.data.index];while(n=n.next)}e.value=t}function f(e,i,l,u){if(!e.value)return!0;var d=e.x-t.x,f=e.y-t.y,p=u-i,m=d*d+f*f;if(p*p/c<m)return m<s&&(d===0&&(d=YQ(n),m+=d*d),f===0&&(f=YQ(n),m+=f*f),m<o&&(m=Math.sqrt(o*m)),t.vx+=d*e.value*r/m,t.vy+=f*e.value*r/m),!0;if(!(e.length||m>=s)){(e.data!==t||e.next)&&(d===0&&(d=YQ(n),m+=d*d),f===0&&(f=YQ(n),m+=f*f),m<o&&(m=Math.sqrt(o*m)));do e.data!==t&&(p=a[e.data.index]*r/m,t.vx+=d*p,t.vy+=f*p);while(e=e.next)}}return l.initialize=function(t,r){e=t,n=r,u()},l.strength=function(e){return arguments.length?(i=typeof e==`function`?e:JQ(+e),u(),l):i},l.distanceMin=function(e){return arguments.length?(o=e*e,l):Math.sqrt(o)},l.distanceMax=function(e){return arguments.length?(s=e*e,l):Math.sqrt(s)},l.theta=function(e){return arguments.length?(c=e*e,l):Math.sqrt(c)},l}function R$(e){var t=JQ(.1),n,r,i;typeof e!=`function`&&(e=JQ(e==null?0:+e));function a(e){for(var t=0,a=n.length,o;t<a;++t)o=n[t],o.vx+=(i[t]-o.x)*r[t]*e}function o(){if(n){var a,o=n.length;for(r=Array(o),i=Array(o),a=0;a<o;++a)r[a]=isNaN(i[a]=+e(n[a],a,n))?0:+t(n[a],a,n)}}return a.initialize=function(e){n=e,o()},a.strength=function(e){return arguments.length?(t=typeof e==`function`?e:JQ(+e),o(),a):t},a.x=function(t){return arguments.length?(e=typeof t==`function`?t:JQ(+t),o(),a):e},a}function z$(e){var t=JQ(.1),n,r,i;typeof e!=`function`&&(e=JQ(e==null?0:+e));function a(e){for(var t=0,a=n.length,o;t<a;++t)o=n[t],o.vy+=(i[t]-o.y)*r[t]*e}function o(){if(n){var a,o=n.length;for(r=Array(o),i=Array(o),a=0;a<o;++a)r[a]=isNaN(i[a]=+e(n[a],a,n))?0:+t(n[a],a,n)}}return a.initialize=function(e){n=e,o()},a.strength=function(e){return arguments.length?(t=typeof e==`function`?e:JQ(+e),o(),a):t},a.y=function(t){return arguments.length?(e=typeof t==`function`?t:JQ(+t),o(),a):e},a}function B$(e){var t=0,n=e.children,r=n&&n.length;if(!r)t=1;else for(;--r>=0;)t+=n[r].value;e.value=t}function V$(){return this.eachAfter(B$)}function H$(e,t){let n=-1;for(let r of this)e.call(t,r,++n,this);return this}function U$(e,t){for(var n=this,r=[n],i,a,o=-1;n=r.pop();)if(e.call(t,n,++o,this),i=n.children)for(a=i.length-1;a>=0;--a)r.push(i[a]);return this}function W$(e,t){for(var n=this,r=[n],i=[],a,o,s,c=-1;n=r.pop();)if(i.push(n),a=n.children)for(o=0,s=a.length;o<s;++o)r.push(a[o]);for(;n=i.pop();)e.call(t,n,++c,this);return this}function G$(e,t){let n=-1;for(let r of this)if(e.call(t,r,++n,this))return r}function K$(e){return this.eachAfter(function(t){for(var n=+e(t.data)||0,r=t.children,i=r&&r.length;--i>=0;)n+=r[i].value;t.value=n})}function q$(e){return this.eachBefore(function(t){t.children&&t.children.sort(e)})}function J$(e){for(var t=this,n=Y$(t,e),r=[t];t!==n;)t=t.parent,r.push(t);for(var i=r.length;e!==n;)r.splice(i,0,e),e=e.parent;return r}function Y$(e,t){if(e===t)return e;var n=e.ancestors(),r=t.ancestors(),i=null;for(e=n.pop(),t=r.pop();e===t;)i=e,e=n.pop(),t=r.pop();return i}function X$(){for(var e=this,t=[e];e=e.parent;)t.push(e);return t}function Z$(){return Array.from(this)}function Q$(){var e=[];return this.eachBefore(function(t){t.children||e.push(t)}),e}function $$(){var e=this,t=[];return e.each(function(n){n!==e&&t.push({source:n.parent,target:n})}),t}function*e1(){var e=this,t,n=[e],r,i,a;do for(t=n.reverse(),n=[];e=t.pop();)if(yield e,r=e.children)for(i=0,a=r.length;i<a;++i)n.push(r[i]);while(n.length)}function t1(e,t){e instanceof Map?(e=[void 0,e],t===void 0&&(t=i1)):t===void 0&&(t=r1);for(var n=new s1(e),r,i=[n],a,o,s,c;r=i.pop();)if((o=t(r.data))&&(c=(o=Array.from(o)).length))for(r.children=o,s=c-1;s>=0;--s)i.push(a=o[s]=new s1(o[s])),a.parent=r,a.depth=r.depth+1;return n.eachBefore(o1)}function n1(){return t1(this).eachBefore(a1)}function r1(e){return e.children}function i1(e){return Array.isArray(e)?e[1]:null}function a1(e){e.data.value!==void 0&&(e.value=e.data.value),e.data=e.data.data}function o1(e){var t=0;do e.height=t;while((e=e.parent)&&e.height<++t)}function s1(e){this.data=e,this.depth=this.height=0,this.parent=null}s1.prototype=t1.prototype={constructor:s1,count:V$,each:H$,eachAfter:W$,eachBefore:U$,find:G$,sum:K$,sort:q$,path:J$,ancestors:X$,descendants:Z$,leaves:Q$,links:$$,copy:n1,[Symbol.iterator]:e1};function c1(e,t){return e.parent===t.parent?1:2}function l1(e){var t=e.children;return t?t[0]:e.t}function u1(e){var t=e.children;return t?t[t.length-1]:e.t}function d1(e,t,n){var r=n/(t.i-e.i);t.c-=r,t.s+=n,e.c+=r,t.z+=n,t.m+=n}function f1(e){for(var t=0,n=0,r=e.children,i=r.length,a;--i>=0;)a=r[i],a.z+=t,a.m+=t,t+=a.s+(n+=a.c)}function p1(e,t,n){return e.a.parent===t.parent?e.a:n}function m1(e,t){this._=e,this.parent=null,this.children=null,this.A=null,this.a=this,this.z=0,this.m=0,this.c=0,this.s=0,this.t=null,this.i=t}m1.prototype=Object.create(s1.prototype);function h1(e){for(var t=new m1(e,0),n,r=[t],i,a,o,s;n=r.pop();)if(a=n._.children)for(n.children=Array(s=a.length),o=s-1;o>=0;--o)r.push(i=n.children[o]=new m1(a[o],o)),i.parent=n;return(t.parent=new m1(null,0)).children=[t],t}function g1(){var e=c1,t=1,n=1,r=null;function i(i){var s=h1(i);if(s.eachAfter(a),s.parent.m=-s.z,s.eachBefore(o),r)i.eachBefore(c);else{var l=i,u=i,d=i;i.eachBefore(function(e){e.x<l.x&&(l=e),e.x>u.x&&(u=e),e.depth>d.depth&&(d=e)});var f=l===u?1:e(l,u)/2,p=f-l.x,m=t/(u.x+f+p),h=n/(d.depth||1);i.eachBefore(function(e){e.x=(e.x+p)*m,e.y=e.depth*h})}return i}function a(t){var n=t.children,r=t.parent.children,i=t.i?r[t.i-1]:null;if(n){f1(t);var a=(n[0].z+n[n.length-1].z)/2;i?(t.z=i.z+e(t._,i._),t.m=t.z-a):t.z=a}else i&&(t.z=i.z+e(t._,i._));t.parent.A=s(t,i,t.parent.A||r[0])}function o(e){e._.x=e.z+e.parent.m,e.m+=e.parent.m}function s(t,n,r){if(n){for(var i=t,a=t,o=n,s=i.parent.children[0],c=i.m,l=a.m,u=o.m,d=s.m,f;o=u1(o),i=l1(i),o&&i;)s=l1(s),a=u1(a),a.a=t,f=o.z+u-i.z-c+e(o._,i._),f>0&&(d1(p1(o,t,r),t,f),c+=f,l+=f),u+=o.m,c+=i.m,d+=s.m,l+=a.m;o&&!u1(a)&&(a.t=o,a.m+=u-l),i&&!l1(s)&&(s.t=i,s.m+=c-d,r=t)}return r}function c(e){e.x*=t,e.y=e.depth*n}return i.separation=function(t){return arguments.length?(e=t,i):e},i.size=function(e){return arguments.length?(r=!1,t=+e[0],n=+e[1],i):r?null:[t,n]},i.nodeSize=function(e){return arguments.length?(r=!0,t=+e[0],n=+e[1],i):r?[t,n]:null},i}var _1=7.8,v1=/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\u3000-\u303F\uFF01-\uFF60]/gu,y1=30,b1=18,x1=72,S1=18,C1=30,w1=1500,T1=15,E1=28,D1=34,O1=30,k1=16,A1=.6,j1=9,M1=4.5,N1=8,P1=18,F1=4,I1=[.5,.4,.6,.3,.7,.22,.78],L1=6,R1=150;function z1(e){let t=e=>e.length*_1+(e.match(v1)?.length??0)*5.2,n=0,r=0;for(let i of e.matchAll(/\$([^$]+)\$/g)){n+=t(e.slice(r,i.index));let a=i[1].replace(/\\(?:text|mathrm|mathbf|mathbb|mathit)\b/g,``).replace(/\\[a-zA-Z]+|\\[^a-zA-Z]/g,`x`).replace(/[_^{}\s]/g,``);n+=Math.min(a.length,12)*13*1.1+4,r=i.index+i[0].length}return n+t(e.slice(r))}var B1=e=>e.weight===void 0?e.label:String(e.weight),V1=e=>(e?z1(e):0)+8;function H1(e,t){let n=Math.max(...[...e.values()].map(e=>e.width)),r=t1(t.root,e=>t.children.get(e));g1().nodeSize([n+S1,x1]).separation(()=>1)(r),r.each(t=>Object.assign(e.get(t.data),{x:t.x,y:t.y}))}function U1(e,t,n){let r=new Map(e.edges.map(e=>[e.to,e.side])),i=Math.max(...[...t.values()].map(e=>e.width)),a=Math.max(0,...e.edges.map(e=>V1(B1(e)))),o=Math.max((i+S1)/2,a+F1),s=new Map,c=(e,i,a)=>{let l=n.children.get(e),u=t.get(e),d;if(l.some(e=>r.get(e))){let t=l.find(e=>r.get(e)===`left`),n=l.find(e=>r.get(e)===`right`),o=t===void 0?a:c(t,i+1,a);s.set(e,o),d=n===void 0?o+1:c(n,i+1,o+1)}else{d=l.reduce((e,t,n)=>c(t,i+1,e+ +(n>0)),a);let t=l[0],n=l.at(-1);s.set(e,t===void 0||n===void 0?a:(s.get(t)+s.get(n))/2),d=Math.max(d,a+1)}return Object.assign(u,{x:s.get(e)*o,y:i*x1}),d};c(n.root,0,0)}var W1=e=>t=>{let n=w1*Math.min(1,T1/e.length);for(let r=0;r<e.length;r++){let i=e[r];for(let a=r+1;a<e.length;a++){let r=e[a],o=r.x-i.x,s=r.y-i.y,c=o*o+s*s||1,l=i.radius+r.radius+E1,u=n*t/c+(c<l*l?(l/Math.sqrt(c)-1)*.25:0);i.vx-=o*u,i.vy-=s*u,r.vx+=o*u,r.vy+=s*u}}};function G1(e,t){let n=e.nodes.map(({id:e})=>({id:e,radius:t.get(e).width/2})),r=new Map;for(let{from:t,to:n}of e.edges)t!==n&&r.set(JSON.stringify([t,n].sort()),{source:t,target:n});let i=new Map(n.map(e=>[e.id,e])),a=[...r.values()].map(({source:e,target:t})=>[i.get(e),i.get(t)]),o=()=>{for(let[e,t]of a){let r=t.x-e.x,i=t.y-e.y,a=r*r+i*i||1;for(let o of n){if(o===e||o===t)continue;let n=Math.max(0,Math.min(1,((o.x-e.x)*r+(o.y-e.y)*i)/a)),s=o.x-e.x-n*r,c=o.y-e.y-n*i,l=Math.hypot(s,c),u=Math.max(0,o.radius+12-l)*.5;if(u===0)continue;let d=l>.001?s/l:-i/(Math.hypot(r,i)||1),f=l>.001?c/l:r/(Math.hypot(r,i)||1);o.vx+=d*u,o.vy+=f*u,e.vx-=d*u*(1-n),e.vy-=f*u*(1-n),t.vx-=d*u*n,t.vy-=f*u*n}}},s=t$([...r.values()]).id(e=>e.id).distance(e=>C1+e.source.radius+e.target.radius);I$(n).stop().alphaDecay(1-.001**(1/R1)).force(`link`,s).force(`repel`,W1(n)).force(`edgeClearance`,o).force(`x`,R$().strength(.05)).force(`y`,z$().strength(.05)).tick(R1);for(let e of n)Object.assign(t.get(e.id),{x:e.x,y:e.y})}function K1(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*i)/(r*r+i*i||1)));return Math.hypot(e.x-t.x-a*r,e.y-t.y-a*i)}function q1(e,t,n){let r=new Map,i=(e,t)=>JSON.stringify([e,t].sort());for(let t of e.edges)r.set(i(t.from,t.to),(r.get(i(t.from,t.to))??0)+1);let a=()=>{let n=1;for(let a of e.edges){let o=t.get(a.from),s=t.get(a.to),c=r.get(i(a.from,a.to));for(let[r,i]of t){if(r===a.from||r===a.to)continue;let t=a.from===a.to?Math.hypot(i.x-o.x,i.y-o.y):K1(i,o,s),l=(a.from===a.to?o.width/2+O1+(c-1)*k1:(c-1)*D1/2)+(e.directed?M1:0);n=Math.max(n,(i.width/2+6.1+l)/Math.max(t,1e-4))}}return n},o=a();if(!n&&o>3){let n=Math.max(80,...[...t.values()].map(e=>e.width))*t.size/Math.PI;e.nodes.forEach(({id:e},r)=>{let i=2*Math.PI*r/t.size-Math.PI/2;Object.assign(t.get(e),{x:Math.cos(i)*n,y:Math.sin(i)*n})}),o=a()}if(o>1)for(let e of t.values())e.x*=o,e.y*=o;if(!n&&o>1){let e=[...t.values()],n=1/0,r=0;for(let t=0;t<36;t++){let i=t*Math.PI/36,a=e.map(e=>e.x*Math.cos(i)-e.y*Math.sin(i)),o=Math.max(...a.map((t,n)=>t+e[n].width/2))-Math.min(...a.map((t,n)=>t-e[n].width/2));o<n-.01&&(n=o,r=i)}for(let t of e){let{x:e,y:n}=t;t.x=e*Math.cos(r)-n*Math.sin(r),t.y=e*Math.sin(r)+n*Math.cos(r)}}}function J1(e,t){let n=e.height/2,r=Math.max(Math.abs(t.x-e.x)-(e.width/2-n),0),i=t.y-e.y;return r*r+i*i<=n*n}function Y1(e,t,n){for(let r=0;r<14;r++){let r=(e+t)/2;n(r)?e=r:t=r}return e}var X1=(e,t,n)=>e+(t-e)*n,Z1=(e,t,n)=>({x:X1(e.x,t.x,n),y:X1(e.y,t.y,n)}),Q1=(e,t,n)=>r=>Z1(Z1(e,t,r),Z1(t,n,r),r),$1=(e,t,n,r)=>i=>Z1(Q1(e,t,n)(i),Q1(t,n,r)(i),i);function e0(e,t,n,r,i){let a=J1(t,e(.5))?.5:Y1(0,.5,n=>J1(t,e(n))),o=J1(n,e(.5))?.5:Y1(1,.5,t=>J1(n,e(t))),s=e(o),c=i?Y1(o,a,t=>Math.hypot(e(t).x-s.x,e(t).y-s.y)<j1):o,l=Array.from({length:r+1},(t,n)=>e(X1(a,c,n/r)));if(!i)return{points:l};let u=e(c),d=Math.hypot(s.x-u.x,s.y-u.y)||1,f={x:(u.y-s.y)/d*M1,y:(s.x-u.x)/d*M1};return{points:l,arrow:[s,{x:u.x+f.x,y:u.y+f.y},{x:u.x-f.x,y:u.y-f.y}]}}function t0(e,t,n){return Y1(0,e.width+e.height,r=>J1(e,{x:e.x+t*r,y:e.y+n*r}))}var n0=(e,t)=>Math.abs(e.x-t.x)<(e.width+t.width)/2&&Math.abs(e.y-t.y)<(e.height+t.height)/2,r0=e=>Math.round(e*100)/100,i0=(e,t)=>e.map(e=>`${r0(e.x+t.x)},${r0(e.y+t.y)}`);function a0(e){let t=new Map(e.nodes.map(e=>[e.id,{x:0,y:0,width:Math.max(y1,z1(e.label??e.id)+b1),height:y1}])),n=e.kind===`tree`?aj(e):void 0;n?e.edges.some(e=>e.side)?U1(e,t,n):H1(t,n):G1(e,t),q1(e,t,!!n);let r=[...t.values()],i={x:r.reduce((e,t)=>e+t.x,0)/r.length,y:r.reduce((e,t)=>e+t.y,0)/r.length},a=new Map(e.nodes.map((e,t)=>[e.id,t])),o=(e,t)=>a.get(e)<=a.get(t)?`${a.get(e)}:${a.get(t)}`:`${a.get(t)}:${a.get(e)}`,s=new Map;for(let{from:t,to:n}of e.edges)s.set(o(t,n),(s.get(o(t,n))??0)+1);let c=new Map,l=e.edges.map(n=>{let r=o(n.from,n.to),l=c.get(r)??0;c.set(r,l+1);let u=t.get(n.from),d=t.get(n.to);if(n.from===n.to){let t=Math.hypot(u.x-i.x,u.y-i.y)>1?Math.atan2(u.y-i.y,u.x-i.x):-Math.PI/2,n=(t0(u,Math.cos(t),Math.sin(t))+O1+l*k1)/(.75*Math.cos(A1)),r=e=>({x:u.x+Math.cos(e)*n,y:u.y+Math.sin(e)*n}),a=$1(u,r(t-A1),r(t+A1),u);return{...e0(a,u,u,24,e.directed),curve:a}}let f=s.get(r),[p,m]=a.get(n.from)<=a.get(n.to)?[u,d]:[d,u],h=Math.hypot(m.x-p.x,m.y-p.y)||1,g=(l-(f-1)/2)*D1*2,_=Z1(u,d,.5),v=Q1(u,{x:_.x+(p.y-m.y)/h*g,y:_.y+(m.x-p.x)/h*g},d);return{...e0(v,u,d,f>1?16:1,e.directed),curve:v}}),u=[...r],d=l.map((t,n)=>{let r=B1(e.edges[n]),i={width:V1(r),height:P1},a=I1.map(e=>({...t.curve(e),...i}));if(!r)return a[0];let o=a.map(e=>u.filter(t=>n0(t,e)).length),s=a[o.indexOf(Math.min(...o))],c=Array.from({length:L1},(e,t)=>t+1).flatMap(e=>{let[t,n]=[e*(i.height+F1),e*(i.width+F1)];return[{...a[0],y:a[0].y-t},{...a[0],y:a[0].y+t},{...a[0],x:a[0].x-n},{...a[0],x:a[0].x+n}]}),l=Math.min(...o)===0||e.edges[n].weight!==void 0?s:c.find(e=>!u.some(t=>n0(t,e)))??s;return u.push(l),l}),f=[...r,...d.filter((t,n)=>B1(e.edges[n]))];for(let e of l)f.push(...e.points.map(e=>({...e,width:0,height:0})));let p=Math.min(...f.map(e=>e.x-e.width/2))-N1,m=Math.min(...f.map(e=>e.y-e.height/2))-N1,h=Math.max(...f.map(e=>e.x+e.width/2))+N1,g=Math.max(...f.map(e=>e.y+e.height/2))+N1,_={x:-p,y:-m};return{mode:n?`tree`:`general`,width:Math.ceil(h-p),height:Math.ceil(g-m),nodes:e.nodes.map(({id:e})=>{let n=t.get(e);return{id:e,x:r0(n.x+_.x),y:r0(n.y+_.y),width:n.width,height:n.height}}),edges:l.map((e,t)=>({path:`M${i0(e.points,_).join(`L`)}`,...e.arrow?{arrow:i0(e.arrow,_).join(` `)}:{},label:{x:r0(d[t].x+_.x),y:r0(d[t].y+_.y),width:d[t].width,height:d[t].height}}))}}var o0=11/13,s0={x:2,y:4},c0=.5,l0=e=>`${e/13}em`,u0={active:`border-foreground border-[3px] bg-muted font-semibold`,done:`border-success border-2 bg-[color-mix(in_oklab,var(--success)_15%,var(--card))]`,muted:`border-muted-foreground/50 bg-muted text-muted-foreground border-dashed`},d0={active:{stroke:`stroke-foreground`,fill:`fill-foreground`,width:3.5},done:{stroke:`stroke-success`,fill:`fill-success`,width:2.5},muted:{stroke:`stroke-muted-foreground/50`,fill:`fill-muted-foreground/50`,width:1.25,dash:`4 4`}},f0={active:`font-semibold`,done:`text-success`,muted:`text-muted-foreground`},p0={active:`active`,done:`done`,muted:`ruled out`};function m0(e,t){let n=e.steps?.[t],r=ij(e),i=new Map;for(let e of n?.nodeStates??[])i.set(e.id,e.tone??`active`);let a=new Map;for(let e of n?.edgeStates??[]){let t=r(e);`index`in t&&a.set(t.index,e.tone??`active`)}return{explanation:n?.explanation??``,nodes:i,edges:a,variables:n?.variables??[]}}function h0({labelKey:e,width:t,height:n,truncated:r,children:i}){return(0,j.jsxs)(`span`,{className:`relative block overflow-hidden`,style:{width:l0(t),height:l0(n)},"data-label-clip":e,"data-truncated":r?`true`:void 0,children:[(0,j.jsx)(`span`,{className:A(`grid size-full items-center`,r?`justify-items-start mask-r-from-[calc(100%-1.4em)] mask-r-to-[calc(100%-0.8em)]`:`justify-items-center`),children:(0,j.jsx)(`span`,{className:`w-max whitespace-nowrap`,"data-label-content":!0,children:i})}),r&&(0,j.jsx)(`span`,{className:`absolute inset-y-0 right-0 grid place-items-center`,"data-testid":`graph-label-cut`,children:`…`})]})}function g0({view:e}){let{spec:t}=e,n=t.steps??[],r=lQ(n.length),i=JSON.stringify([t.directed,t.kind,t.nodes,t.edges]),a=(0,v.useMemo)(()=>a0(t),[i]),o=(0,v.useRef)(null);(0,v.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=a.mode===`tree`?a.nodes.reduce((e,t)=>t.y<e.y?t:e):void 0;e.scrollLeft=t?t.x*e.scrollWidth/a.width-e.clientWidth/2:(e.scrollWidth-e.clientWidth)/2,e.scrollTop=t?0:(e.scrollHeight-e.clientHeight)/2},[a]);let[s,c]=(0,v.useState)(!1);(0,v.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=()=>c(e.scrollWidth>e.clientWidth||e.scrollHeight>e.clientHeight);if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[a]);let l=(0,v.useRef)(null),[u,d]=(0,v.useState)(new Set);(0,v.useLayoutEffect)(()=>{let e=()=>{let e=[...l.current?.querySelectorAll(`[data-label-clip]`)??[]].filter(e=>{let t=e.getBoundingClientRect(),n=e.querySelector(`[data-label-content]`),r=[...n.querySelectorAll(`.katex-html .strut`)].map(e=>e.getBoundingClientRect().height),i=r.length>0?Math.max(...r):n.getBoundingClientRect().height;return n.getBoundingClientRect().width>t.width+c0||i>t.height+c0}).map(e=>e.dataset.labelClip);d(t=>t.size===e.length&&e.every(e=>t.has(e))?t:new Set(e))};e();let t=!0;document.fonts.ready.then(()=>{t&&e()}),document.fonts.addEventListener?.(`loadingdone`,e);let n=typeof ResizeObserver>`u`?void 0:new ResizeObserver(e);return l.current&&n?.observe(l.current),()=>{t=!1,document.fonts.removeEventListener?.(`loadingdone`,e),n?.disconnect()}},[i]);let f=new Map(t.nodes.flatMap((e,t)=>u.has(`n-${e.id}`)?[[e.id,`[${t+1}]`]]:[])),p=e=>{o.current?.contains(e.target)||r.onKeyDown(e)},m=m0(t,r.index),h=n.length>0,g=(e,t)=>`${e/t*100}%`,_=(0,v.useId)(),y=(0,v.useId)();return(0,j.jsxs)(pQ,{role:`region`,"aria-labelledby":`${_} ${y}`,tabIndex:h?0:void 0,onKeyDown:h?p:void 0,children:[(0,j.jsx)(mQ,{kind:t.directed?`Directed graph`:`Graph`,kindId:y,children:(0,j.jsx)(hQ,{id:_,text:t.title})}),(0,j.jsxs)(gQ,{children:[(0,j.jsx)(x0,{spec:t}),(0,j.jsx)(`div`,{ref:o,className:`focus-visible:ring-ring/50 max-h-[36rem] overflow-auto rounded-sm outline-none focus-visible:ring-[3px]`,"data-testid":`graph-scroll`,...s?{tabIndex:0,role:`group`,"aria-label":`Scrollable graph drawing`}:{},children:(0,j.jsxs)(`div`,{ref:l,className:`@container relative mx-auto w-full`,style:{maxWidth:a.width,minWidth:a.width*o0,aspectRatio:`${a.width} / ${a.height}`},"aria-hidden":`true`,"data-testid":`graph-canvas`,"data-layout":a.mode,children:[(0,j.jsx)(`svg`,{viewBox:`0 0 ${a.width} ${a.height}`,className:`absolute inset-0 size-full`,fill:`none`,children:a.edges.map((e,t)=>{let n=m.edges.get(t),r=n?d0[n]:{stroke:`stroke-muted-foreground`,fill:`fill-muted-foreground`,width:1.5,dash:void 0};return(0,j.jsxs)(`g`,{"data-testid":`graph-edge`,"data-tone":n,children:[(0,j.jsx)(`path`,{d:e.path,className:r.stroke,strokeWidth:r.width,strokeDasharray:r.dash,strokeLinecap:`round`}),e.arrow&&(0,j.jsx)(`polygon`,{points:e.arrow,className:r.fill,"data-testid":`graph-arrow`})]},t)})}),(0,j.jsxs)(`div`,{className:`absolute inset-0 font-mono leading-none`,style:{fontSize:`calc(13 * 100cqw / ${a.width})`},children:[t.edges.map((e,t)=>{let n=B1(e),r=a.edges[t].label,i=m.edges.get(t);return n===void 0?null:(0,j.jsx)(`span`,{className:A(`bg-card absolute -translate-x-1/2 -translate-y-1/2 rounded-sm [&_.katex]:text-[1.1em]!`,i&&f0[i]),style:{left:g(r.x,a.width),top:g(r.y,a.height)},"data-testid":`graph-edge-label`,children:(0,j.jsx)(h0,{labelKey:`e-${t}`,width:r.width,height:r.height,truncated:u.has(`e-${t}`),children:e.weight===void 0?(0,j.jsx)(rQ,{text:n,mode:`math`}):n})},t)}),a.nodes.map((e,n)=>{let r=m.nodes.get(e.id);return(0,j.jsxs)(`div`,{className:A(`absolute grid -translate-x-1/2 -translate-y-1/2 place-items-center rounded-full border`,r?u0[r]:`border-muted-foreground bg-card`),style:{left:g(e.x,a.width),top:g(e.y,a.height),width:g(e.width,a.width),height:g(e.height,a.height)},"data-testid":`graph-node`,"data-node":e.id,"data-tone":r,children:[(0,j.jsx)(h0,{labelKey:`n-${e.id}`,width:e.width-s0.x,height:e.height-s0.y,truncated:u.has(`n-${e.id}`),children:(0,j.jsx)(`span`,{className:f.has(e.id)?`invisible`:void 0,children:(0,j.jsx)(rQ,{text:t.nodes[n].label??e.id,mode:`math`})})}),f.has(e.id)&&(0,j.jsx)(`span`,{className:`bg-card absolute rounded-sm px-1`,"data-node-key":f.get(e.id),children:f.get(e.id)}),r===`done`&&(0,j.jsx)(`span`,{className:`bg-success text-card absolute -top-[0.35em] -right-[0.35em] grid size-[1.05em] place-items-center rounded-full`,children:(0,j.jsx)(qm,{className:`size-[0.8em]`,strokeWidth:3.5})})]},e.id)})]})]})}),(0,j.jsx)(_0,{spec:t,truncated:u,nodeKeys:f}),m.variables.length>0&&(0,j.jsx)(`dl`,{className:`flex flex-wrap gap-2`,"aria-hidden":h?!0:void 0,children:m.variables.map((e,t)=>(0,j.jsxs)(`div`,{className:`border-border-strong bg-card flex max-w-full min-w-0 gap-1.5 rounded-md border px-2 py-0.5 font-mono text-xs wrap-anywhere`,children:[(0,j.jsx)(`dt`,{className:`min-w-0`,children:e.name}),(0,j.jsxs)(`dd`,{className:`min-w-0`,children:[`= `,String(e.value)]})]},t))}),h&&(0,j.jsx)(j.Fragment,{children:(0,j.jsx)(b0,{spec:t,state:m,step:r.index+1,of:n.length})})]}),h&&(0,j.jsx)(fQ,{stepper:r,play:!0})]})}function _0({spec:e,truncated:t,nodeKeys:n}){if(t.size===0)return null;let r=e.directed?`→`:`–`;return(0,j.jsxs)(`div`,{className:`flex flex-col gap-1 text-xs`,"data-testid":`graph-overflow`,children:[(0,j.jsx)(`p`,{"aria-hidden":`true`,className:`text-muted-foreground`,children:`… Cut short in the drawing:`}),e.nodes.map(r=>t.has(`n-${r.id}`)?(0,j.jsxs)(dQ,{children:[(0,j.jsxs)(`span`,{className:`font-medium`,children:[`Node `,n.get(r.id),`:`]}),` `,(0,j.jsx)(v0,{spec:e,id:r.id})]},r.id):null),e.edges.map((i,a)=>t.has(`e-${a}`)?(0,j.jsxs)(dQ,{children:[(0,j.jsxs)(`span`,{className:`font-medium`,children:[`Edge `,n.get(i.from)??(0,j.jsx)(v0,{spec:e,id:i.from}),` `,r,` `,n.get(i.to)??(0,j.jsx)(v0,{spec:e,id:i.to}),`:`]}),` `,i.weight===void 0?(0,j.jsx)(rQ,{text:i.label,mode:`math`}):i.weight]},a):null)]})}function v0({spec:e,id:t}){return(0,j.jsx)(rQ,{text:e.nodes.find(e=>e.id===t)?.label??t,mode:`math`})}function y0({spec:e,index:t}){let n=e.edges[t];return(0,j.jsxs)(j.Fragment,{children:[n.from===n.to?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(v0,{spec:e,id:n.from}),` to itself`]}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(v0,{spec:e,id:n.from}),` `,e.directed?`to`:`and`,` `,(0,j.jsx)(v0,{spec:e,id:n.to})]}),n.side&&`, ${n.side} child`,n.weight!==void 0&&`, weight ${n.weight}`,n.label!==void 0&&(0,j.jsxs)(j.Fragment,{children:[`, labelled `,(0,j.jsx)(rQ,{text:n.label,mode:`math`})]})]})}function b0({spec:e,state:t,step:n,of:r}){return(0,j.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"aria-atomic":`true`,"data-testid":`graph-status`,children:[(0,j.jsxs)(`p`,{className:`sr-only`,children:[`Step `,n,` of `,r,`.`]}),(0,j.jsx)(`div`,{"data-testid":`graph-explanation`,children:(0,j.jsx)(uQ,{children:(0,j.jsx)(rQ,{text:t.explanation,mode:`math`})})}),(0,j.jsxs)(`ul`,{className:`sr-only`,children:[[...t.nodes].map(([t,n])=>(0,j.jsxs)(`li`,{children:[`Node `,(0,j.jsx)(v0,{spec:e,id:t}),` is `,p0[n],`.`]},`n-${t}`)),[...t.edges].map(([t,n])=>(0,j.jsxs)(`li`,{children:[`Edge `,(0,j.jsx)(y0,{spec:e,index:t}),` is `,p0[n],`.`]},`e-${t}`)),t.variables.map((e,t)=>(0,j.jsxs)(`li`,{children:[e.name,` = `,String(e.value),`.`]},`v-${t}`))]})]})}function x0({spec:e}){let t=e.nodes.length,n=e.edges.length;return(0,j.jsxs)(`ul`,{className:`sr-only`,"data-testid":`graph-description`,children:[(0,j.jsxs)(`li`,{children:[e.directed?`Directed`:`Undirected`,` graph with `,t,` `,t===1?`node`:`nodes`,` and `,n,` `,n===1?`edge`:`edges`,`.`]}),(0,j.jsxs)(`li`,{children:[`Nodes:`,` `,e.nodes.map((t,n)=>(0,j.jsxs)(`span`,{children:[n>0&&`, `,(0,j.jsx)(v0,{spec:e,id:t.id})]},t.id))]}),e.edges.map((t,n)=>(0,j.jsxs)(`li`,{children:[`Edge: `,(0,j.jsx)(y0,{spec:e,index:n})]},`e-${n}`))]})}function S0({className:e,...t}){return(0,j.jsx)(`textarea`,{"data-slot":`textarea`,className:A(`flex field-sizing-content min-h-16 w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:aria-invalid:ring-destructive/40`,e),...t})}function C0({view:e,replyInProgress:t,onUpdate:n,onRefresh:r}){let{spec:i,latestAttempt:a}=e,[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(),f=(0,v.useId)(),p=a!==void 0,m=p||t||c,h=a?.grade.result===`answered`&&`text`in a.answer?a.answer.text:void 0,g=async t=>{if(m)return;l(!0),d(void 0);let i=await KM(e.id,t);if(i.ok)return l(!1),n(i.view);d(i.error);try{await r()}catch{}finally{l(!1)}},_=o.trim();return(0,j.jsxs)(pQ,{role:`region`,"aria-label":`Anything else to add`,children:[(0,j.jsx)(mQ,{kind:`Placement`,aside:`Optional`}),(0,j.jsxs)(gQ,{className:`gap-4`,children:[(0,j.jsx)(`label`,{htmlFor:f,className:`font-heading text-[1.2rem] leading-snug font-medium text-pretty`,children:(0,j.jsx)(rQ,{text:i.question,mode:`math`})}),p?h===void 0?(0,j.jsx)(`p`,{className:`text-muted-foreground text-sm font-medium`,children:`Skipped.`}):(0,j.jsx)(`p`,{className:`bg-sunken rounded-md px-3 py-2 text-sm whitespace-pre-wrap wrap-anywhere`,children:h}):(0,j.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),_&&g({text:_})},children:[(0,j.jsx)(S0,{id:f,value:o,maxLength:PA,rows:3,placeholder:`For example: I know the basics, but I want to go deep on one part of it.`,"aria-describedby":`${f}-help`,disabled:m,onChange:e=>s(e.target.value)}),(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,j.jsx)(M,{type:`submit`,size:`sm`,disabled:m||!_,children:`Send`}),(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`sm`,className:`text-muted-foreground`,disabled:m,onClick:()=>void g({skipped:!0}),children:`Skip`}),(0,j.jsxs)(`span`,{id:`${f}-help`,className:`text-muted-foreground ml-auto text-xs`,children:[`Fine to leave blank · `,o.length,`/`,PA]})]})]}),(0,j.jsxs)(`div`,{"aria-live":`polite`,className:`flex flex-col gap-1 text-sm`,children:[!p&&t&&(0,j.jsx)(`p`,{className:`text-muted-foreground`,children:`Answer once the reply finishes.`}),u&&(0,j.jsx)(`p`,{className:`text-destructive`,children:u})]})]})]})}var w0=ce(`relative grid w-full grid-cols-[0_1fr] items-start gap-y-0.5 rounded-lg border px-4 py-3 text-sm has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] has-[>svg]:gap-x-3 [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current`,{variants:{variant:{default:`bg-card text-card-foreground`,destructive:`bg-card text-destructive *:data-[slot=alert-description]:text-destructive/90 [&>svg]:text-current`}},defaultVariants:{variant:`default`}});function T0({className:e,variant:t,...n}){return(0,j.jsx)(`div`,{"data-slot":`alert`,role:`alert`,className:A(w0({variant:t}),e),...n})}function E0({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`alert-title`,className:A(`col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight`,e),...t})}function D0({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`alert-description`,className:A(`col-start-2 grid justify-items-start gap-1 text-sm text-muted-foreground [&_p]:leading-relaxed`,e),...t})}function O0({view:e,replyInProgress:t,onUpdate:n,onRefresh:r}){let{spec:i,latestAttempt:a}=e,[o,s]=(0,v.useState)(),[c,l]=(0,v.useState)(),u=a!==void 0,d=u||t||o!==void 0,f=a?.answer.optionIndex,p=a?.grade,m=async t=>{if(d)return;s(t),l(void 0);let i=await WM(e.id,t);if(i.ok)return s(void 0),n(i.view);l(i.error);try{await r()}catch{}finally{s(void 0)}},h=e=>{if(p)return e===p.correctOptionIndex?`correct`:e===f?`incorrect`:void 0},g=e=>p?e===f?p.correct?`✓ Your answer, correct`:`✗ Your answer, incorrect`:e===p.correctOptionIndex?`✓ Correct answer`:null:null;return(0,j.jsxs)(pQ,{role:`region`,"aria-label":`Check: ${i.concept}`,children:[(0,j.jsx)(mQ,{kind:`Check`,aside:`Graded against an answer key`,children:(0,j.jsx)(`span`,{className:`text-muted-foreground min-w-0 text-sm font-semibold wrap-anywhere`,children:i.concept})}),(0,j.jsxs)(gQ,{className:`gap-4`,children:[(0,j.jsx)(`div`,{"data-slot":`check-question`,className:`font-heading text-[1.2rem] leading-snug font-medium text-pretty`,children:(0,j.jsx)(rQ,{text:i.question,mode:`math`})}),(0,j.jsx)(`div`,{className:`flex flex-col gap-2`,role:`group`,"aria-label":`Options`,children:i.options.map((e,t)=>{let n=h(t);return(0,j.jsxs)(M,{type:`button`,variant:`outline`,"data-result":n,className:A(`border-border-strong dark:border-border-strong bg-card dark:bg-card hover:bg-sunken dark:hover:bg-sunken h-auto flex-wrap justify-start gap-x-3 gap-y-1 rounded-[10px] px-3.5 py-2.5 text-left font-medium whitespace-normal`,u&&`disabled:opacity-100`,o===t&&`border-foreground dark:border-foreground`,n===`correct`&&`border-success bg-success/10 dark:border-success dark:bg-success/15`,n===`incorrect`&&`border-destructive bg-destructive/10 dark:border-destructive dark:bg-destructive/15`),disabled:d,onClick:()=>void m(t),children:[(0,j.jsx)(_Q,{index:t}),(0,j.jsx)(`span`,{className:`min-w-0 flex-[1_1_10rem] wrap-anywhere`,children:(0,j.jsx)(rQ,{text:e.text,mode:`math`})}),g(t)&&(0,j.jsx)(`span`,{className:A(`shrink-0 pl-9 text-sm font-semibold sm:pl-0`,n===`incorrect`?`text-destructive`:`text-success`),children:g(t)})]},t)})}),(0,j.jsxs)(`div`,{"aria-live":`polite`,className:`flex flex-col gap-2`,children:[!u&&t&&(0,j.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Answer once the reply finishes.`}),c&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,children:c}),p&&(0,j.jsxs)(T0,{className:`bg-sunken border-0 px-4 py-3`,children:[(0,j.jsx)(E0,{className:A(`font-heading text-[1.15rem] font-medium`,p.correct?`text-success`:`text-destructive`),children:p.correct?`Correct!`:`Not quite.`}),(0,j.jsxs)(D0,{className:`text-foreground`,children:[p.feedback&&(0,j.jsx)(`p`,{children:(0,j.jsx)(rQ,{text:p.feedback,mode:`math`})}),(0,j.jsx)(`p`,{children:(0,j.jsx)(rQ,{text:p.explanation,mode:`math`})})]})]})]})]})]})}var k0=e=>e===`unsure`?{unsure:!0}:e===`skipped`?{skipped:!0}:{optionIndex:e};function A0({view:e,replyInProgress:t,onUpdate:n,onRefresh:r}){let{spec:i,latestAttempt:a}=e,[o,s]=(0,v.useState)(),[c,l]=(0,v.useState)(),u=a!==void 0,d=u||t||o!==void 0,f=a?.grade,p=a?.answer,m=p&&`optionIndex`in p?p.optionIndex:void 0,h=async t=>{if(d)return;s(t),l(void 0);let i=await GM(e.id,k0(t));if(i.ok)return s(void 0),n(i.view);l(i.error);try{await r()}catch{}finally{s(void 0)}},g=e=>{if(f)return e===f.correctOptionIndex?`correct`:e===m?`incorrect`:void 0},_=f?.result===`correct`?`Correct.`:f?.result===`incorrect`?`Not quite.`:f?.result===`unsure`?`Marked as not sure.`:`Skipped.`;return(0,j.jsxs)(pQ,{role:`region`,"aria-label":`Placement question: ${i.concept}`,children:[(0,j.jsx)(mQ,{kind:`Placement`,children:(0,j.jsx)(`span`,{className:`text-muted-foreground min-w-0 text-sm font-semibold wrap-anywhere`,children:i.concept})}),(0,j.jsxs)(gQ,{className:`gap-4`,children:[(0,j.jsx)(`div`,{className:`font-heading text-[1.2rem] leading-snug font-medium text-pretty`,children:(0,j.jsx)(rQ,{text:i.question,mode:`math`})}),(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-2`,role:`group`,"aria-label":`Answers`,children:[i.options.map((e,t)=>{let n=g(t);return(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,"data-result":n,"aria-pressed":m===t,className:A(`border-border-strong dark:border-border-strong bg-card dark:bg-card hover:bg-sunken dark:hover:bg-sunken h-auto max-w-full rounded-[10px] px-3.5 py-2 text-left font-medium whitespace-normal wrap-anywhere`,u&&`disabled:opacity-100`,o===t&&`border-foreground dark:border-foreground`,n===`correct`&&`border-success bg-success/10 dark:border-success dark:bg-success/15`,n===`incorrect`&&`border-destructive bg-destructive/10 dark:border-destructive dark:bg-destructive/15`),disabled:d,onClick:()=>void h(t),children:(0,j.jsx)(rQ,{text:e.text,mode:`math`})},t)}),(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`sm`,"aria-pressed":f?.result===`unsure`,className:A(u&&`disabled:opacity-100`,f?.result===`unsure`&&`bg-muted`),disabled:d,onClick:()=>void h(`unsure`),children:`Not sure`}),(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`sm`,"aria-pressed":f?.result===`skipped`,className:A(`text-muted-foreground`,u&&`disabled:opacity-100`,f?.result===`skipped`&&`bg-muted`),disabled:d,onClick:()=>void h(`skipped`),children:`Skip`})]}),(0,j.jsxs)(`div`,{"aria-live":`polite`,className:`flex flex-col gap-1 text-sm`,children:[!u&&t&&(0,j.jsx)(`p`,{className:`text-muted-foreground`,children:`Answer once the reply finishes.`}),c&&(0,j.jsx)(`p`,{className:`text-destructive`,children:c}),f&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`p`,{className:A(`font-medium`,f.result===`correct`?`text-success`:f.result===`incorrect`?`text-destructive`:`text-muted-foreground`),children:_}),f.result!==`skipped`&&(0,j.jsx)(`p`,{className:`text-muted-foreground`,children:(0,j.jsx)(rQ,{text:f.explanation,mode:`math`})})]})]})]})]})}var j0=380,M0=100,N0={1:{width:j0,height:320,radius:M0,circles:[{x:190,y:148}],slots:{1:{x:190,y:148,width:136,rows:5},0:{x:318,y:278,width:106,rows:3}}},2:{width:j0,height:320,radius:M0,circles:[{x:135,y:148},{x:245,y:148}],slots:{1:{x:104,y:148,width:76,rows:5},2:{x:276,y:148,width:76,rows:5},3:{x:190,y:148,width:53,rows:3},0:{x:318,y:288,width:106,rows:2}}},3:{width:j0,height:410,radius:M0,circles:[{x:138,y:148},{x:242,y:148},{x:190,y:238}],slots:{1:{x:100,y:116,width:76,rows:2},2:{x:280,y:116,width:76,rows:2},4:{x:190,y:280,width:124,rows:2},3:{x:190,y:116,width:64,rows:1},5:{x:124,y:220,width:53,rows:1},6:{x:256,y:220,width:53,rows:1},7:{x:190,y:172,width:53,rows:2},0:{x:318,y:366,width:106,rows:3}}}},P0=16/(230/j0);function F0(e,t,n){let r=n/e.width;return{width:t.width*r,height:t.rows*P0*r}}var I0=.5,L0=(e,t)=>e.width<=t.width+I0&&e.height<=t.height+I0;function R0(e,t,n){return L0(t,e)?`contents`:L0(n,e)?`marker`:`arrow`}function z0(e){return Array.from({length:2**e},(e,t)=>t)}function B0({circles:e,radius:t},n){let r=[];return e.forEach((i,a)=>{let o=e=>({x:i.x+t*Math.cos(e),y:i.y+t*Math.sin(e)}),s=e.flatMap((e,n)=>{if(n===a)return[];let r=Math.atan2(e.y-i.y,e.x-i.x),o=Math.acos(Math.hypot(e.x-i.x,e.y-i.y)/(2*t));return[r-o,r+o]}),c=(s.length?s:[0,Math.PI]).map(e=>(e+2*Math.PI)%(2*Math.PI)).sort((e,t)=>e-t);c.forEach((i,s)=>{let l=s+1<c.length?c[s+1]:c[0]+2*Math.PI,u=o((i+l)/2);if(!e.every((e,r)=>r===a||Math.hypot(u.x-e.x,u.y-e.y)<t==!!(n&1<<r)))return;let d=l-i>Math.PI;r.push(n&1<<a?{from:o(i),to:o(l),large:d,sweep:1}:{from:o(l),to:o(i),large:d,sweep:0})})}),r}var V0=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y)<1e-6,H0=e=>String(Math.round(e*100)/100);function U0(e,t){let{radius:n,width:r,height:i}=e,a=B0(e,t),o=[];for(;a.length;){let e=a.shift(),t=`M${H0(e.from.x)} ${H0(e.from.y)}`,r=e;for(;r;){let{to:e,large:i,sweep:o}=r;t+=`A${n} ${n} 0 ${+!!i} ${o} ${H0(e.x)} ${H0(e.y)}`;let s=a.findIndex(t=>V0(t.from,e));r=s>=0?a.splice(s,1)[0]:void 0}o.push(`${t}Z`)}return t===0&&o.unshift(W0(r,i)),o.join(``)}var W0=(e,t)=>`M1 1H${e-1}V${t-1}H1Z`,G0={active:{word:`Focus`,tint:`fill-foreground/15`,pattern:`hatch`,line:`stroke-foreground`,outline:``},done:{word:`Done`,tint:`fill-success/20`,pattern:`dots`,line:`stroke-success`,outline:``},muted:{word:`Ruled out`,tint:`fill-muted-foreground/15`,pattern:``,line:`stroke-muted-foreground`,outline:`5 4`}};function K0(e,t){return e.sets.reduce((e,n,r)=>t.includes(n.id)?e|1<<r:e,0)}function q0(e,t){let n=e.steps?.[t],r=new Map;for(let t of n?.highlights??[])r.set(K0(e,t.in),t.tone??`active`);return{explanation:n?.explanation??``,tones:r,variables:n?.variables??[]}}function J0(e){return z0(e.sets.length).filter(t=>t!==0||e.universe!==void 0).sort((e,t)=>e===0?1:t===0?-1:e-t)}var Y0=e=>String(e);function X0({text:e}){return(0,j.jsx)(rQ,{text:e,mode:`math`})}function Z0({elements:e}){return e.map((e,t)=>(0,j.jsxs)(v.Fragment,{children:[t>0&&`, `,(0,j.jsx)(X0,{text:Y0(e)})]},t))}function Q0(e,t){return e.map((n,r)=>(0,j.jsxs)(v.Fragment,{children:[r>0&&(r===e.length-1?` ${t} `:`, `),n]},r))}function $0({spec:e,mask:t}){let n=e=>(0,j.jsx)(X0,{text:e.label},e.id),r=e.sets.filter((e,n)=>t&1<<n).map(n),i=e.sets.filter((e,n)=>!(t&1<<n)).map(n);return r.length===0?(0,j.jsxs)(j.Fragment,{children:[`outside `,Q0(i,`and`)]}):(0,j.jsxs)(j.Fragment,{children:[`in `,Q0(r,`and`),i.length>0&&(0,j.jsxs)(j.Fragment,{children:[`, not `,Q0(i,`or`)]})]})}var e2=e=>e.count??e.elements.length;function t2({total:e}){return(0,j.jsxs)(`span`,{className:`whitespace-nowrap`,children:[`n = `,e]})}function n2({region:e}){let t=e2(e);return e.elements.length===0?(0,j.jsx)(t2,{total:t}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(Z0,{elements:e.elements}),t!==e.elements.length&&(0,j.jsxs)(j.Fragment,{children:[` `,`(`,(0,j.jsx)(t2,{total:t}),`)`]})]})}function r2({slot:e,layout:t,children:n,...r}){let i=(e,t)=>`${e/t*100}%`;return(0,j.jsx)(`div`,{className:`absolute flex -translate-x-1/2 -translate-y-1/2 items-center justify-center text-center font-mono text-xs leading-4`,style:{left:i(e.x,t.width),top:i(e.y,t.height),width:i(e.width,t.width),height:i(e.rows*P0,t.height)},...r,children:(0,j.jsx)(`span`,{className:`bg-card/85 rounded-sm px-0.5`,children:n})})}function i2(e){let{width:t,height:n}=e.getBoundingClientRect();return{width:t+[...e.querySelectorAll(`.katex`)].reduce((e,t)=>e+Math.max(0,t.scrollWidth-t.clientWidth),0),height:n}}function a2(e){return[e,...e.querySelectorAll(`.katex`)].some(e=>e.scrollWidth>e.clientWidth)}function o2(e,t){let n=(0,v.useRef)(null),[r,i]=(0,v.useState)(new Map),[a,o]=(0,v.useState)([]);return(0,v.useLayoutEffect)(()=>{let r=n.current,a=0,s=()=>{if(a=r.getBoundingClientRect().width,a===0)return;let n=new Map;for(let i of J0(e)){let e=r.querySelector(`[data-probe="contents"][data-mask="${i}"] > span`),o=r.querySelector(`[data-probe="marker"][data-mask="${i}"] > span`);e&&o&&n.set(i,R0(F0(t,t.slots[i],a),i2(e),i2(o)))}i(e=>n.size===e.size&&[...n].every(([t,n])=>e.get(t)===n)?e:n);let s=[...r.querySelectorAll(`[data-label]`)].filter(a2).map(e=>e.dataset.label);o(e=>e.join()===s.join()?e:s)};s();let c=typeof ResizeObserver>`u`?void 0:new ResizeObserver(()=>{r.getBoundingClientRect().width!==a&&(0,It.flushSync)(s)});return c?.observe(r),document.fonts?.addEventListener(`loadingdone`,s),()=>{c?.disconnect(),document.fonts?.removeEventListener(`loadingdone`,s)}},[e,t]),[n,r,a]}var s2=[`Top left`,`Top right`,`Bottom left`];function c2(e,t){return e===0?{left:`2%`,top:`1.5%`,width:`45%`}:e===1?{right:`2%`,top:`1.5%`,width:`45%`,textAlign:`right`}:{left:`2%`,bottom:`1.5%`,width:t===3?`30%`:`45%`}}function l2({d:e,mask:t,tone:n,ids:r}){let i=n&&G0[n],a=`${r.clip}-${t}`;return(0,j.jsxs)(`g`,{"data-testid":`set-region`,"data-mask":t,"data-tone":n??`none`,children:[(0,j.jsx)(`path`,{d:e,fillRule:`evenodd`,className:i?i.tint:`fill-transparent`,"data-testid":`set-region-shape`}),i&&(0,j.jsxs)(j.Fragment,{children:[i.pattern&&(0,j.jsx)(`path`,{d:e,fillRule:`evenodd`,fill:`url(#${i.pattern===`hatch`?r.hatch:r.dots})`}),(0,j.jsx)(`clipPath`,{id:a,children:(0,j.jsx)(`path`,{d:e,clipRule:`evenodd`})}),(0,j.jsx)(`path`,{d:e,clipPath:`url(#${a})`,fill:`none`,strokeWidth:6,strokeDasharray:i.outline||void 0,className:i.line})]})]})}function u2({spec:e,layout:t,tones:n,fits:r,drawing:i}){let a=(0,v.useId)().replace(/[^a-zA-Z0-9_-]/g,``),o={hatch:`${a}-hatch`,dots:`${a}-dots`,clip:`${a}-clip`},{width:s,height:c,radius:l,circles:u,slots:d}=t,f=J0(e),p=new Map(e.regions.map(t=>[K0(e,t.in),t]));return(0,j.jsxs)(`div`,{ref:i,className:`relative mx-auto w-full max-w-md`,style:{aspectRatio:`${s} / ${c}`},"aria-hidden":`true`,inert:!0,"data-testid":`set-diagram`,children:[(0,j.jsxs)(`svg`,{viewBox:`0 0 ${s} ${c}`,className:`absolute inset-0 size-full`,children:[(0,j.jsxs)(`defs`,{children:[(0,j.jsx)(`pattern`,{id:o.hatch,patternUnits:`userSpaceOnUse`,width:`10`,height:`10`,patternTransform:`rotate(45)`,children:(0,j.jsx)(`line`,{x1:`0`,y1:`0`,x2:`0`,y2:`10`,strokeWidth:`2`,className:`stroke-foreground/45`})}),(0,j.jsx)(`pattern`,{id:o.dots,patternUnits:`userSpaceOnUse`,width:`10`,height:`10`,children:(0,j.jsx)(`circle`,{cx:`5`,cy:`5`,r:`1.6`,className:`fill-success/70`})})]}),f.map(e=>(0,j.jsx)(l2,{d:U0(t,e),mask:e,tone:n.get(e),ids:o},e)),e.universe!==void 0&&(0,j.jsx)(`rect`,{x:1,y:1,width:s-2,height:c-2,strokeWidth:`1.5`,className:`stroke-muted-foreground fill-none`,"data-testid":`set-universe`}),u.map((e,t)=>(0,j.jsx)(`circle`,{cx:e.x,cy:e.y,r:l,strokeWidth:`1.5`,className:`stroke-foreground/70 fill-none`,"data-testid":`set-circle`},t))]}),e.sets.map((t,n)=>(0,j.jsx)(`div`,{className:`absolute text-xs leading-4 font-medium`,style:c2(n,e.sets.length),"data-testid":`set-label`,"data-label":n,children:(0,j.jsx)(`span`,{className:`bg-card/85 rounded-sm px-0.5`,children:(0,j.jsx)(X0,{text:t.label})})},t.id)),e.universe!==void 0&&(0,j.jsx)(`div`,{className:`text-muted-foreground absolute bottom-[1.5%] left-1/2 w-[36%] -translate-x-1/2 text-center text-xs leading-4`,"data-testid":`set-universe-label`,"data-label":`universe`,children:(0,j.jsx)(`span`,{className:`bg-card/85 rounded-sm px-0.5`,children:(0,j.jsx)(X0,{text:e.universe})})}),f.map(e=>{let n=p.get(e);if(!n)return null;let i=r.get(e)??`contents`;return(0,j.jsx)(r2,{slot:d[e],layout:t,"data-testid":`set-elements`,"data-mask":e,"data-fit":i,children:e2(n)===0?`∅`:i===`contents`?(0,j.jsx)(n2,{region:n}):i===`marker`?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(t2,{total:e2(n)}),` ↓`]}):`↓`},e)}),(0,j.jsx)(`div`,{className:`invisible absolute inset-0 overflow-hidden`,children:f.map(e=>{let n=p.get(e);return!n||e2(n)===0?null:(0,j.jsxs)(v.Fragment,{children:[(0,j.jsx)(r2,{slot:d[e],layout:t,"data-probe":`contents`,"data-mask":e,children:(0,j.jsx)(n2,{region:n})}),(0,j.jsxs)(r2,{slot:d[e],layout:t,"data-probe":`marker`,"data-mask":e,children:[(0,j.jsx)(t2,{total:e2(n)}),` ↓`]})]},e)})})]})}function d2({view:e}){let{spec:t}=e,n=t.steps?.length??0,r=lQ(n),{index:i}=r,a=(0,v.useId)(),o=(0,v.useId)(),s=N0[t.sets.length],c=q0(t,i),l=J0(t),u=new Map(t.regions.map(e=>[K0(t,e.in),e])),d=l.filter(e=>c.tones.has(e)),[f,p,m]=o2(t,s),h=l.filter(e=>(p.get(e)??`contents`)!==`contents`);return(0,j.jsxs)(pQ,{role:`region`,"aria-labelledby":`${a} ${o}`,...n>0?{tabIndex:0,onKeyDown:r.onKeyDown}:{},children:[(0,j.jsx)(mQ,{kind:`Set diagram`,kindId:o,children:(0,j.jsx)(hQ,{id:a,text:t.title})}),(0,j.jsxs)(gQ,{children:[(0,j.jsxs)(`ul`,{className:`sr-only`,"data-testid":`set-description`,children:[t.sets.map(e=>(0,j.jsxs)(`li`,{children:[`Set: `,(0,j.jsx)(X0,{text:e.label})]},e.id)),t.universe!==void 0&&(0,j.jsxs)(`li`,{children:[`Universe: `,(0,j.jsx)(X0,{text:t.universe})]}),l.map(e=>{let n=u.get(e);if(!n)return null;let r=n.elements.length===0&&!n.count;return(0,j.jsxs)(`li`,{children:[(0,j.jsx)($0,{spec:t,mask:e}),`: `,r&&`empty`,(0,j.jsx)(Z0,{elements:n.elements}),n.count!==void 0&&n.count!==n.elements.length&&!r&&`${n.elements.length>0?`, `:``}${n.count} in total`]},e)})]}),(0,j.jsx)(u2,{spec:t,layout:s,tones:c.tones,fits:p,drawing:f}),(h.length>0||m.length>0)&&(0,j.jsxs)(`div`,{className:`flex flex-col gap-1 text-xs`,"data-testid":`set-overflow`,children:[(0,j.jsx)(`p`,{"aria-hidden":`true`,className:`text-muted-foreground`,children:`↓ Doesn't fit in the diagram:`}),m.map(e=>(0,j.jsxs)(dQ,{children:[(0,j.jsxs)(`span`,{className:`font-medium`,children:[e===`universe`?`Universe`:`${s2[Number(e)]} label`,`:`]}),` `,(0,j.jsx)(X0,{text:e===`universe`?t.universe:t.sets[Number(e)].label})]},e)),h.map(e=>(0,j.jsxs)(dQ,{children:[(0,j.jsxs)(`span`,{className:`font-medium`,children:[(0,j.jsx)($0,{spec:t,mask:e}),`:`]}),` `,(0,j.jsx)(`span`,{className:`font-mono`,children:(0,j.jsx)(n2,{region:u.get(e)})})]},e))]}),d.length>0&&(0,j.jsx)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-xs`,"data-testid":`set-key`,children:d.map(e=>{let n=c.tones.get(e);return(0,j.jsx)(`div`,{className:`max-w-full min-w-0`,"data-tone":n,children:(0,j.jsxs)(dQ,{children:[(0,j.jsxs)(`span`,{className:`font-medium`,children:[G0[n].word,`:`]}),` `,(0,j.jsx)($0,{spec:t,mask:e})]})},e)})}),c.variables.length>0&&(0,j.jsx)(`div`,{className:`flex flex-wrap gap-2`,"data-testid":`set-variables`,children:c.variables.map((e,t)=>(0,j.jsx)(`div`,{className:`border-border-strong bg-card max-w-full min-w-0 rounded-md border px-2 py-0.5 font-mono text-xs`,children:(0,j.jsxs)(dQ,{children:[(0,j.jsx)(X0,{text:e.name}),` = `,(0,j.jsx)(X0,{text:String(e.value)})]})},t))}),n>0&&(0,j.jsx)(j.Fragment,{children:(0,j.jsxs)(`div`,{"aria-live":`polite`,"aria-atomic":`true`,"data-testid":`set-announcement`,children:[(0,j.jsxs)(`span`,{className:`sr-only`,children:[`Step `,i+1,` of `,n,`:`,` `]}),(0,j.jsx)(`div`,{"data-testid":`set-explanation`,children:(0,j.jsx)(uQ,{children:(0,j.jsx)(rQ,{text:c.explanation,mode:`math`})})}),(0,j.jsxs)(`span`,{className:`sr-only`,children:[d.length===0&&`Nothing highlighted. `,d.map(e=>(0,j.jsxs)(v.Fragment,{children:[G0[c.tones.get(e)].word,`: `,(0,j.jsx)($0,{spec:t,mask:e}),`.`,` `]},e)),c.variables.map((e,t)=>(0,j.jsxs)(v.Fragment,{children:[(0,j.jsx)(X0,{text:e.name}),` = `,(0,j.jsx)(X0,{text:String(e.value)}),`.`,` `]},t))]})]})})]}),n>0&&(0,j.jsx)(fQ,{stepper:r,play:!0})]})}var f2={active:`Highlighted`,done:`Done`,muted:`Ruled out`};function p2(e,t){let n=e.rows.map(e=>[...e]);for(let r of e.steps?.slice(0,t+1)??[])for(let{row:e,column:t,value:i}of r.cells??[])n[e]&&t<n[e].length&&(n[e][t]=i);let r=e.steps?.[t];return{rows:n,explanation:r?.explanation,highlight:r?.highlight??[],changes:r?.cells??[]}}var m2=e=>typeof e==`boolean`?e?`T`:`F`:String(e),h2=({row:e,column:t})=>[e!==void 0&&`row ${e+1}`,t!==void 0&&`column ${t+1}`].filter(Boolean).join(`, `),g2=`wrap-normal!`;function _2({view:e}){let{spec:t}=e,n=lQ(t.steps?.length??1),r=p2(t,n.index),i=e=>{let t=r.highlight.findLast(e);return t&&(t.tone??`active`)},a=t.steps!==void 0,o=(0,v.useId)(),s=(0,v.useId)();return(0,j.jsxs)(pQ,{role:`region`,"aria-labelledby":`${o} ${s}`,...a?{tabIndex:0,onKeyDown:n.onKeyDown}:{},children:[(0,j.jsx)(mQ,{kind:`Table`,kindId:s,children:(0,j.jsx)(hQ,{id:o,text:t.title})}),(0,j.jsxs)(gQ,{children:[(0,j.jsx)(`div`,{className:`overflow-x-auto`,role:`group`,"aria-label":`Table contents, scrolls sideways`,tabIndex:0,"data-testid":`table-scroll`,onKeyDown:e=>{(e.key===`ArrowLeft`||e.key===`ArrowRight`)&&e.stopPropagation()},children:(0,j.jsxs)(`table`,{className:`mx-auto border-collapse text-sm`,children:[(0,j.jsx)(`caption`,{className:`sr-only`,children:(0,j.jsx)(rQ,{text:t.title,mode:`math`})}),(0,j.jsx)(`thead`,{children:(0,j.jsxs)(`tr`,{children:[t.rowHeaders&&(0,j.jsx)(`td`,{className:`border-b px-3 py-1.5`}),t.columns.map((e,t)=>{let n=i(e=>e.column===t&&e.row===void 0);return(0,j.jsx)(`th`,{scope:`col`,className:A(`border-b px-3 py-1.5 text-center font-medium`,n&&sQ[n]),children:(0,j.jsx)(rQ,{text:e,mode:`math`,className:g2})},t)})]})}),(0,j.jsx)(`tbody`,{children:r.rows.map((e,n)=>{let r=i(e=>e.row===n&&e.column===void 0),a=t.rowHeaders?.[n];return(0,j.jsxs)(`tr`,{className:`border-b last:border-b-0`,children:[a!==void 0&&(0,j.jsx)(`th`,{scope:`row`,className:A(`border-r px-3 py-1.5 text-center font-medium`,r&&sQ[r]),children:(0,j.jsx)(rQ,{text:a,mode:`math`,className:g2})}),e.map((e,t)=>{let r=i(e=>(e.row===void 0||e.row===n)&&(e.column===void 0||e.column===t));return(0,j.jsx)(`td`,{className:A(`px-3 py-1.5 text-center tabular-nums`,r&&sQ[r]),"data-tone":r,"data-testid":`table-cell`,children:(0,j.jsx)(rQ,{text:m2(e),mode:`math`,className:g2})},t)})]},n)})})]})}),a&&(0,j.jsxs)(`div`,{"aria-live":`polite`,"aria-atomic":`true`,"data-testid":`table-live`,children:[(0,j.jsxs)(`span`,{className:`sr-only`,children:[`Step `,n.index+1,` of `,n.last+1,`.`,` `]}),(0,j.jsx)(uQ,{children:(0,j.jsx)(rQ,{text:r.explanation??``,mode:`math`})}),(0,j.jsxs)(`span`,{className:`sr-only`,"data-testid":`table-description`,children:[r.highlight.map(e=>` ${f2[e.tone??`active`]}: ${h2(e)}.`),r.changes.map(e=>` Changed ${h2(e)} to ${m2(e.value)}.`)]})]})]}),(0,j.jsx)(fQ,{stepper:n,play:!0})]})}function v2({view:e}){let{spec:t}=e,n=lQ(t.steps.length),{index:r,last:i,go:a}=n,o=r===i,s=t.steps[r],c=(0,v.useId)(),l=(0,v.useId)();return(0,j.jsxs)(pQ,{role:`region`,"aria-labelledby":`${c} ${l}`,tabIndex:0,onKeyDown:n.onKeyDown,children:[(0,j.jsx)(mQ,{kind:`Worked steps`,kindId:l,children:(0,j.jsx)(hQ,{id:c,text:t.title})}),(0,j.jsxs)(gQ,{children:[t.goal&&(0,j.jsx)(`p`,{className:`bg-sunken rounded-lg px-3.5 py-2.5 leading-normal`,children:(0,j.jsxs)(uQ,{children:[(0,j.jsx)(`span`,{className:`font-semibold`,children:`Goal: `}),(0,j.jsx)(rQ,{text:t.goal,mode:`math`})]})}),(0,j.jsx)(`ol`,{className:`flex flex-col`,children:t.steps.slice(0,r+1).map((e,t)=>(0,j.jsxs)(`li`,{"aria-current":t===r?`step`:void 0,className:`group relative flex min-w-0 flex-col gap-0.5 border-t py-2.5 pl-9 first:border-t-0 first:pt-0.5 last:pb-0`,"data-testid":`worked-step`,children:[(0,j.jsx)(`span`,{"aria-hidden":`true`,className:A(`absolute top-2.5 left-0 grid size-6 place-items-center rounded-full font-mono text-[0.7rem] font-medium group-first:top-0.5`,t===r?cQ.current:cQ.other),"data-testid":`worked-step-number`,children:t+1}),e.label&&(0,j.jsx)(`p`,{className:`text-muted-foreground font-mono text-[0.6875rem] font-medium tracking-[0.06em] uppercase`,children:(0,j.jsx)(uQ,{children:(0,j.jsx)(rQ,{text:e.label,mode:`math`})})}),(0,j.jsx)(`div`,{className:`font-heading text-[1.0625rem] leading-normal`,children:(0,j.jsx)(uQ,{children:(0,j.jsx)(rQ,{text:e.statement,mode:`math`})})}),(0,j.jsx)(`p`,{className:`text-muted-foreground text-sm leading-snug`,children:(0,j.jsx)(uQ,{children:(0,j.jsx)(rQ,{text:e.justification,mode:`math`})})})]},t))}),(0,j.jsxs)(`div`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,"data-testid":`worked-status`,children:[`Step `,r+1,` of `,i+1,`.`,` `,s?.label&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(rQ,{text:s.label,mode:`math`}),`.`,` `]}),s&&(0,j.jsx)(rQ,{text:s.statement,mode:`math`}),` `,s&&(0,j.jsx)(rQ,{text:s.justification,mode:`math`})]})]}),(0,j.jsx)(fQ,{stepper:n,children:(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`sm`,className:`text-muted-foreground hover:text-foreground decoration-border-strong underline underline-offset-4 hover:bg-transparent dark:hover:bg-transparent`,onClick:()=>a(o?0:i),children:o?`Start over`:`Show all`})})]})}var y2={algorithm_trace:SQ,code_walkthrough:TQ,graph:g0,interview_context:C0,multiple_choice:O0,placement_question:A0,set_diagram:d2,table:_2,worked_steps:v2};function b2({data:e,replyInProgress:t,onUpdate:n,onRefresh:r}){let i=wM.safeParse(e);if(!i.success)return(0,j.jsx)(`div`,{className:`text-muted-foreground rounded-lg border border-dashed p-3 text-sm`,role:`note`,children:`Can't display this item.`});let a=i.data,o=y2[a.kind];return(0,j.jsx)(o,{view:a,replyInProgress:t,onUpdate:n,onRefresh:r})}function x2(e,t,n){return(e===`submitted`||e===`streaming`)&&t===n-1}function S2(e,t){return e.id&&t[e.id]||e.data}function C2(e){let t={};for(let n of e)for(let e of n.parts){if(e.type!==`data-artifact`)continue;let n=wM.safeParse(e.data);n.success&&(t[n.data.id]=n.data)}return t}var w2=e=>e?.kind===`multiple_choice`&&e.latestAttempt!==void 0;function T2(e,t){let n={...e};for(let[r,i]of Object.entries(t))(!w2(e[r])||w2(i))&&(n[r]=i);return n}var E2=ce(`inline-flex w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-full border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3`,{variants:{variant:{default:`bg-primary text-primary-foreground [a&]:hover:bg-primary/90`,secondary:`bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90`,destructive:`bg-destructive text-white focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40 [a&]:hover:bg-destructive/90`,outline:`border-border text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground`,ghost:`[a&]:hover:bg-accent [a&]:hover:text-accent-foreground`,link:`text-primary underline-offset-4 [a&]:hover:underline`}},defaultVariants:{variant:`default`}});function D2({className:e,variant:t=`default`,asChild:n=!1,...r}){let i=n?Gt:`span`;return(0,j.jsx)(i,{"data-slot":`badge`,"data-variant":t,className:A(E2({variant:t}),e),...r})}function O2({...e}){return(0,j.jsx)(wr,{"data-slot":`collapsible`,...e})}function k2({...e}){return(0,j.jsx)(Er,{"data-slot":`collapsible-trigger`,...e})}function A2({...e}){return(0,j.jsx)(Or,{"data-slot":`collapsible-content`,...e})}function j2({className:e,...t}){return(0,j.jsx)(Ed,{"data-slot":`label`,className:A(`flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50`,e),...t})}function M2({className:e,orientation:t=`horizontal`,decorative:n=!0,...r}){return(0,j.jsx)(Mp,{"data-slot":`separator`,decorative:n,orientation:t,className:A(`shrink-0 bg-border data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px`,e),...r})}var N2=ce(`group/field flex w-full gap-3 data-[invalid=true]:text-destructive`,{variants:{orientation:{vertical:[`flex-col [&>*]:w-full [&>.sr-only]:w-auto`],horizontal:[`flex-row items-center`,`[&>[data-slot=field-label]]:flex-auto`,`has-[>[data-slot=field-content]]:items-start has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px`],responsive:[`flex-col @md/field-group:flex-row @md/field-group:items-center [&>*]:w-full @md/field-group:[&>*]:w-auto [&>.sr-only]:w-auto`,`@md/field-group:[&>[data-slot=field-label]]:flex-auto`,`@md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px`]}},defaultVariants:{orientation:`vertical`}});function P2({className:e,orientation:t=`vertical`,...n}){return(0,j.jsx)(`div`,{role:`group`,"data-slot":`field`,"data-orientation":t,className:A(N2({orientation:t}),e),...n})}function F2({className:e,...t}){return(0,j.jsx)(j2,{"data-slot":`field-label`,className:A(`group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50`,`has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border [&>*]:data-[slot=field]:p-4`,`has-data-[state=checked]:border-primary has-data-[state=checked]:bg-primary/5 dark:has-data-[state=checked]:bg-primary/10`,e),...t})}function I2({className:e,...t}){return(0,j.jsx)(`p`,{"data-slot":`field-description`,className:A(`text-sm leading-normal font-normal text-muted-foreground group-has-[[data-orientation=horizontal]]/field:text-balance`,`last:mt-0 nth-last-2:-mt-1 [[data-variant=legend]+&]:-mt-1.5`,`[&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary`,e),...t})}function L2({className:e,children:t,errors:n,...r}){let i=(0,v.useMemo)(()=>{if(t)return t;if(!n?.length)return null;let e=[...new Map(n.map(e=>[e?.message,e])).values()];return e?.length==1?e[0]?.message:(0,j.jsx)(`ul`,{className:`ml-4 flex list-disc flex-col gap-1`,children:e.map((e,t)=>e?.message&&(0,j.jsx)(`li`,{children:e.message},t))})},[t,n]);return i?(0,j.jsx)(`div`,{role:`alert`,"data-slot":`field-error`,className:A(`text-sm font-normal text-destructive`,e),...r,children:i}):null}function R2({className:e,...t}){return(0,j.jsx)(rg,{role:`status`,"aria-label":`Loading`,className:A(`size-4 animate-spin motion-reduce:animate-none`,e),...t})}function z2({className:e,type:t,...n}){return(0,j.jsx)(`input`,{type:t,"data-slot":`input`,className:A(`h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none selection:bg-primary selection:text-primary-foreground file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:bg-input/30`,`focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50`,`aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40`,e),...n})}var B2=1,V2=.9,H2=.8,U2=.17,W2=.1,G2=.999,K2=.9999,q2=.99,J2=/[\\\/_+.#"@\[\(\{&]/,Y2=/[\\\/_+.#"@\[\(\{&]/g,X2=/[\s-]/,Z2=/[\s-]/g;function Q2(e,t,n,r,i,a,o){if(a===t.length)return i===e.length?B2:q2;var s=`${i},${a}`;if(o[s]!==void 0)return o[s];for(var c=r.charAt(a),l=n.indexOf(c,i),u=0,d,f,p,m;l>=0;)d=Q2(e,t,n,r,l+1,a+1,o),d>u&&(l===i?d*=B2:J2.test(e.charAt(l-1))?(d*=H2,p=e.slice(i,l-1).match(Y2),p&&i>0&&(d*=G2**+p.length)):X2.test(e.charAt(l-1))?(d*=V2,m=e.slice(i,l-1).match(Z2),m&&i>0&&(d*=G2**+m.length)):(d*=U2,i>0&&(d*=G2**+(l-i))),e.charAt(l)!==t.charAt(a)&&(d*=K2)),(d<W2&&n.charAt(l-1)===r.charAt(a+1)||r.charAt(a+1)===r.charAt(a)&&n.charAt(l-1)!==r.charAt(a))&&(f=Q2(e,t,n,r,l+1,a+2,o),f*W2>d&&(d=f*W2)),d>u&&(u=d),l=n.indexOf(c,l+1);return o[s]=u,u}function $2(e){return e.toLowerCase().replace(Z2,` `)}function e4(e,t,n){return e=n&&n.length>0?`${e+` `+n.join(` `)}`:e,Q2(e,t,$2(e),$2(t),0,0,{})}var t4=`[cmdk-group=""]`,n4=`[cmdk-group-items=""]`,r4=`[cmdk-group-heading=""]`,i4=`[cmdk-item=""]`,a4=`${i4}:not([aria-disabled="true"])`,o4=`cmdk-item-select`,s4=`data-value`,c4=(e,t,n)=>e4(e,t,n),l4=v.createContext(void 0),u4=()=>v.useContext(l4),d4=v.createContext(void 0),f4=()=>v.useContext(d4),p4=v.createContext(void 0),m4=v.forwardRef((e,t)=>{let n=O4(()=>({search:``,value:e.value??e.defaultValue??``,selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}})),r=O4(()=>new Set),i=O4(()=>new Map),a=O4(()=>new Map),o=O4(()=>new Set),s=E4(e),{label:c,children:l,value:u,onValueChange:d,filter:f,shouldFilter:p,loop:m,disablePointerSelection:h=!1,vimBindings:g=!0,..._}=e,y=gr(),b=gr(),x=gr(),S=v.useRef(null),C=j4();D4(()=>{if(u!==void 0){let e=u.trim();n.current.value=e,w.emit()}},[u]),D4(()=>{C(6,ne)},[]);let w=v.useMemo(()=>({subscribe:e=>(o.current.add(e),()=>o.current.delete(e)),snapshot:()=>n.current,setState:(e,t,r)=>{var i,a,o;if(!Object.is(n.current[e],t)){if(n.current[e]=t,e===`search`)te(),D(),C(1,ee);else if(e===`value`){if(document.activeElement.hasAttribute(`cmdk-input`)||document.activeElement.hasAttribute(`cmdk-root`)){let e=document.getElementById(x);e?e.focus():(i=document.getElementById(y))==null||i.focus()}if(C(7,()=>{n.current.selectedItemId=re()?.id,w.emit()}),r||C(5,ne),s.current?.value!==void 0){let e=t??``;(o=(a=s.current).onValueChange)==null||o.call(a,e);return}}w.emit()}},emit:()=>{o.current.forEach(e=>e())}}),[]),T=v.useMemo(()=>({value:(e,t,r)=>{t!==a.current.get(e)?.value&&(a.current.set(e,{value:t,keywords:r}),n.current.filtered.items.set(e,E(t,r)),C(2,()=>{D(),w.emit()}))},item:(e,t)=>(r.current.add(e),t&&(i.current.has(t)?i.current.get(t).add(e):i.current.set(t,new Set([e]))),C(3,()=>{te(),D(),n.current.value||ee(),w.emit()}),()=>{a.current.delete(e),r.current.delete(e),n.current.filtered.items.delete(e);let t=re();C(4,()=>{te(),t?.getAttribute(`id`)===e&&ee(),w.emit()})}),group:e=>(i.current.has(e)||i.current.set(e,new Set),()=>{a.current.delete(e),i.current.delete(e)}),filter:()=>s.current.shouldFilter,label:c||e[`aria-label`],getDisablePointerSelection:()=>s.current.disablePointerSelection,listId:y,inputId:x,labelId:b,listInnerRef:S}),[]);function E(e,t){let r=s.current?.filter??c4;return e?r(e,n.current.search,t):0}function D(){if(!n.current.search||s.current.shouldFilter===!1)return;let e=n.current.filtered.items,t=[];n.current.filtered.groups.forEach(n=>{let r=i.current.get(n),a=0;r.forEach(t=>{let n=e.get(t);a=Math.max(n,a)}),t.push([n,a])});let r=S.current;ie().sort((t,n)=>{let r=t.getAttribute(`id`),i=n.getAttribute(`id`);return(e.get(i)??0)-(e.get(r)??0)}).forEach(e=>{let t=e.closest(n4);t?t.appendChild(e.parentElement===t?e:e.closest(`${n4} > *`)):r.appendChild(e.parentElement===r?e:e.closest(`${n4} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{let t=S.current?.querySelector(`${t4}[${s4}="${encodeURIComponent(e[0])}"]`);t?.parentElement.appendChild(t)})}function ee(){let e=ie().find(e=>e.getAttribute(`aria-disabled`)!==`true`)?.getAttribute(s4);w.setState(`value`,e||void 0)}function te(){if(!n.current.search||s.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let e=0;for(let t of r.current){let r=E(a.current.get(t)?.value??``,a.current.get(t)?.keywords??[]);n.current.filtered.items.set(t,r),r>0&&e++}for(let[e,t]of i.current)for(let r of t)if(n.current.filtered.items.get(r)>0){n.current.filtered.groups.add(e);break}n.current.filtered.count=e}function ne(){var e;let t=re();t&&(t.parentElement?.firstChild===t&&((e=t.closest(t4)?.querySelector(r4))==null||e.scrollIntoView({block:`nearest`})),t.scrollIntoView({block:`nearest`}))}function re(){return S.current?.querySelector(`${i4}[aria-selected="true"]`)}function ie(){return Array.from(S.current?.querySelectorAll(a4)||[])}function ae(e){let t=ie()[e];t&&w.setState(`value`,t.getAttribute(s4))}function oe(e){var t;let n=re(),r=ie(),i=r.findIndex(e=>e===n),a=r[i+e];(t=s.current)!=null&&t.loop&&(a=i+e<0?r[r.length-1]:i+e===r.length?r[0]:r[i+e]),a&&w.setState(`value`,a.getAttribute(s4))}function se(e){let t=re()?.closest(t4),n;for(;t&&!n;)t=e>0?w4(t,t4):T4(t,t4),n=t?.querySelector(a4);n?w.setState(`value`,n.getAttribute(s4)):oe(e)}let O=()=>ae(ie().length-1),ce=e=>{e.preventDefault(),e.metaKey?O():e.altKey?se(1):oe(1)},le=e=>{e.preventDefault(),e.metaKey?ae(0):e.altKey?se(-1):oe(-1)};return v.createElement(un.div,{ref:t,tabIndex:-1,..._,"cmdk-root":``,onKeyDown:e=>{var t;(t=_.onKeyDown)==null||t.call(_,e);let n=e.nativeEvent.isComposing||e.keyCode===229;if(!(e.defaultPrevented||n))switch(e.key){case`n`:case`j`:g&&e.ctrlKey&&ce(e);break;case`ArrowDown`:ce(e);break;case`p`:case`k`:g&&e.ctrlKey&&le(e);break;case`ArrowUp`:le(e);break;case`Home`:e.preventDefault(),ae(0);break;case`End`:e.preventDefault(),O();break;case`Enter`:{e.preventDefault();let t=re();if(t){let e=new Event(o4);t.dispatchEvent(e)}}}}},v.createElement(`label`,{"cmdk-label":``,htmlFor:T.inputId,id:T.labelId,style:P4},c),N4(e,e=>v.createElement(d4.Provider,{value:w},v.createElement(l4.Provider,{value:T},e))))}),h4=v.forwardRef((e,t)=>{let n=gr(),r=v.useRef(null),i=v.useContext(p4),a=u4(),o=E4(e),s=o.current?.forceMount??i?.forceMount;D4(()=>{if(!s)return a.item(n,i?.id)},[s]);let c=A4(n,r,[e.value,e.children,r],e.keywords),l=f4(),u=k4(e=>e.value&&e.value===c.current),d=k4(e=>s||a.filter()===!1?!0:!e.search||e.filtered.items.get(n)>0);v.useEffect(()=>{let t=r.current;if(t&&!e.disabled)return t.addEventListener(o4,f),()=>t.removeEventListener(o4,f)},[d,e.onSelect,e.disabled]);function f(){var e,t;p(),(t=(e=o.current).onSelect)==null||t.call(e,c.current)}function p(){l.setState(`value`,c.current,!0)}if(!d)return null;let{disabled:m,value:h,onSelect:g,forceMount:_,keywords:y,...b}=e;return v.createElement(un.div,{ref:Bt(r,t),...b,id:n,"cmdk-item":``,role:`option`,"aria-disabled":!!m,"aria-selected":!!u,"data-disabled":!!m,"data-selected":!!u,onPointerMove:m||a.getDisablePointerSelection()?void 0:p,onClick:m?void 0:f},e.children)}),g4=v.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:i,...a}=e,o=gr(),s=v.useRef(null),c=v.useRef(null),l=gr(),u=u4(),d=k4(e=>i||u.filter()===!1?!0:!e.search||e.filtered.groups.has(o));D4(()=>u.group(o),[]),A4(o,s,[e.value,e.heading,c]);let f=v.useMemo(()=>({id:o,forceMount:i}),[i]);return v.createElement(un.div,{ref:Bt(s,t),...a,"cmdk-group":``,role:`presentation`,hidden:!d||void 0},n&&v.createElement(`div`,{ref:c,"cmdk-group-heading":``,"aria-hidden":!0,id:l},n),N4(e,e=>v.createElement(`div`,{"cmdk-group-items":``,role:`group`,"aria-labelledby":n?l:void 0},v.createElement(p4.Provider,{value:f},e))))}),_4=v.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,i=v.useRef(null),a=k4(e=>!e.search);return!n&&!a?null:v.createElement(un.div,{ref:Bt(i,t),...r,"cmdk-separator":``,role:`separator`})}),v4=v.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,i=e.value!=null,a=f4(),o=k4(e=>e.search),s=k4(e=>e.selectedItemId),c=u4();return v.useEffect(()=>{e.value!=null&&a.setState(`search`,e.value)},[e.value]),v.createElement(un.input,{ref:t,...r,"cmdk-input":``,autoComplete:`off`,autoCorrect:`off`,spellCheck:!1,"aria-autocomplete":`list`,role:`combobox`,"aria-expanded":!0,"aria-controls":c.listId,"aria-labelledby":c.labelId,"aria-activedescendant":s,id:c.inputId,type:`text`,value:i?e.value:o,onChange:e=>{i||a.setState(`search`,e.target.value),n?.(e.target.value)}})}),y4=v.forwardRef((e,t)=>{let{children:n,label:r=`Suggestions`,...i}=e,a=v.useRef(null),o=v.useRef(null),s=k4(e=>e.selectedItemId),c=u4();return v.useEffect(()=>{if(o.current&&a.current){let e=o.current,t=a.current,n,r=new ResizeObserver(()=>{n=requestAnimationFrame(()=>{let n=e.offsetHeight;t.style.setProperty(`--cmdk-list-height`,n.toFixed(1)+`px`)})});return r.observe(e),()=>{cancelAnimationFrame(n),r.unobserve(e)}}},[]),v.createElement(un.div,{ref:Bt(a,t),...i,"cmdk-list":``,role:`listbox`,tabIndex:-1,"aria-activedescendant":s,"aria-label":r,id:c.listId},N4(e,e=>v.createElement(`div`,{ref:Bt(o,c.listInnerRef),"cmdk-list-sizer":``},e)))}),b4=v.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:i,contentClassName:a,container:o,...s}=e;return v.createElement(eo,{open:n,onOpenChange:r},v.createElement(oo,{container:o},v.createElement(co,{"cmdk-overlay":``,className:i}),v.createElement(po,{"aria-label":e.label,"cmdk-dialog":``,className:a},v.createElement(m4,{ref:t,...s}))))}),x4=v.forwardRef((e,t)=>k4(e=>e.filtered.count===0)?v.createElement(un.div,{ref:t,...e,"cmdk-empty":``,role:`presentation`}):null),S4=v.forwardRef((e,t)=>{let{progress:n,children:r,label:i=`Loading...`,...a}=e;return v.createElement(un.div,{ref:t,...a,"cmdk-loading":``,role:`progressbar`,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i},N4(e,e=>v.createElement(`div`,{"aria-hidden":!0},e)))}),C4=Object.assign(m4,{List:y4,Item:h4,Input:v4,Group:g4,Separator:_4,Dialog:b4,Empty:x4,Loading:S4});function w4(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function T4(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function E4(e){let t=v.useRef(e);return D4(()=>{t.current=e}),t}var D4=typeof window>`u`?v.useEffect:v.useLayoutEffect;function O4(e){let t=v.useRef();return t.current===void 0&&(t.current=e()),t}function k4(e){let t=f4(),n=()=>e(t.snapshot());return v.useSyncExternalStore(t.subscribe,n,n)}function A4(e,t,n,r=[]){let i=v.useRef(),a=u4();return D4(()=>{var o;let s=(()=>{for(let e of n){if(typeof e==`string`)return e.trim();if(typeof e==`object`&&`current`in e)return e.current?e.current.textContent?.trim():i.current}})(),c=r.map(e=>e.trim());a.value(e,s,c),(o=t.current)==null||o.setAttribute(s4,s),i.current=s}),i}var j4=()=>{let[e,t]=v.useState(),n=O4(()=>new Map);return D4(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function M4(e){let t=e.type;return typeof t==`function`?t(e.props):`render`in t?t.render(e.props):e}function N4({asChild:e,children:t},n){return e&&v.isValidElement(t)?v.cloneElement(M4(t),{ref:t.ref},n(t.props.children)):n(t)}var P4={position:`absolute`,width:`1px`,height:`1px`,padding:`0`,margin:`-1px`,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,borderWidth:`0`};function F4({...e}){return(0,j.jsx)(eo,{"data-slot":`dialog`,...e})}function I4({...e}){return(0,j.jsx)(oo,{"data-slot":`dialog-portal`,...e})}function L4({className:e,...t}){return(0,j.jsx)(co,{"data-slot":`dialog-overlay`,className:A(`fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0`,e),...t})}function R4({className:e,children:t,showCloseButton:n=!0,...r}){return(0,j.jsxs)(I4,{"data-slot":`dialog-portal`,children:[(0,j.jsx)(L4,{}),(0,j.jsxs)(po,{"data-slot":`dialog-content`,className:A(`fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg`,e),...r,children:[t,n&&(0,j.jsxs)(bo,{"data-slot":`dialog-close`,className:`absolute top-4 right-4 rounded-xs opacity-70 after:absolute after:-inset-3 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,children:[(0,j.jsx)(d_,{}),(0,j.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function z4({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`dialog-header`,className:A(`flex flex-col gap-2 text-center sm:text-left`,e),...t})}function B4({className:e,showCloseButton:t=!1,children:n,...r}){return(0,j.jsxs)(`div`,{"data-slot":`dialog-footer`,className:A(`flex flex-col-reverse gap-2 sm:flex-row sm:justify-end`,e),...r,children:[n,t&&(0,j.jsx)(bo,{asChild:!0,children:(0,j.jsx)(M,{variant:`outline`,children:`Close`})})]})}function V4({className:e,...t}){return(0,j.jsx)(_o,{"data-slot":`dialog-title`,className:A(`text-lg leading-none font-semibold`,e),...t})}function H4({className:e,...t}){return(0,j.jsx)(vo,{"data-slot":`dialog-description`,className:A(`text-sm text-muted-foreground`,e),...t})}function U4({className:e,...t}){return(0,j.jsx)(C4,{"data-slot":`command`,className:A(`flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground`,e),...t})}function W4({className:e,...t}){return(0,j.jsxs)(`div`,{"data-slot":`command-input-wrapper`,className:`flex h-9 items-center gap-2 border-b px-3`,children:[(0,j.jsx)(Lg,{className:`size-4 shrink-0 opacity-50`}),(0,j.jsx)(C4.Input,{"data-slot":`command-input`,className:A(`flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50`,e),...t})]})}function G4({className:e,...t}){return(0,j.jsx)(C4.List,{"data-slot":`command-list`,className:A(`max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto`,e),...t})}function K4({...e}){return(0,j.jsx)(C4.Empty,{"data-slot":`command-empty`,className:`py-6 text-center text-sm`,...e})}function q4({className:e,...t}){return(0,j.jsx)(C4.Group,{"data-slot":`command-group`,className:A(`overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground`,e),...t})}function J4({className:e,...t}){return(0,j.jsx)(C4.Item,{"data-slot":`command-item`,className:A(`relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground`,e),...t})}function Y4({...e}){return(0,j.jsx)(pd,{"data-slot":`dropdown-menu`,...e})}function X4({...e}){return(0,j.jsx)(hd,{"data-slot":`dropdown-menu-trigger`,...e})}function Z4({className:e,sideOffset:t=4,...n}){return(0,j.jsx)(gd,{children:(0,j.jsx)(vd,{"data-slot":`dropdown-menu-content`,sideOffset:t,className:A(`z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,e),...n})})}function Q4({className:e,inset:t,variant:n=`default`,...r}){return(0,j.jsx)(bd,{"data-slot":`dropdown-menu-item`,"data-inset":t,"data-variant":n,className:A(`relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!`,e),...r})}function $4({...e}){return(0,j.jsx)(xd,{"data-slot":`dropdown-menu-radio-group`,...e})}function e3({className:e,children:t,...n}){return(0,j.jsxs)(Sd,{"data-slot":`dropdown-menu-radio-item`,className:A(`relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,e),...n,children:[(0,j.jsx)(`span`,{className:`pointer-events-none absolute left-2 flex size-3.5 items-center justify-center`,children:(0,j.jsx)(Cd,{children:(0,j.jsx)(lh,{className:`size-2 fill-current`})})}),t]})}function t3({className:e,inset:t,...n}){return(0,j.jsx)(yd,{"data-slot":`dropdown-menu-label`,"data-inset":t,className:A(`px-2 py-1.5 text-sm font-medium data-[inset]:pl-8`,e),...n})}function n3({className:e,...t}){return(0,j.jsx)(wd,{"data-slot":`dropdown-menu-separator`,className:A(`-mx-1 my-1 h-px bg-border`,e),...t})}function r3({...e}){return(0,j.jsx)(Rd,{"data-slot":`popover`,...e})}function i3({...e}){return(0,j.jsx)(Bd,{"data-slot":`popover-trigger`,...e})}function a3({className:e,align:t=`center`,sideOffset:n=4,...r}){return(0,j.jsx)(Wd,{children:(0,j.jsx)(Kd,{"data-slot":`popover-content`,align:t,sideOffset:n,className:A(`z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,e),...r})})}function o3({className:e}){return(0,j.jsx)(`svg`,{viewBox:`0 0 21 21`,fill:`none`,"aria-hidden":`true`,focusable:`false`,className:A(`size-[21px] shrink-0`,e),children:(0,j.jsx)(`path`,{fill:`currentColor`,d:`M11.8102 19.1625C11.2327 19.1625 10.6841 19.0528 10.1643 18.8334C9.64459 18.6139 9.18259 18.3078 8.77834 17.9151C8.33944 18.0653 7.88322 18.1404 7.40967 18.1404C6.63582 18.1404 5.91972 17.9498 5.26137 17.5686C4.60302 17.1875 4.07172 16.6677 3.66747 16.0094C3.27477 15.351 3.07842 14.6176 3.07842 13.8091C3.07842 13.4742 3.12462 13.1103 3.21702 12.7176C2.75502 12.2903 2.39697 11.7994 2.14287 11.245C1.88877 10.679 1.76172 10.09 1.76172 9.47785C1.76172 8.85415 1.89454 8.25355 2.16019 7.67605C2.42584 7.09855 2.79544 6.6019 3.26899 6.1861C3.75409 5.75875 4.31427 5.46422 4.94952 5.30252C5.07657 4.64417 5.34222 4.05512 5.74647 3.53537C6.16227 3.00407 6.67047 2.58827 7.27107 2.28797C7.87167 1.98767 8.51269 1.83752 9.19414 1.83752C9.77164 1.83752 10.3203 1.94725 10.84 2.1667C11.3598 2.38615 11.8218 2.69222 12.226 3.08492C12.6649 2.93477 13.1211 2.8597 13.5947 2.8597C14.3685 2.8597 15.0846 3.05027 15.743 3.43142C16.4013 3.81257 16.9269 4.33232 17.3196 4.99067C17.7238 5.64902 17.9259 6.38245 17.9259 7.19095C17.9259 7.5259 17.8797 7.88973 17.7873 8.28242C18.2493 8.70977 18.6074 9.20643 18.8615 9.77238C19.1156 10.3268 19.2426 10.91 19.2426 11.5222C19.2426 12.1459 19.1098 12.7465 18.8442 13.324C18.5785 13.9015 18.2031 14.4039 17.718 14.8313C17.2445 15.2471 16.6901 15.5358 16.0548 15.6975C15.9278 16.3559 15.6564 16.9449 15.2406 17.4647C14.8363 17.996 14.3339 18.4118 13.7333 18.7121C13.1327 19.0124 12.4917 19.1625 11.8102 19.1625ZM7.53094 16.9969C8.10844 16.9969 8.61087 16.8756 9.03822 16.6331L12.2953 14.762C12.4108 14.6811 12.4686 14.5714 12.4686 14.4328V12.9429L8.27592 15.351C8.02182 15.5012 7.76772 15.5012 7.51362 15.351L4.23919 13.4626C4.23919 13.4973 4.23342 13.5377 4.22187 13.5839C4.22187 13.6301 4.22187 13.6994 4.22187 13.7918C4.22187 14.3808 4.36047 14.9237 4.63767 15.4203C4.92642 15.9054 5.32489 16.2866 5.83309 16.5638C6.34129 16.8525 6.90724 16.9969 7.53094 16.9969ZM7.70419 14.1729C7.77349 14.2076 7.83702 14.2249 7.89477 14.2249C7.95252 14.2249 8.01027 14.2076 8.06802 14.1729L9.36739 13.4279L5.19207 11.0024C4.93797 10.8523 4.81092 10.6271 4.81092 10.3268V6.56725C4.23342 6.82135 3.77142 7.21405 3.42492 7.74535C3.07842 8.2651 2.90517 8.8426 2.90517 9.47785C2.90517 10.0438 3.04954 10.5866 3.33829 11.1064C3.62704 11.6261 4.00242 12.0189 4.46442 12.2845L7.70419 14.1729ZM11.8102 18.0191C12.4224 18.0191 12.9768 17.8805 13.4734 17.6033C13.9701 17.3261 14.3628 16.9449 14.6515 16.4598C14.9403 15.9747 15.0846 15.4319 15.0846 14.8313V11.0891C15.0846 10.9505 15.0269 10.8465 14.9114 10.7772L13.5947 10.0149V14.8486C13.5947 15.1489 13.4676 15.3741 13.2135 15.5243L9.93912 17.4127C10.5051 17.817 11.1288 18.0191 11.8102 18.0191ZM12.4686 11.6781V9.32192L10.5108 8.21312L8.53579 9.32192V11.6781L10.5108 12.7869L12.4686 11.6781ZM7.40967 6.15145C7.40967 5.85115 7.53672 5.62592 7.79082 5.47577L11.0652 3.58735C10.4993 3.1831 9.87559 2.98097 9.19414 2.98097C8.58199 2.98097 8.02759 3.11957 7.53094 3.39677C7.03429 3.67397 6.64159 4.05512 6.35284 4.54022C6.07564 5.02532 5.93704 5.56817 5.93704 6.16878V9.89365C5.93704 10.0323 5.99479 10.142 6.11029 10.2228L7.40967 10.9851V6.15145ZM16.2108 14.4328C16.7883 14.1787 17.2445 13.786 17.5794 13.2547C17.9259 12.7234 18.0992 12.1459 18.0992 11.5222C18.0992 10.9562 17.9548 10.4134 17.6661 9.89365C17.3773 9.3739 17.0019 8.9812 16.5399 8.71555L13.3002 6.84445C13.2309 6.79825 13.1673 6.78092 13.1096 6.79248C13.0518 6.79248 12.9941 6.8098 12.9363 6.84445L11.637 7.5721L15.8296 10.0149C15.9567 10.0842 16.0491 10.1766 16.1068 10.2921C16.1761 10.3961 16.2108 10.5231 16.2108 10.6733V14.4328ZM12.7284 5.6317C12.9825 5.47 13.2366 5.47 13.4907 5.6317L16.7825 7.55477C16.7825 7.47393 16.7825 7.36997 16.7825 7.24292C16.7825 6.68852 16.6439 6.163 16.3667 5.66635C16.101 5.15815 15.7141 4.7539 15.2059 4.4536C14.7093 4.1533 14.1318 4.00315 13.4734 4.00315C12.8959 4.00315 12.3935 4.12442 11.9661 4.36697L8.70904 6.23808C8.59354 6.31892 8.53579 6.42865 8.53579 6.56725V8.0572L12.7284 5.6317Z`})})}function s3({busy:e,className:t,...n}){return(0,j.jsxs)(`button`,{type:`button`,"aria-busy":e||void 0,className:A(`inline-flex min-h-[45px] w-full max-w-[242px] items-center justify-center gap-3 rounded-[12px] px-5 py-3 text-[15px] font-medium`,`bg-black text-white hover:opacity-85 active:opacity-70 disabled:opacity-50 dark:bg-white dark:text-black`,`focus-visible:ring-ring/50 outline-none focus-visible:ring-[3px]`,t),...n,children:[(0,j.jsx)(o3,{}),e?`Opening ChatGPT…`:`Continue with ChatGPT`]})}function c3({className:e,primary:t=!1}){return(0,j.jsx)(M,{asChild:!0,size:t?`sm`:`xs`,variant:t?`default`:`link`,className:A(!t&&`h-auto p-0`,e),children:(0,j.jsxs)(`a`,{href:TM,target:`_blank`,rel:`noreferrer`,"aria-label":`Manage ChatGPT usage (opens in a new tab)`,children:[`Manage usage `,(0,j.jsx)(jh,{"aria-hidden":!0})]})})}function l3(){return(0,j.jsxs)(`span`,{className:`text-muted-foreground inline-flex items-center gap-1.5 text-xs`,"aria-live":`polite`,children:[(0,j.jsx)(o3,{className:`size-4`}),`Using ChatGPT plan`,(0,j.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,j.jsx)(c3,{})]})}function u3(){return(0,j.jsxs)(`div`,{role:`alert`,className:`flex flex-col gap-1 rounded-lg border p-3 text-sm`,children:[(0,j.jsxs)(`span`,{className:`text-muted-foreground inline-flex items-center gap-1.5 text-xs font-medium`,children:[(0,j.jsx)(o3,{className:`size-4`}),` ChatGPT`]}),(0,j.jsx)(`p`,{className:`font-semibold`,children:`Usage limit reached`}),(0,j.jsx)(`p`,{className:`text-muted-foreground`,children:`Review your plan or this app's limit in ChatGPT settings.`}),(0,j.jsx)(c3,{primary:!0,className:`mt-1 self-start`})]})}function d3(){let[e,t]=(0,v.useState)(!1),n=(0,v.useCallback)(()=>{LN().then(e=>{e.ok&&e.value.chatgpt?.welcome&&t(!0)})},[]);(0,v.useEffect)(()=>(n(),window.addEventListener(FN,n),()=>window.removeEventListener(FN,n)),[n]);let r=()=>{t(!1),WN()};return(0,j.jsx)(F4,{open:e,onOpenChange:e=>!e&&r(),children:(0,j.jsxs)(R4,{className:`sm:max-w-sm`,children:[(0,j.jsxs)(z4,{className:`items-center text-center sm:text-center`,children:[(0,j.jsx)(o3,{className:`text-foreground mb-2 size-[72px]`}),(0,j.jsx)(V4,{children:`You're using your ChatGPT plan`}),(0,j.jsx)(H4,{children:`Eligible usage in this app uses your ChatGPT plan. Manage usage in your ChatGPT settings.`})]}),(0,j.jsx)(B4,{className:`sm:justify-center`,children:(0,j.jsx)(M,{onClick:r,children:`Got it`})})]})})}var f3=50,p3={none:`None`,minimal:`Minimal`,low:`Low`,medium:`Medium`,high:`High`,xhigh:`Extra high`,max:`Max`},m3=`custom:`,h3=e=>e.startsWith(m3)&&e.indexOf(`/`)>7?e.slice(0,e.indexOf(`/`)):void 0,g3=e=>h3(e)?e.slice(e.indexOf(`/`)+1):e.slice(e.indexOf(`:`)+1);function _3(e,t=[]){if(h3(e))return g3(e);let n=t.find(t=>t.id===e)?.name;return n&&n!==e?n.replace(/^[^:]{1,40}:\s+/,``):e.replace(/^[a-z][a-z0-9-]*:/,``)}var v3={openrouter:`OpenRouter`,anthropic:`Anthropic`,openai:`OpenAI`,chatgpt:`ChatGPT`};function y3(e,t=[]){let n=h3(e);if(n)return t.find(e=>e.id===n)?.name??`Removed provider`;let r=e.slice(0,Math.max(0,e.indexOf(`:`)));return v3[r]??r}function b3(e,t=[],n=[]){let r=_3(e,t);return h3(e)?`${r} (${y3(e,n)})`:e.startsWith(`openrouter:`)||!(e.split(`:`)[0]in v3)?r:`${r} (${y3(e)})`}var x3={unverified:`not tested`,verified:`tested`,failed:`test failed`};function S3(e){if(!e)return;if(e.input===0&&e.output===0)return`free`;let t=e=>`$${e<1?e.toFixed(2):Number(e.toFixed(2))}`;return`${t(e.input)} in · ${t(e.output)} out per 1M tokens`}function C3(e,t){let n=t.toLowerCase().split(/\s+/).filter(Boolean);return e.filter(e=>{let t=`${e.name} ${e.id}`.toLowerCase();return n.every(e=>t.includes(e))})}function w3(){let[e,t]=(0,v.useState)(),[n,r]=(0,v.useState)(),i=(0,v.useCallback)(async()=>{let e=await wN();e.ok?t(e.value):r(e.error)},[]);return(0,v.useEffect)(()=>{i();let e=()=>void i();return window.addEventListener(FN,e),()=>window.removeEventListener(FN,e)},[i]),{view:e,error:n,refresh:i,choose:(0,v.useCallback)(async e=>{r(void 0);let n=await TN(e);if(!n.ok)return r(n.error);t(e=>e&&{...e,current:n.value,unavailable:null})},[]),togglePin:(0,v.useCallback)(async n=>{if(!e)return;r(void 0);let i=await EN(e.pinned.includes(n)?e.pinned.filter(e=>e!==n):[...e.pinned,n]);if(!i.ok)return r(i.error);t(e=>e&&{...e,pinned:i.value})},[e])}}function T3({model:e,selected:t,names:n}){let r=e.id.startsWith(`chatgpt:`)?`your ChatGPT plan`:e.verification?x3[e.verification]:S3(e.price);return(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(qm,{className:A(`mt-0.5 self-start`,t?`opacity-100`:`opacity-0`),"aria-hidden":!0}),(0,j.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[(0,j.jsx)(`span`,{className:`truncate`,children:e.name}),(0,j.jsxs)(`span`,{className:`text-muted-foreground truncate text-xs`,children:[y3(e.id,n),` · `,g3(e.id),r&&` · ${r}`]})]})]})}function E3({state:e,disabled:t,value:n,onChoose:r,unavailable:i,label:a=`Model`}){let{view:o,error:s,refresh:c,togglePin:l}=e,u=r??e.choose,d=n===void 0,f=o&&n?{...o,current:n,unavailable:i??null}:o,[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(``),_=(0,v.useMemo)(()=>new Map(f?.models.map(e=>[e.id,e])),[f]),y=(0,v.useMemo)(()=>{if(!f)return[];let e=e=>e.flatMap(e=>_.get(e)??[]);if(h.trim()){let e=C3(f.models,h),t=e.slice(0,f3),n=e.length>f3?`First ${f3} of ${e.length} matches`:void 0,r=[...new Set(t.map(e=>y3(e.id,f.providers)))];return r.length<2?[{heading:n,models:t}]:r.map((e,r)=>({heading:r===0&&n?`${n} · ${e}`:e,models:t.filter(t=>y3(t.id,f.providers)===e)}))}let t=new Set(f.pinned),n=new Set([...f.pinned,...f.recent]),r=f.models.filter(e=>e.id.startsWith(`chatgpt:`)),i=f.providers.filter(e=>!e.removed).map(e=>({heading:e.name,models:f.models.filter(t=>t.id.startsWith(`${e.id}/`)&&!n.has(t.id))})),a=[{heading:`Pinned`,models:e(f.pinned)},{heading:`Recent`,models:e(f.recent.filter(e=>!t.has(e)))},{heading:`ChatGPT plan`,models:r.filter(e=>!n.has(e.id))},...i,{heading:`Suggested`,models:e(f.suggested.filter(e=>!e.startsWith(`chatgpt:`)))}],o=new Set(a.flatMap(e=>e.models.map(e=>e.id))),s=_.get(f.current.model);return[...s&&!o.has(s.id)?[{heading:`Current`,models:[s]}]:[],...a].filter(e=>e.models.length>0)},[f,h,_]);if(!f)return s?(0,j.jsx)(`span`,{className:`text-destructive text-xs`,children:s}):null;let b=_.get(f.current.model),x=b3(f.current.model,f.models,f.providers),S=b?.reasoning?.efforts??[],C=b?.reasoning?.defaultEffort,w=f.pinned.includes(f.current.model),T=e=>{m(!1),g(``);let t=f.current.effort&&e.reasoning?.efforts.includes(f.current.effort)?f.current.effort:null;(e.id!==f.current.model||t!==f.current.effort)&&u({model:e.id,effort:t})};return(0,j.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1`,children:[(0,j.jsxs)(r3,{open:p,onOpenChange:e=>{m(e),e?c():g(``)},children:[(0,j.jsx)(i3,{asChild:!0,children:(0,j.jsxs)(M,{type:`button`,variant:`ghost`,size:`sm`,className:`text-muted-foreground max-w-64 min-w-0`,"aria-label":`${a}: ${x}. Change model`,disabled:t,children:[(0,j.jsx)(`span`,{className:`truncate`,children:x}),(0,j.jsx)(rh,{"aria-hidden":!0})]})}),(0,j.jsx)(a3,{className:`w-[min(28rem,calc(100vw-2rem))] p-0`,align:`start`,children:(0,j.jsxs)(U4,{shouldFilter:!1,label:`Choose a model`,children:[(0,j.jsx)(W4,{placeholder:`Search models…`,value:h,onValueChange:g}),(0,j.jsxs)(G4,{className:`max-h-80`,label:`Models`,children:[(0,j.jsx)(K4,{children:f.catalog===`unavailable`?`The model list couldn't be loaded.`:`No models match.`}),y.map((e,t)=>(0,j.jsx)(q4,{heading:e.heading,children:e.models.map(e=>(0,j.jsx)(J4,{value:e.id,onSelect:()=>T(e),className:`items-start`,children:(0,j.jsx)(T3,{model:e,selected:e.id===f.current.model,names:f.providers})},e.id))},e.heading??t))]}),f.catalog!==`fresh`&&(0,j.jsx)(`p`,{className:`text-muted-foreground border-t px-3 py-2 text-xs`,children:f.catalog===`stale`?`Couldn't refresh every provider's model list, so some of this is a saved copy.`:`Couldn't load the model list. Search covers only the default model.`})]})})]}),d&&(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground`,"aria-label":w?`Unpin ${x}`:`Pin ${x}`,"aria-pressed":w,title:w?`Unpin this model`:`Pin this model to the top of the list`,disabled:t,onClick:()=>void l(f.current.model),children:(0,j.jsx)(qg,{className:A(w&&`fill-current`),"aria-hidden":!0})}),S.length>0&&(0,j.jsxs)(Y4,{children:[(0,j.jsx)(X4,{asChild:!0,children:(0,j.jsxs)(M,{type:`button`,variant:`ghost`,size:`sm`,className:`text-muted-foreground`,disabled:t,"aria-label":`${d?`Reasoning effort`:`${a} reasoning effort`}: ${f.current.effort?p3[f.current.effort]:`the model's default`}. Change effort`,children:[f.current.effort?p3[f.current.effort]:`Default effort`,(0,j.jsx)(rh,{"aria-hidden":!0})]})}),(0,j.jsxs)(Z4,{align:`start`,children:[(0,j.jsx)(t3,{children:`Reasoning effort`}),(0,j.jsx)(n3,{}),(0,j.jsxs)($4,{value:f.current.effort??`default`,onValueChange:e=>void u({model:f.current.model,effort:e==="default"?null:e}),children:[(0,j.jsxs)(e3,{value:`default`,children:[`Default`,C?` (${p3[C]})`:``]}),S.map(e=>(0,j.jsx)(e3,{value:e,children:p3[e]},e))]})]})]}),d&&f.current.model.startsWith(`chatgpt:`)&&(0,j.jsx)(l3,{}),f.unavailable&&!s&&(0,j.jsx)(`span`,{role:`alert`,className:`text-destructive text-xs`,children:f.unavailable}),s&&(0,j.jsx)(`span`,{role:`alert`,className:`text-destructive text-xs`,children:s})]})}var D3=`text-muted-foreground font-mono text-[0.6875rem] leading-snug font-medium tracking-[0.09em] uppercase`,O3=`bg-card gap-0`,k3=`border-b px-5 py-4`,A3=`font-heading text-[1.35rem] leading-tight font-medium tracking-[-0.015em]`,j3=`bg-sunken inline-flex max-w-full flex-wrap gap-0.5 self-start rounded-lg border p-0.5`,M3=e=>A(`h-7 rounded-md px-2.5 text-[0.8125rem] font-medium hover:bg-transparent dark:hover:bg-transparent`,e?`bg-card text-foreground hover:bg-card dark:hover:bg-card shadow-xs`:`text-muted-foreground hover:text-foreground`);function N3({onStarted:e,onFreeChat:t}){let n=(0,v.useId)(),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(),l=w3();return(0,j.jsxs)(`form`,{onSubmit:async t=>{t.preventDefault();let n=r.trim();if(!n||a)return;o(!0),c(void 0);let i=await mN(n);if(o(!1),!i.ok)return c(i.error);e({session:i.value.session,goal:n})},className:`m-auto flex w-full max-w-xl flex-col gap-5 p-4 sm:p-6`,children:[(0,j.jsxs)(`div`,{className:`flex flex-col gap-2 text-center`,children:[(0,j.jsx)(`h2`,{className:`font-heading text-[2rem] leading-[1.08] font-normal tracking-[-0.024em] text-balance`,children:`What do you want to learn?`}),(0,j.jsx)(I2,{id:`${n}-description`,className:`text-center text-[0.95rem]`,children:`Mivra asks a few quick questions to see what you already know, then plans a course of short lessons.`})]}),(0,j.jsxs)(P2,{"data-invalid":!!s,className:`bg-card border-border-strong shadow-paper rounded-xl border p-4 sm:p-5`,children:[(0,j.jsx)(F2,{htmlFor:n,className:D3,children:`Learning goal`}),(0,j.jsxs)(`div`,{className:`flex gap-2 max-[480px]:flex-col`,children:[(0,j.jsx)(z2,{id:n,"aria-describedby":`${n}-description${s?` ${n}-error`:``}`,"aria-invalid":!!s,value:r,onChange:e=>i(e.target.value),maxLength:300,placeholder:`e.g. Calculus for machine learning`,className:`bg-card dark:bg-card h-10 text-base md:text-base`,autoFocus:!0}),(0,j.jsxs)(M,{type:`submit`,className:`h-10 px-5`,disabled:!r.trim()||a,children:[a&&(0,j.jsx)(R2,{"aria-hidden":`true`}),a?`Starting…`:`Start`]})]}),s&&(0,j.jsx)(L2,{id:`${n}-error`,role:`alert`,children:s})]}),(0,j.jsx)(`div`,{className:`flex justify-center`,children:(0,j.jsx)(E3,{state:l,disabled:a})}),(0,j.jsx)(M,{type:`button`,variant:`link`,className:`text-muted-foreground self-center`,onClick:t,children:`Or just chat`})]})}var P3={memory:`From memory`,test:`From the test`,guess:`Guessed`};function F3({course:e,children:t,onUndo:n}){let[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(),l=e.syllabus;return(0,j.jsxs)(O2,{open:r,onOpenChange:i,className:`bg-sunken/60 shrink-0 border-b`,"aria-label":`Course`,role:`region`,children:[(0,j.jsxs)(`div`,{className:`mx-auto flex max-w-3xl items-center gap-x-2 gap-y-1 px-4 py-2 text-sm max-sm:flex-wrap`,children:[(0,j.jsx)(Uh,{className:`text-muted-foreground size-4 shrink-0`,"aria-hidden":!0}),(0,j.jsx)(`span`,{className:`min-w-0 truncate font-medium max-sm:min-w-48`,children:e.goal}),(0,j.jsx)(D2,{variant:`outline`,className:`border-border-strong bg-card shrink-0 font-mono text-[0.6875rem] font-medium tracking-[0.06em] uppercase`,children:e.status===`interviewing`?`Placement interview`:e.status===`complete`?`Complete`:`In progress`}),l&&(0,j.jsx)(k2,{asChild:!0,children:(0,j.jsxs)(M,{variant:`ghost`,size:`sm`,className:`ml-auto shrink-0`,children:[`Syllabus · `,l.topics.length,` topics`,(0,j.jsx)(Ym,{className:A(`transition-transform`,r&&`rotate-180`),"aria-hidden":!0})]})}),t&&(0,j.jsx)(`div`,{className:A(`flex shrink-0 gap-2`,!l&&`ml-auto`),children:t})]}),l?.canUndo&&(0,j.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-wrap items-center gap-2 px-4 pb-2 text-sm`,role:`status`,children:[(0,j.jsxs)(`span`,{children:[`Mivra changed the plan: `,l.reason]}),n&&(0,j.jsx)(M,{variant:`outline`,size:`xs`,disabled:a,onClick:async()=>{o(!0),c(await n()),o(!1)},children:`Undo`}),s&&(0,j.jsx)(`span`,{className:`text-destructive`,children:s})]}),l&&(0,j.jsx)(A2,{children:(0,j.jsx)(`div`,{className:`mx-auto max-w-3xl px-4 pt-1 pb-4`,children:(0,j.jsxs)(`div`,{className:`bg-card border-border-strong shadow-paper focus-visible:ring-ring/50 flex max-h-[50svh] flex-col gap-4 overflow-y-auto overscroll-contain rounded-xl border px-4 py-3 outline-none focus-visible:ring-[3px]`,role:`region`,"aria-label":`Syllabus`,tabIndex:0,children:[l.reason&&l.version>1&&(0,j.jsxs)(`p`,{className:`text-muted-foreground`,role:`status`,children:[`Version `,l.version,l.source===`adaptive`?` (changed by Mivra)`:``,`: `,l.reason]}),(0,j.jsx)(`ol`,{className:`flex flex-col`,"aria-label":`Syllabus topics`,children:l.topics.map((e,t)=>(0,j.jsxs)(`li`,{className:A(`flex gap-3 border-t py-3 first:border-t-0`,l.changedTopicIds.includes(e.id)&&`bg-sunken -mx-4 px-4`),children:[(0,j.jsx)(`span`,{"aria-hidden":`true`,className:`bg-sunken text-muted-foreground ring-border-strong mt-0.5 grid size-6 shrink-0 place-items-center rounded-full font-mono text-[0.7rem] font-medium ring-1 ring-inset`,children:t+1}),(0,j.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5 wrap-anywhere`,children:[(0,j.jsxs)(`p`,{className:`font-heading text-[1.0625rem] leading-snug font-medium`,children:[e.title,l.changedTopicIds.includes(e.id)&&(0,j.jsxs)(D2,{variant:`secondary`,className:`ml-2 align-middle`,children:[`Changed in v`,l.version]}),e.requestedByLearner&&(0,j.jsx)(D2,{variant:`secondary`,className:`ml-2 align-middle`,children:`You asked for this`})]}),(0,j.jsx)(`p`,{className:`text-muted-foreground`,children:e.summary}),(0,j.jsxs)(`p`,{className:`text-muted-foreground text-[0.8125rem] italic`,children:[`Why: `,e.reason]})]})]},e.id))}),l.known.length>0&&(0,j.jsxs)(`div`,{className:`border-t pt-3`,children:[(0,j.jsx)(`p`,{className:A(`text-muted-foreground font-mono text-[0.6875rem] leading-snug font-medium tracking-[0.09em] uppercase`,`mb-2`),children:`What Mivra thinks you know`}),(0,j.jsx)(`ul`,{className:`flex flex-col`,"aria-label":`What Mivra thinks you know`,children:l.known.map((e,t)=>(0,j.jsxs)(`li`,{className:`flex flex-wrap items-baseline gap-x-2 border-t py-1.5 first:border-t-0 wrap-anywhere`,children:[(0,j.jsx)(`span`,{children:e.concept}),(0,j.jsx)(D2,{variant:`outline`,className:`text-xs`,children:P3[e.source]}),(0,j.jsx)(`span`,{className:`text-muted-foreground`,children:e.note})]},t))})]})]})})})]})}var I3={sigma:Ug,calculator:zm,code:dh,terminal:t_,cpu:hh,database:_h,network:_g,shield:Vg,"flask-conical":Lh,atom:jm,dna:yh,leaf:$h,telescope:$g,globe:Vh,landmark:Yh,"book-open":Nm,"pen-tool":Dg,languages:Zh,music:Dh,palette:yg,camera:Vm,brain:Fm,users:a_,"chart-line":Gm,briefcase:Lm,scale:Fg,stethoscope:Yg,"heart-pulse":Gh,wrench:l_,dumbbell:Th};function L3({icon:e,...t}){let n=BA.safeParse(e),r=n.success?I3[n.data]:Uh;return(0,j.jsx)(r,{"data-icon":n.success?n.data:`graduation-cap`,...t})}function R3({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`skeleton`,className:A(`animate-pulse rounded-md bg-accent`,e),...t})}function z3(e){let[t,n]=(0,v.useState)(),[r,i]=(0,v.useState)(),a=(0,v.useRef)(void 0),o=(0,v.useCallback)(e=>{a.current=e.revision,n(e.lesson),i(void 0)},[]);return(0,v.useEffect)(()=>{let t=new AbortController;return a.current=void 0,n(void 0),(async()=>{let n=0;for(;!t.signal.aborted;){let r=await yN(e,a.current,t.signal);if(t.signal.aborted)return;if(r.ok){if(n=0,o(r.value),r.value.lesson.status===`finished`)return}else i(r.error),await new Promise(e=>setTimeout(e,Math.min(1e4,1e3*2**n++)))}})(),()=>t.abort()},[e,o]),{lesson:t,error:r,apply:o}}function B3(e){return e===`finished`?` (finished)`:e===`generating`?` (being written)`:e===`failed`?` (stopped)`:e?` (started)`:` (not started)`}function V3({lessons:e,selectedId:t,onSelect:n}){return(0,j.jsx)(`nav`,{"aria-label":`Lessons`,children:(0,j.jsx)(`ol`,{className:`flex flex-col gap-1 text-sm`,children:e.topics.map((e,r)=>{let i=e.lesson?.status;return(0,j.jsx)(`li`,{children:(0,j.jsxs)(`button`,{type:`button`,disabled:!e.lesson,"aria-current":e.lesson?.id===t?`page`:void 0,onClick:()=>e.lesson&&n(e.lesson.id),className:A(`flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left`,e.lesson?`hover:bg-accent`:`text-muted-foreground cursor-default`,e.lesson?.id===t&&`bg-accent font-medium`),children:[(0,j.jsx)(`span`,{className:`mt-0.5 shrink-0`,"aria-hidden":!0,children:i===`finished`?(0,j.jsx)(qm,{className:`text-success size-4`}):i===`generating`?(0,j.jsx)(R2,{"aria-hidden":`true`}):(0,j.jsx)(ah,{className:`size-4`})}),(0,j.jsxs)(`span`,{className:`min-w-0`,children:[r+1,`. `,e.title,(0,j.jsx)(`span`,{className:`sr-only`,children:B3(i)})]})]})},e.topicId)})})})}function H3({lessonId:e,nextTopic:t,onFinished:n,onStartNext:r,onExplain:i,onChange:a,onLoaded:o,onOpenSection:s,focusSectionId:c,courseComplete:l=!1}){let{lesson:u,error:d,apply:f}=z3(e),[p,m]=(0,v.useState)({}),[h,g]=(0,v.useState)(!1),[_,y]=(0,v.useState)(),b=(0,v.useRef)(o);b.current=o,(0,v.useEffect)(()=>{u&&b.current?.(u)},[u]);let x=!!u;if((0,v.useEffect)(()=>{if(!x||!c)return;let e=document.getElementById(`section-${c}`);e?.scrollIntoView({block:`start`}),e?.focus({preventScroll:!0})},[x,c]),!u)return d?(0,j.jsx)(`p`,{className:`text-destructive m-auto p-6`,children:d}):(0,j.jsxs)(`p`,{className:`text-muted-foreground m-auto flex items-center gap-2 p-6`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Loading the lesson…`]});let S=u.status===`generating`,C=u.status===`ready`,w=new Set(u.changedSectionIds),T=u.outline?u.outline.sections.slice(u.sections.length):[],E=async e=>{g(!0),y(void 0);let t=await e();return g(!1),t.ok?f(t.value):y(t.error),t.ok};return(0,j.jsxs)(`article`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-6 p-4 pb-16`,"aria-busy":S,"aria-labelledby":`lesson-title`,children:[(0,j.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[(0,j.jsxs)(`p`,{className:`text-muted-foreground text-sm`,children:[`Lesson `,u.position+1]}),(0,j.jsx)(`h2`,{id:`lesson-title`,className:`font-heading text-2xl font-semibold`,children:u.outline?.title??u.topicTitle}),u.status===`finished`&&(0,j.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Finished. This lesson won't change.`}),u.changeReason&&u.version&&u.version>1&&(0,j.jsxs)(`p`,{className:`text-muted-foreground text-sm`,role:`status`,children:[`Version `,u.version,`: `,u.changeReason]})]}),!u.outline&&S&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Planning the lesson…`]}),u.sections.map(t=>(0,j.jsxs)(`section`,{id:`section-${t.id}`,tabIndex:-1,"aria-label":t.title,"data-changed":w.has(t.id)||void 0,className:A(`group flex min-w-0 flex-col gap-2`,w.has(t.id)&&`bg-muted/60 -mx-3 rounded-lg px-3 py-2`),children:[(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,j.jsx)(`h3`,{className:`font-heading text-lg font-medium`,children:t.title}),w.has(t.id)&&(0,j.jsxs)(D2,{variant:`secondary`,children:[`Changed in v`,u.version]}),(i||a&&C)&&(0,j.jsxs)(`div`,{className:`ml-auto flex gap-1`,children:[i&&(0,j.jsxs)(M,{variant:`ghost`,size:`xs`,onClick:()=>i(t),"aria-label":`Explain: ${t.title}`,children:[(0,j.jsx)(sh,{"aria-hidden":!0}),` Explain`]}),a&&C&&(0,j.jsxs)(M,{variant:`ghost`,size:`xs`,onClick:()=>a(t),"aria-label":`Change: ${t.title}`,children:[(0,j.jsx)(kg,{"aria-hidden":!0}),` Change`]})]})]}),t.kind===`prose`?(0,j.jsxs)(j.Fragment,{children:[t.revisits.length>0&&(0,j.jsx)(`ul`,{className:`flex flex-wrap gap-2 text-sm`,"aria-label":`Revisits`,children:t.revisits.map(e=>(0,j.jsx)(`li`,{children:(0,j.jsxs)(M,{variant:`outline`,size:`xs`,onClick:()=>s?.(e.lessonId,e.sectionId),disabled:!s,children:[(0,j.jsx)(ph,{"aria-hidden":!0}),` `,e.lessonTitle,`: `,e.title]})},e.sectionId))}),(0,j.jsx)(rQ,{text:t.markdown})]}):(0,j.jsx)(b2,{data:t.artifact?.id?p[t.artifact.id]??t.artifact:t.artifact,replyInProgress:!1,onUpdate:e=>m(t=>T2(t,{[e.id]:e})),onRefresh:async()=>{let t=await yN(e);t.ok&&f(t.value)}})]},t.id)),S&&T.map((e,t)=>(0,j.jsxs)(`section`,{"aria-label":`${e.title} (being written)`,className:`flex flex-col gap-2`,children:[(0,j.jsx)(`h3`,{className:`font-heading text-muted-foreground text-lg font-medium`,children:e.title}),t===0?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Writing…`]}),(0,j.jsx)(R3,{className:`h-16 w-full`})]}):(0,j.jsx)(R3,{className:`h-4 w-1/3`})]},`pending-${t}`)),u.status===`failed`&&(0,j.jsxs)(T0,{variant:`destructive`,children:[(0,j.jsx)(E0,{children:u.error}),(0,j.jsxs)(D0,{children:[(0,j.jsxs)(`p`,{children:[`The sections above are kept. Mivra can carry on from here`,u.errorAction===`lesson-model`?` once the lesson model can be used`:``,`.`]}),(0,j.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:[u.errorAction===`lesson-model`&&(0,j.jsx)(M,{size:`sm`,variant:`outline`,onClick:()=>window.dispatchEvent(new Event(`mivra:open-settings`)),children:`Lesson model settings`}),(0,j.jsx)(M,{size:`sm`,disabled:h,onClick:()=>void E(()=>xN(e)),children:`Continue writing`})]})]})]}),(u.status===`ready`||u.status===`finished`)&&(0,j.jsxs)(`footer`,{className:`flex flex-col gap-3 border-t pt-4`,"aria-live":`polite`,children:[u.status===`ready`?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`p`,{className:`text-muted-foreground text-sm`,children:[u.checks.answered,` of `,u.checks.total,` checks answered.`,!u.canFinish&&` Answer every check to finish; your score doesn't matter.`]}),(0,j.jsx)(M,{className:`self-start`,disabled:!u.canFinish||h,onClick:async()=>{await E(()=>bN(e))&&n()},children:`Finish lesson`})]}):t?(0,j.jsxs)(M,{className:`self-start`,disabled:h,onClick:async()=>{g(!0),await r(t.id),g(!1)},children:[`Next lesson: `,t.title]}):l?(0,j.jsx)(`p`,{className:`font-medium`,children:`You've reached the end of the syllabus.`}):null,_&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,children:_})]}),d&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,children:d})]})}function U3({delayDuration:e=0,...t}){return(0,j.jsx)(Wp,{"data-slot":`tooltip-provider`,delayDuration:e,...t})}function W3({...e}){return(0,j.jsx)(Jp,{"data-slot":`tooltip`,...e})}function G3({...e}){return(0,j.jsx)(Xp,{"data-slot":`tooltip-trigger`,...e})}function K3({className:e,sideOffset:t=0,children:n,...r}){return(0,j.jsx)(em,{children:(0,j.jsxs)(nm,{"data-slot":`tooltip-content`,sideOffset:t,className:A(`z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95`,e),...r,children:[n,(0,j.jsx)(om,{className:`z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground`})]})})}var q3=`Only text is read: images and diagrams aren't, and formulas may come through garbled.`,J3=new Set;function Y3(e){let[t,n]=(0,v.useState)([]),[r,i]=(0,v.useState)(),[a,o]=(0,v.useState)(),s=(0,v.useRef)(e);s.current=e;let c=(0,v.useRef)(!0);(0,v.useEffect)(()=>(c.current=!0,()=>{c.current=!1}),[]),(0,v.useEffect)(()=>{n([]),i(void 0),o(void 0);let t=!1,r=()=>void tN(e).then(e=>{t||(e.ok?n(t=>[...e.value,...t.filter(t=>!e.value.some(e=>e.id===t.id))]):o(e.error))});r();let a=t=>{t===e&&r()};return J3.add(a),()=>{t=!0,J3.delete(a)}},[e]);let l=(0,v.useCallback)(async()=>{let t=await tN(e);c.current&&s.current===e&&(t.ok?n(e=>[...t.value,...e.filter(e=>!t.value.some(t=>t.id===e.id))]):o(t.error))},[e]);return{documents:t,uploading:r,error:a,upload:(0,v.useCallback)(async t=>{if(o(void 0),t.size>26214400)return o(`${t.name} is over the ${tM/1048576} MB limit.`);i(t.name);let r=await nN(e,t);if(c.current)s.current===e&&(i(void 0),r.ok?n(e=>[...e.filter(e=>e.id!==r.value.id),r.value]):o(r.error));else if(r.ok)for(let t of J3)t(e)},[e]),remove:(0,v.useCallback)(async t=>{o(void 0);let r=await rN(t);s.current===e&&(r.ok?n(e=>e.filter(e=>e.id!==t)):o(r.error))},[e]),refresh:l}}function X3({kind:e,pageCount:t,pagesWithText:n}){let r=`${t} ${e===`pptx`?`slide`:`page`}${t===1?``:`s`}`;return n<t?`${r}, ${n} with text`:r}function Z3({documents:{uploading:e,upload:t}}){let n=(0,v.useRef)(null);return(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`input`,{ref:n,type:`file`,accept:`.pdf,.pptx`,className:`hidden`,"data-testid":`document-input`,onChange:e=>{let n=e.target.files?.[0];e.target.value=``,n&&t(n)}}),(0,j.jsx)(U3,{delayDuration:400,children:(0,j.jsxs)(W3,{children:[(0,j.jsx)(G3,{asChild:!0,children:(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`Attach a PDF or PowerPoint file`,disabled:e!==void 0,onClick:()=>n.current?.click(),children:e===void 0?(0,j.jsx)(Cg,{"aria-hidden":`true`}):(0,j.jsx)(R2,{"aria-hidden":`true`})})}),(0,j.jsx)(K3,{children:`Attach a PDF or PowerPoint file`})]})})]})}function Q3({documents:{documents:e,uploading:t,error:n,remove:r},messageId:i}){let a=e.filter(e=>(e.messageId??void 0)===i);return i&&(t=void 0,n=void 0),a.length===0&&t===void 0&&!n?null:(0,j.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-col gap-1.5 px-3 pt-3 text-sm`,children:[a.length>0&&(0,j.jsx)(`ul`,{"aria-label":`Attached documents`,className:`flex flex-wrap gap-1.5`,children:a.map(e=>(0,j.jsxs)(`li`,{className:`bg-muted text-foreground flex max-w-full min-w-0 flex-wrap items-center gap-1.5 rounded-md border py-0.5 pr-0.5 pl-2`,children:[(0,j.jsx)(Fh,{className:`text-muted-foreground size-3.5 shrink-0`,"aria-hidden":!0}),(0,j.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.filename,children:e.filename}),(0,j.jsx)(`span`,{className:`text-muted-foreground shrink-0 text-xs`,children:X3(e)}),(0,j.jsx)(U3,{delayDuration:400,children:(0,j.jsxs)(W3,{children:[(0,j.jsx)(G3,{asChild:!0,children:(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`icon`,className:`size-6`,"aria-label":`Remove ${e.filename}`,onClick:()=>void r(e.id),children:(0,j.jsx)(d_,{"aria-hidden":`true`})})}),(0,j.jsx)(K3,{children:`Remove attachment`})]})})]},e.id))}),t!==void 0&&(0,j.jsxs)(`p`,{role:`status`,className:`text-muted-foreground flex min-w-0 items-center gap-2`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),(0,j.jsxs)(`span`,{className:`truncate`,children:[`Reading `,t,`…`]})]}),n&&(0,j.jsx)(`p`,{role:`alert`,className:`text-destructive wrap-anywhere`,children:n}),a.length>0&&!i&&(0,j.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:q3})]})}var $3=(0,v.createContext)(null),e6=()=>{let e=(0,v.useContext)($3);if(!e)throw Error(`ChainOfThought components must be used within ChainOfThought`);return e},t6=(0,v.memo)(({className:e,open:t,defaultOpen:n=!1,onOpenChange:r,children:i,...a})=>{let[o,s]=Qn({prop:t,defaultProp:n,onChange:r}),c=(0,v.useMemo)(()=>({isOpen:o}),[o]);return(0,j.jsx)($3.Provider,{value:c,children:(0,j.jsx)(O2,{asChild:!0,open:o,onOpenChange:s,children:(0,j.jsx)(`div`,{className:A(`not-prose min-w-0 max-w-prose space-y-4`,e),...a,children:i})})})}),n6=(0,v.memo)(({className:e,children:t,...n})=>{let{isOpen:r}=e6();return(0,j.jsxs)(k2,{className:A(`flex min-w-0 w-full items-center gap-2 rounded-sm text-muted-foreground text-sm hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,e),...n,children:[(0,j.jsx)(Fm,{"aria-hidden":`true`,className:`size-4 shrink-0`}),(0,j.jsx)(`span`,{className:`min-w-0 flex-1 text-left wrap-anywhere`,children:t??`Chain of Thought`}),(0,j.jsx)(Ym,{"aria-hidden":`true`,className:A(`size-4 shrink-0`,r?`rotate-180`:`rotate-0`)})]})}),r6=(0,v.memo)(({className:e,icon:t=xh,label:n,description:r,status:i=`complete`,children:a,...o})=>(0,j.jsxs)(`div`,{className:A(`flex min-w-0 gap-2 text-sm`,{complete:`text-muted-foreground`,active:`text-foreground`,pending:`text-muted-foreground/50`}[i],e),...o,children:[(0,j.jsxs)(`div`,{"aria-hidden":`true`,className:`relative mt-0.5 shrink-0`,children:[(0,j.jsx)(t,{className:`size-4`}),(0,j.jsx)(`div`,{className:`-mx-px absolute top-7 bottom-0 left-1/2 w-px bg-border`})]}),(0,j.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-2 wrap-anywhere`,children:[(0,j.jsx)(`div`,{children:n}),r&&(0,j.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:r}),a]})]})),i6=(0,v.memo)(({className:e,children:t,...n})=>(0,j.jsx)(A2,{className:A(`mt-2 min-w-0 space-y-3 text-foreground outline-none`,e),...n,children:t}));t6.displayName=`ChainOfThought`,n6.displayName=`ChainOfThoughtHeader`,r6.displayName=`ChainOfThoughtStep`,i6.displayName=`ChainOfThoughtContent`;function a6({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`empty`,className:A(`flex min-w-0 flex-1 flex-col items-center justify-center gap-6 rounded-lg border-dashed p-6 text-center text-balance md:p-12`,e),...t})}function o6({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`empty-header`,className:A(`flex max-w-sm flex-col items-center gap-2 text-center`,e),...t})}var s6=ce(`mb-2 flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0`,{variants:{variant:{default:`bg-transparent`,icon:`flex size-10 shrink-0 items-center justify-center rounded-lg bg-muted text-foreground [&_svg:not([class*='size-'])]:size-6`}},defaultVariants:{variant:`default`}});function c6({className:e,variant:t=`default`,...n}){return(0,j.jsx)(`div`,{"data-slot":`empty-icon`,"data-variant":t,className:A(s6({variant:t,className:e})),...n})}function l6({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`empty-title`,className:A(`text-lg font-medium tracking-tight`,e),...t})}function u6({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`empty-description`,className:A(`text-sm/relaxed text-muted-foreground [&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary`,e),...t})}function d6({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`empty-content`,className:A(`flex w-full max-w-sm min-w-0 flex-col items-center gap-4 text-sm text-balance`,e),...t})}function f6({...e}){return(0,j.jsx)(eo,{"data-slot":`sheet`,...e})}function p6({...e}){return(0,j.jsx)(oo,{"data-slot":`sheet-portal`,...e})}function m6({className:e,...t}){return(0,j.jsx)(co,{"data-slot":`sheet-overlay`,className:A(`fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0`,e),...t})}function h6({className:e,children:t,side:n=`right`,showCloseButton:r=!0,...i}){return(0,j.jsxs)(p6,{children:[(0,j.jsx)(m6,{}),(0,j.jsxs)(po,{"data-slot":`sheet-content`,className:A(`fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:animate-in data-[state=open]:duration-500`,n===`right`&&`inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm`,n===`left`&&`inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm`,n===`top`&&`inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top`,n===`bottom`&&`inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom`,e),...i,children:[t,r&&(0,j.jsxs)(bo,{className:`absolute top-4 right-4 rounded-xs opacity-70 after:absolute after:-inset-3 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-secondary`,children:[(0,j.jsx)(d_,{className:`size-4`}),(0,j.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function g6({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`sheet-header`,className:A(`flex flex-col gap-1.5 p-4`,e),...t})}function _6({className:e,...t}){return(0,j.jsx)(_o,{"data-slot":`sheet-title`,className:A(`font-semibold text-foreground`,e),...t})}function v6({className:e,...t}){return(0,j.jsx)(vo,{"data-slot":`sheet-description`,className:A(`text-sm text-muted-foreground`,e),...t})}function y6({className:e,value:t,...n}){return(0,j.jsx)(cf,{"data-slot":`progress`,className:A(`relative h-2 w-full overflow-hidden rounded-full bg-primary/20`,e),...n,children:(0,j.jsx)(uf,{"data-slot":`progress-indicator`,className:`h-full w-full flex-1 bg-primary transition-all`,style:{transform:`translateX(-${100-(t||0)}%)`}})})}function b6(){let[e,t]=(0,v.useState)({step:`idle`}),n=async()=>{t({step:`busy`});let e=await eP();t(e.ok?{step:`done`,filename:e.filename}:{step:`error`,error:e.error})};return(0,j.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,j.jsxs)(M,{type:`button`,variant:`outline`,className:`self-start`,disabled:e.step===`busy`,onClick:()=>void n(),children:[e.step===`busy`?(0,j.jsx)(R2,{"aria-hidden":`true`}):(0,j.jsx)(Ch,{"aria-hidden":`true`}),`Export to Obsidian`]}),(0,j.jsx)(`p`,{className:`text-muted-foreground text-sm`,role:`status`,children:e.step===`done`?`Downloaded ${e.filename}. Unzip it into your vault: it adds a Mivra folder of concepts and memories that link to your notes.`:`Concepts and memories as linked notes, for your Obsidian vault. Your own notes aren't included.`}),e.step===`error`&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,children:e.error})]})}var x6=cM*4,S6=1048576;function C6(e){let t=(e.webkitRelativePath||e.name).split(`/`);return t.length<2?{folder:void 0,path:t[0]}:{folder:t[0],path:t.slice(1).join(`/`)}}function w6(e){let t,n=[],r=[],i=0,a=0;for(let o of Array.from(e)){let e=C6(o);t??=e.folder;let{path:s}=e;if(!s.split(`/`).some(e=>e.startsWith(`.`)||e===``)){if(!/\.md$/i.test(s))i++;else if(o.size>x6)r.push(s);else{if(n.length>=1e4)return{ok:!1,error:`This folder has more than ${sM.toLocaleString(`en`)} notes, more than one import can take.`};if(a+=o.size,a>67108864)return{ok:!1,error:`This folder's notes come to more than ${lM/S6} MB, more than one import can take.`};n.push({path:s,file:o})}}}return n.sort((e,t)=>e.path.localeCompare(t.path)),{ok:!0,folder:t,notes:n,tooLong:r,notMarkdown:i}}async function T6(e,t){let n=w6(e);if(!n.ok)return n;let{folder:r,notes:i,notMarkdown:a}=n,o=[...n.tooLong],s=[];t?.(0,i.length);for(let[e,{path:n,file:r}]of i.entries()){let a;try{a=await r.text()}catch{return{ok:!1,error:`Couldn't read ${n}. It may have been moved or deleted; choose the folder again.`}}a.length>1e6?o.push(n):s.push({path:n,text:a}),t?.(e+1,i.length)}return{ok:!0,vault:{folder:r,files:s,notMarkdown:a,tooLong:o}}}var E6=(e,t,n=`${t}s`)=>`${e.toLocaleString(`en`)} ${e===1?t:n}`,D6=1500,O6=e=>e.status===`queued`||e.status===`running`;function k6({open:e,onOpenChange:t,onOpenGraph:n}){let r=(0,v.useRef)(!1),[i,a]=(0,v.useState)(),[o,s]=(0,v.useState)(),[c,l]=(0,v.useState)({open:!1,key:0}),u=e=>l(t=>({open:!0,key:t.key+1,...e?{reimport:e}:{}}));(0,v.useEffect)(()=>{if(!e)return;let t=!1;return a(void 0),s(void 0),l(e=>({...e,open:!1})),iN().then(e=>{t||(e.ok?a(e.value):s(e.error))}),()=>{t=!0}},[e]);let d=({import:e})=>a((t=[])=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e]),f=(e,t)=>a(n=>n?.map(n=>n.id===e?{...n,distillation:t}:n)),p=!!i?.some(e=>O6(e.distillation));return(0,v.useEffect)(()=>{if(!e||!p)return;let t=!1,n=setInterval(()=>{iN().then(e=>{!t&&e.ok&&a(e.value)})},D6);return()=>{t=!0,clearInterval(n)}},[e,p]),(0,j.jsxs)(f6,{open:e,onOpenChange:t,children:[(0,j.jsxs)(h6,{className:`w-full overflow-y-auto sm:max-w-md`,onCloseAutoFocus:e=>{e.preventDefault(),r.current?(r.current=!1,document.querySelector(`[data-notes-graph-start]`)?.focus()):(document.querySelector(`[data-imports-trigger]`)??document.querySelector(`[data-sidebar="trigger"]`))?.focus()},children:[(0,j.jsxs)(g6,{children:[(0,j.jsx)(_6,{className:`font-heading`,children:`Imported notes`}),(0,j.jsx)(v6,{children:`Notes from your Obsidian vaults. They're read-only here: edit them in Obsidian, then re-import the vault.`})]}),(0,j.jsxs)(`div`,{className:`flex flex-col gap-4 px-4 pb-4`,"aria-live":`polite`,children:[i&&i.length>0&&(0,j.jsxs)(M,{type:`button`,className:`self-start`,onClick:()=>u(),children:[(0,j.jsx)(zh,{"aria-hidden":`true`}),`Import a vault`]}),i&&i.length>0&&(0,j.jsx)(b6,{}),o&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,children:o}),!i&&!o&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Loading imports…`]}),i?.length===0&&(0,j.jsxs)(a6,{className:`border p-6 md:p-6`,children:[(0,j.jsxs)(o6,{children:[(0,j.jsx)(c6,{variant:`icon`,children:(0,j.jsx)(tg,{"aria-hidden":`true`})}),(0,j.jsx)(l6,{children:`No vaults imported yet`}),(0,j.jsx)(u6,{children:`Import an Obsidian vault to bring its notes, links and tags into Mivra. Only Markdown notes are read.`})]}),(0,j.jsx)(d6,{children:(0,j.jsxs)(M,{type:`button`,onClick:()=>u(),children:[(0,j.jsx)(zh,{"aria-hidden":`true`}),`Import a vault`]})})]}),i&&i.length>0&&(0,j.jsx)(`ul`,{className:`flex flex-col gap-2`,"aria-label":`Imported vaults`,children:i.map(e=>(0,j.jsx)(A6,{entry:e,onReimport:()=>u(e),onGraph:n&&(()=>{r.current=!0,n(e.id),t(!1)}),onDelete:()=>a(t=>t?.filter(t=>t.id!==e.id)),onDistillation:t=>f(e.id,t)},e.id))})]})]}),(0,j.jsx)(P6,{open:c.open,onOpenChange:e=>{e||l(e=>({...e,open:!1}))},imports:i??[],...c.reimport?{reimport:c.reimport}:{},onImported:d},c.key)]})}function A6({entry:e,onReimport:t,onGraph:n,onDelete:r,onDistillation:i}){let[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(),d=async()=>{c(!0),u(void 0);let t=await aN(e.id);c(!1),t.ok?r():u(t.error)};return(0,j.jsxs)(`li`,{className:`flex flex-col gap-2 rounded-lg border p-3 text-sm wrap-anywhere`,"aria-label":e.name,children:[(0,j.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,j.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,j.jsxs)(`span`,{className:`text-muted-foreground text-xs`,children:[E6(e.noteCount,`note`),` · Updated `,new Date(e.updatedAt).toLocaleDateString()]})]}),(0,j.jsx)(j6,{entry:e,onChange:i}),a?(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,j.jsxs)(`span`,{className:`text-muted-foreground`,children:[`Delete this import and its `,E6(e.noteCount,`note`),`, with the concepts and memories drawn from them? Your vault itself isn't touched.`]}),(0,j.jsxs)(M,{type:`button`,variant:`destructive`,size:`sm`,disabled:s,onClick:()=>void d(),children:[s&&(0,j.jsx)(R2,{"aria-hidden":`true`}),`Yes, delete`]}),(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,disabled:s,onClick:()=>o(!1),children:`Keep`})]}):(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[n&&e.noteCount>0&&(0,j.jsxs)(M,{type:`button`,variant:`outline`,size:`sm`,onClick:n,children:[(0,j.jsx)(s_,{"aria-hidden":`true`}),`Graph`]}),(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,onClick:t,children:`Re-import`}),(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>o(!0),children:`Delete`})]}),l&&(0,j.jsx)(`p`,{className:`text-destructive`,role:`alert`,children:l})]})}function j6({entry:e,onChange:t}){let n=e.distillation,[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(),s=async n=>{i(!0),o(void 0);let r=await n(e.id);i(!1),r.ok?t(r.value):o(r.error)},c=`${E6(n.concepts,`concept`)} and ${E6(n.memories,`memory`,`memories`)} drawn from these notes`,l;if(O6(n)){let e=n.groups>0?Math.round(n.groupsDone/n.groups*100):0;l=(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),n.status===`queued`?`Waiting to read these notes for concepts…`:n.groups>0?`Reading notes for concepts… group ${Math.min(n.groupsDone+1,n.groups).toLocaleString(`en`)} of ${n.groups.toLocaleString(`en`)}`:`Reading notes for concepts…`]}),(0,j.jsx)(y6,{value:e,"aria-label":`Reading notes for concepts`}),(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,className:`self-start`,disabled:r,onClick:()=>void s(sN),children:`Cancel`})]})}else if(n.pendingNotes>0){let e=n.status===`failed`?`Reading notes for concepts stopped: ${n.error??`the model request failed.`}`:n.status===`cancelled`?`Cancelled. ${E6(n.pendingNotes,`note`)} not read for concepts yet.`:`${E6(n.pendingNotes,`note`)} not read for concepts yet.`;l=(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`p`,{className:n.status===`failed`?`text-destructive`:`text-muted-foreground`,children:e}),(n.concepts>0||n.memories>0)&&(0,j.jsxs)(`p`,{className:`text-muted-foreground`,children:[`So far: `,c,`.`]}),(0,j.jsxs)(M,{type:`button`,variant:`outline`,size:`sm`,className:`self-start`,disabled:r,onClick:()=>void s(oN),children:[r&&(0,j.jsx)(R2,{"aria-hidden":`true`}),n.status===`failed`?`Try again`:n.status===`cancelled`?`Resume`:`Read notes`]})]})}else if(n.concepts>0||n.memories>0)l=(0,j.jsxs)(`p`,{className:`text-muted-foreground`,children:[c[0].toUpperCase()+c.slice(1),`.`]});else return null;return(0,j.jsxs)(`div`,{className:`flex flex-col gap-2`,role:`group`,"aria-label":`Concepts from these notes`,children:[l,a&&(0,j.jsx)(`p`,{className:`text-destructive`,role:`alert`,children:a})]})}var M6=e=>e.replace(/\.zip$/i,``).trim(),N6=e=>(e.kind===`zip`?M6(e.file.name):e.vault.folder??``).slice(0,120);function P6({open:e,onOpenChange:t,imports:n,reimport:r,onImported:i}){let a=(0,v.useId)(),o=(0,v.useRef)(null),s=(0,v.useRef)(null),[c,l]=(0,v.useState)({step:`choose`}),[u,d]=(0,v.useState)(``),f=(0,v.useRef)(0);(0,v.useEffect)(()=>{e&&(f.current++,l({step:`choose`}),d(``))},[e]);let p=r??n.find(e=>e.name===u.trim()),m=p?{importId:p.id}:{name:u.trim()},h=async e=>{let t=++f.current;l({step:`reading`,read:0,total:0});let n=await T6(e,(e,n)=>{f.current===t&&l({step:`reading`,read:e,total:n})});if(f.current!==t)return;if(!n.ok)return l({step:`choose`,error:n.error});if(n.vault.files.length===0)return l({step:`choose`,error:`No Markdown notes were found in this folder. Choose the folder that holds your vault's notes.`});let r={kind:`folder`,vault:n.vault};d(N6(r)),l({step:`ready`,source:r})},g=e=>{f.current++;let t={kind:`zip`,file:e};d(N6(t)),l({step:`ready`,source:t})},_=async e=>{if(e.preventDefault(),c.step!==`ready`)return;let{source:t}=c,n=++f.current;l({step:`sending`,source:t});let r=t.kind===`zip`?await pN(m,t.file):await fN(m,t.vault.files);if(f.current===n){if(!r.ok)return l({step:`ready`,source:t,error:r.error});i(r.value),l({step:`done`,result:r.value,source:t,replaced:!!p})}},y=r?`Re-import ${r.name}`:`Import an Obsidian vault`;return(0,j.jsx)(F4,{open:e,onOpenChange:t,children:(0,j.jsxs)(R4,{className:`sm:max-w-lg`,children:[(0,j.jsxs)(z4,{children:[(0,j.jsx)(V4,{className:`font-heading wrap-anywhere`,children:y}),(0,j.jsx)(H4,{children:r?`Choose the same vault again. Changed notes are updated, new ones added, and notes that are gone from it removed.`:`Choose your vault's folder. Only Markdown notes are read; attachments and hidden folders such as .obsidian are left out.`})]}),(0,j.jsx)(`input`,{ref:o,type:`file`,multiple:!0,className:`hidden`,"data-testid":`vault-folder-input`,webkitdirectory:``,onChange:e=>{let t=e.target.files;t&&t.length>0&&h(t),e.target.value=``}}),(0,j.jsx)(`input`,{ref:s,type:`file`,accept:`.zip,application/zip`,className:`hidden`,"data-testid":`vault-zip-input`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&g(t)}}),c.step===`choose`&&(0,j.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,j.jsxs)(P2,{"data-invalid":!!c.error,children:[(0,j.jsxs)(M,{type:`button`,onClick:()=>o.current?.click(),children:[(0,j.jsx)(zh,{"aria-hidden":`true`}),`Choose vault folder`]}),c.error&&(0,j.jsx)(L2,{role:`alert`,children:c.error})]}),(0,j.jsxs)(`p`,{className:`text-muted-foreground text-sm`,children:[`Can't choose a folder on this device?`,` `,(0,j.jsx)(M,{type:`button`,variant:`link`,className:`h-auto p-0`,onClick:()=>s.current?.click(),children:`Upload a .zip instead`})]})]}),c.step===`reading`&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),c.total>0?`Reading notes… ${c.read.toLocaleString(`en`)} of ${c.total.toLocaleString(`en`)}`:`Looking through the folder…`]}),(c.step===`ready`||c.step===`sending`)&&(0,j.jsxs)(`form`,{onSubmit:_,className:`flex flex-col gap-4`,children:[(0,j.jsx)(F6,{source:c.source}),!r&&(0,j.jsxs)(P2,{"data-invalid":c.step===`ready`&&!!c.error,children:[(0,j.jsx)(F2,{htmlFor:a,children:`Import name`}),(0,j.jsx)(z2,{id:a,value:u,maxLength:120,disabled:c.step===`sending`,onChange:e=>d(e.target.value),"aria-describedby":`${a}-description`}),(0,j.jsx)(I2,{id:`${a}-description`,children:p?`An import called ${p.name} already exists, so this re-imports it: changed notes are updated and notes that are gone are removed.`:`Tells your imports apart. Import the same vault under this name again to update it.`})]}),c.step===`ready`&&c.error&&(0,j.jsx)(L2,{role:`alert`,className:`wrap-anywhere`,children:c.error}),c.step===`sending`&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),c.source.kind===`zip`?`Uploading and unpacking the zip…`:`Sending ${E6(c.source.vault.files.length,`note`)}…`]}),(0,j.jsxs)(B4,{children:[(0,j.jsx)(M,{type:`button`,variant:`outline`,disabled:c.step===`sending`,onClick:()=>l({step:`choose`}),children:`Choose again`}),(0,j.jsxs)(M,{type:`submit`,disabled:c.step===`sending`||!r&&!u.trim(),children:[c.step===`sending`&&(0,j.jsx)(R2,{"aria-hidden":`true`}),p?`Re-import`:`Import`]})]})]}),c.step===`done`&&(0,j.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,j.jsx)(L6,{result:c.result,source:c.source,replaced:c.replaced}),(0,j.jsx)(B4,{children:(0,j.jsx)(M,{type:`button`,onClick:()=>t(!1),children:`Done`})})]})]})})}function F6({source:e}){if(e.kind===`zip`)return(0,j.jsxs)(`p`,{className:`flex items-center gap-2 text-sm wrap-anywhere`,children:[(0,j.jsx)(Nh,{className:`text-muted-foreground size-4 shrink-0`,"aria-hidden":`true`}),e.file.name,` (`,(e.file.size/1048576).toFixed(1),` MB)`]});let{vault:t}=e,n=[t.notMarkdown>0&&E6(t.notMarkdown,`other file`),t.tooLong.length>0&&E6(t.tooLong.length,`note`)+` too long to import`].filter(Boolean);return(0,j.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[(0,j.jsxs)(`p`,{className:`flex items-center gap-2 wrap-anywhere`,children:[(0,j.jsx)(zh,{className:`text-muted-foreground size-4 shrink-0`,"aria-hidden":`true`}),E6(t.files.length,`note`),` found`,t.folder?` in ${t.folder}`:``]}),n.length>0&&(0,j.jsxs)(`p`,{className:`text-muted-foreground`,children:[`Left out: `,n.join(`, `),`.`]})]})}var I6={not_markdown:`not a note`,hidden:`hidden`,bad_path:`unsafe path`,duplicate:`duplicate`,too_long:`too long`,symlink:`link to another file`,generated:`exported by Mivra`};function L6({result:e,source:t,replaced:n}){let r=t.kind===`folder`?t.vault.tooLong:[],i=t.kind===`folder`?t.vault.notMarkdown:0,a=[...r.map(e=>({path:e,reason:`too_long`})),...e.skipped],o=e.skippedCount+r.length+i,s=[[`Added`,e.added],[`Updated`,e.updated],[`Removed`,e.removed],[`Unchanged`,e.unchanged]];return(0,j.jsxs)(`div`,{className:`flex flex-col gap-3 text-sm`,role:`status`,children:[(0,j.jsxs)(`p`,{className:`wrap-anywhere`,children:[n?`Re-imported`:`Imported`,` `,(0,j.jsx)(`span`,{className:`font-medium`,children:e.import.name}),`: `,E6(e.import.noteCount,`note`),` in all.`]}),(0,j.jsx)(`dl`,{className:`grid grid-cols-4 gap-2`,"aria-label":`What changed`,children:s.map(([e,t])=>(0,j.jsxs)(`div`,{className:`bg-muted flex flex-col rounded-md px-2 py-1.5`,children:[(0,j.jsx)(`dt`,{className:`text-muted-foreground text-xs`,children:e}),(0,j.jsx)(`dd`,{className:`font-medium tabular-nums`,children:t.toLocaleString(`en`)})]},e))}),o>0&&(0,j.jsxs)(`div`,{className:`text-muted-foreground flex flex-col gap-1`,children:[(0,j.jsxs)(`p`,{children:[`Skipped `,E6(o,`file`),i>0?`, including ${E6(i,`attachment or other file`,`attachments and other files`)}`:``,`.`]}),a.length>0&&(0,j.jsxs)(`ul`,{className:`list-disc pl-5 wrap-anywhere`,children:[a.slice(0,5).map(e=>(0,j.jsxs)(`li`,{children:[e.path,` (`,I6[e.reason],`)`]},`${e.path}:${e.reason}`)),a.length>5&&(0,j.jsx)(`li`,{children:`…`})]})]}),e.truncated&&(0,j.jsx)(`p`,{className:`text-muted-foreground`,children:`Some links or tags were left out: a note or the vault had more than Mivra keeps.`}),O6(e.import.distillation)&&(0,j.jsx)(`p`,{className:`text-muted-foreground`,children:`Mivra is now reading the new and changed notes for concepts and memories, using your model. Follow or cancel it in the list.`})]})}var R6=[{kind:`goal`,title:`Goals`},{kind:`preference`,title:`Preferences`},{kind:`misconception`,title:`Misconceptions`},{kind:`known`,title:`Known from your notes`}],z6=[{value:`all`,label:`All`},{value:`import`,label:`From notes`},{value:`other`,label:`From learning`}],B6=(e,t)=>e===`all`||e===`import`==(t.basis===`import`),V6=e=>e.basis===`import`?e.source?`From your note ${e.source.title}`:`From your notes`:e.basis===`wrong_answer`?`From a wrong answer`:`From chat`;function H6({open:e,onOpenChange:t}){let[n,r]=(0,v.useState)(),[i,a]=(0,v.useState)(),[o,s]=(0,v.useState)(`all`),c=n?.filter(e=>e.basis===`import`).length??0,l=n?.filter(e=>B6(o,e));return(0,v.useEffect)(()=>{if(!e)return;let t=!1;r(void 0),s(`all`);let n=()=>{a(void 0),ZM().then(e=>{t||(e.ok?r(e.value):a(e.error))})};return n(),window.addEventListener(`focus`,n),()=>{t=!0,window.removeEventListener(`focus`,n)}},[e]),(0,j.jsx)(f6,{open:e,onOpenChange:t,children:(0,j.jsxs)(h6,{className:A(`w-full overflow-y-auto sm:max-w-md`,O3),onCloseAutoFocus:e=>{e.preventDefault(),(document.querySelector(`[data-memory-trigger]`)??document.querySelector(`[data-sidebar="trigger"]`))?.focus()},children:[(0,j.jsxs)(g6,{className:k3,children:[(0,j.jsx)(_6,{className:A3,children:`Memory`}),(0,j.jsx)(v6,{children:`What Mivra has noted about you across sessions. It can be wrong, so correct or delete anything here.`})]}),(0,j.jsxs)(`div`,{className:`flex flex-col gap-5 px-5 py-5`,"aria-live":`polite`,children:[i&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,children:i}),!n&&!i&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Loading memories…`]}),n?.length===0&&(0,j.jsxs)(a6,{className:`bg-sunken/50 border border-dashed p-6 md:p-6`,children:[(0,j.jsxs)(o6,{children:[(0,j.jsx)(c6,{variant:`icon`,children:(0,j.jsx)(Fm,{"aria-hidden":`true`})}),(0,j.jsx)(l6,{children:`No memories yet`}),(0,j.jsx)(u6,{children:`Start a conversation or course. As you learn, Mivra can remember your goals, preferences and concepts to revisit.`})]}),(0,j.jsx)(d6,{children:(0,j.jsx)(M,{variant:`outline`,onClick:()=>t(!1),children:`Back to learning`})})]}),c>0&&(0,j.jsx)(U6,{filter:o,onFilter:s,count:c,onDeleted:()=>{r(e=>e?.filter(e=>e.basis!==`import`)),s(`all`)}}),l&&R6.map(({kind:e,title:t})=>{let n=l.filter(t=>t.kind===e);return n.length>0?(0,j.jsxs)(`section`,{className:`flex flex-col gap-1.5 [section+&]:border-t [section+&]:pt-4`,children:[(0,j.jsx)(`h2`,{className:`text-muted-foreground font-mono text-[0.6875rem] leading-snug font-medium tracking-[0.09em] uppercase`,children:t}),(0,j.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:n.map(e=>(0,j.jsx)(W6,{memory:e,onChange:e=>r(t=>t?.map(t=>t.id===e.id?e:t)),onDelete:()=>r(t=>t?.filter(t=>t.id!==e.id))},e.id))})]},e):null}),n&&n.length>0&&(0,j.jsx)(`div`,{className:`border-t pt-4`,children:(0,j.jsx)(b6,{})})]})]})})}function U6({filter:e,onFilter:t,count:n,onDeleted:r}){let[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(),u=async()=>{s(!0),l(void 0);let e=await eN();if(s(!1),!e.ok)return l(e.error);a(!1),r()};return(0,j.jsxs)(`div`,{className:`flex flex-col gap-2 text-sm`,children:[(0,j.jsx)(`div`,{className:j3,role:`group`,"aria-label":`Show memories`,children:z6.map(({value:n,label:r})=>(0,j.jsx)(M,{type:`button`,size:`sm`,variant:`ghost`,className:M3(e===n),"aria-pressed":e===n,onClick:()=>t(n),children:r},n))}),e===`import`&&(i?(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,j.jsxs)(`span`,{className:`text-muted-foreground`,children:[`Delete all `,n.toLocaleString(`en`),` memories drawn from your notes? Your notes stay imported.`]}),(0,j.jsxs)(M,{type:`button`,variant:`destructive`,size:`sm`,disabled:o,onClick:()=>void u(),children:[o&&(0,j.jsx)(R2,{"aria-hidden":`true`}),`Yes, delete all`]}),(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,disabled:o,onClick:()=>a(!1),children:`Keep`})]}):(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,className:`self-start`,onClick:()=>a(!0),children:`Delete all from notes`})),c&&(0,j.jsx)(`p`,{className:`text-destructive`,role:`alert`,children:c})]})}function W6({memory:e,onChange:t,onDelete:n}){let r=(0,v.useId)(),[i,a]=(0,v.useState)(`view`),[o,s]=(0,v.useState)(e.text??``),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(),f=async n=>{n.preventDefault(),l(!0),d(void 0);let r=await QM(e.id,o);if(l(!1),!r.ok)return d(r.error);t(r.value),a(`view`)},p=async()=>{l(!0),d(void 0);let t=await $M(e.id);l(!1),t.ok?n():d(t.error)};return(0,j.jsxs)(`li`,{className:`hover:bg-sunken focus-within:bg-sunken -mx-2.5 flex flex-col gap-1.5 rounded-lg px-2.5 py-2.5 text-[0.95rem] leading-snug wrap-anywhere transition-colors`,children:[i===`edit`?(0,j.jsxs)(`form`,{onSubmit:f,className:`flex flex-col gap-2`,children:[(0,j.jsxs)(P2,{"data-invalid":!!u,children:[(0,j.jsx)(F2,{htmlFor:r,children:`Memory text`}),(0,j.jsx)(S0,{id:r,"aria-describedby":`${r}-description${u?` ${r}-error`:``}`,"aria-invalid":!!u,value:o,maxLength:300,onChange:e=>s(e.target.value),autoFocus:!0}),(0,j.jsx)(I2,{id:`${r}-description`,children:`Correct what Mivra should remember. Up to 300 characters.`}),u&&(0,j.jsx)(L2,{id:`${r}-error`,role:`alert`,children:u})]}),(0,j.jsxs)(`div`,{className:`flex gap-2`,children:[(0,j.jsxs)(M,{type:`submit`,size:`sm`,disabled:c||!o.trim(),children:[c&&(0,j.jsx)(R2,{"aria-hidden":`true`}),c?`Saving…`:`Save`]}),(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{s(e.text??``),d(void 0),a(`view`)},children:`Cancel`})]})]}):(0,j.jsxs)(j.Fragment,{children:[e.held?(0,j.jsx)(`p`,{className:`text-muted-foreground italic`,children:`Hidden until you answer the check in that session.`}):(0,j.jsx)(`p`,{children:e.text}),(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[!e.held&&(0,j.jsx)(`span`,{className:`text-muted-foreground max-w-full truncate text-[0.8125rem]`,title:e.source?`${e.source.importName}: ${e.source.path}`:void 0,children:V6(e)}),e.editedAt&&(0,j.jsx)(D2,{variant:`outline`,children:`Edited by you`}),(0,j.jsx)(`span`,{className:`text-muted-foreground font-mono text-[0.72rem]`,children:new Date(e.createdAt).toLocaleDateString()})]}),i===`confirm-delete`?(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,j.jsx)(`span`,{className:`text-muted-foreground`,children:`Delete permanently?`}),(0,j.jsx)(M,{type:`button`,variant:`destructive`,size:`sm`,disabled:c,onClick:()=>void p(),children:`Yes, delete`}),(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>a(`view`),children:`Keep`})]}):(0,j.jsxs)(`div`,{className:`flex gap-1.5`,children:[!e.held&&(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 bg-card dark:bg-card border-border-strong dark:border-border-strong hover:bg-sunken dark:hover:bg-sunken`,onClick:()=>{s(e.text??``),a(`edit`)},children:`Edit`}),(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 bg-card dark:bg-card border-border-strong dark:border-border-strong hover:bg-sunken dark:hover:bg-sunken`,onClick:()=>a(`confirm-delete`),children:`Delete`})]})]}),u&&i!==`edit`&&(0,j.jsx)(`p`,{className:`text-destructive`,role:`alert`,children:u})]})}function G6({...e}){return(0,j.jsx)(If,{"data-slot":`select`,...e})}function K6({...e}){return(0,j.jsx)(Bf,{"data-slot":`select-value`,...e})}function q6({className:e,size:t=`default`,children:n,...r}){return(0,j.jsxs)(Rf,{"data-slot":`select-trigger`,"data-size":t,className:A(`flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground`,e),...r,children:[n,(0,j.jsx)(Vf,{asChild:!0,children:(0,j.jsx)(Ym,{className:`size-4 opacity-50`})})]})}function J6({className:e,children:t,position:n=`item-aligned`,align:r=`center`,...i}){return(0,j.jsx)(Wf,{children:(0,j.jsxs)(Kf,{"data-slot":`select-content`,className:A(`relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,n===`popper`&&`data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1`,e),position:n,align:r,...i,children:[(0,j.jsx)(X6,{}),(0,j.jsx)(ip,{className:A(`p-1`,n===`popper`&&`h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1`),children:t}),(0,j.jsx)(Z6,{})]})})}function Y6({className:e,children:t,...n}){return(0,j.jsxs)(up,{"data-slot":`select-item`,className:A(`relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2`,e),...n,children:[(0,j.jsx)(`span`,{"data-slot":`select-item-indicator`,className:`absolute right-2 flex size-3.5 items-center justify-center`,children:(0,j.jsx)(mp,{children:(0,j.jsx)(qm,{className:`size-4`})})}),(0,j.jsx)(fp,{children:t})]})}function X6({className:e,...t}){return(0,j.jsx)(gp,{"data-slot":`select-scroll-up-button`,className:A(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,j.jsx)(th,{className:`size-4`})})}function Z6({className:e,...t}){return(0,j.jsx)(vp,{"data-slot":`select-scroll-down-button`,className:A(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,j.jsx)(Ym,{className:`size-4`})})}var Q6=220,$6=70,e8=4e4,t8=40,n8=14;function r8(e=1){let t=e;return()=>(t=(t*1664525+1013904223)%4294967296,t/4294967296)}function i8(e,t){return e===`note`?5+Math.min(7,Math.sqrt(t)*1.4):e===`ghost`?4:5+Math.min(5,Math.sqrt(t))}function a8(e){let t=new Map(e.nodes.map((e,t)=>[e.id,t])),n=e.edges.flatMap(({from:e,to:n})=>{let r=t.get(e),i=t.get(n);return r===void 0||i===void 0||r===i?[]:[[r,i]]}),r=e.nodes.map(()=>0);for(let[e,t]of n)r[e]++,r[t]++;let i=e.nodes.map((e,t)=>({index:t,radius:i8(e.kind,r[t])}));if(i.length>0){let e=Math.min(1,60/i.length),t=Math.round(Math.min(Q6,Math.max($6,e8/i.length))),r=Math.round(t*.65);I$(i).stop().randomSource(r8()).alphaDecay(1-.001**(1/t)).force(`link`,t$(n.map(([e,t])=>({source:e,target:t}))).id(e=>e.index).distance(e=>26+e.source.radius+e.target.radius)).force(`charge`,L$().strength(-90-120*e).theta(.9).distanceMax(250)).force(`x`,R$().strength(.06)).force(`y`,z$().strength(.06)).tick(r).force(`collide`,QQ(e=>e.radius+n8).iterations(1)).tick(t-r)}let a=i.length>0?i.map(e=>e.x):[0],o=i.length>0?i.map(e=>e.y):[0],s=Math.min(...a)-t8,c=Math.min(...o)-t8,l=Math.max(...a)+t8-s,u=Math.max(...o)+t8+n8-c;return{width:Math.max(l,200),height:Math.max(u,160),nodes:i.map((t,n)=>({id:e.nodes[n].id,x:t.x-s,y:t.y-c,radius:t.radius})),edges:n}}var o8=`__all`,s8=1.25,c8=.1,l8=3,u8=1.6,d8=150,f8=14,p8=200,m8=(e,t,n=`${t}s`)=>`${e.toLocaleString(`en`)} ${e===1?t:n}`,h8=e=>Math.min(l8,Math.max(c8,e));function g8(e,t){let n=m8(t,`connection`);switch(e.kind){case`note`:return`${e.label}, note in ${e.path}, ${n}`;case`tag`:return`${e.label}, tag on ${m8(e.notes??0,`note`)}`;case`concept`:return`${e.label}, concept from ${m8(e.notes??0,`note`)}`;case`ghost`:return`${e.label}, unresolved link, no such note`}}var _8,v8=0;function y8(e){let[t,n]=(0,v.useState)();return(0,v.useEffect)(()=>{if(!e)return;let t=()=>n({view:e,layout:a8(e)});if(typeof Worker>`u`)return t();let r;try{r=_8??=new Worker(new URL(`/assets/notes-graph.worker-DaVQvftJ.js`,``+import.meta.url),{type:`module`,name:`mivra-graph-layout`})}catch{return t()}let i=++v8,a=!1,o=()=>{a=!0,r.removeEventListener(`message`,s),r.removeEventListener(`error`,c)},s=t=>{t.data.id===i&&(o(),n({view:e,layout:t.data.layout}))},c=()=>{o(),r.terminate(),_8===r&&(_8=void 0),t()};return r.addEventListener(`message`,s),r.addEventListener(`error`,c),r.postMessage({id:i,view:{nodes:e.nodes,edges:e.edges}}),()=>{a||(o(),r.terminate(),_8===r&&(_8=void 0))}},[e]),{drawn:t,pending:!!(e&&t?.view!==e)}}function b8({importId:e}){let[t,n]=(0,v.useState)(e);(0,v.useEffect)(()=>n(e),[e]);let[r,i]=(0,v.useState)([]);(0,v.useEffect)(()=>{iN().then(e=>e.ok&&i(e.value))},[]);let[a,o]=(0,v.useState)({mode:`auto`,depth:2}),[s,c]=(0,v.useState)({loading:!0});(0,v.useEffect)(()=>{let e=!1;return c(e=>({...e,loading:!0,error:void 0})),cN(t,a).then(t=>{e||c(t.ok?{view:t.value,loading:!1}:{error:t.error,loading:!1})}),()=>{e=!0}},[t,a]);let l=s.view,u=y8(l),[d,f]=(0,v.useState)(),[p,m]=(0,v.useState)();(0,v.useEffect)(()=>{l&&f(e=>e&&l.nodes.some(t=>t.id===e)?e:l.focus??void 0)},[l]);let h=e=>{n(e),o({mode:`auto`,depth:2}),f(void 0)},g=e=>{f(e),o(t=>({...t,focus:e,mode:l&&l.matchingNotes>500?`local`:t.mode}))},_=e=>{f(e.id),e.kind===`note`&&m(e.id)},y=r.find(e=>e.id===t)?.name,b=!!(l&&l.matchingNotes>500);return(0,j.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,"data-testid":`notes-graph`,children:[(0,j.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2 border-b p-3`,role:`toolbar`,"aria-label":`Graph filters`,children:[(0,j.jsx)(S8,{label:`Import`,value:t,onChange:h,options:(r.length>0?r:[{id:t,name:`This import`}]).map(e=>({value:e.id,text:e.name}))}),(0,j.jsx)(S8,{label:`Tag`,value:a.tag??o8,onChange:e=>o(t=>({...t,tag:e===o8?void 0:e})),options:[{value:o8,text:`All tags`},...x8(l?.tags.map(e=>({value:e.name,text:`#${e.name} (${e.notes})`}))??[],a.tag,e=>`#${e}`)]}),(0,j.jsx)(S8,{label:`Folder`,value:a.folder??o8,onChange:e=>o(t=>({...t,folder:e===o8?void 0:e})),options:[{value:o8,text:`All folders`},...x8(l?.folders.map(e=>({value:e.path,text:`${e.path} (${e.notes})`}))??[],a.folder,e=>e)]}),(0,j.jsx)(S8,{label:`Show`,value:a.mode===`local`||b?`local`:`auto`,onChange:e=>o(t=>({...t,mode:e})),options:[{value:`auto`,text:b?`Whole graph (over 500 notes)`:`Whole graph`,disabled:b},{value:`local`,text:`Around the selected note`}]}),(a.mode===`local`||b)&&(0,j.jsx)(S8,{label:`Reach`,value:String(a.depth),onChange:e=>o(t=>({...t,depth:Number(e)})),options:[1,2,3].map(e=>({value:String(e),text:m8(e,`hop`)}))}),(0,j.jsx)(C8,{importId:t,onPick:e=>g(e.id)})]}),(0,j.jsx)(w8,{view:l,loading:s.loading||u.pending,error:s.error,importName:y}),!u.drawn&&!s.error&&(s.loading||u.pending)&&(0,j.jsxs)(`div`,{"aria-hidden":!0,className:`text-muted-foreground flex flex-1 items-center justify-center gap-2 text-sm`,children:[(0,j.jsx)(R2,{}),`Drawing the graph…`]}),u.drawn&&(0,j.jsx)(O8,{view:u.drawn.view,layout:u.drawn.layout,selected:d,onSelect:f,onActivate:_}),(0,j.jsx)(A8,{noteId:p,onOpenChange:e=>!e&&m(void 0),onCentre:e=>{m(void 0),o(t=>({...t,mode:`local`,focus:e})),f(e)}})]})}function x8(e,t,n){return t&&!e.some(e=>e.value===t)?[{value:t,text:n(t)},...e]:e}function S8({label:e,value:t,onChange:n,options:r}){let i=(0,v.useId)();return(0,j.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,j.jsx)(`span`,{id:i,className:`text-muted-foreground text-xs`,children:e}),(0,j.jsxs)(G6,{value:t,onValueChange:n,children:[(0,j.jsx)(q6,{size:`sm`,"aria-labelledby":i,className:`max-w-56`,children:(0,j.jsx)(K6,{})}),(0,j.jsx)(J6,{position:`popper`,className:`max-h-80`,children:r.map(e=>(0,j.jsx)(Y6,{value:e.value,disabled:e.disabled,children:e.text},e.value))})]})]})}function C8({importId:e,onPick:t}){let[n,r]=(0,v.useState)(!1),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)([]);return(0,v.useEffect)(()=>{let t=i.trim();if(!t)return s([]);let n=!1,r=setTimeout(()=>{lN(e,t).then(e=>{!n&&e.ok&&s(e.value)})},p8);return()=>{n=!0,clearTimeout(r)}},[e,i]),(0,j.jsxs)(r3,{open:n,onOpenChange:r,children:[(0,j.jsx)(i3,{asChild:!0,children:(0,j.jsxs)(M,{type:`button`,variant:`outline`,size:`sm`,children:[(0,j.jsx)(Lg,{}),`Find a note`]})}),(0,j.jsx)(a3,{className:`w-80 p-0`,align:`start`,children:(0,j.jsxs)(U4,{shouldFilter:!1,children:[(0,j.jsx)(W4,{placeholder:`Title or path`,value:i,onValueChange:a,"aria-label":`Find a note by title or path`}),(0,j.jsxs)(G4,{children:[i.trim()&&(0,j.jsx)(K4,{children:`No note matches.`}),o.map(e=>(0,j.jsx)(J4,{value:e.id,onSelect:()=>{r(!1),a(``),t(e)},children:(0,j.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[(0,j.jsx)(`span`,{className:`truncate`,children:e.title}),(0,j.jsx)(`span`,{className:`text-muted-foreground truncate text-xs`,children:e.path})]})},e.id))]})]})})]})}function w8({view:e,loading:t,error:n,importName:r}){let i=``;if(e){let t=t=>e.nodes.filter(e=>e.kind===t).length,n=[m8(t(`note`),`note`),m8(t(`tag`),`tag`),m8(t(`concept`),`concept`),m8(t(`ghost`),`unresolved link`)],r=e.nodes.find(t=>t.id===e.focus),a=e.mode===`whole`?`Whole graph`:`Around ${r?.label??`the best-connected note`}, within ${m8(e.depth,`hop`)}`,o=e.matchingNotes===e.totalNotes?m8(e.totalNotes,`note`):`${m8(e.matchingNotes,`matching note`)} (${m8(e.totalNotes,`note`)} in all)`;i=`${a}: ${n.join(`, `)}, of ${o}.${e.truncated?` Only the nearest are drawn; filter or centre on a note to see others.`:``}`,e.matchingNotes===0&&(i=e.totalNotes===0?`This import has no notes.`:`No note matches these filters.`)}return(0,j.jsxs)(`div`,{className:`flex min-h-9 items-center gap-2 border-b px-3 py-1.5 text-sm`,children:[r&&(0,j.jsxs)(`span`,{className:`sr-only`,children:[r,`.`]}),(0,j.jsx)(`p`,{role:`status`,"aria-live":`polite`,className:A(`min-w-0 flex-1`,n?`text-destructive`:`text-muted-foreground`),"data-testid":`notes-graph-status`,children:n??i}),t&&(0,j.jsx)(R2,{"aria-label":`Loading the graph`}),(0,j.jsx)(T8,{})]})}function T8(){return(0,j.jsx)(`ul`,{className:`text-muted-foreground hidden shrink-0 items-center gap-3 text-xs sm:flex`,"aria-hidden":`true`,children:[[`note`,`Note`],[`concept`,`Concept`],[`tag`,`Tag`],[`ghost`,`Unresolved`]].map(([e,t])=>(0,j.jsxs)(`li`,{className:`flex items-center gap-1`,children:[(0,j.jsx)(`svg`,{viewBox:`-7 -7 14 14`,className:`size-3.5 overflow-visible`,children:(0,j.jsx)(E8,{kind:e,radius:5,emphasis:!1})}),t]},e))})}function E8({kind:e,radius:t,emphasis:n}){switch(e){case`note`:return(0,j.jsx)(`circle`,{r:t,className:n?`fill-foreground`:`fill-muted-foreground`});case`concept`:return(0,j.jsx)(`polygon`,{points:`0,${-t*1.2} ${t*1.2},0 0,${t*1.2} ${-t*1.2},0`,className:A(`stroke-foreground stroke-[1.5]`,n?`fill-foreground`:`fill-card`)});case`tag`:return(0,j.jsx)(`rect`,{x:-t,y:-t,width:t*2,height:t*2,rx:1.5,className:A(`stroke-muted-foreground stroke-[1.5]`,n?`fill-muted-foreground`:`fill-muted`)});case`ghost`:return(0,j.jsx)(`circle`,{r:t,className:A(`fill-card stroke-muted-foreground stroke-[1.5]`,n&&`stroke-foreground`),strokeDasharray:`2 2`})}}function D8(e,t,n){let[r,i]={ArrowRight:[1,0],ArrowLeft:[-1,0],ArrowDown:[0,1],ArrowUp:[0,-1]}[n]??[0,0];if(r===0&&i===0)return;let a=e.nodes[t],o,s=1/0;return e.nodes.forEach((e,n)=>{let c=e.x-a.x,l=e.y-a.y,u=c*r+l*i;if(n===t||u<=0)return;let d=u+Math.abs(c*i-l*r)*2;d<s&&(s=d,o=n)}),o}function O8({view:e,layout:t,selected:n,onSelect:r,onActivate:i}){let a=(0,v.useMemo)(()=>new Map(e.nodes.map((e,t)=>[e.id,t])),[e]),o=(0,v.useMemo)(()=>{let n=e.nodes.map(()=>new Set);for(let[e,r]of t.edges)n[e].add(r),n[r].add(e);return n},[e,t]),s=(0,v.useRef)(null),[c,l]=(0,v.useState)(1),u=()=>{let e=s.current;return!e||e.clientWidth===0?1:h8(Math.min(u8,e.clientWidth/t.width,e.clientHeight/t.height))},d=n===void 0?void 0:a.get(n),f=(e,n)=>{let r=s.current;if(!r)return;let i=e===void 0?void 0:t.nodes[e];r.scrollLeft=i?i.x*n-r.clientWidth/2:(t.width*n-r.clientWidth)/2,r.scrollTop=i?i.y*n-r.clientHeight/2:(t.height*n-r.clientHeight)/2};(0,v.useLayoutEffect)(()=>{let t=u();l(t),requestAnimationFrame(()=>f(e.focus?a.get(e.focus):void 0,t))},[t]);let p=e=>{let t=h8(e);l(t),requestAnimationFrame(()=>f(d,t))},[m,h]=(0,v.useState)(),g=m!==void 0&&m<e.nodes.length?m:d??0;(0,v.useEffect)(()=>h(void 0),[e]);let _=(0,v.useRef)(new Map),y=e=>{h(e);let t=_.current.get(e);t?.focus({preventScroll:!0}),t?.scrollIntoView?.({block:`nearest`,inline:`nearest`})},b=(i,o)=>{if(i.key===`Escape`){n!==void 0&&(i.stopPropagation(),r(void 0));return}if(i.key===`Home`){i.preventDefault(),y(e.focus?a.get(e.focus)??0:0);return}let s=D8(t,o,i.key);i.key.startsWith(`Arrow`)&&i.preventDefault(),s!==void 0&&y(s)},x=(0,v.useRef)(void 0),S=e=>{let t=s.current;t&&e.button===0&&!e.target.closest(`button`)&&(x.current={x:e.clientX,y:e.clientY,left:t.scrollLeft,top:t.scrollTop},e.currentTarget.setPointerCapture?.(e.pointerId))},C=e=>{let t=s.current;t&&x.current&&(t.scrollLeft=x.current.left-(e.clientX-x.current.x),t.scrollTop=x.current.top-(e.clientY-x.current.y))},w=()=>x.current=void 0,[T,E]=(0,v.useState)(),D=new Set;for(let e of[d,T,m])if(e!==void 0&&(D.add(e),e===d))for(let t of o[e]??[])D.add(t);let ee=e.nodes.length<=d8||c>=1.5,te=d!==void 0,ne=e=>Math.max(f8,e*2*c),re=(0,v.useId)(),ie=e.nodes[g];return e.nodes.length===0?(0,j.jsx)(`div`,{className:`flex-1`}):(0,j.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 flex-col`,children:[(0,j.jsx)(`div`,{ref:s,className:`bg-background flex min-h-64 flex-1 cursor-grab overflow-auto active:cursor-grabbing`,onPointerDown:S,onPointerMove:C,onPointerUp:w,onPointerCancel:w,"data-testid":`notes-graph-scroll`,children:(0,j.jsxs)(`div`,{className:`relative m-auto shrink-0`,style:{width:t.width*c,height:t.height*c},"data-testid":`notes-graph-canvas`,"data-zoom":c.toFixed(3),children:[(0,j.jsxs)(`svg`,{viewBox:`0 0 ${t.width} ${t.height}`,className:`absolute inset-0 size-full`,"aria-hidden":`true`,children:[(0,j.jsx)(`defs`,{children:(0,j.jsx)(`marker`,{id:`${re}-arrow`,viewBox:`0 0 10 10`,refX:`10`,refY:`5`,markerWidth:`6`,markerHeight:`6`,orient:`auto-start-reverse`,children:(0,j.jsx)(`path`,{d:`M 0 0 L 10 5 L 0 10 z`,className:`fill-muted-foreground`})})}),t.edges.map(([n,r],i)=>{let a=e.edges[i],o=t.nodes[n],s=t.nodes[r],c=d!==void 0&&(n===d||r===d),l=Math.hypot(s.x-o.x,s.y-o.y)||1,u=a.kind===`prerequisite`?s.radius+2:0;return(0,j.jsx)(`line`,{x1:o.x,y1:o.y,x2:s.x-(s.x-o.x)/l*u,y2:s.y-(s.y-o.y)/l*u,className:A(c?`stroke-foreground`:`stroke-muted-foreground`,te&&!c&&`opacity-25`),strokeOpacity:c?1:a.kind===`tag`||a.kind===`concept`?.45:.7,strokeWidth:c?1.6:1,strokeDasharray:a.kind===`tag`||a.kind===`concept`?`3 3`:void 0,markerEnd:a.kind===`prerequisite`?`url(#${re}-arrow)`:void 0,"data-testid":`notes-graph-edge`,"data-kind":a.kind},i)}),t.nodes.map((t,n)=>(0,j.jsxs)(`g`,{transform:`translate(${t.x} ${t.y})`,className:A(te&&!D.has(n)&&`opacity-35`),children:[(n===d||e.focus===t.id&&d===void 0)&&(0,j.jsx)(`circle`,{r:t.radius+4,className:`fill-none stroke-foreground stroke-[1.5]`}),(0,j.jsx)(E8,{kind:e.nodes[n].kind,radius:t.radius,emphasis:D.has(n)})]},t.id))]}),(0,j.jsx)(`div`,{className:`pointer-events-none absolute inset-0 text-[11px] leading-tight`,"aria-hidden":`true`,children:t.nodes.map((t,n)=>ee||D.has(n)||e.focus===t.id?(0,j.jsx)(`span`,{className:A(`bg-background/80 absolute max-w-40 -translate-x-1/2 truncate rounded-sm px-0.5`,D.has(n)?`text-foreground font-medium`:`text-muted-foreground`,e.nodes[n].kind===`ghost`&&`italic`,te&&!D.has(n)&&`opacity-50`),style:{left:t.x*c,top:t.y*c+t.radius*c+2},"data-testid":`notes-graph-label`,children:e.nodes[n].label},t.id):null)}),(0,j.jsx)(`div`,{role:`group`,"aria-label":`Notes graph. Arrow keys move between nodes by where they're drawn; Enter opens a note.`,"aria-describedby":re,className:`absolute inset-0`,children:t.nodes.map((t,n)=>{let r=e.nodes[n],a=ne(t.radius);return(0,j.jsx)(`button`,{ref:e=>{e?_.current.set(n,e):_.current.delete(n)},type:`button`,tabIndex:n===g?0:-1,"aria-label":g8(r,o[n].size),"aria-pressed":n===d,className:A(`focus-visible:ring-ring/60 absolute -translate-x-1/2 -translate-y-1/2 cursor-pointer rounded-full outline-none focus-visible:ring-[3px]`,n===d&&`z-10`),style:{left:t.x*c,top:t.y*c,width:a,height:a},onClick:()=>{h(n),i(r)},onFocus:()=>h(n),onKeyDown:e=>b(e,n),onPointerEnter:()=>E(n),onPointerLeave:()=>E(e=>e===n?void 0:e),"data-testid":`notes-graph-node`,"data-node":t.id,"data-kind":r.kind},t.id)})})]})}),(0,j.jsx)(`p`,{id:re,className:`sr-only`,"aria-live":`polite`,"data-testid":`notes-graph-neighbours`,children:ie&&m!==void 0?k8(e,o[g],ie):``}),(0,j.jsxs)(`div`,{className:`bg-card/90 absolute right-3 bottom-3 flex gap-1 rounded-md border p-1 shadow-xs`,role:`group`,"aria-label":`Zoom`,children:[(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`Zoom out`,onClick:()=>p(c/s8),disabled:c<=c8,children:(0,j.jsx)(dg,{})}),(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`Fit to the window`,onClick:()=>p(u()),children:(0,j.jsx)(ag,{})}),(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`Zoom in`,onClick:()=>p(c*s8),disabled:c>=l8,children:(0,j.jsx)(Ng,{})})]})]})}function k8(e,t,n){let r=[...t].map(t=>e.nodes[t]).map(e=>e.kind===`ghost`?`${e.label} (unresolved)`:e.label),i=r.slice(0,12),a=r.length-i.length;return r.length===0?`${n.label} connects to nothing drawn.`:`${n.label} connects to ${i.join(`, `)}${a>0?` and ${m8(a,`more`)}`:``}.`}function A8({noteId:e,onOpenChange:t,onCentre:n}){let[r,i]=(0,v.useState)();(0,v.useEffect)(()=>{if(!e)return;let t=!1;return i({id:e}),uN(e).then(n=>{t||i(n.ok?{id:e,view:n.value}:{id:e,error:n.error})}),()=>{t=!0}},[e]);let a=r?.view;return(0,j.jsx)(f6,{open:!!e,onOpenChange:t,children:(0,j.jsxs)(h6,{className:`w-full overflow-y-auto sm:max-w-xl`,"data-testid":`note-reader`,onCloseAutoFocus:e=>{let t=r&&document.querySelector(`[data-testid="notes-graph-node"][data-node="${CSS.escape(r.id)}"]`);t&&(e.preventDefault(),t.focus())},children:[(0,j.jsxs)(g6,{children:[(0,j.jsx)(_6,{className:`font-heading wrap-anywhere`,children:a?.title??`Note`}),(0,j.jsx)(v6,{className:`wrap-anywhere`,children:a?`${a.path} · read-only`:r?.error?`Couldn't open this note.`:`Loading…`})]}),(0,j.jsxs)(`div`,{className:`flex flex-col gap-3 px-4 pb-6`,children:[r?.error&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,children:r.error}),!a&&!r?.error&&(0,j.jsx)(R2,{"aria-label":`Loading the note`}),a&&(0,j.jsxs)(j.Fragment,{children:[(a.tags.length>0||a.aliases.length>0)&&(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[a.tags.map(e=>(0,j.jsxs)(D2,{variant:`secondary`,children:[`#`,e]},e)),a.aliases.length>0&&(0,j.jsxs)(`span`,{className:`text-muted-foreground text-xs`,children:[`Also called `,a.aliases.join(`, `)]})]}),(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,className:`self-start`,onClick:()=>n(a.id),children:`Show the graph around this note`}),(0,j.jsx)(`div`,{className:`text-sm leading-relaxed wrap-anywhere whitespace-pre-wrap`,"data-testid":`note-body`,children:a.body})]})]})]})})}function j8({custom:e,canEdit:t,onChange:n}){let[r,i]=(0,v.useState)(!1);return(0,j.jsxs)(`section`,{className:`flex flex-col gap-3`,"aria-labelledby":`custom-providers-heading`,children:[(0,j.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,j.jsx)(`h2`,{id:`custom-providers-heading`,className:`text-sm font-semibold`,children:`OpenAI-compatible providers`}),(0,j.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Any service with an OpenAI-compatible Chat Completions API, such as a local server or another provider. Compatibility varies: test each model before relying on it.`})]}),e.map(e=>(0,j.jsx)(F8,{provider:e,canEdit:t,onChange:n},e.id)),t&&(r?(0,j.jsx)(P8,{onDone:()=>i(!1),onChange:n}):(0,j.jsx)(M,{type:`button`,variant:`outline`,className:`self-start`,onClick:()=>i(!0),children:`Add an OpenAI-compatible provider`}))]})}var M8=`The API base, including any version prefix, such as https://api.example.com/v1 or http://127.0.0.1:11434/v1. Not the full /chat/completions address.`,N8=e=>[...new Set(e.split(/[\s,]+/).map(e=>e.trim()).filter(Boolean))];function P8({onDone:e,onChange:t}){let[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)();return(0,j.jsxs)(`form`,{onSubmit:async r=>{r.preventDefault(),d(!0),p(void 0);let a=await YN({name:n,baseUrl:i.trim()||null,...o.trim()?{key:o.trim()}:{},models:N8(c).map(e=>({id:e}))});if(!a.ok)return d(!1),p(a.error);t(a.value);let s=a.value.custom.at(-1);if(s?.baseUrl.value){let e=await QN(s.id);e.ok&&t(e.value)}d(!1),e()},className:`flex flex-col gap-3 rounded-lg border p-3`,"aria-label":`Add an OpenAI-compatible provider`,children:[(0,j.jsxs)(P2,{children:[(0,j.jsx)(F2,{htmlFor:`custom-new-name`,children:`Provider name`}),(0,j.jsx)(z2,{id:`custom-new-name`,value:n,onChange:e=>r(e.target.value),disabled:u,autoComplete:`off`,placeholder:`DeepSeek`})]}),(0,j.jsxs)(P2,{children:[(0,j.jsx)(F2,{htmlFor:`custom-new-url`,children:`API base URL`}),(0,j.jsx)(I2,{id:`custom-new-url-help`,children:M8}),(0,j.jsx)(z2,{id:`custom-new-url`,"aria-describedby":`custom-new-url-help`,value:i,onChange:e=>a(e.target.value),disabled:u,autoComplete:`off`,spellCheck:!1,inputMode:`url`,placeholder:`https://api.example.com/v1`})]}),(0,j.jsxs)(P2,{children:[(0,j.jsx)(F2,{htmlFor:`custom-new-key`,children:`API key`}),(0,j.jsx)(I2,{id:`custom-new-key-help`,children:`Kept on this computer and never shown again. Leave it empty for a local server that needs none.`}),(0,j.jsx)(z2,{id:`custom-new-key`,"aria-describedby":`custom-new-key-help`,type:`password`,value:o,onChange:e=>s(e.target.value),disabled:u,autoComplete:`off`,spellCheck:!1,placeholder:`Paste your API key`})]}),(0,j.jsxs)(P2,{children:[(0,j.jsx)(F2,{htmlFor:`custom-new-models`,children:`Model ids`}),(0,j.jsx)(I2,{id:`custom-new-models-help`,children:`One per line, as the provider names them. You can also pick from its list after saving.`}),(0,j.jsx)(S0,{id:`custom-new-models`,"aria-describedby":`custom-new-models-help`,value:c,onChange:e=>l(e.target.value),disabled:u,spellCheck:!1,rows:2,placeholder:`model-id`})]}),f&&(0,j.jsx)(L2,{children:f}),(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,j.jsxs)(M,{type:`submit`,disabled:u||!n.trim(),children:[u&&(0,j.jsx)(R2,{"aria-hidden":`true`}),`Save provider`]}),(0,j.jsx)(M,{type:`button`,variant:`ghost`,disabled:u,onClick:e,children:`Cancel`})]})]})}function F8({provider:e,canEdit:t,onChange:n}){let[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(),p=`custom-${e.id}`,m=async(e,t)=>{u(e),c(!0),f(void 0);let r=await t();return c(!1),r.ok?(n(r.value),!0):(f({kind:`error`,text:r.error}),!1)},h=t=>m(`Saving models…`,()=>XN(e.id,{models:t})),g=e.models.map(({id:e,contextLength:t,maxOutputTokens:n})=>({id:e,contextLength:t,maxOutputTokens:n})),_=e.baseUrl,y=_.value?`${_.value} · ${_.source===`env`?`from ${e.envNames.baseUrl}`:`saved`}`:`No API base URL. Set one here or with ${e.envNames.baseUrl}.`,b=e.key.source===`env`?`Key set by ${e.envNames.key}${e.key.hint?` · ends in ${e.key.hint}`:``}.`:e.key.source===`saved`?`Key saved${e.key.hint?` · ends in ${e.key.hint}`:``}.`:`No key.`;return(0,j.jsxs)(`section`,{className:`flex flex-col gap-3 rounded-lg border p-3`,"aria-labelledby":`${p}-name`,children:[(0,j.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,j.jsx)(`h3`,{id:`${p}-name`,className:`text-sm font-semibold wrap-anywhere`,children:e.name}),(0,j.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Chat Completions`})]}),(0,j.jsxs)(`div`,{className:`text-muted-foreground flex flex-col gap-0.5 text-xs wrap-anywhere`,children:[(0,j.jsx)(`p`,{children:y}),_.error&&(0,j.jsx)(`p`,{className:`text-destructive`,children:_.error}),(0,j.jsx)(`p`,{children:b})]}),r?(0,j.jsx)(I8,{provider:e,onDone:()=>i(!1),onChange:n}):t&&(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,j.jsx)(M,{size:`sm`,variant:`outline`,disabled:s,onClick:()=>i(!0),children:`Edit`}),_.source===`saved`&&_.env&&(0,j.jsxs)(M,{size:`sm`,variant:`outline`,disabled:s,onClick:()=>void m(`Resetting the URL…`,()=>XN(e.id,{baseUrl:null})),children:[`Use `,e.envNames.baseUrl]}),!a&&(0,j.jsx)(M,{size:`sm`,variant:`ghost`,className:`text-destructive`,disabled:s,onClick:()=>o(!0),children:`Remove provider`})]}),a&&(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-sm`,children:[(0,j.jsxs)(`span`,{className:`text-muted-foreground`,children:[`Remove `,e.name,` and its saved key? Replies it wrote stay in your sessions.`]}),(0,j.jsx)(M,{type:`button`,variant:`destructive`,size:`sm`,disabled:s,onClick:()=>void m(`Removing…`,()=>ZN(e.id)).then(e=>e&&o(!1)),children:`Yes, remove`}),(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,disabled:s,onClick:()=>o(!1),children:`Keep`})]}),(0,j.jsx)(R8,{provider:e,canEdit:t,busy:s,onRemove:e=>void h(g.filter(t=>t.id!==e)),onChange:n}),t&&(0,j.jsx)(z8,{provider:e,busy:s,onAdd:e=>h([...g,e])}),(0,j.jsx)(B8,{provider:e,busy:s,onRefresh:()=>void m(`Loading the provider's models…`,()=>QN(e.id))}),s&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` `,l]}),d&&(0,j.jsx)(`p`,{className:d.kind===`ok`?`text-success text-sm`:`text-destructive text-sm`,role:d.kind===`error`?`alert`:void 0,children:d.text})]})}function I8({provider:e,onDone:t,onChange:n}){let[r,i]=(0,v.useState)(e.name),[a,o]=(0,v.useState)(e.baseUrl.source===`saved`?e.baseUrl.value??``:``),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(!1),[d,f]=(0,v.useState)(),p=`custom-${e.id}-edit`,m=e.key.source===`env`,h=async r=>{u(!0),f(void 0);let i=await XN(e.id,r);if(u(!1),!i.ok)return f(i.error);n(i.value),t()};return(0,j.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),h({name:r,baseUrl:a.trim()||null,...s.trim()?{key:s.trim()}:{}})},className:`flex flex-col gap-3`,"aria-label":`Edit ${e.name}`,children:[(0,j.jsxs)(P2,{children:[(0,j.jsx)(F2,{htmlFor:`${p}-name`,children:`Provider name`}),(0,j.jsx)(z2,{id:`${p}-name`,value:r,onChange:e=>i(e.target.value),disabled:l,autoComplete:`off`})]}),(0,j.jsxs)(P2,{children:[(0,j.jsx)(F2,{htmlFor:`${p}-url`,children:`API base URL`}),(0,j.jsxs)(I2,{id:`${p}-url-help`,children:[M8,e.baseUrl.env?` Leave it empty to use ${e.envNames.baseUrl} (${e.baseUrl.env}).`:``,` A new URL or key clears earlier test results.`]}),(0,j.jsx)(z2,{id:`${p}-url`,"aria-describedby":`${p}-url-help`,value:a,onChange:e=>o(e.target.value),disabled:l,autoComplete:`off`,spellCheck:!1,inputMode:`url`,placeholder:e.baseUrl.env??`https://api.example.com/v1`})]}),!m&&(0,j.jsxs)(P2,{children:[(0,j.jsx)(F2,{htmlFor:`${p}-key`,children:`New API key`}),(0,j.jsx)(I2,{id:`${p}-key-help`,children:`Leave it empty to keep the current key.`}),(0,j.jsx)(z2,{id:`${p}-key`,"aria-describedby":`${p}-key-help`,type:`password`,value:s,onChange:e=>c(e.target.value),disabled:l,autoComplete:`off`,spellCheck:!1,placeholder:`Paste a new API key`})]}),d&&(0,j.jsx)(L2,{children:d}),(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,j.jsxs)(M,{type:`submit`,size:`sm`,disabled:l||!r.trim(),children:[l&&(0,j.jsx)(R2,{"aria-hidden":`true`}),`Save`]}),!m&&e.key.source===`saved`&&(0,j.jsx)(M,{type:`button`,size:`sm`,variant:`outline`,disabled:l,onClick:()=>void h({key:null}),children:`Remove saved key`}),(0,j.jsx)(M,{type:`button`,size:`sm`,variant:`ghost`,disabled:l,onClick:t,children:`Cancel`})]})]})}var L8={unverified:{text:`Not tested`,className:``},verified:{text:`Works`,className:`text-success`},failed:{text:`Test failed`,className:`text-destructive`}};function R8({provider:e,canEdit:t,busy:n,onRemove:r,onChange:i}){let[a,o]=(0,v.useState)(),[s,c]=(0,v.useState)({}),l=(0,v.useRef)(void 0);if((0,v.useEffect)(()=>()=>l.current?.abort(),[]),e.models.length===0)return(0,j.jsxs)(`p`,{className:`text-muted-foreground text-sm`,children:[`No models yet. Add a model id`,e.baseUrl.value?` or pick one from the provider's list`:``,`.`]});let u=async t=>{let n=new AbortController;l.current=n,o(t),c(e=>({...e,[t]:void 0}));let r=await $N(e.id,t,n.signal);if(o(void 0),n.signal.aborted)return c(e=>({...e,[t]:{kind:`error`,text:`Test cancelled.`}}));if(!r.ok)return c(e=>({...e,[t]:{kind:`error`,text:r.error}}));i(r.value.providers),c(e=>({...e,[t]:{kind:r.value.result.ok?`ok`:`error`,text:r.value.result.message}}))};return(0,j.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,j.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Test model sends a short request with a tool call, which may use a few tokens.`}),(0,j.jsx)(`ul`,{className:`flex flex-col gap-2`,"aria-label":`${e.name} models`,children:e.models.map(i=>{let o=L8[i.verification.status],c=s[i.id],d=[i.contextLength&&`${i.contextLength.toLocaleString()} context`,i.maxOutputTokens&&`${i.maxOutputTokens.toLocaleString()} max output`].filter(Boolean).join(` · `);return(0,j.jsxs)(`li`,{className:`flex flex-col gap-1 rounded-md border px-2 py-1.5 text-sm`,"aria-label":i.id,children:[(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,j.jsx)(`span`,{className:`min-w-0 flex-1 font-mono text-xs wrap-anywhere`,children:i.id}),(0,j.jsx)(D2,{variant:`outline`,className:o.className,children:o.text})]}),d&&(0,j.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:d}),!c&&i.verification.status===`failed`&&i.verification.message&&(0,j.jsx)(`span`,{className:`text-destructive text-xs`,children:i.verification.message}),(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[a===i.id?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`span`,{className:`text-muted-foreground flex items-center gap-1.5 text-xs`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Testing `,i.id,`…`]}),(0,j.jsx)(M,{size:`xs`,variant:`outline`,onClick:()=>l.current?.abort(),children:`Cancel test`})]}):(0,j.jsx)(M,{size:`xs`,variant:`outline`,disabled:n||a!==void 0||!e.baseUrl.value,onClick:()=>void u(i.id),"aria-label":`Test model ${i.id}`,children:`Test model`}),t&&(0,j.jsx)(M,{size:`xs`,variant:`ghost`,className:`text-destructive`,disabled:n||a===i.id,onClick:()=>r(i.id),"aria-label":`Remove model ${i.id}`,children:`Remove`})]}),c&&(0,j.jsx)(`span`,{className:c.kind===`ok`?`text-success text-xs`:`text-destructive text-xs`,role:`status`,children:c.text})]},i.id)})})]})}function z8({provider:e,busy:t,onAdd:n}){let[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(``),[s,c]=(0,v.useState)(``),[l,u]=(0,v.useState)(),d=`custom-${e.id}-add`,f=`${d}-suggestions`,p=new Set(e.models.map(e=>e.id)),m=e.discovery.ids.filter(e=>!p.has(e)),h=e=>e.trim()?Number(e.trim().replace(/[,_]/g,``)):null,g=e=>e===null||Number.isInteger(e)&&e>0;return(0,j.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault();let t=r.trim();if(t){if(u(void 0),!g(h(a))||!g(h(s)))return u(`Limits are whole numbers of tokens, such as 128000.`);await n({id:t,contextLength:h(a),maxOutputTokens:h(s)})&&(i(``),o(``),c(``))}},className:`flex flex-col gap-2`,"aria-label":`Add a model to ${e.name}`,children:[(0,j.jsxs)(P2,{children:[(0,j.jsx)(F2,{htmlFor:d,children:`Add a model id`}),(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,j.jsx)(z2,{id:d,className:`min-w-0 flex-[1_1_10rem] font-mono`,list:m.length?f:void 0,value:r,onChange:e=>i(e.target.value),disabled:t,autoComplete:`off`,spellCheck:!1,placeholder:m[0]??`model-id`}),(0,j.jsx)(M,{type:`submit`,size:`sm`,variant:`outline`,disabled:t||!r.trim(),children:`Add`})]}),m.length>0&&(0,j.jsx)(`datalist`,{id:f,children:m.slice(0,500).map(e=>(0,j.jsx)(`option`,{value:e},e))})]}),l&&(0,j.jsx)(L2,{children:l}),(0,j.jsxs)(`details`,{className:`text-sm`,children:[(0,j.jsx)(`summary`,{className:`text-muted-foreground cursor-pointer text-xs`,children:`Advanced: limits`}),(0,j.jsxs)(`div`,{className:`mt-2 flex flex-col gap-2`,children:[(0,j.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Only if you know them. Mivra doesn't guess a model's limits; the output limit caps each reply.`}),(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,j.jsxs)(P2,{className:`flex-[1_1_8rem]`,children:[(0,j.jsx)(F2,{htmlFor:`${d}-context`,children:`Context length`}),(0,j.jsx)(z2,{id:`${d}-context`,inputMode:`numeric`,value:a,onChange:e=>o(e.target.value),disabled:t,placeholder:`Unknown`})]}),(0,j.jsxs)(P2,{className:`flex-[1_1_8rem]`,children:[(0,j.jsx)(F2,{htmlFor:`${d}-output`,children:`Max output tokens`}),(0,j.jsx)(z2,{id:`${d}-output`,inputMode:`numeric`,value:s,onChange:e=>c(e.target.value),disabled:t,placeholder:`Provider default`})]})]})]})]})]})}function B8({provider:e,busy:t,onRefresh:n}){let r=e.discovery,i=r.fetchedAt?new Date(r.fetchedAt).toLocaleString():void 0,a=r.state===`fresh`?`The provider lists ${r.ids.length} ${r.ids.length===1?`model`:`models`}. Type in the field above to pick one.`:r.state===`stale`?`Showing the list from ${i}: ${r.error}`:r.state===`failed`?r.error:`Load the provider's own list of models, or enter ids by hand.`;return(0,j.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,j.jsx)(`p`,{className:r.state===`failed`||r.state===`stale`?`text-destructive text-xs`:`text-muted-foreground text-xs`,children:a}),(0,j.jsx)(M,{type:`button`,size:`sm`,variant:`outline`,className:`self-start`,disabled:t||!e.baseUrl.value,onClick:n,children:`Refresh models`})]})}var V8={openrouter:{env:`OPENROUTER_API_KEY`,keysUrl:`https://openrouter.ai/keys`,note:`One key reaches every model.`},anthropic:{env:`ANTHROPIC_API_KEY`,keysUrl:`https://console.anthropic.com/settings/keys`,note:`Claude models, directly.`},openai:{env:`OPENAI_API_KEY`,keysUrl:`https://platform.openai.com/api-keys`,note:`GPT models, directly.`}},H8=e=>e.providers.some(e=>e.source!==null)||!!e.chatgpt?.signedIn||e.custom.some(e=>e.baseUrl.value!==null);function U8({open:e,onOpenChange:t,firstRun:n=!1}){let[r,i]=(0,v.useState)(),[a,o]=(0,v.useState)();return(0,v.useEffect)(()=>{if(!e)return;let t=!1;return o(void 0),LN().then(e=>{t||(e.ok?i(e.value):o(e.error))}),()=>{t=!0}},[e]),(0,j.jsx)(f6,{open:e,onOpenChange:t,children:(0,j.jsxs)(h6,{className:`w-full overflow-y-auto sm:max-w-md`,onCloseAutoFocus:e=>{e.preventDefault(),(document.querySelector(`[data-providers-trigger]`)??document.querySelector(`[data-sidebar="trigger"]`))?.focus()},children:[(0,j.jsxs)(g6,{children:[(0,j.jsx)(_6,{className:`font-heading`,children:`Model providers`}),(0,j.jsx)(v6,{children:n&&r&&!H8(r)?`Mivra needs a model provider before it can teach: sign in with ChatGPT, or add an API key from one of these providers. OpenRouter is the simplest key: one key reaches every model.`:`How Mivra reaches models. Keys and sign-ins stay on this computer, and keys are never shown again after you save them.`})]}),(0,j.jsxs)(`div`,{className:`flex flex-col gap-4 px-4 pb-4`,"aria-live":`polite`,children:[a&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,role:`alert`,children:a}),!r&&!a&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Loading providers…`]}),r&&!r.canEdit&&(0,j.jsxs)(`p`,{className:`text-muted-foreground text-sm`,children:[`API keys can only be changed on the computer running Mivra. There, open this panel or run `,(0,j.jsx)(`code`,{children:`mivra auth set <provider>`}),`.`]}),r?.chatgpt&&(0,j.jsx)(K8,{chatgpt:r.chatgpt,canEdit:r.canEdit,onChange:i}),r?.providers.map(e=>(0,j.jsx)(W8,{provider:e,canEdit:r.canEdit,onChange:i},e.id)),r&&(0,j.jsx)(j8,{custom:r.custom,canEdit:r.canEdit,onChange:i})]})]})})}function W8({provider:e,canEdit:t,onChange:n}){let r=V8[e.id],[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(),m=`provider-key-${e.id}`,h=async()=>{d(`Checking the key…`),l(!0),p(void 0);let t=await KN(e.id);if(l(!1),!t.ok)return p({kind:`error`,text:t.error});p(t.value.ok?{kind:`ok`,text:`The key works.`}:{kind:`error`,text:t.value.message??`The key didn't work.`})},g=async t=>{if(t.preventDefault(),!o.trim())return;d(`Saving the key…`),l(!0),p(void 0);let r=await RN(e.id,o);if(l(!1),!r.ok)return p({kind:`error`,text:r.error});s(``),a(!1),n(r.value),await h()},_=async()=>{d(`Removing the key…`),l(!0),p(void 0);let t=await zN(e.id);if(l(!1),!t.ok)return p({kind:`error`,text:t.error});n(t.value)},y=t&&e.source!==`env`&&(e.source===null||i),b=e.hint?` · ends in ${e.hint}`:``;return(0,j.jsxs)(`section`,{className:`flex flex-col gap-2 rounded-lg border p-3`,"aria-labelledby":`${m}-name`,children:[(0,j.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,j.jsx)(`h2`,{id:`${m}-name`,className:`text-sm font-semibold`,children:e.label}),(0,j.jsxs)(`a`,{href:r.keysUrl,target:`_blank`,rel:`noreferrer`,className:`text-muted-foreground hover:text-foreground inline-flex items-center gap-1 text-xs underline-offset-2 hover:underline`,children:[`Get a key `,(0,j.jsx)(jh,{className:`size-3`,"aria-hidden":!0})]})]}),(0,j.jsx)(`p`,{id:`${m}-source`,className:`text-muted-foreground text-xs`,children:e.source===`env`?`Set by ${r.env}${b}. Change it there.`:e.source===`saved`?`Saved${b}.`:`Not set. ${r.note}`}),y?(0,j.jsx)(`form`,{onSubmit:g,children:(0,j.jsxs)(P2,{"data-invalid":f?.kind===`error`,children:[(0,j.jsxs)(F2,{htmlFor:m,children:[e.label,` API key`]}),(0,j.jsxs)(I2,{id:`${m}-description`,children:[`Paste a key from your `,e.label,` account.`]}),(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,j.jsx)(z2,{className:`min-w-0 flex-[1_1_10rem]`,"aria-describedby":`${m}-source ${m}-description${f?` ${m}-status`:``}`,"aria-invalid":f?.kind===`error`,id:m,type:`password`,autoComplete:`off`,spellCheck:!1,placeholder:`Paste your API key`,value:o,onChange:e=>s(e.target.value),disabled:c}),(0,j.jsx)(M,{type:`submit`,disabled:c||!o.trim(),children:c?`Saving…`:`Save`}),i&&(0,j.jsx)(M,{type:`button`,variant:`ghost`,disabled:c,onClick:()=>a(!1),children:`Cancel`})]}),f?.kind===`error`&&(0,j.jsx)(L2,{id:`${m}-status`,children:f.text})]})}):e.source!==null&&(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,j.jsx)(M,{size:`sm`,variant:`outline`,disabled:c,onClick:()=>void h(),children:`Check`}),t&&e.source===`saved`&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(M,{size:`sm`,variant:`outline`,disabled:c,onClick:()=>a(!0),children:`Replace`}),(0,j.jsx)(M,{size:`sm`,variant:`ghost`,className:`text-destructive`,disabled:c,onClick:()=>void _(),children:`Remove`})]})]}),c&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` `,u]}),f&&!(y&&f.kind===`error`)&&(0,j.jsx)(`p`,{id:`${m}-status`,className:f.kind===`ok`?`text-success text-sm`:`text-destructive text-sm`,children:f.text})]})}var G8=1500;function K8({chatgpt:e,canEdit:t,onChange:n}){let[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(``),[s,c]=(0,v.useState)(),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(),p=`provider-chatgpt`,m=t;(0,v.useEffect)(()=>{if(!e.pending)return;let t=setInterval(()=>{LN().then(e=>{e.ok&&!e.value.chatgpt?.pending&&(n(e.value),f(void 0),window.dispatchEvent(new Event(FN)))})},G8);return()=>clearInterval(t)},[e.pending,n]);let h=async(e,t)=>{o(e),i(!0),c(void 0);let n=await t();return i(!1),n.ok||c({kind:`error`,text:n.error}),n.ok?n.value:void 0},g=async(e=!1)=>{let t=window.open(`about:blank`,`_blank`),r=await h(`Opening ChatGPT…`,()=>BN(e));if(!r){t?.close();return}t?(t.opener=null,t.location.href=r.url):f(r.url);let i=await LN();i.ok&&n(i.value)},_=async e=>{if(e.preventDefault(),!l.trim())return;let t=await h(`Finishing sign-in…`,()=>VN(l));t&&(u(``),f(void 0),n(t))},y=async()=>{let e=await h(`Cancelling…`,HN);f(void 0),e&&n(e)},b=async()=>{let e=await h(`Disconnecting…`,UN);e&&n(e)},x=async()=>{let e=await h(`Checking the connection…`,GN);e&&c(e.ok?{kind:`ok`,text:`The connection works.`}:{kind:`error`,text:e.message??`The connection didn't work.`})},S=e.signedIn?`Replies from ChatGPT models use your ChatGPT plan, not an API key.`:e.pending?`Finish connecting in your browser.`:e.previous&&e.notice?`Reconnect to renew your ChatGPT connection.`:`Complete eligible AI requests in this app with usage included in your ChatGPT plan or credits balance.`;return(0,j.jsxs)(`section`,{className:`flex flex-col gap-2 rounded-lg border p-3`,"aria-labelledby":`${p}-name`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,j.jsxs)(`h2`,{id:`${p}-name`,className:`inline-flex items-center gap-1.5 text-sm font-semibold`,children:[(0,j.jsx)(o3,{className:`size-4`}),`ChatGPT`]}),e.signedIn&&(0,j.jsx)(D2,{variant:`secondary`,children:`Connected`})]}),e.signedIn?(0,j.jsxs)(`p`,{className:`text-sm`,children:[(0,j.jsx)(`span`,{className:`font-medium`,children:e.name??`Connected with ChatGPT`}),e.email&&(0,j.jsx)(`span`,{className:`text-muted-foreground block text-xs`,children:e.email})]}):!e.pending&&(0,j.jsx)(`p`,{className:`text-sm font-medium`,children:e.previous&&e.notice?`Reconnect to ChatGPT`:`Use your ChatGPT plan`}),(0,j.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:S}),e.notice&&!e.pending&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,role:`alert`,children:e.notice}),e.pending?(0,j.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Waiting for you to approve Mivra in the ChatGPT tab…`]}),d&&(0,j.jsx)(`a`,{href:d,target:`_blank`,rel:`noreferrer`,className:`text-sm underline underline-offset-2`,children:`Open the ChatGPT sign-in page`}),(0,j.jsx)(`form`,{onSubmit:_,children:(0,j.jsxs)(P2,{"data-invalid":s?.kind===`error`,children:[(0,j.jsx)(F2,{htmlFor:`${p}-address`,children:m?`Browser showing an error page?`:`Paste the address from the ChatGPT tab`}),(0,j.jsx)(I2,{id:`${p}-address-description`,children:m?`After approving, if the tab can't load, copy its whole address and paste it here.`:`This browser isn't on the computer running Mivra, so after you approve, the tab will show an error page. Copy its whole address and paste it here.`}),(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,j.jsx)(z2,{className:`min-w-0 flex-[1_1_10rem]`,id:`${p}-address`,"aria-describedby":`${p}-address-description${s?` ${p}-status`:``}`,"aria-invalid":s?.kind===`error`,autoComplete:`off`,spellCheck:!1,placeholder:`http://127.0.0.1:1455/auth/callback?code=…`,value:l,onChange:e=>u(e.target.value),disabled:r}),(0,j.jsx)(M,{type:`submit`,disabled:r||!l.trim(),children:`Finish`}),(0,j.jsx)(M,{type:`button`,variant:`ghost`,disabled:r,onClick:()=>void y(),children:`Cancel`})]}),s?.kind===`error`&&(0,j.jsx)(L2,{id:`${p}-status`,children:s.text})]})})]}):e.signedIn?(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,j.jsx)(c3,{primary:!0}),(0,j.jsx)(M,{size:`sm`,variant:`outline`,disabled:r,onClick:()=>void x(),children:`Check`}),(0,j.jsx)(M,{size:`sm`,variant:`ghost`,className:`text-destructive`,disabled:r,onClick:()=>void b(),children:`Disconnect`})]}):(0,j.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,j.jsx)(s3,{busy:r,disabled:r,onClick:()=>void g()}),e.previous&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex flex-wrap items-center gap-x-2 text-xs`,children:[`Signs in as `,e.previous,`.`,(0,j.jsx)(M,{size:`xs`,variant:`link`,className:`h-auto p-0`,disabled:r,onClick:()=>void g(!0),children:`Use a different account`})]})]}),r&&(e.signedIn||e.pending)&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` `,a]}),s&&!(e.pending&&s.kind===`error`)&&(0,j.jsx)(`p`,{id:`${p}-status`,className:s.kind===`ok`?`text-success text-sm`:`text-destructive text-sm`,children:s.text})]})}var q8={lesson:{title:`Lesson generation`,label:`Lesson model`,description:`Writes each lesson's outline and sections in the background.`}};function J8({open:e,onOpenChange:t}){return(0,j.jsx)(f6,{open:e,onOpenChange:t,children:(0,j.jsxs)(h6,{className:`w-full overflow-y-auto sm:max-w-md`,onCloseAutoFocus:e=>{e.preventDefault(),(document.querySelector(`[data-settings-trigger]`)??document.querySelector(`[data-sidebar="trigger"]`))?.focus()},children:[(0,j.jsxs)(g6,{children:[(0,j.jsx)(_6,{className:`font-heading`,children:`Settings`}),(0,j.jsx)(v6,{children:`Settings apply from the next reply or lesson; anything already being written keeps its model.`})]}),e&&(0,j.jsx)(Y8,{}),e&&(0,j.jsxs)(`section`,{"aria-labelledby":`settings-usage`,className:`flex flex-col gap-2 px-4 pb-4`,children:[(0,j.jsx)(`h3`,{id:`settings-usage`,className:`font-heading text-base font-medium`,children:`Usage`}),(0,j.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Tokens and costs of Mivra's model calls, custom prices and clearing the history are on the Usage page.`}),(0,j.jsx)(`div`,{children:(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>window.dispatchEvent(new Event(`mivra:open-usage`)),children:`Open Usage`})})]})]})})}function Y8(){let e=w3(),[t,n]=(0,v.useState)(),[r,i]=(0,v.useState)();(0,v.useEffect)(()=>{let e=!1;return DN().then(t=>{e||(t.ok?n(t.value):i(t.error))}),()=>{e=!0}},[]);let a=(0,v.useCallback)(e=>n(t=>t?.map(t=>t.id===e.id?e:t)),[]);return(0,j.jsxs)(`section`,{"aria-labelledby":`settings-models`,className:`flex flex-col gap-4 px-4 pb-4`,children:[(0,j.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,j.jsx)(`h3`,{id:`settings-models`,className:`font-heading text-base font-medium`,children:`Models`}),(0,j.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`The picker under the message box sets the main model, which chat and new syllabuses always use. A task uses the main model too, and follows it when it changes, unless you choose one for it here.`})]}),r&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,role:`alert`,children:r}),!t&&!r&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Loading…`]}),t?.map(t=>(0,j.jsx)(X8,{task:t,picker:e,onChange:a},t.id))]})}function X8({task:e,picker:t,onChange:n}){let{title:r,label:i,description:a}=q8[e.id],[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(),u=t.view,d=e=>b3(e.model,u?.models,u?.providers),f=async e=>{s(!0),l(void 0);let t=await e();s(!1),t.ok?n(t.value):l(t.error)};return(0,j.jsxs)(`div`,{role:`group`,"aria-labelledby":`task-${e.id}`,className:`flex flex-col gap-2 rounded-md border p-3`,children:[(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,j.jsx)(`h4`,{id:`task-${e.id}`,className:`text-sm font-medium`,children:r}),(0,j.jsx)(D2,{variant:e.override?`default`:`secondary`,children:e.override?`Own model`:`Uses main model`})]}),(0,j.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:a}),e.override?(0,j.jsx)(`p`,{className:`text-sm`,children:`Always uses the model below, whatever the main model is.`}):(0,j.jsxs)(`p`,{className:`text-sm`,children:[`Follows the main model, now `,d(e.effective),`. Choose a model below to use another one for this task.`]}),e.unavailable&&(0,j.jsxs)(T0,{variant:`destructive`,children:[(0,j.jsxs)(E0,{children:[d(e.effective),` can't be used for this task`]}),(0,j.jsxs)(D0,{children:[(0,j.jsx)(`p`,{children:e.unavailable}),(0,j.jsx)(`p`,{children:`Choose another model, or use the main model. Until then, this task fails rather than switching models.`})]})]}),(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,j.jsx)(E3,{state:t,disabled:o,label:i,value:e.effective,unavailable:null,onChoose:t=>void f(()=>ON(e.id,t))}),e.override&&(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,disabled:o,onClick:()=>void f(()=>kN(e.id)),children:`Use main model`})]}),c&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,role:`alert`,children:c})]})}var Z8=[{id:`7`,label:`7 days`,days:7},{id:`30`,label:`30 days`,days:30},{id:`90`,label:`90 days`,days:90},{id:`all`,label:`All time`,days:null}],Q8=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),$8=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1}),e5=e=>e===null?`Unknown`:Q8.format(e),t5=e=>e===null?`Unknown`:$8.format(e);function n5(e){return e===0?`$0.00`:e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}var r5=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function i5(e){let t=[];return e.reportedCost!==null&&t.push(`${n5(e.reportedCost)} reported`),e.estimatedCost!==null&&t.push(`≈${n5(e.estimatedCost)} estimated`),e.unknownCost>0&&t.push(`${r5(e.unknownCost,`call`)} unknown`),t.length>0?t.join(` + `):`None`}function a5({open:e,onOpenChange:t}){return(0,j.jsx)(f6,{open:e,onOpenChange:t,children:(0,j.jsxs)(h6,{className:A(`w-full overflow-y-auto sm:max-w-2xl`,O3),onCloseAutoFocus:e=>{e.preventDefault(),(document.querySelector(`[data-usage-trigger]`)??document.querySelector(`[data-sidebar="trigger"]`))?.focus()},children:[(0,j.jsxs)(g6,{className:k3,children:[(0,j.jsx)(_6,{className:A3,children:`Usage`}),(0,j.jsx)(v6,{children:`Tokens and costs from the model calls Mivra makes, counted from when usage tracking started on this computer. It isn't your whole account's usage and doesn't show any remaining allowance.`})]}),e&&(0,j.jsx)(o5,{})]})})}function o5(){let[e,t]=(0,v.useState)(`30`),[n,r]=(0,v.useState)(),[i,a]=(0,v.useState)(),[o,s]=(0,v.useState)(0),c=(0,v.useCallback)(()=>s(e=>e+1),[]);return(0,v.useEffect)(()=>{let t=!1,n=Z8.find(t=>t.id===e).days;return AN(n===null?null:new Date(Date.now()-n*24*60*60*1e3)).then(e=>{t||(e.ok?(r(e.value),a(void 0)):a(e.error))}),()=>{t=!0}},[e,o]),(0,j.jsxs)(`div`,{className:`flex flex-col gap-6 px-5 py-5`,children:[(0,j.jsx)(`div`,{role:`radiogroup`,"aria-label":`Date range`,className:j3,children:Z8.map(n=>(0,j.jsx)(M,{type:`button`,size:`sm`,role:`radio`,"aria-checked":e===n.id,variant:`ghost`,className:M3(e===n.id),onClick:()=>t(n.id),children:n.label},n.id))}),i&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,role:`alert`,children:i}),!n&&!i&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Loading…`]}),n&&(0,j.jsx)(s5,{view:n,onChanged:c})]})}function s5({view:e,onChanged:t}){let{totals:n,api:r,subscription:i}=e,a=n.calls===0;return(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:e.since?`Counting since ${new Date(e.since).toLocaleString()}.`:`Nothing recorded yet. Usage is counted from the next model call.`}),!a&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`section`,{"aria-label":`Totals`,className:`grid gap-x-6 gap-y-4 sm:grid-cols-3`,children:[(0,j.jsxs)(d5,{label:`Tokens`,value:t5(n.total),children:[(0,j.jsxs)(`span`,{children:[e5(n.input),` in · `,e5(n.output),` out`]}),n.cacheRead!==null&&(0,j.jsxs)(`span`,{children:[`of input, `,e5(n.cacheRead),` cached`]}),n.reasoning!==null&&(0,j.jsxs)(`span`,{children:[`of output, `,e5(n.reasoning),` reasoning`]}),n.unreported>0&&(0,j.jsxs)(`span`,{children:[r5(n.unreported,`call`),` didn't report tokens`]})]}),(0,j.jsxs)(d5,{label:`API spending`,value:r.calls===0?`None`:u5(r),children:[(0,j.jsx)(`span`,{children:r5(r.calls,`API call`)}),r.calls>0&&(0,j.jsx)(`span`,{children:i5(r)})]}),(0,j.jsxs)(d5,{label:`ChatGPT plan`,value:i.calls===0?`Not used`:t5(i.total),children:[i.calls>0&&(0,j.jsxs)(`span`,{children:[`tokens in `,r5(i.calls,`call`),`, billed to your plan`]}),(0,j.jsxs)(`span`,{children:[`Limits and plan usage: `,(0,j.jsx)(c3,{})]})]})]}),i.calls>0&&(0,j.jsx)(f5,{totals:i}),(n.incomplete>0||n.unreported>0)&&(0,j.jsxs)(`p`,{className:`text-muted-foreground text-sm`,children:[r5(n.incomplete,`call`),` failed or `,n.incomplete===1?`was`:`were`,` cancelled. Whatever tokens they reported are counted; calls that reported none are shown as unknown rather than free, since a provider may still bill them.`]}),(0,j.jsx)(p5,{days:e.days}),(0,j.jsx)(h5,{title:`By model`,rows:e.byModel.map(e=>({key:e.key,name:e.label,detail:e.providerLabel,totals:e,billing:e.billing}))}),(0,j.jsx)(h5,{title:`By provider`,rows:e.byProvider.map(e=>({key:e.key,name:e.label,totals:e,billing:e.billing}))}),(0,j.jsx)(h5,{title:`By activity`,rows:e.byKind.map(e=>({key:e.key,name:e.label,detail:c5[e.kind],totals:e}))}),(0,j.jsx)(h5,{title:`Recent runs`,note:`A run is one reply, continuation, lesson or test; each tool-call step is a separate call.`,rows:e.runs.map(e=>({key:e.key,name:e.session??`Model test`,detail:`${l5[e.kind]} · ${e.label} · ${new Date(e.startedAt).toLocaleString()}${e.status===`completed`?``:` · ${e.status}`}`,totals:e,billing:e.billing}))}),(0,j.jsx)(h5,{title:`Sessions`,rows:e.sessions.map(e=>({key:e.key,name:e.label,detail:e.deleted?`Its records are kept`:void 0,totals:e}))})]}),(0,j.jsx)(_5,{prices:e.prices,onChanged:t}),(0,j.jsx)(y5,{disabled:!e.since,onCleared:t})]})}var c5={chat:`Your messages and the tutor's replies, syllabus writing included`,continuation:`The tutor carrying on after you answer its checks`,lesson:`Background generation of lessons`,distillation:`Background reading of imported notes into concepts and memories`,test:`Test model under Model providers`},l5={chat:`Chat`,continuation:`Continuation`,lesson:`Lesson`,distillation:`Note reading`,test:`Test model`};function u5(e){let t=(e.reportedCost??0)+(e.estimatedCost??0);return e.reportedCost===null&&e.estimatedCost===null?`Unknown`:`${e.estimatedCost===null?``:`≈`}${n5(t)}${e.unknownCost>0?`+`:``}`}function d5({label:e,value:t,children:n}){return(0,j.jsxs)(`div`,{role:`group`,"aria-label":e,className:`flex min-w-0 flex-col gap-1`,children:[(0,j.jsx)(`span`,{className:D3,children:e}),(0,j.jsx)(`span`,{className:`font-heading text-[1.85rem] leading-tight font-normal tracking-[-0.02em] tabular-nums wrap-anywhere`,children:t}),(0,j.jsx)(`div`,{className:`text-muted-foreground flex flex-col text-[0.8125rem] leading-snug`,children:n})]})}function f5({totals:e}){let[t,n]=(0,v.useState)(!1);return(0,j.jsxs)(O2,{open:t,onOpenChange:n,className:`border-border-strong rounded-lg border`,children:[(0,j.jsx)(k2,{asChild:!0,children:(0,j.jsxs)(M,{type:`button`,variant:`ghost`,className:`w-full justify-between`,children:[`Estimated API equivalent`,(0,j.jsx)(Ym,{"aria-hidden":!0,className:A(`transition-transform`,t&&`rotate-180`)})]})}),(0,j.jsxs)(A2,{className:`flex flex-col gap-1 px-3 pb-3 text-sm`,children:[(0,j.jsx)(`p`,{className:`text-muted-foreground`,children:`What these tokens would cost at published API rates. This is not a charge or your subscription cost.`}),e.apiEquivalent===null?(0,j.jsx)(`p`,{className:`text-muted-foreground`,children:`None of these models has a published API price to compare with.`}):(0,j.jsxs)(`p`,{children:[(0,j.jsxs)(`span`,{className:`font-medium tabular-nums`,children:[`≈`,n5(e.apiEquivalent)]}),e.uncompared>0&&(0,j.jsxs)(`span`,{className:`text-muted-foreground`,children:[` for the calls with a published price; `,r5(e.uncompared,`call`),` had none to compare with.`]})]})]})]})}function p5({days:e}){if(e.length<2)return null;let t=e=>e.api+e.subscription,n=Math.max(1,...e.map(t));return(0,j.jsxs)(`section`,{"aria-labelledby":`usage-daily`,className:`flex flex-col gap-2`,children:[(0,j.jsx)(`h3`,{id:`usage-daily`,className:D3,children:`Tokens per day`}),(0,j.jsx)(`div`,{className:`border-border-strong flex h-28 items-end gap-0.5 border-b`,role:`list`,"aria-label":`Tokens per day`,children:e.map(e=>{let r=`${new Date(`${e.day}T00:00:00`).toLocaleDateString()}: ${Q8.format(t(e))} tokens in ${r5(e.calls,`call`)}`;return(0,j.jsx)(`div`,{role:`listitem`,"aria-label":r,title:r,className:`group flex h-full min-w-1 flex-1 items-end`,children:(0,j.jsx)(`div`,{className:`bg-muted-foreground/60 group-hover:bg-foreground w-full rounded-t-[3px]`,style:{height:`${Math.max(2,t(e)/n*100)}%`}})},e.day)})}),(0,j.jsxs)(`div`,{className:`text-muted-foreground flex justify-between gap-2 font-mono text-[0.72rem] tabular-nums`,children:[(0,j.jsx)(`span`,{children:new Date(`${e[0].day}T00:00:00`).toLocaleDateString()}),(0,j.jsxs)(`span`,{children:[`Peak `,t5(n)]}),(0,j.jsx)(`span`,{children:new Date(`${e.at(-1).day}T00:00:00`).toLocaleDateString()})]})]})}function m5(e){if(e.billing===`subscription`)return`ChatGPT plan`;let t=e.totals,n=i5(t);return e.billing===void 0&&(t.apiEquivalent!==null||t.uncompared>0)?n===`None`?`ChatGPT plan`:`${n} + ChatGPT plan`:n}function h5({title:e,note:t,rows:n}){if(n.length===0)return null;let r=`usage-${e.toLowerCase().replace(/\s+/g,`-`)}`;return(0,j.jsxs)(`section`,{"aria-labelledby":r,className:`flex flex-col gap-2`,children:[(0,j.jsx)(`h3`,{id:r,className:`font-heading text-[1.05rem] font-medium`,children:e}),t&&(0,j.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:t}),(0,j.jsx)(`div`,{className:`overflow-x-auto`,children:(0,j.jsxs)(`table`,{className:`w-full text-sm`,"aria-labelledby":r,children:[(0,j.jsx)(`thead`,{className:`text-muted-foreground text-left font-mono text-[0.6875rem] tracking-[0.09em] uppercase`,children:(0,j.jsxs)(`tr`,{children:[(0,j.jsx)(`th`,{scope:`col`,className:`pb-2 pr-2 font-medium`,children:`Name`}),(0,j.jsx)(`th`,{scope:`col`,className:`pb-2 pr-2 text-right font-medium`,children:`Tokens`}),(0,j.jsx)(`th`,{scope:`col`,className:`pb-2 pr-2 text-right font-medium`,children:`Calls`}),(0,j.jsx)(`th`,{scope:`col`,className:`pb-2 text-right font-medium`,children:`Cost`})]})}),(0,j.jsx)(`tbody`,{children:n.map(e=>(0,j.jsxs)(`tr`,{className:`border-t align-top`,children:[(0,j.jsxs)(`th`,{scope:`row`,className:`py-2.5 pr-2 text-left font-semibold`,children:[(0,j.jsx)(`span`,{className:`block break-words`,children:e.name}),e.detail&&(0,j.jsx)(`span`,{className:`text-muted-foreground block text-xs font-normal`,children:e.detail})]}),(0,j.jsxs)(`td`,{className:`py-2.5 pr-2 text-right font-mono text-[0.8125rem] tabular-nums`,children:[e5(e.totals.total),e.totals.unreported>0&&(0,j.jsxs)(`span`,{className:`text-muted-foreground block text-xs`,children:[`+`,e.totals.unreported,` unknown`]})]}),(0,j.jsx)(`td`,{className:`py-2.5 pr-2 text-right font-mono text-[0.8125rem] tabular-nums`,children:e.totals.calls}),(0,j.jsx)(`td`,{className:`py-2.5 text-right text-xs`,children:m5(e)})]},e.key))})]})})]})}var g5=[{key:`input`,label:`Input`},{key:`output`,label:`Output`},{key:`cacheRead`,label:`Cached input`}];function _5({prices:e,onChanged:t}){let[n,r]=(0,v.useState)(!1);return(0,j.jsxs)(O2,{open:n,onOpenChange:r,className:`border-border-strong rounded-lg border`,children:[(0,j.jsx)(k2,{asChild:!0,children:(0,j.jsxs)(M,{type:`button`,variant:`ghost`,className:`w-full justify-between`,children:[`Advanced: custom prices`,(0,j.jsx)(Ym,{"aria-hidden":!0,className:A(`transition-transform`,n&&`rotate-180`)})]})}),(0,j.jsxs)(A2,{className:`flex flex-col gap-3 px-3 pb-3`,children:[(0,j.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`US dollars per million tokens. A price you set wins over the published one for calls from now on; costs already recorded don't change. No model needs a price to work: without one its cost stays unknown.`}),e.length===0&&(0,j.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`No models yet.`}),e.map(e=>(0,j.jsx)(v5,{price:e,onChanged:t},e.model))]})]})}function v5({price:e,onChanged:t}){let n=t=>String(e.custom?.[t]??``),[r,i]=(0,v.useState)(()=>Object.fromEntries(g5.map(e=>[e.key,n(e.key)]))),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(),l=`price-${e.model.replace(/[^a-z0-9]/gi,`-`)}`,u=e.published?`Published: ${n5(e.published.input)} in, ${n5(e.published.output)} out`:`No published price`,d=async n=>{o(!0),c(void 0);let r=await MN(e.model,n);o(!1),r.ok?t():c(r.error)};return(0,j.jsxs)(`div`,{role:`group`,"aria-labelledby":l,className:`flex flex-col gap-2 border-t pt-3`,children:[(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,j.jsx)(`span`,{id:l,className:`text-sm font-medium break-all`,children:e.label}),(0,j.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,j.jsx)(D2,{variant:`secondary`,children:e.providerLabel}),e.custom&&(0,j.jsx)(D2,{children:`Custom price`})]})]}),(0,j.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:e.billing===`subscription`?`Billed to your ChatGPT plan. Its API comparison uses only published prices, so it has no price of your own. ${u}.`:`${u}.`}),e.billing!==`subscription`&&(0,j.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[g5.map(t=>(0,j.jsxs)(`label`,{className:`flex w-28 flex-col gap-1 text-xs`,children:[t.label,(0,j.jsx)(z2,{inputMode:`decimal`,value:r[t.key],disabled:a,"aria-label":`${t.label} price for ${e.label}, dollars per million tokens`,onChange:e=>i(n=>({...n,[t.key]:e.target.value}))})]},t.key)),(0,j.jsx)(M,{type:`button`,size:`sm`,disabled:a,onClick:()=>{let e=Number(r.input),t=Number(r.output);if(r.input===``||r.output===``||!Number.isFinite(e)||!Number.isFinite(t)||e<0||t<0){c(`Enter input and output prices of 0 or more.`);return}let n=r.cacheRead===``?void 0:Number(r.cacheRead);n!==void 0&&(!Number.isFinite(n)||n<0)?c(`The cached input price must be 0 or more, or empty.`):d({input:e,output:t,...n===void 0?{}:{cacheRead:n}})},children:`Save price`}),e.custom&&(0,j.jsx)(M,{type:`button`,size:`sm`,variant:`outline`,disabled:a,onClick:()=>void d(null),children:`Remove`})]}),s&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,role:`alert`,children:s})]})}function y5({disabled:e,onCleared:t}){let[n,r]=(0,v.useState)(!1),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(),c=async()=>{a(!0),s(void 0);let e=await jN();if(a(!1),!e.ok)return s(e.error);r(!1),t()};return(0,j.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,j.jsx)(`div`,{children:(0,j.jsx)(M,{type:`button`,variant:`outline`,size:`sm`,disabled:e,onClick:()=>r(!0),children:`Clear usage history`})}),(0,j.jsx)(F4,{open:n,onOpenChange:r,children:(0,j.jsxs)(R4,{children:[(0,j.jsxs)(z4,{children:[(0,j.jsx)(V4,{children:`Clear usage history?`}),(0,j.jsx)(H4,{children:`This deletes Mivra's usage records. Your conversations, lessons and provider settings are kept. It doesn't reset any provider's billing or your plan's limits. Usage starts counting again from the next model call.`})]}),o&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,role:`alert`,children:o}),(0,j.jsxs)(B4,{children:[(0,j.jsx)(M,{type:`button`,variant:`outline`,onClick:()=>r(!1),children:`Cancel`}),(0,j.jsx)(M,{type:`button`,variant:`destructive`,disabled:i,onClick:()=>void c(),children:`Clear usage history`})]})]})})]})}var b5=768;function x5(){let[e,t]=v.useState(void 0);return v.useEffect(()=>{let e=window.matchMedia(`(max-width: 767px)`),n=()=>{t(window.innerWidth<b5)};return e.addEventListener(`change`,n),t(window.innerWidth<b5),()=>e.removeEventListener(`change`,n)},[]),!!e}var S5=`sidebar_state`,C5=604800,w5=`16rem`,T5=`18rem`,E5=`3rem`,D5=`b`,O5=v.createContext(null);function k5(){let e=v.useContext(O5);if(!e)throw Error(`useSidebar must be used within a SidebarProvider.`);return e}function A5({defaultOpen:e=!0,open:t,onOpenChange:n,className:r,style:i,children:a,...o}){let s=x5(),[c,l]=v.useState(!1),[u,d]=v.useState(e),f=t??u,p=v.useCallback(e=>{let t=typeof e==`function`?e(f):e;n?n(t):d(t),document.cookie=`${S5}=${t}; path=/; max-age=${C5}`},[n,f]),m=v.useCallback(()=>s?l(e=>!e):p(e=>!e),[s,p,l]);v.useEffect(()=>{let e=e=>{e.key===D5&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),m())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[m]);let h=f?`expanded`:`collapsed`,g=v.useMemo(()=>({state:h,open:f,setOpen:p,isMobile:s,openMobile:c,setOpenMobile:l,toggleSidebar:m}),[h,f,p,s,c,l,m]);return(0,j.jsx)(O5.Provider,{value:g,children:(0,j.jsx)(U3,{delayDuration:0,children:(0,j.jsx)(`div`,{"data-slot":`sidebar-wrapper`,style:{"--sidebar-width":w5,"--sidebar-width-icon":E5,...i},className:A(`group/sidebar-wrapper flex min-h-svh w-full has-data-[variant=inset]:bg-sidebar`,r),...o,children:a})})})}function j5({side:e=`left`,variant:t=`sidebar`,collapsible:n=`offcanvas`,className:r,children:i,...a}){let{isMobile:o,state:s,openMobile:c,setOpenMobile:l}=k5();return n===`none`?(0,j.jsx)(`div`,{"data-slot":`sidebar`,className:A(`flex h-full w-(--sidebar-width) flex-col bg-sidebar text-sidebar-foreground`,r),...a,children:i}):o?(0,j.jsx)(f6,{open:c,onOpenChange:l,...a,children:(0,j.jsxs)(h6,{"data-sidebar":`sidebar`,"data-slot":`sidebar`,"data-mobile":`true`,className:`w-(--sidebar-width) bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden`,style:{"--sidebar-width":T5},side:e,children:[(0,j.jsxs)(g6,{className:`sr-only`,children:[(0,j.jsx)(_6,{children:`Sidebar`}),(0,j.jsx)(v6,{children:`Displays the mobile sidebar.`})]}),(0,j.jsx)(`div`,{className:`flex h-full w-full flex-col`,children:i})]})}):(0,j.jsxs)(`div`,{className:`group peer hidden text-sidebar-foreground md:block`,"data-state":s,"data-collapsible":s===`collapsed`?n:``,"data-variant":t,"data-side":e,"data-slot":`sidebar`,children:[(0,j.jsx)(`div`,{"data-slot":`sidebar-gap`,className:A(`relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear`,`group-data-[collapsible=offcanvas]:w-0`,`group-data-[side=right]:rotate-180`,t===`floating`||t===`inset`?`group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]`:`group-data-[collapsible=icon]:w-(--sidebar-width-icon)`)}),(0,j.jsx)(`div`,{"data-slot":`sidebar-container`,className:A(`fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear md:flex`,e===`left`?`left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]`:`right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]`,t===`floating`||t===`inset`?`p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]`:`group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l`,r),...a,children:(0,j.jsx)(`div`,{"data-sidebar":`sidebar`,"data-slot":`sidebar-inner`,className:`flex h-full w-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:shadow-sm`,children:i})})]})}function M5({className:e,onClick:t,...n}){let{toggleSidebar:r}=k5();return(0,j.jsxs)(M,{"data-sidebar":`trigger`,"data-slot":`sidebar-trigger`,variant:`ghost`,size:`icon`,className:A(`size-7`,e),onClick:e=>{t?.(e),r()},...n,children:[(0,j.jsx)(xg,{}),(0,j.jsx)(`span`,{className:`sr-only`,children:`Toggle Sidebar`})]})}function N5({className:e,...t}){let{toggleSidebar:n}=k5();return(0,j.jsx)(`button`,{"data-sidebar":`rail`,"data-slot":`sidebar-rail`,"aria-label":`Toggle Sidebar`,tabIndex:-1,onClick:n,title:`Toggle Sidebar`,className:A(`absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border sm:flex`,`in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize`,`[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize`,`group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full hover:group-data-[collapsible=offcanvas]:bg-sidebar`,`[[data-side=left][data-collapsible=offcanvas]_&]:-right-2`,`[[data-side=right][data-collapsible=offcanvas]_&]:-left-2`,e),...t})}function P5({className:e,...t}){return(0,j.jsx)(`main`,{"data-slot":`sidebar-inset`,className:A(`relative flex w-full flex-1 flex-col bg-background`,`md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2`,e),...t})}function F5({className:e,...t}){return(0,j.jsx)(z2,{"data-slot":`sidebar-input`,"data-sidebar":`input`,className:A(`h-8 w-full bg-background shadow-none`,e),...t})}function I5({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`sidebar-header`,"data-sidebar":`header`,className:A(`flex flex-col gap-2 p-2`,e),...t})}function L5({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`sidebar-footer`,"data-sidebar":`footer`,className:A(`flex flex-col gap-2 p-2`,e),...t})}function R5({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`sidebar-content`,"data-sidebar":`content`,className:A(`flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden`,e),...t})}function z5({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`sidebar-group`,"data-sidebar":`group`,className:A(`relative flex w-full min-w-0 flex-col p-2`,e),...t})}function B5({className:e,asChild:t=!1,...n}){let r=t?Gt:`div`;return(0,j.jsx)(r,{"data-slot":`sidebar-group-label`,"data-sidebar":`group-label`,className:A(`flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground/70 ring-sidebar-ring outline-hidden transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0`,`group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0`,e),...n})}function V5({className:e,...t}){return(0,j.jsx)(`ul`,{"data-slot":`sidebar-menu`,"data-sidebar":`menu`,className:A(`flex w-full min-w-0 flex-col gap-1`,e),...t})}function H5({className:e,...t}){return(0,j.jsx)(`li`,{"data-slot":`sidebar-menu-item`,"data-sidebar":`menu-item`,className:A(`group/menu-item relative`,e),...t})}var U5=ce(`peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm ring-sidebar-ring outline-hidden transition-[width,height,padding] group-has-data-[sidebar=menu-action]/menu-item:pr-8 group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0`,{variants:{variant:{default:`hover:bg-sidebar-accent hover:text-sidebar-accent-foreground`,outline:`bg-background shadow-[0_0_0_1px_var(--sidebar-border)] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_var(--sidebar-accent)]`},size:{default:`h-8 text-sm`,sm:`h-7 text-xs`,lg:`h-12 text-sm group-data-[collapsible=icon]:p-0!`}},defaultVariants:{variant:`default`,size:`default`}});function W5({asChild:e=!1,isActive:t=!1,variant:n=`default`,size:r=`default`,tooltip:i,className:a,...o}){let s=e?Gt:`button`,{isMobile:c,state:l}=k5(),u=(0,j.jsx)(s,{"data-slot":`sidebar-menu-button`,"data-sidebar":`menu-button`,"data-size":r,"data-active":t,className:A(U5({variant:n,size:r}),a),...o});if(!i)return u;typeof i==`string`&&(i={children:i});let d=l!==`collapsed`||c;return(0,j.jsxs)(W3,{open:!d&&void 0,children:[(0,j.jsx)(G3,{asChild:!0,children:u}),(0,j.jsx)(K3,{side:`right`,align:`center`,hidden:d,...i})]})}function G5({className:e,asChild:t=!1,showOnHover:n=!1,...r}){let i=t?Gt:`button`;return(0,j.jsx)(i,{"data-slot":`sidebar-menu-action`,"data-sidebar":`menu-action`,className:A(`absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground ring-sidebar-ring outline-hidden transition-transform peer-hover/menu-button:text-sidebar-accent-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0`,`after:absolute after:-inset-2 md:pointer-fine:after:hidden`,`peer-data-[size=sm]/menu-button:top-1`,`peer-data-[size=default]/menu-button:top-1.5`,`peer-data-[size=lg]/menu-button:top-2.5`,`group-data-[collapsible=icon]:hidden`,n&&`group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 peer-data-[active=true]/menu-button:text-sidebar-accent-foreground data-[state=open]:opacity-100 md:pointer-fine:opacity-0`,e),...r})}var K5=[{value:`system`,label:`System`,Icon:pg},{value:`light`,label:`Light`,Icon:Zg},{value:`dark`,label:`Dark`,Icon:hg}];function q5({choice:e,onChange:t}){let{label:n,Icon:r}=K5.find(t=>t.value===e)??K5[0];return(0,j.jsx)(V5,{children:(0,j.jsx)(H5,{children:(0,j.jsxs)(Y4,{children:[(0,j.jsx)(X4,{asChild:!0,children:(0,j.jsxs)(W5,{tooltip:`Theme`,"aria-label":`Theme: ${n}`,children:[(0,j.jsx)(r,{}),(0,j.jsx)(`span`,{children:n})]})}),(0,j.jsx)(Z4,{side:`top`,align:`start`,children:(0,j.jsx)($4,{value:e,onValueChange:e=>t(e),children:K5.map(({value:e,label:t,Icon:n})=>(0,j.jsxs)(e3,{value:e,children:[(0,j.jsx)(n,{}),t]},e))})})]})})})}var J5=`mivra-theme`,Y5=()=>window.matchMedia(`(prefers-color-scheme: dark)`);function X5(){try{let e=localStorage.getItem(J5);return e===`light`||e===`dark`?e:`system`}catch{return`system`}}function Z5(e){let t=e===`dark`||e===`system`&&Y5().matches;document.documentElement.classList.toggle(`dark`,t)}function Q5(){let[e,t]=(0,v.useState)(X5);return(0,v.useEffect)(()=>{Z5(e);try{e===`system`?localStorage.removeItem(J5):localStorage.setItem(J5,e)}catch{}if(e!==`system`)return;let t=Y5(),n=()=>Z5(`system`);return t.addEventListener(`change`,n),()=>t.removeEventListener(`change`,n)},[e]),[e,t]}function $5(e,t=new Date){let n=new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime(),r=new Date(t.getFullYear(),t.getMonth(),t.getDate()-7).getTime(),i=[{label:`Today`,sessions:[]},{label:`Previous 7 days`,sessions:[]},{label:`Older`,sessions:[]}];for(let t of e){let e=new Date(t.updatedAt).getTime();(e>=n?i[0]:e>=r?i[1]:i[2]).sessions.push(t)}return i.filter(e=>e.sessions.length>0)}function e7({...e}){return(0,j.jsx)(Oo,{"data-slot":`alert-dialog`,...e})}function t7({...e}){return(0,j.jsx)(ko,{"data-slot":`alert-dialog-portal`,...e})}function n7({className:e,...t}){return(0,j.jsx)(Ao,{"data-slot":`alert-dialog-overlay`,className:A(`fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0`,e),...t})}function r7({className:e,size:t=`default`,...n}){return(0,j.jsxs)(t7,{children:[(0,j.jsx)(n7,{}),(0,j.jsx)(No,{"data-slot":`alert-dialog-content`,"data-size":t,className:A(`group/alert-dialog-content fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 data-[size=sm]:max-w-xs data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[size=default]:sm:max-w-lg`,e),...n})]})}function i7({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`alert-dialog-header`,className:A(`grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-6 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]`,e),...t})}function a7({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`alert-dialog-footer`,className:A(`flex flex-col-reverse gap-2 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end`,e),...t})}function o7({className:e,...t}){return(0,j.jsx)(Po,{"data-slot":`alert-dialog-title`,className:A(`text-lg font-semibold sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2`,e),...t})}function s7({className:e,...t}){return(0,j.jsx)(Fo,{"data-slot":`alert-dialog-description`,className:A(`text-sm text-muted-foreground`,e),...t})}function c7({className:e,variant:t=`default`,size:n=`default`,...r}){return(0,j.jsx)(M,{variant:t,size:n,asChild:!0,children:(0,j.jsx)(Io,{"data-slot":`alert-dialog-action`,className:A(e),...r})})}function l7({className:e,variant:t=`outline`,size:n=`default`,...r}){return(0,j.jsx)(M,{variant:t,size:n,asChild:!0,children:(0,j.jsx)(Ro,{"data-slot":`alert-dialog-cancel`,className:A(e),...r})})}var u7=120;function d7({onRename:e,onDelete:t}){let n=(0,v.useRef)(!1);return(0,j.jsxs)(Y4,{children:[(0,j.jsx)(X4,{asChild:!0,children:(0,j.jsx)(G5,{showOnHover:!0,"aria-label":`Session actions`,children:(0,j.jsx)(kh,{})})}),(0,j.jsxs)(Z4,{side:`right`,align:`start`,onCloseAutoFocus:t=>{n.current&&(n.current=!1,t.preventDefault(),e())},children:[(0,j.jsxs)(Q4,{onSelect:()=>n.current=!0,children:[(0,j.jsx)(kg,{}),`Rename`]}),(0,j.jsxs)(Q4,{variant:`destructive`,onSelect:t,children:[(0,j.jsx)(r_,{}),`Delete`]})]})]})}function f7({session:e,onDone:t,onRenamed:n}){let[r,i]=(0,v.useState)(e.title),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(),l=(0,v.useRef)(null),u=(0,v.useRef)(!1);(0,v.useEffect)(()=>{l.current?.focus(),l.current?.select()},[]);let d=async()=>{if(u.current||a)return;let i=r.trim();if(!i||i===e.title)return u.current=!0,t();o(!0),c(void 0);let s=await qN(e.id,i);o(!1),s.ok?(u.current=!0,n(s.value),t()):(c(s.error),l.current?.focus())};return(0,j.jsxs)(`div`,{className:`px-0.5 py-0.5`,children:[(0,j.jsx)(F5,{ref:l,value:r,maxLength:u7,readOnly:a,"aria-label":`Title`,"aria-invalid":s?!0:void 0,"aria-describedby":s?`rename-error-${e.id}`:void 0,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),d()):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),u.current=!0,t())},onBlur:()=>void d()}),s&&(0,j.jsx)(`p`,{id:`rename-error-${e.id}`,className:`text-destructive px-1 pt-1 text-xs`,role:`alert`,children:s})]})}function p7({session:e,onClose:t,onDeleted:n}){let[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(),s=async()=>{if(!e)return;i(!0),o(void 0);let t=await JN(e.id);if(i(!1),!t.ok)return o(t.error);n(e)};return(0,j.jsx)(e7,{open:!!e,onOpenChange:e=>{e||r||(o(void 0),t())},children:(0,j.jsxs)(r7,{children:[(0,j.jsxs)(i7,{children:[(0,j.jsxs)(o7,{className:`font-heading wrap-anywhere`,children:[`Delete “`,e?.title,`”?`]}),(0,j.jsx)(s7,{children:e?.courseId?`This deletes the course with its syllabus, lessons and every lesson's chat. It can't be undone. What Mivra remembers about you is kept.`:`This deletes the session with its messages and attached documents. It can't be undone. What Mivra remembers about you is kept.`})]}),a&&(0,j.jsx)(`p`,{className:`text-destructive text-sm`,role:`alert`,children:a}),(0,j.jsxs)(a7,{children:[(0,j.jsx)(l7,{disabled:r,children:`Cancel`}),(0,j.jsxs)(c7,{variant:`destructive`,disabled:r,onClick:e=>{e.preventDefault(),s()},children:[r&&(0,j.jsx)(R2,{}),`Delete`]})]})]})})}function m7({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`input-group`,role:`group`,className:A(`group/input-group relative flex w-full items-center rounded-md border border-input shadow-xs transition-[color,box-shadow] outline-none dark:bg-input/30`,`h-9 min-w-0 has-[>textarea]:h-auto`,`has-[>[data-align=inline-start]]:[&>input]:pl-2`,`has-[>[data-align=inline-end]]:[&>input]:pr-2`,`has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>[data-align=block-start]]:[&>input]:pb-3`,`has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-end]]:[&>input]:pt-3`,`has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-[3px] has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50`,`has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-destructive/20 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40`,e),...t})}var h7=ce(`flex h-auto cursor-text items-center justify-center gap-2 py-1.5 text-sm font-medium text-muted-foreground select-none group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4`,{variants:{align:{"inline-start":`order-first pl-3 has-[>button]:ml-[-0.45rem] has-[>kbd]:ml-[-0.35rem]`,"inline-end":`order-last pr-3 has-[>button]:mr-[-0.45rem] has-[>kbd]:mr-[-0.35rem]`,"block-start":`order-first w-full justify-start px-3 pt-3 group-has-[>input]/input-group:pt-2.5 [.border-b]:pb-3`,"block-end":`order-last w-full justify-start px-3 pb-3 group-has-[>input]/input-group:pb-2.5 [.border-t]:pt-3`}},defaultVariants:{align:`inline-start`}});function g7({className:e,align:t=`inline-start`,...n}){return(0,j.jsx)(`div`,{role:`group`,"data-slot":`input-group-addon`,"data-align":t,className:A(h7({align:t}),e),onClick:e=>{e.target.closest(`button`)||e.currentTarget.parentElement?.querySelector(`[data-slot="input-group-control"]`)?.focus()},...n})}function _7({className:e,...t}){return(0,j.jsx)(z2,{"data-slot":`input-group-control`,className:A(`flex-1 rounded-none border-0 bg-transparent shadow-none focus-visible:ring-0 dark:bg-transparent`,e),...t})}function v7(){let[e,t]=(0,v.useState)([]),[n,r]=(0,v.useState)({kind:`start`}),i=n.kind===`session`?n.id:void 0,[a,o]=(0,v.useState)(),[s,c]=(0,v.useState)(),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(0),p=async()=>{try{let e=await HM.sessions.$get();if(!e.ok)return o(await UM(e));t(await e.json()),o(void 0)}catch{o(`Can't reach the Mivra server.`)}};(0,v.useEffect)(()=>{p()},[]);let m=()=>{r({kind:`draft`}),f(e=>e+1)},h=(e,n)=>{t(t=>[e,...t]),c({sessionId:e.id,...n}),r({kind:`session`,id:e.id})},g=({session:e,goal:t})=>h(e,{message:t}),_=(e,t)=>{u(``),h(e,t)},[y,b]=(0,v.useState)(),x=e=>{b(void 0),r(e)},S=e.find(e=>e.id===i),[C,w]=(0,v.useState)(),T=e=>{w(void 0),t(t=>t.filter(t=>t.id!==e.id)),s?.sessionId===e.id&&c(void 0),i===e.id&&r({kind:`start`})},[E,D]=Q5(),[ee,te]=(0,v.useState)(!1),[ne,re]=(0,v.useState)(!1),[ie,ae]=(0,v.useState)(!1),[oe,se]=(0,v.useState)(!1),[O,ce]=(0,v.useState)(!1);(0,v.useEffect)(()=>{let e=()=>se(!0),t=()=>{se(!1),ce(!0)};return window.addEventListener(PN,e),window.addEventListener(NN,t),()=>{window.removeEventListener(PN,e),window.removeEventListener(NN,t)}},[]);let[le,ue]=(0,v.useState)(!1);return(0,v.useEffect)(()=>{BM&&LN().then(e=>{e.ok&&!H8(e.value)&&(ue(!0),ae(!0))})},[]),(0,j.jsxs)(A5,{children:[(0,j.jsx)(b7,{sessions:e,activeId:i,theme:E,onThemeChange:D,drafting:n.kind===`draft`,onSelect:e=>x({kind:`session`,id:e}),onDelete:w,onRenamed:e=>t(t=>t.map(t=>t.id===e.id?{...t,title:e.title}:t)),onNew:()=>{b(void 0),m()},onNewCourse:()=>x({kind:`start`}),onOpenMemory:()=>te(!0),onOpenImports:()=>re(!0),onOpenProviders:()=>ae(!0),onOpenSettings:()=>se(!0),onOpenUsage:()=>ce(!0)}),(0,j.jsx)(H6,{open:ee,onOpenChange:te}),(0,j.jsx)(k6,{open:ne,onOpenChange:re,onOpenGraph:b}),(0,j.jsx)(U8,{open:ie,onOpenChange:ae,firstRun:le}),(0,j.jsx)(J8,{open:oe,onOpenChange:se}),(0,j.jsx)(a5,{open:O,onOpenChange:ce}),(0,j.jsx)(d3,{}),(0,j.jsx)(p7,{session:C,onClose:()=>w(void 0),onDeleted:T}),(0,j.jsxs)(P5,{className:`h-svh min-w-0 overflow-hidden`,children:[(0,j.jsxs)(`header`,{className:`flex h-13 shrink-0 items-center gap-2 border-b px-3`,children:[(0,j.jsx)(M5,{}),(0,j.jsx)(M2,{orientation:`vertical`,className:`mr-1 data-[orientation=vertical]:h-4`}),(0,j.jsx)(`h1`,{className:`truncate text-base font-medium outline-none`,tabIndex:y?-1:void 0,"data-notes-graph-start":y?``:void 0,children:y?`Notes graph`:S?.title??(n.kind===`draft`?`New session`:`Mivra`)})]}),BM?y?(0,j.jsx)(b8,{importId:y}):a?(0,j.jsx)(y7,{error:!0,children:a}):i?(0,j.jsx)(x7,{sessionId:i,course:!!S?.courseId,start:s?.sessionId===i?s:void 0,onStartUsed:()=>c(void 0),onReply:p},i):n.kind===`draft`?(0,j.jsx)(D7,{text:l,onTextChange:u,focus:d,onSaved:_}):(0,j.jsx)(N3,{onStarted:g,onFreeChat:m}):(0,j.jsx)(y7,{error:!0,children:`No API token found. Start the server, then reload this page.`})]})]})}function y7({error:e,children:t}){return(0,j.jsx)(`p`,{className:A(`m-auto p-6 text-center`,e?`text-destructive`:`text-muted-foreground`),children:t})}function b7({sessions:e,activeId:t,drafting:n,theme:r,onThemeChange:i,onSelect:a,onDelete:o,onRenamed:s,onNew:c,onNewCourse:l,onOpenMemory:u,onOpenImports:d,onOpenProviders:f,onOpenSettings:p,onOpenUsage:m}){let{isMobile:h,setOpenMobile:g}=k5(),[_,y]=(0,v.useState)(),b=e=>{y(void 0),requestAnimationFrame(()=>document.querySelector(`[data-session-id="${CSS.escape(e)}"]`)?.focus())},x=()=>{h&&g(!1)};return(0,j.jsxs)(j5,{collapsible:`icon`,children:[(0,j.jsxs)(I5,{children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2 p-1`,children:[(0,j.jsx)(`div`,{className:`bg-sidebar-primary text-sidebar-primary-foreground font-heading grid size-6 shrink-0 place-items-center rounded-md text-sm font-semibold`,children:`M`}),(0,j.jsx)(`span`,{className:`font-heading truncate text-base font-semibold group-data-[collapsible=icon]:hidden`,children:`Mivra`})]}),(0,j.jsxs)(V5,{children:[(0,j.jsx)(H5,{children:(0,j.jsxs)(W5,{variant:`outline`,tooltip:`New session`,isActive:n,onClick:()=>{c(),x()},children:[(0,j.jsx)(Ng,{}),(0,j.jsx)(`span`,{children:`New session`})]})}),(0,j.jsx)(H5,{children:(0,j.jsxs)(W5,{tooltip:`New course`,onClick:()=>{l(),x()},children:[(0,j.jsx)(Uh,{}),(0,j.jsx)(`span`,{children:`New course`})]})})]})]}),(0,j.jsx)(R5,{children:$5(e).map(e=>(0,j.jsxs)(z5,{children:[(0,j.jsx)(B5,{children:e.label}),(0,j.jsx)(V5,{children:e.sessions.map(e=>(0,j.jsx)(H5,{children:_===e.id?(0,j.jsx)(f7,{session:e,onRenamed:s,onDone:()=>b(e.id)}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(W5,{"data-session-id":e.id,isActive:e.id===t,tooltip:e.title,onClick:()=>{a(e.id),x()},children:[e.courseId?(0,j.jsx)(L3,{icon:e.icon,"aria-label":`Course`}):(0,j.jsx)(sg,{}),(0,j.jsx)(`span`,{children:e.title})]}),(0,j.jsx)(d7,{onRename:()=>y(e.id),onDelete:()=>o(e)})]})},e.id))})]},e.label))}),(0,j.jsxs)(L5,{className:`border-t border-sidebar-border`,children:[(0,j.jsxs)(V5,{children:[(0,j.jsx)(H5,{children:(0,j.jsxs)(W5,{tooltip:`Memory`,"data-memory-trigger":!0,onClick:()=>{u(),x()},children:[(0,j.jsx)(Fm,{}),(0,j.jsx)(`span`,{children:`Memory`})]})}),(0,j.jsx)(H5,{children:(0,j.jsxs)(W5,{tooltip:`Imported notes`,"data-imports-trigger":!0,onClick:()=>{d(),x()},children:[(0,j.jsx)(tg,{}),(0,j.jsx)(`span`,{children:`Imported notes`})]})}),(0,j.jsx)(H5,{children:(0,j.jsxs)(W5,{tooltip:`Model providers`,"data-providers-trigger":!0,onClick:()=>{f(),x()},children:[(0,j.jsx)(qh,{}),(0,j.jsx)(`span`,{children:`Model providers`})]})}),(0,j.jsx)(H5,{children:(0,j.jsxs)(W5,{tooltip:`Settings`,"data-settings-trigger":!0,onClick:()=>{p(),x()},children:[(0,j.jsx)(zg,{}),(0,j.jsx)(`span`,{children:`Settings`})]})}),(0,j.jsx)(H5,{children:(0,j.jsxs)(W5,{tooltip:`Usage`,"data-usage-trigger":!0,onClick:()=>{m(),x()},children:[(0,j.jsx)(Um,{}),(0,j.jsx)(`span`,{children:`Usage`})]})})]}),(0,j.jsx)(q5,{choice:r,onChange:i})]}),(0,j.jsx)(N5,{})]})}function x7({course:e,...t}){return e?(0,j.jsx)(S7,{...t}):(0,j.jsx)(C7,{...t})}function S7(e){let{sessionId:t}=e,[n,r]=(0,v.useState)(),[i,a]=(0,v.useState)(),[o,s]=(0,v.useState)(),[c,l]=(0,v.useState)(),[u,d]=(0,v.useState)(!1),f=(0,v.useRef)(0),p=()=>{f.current=performance.now(),d(!0)},[m,h]=(0,v.useState)(),[g,_]=(0,v.useState)(),[y,b]=(0,v.useState)(),x=(0,v.useRef)(void 0),S=(0,v.useRef)(e.onReply);S.current=e.onReply;let C=(0,v.useRef)(!1),w=(0,v.useCallback)(async()=>{let e=await hN(t);if(!e.ok)return h(e.error);if(r(e.value),C.current&&e.value.status!==`interviewing`&&S.current(),C.current=e.value.status===`interviewing`,e.value.status===`interviewing`)return;let n=await gN(e.value.id);n.ok&&a(n.value)},[t]);(0,v.useEffect)(()=>{w()},[w]);let T=async e=>{if(!n)return;let t=await vN(n.id,e);if(!t.ok)return h(t.error);s(t.value.lesson.id),await w()},E=o??i?.currentLessonId??void 0,D=i?.topics.find(e=>e.lesson&&e.lesson.id===i.currentLessonId&&e.lesson.status!==`finished`);(0,v.useEffect)(()=>{if(!E)return;let e=e=>{(e.ctrlKey||e.metaKey)&&!e.altKey&&e.key.toLowerCase()===`k`&&(e.preventDefault(),f.current=performance.now(),d(e=>!e))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[E]);let ee=(0,v.useRef)(0),te=(e,t)=>{_({text:e,send:t,nonce:++ee.current}),p()},ne=async e=>{if(!E)return`No lesson is open.`;let t=x.current?.lessonId===E&&y?.id===E&&y.sections.some(e=>e.id===x.current.section.id)?x.current.section:void 0,n=t??(y?.id===E?y.sections.at(-1):void 0),r=await SN(E,{messageId:e,afterSectionId:n?.id??null,title:t?`More on ${t.title}`.slice(0,120):`From the tutor`});if(!r.ok)return r.error;b(r.value.lesson)},re=n?.syllabus?.version,ie=y?.syllabusVersion;(0,v.useEffect)(()=>{ie&&re&&ie!==re&&w()},[ie,re,w]);let ae=y?.status,oe=y&&i?.topics.find(e=>e.lesson?.id===y.id)?.lesson?.status;(0,v.useEffect)(()=>{ae&&oe&&ae!==oe&&w()},[ae,oe,w]);let se=async()=>{if(!n?.syllabus)return;let e=await CN(n.id,n.syllabus.version);if(!e.ok)return e.error;await w()};if(m)return(0,j.jsx)(y7,{error:!0,children:m});if(!n)return null;let O=i?.topics.find(e=>e.topicId===i.nextTopicId);return E?(0,j.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,j.jsx)(F3,{course:n,onUndo:se,children:(0,j.jsxs)(M,{size:`sm`,variant:`outline`,onClick:p,"data-tutor-trigger":!0,children:[(0,j.jsx)(lg,{"aria-hidden":!0}),` Tutor`]})}),(0,j.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[i&&(0,j.jsx)(`aside`,{className:`hidden w-60 shrink-0 overflow-y-auto border-r p-3 md:block`,children:(0,j.jsx)(V3,{lessons:i,selectedId:E,onSelect:e=>{l(void 0),s(e)}})}),(0,j.jsxs)(`div`,{className:`min-w-0 flex-1 overflow-y-auto`,"data-testid":`lesson-scroll`,children:[i&&(0,j.jsxs)(`details`,{className:`border-b px-4 py-2 md:hidden`,children:[(0,j.jsx)(`summary`,{className:`cursor-pointer text-sm font-medium`,children:`Lessons`}),(0,j.jsx)(`div`,{className:`pt-2`,children:(0,j.jsx)(V3,{lessons:i,selectedId:E,onSelect:e=>{l(void 0),s(e)}})})]}),D&&E!==D.lesson.id&&(0,j.jsxs)(`div`,{className:`bg-muted mx-auto mt-4 flex max-w-3xl flex-wrap items-center gap-2 rounded-lg px-4 py-2 text-sm`,role:`status`,children:[(0,j.jsx)(`span`,{children:`You're looking at an earlier lesson.`}),(0,j.jsxs)(M,{size:`xs`,variant:`outline`,onClick:()=>{l(void 0),s(D.lesson.id)},children:[`Back to lesson `,i.topics.indexOf(D)+1,`: `,D.title]})]}),(0,j.jsx)(H3,{courseComplete:n.status===`complete`,lessonId:E,nextTopic:O&&{id:O.topicId,title:O.title},onFinished:()=>void w(),onStartNext:T,onLoaded:b,focusSectionId:c,onOpenSection:(e,t)=>{s(e),l(t)},onExplain:e=>{x.current={lessonId:E,section:e},te(`Explain "${e.title}"`,!0)},onChange:e=>{x.current=void 0,te(`Change "${e.title}": `,!1)}},E)]})]}),(0,j.jsx)(f6,{open:u,onOpenChange:d,children:(0,j.jsxs)(h6,{className:`flex w-full flex-col gap-0 p-0 sm:max-w-lg`,onPointerDownOutside:e=>{e.detail.originalEvent.timeStamp<f.current&&e.preventDefault()},children:[(0,j.jsxs)(g6,{className:`border-b`,children:[(0,j.jsx)(_6,{className:`font-heading`,children:`Tutor`}),(0,j.jsxs)(v6,{children:[`Ask anything and the lesson stays as it is, or ask for a change. `,(0,j.jsx)(`kbd`,{className:`text-xs`,children:`Ctrl K`}),` opens and closes this.`]})]}),(0,j.jsx)(C7,{...e,onSettled:w,lessonId:E,prompt:g,onPromptUsed:()=>_(void 0),foldThroughMessageId:n.interviewMessageId,placeholder:`Ask the tutor…`,onAddToLesson:y?.status===`ready`?ne:void 0})]})})]}):(0,j.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,j.jsx)(F3,{course:n,children:O&&(0,j.jsx)(M,{size:`sm`,onClick:()=>void T(O.topicId),children:`Start lesson 1`})}),(0,j.jsx)(C7,{...e,onSettled:w})]})}function C7({sessionId:e,onReply:t,...n}){let[r,i]=(0,v.useState)(()=>n.start?[]:void 0),[a,o]=(0,v.useState)();return(0,v.useEffect)(()=>{r||JM(e).then(e=>e.ok?i(e.messages):o(e.error))},[e]),a?(0,j.jsxs)(y7,{error:!0,children:[`Couldn't load this session: `,a]}):r?(0,j.jsx)(w7,{sessionId:e,initialMessages:r,onReply:t,...n}):(0,j.jsxs)(`div`,{className:`text-muted-foreground flex flex-1 items-center justify-center gap-2 text-sm`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Loading the session…`]})}function w7({sessionId:e,initialMessages:t,start:n,onStartUsed:r,onReply:i,onSettled:a,lessonId:o,prompt:s,onPromptUsed:c,onAddToLesson:l,foldThroughMessageId:u,placeholder:d=`What do you want to learn?`}){let[f,p]=(0,v.useState)(!1),m=(0,v.useRef)(o);m.current=o;let[h,g]=(0,v.useState)(n?.input??``),_=Y3(e),y=w3(),b=(0,v.useRef)(_);b.current=_;let[x,S]=(0,v.useState)({}),C=w({initial:`instant`,resize:`instant`}),T=(0,v.useRef)(!1),E=(0,v.useRef)(null),[D,ee]=(0,v.useState)(),[te,ne]=(0,v.useState)(),re=(0,v.useRef)(void 0),ie=(0,v.useRef)(!1),ae=(0,v.useRef)(0),oe=(0,v.useRef)(!1),se=(0,v.useRef)(!1),O=(0,v.useRef)(!1),ce=(0,v.useRef)(0),le=(0,v.useRef)(!0),{messages:ue,sendMessage:de,setMessages:fe,status:pe,error:me,resumeStream:he,stop:ge}=oA({id:e,experimental_throttle:50,messages:t,transport:new Jk({api:`/api/sessions/${e}/chat`,headers:VM,prepareReconnectToStreamRequest:()=>({api:`/api/sessions/${e}/continuation`}),prepareSendMessagesRequest:({messages:e,body:t})=>({body:{...t,message:e.at(-1),...m.current?{lessonId:m.current}:{}}}),fetch:async(e,t)=>{let n=ce.current,r=await fetch(e,t);if(t?.method===`GET`){re.current=r.headers.get(`x-mivra-continuation-stop-id`)??void 0,ie.current=r.status===200,ie.current&&(O.current=!1),r.status===204&&await Ce(n),se.current=!1;let e=r.headers.get(`x-mivra-continuation-error`);if(e&&(ne(e),r.status===204))throw Error(e)}else r.ok&&await b.current.refresh();return r}}),onFinish:({message:t,isDisconnect:n})=>{oe.current||n||!le.current||(ie.current?(ie.current=!1,re.current=void 0,Ce(ce.current)):T.current&&JM(e).then(e=>{e.ok&&fe(n=>n.at(-1)?.id===t.id?e.messages:n)}),i())}}),_e=(0,v.useRef)(0);(0,v.useEffect)(()=>{s&&s.nonce!==_e.current&&(_e.current=s.nonce,c?.(),s.send&&!Se.current.busy?de({text:s.text},{body:{documentIds:[]}}):(g(s.text),requestAnimationFrame(()=>E.current?.focus())))},[s,de,c]);let ve=(0,v.useRef)(!1),{upload:ye}=_;(0,v.useEffect)(()=>{!n||ve.current||t.length>0||(ve.current=!0,r(),n.file&&ye(n.file),n.message&&de({text:n.message},{body:{documentIds:[]}}))},[n,t.length,r,de,ye]),(0,v.useEffect)(()=>{let e=C.scrollRef.current;if(!e)return;e.dataset.testid=`transcript`,e.tabIndex=0,e.setAttribute(`aria-label`,`Conversation messages`);let t,n=e=>{let n=e.touches[0];t=n?{x:n.clientX,y:n.clientY}:void 0},r=n=>{let r=n.touches[0];if(!t||!r||e.scrollTop<=0)return;let i=r.clientY-t.y;i>8&&i>Math.abs(r.clientX-t.x)&&C.stopScroll()},i=t=>{t.target===e&&([`ArrowUp`,`PageUp`,`Home`].includes(t.key)||t.key===` `&&t.shiftKey)&&C.stopScroll()};return e.addEventListener(`touchstart`,n,{passive:!0}),e.addEventListener(`touchmove`,r,{passive:!0}),e.addEventListener(`keydown`,i),()=>{e.removeEventListener(`touchstart`,n),e.removeEventListener(`touchmove`,r),e.removeEventListener(`keydown`,i)}},[C.scrollRef,C.stopScroll]),(0,v.useEffect)(()=>{let e=requestAnimationFrame(()=>{let e=C.scrollRef.current;e&&e.scrollHeight-e.clientHeight-e.scrollTop<=1&&C.scrollToBottom(`instant`)});return()=>cancelAnimationFrame(e)},[x,C.scrollRef,C.scrollToBottom]);let be=pe===`submitted`||pe===`streaming`,xe=(0,v.useRef)(a);xe.current=a,(0,v.useEffect)(()=>{be||xe.current?.()},[be,ue.length]);let Se=(0,v.useRef)({busy:be,resumeStream:he,stop:ge});Se.current={busy:be,resumeStream:he,stop:ge};async function Ce(t){let n=await JM(e);n.ok&&le.current&&ce.current===t&&fe(n.messages)}let we=async(e=!1)=>{if(se.current){e&&(O.current=!0);return}if(Se.current.busy&&!re.current)return;se.current=!0;let t=++ae.current,n=ce.current;try{if(re.current&&(oe.current=!0,await Se.current.stop(),oe.current=!1),!le.current||ce.current!==n)return;se.current=!0,T.current=!1,await Se.current.resumeStream()}finally{ae.current===t&&(se.current=!1,O.current&&le.current&&(O.current=!1,Te.current())),oe.current=!1}},Te=(0,v.useRef)(we);Te.current=we;let Ee=(0,v.useRef)(!!n?.message&&t.length===0);(0,v.useEffect)(()=>{le.current=!0;let e=()=>{document.visibilityState===`visible`&&Te.current()};return Ee.current||e(),window.addEventListener(`focus`,e),document.addEventListener(`visibilitychange`,e),()=>{le.current=!1,window.removeEventListener(`focus`,e),document.removeEventListener(`visibilitychange`,e)}},[]);let De=async()=>{let t=await JM(e);t.ok&&S(e=>T2(e,C2(t.messages))),we(!0)},Oe=async e=>{e.preventDefault();let t=h.trim();if(!t||be)return;T.current=!1,ee(void 0),ne(void 0),ce.current++,ae.current++,O.current=!1,oe.current=!0,await ge(),se.current=!1,oe.current=!1,ie.current=!1,re.current=void 0,C.scrollToBottom(`instant`);let n=_.documents.filter(e=>e.messageId===null).map(e=>e.id);de({text:t},{body:{documentIds:n}}),g(``)},ke=u?ue.findIndex(e=>e.id===u):-1;return(0,j.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,j.jsxs)(f_,{"aria-busy":be,instance:C,initial:`instant`,resize:`instant`,className:`min-h-0 min-w-0`,children:[(0,j.jsxs)(p_,{className:`relative mx-auto max-w-3xl gap-5 px-4 py-6 leading-relaxed`,scrollClassName:`overflow-y-auto overscroll-contain [scrollbar-gutter:auto]!`,onPointerDownCapture:e=>{e.target.closest(`button, input, [role=button]`)&&C.stopScroll()},onKeyDownCapture:e=>{e.key!==`Tab`&&e.target.closest(`button, input, [role=region]`)&&C.stopScroll()},children:[ue.length===0&&!be&&(0,j.jsx)(T7,{}),ke>=0&&!f&&(0,j.jsx)(M,{variant:`ghost`,size:`sm`,className:`text-muted-foreground self-center`,onClick:()=>p(!0),children:`Show the placement interview`}),ue.map((e,t)=>!f&&t<=ke?null:(0,j.jsxs)(`div`,{"data-message-id":e.id,"data-message-role":e.role,className:A(`flex min-w-0 flex-col gap-3`,e.role===`user`&&`bg-sunken text-foreground max-w-[min(80%,34rem)] self-end rounded-2xl rounded-br-sm px-4 py-2.5 leading-relaxed whitespace-pre-wrap wrap-anywhere`),children:[e.role===`user`&&(0,j.jsx)(Q3,{documents:_,messageId:e.id}),e.role===`assistant`&&e.parts.some(e=>e.type===`reasoning`&&e.text.length>0)&&(0,j.jsxs)(t6,{defaultOpen:!1,children:[(0,j.jsxs)(n6,{children:[`Thinking`,x2(pe,t,ue.length)&&e.parts.some(e=>e.type===`reasoning`&&e.state===`streaming`)&&(0,j.jsx)(`span`,{className:`ml-2 text-xs`,children:`In progress…`})]}),(0,j.jsx)(i6,{children:e.parts.map((e,n)=>e.type===`reasoning`&&(0,j.jsx)(r6,{label:(0,j.jsx)(`span`,{className:`whitespace-pre-wrap`,children:e.text}),status:x2(pe,t,ue.length)&&e.state===`streaming`?`active`:`complete`},n))})]}),e.parts.map((n,r)=>n.type===`text`?e.role===`user`?(0,j.jsx)(`p`,{children:n.text},r):(0,j.jsx)(rQ,{text:n.text},r):n.type===`data-artifact`?(0,j.jsx)(b2,{data:S2(n,x),replyInProgress:x2(pe,t,ue.length),onUpdate:e=>{S(t=>T2(t,{[e.id]:e})),we(!0)},onRefresh:De},n.id??r):null),e.role===`assistant`&&typeof e.metadata?.model==`string`&&(0,j.jsx)(`p`,{className:`text-muted-foreground text-xs`,"data-reply-model":!0,children:b3(e.metadata.model,y.view?.models,y.view?.providers)}),l&&e.role===`assistant`&&t>ke&&!x2(pe,t,ue.length)&&e.parts.some(e=>e.type===`text`&&e.text.trim())&&(0,j.jsx)(O7,{onAdd:()=>l(e.id)})]},e.id)),pe===`submitted`&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Thinking…`]}),D&&(0,j.jsx)(`p`,{className:`text-destructive`,children:D}),(me||te)&&((me?k7(me):te)===`ChatGPT usage limit reached. Review your plan or this app's limit in ChatGPT settings.`?(0,j.jsx)(u3,{}):(0,j.jsx)(`p`,{className:`text-destructive`,children:me?k7(me):te}))]}),(0,j.jsx)(m_,{"aria-label":`Scroll to bottom`,onClick:()=>void C.scrollToBottom(`instant`)})]}),(0,j.jsx)(E7,{documents:_,input:h,onInputChange:g,onSubmit:Oe,inputRef:E,placeholder:d,modelPicker:y,action:be?(0,j.jsx)(M,{type:`button`,variant:`secondary`,onClick:async t=>{let n=t.currentTarget,r=document.activeElement===n;try{if(T.current)return;T.current=!0;let t=re.current??ue.findLast(e=>e.role===`user`)?.id;if(!t)return;let i=await HM.sessions[`:id`].stop.$post({param:{id:e},json:{messageId:t}});i.ok&&r&&(document.activeElement===n||document.activeElement===document.body)&&E.current?.focus(),i.ok||(T.current=!1),i.ok||ee(`Couldn’t stop the reply. Try again.`)}catch{T.current=!1,ee(`Couldn’t stop the reply. Try again.`)}},children:`Stop`}):(0,j.jsx)(M,{type:`submit`,disabled:!h.trim(),children:`Send`})})]})}function T7(){return(0,j.jsx)(a6,{className:`my-auto`,children:(0,j.jsxs)(o6,{children:[(0,j.jsx)(c6,{variant:`icon`,children:(0,j.jsx)(lg,{"aria-hidden":`true`})}),(0,j.jsx)(l6,{children:`Start a conversation`}),(0,j.jsx)(u6,{children:`Ask a question, explore a concept or attach course notes to learn from.`})]})})}function E7({documents:e,input:t,onInputChange:n,onSubmit:r,inputRef:i,placeholder:a,modelPicker:o,action:s,disabled:c}){return(0,j.jsxs)(`form`,{onSubmit:r,className:`bg-background border-t`,children:[(0,j.jsx)(Q3,{documents:e}),(0,j.jsx)(`div`,{className:`mx-auto w-full max-w-3xl p-3`,children:(0,j.jsxs)(m7,{className:`bg-card dark:bg-card border-border-strong shadow-paper h-auto min-h-11 rounded-xl`,"aria-label":`Message composer`,children:[(0,j.jsx)(g7,{align:`inline-start`,children:(0,j.jsx)(Z3,{documents:e})}),(0,j.jsx)(_7,{ref:i,value:t,onChange:e=>n(e.target.value),placeholder:a,"aria-label":`Message`,readOnly:c,autoFocus:!0}),(0,j.jsx)(g7,{align:`inline-end`,children:s})]})}),(0,j.jsx)(`div`,{className:`mx-auto flex max-w-3xl px-3 pb-2`,children:(0,j.jsx)(E3,{state:o})})]})}function D7({text:e,onTextChange:t,focus:n,onSaved:r}){let i=w3(),a=(0,v.useRef)(null),[o,s]=(0,v.useState)(),[c,l]=(0,v.useState)();(0,v.useEffect)(()=>{a.current?.focus()},[n]);let u=async(e,t)=>{if(o)return;s({file:t}),l(void 0);let n=await XM();if(s(void 0),!n.ok)return l(n.error);r(n.value,e)},d={documents:[],uploading:o?.file,error:c,upload:t=>u({file:t,input:e},t.name),remove:async()=>{},refresh:async()=>{}};return(0,j.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,j.jsxs)(`div`,{className:`mx-auto flex min-h-0 w-full max-w-3xl flex-1 flex-col overflow-y-auto p-4`,children:[(0,j.jsx)(T7,{}),o&&!o.file&&(0,j.jsxs)(`p`,{className:`text-muted-foreground flex items-center gap-2`,role:`status`,children:[(0,j.jsx)(R2,{"aria-hidden":`true`}),` Thinking…`]})]}),(0,j.jsx)(E7,{documents:d,input:e,onInputChange:t,onSubmit:t=>{t.preventDefault();let n=e.trim();n&&u({message:n})},inputRef:a,placeholder:`What do you want to learn?`,modelPicker:i,disabled:o!==void 0,action:(0,j.jsx)(M,{type:`submit`,disabled:!e.trim()||o!==void 0,children:`Send`})})]})}function O7({onAdd:e}){let[t,n]=(0,v.useState)(`idle`),[r,i]=(0,v.useState)();return(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,j.jsxs)(M,{variant:`outline`,size:`xs`,className:`self-start`,disabled:t!==`idle`,onClick:async()=>{n(`adding`),i(void 0);let t=await e();i(t),n(t?`idle`:`added`)},children:[(0,j.jsx)(Gg,{"aria-hidden":!0}),` `,t===`added`?`Added to lesson`:`Add to lesson`]}),r&&(0,j.jsx)(`span`,{className:`text-destructive text-xs`,children:r})]})}function k7(e){try{let t=JSON.parse(e.message);if(t.error)return t.error}catch{}return e.message}(0,ie.createRoot)(document.getElementById(`root`)).render((0,j.jsx)(v.StrictMode,{children:(0,j.jsx)(v7,{})}));