var B=Object.defineProperty;var N=Object.getOwnPropertySymbols;var O=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable;var b=(l,a,e)=>a in l?B(l,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[a]=e,d=(l,a)=>{for(var e in a||(a={}))O.call(a,e)&&b(l,e,a[e]);if(N)for(var e of N(a))D.call(a,e)&&b(l,e,a[e]);return l};import{r as j,j as t}from"./main-406.js";import{_ as s,J as R,L as A,x as S,y as u,P as p,K as U,R as V,O as q,n as z,F as G,N as J,b as K}from"./bi.394.85.js";import{B as M}from"./bi.46.744.js";function Z({formFields:l,webHooks:a,setWebHooks:e,setStep:C,setSnackbar:h,create:y,isInfo:c}){var f,v;const[T,m]=j.useState(!1),[x,o]=j.useState(1),_=["GET","POST","PUT","PATCH","OPTION","DELETE","TRACE","CONNECT"],g=n=>{const i=d({},a);i[n.target.name]=n.target.value,e(d({},i))},E=n=>{m(!0),K({hookDetails:n},"test_webhook").then(i=>{if(i&&i.success)h({show:!0,msg:`${i.data}`}),m(!1);else if(i&&i.data){const r=typeof i.data=="string"?i.data:"Unknown error";h({show:!0,msg:`${r}. ${s("please try again","bit-integrations")}`}),m(!1)}else h({show:!0,msg:s("Webhook tests failed. please try again","bit-integrations")}),m(!1)})};j.useEffect(()=>{if(a&&!(a!=null&&a.condition)){const n=d({},a);n.condition={action_behavior:"",actions:[{field:"",action:"value"}],logics:[{field:"",logic:"",val:""},"or",{field:"",logic:"",val:""}]},e(n)}},[]);const P=(n,i)=>{const r=d({},a);i?r.condition.action_behavior=n:r.condition.action_behavior="",e(r)},L=()=>{setTimeout(()=>{document.getElementById("btcd-settings-wrp").scrollTop=0},300),C(2)},$='You can test any kind of webhook using <a href="https://app.webhook.is/test" target="_blank" rel="noreferrer">app.webhook.is</a>';return t.jsxs("div",{style:{width:c&&900},children:[t.jsx("div",{className:"flx ",children:t.jsxs("div",{className:"w-8 mr-2 mt-2 mb-4",children:[t.jsx("div",{className:"f-m",children:s("Integration name","bit-integrations")}),t.jsx("input",{name:"name",onChange:n=>g(n),className:"btcd-paper-inp mt-1",type:"text",value:a.name,disabled:c})]})}),t.jsxs("div",{className:"flx",children:[t.jsxs("div",{className:"w-5 mr-2 ",children:[t.jsx("div",{className:"f-m",children:s("Link:","bit-integrations")}),t.jsx("input",{name:"url",onChange:n=>g(n),className:"btcd-paper-inp mt-1",type:"text",value:a.url,disabled:c})]}),t.jsxs("div",{className:"w-3",children:[t.jsx("div",{className:"f-m",children:s("Method:","bit-integrations")}),t.jsx("select",{name:"method",onChange:n=>g(n),defaultValue:a.method,className:"btcd-paper-inp mt-1",disabled:c,children:_.map((n,i)=>t.jsx("option",{value:n,children:n},`method-${i*2}`))})]})]}),(a==null?void 0:a.apiConsole)&&t.jsxs("small",{className:"d-blk mt-2",children:[s("To got Webhook , Please Visit","bit-integrations")," ",t.jsx("a",{className:"btcd-link",href:a.apiConsole,target:"_blank",rel:"noreferrer",children:s(`${a.type} Dashboard`,"bit-integrations")})]}),!c&&t.jsxs(R,{onClick:()=>E(a),className:"btn btcd-btn-o-purple",children:[s("Test Webhook","bit-integrations"),T&&t.jsx(A,{size:14,clr:"#022217",className:"ml-2"})]}),t.jsx("br",{}),t.jsx("br",{}),t.jsxs(S,{children:[t.jsxs("div",{className:"flx mt-2",children:[t.jsx(u,{children:t.jsx("button",{className:`btcd-s-tab-link ${x===1&&"s-t-l-active"}`,type:"button",children:s("Params","bit-integrations")})}),t.jsx(u,{children:t.jsx("button",{className:`btcd-s-tab-link ${x===2&&"s-t-l-active"}`,type:"button",children:s("Headers","bit-integrations")})}),t.jsx(u,{children:t.jsx("button",{className:`btcd-s-tab-link ${x===3&&"s-t-l-active"}`,type:"button",children:s("Body","bit-integrations")})})]}),t.jsx("div",{className:"btcd-hr"}),t.jsx(p,{children:t.jsx(U,{webHooks:a,setWebHooks:e,formFields:l,isInfo:c,setTab:o})}),t.jsx(p,{children:t.jsx(V,{webHooks:a,setWebHooks:e,formFields:l,isInfo:c,setTab:o})}),t.jsx(p,{children:t.jsx(q,{webHooks:a,setWebHooks:e,formFields:l,isInfo:c,setTab:o})})]}),(a==null?void 0:a.condition)&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flx",children:t.jsx(z,{onChange:n=>P(n.target.value,n.target.checked),checked:((f=a==null?void 0:a.condition)==null?void 0:f.action_behavior)==="cond",className:"wdt-200 mt-4 mr-2",value:"cond",title:s("Conditional Logics","bit_integration"),isInfo:c})}),t.jsx("br",{}),((v=a==null?void 0:a.condition)==null?void 0:v.action_behavior)==="cond"&&t.jsx(G,{formFields:l,dataConf:a,setDataConf:e})]}),y&&t.jsxs("button",{onClick:()=>L(),className:"btn btcd-btn-lg purple sh-sm flx",type:"button",children:[s("Next","bit-integrations"),t.jsx(M,{className:"ml-1 rev-icn"})]}),t.jsx(J,{note:$})]})}export{Z as default};
