import{r as P,j as e}from"./vendor-react-wBh_31cN.js";import{aV as G,G as h,D as I,z as K,B as A,C as z,E as S,F as $}from"./index-dNe6i2rS.js";import{I as x}from"./icon-button-BZeFL7T7.js";import{T as b}from"./tooltip-DFFgUYh6.js";import{I as B}from"./input-DFI7JniT.js";import{u as L}from"./useCopyToClipboard-DfzwgDFE.js";import{u as _}from"./useNotifier-BGMn6HaH.js";import{u as H}from"./useCurrentProject-CTMLbmkf.js";import{u as V}from"./useProjectRole-DpUIGfh9.js";import{a as q}from"./utils-C3tzOLw4.js";import{b as Q}from"./index-z4ckdzvI.js";import{bF as N,aI as M,a6 as J,aj as W,S as T}from"./vendor-icons-BUUmD6ht.js";import{K as X,a as Y}from"./KubeMonitoringPods-AgUoLYA7.js";const Z=window.location.origin,me=({projectId:r,appName:l,appKind:d,publicAccess:n,publicToken:a,serving:c,compact:i=!1})=>{const{isDataOwner:p}=V(),{project:o}=H(),g=_(),{copyToClipboard:U,copied:j}=L(),[F,{isLoading:f}]=Q(),[u,m]=P.useState(null),{data:O}=G("streamlit_sharing"),R=O==="true",k=o==null?void 0:o.projectName;if(d!==q.STREAMLIT||!p||!R)return null;const t=!!n,C=f||!t&&!c,y=s=>s&&k?`${Z}/hopsworks-api/pythonapp/${encodeURIComponent(k)}/${encodeURIComponent(l)}/__public?t=${encodeURIComponent(s)}`:null,v=y(a),D=async()=>{try{const s=await F({pId:r,name:l,enabled:!t}).unwrap();t?g.success({title:"App is now private",content:""}):i&&m(y(s==null?void 0:s.publicToken))}catch{g.error({title:"Could not change public access",content:""})}},E=t?"Make private":c?"Make public (no login required)":"Start the app to make it public",w=s=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{readOnly:!0,value:s,className:"flex-1"}),e.jsx(b,{content:j?"Copied":"Copy link",children:e.jsx(x,{"aria-label":"Copy public link",onClick:()=>U(s),children:j?e.jsx(J,{className:"size-4"}):e.jsx(W,{className:"size-4"})})})]});return e.jsxs(e.Fragment,{children:[i?e.jsx(b,{content:E,children:e.jsx(x,{"aria-label":t?"Make app private":"Make app public",disabled:C,onClick:s=>{s.stopPropagation(),D()},children:t?e.jsx(N,{className:"text-primary"}):e.jsx(M,{})})}):e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs(h,{variant:t?"outline":"default",disabled:C,loading:f,onClick:D,className:"w-fit",children:[t?e.jsx(N,{className:"mr-1.5 size-4"}):e.jsx(M,{className:"mr-1.5 size-4"}),t?"Make private":"Make public"]}),t&&v&&w(v)]}),e.jsx(I,{open:!!u,onOpenChange:s=>!s&&m(null),children:e.jsxs(K,{children:[e.jsxs(A,{children:[e.jsx(z,{children:"Public link created"}),e.jsx(S,{children:"Anyone with this link can use the app with no Hopsworks login. The app runs with its own credentials and data access, so the link grants the app's full privileges. Disable public access any time to revoke it."})]}),u&&w(u),e.jsx($,{children:e.jsx(h,{variant:"outline",onClick:()=>m(null),children:"Done"})})]})})]})},he=({app:r,compact:l=!1})=>{var i,p;const[d,n]=P.useState(!1),a=(i=r.kubeMonitor)==null?void 0:i.deployment,c=l?e.jsx(b,{content:"Kubernetes status",children:e.jsx(x,{size:"icon-sm",variant:"ghost","aria-label":"Kubernetes status",onClick:o=>{o.stopPropagation(),n(!0)},children:e.jsx(T,{className:"size-4"})})}):e.jsxs(h,{variant:"outline",size:"sm",onClick:o=>{o.stopPropagation(),n(!0)},children:[e.jsx(T,{}),"Kubernetes status"]});return e.jsxs(e.Fragment,{children:[c,e.jsx(I,{open:d,onOpenChange:n,children:e.jsxs(K,{className:"max-w-5xl",children:[e.jsxs(A,{children:[e.jsx(z,{children:"Kubernetes status"}),e.jsxs(S,{children:["Deployment health and pod events for ",r.name,"."]})]}),a?e.jsx(X,{title:"Deployment status",...a,children:((p=a.pods)==null?void 0:p.items)&&e.jsx(Y,{pods:a.pods.items})}):e.jsx("div",{className:"rounded-md border border-dashed border-border/60 bg-surface-recessed p-4 text-sm text-muted-foreground",children:"Kubernetes status is not available yet."})]})})]})};export{me as A,he as a};
