var C=Object.defineProperty,H=Object.defineProperties;var E=Object.getOwnPropertyDescriptors;var k=Object.getOwnPropertySymbols;var B=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var A=(i,t,a)=>t in i?C(i,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):i[t]=a,u=(i,t)=>{for(var a in t||(t={}))B.call(t,a)&&A(i,a,t[a]);if(k)for(var a of k(t))$.call(t,a)&&A(i,a,t[a]);return i},S=(i,t)=>H(i,E(t));import{c as F,_ as s,r as f,j as e,L as K,bu as V,T as q,d as D,H as O,e as R,f as G,F as U,g as J,S as Q}from"./main-762.js";import{s as T}from"./bf-767-42.js";import{t as L}from"./bf-281-48.js";import{T as W}from"./bf-525-114.js";import{A as X}from"./bf-704-110.js";import{N as Y}from"./bf-680-111.js";import{u as z}from"./bf-871-60.js";import{C as M}from"./bf-241-52.js";import{d as Z}from"./bf-685-46.js";import{S as N}from"./bf-432-66.js";import{u as ee}from"./bf-689-67.js";import"./bf-383-45.js";import"./bf-848-68.js";import"./bf-145-47.js";import"./bf-213-54.js";import"./bf-249-69.js";import"./bf-284-49.js";import"./bf-466-50.js";import"./bf-604-51.js";import"./bf-441-53.js";import"./bf-897-55.js";import"./bf-142-115.js";import"./bf-959-70.js";const I=(i,t,a,l)=>{const r=u({},i),h={bot_api_key:r.bot_api_key};a(!0),F(h,"bitforms_refresh_get_updates").then(o=>{o&&o.success?(r.default||(r.default={}),o.data.telegramChatLists&&(r.default.telegramChatLists=o.data.telegramChatLists),l({show:!0,msg:s("Chat list refreshed")}),t(u({},r))):o&&o.data&&o.data.data||!o.success&&typeof o.data=="string"?l({show:!0,msg:`${s("Chat list refresh failed Cause:")}${o.data.data||o.data}. ${s("please try again")}`}):l({show:!0,msg:s("Chat list refresh failed. please try again")}),a(!1)}).catch(()=>a(!1))},P=["file-up","advanced-file-up","signature"];function te({telegramConf:i,setTelegramConf:t,step:a,setstep:l,setSnackbar:r,isInfo:h}){const[o,x]=f.useState(!1),[m,d]=f.useState({name:"",bot_api_key:"",apiError:""}),[b,n]=f.useState(!1),[c,g]=f.useState(!1),y=()=>{const p=u({},i);if(!p.name||!p.bot_api_key){d({name:p.name?"":s("Integration name cann't be empty"),bot_api_key:p.bot_api_key?"":s("API Key cann't be empty")});return}g("auth");const w={bot_api_key:p.bot_api_key};F(w,"bitforms_telegram_authorize").then(j=>{j!=null&&j.success?(x(!0),r({show:!0,msg:s("Authorized Successfully")})):(x(!1),d({apiError:j==null?void 0:j.data.description}),r({show:!0,msg:s("Authorized Filled")})),n(!0),g(!1)})},v=p=>{const w=u({},i),j=u({},m);j[p.target.name]="",w[p.target.name]=p.target.value,d(j),t(w)},_=()=>{setTimeout(()=>{document.getElementById("btcd-settings-wrp").scrollTop=0},300),I(i,t,g,r),l(2)};return e.jsxs(e.Fragment,{children:[e.jsx(W,{title:L.telegram.title,youTubeLink:L.telegram.link}),e.jsxs("div",{className:"btcd-stp-page",style:{width:a===1&&900,height:a===1&&"100%"},children:[e.jsx("div",{className:"mt-3",children:e.jsx("b",{children:s("Integration Name:")})}),e.jsx("input",{className:"btcd-paper-inp w-6 mt-1",onChange:v,name:"name",value:i.name,type:"text",placeholder:s("Integration Name..."),disabled:h}),e.jsx("div",{style:{color:"red",fontSize:"15px",marginTop:"5px"},children:m.name}),e.jsx("div",{className:"mt-3",children:e.jsx("b",{children:s("Bot API Key:")})}),e.jsx("input",{className:"btcd-paper-inp w-6 mt-1",onChange:v,name:"bot_api_key",value:i.bot_api_key,type:"text",placeholder:s("Bot API Key..."),disabled:h}),e.jsx("div",{style:{color:"red",fontSize:"15px",marginTop:"5px"},children:m.bot_api_key}),c==="auth"&&e.jsxs("div",{className:"flx mt-5",children:[e.jsx(K,{size:25,clr:"#022217",className:"mr-2"}),"Checking API Key!!!"]}),b&&!o&&!c&&e.jsxs("div",{className:"flx mt-5",style:{color:"red"},children:[e.jsx("span",{className:"mr-2",style:{fontSize:30,marginTop:-5},children:e.jsx(V,{size:"15"})}),m.apiError]}),!h&&e.jsxs(e.Fragment,{children:[e.jsx(X,{isAuthorized:o,isLoading:c,handleAuthorize:()=>y()}),e.jsx("br",{}),e.jsx(Y,{autoAdvance:!0,nextPageHandler:()=>_(),disabled:!o})]})]})]})}function se({formFields:i,telegramConf:t,setTelegramConf:a}){var x,m;const[l,r]=f.useState({show:!1}),h=typeof((x=t.actions)==null?void 0:x.attachments)=="string"?t.actions.attachments.split(","):(m=t.actions)==null?void 0:m.attachments,o=d=>{const b=O(t);d!==""?b.actions.attachments=d?d.split(","):[]:delete b.actions.attachments,a(u({},b))};return e.jsxs("div",{className:"pos-rel",children:[e.jsx("div",{className:"d-flx flx-wrp",children:e.jsx(q,{onChange:()=>r({show:"attachments"}),checked:"attachments"in t.actions,className:"wdt-400 mt-4 mr-2",value:"Attachment",title:s("Attachments or Signature field"),subTitle:s("Add attachments or Signature field from BitForm to send Telegram.")})}),e.jsxs(D,{className:"custom-conf-mdl",mainMdlCls:"o-v",btnClass:"blue",btnTxt:"Ok",show:l.show==="attachments",close:()=>r({show:!1}),action:()=>r({show:!1}),title:s("Select Attachment"),children:[e.jsx("div",{className:"btcd-hr mt-2"}),e.jsx("div",{className:"mt-2",children:s("Please select file upload or signature field")}),e.jsx(z,{options:i.filter(d=>P.includes(d.type)).map(d=>({label:d.name,value:d.key})),className:"btcd-paper-drpdwn w-10",defaultValue:h,onChange:d=>o(d)})]})]})}function ae({formFields:i,telegramConf:t,setTelegramConf:a,isLoading:l,setisLoading:r,setSnackbar:h}){var b;const o=i.filter(n=>!P.includes(n.type)),x=n=>{const c=u({},t);c[n.target.name]=n.target.value,a(c)},m=n=>{a(c=>G(c,g=>{g.body=n}))},d=n=>{const c=u({},t);c!=null&&c.body&&(c.body=""),c.parse_mode=n.target.value,a(c)};return e.jsxs(e.Fragment,{children:[e.jsx("br",{}),e.jsxs("div",{className:"flx",children:[e.jsx("b",{className:"wdt-150 d-in-b",children:s("Chat List:")}),e.jsxs("select",{onChange:x,name:"chat_id",value:t.chat_id,className:"btcd-paper-inp w-5",children:[e.jsx("option",{value:"",children:s("Select Chat List")}),((b=t==null?void 0:t.default)==null?void 0:b.telegramChatLists)&&Object.keys(t.default.telegramChatLists).map(n=>e.jsx("option",{value:t.default.telegramChatLists[n].id,children:t.default.telegramChatLists[n].name},n))]}),e.jsx("button",{onClick:()=>I(t,a,r,h),className:"icn-btn sh-sm ml-2 mr-2 tooltip",style:{"--tooltip-txt":`'${s("Refresh Telegram List")}'`},type:"button",disabled:l,children:"↻"})]}),l&&e.jsx(R,{style:{display:"flex",justifyContent:"center",alignItems:"center",height:100,transform:"scale(0.7)"}}),(t==null?void 0:t.chat_id)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flx mt-4",children:[e.jsx("b",{className:"wdt-150 d-in-b",children:s("Parse Mode:")}),e.jsx(M,{radio:!0,onChange:n=>d(n),name:"HTML",title:e.jsx("small",{className:"txt-dp",children:s("HTML")}),checked:t.parse_mode==="HTML",value:"HTML"}),e.jsx(M,{radio:!0,onChange:n=>d(n),name:"MarkdownV2",title:e.jsx("small",{className:"txt-dp",children:s("Markdown v2")}),checked:t.parse_mode==="MarkdownV2",value:"MarkdownV2"})]}),e.jsxs("div",{className:"flx mt-4",children:[e.jsx("b",{className:"wdt-150 d-in-b",children:s("Messages:")}),(t==null?void 0:t.parse_mode)==="HTML"?e.jsx(Z,{formFields:o,value:t.body,onChangeHandler:m,width:"100%",toolbarMnu:"bold italic underline strikethrough | link | code | addFormField | addSmartField"}):e.jsxs(e.Fragment,{children:[e.jsx("textarea",{className:"w-7",onChange:x,name:"body",rows:"5",value:t.body}),e.jsx(z,{options:o.map(n=>({label:n.name,value:`\${${n.key}}`})),className:"btcd-paper-drpdwn wdt-200 ml-2",singleSelect:!0,onChange:n=>m(n)})]})]}),e.jsx("div",{className:"mt-4",children:e.jsx("b",{className:"wdt-100",children:s("Actions")})}),e.jsx("div",{className:"btcd-hr mt-1"}),e.jsx(se,{telegramConf:t,setTelegramConf:a,formFields:i})]})]})}function Te({mode:i="new",formFields:t,integrations:a,setIntegration:l,allIntegURL:r}){const h=U(),{id:o,formID:x}=J(),[m,d]=f.useState(!1),[b,n]=f.useState({show:!1}),[c,g]=f.useState(1),[y,v]=f.useState(()=>i==="edit"?u({},a[o]):{name:"Telegram",type:"Telegram",parse_mode:"HTML",bot_api_key:"",chat_id:"",body:"",actions:{}}),_=()=>{i==="edit"?T(a,l,r,y,h,o,1):T(a,l,r,y,h)},p=i==="edit"||c>=2;return ee({conf:y,onSeed:w=>{v(u({},w)),g(2)},save:_,saveDisabled:!y.chat_id,ready:p}),e.jsxs("div",{children:[e.jsx(Q,{snack:b,setSnackbar:n}),i==="new"?e.jsx(N,{title:s("Connect"),subtitle:s("Authorize this service to continue."),children:e.jsx(te,{formID:x,telegramConf:y,setTelegramConf:v,step:c,setstep:g,isLoading:m,setisLoading:d,setSnackbar:n})}):e.jsx(N,{title:s("Name this integration"),children:e.jsx("input",{className:"btcd-paper-inp w-10",onChange:w=>v(j=>S(u({},j),{name:w.target.value})),name:"name",value:y.name,type:"text",placeholder:s("Integration Name...")})}),p&&e.jsx(N,{title:s("Field mapping"),subtitle:s("Choose the destination and match form fields to it."),children:e.jsx(ae,{formID:x,formFields:t,telegramConf:y,setTelegramConf:v,isLoading:m,setisLoading:d,setSnackbar:n})})]})}export{Te as default};