import{s as j}from"./chunk-LvLJmgfZ.js";import{d as L,l as P,n as E,u as O}from"./useEvent-D91BmmQi.js";import{E as T,N as w,Qi as b,j as y,kt as A,ua as S,un as $}from"./cells-CJLUCcQg.js";import{t as _}from"./compiler-runtime-B3qBwwSJ.js";import{g as D}from"./useEventListener-C0195JsF.js";import{m as F}from"./utils-BWBBpCkT.js";import{r as N}from"./constants-CDyU_g2F.js";import{T as q,v as B}from"./config-B-Q7J_6d.js";import{t as H}from"./cn-DYvqRARy.js";import{t as M}from"./jsx-runtime-Blw4afVn.js";import{r as Q}from"./requests-9-v2bhoi.js";import{n as R}from"./paths-BKO-pHK6.js";import{s as U}from"./session-BmukRjSi.js";import{n as V}from"./ImperativeModal-fY-ZfT0b.js";var z=_();function I(){return O(b)}function G(){let r=(0,z.c)(5),[t]=P(B),e=L(b),{openAlert:s}=V(),{sendRename:o}=Q(),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?(U(i=>{l===null?i.delete(N.filePath):i.set(N.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],E(a)}var p=_(),v=j(M(),1);const k=r=>{let t=(0,p.c)(12),{className:e,cellId:s,variant:o,onClick:a,formatCellName:l,skipScroll:n}=r,i=w()[s]??"",C=y().inOrderIds.indexOf(s),{showCellIfHidden:d}=T(),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=h=>{if(s==="__scratch__")return!1;d({cellId:s}),h.stopPropagation(),h.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)(k,{...r,variant:"destructive"}),t[0]=r,t[1]=e),e},K=r=>{let t=(0,p.c)(10),{cellId:e,lineNumber:s}=r,o=I(),a;t[0]!==e||t[1]!==s?(a=()=>$(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)(k,{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=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,x as i,J as n,G as o,K as r,k as t};
