import*as e from"react";import{useMutation as h,useQueryClient as P}from"@tanstack/react-query";import{useParams as D}from"react-router-dom";import{Button as k}from"@redocly/theme/components/Button/Button";import{H2 as A}from"@redocly/theme/components/Typography/H2";import{Admonition as S}from"@redocly/theme/markdoc/components/Admonition/Admonition";import{useTranslate as T}from"../../../../../client/app/hooks";import{Dialog as w}from"./Dialog";import{ButtonWithLoading as I}from"./ButtonWithLoading";import{ButtonsContainer as K}from"./RollAPIKey";import{DialogInputMultiline as O,DialogRow as R,DialogRowContent as x}from"./DialogStyledComponents";import{MAX_DESCRIPTION_LENGTH as p,CharacterCounter as B}from"./CharacterCounter";const G=u=>{const{id:o}=D(),{initialDescription:g,open:y,onOpen:f,onClose:s}=u,t=g||"",{translate:a}=T(),[n,i]=e.useState(t);e.useEffect(()=>{i(t)},[t]);const c=async()=>{await C(),s()},E=l=>{l.key==="Enter"&&!r&&c()},d=()=>{s(),i(t)},v=P(),{mutateAsync:C,isPending:r,error:m}=h({mutationKey:["UPDATE_APP"+o],mutationFn:()=>fetch(`/api/api-keys/apps/${o}`,{method:"PUT",body:JSON.stringify({description:n})}),onSettled:()=>{v.invalidateQueries({queryKey:["APP:"+o]}),i(n)}});return e.createElement(w,{open:y,onClose:d,onOpen:f},e.createElement(e.Fragment,null,e.createElement(A,{"data-translation-key":"dev.edit.description.dialog.title"},a("dev.edit.description.dialog.title","Change description")),e.createElement(R,null,e.createElement(x,null,e.createElement(O,{maxLength:p,value:n,onChange:l=>i(l.target.value),onKeyPress:E,rows:6,cols:60}))),e.createElement(B,null,n.length,"/",p),m&&e.createElement(S,{type:"danger"},m.message," "),e.createElement(K,null,e.createElement(k,{onClick:d,"data-translation-key":"dev.edit.description.dialog.cancel",variant:"text",size:"large"},a("dev.edit.description.dialog.cancel","Cancel")),e.createElement(I,{variant:"primary",loading:r,onClick:c,disabled:r,"data-translation-key":"dev.edit.description.dialog.save"},a("dev.edit.description.dialog.save","Save changes")))))};export{G as EditAppDescriptionDialog};
