1import{j as e,E as C,a2 as s,A as I,p as ge,f as je,u as we,q as ke,r,a as ve,L as A,C as be,S as c,v as De,T as j,G as F,o as ze,a3 as ye,b as d,s as Se,w as R,g as Ce,R as Ie,B as w,x as m,a4 as G}from"./index-CB1LRsvg.js";import{W as $e}from"./WorkspaceBreadcrumbs-D1n3jZND.js";import{P as Te}from"./PageHeader-Cn1NvYjo.js";import{a as k}from"./layout-2mrj5SBU.js";import{I as O}from"./IconPresentation-C3fRhwcl.js";import{E as Ee}from"./EmptyState-DqWHbZL6.js";import{C as Le}from"./IconChartDots-DkoRXFwt.js";import{b as We,s as _,d as Pe}from"./useDecks-Re5MFzij.js";import{a as Ne}from"./useVisualization-C3neUNqV.js";import{V as Be}from"./VisualizationLibrary-BKs2u01E.js";import{g as U}from"./vizTitle-DtATiW7_.js";import{I as q}from"./IconUpload-A3Bp_SVN.js";import{I as Ve}from"./IconChartBar-BP2caZyo.js";import{I as Me}from"./IconStar-9-CEEvth.js";import{I as H}from"./IconTrash-B56plgcD.js";import{I as Ae}from"./IconPencil-oMykwAVz.js";import{I as Fe}from"./IconCode-0PJYF6Gd.js";import{A as K}from"./AddDatasourceButton-BLNHQZxN.js";import{D as Re}from"./DeckLibrary-D37siqkp.js";import{I as Ge}from"./IconDots-B1aCp1zV.js";import{S as Oe}from"./SectionTitle-DUWdJHXc.js";import{u as _e}from"./useConfirm-B_NA31aX.js";import{u as Ue}from"./usePrompt-pQsCHLvP.js";import{u as qe}from"./usePageTitle-PP7G01cs.js";import{C as He}from"./Container-Bk7wpkPw.js";import{B as Ke}from"./Badge-CvorhVBt.js";import{C as Qe}from"./Card-DwzWyE8m.js";import"./Breadcrumbs-Jo-mBNaQ.js";import"./ThemeIcon-DUJfKgY0.js";import"./IconCopy-Coo_r-4m.js";import"./use-clipboard-Dyb8n21I.js";import"./IconSearch-CqQSV7iv.js";import"./libraryView-De30Gts8.js";import"./VisualizationImage-9QCisdbA.js";import"./IconPhoto-DUZWNaK7.js";import"./pressable-tRM_bxh-.js";import"./AspectRatio-CMHm-VhU.js";import"./SegmentedControl-B2vw4mHc.js";import"./SimpleGrid-C5deGO61.js";import"./richText-CBRloJre.js";import"./List-DPFssads.js";function Q({label:i,children:v}){return e.jsx(C,{flex:"none",onClick:n=>n.stopPropagation(),onKeyDown:n=>n.stopPropagation(),children:e.jsxs(s,{shadow:"md",position:"bottom-end",withinPortal:!0,children:[e.jsx(s.Target,{children:e.jsx(I,{variant:"subtle",color:"gray",size:"sm","aria-label":i,children:e.jsx(Ge,{size:16,"aria-hidden":!0})})}),e.jsx(s.Dropdown,{children:v})]})})}function Mt(){var M;const{workspace:i}=ge(),v=je(),{loading:n,workspaces:b}=we(),{loading:J,decks:D,refetch:z}=We(i),{visualizations:X,loading:Y,refetch:Z}=Ne(i),{capability:x,loading:ee}=ke(i),[te,y]=r.useState(!1),[f,ie]=r.useState(""),[$,ae]=r.useState(""),[p,T]=r.useState(!1),[se,E]=r.useState(!1),[L,W]=r.useState(null),[P,u]=r.useState("pending"),{confirm:N,confirmDialog:oe}=_e(),{prompt:re,promptDialog:ne}=Ue(),{canCreateContent:le,loading:ce}=ve(),g=b==null?void 0:b.find(t=>t.id===i);r.useEffect(()=>{if(!i||n)return;if(g){W(null),u("found");return}let t=!1;return u("pending"),fetch(`/v2/workspaces/${i}`,{credentials:"include"}).then(async a=>{t||(a.ok?(W(await a.json()),u("found")):u("notfound"))}).catch(()=>{t||u("notfound")}),()=>{t=!0}},[g,i,n]);const B=(M=g??L)==null?void 0:M.name;if(qe(B?`Workspace: ${B}`:void 0),n||P==="pending")return e.jsx(A,{visible:!0});if(P==="notfound")return e.jsx(be,{h:"var(--app-vh)",w:"100%",children:e.jsxs(c,{align:"center",justify:"center",ta:"center",gap:0,children:[e.jsx(De,{children:"404"}),e.jsx(j,{fw:"bold",mb:"xs",size:"lg",children:"Workspace Not Found"}),e.jsx(j,{size:"sm",children:"This workspace doesn't exist or you don't have access to it."})]})});if(J||ce||ee)return e.jsx(A,{visible:!0});const o=g??L??void 0,de=async()=>{if(f.trim())try{T(!0);const t=await _({title:f,description:$||void 0,private:!0,workspace_id:i});v(`/${i}/decks/${t.id}`)}catch(t){m.show({color:"red",message:"Failed to create deck: "+t.message})}finally{T(!1)}},me=async t=>{const a=await re({title:"Rename deck",label:"Title",initialValue:t.title,confirmLabel:"Rename"});if(!(a==null||a.trim()===t.title))try{await _({id:t.id,title:a.trim(),description:t.description,private:t.private,workspace_id:t.workspace_id}),await z()}catch{m.show({color:"red",message:"Couldn't rename the deck"})}},pe=async t=>{const a=t.title||"this deck";if(await N({title:"Delete deck?",message:`â${a}â and its slides will be permanently deleted. This canât be undone.`,confirmLabel:"Delete"}))try{await Pe(t.id),await z(),m.show({color:"green",message:`Deleted â${a}â`})}catch{m.show({color:"red",message:`Couldn't delete â${a}â`})}},ue=async t=>{const a=U(t)||"this visualization",l=t.deck_names??[];if(await N({title:"Delete visualization?",message:`â${a}â will be permanently deleted. This canât be undone.${l.length>0?` Itâs used in ${l.join(", ")}; those slides will show an âunavailableâ placeholder.`:""}`,confirmLabel:"Delete"}
1))try{if(!(await fetch(`/v2/visualizations/${t.id}`,{method:"DELETE",credentials:"include"})).ok)throw new Error("Failed to delete visualization");await Promise.all([Z(),z()]),m.show({color:"green",message:`Deleted â${a}â`})}catch{m.show({color:"red",message:`Couldn't delete â${a}â`})}},h=le&&!!x&&x!=="read",he=t=>e.jsxs(Q,{label:`Options for ${t.title||"deck"}`,children:[e.jsx(s.Item,{component:d,to:`/${i}/decks/${t.id}`,leftSection:e.jsx(G,{size:16,"aria-hidden":!0}),children:"Open"}),e.jsx(s.Item,{leftSection:e.jsx(Ae,{size:16,"aria-hidden":!0}),onClick:()=>void me(t),children:"Rename"}),e.jsx(s.Divider,{}),e.jsx(s.Item,{color:"red",leftSection:e.jsx(H,{size:16,"aria-hidden":!0}),onClick:()=>void pe(t),children:"Delete"})]}),xe=t=>{var l,S;const a=!!((l=t.content)!=null&&l.sql)&&!!((S=t.content)!=null&&S.datasource_id)&&!t.locked;return e.jsxs(Q,{label:`Options for ${U(t)||"visualization"}`,children:[e.jsx(s.Item,{component:d,to:`/${i}/visualization/${t.id}`,leftSection:e.jsx(G,{size:16,"aria-hidden":!0}),children:"Open"}),a&&e.jsx(s.Item,{component:d,to:`/${i}/visualization/new?edit=${t.id}`,leftSection:e.jsx(Fe,{size:16,"aria-hidden":!0}),children:"Edit query"}),e.jsx(s.Divider,{}),e.jsx(s.Item,{color:"red",leftSection:e.jsx(H,{size:16,"aria-hidden":!0}),onClick:()=>void ue(t),children:"Delete"})]})},V=h&&e.jsx(w,{size:"xs",variant:"default",leftSection:e.jsx(O,{size:14,"aria-hidden":!0}),onClick:()=>y(!0),children:"New Deck"}),fe=h&&e.jsx(w,{size:"xs",variant:"primary",component:d,to:`/${i}/visualization/new`,leftSection:e.jsx(Ve,{size:14,"aria-hidden":!0}),children:"New Visualization"});return e.jsxs(He,{size:"lg",py:"xl",children:[e.jsxs(c,{gap:k.sectionGap,children:[e.jsx(Te,{breadcrumbs:e.jsx($e,{workspace:i}),title:o==null?void 0:o.name,badge:(o==null?void 0:o.discoverable)&&e.jsx(Ke,{variant:"light",color:"blue",leftSection:e.jsx(Me,{size:12,"aria-hidden":!0}),title:"Featured as an Example on the Explore page",children:"Example"}),actions:x&&e.jsxs(F,{gap:"xs",wrap:"nowrap",style:{flex:"none"},children:[h&&e.jsxs(e.Fragment,{children:[e.jsx(C,{visibleFrom:"sm",children:e.jsx(K,{workspaceId:i,leftSection:e.jsx(q,{size:16,"aria-hidden":!0}),children:"Upload Datasource"})}),e.jsx(C,{hiddenFrom:"sm",children:e.jsx(K,{workspaceId:i,iconOnly:!0,leftSection:e.jsx(q,{size:16,"aria-hidden":!0}),children:"Upload Datasource"})})]}),(o==null?void 0:o.discoverable)&&e.jsx(ze,{label:"Share",withArrow:!0,children:e.jsx(I,{size:"lg",variant:"default",onClick:()=>E(!0),"aria-label":"Share",children:e.jsx(ye,{size:16,"aria-hidden":!0})})}),x==="manage"&&e.jsx(I,{component:d,size:"lg",variant:"subtle",color:"gray",to:`/${i}/settings`,"aria-label":"Settings",children:e.jsx(Se,{size:20,"aria-hidden":!0})})]})}),D&&D.length>0?e.jsx(Re,{decks:D,workspaceId:i,trailing:V,renderMenu:h?he:void 0}):e.jsxs(c,{gap:k.headingGap,children:[e.jsx(Oe,{count:0,mb:0,trailing:V,children:"Decks"}),e.jsx(Qe,{withBorder:!0,padding:k.cardPadding,children:e.jsx(Ee,{icon:e.jsx(O,{size:20,"aria-hidden":!0}),title:"No decks yet",description:"Arrange this workspaceâs charts into slides you can present or export."})})]}),!Y&&e.jsx(c,{gap:k.headingGap,children:e.jsx(Be,{visualizations:X??[],workspaceId:i,title:"Visualizations",emptyText:"No visualizations yet",trailing:fe,renderMenu:h?xe:void 0})})]}),e.jsx(R,{size:"auto",opened:te,onClose:()=>y(!1),title:"Create New Deck",children:e.jsxs(c,{gap:"md",w:"100%",miw:{base:0,sm:400},children:[e.jsx(Ce,{label:"Title",placeholder:"Deck title",value:f,onChange:t=>ie(t.currentTarget.value),disabled:p}),e.jsx(Ie,{label:"Description (optional)",placeholder:"Add a description...",value:$,onChange:t=>ae(t.currentTarget.value),disabled:p,rows:3}),e.jsxs(F,{justify:"flex-end",gap:"sm",children:[e.jsx(w,{variant:"default",onClick:()=>y(!1),disabled:p,children:"Cancel"}),e.jsx(w,{variant:"primary",onClick:de,disabled:!f.trim()||p,loading:p,children:"Create Deck"})]})]})}),e.jsx(R,{size:"auto",opened:se,onClose:()=>E(!1),title:"Share Workspace",children:e.jsxs(c,{maw:600,w:"calc(100vw - var(--mantine-spacing-xl) * 2)",gap:"md",children:[e.jsx(j,{size:"sm",c:"dimmed",children:"This workspace is featured as an Example. Any logged-in user with this link can view it and its decks and visualizations."}),e.jsx(Le,{label:"Workspace URL",url:`${window.location.origin}/${i}`}),e.jsxs(j,{size:"xs",c:"dimmed",children:["It is also discoverable on the"," ",e.jsx(d,{to:"/explore",style:{color:"inherit"},children:"Explore page"}),"."]})]})}),oe,ne]})}export{Mt as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.