import{a as N,x as g,U as E,s as T,ag as _,d as i,r as $,n as w,Q as B,J as F,j as e,K as I,t as p,fG as L,aS as Q,R as h,q}from"./index-Dz5JRQhj.js";const U=()=>{const{isFineGrained:t}=N();return{canDeletePool:o=>g(t,"can_delete",o?.access_entitlements),canEditPool:o=>g(t,"can_edit",o?.access_entitlements)}},A=({pool:t,project:a,shouldExpand:n=!1})=>{const o=E(),S=T(),x=_(),y=i.useNotify(),r=i.useToastNotification(),[c,l]=$.useState(!1),j=w(),{canDeletePool:b}=U(),{hasStorageAndNetworkOperations:C}=B(),D=F(),P=s=>{r.success(e.jsxs(e.Fragment,{children:["Storage pool ",e.jsx(p,{bold:!0,type:"pool",value:s})," ","deleted."]}))},u=()=>{j.invalidateQueries({queryKey:[q.storage]})},d=()=>{u();const s=`${h}/ui/project/${encodeURIComponent(a)}/storage/pool/${encodeURIComponent(t.name)}`;x.pathname.startsWith(s)&&S(`${h}/ui/project/${encodeURIComponent(a)}/storage/pools`),P(t.name)},m=s=>{u(),l(!1),y.failure(`Deleting storage pool ${t.name} failed`,s)},v=()=>{l(!0),L(t.name).then(s=>{C?(r.info(e.jsxs(e.Fragment,{children:["Deletion of storage pool"," ",e.jsx(Q,{poolName:t.name,projectName:a})," ","has started."]})),D.set(s.metadata.id,()=>{l(!1),d()},R=>{m(new Error(R))})):d()}).catch(s=>{m(s)})},f=()=>{if(!b(t))return"You do not have permission to delete this storage pool";if(t.used_by?.length??!1)return"Storage pool is in use"};return e.jsxs(i.ConfirmationButton,{confirmationModalProps:{title:"Confirm delete",children:e.jsxs("p",{children:["This will permanently delete storage pool"," ",e.jsx(p,{type:"pool",value:t.name,bold:!0}),".",e.jsx("br",{}),"This action cannot be undone, and can result in data loss."]}),confirmButtonLabel:"Delete pool",onConfirm:v,message:"Delete storage"},appearance:n?"default":"base",className:I("u-no-margin--bottom",{"is-dense":!n,"has-icon":!o}),loading:c,shiftClickEnabled:!0,showShiftClickHint:!0,disabled:!!f()||c,onHoverText:f(),children:[(!o||!n)&&e.jsx(i.Icon,{name:"delete"}),n&&e.jsx("span",{children:"Delete pool"})]})};export{A as D,U as u};
