import*as e from"react";import{useMutation as f,useQueryClient as y}from"@tanstack/react-query";import{useParams as g}from"react-router-dom";import{Button as E}from"@redocly/theme/components/Button/Button";import{H2 as v}from"@redocly/theme/components/Typography/H2";import{Admonition as h}from"@redocly/theme/markdoc/components/Admonition/Admonition";import{usePreloadHistory as D}from"../../../../../client/app/usePreloadHistory";import{useTranslate as C}from"../../../../../client/app/hooks";import{Dialog as k}from"./Dialog";import{ButtonWithLoading as P}from"./ButtonWithLoading";import{ButtonsContainer as A}from"./RollAPIKey";const Q=e.forwardRef((w,p)=>{const d=D(),{id:a}=g(),{translate:t}=C(),s=y(),[m,o]=e.useState(!1),n=()=>o(!0),l=()=>o(!1);e.useImperativeHandle(p,()=>({open:n}));const c=async()=>{await u(),d.push("/apps/")},{isPending:r,error:i,mutateAsync:u}=f({mutationKey:["DELETE_APP"+a],mutationFn:()=>fetch(`/api/api-keys/apps/${a}`,{method:"DELETE"}),onSuccess:()=>{s.invalidateQueries({queryKey:["APPS"]})}});return e.createElement(k,{open:m,onOpen:n,onClose:l},e.createElement(e.Fragment,null,e.createElement(v,{"data-translation-key":"dev.delete.app.dialog.title"},t("dev.delete.app.dialog.title","Delete app")),e.createElement("div",{"data-translation-key":"dev.delete.app.dialog.confirmation"},t("dev.delete.app.dialog.confirmation","Do you really want to delete this app?")),i&&e.createElement(h,{type:"danger"},i.message),e.createElement(A,null,e.createElement(E,{onClick:l,"data-translation-key":"dev.delete.app.dialog.cancel",variant:"text",size:"large"},t("dev.delete.app.dialog.cancel","Cancel")),e.createElement(P,{variant:"primary",onClick:c,disabled:r,loading:r,"data-translation-key":"dev.delete.app.dialog.delete"},t("dev.delete.app.dialog.delete","Delete app")))))});export{Q as DeleteAppDialog};
