1import{j as e}from"./vendor-query-CTD2tXPx.js";import{r}from"./vendor-charts-Debegyj1.js";import{b as T,B as o,s as m,t as i}from"./index-DOCSA3X_.js";import{N as A}from"./Navbar-oaSoPaU-.js";import{I as B}from"./input-DsvowBq8.js";import{L as I}from"./label-CFJeKN0k.js";import{D as L,a as P,b as q,c as z,d as E}from"./dialog-DDAk0TRZ.js";import{B as F}from"./badge-sO-2LWky.js";import{a as H,s as O}from"./tokens-Cb7VcqqI.js";import{P as R,J as G,g as $,h as J}from"./vendor-icons-B3WZHYud.js";import"./vendor-router-BVlBSwqy.js";import"./vendor-radix-khLywtIJ.js";import"./vendor-supabase-CQ9eTX7v.js";function re(){const{user:d}=T(),[p,l]=r.useState([]),[b,h]=r.useState(!0),[x,f]=r.useState(""),[N,g]=r.useState(!1),[c,u]=r.useState(null),[w,j]=r.useState(!1),_=async()=>{h(!0);const{data:t,error:s}=await m.from("api_keys").select("id, name, prefix, last_used_at, revoked_at, created_at").eq("owner_id",d.id).order("created_at",{ascending:!1});s&&i({title:"ÐÑеÑка",description:s.message,variant:"destructive"}),l(t??[]),h(!1)};r.useEffect(()=>{d&&_()},[d]);const y=async()=>{if(!x.trim())return i({title:"ÐÑведи име на клÑÑа",variant:"destructive"});g(!0);const{token:t,prefix:s}=H(),n=await O(t),{data:a,error:v}=await m.from("api_keys").insert({owner_id:d.id,name:x.trim(),prefix:s,token_hash:n}).select().single();if(g(!1),v)return i({title:"ÐÑеÑка",description:v.message,variant:"destructive"});l(S=>[a,...S]),u(t),f("")},k=async t=>{if(!confirm("Ðа оÑнема ли Ñози клÑÑ? Той веднага Ñе ÑпÑе да ÑабоÑи."))return;const{error:s}=await m.from("api_keys").update({revoked_at:new Date().toISOString()}).eq("id",t);if(s)return i({title:"ÐÑеÑка",description:s.message,variant:"destructive"});l(n=>n.map(a=>a.id===t?{...a,revoked_at:new Date().toISOString()}:a)),i({title:"ÐлÑÑÑÑ Ðµ оÑнеÑ"})},C=async t=>{if(!confirm("Ðа изÑÑÐ¸Ñ Ð»Ð¸ клÑÑа оконÑаÑелно?"))return;const{error:s}=await m.from("api_keys").delete().eq("id",t);if(s)return i({title:"ÐÑеÑка",description:s.message,variant:"destructive"});l(n=>n.filter(a=>a.id!==t))},D=()=>{c&&(navigator.clipboard.writeText(c),j(!0),setTimeout(()=>j(!1),2e3))};return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(A,{}),e.jsxs("div",{className:"container mx-auto px-4 py-8 max-w-3xl",children:[e.jsx("h1",{className:"font-serif text-3xl font-bold text-foreground mb-1",children:"API клÑÑове"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-6",children:"Ðзползвай Ñези клÑÑове за доÑÑÑп до пÑблиÑноÑо API на ÑимÑлаÑииÑе. Ðе ги ÑподелÑй пÑблиÑно."}),e.jsxs("div",{className:"rounded-2xl border bg-card p-5 mb-6",children:[e.jsx(I,{children:"Ðме на нов клÑÑ"}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(B,{value:x,onChange:t=>f(t.target.value),placeholder:"напÑ. ÐоÑÑ ÑайÑ",maxLength:80}),e.jsxs(o,{onClick:y,disabled:N,children:[e.jsx(R,{className:"h-4 w-4 mr-1"}),"СÑздай"]})]})]}),b?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:"ÐаÑежданеâ¦"}):p.length===0?e.jsx("p",{className:"text-center text-muted-foreground py-12",children:"ÐÑе оÑе нÑÐ¼Ð°Ñ ÑÑздадени клÑÑове."}):e.jsx("div",{className:"space-y-2",children:p.map(t=>e.jsxs("div",{className:"rounded-xl border bg-card p-4 flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"font-semibold text-foreground",children:t.name}),t.revoked_at&&e.jsx(F,{variant:"destructive",className:"text-[10px]",children:"ÐÑнеÑ"})]}),e.jsxs("div",{className:"text-xs text-muted-foreground font-mono",children:[t.prefix,"â¦"]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground mt-1",children:["СÑздаден: ",new Date(t.created_at).toLocaleDateString("bg-BG"),t.last_used_at&&` · ÐоÑледна ÑпоÑÑеба: ${new Date(t.last_used_at).toLocaleDateString("bg-BG")}`]})]}),e.jsxs("div",{className:"flex gap-2",children:[!t.revoked_at&&e.jsx(o,{size:"sm",variant:"outline",onClick:()=>k(t.id),children:"ÐÑнеми"}),e.jsx(o,{size:"sm",variant:"ghost",onClick:()=>C(t.id),className:"text-destructive hover:text-destructive",children:e.jsx(G,{className:"h-4 w-4"})})]})]},t.id))}),e.jsxs("div",{className:"mt-8 rounded-xl border bg-muted/30 p-5 text-sm",children:[e.jsx("h2",{className:"font-bold text-foreground mb-2",children:"ÐÑимеÑна заÑвка"}),e.jsx("pre",{className:"text-xs bg-card rounded-md p-3 overflow-x-auto",children:e.jsx("code",{children:`curl -H "Authorization: Bearer lvbl_live_xxx" \\ 2 https://nwmopzsloohwqimbywkp.supabase.co/functions/v1/sims-api/simulations`})}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:["ÐалиÑни endpoint-и: ",e.jsx("code",{children:"/templates"}),", ",e.jsx("code",{children:"/simulations"}),", ",e.jsx("code",{children:"/simulations/:id"}),", ",e.jsx("code",{children:"/public/:slug"})]})]})]}),e.jsx(L,{open:!!c,onOpenChange:t=>{t||u(null)},children:e.jsxs(P,{children:[e.jsx(q,{children:e.jsx(z,{children:"Ðапази ÑÐ²Ð¾Ñ Ð½Ð¾Ð² API клÑÑ"})}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Този клÑÑ Ñе показва ",e.jsx("strong",{children:"Ñамо веднÑж"}),". ÐопиÑай го и го ÑÑÑ ÑанÑвай на ÑигÑÑно мÑ
2ÑÑо."]}),e.jsx("div",{className:"bg-muted rounded-md p-3 font-mono text-xs break-all",children:c}),e.jsxs(E,{children:[e.jsx(o,{onClick:D,children:w?e.jsxs(e.Fragment,{children:[e.jsx($,{className:"h-4 w-4 mr-1"}),"ÐопиÑано"]}):e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"h-4 w-4 mr-1"}),"ÐопиÑай"]})}),e.jsx(o,{variant:"outline",onClick:()=>u(null),children:"ÐаÑвоÑи"})]})]})})]})}export{re as default};
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.