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