import{a as D,x as r,d as u,r as Q,n as j,J as q,Q as C,j as n,K as B,t as K,fS as R,q as o}from"./index-Dz5JRQhj.js";const k=()=>{const{isFineGrained:a}=D();return{canDeleteVolume:t=>r(a,"can_delete",t?.access_entitlements),canEditVolume:t=>r(a,"can_edit",t?.access_entitlements),canManageStorageVolumeSnapshots:t=>r(a,"can_manage_snapshots",t?.access_entitlements),canManageVolumeBackups:t=>r(a,"can_manage_backups",t?.access_entitlements)}},L=({project:a,volume:e,onFinish:i,appearance:d="base",hasIcon:c=!0,label:t,classname:y,onClose:b})=>{const x=u.useNotify(),[m,h]=Q.useState(!1),l=j(),{canDeleteVolume:p}=k(),S=q(),{hasStorageAndProfileOperations:V}=C(),g=(()=>{if(e.name.includes("/"))return"Go to the instance detail page, to remove this snapshot";if(e.type==="container")return"Go to the instance detail page, to remove this container";if(e.type==="virtual-machine")return"Go to the instance detail page, to remove this virtual-machine";if(e.type==="image")return"Go to the image list, to remove this image";if(e.type!=="custom")return"Only custom volumes can be deleted";if(e.used_by?.length??0)return"Remove all usages of the volume to delete it"})(),f=s=>{x.failure("Storage volume deletion failed",s)},v=()=>{i(),h(!1),l.invalidateQueries({queryKey:[o.isoVolumes]}),l.invalidateQueries({queryKey:[o.projects,a]}),l.invalidateQueries({queryKey:[o.storage,e.pool,o.volumes,a,e.location]}),l.invalidateQueries({predicate:s=>s.queryKey[0]===o.volumes})},_=()=>{h(!0),R(e.name,e.pool,a,e.location).then(s=>{V?S.set(s.metadata.id,i,E=>{f(new Error(E))},v):i()}).catch(f)};return n.jsxs(u.ConfirmationButton,{loading:m,confirmationModalProps:{close:b,title:"Confirm delete",children:n.jsxs("p",{children:["This will permanently delete volume"," ",n.jsx(K,{type:"volume",value:e.name,bold:!0}),".",n.jsx("br",{}),"This action cannot be undone, and can result in data loss."]}),confirmButtonLabel:"Delete",onConfirm:_},appearance:d,className:B("u-no-margin--bottom",y,{"has-icon":c}),shiftClickEnabled:!0,showShiftClickHint:!0,disabled:!p(e)||!!g||m,onHoverText:p(e)?g:"You do not have permission to delete this volume.",children:[c&&n.jsx(u.Icon,{name:"delete"}),t&&n.jsx("span",{children:t})]})};export{L as D,k as u};
