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"./BXmb29An.js";import{E as x,M as S,N as C,O as w,P as T,j as E,k as D}from"./CcwhSY5o.js";import{f as O,g as k,m as A,p as j}from"./BsK1_UFs.js";import{t as M}from"./Cvnwo5OO2.js";import{t as N}from"./DU2630_A.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(()=>O.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 j.create(t,{config:k(e.scratch),viewType:e.viz,scope:e.defaultScope});v(V,!1),n?(O.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 O.open},onOpenChange:e=>{e||O.close()},children:(s,c)=>{var f=l();n(g(f),()=>C,(s,c)=>{c(s,{size:`sm`,children:(s,c)=>{var f=L(),_=g(f);n(_,()=>S,(e,t)=>{t(e,{class:`close-only-header`,children:(e,t)=>{var r=l();n(g(r),()=>x,(e,t)=>{t(e,{})}),a(e,r)},$$slots:{default:!0}})});var y=m(_,2);n(y,()=>D,(t,s)=>{s(t,{class:`dialog-body-lg`,children:(t,s)=>{var c=F(),l=g(c);n(l,()=>E,(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);M(s,{variant:`ghost`,onclick:()=>O.close(),children:(t,n)=>{e(),a(t,i(`Cancel`))},$$slots:{default:!0}});var c=m(s,2);{let n=t(()=>!d(B).trim());M(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};