import{s as j}from"./chunk-LvLJmgfZ.js";import{d as y,l as L,n as P,u as A}from"./useEvent-WUlsM6MC.js";import{A as O,M as T,T as w,cn as E,jt as S,si as _,vi as $}from"./cells-CCtxWKxf.js";import{t as b}from"./compiler-runtime-B3qBwwSJ.js";import{m as D}from"./useEventListener-CjXriKgk.js";import{d as F}from"./utils-CORJ8yYa.js";import{r as x}from"./constants-CdR60lKM.js";import{h as M,x as q}from"./config-D9X9QKiL.js";import{t as B}from"./jsx-runtime-CP2fAiZX.js";import{t as H}from"./cn-d_A4rA-x.js";import{r as R}from"./requests-DZy_SQ_v.js";import{n as U}from"./paths-bMgYkaP2.js";import{s as V}from"./session-DnMOyddG.js";import{n as z}from"./ImperativeModal-CRNJOvqT.js";var G=b();function I(){return A(_)}function J(){let r=(0,G.c)(5),[t]=L(M),e=y(_),{openAlert:s}=z(),{sendRename:o}=R(),a;return r[0]!==t.state||r[1]!==s||r[2]!==o||r[3]!==e?(a=async l=>{let n=F();return t.state===q.OPEN?(V(i=>{l===null?i.delete(x.filePath):i.set(x.filePath,l)}),o({filename:l}).then(()=>(e(l),document.title=n.app_title||U.basename(l)||"Untitled Notebook",l)).catch(i=>(s(i.message),null))):(s("Failed to save notebook: not connected to a kernel."),null)},r[0]=t.state,r[1]=s,r[2]=o,r[3]=e,r[4]=a):a=r[4],P(a)}var p=b(),v=j(B(),1);const h=r=>{let t=(0,p.c)(12),{className:e,cellId:s,variant:o,onClick:a,formatCellName:l,skipScroll:n}=r,i=T()[s]??"",C=O().inOrderIds.indexOf(s),{showCellIfHidden:d}=w(),g=l??W,c;t[0]===e?c=t[1]:(c=H("inline-block cursor-pointer text-link hover:underline",e),t[0]=e,t[1]=c);let m;t[2]!==s||t[3]!==a||t[4]!==d||t[5]!==n||t[6]!==o?(m=k=>{if(s==="__scratch__")return!1;d({cellId:s}),k.stopPropagation(),k.preventDefault(),requestAnimationFrame(()=>{N(s,o,n)&&(a==null||a())})},t[2]=s,t[3]=a,t[4]=d,t[5]=n,t[6]=o,t[7]=m):m=t[7];let f=g(S(i,C)),u;return t[8]!==c||t[9]!==m||t[10]!==f?(u=(0,v.jsx)("div",{className:c,role:"link",tabIndex:-1,onClick:m,children:f}),t[8]=c,t[9]=m,t[10]=f,t[11]=u):u=t[11],u},K=r=>{let t=(0,p.c)(2),e;return t[0]===r?e=t[1]:(e=(0,v.jsx)(h,{...r,variant:"destructive"}),t[0]=r,t[1]=e),e},Q=r=>{let t=(0,p.c)(10),{cellId:e,lineNumber:s}=r,o=I(),a;t[0]!==e||t[1]!==s?(a=()=>E(e,s),t[0]=e,t[1]=s,t[2]=a):a=t[2];let l;t[3]!==e||t[4]!==o?(l=i=>e==="__scratch__"?"scratch":`marimo://${o||"untitled"}#cell=${i}`,t[3]=e,t[4]=o,t[5]=l):l=t[5];let n;return t[6]!==e||t[7]!==a||t[8]!==l?(n=(0,v.jsx)(h,{cellId:e,onClick:a,skipScroll:!0,variant:"destructive",className:"traceback-cell-link",formatCellName:l}),t[6]=e,t[7]=a,t[8]=l,t[9]=n):n=t[9],n};function N(r,t,e){let s=$.create(r),o=document.getElementById(s),a=o==null?void 0:o.classList.contains("has-error");return o===null?(D.error(`Cell ${s} not found on page.`),!1):(e||o.scrollIntoView({behavior:"smooth",block:"center"}),(t==="destructive"||a&&t===void 0)&&(o.classList.add("error-outline"),setTimeout(()=>{o.classList.remove("error-outline")},2e3)),(t==="focus"||!a&&t===void 0)&&(o.classList.add("focus-outline"),setTimeout(()=>{o.classList.remove("focus-outline")},2e3)),!0)}function W(r){return r}export{I as a,N as i,K as n,J as o,Q as r,h as t};
