import{Y as N,R as o,t as p,r as j,j as e,N as v}from"./index-B-YXshIJ.js";import{A as w}from"./arrow-left-CFpSQjrL.js";import{E as T}from"./edit-2-DHSaoIVm.js";import{C}from"./copy-DFTSanX-.js";const E=()=>{const r=N(),[x,b]=o.useState(!1),c=p.apiToken.createToken.useMutation(),[t,d]=o.useState(""),[a,h]=o.useState(""),[u,k]=o.useState(""),[g,y]=o.useState(""),l=p.auth.verifySession.useQuery().data,m=localStorage.getItem("currentOrganization"),i=m?JSON.parse(m).value:null,f=j.useCallback(async s=>{if(s.preventDefault(),!l||!i)return;const n=await c.mutateAsync({createdBy:l.email,organizationId:i,tokenName:t,tokenDescription:a});n&&(b(!0),d(n.tokenName),k(n.token),y(n.tokenId.toString()))},[c,l,i,a,t]);return e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("button",{title:"back","aria-label":"Go Back",type:"button",onClick:()=>r(-1),className:"flex justify-start items-center text-gray-700 hover:text-gray-900 cursor-pointer mb-4",children:[e.jsx(w,{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:"Create 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."}),x?e.jsxs("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:t}),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:()=>{r("/settings/tokens/edit-token/".concat(g,"?auth=true"))},children:[e.jsx(T,{className:"w-4 h-4 text-purple-950"}),e.jsx("span",{children:"Edit"})]})})]}),e.jsxs("div",{className:"p-5 bg-gray-100",children:[e.jsx("p",{className:"block text-gray-700 text-base font-bold mb-1",children:"Token Number"}),e.jsx("p",{className:"block text-gray-500 text-sm font-normal mb-1",children:"Make sure to copy this token as you will not see this again"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{title:"token",type:"text",className:"shadow appearance-none border rounded w-full py-2 px-3 bg-gray-200 text-gray-700 leading-tight focus:outline-none focus:shadow-outline pr-10",value:u,readOnly:!0}),e.jsx("button",{className:"absolute inset-y-0 right-0 px-3 py-2 text-gray-600 hover:text-gray-800",type:"button","aria-label":"copy token",title:"copy token",onClick:async()=>{await navigator.clipboard.writeText(u)},children:e.jsx(C,{className:"w-4 h-4"})})]})]})]}):e.jsxs("form",{onSubmit:f,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:t,onChange:s=>d(s.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:a,onChange:s=>h(s.target.value)})]}),e.jsxs("div",{className:"mt-4 flex gap-5",children:[e.jsx("button",{className:v(t===""||a===""?"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:t===""||a==="",type:"submit",title:"create token",children:"Create Token"}),e.jsx("button",{type:"button",title:"cancel",onClick:()=>{r(-1)},children:"Cancel"})]})]})]})})]})};export{E as default};
