import{Y as j,J as y,R as l,t as c,r as w,j as e,N as v}from"./index-B-YXshIJ.js";import{A as D}from"./arrow-left-CFpSQjrL.js";import{E}from"./edit-2-DHSaoIVm.js";const A=()=>{var f,g;const i=j(),{tokenId:a}=y(),[k,d]=l.useState(!1),t=a?c.apiToken.getToken.useQuery({tokenId:a}):null,u=c.apiToken.updateToken.useMutation(),[s,m]=l.useState(""),[o,p]=l.useState(""),x=c.auth.verifySession.useQuery().data,b=localStorage.getItem("currentOrganization"),r=b?JSON.parse(b).value:null,h=s===""||o===""||s===((f=t==null?void 0:t.data)==null?void 0:f.tokenName)&&o===((g=t==null?void 0:t.data)==null?void 0:g.tokenDescription);l.useEffect(()=>{t!=null&&t.data&&(m(t.data.tokenName),p(t.data.tokenDescription))},[t==null?void 0:t.data]);const N=w.useCallback(async n=>{if(n.preventDefault(),!x||!r||!a)return;await u.mutateAsync({tokenId:a,organizationId:r,tokenName:s,tokenDescription:o})&&d(!0)},[x,r,o,a,s,u]);return!a&&!(t!=null&&t.data)?e.jsx("div",{className:"p-5",children:e.jsx("h3",{className:"text-gray-900 text-2xl font-semibold mb-2",children:"Token not found"})}):e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("button",{title:"back","aria-label":"Go Back",type:"button",onClick:()=>i(-1),className:"flex justify-start items-center text-gray-700 hover:text-gray-900 cursor-pointer mb-4",children:[e.jsx(D,{className:"inline-block w-4 h-4 mr-2"})," Back"]}),e.jsx("div",{className:"flex flex-row justify-between",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-gray-900 text-2xl font-semibold mb-2",children:"Edit Token"}),e.jsx("p",{children:"Lorem ipsum dolor sit amet, consectetur adipisicing elit. Vel obcaecati repudiandae illum quidem doloremque. Porro voluptas asperiores, tempora eos voluptatibus eveniet corrupti. Distinctio aliquam eligendi consequatur? Harum iste quam dolorem."}),k?e.jsx("div",{className:"mt-4 border border-gray-300 p-5 rounded-md",children:e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("p",{className:"block text-gray-700 text-base font-bold mb-1",children:s}),e.jsx("div",{className:"flex gap-2",children:e.jsxs("button",{type:"button",className:"ml-2 text-purple-950 flex items-center gap-2",onClick:()=>{d(!1),i("/settings/tokens/edit-token/".concat(a,"?auth=true"))},children:[e.jsx(E,{className:"w-4 h-4 text-purple-950"}),e.jsx("span",{children:"Edit"})]})})]})}):e.jsxs("form",{onSubmit:N,children:[e.jsxs("div",{className:"mt-4",children:[e.jsx("label",{htmlFor:"tokenName",className:"block text-gray-700 text-base font-bold mb-1",children:"Token Name"}),e.jsx("p",{className:"block text-gray-500 text-base font-normal mb-2",children:"A unique name for this token. May be visible to resource owners or users with possession of the token."}),e.jsx("input",{id:"tokenName",type:"text",className:"shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline",placeholder:"Token Name",value:s||"",onChange:n=>m(n.target.value)})]}),e.jsxs("div",{className:"mt-4",children:[e.jsx("label",{htmlFor:"tokenDescription",className:"block text-gray-700 text-base font-bold mb-2",children:"Token Description"}),e.jsx("textarea",{id:"tokenDescription",className:"shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline h-32",placeholder:"Token Description",value:o||"",onChange:n=>p(n.target.value)})]}),e.jsxs("div",{className:"mt-4 flex gap-5",children:[e.jsx("button",{className:v(h?"bg-slate-300 px-5 py-3 text-stone-700 cursor-not-allowed":"bg-gradient-to-r from-purple-950 to-purple-800 text-white cursor-pointer","px-5 py-3 rounded-md text-base font-semibold"),disabled:h,type:"submit",title:"create token",children:"Save"}),e.jsx("button",{type:"button",title:"cancel",onClick:()=>{i(-1)},children:"Cancel"})]})]})]})})]})};export{A as default};
