1import{n as o,o as i,dQ as M,r as d,j as e,dR as v}from"./main-Bo0oayNO.js";import{f as D}from"./ui-utils-CNoARbDA.js";o({method:"GET"}).handler(i("41664dd8c1308a7b545f1e6f1f1d6cb18e6b7bb39e65da0fc5b0e2ebf83671de"));o({method:"GET"}).handler(i("99d6c3df322506826bd929a0fa0c4308cb178dfe226ff5d4b03bc7856ec2550d"));const G=o({method:"POST"}).handler(i("a1de7f7fa5adbe474fb1f77b21faea3b36fd034c8343ec37f887f4e86662f750")),U=o({method:"POST"}).handler(i("083f84f06fd81f0f442200567be48d4c9c3db4d5d22ce974f4f14d633e054d07")),O=o({method:"POST"}).handler(i("13d3ac4af79bd8469d5cb6225f7edf0374f5f8b1ba3d71cb6de2e782cbb66471")),R=({className:a})=>e.jsx("svg",{className:a,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"})}),B=({className:a})=>e.jsx("svg",{className:a,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),H=({className:a})=>e.jsx("svg",{className:a,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),W=({className:a})=>e.jsx("svg",{className:a,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3"})}),F=({className:a})=>e.jsx("svg",{className:a,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})});function Y(){const{apiKeys:a,userId:N}=M.useLoaderData(),[l,m]=d.useState(a),[w,p]=d.useState(!1),[c,y]=d.useState(""),[r,n]=d.useState([]),[x,b]=d.useState(null),[C,u]=d.useState(!1),[k,j]=d.useState(!1),[T,h]=d.useState(null),E=async()=>{if(!(!c||r.length===0)){j(!0);try{const t=await G({data:{name:c,userId:N,scopes:r}});if(t.success&&t.apiKey){b(t.apiKey.key);const s={...t.apiKey,key:void 0,scopes:r};m([s,...l])}}finally{j(!1)}}},A=async()=>{x&&(await navigator.clipboard.writeText(x),u(!0),setTimeout(()=>u(!1),2e3))},f=()=>{p(!1),b(null),y(""),n([])},P=async t=>{await U({data:t}),m(l.filter(s=>s.id!==t)),h(null)},S=async(t,s)=>{await O({data:{id:t,isActive:s}}),m(l.map(g=>g.id===t?{...g,isActive:s}:g))},I=t=>{r.includes(t)?n(r.filter(s=>s!==t)):n([...r,t])},L=()=>{n(v.map(t=>t.value))},K=()=>{n([])};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"API Keys"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"Manage API keys for programmatic access to your site"})]}),e.jsxs("button",{onClick:()=>p(!0),className:"flex items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700",children:[e.jsx(B,{className:"w-5 h-5"}),"Create API Key"]})]}),e.jsxs("div",{className:"mb-6 p-4 bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg",children:[e.jsx("h3",{className:"font-medium text-blue-900 dark:text-blue-100 mb-2",children:"API Documentation"}),e.jsx("p",{className:"text-sm text-blue-800 dark:text-blue-200 mb-2",children:"Use the REST API to programmatically manage your content. Base URL:"}),e.jsxs("code",{className:"block p-2 bg-blue-100 dark:bg-blue-900/40 rounded-sm text-sm text-blue-900 dark:text-blue-100",children:[typeof window<"u"?window.location.origin:"","/api/v1"]}),e.jsxs("p",{className:"text-sm text-blue-800 dark:text-blue-200 mt-2",children:["Include your API key in the Authorization header:"," ",e.jsx("code",{className:"bg-blue-100 dar
1k:bg-blue-900/40 px-1 rounded-sm",children:"Bearer sk_live_xxx..."})]})]}),e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-sm",children:l.length===0?e.jsxs("div",{className:"p-12 text-center",children:[e.jsx(R,{className:"w-12 h-12 mx-auto text-gray-400 mb-4"}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-white mb-2",children:"No API keys yet"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mb-4",children:"Create an API key to start using the REST API"}),e.jsx("button",{onClick:()=>p(!0),className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700",children:"Create your first API key"})]}):e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"bg-gray-50 dark:bg-gray-700",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase",children:"Name"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase",children:"Key"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase",children:"Scopes"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase",children:"Last Used"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase",children:"Status"}),e.jsx("th",{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-300 uppercase",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-200 dark:divide-gray-700",children:l.map(t=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("span",{className:"font-medium text-gray-900 dark:text-white",children:t.name})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("code",{className:"text-sm text-gray-600 dark:text-gray-400",children:t.keyPrefix})}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[t.scopes.slice(0,3).map(s=>e.jsx("span",{className:"px-2 py-0.5 text-xs bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300 rounded-sm",children:s},s)),t.scopes.length>3&&e.jsxs("span",{className:"px-2 py-0.5 text-xs bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300 rounded-sm",children:["+",t.scopes.length-3," more"]})]})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-600 dark:text-gray-400",children:t.lastUsedAt?D(t.lastUsedAt):"Never"}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("button",{onClick:()=>S(t.id,!t.isActive),className:`px-2 py-1 text-xs rounded ${t.isActive?"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400":"bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-400"}`,children:t.isActive?"Active":"Disabled"})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-right",children:T===t.id?e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Delete?"}),e.jsx("button",{onClick:()=>P(t.id),className:"px-2 py-1 text-xs bg-red-600 text-white rounded-sm hover:bg-red-700",children:"Yes"}),e.jsx("button",{onClick:()=>h(null),className:"px-2 py-1 text-xs bg-gray-200 text-gray-700 rounded-sm hover:bg-gray-300 dark:bg-gray-700 dark:text-gray-300",children:"No"})]}):e.jsx("button",{onClick:()=>h(t.id),className:"text-red-600 hover:text-red-700 dark:text-red-400",children:e.jsx(H,{className:"w-5 h-5"})})})]},t.id))})]})}),e.jsxs("div",{className:"mt-8",children:[e.jsx("h2",{className:"text-lg font-medium text-gray-900 dark:text-white mb-4",children:"Available Endpoints"}),e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-sm overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-gray-50 dark:bg-gray-700",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase",children:"Method"}),e.jsx("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase",children:"Endpoint"}),e.jsx("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase",children:"Required Scope"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-200 dark:divide-gray-700",children:[{method:"GET",endpoint:"/api/v1/posts",scope:"posts:read"},{method:"POST",endpoint:"/api/v1/posts",scope:"posts:write"},{method:"GET",endpoint:"/api/v1/posts/:id",scope:"posts:read"},{method:"PUT",endpoint:"/api/v1/posts/:id",scope:"posts:write"},{method:"DELETE",endpoint:"/api/v1/posts/:id",scope:"posts:write"},{method:"GET",endpoint:"/api/v1/pages",scope:"pages:read"},{method:"POST",endpoint:"/api/v1/pages",scope:"pages:write"},{method:"GET",endpoint:"/api/v1/pages/:id",scope:"pages:read"},{method:"PUT",endpoint:"/api/v1/pages/:id",scope:"pages:write"},{method:"DELETE",endpoint:"/api/v1/pages/:id",scope:"pages:write"},{method:"GET",endpoint:"/api/v1/media",scope:"media:read"},{method:"POST",endpoint:"/api/v1/media",scope:"media:write"},{method:"GET",endpoint:"/api/v1/media/:id",scope:"media:read"},{method:"DELETE",endpoint:"/api/v1/media/:id",scope:"media:write"},{method:"GET",endpoint:"/api/v1/comments",scope:"comments:read"},{method:"PUT",endpoint:"/api/v1/comments/:id",scope:"comments:write"},{method:"DELETE",endpoint:"/api/v1/comments/:id",scope:"comments:write"},{method:"GET",endpoint:"/api/v1/users",scope:"users:read"},{method:"POST",endpoint:"/api/v1/users",scope:"users:write"},{method:"GET",endpoint:"/api/v1/users/:id",scope:"users:read"},{method:"PUT",endpoint:"/api/v1/users/:id",scope:"users:write"},{method:"DELETE",endpoint:"/api/v1/users/:id",scope:"users:write"},{method:"GET",endpoint:"/api/v1/settings",scope:"settings:read"},{method:"PUT",endpoint:"/api/v1/settings",scope:"settings:write"}].map((t,s)=>e.jsxs("tr",{className:"hover:bg-gray-50 dark:hover:bg-gray-700/50",children:[e.jsx("td",{className:"px-4 py-2",children:e.jsx("span",{className:`px-2 py-0.5 text-xs font-medium rounded ${t.method==="GET"?"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400":t.method==="POST"?"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-400":t.method==="PUT"?"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400":"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400"}`,children:t.method})}),e.jsx("td",{className:"px-4 py-2 font-mono text-gray-900 dark:text-white",children:t.endpoint}),e.jsx("td",{className:"px-4 py-2 text-gray-600 dark:text-gray-400",children:t.scope})]},s))})]})})]})]}),w&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-lg w-full mx-4 max-h-[90vh] overflow-y-auto",children:e.jsx("div",{className:"p-6",children:x?e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-xl font-bold text-gray-900 dark:text-white mb-4",children:"API Key Created"}),e.jsx("div",{className:"p-4 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg mb-4",children:e.jsx("p",{className:"text-sm text-yellow-800 dark:text-yellow-200 mb-2",children:"Make sure to copy your API key now. You won't be able to see it again!"})}),e.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[e.jsx("code",{className:"flex-1 p-3 bg-gray-100 dark:bg-gray-700 rounded-sm text-sm font-mono text-gray-900 dark:text-white break-all",children:x}),e.jsx("button",{onClick:A,className:"p-2 bg-blue-600 text-white rounded-sm hover:bg-blue-700",children:C?e.jsx(F,{className:"w-5 h-5"}):e.jsx(W,{className:"w-5 h-5"})})]}),e.jsx("button",{onClick:f,className:"w-full px-4 py-2 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 dark:bg-gray-700 dark:text-gray-300",children:"Done"})]}):e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-xl font-bold text-gray-900 dark:text-white mb-4",children:"Create API Key"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Key Name"}),e.jsx("input",{type:"text",value:c,onChange:t=>y(t.target.value),placeholder:"e.g., Mobile App, External Integration",className:"w-full p-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Permissions"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:L,className:"text-xs text-blue-600 hover:underline",children:"Select All"}),e.jsx("button",{onClick:K,className:"text-xs text-gray-600 hover:underline",children:"Clear"})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2 max-h-60 overflow-y-auto",children:v.map(t=>e.jsxs("label",{className:"flex items-start gap-2 p-2 border border-gray-200 dark:border-gray-600 rounded-sm cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-700",children:[e.jsx("input",{type:"checkbox",checked:r.includes(t.value),onChange:()=>I(t.value),className:"mt-0.5"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-white",children:t.label}),e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:t.description})]})]},t.value))})]})]}),e.jsxs("div",{className:"flex gap-3 mt-6",children:[e.jsx("button",{onClick:f,className:"flex-1 px-4 py-2 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 dark:bg-gray-700 dark:text-gray-300",children:"Cancel"}),e.jsx("button",{onClick:E,disabled:!c||r.length===0||k,className:"flex-1 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed",children:k?"Creating...":"Create Key"})]})]})})})})]})}export{Y as component};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.