import*as e from"react";import{useMutation as C,useQueryClient as v}from"@tanstack/react-query";import{useParams as E}from"react-router-dom";import{Button as m}from"@redocly/theme/components/Button/Button";import{H3 as h}from"@redocly/theme/components/Typography/H3";import{Admonition as A}from"@redocly/theme/markdoc/components/Admonition/Admonition";import{useTranslate as P}from"../../../../../client/app/hooks";import{Dialog as S}from"./Dialog";import D from"./ApisList";import{ButtonWithLoading as O}from"./ButtonWithLoading";import{ButtonsContainer as b}from"./RollAPIKey";import{DialogRow as w,DialogRowTitle as B,DialogRowContent as I,DialogBodyWrapper as R}from"./DialogStyledComponents";function T({initialEnabledApis:r}){const p=v(),[u,o]=e.useState(!1),{translate:t}=P(),{id:i}=E(),{isPending:l,error:s,mutateAsync:y}=C({mutationFn:()=>fetch(`/api/api-keys/apps/${i}/credentials`,{method:"POST",body:JSON.stringify({apiProductIds:d})}).then(n=>n.json()),onSuccess:()=>{p.invalidateQueries({queryKey:["APP:"+i]})}}),c=()=>o(!0),a=()=>o(!1),g=async()=>{await y(),a()},[d,f]=e.useState(r),k=n=>{f(n||[])};return e.createElement(e.Fragment,null,e.createElement(m,{size:"large",variant:"primary",onClick:c},t("dev.app.key.create","Create key")),e.createElement(S,{open:u,onOpen:c,onClose:a},e.createElement(R,null,e.createElement(h,{"data-translation-key":"dev.create.key.dialog.title"},t("dev.create.key.dialog.title","Create key")),e.createElement(w,null,e.createElement(B,{"data-translation-key":"dev.edit.apis.dialog.selectedAPIs"},t("dev.edit.apis.dialog.selectedAPIs","Selected APIs")),e.createElement(I,null,e.createElement(D,{initialEnabledApis:r,onChange:k}))),s?e.createElement(A,{type:"danger"}," ",s.message," "):null,e.createElement(b,null,e.createElement(m,{onClick:a,"data-translation-key":"dev.create.key.dialog.cancel",variant:"text",size:"large"},t("dev.create.key.dialog.cancel","Cancel")),e.createElement(O,{variant:"primary",onClick:g,disabled:l||d.length<1,loading:l,"data-translation-key":"dev.create.key.dialog.create"},t("dev.create.key.dialog.create","Create key"))))))}export{T as default};
