import{D as g,r as m,Q as p,E as T,q as w,e as i,j as e,f as r,B as u,F as W,ah as C,S as F,ai as _,n as y,aj as D,o as b}from"./main-few-lands-burn.js";import{u as E}from"./usewebho-CfqIoF8t.js";import{c as I}from"./mutative-C6xjlr6O.js";import{F as h}from"./index-D1WPCLK6.js";import{M}from"./index-CB2KTxNj.js";import{I as N}from"./index-DAhFlZRY.js";import{h as A,d as L}from"./index-oNbYxbiS.js";import{T as q}from"./index-ubWv-fhI.js";import{D as S,P as j}from"./index-XyHDR-91.js";import{L as k}from"./index-DkD03DCM.js";import"./useclosa-m-cf8k_D.js";import"./context-Ba3TiTex.js";import"./index-Cj8-kItB.js";import"./index-BcDJZYeX.js";import"./usebreak-DJkppNCB.js";import"./paginati-DuhDnQhP.js";function v(){const n=g(),{messageApi:l}=m.useContext(p),{isPending:s,mutateAsync:a}=T({mutationFn:async o=>w(`webhooks/${o}/delete`),mutationKey:["delete_webhook"],onError:o=>{l?.warning(o.data)},onSuccess:({data:o})=>{n.setQueryData(["webhooks","all","all"],t=>t&&{...t,data:t.data.filter(({id:c})=>c!==o)})}});return{deleteWebhook:a,isWebhookDeleting:s}}function P(){const n=g(),{messageApi:l}=m.useContext(p),{isPending:s,mutateAsync:a}=T({mutationFn:async({title:o,webhookId:t})=>w(`webhooks/${t}/update-title`,{title:o}),mutationKey:["update_webhook_title"],onError:o=>{typeof o.data=="string"&&l?.error(o.data)},onSuccess:({data:o})=>{n.setQueryData(["webhooks","all","all"],t=>t&&I(t,c=>{const d=c.data.findIndex(f=>f.id===o.id);d!==-1&&(c.data[d].title=o.title)})),l?.success(i("Webhook updated successfully"))}});return{isUpdatingTitle:s,updateWebhookTitle:a}}function U({isOpen:n,onClose:l,webhook:s}){const[a]=h.useForm(),{isUpdatingTitle:o,updateWebhookTitle:t}=P();m.useEffect(()=>{n&&s&&a.setFieldsValue({webhookTitle:s.title})},[n,s,a]);const c=async f=>{await t({title:f.webhookTitle,webhookId:s.id}),l(),a.resetFields()},d=()=>{a.resetFields(),l()};return e(M,{destroyOnClose:!0,footer:!1,maskClosable:!1,onCancel:d,open:n,title:i("Edit Webhook"),width:500,children:r(h,{form:a,layout:"vertical",onFinish:c,children:[e(h.Item,{label:i("Title"),name:"webhookTitle",rules:[{message:i("Webhook title is required"),required:!0},{max:255,message:i("Webhook title cannot exceed 255 characters")}],children:e(N,{placeholder:i("Enter webhook title")})}),e(h.Item,{className:"mb-0",children:r("div",{className:"flex justify-end gap-2",children:[e(u,{onClick:d,children:i("Cancel")}),e(u,{htmlType:"submit",loading:o,type:"primary",children:i("Update")})]})})]})})}function $({webhook:n}){const[l,s]=m.useState(!1),a=()=>{s(!0)},o=()=>{s(!1)};return r(W,{children:[e(u,{"data-testid":"edit-webhook",icon:e(C,{}),onClick:a,title:i("Edit webhook")}),e(U,{isOpen:l,onClose:o,webhook:n})]})}const{Link:O,Text:x,Title:Q}=q;var R={name:"f3vz0n",styles:"font-weight:500"};function ne(){const{isWebhookLoading:n,webhooks:l}=E(),{deleteWebhook:s}=v(),{messageApi:a}=m.useContext(p),o=async t=>{await s(t),a?.success("Webhook deleted successfully")};return r("div",{className:"p-6",children:[e("div",{className:"mb-4 flex items-center gap-2",children:e(Q,{className:"mb-0",level:3,children:i("Webhooks")})}),e(S,{style:{marginTop:6}}),e(k,{dataSource:l,itemLayout:"horizontal",loading:n,renderItem:t=>e(k.Item,{actions:[e(W,{children:r("div",{className:"space-x-2",children:[r(x,{className:"inline-flex flex-col text-right",type:"secondary",children:[e("span",{children:A(t.created_at,new Date)}),e("small",{children:L(`${y.DATE_FORMAT} | ${y.TIME_FORMAT}`,t.created_at)})]}),r("div",{className:"inline-flex w-80 justify-end space-x-2",children:[t?.flow_id&&e(u,{href:`#/flows/details/${t.flow_id}`,icon:e(D,{}),iconPosition:"end",target:"_blank",children:i("Go to Flow")}),e($,{webhook:t}),e(j,{cancelText:i("No"),description:i("Are you sure to delete this webhook?"),icon:e(b,{color:"red"}),okText:i("Yes"),onConfirm:()=>o(t.id),title:i("Delete the webhook"),children:e(u,{icon:e(b,{})})},"delete")]})]})})],children:r(F,{direction:"vertical",size:0,children:[e(x,{css:R,children:t.title}),e(O,{className:"text-xs text-slate-500",copyable:{icon:[e(_,{},"copy-icon")]},href:t.url,children:t.url})]})})})]})}export{ne as default};
