diff --git a/manager/dist/assets/index-BmAfUzu7.js b/manager/dist/assets/index-C6xnilvd.js similarity index 76% rename from manager/dist/assets/index-BmAfUzu7.js rename to manager/dist/assets/index-C6xnilvd.js index 2edd6760..43b11971 100644 --- a/manager/dist/assets/index-BmAfUzu7.js +++ b/manager/dist/assets/index-C6xnilvd.js @@ -378,4 +378,4 @@ lodash-es/lodash.js: * LICENSE.md file in the root directory of this source tree. * * @license MIT - */function Rr(e,t){return e?VZ(e)?m.createElement(e,t):e:null}function VZ(e){return HZ(e)||typeof e=="function"||WZ(e)}function HZ(e){return typeof e=="function"&&(()=>{const t=Object.getPrototypeOf(e);return t.prototype&&t.prototype.isReactComponent})()}function WZ(e){return typeof e=="object"&&typeof e.$$typeof=="symbol"&&["react.memo","react.forward_ref"].includes(e.$$typeof.description)}function Ul(e){const t={state:{},onStateChange:()=>{},renderFallbackValue:null,...e},[n]=m.useState(()=>({current:LZ(t)})),[r,s]=m.useState(()=>n.current.initialState);return n.current.setOptions(o=>({...o,...e,state:{...r,...e.state},onStateChange:a=>{s(a),e.onStateChange==null||e.onStateChange(a)}})),n.current}const ri=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{className:"relative w-full overflow-auto",children:i.jsx("table",{ref:n,className:me("w-full caption-bottom text-sm",e),...t})}));ri.displayName="Table";const si=m.forwardRef(({className:e,...t},n)=>i.jsx("thead",{ref:n,className:me("[&_tr]:border-b",e),...t}));si.displayName="TableHeader";const oi=m.forwardRef(({className:e,...t},n)=>i.jsx("tbody",{ref:n,className:me("[&_tr:last-child]:border-0",e),...t}));oi.displayName="TableBody";const GZ=m.forwardRef(({className:e,...t},n)=>i.jsx("tfoot",{ref:n,className:me("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",e),...t}));GZ.displayName="TableFooter";const en=m.forwardRef(({className:e,...t},n)=>i.jsx("tr",{ref:n,className:me("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",e),...t}));en.displayName="TableRow";const ai=m.forwardRef(({className:e,...t},n)=>i.jsx("th",{ref:n,className:me("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",e),...t}));ai.displayName="TableHead";const ir=m.forwardRef(({className:e,...t},n)=>i.jsx("td",{ref:n,className:me("p-4 align-middle [&:has([role=checkbox])]:pr-0",e),...t}));ir.displayName="TableCell";const qZ=m.forwardRef(({className:e,...t},n)=>i.jsx("caption",{ref:n,className:me("mt-4 text-sm text-muted-foreground",e),...t}));qZ.displayName="TableCaption";const T1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await JJ(e.name,r,n);t(s)}else console.error("Token not found.")}catch(r){console.error("Errors:",r)}};function DP({difyId:e}){var h,v;const{t}=Le(),{instance:n}=st(),[r,s]=m.useState([]),[o,a]=m.useState([]),[l,c]=m.useState(!1);m.useEffect(()=>{l&&T1(n,a,e)},[n,e,l]);function u(){T1(n,a,e)}const d=async(g,b)=>{var y,x,w;try{if(!n)return;await ZJ(n.name,n.token,g,b),X.success(t("dify.toast.success.status")),u()}catch(S){console.error("Error:",S),X.error(`Error : ${(w=(x=(y=S==null?void 0:S.response)==null?void 0:y.data)==null?void 0:x.response)==null?void 0:w.message}`)}},f=[{accessorKey:"remoteJid",header:()=>i.jsx("div",{className:"text-center",children:t("dify.sessions.table.remoteJid")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>i.jsx("div",{className:"text-center",children:t("dify.sessions.table.pushName")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("pushName")})},{accessorKey:"sessionId",header:()=>i.jsx("div",{className:"text-center",children:t("dify.sessions.table.sessionId")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("sessionId")})},{accessorKey:"status",header:()=>i.jsx("div",{className:"text-center",children:t("dify.sessions.table.status")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:g})=>{const b=g.original;return i.jsxs(to,{children:[i.jsx(no,{asChild:!0,children:i.jsxs(J,{variant:"ghost",className:"h-8 w-8 p-0",children:[i.jsx("span",{className:"sr-only",children:t("dify.sessions.table.actions.title")}),i.jsx(Sl,{className:"h-4 w-4"})]})}),i.jsxs(Qr,{align:"end",children:[i.jsx(ei,{children:t("dify.sessions.table.actions.title")}),i.jsx(ra,{}),b.status!=="opened"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"opened"),children:[i.jsx(Ku,{className:"mr-2 h-4 w-4"}),t("dify.sessions.table.actions.open")]}),b.status!=="paused"&&b.status!=="closed"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"paused"),children:[i.jsx(qu,{className:"mr-2 h-4 w-4"}),t("dify.sessions.table.actions.pause")]}),b.status!=="closed"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"closed"),children:[i.jsx(Hu,{className:"mr-2 h-4 w-4"}),t("dify.sessions.table.actions.close")]}),i.jsxs(at,{onClick:()=>d(b.remoteJid,"delete"),children:[i.jsx(Wu,{className:"mr-2 h-4 w-4"}),t("dify.sessions.table.actions.delete")]})]})]})}}],p=Ul({data:o,columns:f,onSortingChange:s,getCoreRowModel:Ll(),getPaginationRowModel:Bl(),getSortedRowModel:zl(),getFilteredRowModel:$l(),state:{sorting:r}});return i.jsxs(yt,{open:l,onOpenChange:c,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{variant:"secondary",size:"sm",children:[i.jsx(Gu,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("dify.sessions.label")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:u,children:[i.jsx(gt,{children:i.jsx(At,{children:t("dify.sessions.label")})}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[i.jsx(A,{placeholder:t("dify.sessions.search"),value:((h=p.getColumn("remoteJid"))==null?void 0:h.getFilterValue())??"",onChange:g=>{var b;return(b=p.getColumn("remoteJid"))==null?void 0:b.setFilterValue(g.target.value)}}),i.jsx(J,{variant:"outline",onClick:u,size:"icon",children:i.jsx(Ju,{})})]}),i.jsxs(ri,{children:[i.jsx(si,{children:p.getHeaderGroups().map(g=>i.jsx(en,{children:g.headers.map(b=>i.jsx(ai,{children:b.isPlaceholder?null:Rr(b.column.columnDef.header,b.getContext())},b.id))},g.id))}),i.jsx(oi,{children:(v=p.getRowModel().rows)!=null&&v.length?p.getRowModel().rows.map(g=>i.jsx(en,{"data-state":g.getIsSelected()&&"selected",children:g.getVisibleCells().map(b=>i.jsx(ir,{children:Rr(b.column.columnDef.cell,b.getContext())},b.id))},g.id)):i.jsx(en,{children:i.jsx(ir,{colSpan:f.length,className:"h-24 text-center",children:t("dify.sessions.table.none")})})})]})]})]})]})}const KZ=k.object({enabled:k.boolean(),description:k.string(),botType:k.string(),apiUrl:k.string(),apiKey:k.string(),triggerType:k.string(),triggerOperator:k.string().optional(),triggerValue:k.string().optional(),expire:k.coerce.number(),keywordFinish:k.string(),delayMessage:k.coerce.number(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.coerce.number()});function JZ({difyId:e,instance:t,resetTable:n}){const{t:r}=Le(),[,s]=m.useState(""),[o,a]=m.useState(!0),[l,c]=m.useState(!1),u=En(),d=kt({resolver:Et(KZ),defaultValues:{enabled:!0,description:"",botType:"chatBot",apiUrl:"",apiKey:"",triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:0,keywordFinish:"",delayMessage:0,unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:0}});m.useEffect(()=>{(async()=>{try{const b=localStorage.getItem("token");if(b&&t&&t.name&&e){s(b);const y=await VJ(t.name,b,e);d.reset({enabled:y.enabled,description:y.description,botType:y.botType,apiUrl:y.apiUrl,apiKey:y.apiKey,triggerType:y.triggerType,triggerOperator:y.triggerOperator,triggerValue:y.triggerValue,expire:y.expire,keywordFinish:y.keywordFinish,delayMessage:y.delayMessage,unknownMessage:y.unknownMessage,listeningFromMe:y.listeningFromMe,stopBotFromMe:y.stopBotFromMe,keepOpen:y.keepOpen,debounceTime:y.debounceTime})}else console.error("Token not found.");a(!1)}catch(b){console.error("Error:",b),a(!1)}})()},[d,t,e]);const f=async g=>{var b,y,x;try{const w=localStorage.getItem("token");if(w&&t&&t.name&&e){const S={enabled:g.enabled,description:g.description,botType:g.botType,apiUrl:g.apiUrl,apiKey:g.apiKey,triggerType:g.triggerType,triggerOperator:g.triggerOperator||"",triggerValue:g.triggerValue||"",expire:g.expire,keywordFinish:g.keywordFinish,delayMessage:g.delayMessage,unknownMessage:g.unknownMessage,listeningFromMe:g.listeningFromMe,stopBotFromMe:g.stopBotFromMe,keepOpen:g.keepOpen,debounceTime:g.debounceTime};await WJ(t.name,w,e,S),X.success(r("dify.toast.success.update"))}else console.error("Token not found")}catch(w){console.error("Error:",w),X.error(`Error: ${(x=(y=(b=w==null?void 0:w.response)==null?void 0:b.data)==null?void 0:y.response)==null?void 0:x.message}`)}},p=async()=>{try{const g=localStorage.getItem("token");g&&t&&t.name&&e?(await GJ(t.name,g,e),X.success(r("dify.toast.success.delete")),c(!1),n(),u(`/manager/instance/${t.id}/dify`)):console.error("instance not found")}catch(g){console.error("Erro ao excluir dify:",g)}},h=d.watch("description"),v=d.watch("triggerType");return i.jsxs(i.Fragment,{children:[o&&i.jsx(or,{}),!o&&i.jsx(fr,{...d,children:i.jsxs("form",{onSubmit:d.handleSubmit(f),className:"w-full space-y-6 pl-4 pr-2",children:[i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[i.jsxs("h3",{className:"mb-4 text-lg font-medium",children:["Dify: ",h]}),i.jsx(he,{name:"enabled",className:"flex items-center gap-3"})]}),i.jsxs("div",{className:"space-y-4",children:[i.jsx(D,{name:"description",label:r("dify.form.description.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("dify.form.difySettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"botType",label:r("dify.form.botType.label"),required:!0,options:[{label:r("dify.form.botType.chatBot"),value:"chatBot"},{label:r("dify.form.botType.textGenerator"),value:"textGenerator"},{label:r("dify.form.botType.agent"),value:"agent"},{label:r("dify.form.botType.workflow"),value:"workflow"}]}),i.jsx(D,{name:"apiUrl",label:r("dify.form.apiUrl.label"),required:!0,children:i.jsx(A,{})}),i.jsx(D,{name:"apiKey",label:r("dify.form.apiKey.label"),required:!0,children:i.jsx(A,{type:"password"})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("dify.form.triggerSettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"triggerType",label:r("dify.form.triggerType.label"),options:[{label:r("dify.form.triggerType.keyword"),value:"keyword"},{label:r("dify.form.triggerType.all"),value:"all"},{label:r("dify.form.triggerType.advanced"),value:"advanced"},{label:r("dify.form.triggerType.none"),value:"none"}],required:!0}),v==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(et,{name:"triggerOperator",label:r("dify.form.triggerOperator.label"),options:[{label:r("dify.form.triggerOperator.contains"),value:"contains"},{label:r("dify.form.triggerOperator.equals"),value:"equals"},{label:r("dify.form.triggerOperator.startsWith"),value:"startsWith"},{label:r("dify.form.triggerOperator.endsWith"),value:"endsWith"},{label:r("dify.form.triggerOperator.regex"),value:"regex"}],required:!0}),i.jsx(D,{name:"triggerValue",label:r("dify.form.triggerValue.label"),required:!0,children:i.jsx(A,{})})]}),v==="advanced"&&i.jsx(D,{name:"triggerValue",label:r("dify.form.triggerConditions.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("dify.form.generalSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"expire",label:r("dify.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:r("dify.form.keywordFinish.label"),required:!0,children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:r("dify.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:r("dify.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:r("dify.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:r("dify.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:r("dify.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:r("dify.form.debounceTime.label"),children:i.jsx(A,{type:"number"})})]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx(DP,{difyId:e}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs(yt,{open:l,onOpenChange:c,children:[i.jsx(Rt,{asChild:!0,children:i.jsx(J,{variant:"destructive",size:"sm",children:r("dify.button.delete")})}),i.jsx(pt,{children:i.jsxs(gt,{children:[i.jsx(At,{children:r("modal.delete.title")}),i.jsx(ti,{children:r("modal.delete.messageSingle")}),i.jsxs(Jt,{children:[i.jsx(J,{size:"sm",variant:"outline",onClick:()=>c(!1),children:r("button.cancel")}),i.jsx(J,{variant:"destructive",onClick:p,children:r("button.delete")})]})]})})]}),i.jsx(J,{type:"submit",children:r("dify.button.update")})]})]})]})})]})}const j1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await EP(e.name,r);t(s)}else console.error("Token not found");n(!1)}catch(r){console.error("Error:",r),n(!1)}};function _1(){const{t:e}=Le(),t=Fl("(min-width: 768px)"),{instance:n}=st(),{difyId:r}=Ys(),[s,o]=m.useState(!0),[a,l]=m.useState([]),c=En();m.useEffect(()=>{n&&j1(n,l,o)},[n]);const u=f=>{n&&c(`/manager/instance/${n.id}/dify/${f}`)},d=()=>{j1(n,l,o)};return i.jsxs("main",{className:"pt-5",children:[i.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[i.jsx("h3",{className:"text-lg font-medium",children:e("dify.title")}),i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[i.jsx(DP,{}),i.jsx(YJ,{}),i.jsx(eZ,{resetTable:d})]})]}),i.jsx(Ze,{className:"my-4"}),i.jsxs(Dl,{direction:t?"horizontal":"vertical",children:[i.jsx(_r,{defaultSize:35,className:"pr-4",children:i.jsx("div",{className:"flex flex-col gap-3",children:s?i.jsx(or,{}):i.jsx(i.Fragment,{children:a&&a.length>0&&Array.isArray(a)?a.map(f=>i.jsxs(J,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>u(`${f.id}`),variant:r===f.id?"secondary":"outline",children:[i.jsx("h4",{className:"text-base",children:f.description||f.id}),i.jsx("p",{className:"text-sm font-normal text-muted-foreground",children:f.botType})]},f.id)):i.jsx(J,{variant:"link",children:e("dify.table.none")})})})}),r&&i.jsxs(i.Fragment,{children:[i.jsx(Al,{withHandle:!0,className:"border border-border"}),i.jsx(_r,{className:"",children:i.jsx(JZ,{difyId:r,instance:n,resetTable:d})})]})]})]})}const gr=new ur,Wg=async(e,t)=>(await gr.getInstance().get(`/openai/creds/${e}`,{headers:{apikey:t}})).data,ZZ=async(e,t,n)=>(await gr.getInstance().post(`/openai/creds/${e}`,n,{headers:{apikey:t}})).data,QZ=async(e,t)=>(await gr.getInstance().delete(`/openai/creds/${e}/${t}`)).data,AP=async(e,t)=>(await gr.getInstance().get(`/openai/find/${e}`,{headers:{apikey:t}})).data,YZ=async(e,t,n)=>(await gr.getInstance().get(`/openai/fetch/${n}/${e}`,{headers:{apikey:t}})).data,XZ=async(e,t,n)=>(await gr.getInstance().post(`/openai/create/${e}`,n,{headers:{apikey:t}})).data,eQ=async(e,t,n,r)=>(await gr.getInstance().put(`/openai/update/${n}/${e}`,r,{headers:{apikey:t}})).data,tQ=async(e,t,n)=>(await gr.getInstance().delete(`/openai/delete/${n}/${e}`,{headers:{apikey:t}})).data,nQ=async(e,t)=>(await gr.getInstance().get(`/openai/fetchSettings/${e}`,{headers:{apikey:t}})).data,rQ=async(e,t,n)=>(await gr.getInstance().post(`/openai/settings/${e}`,n,{headers:{apikey:t}})).data,sQ=async(e,t,n)=>(await gr.getInstance().get(`/openai/fetchSessions/${n}/${e}`,{headers:{apikey:t}})).data,oQ=async(e,t,n,r)=>(await gr.getInstance().post(`/openai/changeStatus/${e}`,{remoteJid:n,status:r},{headers:{apikey:t}})).data,FP=async(e,t)=>(await gr.getInstance().get(`/openai/getModels/${e}`,{headers:{apikey:t}})).data,aQ=k.object({name:k.string(),apiKey:k.string()}),pm=async(e,t)=>{try{const n=localStorage.getItem("token");if(n&&e&&e.name){const r=await Wg(e.name,n);t(r)}else console.error("Token not found.")}catch(n){console.error("Error:",n)}};function iQ(){var v;const{t:e}=Le(),{instance:t}=st(),[n,r]=m.useState(!1),[s,o]=m.useState([]),[a,l]=m.useState([]),c=kt({resolver:Et(aQ),defaultValues:{name:"",apiKey:""}});m.useEffect(()=>{n&&pm(t,l)},[t,n]);const u=async g=>{var b,y,x;try{if(!t||!t.name)throw new Error("instance not found.");const w={name:g.name,apiKey:g.apiKey};await ZZ(t.name,t.token,w),X.success(e("openai.toast.success.credentialsCreate")),d()}catch(w){console.error("Error:",w),X.error(`Error: ${(x=(y=(b=w==null?void 0:w.response)==null?void 0:b.data)==null?void 0:y.response)==null?void 0:x.message}`)}};function d(){c.reset(),pm(t,l)}const f=async g=>{var b,y,x;try{await QZ(g,t==null?void 0:t.name),X.success(e("openai.toast.success.credentialsDelete")),pm(t,l)}catch(w){console.error("Error:",w),X.error(`Error: ${(x=(y=(b=w==null?void 0:w.response)==null?void 0:b.data)==null?void 0:y.response)==null?void 0:x.message}`)}},p=[{accessorKey:"name",header:({column:g})=>i.jsxs(J,{variant:"ghost",onClick:()=>g.toggleSorting(g.getIsSorted()==="asc"),children:[e("openai.credentials.table.name"),i.jsx(e4,{className:"ml-2 h-4 w-4"})]}),cell:({row:g})=>i.jsx("div",{children:g.getValue("name")})},{accessorKey:"apiKey",header:()=>i.jsx("div",{className:"text-right",children:e("openai.credentials.table.apiKey")}),cell:({row:g})=>i.jsxs("div",{children:[`${g.getValue("apiKey")}`.slice(0,20),"..."]})},{id:"actions",enableHiding:!1,cell:({row:g})=>{const b=g.original;return i.jsxs(to,{children:[i.jsx(no,{asChild:!0,children:i.jsxs(J,{variant:"ghost",className:"h-8 w-8 p-0",children:[i.jsx("span",{className:"sr-only",children:e("openai.credentials.table.actions.title")}),i.jsx(Sl,{className:"h-4 w-4"})]})}),i.jsxs(Qr,{align:"end",children:[i.jsx(ei,{children:e("openai.credentials.table.actions.title")}),i.jsx(ra,{}),i.jsx(at,{onClick:()=>f(b.id),children:e("openai.credentials.table.actions.delete")})]})]})}}],h=Ul({data:a,columns:p,onSortingChange:o,getCoreRowModel:Ll(),getPaginationRowModel:Bl(),getSortedRowModel:zl(),getFilteredRowModel:$l(),state:{sorting:s}});return i.jsxs(yt,{open:n,onOpenChange:r,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{variant:"secondary",size:"sm",children:[i.jsx(v4,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden md:inline",children:e("openai.credentials.title")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:d,children:[i.jsx(gt,{children:i.jsx(At,{children:e("openai.credentials.title")})}),i.jsx(dr,{...c,children:i.jsxs("form",{onSubmit:c.handleSubmit(u),className:"w-full space-y-6",children:[i.jsx("div",{children:i.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[i.jsx(D,{name:"name",label:e("openai.credentials.table.name"),children:i.jsx(A,{})}),i.jsx(D,{name:"apiKey",label:e("openai.credentials.table.apiKey"),children:i.jsx(A,{type:"password"})})]})}),i.jsx(Jt,{children:i.jsx(J,{type:"submit",children:e("openai.button.save")})})]})}),i.jsx(Ze,{}),i.jsx("div",{children:i.jsxs(ri,{children:[i.jsx(si,{children:h.getHeaderGroups().map(g=>i.jsx(en,{children:g.headers.map(b=>i.jsx(ai,{children:b.isPlaceholder?null:Rr(b.column.columnDef.header,b.getContext())},b.id))},g.id))}),i.jsx(oi,{children:(v=h.getRowModel().rows)!=null&&v.length?h.getRowModel().rows.map(g=>i.jsx(en,{"data-state":g.getIsSelected()&&"selected",children:g.getVisibleCells().map(b=>i.jsx(ir,{children:Rr(b.column.columnDef.cell,b.getContext())},b.id))},g.id)):i.jsx(en,{children:i.jsx(ir,{colSpan:p.length,className:"h-24 text-center",children:e("openai.credentials.table.none")})})})]})})]})]})}const lQ=k.object({openaiCredsId:k.string(),expire:k.coerce.number(),keywordFinish:k.string(),delayMessage:k.coerce.number().default(0),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.coerce.number(),speechToText:k.boolean(),ignoreJids:k.array(k.string()).default([]),openaiIdFallback:k.union([k.null(),k.string()]).optional()}),R1=async(e,t,n,r)=>{try{const s=localStorage.getItem("token");if(s&&e&&e.name){const o=await nQ(e.name,s);t(o);const a=await AP(e.name,s);n(a);const l=await Wg(e.name,s);r(l)}else console.error("Token not found")}catch(s){console.error("Error:",s)}};function cQ(){const{t:e}=Le(),{instance:t}=st(),[n,r]=m.useState(!1),[s,o]=m.useState(),[a,l]=m.useState([]),[c,u]=m.useState(),d=kt({resolver:Et(lQ),defaultValues:{openaiCredsId:"",expire:0,keywordFinish:e("openai.form.examples.keywordFinish"),delayMessage:1e3,unknownMessage:e("openai.form.examples.unknownMessage"),listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:0,speechToText:!1,ignoreJids:[],openaiIdFallback:void 0}});m.useEffect(()=>{n&&R1(t,o,l,u)},[t,n]),m.useEffect(()=>{s&&d.reset({openaiCredsId:s.openaiCredsId,expire:(s==null?void 0:s.expire)??0,keywordFinish:s.keywordFinish,delayMessage:s.delayMessage??0,unknownMessage:s.unknownMessage,listeningFromMe:s.listeningFromMe,stopBotFromMe:s.stopBotFromMe,keepOpen:s.keepOpen,debounceTime:s.debounceTime??0,speechToText:s.speechToText,ignoreJids:s.ignoreJids,openaiIdFallback:s.openaiIdFallback})},[s]);const f=async h=>{var v,g,b;try{if(!t||!t.name)throw new Error("instance not found.");const y={openaiCredsId:h.openaiCredsId,expire:h.expire,keywordFinish:h.keywordFinish,delayMessage:h.delayMessage,unknownMessage:h.unknownMessage,listeningFromMe:h.listeningFromMe,stopBotFromMe:h.stopBotFromMe,keepOpen:h.keepOpen,debounceTime:h.debounceTime,speechToText:h.speechToText,openaiIdFallback:h.openaiIdFallback||void 0,ignoreJids:h.ignoreJids};await rQ(t.name,t.token,y),X.success(e("openai.toast.defaultSettings.success"))}catch(y){console.error("Error:",y),X.error(`Error: ${(b=(g=(v=y==null?void 0:y.response)==null?void 0:v.data)==null?void 0:g.response)==null?void 0:b.message}`)}};function p(){R1(t,o,l,u)}return i.jsxs(yt,{open:n,onOpenChange:r,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{variant:"secondary",size:"sm",children:[i.jsx(Za,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden md:inline",children:e("openai.defaultSettings")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:p,children:[i.jsx(gt,{children:i.jsx(At,{children:e("openai.defaultSettings")})}),i.jsx(dr,{...d,children:i.jsxs("form",{className:"w-full space-y-6",onSubmit:d.handleSubmit(f),children:[i.jsx("div",{children:i.jsxs("div",{className:"space-y-4",children:[i.jsx(et,{name:"openaiCredsId",label:e("openai.form.openaiCredsId.label"),options:(c==null?void 0:c.filter(h=>!!h.id).map(h=>({label:h.name?h.name:h.apiKey.substring(0,15)+"...",value:h.id})))||[]}),i.jsx(et,{name:"openaiIdFallback",label:e("openai.form.openaiIdFallback.label"),options:(a==null?void 0:a.filter(h=>!!h.id).map(h=>({label:h.description,value:h.id})))??[]}),i.jsx(D,{name:"expire",label:e("openai.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:e("openai.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:e("openai.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:e("openai.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:e("openai.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:e("openai.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:e("openai.form.keepOpen.label"),reverse:!0}),i.jsx(he,{name:"speechToText",label:e("openai.form.speechToText.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:e("openai.form.debounceTime.label"),children:i.jsx(A,{type:"number"})}),i.jsx(Ml,{name:"ignoreJids",label:e("openai.form.ignoreJids.label"),placeholder:e("openai.form.ignoreJids.placeholder")})]})}),i.jsx(Jt,{children:i.jsx(J,{type:"submit",children:e("openai.button.save")})})]})})]})]})}const uQ=k.object({enabled:k.boolean(),description:k.string(),openaiCredsId:k.string(),botType:k.string(),assistantId:k.string(),functionUrl:k.string(),model:k.string(),systemMessages:k.string(),assistantMessages:k.string(),userMessages:k.string(),maxTokens:k.string(),triggerType:k.string(),triggerOperator:k.string().optional(),triggerValue:k.string().optional(),expire:k.string(),keywordFinish:k.string(),delayMessage:k.string(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.string()});function dQ({resetTable:e}){const{t}=Le(),{instance:n}=st(),[r,s]=m.useState(!1),[o,a]=m.useState(!1),[l,c]=m.useState([]),[u,d]=m.useState([]),f=kt({resolver:Et(uQ),defaultValues:{enabled:!0,description:"",openaiCredsId:"",botType:"assistant",assistantId:"",functionUrl:"",model:"gpt-4o-mini",systemMessages:"",assistantMessages:"",userMessages:"",maxTokens:"300",triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:"0",keywordFinish:"",delayMessage:"0",unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:"0"}});m.useEffect(()=>{o&&(async()=>{try{if(!n)return;const y=await FP(n.name,n.token);c(y);const x=await Wg(n.name,n.token);d(x)}catch(y){console.error("Error:",y)}})()},[n,o]);const p=async b=>{var y,x,w;try{if(!n||!n.name)throw new Error("instance not found.");s(!0);const S={enabled:b.enabled,description:b.description,openaiCredsId:b.openaiCredsId,botType:b.botType,assistantId:b.assistantId,functionUrl:b.functionUrl,model:b.model,systemMessages:[b.systemMessages],assistantMessages:[b.assistantMessages],userMessages:[b.userMessages],maxTokens:parseInt(b.maxTokens,10),triggerType:b.triggerType,triggerOperator:b.triggerOperator||"",triggerValue:b.triggerValue||"",expire:parseInt(b.expire,10),keywordFinish:b.keywordFinish,delayMessage:parseInt(b.delayMessage,10),unknownMessage:b.unknownMessage,listeningFromMe:b.listeningFromMe,stopBotFromMe:b.stopBotFromMe,keepOpen:b.keepOpen,debounceTime:parseInt(b.debounceTime,10)};await XZ(n.name,n.token,S),X.success(t("openai.toast.success.create")),a(!1),h(),e()}catch(S){console.error("Error:",S),X.error(`Error: ${(w=(x=(y=S==null?void 0:S.response)==null?void 0:y.data)==null?void 0:x.response)==null?void 0:w.message}`)}finally{s(!1)}};function h(){f.reset()}const v=f.watch("botType"),g=f.watch("triggerType");return i.jsxs(yt,{open:o,onOpenChange:a,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{size:"sm",children:[i.jsx(Qa,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("openai.button.create")})]})}),i.jsxs(pt,{className:"max-w-xl",onCloseAutoFocus:h,children:[i.jsx(gt,{children:i.jsx(At,{children:t("openai.form.title")})}),i.jsx(dr,{...f,children:i.jsxs("form",{onSubmit:f.handleSubmit(p),className:"w-full space-y-6",children:[i.jsx("div",{children:i.jsxs("div",{className:"space-y-4",children:[i.jsx(he,{name:"enabled",label:t("openai.form.enabled.label"),reverse:!0}),i.jsx(D,{name:"description",label:t("openai.form.description.label"),required:!0,children:i.jsx(A,{})}),i.jsx(et,{name:"openaiCredsId",label:t("openai.form.openaiCredsId.label"),required:!0,options:u.filter(b=>!!b.id).map(b=>({label:b.name?b.name:b.apiKey.substring(0,15)+"...",value:b.id}))}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("openai.form.openaiSettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"botType",label:t("openai.form.botType.label"),required:!0,options:[{label:t("openai.form.botType.assistant"),value:"assistant"},{label:t("openai.form.botType.chatCompletion"),value:"chatCompletion"}]}),v==="assistant"&&i.jsxs(i.Fragment,{children:[i.jsx(D,{name:"assistantId",label:t("openai.form.assistantId.label"),required:!0,children:i.jsx(A,{})}),i.jsx(D,{name:"functionUrl",label:t("openai.form.functionUrl.label"),required:!0,children:i.jsx(A,{})})]}),v==="chatCompletion"&&i.jsxs(i.Fragment,{children:[i.jsx(et,{name:"model",label:t("openai.form.model.label"),required:!0,options:l.map(b=>({label:b.id,value:b.id}))}),i.jsx(D,{name:"systemMessages",label:t("openai.form.systemMessages.label"),children:i.jsx(zs,{})}),i.jsx(D,{name:"assistantMessages",label:t("openai.form.assistantMessages.label"),children:i.jsx(zs,{})}),i.jsx(D,{name:"userMessages",label:t("openai.form.userMessages.label"),children:i.jsx(zs,{})}),i.jsx(D,{name:"maxTokens",label:t("openai.form.maxTokens.label"),children:i.jsx(A,{type:"number"})})]}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("openai.form.triggerSettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"triggerType",label:t("openai.form.triggerType.label"),required:!0,options:[{label:t("openai.form.triggerType.keyword"),value:"keyword"},{label:t("openai.form.triggerType.all"),value:"all"},{label:t("openai.form.triggerType.advanced"),value:"advanced"},{label:t("openai.form.triggerType.none"),value:"none"}]}),g==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(et,{name:"triggerOperator",label:t("openai.form.triggerOperator.label"),required:!0,options:[{label:t("openai.form.triggerOperator.contains"),value:"contains"},{label:t("openai.form.triggerOperator.equals"),value:"equals"},{label:t("openai.form.triggerOperator.startsWith"),value:"startsWith"},{label:t("openai.form.triggerOperator.endsWith"),value:"endsWith"},{label:t("openai.form.triggerOperator.regex"),value:"regex"}]}),i.jsx(D,{name:"triggerValue",label:t("openai.form.triggerValue.label"),required:!0,children:i.jsx(A,{})})]}),g==="advanced"&&i.jsx(D,{name:"triggerValue",label:t("openai.form.triggerConditions.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("openai.form.generalSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"expire",label:t("openai.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:t("openai.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:t("openai.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:t("openai.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:t("openai.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:t("openai.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:t("openai.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:t("openai.form.debounceTime.label"),children:i.jsx(A,{type:"number"})})]})}),i.jsx(Jt,{children:i.jsx(J,{disabled:r,type:"submit",children:t(r?"openai.button.saving":"openai.button.save")})})]})})]})]})}const I1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await sQ(e.name,r,n);t(s)}else console.error("Token not found")}catch(r){console.error("Error:",r)}};function LP({botId:e}){var h,v;const{t}=Le(),{instance:n}=st(),[r,s]=m.useState([]),[o,a]=m.useState([]),[l,c]=m.useState(!1);m.useEffect(()=>{l&&I1(n,a,e)},[n,e,l]);function u(){I1(n,a,e)}const d=async(g,b)=>{var y,x,w;try{if(!n)return;await oQ(n.name,n.token,g,b),X.success(t("openai.toast.success.status")),u()}catch(S){console.error("Error:",S),X.error(`Error : ${(w=(x=(y=S==null?void 0:S.response)==null?void 0:y.data)==null?void 0:x.response)==null?void 0:w.message}`)}},f=[{accessorKey:"remoteJid",header:()=>i.jsx("div",{className:"text-center",children:t("openai.sessions.table.remoteJid")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>i.jsx("div",{className:"text-center",children:t("openai.sessions.table.pushName")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("pushName")})},{accessorKey:"sessionId",header:()=>i.jsx("div",{className:"text-center",children:t("openai.sessions.table.sessionId")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("sessionId")})},{accessorKey:"status",header:()=>i.jsx("div",{className:"text-center",children:t("openai.sessions.table.status")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:g})=>{const b=g.original;return i.jsxs(to,{children:[i.jsx(no,{asChild:!0,children:i.jsxs(J,{variant:"ghost",size:"icon",children:[i.jsx("span",{className:"sr-only",children:t("openai.sessions.table.actions.title")}),i.jsx(Sl,{className:"h-4 w-4"})]})}),i.jsxs(Qr,{align:"end",children:[i.jsx(ei,{children:t("openai.sessions.table.actions.title")}),i.jsx(ra,{}),b.status!=="opened"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"opened"),children:[i.jsx(Ku,{className:"mr-2 h-4 w-4"}),t("openai.sessions.table.actions.open")]}),b.status!=="paused"&&b.status!=="closed"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"paused"),children:[i.jsx(qu,{className:"mr-2 h-4 w-4"}),t("openai.sessions.table.actions.pause")]}),b.status!=="closed"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"closed"),children:[i.jsx(Hu,{className:"mr-2 h-4 w-4"}),t("openai.sessions.table.actions.close")]}),i.jsxs(at,{onClick:()=>d(b.remoteJid,"delete"),children:[i.jsx(Wu,{className:"mr-2 h-4 w-4"}),t("openai.sessions.table.actions.delete")]})]})]})}}],p=Ul({data:o,columns:f,onSortingChange:s,getCoreRowModel:Ll(),getPaginationRowModel:Bl(),getSortedRowModel:zl(),getFilteredRowModel:$l(),state:{sorting:r}});return i.jsxs(yt,{open:l,onOpenChange:c,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{variant:"secondary",size:"sm",children:[i.jsx(Gu,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden md:inline",children:t("openai.sessions.label")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:u,children:[i.jsx(gt,{children:i.jsx(At,{children:t("openai.sessions.label")})}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[i.jsx(A,{placeholder:t("openai.sessions.search"),value:((h=p.getColumn("remoteJid"))==null?void 0:h.getFilterValue())??"",onChange:g=>{var b;return(b=p.getColumn("remoteJid"))==null?void 0:b.setFilterValue(g.target.value)}}),i.jsx(J,{variant:"outline",onClick:u,size:"icon",children:i.jsx(Ju,{size:16})})]}),i.jsxs(ri,{children:[i.jsx(si,{children:p.getHeaderGroups().map(g=>i.jsx(en,{children:g.headers.map(b=>i.jsx(ai,{children:b.isPlaceholder?null:Rr(b.column.columnDef.header,b.getContext())},b.id))},g.id))}),i.jsx(oi,{children:(v=p.getRowModel().rows)!=null&&v.length?p.getRowModel().rows.map(g=>i.jsx(en,{"data-state":g.getIsSelected()&&"selected",children:g.getVisibleCells().map(b=>i.jsx(ir,{children:Rr(b.column.columnDef.cell,b.getContext())},b.id))},g.id)):i.jsx(en,{children:i.jsx(ir,{colSpan:f.length,className:"h-24 text-center",children:t("openai.sessions.table.none")})})})]})]})]})]})}const fQ=k.object({enabled:k.boolean(),description:k.string(),openaiCredsId:k.string(),botType:k.string(),assistantId:k.string(),functionUrl:k.string().optional(),model:k.string(),systemMessages:k.string(),assistantMessages:k.string(),userMessages:k.string(),maxTokens:k.coerce.number(),triggerType:k.string(),triggerOperator:k.string().optional(),triggerValue:k.string().optional(),expire:k.coerce.number(),keywordFinish:k.string(),delayMessage:k.coerce.number(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.coerce.number(),ignoreJids:k.array(k.string()).default([])});function pQ({botId:e,instance:t,resetTable:n}){const{t:r}=Le(),[,s]=m.useState(""),[o,a]=m.useState(!0),[l,c]=m.useState(!1),[u,d]=m.useState([]),[f,p]=m.useState([]),h=En(),v=kt({resolver:Et(fQ),defaultValues:{enabled:!0,description:"",openaiCredsId:"",botType:"assistant",assistantId:"",functionUrl:"",model:"gpt-3.5-turbo",systemMessages:"",assistantMessages:"",userMessages:"",maxTokens:300,triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:0,keywordFinish:"",delayMessage:0,unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:0}});m.useEffect(()=>{const S=async()=>{try{const C=localStorage.getItem("token");if(C&&t&&t.name&&e){s(C);const T=await YZ(t.name,C,e);v.reset({enabled:T.enabled,description:T.description,openaiCredsId:T.openaiCredsId,botType:T.botType,assistantId:T.assistantId,functionUrl:T.functionUrl,model:T.model,systemMessages:T.systemMessages.toString(),assistantMessages:T.assistantMessages.toString(),userMessages:T.userMessages.toString(),maxTokens:T.maxTokens,triggerType:T.triggerType,triggerOperator:T.triggerOperator,triggerValue:T.triggerValue,expire:T.expire,keywordFinish:T.keywordFinish,delayMessage:T.delayMessage,unknownMessage:T.unknownMessage,listeningFromMe:T.listeningFromMe,stopBotFromMe:T.stopBotFromMe,keepOpen:T.keepOpen,debounceTime:T.debounceTime})}else console.error("Token not found.");a(!1)}catch(C){console.error("Error:",C),a(!1)}},E=async()=>{try{if(!t)return;const C=await FP(t.name,t.token);d(C);const T=await Wg(t.name,t.token);p(T)}catch(C){console.error("Error:",C)}};S(),E()},[v,t,e]);const g=async S=>{var E,C,T;try{const j=localStorage.getItem("token");if(j&&t&&t.name&&e){const I={enabled:S.enabled,description:S.description,openaiCredsId:S.openaiCredsId,botType:S.botType,assistantId:S.assistantId,functionUrl:S.functionUrl||"",model:S.model,systemMessages:[S.systemMessages],assistantMessages:[S.assistantMessages],userMessages:[S.userMessages],maxTokens:S.maxTokens,triggerType:S.triggerType,triggerOperator:S.triggerOperator||"",triggerValue:S.triggerValue||"",expire:S.expire,keywordFinish:S.keywordFinish,delayMessage:S.delayMessage,unknownMessage:S.unknownMessage,listeningFromMe:S.listeningFromMe,stopBotFromMe:S.stopBotFromMe,keepOpen:S.keepOpen,debounceTime:S.debounceTime};await eQ(t.name,j,e,I),X.success(r("openai.toast.success.update"))}else console.error("Instance not found")}catch(j){console.error("Error:",j),X.error(`Error: ${(T=(C=(E=j==null?void 0:j.response)==null?void 0:E.data)==null?void 0:C.response)==null?void 0:T.message}`)}},b=async()=>{try{const S=localStorage.getItem("token");S&&t&&t.name&&e?(await tQ(t.name,S,e),X.success(r("openai.toast.success.delete")),c(!1),n(),h(`/manager/instance/${t.id}/openai`)):console.error("Instance not found.")}catch(S){console.error("Error:",S)}},y=v.watch("description"),x=v.watch("botType"),w=v.watch("triggerType");return i.jsxs(i.Fragment,{children:[o&&i.jsx(or,{}),!o&&i.jsx(fr,{...v,children:i.jsxs("form",{onSubmit:v.handleSubmit(g),className:"w-full space-y-6 pl-4 pr-2",children:[i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[i.jsxs("h3",{className:"mb-4 text-lg font-medium",children:["OpenAI: ",y]}),i.jsx(he,{name:"enabled",className:"flex items-center gap-3"})]}),i.jsxs("div",{className:"space-y-4",children:[i.jsx(D,{name:"description",label:r("openai.form.description.label"),required:!0,children:i.jsx(A,{})}),i.jsx(et,{name:"openaiCredsId",label:r("openai.form.openaiCredsId.label"),required:!0,options:f.filter(S=>!!S.id).map(S=>({label:S.name?S.name:S.apiKey.substring(0,15)+"...",value:S.id}))}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("openai.form.openaiSettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"botType",label:r("openai.form.botType.label"),required:!0,options:[{label:r("openai.form.botType.assistant"),value:"assistant"},{label:r("openai.form.botType.chatCompletion"),value:"chatCompletion"}]}),x==="assistant"&&i.jsxs(i.Fragment,{children:[i.jsx(D,{name:"assistantId",label:r("openai.form.assistantId.label"),required:!0,children:i.jsx(A,{})}),i.jsx(D,{name:"functionUrl",label:r("openai.form.functionUrl.label"),required:!0,children:i.jsx(A,{})})]}),x==="chatCompletion"&&i.jsxs(i.Fragment,{children:[i.jsx(et,{name:"model",label:r("openai.form.model.label"),required:!0,options:u.map(S=>({label:S.id,value:S.id}))}),i.jsx(D,{name:"systemMessages",label:r("openai.form.systemMessages.label"),children:i.jsx(zs,{})}),i.jsx(D,{name:"assistantMessages",label:r("openai.form.assistantMessages.label"),children:i.jsx(zs,{})}),i.jsx(D,{name:"userMessages",label:r("openai.form.userMessages.label"),children:i.jsx(zs,{})}),i.jsx(D,{name:"maxTokens",label:r("openai.form.maxTokens"),children:i.jsx(A,{type:"number"})})]}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("openai.form.triggerSettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"triggerType",label:r("openai.form.triggerType.label"),required:!0,options:[{label:r("openai.form.triggerType.keyword"),value:"keyword"},{label:r("openai.form.triggerType.all"),value:"all"},{label:r("openai.form.triggerType.advanced"),value:"advanced"},{label:r("openai.form.triggerType.none"),value:"none"}]}),w==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(et,{name:"triggerOperator",label:r("openai.form.triggerOperator.label"),required:!0,options:[{label:r("openai.form.triggerOperator.contains"),value:"contains"},{label:r("openai.form.triggerOperator.equals"),value:"equals"},{label:r("openai.form.triggerOperator.startsWith"),value:"startsWith"},{label:r("openai.form.triggerOperator.endsWith"),value:"endsWith"},{label:r("openai.form.triggerOperator.regex"),value:"regex"}]}),i.jsx(D,{name:"triggerValue",label:r("openai.form.triggerValue.label"),required:!0,children:i.jsx(A,{})})]}),w==="advanced"&&i.jsx(D,{name:"triggerValue",label:r("openai.form.triggerConditions.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("openai.form.generalSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"expire",label:r("openai.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:r("openai.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:r("openai.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:r("openai.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:r("openai.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:r("openai.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:r("openai.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:r("openai.form.debounceTime.label"),children:i.jsx(A,{type:"number"})})]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx(LP,{botId:e}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs(yt,{open:l,onOpenChange:c,children:[i.jsx(Rt,{asChild:!0,children:i.jsx(J,{variant:"destructive",size:"sm",children:r("openai.button.delete")})}),i.jsx(pt,{children:i.jsxs(gt,{children:[i.jsx(At,{children:r("modal.delete.title")}),i.jsx(ti,{children:r("modal.delete.messageSingle")}),i.jsxs(Jt,{children:[i.jsx(J,{size:"sm",variant:"outline",onClick:()=>c(!1),children:r("button.cancel")}),i.jsx(J,{variant:"destructive",onClick:b,children:r("button.delete")})]})]})})]}),i.jsx(J,{type:"submit",children:r("openai.button.update")})]})]})]})})]})}const N1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await AP(e.name,r);t(s)}else console.error("Token ou nome da instância não encontrados.");n(!1)}catch(r){console.error("Erro ao carregar configurações:",r),n(!1)}};function P1(){const{t:e}=Le(),t=Fl("(min-width: 768px)"),{instance:n}=st(),{botId:r}=Ys(),[s,o]=m.useState(!0),[a,l]=m.useState([]),c=En();m.useEffect(()=>{n&&N1(n,l,o)},[n]);const u=f=>{n&&c(`/manager/instance/${n.id}/openai/${f}`)},d=()=>{N1(n,l,o)};return i.jsxs("main",{className:"pt-5",children:[i.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[i.jsx("h3",{className:"text-lg font-medium",children:e("openai.title")}),i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[i.jsx(LP,{}),i.jsx(cQ,{}),i.jsx(iQ,{}),i.jsx(dQ,{resetTable:d})]})]}),i.jsx(Ze,{className:"my-4"}),i.jsxs(Dl,{direction:t?"horizontal":"vertical",children:[i.jsx(_r,{defaultSize:35,className:"pr-4",children:i.jsx("div",{className:"flex flex-col gap-3",children:s?i.jsx(or,{}):i.jsx(i.Fragment,{children:a&&a.length>0&&Array.isArray(a)?a.map(f=>i.jsxs(J,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>u(`${f.id}`),variant:r===f.id?"secondary":"outline",children:[i.jsx("h4",{className:"text-base",children:f.description||f.id}),i.jsx("p",{className:"text-sm font-normal text-muted-foreground",children:f.botType})]},f.id)):i.jsx(J,{variant:"link",children:e("openai.table.none")})})})}),r&&i.jsxs(i.Fragment,{children:[i.jsx(Al,{withHandle:!0,className:"border border-border"}),i.jsx(_r,{className:"",children:i.jsx(pQ,{botId:r,instance:n,resetTable:d})})]})]})]})}const $P=new ur,gQ=async(e,t)=>(await $P.getInstance().get(`/proxy/find/${e}`,{headers:{apikey:t}})).data,hQ=async(e,t,n)=>(await $P.getInstance().post(`/proxy/set/${e}`,n,{headers:{apikey:t}})).data,mQ=k.object({enabled:k.boolean(),host:k.string(),port:k.string(),protocol:k.string(),username:k.string(),password:k.string()});function vQ(){const{t:e}=Le(),{instance:t}=st(),[n,r]=m.useState(!1),s=kt({resolver:Et(mQ),defaultValues:{enabled:!1,host:"",port:"",protocol:"http",username:"",password:""}});m.useEffect(()=>{(async()=>{if(t){r(!0);try{const l=await gQ(t.name,t.token);s.reset(l)}catch(l){console.error("Error:",l)}finally{r(!1)}}})()},[t,s]);const o=async a=>{var l,c,u;if(t){r(!0);try{const d={enabled:a.enabled,host:a.host,port:a.port,protocol:a.protocol,username:a.username,password:a.password};await hQ(t.name,t.token,d),X.success(e("proxy.toast.success"))}catch(d){console.error(e("proxy.toast.error"),d),X.error(`Error : ${(u=(c=(l=d==null?void 0:d.response)==null?void 0:l.data)==null?void 0:c.response)==null?void 0:u.message}`)}finally{r(!1)}}};return i.jsx(i.Fragment,{children:i.jsx(fr,{...s,children:i.jsx("form",{onSubmit:s.handleSubmit(o),className:"w-full space-y-6",children:i.jsxs("div",{children:[i.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("proxy.title")}),i.jsx(na,{className:"my-4"}),i.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[i.jsx(he,{name:"enabled",label:e("proxy.form.enabled.label"),className:"w-full justify-between",helper:e("proxy.form.enabled.description")}),i.jsxs("div",{className:"grid gap-4 sm:grid-cols-[10rem_1fr_10rem] md:gap-8",children:[i.jsx(D,{name:"protocol",label:e("proxy.form.protocol.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"host",label:e("proxy.form.host.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"port",label:e("proxy.form.port.label"),children:i.jsx(A,{type:"number"})})]}),i.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 md:gap-8",children:[i.jsx(D,{name:"username",label:e("proxy.form.username.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"password",label:e("proxy.form.password.label"),children:i.jsx(A,{type:"password"})})]}),i.jsx("div",{className:"flex justify-end px-4 pt-6",children:i.jsx(J,{type:"submit",disabled:n,children:e(n?"proxy.button.saving":"proxy.button.save")})})]})]})})})})}const BP=new ur,yQ=async(e,t)=>(await BP.getInstance().get(`/rabbitmq/find/${e}`,{headers:{apikey:t}})).data,bQ=async(e,t,n)=>(await BP.getInstance().post(`/rabbitmq/set/${e}`,n,{headers:{apikey:t}})).data,xQ=k.object({enabled:k.boolean(),events:k.array(k.string())});function wQ(){const{t:e}=Le(),{instance:t}=st(),[n,r]=m.useState(!1),s=kt({resolver:Et(xQ),defaultValues:{enabled:!1,events:[]}});m.useEffect(()=>{(async()=>{if(t){r(!0);try{const c=await yQ(t.name,t.token);s.reset(c)}catch(c){console.error("Error:",c)}finally{r(!1)}}})()},[t,s]);const o=async l=>{var c,u,d;if(t){r(!0);try{const f={enabled:l.enabled,events:l.events};await bQ(t.name,t.token,f),X.success(e("rabbitmq.toast.success"))}catch(f){console.error(e("rabbitmq.toast.error"),f),X.error(`Error: ${(d=(u=(c=f==null?void 0:f.response)==null?void 0:c.data)==null?void 0:u.response)==null?void 0:d.message}`)}finally{r(!1)}}},a=["APPLICATION_STARTUP","QRCODE_UPDATED","MESSAGES_SET","MESSAGES_UPSERT","MESSAGES_UPDATE","MESSAGES_DELETE","SEND_MESSAGE","CONTACTS_SET","CONTACTS_UPSERT","CONTACTS_UPDATE","PRESENCE_UPDATE","CHATS_SET","CHATS_UPSERT","CHATS_UPDATE","CHATS_DELETE","GROUPS_UPSERT","GROUP_UPDATE","GROUP_PARTICIPANTS_UPDATE","CONNECTION_UPDATE","REMOVE_INSTANCE","LOGOUT_INSTANCE","LABELS_EDIT","LABELS_ASSOCIATION","CALL","TYPEBOT_START","TYPEBOT_CHANGE_STATUS"];return i.jsx(i.Fragment,{children:i.jsx(fr,{...s,children:i.jsx("form",{onSubmit:s.handleSubmit(o),className:"w-full space-y-6",children:i.jsxs("div",{children:[i.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("rabbitmq.title")}),i.jsx(na,{className:"my-4"}),i.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[i.jsx(he,{name:"enabled",label:e("rabbitmq.form.enabled.label"),className:"w-full justify-between",helper:e("rabbitmq.form.enabled.description")}),i.jsx(aa,{control:s.control,name:"events",render:({field:l})=>i.jsxs(so,{className:"flex flex-col",children:[i.jsx(sr,{className:"my-2 text-lg",children:e("rabbitmq.form.events.label")}),i.jsx(Ss,{children:i.jsx("div",{className:"flex flex-col gap-2 space-y-1 divide-y",children:a.sort((c,u)=>c.localeCompare(u)).map(c=>i.jsxs("div",{className:"flex items-center justify-between gap-3 pt-3",children:[i.jsx(sr,{className:me("break-all",l.value.includes(c)?"text-foreground":"text-muted-foreground"),children:c}),i.jsx(Ol,{checked:l.value.includes(c),onCheckedChange:u=>{u?l.onChange([...l.value,c]):l.onChange(l.value.filter(d=>d!==c))}})]},c))})})]})})]}),i.jsx("div",{className:"mx-4 flex justify-end pt-6",children:i.jsx(J,{type:"submit",disabled:n,children:e(n?"rabbitmq.button.saving":"rabbitmq.button.save")})})]})})})})}const SQ=k.object({rejectCall:k.boolean(),msgCall:k.string().optional(),groupsIgnore:k.boolean(),alwaysOnline:k.boolean(),readMessages:k.boolean(),syncFullHistory:k.boolean(),readStatus:k.boolean()});function CQ(){const{t:e}=Le(),[t,n]=m.useState(!0),[r,s]=m.useState(!1),[o,a]=m.useState(""),{instance:l}=st(),c=kt({resolver:Et(SQ),defaultValues:{rejectCall:!1,msgCall:"",groupsIgnore:!1,alwaysOnline:!1,readMessages:!1,syncFullHistory:!1,readStatus:!1}});m.useEffect(()=>{(async()=>{try{if(l&&l.name&&l.token){a(l.token);const h=await _4(l.name,l.token);c.reset({rejectCall:h.rejectCall,msgCall:h.msgCall||"",groupsIgnore:h.groupsIgnore,alwaysOnline:h.alwaysOnline,readMessages:h.readMessages,syncFullHistory:h.syncFullHistory,readStatus:h.readStatus})}else console.error("token not found");n(!1)}catch(h){console.error("Error:",h),n(!1)}})()},[c,l]);const u=async p=>{try{if(!l||!l.name)throw new Error("instance not found");s(!0);const h={rejectCall:p.rejectCall,msgCall:p.msgCall,groupsIgnore:p.groupsIgnore,alwaysOnline:p.alwaysOnline,readMessages:p.readMessages,syncFullHistory:p.syncFullHistory,readStatus:p.readStatus};await R4(l.name,o,h),X.success(e("settings.toast.success"))}catch(h){console.error(e("settings.toast.success"),h),X.error(e("settings.toast.error"))}finally{s(!1)}},d=[{name:"groupsIgnore",label:e("settings.form.groupsIgnore.label"),description:e("settings.form.groupsIgnore.description")},{name:"alwaysOnline",label:e("settings.form.alwaysOnline.label"),description:e("settings.form.alwaysOnline.description")},{name:"readMessages",label:e("settings.form.readMessages.label"),description:e("settings.form.readMessages.description")},{name:"syncFullHistory",label:e("settings.form.syncFullHistory.label"),description:e("settings.form.syncFullHistory.description")},{name:"readStatus",label:e("settings.form.readStatus.label"),description:e("settings.form.readStatus.description")}],f=c.watch("rejectCall");return t?i.jsx(or,{}):i.jsx(i.Fragment,{children:i.jsx(fr,{...c,children:i.jsx("form",{onSubmit:c.handleSubmit(u),className:"w-full space-y-6",children:i.jsxs("div",{children:[i.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("settings.title")}),i.jsx(Ze,{className:"my-4"}),i.jsxs("div",{className:"mx-4 space-y-2 divide-y",children:[i.jsxs("div",{className:"flex flex-col p-4",children:[i.jsx(he,{name:"rejectCall",label:e("settings.form.rejectCall.label"),className:"w-full justify-between",helper:e("settings.form.rejectCall.description")}),f&&i.jsx("div",{className:"mr-16 mt-2",children:i.jsx(D,{name:"msgCall",children:i.jsx(zs,{placeholder:e("settings.form.msgCall.description")})})})]}),d.map(p=>i.jsx("div",{className:"flex p-4",children:i.jsx(he,{name:p.name,label:p.label,className:"w-full justify-between",helper:p.description})},p.name)),i.jsx("div",{className:"flex justify-end pt-6",children:i.jsx(J,{type:"submit",disabled:r,children:e(r?"settings.button.saving":"settings.button.save")})})]})]})})})})}const zP=new ur,kQ=async(e,t)=>(await zP.getInstance().get(`/sqs/find/${e}`,{headers:{apikey:t}})).data,EQ=async(e,t,n)=>(await zP.getInstance().post(`/sqs/set/${e}`,n,{headers:{apikey:t}})).data,TQ=k.object({enabled:k.boolean(),events:k.array(k.string())});function jQ(){const{t:e}=Le(),{instance:t}=st(),[n,r]=m.useState(!1),s=kt({resolver:Et(TQ),defaultValues:{enabled:!1,events:[]}});m.useEffect(()=>{(async()=>{if(t){r(!0);try{const c=await kQ(t.name,t.token);s.reset(c)}catch(c){console.error("Error",c)}finally{r(!1)}}})()},[t,s]);const o=async l=>{var c,u,d;if(t){r(!0);try{const f={enabled:l.enabled,events:l.events};await EQ(t.name,t.token,f),X.success(e("sqs.toast.success"))}catch(f){console.error(e("sqs.toast.error"),f),X.error(`Error: ${(d=(u=(c=f==null?void 0:f.response)==null?void 0:c.data)==null?void 0:u.response)==null?void 0:d.message}`)}finally{r(!1)}}},a=["APPLICATION_STARTUP","QRCODE_UPDATED","MESSAGES_SET","MESSAGES_UPSERT","MESSAGES_UPDATE","MESSAGES_DELETE","SEND_MESSAGE","CONTACTS_SET","CONTACTS_UPSERT","CONTACTS_UPDATE","PRESENCE_UPDATE","CHATS_SET","CHATS_UPSERT","CHATS_UPDATE","CHATS_DELETE","GROUPS_UPSERT","GROUP_UPDATE","GROUP_PARTICIPANTS_UPDATE","CONNECTION_UPDATE","REMOVE_INSTANCE","LOGOUT_INSTANCE","LABELS_EDIT","LABELS_ASSOCIATION","CALL","TYPEBOT_START","TYPEBOT_CHANGE_STATUS"];return i.jsx(i.Fragment,{children:i.jsx(fr,{...s,children:i.jsx("form",{onSubmit:s.handleSubmit(o),className:"w-full space-y-6",children:i.jsxs("div",{children:[i.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("sqs.title")}),i.jsx(na,{className:"my-4"}),i.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[i.jsx(he,{name:"enabled",label:e("sqs.form.enabled.label"),className:"w-full justify-between",helper:e("sqs.form.enabled.description")}),i.jsx(aa,{control:s.control,name:"events",render:({field:l})=>i.jsxs(so,{className:"flex flex-col",children:[i.jsx(sr,{className:"my-2 text-lg",children:e("sqs.form.events.label")}),i.jsx(Ss,{children:i.jsx("div",{className:"flex flex-col gap-2 space-y-1 divide-y",children:a.sort((c,u)=>c.localeCompare(u)).map(c=>i.jsxs("div",{className:"flex items-center justify-between gap-3 pt-3",children:[i.jsx(sr,{className:me("break-all",l.value.includes(c)?"text-foreground":"text-muted-foreground"),children:c}),i.jsx(Ol,{checked:l.value.includes(c),onCheckedChange:u=>{u?l.onChange([...l.value,c]):l.onChange(l.value.filter(d=>d!==c))}})]},c))})})]})})]}),i.jsx("div",{className:"mx-4 flex justify-end pt-6",children:i.jsx(J,{type:"submit",disabled:n,children:e(n?"sqs.button.saving":"sqs.button.save")})})]})})})})}const ao=new ur,UP=async(e,t)=>(await ao.getInstance().get(`/typebot/find/${e}`,{headers:{apikey:t}})).data,_Q=async(e,t,n)=>(await ao.getInstance().get(`/typebot/fetch/${n}/${e}`,{headers:{apikey:t}})).data,RQ=async(e,t,n)=>(await ao.getInstance().post(`/typebot/create/${e}`,n,{headers:{apikey:t}})).data,IQ=async(e,t,n,r)=>(await ao.getInstance().put(`/typebot/update/${n}/${e}`,r,{headers:{apikey:t}})).data,NQ=async(e,t,n)=>(await ao.getInstance().delete(`/typebot/delete/${n}/${e}`,{headers:{apikey:t}})).data,PQ=async(e,t)=>(await ao.getInstance().get(`/typebot/fetchSettings/${e}`,{headers:{apikey:t}})).data,OQ=async(e,t,n)=>(await ao.getInstance().post(`/typebot/settings/${e}`,n,{headers:{apikey:t}})).data,MQ=async(e,t,n)=>(await ao.getInstance().get(`/typebot/fetchSessions/${n}/${e}`,{headers:{apikey:t}})).data,DQ=async(e,t,n,r)=>(await ao.getInstance().post(`/typebot/changeStatus/${e}`,{remoteJid:n,status:r},{headers:{apikey:t}})).data,AQ=k.object({expire:k.coerce.number(),keywordFinish:k.string(),delayMessage:k.coerce.number(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.coerce.number(),ignoreJids:k.array(k.string()).default([]),typebotIdFallback:k.union([k.null(),k.string()]).optional()}),O1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await PQ(e.name,r);t(s);const o=await UP(e.name,r);n(o)}else console.error("token not found.")}catch(r){console.error("Error:",r)}};function FQ(){const{t:e}=Le(),{instance:t}=st(),[n,r]=m.useState(),[s,o]=m.useState([]),[a,l]=m.useState(!1),c=kt({resolver:Et(AQ),defaultValues:{expire:0,keywordFinish:e("typebot.form.examples.keywordFinish"),delayMessage:1e3,unknownMessage:e("typebot.form.examples.unknownMessage"),listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:0,ignoreJids:[],typebotIdFallback:void 0}});m.useEffect(()=>{a&&O1(t,r,o)},[t,a]),m.useEffect(()=>{n&&c.reset({expire:(n==null?void 0:n.expire)??0,keywordFinish:n.keywordFinish,delayMessage:n.delayMessage??0,unknownMessage:n.unknownMessage,listeningFromMe:n.listeningFromMe,stopBotFromMe:n.stopBotFromMe,keepOpen:n.keepOpen,debounceTime:n.debounceTime??0,ignoreJids:n.ignoreJids,typebotIdFallback:n.typebotIdFallback})},[n]);const u=async f=>{var p,h,v;try{if(!t||!t.name)throw new Error("instance not found.");const g={expire:f.expire,keywordFinish:f.keywordFinish,delayMessage:f.delayMessage,unknownMessage:f.unknownMessage,listeningFromMe:f.listeningFromMe,stopBotFromMe:f.stopBotFromMe,keepOpen:f.keepOpen,debounceTime:f.debounceTime,typebotIdFallback:f.typebotIdFallback||void 0,ignoreJids:f.ignoreJids};await OQ(t.name,t.token,g),X.success(e("typebot.toast.defaultSettings.success"))}catch(g){console.error(e("typebot.toast.defaultSettings.error"),g),X.error(`Error: ${(v=(h=(p=g==null?void 0:g.response)==null?void 0:p.data)==null?void 0:h.response)==null?void 0:v.message}`)}};function d(){O1(t,r,o)}return i.jsxs(yt,{open:a,onOpenChange:l,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{variant:"secondary",size:"sm",children:[i.jsx(Za,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:e("typebot.button.defaultSettings")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:d,children:[i.jsx(gt,{children:i.jsx(At,{children:e("typebot.modal.defaultSettings.title")})}),i.jsx(dr,{...c,children:i.jsxs("form",{className:"w-full space-y-6",onSubmit:c.handleSubmit(u),children:[i.jsx("div",{children:i.jsxs("div",{className:"space-y-4",children:[i.jsx(et,{name:"typebotIdFallback",label:e("typebot.form.typebotIdFallback.label"),options:(s==null?void 0:s.filter(f=>!!f.id).map(f=>({label:f.typebot,value:f.description})))??[]}),i.jsx(D,{name:"expire",label:e("typebot.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:e("typebot.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:e("typebot.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:e("typebot.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:e("typebot.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:e("typebot.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:e("typebot.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:e("typebot.form.debounceTime.label"),children:i.jsx(A,{type:"number"})}),i.jsx(Ml,{name:"ignoreJids",label:e("typebot.form.ignoreJids.label"),placeholder:e("typebot.form.ignoreJids.placeholder")})]})}),i.jsx(Jt,{children:i.jsx(J,{type:"submit",children:e("typebot.button.save")})})]})})]})]})}const LQ=k.object({enabled:k.boolean(),description:k.string(),url:k.string().url(),typebot:k.string(),triggerType:k.string(),triggerOperator:k.string().optional(),triggerValue:k.string().optional(),expire:k.string(),keywordFinish:k.string(),delayMessage:k.string(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.string(),ignoreJids:k.array(k.string()).default([])});function $Q({resetTable:e}){const{t}=Le(),{instance:n}=st(),[r,s]=m.useState(!1),[o,a]=m.useState(!1),l=kt({resolver:Et(LQ),defaultValues:{enabled:!0,description:"",url:"",typebot:"",triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:"0",keywordFinish:"",delayMessage:"0",unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:"0",ignoreJids:[]}}),c=async f=>{var p,h,v;try{if(!n||!n.name)throw new Error("Nome da instância não encontrado.");s(!0);const g={enabled:f.enabled,description:f.description,url:f.url,typebot:f.typebot,triggerType:f.triggerType,triggerOperator:f.triggerOperator||"",triggerValue:f.triggerValue||"",expire:parseInt(f.expire,10),keywordFinish:f.keywordFinish,delayMessage:parseInt(f.delayMessage,10),unknownMessage:f.unknownMessage,listeningFromMe:f.listeningFromMe,stopBotFromMe:f.stopBotFromMe,keepOpen:f.keepOpen,debounceTime:parseInt(f.debounceTime,10)};await RQ(n.name,n.token,g),X.success(t("typebot.toast.success.create")),a(!1),u(),e()}catch(g){console.error(t("typebot.toast.error"),g),X.error(`Error: ${(v=(h=(p=g==null?void 0:g.response)==null?void 0:p.data)==null?void 0:h.response)==null?void 0:v.message}`)}finally{s(!1)}};function u(){l.reset()}const d=l.watch("triggerType");return i.jsxs(yt,{open:o,onOpenChange:a,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{variant:"default",className:"mr-5 text-white",children:[i.jsx(Qa,{}),i.jsx("span",{className:"hidden sm:inline",children:t("typebot.button.create")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:u,children:[i.jsx(gt,{children:i.jsx(At,{children:t("typebot.form.title")})}),i.jsx(dr,{...l,children:i.jsxs("form",{onSubmit:l.handleSubmit(c),className:"w-full space-y-6",children:[i.jsx("div",{children:i.jsxs("div",{className:"space-y-4",children:[i.jsx(he,{name:"enabled",label:t("typebot.form.enabled.label"),reverse:!0}),i.jsx(D,{name:"description",label:t("typebot.form.description.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("typebot.form.typebotSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"url",label:t("typebot.form.url.label"),required:!0,children:i.jsx(A,{})}),i.jsx(D,{name:"typebot",label:t("typebot.form.typebot.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("typebot.form.triggerSettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"triggerType",label:t("typebot.form.triggerType.label"),required:!0,options:[{label:t("typebot.form.triggerType.keyword"),value:"keyword"},{label:t("typebot.form.triggerType.all"),value:"all"},{label:t("typebot.form.triggerType.advanced"),value:"advanced"},{label:t("typebot.form.triggerType.none"),value:"none"}]}),d==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(et,{name:"triggerOperator",label:t("typebot.form.triggerOperator.label"),required:!0,options:[{label:t("typebot.form.triggerOperator.contains"),value:"contains"},{label:t("typebot.form.triggerOperator.equals"),value:"equals"},{label:t("typebot.form.triggerOperator.startsWith"),value:"startsWith"},{label:t("typebot.form.triggerOperator.endsWith"),value:"endsWith"},{label:t("typebot.form.triggerOperator.regex"),value:"regex"}]}),i.jsx(D,{name:"triggerValue",label:t("typebot.form.triggerValue.label"),required:!0,children:i.jsx(A,{})})]}),d==="advanced"&&i.jsx(D,{name:"triggerValue",label:t("typebot.form.triggerConditions.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("typebot.form.generalSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"expire",label:t("typebot.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:t("typebot.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:t("typebot.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:t("typebot.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:t("typebot.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:t("typebot.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:t("typebot.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:t("typebot.form.debounceTime.label"),children:i.jsx(A,{type:"number"})})]})}),i.jsx(Jt,{children:i.jsx(J,{disabled:r,type:"submit",children:t("typebot.button.save")})})]})})]})]})}const M1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await MQ(e.name,r,n);t(s)}else console.error("Token ou nome da instância não encontrados.")}catch(r){console.error("Erro ao carregar sessões:",r)}};function VP({typebotId:e}){var h,v;const{t}=Le(),{instance:n}=st(),[r,s]=m.useState([]),[o,a]=m.useState([]),[l,c]=m.useState(!1);m.useEffect(()=>{l&&M1(n,a,e)},[n,e,l]);function u(){M1(n,a,e)}const d=async(g,b)=>{var y,x,w;try{if(!n)return;await DQ(n.name,n.token,g,b),X.success(t("typebot.toast.success.status")),u()}catch(S){console.error("Error:",S),X.error(`Error : ${(w=(x=(y=S==null?void 0:S.response)==null?void 0:y.data)==null?void 0:x.response)==null?void 0:w.message}`)}},f=[{accessorKey:"remoteJid",header:()=>i.jsx("div",{className:"text-center",children:t("typebot.sessions.table.remoteJid")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>i.jsx("div",{className:"text-center",children:t("typebot.sessions.table.pushName")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("pushName")})},{accessorKey:"sessionId",header:()=>i.jsx("div",{className:"text-center",children:t("typebot.sessions.table.sessionId")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("sessionId")})},{accessorKey:"status",header:()=>i.jsx("div",{className:"text-center",children:t("typebot.sessions.table.status")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:g})=>{const b=g.original;return i.jsxs(to,{children:[i.jsx(no,{asChild:!0,children:i.jsxs(J,{variant:"ghost",className:"h-8 w-8 p-0",children:[i.jsx("span",{className:"sr-only",children:t("typebot.sessions.table.actions.title")}),i.jsx(Sl,{className:"h-4 w-4"})]})}),i.jsxs(Qr,{align:"end",children:[i.jsx(ei,{children:"Actions"}),i.jsx(ra,{}),b.status!=="opened"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"opened"),children:[i.jsx(Ku,{className:"mr-2 h-4 w-4"}),t("typebot.sessions.table.actions.open")]}),b.status!=="paused"&&b.status!=="closed"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"paused"),children:[i.jsx(qu,{className:"mr-2 h-4 w-4"}),t("typebot.sessions.table.actions.pause")]}),b.status!=="closed"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"closed"),children:[i.jsx(Hu,{className:"mr-2 h-4 w-4"}),t("typebot.sessions.table.actions.close")]}),i.jsxs(at,{onClick:()=>d(b.remoteJid,"delete"),children:[i.jsx(Wu,{className:"mr-2 h-4 w-4"}),t("typebot.sessions.table.actions.delete")]})]})]})}}],p=Ul({data:o,columns:f,onSortingChange:s,getCoreRowModel:Ll(),getPaginationRowModel:Bl(),getSortedRowModel:zl(),getFilteredRowModel:$l(),state:{sorting:r}});return i.jsxs(yt,{open:l,onOpenChange:c,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{variant:"secondary",size:"sm",children:[i.jsx(Gu,{size:16,className:"mr-1"})," ",i.jsx("span",{className:"hidden sm:inline",children:t("typebot.sessions.label")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:u,children:[i.jsx(gt,{children:i.jsx(At,{children:t("typebot.sessions.label")})}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[i.jsx(A,{placeholder:t("typebot.sessions.search"),value:((h=p.getColumn("remoteJid"))==null?void 0:h.getFilterValue())??"",onChange:g=>{var b;return(b=p.getColumn("remoteJid"))==null?void 0:b.setFilterValue(g.target.value)}}),i.jsx(J,{variant:"outline",onClick:u,size:"icon",children:i.jsx(Ju,{size:16})})]}),i.jsxs(ri,{children:[i.jsx(si,{children:p.getHeaderGroups().map(g=>i.jsx(en,{children:g.headers.map(b=>i.jsx(ai,{children:b.isPlaceholder?null:Rr(b.column.columnDef.header,b.getContext())},b.id))},g.id))}),i.jsx(oi,{children:(v=p.getRowModel().rows)!=null&&v.length?p.getRowModel().rows.map(g=>i.jsx(en,{"data-state":g.getIsSelected()&&"selected",children:g.getVisibleCells().map(b=>i.jsx(ir,{children:Rr(b.column.columnDef.cell,b.getContext())},b.id))},g.id)):i.jsx(en,{children:i.jsx(ir,{colSpan:f.length,className:"h-24 text-center",children:t("typebot.sessions.table.none")})})})]})]})]})]})}const BQ=k.object({enabled:k.boolean(),description:k.string(),url:k.string().url(),typebot:k.string(),triggerType:k.string(),triggerOperator:k.string().optional(),triggerValue:k.string().optional(),expire:k.coerce.number(),keywordFinish:k.string(),delayMessage:k.coerce.number(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.coerce.number(),ignoreJids:k.array(k.string()).default([])});function zQ({typebotId:e,instance:t,resetTable:n}){const{t:r}=Le(),[,s]=m.useState(""),[o,a]=m.useState(!0),[l,c]=m.useState(!1),u=En(),d=kt({resolver:Et(BQ),defaultValues:{enabled:!0,description:"",url:"",typebot:"",triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:0,keywordFinish:"",delayMessage:0,unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:0,ignoreJids:[]}});m.useEffect(()=>{(async()=>{try{const b=localStorage.getItem("token");if(b&&t&&t.name&&e){s(b);const y=await _Q(t.name,b,e);d.reset({enabled:y.enabled,description:y.description,url:y.url,typebot:y.typebot,triggerType:y.triggerType,triggerOperator:y.triggerOperator,triggerValue:y.triggerValue,expire:y.expire,keywordFinish:y.keywordFinish,delayMessage:y.delayMessage,unknownMessage:y.unknownMessage,listeningFromMe:y.listeningFromMe,stopBotFromMe:y.stopBotFromMe,keepOpen:y.keepOpen,debounceTime:y.debounceTime})}else console.error("Token not found");a(!1)}catch(b){console.error("Error:",b),a(!1)}})()},[d,t,e]);const f=async g=>{var b,y,x;try{const w=localStorage.getItem("token");if(w&&t&&t.name&&e){const S={enabled:g.enabled,description:g.description,url:g.url,typebot:g.typebot,triggerType:g.triggerType,triggerOperator:g.triggerOperator||"",triggerValue:g.triggerValue||"",expire:g.expire,keywordFinish:g.keywordFinish,delayMessage:g.delayMessage,unknownMessage:g.unknownMessage,listeningFromMe:g.listeningFromMe,stopBotFromMe:g.stopBotFromMe,keepOpen:g.keepOpen,debounceTime:g.debounceTime};await IQ(t.name,w,e,S),X.success(r("typebot.toast.success.update"))}else console.error("Token not found")}catch(w){console.error("Error:",w),X.error(`Error: ${(x=(y=(b=w==null?void 0:w.response)==null?void 0:b.data)==null?void 0:y.response)==null?void 0:x.message}`)}},p=async()=>{try{const g=localStorage.getItem("token");g&&t&&t.name&&e?(await NQ(t.name,g,e),X.success(r("typebot.toast.success.delete")),c(!1),n(),u(`/manager/instance/${t.id}/typebot`)):console.error("Token not found")}catch(g){console.error("Error:",g)}},h=d.watch("description"),v=d.watch("triggerType");return i.jsxs(i.Fragment,{children:[o&&i.jsx(or,{}),!o&&i.jsx(fr,{...d,children:i.jsxs("form",{onSubmit:d.handleSubmit(f),className:"w-full space-y-6 pl-4 pr-2",children:[i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[i.jsxs("h3",{className:"mb-4 text-lg font-medium",children:["Typebot: ",h]}),i.jsx(he,{name:"enabled",className:"flex items-center gap-3"})]}),i.jsxs("div",{className:"space-y-4",children:[i.jsx(D,{name:"description",label:r("typebot.form.description.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("typebot.form.typebotSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"url",label:r("typebot.form.url.label"),required:!0,children:i.jsx(A,{})}),i.jsx(D,{name:"typebot",label:r("typebot.form.typebot.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("typebot.form.triggerSettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"triggerType",label:r("typebot.form.triggerType.label"),required:!0,options:[{label:r("typebot.form.triggerType.keyword"),value:"keyword"},{label:r("typebot.form.triggerType.all"),value:"all"},{label:r("typebot.form.triggerType.advanced"),value:"advanced"},{label:r("typebot.form.triggerType.none"),value:"none"}]}),v==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(et,{name:"triggerOperator",label:r("typebot.form.triggerOperator.label"),required:!0,options:[{label:r("typebot.form.triggerOperator.contains"),value:"contains"},{label:r("typebot.form.triggerOperator.equals"),value:"equals"},{label:r("typebot.form.triggerOperator.startsWith"),value:"startsWith"},{label:r("typebot.form.triggerOperator.endsWith"),value:"endsWith"},{label:r("typebot.form.triggerOperator.regex"),value:"regex"}]}),i.jsx(D,{name:"triggerValue",label:r("typebot.form.triggerValue.label"),required:!0,children:i.jsx(A,{})})]}),v==="advanced"&&i.jsx(D,{name:"triggerValue",label:r("typebot.form.triggerConditions.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("typebot.form.generalSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"expire",label:r("typebot.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:r("typebot.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:r("typebot.form.delay.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:r("typebot.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:r("typebot.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:r("typebot.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:r("typebot.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:r("typebot.form.debounceTime.label"),children:i.jsx(A,{type:"number"})})]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx(VP,{typebotId:e}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs(yt,{open:l,onOpenChange:c,children:[i.jsx(Rt,{asChild:!0,children:i.jsx(J,{variant:"destructive",size:"sm",children:r("typebot.button.delete")})}),i.jsx(pt,{children:i.jsxs(gt,{children:[i.jsx(At,{children:r("modal.delete.title")}),i.jsx(ti,{children:r("modal.delete.messageSingle")}),i.jsxs(Jt,{children:[i.jsx(J,{size:"sm",variant:"outline",onClick:()=>c(!1),children:r("button.cancel")}),i.jsx(J,{variant:"destructive",onClick:p,children:r("button.delete")})]})]})})]}),i.jsx(J,{type:"submit",children:r("typebot.button.update")})]})]})]})})]})}const D1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await UP(e.name,r);t(s)}else console.error("token not found.");n(!1)}catch(r){console.error("Error",r),n(!1)}};function A1(){const{t:e}=Le(),t=Fl("(min-width: 768px)"),{instance:n}=st(),{typebotId:r}=Ys(),[s,o]=m.useState(!0),[a,l]=m.useState([]),c=En();m.useEffect(()=>{n&&D1(n,l,o)},[n]);const u=f=>{n&&c(`/manager/instance/${n.id}/typebot/${f}`)},d=()=>{D1(n,l,o)};return i.jsxs("main",{className:"pt-5",children:[i.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[i.jsx("h3",{className:"text-lg font-medium",children:e("typebot.title")}),i.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[i.jsx(VP,{}),i.jsx(FQ,{}),i.jsx($Q,{resetTable:d})]})]}),i.jsx(Ze,{className:"my-4"}),i.jsxs(Dl,{direction:t?"horizontal":"vertical",children:[i.jsx(_r,{defaultSize:35,className:"pr-4",children:i.jsx("div",{className:"flex flex-col gap-3",children:s?i.jsx(or,{}):i.jsx(i.Fragment,{children:a&&a.length>0&&Array.isArray(a)?a.map(f=>i.jsx(J,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>u(`${f.id}`),variant:r===f.id?"secondary":"outline",children:f.description?i.jsxs(i.Fragment,{children:[i.jsx("h4",{className:"text-base",children:f.description}),i.jsxs("p",{className:"text-wrap text-sm font-normal text-muted-foreground",children:[f.url," - ",f.typebot]})]}):i.jsxs(i.Fragment,{children:[i.jsx("h4",{className:"text-base",children:f.url}),i.jsx("p",{className:"text-wrap text-sm font-normal text-muted-foreground",children:f.typebot})]})},f.id)):i.jsx(J,{variant:"link",children:e("typebot.table.none")})})})}),r&&i.jsxs(i.Fragment,{children:[i.jsx(Al,{withHandle:!0,className:"border border-black"}),i.jsx(_r,{className:"",children:i.jsx(zQ,{typebotId:r,instance:n,resetTable:d})})]})]})]})}const HP=new ur,UQ=async(e,t)=>(await HP.getInstance().get(`/webhook/find/${e}`,{headers:{apikey:t}})).data,VQ=async(e,t,n)=>(await HP.getInstance().post(`/webhook/set/${e}`,n,{headers:{apikey:t}})).data,HQ=k.object({enabled:k.boolean(),url:k.string().url("Invalid URL format"),events:k.array(k.string()),webhookBase64:k.boolean(),webhookByEvents:k.boolean()});function WQ(){const{t:e}=Le(),{instance:t}=st(),[n,r]=m.useState(!1),s=kt({resolver:Et(HQ),defaultValues:{enabled:!1,url:"",events:[],webhookBase64:!1,webhookByEvents:!1}});m.useEffect(()=>{(async()=>{if(t){r(!0);try{const c=await UQ(t.name,t.token);s.reset(c)}catch(c){console.error("Error:",c)}finally{r(!1)}}})()},[t,s]);const o=async l=>{var c,u,d;if(t){r(!0);try{const f={enabled:l.enabled,url:l.url,events:l.events,webhookBase64:l.webhookBase64,webhookByEvents:l.webhookByEvents};await VQ(t.name,t.token,f),X.success(e("webhook.toast.success"))}catch(f){console.error(e("webhook.toast.error"),f),X.error(`Error: ${(d=(u=(c=f==null?void 0:f.response)==null?void 0:c.data)==null?void 0:u.response)==null?void 0:d.message}`)}finally{r(!1)}}},a=["APPLICATION_STARTUP","QRCODE_UPDATED","MESSAGES_SET","MESSAGES_UPSERT","MESSAGES_UPDATE","MESSAGES_DELETE","SEND_MESSAGE","CONTACTS_SET","CONTACTS_UPSERT","CONTACTS_UPDATE","PRESENCE_UPDATE","CHATS_SET","CHATS_UPSERT","CHATS_UPDATE","CHATS_DELETE","GROUPS_UPSERT","GROUP_UPDATE","GROUP_PARTICIPANTS_UPDATE","CONNECTION_UPDATE","REMOVE_INSTANCE","LOGOUT_INSTANCE","LABELS_EDIT","LABELS_ASSOCIATION","CALL","TYPEBOT_START","TYPEBOT_CHANGE_STATUS"];return i.jsx(i.Fragment,{children:i.jsx(fr,{...s,children:i.jsx("form",{onSubmit:s.handleSubmit(o),className:"w-full space-y-6",children:i.jsxs("div",{children:[i.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("webhook.title")}),i.jsx(na,{className:"my-4"}),i.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[i.jsx(he,{name:"enabled",label:e("webhook.form.enabled.label"),className:"w-full justify-between",helper:e("webhook.form.enabled.description")}),i.jsx(D,{name:"url",label:"URL",children:i.jsx(A,{})}),i.jsx(he,{name:"webhookByEvents",label:e("webhook.form.webhookByEvents.label"),className:"w-full justify-between",helper:e("webhook.form.webhookByEvents.description")}),i.jsx(he,{name:"webhookBase64",label:e("webhook.form.webhookBase64.label"),className:"w-full justify-between",helper:e("webhook.form.webhookBase64.description")}),i.jsx(aa,{control:s.control,name:"events",render:({field:l})=>i.jsxs(so,{className:"flex flex-col",children:[i.jsx(sr,{className:"my-2 text-lg",children:e("webhook.form.events.label")}),i.jsx(Ss,{children:i.jsx("div",{className:"flex flex-col gap-2 space-y-1 divide-y",children:a.sort((c,u)=>c.localeCompare(u)).map(c=>i.jsxs("div",{className:"flex items-center justify-between gap-3 pt-3",children:[i.jsx(sr,{className:me("break-all",l.value.includes(c)?"text-foreground":"text-muted-foreground"),children:c}),i.jsx(Ol,{checked:l.value.includes(c),onCheckedChange:u=>{u?l.onChange([...l.value,c]):l.onChange(l.value.filter(d=>d!==c))}})]},c))})})]})})]}),i.jsx("div",{className:"mx-4 flex justify-end pt-6",children:i.jsx(J,{type:"submit",disabled:n,children:e(n?"webhook.button.saving":"webhook.button.save")})})]})})})})}const WP=new ur,GQ=async(e,t)=>(await WP.getInstance().get(`/websocket/find/${e}`,{headers:{apikey:t}})).data,qQ=async(e,t,n)=>(await WP.getInstance().post(`/websocket/set/${e}`,n,{headers:{apikey:t}})).data,KQ=k.object({enabled:k.boolean(),events:k.array(k.string())});function JQ(){const{t:e}=Le(),{instance:t}=st(),[n,r]=m.useState(!1),s=kt({resolver:Et(KQ),defaultValues:{enabled:!1,events:[]}});m.useEffect(()=>{(async()=>{if(t){r(!0);try{const c=await GQ(t.name,t.token);s.reset(c)}catch(c){console.error("Erro ao buscar dados do websocket:",c)}finally{r(!1)}}})()},[t,s]);const o=async l=>{var c,u,d;if(t){r(!0);try{const f={enabled:l.enabled,events:l.events};await qQ(t.name,t.token,f),X.success(e("websocket.toast.success"))}catch(f){console.error(e("websocket.toast.error"),f),X.error(`Error: ${(d=(u=(c=f==null?void 0:f.response)==null?void 0:c.data)==null?void 0:u.response)==null?void 0:d.message}`)}finally{r(!1)}}},a=["APPLICATION_STARTUP","QRCODE_UPDATED","MESSAGES_SET","MESSAGES_UPSERT","MESSAGES_UPDATE","MESSAGES_DELETE","SEND_MESSAGE","CONTACTS_SET","CONTACTS_UPSERT","CONTACTS_UPDATE","PRESENCE_UPDATE","CHATS_SET","CHATS_UPSERT","CHATS_UPDATE","CHATS_DELETE","GROUPS_UPSERT","GROUP_UPDATE","GROUP_PARTICIPANTS_UPDATE","CONNECTION_UPDATE","REMOVE_INSTANCE","LOGOUT_INSTANCE","LABELS_EDIT","LABELS_ASSOCIATION","CALL","TYPEBOT_START","TYPEBOT_CHANGE_STATUS"];return i.jsx(i.Fragment,{children:i.jsx(fr,{...s,children:i.jsx("form",{onSubmit:s.handleSubmit(o),className:"w-full space-y-6",children:i.jsxs("div",{children:[i.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("websocket.title")}),i.jsx(na,{className:"my-4"}),i.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[i.jsx(he,{name:"enabled",label:e("websocket.form.enabled.label"),className:"w-full justify-between",helper:e("websocket.form.enabled.description")}),i.jsx(aa,{control:s.control,name:"events",render:({field:l})=>i.jsxs(so,{className:"flex flex-col",children:[i.jsx(sr,{className:"my-2 text-lg",children:e("websocket.form.events.label")}),i.jsx(Ss,{children:i.jsx("div",{className:"flex flex-col gap-2 space-y-1 divide-y",children:a.sort((c,u)=>c.localeCompare(u)).map(c=>i.jsxs("div",{className:"flex items-center justify-between gap-3 pt-3",children:[i.jsx(sr,{className:me("break-all",l.value.includes(c)?"text-foreground":"text-muted-foreground"),children:c}),i.jsx(Ol,{checked:l.value.includes(c),onCheckedChange:u=>{u?l.onChange([...l.value,c]):l.onChange(l.value.filter(d=>d!==c))}})]},c))})})]})})]}),i.jsx("div",{className:"mx-4 flex justify-end pt-6",children:i.jsx(J,{type:"submit",disabled:n,children:e(n?"websocket.button.saving":"websocket.button.save")})})]})})})})}const ZQ=k.object({serverUrl:k.string({required_error:"serverUrl is required"}).url("URL inválida"),apiKey:k.string({required_error:"ApiKey is required"})});function QQ(){const{t:e}=Le(),t=En(),n=kt({resolver:Et(ZQ),defaultValues:{serverUrl:window.location.protocol+"//"+window.location.host,apiKey:""}}),r=async s=>{const o=await pT(s.serverUrl);if(!o||!o.version){gT(),n.setError("serverUrl",{type:"manual",message:e("login.message.invalidServer")});return}if(!await dL(s.serverUrl,s.apiKey)){n.setError("apiKey",{type:"manual",message:e("login.message.invalidCredentials")});return}if(!await uL(s.serverUrl,s.apiKey)){X.error(e("login.message.invalidCredentials"));return}localStorage.setItem("version",o.version),localStorage.setItem("clientName",o.clientName),t("/manager/")};return i.jsxs("div",{className:"flex min-h-screen flex-col",children:[i.jsx("div",{className:"flex items-center justify-center pt-2",children:i.jsx("img",{className:"h-10",src:"/assets/images/evolution-logo.png",alt:"logo"})}),i.jsx("div",{className:"flex flex-1 items-center justify-center p-8",children:i.jsxs(wa,{className:"b-none w-[350px] shadow-none",children:[i.jsxs(Sa,{children:[i.jsx(Dc,{className:"text-center",children:e("login.title")}),i.jsx(lR,{className:"text-center",children:e("login.description")})]}),i.jsx(fr,{...n,children:i.jsxs("form",{onSubmit:n.handleSubmit(r),children:[i.jsx(Ca,{children:i.jsxs("div",{className:"grid w-full items-center gap-4",children:[i.jsx(D,{required:!0,name:"serverUrl",label:e("login.form.serverUrl"),children:i.jsx(A,{})}),i.jsx(D,{required:!0,name:"apiKey",label:e("login.form.apiKey"),children:i.jsx(A,{type:"password"})})]})}),i.jsx(wg,{className:"flex justify-center",children:i.jsx(J,{className:"w-full",type:"submit",children:e("login.button.login")})})]})})]})}),i.jsx(fb,{})]})}const io=new ur,GP=async(e,t)=>(await io.getInstance().get(`/generic/find/${e}`,{headers:{apikey:t}})).data,YQ=async(e,t,n)=>(await io.getInstance().get(`/generic/fetch/${n}/${e}`,{headers:{apikey:t}})).data,XQ=async(e,t,n)=>(await io.getInstance().post(`/generic/create/${e}`,n,{headers:{apikey:t}})).data,eY=async(e,t,n,r)=>(await io.getInstance().put(`/generic/update/${n}/${e}`,r,{headers:{apikey:t}})).data,tY=async(e,t,n)=>(await io.getInstance().delete(`/generic/delete/${n}/${e}`,{headers:{apikey:t}})).data,nY=async(e,t)=>(await io.getInstance().get(`/generic/fetchSettings/${e}`,{headers:{apikey:t}})).data,rY=async(e,t,n)=>(await io.getInstance().post(`/generic/settings/${e}`,n,{headers:{apikey:t}})).data,sY=async(e,t,n)=>(await io.getInstance().get(`/generic/fetchSessions/${n}/${e}`,{headers:{apikey:t}})).data,oY=async(e,t,n,r)=>(await io.getInstance().post(`/generic/changeStatus/${e}`,{remoteJid:n,status:r},{headers:{apikey:t}})).data,aY=k.object({expire:k.string(),keywordFinish:k.string(),delayMessage:k.string(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.string(),ignoreJids:k.array(k.string()).default([]),botIdFallback:k.union([k.null(),k.string()]).optional()}),F1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await nY(e.name,r);t(s);const o=await GP(e.name,r);n(o)}else console.error("Token not found.")}catch(r){console.error("Error:",r)}};function iY(){const{t:e}=Le(),{instance:t}=st(),[n,r]=m.useState(!1),[s,o]=m.useState(),[a,l]=m.useState([]),c=kt({resolver:Et(aY),defaultValues:{expire:"0",keywordFinish:e("genericBot.form.examples.keywordFinish"),delayMessage:"1000",unknownMessage:e("genericBot.form.examples.unknownMessage"),listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:"0",ignoreJids:[],botIdFallback:void 0}});m.useEffect(()=>{n&&F1(t,o,l)},[t,n]),m.useEffect(()=>{s&&c.reset({expire:s!=null&&s.expire?s.expire.toString():"0",keywordFinish:s.keywordFinish,delayMessage:s.delayMessage?s.delayMessage.toString():"0",unknownMessage:s.unknownMessage,listeningFromMe:s.listeningFromMe,stopBotFromMe:s.stopBotFromMe,keepOpen:s.keepOpen,debounceTime:s.debounceTime?s.debounceTime.toString():"0",ignoreJids:s.ignoreJids,botIdFallback:s.botIdFallback})},[s]);const u=async f=>{var p,h,v;try{if(!t||!t.name)throw new Error("instance not found.");const g={expire:parseInt(f.expire),keywordFinish:f.keywordFinish,delayMessage:parseInt(f.delayMessage),unknownMessage:f.unknownMessage,listeningFromMe:f.listeningFromMe,stopBotFromMe:f.stopBotFromMe,keepOpen:f.keepOpen,debounceTime:parseInt(f.debounceTime),botIdFallback:f.botIdFallback||void 0,ignoreJids:f.ignoreJids};await rY(t.name,t.token,g),X.success(e("genericBot.toast.defaultSettings.success"))}catch(g){console.error("Error:",g),X.error(`Error: ${(v=(h=(p=g==null?void 0:g.response)==null?void 0:p.data)==null?void 0:h.response)==null?void 0:v.message}`)}};function d(){F1(t,o,l)}return i.jsxs(yt,{open:n,onOpenChange:r,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{variant:"secondary",size:"sm",children:[i.jsx(Za,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:e("genericBot.defaultSettings")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:d,children:[i.jsx(gt,{children:i.jsx(At,{children:e("genericBot.defaultSettings")})}),i.jsx(dr,{...c,children:i.jsxs("form",{className:"w-full space-y-6",onSubmit:c.handleSubmit(u),children:[i.jsx("div",{children:i.jsxs("div",{className:"space-y-4",children:[i.jsx(et,{name:"botIdFallback",label:e("genericBot.form.botIdFallback.label"),options:(a==null?void 0:a.filter(f=>!!f.id).map(f=>({label:f.description,value:f.id})))??[]}),i.jsx(D,{name:"expire",label:e("genericBot.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:e("genericBot.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:e("genericBot.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:e("genericBot.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:e("genericBot.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:e("genericBot.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:e("genericBot.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:e("genericBot.form.debounceTime.label"),children:i.jsx(A,{type:"number"})}),i.jsx(Ml,{name:"ignoreJids",label:e("genericBot.form.ignoreJids.label"),placeholder:e("genericBot.form.ignoreJids.placeholder")})]})}),i.jsx(Jt,{children:i.jsx(J,{type:"submit",children:e("genericBot.button.save")})})]})})]})]})}const lY=k.object({enabled:k.boolean(),description:k.string(),apiUrl:k.string(),apiKey:k.string(),triggerType:k.string(),triggerOperator:k.string().optional(),triggerValue:k.string().optional(),expire:k.string(),keywordFinish:k.string(),delayMessage:k.string(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.string()});function cY({resetTable:e}){const{t}=Le(),{instance:n}=st(),[r,s]=m.useState(!1),[o,a]=m.useState(!1),l=kt({resolver:Et(lY),defaultValues:{enabled:!0,description:"",apiUrl:"",apiKey:"",triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:"0",keywordFinish:"",delayMessage:"0",unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:"0"}}),c=async f=>{var p,h,v;try{if(!n||!n.name)throw new Error("instance not found");s(!0);const g={enabled:f.enabled,description:f.description,apiUrl:f.apiUrl,apiKey:f.apiKey,triggerType:f.triggerType,triggerOperator:f.triggerOperator||"",triggerValue:f.triggerValue||"",expire:parseInt(f.expire,10),keywordFinish:f.keywordFinish,delayMessage:parseInt(f.delayMessage,10),unknownMessage:f.unknownMessage,listeningFromMe:f.listeningFromMe,stopBotFromMe:f.stopBotFromMe,keepOpen:f.keepOpen,debounceTime:parseInt(f.debounceTime,10)};await XQ(n.name,n.token,g),X.success(t("genericBot.toast.success.create")),a(!1),u(),e()}catch(g){console.error("Error:",g),X.error(`Error: ${(v=(h=(p=g==null?void 0:g.response)==null?void 0:p.data)==null?void 0:h.response)==null?void 0:v.message}`)}finally{s(!1)}};function u(){l.reset()}const d=l.watch("triggerType");return i.jsxs(yt,{open:o,onOpenChange:a,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{size:"sm",children:[i.jsx(Qa,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("genericBot.button.create")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:u,children:[i.jsx(gt,{children:i.jsx(At,{children:t("genericBot.form.title")})}),i.jsx(dr,{...l,children:i.jsxs("form",{onSubmit:l.handleSubmit(c),className:"w-full space-y-6",children:[i.jsx("div",{children:i.jsxs("div",{className:"space-y-4",children:[i.jsx(he,{name:"enabled",label:t("genericBot.form.enabled.label"),reverse:!0}),i.jsx(D,{name:"description",label:t("genericBot.form.description.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("genericBot.form.genericBotSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"apiUrl",label:t("genericBot.form.apiUrl.label"),required:!0,children:i.jsx(A,{})}),i.jsx(D,{name:"apiKey",label:t("genericBot.form.apiKey.label"),children:i.jsx(A,{type:"password"})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("genericBot.form.triggerSettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"triggerType",label:t("genericBot.form.triggerType.label"),options:[{label:t("genericBot.form.triggerType.keyword"),value:"keyword"},{label:t("genericBot.form.triggerType.all"),value:"all"},{label:t("genericBot.form.triggerType.advanced"),value:"advanced"},{label:t("genericBot.form.triggerType.none"),value:"none"}],required:!0}),d==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(et,{name:"triggerOperator",label:t("genericBot.form.triggerOperator.label"),options:[{label:t("genericBot.form.triggerOperator.contains"),value:"contains"},{label:t("genericBot.form.triggerOperator.equals"),value:"equals"},{label:t("genericBot.form.triggerOperator.startsWith"),value:"startsWith"},{label:t("genericBot.form.triggerOperator.endsWith"),value:"endsWith"},{label:t("genericBot.form.triggerOperator.regex"),value:"regex"}],required:!0}),i.jsx(D,{name:"triggerValue",label:t("genericBot.form.triggerValue.label"),required:!0,children:i.jsx(A,{})})]}),d==="advanced"&&i.jsx(D,{name:"triggerValue",label:t("genericBot.form.triggerConditions.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("genericBot.form.generalSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"expire",label:t("genericBot.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:t("genericBot.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:t("genericBot.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:t("genericBot.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:t("genericBot.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:t("genericBot.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:t("genericBot.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:t("genericBot.form.debounceTime.label"),children:i.jsx(A,{type:"number"})})]})}),i.jsx(Jt,{children:i.jsx(J,{disabled:r,type:"submit",children:t("genericBot.button.save")})})]})})]})]})}const L1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await sY(e.name,r,n);t(s)}else console.error("Token not found.")}catch(r){console.error("Errors:",r)}};function qP({genericBotId:e}){var h,v;const{t}=Le(),{instance:n}=st(),[r,s]=m.useState([]),[o,a]=m.useState([]),[l,c]=m.useState(!1);m.useEffect(()=>{l&&L1(n,a,e)},[n,e,l]);function u(){L1(n,a,e)}const d=async(g,b)=>{var y,x,w;try{if(!n)return;await oY(n.name,n.token,g,b),X.success(t("genericBot.toast.success.status")),u()}catch(S){console.error("Error:",S),X.error(`Error : ${(w=(x=(y=S==null?void 0:S.response)==null?void 0:y.data)==null?void 0:x.response)==null?void 0:w.message}`)}},f=[{accessorKey:"remoteJid",header:()=>i.jsx("div",{className:"text-center",children:t("genericBot.sessions.table.remoteJid")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>i.jsx("div",{className:"text-center",children:t("genericBot.sessions.table.pushName")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("pushName")})},{accessorKey:"sessionId",header:()=>i.jsx("div",{className:"text-center",children:t("genericBot.sessions.table.sessionId")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("sessionId")})},{accessorKey:"status",header:()=>i.jsx("div",{className:"text-center",children:t("genericBot.sessions.table.status")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:g})=>{const b=g.original;return i.jsxs(to,{children:[i.jsx(no,{asChild:!0,children:i.jsxs(J,{variant:"ghost",className:"h-8 w-8 p-0",children:[i.jsx("span",{className:"sr-only",children:t("genericBot.sessions.table.actions.title")}),i.jsx(Sl,{className:"h-4 w-4"})]})}),i.jsxs(Qr,{align:"end",children:[i.jsx(ei,{children:t("genericBot.sessions.table.actions.title")}),i.jsx(ra,{}),b.status!=="opened"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"opened"),children:[i.jsx(Ku,{className:"mr-2 h-4 w-4"}),t("genericBot.sessions.table.actions.open")]}),b.status!=="paused"&&b.status!=="closed"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"paused"),children:[i.jsx(qu,{className:"mr-2 h-4 w-4"}),t("genericBot.sessions.table.actions.pause")]}),b.status!=="closed"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"closed"),children:[i.jsx(Hu,{className:"mr-2 h-4 w-4"}),t("genericBot.sessions.table.actions.close")]}),i.jsxs(at,{onClick:()=>d(b.remoteJid,"delete"),children:[i.jsx(Wu,{className:"mr-2 h-4 w-4"}),t("genericBot.sessions.table.actions.delete")]})]})]})}}],p=Ul({data:o,columns:f,onSortingChange:s,getCoreRowModel:Ll(),getPaginationRowModel:Bl(),getSortedRowModel:zl(),getFilteredRowModel:$l(),state:{sorting:r}});return i.jsxs(yt,{open:l,onOpenChange:c,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{variant:"secondary",size:"sm",children:[i.jsx(Gu,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("genericBot.sessions.label")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:u,children:[i.jsx(gt,{children:i.jsx(At,{children:t("genericBot.sessions.label")})}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[i.jsx(A,{placeholder:t("genericBot.sessions.search"),value:((h=p.getColumn("remoteJid"))==null?void 0:h.getFilterValue())??"",onChange:g=>{var b;return(b=p.getColumn("remoteJid"))==null?void 0:b.setFilterValue(g.target.value)}}),i.jsx(J,{variant:"outline",onClick:u,size:"icon",children:i.jsx(Ju,{})})]}),i.jsxs(ri,{children:[i.jsx(si,{children:p.getHeaderGroups().map(g=>i.jsx(en,{children:g.headers.map(b=>i.jsx(ai,{children:b.isPlaceholder?null:Rr(b.column.columnDef.header,b.getContext())},b.id))},g.id))}),i.jsx(oi,{children:(v=p.getRowModel().rows)!=null&&v.length?p.getRowModel().rows.map(g=>i.jsx(en,{"data-state":g.getIsSelected()&&"selected",children:g.getVisibleCells().map(b=>i.jsx(ir,{children:Rr(b.column.columnDef.cell,b.getContext())},b.id))},g.id)):i.jsx(en,{children:i.jsx(ir,{colSpan:f.length,className:"h-24 text-center",children:t("genericBot.sessions.table.none")})})})]})]})]})]})}const uY=k.object({enabled:k.boolean(),description:k.string(),botType:k.string(),apiUrl:k.string(),apiKey:k.string(),triggerType:k.string(),triggerOperator:k.string().optional(),triggerValue:k.string().optional(),expire:k.coerce.number(),keywordFinish:k.string(),delayMessage:k.coerce.number(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.coerce.number()});function dY({genericBotId:e,instance:t,resetTable:n}){const{t:r}=Le(),[,s]=m.useState(""),[o,a]=m.useState(!0),[l,c]=m.useState(!1),u=En(),d=kt({resolver:Et(uY),defaultValues:{enabled:!0,description:"",apiUrl:"",apiKey:"",triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:0,keywordFinish:"",delayMessage:0,unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:0}});m.useEffect(()=>{(async()=>{try{const b=localStorage.getItem("token");if(b&&t&&t.name&&e){s(b);const y=await YQ(t.name,b,e);d.reset({enabled:y.enabled,description:y.description,apiUrl:y.apiUrl,apiKey:y.apiKey,triggerType:y.triggerType,triggerOperator:y.triggerOperator,triggerValue:y.triggerValue,expire:y.expire,keywordFinish:y.keywordFinish,delayMessage:y.delayMessage,unknownMessage:y.unknownMessage,listeningFromMe:y.listeningFromMe,stopBotFromMe:y.stopBotFromMe,keepOpen:y.keepOpen,debounceTime:y.debounceTime})}else console.error("Token not found.");a(!1)}catch(b){console.error("Error:",b),a(!1)}})()},[d,t,e]);const f=async g=>{var b,y,x;try{const w=localStorage.getItem("token");if(w&&t&&t.name&&e){const S={enabled:g.enabled,description:g.description,apiUrl:g.apiUrl,apiKey:g.apiKey,triggerType:g.triggerType,triggerOperator:g.triggerOperator||"",triggerValue:g.triggerValue||"",expire:g.expire,keywordFinish:g.keywordFinish,delayMessage:g.delayMessage,unknownMessage:g.unknownMessage,listeningFromMe:g.listeningFromMe,stopBotFromMe:g.stopBotFromMe,keepOpen:g.keepOpen,debounceTime:g.debounceTime};await eY(t.name,w,e,S),X.success(r("genericBot.toast.success.update"))}else console.error("Token not found")}catch(w){console.error("Error:",w),X.error(`Error: ${(x=(y=(b=w==null?void 0:w.response)==null?void 0:b.data)==null?void 0:y.response)==null?void 0:x.message}`)}},p=async()=>{try{const g=localStorage.getItem("token");g&&t&&t.name&&e?(await tY(t.name,g,e),X.success(r("genericBot.toast.success.delete")),c(!1),n(),u(`/manager/instance/${t.id}/generic`)):console.error("instance not found")}catch(g){console.error("Erro ao excluir genericBot:",g)}},h=d.watch("description"),v=d.watch("triggerType");return i.jsxs(i.Fragment,{children:[o&&i.jsx(or,{}),!o&&i.jsx(fr,{...d,children:i.jsxs("form",{onSubmit:d.handleSubmit(f),className:"w-full space-y-6 pl-4 pr-2",children:[i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[i.jsxs("h3",{className:"mb-4 text-lg font-medium",children:["GenericBot: ",h]}),i.jsx(he,{name:"enabled",className:"flex items-center gap-3"})]}),i.jsxs("div",{className:"space-y-4",children:[i.jsx(D,{name:"description",label:r("genericBot.form.description.label"),children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("genericBot.form.genericBotSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"apiUrl",label:r("genericBot.form.apiUrl.label"),required:!0,children:i.jsx(A,{})}),i.jsx(D,{name:"apiKey",label:r("genericBot.form.apiKey.label"),children:i.jsx(A,{type:"password"})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("genericBot.form.triggerSettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"triggerType",label:r("genericBot.form.triggerType.label"),options:[{label:r("genericBot.form.triggerType.keyword"),value:"keyword"},{label:r("genericBot.form.triggerType.all"),value:"all"},{label:r("genericBot.form.triggerType.advanced"),value:"advanced"},{label:r("genericBot.form.triggerType.none"),value:"none"}]}),v==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(et,{name:"triggerOperator",label:r("genericBot.form.triggerOperator.label"),options:[{label:r("genericBot.form.triggerOperator.contains"),value:"contains"},{label:r("genericBot.form.triggerOperator.equals"),value:"equals"},{label:r("genericBot.form.triggerOperator.startsWith"),value:"startsWith"},{label:r("genericBot.form.triggerOperator.endsWith"),value:"endsWith"},{label:r("genericBot.form.triggerOperator.regex"),value:"regex"}]}),i.jsx(D,{name:"triggerValue",label:r("genericBot.form.triggerValue.label"),children:i.jsx(A,{})})]}),v==="advanced"&&i.jsx(D,{name:"triggerValue",label:r("genericBot.form.triggerConditions.label"),children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("genericBot.form.generalSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"expire",label:r("genericBot.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:r("genericBot.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:r("genericBot.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:r("genericBot.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:r("genericBot.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:r("genericBot.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:r("genericBot.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:r("genericBot.form.debounceTime.label"),children:i.jsx(A,{type:"number"})})]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx(qP,{genericBotId:e}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs(yt,{open:l,onOpenChange:c,children:[i.jsx(Rt,{asChild:!0,children:i.jsx(J,{variant:"destructive",size:"sm",children:r("genericBot.button.delete")})}),i.jsx(pt,{children:i.jsxs(gt,{children:[i.jsx(At,{children:r("modal.delete.title")}),i.jsx(ti,{children:r("modal.delete.messageSingle")}),i.jsxs(Jt,{children:[i.jsx(J,{size:"sm",variant:"outline",onClick:()=>c(!1),children:r("button.cancel")}),i.jsx(J,{variant:"destructive",onClick:p,children:r("button.delete")})]})]})})]}),i.jsx(J,{type:"submit",children:r("genericBot.button.update")})]})]})]})})]})}const $1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await GP(e.name,r);t(s)}else console.error("Token not found");n(!1)}catch(r){console.error("Error:",r),n(!1)}};function B1(){const{t:e}=Le(),t=Fl("(min-width: 768px)"),{instance:n}=st(),{genericBotId:r}=Ys(),[s,o]=m.useState(!0),[a,l]=m.useState([]),c=En();m.useEffect(()=>{n&&$1(n,l,o)},[n]);const u=f=>{n&&c(`/manager/instance/${n.id}/generic/${f}`)},d=()=>{$1(n,l,o)};return i.jsxs("main",{className:"pt-5",children:[i.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[i.jsx("h3",{className:"text-lg font-medium",children:e("genericBot.title")}),i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[i.jsx(qP,{}),i.jsx(iY,{}),i.jsx(cY,{resetTable:d})]})]}),i.jsx(Ze,{className:"my-4"}),i.jsxs(Dl,{direction:t?"horizontal":"vertical",children:[i.jsx(_r,{defaultSize:35,className:"pr-4",children:i.jsx("div",{className:"flex flex-col gap-3",children:s?i.jsx(or,{}):i.jsx(i.Fragment,{children:a&&a.length>0&&Array.isArray(a)?a.map(f=>i.jsx(J,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>u(`${f.id}`),variant:r===f.id?"secondary":"outline",children:i.jsx("h4",{className:"text-base",children:f.description||f.id})},f.id)):i.jsx(J,{variant:"link",children:e("genericBot.table.none")})})})}),r&&i.jsxs(i.Fragment,{children:[i.jsx(Al,{withHandle:!0,className:"border border-border"}),i.jsx(_r,{className:"",children:i.jsx(dY,{genericBotId:r,instance:n,resetTable:d})})]})]})]})}const lo=new ur,KP=async(e,t)=>(await lo.getInstance().get(`/flowise/find/${e}`,{headers:{apikey:t}})).data,fY=async(e,t,n)=>(await lo.getInstance().get(`/flowise/fetch/${n}/${e}`,{headers:{apikey:t}})).data,pY=async(e,t,n)=>(await lo.getInstance().post(`/flowise/create/${e}`,n,{headers:{apikey:t}})).data,gY=async(e,t,n,r)=>(await lo.getInstance().put(`/flowise/update/${n}/${e}`,r,{headers:{apikey:t}})).data,hY=async(e,t,n)=>(await lo.getInstance().delete(`/flowise/delete/${n}/${e}`,{headers:{apikey:t}})).data,mY=async(e,t)=>(await lo.getInstance().get(`/flowise/fetchSettings/${e}`,{headers:{apikey:t}})).data,vY=async(e,t,n)=>(await lo.getInstance().post(`/flowise/settings/${e}`,n,{headers:{apikey:t}})).data,yY=async(e,t,n)=>(await lo.getInstance().get(`/flowise/fetchSessions/${n}/${e}`,{headers:{apikey:t}})).data,bY=async(e,t,n,r)=>(await lo.getInstance().post(`/flowise/changeStatus/${e}`,{remoteJid:n,status:r},{headers:{apikey:t}})).data,xY=k.object({expire:k.string(),keywordFinish:k.string(),delayMessage:k.string(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.string(),ignoreJids:k.array(k.string()).default([]),flowiseIdFallback:k.union([k.null(),k.string()]).optional()}),z1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await mY(e.name,r);t(s);const o=await KP(e.name,r);n(o)}else console.error("Token not found.")}catch(r){console.error("Error:",r)}};function wY(){const{t:e}=Le(),{instance:t}=st(),[n,r]=m.useState(!1),[s,o]=m.useState(),[a,l]=m.useState([]),c=kt({resolver:Et(xY),defaultValues:{expire:"0",keywordFinish:e("flowise.form.examples.keywordFinish"),delayMessage:"1000",unknownMessage:e("flowise.form.examples.unknownMessage"),listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:"0",ignoreJids:[],flowiseIdFallback:void 0}});m.useEffect(()=>{n&&z1(t,o,l)},[t,n]),m.useEffect(()=>{s&&c.reset({expire:s!=null&&s.expire?s.expire.toString():"0",keywordFinish:s.keywordFinish,delayMessage:s.delayMessage?s.delayMessage.toString():"0",unknownMessage:s.unknownMessage,listeningFromMe:s.listeningFromMe,stopBotFromMe:s.stopBotFromMe,keepOpen:s.keepOpen,debounceTime:s.debounceTime?s.debounceTime.toString():"0",ignoreJids:s.ignoreJids,flowiseIdFallback:s.flowiseIdFallback})},[s]);const u=async f=>{var p,h,v;try{if(!t||!t.name)throw new Error("instance not found.");const g={expire:parseInt(f.expire),keywordFinish:f.keywordFinish,delayMessage:parseInt(f.delayMessage),unknownMessage:f.unknownMessage,listeningFromMe:f.listeningFromMe,stopBotFromMe:f.stopBotFromMe,keepOpen:f.keepOpen,debounceTime:parseInt(f.debounceTime),flowiseIdFallback:f.flowiseIdFallback||void 0,ignoreJids:f.ignoreJids};await vY(t.name,t.token,g),X.success(e("flowise.toast.defaultSettings.success"))}catch(g){console.error("Error:",g),X.error(`Error: ${(v=(h=(p=g==null?void 0:g.response)==null?void 0:p.data)==null?void 0:h.response)==null?void 0:v.message}`)}};function d(){z1(t,o,l)}return i.jsxs(yt,{open:n,onOpenChange:r,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{variant:"secondary",size:"sm",children:[i.jsx(Za,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:e("flowise.defaultSettings")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:d,children:[i.jsx(gt,{children:i.jsx(At,{children:e("flowise.defaultSettings")})}),i.jsx(dr,{...c,children:i.jsxs("form",{className:"w-full space-y-6",onSubmit:c.handleSubmit(u),children:[i.jsx("div",{children:i.jsxs("div",{className:"space-y-4",children:[i.jsx(et,{name:"flowiseIdFallback",label:e("flowise.form.flowiseIdFallback.label"),options:(a==null?void 0:a.filter(f=>!!f.id).map(f=>({label:f.description,value:f.id})))??[]}),i.jsx(D,{name:"expire",label:e("flowise.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:e("flowise.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:e("flowise.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:e("flowise.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:e("flowise.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:e("flowise.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:e("flowise.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:e("flowise.form.debounceTime.label"),children:i.jsx(A,{type:"number"})}),i.jsx(Ml,{name:"ignoreJids",label:e("flowise.form.ignoreJids.label"),placeholder:e("flowise.form.ignoreJids.placeholder")})]})}),i.jsx(Jt,{children:i.jsx(J,{type:"submit",children:e("flowise.button.save")})})]})})]})]})}const SY=k.object({enabled:k.boolean(),description:k.string(),apiUrl:k.string(),apiKey:k.string(),triggerType:k.string(),triggerOperator:k.string().optional(),triggerValue:k.string().optional(),expire:k.string(),keywordFinish:k.string(),delayMessage:k.string(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.string()});function CY({resetTable:e}){const{t}=Le(),{instance:n}=st(),[r,s]=m.useState(!1),[o,a]=m.useState(!1),l=kt({resolver:Et(SY),defaultValues:{enabled:!0,description:"",apiUrl:"",apiKey:"",triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:"0",keywordFinish:"",delayMessage:"0",unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:"0"}}),c=async f=>{var p,h,v;try{if(!n||!n.name)throw new Error("instance not found");s(!0);const g={enabled:f.enabled,description:f.description,apiUrl:f.apiUrl,apiKey:f.apiKey,triggerType:f.triggerType,triggerOperator:f.triggerOperator||"",triggerValue:f.triggerValue||"",expire:parseInt(f.expire,10),keywordFinish:f.keywordFinish,delayMessage:parseInt(f.delayMessage,10),unknownMessage:f.unknownMessage,listeningFromMe:f.listeningFromMe,stopBotFromMe:f.stopBotFromMe,keepOpen:f.keepOpen,debounceTime:parseInt(f.debounceTime,10)};await pY(n.name,n.token,g),X.success(t("flowise.toast.success.create")),a(!1),u(),e()}catch(g){console.error("Error:",g),X.error(`Error: ${(v=(h=(p=g==null?void 0:g.response)==null?void 0:p.data)==null?void 0:h.response)==null?void 0:v.message}`)}finally{s(!1)}};function u(){l.reset()}const d=l.watch("triggerType");return i.jsxs(yt,{open:o,onOpenChange:a,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{size:"sm",children:[i.jsx(Qa,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("flowise.button.create")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:u,children:[i.jsx(gt,{children:i.jsx(At,{children:t("flowise.form.title")})}),i.jsx(dr,{...l,children:i.jsxs("form",{onSubmit:l.handleSubmit(c),className:"w-full space-y-6",children:[i.jsx("div",{children:i.jsxs("div",{className:"space-y-4",children:[i.jsx(he,{name:"enabled",label:t("flowise.form.enabled.label"),reverse:!0}),i.jsx(D,{name:"description",label:t("flowise.form.description.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("flowise.form.flowiseSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"apiUrl",label:t("flowise.form.apiUrl.label"),required:!0,children:i.jsx(A,{})}),i.jsx(D,{name:"apiKey",label:t("flowise.form.apiKey.label"),children:i.jsx(A,{type:"password"})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("flowise.form.triggerSettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"triggerType",label:t("flowise.form.triggerType.label"),options:[{label:t("flowise.form.triggerType.keyword"),value:"keyword"},{label:t("flowise.form.triggerType.all"),value:"all"},{label:t("flowise.form.triggerType.advanced"),value:"advanced"},{label:t("flowise.form.triggerType.none"),value:"none"}],required:!0}),d==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(et,{name:"triggerOperator",label:t("flowise.form.triggerOperator.label"),options:[{label:t("flowise.form.triggerOperator.contains"),value:"contains"},{label:t("flowise.form.triggerOperator.equals"),value:"equals"},{label:t("flowise.form.triggerOperator.startsWith"),value:"startsWith"},{label:t("flowise.form.triggerOperator.endsWith"),value:"endsWith"},{label:t("flowise.form.triggerOperator.regex"),value:"regex"}],required:!0}),i.jsx(D,{name:"triggerValue",label:t("flowise.form.triggerValue.label"),required:!0,children:i.jsx(A,{})})]}),d==="advanced"&&i.jsx(D,{name:"triggerValue",label:t("flowise.form.triggerConditions.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("flowise.form.generalSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"expire",label:t("flowise.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:t("flowise.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:t("flowise.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:t("flowise.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:t("flowise.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:t("flowise.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:t("flowise.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:t("flowise.form.debounceTime.label"),children:i.jsx(A,{type:"number"})})]})}),i.jsx(Jt,{children:i.jsx(J,{disabled:r,type:"submit",children:t("flowise.button.save")})})]})})]})]})}const U1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await yY(e.name,r,n);t(s)}else console.error("Token not found.")}catch(r){console.error("Errors:",r)}};function JP({flowiseId:e}){var h,v;const{t}=Le(),{instance:n}=st(),[r,s]=m.useState([]),[o,a]=m.useState([]),[l,c]=m.useState(!1);m.useEffect(()=>{l&&U1(n,a,e)},[n,e,l]);function u(){U1(n,a,e)}const d=async(g,b)=>{var y,x,w;try{if(!n)return;await bY(n.name,n.token,g,b),X.success(t("flowise.toast.success.status")),u()}catch(S){console.error("Error:",S),X.error(`Error : ${(w=(x=(y=S==null?void 0:S.response)==null?void 0:y.data)==null?void 0:x.response)==null?void 0:w.message}`)}},f=[{accessorKey:"remoteJid",header:()=>i.jsx("div",{className:"text-center",children:t("flowise.sessions.table.remoteJid")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>i.jsx("div",{className:"text-center",children:t("flowise.sessions.table.pushName")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("pushName")})},{accessorKey:"sessionId",header:()=>i.jsx("div",{className:"text-center",children:t("flowise.sessions.table.sessionId")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("sessionId")})},{accessorKey:"status",header:()=>i.jsx("div",{className:"text-center",children:t("flowise.sessions.table.status")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:g})=>{const b=g.original;return i.jsxs(to,{children:[i.jsx(no,{asChild:!0,children:i.jsxs(J,{variant:"ghost",className:"h-8 w-8 p-0",children:[i.jsx("span",{className:"sr-only",children:t("flowise.sessions.table.actions.title")}),i.jsx(Sl,{className:"h-4 w-4"})]})}),i.jsxs(Qr,{align:"end",children:[i.jsx(ei,{children:t("flowise.sessions.table.actions.title")}),i.jsx(ra,{}),b.status!=="opened"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"opened"),children:[i.jsx(Ku,{className:"mr-2 h-4 w-4"}),t("flowise.sessions.table.actions.open")]}),b.status!=="paused"&&b.status!=="closed"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"paused"),children:[i.jsx(qu,{className:"mr-2 h-4 w-4"}),t("flowise.sessions.table.actions.pause")]}),b.status!=="closed"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"closed"),children:[i.jsx(Hu,{className:"mr-2 h-4 w-4"}),t("flowise.sessions.table.actions.close")]}),i.jsxs(at,{onClick:()=>d(b.remoteJid,"delete"),children:[i.jsx(Wu,{className:"mr-2 h-4 w-4"}),t("flowise.sessions.table.actions.delete")]})]})]})}}],p=Ul({data:o,columns:f,onSortingChange:s,getCoreRowModel:Ll(),getPaginationRowModel:Bl(),getSortedRowModel:zl(),getFilteredRowModel:$l(),state:{sorting:r}});return i.jsxs(yt,{open:l,onOpenChange:c,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{variant:"secondary",size:"sm",children:[i.jsx(Gu,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("flowise.sessions.label")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:u,children:[i.jsx(gt,{children:i.jsx(At,{children:t("flowise.sessions.label")})}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[i.jsx(A,{placeholder:t("flowise.sessions.search"),value:((h=p.getColumn("remoteJid"))==null?void 0:h.getFilterValue())??"",onChange:g=>{var b;return(b=p.getColumn("remoteJid"))==null?void 0:b.setFilterValue(g.target.value)}}),i.jsx(J,{variant:"outline",onClick:u,size:"icon",children:i.jsx(Ju,{})})]}),i.jsxs(ri,{children:[i.jsx(si,{children:p.getHeaderGroups().map(g=>i.jsx(en,{children:g.headers.map(b=>i.jsx(ai,{children:b.isPlaceholder?null:Rr(b.column.columnDef.header,b.getContext())},b.id))},g.id))}),i.jsx(oi,{children:(v=p.getRowModel().rows)!=null&&v.length?p.getRowModel().rows.map(g=>i.jsx(en,{"data-state":g.getIsSelected()&&"selected",children:g.getVisibleCells().map(b=>i.jsx(ir,{children:Rr(b.column.columnDef.cell,b.getContext())},b.id))},g.id)):i.jsx(en,{children:i.jsx(ir,{colSpan:f.length,className:"h-24 text-center",children:t("flowise.sessions.table.none")})})})]})]})]})]})}const kY=k.object({enabled:k.boolean(),description:k.string(),botType:k.string(),apiUrl:k.string(),apiKey:k.string(),triggerType:k.string(),triggerOperator:k.string().optional(),triggerValue:k.string().optional(),expire:k.coerce.number(),keywordFinish:k.string(),delayMessage:k.coerce.number(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.coerce.number()});function EY({flowiseId:e,instance:t,resetTable:n}){const{t:r}=Le(),[,s]=m.useState(""),[o,a]=m.useState(!0),[l,c]=m.useState(!1),u=En(),d=kt({resolver:Et(kY),defaultValues:{enabled:!0,description:"",apiUrl:"",apiKey:"",triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:0,keywordFinish:"",delayMessage:0,unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:0}});m.useEffect(()=>{(async()=>{try{const b=localStorage.getItem("token");if(b&&t&&t.name&&e){s(b);const y=await fY(t.name,b,e);d.reset({enabled:y.enabled,description:y.description,apiUrl:y.apiUrl,apiKey:y.apiKey,triggerType:y.triggerType,triggerOperator:y.triggerOperator,triggerValue:y.triggerValue,expire:y.expire,keywordFinish:y.keywordFinish,delayMessage:y.delayMessage,unknownMessage:y.unknownMessage,listeningFromMe:y.listeningFromMe,stopBotFromMe:y.stopBotFromMe,keepOpen:y.keepOpen,debounceTime:y.debounceTime})}else console.error("Token not found.");a(!1)}catch(b){console.error("Error:",b),a(!1)}})()},[d,t,e]);const f=async g=>{var b,y,x;try{const w=localStorage.getItem("token");if(w&&t&&t.name&&e){const S={enabled:g.enabled,description:g.description,apiUrl:g.apiUrl,apiKey:g.apiKey,triggerType:g.triggerType,triggerOperator:g.triggerOperator||"",triggerValue:g.triggerValue||"",expire:g.expire,keywordFinish:g.keywordFinish,delayMessage:g.delayMessage,unknownMessage:g.unknownMessage,listeningFromMe:g.listeningFromMe,stopBotFromMe:g.stopBotFromMe,keepOpen:g.keepOpen,debounceTime:g.debounceTime};await gY(t.name,w,e,S),X.success(r("flowise.toast.success.update"))}else console.error("Token not found")}catch(w){console.error("Error:",w),X.error(`Error: ${(x=(y=(b=w==null?void 0:w.response)==null?void 0:b.data)==null?void 0:y.response)==null?void 0:x.message}`)}},p=async()=>{try{const g=localStorage.getItem("token");g&&t&&t.name&&e?(await hY(t.name,g,e),X.success(r("flowise.toast.success.delete")),c(!1),n(),u(`/manager/instance/${t.id}/flowise`)):console.error("instance not found")}catch(g){console.error("Erro ao excluir flowise:",g)}},h=d.watch("description"),v=d.watch("triggerType");return i.jsxs(i.Fragment,{children:[o&&i.jsx(or,{}),!o&&i.jsx(fr,{...d,children:i.jsxs("form",{onSubmit:d.handleSubmit(f),className:"w-full space-y-6 pl-4 pr-2",children:[i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[i.jsxs("h3",{className:"mb-4 text-lg font-medium",children:["Flowise: ",h]}),i.jsx(he,{name:"enabled",className:"flex items-center gap-3"})]}),i.jsxs("div",{className:"space-y-4",children:[i.jsx(D,{name:"description",label:r("flowise.form.description.label"),children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("flowise.form.flowiseSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"apiUrl",label:r("flowise.form.apiUrl.label"),required:!0,children:i.jsx(A,{})}),i.jsx(D,{name:"apiKey",label:r("flowise.form.apiKey.label"),children:i.jsx(A,{type:"password"})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("flowise.form.triggerSettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"triggerType",label:r("flowise.form.triggerType.label"),options:[{label:r("flowise.form.triggerType.keyword"),value:"keyword"},{label:r("flowise.form.triggerType.all"),value:"all"},{label:r("flowise.form.triggerType.advanced"),value:"advanced"},{label:r("flowise.form.triggerType.none"),value:"none"}]}),v==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(et,{name:"triggerOperator",label:r("flowise.form.triggerOperator.label"),options:[{label:r("flowise.form.triggerOperator.contains"),value:"contains"},{label:r("flowise.form.triggerOperator.equals"),value:"equals"},{label:r("flowise.form.triggerOperator.startsWith"),value:"startsWith"},{label:r("flowise.form.triggerOperator.endsWith"),value:"endsWith"},{label:r("flowise.form.triggerOperator.regex"),value:"regex"}]}),i.jsx(D,{name:"triggerValue",label:r("flowise.form.triggerValue.label"),children:i.jsx(A,{})})]}),v==="advanced"&&i.jsx(D,{name:"triggerValue",label:r("flowise.form.triggerConditions.label"),children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("flowise.form.generalSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"expire",label:r("flowise.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:r("flowise.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:r("flowise.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:r("flowise.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:r("flowise.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:r("flowise.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:r("flowise.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:r("flowise.form.debounceTime.label"),children:i.jsx(A,{type:"number"})})]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx(JP,{flowiseId:e}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs(yt,{open:l,onOpenChange:c,children:[i.jsx(Rt,{asChild:!0,children:i.jsx(J,{variant:"destructive",size:"sm",children:r("flowise.button.delete")})}),i.jsx(pt,{children:i.jsxs(gt,{children:[i.jsx(At,{children:r("modal.delete.title")}),i.jsx(ti,{children:r("modal.delete.messageSingle")}),i.jsxs(Jt,{children:[i.jsx(J,{size:"sm",variant:"outline",onClick:()=>c(!1),children:r("button.cancel")}),i.jsx(J,{variant:"destructive",onClick:p,children:r("button.delete")})]})]})})]}),i.jsx(J,{type:"submit",children:r("flowise.button.update")})]})]})]})})]})}const V1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await KP(e.name,r);t(s)}else console.error("Token not found");n(!1)}catch(r){console.error("Error:",r),n(!1)}};function H1(){const{t:e}=Le(),t=Fl("(min-width: 768px)"),{instance:n}=st(),{flowiseId:r}=Ys(),[s,o]=m.useState(!0),[a,l]=m.useState([]),c=En();m.useEffect(()=>{n&&V1(n,l,o)},[n]);const u=f=>{n&&c(`/manager/instance/${n.id}/flowise/${f}`)},d=()=>{V1(n,l,o)};return i.jsxs("main",{className:"pt-5",children:[i.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[i.jsx("h3",{className:"text-lg font-medium",children:e("flowise.title")}),i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[i.jsx(JP,{}),i.jsx(wY,{}),i.jsx(CY,{resetTable:d})]})]}),i.jsx(Ze,{className:"my-4"}),i.jsxs(Dl,{direction:t?"horizontal":"vertical",children:[i.jsx(_r,{defaultSize:35,className:"pr-4",children:i.jsx("div",{className:"flex flex-col gap-3",children:s?i.jsx(or,{}):i.jsx(i.Fragment,{children:a&&a.length>0&&Array.isArray(a)?a.map(f=>i.jsx(J,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>u(`${f.id}`),variant:r===f.id?"secondary":"outline",children:i.jsx("h4",{className:"text-base",children:f.description||f.id})},f.id)):i.jsx(J,{variant:"link",children:e("flowise.table.none")})})})}),r&&i.jsxs(i.Fragment,{children:[i.jsx(Al,{withHandle:!0,className:"border border-border"}),i.jsx(_r,{className:"",children:i.jsx(EY,{flowiseId:r,instance:n,resetTable:d})})]})]})]})}const TY=lF([{path:"/manager/login",element:i.jsx(FF,{children:i.jsx(QQ,{})})},{path:"/manager/",element:i.jsx(zt,{children:i.jsx(Xz,{children:i.jsx(xK,{})})})},{path:"/manager/instance/:instanceId/dashboard",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx($J,{})})})},{path:"/manager/instance/:instanceId/chat",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(x1,{})})})},{path:"/manager/instance/:instanceId/chat/:remoteJid",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(x1,{})})})},{path:"/manager/instance/:instanceId/settings",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(CQ,{})})})},{path:"/manager/instance/:instanceId/openai",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(P1,{})})})},{path:"/manager/instance/:instanceId/openai/:botId",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(P1,{})})})},{path:"/manager/instance/:instanceId/webhook",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(WQ,{})})})},{path:"/manager/instance/:instanceId/websocket",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(JQ,{})})})},{path:"/manager/instance/:instanceId/rabbitmq",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(wQ,{})})})},{path:"/manager/instance/:instanceId/sqs",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(jQ,{})})})},{path:"/manager/instance/:instanceId/chatwoot",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(iJ,{})})})},{path:"/manager/instance/:instanceId/typebot",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(A1,{})})})},{path:"/manager/instance/:instanceId/typebot/:typebotId",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(A1,{})})})},{path:"/manager/instance/:instanceId/dify",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(_1,{})})})},{path:"/manager/instance/:instanceId/dify/:difyId",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(_1,{})})})},{path:"/manager/instance/:instanceId/generic",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(B1,{})})})},{path:"/manager/instance/:instanceId/generic/:genericBotId",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(B1,{})})})},{path:"/manager/instance/:instanceId/flowise",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(H1,{})})})},{path:"/manager/instance/:instanceId/flowise/:flowiseId",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(H1,{})})})},{path:"/manager/instance/:instanceId/proxy",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(vQ,{})})})}]),jY={type:"logger",log(e){this.output("log",e)},warn(e){this.output("warn",e)},error(e){this.output("error",e)},output(e,t){console&&console[e]&&console[e].apply(console,t)}};class Cp{constructor(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.init(t,n)}init(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.prefix=n.prefix||"i18next:",this.logger=t||jY,this.options=n,this.debug=n.debug}log(){for(var t=arguments.length,n=new Array(t),r=0;r{this.observers[r]||(this.observers[r]=new Map);const s=this.observers[r].get(n)||0;this.observers[r].set(n,s+1)}),this}off(t,n){if(this.observers[t]){if(!n){delete this.observers[t];return}this.observers[t].delete(n)}}emit(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),s=1;s{let[l,c]=a;for(let u=0;u{let[l,c]=a;for(let u=0;u{let e,t;const n=new Promise((r,s)=>{e=r,t=s});return n.resolve=e,n.reject=t,n},W1=e=>e==null?"":""+e,_Y=(e,t,n)=>{e.forEach(r=>{t[r]&&(n[r]=t[r])})},RY=/###/g,G1=e=>e&&e.indexOf("###")>-1?e.replace(RY,"."):e,q1=e=>!e||typeof e=="string",zc=(e,t,n)=>{const r=typeof t!="string"?t:t.split(".");let s=0;for(;s{const{obj:r,k:s}=zc(e,t,Object);if(r!==void 0||t.length===1){r[s]=n;return}let o=t[t.length-1],a=t.slice(0,t.length-1),l=zc(e,a,Object);for(;l.obj===void 0&&a.length;)o=`${a[a.length-1]}.${o}`,a=a.slice(0,a.length-1),l=zc(e,a,Object),l&&l.obj&&typeof l.obj[`${l.k}.${o}`]<"u"&&(l.obj=void 0);l.obj[`${l.k}.${o}`]=n},IY=(e,t,n,r)=>{const{obj:s,k:o}=zc(e,t,Object);s[o]=s[o]||[],s[o].push(n)},kp=(e,t)=>{const{obj:n,k:r}=zc(e,t);if(n)return n[r]},NY=(e,t,n)=>{const r=kp(e,n);return r!==void 0?r:kp(t,n)},ZP=(e,t,n)=>{for(const r in t)r!=="__proto__"&&r!=="constructor"&&(r in e?typeof e[r]=="string"||e[r]instanceof String||typeof t[r]=="string"||t[r]instanceof String?n&&(e[r]=t[r]):ZP(e[r],t[r],n):e[r]=t[r]);return e},wi=e=>e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&");var PY={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};const OY=e=>typeof e=="string"?e.replace(/[&<>"'\/]/g,t=>PY[t]):e;class MY{constructor(t){this.capacity=t,this.regExpMap=new Map,this.regExpQueue=[]}getRegExp(t){const n=this.regExpMap.get(t);if(n!==void 0)return n;const r=new RegExp(t);return this.regExpQueue.length===this.capacity&&this.regExpMap.delete(this.regExpQueue.shift()),this.regExpMap.set(t,r),this.regExpQueue.push(t),r}}const DY=[" ",",","?","!",";"],AY=new MY(20),FY=(e,t,n)=>{t=t||"",n=n||"";const r=DY.filter(a=>t.indexOf(a)<0&&n.indexOf(a)<0);if(r.length===0)return!0;const s=AY.getRegExp(`(${r.map(a=>a==="?"?"\\?":a).join("|")})`);let o=!s.test(e);if(!o){const a=e.indexOf(n);a>0&&!s.test(e.substring(0,a))&&(o=!0)}return o},ay=function(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:".";if(!e)return;if(e[t])return e[t];const r=t.split(n);let s=e;for(let o=0;o-1&&ce&&e.indexOf("_")>0?e.replace("_","-"):e;class J1 extends Gg{constructor(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{ns:["translation"],defaultNS:"translation"};super(),this.data=t||{},this.options=n,this.options.keySeparator===void 0&&(this.options.keySeparator="."),this.options.ignoreJSONStructure===void 0&&(this.options.ignoreJSONStructure=!0)}addNamespaces(t){this.options.ns.indexOf(t)<0&&this.options.ns.push(t)}removeNamespaces(t){const n=this.options.ns.indexOf(t);n>-1&&this.options.ns.splice(n,1)}getResource(t,n,r){let s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};const o=s.keySeparator!==void 0?s.keySeparator:this.options.keySeparator,a=s.ignoreJSONStructure!==void 0?s.ignoreJSONStructure:this.options.ignoreJSONStructure;let l;t.indexOf(".")>-1?l=t.split("."):(l=[t,n],r&&(Array.isArray(r)?l.push(...r):typeof r=="string"&&o?l.push(...r.split(o)):l.push(r)));const c=kp(this.data,l);return!c&&!n&&!r&&t.indexOf(".")>-1&&(t=l[0],n=l[1],r=l.slice(2).join(".")),c||!a||typeof r!="string"?c:ay(this.data&&this.data[t]&&this.data[t][n],r,o)}addResource(t,n,r,s){let o=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{silent:!1};const a=o.keySeparator!==void 0?o.keySeparator:this.options.keySeparator;let l=[t,n];r&&(l=l.concat(a?r.split(a):r)),t.indexOf(".")>-1&&(l=t.split("."),s=n,n=l[1]),this.addNamespaces(n),K1(this.data,l,s),o.silent||this.emit("added",t,n,r,s)}addResources(t,n,r){let s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{silent:!1};for(const o in r)(typeof r[o]=="string"||Array.isArray(r[o]))&&this.addResource(t,n,o,r[o],{silent:!0});s.silent||this.emit("added",t,n,r)}addResourceBundle(t,n,r,s,o){let a=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{silent:!1,skipCopy:!1},l=[t,n];t.indexOf(".")>-1&&(l=t.split("."),s=r,r=n,n=l[1]),this.addNamespaces(n);let c=kp(this.data,l)||{};a.skipCopy||(r=JSON.parse(JSON.stringify(r))),s?ZP(c,r,o):c={...c,...r},K1(this.data,l,c),a.silent||this.emit("added",t,n,r)}removeResourceBundle(t,n){this.hasResourceBundle(t,n)&&delete this.data[t][n],this.removeNamespaces(n),this.emit("removed",t,n)}hasResourceBundle(t,n){return this.getResource(t,n)!==void 0}getResourceBundle(t,n){return n||(n=this.options.defaultNS),this.options.compatibilityAPI==="v1"?{...this.getResource(t,n)}:this.getResource(t,n)}getDataByLanguage(t){return this.data[t]}hasLanguageSomeTranslations(t){const n=this.getDataByLanguage(t);return!!(n&&Object.keys(n)||[]).find(s=>n[s]&&Object.keys(n[s]).length>0)}toJSON(){return this.data}}var QP={processors:{},addPostProcessor(e){this.processors[e.name]=e},handle(e,t,n,r,s){return e.forEach(o=>{this.processors[o]&&(t=this.processors[o].process(t,n,r,s))}),t}};const Z1={};class Tp extends Gg{constructor(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),_Y(["resourceStore","languageUtils","pluralResolver","interpolator","backendConnector","i18nFormat","utils"],t,this),this.options=n,this.options.keySeparator===void 0&&(this.options.keySeparator="."),this.logger=gs.create("translator")}changeLanguage(t){t&&(this.language=t)}exists(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{interpolation:{}};if(t==null)return!1;const r=this.resolve(t,n);return r&&r.res!==void 0}extractFromKey(t,n){let r=n.nsSeparator!==void 0?n.nsSeparator:this.options.nsSeparator;r===void 0&&(r=":");const s=n.keySeparator!==void 0?n.keySeparator:this.options.keySeparator;let o=n.ns||this.options.defaultNS||[];const a=r&&t.indexOf(r)>-1,l=!this.options.userDefinedKeySeparator&&!n.keySeparator&&!this.options.userDefinedNsSeparator&&!n.nsSeparator&&!FY(t,r,s);if(a&&!l){const c=t.match(this.interpolator.nestingRegexp);if(c&&c.length>0)return{key:t,namespaces:o};const u=t.split(r);(r!==s||r===s&&this.options.ns.indexOf(u[0])>-1)&&(o=u.shift()),t=u.join(s)}return typeof o=="string"&&(o=[o]),{key:t,namespaces:o}}translate(t,n,r){if(typeof n!="object"&&this.options.overloadTranslationOptionHandler&&(n=this.options.overloadTranslationOptionHandler(arguments)),typeof n=="object"&&(n={...n}),n||(n={}),t==null)return"";Array.isArray(t)||(t=[String(t)]);const s=n.returnDetails!==void 0?n.returnDetails:this.options.returnDetails,o=n.keySeparator!==void 0?n.keySeparator:this.options.keySeparator,{key:a,namespaces:l}=this.extractFromKey(t[t.length-1],n),c=l[l.length-1],u=n.lng||this.language,d=n.appendNamespaceToCIMode||this.options.appendNamespaceToCIMode;if(u&&u.toLowerCase()==="cimode"){if(d){const S=n.nsSeparator||this.options.nsSeparator;return s?{res:`${c}${S}${a}`,usedKey:a,exactUsedKey:a,usedLng:u,usedNS:c,usedParams:this.getUsedParamsDetails(n)}:`${c}${S}${a}`}return s?{res:a,usedKey:a,exactUsedKey:a,usedLng:u,usedNS:c,usedParams:this.getUsedParamsDetails(n)}:a}const f=this.resolve(t,n);let p=f&&f.res;const h=f&&f.usedKey||a,v=f&&f.exactUsedKey||a,g=Object.prototype.toString.apply(p),b=["[object Number]","[object Function]","[object RegExp]"],y=n.joinArrays!==void 0?n.joinArrays:this.options.joinArrays,x=!this.i18nFormat||this.i18nFormat.handleAsObject;if(x&&p&&(typeof p!="string"&&typeof p!="boolean"&&typeof p!="number")&&b.indexOf(g)<0&&!(typeof y=="string"&&Array.isArray(p))){if(!n.returnObjects&&!this.options.returnObjects){this.options.returnedObjectHandler||this.logger.warn("accessing an object - but returnObjects options is not enabled!");const S=this.options.returnedObjectHandler?this.options.returnedObjectHandler(h,p,{...n,ns:l}):`key '${a} (${this.language})' returned an object instead of string.`;return s?(f.res=S,f.usedParams=this.getUsedParamsDetails(n),f):S}if(o){const S=Array.isArray(p),E=S?[]:{},C=S?v:h;for(const T in p)if(Object.prototype.hasOwnProperty.call(p,T)){const j=`${C}${o}${T}`;E[T]=this.translate(j,{...n,joinArrays:!1,ns:l}),E[T]===j&&(E[T]=p[T])}p=E}}else if(x&&typeof y=="string"&&Array.isArray(p))p=p.join(y),p&&(p=this.extendTranslation(p,t,n,r));else{let S=!1,E=!1;const C=n.count!==void 0&&typeof n.count!="string",T=Tp.hasDefaultValue(n),j=C?this.pluralResolver.getSuffix(u,n.count,n):"",I=n.ordinal&&C?this.pluralResolver.getSuffix(u,n.count,{ordinal:!1}):"",P=C&&!n.ordinal&&n.count===0&&this.pluralResolver.shouldUseIntlApi(),V=P&&n[`defaultValue${this.options.pluralSeparator}zero`]||n[`defaultValue${j}`]||n[`defaultValue${I}`]||n.defaultValue;!this.isValidLookup(p)&&T&&(S=!0,p=V),this.isValidLookup(p)||(E=!0,p=a);const Z=(n.missingKeyNoValueFallbackToKey||this.options.missingKeyNoValueFallbackToKey)&&E?void 0:p,H=T&&V!==p&&this.options.updateMissing;if(E||S||H){if(this.logger.log(H?"updateKey":"missingKey",u,c,a,H?V:p),o){const L=this.resolve(a,{...n,keySeparator:!1});L&&L.res&&this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.")}let K=[];const Y=this.languageUtils.getFallbackCodes(this.options.fallbackLng,n.lng||this.language);if(this.options.saveMissingTo==="fallback"&&Y&&Y[0])for(let L=0;L{const ue=T&&Q!==p?Q:Z;this.options.missingKeyHandler?this.options.missingKeyHandler(L,c,F,ue,H,n):this.backendConnector&&this.backendConnector.saveMissing&&this.backendConnector.saveMissing(L,c,F,ue,H,n),this.emit("missingKey",L,c,F,p)};this.options.saveMissing&&(this.options.saveMissingPlurals&&C?K.forEach(L=>{const F=this.pluralResolver.getSuffixes(L,n);P&&n[`defaultValue${this.options.pluralSeparator}zero`]&&F.indexOf(`${this.options.pluralSeparator}zero`)<0&&F.push(`${this.options.pluralSeparator}zero`),F.forEach(Q=>{G([L],a+Q,n[`defaultValue${Q}`]||V)})}):G(K,a,V))}p=this.extendTranslation(p,t,n,f,r),E&&p===a&&this.options.appendNamespaceToMissingKey&&(p=`${c}:${a}`),(E||S)&&this.options.parseMissingKeyHandler&&(this.options.compatibilityAPI!=="v1"?p=this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey?`${c}:${a}`:a,S?p:void 0):p=this.options.parseMissingKeyHandler(p))}return s?(f.res=p,f.usedParams=this.getUsedParamsDetails(n),f):p}extendTranslation(t,n,r,s,o){var a=this;if(this.i18nFormat&&this.i18nFormat.parse)t=this.i18nFormat.parse(t,{...this.options.interpolation.defaultVariables,...r},r.lng||this.language||s.usedLng,s.usedNS,s.usedKey,{resolved:s});else if(!r.skipInterpolation){r.interpolation&&this.interpolator.init({...r,interpolation:{...this.options.interpolation,...r.interpolation}});const u=typeof t=="string"&&(r&&r.interpolation&&r.interpolation.skipOnVariables!==void 0?r.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables);let d;if(u){const p=t.match(this.interpolator.nestingRegexp);d=p&&p.length}let f=r.replace&&typeof r.replace!="string"?r.replace:r;if(this.options.interpolation.defaultVariables&&(f={...this.options.interpolation.defaultVariables,...f}),t=this.interpolator.interpolate(t,f,r.lng||this.language||s.usedLng,r),u){const p=t.match(this.interpolator.nestingRegexp),h=p&&p.length;d1&&arguments[1]!==void 0?arguments[1]:{},r,s,o,a,l;return typeof t=="string"&&(t=[t]),t.forEach(c=>{if(this.isValidLookup(r))return;const u=this.extractFromKey(c,n),d=u.key;s=d;let f=u.namespaces;this.options.fallbackNS&&(f=f.concat(this.options.fallbackNS));const p=n.count!==void 0&&typeof n.count!="string",h=p&&!n.ordinal&&n.count===0&&this.pluralResolver.shouldUseIntlApi(),v=n.context!==void 0&&(typeof n.context=="string"||typeof n.context=="number")&&n.context!=="",g=n.lngs?n.lngs:this.languageUtils.toResolveHierarchy(n.lng||this.language,n.fallbackLng);f.forEach(b=>{this.isValidLookup(r)||(l=b,!Z1[`${g[0]}-${b}`]&&this.utils&&this.utils.hasLoadedNamespace&&!this.utils.hasLoadedNamespace(l)&&(Z1[`${g[0]}-${b}`]=!0,this.logger.warn(`key "${s}" for languages "${g.join(", ")}" won't get resolved as namespace "${l}" was not yet loaded`,"This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!")),g.forEach(y=>{if(this.isValidLookup(r))return;a=y;const x=[d];if(this.i18nFormat&&this.i18nFormat.addLookupKeys)this.i18nFormat.addLookupKeys(x,d,y,b,n);else{let S;p&&(S=this.pluralResolver.getSuffix(y,n.count,n));const E=`${this.options.pluralSeparator}zero`,C=`${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;if(p&&(x.push(d+S),n.ordinal&&S.indexOf(C)===0&&x.push(d+S.replace(C,this.options.pluralSeparator)),h&&x.push(d+E)),v){const T=`${d}${this.options.contextSeparator}${n.context}`;x.push(T),p&&(x.push(T+S),n.ordinal&&S.indexOf(C)===0&&x.push(T+S.replace(C,this.options.pluralSeparator)),h&&x.push(T+E))}}let w;for(;w=x.pop();)this.isValidLookup(r)||(o=w,r=this.getResource(y,b,w,n))}))})}),{res:r,usedKey:s,exactUsedKey:o,usedLng:a,usedNS:l}}isValidLookup(t){return t!==void 0&&!(!this.options.returnNull&&t===null)&&!(!this.options.returnEmptyString&&t==="")}getResource(t,n,r){let s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};return this.i18nFormat&&this.i18nFormat.getResource?this.i18nFormat.getResource(t,n,r,s):this.resourceStore.getResource(t,n,r,s)}getUsedParamsDetails(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const n=["defaultValue","ordinal","context","replace","lng","lngs","fallbackLng","ns","keySeparator","nsSeparator","returnObjects","returnDetails","joinArrays","postProcess","interpolation"],r=t.replace&&typeof t.replace!="string";let s=r?t.replace:t;if(r&&typeof t.count<"u"&&(s.count=t.count),this.options.interpolation.defaultVariables&&(s={...this.options.interpolation.defaultVariables,...s}),!r){s={...s};for(const o of n)delete s[o]}return s}static hasDefaultValue(t){const n="defaultValue";for(const r in t)if(Object.prototype.hasOwnProperty.call(t,r)&&n===r.substring(0,n.length)&&t[r]!==void 0)return!0;return!1}}const gm=e=>e.charAt(0).toUpperCase()+e.slice(1);class Q1{constructor(t){this.options=t,this.supportedLngs=this.options.supportedLngs||!1,this.logger=gs.create("languageUtils")}getScriptPartFromCode(t){if(t=Ep(t),!t||t.indexOf("-")<0)return null;const n=t.split("-");return n.length===2||(n.pop(),n[n.length-1].toLowerCase()==="x")?null:this.formatLanguageCode(n.join("-"))}getLanguagePartFromCode(t){if(t=Ep(t),!t||t.indexOf("-")<0)return t;const n=t.split("-");return this.formatLanguageCode(n[0])}formatLanguageCode(t){if(typeof t=="string"&&t.indexOf("-")>-1){const n=["hans","hant","latn","cyrl","cans","mong","arab"];let r=t.split("-");return this.options.lowerCaseLng?r=r.map(s=>s.toLowerCase()):r.length===2?(r[0]=r[0].toLowerCase(),r[1]=r[1].toUpperCase(),n.indexOf(r[1].toLowerCase())>-1&&(r[1]=gm(r[1].toLowerCase()))):r.length===3&&(r[0]=r[0].toLowerCase(),r[1].length===2&&(r[1]=r[1].toUpperCase()),r[0]!=="sgn"&&r[2].length===2&&(r[2]=r[2].toUpperCase()),n.indexOf(r[1].toLowerCase())>-1&&(r[1]=gm(r[1].toLowerCase())),n.indexOf(r[2].toLowerCase())>-1&&(r[2]=gm(r[2].toLowerCase()))),r.join("-")}return this.options.cleanCode||this.options.lowerCaseLng?t.toLowerCase():t}isSupportedCode(t){return(this.options.load==="languageOnly"||this.options.nonExplicitSupportedLngs)&&(t=this.getLanguagePartFromCode(t)),!this.supportedLngs||!this.supportedLngs.length||this.supportedLngs.indexOf(t)>-1}getBestMatchFromCodes(t){if(!t)return null;let n;return t.forEach(r=>{if(n)return;const s=this.formatLanguageCode(r);(!this.options.supportedLngs||this.isSupportedCode(s))&&(n=s)}),!n&&this.options.supportedLngs&&t.forEach(r=>{if(n)return;const s=this.getLanguagePartFromCode(r);if(this.isSupportedCode(s))return n=s;n=this.options.supportedLngs.find(o=>{if(o===s)return o;if(!(o.indexOf("-")<0&&s.indexOf("-")<0)&&(o.indexOf("-")>0&&s.indexOf("-")<0&&o.substring(0,o.indexOf("-"))===s||o.indexOf(s)===0&&s.length>1))return o})}),n||(n=this.getFallbackCodes(this.options.fallbackLng)[0]),n}getFallbackCodes(t,n){if(!t)return[];if(typeof t=="function"&&(t=t(n)),typeof t=="string"&&(t=[t]),Array.isArray(t))return t;if(!n)return t.default||[];let r=t[n];return r||(r=t[this.getScriptPartFromCode(n)]),r||(r=t[this.formatLanguageCode(n)]),r||(r=t[this.getLanguagePartFromCode(n)]),r||(r=t.default),r||[]}toResolveHierarchy(t,n){const r=this.getFallbackCodes(n||this.options.fallbackLng||[],t),s=[],o=a=>{a&&(this.isSupportedCode(a)?s.push(a):this.logger.warn(`rejecting language code not found in supportedLngs: ${a}`))};return typeof t=="string"&&(t.indexOf("-")>-1||t.indexOf("_")>-1)?(this.options.load!=="languageOnly"&&o(this.formatLanguageCode(t)),this.options.load!=="languageOnly"&&this.options.load!=="currentOnly"&&o(this.getScriptPartFromCode(t)),this.options.load!=="currentOnly"&&o(this.getLanguagePartFromCode(t))):typeof t=="string"&&o(this.formatLanguageCode(t)),r.forEach(a=>{s.indexOf(a)<0&&o(this.formatLanguageCode(a))}),s}}let LY=[{lngs:["ach","ak","am","arn","br","fil","gun","ln","mfe","mg","mi","oc","pt","pt-BR","tg","tl","ti","tr","uz","wa"],nr:[1,2],fc:1},{lngs:["af","an","ast","az","bg","bn","ca","da","de","dev","el","en","eo","es","et","eu","fi","fo","fur","fy","gl","gu","ha","hi","hu","hy","ia","it","kk","kn","ku","lb","mai","ml","mn","mr","nah","nap","nb","ne","nl","nn","no","nso","pa","pap","pms","ps","pt-PT","rm","sco","se","si","so","son","sq","sv","sw","ta","te","tk","ur","yo"],nr:[1,2],fc:2},{lngs:["ay","bo","cgg","fa","ht","id","ja","jbo","ka","km","ko","ky","lo","ms","sah","su","th","tt","ug","vi","wo","zh"],nr:[1],fc:3},{lngs:["be","bs","cnr","dz","hr","ru","sr","uk"],nr:[1,2,5],fc:4},{lngs:["ar"],nr:[0,1,2,3,11,100],fc:5},{lngs:["cs","sk"],nr:[1,2,5],fc:6},{lngs:["csb","pl"],nr:[1,2,5],fc:7},{lngs:["cy"],nr:[1,2,3,8],fc:8},{lngs:["fr"],nr:[1,2],fc:9},{lngs:["ga"],nr:[1,2,3,7,11],fc:10},{lngs:["gd"],nr:[1,2,3,20],fc:11},{lngs:["is"],nr:[1,2],fc:12},{lngs:["jv"],nr:[0,1],fc:13},{lngs:["kw"],nr:[1,2,3,4],fc:14},{lngs:["lt"],nr:[1,2,10],fc:15},{lngs:["lv"],nr:[1,2,0],fc:16},{lngs:["mk"],nr:[1,2],fc:17},{lngs:["mnk"],nr:[0,1,2],fc:18},{lngs:["mt"],nr:[1,2,11,20],fc:19},{lngs:["or"],nr:[2,1],fc:2},{lngs:["ro"],nr:[1,2,20],fc:20},{lngs:["sl"],nr:[5,1,2,3],fc:21},{lngs:["he","iw"],nr:[1,2,20,21],fc:22}],$Y={1:e=>+(e>1),2:e=>+(e!=1),3:e=>0,4:e=>e%10==1&&e%100!=11?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2,5:e=>e==0?0:e==1?1:e==2?2:e%100>=3&&e%100<=10?3:e%100>=11?4:5,6:e=>e==1?0:e>=2&&e<=4?1:2,7:e=>e==1?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2,8:e=>e==1?0:e==2?1:e!=8&&e!=11?2:3,9:e=>+(e>=2),10:e=>e==1?0:e==2?1:e<7?2:e<11?3:4,11:e=>e==1||e==11?0:e==2||e==12?1:e>2&&e<20?2:3,12:e=>+(e%10!=1||e%100==11),13:e=>+(e!==0),14:e=>e==1?0:e==2?1:e==3?2:3,15:e=>e%10==1&&e%100!=11?0:e%10>=2&&(e%100<10||e%100>=20)?1:2,16:e=>e%10==1&&e%100!=11?0:e!==0?1:2,17:e=>e==1||e%10==1&&e%100!=11?0:1,18:e=>e==0?0:e==1?1:2,19:e=>e==1?0:e==0||e%100>1&&e%100<11?1:e%100>10&&e%100<20?2:3,20:e=>e==1?0:e==0||e%100>0&&e%100<20?1:2,21:e=>e%100==1?1:e%100==2?2:e%100==3||e%100==4?3:0,22:e=>e==1?0:e==2?1:(e<0||e>10)&&e%10==0?2:3};const BY=["v1","v2","v3"],zY=["v4"],Y1={zero:0,one:1,two:2,few:3,many:4,other:5},UY=()=>{const e={};return LY.forEach(t=>{t.lngs.forEach(n=>{e[n]={numbers:t.nr,plurals:$Y[t.fc]}})}),e};class VY{constructor(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.languageUtils=t,this.options=n,this.logger=gs.create("pluralResolver"),(!this.options.compatibilityJSON||zY.includes(this.options.compatibilityJSON))&&(typeof Intl>"u"||!Intl.PluralRules)&&(this.options.compatibilityJSON="v3",this.logger.error("Your environment seems not to be Intl API compatible, use an Intl.PluralRules polyfill. Will fallback to the compatibilityJSON v3 format handling.")),this.rules=UY(),this.pluralRulesCache={}}addRule(t,n){this.rules[t]=n}clearCache(){this.pluralRulesCache={}}getRule(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(this.shouldUseIntlApi())try{const r=Ep(t==="dev"?"en":t),s=n.ordinal?"ordinal":"cardinal",o=JSON.stringify({cleanedCode:r,type:s});if(o in this.pluralRulesCache)return this.pluralRulesCache[o];const a=new Intl.PluralRules(r,{type:s});return this.pluralRulesCache[o]=a,a}catch{return}return this.rules[t]||this.rules[this.languageUtils.getLanguagePartFromCode(t)]}needsPlural(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const r=this.getRule(t,n);return this.shouldUseIntlApi()?r&&r.resolvedOptions().pluralCategories.length>1:r&&r.numbers.length>1}getPluralFormsOfKey(t,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return this.getSuffixes(t,r).map(s=>`${n}${s}`)}getSuffixes(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const r=this.getRule(t,n);return r?this.shouldUseIntlApi()?r.resolvedOptions().pluralCategories.sort((s,o)=>Y1[s]-Y1[o]).map(s=>`${this.options.prepend}${n.ordinal?`ordinal${this.options.prepend}`:""}${s}`):r.numbers.map(s=>this.getSuffix(t,s,n)):[]}getSuffix(t,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const s=this.getRule(t,r);return s?this.shouldUseIntlApi()?`${this.options.prepend}${r.ordinal?`ordinal${this.options.prepend}`:""}${s.select(n)}`:this.getSuffixRetroCompatible(s,n):(this.logger.warn(`no plural rule found for: ${t}`),"")}getSuffixRetroCompatible(t,n){const r=t.noAbs?t.plurals(n):t.plurals(Math.abs(n));let s=t.numbers[r];this.options.simplifyPluralSuffix&&t.numbers.length===2&&t.numbers[0]===1&&(s===2?s="plural":s===1&&(s=""));const o=()=>this.options.prepend&&s.toString()?this.options.prepend+s.toString():s.toString();return this.options.compatibilityJSON==="v1"?s===1?"":typeof s=="number"?`_plural_${s.toString()}`:o():this.options.compatibilityJSON==="v2"||this.options.simplifyPluralSuffix&&t.numbers.length===2&&t.numbers[0]===1?o():this.options.prepend&&r.toString()?this.options.prepend+r.toString():r.toString()}shouldUseIntlApi(){return!BY.includes(this.options.compatibilityJSON)}}const X1=function(e,t,n){let r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:".",s=arguments.length>4&&arguments[4]!==void 0?arguments[4]:!0,o=NY(e,t,n);return!o&&s&&typeof n=="string"&&(o=ay(e,n,r),o===void 0&&(o=ay(t,n,r))),o},hm=e=>e.replace(/\$/g,"$$$$");class HY{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.logger=gs.create("interpolator"),this.options=t,this.format=t.interpolation&&t.interpolation.format||(n=>n),this.init(t)}init(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};t.interpolation||(t.interpolation={escapeValue:!0});const{escape:n,escapeValue:r,useRawValueToEscape:s,prefix:o,prefixEscaped:a,suffix:l,suffixEscaped:c,formatSeparator:u,unescapeSuffix:d,unescapePrefix:f,nestingPrefix:p,nestingPrefixEscaped:h,nestingSuffix:v,nestingSuffixEscaped:g,nestingOptionsSeparator:b,maxReplaces:y,alwaysFormat:x}=t.interpolation;this.escape=n!==void 0?n:OY,this.escapeValue=r!==void 0?r:!0,this.useRawValueToEscape=s!==void 0?s:!1,this.prefix=o?wi(o):a||"{{",this.suffix=l?wi(l):c||"}}",this.formatSeparator=u||",",this.unescapePrefix=d?"":f||"-",this.unescapeSuffix=this.unescapePrefix?"":d||"",this.nestingPrefix=p?wi(p):h||wi("$t("),this.nestingSuffix=v?wi(v):g||wi(")"),this.nestingOptionsSeparator=b||",",this.maxReplaces=y||1e3,this.alwaysFormat=x!==void 0?x:!1,this.resetRegExp()}reset(){this.options&&this.init(this.options)}resetRegExp(){const t=(n,r)=>n&&n.source===r?(n.lastIndex=0,n):new RegExp(r,"g");this.regexp=t(this.regexp,`${this.prefix}(.+?)${this.suffix}`),this.regexpUnescape=t(this.regexpUnescape,`${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`),this.nestingRegexp=t(this.nestingRegexp,`${this.nestingPrefix}(.+?)${this.nestingSuffix}`)}interpolate(t,n,r,s){let o,a,l;const c=this.options&&this.options.interpolation&&this.options.interpolation.defaultVariables||{},u=h=>{if(h.indexOf(this.formatSeparator)<0){const y=X1(n,c,h,this.options.keySeparator,this.options.ignoreJSONStructure);return this.alwaysFormat?this.format(y,void 0,r,{...s,...n,interpolationkey:h}):y}const v=h.split(this.formatSeparator),g=v.shift().trim(),b=v.join(this.formatSeparator).trim();return this.format(X1(n,c,g,this.options.keySeparator,this.options.ignoreJSONStructure),b,r,{...s,...n,interpolationkey:g})};this.resetRegExp();const d=s&&s.missingInterpolationHandler||this.options.missingInterpolationHandler,f=s&&s.interpolation&&s.interpolation.skipOnVariables!==void 0?s.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables;return[{regex:this.regexpUnescape,safeValue:h=>hm(h)},{regex:this.regexp,safeValue:h=>this.escapeValue?hm(this.escape(h)):hm(h)}].forEach(h=>{for(l=0;o=h.regex.exec(t);){const v=o[1].trim();if(a=u(v),a===void 0)if(typeof d=="function"){const b=d(t,o,s);a=typeof b=="string"?b:""}else if(s&&Object.prototype.hasOwnProperty.call(s,v))a="";else if(f){a=o[0];continue}else this.logger.warn(`missed to pass in variable ${v} for interpolating ${t}`),a="";else typeof a!="string"&&!this.useRawValueToEscape&&(a=W1(a));const g=h.safeValue(a);if(t=t.replace(o[0],g),f?(h.regex.lastIndex+=a.length,h.regex.lastIndex-=o[0].length):h.regex.lastIndex=0,l++,l>=this.maxReplaces)break}}),t}nest(t,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},s,o,a;const l=(c,u)=>{const d=this.nestingOptionsSeparator;if(c.indexOf(d)<0)return c;const f=c.split(new RegExp(`${d}[ ]*{`));let p=`{${f[1]}`;c=f[0],p=this.interpolate(p,a);const h=p.match(/'/g),v=p.match(/"/g);(h&&h.length%2===0&&!v||v.length%2!==0)&&(p=p.replace(/'/g,'"'));try{a=JSON.parse(p),u&&(a={...u,...a})}catch(g){return this.logger.warn(`failed parsing options string in nesting for key ${c}`,g),`${c}${d}${p}`}return a.defaultValue&&a.defaultValue.indexOf(this.prefix)>-1&&delete a.defaultValue,c};for(;s=this.nestingRegexp.exec(t);){let c=[];a={...r},a=a.replace&&typeof a.replace!="string"?a.replace:a,a.applyPostProcessor=!1,delete a.defaultValue;let u=!1;if(s[0].indexOf(this.formatSeparator)!==-1&&!/{.*}/.test(s[1])){const d=s[1].split(this.formatSeparator).map(f=>f.trim());s[1]=d.shift(),c=d,u=!0}if(o=n(l.call(this,s[1].trim(),a),a),o&&s[0]===t&&typeof o!="string")return o;typeof o!="string"&&(o=W1(o)),o||(this.logger.warn(`missed to resolve ${s[1]} for nesting ${t}`),o=""),u&&(o=c.reduce((d,f)=>this.format(d,f,r.lng,{...r,interpolationkey:s[1].trim()}),o.trim())),t=t.replace(s[0],o),this.regexp.lastIndex=0}return t}}const WY=e=>{let t=e.toLowerCase().trim();const n={};if(e.indexOf("(")>-1){const r=e.split("(");t=r[0].toLowerCase().trim();const s=r[1].substring(0,r[1].length-1);t==="currency"&&s.indexOf(":")<0?n.currency||(n.currency=s.trim()):t==="relativetime"&&s.indexOf(":")<0?n.range||(n.range=s.trim()):s.split(";").forEach(a=>{if(a){const[l,...c]=a.split(":"),u=c.join(":").trim().replace(/^'+|'+$/g,""),d=l.trim();n[d]||(n[d]=u),u==="false"&&(n[d]=!1),u==="true"&&(n[d]=!0),isNaN(u)||(n[d]=parseInt(u,10))}})}return{formatName:t,formatOptions:n}},Si=e=>{const t={};return(n,r,s)=>{let o=s;s&&s.interpolationkey&&s.formatParams&&s.formatParams[s.interpolationkey]&&s[s.interpolationkey]&&(o={...o,[s.interpolationkey]:void 0});const a=r+JSON.stringify(o);let l=t[a];return l||(l=e(Ep(r),s),t[a]=l),l(n)}};class GY{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.logger=gs.create("formatter"),this.options=t,this.formats={number:Si((n,r)=>{const s=new Intl.NumberFormat(n,{...r});return o=>s.format(o)}),currency:Si((n,r)=>{const s=new Intl.NumberFormat(n,{...r,style:"currency"});return o=>s.format(o)}),datetime:Si((n,r)=>{const s=new Intl.DateTimeFormat(n,{...r});return o=>s.format(o)}),relativetime:Si((n,r)=>{const s=new Intl.RelativeTimeFormat(n,{...r});return o=>s.format(o,r.range||"day")}),list:Si((n,r)=>{const s=new Intl.ListFormat(n,{...r});return o=>s.format(o)})},this.init(t)}init(t){const r=(arguments.length>1&&arguments[1]!==void 0?arguments[1]:{interpolation:{}}).interpolation;this.formatSeparator=r.formatSeparator?r.formatSeparator:r.formatSeparator||","}add(t,n){this.formats[t.toLowerCase().trim()]=n}addCached(t,n){this.formats[t.toLowerCase().trim()]=Si(n)}format(t,n,r){let s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};const o=n.split(this.formatSeparator);if(o.length>1&&o[0].indexOf("(")>1&&o[0].indexOf(")")<0&&o.find(l=>l.indexOf(")")>-1)){const l=o.findIndex(c=>c.indexOf(")")>-1);o[0]=[o[0],...o.splice(1,l)].join(this.formatSeparator)}return o.reduce((l,c)=>{const{formatName:u,formatOptions:d}=WY(c);if(this.formats[u]){let f=l;try{const p=s&&s.formatParams&&s.formatParams[s.interpolationkey]||{},h=p.locale||p.lng||s.locale||s.lng||r;f=this.formats[u](l,h,{...d,...s,...p})}catch(p){this.logger.warn(p)}return f}else this.logger.warn(`there was no format function for ${u}`);return l},t)}}const qY=(e,t)=>{e.pending[t]!==void 0&&(delete e.pending[t],e.pendingCount--)};class KY extends Gg{constructor(t,n,r){let s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};super(),this.backend=t,this.store=n,this.services=r,this.languageUtils=r.languageUtils,this.options=s,this.logger=gs.create("backendConnector"),this.waitingReads=[],this.maxParallelReads=s.maxParallelReads||10,this.readingCalls=0,this.maxRetries=s.maxRetries>=0?s.maxRetries:5,this.retryTimeout=s.retryTimeout>=1?s.retryTimeout:350,this.state={},this.queue=[],this.backend&&this.backend.init&&this.backend.init(r,s.backend,s)}queueLoad(t,n,r,s){const o={},a={},l={},c={};return t.forEach(u=>{let d=!0;n.forEach(f=>{const p=`${u}|${f}`;!r.reload&&this.store.hasResourceBundle(u,f)?this.state[p]=2:this.state[p]<0||(this.state[p]===1?a[p]===void 0&&(a[p]=!0):(this.state[p]=1,d=!1,a[p]===void 0&&(a[p]=!0),o[p]===void 0&&(o[p]=!0),c[f]===void 0&&(c[f]=!0)))}),d||(l[u]=!0)}),(Object.keys(o).length||Object.keys(a).length)&&this.queue.push({pending:a,pendingCount:Object.keys(a).length,loaded:{},errors:[],callback:s}),{toLoad:Object.keys(o),pending:Object.keys(a),toLoadLanguages:Object.keys(l),toLoadNamespaces:Object.keys(c)}}loaded(t,n,r){const s=t.split("|"),o=s[0],a=s[1];n&&this.emit("failedLoading",o,a,n),!n&&r&&this.store.addResourceBundle(o,a,r,void 0,void 0,{skipCopy:!0}),this.state[t]=n?-1:2,n&&r&&(this.state[t]=0);const l={};this.queue.forEach(c=>{IY(c.loaded,[o],a),qY(c,t),n&&c.errors.push(n),c.pendingCount===0&&!c.done&&(Object.keys(c.loaded).forEach(u=>{l[u]||(l[u]={});const d=c.loaded[u];d.length&&d.forEach(f=>{l[u][f]===void 0&&(l[u][f]=!0)})}),c.done=!0,c.errors.length?c.callback(c.errors):c.callback())}),this.emit("loaded",l),this.queue=this.queue.filter(c=>!c.done)}read(t,n,r){let s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0,o=arguments.length>4&&arguments[4]!==void 0?arguments[4]:this.retryTimeout,a=arguments.length>5?arguments[5]:void 0;if(!t.length)return a(null,{});if(this.readingCalls>=this.maxParallelReads){this.waitingReads.push({lng:t,ns:n,fcName:r,tried:s,wait:o,callback:a});return}this.readingCalls++;const l=(u,d)=>{if(this.readingCalls--,this.waitingReads.length>0){const f=this.waitingReads.shift();this.read(f.lng,f.ns,f.fcName,f.tried,f.wait,f.callback)}if(u&&d&&s{this.read.call(this,t,n,r,s+1,o*2,a)},o);return}a(u,d)},c=this.backend[r].bind(this.backend);if(c.length===2){try{const u=c(t,n);u&&typeof u.then=="function"?u.then(d=>l(null,d)).catch(l):l(null,u)}catch(u){l(u)}return}return c(t,n,l)}prepareLoading(t,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},s=arguments.length>3?arguments[3]:void 0;if(!this.backend)return this.logger.warn("No backend was added via i18next.use. Will not load resources."),s&&s();typeof t=="string"&&(t=this.languageUtils.toResolveHierarchy(t)),typeof n=="string"&&(n=[n]);const o=this.queueLoad(t,n,r,s);if(!o.toLoad.length)return o.pending.length||s(),null;o.toLoad.forEach(a=>{this.loadOne(a)})}load(t,n,r){this.prepareLoading(t,n,{},r)}reload(t,n,r){this.prepareLoading(t,n,{reload:!0},r)}loadOne(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"";const r=t.split("|"),s=r[0],o=r[1];this.read(s,o,"read",void 0,void 0,(a,l)=>{a&&this.logger.warn(`${n}loading namespace ${o} for language ${s} failed`,a),!a&&l&&this.logger.log(`${n}loaded namespace ${o} for language ${s}`,l),this.loaded(t,a,l)})}saveMissing(t,n,r,s,o){let a=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{},l=arguments.length>6&&arguments[6]!==void 0?arguments[6]:()=>{};if(this.services.utils&&this.services.utils.hasLoadedNamespace&&!this.services.utils.hasLoadedNamespace(n)){this.logger.warn(`did not save key "${r}" as the namespace "${n}" was not yet loaded`,"This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");return}if(!(r==null||r==="")){if(this.backend&&this.backend.create){const c={...a,isUpdate:o},u=this.backend.create.bind(this.backend);if(u.length<6)try{let d;u.length===5?d=u(t,n,r,s,c):d=u(t,n,r,s),d&&typeof d.then=="function"?d.then(f=>l(null,f)).catch(l):l(null,d)}catch(d){l(d)}else u(t,n,r,s,l,c)}!t||!t[0]||this.store.addResource(t[0],n,r,s)}}}const eC=()=>({debug:!1,initImmediate:!0,ns:["translation"],defaultNS:["translation"],fallbackLng:["dev"],fallbackNS:!1,supportedLngs:!1,nonExplicitSupportedLngs:!1,load:"all",preload:!1,simplifyPluralSuffix:!0,keySeparator:".",nsSeparator:":",pluralSeparator:"_",contextSeparator:"_",partialBundledLanguages:!1,saveMissing:!1,updateMissing:!1,saveMissingTo:"fallback",saveMissingPlurals:!0,missingKeyHandler:!1,missingInterpolationHandler:!1,postProcess:!1,postProcessPassResolved:!1,returnNull:!1,returnEmptyString:!0,returnObjects:!1,joinArrays:!1,returnedObjectHandler:!1,parseMissingKeyHandler:!1,appendNamespaceToMissingKey:!1,appendNamespaceToCIMode:!1,overloadTranslationOptionHandler:e=>{let t={};if(typeof e[1]=="object"&&(t=e[1]),typeof e[1]=="string"&&(t.defaultValue=e[1]),typeof e[2]=="string"&&(t.tDescription=e[2]),typeof e[2]=="object"||typeof e[3]=="object"){const n=e[3]||e[2];Object.keys(n).forEach(r=>{t[r]=n[r]})}return t},interpolation:{escapeValue:!0,format:e=>e,prefix:"{{",suffix:"}}",formatSeparator:",",unescapePrefix:"-",nestingPrefix:"$t(",nestingSuffix:")",nestingOptionsSeparator:",",maxReplaces:1e3,skipOnVariables:!0}}),tC=e=>(typeof e.ns=="string"&&(e.ns=[e.ns]),typeof e.fallbackLng=="string"&&(e.fallbackLng=[e.fallbackLng]),typeof e.fallbackNS=="string"&&(e.fallbackNS=[e.fallbackNS]),e.supportedLngs&&e.supportedLngs.indexOf("cimode")<0&&(e.supportedLngs=e.supportedLngs.concat(["cimode"])),e),qd=()=>{},JY=e=>{Object.getOwnPropertyNames(Object.getPrototypeOf(e)).forEach(n=>{typeof e[n]=="function"&&(e[n]=e[n].bind(e))})};class Au extends Gg{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(super(),this.options=tC(t),this.services={},this.logger=gs,this.modules={external:[]},JY(this),n&&!this.isInitialized&&!t.isClone){if(!this.options.initImmediate)return this.init(t,n),this;setTimeout(()=>{this.init(t,n)},0)}}init(){var t=this;let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;this.isInitializing=!0,typeof n=="function"&&(r=n,n={}),!n.defaultNS&&n.defaultNS!==!1&&n.ns&&(typeof n.ns=="string"?n.defaultNS=n.ns:n.ns.indexOf("translation")<0&&(n.defaultNS=n.ns[0]));const s=eC();this.options={...s,...this.options,...tC(n)},this.options.compatibilityAPI!=="v1"&&(this.options.interpolation={...s.interpolation,...this.options.interpolation}),n.keySeparator!==void 0&&(this.options.userDefinedKeySeparator=n.keySeparator),n.nsSeparator!==void 0&&(this.options.userDefinedNsSeparator=n.nsSeparator);const o=d=>d?typeof d=="function"?new d:d:null;if(!this.options.isClone){this.modules.logger?gs.init(o(this.modules.logger),this.options):gs.init(null,this.options);let d;this.modules.formatter?d=this.modules.formatter:typeof Intl<"u"&&(d=GY);const f=new Q1(this.options);this.store=new J1(this.options.resources,this.options);const p=this.services;p.logger=gs,p.resourceStore=this.store,p.languageUtils=f,p.pluralResolver=new VY(f,{prepend:this.options.pluralSeparator,compatibilityJSON:this.options.compatibilityJSON,simplifyPluralSuffix:this.options.simplifyPluralSuffix}),d&&(!this.options.interpolation.format||this.options.interpolation.format===s.interpolation.format)&&(p.formatter=o(d),p.formatter.init(p,this.options),this.options.interpolation.format=p.formatter.format.bind(p.formatter)),p.interpolator=new HY(this.options),p.utils={hasLoadedNamespace:this.hasLoadedNamespace.bind(this)},p.backendConnector=new KY(o(this.modules.backend),p.resourceStore,p,this.options),p.backendConnector.on("*",function(h){for(var v=arguments.length,g=new Array(v>1?v-1:0),b=1;b1?v-1:0),b=1;b{h.init&&h.init(this)})}if(this.format=this.options.interpolation.format,r||(r=qd),this.options.fallbackLng&&!this.services.languageDetector&&!this.options.lng){const d=this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);d.length>0&&d[0]!=="dev"&&(this.options.lng=d[0])}!this.services.languageDetector&&!this.options.lng&&this.logger.warn("init: no languageDetector is used and no lng is defined"),["getResource","hasResourceBundle","getResourceBundle","getDataByLanguage"].forEach(d=>{this[d]=function(){return t.store[d](...arguments)}}),["addResource","addResources","addResourceBundle","removeResourceBundle"].forEach(d=>{this[d]=function(){return t.store[d](...arguments),t}});const c=pc(),u=()=>{const d=(f,p)=>{this.isInitializing=!1,this.isInitialized&&!this.initializedStoreOnce&&this.logger.warn("init: i18next is already initialized. You should call init just once!"),this.isInitialized=!0,this.options.isClone||this.logger.log("initialized",this.options),this.emit("initialized",this.options),c.resolve(p),r(f,p)};if(this.languages&&this.options.compatibilityAPI!=="v1"&&!this.isInitialized)return d(null,this.t.bind(this));this.changeLanguage(this.options.lng,d)};return this.options.resources||!this.options.initImmediate?u():setTimeout(u,0),c}loadResources(t){let r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:qd;const s=typeof t=="string"?t:this.language;if(typeof t=="function"&&(r=t),!this.options.resources||this.options.partialBundledLanguages){if(s&&s.toLowerCase()==="cimode"&&(!this.options.preload||this.options.preload.length===0))return r();const o=[],a=l=>{if(!l||l==="cimode")return;this.services.languageUtils.toResolveHierarchy(l).forEach(u=>{u!=="cimode"&&o.indexOf(u)<0&&o.push(u)})};s?a(s):this.services.languageUtils.getFallbackCodes(this.options.fallbackLng).forEach(c=>a(c)),this.options.preload&&this.options.preload.forEach(l=>a(l)),this.services.backendConnector.load(o,this.options.ns,l=>{!l&&!this.resolvedLanguage&&this.language&&this.setResolvedLanguage(this.language),r(l)})}else r(null)}reloadResources(t,n,r){const s=pc();return typeof t=="function"&&(r=t,t=void 0),typeof n=="function"&&(r=n,n=void 0),t||(t=this.languages),n||(n=this.options.ns),r||(r=qd),this.services.backendConnector.reload(t,n,o=>{s.resolve(),r(o)}),s}use(t){if(!t)throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");if(!t.type)throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");return t.type==="backend"&&(this.modules.backend=t),(t.type==="logger"||t.log&&t.warn&&t.error)&&(this.modules.logger=t),t.type==="languageDetector"&&(this.modules.languageDetector=t),t.type==="i18nFormat"&&(this.modules.i18nFormat=t),t.type==="postProcessor"&&QP.addPostProcessor(t),t.type==="formatter"&&(this.modules.formatter=t),t.type==="3rdParty"&&this.modules.external.push(t),this}setResolvedLanguage(t){if(!(!t||!this.languages)&&!(["cimode","dev"].indexOf(t)>-1))for(let n=0;n-1)&&this.store.hasLanguageSomeTranslations(r)){this.resolvedLanguage=r;break}}}changeLanguage(t,n){var r=this;this.isLanguageChangingTo=t;const s=pc();this.emit("languageChanging",t);const o=c=>{this.language=c,this.languages=this.services.languageUtils.toResolveHierarchy(c),this.resolvedLanguage=void 0,this.setResolvedLanguage(c)},a=(c,u)=>{u?(o(u),this.translator.changeLanguage(u),this.isLanguageChangingTo=void 0,this.emit("languageChanged",u),this.logger.log("languageChanged",u)):this.isLanguageChangingTo=void 0,s.resolve(function(){return r.t(...arguments)}),n&&n(c,function(){return r.t(...arguments)})},l=c=>{!t&&!c&&this.services.languageDetector&&(c=[]);const u=typeof c=="string"?c:this.services.languageUtils.getBestMatchFromCodes(c);u&&(this.language||o(u),this.translator.language||this.translator.changeLanguage(u),this.services.languageDetector&&this.services.languageDetector.cacheUserLanguage&&this.services.languageDetector.cacheUserLanguage(u)),this.loadResources(u,d=>{a(d,u)})};return!t&&this.services.languageDetector&&!this.services.languageDetector.async?l(this.services.languageDetector.detect()):!t&&this.services.languageDetector&&this.services.languageDetector.async?this.services.languageDetector.detect.length===0?this.services.languageDetector.detect().then(l):this.services.languageDetector.detect(l):l(t),s}getFixedT(t,n,r){var s=this;const o=function(a,l){let c;if(typeof l!="object"){for(var u=arguments.length,d=new Array(u>2?u-2:0),f=2;f`${c.keyPrefix}${p}${v}`):h=c.keyPrefix?`${c.keyPrefix}${p}${a}`:a,s.t(h,c)};return typeof t=="string"?o.lng=t:o.lngs=t,o.ns=n,o.keyPrefix=r,o}t(){return this.translator&&this.translator.translate(...arguments)}exists(){return this.translator&&this.translator.exists(...arguments)}setDefaultNamespace(t){this.options.defaultNS=t}hasLoadedNamespace(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!this.isInitialized)return this.logger.warn("hasLoadedNamespace: i18next was not initialized",this.languages),!1;if(!this.languages||!this.languages.length)return this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty",this.languages),!1;const r=n.lng||this.resolvedLanguage||this.languages[0],s=this.options?this.options.fallbackLng:!1,o=this.languages[this.languages.length-1];if(r.toLowerCase()==="cimode")return!0;const a=(l,c)=>{const u=this.services.backendConnector.state[`${l}|${c}`];return u===-1||u===0||u===2};if(n.precheck){const l=n.precheck(this,a);if(l!==void 0)return l}return!!(this.hasResourceBundle(r,t)||!this.services.backendConnector.backend||this.options.resources&&!this.options.partialBundledLanguages||a(r,t)&&(!s||a(o,t)))}loadNamespaces(t,n){const r=pc();return this.options.ns?(typeof t=="string"&&(t=[t]),t.forEach(s=>{this.options.ns.indexOf(s)<0&&this.options.ns.push(s)}),this.loadResources(s=>{r.resolve(),n&&n(s)}),r):(n&&n(),Promise.resolve())}loadLanguages(t,n){const r=pc();typeof t=="string"&&(t=[t]);const s=this.options.preload||[],o=t.filter(a=>s.indexOf(a)<0&&this.services.languageUtils.isSupportedCode(a));return o.length?(this.options.preload=s.concat(o),this.loadResources(a=>{r.resolve(),n&&n(a)}),r):(n&&n(),Promise.resolve())}dir(t){if(t||(t=this.resolvedLanguage||(this.languages&&this.languages.length>0?this.languages[0]:this.language)),!t)return"rtl";const n=["ar","shu","sqr","ssh","xaa","yhd","yud","aao","abh","abv","acm","acq","acw","acx","acy","adf","ads","aeb","aec","afb","ajp","apc","apd","arb","arq","ars","ary","arz","auz","avl","ayh","ayl","ayn","ayp","bbz","pga","he","iw","ps","pbt","pbu","pst","prp","prd","ug","ur","ydd","yds","yih","ji","yi","hbo","men","xmn","fa","jpr","peo","pes","prs","dv","sam","ckb"],r=this.services&&this.services.languageUtils||new Q1(eC());return n.indexOf(r.getLanguagePartFromCode(t))>-1||t.toLowerCase().indexOf("-arab")>1?"rtl":"ltr"}static createInstance(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;return new Au(t,n)}cloneInstance(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:qd;const r=t.forkResourceStore;r&&delete t.forkResourceStore;const s={...this.options,...t,isClone:!0},o=new Au(s);return(t.debug!==void 0||t.prefix!==void 0)&&(o.logger=o.logger.clone(t)),["store","services","language"].forEach(l=>{o[l]=this[l]}),o.services={...this.services},o.services.utils={hasLoadedNamespace:o.hasLoadedNamespace.bind(o)},r&&(o.store=new J1(this.store.data,s),o.services.resourceStore=o.store),o.translator=new Tp(o.services,s),o.translator.on("*",function(l){for(var c=arguments.length,u=new Array(c>1?c-1:0),d=1;d{const t=Object.getPrototypeOf(e);return t.prototype&&t.prototype.isReactComponent})()}function WZ(e){return typeof e=="object"&&typeof e.$$typeof=="symbol"&&["react.memo","react.forward_ref"].includes(e.$$typeof.description)}function Ul(e){const t={state:{},onStateChange:()=>{},renderFallbackValue:null,...e},[n]=m.useState(()=>({current:LZ(t)})),[r,s]=m.useState(()=>n.current.initialState);return n.current.setOptions(o=>({...o,...e,state:{...r,...e.state},onStateChange:a=>{s(a),e.onStateChange==null||e.onStateChange(a)}})),n.current}const ri=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{className:"relative w-full overflow-auto",children:i.jsx("table",{ref:n,className:me("w-full caption-bottom text-sm",e),...t})}));ri.displayName="Table";const si=m.forwardRef(({className:e,...t},n)=>i.jsx("thead",{ref:n,className:me("[&_tr]:border-b",e),...t}));si.displayName="TableHeader";const oi=m.forwardRef(({className:e,...t},n)=>i.jsx("tbody",{ref:n,className:me("[&_tr:last-child]:border-0",e),...t}));oi.displayName="TableBody";const GZ=m.forwardRef(({className:e,...t},n)=>i.jsx("tfoot",{ref:n,className:me("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",e),...t}));GZ.displayName="TableFooter";const en=m.forwardRef(({className:e,...t},n)=>i.jsx("tr",{ref:n,className:me("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",e),...t}));en.displayName="TableRow";const ai=m.forwardRef(({className:e,...t},n)=>i.jsx("th",{ref:n,className:me("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",e),...t}));ai.displayName="TableHead";const ir=m.forwardRef(({className:e,...t},n)=>i.jsx("td",{ref:n,className:me("p-4 align-middle [&:has([role=checkbox])]:pr-0",e),...t}));ir.displayName="TableCell";const qZ=m.forwardRef(({className:e,...t},n)=>i.jsx("caption",{ref:n,className:me("mt-4 text-sm text-muted-foreground",e),...t}));qZ.displayName="TableCaption";const T1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await JJ(e.name,r,n);t(s)}else console.error("Token not found.")}catch(r){console.error("Errors:",r)}};function DP({difyId:e}){var h,v;const{t}=Le(),{instance:n}=st(),[r,s]=m.useState([]),[o,a]=m.useState([]),[l,c]=m.useState(!1);m.useEffect(()=>{l&&T1(n,a,e)},[n,e,l]);function u(){T1(n,a,e)}const d=async(g,b)=>{var y,x,w;try{if(!n)return;await ZJ(n.name,n.token,g,b),X.success(t("dify.toast.success.status")),u()}catch(S){console.error("Error:",S),X.error(`Error : ${(w=(x=(y=S==null?void 0:S.response)==null?void 0:y.data)==null?void 0:x.response)==null?void 0:w.message}`)}},f=[{accessorKey:"remoteJid",header:()=>i.jsx("div",{className:"text-center",children:t("dify.sessions.table.remoteJid")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>i.jsx("div",{className:"text-center",children:t("dify.sessions.table.pushName")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("pushName")})},{accessorKey:"sessionId",header:()=>i.jsx("div",{className:"text-center",children:t("dify.sessions.table.sessionId")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("sessionId")})},{accessorKey:"status",header:()=>i.jsx("div",{className:"text-center",children:t("dify.sessions.table.status")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:g})=>{const b=g.original;return i.jsxs(to,{children:[i.jsx(no,{asChild:!0,children:i.jsxs(J,{variant:"ghost",className:"h-8 w-8 p-0",children:[i.jsx("span",{className:"sr-only",children:t("dify.sessions.table.actions.title")}),i.jsx(Sl,{className:"h-4 w-4"})]})}),i.jsxs(Qr,{align:"end",children:[i.jsx(ei,{children:t("dify.sessions.table.actions.title")}),i.jsx(ra,{}),b.status!=="opened"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"opened"),children:[i.jsx(Ku,{className:"mr-2 h-4 w-4"}),t("dify.sessions.table.actions.open")]}),b.status!=="paused"&&b.status!=="closed"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"paused"),children:[i.jsx(qu,{className:"mr-2 h-4 w-4"}),t("dify.sessions.table.actions.pause")]}),b.status!=="closed"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"closed"),children:[i.jsx(Hu,{className:"mr-2 h-4 w-4"}),t("dify.sessions.table.actions.close")]}),i.jsxs(at,{onClick:()=>d(b.remoteJid,"delete"),children:[i.jsx(Wu,{className:"mr-2 h-4 w-4"}),t("dify.sessions.table.actions.delete")]})]})]})}}],p=Ul({data:o,columns:f,onSortingChange:s,getCoreRowModel:Ll(),getPaginationRowModel:Bl(),getSortedRowModel:zl(),getFilteredRowModel:$l(),state:{sorting:r}});return i.jsxs(yt,{open:l,onOpenChange:c,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{variant:"secondary",size:"sm",children:[i.jsx(Gu,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("dify.sessions.label")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:u,children:[i.jsx(gt,{children:i.jsx(At,{children:t("dify.sessions.label")})}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[i.jsx(A,{placeholder:t("dify.sessions.search"),value:((h=p.getColumn("remoteJid"))==null?void 0:h.getFilterValue())??"",onChange:g=>{var b;return(b=p.getColumn("remoteJid"))==null?void 0:b.setFilterValue(g.target.value)}}),i.jsx(J,{variant:"outline",onClick:u,size:"icon",children:i.jsx(Ju,{})})]}),i.jsxs(ri,{children:[i.jsx(si,{children:p.getHeaderGroups().map(g=>i.jsx(en,{children:g.headers.map(b=>i.jsx(ai,{children:b.isPlaceholder?null:Rr(b.column.columnDef.header,b.getContext())},b.id))},g.id))}),i.jsx(oi,{children:(v=p.getRowModel().rows)!=null&&v.length?p.getRowModel().rows.map(g=>i.jsx(en,{"data-state":g.getIsSelected()&&"selected",children:g.getVisibleCells().map(b=>i.jsx(ir,{children:Rr(b.column.columnDef.cell,b.getContext())},b.id))},g.id)):i.jsx(en,{children:i.jsx(ir,{colSpan:f.length,className:"h-24 text-center",children:t("dify.sessions.table.none")})})})]})]})]})]})}const KZ=k.object({enabled:k.boolean(),description:k.string(),botType:k.string(),apiUrl:k.string(),apiKey:k.string(),triggerType:k.string(),triggerOperator:k.string().optional(),triggerValue:k.string().optional(),expire:k.coerce.number(),keywordFinish:k.string(),delayMessage:k.coerce.number(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.coerce.number()});function JZ({difyId:e,instance:t,resetTable:n}){const{t:r}=Le(),[,s]=m.useState(""),[o,a]=m.useState(!0),[l,c]=m.useState(!1),u=En(),d=kt({resolver:Et(KZ),defaultValues:{enabled:!0,description:"",botType:"chatBot",apiUrl:"",apiKey:"",triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:0,keywordFinish:"",delayMessage:0,unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:0}});m.useEffect(()=>{(async()=>{try{const b=localStorage.getItem("token");if(b&&t&&t.name&&e){s(b);const y=await VJ(t.name,b,e);d.reset({enabled:y.enabled,description:y.description,botType:y.botType,apiUrl:y.apiUrl,apiKey:y.apiKey,triggerType:y.triggerType,triggerOperator:y.triggerOperator,triggerValue:y.triggerValue,expire:y.expire,keywordFinish:y.keywordFinish,delayMessage:y.delayMessage,unknownMessage:y.unknownMessage,listeningFromMe:y.listeningFromMe,stopBotFromMe:y.stopBotFromMe,keepOpen:y.keepOpen,debounceTime:y.debounceTime})}else console.error("Token not found.");a(!1)}catch(b){console.error("Error:",b),a(!1)}})()},[d,t,e]);const f=async g=>{var b,y,x;try{const w=localStorage.getItem("token");if(w&&t&&t.name&&e){const S={enabled:g.enabled,description:g.description,botType:g.botType,apiUrl:g.apiUrl,apiKey:g.apiKey,triggerType:g.triggerType,triggerOperator:g.triggerOperator||"",triggerValue:g.triggerValue||"",expire:g.expire,keywordFinish:g.keywordFinish,delayMessage:g.delayMessage,unknownMessage:g.unknownMessage,listeningFromMe:g.listeningFromMe,stopBotFromMe:g.stopBotFromMe,keepOpen:g.keepOpen,debounceTime:g.debounceTime};await WJ(t.name,w,e,S),X.success(r("dify.toast.success.update"))}else console.error("Token not found")}catch(w){console.error("Error:",w),X.error(`Error: ${(x=(y=(b=w==null?void 0:w.response)==null?void 0:b.data)==null?void 0:y.response)==null?void 0:x.message}`)}},p=async()=>{try{const g=localStorage.getItem("token");g&&t&&t.name&&e?(await GJ(t.name,g,e),X.success(r("dify.toast.success.delete")),c(!1),n(),u(`/manager/instance/${t.id}/dify`)):console.error("instance not found")}catch(g){console.error("Erro ao excluir dify:",g)}},h=d.watch("description"),v=d.watch("triggerType");return i.jsxs(i.Fragment,{children:[o&&i.jsx(or,{}),!o&&i.jsx(fr,{...d,children:i.jsxs("form",{onSubmit:d.handleSubmit(f),className:"w-full space-y-6 pl-4 pr-2",children:[i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[i.jsxs("h3",{className:"mb-4 text-lg font-medium",children:["Dify: ",h]}),i.jsx(he,{name:"enabled",className:"flex items-center gap-3"})]}),i.jsxs("div",{className:"space-y-4",children:[i.jsx(D,{name:"description",label:r("dify.form.description.label"),children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("dify.form.difySettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"botType",label:r("dify.form.botType.label"),options:[{label:r("dify.form.botType.chatBot"),value:"chatBot"},{label:r("dify.form.botType.textGenerator"),value:"textGenerator"},{label:r("dify.form.botType.agent"),value:"agent"},{label:r("dify.form.botType.workflow"),value:"workflow"}]}),i.jsx(D,{name:"apiUrl",label:r("dify.form.apiUrl.label"),required:!0,children:i.jsx(A,{})}),i.jsx(D,{name:"apiKey",label:r("dify.form.apiKey.label"),required:!0,children:i.jsx(A,{type:"password"})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("dify.form.triggerSettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"triggerType",label:r("dify.form.triggerType.label"),options:[{label:r("dify.form.triggerType.keyword"),value:"keyword"},{label:r("dify.form.triggerType.all"),value:"all"},{label:r("dify.form.triggerType.advanced"),value:"advanced"},{label:r("dify.form.triggerType.none"),value:"none"}]}),v==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(et,{name:"triggerOperator",label:r("dify.form.triggerOperator.label"),options:[{label:r("dify.form.triggerOperator.contains"),value:"contains"},{label:r("dify.form.triggerOperator.equals"),value:"equals"},{label:r("dify.form.triggerOperator.startsWith"),value:"startsWith"},{label:r("dify.form.triggerOperator.endsWith"),value:"endsWith"},{label:r("dify.form.triggerOperator.regex"),value:"regex"}]}),i.jsx(D,{name:"triggerValue",label:r("dify.form.triggerValue.label"),children:i.jsx(A,{})})]}),v==="advanced"&&i.jsx(D,{name:"triggerValue",label:r("dify.form.triggerConditions.label"),children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("dify.form.generalSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"expire",label:r("dify.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:r("dify.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:r("dify.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:r("dify.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:r("dify.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:r("dify.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:r("dify.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:r("dify.form.debounceTime.label"),children:i.jsx(A,{type:"number"})})]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx(DP,{difyId:e}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs(yt,{open:l,onOpenChange:c,children:[i.jsx(Rt,{asChild:!0,children:i.jsx(J,{variant:"destructive",size:"sm",children:r("dify.button.delete")})}),i.jsx(pt,{children:i.jsxs(gt,{children:[i.jsx(At,{children:r("modal.delete.title")}),i.jsx(ti,{children:r("modal.delete.messageSingle")}),i.jsxs(Jt,{children:[i.jsx(J,{size:"sm",variant:"outline",onClick:()=>c(!1),children:r("button.cancel")}),i.jsx(J,{variant:"destructive",onClick:p,children:r("button.delete")})]})]})})]}),i.jsx(J,{type:"submit",children:r("dify.button.update")})]})]})]})})]})}const j1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await EP(e.name,r);t(s)}else console.error("Token not found");n(!1)}catch(r){console.error("Error:",r),n(!1)}};function _1(){const{t:e}=Le(),t=Fl("(min-width: 768px)"),{instance:n}=st(),{difyId:r}=Ys(),[s,o]=m.useState(!0),[a,l]=m.useState([]),c=En();m.useEffect(()=>{n&&j1(n,l,o)},[n]);const u=f=>{n&&c(`/manager/instance/${n.id}/dify/${f}`)},d=()=>{j1(n,l,o)};return i.jsxs("main",{className:"pt-5",children:[i.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[i.jsx("h3",{className:"text-lg font-medium",children:e("dify.title")}),i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[i.jsx(DP,{}),i.jsx(YJ,{}),i.jsx(eZ,{resetTable:d})]})]}),i.jsx(Ze,{className:"my-4"}),i.jsxs(Dl,{direction:t?"horizontal":"vertical",children:[i.jsx(_r,{defaultSize:35,className:"pr-4",children:i.jsx("div",{className:"flex flex-col gap-3",children:s?i.jsx(or,{}):i.jsx(i.Fragment,{children:a&&a.length>0&&Array.isArray(a)?a.map(f=>i.jsxs(J,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>u(`${f.id}`),variant:r===f.id?"secondary":"outline",children:[i.jsx("h4",{className:"text-base",children:f.description||f.id}),i.jsx("p",{className:"text-sm font-normal text-muted-foreground",children:f.botType})]},f.id)):i.jsx(J,{variant:"link",children:e("dify.table.none")})})})}),r&&i.jsxs(i.Fragment,{children:[i.jsx(Al,{withHandle:!0,className:"border border-border"}),i.jsx(_r,{className:"",children:i.jsx(JZ,{difyId:r,instance:n,resetTable:d})})]})]})]})}const gr=new ur,Wg=async(e,t)=>(await gr.getInstance().get(`/openai/creds/${e}`,{headers:{apikey:t}})).data,ZZ=async(e,t,n)=>(await gr.getInstance().post(`/openai/creds/${e}`,n,{headers:{apikey:t}})).data,QZ=async(e,t)=>(await gr.getInstance().delete(`/openai/creds/${e}/${t}`)).data,AP=async(e,t)=>(await gr.getInstance().get(`/openai/find/${e}`,{headers:{apikey:t}})).data,YZ=async(e,t,n)=>(await gr.getInstance().get(`/openai/fetch/${n}/${e}`,{headers:{apikey:t}})).data,XZ=async(e,t,n)=>(await gr.getInstance().post(`/openai/create/${e}`,n,{headers:{apikey:t}})).data,eQ=async(e,t,n,r)=>(await gr.getInstance().put(`/openai/update/${n}/${e}`,r,{headers:{apikey:t}})).data,tQ=async(e,t,n)=>(await gr.getInstance().delete(`/openai/delete/${n}/${e}`,{headers:{apikey:t}})).data,nQ=async(e,t)=>(await gr.getInstance().get(`/openai/fetchSettings/${e}`,{headers:{apikey:t}})).data,rQ=async(e,t,n)=>(await gr.getInstance().post(`/openai/settings/${e}`,n,{headers:{apikey:t}})).data,sQ=async(e,t,n)=>(await gr.getInstance().get(`/openai/fetchSessions/${n}/${e}`,{headers:{apikey:t}})).data,oQ=async(e,t,n,r)=>(await gr.getInstance().post(`/openai/changeStatus/${e}`,{remoteJid:n,status:r},{headers:{apikey:t}})).data,FP=async(e,t)=>(await gr.getInstance().get(`/openai/getModels/${e}`,{headers:{apikey:t}})).data,aQ=k.object({name:k.string(),apiKey:k.string()}),pm=async(e,t)=>{try{const n=localStorage.getItem("token");if(n&&e&&e.name){const r=await Wg(e.name,n);t(r)}else console.error("Token not found.")}catch(n){console.error("Error:",n)}};function iQ(){var v;const{t:e}=Le(),{instance:t}=st(),[n,r]=m.useState(!1),[s,o]=m.useState([]),[a,l]=m.useState([]),c=kt({resolver:Et(aQ),defaultValues:{name:"",apiKey:""}});m.useEffect(()=>{n&&pm(t,l)},[t,n]);const u=async g=>{var b,y,x;try{if(!t||!t.name)throw new Error("instance not found.");const w={name:g.name,apiKey:g.apiKey};await ZZ(t.name,t.token,w),X.success(e("openai.toast.success.credentialsCreate")),d()}catch(w){console.error("Error:",w),X.error(`Error: ${(x=(y=(b=w==null?void 0:w.response)==null?void 0:b.data)==null?void 0:y.response)==null?void 0:x.message}`)}};function d(){c.reset(),pm(t,l)}const f=async g=>{var b,y,x;try{await QZ(g,t==null?void 0:t.name),X.success(e("openai.toast.success.credentialsDelete")),pm(t,l)}catch(w){console.error("Error:",w),X.error(`Error: ${(x=(y=(b=w==null?void 0:w.response)==null?void 0:b.data)==null?void 0:y.response)==null?void 0:x.message}`)}},p=[{accessorKey:"name",header:({column:g})=>i.jsxs(J,{variant:"ghost",onClick:()=>g.toggleSorting(g.getIsSorted()==="asc"),children:[e("openai.credentials.table.name"),i.jsx(e4,{className:"ml-2 h-4 w-4"})]}),cell:({row:g})=>i.jsx("div",{children:g.getValue("name")})},{accessorKey:"apiKey",header:()=>i.jsx("div",{className:"text-right",children:e("openai.credentials.table.apiKey")}),cell:({row:g})=>i.jsxs("div",{children:[`${g.getValue("apiKey")}`.slice(0,20),"..."]})},{id:"actions",enableHiding:!1,cell:({row:g})=>{const b=g.original;return i.jsxs(to,{children:[i.jsx(no,{asChild:!0,children:i.jsxs(J,{variant:"ghost",className:"h-8 w-8 p-0",children:[i.jsx("span",{className:"sr-only",children:e("openai.credentials.table.actions.title")}),i.jsx(Sl,{className:"h-4 w-4"})]})}),i.jsxs(Qr,{align:"end",children:[i.jsx(ei,{children:e("openai.credentials.table.actions.title")}),i.jsx(ra,{}),i.jsx(at,{onClick:()=>f(b.id),children:e("openai.credentials.table.actions.delete")})]})]})}}],h=Ul({data:a,columns:p,onSortingChange:o,getCoreRowModel:Ll(),getPaginationRowModel:Bl(),getSortedRowModel:zl(),getFilteredRowModel:$l(),state:{sorting:s}});return i.jsxs(yt,{open:n,onOpenChange:r,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{variant:"secondary",size:"sm",children:[i.jsx(v4,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden md:inline",children:e("openai.credentials.title")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:d,children:[i.jsx(gt,{children:i.jsx(At,{children:e("openai.credentials.title")})}),i.jsx(dr,{...c,children:i.jsxs("form",{onSubmit:c.handleSubmit(u),className:"w-full space-y-6",children:[i.jsx("div",{children:i.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[i.jsx(D,{name:"name",label:e("openai.credentials.table.name"),children:i.jsx(A,{})}),i.jsx(D,{name:"apiKey",label:e("openai.credentials.table.apiKey"),children:i.jsx(A,{type:"password"})})]})}),i.jsx(Jt,{children:i.jsx(J,{type:"submit",children:e("openai.button.save")})})]})}),i.jsx(Ze,{}),i.jsx("div",{children:i.jsxs(ri,{children:[i.jsx(si,{children:h.getHeaderGroups().map(g=>i.jsx(en,{children:g.headers.map(b=>i.jsx(ai,{children:b.isPlaceholder?null:Rr(b.column.columnDef.header,b.getContext())},b.id))},g.id))}),i.jsx(oi,{children:(v=h.getRowModel().rows)!=null&&v.length?h.getRowModel().rows.map(g=>i.jsx(en,{"data-state":g.getIsSelected()&&"selected",children:g.getVisibleCells().map(b=>i.jsx(ir,{children:Rr(b.column.columnDef.cell,b.getContext())},b.id))},g.id)):i.jsx(en,{children:i.jsx(ir,{colSpan:p.length,className:"h-24 text-center",children:e("openai.credentials.table.none")})})})]})})]})]})}const lQ=k.object({openaiCredsId:k.string(),expire:k.coerce.number(),keywordFinish:k.string(),delayMessage:k.coerce.number().default(0),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.coerce.number(),speechToText:k.boolean(),ignoreJids:k.array(k.string()).default([]),openaiIdFallback:k.union([k.null(),k.string()]).optional()}),R1=async(e,t,n,r)=>{try{const s=localStorage.getItem("token");if(s&&e&&e.name){const o=await nQ(e.name,s);t(o);const a=await AP(e.name,s);n(a);const l=await Wg(e.name,s);r(l)}else console.error("Token not found")}catch(s){console.error("Error:",s)}};function cQ(){const{t:e}=Le(),{instance:t}=st(),[n,r]=m.useState(!1),[s,o]=m.useState(),[a,l]=m.useState([]),[c,u]=m.useState(),d=kt({resolver:Et(lQ),defaultValues:{openaiCredsId:"",expire:0,keywordFinish:e("openai.form.examples.keywordFinish"),delayMessage:1e3,unknownMessage:e("openai.form.examples.unknownMessage"),listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:0,speechToText:!1,ignoreJids:[],openaiIdFallback:void 0}});m.useEffect(()=>{n&&R1(t,o,l,u)},[t,n]),m.useEffect(()=>{s&&d.reset({openaiCredsId:s.openaiCredsId,expire:(s==null?void 0:s.expire)??0,keywordFinish:s.keywordFinish,delayMessage:s.delayMessage??0,unknownMessage:s.unknownMessage,listeningFromMe:s.listeningFromMe,stopBotFromMe:s.stopBotFromMe,keepOpen:s.keepOpen,debounceTime:s.debounceTime??0,speechToText:s.speechToText,ignoreJids:s.ignoreJids,openaiIdFallback:s.openaiIdFallback})},[s]);const f=async h=>{var v,g,b;try{if(!t||!t.name)throw new Error("instance not found.");const y={openaiCredsId:h.openaiCredsId,expire:h.expire,keywordFinish:h.keywordFinish,delayMessage:h.delayMessage,unknownMessage:h.unknownMessage,listeningFromMe:h.listeningFromMe,stopBotFromMe:h.stopBotFromMe,keepOpen:h.keepOpen,debounceTime:h.debounceTime,speechToText:h.speechToText,openaiIdFallback:h.openaiIdFallback||void 0,ignoreJids:h.ignoreJids};await rQ(t.name,t.token,y),X.success(e("openai.toast.defaultSettings.success"))}catch(y){console.error("Error:",y),X.error(`Error: ${(b=(g=(v=y==null?void 0:y.response)==null?void 0:v.data)==null?void 0:g.response)==null?void 0:b.message}`)}};function p(){R1(t,o,l,u)}return i.jsxs(yt,{open:n,onOpenChange:r,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{variant:"secondary",size:"sm",children:[i.jsx(Za,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden md:inline",children:e("openai.defaultSettings")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:p,children:[i.jsx(gt,{children:i.jsx(At,{children:e("openai.defaultSettings")})}),i.jsx(dr,{...d,children:i.jsxs("form",{className:"w-full space-y-6",onSubmit:d.handleSubmit(f),children:[i.jsx("div",{children:i.jsxs("div",{className:"space-y-4",children:[i.jsx(et,{name:"openaiCredsId",label:e("openai.form.openaiCredsId.label"),options:(c==null?void 0:c.filter(h=>!!h.id).map(h=>({label:h.name?h.name:h.apiKey.substring(0,15)+"...",value:h.id})))||[]}),i.jsx(et,{name:"openaiIdFallback",label:e("openai.form.openaiIdFallback.label"),options:(a==null?void 0:a.filter(h=>!!h.id).map(h=>({label:h.description,value:h.id})))??[]}),i.jsx(D,{name:"expire",label:e("openai.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:e("openai.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:e("openai.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:e("openai.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:e("openai.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:e("openai.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:e("openai.form.keepOpen.label"),reverse:!0}),i.jsx(he,{name:"speechToText",label:e("openai.form.speechToText.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:e("openai.form.debounceTime.label"),children:i.jsx(A,{type:"number"})}),i.jsx(Ml,{name:"ignoreJids",label:e("openai.form.ignoreJids.label"),placeholder:e("openai.form.ignoreJids.placeholder")})]})}),i.jsx(Jt,{children:i.jsx(J,{type:"submit",children:e("openai.button.save")})})]})})]})]})}const uQ=k.object({enabled:k.boolean(),description:k.string(),openaiCredsId:k.string(),botType:k.string(),assistantId:k.string(),functionUrl:k.string(),model:k.string(),systemMessages:k.string(),assistantMessages:k.string(),userMessages:k.string(),maxTokens:k.string(),triggerType:k.string(),triggerOperator:k.string().optional(),triggerValue:k.string().optional(),expire:k.string(),keywordFinish:k.string(),delayMessage:k.string(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.string()});function dQ({resetTable:e}){const{t}=Le(),{instance:n}=st(),[r,s]=m.useState(!1),[o,a]=m.useState(!1),[l,c]=m.useState([]),[u,d]=m.useState([]),f=kt({resolver:Et(uQ),defaultValues:{enabled:!0,description:"",openaiCredsId:"",botType:"assistant",assistantId:"",functionUrl:"",model:"gpt-4o-mini",systemMessages:"",assistantMessages:"",userMessages:"",maxTokens:"300",triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:"0",keywordFinish:"",delayMessage:"0",unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:"0"}});m.useEffect(()=>{o&&(async()=>{try{if(!n)return;const y=await FP(n.name,n.token);c(y);const x=await Wg(n.name,n.token);d(x)}catch(y){console.error("Error:",y)}})()},[n,o]);const p=async b=>{var y,x,w;try{if(!n||!n.name)throw new Error("instance not found.");s(!0);const S={enabled:b.enabled,description:b.description,openaiCredsId:b.openaiCredsId,botType:b.botType,assistantId:b.assistantId,functionUrl:b.functionUrl,model:b.model,systemMessages:[b.systemMessages],assistantMessages:[b.assistantMessages],userMessages:[b.userMessages],maxTokens:parseInt(b.maxTokens,10),triggerType:b.triggerType,triggerOperator:b.triggerOperator||"",triggerValue:b.triggerValue||"",expire:parseInt(b.expire,10),keywordFinish:b.keywordFinish,delayMessage:parseInt(b.delayMessage,10),unknownMessage:b.unknownMessage,listeningFromMe:b.listeningFromMe,stopBotFromMe:b.stopBotFromMe,keepOpen:b.keepOpen,debounceTime:parseInt(b.debounceTime,10)};await XZ(n.name,n.token,S),X.success(t("openai.toast.success.create")),a(!1),h(),e()}catch(S){console.error("Error:",S),X.error(`Error: ${(w=(x=(y=S==null?void 0:S.response)==null?void 0:y.data)==null?void 0:x.response)==null?void 0:w.message}`)}finally{s(!1)}};function h(){f.reset()}const v=f.watch("botType"),g=f.watch("triggerType");return i.jsxs(yt,{open:o,onOpenChange:a,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{size:"sm",children:[i.jsx(Qa,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("openai.button.create")})]})}),i.jsxs(pt,{className:"max-w-xl",onCloseAutoFocus:h,children:[i.jsx(gt,{children:i.jsx(At,{children:t("openai.form.title")})}),i.jsx(dr,{...f,children:i.jsxs("form",{onSubmit:f.handleSubmit(p),className:"w-full space-y-6",children:[i.jsx("div",{children:i.jsxs("div",{className:"space-y-4",children:[i.jsx(he,{name:"enabled",label:t("openai.form.enabled.label"),reverse:!0}),i.jsx(D,{name:"description",label:t("openai.form.description.label"),required:!0,children:i.jsx(A,{})}),i.jsx(et,{name:"openaiCredsId",label:t("openai.form.openaiCredsId.label"),required:!0,options:u.filter(b=>!!b.id).map(b=>({label:b.name?b.name:b.apiKey.substring(0,15)+"...",value:b.id}))}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("openai.form.openaiSettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"botType",label:t("openai.form.botType.label"),required:!0,options:[{label:t("openai.form.botType.assistant"),value:"assistant"},{label:t("openai.form.botType.chatCompletion"),value:"chatCompletion"}]}),v==="assistant"&&i.jsxs(i.Fragment,{children:[i.jsx(D,{name:"assistantId",label:t("openai.form.assistantId.label"),required:!0,children:i.jsx(A,{})}),i.jsx(D,{name:"functionUrl",label:t("openai.form.functionUrl.label"),required:!0,children:i.jsx(A,{})})]}),v==="chatCompletion"&&i.jsxs(i.Fragment,{children:[i.jsx(et,{name:"model",label:t("openai.form.model.label"),required:!0,options:l.map(b=>({label:b.id,value:b.id}))}),i.jsx(D,{name:"systemMessages",label:t("openai.form.systemMessages.label"),children:i.jsx(zs,{})}),i.jsx(D,{name:"assistantMessages",label:t("openai.form.assistantMessages.label"),children:i.jsx(zs,{})}),i.jsx(D,{name:"userMessages",label:t("openai.form.userMessages.label"),children:i.jsx(zs,{})}),i.jsx(D,{name:"maxTokens",label:t("openai.form.maxTokens.label"),children:i.jsx(A,{type:"number"})})]}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("openai.form.triggerSettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"triggerType",label:t("openai.form.triggerType.label"),required:!0,options:[{label:t("openai.form.triggerType.keyword"),value:"keyword"},{label:t("openai.form.triggerType.all"),value:"all"},{label:t("openai.form.triggerType.advanced"),value:"advanced"},{label:t("openai.form.triggerType.none"),value:"none"}]}),g==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(et,{name:"triggerOperator",label:t("openai.form.triggerOperator.label"),required:!0,options:[{label:t("openai.form.triggerOperator.contains"),value:"contains"},{label:t("openai.form.triggerOperator.equals"),value:"equals"},{label:t("openai.form.triggerOperator.startsWith"),value:"startsWith"},{label:t("openai.form.triggerOperator.endsWith"),value:"endsWith"},{label:t("openai.form.triggerOperator.regex"),value:"regex"}]}),i.jsx(D,{name:"triggerValue",label:t("openai.form.triggerValue.label"),required:!0,children:i.jsx(A,{})})]}),g==="advanced"&&i.jsx(D,{name:"triggerValue",label:t("openai.form.triggerConditions.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("openai.form.generalSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"expire",label:t("openai.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:t("openai.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:t("openai.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:t("openai.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:t("openai.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:t("openai.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:t("openai.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:t("openai.form.debounceTime.label"),children:i.jsx(A,{type:"number"})})]})}),i.jsx(Jt,{children:i.jsx(J,{disabled:r,type:"submit",children:t(r?"openai.button.saving":"openai.button.save")})})]})})]})]})}const I1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await sQ(e.name,r,n);t(s)}else console.error("Token not found")}catch(r){console.error("Error:",r)}};function LP({botId:e}){var h,v;const{t}=Le(),{instance:n}=st(),[r,s]=m.useState([]),[o,a]=m.useState([]),[l,c]=m.useState(!1);m.useEffect(()=>{l&&I1(n,a,e)},[n,e,l]);function u(){I1(n,a,e)}const d=async(g,b)=>{var y,x,w;try{if(!n)return;await oQ(n.name,n.token,g,b),X.success(t("openai.toast.success.status")),u()}catch(S){console.error("Error:",S),X.error(`Error : ${(w=(x=(y=S==null?void 0:S.response)==null?void 0:y.data)==null?void 0:x.response)==null?void 0:w.message}`)}},f=[{accessorKey:"remoteJid",header:()=>i.jsx("div",{className:"text-center",children:t("openai.sessions.table.remoteJid")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>i.jsx("div",{className:"text-center",children:t("openai.sessions.table.pushName")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("pushName")})},{accessorKey:"sessionId",header:()=>i.jsx("div",{className:"text-center",children:t("openai.sessions.table.sessionId")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("sessionId")})},{accessorKey:"status",header:()=>i.jsx("div",{className:"text-center",children:t("openai.sessions.table.status")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:g})=>{const b=g.original;return i.jsxs(to,{children:[i.jsx(no,{asChild:!0,children:i.jsxs(J,{variant:"ghost",size:"icon",children:[i.jsx("span",{className:"sr-only",children:t("openai.sessions.table.actions.title")}),i.jsx(Sl,{className:"h-4 w-4"})]})}),i.jsxs(Qr,{align:"end",children:[i.jsx(ei,{children:t("openai.sessions.table.actions.title")}),i.jsx(ra,{}),b.status!=="opened"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"opened"),children:[i.jsx(Ku,{className:"mr-2 h-4 w-4"}),t("openai.sessions.table.actions.open")]}),b.status!=="paused"&&b.status!=="closed"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"paused"),children:[i.jsx(qu,{className:"mr-2 h-4 w-4"}),t("openai.sessions.table.actions.pause")]}),b.status!=="closed"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"closed"),children:[i.jsx(Hu,{className:"mr-2 h-4 w-4"}),t("openai.sessions.table.actions.close")]}),i.jsxs(at,{onClick:()=>d(b.remoteJid,"delete"),children:[i.jsx(Wu,{className:"mr-2 h-4 w-4"}),t("openai.sessions.table.actions.delete")]})]})]})}}],p=Ul({data:o,columns:f,onSortingChange:s,getCoreRowModel:Ll(),getPaginationRowModel:Bl(),getSortedRowModel:zl(),getFilteredRowModel:$l(),state:{sorting:r}});return i.jsxs(yt,{open:l,onOpenChange:c,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{variant:"secondary",size:"sm",children:[i.jsx(Gu,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden md:inline",children:t("openai.sessions.label")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:u,children:[i.jsx(gt,{children:i.jsx(At,{children:t("openai.sessions.label")})}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[i.jsx(A,{placeholder:t("openai.sessions.search"),value:((h=p.getColumn("remoteJid"))==null?void 0:h.getFilterValue())??"",onChange:g=>{var b;return(b=p.getColumn("remoteJid"))==null?void 0:b.setFilterValue(g.target.value)}}),i.jsx(J,{variant:"outline",onClick:u,size:"icon",children:i.jsx(Ju,{size:16})})]}),i.jsxs(ri,{children:[i.jsx(si,{children:p.getHeaderGroups().map(g=>i.jsx(en,{children:g.headers.map(b=>i.jsx(ai,{children:b.isPlaceholder?null:Rr(b.column.columnDef.header,b.getContext())},b.id))},g.id))}),i.jsx(oi,{children:(v=p.getRowModel().rows)!=null&&v.length?p.getRowModel().rows.map(g=>i.jsx(en,{"data-state":g.getIsSelected()&&"selected",children:g.getVisibleCells().map(b=>i.jsx(ir,{children:Rr(b.column.columnDef.cell,b.getContext())},b.id))},g.id)):i.jsx(en,{children:i.jsx(ir,{colSpan:f.length,className:"h-24 text-center",children:t("openai.sessions.table.none")})})})]})]})]})]})}const fQ=k.object({enabled:k.boolean(),description:k.string(),openaiCredsId:k.string(),botType:k.string(),assistantId:k.string(),functionUrl:k.string().optional(),model:k.string(),systemMessages:k.string(),assistantMessages:k.string(),userMessages:k.string(),maxTokens:k.coerce.number(),triggerType:k.string(),triggerOperator:k.string().optional(),triggerValue:k.string().optional(),expire:k.coerce.number(),keywordFinish:k.string(),delayMessage:k.coerce.number(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.coerce.number(),ignoreJids:k.array(k.string()).default([])});function pQ({botId:e,instance:t,resetTable:n}){const{t:r}=Le(),[,s]=m.useState(""),[o,a]=m.useState(!0),[l,c]=m.useState(!1),[u,d]=m.useState([]),[f,p]=m.useState([]),h=En(),v=kt({resolver:Et(fQ),defaultValues:{enabled:!0,description:"",openaiCredsId:"",botType:"assistant",assistantId:"",functionUrl:"",model:"gpt-3.5-turbo",systemMessages:"",assistantMessages:"",userMessages:"",maxTokens:300,triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:0,keywordFinish:"",delayMessage:0,unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:0}});m.useEffect(()=>{const S=async()=>{try{const C=localStorage.getItem("token");if(C&&t&&t.name&&e){s(C);const T=await YZ(t.name,C,e);v.reset({enabled:T.enabled,description:T.description,openaiCredsId:T.openaiCredsId,botType:T.botType,assistantId:T.assistantId,functionUrl:T.functionUrl,model:T.model,systemMessages:T.systemMessages.toString(),assistantMessages:T.assistantMessages.toString(),userMessages:T.userMessages.toString(),maxTokens:T.maxTokens,triggerType:T.triggerType,triggerOperator:T.triggerOperator,triggerValue:T.triggerValue,expire:T.expire,keywordFinish:T.keywordFinish,delayMessage:T.delayMessage,unknownMessage:T.unknownMessage,listeningFromMe:T.listeningFromMe,stopBotFromMe:T.stopBotFromMe,keepOpen:T.keepOpen,debounceTime:T.debounceTime})}else console.error("Token not found.");a(!1)}catch(C){console.error("Error:",C),a(!1)}},E=async()=>{try{if(!t)return;const C=await FP(t.name,t.token);d(C);const T=await Wg(t.name,t.token);p(T)}catch(C){console.error("Error:",C)}};S(),E()},[v,t,e]);const g=async S=>{var E,C,T;try{const j=localStorage.getItem("token");if(j&&t&&t.name&&e){const I={enabled:S.enabled,description:S.description,openaiCredsId:S.openaiCredsId,botType:S.botType,assistantId:S.assistantId,functionUrl:S.functionUrl||"",model:S.model,systemMessages:[S.systemMessages],assistantMessages:[S.assistantMessages],userMessages:[S.userMessages],maxTokens:S.maxTokens,triggerType:S.triggerType,triggerOperator:S.triggerOperator||"",triggerValue:S.triggerValue||"",expire:S.expire,keywordFinish:S.keywordFinish,delayMessage:S.delayMessage,unknownMessage:S.unknownMessage,listeningFromMe:S.listeningFromMe,stopBotFromMe:S.stopBotFromMe,keepOpen:S.keepOpen,debounceTime:S.debounceTime};await eQ(t.name,j,e,I),X.success(r("openai.toast.success.update"))}else console.error("Instance not found")}catch(j){console.error("Error:",j),X.error(`Error: ${(T=(C=(E=j==null?void 0:j.response)==null?void 0:E.data)==null?void 0:C.response)==null?void 0:T.message}`)}},b=async()=>{try{const S=localStorage.getItem("token");S&&t&&t.name&&e?(await tQ(t.name,S,e),X.success(r("openai.toast.success.delete")),c(!1),n(),h(`/manager/instance/${t.id}/openai`)):console.error("Instance not found.")}catch(S){console.error("Error:",S)}},y=v.watch("description"),x=v.watch("botType"),w=v.watch("triggerType");return i.jsxs(i.Fragment,{children:[o&&i.jsx(or,{}),!o&&i.jsx(fr,{...v,children:i.jsxs("form",{onSubmit:v.handleSubmit(g),className:"w-full space-y-6 pl-4 pr-2",children:[i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[i.jsxs("h3",{className:"mb-4 text-lg font-medium",children:["OpenAI: ",y]}),i.jsx(he,{name:"enabled",className:"flex items-center gap-3"})]}),i.jsxs("div",{className:"space-y-4",children:[i.jsx(D,{name:"description",label:r("openai.form.description.label"),required:!0,children:i.jsx(A,{})}),i.jsx(et,{name:"openaiCredsId",label:r("openai.form.openaiCredsId.label"),required:!0,options:f.filter(S=>!!S.id).map(S=>({label:S.name?S.name:S.apiKey.substring(0,15)+"...",value:S.id}))}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("openai.form.openaiSettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"botType",label:r("openai.form.botType.label"),options:[{label:r("openai.form.botType.assistant"),value:"assistant"},{label:r("openai.form.botType.chatCompletion"),value:"chatCompletion"}]}),x==="assistant"&&i.jsxs(i.Fragment,{children:[i.jsx(D,{name:"assistantId",label:r("openai.form.assistantId.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"functionUrl",label:r("openai.form.functionUrl.label"),children:i.jsx(A,{})})]}),x==="chatCompletion"&&i.jsxs(i.Fragment,{children:[i.jsx(et,{name:"model",label:r("openai.form.model.label"),options:u.map(S=>({label:S.id,value:S.id}))}),i.jsx(D,{name:"systemMessages",label:r("openai.form.systemMessages.label"),children:i.jsx(zs,{})}),i.jsx(D,{name:"assistantMessages",label:r("openai.form.assistantMessages.label"),children:i.jsx(zs,{})}),i.jsx(D,{name:"userMessages",label:r("openai.form.userMessages.label"),children:i.jsx(zs,{})}),i.jsx(D,{name:"maxTokens",label:r("openai.form.maxTokens"),children:i.jsx(A,{type:"number"})})]}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("openai.form.triggerSettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"triggerType",label:r("openai.form.triggerType.label"),options:[{label:r("openai.form.triggerType.keyword"),value:"keyword"},{label:r("openai.form.triggerType.all"),value:"all"},{label:r("openai.form.triggerType.advanced"),value:"advanced"},{label:r("openai.form.triggerType.none"),value:"none"}]}),w==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(et,{name:"triggerOperator",label:r("openai.form.triggerOperator.label"),options:[{label:r("openai.form.triggerOperator.contains"),value:"contains"},{label:r("openai.form.triggerOperator.equals"),value:"equals"},{label:r("openai.form.triggerOperator.startsWith"),value:"startsWith"},{label:r("openai.form.triggerOperator.endsWith"),value:"endsWith"},{label:r("openai.form.triggerOperator.regex"),value:"regex"}]}),i.jsx(D,{name:"triggerValue",label:r("openai.form.triggerValue.label"),children:i.jsx(A,{})})]}),w==="advanced"&&i.jsx(D,{name:"triggerValue",label:r("openai.form.triggerConditions.label"),children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("openai.form.generalSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"expire",label:r("openai.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:r("openai.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:r("openai.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:r("openai.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:r("openai.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:r("openai.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:r("openai.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:r("openai.form.debounceTime.label"),children:i.jsx(A,{type:"number"})})]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx(LP,{botId:e}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs(yt,{open:l,onOpenChange:c,children:[i.jsx(Rt,{asChild:!0,children:i.jsx(J,{variant:"destructive",size:"sm",children:r("openai.button.delete")})}),i.jsx(pt,{children:i.jsxs(gt,{children:[i.jsx(At,{children:r("modal.delete.title")}),i.jsx(ti,{children:r("modal.delete.messageSingle")}),i.jsxs(Jt,{children:[i.jsx(J,{size:"sm",variant:"outline",onClick:()=>c(!1),children:r("button.cancel")}),i.jsx(J,{variant:"destructive",onClick:b,children:r("button.delete")})]})]})})]}),i.jsx(J,{type:"submit",children:r("openai.button.update")})]})]})]})})]})}const N1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await AP(e.name,r);t(s)}else console.error("Token ou nome da instância não encontrados.");n(!1)}catch(r){console.error("Erro ao carregar configurações:",r),n(!1)}};function P1(){const{t:e}=Le(),t=Fl("(min-width: 768px)"),{instance:n}=st(),{botId:r}=Ys(),[s,o]=m.useState(!0),[a,l]=m.useState([]),c=En();m.useEffect(()=>{n&&N1(n,l,o)},[n]);const u=f=>{n&&c(`/manager/instance/${n.id}/openai/${f}`)},d=()=>{N1(n,l,o)};return i.jsxs("main",{className:"pt-5",children:[i.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[i.jsx("h3",{className:"text-lg font-medium",children:e("openai.title")}),i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[i.jsx(LP,{}),i.jsx(cQ,{}),i.jsx(iQ,{}),i.jsx(dQ,{resetTable:d})]})]}),i.jsx(Ze,{className:"my-4"}),i.jsxs(Dl,{direction:t?"horizontal":"vertical",children:[i.jsx(_r,{defaultSize:35,className:"pr-4",children:i.jsx("div",{className:"flex flex-col gap-3",children:s?i.jsx(or,{}):i.jsx(i.Fragment,{children:a&&a.length>0&&Array.isArray(a)?a.map(f=>i.jsxs(J,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>u(`${f.id}`),variant:r===f.id?"secondary":"outline",children:[i.jsx("h4",{className:"text-base",children:f.description||f.id}),i.jsx("p",{className:"text-sm font-normal text-muted-foreground",children:f.botType})]},f.id)):i.jsx(J,{variant:"link",children:e("openai.table.none")})})})}),r&&i.jsxs(i.Fragment,{children:[i.jsx(Al,{withHandle:!0,className:"border border-border"}),i.jsx(_r,{className:"",children:i.jsx(pQ,{botId:r,instance:n,resetTable:d})})]})]})]})}const $P=new ur,gQ=async(e,t)=>(await $P.getInstance().get(`/proxy/find/${e}`,{headers:{apikey:t}})).data,hQ=async(e,t,n)=>(await $P.getInstance().post(`/proxy/set/${e}`,n,{headers:{apikey:t}})).data,mQ=k.object({enabled:k.boolean(),host:k.string(),port:k.string(),protocol:k.string(),username:k.string(),password:k.string()});function vQ(){const{t:e}=Le(),{instance:t}=st(),[n,r]=m.useState(!1),s=kt({resolver:Et(mQ),defaultValues:{enabled:!1,host:"",port:"",protocol:"http",username:"",password:""}});m.useEffect(()=>{(async()=>{if(t){r(!0);try{const l=await gQ(t.name,t.token);s.reset(l)}catch(l){console.error("Error:",l)}finally{r(!1)}}})()},[t,s]);const o=async a=>{var l,c,u;if(t){r(!0);try{const d={enabled:a.enabled,host:a.host,port:a.port,protocol:a.protocol,username:a.username,password:a.password};await hQ(t.name,t.token,d),X.success(e("proxy.toast.success"))}catch(d){console.error(e("proxy.toast.error"),d),X.error(`Error : ${(u=(c=(l=d==null?void 0:d.response)==null?void 0:l.data)==null?void 0:c.response)==null?void 0:u.message}`)}finally{r(!1)}}};return i.jsx(i.Fragment,{children:i.jsx(fr,{...s,children:i.jsx("form",{onSubmit:s.handleSubmit(o),className:"w-full space-y-6",children:i.jsxs("div",{children:[i.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("proxy.title")}),i.jsx(na,{className:"my-4"}),i.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[i.jsx(he,{name:"enabled",label:e("proxy.form.enabled.label"),className:"w-full justify-between",helper:e("proxy.form.enabled.description")}),i.jsxs("div",{className:"grid gap-4 sm:grid-cols-[10rem_1fr_10rem] md:gap-8",children:[i.jsx(D,{name:"protocol",label:e("proxy.form.protocol.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"host",label:e("proxy.form.host.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"port",label:e("proxy.form.port.label"),children:i.jsx(A,{type:"number"})})]}),i.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 md:gap-8",children:[i.jsx(D,{name:"username",label:e("proxy.form.username.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"password",label:e("proxy.form.password.label"),children:i.jsx(A,{type:"password"})})]}),i.jsx("div",{className:"flex justify-end px-4 pt-6",children:i.jsx(J,{type:"submit",disabled:n,children:e(n?"proxy.button.saving":"proxy.button.save")})})]})]})})})})}const BP=new ur,yQ=async(e,t)=>(await BP.getInstance().get(`/rabbitmq/find/${e}`,{headers:{apikey:t}})).data,bQ=async(e,t,n)=>(await BP.getInstance().post(`/rabbitmq/set/${e}`,n,{headers:{apikey:t}})).data,xQ=k.object({enabled:k.boolean(),events:k.array(k.string())});function wQ(){const{t:e}=Le(),{instance:t}=st(),[n,r]=m.useState(!1),s=kt({resolver:Et(xQ),defaultValues:{enabled:!1,events:[]}});m.useEffect(()=>{(async()=>{if(t){r(!0);try{const c=await yQ(t.name,t.token);s.reset(c)}catch(c){console.error("Error:",c)}finally{r(!1)}}})()},[t,s]);const o=async l=>{var c,u,d;if(t){r(!0);try{const f={enabled:l.enabled,events:l.events};await bQ(t.name,t.token,f),X.success(e("rabbitmq.toast.success"))}catch(f){console.error(e("rabbitmq.toast.error"),f),X.error(`Error: ${(d=(u=(c=f==null?void 0:f.response)==null?void 0:c.data)==null?void 0:u.response)==null?void 0:d.message}`)}finally{r(!1)}}},a=["APPLICATION_STARTUP","QRCODE_UPDATED","MESSAGES_SET","MESSAGES_UPSERT","MESSAGES_UPDATE","MESSAGES_DELETE","SEND_MESSAGE","CONTACTS_SET","CONTACTS_UPSERT","CONTACTS_UPDATE","PRESENCE_UPDATE","CHATS_SET","CHATS_UPSERT","CHATS_UPDATE","CHATS_DELETE","GROUPS_UPSERT","GROUP_UPDATE","GROUP_PARTICIPANTS_UPDATE","CONNECTION_UPDATE","REMOVE_INSTANCE","LOGOUT_INSTANCE","LABELS_EDIT","LABELS_ASSOCIATION","CALL","TYPEBOT_START","TYPEBOT_CHANGE_STATUS"];return i.jsx(i.Fragment,{children:i.jsx(fr,{...s,children:i.jsx("form",{onSubmit:s.handleSubmit(o),className:"w-full space-y-6",children:i.jsxs("div",{children:[i.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("rabbitmq.title")}),i.jsx(na,{className:"my-4"}),i.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[i.jsx(he,{name:"enabled",label:e("rabbitmq.form.enabled.label"),className:"w-full justify-between",helper:e("rabbitmq.form.enabled.description")}),i.jsx(aa,{control:s.control,name:"events",render:({field:l})=>i.jsxs(so,{className:"flex flex-col",children:[i.jsx(sr,{className:"my-2 text-lg",children:e("rabbitmq.form.events.label")}),i.jsx(Ss,{children:i.jsx("div",{className:"flex flex-col gap-2 space-y-1 divide-y",children:a.sort((c,u)=>c.localeCompare(u)).map(c=>i.jsxs("div",{className:"flex items-center justify-between gap-3 pt-3",children:[i.jsx(sr,{className:me("break-all",l.value.includes(c)?"text-foreground":"text-muted-foreground"),children:c}),i.jsx(Ol,{checked:l.value.includes(c),onCheckedChange:u=>{u?l.onChange([...l.value,c]):l.onChange(l.value.filter(d=>d!==c))}})]},c))})})]})})]}),i.jsx("div",{className:"mx-4 flex justify-end pt-6",children:i.jsx(J,{type:"submit",disabled:n,children:e(n?"rabbitmq.button.saving":"rabbitmq.button.save")})})]})})})})}const SQ=k.object({rejectCall:k.boolean(),msgCall:k.string().optional(),groupsIgnore:k.boolean(),alwaysOnline:k.boolean(),readMessages:k.boolean(),syncFullHistory:k.boolean(),readStatus:k.boolean()});function CQ(){const{t:e}=Le(),[t,n]=m.useState(!0),[r,s]=m.useState(!1),[o,a]=m.useState(""),{instance:l}=st(),c=kt({resolver:Et(SQ),defaultValues:{rejectCall:!1,msgCall:"",groupsIgnore:!1,alwaysOnline:!1,readMessages:!1,syncFullHistory:!1,readStatus:!1}});m.useEffect(()=>{(async()=>{try{if(l&&l.name&&l.token){a(l.token);const h=await _4(l.name,l.token);c.reset({rejectCall:h.rejectCall,msgCall:h.msgCall||"",groupsIgnore:h.groupsIgnore,alwaysOnline:h.alwaysOnline,readMessages:h.readMessages,syncFullHistory:h.syncFullHistory,readStatus:h.readStatus})}else console.error("token not found");n(!1)}catch(h){console.error("Error:",h),n(!1)}})()},[c,l]);const u=async p=>{try{if(!l||!l.name)throw new Error("instance not found");s(!0);const h={rejectCall:p.rejectCall,msgCall:p.msgCall,groupsIgnore:p.groupsIgnore,alwaysOnline:p.alwaysOnline,readMessages:p.readMessages,syncFullHistory:p.syncFullHistory,readStatus:p.readStatus};await R4(l.name,o,h),X.success(e("settings.toast.success"))}catch(h){console.error(e("settings.toast.success"),h),X.error(e("settings.toast.error"))}finally{s(!1)}},d=[{name:"groupsIgnore",label:e("settings.form.groupsIgnore.label"),description:e("settings.form.groupsIgnore.description")},{name:"alwaysOnline",label:e("settings.form.alwaysOnline.label"),description:e("settings.form.alwaysOnline.description")},{name:"readMessages",label:e("settings.form.readMessages.label"),description:e("settings.form.readMessages.description")},{name:"syncFullHistory",label:e("settings.form.syncFullHistory.label"),description:e("settings.form.syncFullHistory.description")},{name:"readStatus",label:e("settings.form.readStatus.label"),description:e("settings.form.readStatus.description")}],f=c.watch("rejectCall");return t?i.jsx(or,{}):i.jsx(i.Fragment,{children:i.jsx(fr,{...c,children:i.jsx("form",{onSubmit:c.handleSubmit(u),className:"w-full space-y-6",children:i.jsxs("div",{children:[i.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("settings.title")}),i.jsx(Ze,{className:"my-4"}),i.jsxs("div",{className:"mx-4 space-y-2 divide-y",children:[i.jsxs("div",{className:"flex flex-col p-4",children:[i.jsx(he,{name:"rejectCall",label:e("settings.form.rejectCall.label"),className:"w-full justify-between",helper:e("settings.form.rejectCall.description")}),f&&i.jsx("div",{className:"mr-16 mt-2",children:i.jsx(D,{name:"msgCall",children:i.jsx(zs,{placeholder:e("settings.form.msgCall.description")})})})]}),d.map(p=>i.jsx("div",{className:"flex p-4",children:i.jsx(he,{name:p.name,label:p.label,className:"w-full justify-between",helper:p.description})},p.name)),i.jsx("div",{className:"flex justify-end pt-6",children:i.jsx(J,{type:"submit",disabled:r,children:e(r?"settings.button.saving":"settings.button.save")})})]})]})})})})}const zP=new ur,kQ=async(e,t)=>(await zP.getInstance().get(`/sqs/find/${e}`,{headers:{apikey:t}})).data,EQ=async(e,t,n)=>(await zP.getInstance().post(`/sqs/set/${e}`,n,{headers:{apikey:t}})).data,TQ=k.object({enabled:k.boolean(),events:k.array(k.string())});function jQ(){const{t:e}=Le(),{instance:t}=st(),[n,r]=m.useState(!1),s=kt({resolver:Et(TQ),defaultValues:{enabled:!1,events:[]}});m.useEffect(()=>{(async()=>{if(t){r(!0);try{const c=await kQ(t.name,t.token);s.reset(c)}catch(c){console.error("Error",c)}finally{r(!1)}}})()},[t,s]);const o=async l=>{var c,u,d;if(t){r(!0);try{const f={enabled:l.enabled,events:l.events};await EQ(t.name,t.token,f),X.success(e("sqs.toast.success"))}catch(f){console.error(e("sqs.toast.error"),f),X.error(`Error: ${(d=(u=(c=f==null?void 0:f.response)==null?void 0:c.data)==null?void 0:u.response)==null?void 0:d.message}`)}finally{r(!1)}}},a=["APPLICATION_STARTUP","QRCODE_UPDATED","MESSAGES_SET","MESSAGES_UPSERT","MESSAGES_UPDATE","MESSAGES_DELETE","SEND_MESSAGE","CONTACTS_SET","CONTACTS_UPSERT","CONTACTS_UPDATE","PRESENCE_UPDATE","CHATS_SET","CHATS_UPSERT","CHATS_UPDATE","CHATS_DELETE","GROUPS_UPSERT","GROUP_UPDATE","GROUP_PARTICIPANTS_UPDATE","CONNECTION_UPDATE","REMOVE_INSTANCE","LOGOUT_INSTANCE","LABELS_EDIT","LABELS_ASSOCIATION","CALL","TYPEBOT_START","TYPEBOT_CHANGE_STATUS"];return i.jsx(i.Fragment,{children:i.jsx(fr,{...s,children:i.jsx("form",{onSubmit:s.handleSubmit(o),className:"w-full space-y-6",children:i.jsxs("div",{children:[i.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("sqs.title")}),i.jsx(na,{className:"my-4"}),i.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[i.jsx(he,{name:"enabled",label:e("sqs.form.enabled.label"),className:"w-full justify-between",helper:e("sqs.form.enabled.description")}),i.jsx(aa,{control:s.control,name:"events",render:({field:l})=>i.jsxs(so,{className:"flex flex-col",children:[i.jsx(sr,{className:"my-2 text-lg",children:e("sqs.form.events.label")}),i.jsx(Ss,{children:i.jsx("div",{className:"flex flex-col gap-2 space-y-1 divide-y",children:a.sort((c,u)=>c.localeCompare(u)).map(c=>i.jsxs("div",{className:"flex items-center justify-between gap-3 pt-3",children:[i.jsx(sr,{className:me("break-all",l.value.includes(c)?"text-foreground":"text-muted-foreground"),children:c}),i.jsx(Ol,{checked:l.value.includes(c),onCheckedChange:u=>{u?l.onChange([...l.value,c]):l.onChange(l.value.filter(d=>d!==c))}})]},c))})})]})})]}),i.jsx("div",{className:"mx-4 flex justify-end pt-6",children:i.jsx(J,{type:"submit",disabled:n,children:e(n?"sqs.button.saving":"sqs.button.save")})})]})})})})}const ao=new ur,UP=async(e,t)=>(await ao.getInstance().get(`/typebot/find/${e}`,{headers:{apikey:t}})).data,_Q=async(e,t,n)=>(await ao.getInstance().get(`/typebot/fetch/${n}/${e}`,{headers:{apikey:t}})).data,RQ=async(e,t,n)=>(await ao.getInstance().post(`/typebot/create/${e}`,n,{headers:{apikey:t}})).data,IQ=async(e,t,n,r)=>(await ao.getInstance().put(`/typebot/update/${n}/${e}`,r,{headers:{apikey:t}})).data,NQ=async(e,t,n)=>(await ao.getInstance().delete(`/typebot/delete/${n}/${e}`,{headers:{apikey:t}})).data,PQ=async(e,t)=>(await ao.getInstance().get(`/typebot/fetchSettings/${e}`,{headers:{apikey:t}})).data,OQ=async(e,t,n)=>(await ao.getInstance().post(`/typebot/settings/${e}`,n,{headers:{apikey:t}})).data,MQ=async(e,t,n)=>(await ao.getInstance().get(`/typebot/fetchSessions/${n}/${e}`,{headers:{apikey:t}})).data,DQ=async(e,t,n,r)=>(await ao.getInstance().post(`/typebot/changeStatus/${e}`,{remoteJid:n,status:r},{headers:{apikey:t}})).data,AQ=k.object({expire:k.coerce.number(),keywordFinish:k.string(),delayMessage:k.coerce.number(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.coerce.number(),ignoreJids:k.array(k.string()).default([]),typebotIdFallback:k.union([k.null(),k.string()]).optional()}),O1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await PQ(e.name,r);t(s);const o=await UP(e.name,r);n(o)}else console.error("token not found.")}catch(r){console.error("Error:",r)}};function FQ(){const{t:e}=Le(),{instance:t}=st(),[n,r]=m.useState(),[s,o]=m.useState([]),[a,l]=m.useState(!1),c=kt({resolver:Et(AQ),defaultValues:{expire:0,keywordFinish:e("typebot.form.examples.keywordFinish"),delayMessage:1e3,unknownMessage:e("typebot.form.examples.unknownMessage"),listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:0,ignoreJids:[],typebotIdFallback:void 0}});m.useEffect(()=>{a&&O1(t,r,o)},[t,a]),m.useEffect(()=>{n&&c.reset({expire:(n==null?void 0:n.expire)??0,keywordFinish:n.keywordFinish,delayMessage:n.delayMessage??0,unknownMessage:n.unknownMessage,listeningFromMe:n.listeningFromMe,stopBotFromMe:n.stopBotFromMe,keepOpen:n.keepOpen,debounceTime:n.debounceTime??0,ignoreJids:n.ignoreJids,typebotIdFallback:n.typebotIdFallback})},[n]);const u=async f=>{var p,h,v;try{if(!t||!t.name)throw new Error("instance not found.");const g={expire:f.expire,keywordFinish:f.keywordFinish,delayMessage:f.delayMessage,unknownMessage:f.unknownMessage,listeningFromMe:f.listeningFromMe,stopBotFromMe:f.stopBotFromMe,keepOpen:f.keepOpen,debounceTime:f.debounceTime,typebotIdFallback:f.typebotIdFallback||void 0,ignoreJids:f.ignoreJids};await OQ(t.name,t.token,g),X.success(e("typebot.toast.defaultSettings.success"))}catch(g){console.error(e("typebot.toast.defaultSettings.error"),g),X.error(`Error: ${(v=(h=(p=g==null?void 0:g.response)==null?void 0:p.data)==null?void 0:h.response)==null?void 0:v.message}`)}};function d(){O1(t,r,o)}return i.jsxs(yt,{open:a,onOpenChange:l,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{variant:"secondary",size:"sm",children:[i.jsx(Za,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:e("typebot.button.defaultSettings")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:d,children:[i.jsx(gt,{children:i.jsx(At,{children:e("typebot.modal.defaultSettings.title")})}),i.jsx(dr,{...c,children:i.jsxs("form",{className:"w-full space-y-6",onSubmit:c.handleSubmit(u),children:[i.jsx("div",{children:i.jsxs("div",{className:"space-y-4",children:[i.jsx(et,{name:"typebotIdFallback",label:e("typebot.form.typebotIdFallback.label"),options:(s==null?void 0:s.filter(f=>!!f.id).map(f=>({label:f.typebot,value:f.description})))??[]}),i.jsx(D,{name:"expire",label:e("typebot.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:e("typebot.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:e("typebot.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:e("typebot.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:e("typebot.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:e("typebot.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:e("typebot.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:e("typebot.form.debounceTime.label"),children:i.jsx(A,{type:"number"})}),i.jsx(Ml,{name:"ignoreJids",label:e("typebot.form.ignoreJids.label"),placeholder:e("typebot.form.ignoreJids.placeholder")})]})}),i.jsx(Jt,{children:i.jsx(J,{type:"submit",children:e("typebot.button.save")})})]})})]})]})}const LQ=k.object({enabled:k.boolean(),description:k.string(),url:k.string().url(),typebot:k.string(),triggerType:k.string(),triggerOperator:k.string().optional(),triggerValue:k.string().optional(),expire:k.string(),keywordFinish:k.string(),delayMessage:k.string(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.string(),ignoreJids:k.array(k.string()).default([])});function $Q({resetTable:e}){const{t}=Le(),{instance:n}=st(),[r,s]=m.useState(!1),[o,a]=m.useState(!1),l=kt({resolver:Et(LQ),defaultValues:{enabled:!0,description:"",url:"",typebot:"",triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:"0",keywordFinish:"",delayMessage:"0",unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:"0",ignoreJids:[]}}),c=async f=>{var p,h,v;try{if(!n||!n.name)throw new Error("Nome da instância não encontrado.");s(!0);const g={enabled:f.enabled,description:f.description,url:f.url,typebot:f.typebot,triggerType:f.triggerType,triggerOperator:f.triggerOperator||"",triggerValue:f.triggerValue||"",expire:parseInt(f.expire,10),keywordFinish:f.keywordFinish,delayMessage:parseInt(f.delayMessage,10),unknownMessage:f.unknownMessage,listeningFromMe:f.listeningFromMe,stopBotFromMe:f.stopBotFromMe,keepOpen:f.keepOpen,debounceTime:parseInt(f.debounceTime,10)};await RQ(n.name,n.token,g),X.success(t("typebot.toast.success.create")),a(!1),u(),e()}catch(g){console.error(t("typebot.toast.error"),g),X.error(`Error: ${(v=(h=(p=g==null?void 0:g.response)==null?void 0:p.data)==null?void 0:h.response)==null?void 0:v.message}`)}finally{s(!1)}};function u(){l.reset()}const d=l.watch("triggerType");return i.jsxs(yt,{open:o,onOpenChange:a,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{variant:"default",className:"mr-5 text-white",children:[i.jsx(Qa,{}),i.jsx("span",{className:"hidden sm:inline",children:t("typebot.button.create")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:u,children:[i.jsx(gt,{children:i.jsx(At,{children:t("typebot.form.title")})}),i.jsx(dr,{...l,children:i.jsxs("form",{onSubmit:l.handleSubmit(c),className:"w-full space-y-6",children:[i.jsx("div",{children:i.jsxs("div",{className:"space-y-4",children:[i.jsx(he,{name:"enabled",label:t("typebot.form.enabled.label"),reverse:!0}),i.jsx(D,{name:"description",label:t("typebot.form.description.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("typebot.form.typebotSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"url",label:t("typebot.form.url.label"),required:!0,children:i.jsx(A,{})}),i.jsx(D,{name:"typebot",label:t("typebot.form.typebot.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("typebot.form.triggerSettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"triggerType",label:t("typebot.form.triggerType.label"),required:!0,options:[{label:t("typebot.form.triggerType.keyword"),value:"keyword"},{label:t("typebot.form.triggerType.all"),value:"all"},{label:t("typebot.form.triggerType.advanced"),value:"advanced"},{label:t("typebot.form.triggerType.none"),value:"none"}]}),d==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(et,{name:"triggerOperator",label:t("typebot.form.triggerOperator.label"),required:!0,options:[{label:t("typebot.form.triggerOperator.contains"),value:"contains"},{label:t("typebot.form.triggerOperator.equals"),value:"equals"},{label:t("typebot.form.triggerOperator.startsWith"),value:"startsWith"},{label:t("typebot.form.triggerOperator.endsWith"),value:"endsWith"},{label:t("typebot.form.triggerOperator.regex"),value:"regex"}]}),i.jsx(D,{name:"triggerValue",label:t("typebot.form.triggerValue.label"),required:!0,children:i.jsx(A,{})})]}),d==="advanced"&&i.jsx(D,{name:"triggerValue",label:t("typebot.form.triggerConditions.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("typebot.form.generalSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"expire",label:t("typebot.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:t("typebot.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:t("typebot.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:t("typebot.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:t("typebot.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:t("typebot.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:t("typebot.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:t("typebot.form.debounceTime.label"),children:i.jsx(A,{type:"number"})})]})}),i.jsx(Jt,{children:i.jsx(J,{disabled:r,type:"submit",children:t("typebot.button.save")})})]})})]})]})}const M1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await MQ(e.name,r,n);t(s)}else console.error("Token ou nome da instância não encontrados.")}catch(r){console.error("Erro ao carregar sessões:",r)}};function VP({typebotId:e}){var h,v;const{t}=Le(),{instance:n}=st(),[r,s]=m.useState([]),[o,a]=m.useState([]),[l,c]=m.useState(!1);m.useEffect(()=>{l&&M1(n,a,e)},[n,e,l]);function u(){M1(n,a,e)}const d=async(g,b)=>{var y,x,w;try{if(!n)return;await DQ(n.name,n.token,g,b),X.success(t("typebot.toast.success.status")),u()}catch(S){console.error("Error:",S),X.error(`Error : ${(w=(x=(y=S==null?void 0:S.response)==null?void 0:y.data)==null?void 0:x.response)==null?void 0:w.message}`)}},f=[{accessorKey:"remoteJid",header:()=>i.jsx("div",{className:"text-center",children:t("typebot.sessions.table.remoteJid")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>i.jsx("div",{className:"text-center",children:t("typebot.sessions.table.pushName")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("pushName")})},{accessorKey:"sessionId",header:()=>i.jsx("div",{className:"text-center",children:t("typebot.sessions.table.sessionId")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("sessionId")})},{accessorKey:"status",header:()=>i.jsx("div",{className:"text-center",children:t("typebot.sessions.table.status")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:g})=>{const b=g.original;return i.jsxs(to,{children:[i.jsx(no,{asChild:!0,children:i.jsxs(J,{variant:"ghost",className:"h-8 w-8 p-0",children:[i.jsx("span",{className:"sr-only",children:t("typebot.sessions.table.actions.title")}),i.jsx(Sl,{className:"h-4 w-4"})]})}),i.jsxs(Qr,{align:"end",children:[i.jsx(ei,{children:"Actions"}),i.jsx(ra,{}),b.status!=="opened"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"opened"),children:[i.jsx(Ku,{className:"mr-2 h-4 w-4"}),t("typebot.sessions.table.actions.open")]}),b.status!=="paused"&&b.status!=="closed"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"paused"),children:[i.jsx(qu,{className:"mr-2 h-4 w-4"}),t("typebot.sessions.table.actions.pause")]}),b.status!=="closed"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"closed"),children:[i.jsx(Hu,{className:"mr-2 h-4 w-4"}),t("typebot.sessions.table.actions.close")]}),i.jsxs(at,{onClick:()=>d(b.remoteJid,"delete"),children:[i.jsx(Wu,{className:"mr-2 h-4 w-4"}),t("typebot.sessions.table.actions.delete")]})]})]})}}],p=Ul({data:o,columns:f,onSortingChange:s,getCoreRowModel:Ll(),getPaginationRowModel:Bl(),getSortedRowModel:zl(),getFilteredRowModel:$l(),state:{sorting:r}});return i.jsxs(yt,{open:l,onOpenChange:c,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{variant:"secondary",size:"sm",children:[i.jsx(Gu,{size:16,className:"mr-1"})," ",i.jsx("span",{className:"hidden sm:inline",children:t("typebot.sessions.label")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:u,children:[i.jsx(gt,{children:i.jsx(At,{children:t("typebot.sessions.label")})}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[i.jsx(A,{placeholder:t("typebot.sessions.search"),value:((h=p.getColumn("remoteJid"))==null?void 0:h.getFilterValue())??"",onChange:g=>{var b;return(b=p.getColumn("remoteJid"))==null?void 0:b.setFilterValue(g.target.value)}}),i.jsx(J,{variant:"outline",onClick:u,size:"icon",children:i.jsx(Ju,{size:16})})]}),i.jsxs(ri,{children:[i.jsx(si,{children:p.getHeaderGroups().map(g=>i.jsx(en,{children:g.headers.map(b=>i.jsx(ai,{children:b.isPlaceholder?null:Rr(b.column.columnDef.header,b.getContext())},b.id))},g.id))}),i.jsx(oi,{children:(v=p.getRowModel().rows)!=null&&v.length?p.getRowModel().rows.map(g=>i.jsx(en,{"data-state":g.getIsSelected()&&"selected",children:g.getVisibleCells().map(b=>i.jsx(ir,{children:Rr(b.column.columnDef.cell,b.getContext())},b.id))},g.id)):i.jsx(en,{children:i.jsx(ir,{colSpan:f.length,className:"h-24 text-center",children:t("typebot.sessions.table.none")})})})]})]})]})]})}const BQ=k.object({enabled:k.boolean(),description:k.string(),url:k.string().url(),typebot:k.string(),triggerType:k.string(),triggerOperator:k.string().optional(),triggerValue:k.string().optional(),expire:k.coerce.number(),keywordFinish:k.string(),delayMessage:k.coerce.number(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.coerce.number(),ignoreJids:k.array(k.string()).default([])});function zQ({typebotId:e,instance:t,resetTable:n}){const{t:r}=Le(),[,s]=m.useState(""),[o,a]=m.useState(!0),[l,c]=m.useState(!1),u=En(),d=kt({resolver:Et(BQ),defaultValues:{enabled:!0,description:"",url:"",typebot:"",triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:0,keywordFinish:"",delayMessage:0,unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:0,ignoreJids:[]}});m.useEffect(()=>{(async()=>{try{const b=localStorage.getItem("token");if(b&&t&&t.name&&e){s(b);const y=await _Q(t.name,b,e);d.reset({enabled:y.enabled,description:y.description,url:y.url,typebot:y.typebot,triggerType:y.triggerType,triggerOperator:y.triggerOperator,triggerValue:y.triggerValue,expire:y.expire,keywordFinish:y.keywordFinish,delayMessage:y.delayMessage,unknownMessage:y.unknownMessage,listeningFromMe:y.listeningFromMe,stopBotFromMe:y.stopBotFromMe,keepOpen:y.keepOpen,debounceTime:y.debounceTime})}else console.error("Token not found");a(!1)}catch(b){console.error("Error:",b),a(!1)}})()},[d,t,e]);const f=async g=>{var b,y,x;try{const w=localStorage.getItem("token");if(w&&t&&t.name&&e){const S={enabled:g.enabled,description:g.description,url:g.url,typebot:g.typebot,triggerType:g.triggerType,triggerOperator:g.triggerOperator||"",triggerValue:g.triggerValue||"",expire:g.expire,keywordFinish:g.keywordFinish,delayMessage:g.delayMessage,unknownMessage:g.unknownMessage,listeningFromMe:g.listeningFromMe,stopBotFromMe:g.stopBotFromMe,keepOpen:g.keepOpen,debounceTime:g.debounceTime};await IQ(t.name,w,e,S),X.success(r("typebot.toast.success.update"))}else console.error("Token not found")}catch(w){console.error("Error:",w),X.error(`Error: ${(x=(y=(b=w==null?void 0:w.response)==null?void 0:b.data)==null?void 0:y.response)==null?void 0:x.message}`)}},p=async()=>{try{const g=localStorage.getItem("token");g&&t&&t.name&&e?(await NQ(t.name,g,e),X.success(r("typebot.toast.success.delete")),c(!1),n(),u(`/manager/instance/${t.id}/typebot`)):console.error("Token not found")}catch(g){console.error("Error:",g)}},h=d.watch("description"),v=d.watch("triggerType");return i.jsxs(i.Fragment,{children:[o&&i.jsx(or,{}),!o&&i.jsx(fr,{...d,children:i.jsxs("form",{onSubmit:d.handleSubmit(f),className:"w-full space-y-6 pl-4 pr-2",children:[i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[i.jsxs("h3",{className:"mb-4 text-lg font-medium",children:["Typebot: ",h]}),i.jsx(he,{name:"enabled",className:"flex items-center gap-3"})]}),i.jsxs("div",{className:"space-y-4",children:[i.jsx(D,{name:"description",label:r("typebot.form.description.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("typebot.form.typebotSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"url",label:r("typebot.form.url.label"),required:!0,children:i.jsx(A,{})}),i.jsx(D,{name:"typebot",label:r("typebot.form.typebot.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("typebot.form.triggerSettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"triggerType",label:r("typebot.form.triggerType.label"),options:[{label:r("typebot.form.triggerType.keyword"),value:"keyword"},{label:r("typebot.form.triggerType.all"),value:"all"},{label:r("typebot.form.triggerType.advanced"),value:"advanced"},{label:r("typebot.form.triggerType.none"),value:"none"}]}),v==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(et,{name:"triggerOperator",label:r("typebot.form.triggerOperator.label"),options:[{label:r("typebot.form.triggerOperator.contains"),value:"contains"},{label:r("typebot.form.triggerOperator.equals"),value:"equals"},{label:r("typebot.form.triggerOperator.startsWith"),value:"startsWith"},{label:r("typebot.form.triggerOperator.endsWith"),value:"endsWith"},{label:r("typebot.form.triggerOperator.regex"),value:"regex"}]}),i.jsx(D,{name:"triggerValue",label:r("typebot.form.triggerValue.label"),children:i.jsx(A,{})})]}),v==="advanced"&&i.jsx(D,{name:"triggerValue",label:r("typebot.form.triggerConditions.label"),children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("typebot.form.generalSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"expire",label:r("typebot.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:r("typebot.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:r("typebot.form.delay.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:r("typebot.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:r("typebot.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:r("typebot.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:r("typebot.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:r("typebot.form.debounceTime.label"),children:i.jsx(A,{type:"number"})})]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx(VP,{typebotId:e}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs(yt,{open:l,onOpenChange:c,children:[i.jsx(Rt,{asChild:!0,children:i.jsx(J,{variant:"destructive",size:"sm",children:r("typebot.button.delete")})}),i.jsx(pt,{children:i.jsxs(gt,{children:[i.jsx(At,{children:r("modal.delete.title")}),i.jsx(ti,{children:r("modal.delete.messageSingle")}),i.jsxs(Jt,{children:[i.jsx(J,{size:"sm",variant:"outline",onClick:()=>c(!1),children:r("button.cancel")}),i.jsx(J,{variant:"destructive",onClick:p,children:r("button.delete")})]})]})})]}),i.jsx(J,{type:"submit",children:r("typebot.button.update")})]})]})]})})]})}const D1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await UP(e.name,r);t(s)}else console.error("token not found.");n(!1)}catch(r){console.error("Error",r),n(!1)}};function A1(){const{t:e}=Le(),t=Fl("(min-width: 768px)"),{instance:n}=st(),{typebotId:r}=Ys(),[s,o]=m.useState(!0),[a,l]=m.useState([]),c=En();m.useEffect(()=>{n&&D1(n,l,o)},[n]);const u=f=>{n&&c(`/manager/instance/${n.id}/typebot/${f}`)},d=()=>{D1(n,l,o)};return i.jsxs("main",{className:"pt-5",children:[i.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[i.jsx("h3",{className:"text-lg font-medium",children:e("typebot.title")}),i.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[i.jsx(VP,{}),i.jsx(FQ,{}),i.jsx($Q,{resetTable:d})]})]}),i.jsx(Ze,{className:"my-4"}),i.jsxs(Dl,{direction:t?"horizontal":"vertical",children:[i.jsx(_r,{defaultSize:35,className:"pr-4",children:i.jsx("div",{className:"flex flex-col gap-3",children:s?i.jsx(or,{}):i.jsx(i.Fragment,{children:a&&a.length>0&&Array.isArray(a)?a.map(f=>i.jsx(J,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>u(`${f.id}`),variant:r===f.id?"secondary":"outline",children:f.description?i.jsxs(i.Fragment,{children:[i.jsx("h4",{className:"text-base",children:f.description}),i.jsxs("p",{className:"text-wrap text-sm font-normal text-muted-foreground",children:[f.url," - ",f.typebot]})]}):i.jsxs(i.Fragment,{children:[i.jsx("h4",{className:"text-base",children:f.url}),i.jsx("p",{className:"text-wrap text-sm font-normal text-muted-foreground",children:f.typebot})]})},f.id)):i.jsx(J,{variant:"link",children:e("typebot.table.none")})})})}),r&&i.jsxs(i.Fragment,{children:[i.jsx(Al,{withHandle:!0,className:"border border-black"}),i.jsx(_r,{className:"",children:i.jsx(zQ,{typebotId:r,instance:n,resetTable:d})})]})]})]})}const HP=new ur,UQ=async(e,t)=>(await HP.getInstance().get(`/webhook/find/${e}`,{headers:{apikey:t}})).data,VQ=async(e,t,n)=>(await HP.getInstance().post(`/webhook/set/${e}`,n,{headers:{apikey:t}})).data,HQ=k.object({enabled:k.boolean(),url:k.string().url("Invalid URL format"),events:k.array(k.string()),webhookBase64:k.boolean(),webhookByEvents:k.boolean()});function WQ(){const{t:e}=Le(),{instance:t}=st(),[n,r]=m.useState(!1),s=kt({resolver:Et(HQ),defaultValues:{enabled:!1,url:"",events:[],webhookBase64:!1,webhookByEvents:!1}});m.useEffect(()=>{(async()=>{if(t){r(!0);try{const c=await UQ(t.name,t.token);s.reset(c)}catch(c){console.error("Error:",c)}finally{r(!1)}}})()},[t,s]);const o=async l=>{var c,u,d;if(t){r(!0);try{const f={enabled:l.enabled,url:l.url,events:l.events,webhookBase64:l.webhookBase64,webhookByEvents:l.webhookByEvents};await VQ(t.name,t.token,f),X.success(e("webhook.toast.success"))}catch(f){console.error(e("webhook.toast.error"),f),X.error(`Error: ${(d=(u=(c=f==null?void 0:f.response)==null?void 0:c.data)==null?void 0:u.response)==null?void 0:d.message}`)}finally{r(!1)}}},a=["APPLICATION_STARTUP","QRCODE_UPDATED","MESSAGES_SET","MESSAGES_UPSERT","MESSAGES_UPDATE","MESSAGES_DELETE","SEND_MESSAGE","CONTACTS_SET","CONTACTS_UPSERT","CONTACTS_UPDATE","PRESENCE_UPDATE","CHATS_SET","CHATS_UPSERT","CHATS_UPDATE","CHATS_DELETE","GROUPS_UPSERT","GROUP_UPDATE","GROUP_PARTICIPANTS_UPDATE","CONNECTION_UPDATE","REMOVE_INSTANCE","LOGOUT_INSTANCE","LABELS_EDIT","LABELS_ASSOCIATION","CALL","TYPEBOT_START","TYPEBOT_CHANGE_STATUS"];return i.jsx(i.Fragment,{children:i.jsx(fr,{...s,children:i.jsx("form",{onSubmit:s.handleSubmit(o),className:"w-full space-y-6",children:i.jsxs("div",{children:[i.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("webhook.title")}),i.jsx(na,{className:"my-4"}),i.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[i.jsx(he,{name:"enabled",label:e("webhook.form.enabled.label"),className:"w-full justify-between",helper:e("webhook.form.enabled.description")}),i.jsx(D,{name:"url",label:"URL",children:i.jsx(A,{})}),i.jsx(he,{name:"webhookByEvents",label:e("webhook.form.webhookByEvents.label"),className:"w-full justify-between",helper:e("webhook.form.webhookByEvents.description")}),i.jsx(he,{name:"webhookBase64",label:e("webhook.form.webhookBase64.label"),className:"w-full justify-between",helper:e("webhook.form.webhookBase64.description")}),i.jsx(aa,{control:s.control,name:"events",render:({field:l})=>i.jsxs(so,{className:"flex flex-col",children:[i.jsx(sr,{className:"my-2 text-lg",children:e("webhook.form.events.label")}),i.jsx(Ss,{children:i.jsx("div",{className:"flex flex-col gap-2 space-y-1 divide-y",children:a.sort((c,u)=>c.localeCompare(u)).map(c=>i.jsxs("div",{className:"flex items-center justify-between gap-3 pt-3",children:[i.jsx(sr,{className:me("break-all",l.value.includes(c)?"text-foreground":"text-muted-foreground"),children:c}),i.jsx(Ol,{checked:l.value.includes(c),onCheckedChange:u=>{u?l.onChange([...l.value,c]):l.onChange(l.value.filter(d=>d!==c))}})]},c))})})]})})]}),i.jsx("div",{className:"mx-4 flex justify-end pt-6",children:i.jsx(J,{type:"submit",disabled:n,children:e(n?"webhook.button.saving":"webhook.button.save")})})]})})})})}const WP=new ur,GQ=async(e,t)=>(await WP.getInstance().get(`/websocket/find/${e}`,{headers:{apikey:t}})).data,qQ=async(e,t,n)=>(await WP.getInstance().post(`/websocket/set/${e}`,n,{headers:{apikey:t}})).data,KQ=k.object({enabled:k.boolean(),events:k.array(k.string())});function JQ(){const{t:e}=Le(),{instance:t}=st(),[n,r]=m.useState(!1),s=kt({resolver:Et(KQ),defaultValues:{enabled:!1,events:[]}});m.useEffect(()=>{(async()=>{if(t){r(!0);try{const c=await GQ(t.name,t.token);s.reset(c)}catch(c){console.error("Erro ao buscar dados do websocket:",c)}finally{r(!1)}}})()},[t,s]);const o=async l=>{var c,u,d;if(t){r(!0);try{const f={enabled:l.enabled,events:l.events};await qQ(t.name,t.token,f),X.success(e("websocket.toast.success"))}catch(f){console.error(e("websocket.toast.error"),f),X.error(`Error: ${(d=(u=(c=f==null?void 0:f.response)==null?void 0:c.data)==null?void 0:u.response)==null?void 0:d.message}`)}finally{r(!1)}}},a=["APPLICATION_STARTUP","QRCODE_UPDATED","MESSAGES_SET","MESSAGES_UPSERT","MESSAGES_UPDATE","MESSAGES_DELETE","SEND_MESSAGE","CONTACTS_SET","CONTACTS_UPSERT","CONTACTS_UPDATE","PRESENCE_UPDATE","CHATS_SET","CHATS_UPSERT","CHATS_UPDATE","CHATS_DELETE","GROUPS_UPSERT","GROUP_UPDATE","GROUP_PARTICIPANTS_UPDATE","CONNECTION_UPDATE","REMOVE_INSTANCE","LOGOUT_INSTANCE","LABELS_EDIT","LABELS_ASSOCIATION","CALL","TYPEBOT_START","TYPEBOT_CHANGE_STATUS"];return i.jsx(i.Fragment,{children:i.jsx(fr,{...s,children:i.jsx("form",{onSubmit:s.handleSubmit(o),className:"w-full space-y-6",children:i.jsxs("div",{children:[i.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("websocket.title")}),i.jsx(na,{className:"my-4"}),i.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[i.jsx(he,{name:"enabled",label:e("websocket.form.enabled.label"),className:"w-full justify-between",helper:e("websocket.form.enabled.description")}),i.jsx(aa,{control:s.control,name:"events",render:({field:l})=>i.jsxs(so,{className:"flex flex-col",children:[i.jsx(sr,{className:"my-2 text-lg",children:e("websocket.form.events.label")}),i.jsx(Ss,{children:i.jsx("div",{className:"flex flex-col gap-2 space-y-1 divide-y",children:a.sort((c,u)=>c.localeCompare(u)).map(c=>i.jsxs("div",{className:"flex items-center justify-between gap-3 pt-3",children:[i.jsx(sr,{className:me("break-all",l.value.includes(c)?"text-foreground":"text-muted-foreground"),children:c}),i.jsx(Ol,{checked:l.value.includes(c),onCheckedChange:u=>{u?l.onChange([...l.value,c]):l.onChange(l.value.filter(d=>d!==c))}})]},c))})})]})})]}),i.jsx("div",{className:"mx-4 flex justify-end pt-6",children:i.jsx(J,{type:"submit",disabled:n,children:e(n?"websocket.button.saving":"websocket.button.save")})})]})})})})}const ZQ=k.object({serverUrl:k.string({required_error:"serverUrl is required"}).url("URL inválida"),apiKey:k.string({required_error:"ApiKey is required"})});function QQ(){const{t:e}=Le(),t=En(),n=kt({resolver:Et(ZQ),defaultValues:{serverUrl:window.location.protocol+"//"+window.location.host,apiKey:""}}),r=async s=>{const o=await pT(s.serverUrl);if(!o||!o.version){gT(),n.setError("serverUrl",{type:"manual",message:e("login.message.invalidServer")});return}if(!await dL(s.serverUrl,s.apiKey)){n.setError("apiKey",{type:"manual",message:e("login.message.invalidCredentials")});return}if(!await uL(s.serverUrl,s.apiKey)){X.error(e("login.message.invalidCredentials"));return}localStorage.setItem("version",o.version),localStorage.setItem("clientName",o.clientName),t("/manager/")};return i.jsxs("div",{className:"flex min-h-screen flex-col",children:[i.jsx("div",{className:"flex items-center justify-center pt-2",children:i.jsx("img",{className:"h-10",src:"/assets/images/evolution-logo.png",alt:"logo"})}),i.jsx("div",{className:"flex flex-1 items-center justify-center p-8",children:i.jsxs(wa,{className:"b-none w-[350px] shadow-none",children:[i.jsxs(Sa,{children:[i.jsx(Dc,{className:"text-center",children:e("login.title")}),i.jsx(lR,{className:"text-center",children:e("login.description")})]}),i.jsx(fr,{...n,children:i.jsxs("form",{onSubmit:n.handleSubmit(r),children:[i.jsx(Ca,{children:i.jsxs("div",{className:"grid w-full items-center gap-4",children:[i.jsx(D,{required:!0,name:"serverUrl",label:e("login.form.serverUrl"),children:i.jsx(A,{})}),i.jsx(D,{required:!0,name:"apiKey",label:e("login.form.apiKey"),children:i.jsx(A,{type:"password"})})]})}),i.jsx(wg,{className:"flex justify-center",children:i.jsx(J,{className:"w-full",type:"submit",children:e("login.button.login")})})]})})]})}),i.jsx(fb,{})]})}const io=new ur,GP=async(e,t)=>(await io.getInstance().get(`/generic/find/${e}`,{headers:{apikey:t}})).data,YQ=async(e,t,n)=>(await io.getInstance().get(`/generic/fetch/${n}/${e}`,{headers:{apikey:t}})).data,XQ=async(e,t,n)=>(await io.getInstance().post(`/generic/create/${e}`,n,{headers:{apikey:t}})).data,eY=async(e,t,n,r)=>(await io.getInstance().put(`/generic/update/${n}/${e}`,r,{headers:{apikey:t}})).data,tY=async(e,t,n)=>(await io.getInstance().delete(`/generic/delete/${n}/${e}`,{headers:{apikey:t}})).data,nY=async(e,t)=>(await io.getInstance().get(`/generic/fetchSettings/${e}`,{headers:{apikey:t}})).data,rY=async(e,t,n)=>(await io.getInstance().post(`/generic/settings/${e}`,n,{headers:{apikey:t}})).data,sY=async(e,t,n)=>(await io.getInstance().get(`/generic/fetchSessions/${n}/${e}`,{headers:{apikey:t}})).data,oY=async(e,t,n,r)=>(await io.getInstance().post(`/generic/changeStatus/${e}`,{remoteJid:n,status:r},{headers:{apikey:t}})).data,aY=k.object({expire:k.string(),keywordFinish:k.string(),delayMessage:k.string(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.string(),ignoreJids:k.array(k.string()).default([]),botIdFallback:k.union([k.null(),k.string()]).optional()}),F1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await nY(e.name,r);t(s);const o=await GP(e.name,r);n(o)}else console.error("Token not found.")}catch(r){console.error("Error:",r)}};function iY(){const{t:e}=Le(),{instance:t}=st(),[n,r]=m.useState(!1),[s,o]=m.useState(),[a,l]=m.useState([]),c=kt({resolver:Et(aY),defaultValues:{expire:"0",keywordFinish:e("genericBot.form.examples.keywordFinish"),delayMessage:"1000",unknownMessage:e("genericBot.form.examples.unknownMessage"),listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:"0",ignoreJids:[],botIdFallback:void 0}});m.useEffect(()=>{n&&F1(t,o,l)},[t,n]),m.useEffect(()=>{s&&c.reset({expire:s!=null&&s.expire?s.expire.toString():"0",keywordFinish:s.keywordFinish,delayMessage:s.delayMessage?s.delayMessage.toString():"0",unknownMessage:s.unknownMessage,listeningFromMe:s.listeningFromMe,stopBotFromMe:s.stopBotFromMe,keepOpen:s.keepOpen,debounceTime:s.debounceTime?s.debounceTime.toString():"0",ignoreJids:s.ignoreJids,botIdFallback:s.botIdFallback})},[s]);const u=async f=>{var p,h,v;try{if(!t||!t.name)throw new Error("instance not found.");const g={expire:parseInt(f.expire),keywordFinish:f.keywordFinish,delayMessage:parseInt(f.delayMessage),unknownMessage:f.unknownMessage,listeningFromMe:f.listeningFromMe,stopBotFromMe:f.stopBotFromMe,keepOpen:f.keepOpen,debounceTime:parseInt(f.debounceTime),botIdFallback:f.botIdFallback||void 0,ignoreJids:f.ignoreJids};await rY(t.name,t.token,g),X.success(e("genericBot.toast.defaultSettings.success"))}catch(g){console.error("Error:",g),X.error(`Error: ${(v=(h=(p=g==null?void 0:g.response)==null?void 0:p.data)==null?void 0:h.response)==null?void 0:v.message}`)}};function d(){F1(t,o,l)}return i.jsxs(yt,{open:n,onOpenChange:r,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{variant:"secondary",size:"sm",children:[i.jsx(Za,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:e("genericBot.defaultSettings")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:d,children:[i.jsx(gt,{children:i.jsx(At,{children:e("genericBot.defaultSettings")})}),i.jsx(dr,{...c,children:i.jsxs("form",{className:"w-full space-y-6",onSubmit:c.handleSubmit(u),children:[i.jsx("div",{children:i.jsxs("div",{className:"space-y-4",children:[i.jsx(et,{name:"botIdFallback",label:e("genericBot.form.botIdFallback.label"),options:(a==null?void 0:a.filter(f=>!!f.id).map(f=>({label:f.description,value:f.id})))??[]}),i.jsx(D,{name:"expire",label:e("genericBot.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:e("genericBot.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:e("genericBot.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:e("genericBot.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:e("genericBot.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:e("genericBot.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:e("genericBot.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:e("genericBot.form.debounceTime.label"),children:i.jsx(A,{type:"number"})}),i.jsx(Ml,{name:"ignoreJids",label:e("genericBot.form.ignoreJids.label"),placeholder:e("genericBot.form.ignoreJids.placeholder")})]})}),i.jsx(Jt,{children:i.jsx(J,{type:"submit",children:e("genericBot.button.save")})})]})})]})]})}const lY=k.object({enabled:k.boolean(),description:k.string(),apiUrl:k.string(),apiKey:k.string(),triggerType:k.string(),triggerOperator:k.string().optional(),triggerValue:k.string().optional(),expire:k.string(),keywordFinish:k.string(),delayMessage:k.string(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.string()});function cY({resetTable:e}){const{t}=Le(),{instance:n}=st(),[r,s]=m.useState(!1),[o,a]=m.useState(!1),l=kt({resolver:Et(lY),defaultValues:{enabled:!0,description:"",apiUrl:"",apiKey:"",triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:"0",keywordFinish:"",delayMessage:"0",unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:"0"}}),c=async f=>{var p,h,v;try{if(!n||!n.name)throw new Error("instance not found");s(!0);const g={enabled:f.enabled,description:f.description,apiUrl:f.apiUrl,apiKey:f.apiKey,triggerType:f.triggerType,triggerOperator:f.triggerOperator||"",triggerValue:f.triggerValue||"",expire:parseInt(f.expire,10),keywordFinish:f.keywordFinish,delayMessage:parseInt(f.delayMessage,10),unknownMessage:f.unknownMessage,listeningFromMe:f.listeningFromMe,stopBotFromMe:f.stopBotFromMe,keepOpen:f.keepOpen,debounceTime:parseInt(f.debounceTime,10)};await XQ(n.name,n.token,g),X.success(t("genericBot.toast.success.create")),a(!1),u(),e()}catch(g){console.error("Error:",g),X.error(`Error: ${(v=(h=(p=g==null?void 0:g.response)==null?void 0:p.data)==null?void 0:h.response)==null?void 0:v.message}`)}finally{s(!1)}};function u(){l.reset()}const d=l.watch("triggerType");return i.jsxs(yt,{open:o,onOpenChange:a,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{size:"sm",children:[i.jsx(Qa,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("genericBot.button.create")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:u,children:[i.jsx(gt,{children:i.jsx(At,{children:t("genericBot.form.title")})}),i.jsx(dr,{...l,children:i.jsxs("form",{onSubmit:l.handleSubmit(c),className:"w-full space-y-6",children:[i.jsx("div",{children:i.jsxs("div",{className:"space-y-4",children:[i.jsx(he,{name:"enabled",label:t("genericBot.form.enabled.label"),reverse:!0}),i.jsx(D,{name:"description",label:t("genericBot.form.description.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("genericBot.form.genericBotSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"apiUrl",label:t("genericBot.form.apiUrl.label"),required:!0,children:i.jsx(A,{})}),i.jsx(D,{name:"apiKey",label:t("genericBot.form.apiKey.label"),children:i.jsx(A,{type:"password"})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("genericBot.form.triggerSettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"triggerType",label:t("genericBot.form.triggerType.label"),options:[{label:t("genericBot.form.triggerType.keyword"),value:"keyword"},{label:t("genericBot.form.triggerType.all"),value:"all"},{label:t("genericBot.form.triggerType.advanced"),value:"advanced"},{label:t("genericBot.form.triggerType.none"),value:"none"}],required:!0}),d==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(et,{name:"triggerOperator",label:t("genericBot.form.triggerOperator.label"),options:[{label:t("genericBot.form.triggerOperator.contains"),value:"contains"},{label:t("genericBot.form.triggerOperator.equals"),value:"equals"},{label:t("genericBot.form.triggerOperator.startsWith"),value:"startsWith"},{label:t("genericBot.form.triggerOperator.endsWith"),value:"endsWith"},{label:t("genericBot.form.triggerOperator.regex"),value:"regex"}],required:!0}),i.jsx(D,{name:"triggerValue",label:t("genericBot.form.triggerValue.label"),required:!0,children:i.jsx(A,{})})]}),d==="advanced"&&i.jsx(D,{name:"triggerValue",label:t("genericBot.form.triggerConditions.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("genericBot.form.generalSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"expire",label:t("genericBot.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:t("genericBot.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:t("genericBot.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:t("genericBot.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:t("genericBot.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:t("genericBot.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:t("genericBot.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:t("genericBot.form.debounceTime.label"),children:i.jsx(A,{type:"number"})})]})}),i.jsx(Jt,{children:i.jsx(J,{disabled:r,type:"submit",children:t("genericBot.button.save")})})]})})]})]})}const L1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await sY(e.name,r,n);t(s)}else console.error("Token not found.")}catch(r){console.error("Errors:",r)}};function qP({genericBotId:e}){var h,v;const{t}=Le(),{instance:n}=st(),[r,s]=m.useState([]),[o,a]=m.useState([]),[l,c]=m.useState(!1);m.useEffect(()=>{l&&L1(n,a,e)},[n,e,l]);function u(){L1(n,a,e)}const d=async(g,b)=>{var y,x,w;try{if(!n)return;await oY(n.name,n.token,g,b),X.success(t("genericBot.toast.success.status")),u()}catch(S){console.error("Error:",S),X.error(`Error : ${(w=(x=(y=S==null?void 0:S.response)==null?void 0:y.data)==null?void 0:x.response)==null?void 0:w.message}`)}},f=[{accessorKey:"remoteJid",header:()=>i.jsx("div",{className:"text-center",children:t("genericBot.sessions.table.remoteJid")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>i.jsx("div",{className:"text-center",children:t("genericBot.sessions.table.pushName")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("pushName")})},{accessorKey:"sessionId",header:()=>i.jsx("div",{className:"text-center",children:t("genericBot.sessions.table.sessionId")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("sessionId")})},{accessorKey:"status",header:()=>i.jsx("div",{className:"text-center",children:t("genericBot.sessions.table.status")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:g})=>{const b=g.original;return i.jsxs(to,{children:[i.jsx(no,{asChild:!0,children:i.jsxs(J,{variant:"ghost",className:"h-8 w-8 p-0",children:[i.jsx("span",{className:"sr-only",children:t("genericBot.sessions.table.actions.title")}),i.jsx(Sl,{className:"h-4 w-4"})]})}),i.jsxs(Qr,{align:"end",children:[i.jsx(ei,{children:t("genericBot.sessions.table.actions.title")}),i.jsx(ra,{}),b.status!=="opened"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"opened"),children:[i.jsx(Ku,{className:"mr-2 h-4 w-4"}),t("genericBot.sessions.table.actions.open")]}),b.status!=="paused"&&b.status!=="closed"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"paused"),children:[i.jsx(qu,{className:"mr-2 h-4 w-4"}),t("genericBot.sessions.table.actions.pause")]}),b.status!=="closed"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"closed"),children:[i.jsx(Hu,{className:"mr-2 h-4 w-4"}),t("genericBot.sessions.table.actions.close")]}),i.jsxs(at,{onClick:()=>d(b.remoteJid,"delete"),children:[i.jsx(Wu,{className:"mr-2 h-4 w-4"}),t("genericBot.sessions.table.actions.delete")]})]})]})}}],p=Ul({data:o,columns:f,onSortingChange:s,getCoreRowModel:Ll(),getPaginationRowModel:Bl(),getSortedRowModel:zl(),getFilteredRowModel:$l(),state:{sorting:r}});return i.jsxs(yt,{open:l,onOpenChange:c,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{variant:"secondary",size:"sm",children:[i.jsx(Gu,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("genericBot.sessions.label")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:u,children:[i.jsx(gt,{children:i.jsx(At,{children:t("genericBot.sessions.label")})}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[i.jsx(A,{placeholder:t("genericBot.sessions.search"),value:((h=p.getColumn("remoteJid"))==null?void 0:h.getFilterValue())??"",onChange:g=>{var b;return(b=p.getColumn("remoteJid"))==null?void 0:b.setFilterValue(g.target.value)}}),i.jsx(J,{variant:"outline",onClick:u,size:"icon",children:i.jsx(Ju,{})})]}),i.jsxs(ri,{children:[i.jsx(si,{children:p.getHeaderGroups().map(g=>i.jsx(en,{children:g.headers.map(b=>i.jsx(ai,{children:b.isPlaceholder?null:Rr(b.column.columnDef.header,b.getContext())},b.id))},g.id))}),i.jsx(oi,{children:(v=p.getRowModel().rows)!=null&&v.length?p.getRowModel().rows.map(g=>i.jsx(en,{"data-state":g.getIsSelected()&&"selected",children:g.getVisibleCells().map(b=>i.jsx(ir,{children:Rr(b.column.columnDef.cell,b.getContext())},b.id))},g.id)):i.jsx(en,{children:i.jsx(ir,{colSpan:f.length,className:"h-24 text-center",children:t("genericBot.sessions.table.none")})})})]})]})]})]})}const uY=k.object({enabled:k.boolean(),description:k.string(),botType:k.string(),apiUrl:k.string(),apiKey:k.string(),triggerType:k.string(),triggerOperator:k.string().optional(),triggerValue:k.string().optional(),expire:k.coerce.number(),keywordFinish:k.string(),delayMessage:k.coerce.number(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.coerce.number()});function dY({genericBotId:e,instance:t,resetTable:n}){const{t:r}=Le(),[,s]=m.useState(""),[o,a]=m.useState(!0),[l,c]=m.useState(!1),u=En(),d=kt({resolver:Et(uY),defaultValues:{enabled:!0,description:"",apiUrl:"",apiKey:"",triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:0,keywordFinish:"",delayMessage:0,unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:0}});m.useEffect(()=>{(async()=>{try{const b=localStorage.getItem("token");if(b&&t&&t.name&&e){s(b);const y=await YQ(t.name,b,e);d.reset({enabled:y.enabled,description:y.description,apiUrl:y.apiUrl,apiKey:y.apiKey,triggerType:y.triggerType,triggerOperator:y.triggerOperator,triggerValue:y.triggerValue,expire:y.expire,keywordFinish:y.keywordFinish,delayMessage:y.delayMessage,unknownMessage:y.unknownMessage,listeningFromMe:y.listeningFromMe,stopBotFromMe:y.stopBotFromMe,keepOpen:y.keepOpen,debounceTime:y.debounceTime})}else console.error("Token not found.");a(!1)}catch(b){console.error("Error:",b),a(!1)}})()},[d,t,e]);const f=async g=>{var b,y,x;try{const w=localStorage.getItem("token");if(w&&t&&t.name&&e){const S={enabled:g.enabled,description:g.description,apiUrl:g.apiUrl,apiKey:g.apiKey,triggerType:g.triggerType,triggerOperator:g.triggerOperator||"",triggerValue:g.triggerValue||"",expire:g.expire,keywordFinish:g.keywordFinish,delayMessage:g.delayMessage,unknownMessage:g.unknownMessage,listeningFromMe:g.listeningFromMe,stopBotFromMe:g.stopBotFromMe,keepOpen:g.keepOpen,debounceTime:g.debounceTime};await eY(t.name,w,e,S),X.success(r("genericBot.toast.success.update"))}else console.error("Token not found")}catch(w){console.error("Error:",w),X.error(`Error: ${(x=(y=(b=w==null?void 0:w.response)==null?void 0:b.data)==null?void 0:y.response)==null?void 0:x.message}`)}},p=async()=>{try{const g=localStorage.getItem("token");g&&t&&t.name&&e?(await tY(t.name,g,e),X.success(r("genericBot.toast.success.delete")),c(!1),n(),u(`/manager/instance/${t.id}/generic`)):console.error("instance not found")}catch(g){console.error("Erro ao excluir genericBot:",g)}},h=d.watch("description"),v=d.watch("triggerType");return i.jsxs(i.Fragment,{children:[o&&i.jsx(or,{}),!o&&i.jsx(fr,{...d,children:i.jsxs("form",{onSubmit:d.handleSubmit(f),className:"w-full space-y-6 pl-4 pr-2",children:[i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[i.jsxs("h3",{className:"mb-4 text-lg font-medium",children:["GenericBot: ",h]}),i.jsx(he,{name:"enabled",className:"flex items-center gap-3"})]}),i.jsxs("div",{className:"space-y-4",children:[i.jsx(D,{name:"description",label:r("genericBot.form.description.label"),children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("genericBot.form.genericBotSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"apiUrl",label:r("genericBot.form.apiUrl.label"),required:!0,children:i.jsx(A,{})}),i.jsx(D,{name:"apiKey",label:r("genericBot.form.apiKey.label"),children:i.jsx(A,{type:"password"})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("genericBot.form.triggerSettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"triggerType",label:r("genericBot.form.triggerType.label"),options:[{label:r("genericBot.form.triggerType.keyword"),value:"keyword"},{label:r("genericBot.form.triggerType.all"),value:"all"},{label:r("genericBot.form.triggerType.advanced"),value:"advanced"},{label:r("genericBot.form.triggerType.none"),value:"none"}]}),v==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(et,{name:"triggerOperator",label:r("genericBot.form.triggerOperator.label"),options:[{label:r("genericBot.form.triggerOperator.contains"),value:"contains"},{label:r("genericBot.form.triggerOperator.equals"),value:"equals"},{label:r("genericBot.form.triggerOperator.startsWith"),value:"startsWith"},{label:r("genericBot.form.triggerOperator.endsWith"),value:"endsWith"},{label:r("genericBot.form.triggerOperator.regex"),value:"regex"}]}),i.jsx(D,{name:"triggerValue",label:r("genericBot.form.triggerValue.label"),children:i.jsx(A,{})})]}),v==="advanced"&&i.jsx(D,{name:"triggerValue",label:r("genericBot.form.triggerConditions.label"),children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("genericBot.form.generalSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"expire",label:r("genericBot.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:r("genericBot.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:r("genericBot.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:r("genericBot.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:r("genericBot.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:r("genericBot.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:r("genericBot.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:r("genericBot.form.debounceTime.label"),children:i.jsx(A,{type:"number"})})]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx(qP,{genericBotId:e}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs(yt,{open:l,onOpenChange:c,children:[i.jsx(Rt,{asChild:!0,children:i.jsx(J,{variant:"destructive",size:"sm",children:r("genericBot.button.delete")})}),i.jsx(pt,{children:i.jsxs(gt,{children:[i.jsx(At,{children:r("modal.delete.title")}),i.jsx(ti,{children:r("modal.delete.messageSingle")}),i.jsxs(Jt,{children:[i.jsx(J,{size:"sm",variant:"outline",onClick:()=>c(!1),children:r("button.cancel")}),i.jsx(J,{variant:"destructive",onClick:p,children:r("button.delete")})]})]})})]}),i.jsx(J,{type:"submit",children:r("genericBot.button.update")})]})]})]})})]})}const $1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await GP(e.name,r);t(s)}else console.error("Token not found");n(!1)}catch(r){console.error("Error:",r),n(!1)}};function B1(){const{t:e}=Le(),t=Fl("(min-width: 768px)"),{instance:n}=st(),{genericBotId:r}=Ys(),[s,o]=m.useState(!0),[a,l]=m.useState([]),c=En();m.useEffect(()=>{n&&$1(n,l,o)},[n]);const u=f=>{n&&c(`/manager/instance/${n.id}/generic/${f}`)},d=()=>{$1(n,l,o)};return i.jsxs("main",{className:"pt-5",children:[i.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[i.jsx("h3",{className:"text-lg font-medium",children:e("genericBot.title")}),i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[i.jsx(qP,{}),i.jsx(iY,{}),i.jsx(cY,{resetTable:d})]})]}),i.jsx(Ze,{className:"my-4"}),i.jsxs(Dl,{direction:t?"horizontal":"vertical",children:[i.jsx(_r,{defaultSize:35,className:"pr-4",children:i.jsx("div",{className:"flex flex-col gap-3",children:s?i.jsx(or,{}):i.jsx(i.Fragment,{children:a&&a.length>0&&Array.isArray(a)?a.map(f=>i.jsx(J,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>u(`${f.id}`),variant:r===f.id?"secondary":"outline",children:i.jsx("h4",{className:"text-base",children:f.description||f.id})},f.id)):i.jsx(J,{variant:"link",children:e("genericBot.table.none")})})})}),r&&i.jsxs(i.Fragment,{children:[i.jsx(Al,{withHandle:!0,className:"border border-border"}),i.jsx(_r,{className:"",children:i.jsx(dY,{genericBotId:r,instance:n,resetTable:d})})]})]})]})}const lo=new ur,KP=async(e,t)=>(await lo.getInstance().get(`/flowise/find/${e}`,{headers:{apikey:t}})).data,fY=async(e,t,n)=>(await lo.getInstance().get(`/flowise/fetch/${n}/${e}`,{headers:{apikey:t}})).data,pY=async(e,t,n)=>(await lo.getInstance().post(`/flowise/create/${e}`,n,{headers:{apikey:t}})).data,gY=async(e,t,n,r)=>(await lo.getInstance().put(`/flowise/update/${n}/${e}`,r,{headers:{apikey:t}})).data,hY=async(e,t,n)=>(await lo.getInstance().delete(`/flowise/delete/${n}/${e}`,{headers:{apikey:t}})).data,mY=async(e,t)=>(await lo.getInstance().get(`/flowise/fetchSettings/${e}`,{headers:{apikey:t}})).data,vY=async(e,t,n)=>(await lo.getInstance().post(`/flowise/settings/${e}`,n,{headers:{apikey:t}})).data,yY=async(e,t,n)=>(await lo.getInstance().get(`/flowise/fetchSessions/${n}/${e}`,{headers:{apikey:t}})).data,bY=async(e,t,n,r)=>(await lo.getInstance().post(`/flowise/changeStatus/${e}`,{remoteJid:n,status:r},{headers:{apikey:t}})).data,xY=k.object({expire:k.string(),keywordFinish:k.string(),delayMessage:k.string(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.string(),ignoreJids:k.array(k.string()).default([]),flowiseIdFallback:k.union([k.null(),k.string()]).optional()}),z1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await mY(e.name,r);t(s);const o=await KP(e.name,r);n(o)}else console.error("Token not found.")}catch(r){console.error("Error:",r)}};function wY(){const{t:e}=Le(),{instance:t}=st(),[n,r]=m.useState(!1),[s,o]=m.useState(),[a,l]=m.useState([]),c=kt({resolver:Et(xY),defaultValues:{expire:"0",keywordFinish:e("flowise.form.examples.keywordFinish"),delayMessage:"1000",unknownMessage:e("flowise.form.examples.unknownMessage"),listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:"0",ignoreJids:[],flowiseIdFallback:void 0}});m.useEffect(()=>{n&&z1(t,o,l)},[t,n]),m.useEffect(()=>{s&&c.reset({expire:s!=null&&s.expire?s.expire.toString():"0",keywordFinish:s.keywordFinish,delayMessage:s.delayMessage?s.delayMessage.toString():"0",unknownMessage:s.unknownMessage,listeningFromMe:s.listeningFromMe,stopBotFromMe:s.stopBotFromMe,keepOpen:s.keepOpen,debounceTime:s.debounceTime?s.debounceTime.toString():"0",ignoreJids:s.ignoreJids,flowiseIdFallback:s.flowiseIdFallback})},[s]);const u=async f=>{var p,h,v;try{if(!t||!t.name)throw new Error("instance not found.");const g={expire:parseInt(f.expire),keywordFinish:f.keywordFinish,delayMessage:parseInt(f.delayMessage),unknownMessage:f.unknownMessage,listeningFromMe:f.listeningFromMe,stopBotFromMe:f.stopBotFromMe,keepOpen:f.keepOpen,debounceTime:parseInt(f.debounceTime),flowiseIdFallback:f.flowiseIdFallback||void 0,ignoreJids:f.ignoreJids};await vY(t.name,t.token,g),X.success(e("flowise.toast.defaultSettings.success"))}catch(g){console.error("Error:",g),X.error(`Error: ${(v=(h=(p=g==null?void 0:g.response)==null?void 0:p.data)==null?void 0:h.response)==null?void 0:v.message}`)}};function d(){z1(t,o,l)}return i.jsxs(yt,{open:n,onOpenChange:r,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{variant:"secondary",size:"sm",children:[i.jsx(Za,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:e("flowise.defaultSettings")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:d,children:[i.jsx(gt,{children:i.jsx(At,{children:e("flowise.defaultSettings")})}),i.jsx(dr,{...c,children:i.jsxs("form",{className:"w-full space-y-6",onSubmit:c.handleSubmit(u),children:[i.jsx("div",{children:i.jsxs("div",{className:"space-y-4",children:[i.jsx(et,{name:"flowiseIdFallback",label:e("flowise.form.flowiseIdFallback.label"),options:(a==null?void 0:a.filter(f=>!!f.id).map(f=>({label:f.description,value:f.id})))??[]}),i.jsx(D,{name:"expire",label:e("flowise.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:e("flowise.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:e("flowise.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:e("flowise.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:e("flowise.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:e("flowise.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:e("flowise.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:e("flowise.form.debounceTime.label"),children:i.jsx(A,{type:"number"})}),i.jsx(Ml,{name:"ignoreJids",label:e("flowise.form.ignoreJids.label"),placeholder:e("flowise.form.ignoreJids.placeholder")})]})}),i.jsx(Jt,{children:i.jsx(J,{type:"submit",children:e("flowise.button.save")})})]})})]})]})}const SY=k.object({enabled:k.boolean(),description:k.string(),apiUrl:k.string(),apiKey:k.string(),triggerType:k.string(),triggerOperator:k.string().optional(),triggerValue:k.string().optional(),expire:k.string(),keywordFinish:k.string(),delayMessage:k.string(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.string()});function CY({resetTable:e}){const{t}=Le(),{instance:n}=st(),[r,s]=m.useState(!1),[o,a]=m.useState(!1),l=kt({resolver:Et(SY),defaultValues:{enabled:!0,description:"",apiUrl:"",apiKey:"",triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:"0",keywordFinish:"",delayMessage:"0",unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:"0"}}),c=async f=>{var p,h,v;try{if(!n||!n.name)throw new Error("instance not found");s(!0);const g={enabled:f.enabled,description:f.description,apiUrl:f.apiUrl,apiKey:f.apiKey,triggerType:f.triggerType,triggerOperator:f.triggerOperator||"",triggerValue:f.triggerValue||"",expire:parseInt(f.expire,10),keywordFinish:f.keywordFinish,delayMessage:parseInt(f.delayMessage,10),unknownMessage:f.unknownMessage,listeningFromMe:f.listeningFromMe,stopBotFromMe:f.stopBotFromMe,keepOpen:f.keepOpen,debounceTime:parseInt(f.debounceTime,10)};await pY(n.name,n.token,g),X.success(t("flowise.toast.success.create")),a(!1),u(),e()}catch(g){console.error("Error:",g),X.error(`Error: ${(v=(h=(p=g==null?void 0:g.response)==null?void 0:p.data)==null?void 0:h.response)==null?void 0:v.message}`)}finally{s(!1)}};function u(){l.reset()}const d=l.watch("triggerType");return i.jsxs(yt,{open:o,onOpenChange:a,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{size:"sm",children:[i.jsx(Qa,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("flowise.button.create")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:u,children:[i.jsx(gt,{children:i.jsx(At,{children:t("flowise.form.title")})}),i.jsx(dr,{...l,children:i.jsxs("form",{onSubmit:l.handleSubmit(c),className:"w-full space-y-6",children:[i.jsx("div",{children:i.jsxs("div",{className:"space-y-4",children:[i.jsx(he,{name:"enabled",label:t("flowise.form.enabled.label"),reverse:!0}),i.jsx(D,{name:"description",label:t("flowise.form.description.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("flowise.form.flowiseSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"apiUrl",label:t("flowise.form.apiUrl.label"),required:!0,children:i.jsx(A,{})}),i.jsx(D,{name:"apiKey",label:t("flowise.form.apiKey.label"),children:i.jsx(A,{type:"password"})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("flowise.form.triggerSettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"triggerType",label:t("flowise.form.triggerType.label"),options:[{label:t("flowise.form.triggerType.keyword"),value:"keyword"},{label:t("flowise.form.triggerType.all"),value:"all"},{label:t("flowise.form.triggerType.advanced"),value:"advanced"},{label:t("flowise.form.triggerType.none"),value:"none"}],required:!0}),d==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(et,{name:"triggerOperator",label:t("flowise.form.triggerOperator.label"),options:[{label:t("flowise.form.triggerOperator.contains"),value:"contains"},{label:t("flowise.form.triggerOperator.equals"),value:"equals"},{label:t("flowise.form.triggerOperator.startsWith"),value:"startsWith"},{label:t("flowise.form.triggerOperator.endsWith"),value:"endsWith"},{label:t("flowise.form.triggerOperator.regex"),value:"regex"}],required:!0}),i.jsx(D,{name:"triggerValue",label:t("flowise.form.triggerValue.label"),required:!0,children:i.jsx(A,{})})]}),d==="advanced"&&i.jsx(D,{name:"triggerValue",label:t("flowise.form.triggerConditions.label"),required:!0,children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:t("flowise.form.generalSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"expire",label:t("flowise.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:t("flowise.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:t("flowise.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:t("flowise.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:t("flowise.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:t("flowise.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:t("flowise.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:t("flowise.form.debounceTime.label"),children:i.jsx(A,{type:"number"})})]})}),i.jsx(Jt,{children:i.jsx(J,{disabled:r,type:"submit",children:t("flowise.button.save")})})]})})]})]})}const U1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await yY(e.name,r,n);t(s)}else console.error("Token not found.")}catch(r){console.error("Errors:",r)}};function JP({flowiseId:e}){var h,v;const{t}=Le(),{instance:n}=st(),[r,s]=m.useState([]),[o,a]=m.useState([]),[l,c]=m.useState(!1);m.useEffect(()=>{l&&U1(n,a,e)},[n,e,l]);function u(){U1(n,a,e)}const d=async(g,b)=>{var y,x,w;try{if(!n)return;await bY(n.name,n.token,g,b),X.success(t("flowise.toast.success.status")),u()}catch(S){console.error("Error:",S),X.error(`Error : ${(w=(x=(y=S==null?void 0:S.response)==null?void 0:y.data)==null?void 0:x.response)==null?void 0:w.message}`)}},f=[{accessorKey:"remoteJid",header:()=>i.jsx("div",{className:"text-center",children:t("flowise.sessions.table.remoteJid")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>i.jsx("div",{className:"text-center",children:t("flowise.sessions.table.pushName")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("pushName")})},{accessorKey:"sessionId",header:()=>i.jsx("div",{className:"text-center",children:t("flowise.sessions.table.sessionId")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("sessionId")})},{accessorKey:"status",header:()=>i.jsx("div",{className:"text-center",children:t("flowise.sessions.table.status")}),cell:({row:g})=>i.jsx("div",{children:g.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:g})=>{const b=g.original;return i.jsxs(to,{children:[i.jsx(no,{asChild:!0,children:i.jsxs(J,{variant:"ghost",className:"h-8 w-8 p-0",children:[i.jsx("span",{className:"sr-only",children:t("flowise.sessions.table.actions.title")}),i.jsx(Sl,{className:"h-4 w-4"})]})}),i.jsxs(Qr,{align:"end",children:[i.jsx(ei,{children:t("flowise.sessions.table.actions.title")}),i.jsx(ra,{}),b.status!=="opened"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"opened"),children:[i.jsx(Ku,{className:"mr-2 h-4 w-4"}),t("flowise.sessions.table.actions.open")]}),b.status!=="paused"&&b.status!=="closed"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"paused"),children:[i.jsx(qu,{className:"mr-2 h-4 w-4"}),t("flowise.sessions.table.actions.pause")]}),b.status!=="closed"&&i.jsxs(at,{onClick:()=>d(b.remoteJid,"closed"),children:[i.jsx(Hu,{className:"mr-2 h-4 w-4"}),t("flowise.sessions.table.actions.close")]}),i.jsxs(at,{onClick:()=>d(b.remoteJid,"delete"),children:[i.jsx(Wu,{className:"mr-2 h-4 w-4"}),t("flowise.sessions.table.actions.delete")]})]})]})}}],p=Ul({data:o,columns:f,onSortingChange:s,getCoreRowModel:Ll(),getPaginationRowModel:Bl(),getSortedRowModel:zl(),getFilteredRowModel:$l(),state:{sorting:r}});return i.jsxs(yt,{open:l,onOpenChange:c,children:[i.jsx(Rt,{asChild:!0,children:i.jsxs(J,{variant:"secondary",size:"sm",children:[i.jsx(Gu,{size:16,className:"mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("flowise.sessions.label")})]})}),i.jsxs(pt,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:u,children:[i.jsx(gt,{children:i.jsx(At,{children:t("flowise.sessions.label")})}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[i.jsx(A,{placeholder:t("flowise.sessions.search"),value:((h=p.getColumn("remoteJid"))==null?void 0:h.getFilterValue())??"",onChange:g=>{var b;return(b=p.getColumn("remoteJid"))==null?void 0:b.setFilterValue(g.target.value)}}),i.jsx(J,{variant:"outline",onClick:u,size:"icon",children:i.jsx(Ju,{})})]}),i.jsxs(ri,{children:[i.jsx(si,{children:p.getHeaderGroups().map(g=>i.jsx(en,{children:g.headers.map(b=>i.jsx(ai,{children:b.isPlaceholder?null:Rr(b.column.columnDef.header,b.getContext())},b.id))},g.id))}),i.jsx(oi,{children:(v=p.getRowModel().rows)!=null&&v.length?p.getRowModel().rows.map(g=>i.jsx(en,{"data-state":g.getIsSelected()&&"selected",children:g.getVisibleCells().map(b=>i.jsx(ir,{children:Rr(b.column.columnDef.cell,b.getContext())},b.id))},g.id)):i.jsx(en,{children:i.jsx(ir,{colSpan:f.length,className:"h-24 text-center",children:t("flowise.sessions.table.none")})})})]})]})]})]})}const kY=k.object({enabled:k.boolean(),description:k.string(),botType:k.string(),apiUrl:k.string(),apiKey:k.string(),triggerType:k.string(),triggerOperator:k.string().optional(),triggerValue:k.string().optional(),expire:k.coerce.number(),keywordFinish:k.string(),delayMessage:k.coerce.number(),unknownMessage:k.string(),listeningFromMe:k.boolean(),stopBotFromMe:k.boolean(),keepOpen:k.boolean(),debounceTime:k.coerce.number()});function EY({flowiseId:e,instance:t,resetTable:n}){const{t:r}=Le(),[,s]=m.useState(""),[o,a]=m.useState(!0),[l,c]=m.useState(!1),u=En(),d=kt({resolver:Et(kY),defaultValues:{enabled:!0,description:"",apiUrl:"",apiKey:"",triggerType:"keyword",triggerOperator:"contains",triggerValue:"",expire:0,keywordFinish:"",delayMessage:0,unknownMessage:"",listeningFromMe:!1,stopBotFromMe:!1,keepOpen:!1,debounceTime:0}});m.useEffect(()=>{(async()=>{try{const b=localStorage.getItem("token");if(b&&t&&t.name&&e){s(b);const y=await fY(t.name,b,e);d.reset({enabled:y.enabled,description:y.description,apiUrl:y.apiUrl,apiKey:y.apiKey,triggerType:y.triggerType,triggerOperator:y.triggerOperator,triggerValue:y.triggerValue,expire:y.expire,keywordFinish:y.keywordFinish,delayMessage:y.delayMessage,unknownMessage:y.unknownMessage,listeningFromMe:y.listeningFromMe,stopBotFromMe:y.stopBotFromMe,keepOpen:y.keepOpen,debounceTime:y.debounceTime})}else console.error("Token not found.");a(!1)}catch(b){console.error("Error:",b),a(!1)}})()},[d,t,e]);const f=async g=>{var b,y,x;try{const w=localStorage.getItem("token");if(w&&t&&t.name&&e){const S={enabled:g.enabled,description:g.description,apiUrl:g.apiUrl,apiKey:g.apiKey,triggerType:g.triggerType,triggerOperator:g.triggerOperator||"",triggerValue:g.triggerValue||"",expire:g.expire,keywordFinish:g.keywordFinish,delayMessage:g.delayMessage,unknownMessage:g.unknownMessage,listeningFromMe:g.listeningFromMe,stopBotFromMe:g.stopBotFromMe,keepOpen:g.keepOpen,debounceTime:g.debounceTime};await gY(t.name,w,e,S),X.success(r("flowise.toast.success.update"))}else console.error("Token not found")}catch(w){console.error("Error:",w),X.error(`Error: ${(x=(y=(b=w==null?void 0:w.response)==null?void 0:b.data)==null?void 0:y.response)==null?void 0:x.message}`)}},p=async()=>{try{const g=localStorage.getItem("token");g&&t&&t.name&&e?(await hY(t.name,g,e),X.success(r("flowise.toast.success.delete")),c(!1),n(),u(`/manager/instance/${t.id}/flowise`)):console.error("instance not found")}catch(g){console.error("Erro ao excluir flowise:",g)}},h=d.watch("description"),v=d.watch("triggerType");return i.jsxs(i.Fragment,{children:[o&&i.jsx(or,{}),!o&&i.jsx(fr,{...d,children:i.jsxs("form",{onSubmit:d.handleSubmit(f),className:"w-full space-y-6 pl-4 pr-2",children:[i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[i.jsxs("h3",{className:"mb-4 text-lg font-medium",children:["Flowise: ",h]}),i.jsx(he,{name:"enabled",className:"flex items-center gap-3"})]}),i.jsxs("div",{className:"space-y-4",children:[i.jsx(D,{name:"description",label:r("flowise.form.description.label"),children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("flowise.form.flowiseSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"apiUrl",label:r("flowise.form.apiUrl.label"),required:!0,children:i.jsx(A,{})}),i.jsx(D,{name:"apiKey",label:r("flowise.form.apiKey.label"),children:i.jsx(A,{type:"password"})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("flowise.form.triggerSettings.label")}),i.jsx(Ze,{})]}),i.jsx(et,{name:"triggerType",label:r("flowise.form.triggerType.label"),options:[{label:r("flowise.form.triggerType.keyword"),value:"keyword"},{label:r("flowise.form.triggerType.all"),value:"all"},{label:r("flowise.form.triggerType.advanced"),value:"advanced"},{label:r("flowise.form.triggerType.none"),value:"none"}]}),v==="keyword"&&i.jsxs(i.Fragment,{children:[i.jsx(et,{name:"triggerOperator",label:r("flowise.form.triggerOperator.label"),options:[{label:r("flowise.form.triggerOperator.contains"),value:"contains"},{label:r("flowise.form.triggerOperator.equals"),value:"equals"},{label:r("flowise.form.triggerOperator.startsWith"),value:"startsWith"},{label:r("flowise.form.triggerOperator.endsWith"),value:"endsWith"},{label:r("flowise.form.triggerOperator.regex"),value:"regex"}]}),i.jsx(D,{name:"triggerValue",label:r("flowise.form.triggerValue.label"),children:i.jsx(A,{})})]}),v==="advanced"&&i.jsx(D,{name:"triggerValue",label:r("flowise.form.triggerConditions.label"),children:i.jsx(A,{})}),i.jsxs("div",{className:"flex flex-col",children:[i.jsx("h3",{className:"my-4 text-lg font-medium",children:r("flowise.form.generalSettings.label")}),i.jsx(Ze,{})]}),i.jsx(D,{name:"expire",label:r("flowise.form.expire.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"keywordFinish",label:r("flowise.form.keywordFinish.label"),children:i.jsx(A,{})}),i.jsx(D,{name:"delayMessage",label:r("flowise.form.delayMessage.label"),children:i.jsx(A,{type:"number"})}),i.jsx(D,{name:"unknownMessage",label:r("flowise.form.unknownMessage.label"),children:i.jsx(A,{})}),i.jsx(he,{name:"listeningFromMe",label:r("flowise.form.listeningFromMe.label"),reverse:!0}),i.jsx(he,{name:"stopBotFromMe",label:r("flowise.form.stopBotFromMe.label"),reverse:!0}),i.jsx(he,{name:"keepOpen",label:r("flowise.form.keepOpen.label"),reverse:!0}),i.jsx(D,{name:"debounceTime",label:r("flowise.form.debounceTime.label"),children:i.jsx(A,{type:"number"})})]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx(JP,{flowiseId:e}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs(yt,{open:l,onOpenChange:c,children:[i.jsx(Rt,{asChild:!0,children:i.jsx(J,{variant:"destructive",size:"sm",children:r("flowise.button.delete")})}),i.jsx(pt,{children:i.jsxs(gt,{children:[i.jsx(At,{children:r("modal.delete.title")}),i.jsx(ti,{children:r("modal.delete.messageSingle")}),i.jsxs(Jt,{children:[i.jsx(J,{size:"sm",variant:"outline",onClick:()=>c(!1),children:r("button.cancel")}),i.jsx(J,{variant:"destructive",onClick:p,children:r("button.delete")})]})]})})]}),i.jsx(J,{type:"submit",children:r("flowise.button.update")})]})]})]})})]})}const V1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const s=await KP(e.name,r);t(s)}else console.error("Token not found");n(!1)}catch(r){console.error("Error:",r),n(!1)}};function H1(){const{t:e}=Le(),t=Fl("(min-width: 768px)"),{instance:n}=st(),{flowiseId:r}=Ys(),[s,o]=m.useState(!0),[a,l]=m.useState([]),c=En();m.useEffect(()=>{n&&V1(n,l,o)},[n]);const u=f=>{n&&c(`/manager/instance/${n.id}/flowise/${f}`)},d=()=>{V1(n,l,o)};return i.jsxs("main",{className:"pt-5",children:[i.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[i.jsx("h3",{className:"text-lg font-medium",children:e("flowise.title")}),i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[i.jsx(JP,{}),i.jsx(wY,{}),i.jsx(CY,{resetTable:d})]})]}),i.jsx(Ze,{className:"my-4"}),i.jsxs(Dl,{direction:t?"horizontal":"vertical",children:[i.jsx(_r,{defaultSize:35,className:"pr-4",children:i.jsx("div",{className:"flex flex-col gap-3",children:s?i.jsx(or,{}):i.jsx(i.Fragment,{children:a&&a.length>0&&Array.isArray(a)?a.map(f=>i.jsx(J,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>u(`${f.id}`),variant:r===f.id?"secondary":"outline",children:i.jsx("h4",{className:"text-base",children:f.description||f.id})},f.id)):i.jsx(J,{variant:"link",children:e("flowise.table.none")})})})}),r&&i.jsxs(i.Fragment,{children:[i.jsx(Al,{withHandle:!0,className:"border border-border"}),i.jsx(_r,{className:"",children:i.jsx(EY,{flowiseId:r,instance:n,resetTable:d})})]})]})]})}const TY=lF([{path:"/manager/login",element:i.jsx(FF,{children:i.jsx(QQ,{})})},{path:"/manager/",element:i.jsx(zt,{children:i.jsx(Xz,{children:i.jsx(xK,{})})})},{path:"/manager/instance/:instanceId/dashboard",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx($J,{})})})},{path:"/manager/instance/:instanceId/chat",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(x1,{})})})},{path:"/manager/instance/:instanceId/chat/:remoteJid",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(x1,{})})})},{path:"/manager/instance/:instanceId/settings",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(CQ,{})})})},{path:"/manager/instance/:instanceId/openai",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(P1,{})})})},{path:"/manager/instance/:instanceId/openai/:botId",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(P1,{})})})},{path:"/manager/instance/:instanceId/webhook",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(WQ,{})})})},{path:"/manager/instance/:instanceId/websocket",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(JQ,{})})})},{path:"/manager/instance/:instanceId/rabbitmq",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(wQ,{})})})},{path:"/manager/instance/:instanceId/sqs",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(jQ,{})})})},{path:"/manager/instance/:instanceId/chatwoot",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(iJ,{})})})},{path:"/manager/instance/:instanceId/typebot",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(A1,{})})})},{path:"/manager/instance/:instanceId/typebot/:typebotId",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(A1,{})})})},{path:"/manager/instance/:instanceId/dify",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(_1,{})})})},{path:"/manager/instance/:instanceId/dify/:difyId",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(_1,{})})})},{path:"/manager/instance/:instanceId/generic",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(B1,{})})})},{path:"/manager/instance/:instanceId/generic/:genericBotId",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(B1,{})})})},{path:"/manager/instance/:instanceId/flowise",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(H1,{})})})},{path:"/manager/instance/:instanceId/flowise/:flowiseId",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(H1,{})})})},{path:"/manager/instance/:instanceId/proxy",element:i.jsx(zt,{children:i.jsx(Wt,{children:i.jsx(vQ,{})})})}]),jY={type:"logger",log(e){this.output("log",e)},warn(e){this.output("warn",e)},error(e){this.output("error",e)},output(e,t){console&&console[e]&&console[e].apply(console,t)}};class Cp{constructor(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.init(t,n)}init(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.prefix=n.prefix||"i18next:",this.logger=t||jY,this.options=n,this.debug=n.debug}log(){for(var t=arguments.length,n=new Array(t),r=0;r{this.observers[r]||(this.observers[r]=new Map);const s=this.observers[r].get(n)||0;this.observers[r].set(n,s+1)}),this}off(t,n){if(this.observers[t]){if(!n){delete this.observers[t];return}this.observers[t].delete(n)}}emit(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),s=1;s{let[l,c]=a;for(let u=0;u{let[l,c]=a;for(let u=0;u{let e,t;const n=new Promise((r,s)=>{e=r,t=s});return n.resolve=e,n.reject=t,n},W1=e=>e==null?"":""+e,_Y=(e,t,n)=>{e.forEach(r=>{t[r]&&(n[r]=t[r])})},RY=/###/g,G1=e=>e&&e.indexOf("###")>-1?e.replace(RY,"."):e,q1=e=>!e||typeof e=="string",zc=(e,t,n)=>{const r=typeof t!="string"?t:t.split(".");let s=0;for(;s{const{obj:r,k:s}=zc(e,t,Object);if(r!==void 0||t.length===1){r[s]=n;return}let o=t[t.length-1],a=t.slice(0,t.length-1),l=zc(e,a,Object);for(;l.obj===void 0&&a.length;)o=`${a[a.length-1]}.${o}`,a=a.slice(0,a.length-1),l=zc(e,a,Object),l&&l.obj&&typeof l.obj[`${l.k}.${o}`]<"u"&&(l.obj=void 0);l.obj[`${l.k}.${o}`]=n},IY=(e,t,n,r)=>{const{obj:s,k:o}=zc(e,t,Object);s[o]=s[o]||[],s[o].push(n)},kp=(e,t)=>{const{obj:n,k:r}=zc(e,t);if(n)return n[r]},NY=(e,t,n)=>{const r=kp(e,n);return r!==void 0?r:kp(t,n)},ZP=(e,t,n)=>{for(const r in t)r!=="__proto__"&&r!=="constructor"&&(r in e?typeof e[r]=="string"||e[r]instanceof String||typeof t[r]=="string"||t[r]instanceof String?n&&(e[r]=t[r]):ZP(e[r],t[r],n):e[r]=t[r]);return e},wi=e=>e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&");var PY={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};const OY=e=>typeof e=="string"?e.replace(/[&<>"'\/]/g,t=>PY[t]):e;class MY{constructor(t){this.capacity=t,this.regExpMap=new Map,this.regExpQueue=[]}getRegExp(t){const n=this.regExpMap.get(t);if(n!==void 0)return n;const r=new RegExp(t);return this.regExpQueue.length===this.capacity&&this.regExpMap.delete(this.regExpQueue.shift()),this.regExpMap.set(t,r),this.regExpQueue.push(t),r}}const DY=[" ",",","?","!",";"],AY=new MY(20),FY=(e,t,n)=>{t=t||"",n=n||"";const r=DY.filter(a=>t.indexOf(a)<0&&n.indexOf(a)<0);if(r.length===0)return!0;const s=AY.getRegExp(`(${r.map(a=>a==="?"?"\\?":a).join("|")})`);let o=!s.test(e);if(!o){const a=e.indexOf(n);a>0&&!s.test(e.substring(0,a))&&(o=!0)}return o},ay=function(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:".";if(!e)return;if(e[t])return e[t];const r=t.split(n);let s=e;for(let o=0;o-1&&ce&&e.indexOf("_")>0?e.replace("_","-"):e;class J1 extends Gg{constructor(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{ns:["translation"],defaultNS:"translation"};super(),this.data=t||{},this.options=n,this.options.keySeparator===void 0&&(this.options.keySeparator="."),this.options.ignoreJSONStructure===void 0&&(this.options.ignoreJSONStructure=!0)}addNamespaces(t){this.options.ns.indexOf(t)<0&&this.options.ns.push(t)}removeNamespaces(t){const n=this.options.ns.indexOf(t);n>-1&&this.options.ns.splice(n,1)}getResource(t,n,r){let s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};const o=s.keySeparator!==void 0?s.keySeparator:this.options.keySeparator,a=s.ignoreJSONStructure!==void 0?s.ignoreJSONStructure:this.options.ignoreJSONStructure;let l;t.indexOf(".")>-1?l=t.split("."):(l=[t,n],r&&(Array.isArray(r)?l.push(...r):typeof r=="string"&&o?l.push(...r.split(o)):l.push(r)));const c=kp(this.data,l);return!c&&!n&&!r&&t.indexOf(".")>-1&&(t=l[0],n=l[1],r=l.slice(2).join(".")),c||!a||typeof r!="string"?c:ay(this.data&&this.data[t]&&this.data[t][n],r,o)}addResource(t,n,r,s){let o=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{silent:!1};const a=o.keySeparator!==void 0?o.keySeparator:this.options.keySeparator;let l=[t,n];r&&(l=l.concat(a?r.split(a):r)),t.indexOf(".")>-1&&(l=t.split("."),s=n,n=l[1]),this.addNamespaces(n),K1(this.data,l,s),o.silent||this.emit("added",t,n,r,s)}addResources(t,n,r){let s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{silent:!1};for(const o in r)(typeof r[o]=="string"||Array.isArray(r[o]))&&this.addResource(t,n,o,r[o],{silent:!0});s.silent||this.emit("added",t,n,r)}addResourceBundle(t,n,r,s,o){let a=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{silent:!1,skipCopy:!1},l=[t,n];t.indexOf(".")>-1&&(l=t.split("."),s=r,r=n,n=l[1]),this.addNamespaces(n);let c=kp(this.data,l)||{};a.skipCopy||(r=JSON.parse(JSON.stringify(r))),s?ZP(c,r,o):c={...c,...r},K1(this.data,l,c),a.silent||this.emit("added",t,n,r)}removeResourceBundle(t,n){this.hasResourceBundle(t,n)&&delete this.data[t][n],this.removeNamespaces(n),this.emit("removed",t,n)}hasResourceBundle(t,n){return this.getResource(t,n)!==void 0}getResourceBundle(t,n){return n||(n=this.options.defaultNS),this.options.compatibilityAPI==="v1"?{...this.getResource(t,n)}:this.getResource(t,n)}getDataByLanguage(t){return this.data[t]}hasLanguageSomeTranslations(t){const n=this.getDataByLanguage(t);return!!(n&&Object.keys(n)||[]).find(s=>n[s]&&Object.keys(n[s]).length>0)}toJSON(){return this.data}}var QP={processors:{},addPostProcessor(e){this.processors[e.name]=e},handle(e,t,n,r,s){return e.forEach(o=>{this.processors[o]&&(t=this.processors[o].process(t,n,r,s))}),t}};const Z1={};class Tp extends Gg{constructor(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),_Y(["resourceStore","languageUtils","pluralResolver","interpolator","backendConnector","i18nFormat","utils"],t,this),this.options=n,this.options.keySeparator===void 0&&(this.options.keySeparator="."),this.logger=gs.create("translator")}changeLanguage(t){t&&(this.language=t)}exists(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{interpolation:{}};if(t==null)return!1;const r=this.resolve(t,n);return r&&r.res!==void 0}extractFromKey(t,n){let r=n.nsSeparator!==void 0?n.nsSeparator:this.options.nsSeparator;r===void 0&&(r=":");const s=n.keySeparator!==void 0?n.keySeparator:this.options.keySeparator;let o=n.ns||this.options.defaultNS||[];const a=r&&t.indexOf(r)>-1,l=!this.options.userDefinedKeySeparator&&!n.keySeparator&&!this.options.userDefinedNsSeparator&&!n.nsSeparator&&!FY(t,r,s);if(a&&!l){const c=t.match(this.interpolator.nestingRegexp);if(c&&c.length>0)return{key:t,namespaces:o};const u=t.split(r);(r!==s||r===s&&this.options.ns.indexOf(u[0])>-1)&&(o=u.shift()),t=u.join(s)}return typeof o=="string"&&(o=[o]),{key:t,namespaces:o}}translate(t,n,r){if(typeof n!="object"&&this.options.overloadTranslationOptionHandler&&(n=this.options.overloadTranslationOptionHandler(arguments)),typeof n=="object"&&(n={...n}),n||(n={}),t==null)return"";Array.isArray(t)||(t=[String(t)]);const s=n.returnDetails!==void 0?n.returnDetails:this.options.returnDetails,o=n.keySeparator!==void 0?n.keySeparator:this.options.keySeparator,{key:a,namespaces:l}=this.extractFromKey(t[t.length-1],n),c=l[l.length-1],u=n.lng||this.language,d=n.appendNamespaceToCIMode||this.options.appendNamespaceToCIMode;if(u&&u.toLowerCase()==="cimode"){if(d){const S=n.nsSeparator||this.options.nsSeparator;return s?{res:`${c}${S}${a}`,usedKey:a,exactUsedKey:a,usedLng:u,usedNS:c,usedParams:this.getUsedParamsDetails(n)}:`${c}${S}${a}`}return s?{res:a,usedKey:a,exactUsedKey:a,usedLng:u,usedNS:c,usedParams:this.getUsedParamsDetails(n)}:a}const f=this.resolve(t,n);let p=f&&f.res;const h=f&&f.usedKey||a,v=f&&f.exactUsedKey||a,g=Object.prototype.toString.apply(p),b=["[object Number]","[object Function]","[object RegExp]"],y=n.joinArrays!==void 0?n.joinArrays:this.options.joinArrays,x=!this.i18nFormat||this.i18nFormat.handleAsObject;if(x&&p&&(typeof p!="string"&&typeof p!="boolean"&&typeof p!="number")&&b.indexOf(g)<0&&!(typeof y=="string"&&Array.isArray(p))){if(!n.returnObjects&&!this.options.returnObjects){this.options.returnedObjectHandler||this.logger.warn("accessing an object - but returnObjects options is not enabled!");const S=this.options.returnedObjectHandler?this.options.returnedObjectHandler(h,p,{...n,ns:l}):`key '${a} (${this.language})' returned an object instead of string.`;return s?(f.res=S,f.usedParams=this.getUsedParamsDetails(n),f):S}if(o){const S=Array.isArray(p),E=S?[]:{},C=S?v:h;for(const T in p)if(Object.prototype.hasOwnProperty.call(p,T)){const j=`${C}${o}${T}`;E[T]=this.translate(j,{...n,joinArrays:!1,ns:l}),E[T]===j&&(E[T]=p[T])}p=E}}else if(x&&typeof y=="string"&&Array.isArray(p))p=p.join(y),p&&(p=this.extendTranslation(p,t,n,r));else{let S=!1,E=!1;const C=n.count!==void 0&&typeof n.count!="string",T=Tp.hasDefaultValue(n),j=C?this.pluralResolver.getSuffix(u,n.count,n):"",I=n.ordinal&&C?this.pluralResolver.getSuffix(u,n.count,{ordinal:!1}):"",P=C&&!n.ordinal&&n.count===0&&this.pluralResolver.shouldUseIntlApi(),V=P&&n[`defaultValue${this.options.pluralSeparator}zero`]||n[`defaultValue${j}`]||n[`defaultValue${I}`]||n.defaultValue;!this.isValidLookup(p)&&T&&(S=!0,p=V),this.isValidLookup(p)||(E=!0,p=a);const Z=(n.missingKeyNoValueFallbackToKey||this.options.missingKeyNoValueFallbackToKey)&&E?void 0:p,H=T&&V!==p&&this.options.updateMissing;if(E||S||H){if(this.logger.log(H?"updateKey":"missingKey",u,c,a,H?V:p),o){const L=this.resolve(a,{...n,keySeparator:!1});L&&L.res&&this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.")}let K=[];const Y=this.languageUtils.getFallbackCodes(this.options.fallbackLng,n.lng||this.language);if(this.options.saveMissingTo==="fallback"&&Y&&Y[0])for(let L=0;L{const ue=T&&Q!==p?Q:Z;this.options.missingKeyHandler?this.options.missingKeyHandler(L,c,F,ue,H,n):this.backendConnector&&this.backendConnector.saveMissing&&this.backendConnector.saveMissing(L,c,F,ue,H,n),this.emit("missingKey",L,c,F,p)};this.options.saveMissing&&(this.options.saveMissingPlurals&&C?K.forEach(L=>{const F=this.pluralResolver.getSuffixes(L,n);P&&n[`defaultValue${this.options.pluralSeparator}zero`]&&F.indexOf(`${this.options.pluralSeparator}zero`)<0&&F.push(`${this.options.pluralSeparator}zero`),F.forEach(Q=>{G([L],a+Q,n[`defaultValue${Q}`]||V)})}):G(K,a,V))}p=this.extendTranslation(p,t,n,f,r),E&&p===a&&this.options.appendNamespaceToMissingKey&&(p=`${c}:${a}`),(E||S)&&this.options.parseMissingKeyHandler&&(this.options.compatibilityAPI!=="v1"?p=this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey?`${c}:${a}`:a,S?p:void 0):p=this.options.parseMissingKeyHandler(p))}return s?(f.res=p,f.usedParams=this.getUsedParamsDetails(n),f):p}extendTranslation(t,n,r,s,o){var a=this;if(this.i18nFormat&&this.i18nFormat.parse)t=this.i18nFormat.parse(t,{...this.options.interpolation.defaultVariables,...r},r.lng||this.language||s.usedLng,s.usedNS,s.usedKey,{resolved:s});else if(!r.skipInterpolation){r.interpolation&&this.interpolator.init({...r,interpolation:{...this.options.interpolation,...r.interpolation}});const u=typeof t=="string"&&(r&&r.interpolation&&r.interpolation.skipOnVariables!==void 0?r.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables);let d;if(u){const p=t.match(this.interpolator.nestingRegexp);d=p&&p.length}let f=r.replace&&typeof r.replace!="string"?r.replace:r;if(this.options.interpolation.defaultVariables&&(f={...this.options.interpolation.defaultVariables,...f}),t=this.interpolator.interpolate(t,f,r.lng||this.language||s.usedLng,r),u){const p=t.match(this.interpolator.nestingRegexp),h=p&&p.length;d1&&arguments[1]!==void 0?arguments[1]:{},r,s,o,a,l;return typeof t=="string"&&(t=[t]),t.forEach(c=>{if(this.isValidLookup(r))return;const u=this.extractFromKey(c,n),d=u.key;s=d;let f=u.namespaces;this.options.fallbackNS&&(f=f.concat(this.options.fallbackNS));const p=n.count!==void 0&&typeof n.count!="string",h=p&&!n.ordinal&&n.count===0&&this.pluralResolver.shouldUseIntlApi(),v=n.context!==void 0&&(typeof n.context=="string"||typeof n.context=="number")&&n.context!=="",g=n.lngs?n.lngs:this.languageUtils.toResolveHierarchy(n.lng||this.language,n.fallbackLng);f.forEach(b=>{this.isValidLookup(r)||(l=b,!Z1[`${g[0]}-${b}`]&&this.utils&&this.utils.hasLoadedNamespace&&!this.utils.hasLoadedNamespace(l)&&(Z1[`${g[0]}-${b}`]=!0,this.logger.warn(`key "${s}" for languages "${g.join(", ")}" won't get resolved as namespace "${l}" was not yet loaded`,"This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!")),g.forEach(y=>{if(this.isValidLookup(r))return;a=y;const x=[d];if(this.i18nFormat&&this.i18nFormat.addLookupKeys)this.i18nFormat.addLookupKeys(x,d,y,b,n);else{let S;p&&(S=this.pluralResolver.getSuffix(y,n.count,n));const E=`${this.options.pluralSeparator}zero`,C=`${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;if(p&&(x.push(d+S),n.ordinal&&S.indexOf(C)===0&&x.push(d+S.replace(C,this.options.pluralSeparator)),h&&x.push(d+E)),v){const T=`${d}${this.options.contextSeparator}${n.context}`;x.push(T),p&&(x.push(T+S),n.ordinal&&S.indexOf(C)===0&&x.push(T+S.replace(C,this.options.pluralSeparator)),h&&x.push(T+E))}}let w;for(;w=x.pop();)this.isValidLookup(r)||(o=w,r=this.getResource(y,b,w,n))}))})}),{res:r,usedKey:s,exactUsedKey:o,usedLng:a,usedNS:l}}isValidLookup(t){return t!==void 0&&!(!this.options.returnNull&&t===null)&&!(!this.options.returnEmptyString&&t==="")}getResource(t,n,r){let s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};return this.i18nFormat&&this.i18nFormat.getResource?this.i18nFormat.getResource(t,n,r,s):this.resourceStore.getResource(t,n,r,s)}getUsedParamsDetails(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const n=["defaultValue","ordinal","context","replace","lng","lngs","fallbackLng","ns","keySeparator","nsSeparator","returnObjects","returnDetails","joinArrays","postProcess","interpolation"],r=t.replace&&typeof t.replace!="string";let s=r?t.replace:t;if(r&&typeof t.count<"u"&&(s.count=t.count),this.options.interpolation.defaultVariables&&(s={...this.options.interpolation.defaultVariables,...s}),!r){s={...s};for(const o of n)delete s[o]}return s}static hasDefaultValue(t){const n="defaultValue";for(const r in t)if(Object.prototype.hasOwnProperty.call(t,r)&&n===r.substring(0,n.length)&&t[r]!==void 0)return!0;return!1}}const gm=e=>e.charAt(0).toUpperCase()+e.slice(1);class Q1{constructor(t){this.options=t,this.supportedLngs=this.options.supportedLngs||!1,this.logger=gs.create("languageUtils")}getScriptPartFromCode(t){if(t=Ep(t),!t||t.indexOf("-")<0)return null;const n=t.split("-");return n.length===2||(n.pop(),n[n.length-1].toLowerCase()==="x")?null:this.formatLanguageCode(n.join("-"))}getLanguagePartFromCode(t){if(t=Ep(t),!t||t.indexOf("-")<0)return t;const n=t.split("-");return this.formatLanguageCode(n[0])}formatLanguageCode(t){if(typeof t=="string"&&t.indexOf("-")>-1){const n=["hans","hant","latn","cyrl","cans","mong","arab"];let r=t.split("-");return this.options.lowerCaseLng?r=r.map(s=>s.toLowerCase()):r.length===2?(r[0]=r[0].toLowerCase(),r[1]=r[1].toUpperCase(),n.indexOf(r[1].toLowerCase())>-1&&(r[1]=gm(r[1].toLowerCase()))):r.length===3&&(r[0]=r[0].toLowerCase(),r[1].length===2&&(r[1]=r[1].toUpperCase()),r[0]!=="sgn"&&r[2].length===2&&(r[2]=r[2].toUpperCase()),n.indexOf(r[1].toLowerCase())>-1&&(r[1]=gm(r[1].toLowerCase())),n.indexOf(r[2].toLowerCase())>-1&&(r[2]=gm(r[2].toLowerCase()))),r.join("-")}return this.options.cleanCode||this.options.lowerCaseLng?t.toLowerCase():t}isSupportedCode(t){return(this.options.load==="languageOnly"||this.options.nonExplicitSupportedLngs)&&(t=this.getLanguagePartFromCode(t)),!this.supportedLngs||!this.supportedLngs.length||this.supportedLngs.indexOf(t)>-1}getBestMatchFromCodes(t){if(!t)return null;let n;return t.forEach(r=>{if(n)return;const s=this.formatLanguageCode(r);(!this.options.supportedLngs||this.isSupportedCode(s))&&(n=s)}),!n&&this.options.supportedLngs&&t.forEach(r=>{if(n)return;const s=this.getLanguagePartFromCode(r);if(this.isSupportedCode(s))return n=s;n=this.options.supportedLngs.find(o=>{if(o===s)return o;if(!(o.indexOf("-")<0&&s.indexOf("-")<0)&&(o.indexOf("-")>0&&s.indexOf("-")<0&&o.substring(0,o.indexOf("-"))===s||o.indexOf(s)===0&&s.length>1))return o})}),n||(n=this.getFallbackCodes(this.options.fallbackLng)[0]),n}getFallbackCodes(t,n){if(!t)return[];if(typeof t=="function"&&(t=t(n)),typeof t=="string"&&(t=[t]),Array.isArray(t))return t;if(!n)return t.default||[];let r=t[n];return r||(r=t[this.getScriptPartFromCode(n)]),r||(r=t[this.formatLanguageCode(n)]),r||(r=t[this.getLanguagePartFromCode(n)]),r||(r=t.default),r||[]}toResolveHierarchy(t,n){const r=this.getFallbackCodes(n||this.options.fallbackLng||[],t),s=[],o=a=>{a&&(this.isSupportedCode(a)?s.push(a):this.logger.warn(`rejecting language code not found in supportedLngs: ${a}`))};return typeof t=="string"&&(t.indexOf("-")>-1||t.indexOf("_")>-1)?(this.options.load!=="languageOnly"&&o(this.formatLanguageCode(t)),this.options.load!=="languageOnly"&&this.options.load!=="currentOnly"&&o(this.getScriptPartFromCode(t)),this.options.load!=="currentOnly"&&o(this.getLanguagePartFromCode(t))):typeof t=="string"&&o(this.formatLanguageCode(t)),r.forEach(a=>{s.indexOf(a)<0&&o(this.formatLanguageCode(a))}),s}}let LY=[{lngs:["ach","ak","am","arn","br","fil","gun","ln","mfe","mg","mi","oc","pt","pt-BR","tg","tl","ti","tr","uz","wa"],nr:[1,2],fc:1},{lngs:["af","an","ast","az","bg","bn","ca","da","de","dev","el","en","eo","es","et","eu","fi","fo","fur","fy","gl","gu","ha","hi","hu","hy","ia","it","kk","kn","ku","lb","mai","ml","mn","mr","nah","nap","nb","ne","nl","nn","no","nso","pa","pap","pms","ps","pt-PT","rm","sco","se","si","so","son","sq","sv","sw","ta","te","tk","ur","yo"],nr:[1,2],fc:2},{lngs:["ay","bo","cgg","fa","ht","id","ja","jbo","ka","km","ko","ky","lo","ms","sah","su","th","tt","ug","vi","wo","zh"],nr:[1],fc:3},{lngs:["be","bs","cnr","dz","hr","ru","sr","uk"],nr:[1,2,5],fc:4},{lngs:["ar"],nr:[0,1,2,3,11,100],fc:5},{lngs:["cs","sk"],nr:[1,2,5],fc:6},{lngs:["csb","pl"],nr:[1,2,5],fc:7},{lngs:["cy"],nr:[1,2,3,8],fc:8},{lngs:["fr"],nr:[1,2],fc:9},{lngs:["ga"],nr:[1,2,3,7,11],fc:10},{lngs:["gd"],nr:[1,2,3,20],fc:11},{lngs:["is"],nr:[1,2],fc:12},{lngs:["jv"],nr:[0,1],fc:13},{lngs:["kw"],nr:[1,2,3,4],fc:14},{lngs:["lt"],nr:[1,2,10],fc:15},{lngs:["lv"],nr:[1,2,0],fc:16},{lngs:["mk"],nr:[1,2],fc:17},{lngs:["mnk"],nr:[0,1,2],fc:18},{lngs:["mt"],nr:[1,2,11,20],fc:19},{lngs:["or"],nr:[2,1],fc:2},{lngs:["ro"],nr:[1,2,20],fc:20},{lngs:["sl"],nr:[5,1,2,3],fc:21},{lngs:["he","iw"],nr:[1,2,20,21],fc:22}],$Y={1:e=>+(e>1),2:e=>+(e!=1),3:e=>0,4:e=>e%10==1&&e%100!=11?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2,5:e=>e==0?0:e==1?1:e==2?2:e%100>=3&&e%100<=10?3:e%100>=11?4:5,6:e=>e==1?0:e>=2&&e<=4?1:2,7:e=>e==1?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2,8:e=>e==1?0:e==2?1:e!=8&&e!=11?2:3,9:e=>+(e>=2),10:e=>e==1?0:e==2?1:e<7?2:e<11?3:4,11:e=>e==1||e==11?0:e==2||e==12?1:e>2&&e<20?2:3,12:e=>+(e%10!=1||e%100==11),13:e=>+(e!==0),14:e=>e==1?0:e==2?1:e==3?2:3,15:e=>e%10==1&&e%100!=11?0:e%10>=2&&(e%100<10||e%100>=20)?1:2,16:e=>e%10==1&&e%100!=11?0:e!==0?1:2,17:e=>e==1||e%10==1&&e%100!=11?0:1,18:e=>e==0?0:e==1?1:2,19:e=>e==1?0:e==0||e%100>1&&e%100<11?1:e%100>10&&e%100<20?2:3,20:e=>e==1?0:e==0||e%100>0&&e%100<20?1:2,21:e=>e%100==1?1:e%100==2?2:e%100==3||e%100==4?3:0,22:e=>e==1?0:e==2?1:(e<0||e>10)&&e%10==0?2:3};const BY=["v1","v2","v3"],zY=["v4"],Y1={zero:0,one:1,two:2,few:3,many:4,other:5},UY=()=>{const e={};return LY.forEach(t=>{t.lngs.forEach(n=>{e[n]={numbers:t.nr,plurals:$Y[t.fc]}})}),e};class VY{constructor(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.languageUtils=t,this.options=n,this.logger=gs.create("pluralResolver"),(!this.options.compatibilityJSON||zY.includes(this.options.compatibilityJSON))&&(typeof Intl>"u"||!Intl.PluralRules)&&(this.options.compatibilityJSON="v3",this.logger.error("Your environment seems not to be Intl API compatible, use an Intl.PluralRules polyfill. Will fallback to the compatibilityJSON v3 format handling.")),this.rules=UY(),this.pluralRulesCache={}}addRule(t,n){this.rules[t]=n}clearCache(){this.pluralRulesCache={}}getRule(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(this.shouldUseIntlApi())try{const r=Ep(t==="dev"?"en":t),s=n.ordinal?"ordinal":"cardinal",o=JSON.stringify({cleanedCode:r,type:s});if(o in this.pluralRulesCache)return this.pluralRulesCache[o];const a=new Intl.PluralRules(r,{type:s});return this.pluralRulesCache[o]=a,a}catch{return}return this.rules[t]||this.rules[this.languageUtils.getLanguagePartFromCode(t)]}needsPlural(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const r=this.getRule(t,n);return this.shouldUseIntlApi()?r&&r.resolvedOptions().pluralCategories.length>1:r&&r.numbers.length>1}getPluralFormsOfKey(t,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return this.getSuffixes(t,r).map(s=>`${n}${s}`)}getSuffixes(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const r=this.getRule(t,n);return r?this.shouldUseIntlApi()?r.resolvedOptions().pluralCategories.sort((s,o)=>Y1[s]-Y1[o]).map(s=>`${this.options.prepend}${n.ordinal?`ordinal${this.options.prepend}`:""}${s}`):r.numbers.map(s=>this.getSuffix(t,s,n)):[]}getSuffix(t,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const s=this.getRule(t,r);return s?this.shouldUseIntlApi()?`${this.options.prepend}${r.ordinal?`ordinal${this.options.prepend}`:""}${s.select(n)}`:this.getSuffixRetroCompatible(s,n):(this.logger.warn(`no plural rule found for: ${t}`),"")}getSuffixRetroCompatible(t,n){const r=t.noAbs?t.plurals(n):t.plurals(Math.abs(n));let s=t.numbers[r];this.options.simplifyPluralSuffix&&t.numbers.length===2&&t.numbers[0]===1&&(s===2?s="plural":s===1&&(s=""));const o=()=>this.options.prepend&&s.toString()?this.options.prepend+s.toString():s.toString();return this.options.compatibilityJSON==="v1"?s===1?"":typeof s=="number"?`_plural_${s.toString()}`:o():this.options.compatibilityJSON==="v2"||this.options.simplifyPluralSuffix&&t.numbers.length===2&&t.numbers[0]===1?o():this.options.prepend&&r.toString()?this.options.prepend+r.toString():r.toString()}shouldUseIntlApi(){return!BY.includes(this.options.compatibilityJSON)}}const X1=function(e,t,n){let r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:".",s=arguments.length>4&&arguments[4]!==void 0?arguments[4]:!0,o=NY(e,t,n);return!o&&s&&typeof n=="string"&&(o=ay(e,n,r),o===void 0&&(o=ay(t,n,r))),o},hm=e=>e.replace(/\$/g,"$$$$");class HY{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.logger=gs.create("interpolator"),this.options=t,this.format=t.interpolation&&t.interpolation.format||(n=>n),this.init(t)}init(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};t.interpolation||(t.interpolation={escapeValue:!0});const{escape:n,escapeValue:r,useRawValueToEscape:s,prefix:o,prefixEscaped:a,suffix:l,suffixEscaped:c,formatSeparator:u,unescapeSuffix:d,unescapePrefix:f,nestingPrefix:p,nestingPrefixEscaped:h,nestingSuffix:v,nestingSuffixEscaped:g,nestingOptionsSeparator:b,maxReplaces:y,alwaysFormat:x}=t.interpolation;this.escape=n!==void 0?n:OY,this.escapeValue=r!==void 0?r:!0,this.useRawValueToEscape=s!==void 0?s:!1,this.prefix=o?wi(o):a||"{{",this.suffix=l?wi(l):c||"}}",this.formatSeparator=u||",",this.unescapePrefix=d?"":f||"-",this.unescapeSuffix=this.unescapePrefix?"":d||"",this.nestingPrefix=p?wi(p):h||wi("$t("),this.nestingSuffix=v?wi(v):g||wi(")"),this.nestingOptionsSeparator=b||",",this.maxReplaces=y||1e3,this.alwaysFormat=x!==void 0?x:!1,this.resetRegExp()}reset(){this.options&&this.init(this.options)}resetRegExp(){const t=(n,r)=>n&&n.source===r?(n.lastIndex=0,n):new RegExp(r,"g");this.regexp=t(this.regexp,`${this.prefix}(.+?)${this.suffix}`),this.regexpUnescape=t(this.regexpUnescape,`${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`),this.nestingRegexp=t(this.nestingRegexp,`${this.nestingPrefix}(.+?)${this.nestingSuffix}`)}interpolate(t,n,r,s){let o,a,l;const c=this.options&&this.options.interpolation&&this.options.interpolation.defaultVariables||{},u=h=>{if(h.indexOf(this.formatSeparator)<0){const y=X1(n,c,h,this.options.keySeparator,this.options.ignoreJSONStructure);return this.alwaysFormat?this.format(y,void 0,r,{...s,...n,interpolationkey:h}):y}const v=h.split(this.formatSeparator),g=v.shift().trim(),b=v.join(this.formatSeparator).trim();return this.format(X1(n,c,g,this.options.keySeparator,this.options.ignoreJSONStructure),b,r,{...s,...n,interpolationkey:g})};this.resetRegExp();const d=s&&s.missingInterpolationHandler||this.options.missingInterpolationHandler,f=s&&s.interpolation&&s.interpolation.skipOnVariables!==void 0?s.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables;return[{regex:this.regexpUnescape,safeValue:h=>hm(h)},{regex:this.regexp,safeValue:h=>this.escapeValue?hm(this.escape(h)):hm(h)}].forEach(h=>{for(l=0;o=h.regex.exec(t);){const v=o[1].trim();if(a=u(v),a===void 0)if(typeof d=="function"){const b=d(t,o,s);a=typeof b=="string"?b:""}else if(s&&Object.prototype.hasOwnProperty.call(s,v))a="";else if(f){a=o[0];continue}else this.logger.warn(`missed to pass in variable ${v} for interpolating ${t}`),a="";else typeof a!="string"&&!this.useRawValueToEscape&&(a=W1(a));const g=h.safeValue(a);if(t=t.replace(o[0],g),f?(h.regex.lastIndex+=a.length,h.regex.lastIndex-=o[0].length):h.regex.lastIndex=0,l++,l>=this.maxReplaces)break}}),t}nest(t,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},s,o,a;const l=(c,u)=>{const d=this.nestingOptionsSeparator;if(c.indexOf(d)<0)return c;const f=c.split(new RegExp(`${d}[ ]*{`));let p=`{${f[1]}`;c=f[0],p=this.interpolate(p,a);const h=p.match(/'/g),v=p.match(/"/g);(h&&h.length%2===0&&!v||v.length%2!==0)&&(p=p.replace(/'/g,'"'));try{a=JSON.parse(p),u&&(a={...u,...a})}catch(g){return this.logger.warn(`failed parsing options string in nesting for key ${c}`,g),`${c}${d}${p}`}return a.defaultValue&&a.defaultValue.indexOf(this.prefix)>-1&&delete a.defaultValue,c};for(;s=this.nestingRegexp.exec(t);){let c=[];a={...r},a=a.replace&&typeof a.replace!="string"?a.replace:a,a.applyPostProcessor=!1,delete a.defaultValue;let u=!1;if(s[0].indexOf(this.formatSeparator)!==-1&&!/{.*}/.test(s[1])){const d=s[1].split(this.formatSeparator).map(f=>f.trim());s[1]=d.shift(),c=d,u=!0}if(o=n(l.call(this,s[1].trim(),a),a),o&&s[0]===t&&typeof o!="string")return o;typeof o!="string"&&(o=W1(o)),o||(this.logger.warn(`missed to resolve ${s[1]} for nesting ${t}`),o=""),u&&(o=c.reduce((d,f)=>this.format(d,f,r.lng,{...r,interpolationkey:s[1].trim()}),o.trim())),t=t.replace(s[0],o),this.regexp.lastIndex=0}return t}}const WY=e=>{let t=e.toLowerCase().trim();const n={};if(e.indexOf("(")>-1){const r=e.split("(");t=r[0].toLowerCase().trim();const s=r[1].substring(0,r[1].length-1);t==="currency"&&s.indexOf(":")<0?n.currency||(n.currency=s.trim()):t==="relativetime"&&s.indexOf(":")<0?n.range||(n.range=s.trim()):s.split(";").forEach(a=>{if(a){const[l,...c]=a.split(":"),u=c.join(":").trim().replace(/^'+|'+$/g,""),d=l.trim();n[d]||(n[d]=u),u==="false"&&(n[d]=!1),u==="true"&&(n[d]=!0),isNaN(u)||(n[d]=parseInt(u,10))}})}return{formatName:t,formatOptions:n}},Si=e=>{const t={};return(n,r,s)=>{let o=s;s&&s.interpolationkey&&s.formatParams&&s.formatParams[s.interpolationkey]&&s[s.interpolationkey]&&(o={...o,[s.interpolationkey]:void 0});const a=r+JSON.stringify(o);let l=t[a];return l||(l=e(Ep(r),s),t[a]=l),l(n)}};class GY{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.logger=gs.create("formatter"),this.options=t,this.formats={number:Si((n,r)=>{const s=new Intl.NumberFormat(n,{...r});return o=>s.format(o)}),currency:Si((n,r)=>{const s=new Intl.NumberFormat(n,{...r,style:"currency"});return o=>s.format(o)}),datetime:Si((n,r)=>{const s=new Intl.DateTimeFormat(n,{...r});return o=>s.format(o)}),relativetime:Si((n,r)=>{const s=new Intl.RelativeTimeFormat(n,{...r});return o=>s.format(o,r.range||"day")}),list:Si((n,r)=>{const s=new Intl.ListFormat(n,{...r});return o=>s.format(o)})},this.init(t)}init(t){const r=(arguments.length>1&&arguments[1]!==void 0?arguments[1]:{interpolation:{}}).interpolation;this.formatSeparator=r.formatSeparator?r.formatSeparator:r.formatSeparator||","}add(t,n){this.formats[t.toLowerCase().trim()]=n}addCached(t,n){this.formats[t.toLowerCase().trim()]=Si(n)}format(t,n,r){let s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};const o=n.split(this.formatSeparator);if(o.length>1&&o[0].indexOf("(")>1&&o[0].indexOf(")")<0&&o.find(l=>l.indexOf(")")>-1)){const l=o.findIndex(c=>c.indexOf(")")>-1);o[0]=[o[0],...o.splice(1,l)].join(this.formatSeparator)}return o.reduce((l,c)=>{const{formatName:u,formatOptions:d}=WY(c);if(this.formats[u]){let f=l;try{const p=s&&s.formatParams&&s.formatParams[s.interpolationkey]||{},h=p.locale||p.lng||s.locale||s.lng||r;f=this.formats[u](l,h,{...d,...s,...p})}catch(p){this.logger.warn(p)}return f}else this.logger.warn(`there was no format function for ${u}`);return l},t)}}const qY=(e,t)=>{e.pending[t]!==void 0&&(delete e.pending[t],e.pendingCount--)};class KY extends Gg{constructor(t,n,r){let s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};super(),this.backend=t,this.store=n,this.services=r,this.languageUtils=r.languageUtils,this.options=s,this.logger=gs.create("backendConnector"),this.waitingReads=[],this.maxParallelReads=s.maxParallelReads||10,this.readingCalls=0,this.maxRetries=s.maxRetries>=0?s.maxRetries:5,this.retryTimeout=s.retryTimeout>=1?s.retryTimeout:350,this.state={},this.queue=[],this.backend&&this.backend.init&&this.backend.init(r,s.backend,s)}queueLoad(t,n,r,s){const o={},a={},l={},c={};return t.forEach(u=>{let d=!0;n.forEach(f=>{const p=`${u}|${f}`;!r.reload&&this.store.hasResourceBundle(u,f)?this.state[p]=2:this.state[p]<0||(this.state[p]===1?a[p]===void 0&&(a[p]=!0):(this.state[p]=1,d=!1,a[p]===void 0&&(a[p]=!0),o[p]===void 0&&(o[p]=!0),c[f]===void 0&&(c[f]=!0)))}),d||(l[u]=!0)}),(Object.keys(o).length||Object.keys(a).length)&&this.queue.push({pending:a,pendingCount:Object.keys(a).length,loaded:{},errors:[],callback:s}),{toLoad:Object.keys(o),pending:Object.keys(a),toLoadLanguages:Object.keys(l),toLoadNamespaces:Object.keys(c)}}loaded(t,n,r){const s=t.split("|"),o=s[0],a=s[1];n&&this.emit("failedLoading",o,a,n),!n&&r&&this.store.addResourceBundle(o,a,r,void 0,void 0,{skipCopy:!0}),this.state[t]=n?-1:2,n&&r&&(this.state[t]=0);const l={};this.queue.forEach(c=>{IY(c.loaded,[o],a),qY(c,t),n&&c.errors.push(n),c.pendingCount===0&&!c.done&&(Object.keys(c.loaded).forEach(u=>{l[u]||(l[u]={});const d=c.loaded[u];d.length&&d.forEach(f=>{l[u][f]===void 0&&(l[u][f]=!0)})}),c.done=!0,c.errors.length?c.callback(c.errors):c.callback())}),this.emit("loaded",l),this.queue=this.queue.filter(c=>!c.done)}read(t,n,r){let s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0,o=arguments.length>4&&arguments[4]!==void 0?arguments[4]:this.retryTimeout,a=arguments.length>5?arguments[5]:void 0;if(!t.length)return a(null,{});if(this.readingCalls>=this.maxParallelReads){this.waitingReads.push({lng:t,ns:n,fcName:r,tried:s,wait:o,callback:a});return}this.readingCalls++;const l=(u,d)=>{if(this.readingCalls--,this.waitingReads.length>0){const f=this.waitingReads.shift();this.read(f.lng,f.ns,f.fcName,f.tried,f.wait,f.callback)}if(u&&d&&s{this.read.call(this,t,n,r,s+1,o*2,a)},o);return}a(u,d)},c=this.backend[r].bind(this.backend);if(c.length===2){try{const u=c(t,n);u&&typeof u.then=="function"?u.then(d=>l(null,d)).catch(l):l(null,u)}catch(u){l(u)}return}return c(t,n,l)}prepareLoading(t,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},s=arguments.length>3?arguments[3]:void 0;if(!this.backend)return this.logger.warn("No backend was added via i18next.use. Will not load resources."),s&&s();typeof t=="string"&&(t=this.languageUtils.toResolveHierarchy(t)),typeof n=="string"&&(n=[n]);const o=this.queueLoad(t,n,r,s);if(!o.toLoad.length)return o.pending.length||s(),null;o.toLoad.forEach(a=>{this.loadOne(a)})}load(t,n,r){this.prepareLoading(t,n,{},r)}reload(t,n,r){this.prepareLoading(t,n,{reload:!0},r)}loadOne(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"";const r=t.split("|"),s=r[0],o=r[1];this.read(s,o,"read",void 0,void 0,(a,l)=>{a&&this.logger.warn(`${n}loading namespace ${o} for language ${s} failed`,a),!a&&l&&this.logger.log(`${n}loaded namespace ${o} for language ${s}`,l),this.loaded(t,a,l)})}saveMissing(t,n,r,s,o){let a=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{},l=arguments.length>6&&arguments[6]!==void 0?arguments[6]:()=>{};if(this.services.utils&&this.services.utils.hasLoadedNamespace&&!this.services.utils.hasLoadedNamespace(n)){this.logger.warn(`did not save key "${r}" as the namespace "${n}" was not yet loaded`,"This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");return}if(!(r==null||r==="")){if(this.backend&&this.backend.create){const c={...a,isUpdate:o},u=this.backend.create.bind(this.backend);if(u.length<6)try{let d;u.length===5?d=u(t,n,r,s,c):d=u(t,n,r,s),d&&typeof d.then=="function"?d.then(f=>l(null,f)).catch(l):l(null,d)}catch(d){l(d)}else u(t,n,r,s,l,c)}!t||!t[0]||this.store.addResource(t[0],n,r,s)}}}const eC=()=>({debug:!1,initImmediate:!0,ns:["translation"],defaultNS:["translation"],fallbackLng:["dev"],fallbackNS:!1,supportedLngs:!1,nonExplicitSupportedLngs:!1,load:"all",preload:!1,simplifyPluralSuffix:!0,keySeparator:".",nsSeparator:":",pluralSeparator:"_",contextSeparator:"_",partialBundledLanguages:!1,saveMissing:!1,updateMissing:!1,saveMissingTo:"fallback",saveMissingPlurals:!0,missingKeyHandler:!1,missingInterpolationHandler:!1,postProcess:!1,postProcessPassResolved:!1,returnNull:!1,returnEmptyString:!0,returnObjects:!1,joinArrays:!1,returnedObjectHandler:!1,parseMissingKeyHandler:!1,appendNamespaceToMissingKey:!1,appendNamespaceToCIMode:!1,overloadTranslationOptionHandler:e=>{let t={};if(typeof e[1]=="object"&&(t=e[1]),typeof e[1]=="string"&&(t.defaultValue=e[1]),typeof e[2]=="string"&&(t.tDescription=e[2]),typeof e[2]=="object"||typeof e[3]=="object"){const n=e[3]||e[2];Object.keys(n).forEach(r=>{t[r]=n[r]})}return t},interpolation:{escapeValue:!0,format:e=>e,prefix:"{{",suffix:"}}",formatSeparator:",",unescapePrefix:"-",nestingPrefix:"$t(",nestingSuffix:")",nestingOptionsSeparator:",",maxReplaces:1e3,skipOnVariables:!0}}),tC=e=>(typeof e.ns=="string"&&(e.ns=[e.ns]),typeof e.fallbackLng=="string"&&(e.fallbackLng=[e.fallbackLng]),typeof e.fallbackNS=="string"&&(e.fallbackNS=[e.fallbackNS]),e.supportedLngs&&e.supportedLngs.indexOf("cimode")<0&&(e.supportedLngs=e.supportedLngs.concat(["cimode"])),e),qd=()=>{},JY=e=>{Object.getOwnPropertyNames(Object.getPrototypeOf(e)).forEach(n=>{typeof e[n]=="function"&&(e[n]=e[n].bind(e))})};class Au extends Gg{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(super(),this.options=tC(t),this.services={},this.logger=gs,this.modules={external:[]},JY(this),n&&!this.isInitialized&&!t.isClone){if(!this.options.initImmediate)return this.init(t,n),this;setTimeout(()=>{this.init(t,n)},0)}}init(){var t=this;let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;this.isInitializing=!0,typeof n=="function"&&(r=n,n={}),!n.defaultNS&&n.defaultNS!==!1&&n.ns&&(typeof n.ns=="string"?n.defaultNS=n.ns:n.ns.indexOf("translation")<0&&(n.defaultNS=n.ns[0]));const s=eC();this.options={...s,...this.options,...tC(n)},this.options.compatibilityAPI!=="v1"&&(this.options.interpolation={...s.interpolation,...this.options.interpolation}),n.keySeparator!==void 0&&(this.options.userDefinedKeySeparator=n.keySeparator),n.nsSeparator!==void 0&&(this.options.userDefinedNsSeparator=n.nsSeparator);const o=d=>d?typeof d=="function"?new d:d:null;if(!this.options.isClone){this.modules.logger?gs.init(o(this.modules.logger),this.options):gs.init(null,this.options);let d;this.modules.formatter?d=this.modules.formatter:typeof Intl<"u"&&(d=GY);const f=new Q1(this.options);this.store=new J1(this.options.resources,this.options);const p=this.services;p.logger=gs,p.resourceStore=this.store,p.languageUtils=f,p.pluralResolver=new VY(f,{prepend:this.options.pluralSeparator,compatibilityJSON:this.options.compatibilityJSON,simplifyPluralSuffix:this.options.simplifyPluralSuffix}),d&&(!this.options.interpolation.format||this.options.interpolation.format===s.interpolation.format)&&(p.formatter=o(d),p.formatter.init(p,this.options),this.options.interpolation.format=p.formatter.format.bind(p.formatter)),p.interpolator=new HY(this.options),p.utils={hasLoadedNamespace:this.hasLoadedNamespace.bind(this)},p.backendConnector=new KY(o(this.modules.backend),p.resourceStore,p,this.options),p.backendConnector.on("*",function(h){for(var v=arguments.length,g=new Array(v>1?v-1:0),b=1;b1?v-1:0),b=1;b{h.init&&h.init(this)})}if(this.format=this.options.interpolation.format,r||(r=qd),this.options.fallbackLng&&!this.services.languageDetector&&!this.options.lng){const d=this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);d.length>0&&d[0]!=="dev"&&(this.options.lng=d[0])}!this.services.languageDetector&&!this.options.lng&&this.logger.warn("init: no languageDetector is used and no lng is defined"),["getResource","hasResourceBundle","getResourceBundle","getDataByLanguage"].forEach(d=>{this[d]=function(){return t.store[d](...arguments)}}),["addResource","addResources","addResourceBundle","removeResourceBundle"].forEach(d=>{this[d]=function(){return t.store[d](...arguments),t}});const c=pc(),u=()=>{const d=(f,p)=>{this.isInitializing=!1,this.isInitialized&&!this.initializedStoreOnce&&this.logger.warn("init: i18next is already initialized. You should call init just once!"),this.isInitialized=!0,this.options.isClone||this.logger.log("initialized",this.options),this.emit("initialized",this.options),c.resolve(p),r(f,p)};if(this.languages&&this.options.compatibilityAPI!=="v1"&&!this.isInitialized)return d(null,this.t.bind(this));this.changeLanguage(this.options.lng,d)};return this.options.resources||!this.options.initImmediate?u():setTimeout(u,0),c}loadResources(t){let r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:qd;const s=typeof t=="string"?t:this.language;if(typeof t=="function"&&(r=t),!this.options.resources||this.options.partialBundledLanguages){if(s&&s.toLowerCase()==="cimode"&&(!this.options.preload||this.options.preload.length===0))return r();const o=[],a=l=>{if(!l||l==="cimode")return;this.services.languageUtils.toResolveHierarchy(l).forEach(u=>{u!=="cimode"&&o.indexOf(u)<0&&o.push(u)})};s?a(s):this.services.languageUtils.getFallbackCodes(this.options.fallbackLng).forEach(c=>a(c)),this.options.preload&&this.options.preload.forEach(l=>a(l)),this.services.backendConnector.load(o,this.options.ns,l=>{!l&&!this.resolvedLanguage&&this.language&&this.setResolvedLanguage(this.language),r(l)})}else r(null)}reloadResources(t,n,r){const s=pc();return typeof t=="function"&&(r=t,t=void 0),typeof n=="function"&&(r=n,n=void 0),t||(t=this.languages),n||(n=this.options.ns),r||(r=qd),this.services.backendConnector.reload(t,n,o=>{s.resolve(),r(o)}),s}use(t){if(!t)throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");if(!t.type)throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");return t.type==="backend"&&(this.modules.backend=t),(t.type==="logger"||t.log&&t.warn&&t.error)&&(this.modules.logger=t),t.type==="languageDetector"&&(this.modules.languageDetector=t),t.type==="i18nFormat"&&(this.modules.i18nFormat=t),t.type==="postProcessor"&&QP.addPostProcessor(t),t.type==="formatter"&&(this.modules.formatter=t),t.type==="3rdParty"&&this.modules.external.push(t),this}setResolvedLanguage(t){if(!(!t||!this.languages)&&!(["cimode","dev"].indexOf(t)>-1))for(let n=0;n-1)&&this.store.hasLanguageSomeTranslations(r)){this.resolvedLanguage=r;break}}}changeLanguage(t,n){var r=this;this.isLanguageChangingTo=t;const s=pc();this.emit("languageChanging",t);const o=c=>{this.language=c,this.languages=this.services.languageUtils.toResolveHierarchy(c),this.resolvedLanguage=void 0,this.setResolvedLanguage(c)},a=(c,u)=>{u?(o(u),this.translator.changeLanguage(u),this.isLanguageChangingTo=void 0,this.emit("languageChanged",u),this.logger.log("languageChanged",u)):this.isLanguageChangingTo=void 0,s.resolve(function(){return r.t(...arguments)}),n&&n(c,function(){return r.t(...arguments)})},l=c=>{!t&&!c&&this.services.languageDetector&&(c=[]);const u=typeof c=="string"?c:this.services.languageUtils.getBestMatchFromCodes(c);u&&(this.language||o(u),this.translator.language||this.translator.changeLanguage(u),this.services.languageDetector&&this.services.languageDetector.cacheUserLanguage&&this.services.languageDetector.cacheUserLanguage(u)),this.loadResources(u,d=>{a(d,u)})};return!t&&this.services.languageDetector&&!this.services.languageDetector.async?l(this.services.languageDetector.detect()):!t&&this.services.languageDetector&&this.services.languageDetector.async?this.services.languageDetector.detect.length===0?this.services.languageDetector.detect().then(l):this.services.languageDetector.detect(l):l(t),s}getFixedT(t,n,r){var s=this;const o=function(a,l){let c;if(typeof l!="object"){for(var u=arguments.length,d=new Array(u>2?u-2:0),f=2;f`${c.keyPrefix}${p}${v}`):h=c.keyPrefix?`${c.keyPrefix}${p}${a}`:a,s.t(h,c)};return typeof t=="string"?o.lng=t:o.lngs=t,o.ns=n,o.keyPrefix=r,o}t(){return this.translator&&this.translator.translate(...arguments)}exists(){return this.translator&&this.translator.exists(...arguments)}setDefaultNamespace(t){this.options.defaultNS=t}hasLoadedNamespace(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!this.isInitialized)return this.logger.warn("hasLoadedNamespace: i18next was not initialized",this.languages),!1;if(!this.languages||!this.languages.length)return this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty",this.languages),!1;const r=n.lng||this.resolvedLanguage||this.languages[0],s=this.options?this.options.fallbackLng:!1,o=this.languages[this.languages.length-1];if(r.toLowerCase()==="cimode")return!0;const a=(l,c)=>{const u=this.services.backendConnector.state[`${l}|${c}`];return u===-1||u===0||u===2};if(n.precheck){const l=n.precheck(this,a);if(l!==void 0)return l}return!!(this.hasResourceBundle(r,t)||!this.services.backendConnector.backend||this.options.resources&&!this.options.partialBundledLanguages||a(r,t)&&(!s||a(o,t)))}loadNamespaces(t,n){const r=pc();return this.options.ns?(typeof t=="string"&&(t=[t]),t.forEach(s=>{this.options.ns.indexOf(s)<0&&this.options.ns.push(s)}),this.loadResources(s=>{r.resolve(),n&&n(s)}),r):(n&&n(),Promise.resolve())}loadLanguages(t,n){const r=pc();typeof t=="string"&&(t=[t]);const s=this.options.preload||[],o=t.filter(a=>s.indexOf(a)<0&&this.services.languageUtils.isSupportedCode(a));return o.length?(this.options.preload=s.concat(o),this.loadResources(a=>{r.resolve(),n&&n(a)}),r):(n&&n(),Promise.resolve())}dir(t){if(t||(t=this.resolvedLanguage||(this.languages&&this.languages.length>0?this.languages[0]:this.language)),!t)return"rtl";const n=["ar","shu","sqr","ssh","xaa","yhd","yud","aao","abh","abv","acm","acq","acw","acx","acy","adf","ads","aeb","aec","afb","ajp","apc","apd","arb","arq","ars","ary","arz","auz","avl","ayh","ayl","ayn","ayp","bbz","pga","he","iw","ps","pbt","pbu","pst","prp","prd","ug","ur","ydd","yds","yih","ji","yi","hbo","men","xmn","fa","jpr","peo","pes","prs","dv","sam","ckb"],r=this.services&&this.services.languageUtils||new Q1(eC());return n.indexOf(r.getLanguagePartFromCode(t))>-1||t.toLowerCase().indexOf("-arab")>1?"rtl":"ltr"}static createInstance(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;return new Au(t,n)}cloneInstance(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:qd;const r=t.forkResourceStore;r&&delete t.forkResourceStore;const s={...this.options,...t,isClone:!0},o=new Au(s);return(t.debug!==void 0||t.prefix!==void 0)&&(o.logger=o.logger.clone(t)),["store","services","language"].forEach(l=>{o[l]=this[l]}),o.services={...this.services},o.services.utils={hasLoadedNamespace:o.hasLoadedNamespace.bind(o)},r&&(o.store=new J1(this.store.data,s),o.services.resourceStore=o.store),o.translator=new Tp(o.services,s),o.translator.on("*",function(l){for(var c=arguments.length,u=new Array(c>1?c-1:0),d=1;d