import{Bt as e,Ct as t,D as n,F as r,H as i,L as a,N as o,Nt as s,Pt as c,R as l,Vt as u,X as d,bt as f,ft as p,mt as m,ot as h,pt as g,st as _,vt as v,z as y}from"./xY0c-UfG.js";import"./xihTtKlq.js";import{t as b}from"./vgzQgl7V.js";import{A as x,E as S,O as C,T as w,j as T,k as E,w as D}from"./B7ikU8uG.js";import{t as O}from"./Cvnwo5OO.js";import{d as k,f as A,m as j,u as M}from"./BvYk3gM92.js";import{t as N}from"./DDbpVNi02.js";var P=y(`<p class="dialog-error svelte-1p20661"> </p>`),F=y(`<!> <!> <!>`,1),I=y(`<!> <!>`,1),L=y(`<!> <!> <!>`,1);function R(y,R){c(R,!0);let z=t(()=>M.request),B=f(``),V=f(!1),H=f(null);_(()=>{let e=d(z);e&&(v(B,A({scopeLabel:e.scopeLabel,viz:e.viz,groupByLabel:e.groupByLabel}),!0),v(H,null))});async function U(){let e=d(z);if(!e||d(V))return;let t=d(B).trim();if(!t){v(H,`Enter a name`);return}v(V,!0),v(H,null);let n=await k.create(t,{config:j(e.scratch),viewType:e.viz,scope:e.defaultScope});v(V,!1),n?(M.close(),b.showToast(`Saved view “${t}”`)):v(H,`Could not save the view`)}var W=l();n(g(W),()=>T,(s,c)=>{c(s,{get open(){return M.open},onOpenChange:e=>{e||M.close()},children:(s,c)=>{var f=l();n(g(f),()=>x,(s,c)=>{c(s,{size:`sm`,children:(s,c)=>{var f=L(),_=g(f);n(_,()=>E,(e,t)=>{t(e,{class:`close-only-header`,children:(e,t)=>{var r=l();n(g(r),()=>D,(e,t)=>{t(e,{})}),a(e,r)},$$slots:{default:!0}})});var y=m(_,2);n(y,()=>S,(t,s)=>{s(t,{class:`dialog-body-lg`,children:(t,s)=>{var c=F(),l=g(c);n(l,()=>C,(t,n)=>{n(t,{children:(t,n)=>{e(),a(t,i(`Save view`))},$$slots:{default:!0}})});var f=m(l,2);N(f,{type:`text`,placeholder:`View name`,onkeydown:e=>{e.key===`Enter`&&(e.preventDefault(),U())},get value(){return d(B)},set value(e){v(B,e,!0)}});var _=m(f,2),y=e=>{var t=P(),n=p(t,!0);u(t),h(()=>r(n,d(H))),a(e,t)};o(_,e=>{d(H)&&e(y)}),a(t,c)},$$slots:{default:!0}})}),n(m(y,2),()=>w,(n,r)=>{r(n,{children:(n,r)=>{var o=I(),s=g(o);O(s,{variant:`ghost`,onclick:()=>M.close(),children:(t,n)=>{e(),a(t,i(`Cancel`))},$$slots:{default:!0}});var c=m(s,2);{let n=t(()=>!d(B).trim());O(c,{variant:`accent`,get disabled(){return d(n)},get loading(){return d(V)},onclick:U,children:(t,n)=>{e(),a(t,i(`Save view`))},$$slots:{default:!0}})}a(n,o)},$$slots:{default:!0}})}),a(s,f)},$$slots:{default:!0}})}),a(s,f)},$$slots:{default:!0}})}),a(y,W),s()}export{R as default};