import{s as g}from"./chunk-LvLJmgfZ.js";import{d as P,l as j,n as w,u as O}from"./useEvent-D91BmmQi.js";import{D as T,Li as y,Lt as A,M as D,P as E,Ti as _,hn as S}from"./cells-DOA0Gew8.js";import{t as b}from"./compiler-runtime-B3qBwwSJ.js";import{_ as $}from"./useEventListener-DvoEXWke.js";import{p as F}from"./utils-CvI-39U6.js";import{r as I}from"./constants-DMpttj8Q.js";import{v as M,w as R}from"./config-ClMcu_sV.js";import{t as q}from"./cn-DCUzRj2J.js";import{t as B}from"./jsx-runtime-BqBOg78p.js";import{r as H}from"./requests-DIwGYs0l.js";import{n as U}from"./paths-D5zczhUD.js";import{s as V}from"./session-0B5NBztP.js";import{n as z}from"./ImperativeModal-BW1dmntO.js";var G=b();function N(){return O(_)}function J(){let r=(0,G.c)(5),[t]=j(M),e=P(_),{openAlert:s}=z(),{sendRename:o}=H(),a;return r[0]!==t.state||r[1]!==s||r[2]!==o||r[3]!==e?(a=async l=>{let n=F();return t.state===R.OPEN?(V(i=>{l===null?i.delete(I.filePath):i.set(I.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],w(a)}var p=b(),v=g(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=E()[s]??"",C=D().inOrderIds.indexOf(s),{showCellIfHidden:d}=T(),L=l??W,c;t[0]===e?c=t[1]:(c=q("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(()=>{x(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=L(A(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=N(),a;t[0]!==e||t[1]!==s?(a=()=>S(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 x(r,t,e){let s=y.create(r),o=document.getElementById(s),a=o==null?void 0:o.classList.contains("has-error");return o===null?($.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{N as a,x as i,K as n,J as o,Q as r,h as t};
