import{s as p}from"./chunk-DZLz74EQ.js";import{c as P,l as w,s as E}from"./jotai-DDOP7CKM.js";import{Br as L,E as O,Fn as y,N as A,ft as F,j as S,kr as _,wn as T}from"./cells-B6jS0AIj.js";import{n as N,t as $}from"./jsx-runtime-DvsdsEjx.js";import{u as B}from"./hotkeys-Lbk6RHir.js";import{u as D}from"./utils-DnJCRgaX.js";import{n as I}from"./constants-DIZnpo2K.js";import{d as q}from"./config-BjdJmdrN.js";import{t as H}from"./cn-C5VTNYKf.js";import{r as M}from"./requests-D3Z6okhb.js";import{s as R,t as U}from"./connection-DnLUBy9M.js";import{n as V}from"./useEvent-d8iQXgui.js";import{n as z}from"./ImperativeModal-CmOSTULR.js";var G=p(N(),1);function x(){return P(_)}function J(){let r=(0,G.c)(5),[t]=E(U),e=w(_),{openAlert:a}=z(),{sendRename:s}=M(),o;return r[0]!==t.state||r[1]!==a||r[2]!==s||r[3]!==e?(o=async n=>{let l=D();return t.state===R.OPEN?(q(i=>{n===null?i.delete(I.filePath):i.set(I.filePath,n)}),s({filename:n}).then(()=>(e(n),document.title=l.app_title||T.basename(n)||"Untitled Notebook",n)).catch(i=>(a(i.message),null))):(a("Failed to save notebook: not connected to a kernel."),null)},r[0]=t.state,r[1]=a,r[2]=s,r[3]=e,r[4]=o):o=r[4],V(o)}var v=p(N(),1),k=p($(),1);const h=r=>{let t=(0,v.c)(12),{className:e,cellId:a,variant:s,onClick:o,formatCellName:n,skipScroll:l}=r,i=A()[a]??"",g=S().inOrderIds.indexOf(a),{showCellIfHidden:d}=O(),j=n??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]!==a||t[3]!==o||t[4]!==d||t[5]!==l||t[6]!==s?(m=b=>{if(a==="__scratch__")return!1;d({cellId:a}),b.stopPropagation(),b.preventDefault(),requestAnimationFrame(()=>{C(a,s,l)&&(o==null||o())})},t[2]=a,t[3]=o,t[4]=d,t[5]=l,t[6]=s,t[7]=m):m=t[7];let f=j(F(i,g)),u;return t[8]!==c||t[9]!==m||t[10]!==f?(u=(0,k.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,v.c)(2),e;return t[0]===r?e=t[1]:(e=(0,k.jsx)(h,{...r,variant:"destructive"}),t[0]=r,t[1]=e),e},Q=r=>{let t=(0,v.c)(10),{cellId:e,lineNumber:a}=r,s=x(),o;t[0]!==e||t[1]!==a?(o=()=>y(e,a),t[0]=e,t[1]=a,t[2]=o):o=t[2];let n;t[3]!==e||t[4]!==s?(n=i=>e==="__scratch__"?"scratch":`marimo://${s||"untitled"}#cell=${i}`,t[3]=e,t[4]=s,t[5]=n):n=t[5];let l;return t[6]!==e||t[7]!==o||t[8]!==n?(l=(0,k.jsx)(h,{cellId:e,onClick:o,skipScroll:!0,variant:"destructive",className:"traceback-cell-link",formatCellName:n}),t[6]=e,t[7]=o,t[8]=n,t[9]=l):l=t[9],l};function C(r,t,e){let a=L.create(r),s=document.getElementById(a);return s===null?(B.error(`Cell ${a} not found on page.`),!1):(e||s.scrollIntoView({behavior:"smooth",block:"center"}),t==="destructive"&&(s.classList.add("error-outline"),setTimeout(()=>{s.classList.remove("error-outline")},2e3)),t==="focus"&&(s.classList.add("focus-outline"),setTimeout(()=>{s.classList.remove("focus-outline")},2e3)),!0)}function W(r){return r}export{x as a,C as i,K as n,J as o,Q as r,h as t};
