import{s as L}from"./chunk-LvLJmgfZ.js";import{d as P,l as j,n as w,u as O}from"./useEvent-D91BmmQi.js";import{D as y,Lt as A,M as D,Mi as _,P as E,Wi as M,hn as S}from"./cells-DQ5n6Zef.js";import{t as b}from"./compiler-runtime-B3qBwwSJ.js";import{_ as T}from"./useEventListener-BakX-tnw.js";import{p as $}from"./utils-Dev6I_Kv.js";import{r as I}from"./constants-B9JJ72XE.js";import{v as F,w as q}from"./config-BE150fVL.js";import{t as B}from"./cn-X2M2usMq.js";import{t as G}from"./jsx-runtime-PbYoItBR.js";import{r as H}from"./requests-KshNNAOp.js";import{n as R}from"./paths-kNeJ8nbe.js";import{s as U}from"./session-B6_8umQX.js";import{n as V}from"./ImperativeModal-MQnbMIO2.js";var W=b();function N(){return O(_)}function z(){let r=(0,W.c)(5),[t]=j(F),e=P(_),{openAlert:s}=V(),{sendRename:o}=H(),a;return r[0]!==t.state||r[1]!==s||r[2]!==o||r[3]!==e?(a=async l=>{let n=$();return t.state===q.OPEN?(U(i=>{l===null?i.delete(I.filePath):i.set(I.filePath,l)}),o({filename:l}).then(()=>(e(l),document.title=n.app_title||R.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=L(G(),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}=y(),g=l??Q,c;t[0]===e?c=t[1]:(c=B("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=g(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},J=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},K=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=M.create(r),o=document.getElementById(s),a=o==null?void 0:o.classList.contains("has-error");return o===null?(T.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 Q(r){return r}export{N as a,x as i,J as n,z as o,K as r,h as t};
