import{a as i,j as e}from"./vendor-react-YMhRUmcb.js";import{m as v,C as l,B as n,d as p}from"./index-D2uzyr9g.js";import{I as j}from"./input-DL1WY4HG.js";import{w as d}from"./webhookService-BUZkpEvD.js";import{N,aa as y,g as k,aW as b,aZ as T,T as C}from"./vendor-icons-DINCNwpk.js";import"./vendor-fFnFILYR.js";import"./vendor-router-DX94Iu-2.js";import"./vendor-tanstack-CoFNL2zy.js";import"./vendor-utils-4BWoYre8.js";const F=()=>{const{addToast:t}=v(),[o,c]=i.useState([]),[f,m]=i.useState(!0),[r,x]=i.useState(""),h=async()=>{m(!0);try{const s=await d.list();c(s)}catch{t("Failed to load webhooks","error")}finally{m(!1)}};i.useEffect(()=>{h()},[]);const u=async()=>{if(r)try{await d.create(r),x(""),t("Webhook generated successfully","success"),h()}catch{t("Failed to create webhook","error")}},g=s=>{t("Sending test payload to endpoint...","info")},w=async s=>{try{await d.delete(s),c(o.filter(a=>a.id!==s)),t("Webhook disconnected","info")}catch{t("Failed to delete webhook","error")}};return e.jsxs("div",{className:"space-y-6 pb-20 container mx-auto px-4 py-8 max-w-5xl",children:[e.jsx("div",{className:"flex items-end justify-between",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-display font-bold text-white mb-1",children:"Webhooks"}),e.jsxs("p",{className:"text-muted-foreground font-mono text-xs flex items-center gap-2",children:[e.jsx(N,{className:"w-3 h-3"})," EVENT SUBSCRIPTION PROTOCOL"]})]})}),e.jsxs(l,{variant:"glass",className:"p-6 border-primary/20 bg-black/40 relative overflow-hidden group",children:[e.jsx("div",{className:"absolute inset-x-0 bottom-0 h-1 bg-gradient-to-r from-transparent via-primary/50 to-transparent opacity-50 group-hover:opacity-100 transition-opacity"}),e.jsxs("h3",{className:"font-bold text-white mb-4 flex items-center gap-2 text-sm uppercase tracking-widest",children:[e.jsx(y,{className:"w-4 h-4 text-primary"})," Register Endpoint"]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(j,{placeholder:"https://api.domain.com/webhook",value:r,onChange:s=>x(s.target.value),className:"flex-1 font-mono text-sm"}),e.jsx(n,{onClick:u,disabled:!r,className:"shadow-glow-cyan",children:"Create Hook"})]})]}),e.jsx("div",{className:"space-y-4",children:f?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(k,{className:"w-8 h-8 text-primary animate-spin"})}):o.length===0?e.jsxs(l,{variant:"glass",className:"p-12 text-center border-dashed border-white/10 bg-black/20",children:[e.jsx(b,{className:"w-12 h-12 text-muted-foreground mx-auto mb-4 opacity-20"}),e.jsx("h4",{className:"text-white font-bold",children:"No endpoints registered"}),e.jsx("p",{className:"text-muted-foreground text-sm max-w-sm mx-auto mt-2 font-mono",children:"Ready to stream real-time events to your external infra."})]}):o.map(s=>e.jsxs(l,{variant:"glass",className:"group overflow-hidden relative border-white/5 hover:border-white/10 transition-all bg-black/40",children:[e.jsx("div",{className:p("absolute left-0 top-0 bottom-0 w-1",s.status==="active"?"bg-lime-500 shadow-[0_0_10px_rgba(var(--lime-500),0.5)]":"bg-red-500 shadow-[0_0_10px_rgba(var(--red-500),0.5)]")}),e.jsxs("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between p-6 pl-8 gap-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:p("text-xs font-bold px-2 py-0.5 rounded border uppercase tracking-wider",s.status==="active"?"border-lime-500/30 text-lime-500 bg-lime-500/10":"border-red-500/30 text-red-500 bg-red-500/10"),children:s.status}),e.jsx("span",{className:"font-mono text-white text-sm break-all",children:s.url})]}),e.jsxs("div",{className:"flex flex-wrap gap-4 text-xs text-muted-foreground items-center",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"text-primary/70",children:"events:"}),s.events.map(a=>e.jsx("span",{className:"text-white bg-white/5 px-1 rounded",children:a},a))]}),e.jsx("div",{className:"w-1 h-1 rounded-full bg-white/20"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(b,{className:"w-3 h-3"})," Last trigger: ",s.lastTriggered]})]})]}),e.jsxs("div",{className:"flex gap-2 w-full md:w-auto opacity-60 group-hover:opacity-100 transition-opacity",children:[e.jsxs(n,{variant:"outline",size:"sm",onClick:()=>g(s.id),className:"border-white/10 hover:bg-primary/20 hover:text-primary hover:border-primary/50",children:[e.jsx(T,{className:"w-3 h-3 mr-2"})," Test"]}),e.jsx(n,{variant:"outline",size:"sm",onClick:()=>w(s.id),className:"border-white/10 hover:bg-red-500/20 hover:text-red-500 hover:border-red-500/50",children:e.jsx(C,{className:"w-3 h-3"})})]})]})]},s.id))})]})};export{F as WebhooksView};