import{$ as e,Bt as t,Ct as n,F as r,G as i,H as a,Kt as o,L as s,M as c,N as l,Nt as u,Pt as d,R as f,Vt as p,X as m,_ as h,bt as g,ft as _,mt as v,ot as y,p as b,pt as x,st as S,vt as C,z as w}from"../chunks/xY0c-UfG.js";import{r as T}from"../chunks/Bym3iIKr.js";import"../chunks/xihTtKlq.js";import"../chunks/_zekciZc.js";import{t as E}from"../chunks/ByTixK1i.js";import{t as D}from"../chunks/Cvnwo5OO.js";import{d as O,p as k}from"../chunks/BvYk3gM92.js";import{t as A}from"../chunks/DayPzYFE2.js";var j=o({load:()=>M});function M({params:e}){return{viewId:e.id}}var N=w(`<form class="gone-rename svelte-cxwy3h"><input class="gone-input svelte-cxwy3h" placeholder="View name" aria-label="View name"/> <!> <!></form>`),P=w(`<div class="gone-actions svelte-cxwy3h"><!> <!> <!></div>`),F=w(`<div class="gone-state svelte-cxwy3h"><p class="gone-title svelte-cxwy3h">This view’s folder is no longer available</p> <p class="gone-hint svelte-cxwy3h"> </p> <!></div>`);function I(o,w){d(w,!0);let j=n(()=>Number(w.data.viewId)),M=new Set,I=g(!1);S(()=>{let t=m(j);if(!O.loaded){e(()=>O.load());return}!O.views.some(e=>e.id===t)&&!M.has(t)&&(M.add(t),C(I,!0),e(()=>O.load().finally(()=>{C(I,!1)})))});let L=n(()=>O.views.find(e=>e.id===m(j))??null),R=n(()=>O.loaded&&!m(I)&&m(L)===null);S(()=>{m(R)&&e(()=>T(`/`))});let z=g(!1),B=g(``),V=g(!1);function H(){C(B,m(L)?.name??``,!0),C(z,!0)}async function U(){let e=m(L),t=m(B).trim();if(!(!e||!t||m(V))){C(V,!0);try{await O.rename(e.id,t),C(z,!1)}finally{C(V,!1)}}}async function W(){let e=m(L);if(!(!e||m(V))){C(V,!0);try{await O.remove(e.id),T(`/`)}finally{C(V,!1)}}}S(()=>{E.showView(-1)}),S(()=>{let t=m(L);e(()=>{t?.resolvedScope?.kind===`folder`?E.selectRepo(t.resolvedScope.repo,t.resolvedScope.folderPath):E.deselect()})});let G=n(()=>m(L)?.resolvedScope?.kind===`type`?m(L).resolvedScope.entityType:null),K=n(()=>m(L)?.resolvedScope?.kind===`folder`?m(L).resolvedScope.repo:null),q=n(()=>m(L)?.resolvedScope?.kind===`folder`?m(L).resolvedScope.folderPath:null),J=n(()=>!m(L)?.resolvedScope||m(L).resolvedScope.kind===`gone`);var Y=f(),X=x(Y),Z=e=>{var t=f();c(x(t),()=>m(L).id,e=>{{let t=n(()=>`view-${m(L).id}`),r=n(()=>k(m(L).config));A(e,{get name(){return m(L).name},get storageId(){return m(t)},get lockedType(){return m(G)},get lockedFolder(){return m(K)},get lockedFolderPath(){return m(q)},get seedScratch(){return m(r)},get savedViewId(){return m(L).id}})}}),s(e,t)},Q=e=>{var o=F(),c=v(_(o),2),u=_(c);p(c);var d=v(c,2),f=e=>{var r=N(),o=_(r);h(o);var c=v(o,2);{let e=n(()=>m(V)||!m(B).trim());D(c,{type:`submit`,variant:`accent`,get disabled(){return m(e)},children:(e,n)=>{t(),s(e,a(`Save`))},$$slots:{default:!0}})}D(v(c,2),{variant:`ghost`,onclick:()=>C(z,!1),get disabled(){return m(V)},children:(e,n)=>{t(),s(e,a(`Cancel`))},$$slots:{default:!0}}),p(r),i(`submit`,r,e=>{e.preventDefault(),U()}),b(o,()=>m(B),e=>C(B,e)),s(e,r)},g=e=>{var n=P(),r=_(n);D(r,{variant:`outline`,onclick:H,get disabled(){return m(V)},children:(e,n)=>{t(),s(e,a(`Rename`))},$$slots:{default:!0}});var i=v(r,2);D(i,{variant:`destructive`,onclick:W,get disabled(){return m(V)},children:(e,n)=>{t(),s(e,a(`Delete view`))},$$slots:{default:!0}}),D(v(i,2),{variant:`ghost`,onclick:()=>T(`/`),get disabled(){return m(V)},children:(e,n)=>{t(),s(e,a(`Go home`))},$$slots:{default:!0}}),p(n),s(e,n)};l(d,e=>{m(z)?e(f):e(g,-1)}),p(o),y(()=>r(u,`The folder “${m(L).name??``}” pointed at was deleted, or you no longer have access to it.`)),s(e,o)};l(X,e=>{m(L)&&!m(J)?e(Z):m(L)&&m(J)&&e(Q,1)}),s(o,Y),u()}export{I as component,j as universal};