diff --git a/manager/dist/assets/index-DvWuPxCF.js b/manager/dist/assets/index-iGvDtq7l.js similarity index 86% rename from manager/dist/assets/index-DvWuPxCF.js rename to manager/dist/assets/index-iGvDtq7l.js index f51cf039..7dfe40b9 100644 --- a/manager/dist/assets/index-DvWuPxCF.js +++ b/manager/dist/assets/index-iGvDtq7l.js @@ -378,4 +378,4 @@ lodash-es/lodash.js: * LICENSE.md file in the root directory of this source tree. * * @license MIT - */function So(e,t){return e?AZ(e)?m.createElement(e,t):e:null}function AZ(e){return FZ(e)||typeof e=="function"||LZ(e)}function FZ(e){return typeof e=="function"&&(()=>{const t=Object.getPrototypeOf(e);return t.prototype&&t.prototype.isReactComponent})()}function LZ(e){return typeof e=="object"&&typeof e.$$typeof=="symbol"&&["react.memo","react.forward_ref"].includes(e.$$typeof.description)}function Qu(e){const t={state:{},onStateChange:()=>{},renderFallbackValue:null,...e},[n]=m.useState(()=>({current:PZ(t)})),[r,o]=m.useState(()=>n.current.initialState);return n.current.setOptions(s=>({...s,...e,state:{...r,...e.state},onStateChange:a=>{o(a),e.onStateChange==null||e.onStateChange(a)}})),n.current}const jl=m.forwardRef(({className:e,...t},n)=>l.jsx("div",{className:"relative w-full overflow-auto",children:l.jsx("table",{ref:n,className:he("w-full caption-bottom text-sm",e),...t})}));jl.displayName="Table";const Rl=m.forwardRef(({className:e,...t},n)=>l.jsx("thead",{ref:n,className:he("[&_tr]:border-b",e),...t}));Rl.displayName="TableHeader";const Il=m.forwardRef(({className:e,...t},n)=>l.jsx("tbody",{ref:n,className:he("[&_tr:last-child]:border-0",e),...t}));Il.displayName="TableBody";const $Z=m.forwardRef(({className:e,...t},n)=>l.jsx("tfoot",{ref:n,className:he("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",e),...t}));$Z.displayName="TableFooter";const Sn=m.forwardRef(({className:e,...t},n)=>l.jsx("tr",{ref:n,className:he("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",e),...t}));Sn.displayName="TableRow";const Pl=m.forwardRef(({className:e,...t},n)=>l.jsx("th",{ref:n,className:he("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",e),...t}));Pl.displayName="TableHead";const Gr=m.forwardRef(({className:e,...t},n)=>l.jsx("td",{ref:n,className:he("p-4 align-middle [&:has([role=checkbox])]:pr-0",e),...t}));Gr.displayName="TableCell";const BZ=m.forwardRef(({className:e,...t},n)=>l.jsx("caption",{ref:n,className:he("mt-4 text-sm text-muted-foreground",e),...t}));BZ.displayName="TableCaption";const k1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const o=await UJ(e.name,r,n);t(o)}else console.error("Token not found.")}catch(r){console.error("Errors:",r)}};function IN({difyId:e}){var h,v;const{t}=We(),{instance:n}=ut(),[r,o]=m.useState([]),[s,a]=m.useState([]),[i,c]=m.useState(!1);m.useEffect(()=>{i&&k1(n,a,e)},[n,e,i]);function u(){k1(n,a,e)}const d=async(g,b)=>{var y,x,w;try{if(!n)return;await VJ(n.name,n.token,g,b),se.success(t("dify.toast.success.status")),u()}catch(S){console.error("Error:",S),se.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:()=>l.jsx("div",{className:"text-center",children:t("dify.sessions.table.remoteJid")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>l.jsx("div",{className:"text-center",children:t("dify.sessions.table.pushName")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("pushName")})},{accessorKey:"sessionId",header:()=>l.jsx("div",{className:"text-center",children:t("dify.sessions.table.sessionId")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("sessionId")})},{accessorKey:"status",header:()=>l.jsx("div",{className:"text-center",children:t("dify.sessions.table.status")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:g})=>{const b=g.original;return l.jsxs(ea,{children:[l.jsx(ta,{asChild:!0,children:l.jsxs(Y,{variant:"ghost",className:"h-8 w-8 p-0",children:[l.jsx("span",{className:"sr-only",children:t("dify.sessions.table.actions.title")}),l.jsx(Ou,{className:"h-4 w-4"})]})}),l.jsxs(Co,{align:"end",children:[l.jsx(vl,{children:t("dify.sessions.table.actions.title")}),l.jsx(Za,{}),b.status!=="opened"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"opened"),children:[l.jsx(ng,{className:"mr-2 h-4 w-4"}),t("dify.sessions.table.actions.open")]}),b.status!=="paused"&&b.status!=="closed"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"paused"),children:[l.jsx(tg,{className:"mr-2 h-4 w-4"}),t("dify.sessions.table.actions.pause")]}),b.status!=="closed"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"closed"),children:[l.jsx(Qp,{className:"mr-2 h-4 w-4"}),t("dify.sessions.table.actions.close")]}),l.jsxs(ft,{onClick:()=>d(b.remoteJid,"delete"),children:[l.jsx(Yp,{className:"mr-2 h-4 w-4"}),t("dify.sessions.table.actions.delete")]})]})]})}}],p=Qu({data:s,columns:f,onSortingChange:o,getCoreRowModel:qu(),getPaginationRowModel:Ju(),getSortedRowModel:Zu(),getFilteredRowModel:Ku(),state:{sorting:r}});return l.jsxs(Dt,{open:i,onOpenChange:c,children:[l.jsx(Wt,{asChild:!0,children:l.jsxs(Y,{variant:"secondary",size:"sm",children:[l.jsx(Xp,{size:16,className:"mr-1"}),l.jsx("span",{className:"hidden sm:inline",children:t("dify.sessions.label")})]})}),l.jsxs(It,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:u,children:[l.jsx(Pt,{children:l.jsx(Xt,{children:t("dify.sessions.label")})}),l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[l.jsx(B,{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)}}),l.jsx(Y,{variant:"outline",onClick:u,size:"icon",children:l.jsx(rg,{})})]}),l.jsxs(jl,{children:[l.jsx(Rl,{children:p.getHeaderGroups().map(g=>l.jsx(Sn,{children:g.headers.map(b=>l.jsx(Pl,{children:b.isPlaceholder?null:So(b.column.columnDef.header,b.getContext())},b.id))},g.id))}),l.jsx(Il,{children:(v=p.getRowModel().rows)!=null&&v.length?p.getRowModel().rows.map(g=>l.jsx(Sn,{"data-state":g.getIsSelected()&&"selected",children:g.getVisibleCells().map(b=>l.jsx(Gr,{children:So(b.column.columnDef.cell,b.getContext())},b.id))},g.id)):l.jsx(Sn,{children:l.jsx(Gr,{colSpan:f.length,className:"h-24 text-center",children:t("dify.sessions.table.none")})})})]})]})]})]})}const zZ=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 UZ({difyId:e,instance:t,resetTable:n}){const{t:r}=We(),[,o]=m.useState(""),[s,a]=m.useState(!0),[i,c]=m.useState(!1),u=Vn(),d=At({resolver:Ft(zZ),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){o(b);const y=await AJ(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 LJ(t.name,w,e,S),se.success(r("dify.toast.success.update"))}else console.error("Token not found")}catch(w){console.error("Error:",w),se.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 $J(t.name,g,e),se.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 l.jsxs(l.Fragment,{children:[s&&l.jsx(Wr,{}),!s&&l.jsx(Tr,{...d,children:l.jsxs("form",{onSubmit:d.handleSubmit(f),className:"w-full space-y-6 pl-4 pr-2",children:[l.jsxs("div",{className:"space-y-6",children:[l.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[l.jsxs("h3",{className:"mb-4 text-lg font-medium",children:["Dify: ",h]}),l.jsx(Ce,{name:"enabled",className:"flex items-center gap-3"})]}),l.jsxs("div",{className:"space-y-4",children:[l.jsx(L,{name:"description",label:r("dify.form.description.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("dify.form.difySettings.label")}),l.jsx(rt,{})]}),l.jsx(at,{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"}]}),l.jsx(L,{name:"apiUrl",label:r("dify.form.apiUrl.label"),required:!0,children:l.jsx(B,{})}),l.jsx(L,{name:"apiKey",label:r("dify.form.apiKey.label"),required:!0,children:l.jsx(B,{type:"password"})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("dify.form.triggerSettings.label")}),l.jsx(rt,{})]}),l.jsx(at,{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"&&l.jsxs(l.Fragment,{children:[l.jsx(at,{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}),l.jsx(L,{name:"triggerValue",label:r("dify.form.triggerValue.label"),required:!0,children:l.jsx(B,{})})]}),v==="advanced"&&l.jsx(L,{name:"triggerValue",label:r("dify.form.triggerConditions.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("dify.form.generalSettings.label")}),l.jsx(rt,{})]}),l.jsx(L,{name:"expire",label:r("dify.form.expire.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"keywordFinish",label:r("dify.form.keywordFinish.label"),required:!0,children:l.jsx(B,{})}),l.jsx(L,{name:"delayMessage",label:r("dify.form.delayMessage.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"unknownMessage",label:r("dify.form.unknownMessage.label"),children:l.jsx(B,{})}),l.jsx(Ce,{name:"listeningFromMe",label:r("dify.form.listeningFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"stopBotFromMe",label:r("dify.form.stopBotFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"keepOpen",label:r("dify.form.keepOpen.label"),reverse:!0}),l.jsx(L,{name:"debounceTime",label:r("dify.form.debounceTime.label"),children:l.jsx(B,{type:"number"})})]})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx(IN,{difyId:e}),l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsxs(Dt,{open:i,onOpenChange:c,children:[l.jsx(Wt,{asChild:!0,children:l.jsx(Y,{variant:"destructive",size:"sm",children:r("dify.button.delete")})}),l.jsx(It,{children:l.jsxs(Pt,{children:[l.jsx(Xt,{children:r("modal.delete.title")}),l.jsx(yl,{children:r("modal.delete.messageSingle")}),l.jsxs(gn,{children:[l.jsx(Y,{size:"sm",variant:"outline",onClick:()=>c(!1),children:r("button.cancel")}),l.jsx(Y,{variant:"destructive",onClick:p,children:r("button.delete")})]})]})})]}),l.jsx(Y,{type:"submit",children:r("dify.button.update")})]})]})]})})]})}const T1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const o=await xN(e.name,r);t(o)}else console.error("Token not found");n(!1)}catch(r){console.error("Error:",r),n(!1)}};function _1(){const{t:e}=We(),t=Wu("(min-width: 768px)"),{instance:n}=ut(),{difyId:r}=Ys(),[o,s]=m.useState(!0),[a,i]=m.useState([]),c=Vn();m.useEffect(()=>{n&&T1(n,i,s)},[n]);const u=f=>{n&&c(`/manager/instance/${n.id}/dify/${f}`)},d=()=>{T1(n,i,s)};return l.jsxs("main",{className:"pt-5",children:[l.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[l.jsx("h3",{className:"text-lg font-medium",children:e("dify.title")}),l.jsxs("div",{className:"flex items-center justify-end gap-2",children:[l.jsx(IN,{}),l.jsx(WJ,{}),l.jsx(qJ,{resetTable:d})]})]}),l.jsx(rt,{className:"my-4"}),l.jsxs(Vu,{direction:t?"horizontal":"vertical",children:[l.jsx(wo,{defaultSize:35,className:"pr-4",children:l.jsx("div",{className:"flex flex-col gap-3",children:o?l.jsx(Wr,{}):l.jsx(l.Fragment,{children:a&&a.length>0&&Array.isArray(a)?a.map(f=>l.jsxs(Y,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>u(`${f.id}`),variant:r===f.id?"secondary":"outline",children:[l.jsx("h4",{className:"text-base",children:f.description||f.id}),l.jsx("p",{className:"text-sm font-normal text-muted-foreground",children:f.botType})]},f.id)):l.jsx(Y,{variant:"link",children:e("dify.table.none")})})})}),r&&l.jsxs(l.Fragment,{children:[l.jsx(Hu,{withHandle:!0,className:"border border-border"}),l.jsx(wo,{className:"",children:l.jsx(UZ,{difyId:r,instance:n,resetTable:d})})]})]})]})}const cr=new Cr,Hg=async(e,t)=>(await cr.getInstance().get(`/openai/creds/${e}`,{headers:{apikey:t}})).data,VZ=async(e,t,n)=>(await cr.getInstance().post(`/openai/creds/${e}`,n,{headers:{apikey:t}})).data,HZ=async(e,t)=>(await cr.getInstance().delete(`/openai/creds/${e}/${t}`)).data,PN=async(e,t)=>(await cr.getInstance().get(`/openai/find/${e}`,{headers:{apikey:t}})).data,WZ=async(e,t,n)=>(await cr.getInstance().get(`/openai/fetch/${n}/${e}`,{headers:{apikey:t}})).data,GZ=async(e,t,n)=>(await cr.getInstance().post(`/openai/create/${e}`,n,{headers:{apikey:t}})).data,qZ=async(e,t,n,r)=>(await cr.getInstance().put(`/openai/update/${n}/${e}`,r,{headers:{apikey:t}})).data,KZ=async(e,t,n)=>(await cr.getInstance().delete(`/openai/delete/${n}/${e}`,{headers:{apikey:t}})).data,JZ=async(e,t)=>(await cr.getInstance().get(`/openai/fetchSettings/${e}`,{headers:{apikey:t}})).data,ZZ=async(e,t,n)=>(await cr.getInstance().post(`/openai/settings/${e}`,n,{headers:{apikey:t}})).data,QZ=async(e,t,n)=>(await cr.getInstance().get(`/openai/fetchSessions/${n}/${e}`,{headers:{apikey:t}})).data,YZ=async(e,t,n,r)=>(await cr.getInstance().post(`/openai/changeStatus/${e}`,{remoteJid:n,status:r},{headers:{apikey:t}})).data,NN=async(e,t)=>(await cr.getInstance().get(`/openai/getModels/${e}`,{headers:{apikey:t}})).data,XZ=k.object({name:k.string(),apiKey:k.string()}),fm=async(e,t)=>{try{const n=localStorage.getItem("token");if(n&&e&&e.name){const r=await Hg(e.name,n);t(r)}else console.error("Token not found.")}catch(n){console.error("Error:",n)}};function eQ(){var v;const{t:e}=We(),{instance:t}=ut(),[n,r]=m.useState(!1),[o,s]=m.useState([]),[a,i]=m.useState([]),c=At({resolver:Ft(XZ),defaultValues:{name:"",apiKey:""}});m.useEffect(()=>{n&&fm(t,i)},[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 VZ(t.name,t.token,w),se.success(e("openai.toast.success.credentialsCreate")),d()}catch(w){console.error("Error:",w),se.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(),fm(t,i)}const f=async g=>{var b,y,x;try{await HZ(g,t==null?void 0:t.name),se.success(e("openai.toast.success.credentialsDelete")),fm(t,i)}catch(w){console.error("Error:",w),se.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})=>l.jsxs(Y,{variant:"ghost",onClick:()=>g.toggleSorting(g.getIsSorted()==="asc"),children:[e("openai.credentials.table.name"),l.jsx(qL,{className:"ml-2 h-4 w-4"})]}),cell:({row:g})=>l.jsx("div",{children:g.getValue("name")})},{accessorKey:"apiKey",header:()=>l.jsx("div",{className:"text-right",children:e("openai.credentials.table.apiKey")}),cell:({row:g})=>l.jsxs("div",{children:[`${g.getValue("apiKey")}`.slice(0,20),"..."]})},{id:"actions",enableHiding:!1,cell:({row:g})=>{const b=g.original;return l.jsxs(ea,{children:[l.jsx(ta,{asChild:!0,children:l.jsxs(Y,{variant:"ghost",className:"h-8 w-8 p-0",children:[l.jsx("span",{className:"sr-only",children:e("openai.credentials.table.actions.title")}),l.jsx(Ou,{className:"h-4 w-4"})]})}),l.jsxs(Co,{align:"end",children:[l.jsx(vl,{children:e("openai.credentials.table.actions.title")}),l.jsx(Za,{}),l.jsx(ft,{onClick:()=>f(b.id),children:e("openai.credentials.table.actions.delete")})]})]})}}],h=Qu({data:a,columns:p,onSortingChange:s,getCoreRowModel:qu(),getPaginationRowModel:Ju(),getSortedRowModel:Zu(),getFilteredRowModel:Ku(),state:{sorting:o}});return l.jsxs(Dt,{open:n,onOpenChange:r,children:[l.jsx(Wt,{asChild:!0,children:l.jsxs(Y,{variant:"secondary",size:"sm",children:[l.jsx(u4,{size:16,className:"mr-1"}),l.jsx("span",{className:"hidden md:inline",children:e("openai.credentials.title")})]})}),l.jsxs(It,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:d,children:[l.jsx(Pt,{children:l.jsx(Xt,{children:e("openai.credentials.title")})}),l.jsx(Jr,{...c,children:l.jsxs("form",{onSubmit:c.handleSubmit(u),className:"w-full space-y-6",children:[l.jsx("div",{children:l.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[l.jsx(L,{name:"name",label:e("openai.credentials.table.name"),children:l.jsx(B,{})}),l.jsx(L,{name:"apiKey",label:e("openai.credentials.table.apiKey"),children:l.jsx(B,{type:"password"})})]})}),l.jsx(gn,{children:l.jsx(Y,{type:"submit",children:e("openai.button.save")})})]})}),l.jsx(rt,{}),l.jsx("div",{children:l.jsxs(jl,{children:[l.jsx(Rl,{children:h.getHeaderGroups().map(g=>l.jsx(Sn,{children:g.headers.map(b=>l.jsx(Pl,{children:b.isPlaceholder?null:So(b.column.columnDef.header,b.getContext())},b.id))},g.id))}),l.jsx(Il,{children:(v=h.getRowModel().rows)!=null&&v.length?h.getRowModel().rows.map(g=>l.jsx(Sn,{"data-state":g.getIsSelected()&&"selected",children:g.getVisibleCells().map(b=>l.jsx(Gr,{children:So(b.column.columnDef.cell,b.getContext())},b.id))},g.id)):l.jsx(Sn,{children:l.jsx(Gr,{colSpan:p.length,className:"h-24 text-center",children:e("openai.credentials.table.none")})})})]})})]})]})}const tQ=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()}),j1=async(e,t,n,r)=>{try{const o=localStorage.getItem("token");if(o&&e&&e.name){const s=await JZ(e.name,o);t(s);const a=await PN(e.name,o);n(a);const i=await Hg(e.name,o);r(i)}else console.error("Token not found")}catch(o){console.error("Error:",o)}};function nQ(){const{t:e}=We(),{instance:t}=ut(),[n,r]=m.useState(!1),[o,s]=m.useState(),[a,i]=m.useState([]),[c,u]=m.useState(),d=At({resolver:Ft(tQ),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&&j1(t,s,i,u)},[t,n]),m.useEffect(()=>{o&&d.reset({openaiCredsId:o.openaiCredsId,expire:(o==null?void 0:o.expire)??0,keywordFinish:o.keywordFinish,delayMessage:o.delayMessage??0,unknownMessage:o.unknownMessage,listeningFromMe:o.listeningFromMe,stopBotFromMe:o.stopBotFromMe,keepOpen:o.keepOpen,debounceTime:o.debounceTime??0,speechToText:o.speechToText,ignoreJids:o.ignoreJids,openaiIdFallback:o.openaiIdFallback})},[o]);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 ZZ(t.name,t.token,y),se.success(e("openai.toast.defaultSettings.success"))}catch(y){console.error("Error:",y),se.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(){j1(t,s,i,u)}return l.jsxs(Dt,{open:n,onOpenChange:r,children:[l.jsx(Wt,{asChild:!0,children:l.jsxs(Y,{variant:"secondary",size:"sm",children:[l.jsx(pl,{size:16,className:"mr-1"}),l.jsx("span",{className:"hidden md:inline",children:e("openai.defaultSettings")})]})}),l.jsxs(It,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:p,children:[l.jsx(Pt,{children:l.jsx(Xt,{children:e("openai.defaultSettings")})}),l.jsx(Jr,{...d,children:l.jsxs("form",{className:"w-full space-y-6",onSubmit:d.handleSubmit(f),children:[l.jsx("div",{children:l.jsxs("div",{className:"space-y-4",children:[l.jsx(at,{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})))||[]}),l.jsx(at,{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})))??[]}),l.jsx(L,{name:"expire",label:e("openai.form.expire.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"keywordFinish",label:e("openai.form.keywordFinish.label"),children:l.jsx(B,{})}),l.jsx(L,{name:"delayMessage",label:e("openai.form.delayMessage.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"unknownMessage",label:e("openai.form.unknownMessage.label"),children:l.jsx(B,{})}),l.jsx(Ce,{name:"listeningFromMe",label:e("openai.form.listeningFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"stopBotFromMe",label:e("openai.form.stopBotFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"keepOpen",label:e("openai.form.keepOpen.label"),reverse:!0}),l.jsx(Ce,{name:"speechToText",label:e("openai.form.speechToText.label"),reverse:!0}),l.jsx(L,{name:"debounceTime",label:e("openai.form.debounceTime.label"),children:l.jsx(B,{type:"number"})}),l.jsx(Uu,{name:"ignoreJids",label:e("openai.form.ignoreJids.label"),placeholder:e("openai.form.ignoreJids.placeholder")})]})}),l.jsx(gn,{children:l.jsx(Y,{type:"submit",children:e("openai.button.save")})})]})})]})]})}const rQ=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 oQ({resetTable:e}){const{t}=We(),{instance:n}=ut(),[r,o]=m.useState(!1),[s,a]=m.useState(!1),[i,c]=m.useState([]),[u,d]=m.useState([]),f=At({resolver:Ft(rQ),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(()=>{s&&(async()=>{try{if(!n)return;const y=await NN(n.name,n.token);c(y);const x=await Hg(n.name,n.token);d(x)}catch(y){console.error("Error:",y)}})()},[n,s]);const p=async b=>{var y,x,w;try{if(!n||!n.name)throw new Error("instance not found.");o(!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 GZ(n.name,n.token,S),se.success(t("openai.toast.success.create")),a(!1),h(),e()}catch(S){console.error("Error:",S),se.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{o(!1)}};function h(){f.reset()}const v=f.watch("botType"),g=f.watch("triggerType");return l.jsxs(Dt,{open:s,onOpenChange:a,children:[l.jsx(Wt,{asChild:!0,children:l.jsxs(Y,{size:"sm",children:[l.jsx(gl,{size:16,className:"mr-1"}),l.jsx("span",{className:"hidden sm:inline",children:t("openai.button.create")})]})}),l.jsxs(It,{className:"max-w-xl",onCloseAutoFocus:h,children:[l.jsx(Pt,{children:l.jsx(Xt,{children:t("openai.form.title")})}),l.jsx(Jr,{...f,children:l.jsxs("form",{onSubmit:f.handleSubmit(p),className:"w-full space-y-6",children:[l.jsx("div",{children:l.jsxs("div",{className:"space-y-4",children:[l.jsx(Ce,{name:"enabled",label:t("openai.form.enabled.label"),reverse:!0}),l.jsx(L,{name:"description",label:t("openai.form.description.label"),required:!0,children:l.jsx(B,{})}),l.jsx(at,{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}))}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:t("openai.form.openaiSettings.label")}),l.jsx(rt,{})]}),l.jsx(at,{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"&&l.jsxs(l.Fragment,{children:[l.jsx(L,{name:"assistantId",label:t("openai.form.assistantId.label"),required:!0,children:l.jsx(B,{})}),l.jsx(L,{name:"functionUrl",label:t("openai.form.functionUrl.label"),required:!0,children:l.jsx(B,{})})]}),v==="chatCompletion"&&l.jsxs(l.Fragment,{children:[l.jsx(at,{name:"model",label:t("openai.form.model.label"),required:!0,options:i.map(b=>({label:b.id,value:b.id}))}),l.jsx(L,{name:"systemMessages",label:t("openai.form.systemMessages.label"),children:l.jsx(Uo,{})}),l.jsx(L,{name:"assistantMessages",label:t("openai.form.assistantMessages.label"),children:l.jsx(Uo,{})}),l.jsx(L,{name:"userMessages",label:t("openai.form.userMessages.label"),children:l.jsx(Uo,{})}),l.jsx(L,{name:"maxTokens",label:t("openai.form.maxTokens.label"),children:l.jsx(B,{type:"number"})})]}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:t("openai.form.triggerSettings.label")}),l.jsx(rt,{})]}),l.jsx(at,{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"&&l.jsxs(l.Fragment,{children:[l.jsx(at,{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"}]}),l.jsx(L,{name:"triggerValue",label:t("openai.form.triggerValue.label"),required:!0,children:l.jsx(B,{})})]}),g==="advanced"&&l.jsx(L,{name:"triggerValue",label:t("openai.form.triggerConditions.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:t("openai.form.generalSettings.label")}),l.jsx(rt,{})]}),l.jsx(L,{name:"expire",label:t("openai.form.expire.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"keywordFinish",label:t("openai.form.keywordFinish.label"),children:l.jsx(B,{})}),l.jsx(L,{name:"delayMessage",label:t("openai.form.delayMessage.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"unknownMessage",label:t("openai.form.unknownMessage.label"),children:l.jsx(B,{})}),l.jsx(Ce,{name:"listeningFromMe",label:t("openai.form.listeningFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"stopBotFromMe",label:t("openai.form.stopBotFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"keepOpen",label:t("openai.form.keepOpen.label"),reverse:!0}),l.jsx(L,{name:"debounceTime",label:t("openai.form.debounceTime.label"),children:l.jsx(B,{type:"number"})})]})}),l.jsx(gn,{children:l.jsx(Y,{disabled:r,type:"submit",children:t(r?"openai.button.saving":"openai.button.save")})})]})})]})]})}const R1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const o=await QZ(e.name,r,n);t(o)}else console.error("Token not found")}catch(r){console.error("Error:",r)}};function ON({botId:e}){var h,v;const{t}=We(),{instance:n}=ut(),[r,o]=m.useState([]),[s,a]=m.useState([]),[i,c]=m.useState(!1);m.useEffect(()=>{i&&R1(n,a,e)},[n,e,i]);function u(){R1(n,a,e)}const d=async(g,b)=>{var y,x,w;try{if(!n)return;await YZ(n.name,n.token,g,b),se.success(t("openai.toast.success.status")),u()}catch(S){console.error("Error:",S),se.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:()=>l.jsx("div",{className:"text-center",children:t("openai.sessions.table.remoteJid")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>l.jsx("div",{className:"text-center",children:t("openai.sessions.table.pushName")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("pushName")})},{accessorKey:"sessionId",header:()=>l.jsx("div",{className:"text-center",children:t("openai.sessions.table.sessionId")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("sessionId")})},{accessorKey:"status",header:()=>l.jsx("div",{className:"text-center",children:t("openai.sessions.table.status")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:g})=>{const b=g.original;return l.jsxs(ea,{children:[l.jsx(ta,{asChild:!0,children:l.jsxs(Y,{variant:"ghost",size:"icon",children:[l.jsx("span",{className:"sr-only",children:t("openai.sessions.table.actions.title")}),l.jsx(Ou,{className:"h-4 w-4"})]})}),l.jsxs(Co,{align:"end",children:[l.jsx(vl,{children:t("openai.sessions.table.actions.title")}),l.jsx(Za,{}),b.status!=="opened"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"opened"),children:[l.jsx(ng,{className:"mr-2 h-4 w-4"}),t("openai.sessions.table.actions.open")]}),b.status!=="paused"&&b.status!=="closed"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"paused"),children:[l.jsx(tg,{className:"mr-2 h-4 w-4"}),t("openai.sessions.table.actions.pause")]}),b.status!=="closed"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"closed"),children:[l.jsx(Qp,{className:"mr-2 h-4 w-4"}),t("openai.sessions.table.actions.close")]}),l.jsxs(ft,{onClick:()=>d(b.remoteJid,"delete"),children:[l.jsx(Yp,{className:"mr-2 h-4 w-4"}),t("openai.sessions.table.actions.delete")]})]})]})}}],p=Qu({data:s,columns:f,onSortingChange:o,getCoreRowModel:qu(),getPaginationRowModel:Ju(),getSortedRowModel:Zu(),getFilteredRowModel:Ku(),state:{sorting:r}});return l.jsxs(Dt,{open:i,onOpenChange:c,children:[l.jsx(Wt,{asChild:!0,children:l.jsxs(Y,{variant:"secondary",size:"sm",children:[l.jsx(Xp,{size:16,className:"mr-1"}),l.jsx("span",{className:"hidden md:inline",children:t("openai.sessions.label")})]})}),l.jsxs(It,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:u,children:[l.jsx(Pt,{children:l.jsx(Xt,{children:t("openai.sessions.label")})}),l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[l.jsx(B,{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)}}),l.jsx(Y,{variant:"outline",onClick:u,size:"icon",children:l.jsx(rg,{size:16})})]}),l.jsxs(jl,{children:[l.jsx(Rl,{children:p.getHeaderGroups().map(g=>l.jsx(Sn,{children:g.headers.map(b=>l.jsx(Pl,{children:b.isPlaceholder?null:So(b.column.columnDef.header,b.getContext())},b.id))},g.id))}),l.jsx(Il,{children:(v=p.getRowModel().rows)!=null&&v.length?p.getRowModel().rows.map(g=>l.jsx(Sn,{"data-state":g.getIsSelected()&&"selected",children:g.getVisibleCells().map(b=>l.jsx(Gr,{children:So(b.column.columnDef.cell,b.getContext())},b.id))},g.id)):l.jsx(Sn,{children:l.jsx(Gr,{colSpan:f.length,className:"h-24 text-center",children:t("openai.sessions.table.none")})})})]})]})]})]})}const sQ=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 aQ({botId:e,instance:t,resetTable:n}){const{t:r}=We(),[,o]=m.useState(""),[s,a]=m.useState(!0),[i,c]=m.useState(!1),[u,d]=m.useState([]),[f,p]=m.useState([]),h=Vn(),v=At({resolver:Ft(sQ),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){o(C);const T=await WZ(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 NN(t.name,t.token);d(C);const T=await Hg(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 _=localStorage.getItem("token");if(_&&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 qZ(t.name,_,e,I),se.success(r("openai.toast.success.update"))}else console.error("Instance not found")}catch(_){console.error("Error:",_),se.error(`Error: ${(T=(C=(E=_==null?void 0:_.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 KZ(t.name,S,e),se.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 l.jsxs(l.Fragment,{children:[s&&l.jsx(Wr,{}),!s&&l.jsx(Tr,{...v,children:l.jsxs("form",{onSubmit:v.handleSubmit(g),className:"w-full space-y-6 pl-4 pr-2",children:[l.jsxs("div",{className:"space-y-6",children:[l.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[l.jsxs("h3",{className:"mb-4 text-lg font-medium",children:["OpenAI: ",y]}),l.jsx(Ce,{name:"enabled",className:"flex items-center gap-3"})]}),l.jsxs("div",{className:"space-y-4",children:[l.jsx(L,{name:"description",label:r("openai.form.description.label"),required:!0,children:l.jsx(B,{})}),l.jsx(at,{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}))}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("openai.form.openaiSettings.label")}),l.jsx(rt,{})]}),l.jsx(at,{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"&&l.jsxs(l.Fragment,{children:[l.jsx(L,{name:"assistantId",label:r("openai.form.assistantId.label"),required:!0,children:l.jsx(B,{})}),l.jsx(L,{name:"functionUrl",label:r("openai.form.functionUrl.label"),required:!0,children:l.jsx(B,{})})]}),x==="chatCompletion"&&l.jsxs(l.Fragment,{children:[l.jsx(at,{name:"model",label:r("openai.form.model.label"),required:!0,options:u.map(S=>({label:S.id,value:S.id}))}),l.jsx(L,{name:"systemMessages",label:r("openai.form.systemMessages.label"),children:l.jsx(Uo,{})}),l.jsx(L,{name:"assistantMessages",label:r("openai.form.assistantMessages.label"),children:l.jsx(Uo,{})}),l.jsx(L,{name:"userMessages",label:r("openai.form.userMessages.label"),children:l.jsx(Uo,{})}),l.jsx(L,{name:"maxTokens",label:r("openai.form.maxTokens"),children:l.jsx(B,{type:"number"})})]}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("openai.form.triggerSettings.label")}),l.jsx(rt,{})]}),l.jsx(at,{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"&&l.jsxs(l.Fragment,{children:[l.jsx(at,{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"}]}),l.jsx(L,{name:"triggerValue",label:r("openai.form.triggerValue.label"),required:!0,children:l.jsx(B,{})})]}),w==="advanced"&&l.jsx(L,{name:"triggerValue",label:r("openai.form.triggerConditions.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("openai.form.generalSettings.label")}),l.jsx(rt,{})]}),l.jsx(L,{name:"expire",label:r("openai.form.expire.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"keywordFinish",label:r("openai.form.keywordFinish.label"),children:l.jsx(B,{})}),l.jsx(L,{name:"delayMessage",label:r("openai.form.delayMessage.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"unknownMessage",label:r("openai.form.unknownMessage.label"),children:l.jsx(B,{})}),l.jsx(Ce,{name:"listeningFromMe",label:r("openai.form.listeningFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"stopBotFromMe",label:r("openai.form.stopBotFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"keepOpen",label:r("openai.form.keepOpen.label"),reverse:!0}),l.jsx(L,{name:"debounceTime",label:r("openai.form.debounceTime.label"),children:l.jsx(B,{type:"number"})})]})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx(ON,{botId:e}),l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsxs(Dt,{open:i,onOpenChange:c,children:[l.jsx(Wt,{asChild:!0,children:l.jsx(Y,{variant:"destructive",size:"sm",children:r("openai.button.delete")})}),l.jsx(It,{children:l.jsxs(Pt,{children:[l.jsx(Xt,{children:r("modal.delete.title")}),l.jsx(yl,{children:r("modal.delete.messageSingle")}),l.jsxs(gn,{children:[l.jsx(Y,{size:"sm",variant:"outline",onClick:()=>c(!1),children:r("button.cancel")}),l.jsx(Y,{variant:"destructive",onClick:b,children:r("button.delete")})]})]})})]}),l.jsx(Y,{type:"submit",children:r("openai.button.update")})]})]})]})})]})}const I1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const o=await PN(e.name,r);t(o)}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}=We(),t=Wu("(min-width: 768px)"),{instance:n}=ut(),{botId:r}=Ys(),[o,s]=m.useState(!0),[a,i]=m.useState([]),c=Vn();m.useEffect(()=>{n&&I1(n,i,s)},[n]);const u=f=>{n&&c(`/manager/instance/${n.id}/openai/${f}`)},d=()=>{I1(n,i,s)};return l.jsxs("main",{className:"pt-5",children:[l.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[l.jsx("h3",{className:"text-lg font-medium",children:e("openai.title")}),l.jsxs("div",{className:"flex items-center justify-end gap-2",children:[l.jsx(ON,{}),l.jsx(nQ,{}),l.jsx(eQ,{}),l.jsx(oQ,{resetTable:d})]})]}),l.jsx(rt,{className:"my-4"}),l.jsxs(Vu,{direction:t?"horizontal":"vertical",children:[l.jsx(wo,{defaultSize:35,className:"pr-4",children:l.jsx("div",{className:"flex flex-col gap-3",children:o?l.jsx(Wr,{}):l.jsx(l.Fragment,{children:a&&a.length>0&&Array.isArray(a)?a.map(f=>l.jsxs(Y,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>u(`${f.id}`),variant:r===f.id?"secondary":"outline",children:[l.jsx("h4",{className:"text-base",children:f.description||f.id}),l.jsx("p",{className:"text-sm font-normal text-muted-foreground",children:f.botType})]},f.id)):l.jsx(Y,{variant:"link",children:e("openai.table.none")})})})}),r&&l.jsxs(l.Fragment,{children:[l.jsx(Hu,{withHandle:!0,className:"border border-border"}),l.jsx(wo,{className:"",children:l.jsx(aQ,{botId:r,instance:n,resetTable:d})})]})]})]})}const MN=new Cr,iQ=async(e,t)=>(await MN.getInstance().get(`/proxy/find/${e}`,{headers:{apikey:t}})).data,lQ=async(e,t,n)=>(await MN.getInstance().post(`/proxy/set/${e}`,n,{headers:{apikey:t}})).data,cQ=k.object({enabled:k.boolean(),host:k.string(),port:k.string(),protocol:k.string(),username:k.string(),password:k.string()});function uQ(){const{t:e}=We(),{instance:t}=ut(),[n,r]=m.useState(!1),o=At({resolver:Ft(cQ),defaultValues:{enabled:!1,host:"",port:"",protocol:"http",username:"",password:""}});m.useEffect(()=>{(async()=>{if(t){r(!0);try{const i=await iQ(t.name,t.token);o.reset(i)}catch(i){console.error("Error:",i)}finally{r(!1)}}})()},[t,o]);const s=async a=>{var i,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 lQ(t.name,t.token,d),se.success(e("proxy.toast.success"))}catch(d){console.error(e("proxy.toast.error"),d),se.error(`Error : ${(u=(c=(i=d==null?void 0:d.response)==null?void 0:i.data)==null?void 0:c.response)==null?void 0:u.message}`)}finally{r(!1)}}};return l.jsx(l.Fragment,{children:l.jsx(Tr,{...o,children:l.jsx("form",{onSubmit:o.handleSubmit(s),className:"w-full space-y-6",children:l.jsxs("div",{children:[l.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("proxy.title")}),l.jsx(Xs,{className:"my-4"}),l.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[l.jsx(Ce,{name:"enabled",label:e("proxy.form.enabled.label"),className:"w-full justify-between",helper:e("proxy.form.enabled.description")}),l.jsxs("div",{className:"grid gap-4 sm:grid-cols-[10rem_1fr_10rem] md:gap-8",children:[l.jsx(L,{name:"protocol",label:e("proxy.form.protocol.label"),children:l.jsx(B,{})}),l.jsx(L,{name:"host",label:e("proxy.form.host.label"),children:l.jsx(B,{})}),l.jsx(L,{name:"port",label:e("proxy.form.port.label"),children:l.jsx(B,{type:"number"})})]}),l.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 md:gap-8",children:[l.jsx(L,{name:"username",label:e("proxy.form.username.label"),children:l.jsx(B,{})}),l.jsx(L,{name:"password",label:e("proxy.form.password.label"),children:l.jsx(B,{type:"password"})})]}),l.jsx("div",{className:"flex justify-end px-4 pt-6",children:l.jsx(Y,{type:"submit",disabled:n,children:e(n?"proxy.button.saving":"proxy.button.save")})})]})]})})})})}const DN=new Cr,dQ=async(e,t)=>(await DN.getInstance().get(`/rabbitmq/find/${e}`,{headers:{apikey:t}})).data,fQ=async(e,t,n)=>(await DN.getInstance().post(`/rabbitmq/set/${e}`,n,{headers:{apikey:t}})).data,pQ=k.object({enabled:k.boolean(),events:k.array(k.string())});function gQ(){const{t:e}=We(),{instance:t}=ut(),[n,r]=m.useState(!1),o=At({resolver:Ft(pQ),defaultValues:{enabled:!1,events:[]}});m.useEffect(()=>{(async()=>{if(t){r(!0);try{const c=await dQ(t.name,t.token);o.reset(c)}catch(c){console.error("Error:",c)}finally{r(!1)}}})()},[t,o]);const s=async i=>{var c,u,d;if(t){r(!0);try{const f={enabled:i.enabled,events:i.events};await fQ(t.name,t.token,f),se.success(e("rabbitmq.toast.success"))}catch(f){console.error(e("rabbitmq.toast.error"),f),se.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 l.jsx(l.Fragment,{children:l.jsx(Tr,{...o,children:l.jsx("form",{onSubmit:o.handleSubmit(s),className:"w-full space-y-6",children:l.jsxs("div",{children:[l.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("rabbitmq.title")}),l.jsx(Xs,{className:"my-4"}),l.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[l.jsx(Ce,{name:"enabled",label:e("rabbitmq.form.enabled.label"),className:"w-full justify-between",helper:e("rabbitmq.form.enabled.description")}),l.jsx(oa,{control:o.control,name:"events",render:({field:i})=>l.jsxs(ns,{className:"flex flex-col",children:[l.jsx(or,{className:"my-2 text-lg",children:e("rabbitmq.form.events.label")}),l.jsx(xo,{children:l.jsx("div",{className:"flex flex-col gap-2 space-y-1 divide-y",children:a.sort((c,u)=>c.localeCompare(u)).map(c=>l.jsxs("div",{className:"flex items-center justify-between gap-3 pt-3",children:[l.jsx(or,{className:he("break-all",i.value.includes(c)?"text-foreground":"text-muted-foreground"),children:c}),l.jsx(_l,{checked:i.value.includes(c),onCheckedChange:u=>{u?i.onChange([...i.value,c]):i.onChange(i.value.filter(d=>d!==c))}})]},c))})})]})})]}),l.jsx("div",{className:"mx-4 flex justify-end pt-6",children:l.jsx(Y,{type:"submit",disabled:n,children:e(n?"rabbitmq.button.saving":"rabbitmq.button.save")})})]})})})})}const hQ=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 mQ(){const{t:e}=We(),[t,n]=m.useState(!0),[r,o]=m.useState(!1),[s,a]=m.useState(""),{instance:i}=ut(),c=At({resolver:Ft(hQ),defaultValues:{rejectCall:!1,msgCall:"",groupsIgnore:!1,alwaysOnline:!1,readMessages:!1,syncFullHistory:!1,readStatus:!1}});m.useEffect(()=>{(async()=>{try{if(i&&i.name&&i.token){a(i.token);const h=await w4(i.name,i.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,i]);const u=async p=>{try{if(!i||!i.name)throw new Error("instance not found");o(!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 S4(i.name,s,h),se.success(e("settings.toast.success"))}catch(h){console.error(e("settings.toast.success"),h),se.error(e("settings.toast.error"))}finally{o(!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?l.jsx(Wr,{}):l.jsx(l.Fragment,{children:l.jsx(Tr,{...c,children:l.jsx("form",{onSubmit:c.handleSubmit(u),className:"w-full space-y-6",children:l.jsxs("div",{children:[l.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("settings.title")}),l.jsx(rt,{className:"my-4"}),l.jsxs("div",{className:"mx-4 space-y-2 divide-y",children:[l.jsxs("div",{className:"flex flex-col p-4",children:[l.jsx(Ce,{name:"rejectCall",label:e("settings.form.rejectCall.label"),className:"w-full justify-between",helper:e("settings.form.rejectCall.description")}),f&&l.jsx("div",{className:"mr-16 mt-2",children:l.jsx(L,{name:"msgCall",children:l.jsx(Uo,{placeholder:e("settings.form.msgCall.description")})})})]}),d.map(p=>l.jsx("div",{className:"flex p-4",children:l.jsx(Ce,{name:p.name,label:p.label,className:"w-full justify-between",helper:p.description})},p.name)),l.jsx("div",{className:"flex justify-end pt-6",children:l.jsx(Y,{type:"submit",disabled:r,children:e(r?"settings.button.saving":"settings.button.save")})})]})]})})})})}const AN=new Cr,vQ=async(e,t)=>(await AN.getInstance().get(`/sqs/find/${e}`,{headers:{apikey:t}})).data,yQ=async(e,t,n)=>(await AN.getInstance().post(`/sqs/set/${e}`,n,{headers:{apikey:t}})).data,bQ=k.object({enabled:k.boolean(),events:k.array(k.string())});function xQ(){const{t:e}=We(),{instance:t}=ut(),[n,r]=m.useState(!1),o=At({resolver:Ft(bQ),defaultValues:{enabled:!1,events:[]}});m.useEffect(()=>{(async()=>{if(t){r(!0);try{const c=await vQ(t.name,t.token);o.reset(c)}catch(c){console.error("Error",c)}finally{r(!1)}}})()},[t,o]);const s=async i=>{var c,u,d;if(t){r(!0);try{const f={enabled:i.enabled,events:i.events};await yQ(t.name,t.token,f),se.success(e("sqs.toast.success"))}catch(f){console.error(e("sqs.toast.error"),f),se.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 l.jsx(l.Fragment,{children:l.jsx(Tr,{...o,children:l.jsx("form",{onSubmit:o.handleSubmit(s),className:"w-full space-y-6",children:l.jsxs("div",{children:[l.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("sqs.title")}),l.jsx(Xs,{className:"my-4"}),l.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[l.jsx(Ce,{name:"enabled",label:e("sqs.form.enabled.label"),className:"w-full justify-between",helper:e("sqs.form.enabled.description")}),l.jsx(oa,{control:o.control,name:"events",render:({field:i})=>l.jsxs(ns,{className:"flex flex-col",children:[l.jsx(or,{className:"my-2 text-lg",children:e("sqs.form.events.label")}),l.jsx(xo,{children:l.jsx("div",{className:"flex flex-col gap-2 space-y-1 divide-y",children:a.sort((c,u)=>c.localeCompare(u)).map(c=>l.jsxs("div",{className:"flex items-center justify-between gap-3 pt-3",children:[l.jsx(or,{className:he("break-all",i.value.includes(c)?"text-foreground":"text-muted-foreground"),children:c}),l.jsx(_l,{checked:i.value.includes(c),onCheckedChange:u=>{u?i.onChange([...i.value,c]):i.onChange(i.value.filter(d=>d!==c))}})]},c))})})]})})]}),l.jsx("div",{className:"mx-4 flex justify-end pt-6",children:l.jsx(Y,{type:"submit",disabled:n,children:e(n?"sqs.button.saving":"sqs.button.save")})})]})})})})}const os=new Cr,FN=async(e,t)=>(await os.getInstance().get(`/typebot/find/${e}`,{headers:{apikey:t}})).data,wQ=async(e,t,n)=>(await os.getInstance().get(`/typebot/fetch/${n}/${e}`,{headers:{apikey:t}})).data,SQ=async(e,t,n)=>(await os.getInstance().post(`/typebot/create/${e}`,n,{headers:{apikey:t}})).data,CQ=async(e,t,n,r)=>(await os.getInstance().put(`/typebot/update/${n}/${e}`,r,{headers:{apikey:t}})).data,EQ=async(e,t,n)=>(await os.getInstance().delete(`/typebot/delete/${n}/${e}`,{headers:{apikey:t}})).data,kQ=async(e,t)=>(await os.getInstance().get(`/typebot/fetchSettings/${e}`,{headers:{apikey:t}})).data,TQ=async(e,t,n)=>(await os.getInstance().post(`/typebot/settings/${e}`,n,{headers:{apikey:t}})).data,_Q=async(e,t,n)=>(await os.getInstance().get(`/typebot/fetchSessions/${n}/${e}`,{headers:{apikey:t}})).data,jQ=async(e,t,n,r)=>(await os.getInstance().post(`/typebot/changeStatus/${e}`,{remoteJid:n,status:r},{headers:{apikey:t}})).data,RQ=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()}),N1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const o=await kQ(e.name,r);t(o);const s=await FN(e.name,r);n(s)}else console.error("token not found.")}catch(r){console.error("Error:",r)}};function IQ(){const{t:e}=We(),{instance:t}=ut(),[n,r]=m.useState(),[o,s]=m.useState([]),[a,i]=m.useState(!1),c=At({resolver:Ft(RQ),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&&N1(t,r,s)},[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 TQ(t.name,t.token,g),se.success(e("typebot.toast.defaultSettings.success"))}catch(g){console.error(e("typebot.toast.defaultSettings.error"),g),se.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(){N1(t,r,s)}return l.jsxs(Dt,{open:a,onOpenChange:i,children:[l.jsx(Wt,{asChild:!0,children:l.jsxs(Y,{variant:"secondary",size:"sm",children:[l.jsx(pl,{size:16,className:"mr-1"}),l.jsx("span",{className:"hidden sm:inline",children:e("typebot.button.defaultSettings")})]})}),l.jsxs(It,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:d,children:[l.jsx(Pt,{children:l.jsx(Xt,{children:e("typebot.modal.defaultSettings.title")})}),l.jsx(Jr,{...c,children:l.jsxs("form",{className:"w-full space-y-6",onSubmit:c.handleSubmit(u),children:[l.jsx("div",{children:l.jsxs("div",{className:"space-y-4",children:[l.jsx(at,{name:"typebotIdFallback",label:e("typebot.form.typebotIdFallback.label"),options:(o==null?void 0:o.filter(f=>!!f.id).map(f=>({label:f.typebot,value:f.description})))??[]}),l.jsx(L,{name:"expire",label:e("typebot.form.expire.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"keywordFinish",label:e("typebot.form.keywordFinish.label"),children:l.jsx(B,{})}),l.jsx(L,{name:"delayMessage",label:e("typebot.form.delayMessage.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"unknownMessage",label:e("typebot.form.unknownMessage.label"),children:l.jsx(B,{})}),l.jsx(Ce,{name:"listeningFromMe",label:e("typebot.form.listeningFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"stopBotFromMe",label:e("typebot.form.stopBotFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"keepOpen",label:e("typebot.form.keepOpen.label"),reverse:!0}),l.jsx(L,{name:"debounceTime",label:e("typebot.form.debounceTime.label"),children:l.jsx(B,{type:"number"})}),l.jsx(Uu,{name:"ignoreJids",label:e("typebot.form.ignoreJids.label"),placeholder:e("typebot.form.ignoreJids.placeholder")})]})}),l.jsx(gn,{children:l.jsx(Y,{type:"submit",children:e("typebot.button.save")})})]})})]})]})}const PQ=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 NQ({resetTable:e}){const{t}=We(),{instance:n}=ut(),[r,o]=m.useState(!1),[s,a]=m.useState(!1),i=At({resolver:Ft(PQ),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.");o(!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 SQ(n.name,n.token,g),se.success(t("typebot.toast.success.create")),a(!1),u(),e()}catch(g){console.error(t("typebot.toast.error"),g),se.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{o(!1)}};function u(){i.reset()}const d=i.watch("triggerType");return l.jsxs(Dt,{open:s,onOpenChange:a,children:[l.jsx(Wt,{asChild:!0,children:l.jsxs(Y,{variant:"default",className:"mr-5 text-white",children:[l.jsx(gl,{}),l.jsx("span",{className:"hidden sm:inline",children:t("typebot.button.create")})]})}),l.jsxs(It,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:u,children:[l.jsx(Pt,{children:l.jsx(Xt,{children:t("typebot.form.title")})}),l.jsx(Jr,{...i,children:l.jsxs("form",{onSubmit:i.handleSubmit(c),className:"w-full space-y-6",children:[l.jsx("div",{children:l.jsxs("div",{className:"space-y-4",children:[l.jsx(Ce,{name:"enabled",label:t("typebot.form.enabled.label"),reverse:!0}),l.jsx(L,{name:"description",label:t("typebot.form.description.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:t("typebot.form.typebotSettings.label")}),l.jsx(rt,{})]}),l.jsx(L,{name:"url",label:t("typebot.form.url.label"),required:!0,children:l.jsx(B,{})}),l.jsx(L,{name:"typebot",label:t("typebot.form.typebot.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:t("typebot.form.triggerSettings.label")}),l.jsx(rt,{})]}),l.jsx(at,{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"&&l.jsxs(l.Fragment,{children:[l.jsx(at,{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"}]}),l.jsx(L,{name:"triggerValue",label:t("typebot.form.triggerValue.label"),required:!0,children:l.jsx(B,{})})]}),d==="advanced"&&l.jsx(L,{name:"triggerValue",label:t("typebot.form.triggerConditions.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:t("typebot.form.generalSettings.label")}),l.jsx(rt,{})]}),l.jsx(L,{name:"expire",label:t("typebot.form.expire.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"keywordFinish",label:t("typebot.form.keywordFinish.label"),children:l.jsx(B,{})}),l.jsx(L,{name:"delayMessage",label:t("typebot.form.delayMessage.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"unknownMessage",label:t("typebot.form.unknownMessage.label"),children:l.jsx(B,{})}),l.jsx(Ce,{name:"listeningFromMe",label:t("typebot.form.listeningFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"stopBotFromMe",label:t("typebot.form.stopBotFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"keepOpen",label:t("typebot.form.keepOpen.label"),reverse:!0}),l.jsx(L,{name:"debounceTime",label:t("typebot.form.debounceTime.label"),children:l.jsx(B,{type:"number"})})]})}),l.jsx(gn,{children:l.jsx(Y,{disabled:r,type:"submit",children:t("typebot.button.save")})})]})})]})]})}const O1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const o=await _Q(e.name,r,n);t(o)}else console.error("Token ou nome da instância não encontrados.")}catch(r){console.error("Erro ao carregar sessões:",r)}};function LN({typebotId:e}){var h,v;const{t}=We(),{instance:n}=ut(),[r,o]=m.useState([]),[s,a]=m.useState([]),[i,c]=m.useState(!1);m.useEffect(()=>{i&&O1(n,a,e)},[n,e,i]);function u(){O1(n,a,e)}const d=async(g,b)=>{var y,x,w;try{if(!n)return;await jQ(n.name,n.token,g,b),se.success(t("typebot.toast.success.status")),u()}catch(S){console.error("Error:",S),se.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:()=>l.jsx("div",{className:"text-center",children:t("typebot.sessions.table.remoteJid")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>l.jsx("div",{className:"text-center",children:t("typebot.sessions.table.pushName")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("pushName")})},{accessorKey:"sessionId",header:()=>l.jsx("div",{className:"text-center",children:t("typebot.sessions.table.sessionId")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("sessionId")})},{accessorKey:"status",header:()=>l.jsx("div",{className:"text-center",children:t("typebot.sessions.table.status")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:g})=>{const b=g.original;return l.jsxs(ea,{children:[l.jsx(ta,{asChild:!0,children:l.jsxs(Y,{variant:"ghost",className:"h-8 w-8 p-0",children:[l.jsx("span",{className:"sr-only",children:t("typebot.sessions.table.actions.title")}),l.jsx(Ou,{className:"h-4 w-4"})]})}),l.jsxs(Co,{align:"end",children:[l.jsx(vl,{children:"Actions"}),l.jsx(Za,{}),b.status!=="opened"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"opened"),children:[l.jsx(ng,{className:"mr-2 h-4 w-4"}),t("typebot.sessions.table.actions.open")]}),b.status!=="paused"&&b.status!=="closed"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"paused"),children:[l.jsx(tg,{className:"mr-2 h-4 w-4"}),t("typebot.sessions.table.actions.pause")]}),b.status!=="closed"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"closed"),children:[l.jsx(Qp,{className:"mr-2 h-4 w-4"}),t("typebot.sessions.table.actions.close")]}),l.jsxs(ft,{onClick:()=>d(b.remoteJid,"delete"),children:[l.jsx(Yp,{className:"mr-2 h-4 w-4"}),t("typebot.sessions.table.actions.delete")]})]})]})}}],p=Qu({data:s,columns:f,onSortingChange:o,getCoreRowModel:qu(),getPaginationRowModel:Ju(),getSortedRowModel:Zu(),getFilteredRowModel:Ku(),state:{sorting:r}});return l.jsxs(Dt,{open:i,onOpenChange:c,children:[l.jsx(Wt,{asChild:!0,children:l.jsxs(Y,{variant:"secondary",size:"sm",children:[l.jsx(Xp,{size:16,className:"mr-1"})," ",l.jsx("span",{className:"hidden sm:inline",children:t("typebot.sessions.label")})]})}),l.jsxs(It,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:u,children:[l.jsx(Pt,{children:l.jsx(Xt,{children:t("typebot.sessions.label")})}),l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[l.jsx(B,{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)}}),l.jsx(Y,{variant:"outline",onClick:u,size:"icon",children:l.jsx(rg,{size:16})})]}),l.jsxs(jl,{children:[l.jsx(Rl,{children:p.getHeaderGroups().map(g=>l.jsx(Sn,{children:g.headers.map(b=>l.jsx(Pl,{children:b.isPlaceholder?null:So(b.column.columnDef.header,b.getContext())},b.id))},g.id))}),l.jsx(Il,{children:(v=p.getRowModel().rows)!=null&&v.length?p.getRowModel().rows.map(g=>l.jsx(Sn,{"data-state":g.getIsSelected()&&"selected",children:g.getVisibleCells().map(b=>l.jsx(Gr,{children:So(b.column.columnDef.cell,b.getContext())},b.id))},g.id)):l.jsx(Sn,{children:l.jsx(Gr,{colSpan:f.length,className:"h-24 text-center",children:t("typebot.sessions.table.none")})})})]})]})]})]})}const OQ=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 MQ({typebotId:e,instance:t,resetTable:n}){const{t:r}=We(),[,o]=m.useState(""),[s,a]=m.useState(!0),[i,c]=m.useState(!1),u=Vn(),d=At({resolver:Ft(OQ),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){o(b);const y=await wQ(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 CQ(t.name,w,e,S),se.success(r("typebot.toast.success.update"))}else console.error("Token not found")}catch(w){console.error("Error:",w),se.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 EQ(t.name,g,e),se.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 l.jsxs(l.Fragment,{children:[s&&l.jsx(Wr,{}),!s&&l.jsx(Tr,{...d,children:l.jsxs("form",{onSubmit:d.handleSubmit(f),className:"w-full space-y-6 pl-4 pr-2",children:[l.jsxs("div",{className:"space-y-6",children:[l.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[l.jsxs("h3",{className:"mb-4 text-lg font-medium",children:["Typebot: ",h]}),l.jsx(Ce,{name:"enabled",className:"flex items-center gap-3"})]}),l.jsxs("div",{className:"space-y-4",children:[l.jsx(L,{name:"description",label:r("typebot.form.description.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("typebot.form.typebotSettings.label")}),l.jsx(rt,{})]}),l.jsx(L,{name:"url",label:r("typebot.form.url.label"),required:!0,children:l.jsx(B,{})}),l.jsx(L,{name:"typebot",label:r("typebot.form.typebot.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("typebot.form.triggerSettings.label")}),l.jsx(rt,{})]}),l.jsx(at,{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"&&l.jsxs(l.Fragment,{children:[l.jsx(at,{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"}]}),l.jsx(L,{name:"triggerValue",label:r("typebot.form.triggerValue.label"),required:!0,children:l.jsx(B,{})})]}),v==="advanced"&&l.jsx(L,{name:"triggerValue",label:r("typebot.form.triggerConditions.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("typebot.form.generalSettings.label")}),l.jsx(rt,{})]}),l.jsx(L,{name:"expire",label:r("typebot.form.expire.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"keywordFinish",label:r("typebot.form.keywordFinish.label"),children:l.jsx(B,{})}),l.jsx(L,{name:"delayMessage",label:r("typebot.form.delay.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"unknownMessage",label:r("typebot.form.unknownMessage.label"),children:l.jsx(B,{})}),l.jsx(Ce,{name:"listeningFromMe",label:r("typebot.form.listeningFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"stopBotFromMe",label:r("typebot.form.stopBotFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"keepOpen",label:r("typebot.form.keepOpen.label"),reverse:!0}),l.jsx(L,{name:"debounceTime",label:r("typebot.form.debounceTime.label"),children:l.jsx(B,{type:"number"})})]})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx(LN,{typebotId:e}),l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsxs(Dt,{open:i,onOpenChange:c,children:[l.jsx(Wt,{asChild:!0,children:l.jsx(Y,{variant:"destructive",size:"sm",children:r("typebot.button.delete")})}),l.jsx(It,{children:l.jsxs(Pt,{children:[l.jsx(Xt,{children:r("modal.delete.title")}),l.jsx(yl,{children:r("modal.delete.messageSingle")}),l.jsxs(gn,{children:[l.jsx(Y,{size:"sm",variant:"outline",onClick:()=>c(!1),children:r("button.cancel")}),l.jsx(Y,{variant:"destructive",onClick:p,children:r("button.delete")})]})]})})]}),l.jsx(Y,{type:"submit",children:r("typebot.button.update")})]})]})]})})]})}const M1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const o=await FN(e.name,r);t(o)}else console.error("token not found.");n(!1)}catch(r){console.error("Error",r),n(!1)}};function D1(){const{t:e}=We(),t=Wu("(min-width: 768px)"),{instance:n}=ut(),{typebotId:r}=Ys(),[o,s]=m.useState(!0),[a,i]=m.useState([]),c=Vn();m.useEffect(()=>{n&&M1(n,i,s)},[n]);const u=f=>{n&&c(`/manager/instance/${n.id}/typebot/${f}`)},d=()=>{M1(n,i,s)};return l.jsxs("main",{className:"pt-5",children:[l.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[l.jsx("h3",{className:"text-lg font-medium",children:e("typebot.title")}),l.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[l.jsx(LN,{}),l.jsx(IQ,{}),l.jsx(NQ,{resetTable:d})]})]}),l.jsx(rt,{className:"my-4"}),l.jsxs(Vu,{direction:t?"horizontal":"vertical",children:[l.jsx(wo,{defaultSize:35,className:"pr-4",children:l.jsx("div",{className:"flex flex-col gap-3",children:o?l.jsx(Wr,{}):l.jsx(l.Fragment,{children:a&&a.length>0&&Array.isArray(a)?a.map(f=>l.jsx(Y,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>u(`${f.id}`),variant:r===f.id?"secondary":"outline",children:f.description?l.jsxs(l.Fragment,{children:[l.jsx("h4",{className:"text-base",children:f.description}),l.jsxs("p",{className:"text-wrap text-sm font-normal text-muted-foreground",children:[f.url," - ",f.typebot]})]}):l.jsxs(l.Fragment,{children:[l.jsx("h4",{className:"text-base",children:f.url}),l.jsx("p",{className:"text-wrap text-sm font-normal text-muted-foreground",children:f.typebot})]})},f.id)):l.jsx(Y,{variant:"link",children:e("typebot.table.none")})})})}),r&&l.jsxs(l.Fragment,{children:[l.jsx(Hu,{withHandle:!0,className:"border border-black"}),l.jsx(wo,{className:"",children:l.jsx(MQ,{typebotId:r,instance:n,resetTable:d})})]})]})]})}const $N=new Cr,DQ=async(e,t)=>(await $N.getInstance().get(`/webhook/find/${e}`,{headers:{apikey:t}})).data,AQ=async(e,t,n)=>(await $N.getInstance().post(`/webhook/set/${e}`,n,{headers:{apikey:t}})).data,FQ=k.object({enabled:k.boolean(),url:k.string().url("Invalid URL format"),events:k.array(k.string()),webhookBase64:k.boolean(),webhookByEvents:k.boolean()});function LQ(){const{t:e}=We(),{instance:t}=ut(),[n,r]=m.useState(!1),o=At({resolver:Ft(FQ),defaultValues:{enabled:!1,url:"",events:[],webhookBase64:!1,webhookByEvents:!1}});m.useEffect(()=>{(async()=>{if(t){r(!0);try{const c=await DQ(t.name,t.token);o.reset(c)}catch(c){console.error("Error:",c)}finally{r(!1)}}})()},[t,o]);const s=async i=>{var c,u,d;if(t){r(!0);try{const f={enabled:i.enabled,url:i.url,events:i.events,webhookBase64:i.webhookBase64,webhookByEvents:i.webhookByEvents};await AQ(t.name,t.token,f),se.success(e("webhook.toast.success"))}catch(f){console.error(e("webhook.toast.error"),f),se.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 l.jsx(l.Fragment,{children:l.jsx(Tr,{...o,children:l.jsx("form",{onSubmit:o.handleSubmit(s),className:"w-full space-y-6",children:l.jsxs("div",{children:[l.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("webhook.title")}),l.jsx(Xs,{className:"my-4"}),l.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[l.jsx(Ce,{name:"enabled",label:e("webhook.form.enabled.label"),className:"w-full justify-between",helper:e("webhook.form.enabled.description")}),l.jsx(L,{name:"url",label:"URL",children:l.jsx(B,{})}),l.jsx(Ce,{name:"webhookByEvents",label:e("webhook.form.webhookByEvents.label"),className:"w-full justify-between",helper:e("webhook.form.webhookByEvents.description")}),l.jsx(Ce,{name:"webhookBase64",label:e("webhook.form.webhookBase64.label"),className:"w-full justify-between",helper:e("webhook.form.webhookBase64.description")}),l.jsx(oa,{control:o.control,name:"events",render:({field:i})=>l.jsxs(ns,{className:"flex flex-col",children:[l.jsx(or,{className:"my-2 text-lg",children:e("webhook.form.events.label")}),l.jsx(xo,{children:l.jsx("div",{className:"flex flex-col gap-2 space-y-1 divide-y",children:a.sort((c,u)=>c.localeCompare(u)).map(c=>l.jsxs("div",{className:"flex items-center justify-between gap-3 pt-3",children:[l.jsx(or,{className:he("break-all",i.value.includes(c)?"text-foreground":"text-muted-foreground"),children:c}),l.jsx(_l,{checked:i.value.includes(c),onCheckedChange:u=>{u?i.onChange([...i.value,c]):i.onChange(i.value.filter(d=>d!==c))}})]},c))})})]})})]}),l.jsx("div",{className:"mx-4 flex justify-end pt-6",children:l.jsx(Y,{type:"submit",disabled:n,children:e(n?"webhook.button.saving":"webhook.button.save")})})]})})})})}const BN=new Cr,$Q=async(e,t)=>(await BN.getInstance().get(`/websocket/find/${e}`,{headers:{apikey:t}})).data,BQ=async(e,t,n)=>(await BN.getInstance().post(`/websocket/set/${e}`,n,{headers:{apikey:t}})).data,zQ=k.object({enabled:k.boolean(),events:k.array(k.string())});function UQ(){const{t:e}=We(),{instance:t}=ut(),[n,r]=m.useState(!1),o=At({resolver:Ft(zQ),defaultValues:{enabled:!1,events:[]}});m.useEffect(()=>{(async()=>{if(t){r(!0);try{const c=await $Q(t.name,t.token);o.reset(c)}catch(c){console.error("Erro ao buscar dados do websocket:",c)}finally{r(!1)}}})()},[t,o]);const s=async i=>{var c,u,d;if(t){r(!0);try{const f={enabled:i.enabled,events:i.events};await BQ(t.name,t.token,f),se.success(e("websocket.toast.success"))}catch(f){console.error(e("websocket.toast.error"),f),se.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 l.jsx(l.Fragment,{children:l.jsx(Tr,{...o,children:l.jsx("form",{onSubmit:o.handleSubmit(s),className:"w-full space-y-6",children:l.jsxs("div",{children:[l.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("websocket.title")}),l.jsx(Xs,{className:"my-4"}),l.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[l.jsx(Ce,{name:"enabled",label:e("websocket.form.enabled.label"),className:"w-full justify-between",helper:e("websocket.form.enabled.description")}),l.jsx(oa,{control:o.control,name:"events",render:({field:i})=>l.jsxs(ns,{className:"flex flex-col",children:[l.jsx(or,{className:"my-2 text-lg",children:e("websocket.form.events.label")}),l.jsx(xo,{children:l.jsx("div",{className:"flex flex-col gap-2 space-y-1 divide-y",children:a.sort((c,u)=>c.localeCompare(u)).map(c=>l.jsxs("div",{className:"flex items-center justify-between gap-3 pt-3",children:[l.jsx(or,{className:he("break-all",i.value.includes(c)?"text-foreground":"text-muted-foreground"),children:c}),l.jsx(_l,{checked:i.value.includes(c),onCheckedChange:u=>{u?i.onChange([...i.value,c]):i.onChange(i.value.filter(d=>d!==c))}})]},c))})})]})})]}),l.jsx("div",{className:"mx-4 flex justify-end pt-6",children:l.jsx(Y,{type:"submit",disabled:n,children:e(n?"websocket.button.saving":"websocket.button.save")})})]})})})})}const VQ=k.object({serverUrl:k.string({required_error:"serverUrl is required"}).url("URL inválida"),apiKey:k.string({required_error:"ApiKey is required"})});function HQ(){const{t:e}=We(),t=Vn(),n=At({resolver:Ft(VQ),defaultValues:{serverUrl:window.location.protocol+"//"+window.location.host,apiKey:""}}),r=async o=>{const s=await lT(o.serverUrl);if(!s||!s.version){cT(),n.setError("serverUrl",{type:"manual",message:e("login.message.invalidServer")});return}if(!await oL(o.serverUrl,o.apiKey)){n.setError("apiKey",{type:"manual",message:e("login.message.invalidCredentials")});return}if(!await rL(o.serverUrl,o.apiKey)){se.error(e("login.message.invalidCredentials"));return}localStorage.setItem("version",s.version),localStorage.setItem("clientName",s.clientName),t("/manager/")};return l.jsxs("div",{className:"flex min-h-screen flex-col",children:[l.jsx("div",{className:"flex items-center justify-center pt-2",children:l.jsx("img",{className:"h-10",src:"/assets/images/evolution-logo.png",alt:"logo"})}),l.jsx("div",{className:"flex flex-1 items-center justify-center p-8",children:l.jsxs(ba,{className:"b-none w-[350px] shadow-none",children:[l.jsxs(xa,{children:[l.jsx(Ec,{className:"text-center",children:e("login.title")}),l.jsx(rR,{className:"text-center",children:e("login.description")})]}),l.jsx(Tr,{...n,children:l.jsxs("form",{onSubmit:n.handleSubmit(r),children:[l.jsx(wa,{children:l.jsxs("div",{className:"grid w-full items-center gap-4",children:[l.jsx(L,{required:!0,name:"serverUrl",label:e("login.form.serverUrl"),children:l.jsx(B,{})}),l.jsx(L,{required:!0,name:"apiKey",label:e("login.form.apiKey"),children:l.jsx(B,{type:"password"})})]})}),l.jsx(xg,{className:"flex justify-center",children:l.jsx(Y,{className:"w-full",type:"submit",children:e("login.button.login")})})]})})]})}),l.jsx(db,{})]})}const ss=new Cr,zN=async(e,t)=>(await ss.getInstance().get(`/generic/find/${e}`,{headers:{apikey:t}})).data,WQ=async(e,t,n)=>(await ss.getInstance().get(`/generic/fetch/${n}/${e}`,{headers:{apikey:t}})).data,GQ=async(e,t,n)=>(await ss.getInstance().post(`/generic/create/${e}`,n,{headers:{apikey:t}})).data,qQ=async(e,t,n,r)=>(await ss.getInstance().put(`/generic/update/${n}/${e}`,r,{headers:{apikey:t}})).data,KQ=async(e,t,n)=>(await ss.getInstance().delete(`/generic/delete/${n}/${e}`,{headers:{apikey:t}})).data,JQ=async(e,t)=>(await ss.getInstance().get(`/generic/fetchSettings/${e}`,{headers:{apikey:t}})).data,ZQ=async(e,t,n)=>(await ss.getInstance().post(`/generic/settings/${e}`,n,{headers:{apikey:t}})).data,QQ=async(e,t,n)=>(await ss.getInstance().get(`/generic/fetchSessions/${n}/${e}`,{headers:{apikey:t}})).data,YQ=async(e,t,n,r)=>(await ss.getInstance().post(`/generic/changeStatus/${e}`,{remoteJid:n,status:r},{headers:{apikey:t}})).data,XQ=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()}),A1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const o=await JQ(e.name,r);t(o);const s=await zN(e.name,r);n(s)}else console.error("Token not found.")}catch(r){console.error("Error:",r)}};function eY(){const{t:e}=We(),{instance:t}=ut(),[n,r]=m.useState(!1),[o,s]=m.useState(),[a,i]=m.useState([]),c=At({resolver:Ft(XQ),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&&A1(t,s,i)},[t,n]),m.useEffect(()=>{o&&c.reset({expire:o!=null&&o.expire?o.expire.toString():"0",keywordFinish:o.keywordFinish,delayMessage:o.delayMessage?o.delayMessage.toString():"0",unknownMessage:o.unknownMessage,listeningFromMe:o.listeningFromMe,stopBotFromMe:o.stopBotFromMe,keepOpen:o.keepOpen,debounceTime:o.debounceTime?o.debounceTime.toString():"0",ignoreJids:o.ignoreJids,botIdFallback:o.botIdFallback})},[o]);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 ZQ(t.name,t.token,g),se.success(e("genericBot.toast.defaultSettings.success"))}catch(g){console.error("Error:",g),se.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(){A1(t,s,i)}return l.jsxs(Dt,{open:n,onOpenChange:r,children:[l.jsx(Wt,{asChild:!0,children:l.jsxs(Y,{variant:"secondary",size:"sm",children:[l.jsx(pl,{size:16,className:"mr-1"}),l.jsx("span",{className:"hidden sm:inline",children:e("genericBot.defaultSettings")})]})}),l.jsxs(It,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:d,children:[l.jsx(Pt,{children:l.jsx(Xt,{children:e("genericBot.defaultSettings")})}),l.jsx(Jr,{...c,children:l.jsxs("form",{className:"w-full space-y-6",onSubmit:c.handleSubmit(u),children:[l.jsx("div",{children:l.jsxs("div",{className:"space-y-4",children:[l.jsx(at,{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})))??[]}),l.jsx(L,{name:"expire",label:e("genericBot.form.expire.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"keywordFinish",label:e("genericBot.form.keywordFinish.label"),children:l.jsx(B,{})}),l.jsx(L,{name:"delayMessage",label:e("genericBot.form.delayMessage.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"unknownMessage",label:e("genericBot.form.unknownMessage.label"),children:l.jsx(B,{})}),l.jsx(Ce,{name:"listeningFromMe",label:e("genericBot.form.listeningFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"stopBotFromMe",label:e("genericBot.form.stopBotFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"keepOpen",label:e("genericBot.form.keepOpen.label"),reverse:!0}),l.jsx(L,{name:"debounceTime",label:e("genericBot.form.debounceTime.label"),children:l.jsx(B,{type:"number"})}),l.jsx(Uu,{name:"ignoreJids",label:e("genericBot.form.ignoreJids.label"),placeholder:e("genericBot.form.ignoreJids.placeholder")})]})}),l.jsx(gn,{children:l.jsx(Y,{type:"submit",children:e("genericBot.button.save")})})]})})]})]})}const tY=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 nY({resetTable:e}){const{t}=We(),{instance:n}=ut(),[r,o]=m.useState(!1),[s,a]=m.useState(!1),i=At({resolver:Ft(tY),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");o(!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 GQ(n.name,n.token,g),se.success(t("genericBot.toast.success.create")),a(!1),u(),e()}catch(g){console.error("Error:",g),se.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{o(!1)}};function u(){i.reset()}const d=i.watch("triggerType");return l.jsxs(Dt,{open:s,onOpenChange:a,children:[l.jsx(Wt,{asChild:!0,children:l.jsxs(Y,{size:"sm",children:[l.jsx(gl,{size:16,className:"mr-1"}),l.jsx("span",{className:"hidden sm:inline",children:t("genericBot.button.create")})]})}),l.jsxs(It,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:u,children:[l.jsx(Pt,{children:l.jsx(Xt,{children:t("genericBot.form.title")})}),l.jsx(Jr,{...i,children:l.jsxs("form",{onSubmit:i.handleSubmit(c),className:"w-full space-y-6",children:[l.jsx("div",{children:l.jsxs("div",{className:"space-y-4",children:[l.jsx(Ce,{name:"enabled",label:t("genericBot.form.enabled.label"),reverse:!0}),l.jsx(L,{name:"description",label:t("genericBot.form.description.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:t("genericBot.form.genericBotSettings.label")}),l.jsx(rt,{})]}),l.jsx(L,{name:"apiUrl",label:t("genericBot.form.apiUrl.label"),required:!0,children:l.jsx(B,{})}),l.jsx(L,{name:"apiKey",label:t("genericBot.form.apiKey.label"),required:!0,children:l.jsx(B,{type:"password"})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:t("genericBot.form.triggerSettings.label")}),l.jsx(rt,{})]}),l.jsx(at,{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"&&l.jsxs(l.Fragment,{children:[l.jsx(at,{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}),l.jsx(L,{name:"triggerValue",label:t("genericBot.form.triggerValue.label"),required:!0,children:l.jsx(B,{})})]}),d==="advanced"&&l.jsx(L,{name:"triggerValue",label:t("genericBot.form.triggerConditions.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:t("genericBot.form.generalSettings.label")}),l.jsx(rt,{})]}),l.jsx(L,{name:"expire",label:t("genericBot.form.expire.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"keywordFinish",label:t("genericBot.form.keywordFinish.label"),children:l.jsx(B,{})}),l.jsx(L,{name:"delayMessage",label:t("genericBot.form.delayMessage.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"unknownMessage",label:t("genericBot.form.unknownMessage.label"),children:l.jsx(B,{})}),l.jsx(Ce,{name:"listeningFromMe",label:t("genericBot.form.listeningFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"stopBotFromMe",label:t("genericBot.form.stopBotFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"keepOpen",label:t("genericBot.form.keepOpen.label"),reverse:!0}),l.jsx(L,{name:"debounceTime",label:t("genericBot.form.debounceTime.label"),children:l.jsx(B,{type:"number"})})]})}),l.jsx(gn,{children:l.jsx(Y,{disabled:r,type:"submit",children:t("genericBot.button.save")})})]})})]})]})}const F1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const o=await QQ(e.name,r,n);t(o)}else console.error("Token not found.")}catch(r){console.error("Errors:",r)}};function UN({genericBotId:e}){var h,v;const{t}=We(),{instance:n}=ut(),[r,o]=m.useState([]),[s,a]=m.useState([]),[i,c]=m.useState(!1);m.useEffect(()=>{i&&F1(n,a,e)},[n,e,i]);function u(){F1(n,a,e)}const d=async(g,b)=>{var y,x,w;try{if(!n)return;await YQ(n.name,n.token,g,b),se.success(t("genericBot.toast.success.status")),u()}catch(S){console.error("Error:",S),se.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:()=>l.jsx("div",{className:"text-center",children:t("genericBot.sessions.table.remoteJid")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>l.jsx("div",{className:"text-center",children:t("genericBot.sessions.table.pushName")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("pushName")})},{accessorKey:"sessionId",header:()=>l.jsx("div",{className:"text-center",children:t("genericBot.sessions.table.sessionId")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("sessionId")})},{accessorKey:"status",header:()=>l.jsx("div",{className:"text-center",children:t("genericBot.sessions.table.status")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:g})=>{const b=g.original;return l.jsxs(ea,{children:[l.jsx(ta,{asChild:!0,children:l.jsxs(Y,{variant:"ghost",className:"h-8 w-8 p-0",children:[l.jsx("span",{className:"sr-only",children:t("genericBot.sessions.table.actions.title")}),l.jsx(Ou,{className:"h-4 w-4"})]})}),l.jsxs(Co,{align:"end",children:[l.jsx(vl,{children:t("genericBot.sessions.table.actions.title")}),l.jsx(Za,{}),b.status!=="opened"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"opened"),children:[l.jsx(ng,{className:"mr-2 h-4 w-4"}),t("genericBot.sessions.table.actions.open")]}),b.status!=="paused"&&b.status!=="closed"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"paused"),children:[l.jsx(tg,{className:"mr-2 h-4 w-4"}),t("genericBot.sessions.table.actions.pause")]}),b.status!=="closed"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"closed"),children:[l.jsx(Qp,{className:"mr-2 h-4 w-4"}),t("genericBot.sessions.table.actions.close")]}),l.jsxs(ft,{onClick:()=>d(b.remoteJid,"delete"),children:[l.jsx(Yp,{className:"mr-2 h-4 w-4"}),t("genericBot.sessions.table.actions.delete")]})]})]})}}],p=Qu({data:s,columns:f,onSortingChange:o,getCoreRowModel:qu(),getPaginationRowModel:Ju(),getSortedRowModel:Zu(),getFilteredRowModel:Ku(),state:{sorting:r}});return l.jsxs(Dt,{open:i,onOpenChange:c,children:[l.jsx(Wt,{asChild:!0,children:l.jsxs(Y,{variant:"secondary",size:"sm",children:[l.jsx(Xp,{size:16,className:"mr-1"}),l.jsx("span",{className:"hidden sm:inline",children:t("genericBot.sessions.label")})]})}),l.jsxs(It,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:u,children:[l.jsx(Pt,{children:l.jsx(Xt,{children:t("genericBot.sessions.label")})}),l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[l.jsx(B,{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)}}),l.jsx(Y,{variant:"outline",onClick:u,size:"icon",children:l.jsx(rg,{})})]}),l.jsxs(jl,{children:[l.jsx(Rl,{children:p.getHeaderGroups().map(g=>l.jsx(Sn,{children:g.headers.map(b=>l.jsx(Pl,{children:b.isPlaceholder?null:So(b.column.columnDef.header,b.getContext())},b.id))},g.id))}),l.jsx(Il,{children:(v=p.getRowModel().rows)!=null&&v.length?p.getRowModel().rows.map(g=>l.jsx(Sn,{"data-state":g.getIsSelected()&&"selected",children:g.getVisibleCells().map(b=>l.jsx(Gr,{children:So(b.column.columnDef.cell,b.getContext())},b.id))},g.id)):l.jsx(Sn,{children:l.jsx(Gr,{colSpan:f.length,className:"h-24 text-center",children:t("genericBot.sessions.table.none")})})})]})]})]})]})}const rY=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 oY({genericBotId:e,instance:t,resetTable:n}){const{t:r}=We(),[,o]=m.useState(""),[s,a]=m.useState(!0),[i,c]=m.useState(!1),u=Vn(),d=At({resolver:Ft(rY),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){o(b);const y=await WQ(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 qQ(t.name,w,e,S),se.success(r("genericBot.toast.success.update"))}else console.error("Token not found")}catch(w){console.error("Error:",w),se.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 KQ(t.name,g,e),se.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 l.jsxs(l.Fragment,{children:[s&&l.jsx(Wr,{}),!s&&l.jsx(Tr,{...d,children:l.jsxs("form",{onSubmit:d.handleSubmit(f),className:"w-full space-y-6 pl-4 pr-2",children:[l.jsxs("div",{className:"space-y-6",children:[l.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[l.jsxs("h3",{className:"mb-4 text-lg font-medium",children:["GenericBot: ",h]}),l.jsx(Ce,{name:"enabled",className:"flex items-center gap-3"})]}),l.jsxs("div",{className:"space-y-4",children:[l.jsx(L,{name:"description",label:r("genericBot.form.description.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("genericBot.form.genericBotSettings.label")}),l.jsx(rt,{})]}),l.jsx(L,{name:"apiUrl",label:r("genericBot.form.apiUrl.label"),required:!0,children:l.jsx(B,{})}),l.jsx(L,{name:"apiKey",label:r("genericBot.form.apiKey.label"),required:!0,children:l.jsx(B,{type:"password"})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("genericBot.form.triggerSettings.label")}),l.jsx(rt,{})]}),l.jsx(at,{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"}],required:!0}),v==="keyword"&&l.jsxs(l.Fragment,{children:[l.jsx(at,{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"}],required:!0}),l.jsx(L,{name:"triggerValue",label:r("genericBot.form.triggerValue.label"),required:!0,children:l.jsx(B,{})})]}),v==="advanced"&&l.jsx(L,{name:"triggerValue",label:r("genericBot.form.triggerConditions.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("genericBot.form.generalSettings.label")}),l.jsx(rt,{})]}),l.jsx(L,{name:"expire",label:r("genericBot.form.expire.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"keywordFinish",label:r("genericBot.form.keywordFinish.label"),required:!0,children:l.jsx(B,{})}),l.jsx(L,{name:"delayMessage",label:r("genericBot.form.delayMessage.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"unknownMessage",label:r("genericBot.form.unknownMessage.label"),children:l.jsx(B,{})}),l.jsx(Ce,{name:"listeningFromMe",label:r("genericBot.form.listeningFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"stopBotFromMe",label:r("genericBot.form.stopBotFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"keepOpen",label:r("genericBot.form.keepOpen.label"),reverse:!0}),l.jsx(L,{name:"debounceTime",label:r("genericBot.form.debounceTime.label"),children:l.jsx(B,{type:"number"})})]})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx(UN,{genericBotId:e}),l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsxs(Dt,{open:i,onOpenChange:c,children:[l.jsx(Wt,{asChild:!0,children:l.jsx(Y,{variant:"destructive",size:"sm",children:r("genericBot.button.delete")})}),l.jsx(It,{children:l.jsxs(Pt,{children:[l.jsx(Xt,{children:r("modal.delete.title")}),l.jsx(yl,{children:r("modal.delete.messageSingle")}),l.jsxs(gn,{children:[l.jsx(Y,{size:"sm",variant:"outline",onClick:()=>c(!1),children:r("button.cancel")}),l.jsx(Y,{variant:"destructive",onClick:p,children:r("button.delete")})]})]})})]}),l.jsx(Y,{type:"submit",children:r("genericBot.button.update")})]})]})]})})]})}const L1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const o=await zN(e.name,r);t(o)}else console.error("Token not found");n(!1)}catch(r){console.error("Error:",r),n(!1)}};function $1(){const{t:e}=We(),t=Wu("(min-width: 768px)"),{instance:n}=ut(),{genericBotId:r}=Ys(),[o,s]=m.useState(!0),[a,i]=m.useState([]),c=Vn();m.useEffect(()=>{n&&L1(n,i,s)},[n]);const u=f=>{n&&c(`/manager/instance/${n.id}/generic/${f}`)},d=()=>{L1(n,i,s)};return l.jsxs("main",{className:"pt-5",children:[l.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[l.jsx("h3",{className:"text-lg font-medium",children:e("genericBot.title")}),l.jsxs("div",{className:"flex items-center justify-end gap-2",children:[l.jsx(UN,{}),l.jsx(eY,{}),l.jsx(nY,{resetTable:d})]})]}),l.jsx(rt,{className:"my-4"}),l.jsxs(Vu,{direction:t?"horizontal":"vertical",children:[l.jsx(wo,{defaultSize:35,className:"pr-4",children:l.jsx("div",{className:"flex flex-col gap-3",children:o?l.jsx(Wr,{}):l.jsx(l.Fragment,{children:a&&a.length>0&&Array.isArray(a)?a.map(f=>l.jsx(Y,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>u(`${f.id}`),variant:r===f.id?"secondary":"outline",children:l.jsx("h4",{className:"text-base",children:f.description||f.id})},f.id)):l.jsx(Y,{variant:"link",children:e("genericBot.table.none")})})})}),r&&l.jsxs(l.Fragment,{children:[l.jsx(Hu,{withHandle:!0,className:"border border-border"}),l.jsx(wo,{className:"",children:l.jsx(oY,{genericBotId:r,instance:n,resetTable:d})})]})]})]})}const sY=t2([{path:"/manager/login",element:l.jsx(I2,{children:l.jsx(HQ,{})})},{path:"/manager/",element:l.jsx(qt,{children:l.jsx(Gz,{children:l.jsx(pK,{})})})},{path:"/manager/instance/:instanceId/dashboard",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(NJ,{})})})},{path:"/manager/instance/:instanceId/chat",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(b1,{})})})},{path:"/manager/instance/:instanceId/chat/:remoteJid",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(b1,{})})})},{path:"/manager/instance/:instanceId/settings",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(mQ,{})})})},{path:"/manager/instance/:instanceId/openai",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(P1,{})})})},{path:"/manager/instance/:instanceId/openai/:botId",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(P1,{})})})},{path:"/manager/instance/:instanceId/webhook",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(LQ,{})})})},{path:"/manager/instance/:instanceId/websocket",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(UQ,{})})})},{path:"/manager/instance/:instanceId/rabbitmq",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(gQ,{})})})},{path:"/manager/instance/:instanceId/sqs",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(xQ,{})})})},{path:"/manager/instance/:instanceId/chatwoot",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(eJ,{})})})},{path:"/manager/instance/:instanceId/typebot",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(D1,{})})})},{path:"/manager/instance/:instanceId/typebot/:typebotId",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(D1,{})})})},{path:"/manager/instance/:instanceId/dify",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(_1,{})})})},{path:"/manager/instance/:instanceId/dify/:difyId",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(_1,{})})})},{path:"/manager/instance/:instanceId/generic",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx($1,{})})})},{path:"/manager/instance/:instanceId/generic/:genericBotId",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx($1,{})})})},{path:"/manager/instance/:instanceId/proxy",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(uQ,{})})})}]),aY={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 mp{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||aY,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 o=this.observers[r].get(n)||0;this.observers[r].set(n,o+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),o=1;o{let[i,c]=a;for(let u=0;u{let[i,c]=a;for(let u=0;u{let e,t;const n=new Promise((r,o)=>{e=r,t=o});return n.resolve=e,n.reject=t,n},B1=e=>e==null?"":""+e,iY=(e,t,n)=>{e.forEach(r=>{t[r]&&(n[r]=t[r])})},lY=/###/g,z1=e=>e&&e.indexOf("###")>-1?e.replace(lY,"."):e,U1=e=>!e||typeof e=="string",Ic=(e,t,n)=>{const r=typeof t!="string"?t:t.split(".");let o=0;for(;o{const{obj:r,k:o}=Ic(e,t,Object);if(r!==void 0||t.length===1){r[o]=n;return}let s=t[t.length-1],a=t.slice(0,t.length-1),i=Ic(e,a,Object);for(;i.obj===void 0&&a.length;)s=`${a[a.length-1]}.${s}`,a=a.slice(0,a.length-1),i=Ic(e,a,Object),i&&i.obj&&typeof i.obj[`${i.k}.${s}`]<"u"&&(i.obj=void 0);i.obj[`${i.k}.${s}`]=n},cY=(e,t,n,r)=>{const{obj:o,k:s}=Ic(e,t,Object);o[s]=o[s]||[],o[s].push(n)},vp=(e,t)=>{const{obj:n,k:r}=Ic(e,t);if(n)return n[r]},uY=(e,t,n)=>{const r=vp(e,n);return r!==void 0?r:vp(t,n)},VN=(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]):VN(e[r],t[r],n):e[r]=t[r]);return e},fi=e=>e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&");var dY={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};const fY=e=>typeof e=="string"?e.replace(/[&<>"'\/]/g,t=>dY[t]):e;class pY{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 gY=[" ",",","?","!",";"],hY=new pY(20),mY=(e,t,n)=>{t=t||"",n=n||"";const r=gY.filter(a=>t.indexOf(a)<0&&n.indexOf(a)<0);if(r.length===0)return!0;const o=hY.getRegExp(`(${r.map(a=>a==="?"?"\\?":a).join("|")})`);let s=!o.test(e);if(!s){const a=e.indexOf(n);a>0&&!o.test(e.substring(0,a))&&(s=!0)}return s},sy=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 o=e;for(let s=0;s-1&&ce&&e.indexOf("_")>0?e.replace("_","-"):e;class H1 extends Wg{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 o=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};const s=o.keySeparator!==void 0?o.keySeparator:this.options.keySeparator,a=o.ignoreJSONStructure!==void 0?o.ignoreJSONStructure:this.options.ignoreJSONStructure;let i;t.indexOf(".")>-1?i=t.split("."):(i=[t,n],r&&(Array.isArray(r)?i.push(...r):typeof r=="string"&&s?i.push(...r.split(s)):i.push(r)));const c=vp(this.data,i);return!c&&!n&&!r&&t.indexOf(".")>-1&&(t=i[0],n=i[1],r=i.slice(2).join(".")),c||!a||typeof r!="string"?c:sy(this.data&&this.data[t]&&this.data[t][n],r,s)}addResource(t,n,r,o){let s=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{silent:!1};const a=s.keySeparator!==void 0?s.keySeparator:this.options.keySeparator;let i=[t,n];r&&(i=i.concat(a?r.split(a):r)),t.indexOf(".")>-1&&(i=t.split("."),o=n,n=i[1]),this.addNamespaces(n),V1(this.data,i,o),s.silent||this.emit("added",t,n,r,o)}addResources(t,n,r){let o=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{silent:!1};for(const s in r)(typeof r[s]=="string"||Array.isArray(r[s]))&&this.addResource(t,n,s,r[s],{silent:!0});o.silent||this.emit("added",t,n,r)}addResourceBundle(t,n,r,o,s){let a=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{silent:!1,skipCopy:!1},i=[t,n];t.indexOf(".")>-1&&(i=t.split("."),o=r,r=n,n=i[1]),this.addNamespaces(n);let c=vp(this.data,i)||{};a.skipCopy||(r=JSON.parse(JSON.stringify(r))),o?VN(c,r,s):c={...c,...r},V1(this.data,i,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(o=>n[o]&&Object.keys(n[o]).length>0)}toJSON(){return this.data}}var HN={processors:{},addPostProcessor(e){this.processors[e.name]=e},handle(e,t,n,r,o){return e.forEach(s=>{this.processors[s]&&(t=this.processors[s].process(t,n,r,o))}),t}};const W1={};class bp extends Wg{constructor(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),iY(["resourceStore","languageUtils","pluralResolver","interpolator","backendConnector","i18nFormat","utils"],t,this),this.options=n,this.options.keySeparator===void 0&&(this.options.keySeparator="."),this.logger=fo.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 o=n.keySeparator!==void 0?n.keySeparator:this.options.keySeparator;let s=n.ns||this.options.defaultNS||[];const a=r&&t.indexOf(r)>-1,i=!this.options.userDefinedKeySeparator&&!n.keySeparator&&!this.options.userDefinedNsSeparator&&!n.nsSeparator&&!mY(t,r,o);if(a&&!i){const c=t.match(this.interpolator.nestingRegexp);if(c&&c.length>0)return{key:t,namespaces:s};const u=t.split(r);(r!==o||r===o&&this.options.ns.indexOf(u[0])>-1)&&(s=u.shift()),t=u.join(o)}return typeof s=="string"&&(s=[s]),{key:t,namespaces:s}}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 o=n.returnDetails!==void 0?n.returnDetails:this.options.returnDetails,s=n.keySeparator!==void 0?n.keySeparator:this.options.keySeparator,{key:a,namespaces:i}=this.extractFromKey(t[t.length-1],n),c=i[i.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 o?{res:`${c}${S}${a}`,usedKey:a,exactUsedKey:a,usedLng:u,usedNS:c,usedParams:this.getUsedParamsDetails(n)}:`${c}${S}${a}`}return o?{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:i}):`key '${a} (${this.language})' returned an object instead of string.`;return o?(f.res=S,f.usedParams=this.getUsedParamsDetails(n),f):S}if(s){const S=Array.isArray(p),E=S?[]:{},C=S?v:h;for(const T in p)if(Object.prototype.hasOwnProperty.call(p,T)){const _=`${C}${s}${T}`;E[T]=this.translate(_,{...n,joinArrays:!1,ns:i}),E[T]===_&&(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=bp.hasDefaultValue(n),_=C?this.pluralResolver.getSuffix(u,n.count,n):"",I=n.ordinal&&C?this.pluralResolver.getSuffix(u,n.count,{ordinal:!1}):"",N=C&&!n.ordinal&&n.count===0&&this.pluralResolver.shouldUseIntlApi(),V=N&&n[`defaultValue${this.options.pluralSeparator}zero`]||n[`defaultValue${_}`]||n[`defaultValue${I}`]||n.defaultValue;!this.isValidLookup(p)&&T&&(S=!0,p=V),this.isValidLookup(p)||(E=!0,p=a);const J=(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),s){const A=this.resolve(a,{...n,keySeparator:!1});A&&A.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 Q=this.languageUtils.getFallbackCodes(this.options.fallbackLng,n.lng||this.language);if(this.options.saveMissingTo==="fallback"&&Q&&Q[0])for(let A=0;A{const ue=T&&Z!==p?Z:J;this.options.missingKeyHandler?this.options.missingKeyHandler(A,c,D,ue,H,n):this.backendConnector&&this.backendConnector.saveMissing&&this.backendConnector.saveMissing(A,c,D,ue,H,n),this.emit("missingKey",A,c,D,p)};this.options.saveMissing&&(this.options.saveMissingPlurals&&C?K.forEach(A=>{const D=this.pluralResolver.getSuffixes(A,n);N&&n[`defaultValue${this.options.pluralSeparator}zero`]&&D.indexOf(`${this.options.pluralSeparator}zero`)<0&&D.push(`${this.options.pluralSeparator}zero`),D.forEach(Z=>{G([A],a+Z,n[`defaultValue${Z}`]||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 o?(f.res=p,f.usedParams=this.getUsedParamsDetails(n),f):p}extendTranslation(t,n,r,o,s){var a=this;if(this.i18nFormat&&this.i18nFormat.parse)t=this.i18nFormat.parse(t,{...this.options.interpolation.defaultVariables,...r},r.lng||this.language||o.usedLng,o.usedNS,o.usedKey,{resolved:o});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||o.usedLng,r),u){const p=t.match(this.interpolator.nestingRegexp),h=p&&p.length;d1&&arguments[1]!==void 0?arguments[1]:{},r,o,s,a,i;return typeof t=="string"&&(t=[t]),t.forEach(c=>{if(this.isValidLookup(r))return;const u=this.extractFromKey(c,n),d=u.key;o=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)||(i=b,!W1[`${g[0]}-${b}`]&&this.utils&&this.utils.hasLoadedNamespace&&!this.utils.hasLoadedNamespace(i)&&(W1[`${g[0]}-${b}`]=!0,this.logger.warn(`key "${o}" for languages "${g.join(", ")}" won't get resolved as namespace "${i}" 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)||(s=w,r=this.getResource(y,b,w,n))}))})}),{res:r,usedKey:o,exactUsedKey:s,usedLng:a,usedNS:i}}isValidLookup(t){return t!==void 0&&!(!this.options.returnNull&&t===null)&&!(!this.options.returnEmptyString&&t==="")}getResource(t,n,r){let o=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};return this.i18nFormat&&this.i18nFormat.getResource?this.i18nFormat.getResource(t,n,r,o):this.resourceStore.getResource(t,n,r,o)}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 o=r?t.replace:t;if(r&&typeof t.count<"u"&&(o.count=t.count),this.options.interpolation.defaultVariables&&(o={...this.options.interpolation.defaultVariables,...o}),!r){o={...o};for(const s of n)delete o[s]}return o}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 pm=e=>e.charAt(0).toUpperCase()+e.slice(1);class G1{constructor(t){this.options=t,this.supportedLngs=this.options.supportedLngs||!1,this.logger=fo.create("languageUtils")}getScriptPartFromCode(t){if(t=yp(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=yp(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(o=>o.toLowerCase()):r.length===2?(r[0]=r[0].toLowerCase(),r[1]=r[1].toUpperCase(),n.indexOf(r[1].toLowerCase())>-1&&(r[1]=pm(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]=pm(r[1].toLowerCase())),n.indexOf(r[2].toLowerCase())>-1&&(r[2]=pm(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 o=this.formatLanguageCode(r);(!this.options.supportedLngs||this.isSupportedCode(o))&&(n=o)}),!n&&this.options.supportedLngs&&t.forEach(r=>{if(n)return;const o=this.getLanguagePartFromCode(r);if(this.isSupportedCode(o))return n=o;n=this.options.supportedLngs.find(s=>{if(s===o)return s;if(!(s.indexOf("-")<0&&o.indexOf("-")<0)&&(s.indexOf("-")>0&&o.indexOf("-")<0&&s.substring(0,s.indexOf("-"))===o||s.indexOf(o)===0&&o.length>1))return s})}),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),o=[],s=a=>{a&&(this.isSupportedCode(a)?o.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"&&s(this.formatLanguageCode(t)),this.options.load!=="languageOnly"&&this.options.load!=="currentOnly"&&s(this.getScriptPartFromCode(t)),this.options.load!=="currentOnly"&&s(this.getLanguagePartFromCode(t))):typeof t=="string"&&s(this.formatLanguageCode(t)),r.forEach(a=>{o.indexOf(a)<0&&s(this.formatLanguageCode(a))}),o}}let vY=[{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}],yY={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"],xY=["v4"],q1={zero:0,one:1,two:2,few:3,many:4,other:5},wY=()=>{const e={};return vY.forEach(t=>{t.lngs.forEach(n=>{e[n]={numbers:t.nr,plurals:yY[t.fc]}})}),e};class SY{constructor(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.languageUtils=t,this.options=n,this.logger=fo.create("pluralResolver"),(!this.options.compatibilityJSON||xY.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=wY(),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=yp(t==="dev"?"en":t),o=n.ordinal?"ordinal":"cardinal",s=JSON.stringify({cleanedCode:r,type:o});if(s in this.pluralRulesCache)return this.pluralRulesCache[s];const a=new Intl.PluralRules(r,{type:o});return this.pluralRulesCache[s]=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(o=>`${n}${o}`)}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((o,s)=>q1[o]-q1[s]).map(o=>`${this.options.prepend}${n.ordinal?`ordinal${this.options.prepend}`:""}${o}`):r.numbers.map(o=>this.getSuffix(t,o,n)):[]}getSuffix(t,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const o=this.getRule(t,r);return o?this.shouldUseIntlApi()?`${this.options.prepend}${r.ordinal?`ordinal${this.options.prepend}`:""}${o.select(n)}`:this.getSuffixRetroCompatible(o,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 o=t.numbers[r];this.options.simplifyPluralSuffix&&t.numbers.length===2&&t.numbers[0]===1&&(o===2?o="plural":o===1&&(o=""));const s=()=>this.options.prepend&&o.toString()?this.options.prepend+o.toString():o.toString();return this.options.compatibilityJSON==="v1"?o===1?"":typeof o=="number"?`_plural_${o.toString()}`:s():this.options.compatibilityJSON==="v2"||this.options.simplifyPluralSuffix&&t.numbers.length===2&&t.numbers[0]===1?s():this.options.prepend&&r.toString()?this.options.prepend+r.toString():r.toString()}shouldUseIntlApi(){return!bY.includes(this.options.compatibilityJSON)}}const K1=function(e,t,n){let r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:".",o=arguments.length>4&&arguments[4]!==void 0?arguments[4]:!0,s=uY(e,t,n);return!s&&o&&typeof n=="string"&&(s=sy(e,n,r),s===void 0&&(s=sy(t,n,r))),s},gm=e=>e.replace(/\$/g,"$$$$");class CY{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.logger=fo.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:o,prefix:s,prefixEscaped:a,suffix:i,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:fY,this.escapeValue=r!==void 0?r:!0,this.useRawValueToEscape=o!==void 0?o:!1,this.prefix=s?fi(s):a||"{{",this.suffix=i?fi(i):c||"}}",this.formatSeparator=u||",",this.unescapePrefix=d?"":f||"-",this.unescapeSuffix=this.unescapePrefix?"":d||"",this.nestingPrefix=p?fi(p):h||fi("$t("),this.nestingSuffix=v?fi(v):g||fi(")"),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,o){let s,a,i;const c=this.options&&this.options.interpolation&&this.options.interpolation.defaultVariables||{},u=h=>{if(h.indexOf(this.formatSeparator)<0){const y=K1(n,c,h,this.options.keySeparator,this.options.ignoreJSONStructure);return this.alwaysFormat?this.format(y,void 0,r,{...o,...n,interpolationkey:h}):y}const v=h.split(this.formatSeparator),g=v.shift().trim(),b=v.join(this.formatSeparator).trim();return this.format(K1(n,c,g,this.options.keySeparator,this.options.ignoreJSONStructure),b,r,{...o,...n,interpolationkey:g})};this.resetRegExp();const d=o&&o.missingInterpolationHandler||this.options.missingInterpolationHandler,f=o&&o.interpolation&&o.interpolation.skipOnVariables!==void 0?o.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables;return[{regex:this.regexpUnescape,safeValue:h=>gm(h)},{regex:this.regexp,safeValue:h=>this.escapeValue?gm(this.escape(h)):gm(h)}].forEach(h=>{for(i=0;s=h.regex.exec(t);){const v=s[1].trim();if(a=u(v),a===void 0)if(typeof d=="function"){const b=d(t,s,o);a=typeof b=="string"?b:""}else if(o&&Object.prototype.hasOwnProperty.call(o,v))a="";else if(f){a=s[0];continue}else this.logger.warn(`missed to pass in variable ${v} for interpolating ${t}`),a="";else typeof a!="string"&&!this.useRawValueToEscape&&(a=B1(a));const g=h.safeValue(a);if(t=t.replace(s[0],g),f?(h.regex.lastIndex+=a.length,h.regex.lastIndex-=s[0].length):h.regex.lastIndex=0,i++,i>=this.maxReplaces)break}}),t}nest(t,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},o,s,a;const i=(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(;o=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(o[0].indexOf(this.formatSeparator)!==-1&&!/{.*}/.test(o[1])){const d=o[1].split(this.formatSeparator).map(f=>f.trim());o[1]=d.shift(),c=d,u=!0}if(s=n(i.call(this,o[1].trim(),a),a),s&&o[0]===t&&typeof s!="string")return s;typeof s!="string"&&(s=B1(s)),s||(this.logger.warn(`missed to resolve ${o[1]} for nesting ${t}`),s=""),u&&(s=c.reduce((d,f)=>this.format(d,f,r.lng,{...r,interpolationkey:o[1].trim()}),s.trim())),t=t.replace(o[0],s),this.regexp.lastIndex=0}return t}}const EY=e=>{let t=e.toLowerCase().trim();const n={};if(e.indexOf("(")>-1){const r=e.split("(");t=r[0].toLowerCase().trim();const o=r[1].substring(0,r[1].length-1);t==="currency"&&o.indexOf(":")<0?n.currency||(n.currency=o.trim()):t==="relativetime"&&o.indexOf(":")<0?n.range||(n.range=o.trim()):o.split(";").forEach(a=>{if(a){const[i,...c]=a.split(":"),u=c.join(":").trim().replace(/^'+|'+$/g,""),d=i.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}},pi=e=>{const t={};return(n,r,o)=>{let s=o;o&&o.interpolationkey&&o.formatParams&&o.formatParams[o.interpolationkey]&&o[o.interpolationkey]&&(s={...s,[o.interpolationkey]:void 0});const a=r+JSON.stringify(s);let i=t[a];return i||(i=e(yp(r),o),t[a]=i),i(n)}};class kY{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.logger=fo.create("formatter"),this.options=t,this.formats={number:pi((n,r)=>{const o=new Intl.NumberFormat(n,{...r});return s=>o.format(s)}),currency:pi((n,r)=>{const o=new Intl.NumberFormat(n,{...r,style:"currency"});return s=>o.format(s)}),datetime:pi((n,r)=>{const o=new Intl.DateTimeFormat(n,{...r});return s=>o.format(s)}),relativetime:pi((n,r)=>{const o=new Intl.RelativeTimeFormat(n,{...r});return s=>o.format(s,r.range||"day")}),list:pi((n,r)=>{const o=new Intl.ListFormat(n,{...r});return s=>o.format(s)})},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()]=pi(n)}format(t,n,r){let o=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};const s=n.split(this.formatSeparator);if(s.length>1&&s[0].indexOf("(")>1&&s[0].indexOf(")")<0&&s.find(i=>i.indexOf(")")>-1)){const i=s.findIndex(c=>c.indexOf(")")>-1);s[0]=[s[0],...s.splice(1,i)].join(this.formatSeparator)}return s.reduce((i,c)=>{const{formatName:u,formatOptions:d}=EY(c);if(this.formats[u]){let f=i;try{const p=o&&o.formatParams&&o.formatParams[o.interpolationkey]||{},h=p.locale||p.lng||o.locale||o.lng||r;f=this.formats[u](i,h,{...d,...o,...p})}catch(p){this.logger.warn(p)}return f}else this.logger.warn(`there was no format function for ${u}`);return i},t)}}const TY=(e,t)=>{e.pending[t]!==void 0&&(delete e.pending[t],e.pendingCount--)};class _Y extends Wg{constructor(t,n,r){let o=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=o,this.logger=fo.create("backendConnector"),this.waitingReads=[],this.maxParallelReads=o.maxParallelReads||10,this.readingCalls=0,this.maxRetries=o.maxRetries>=0?o.maxRetries:5,this.retryTimeout=o.retryTimeout>=1?o.retryTimeout:350,this.state={},this.queue=[],this.backend&&this.backend.init&&this.backend.init(r,o.backend,o)}queueLoad(t,n,r,o){const s={},a={},i={},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),s[p]===void 0&&(s[p]=!0),c[f]===void 0&&(c[f]=!0)))}),d||(i[u]=!0)}),(Object.keys(s).length||Object.keys(a).length)&&this.queue.push({pending:a,pendingCount:Object.keys(a).length,loaded:{},errors:[],callback:o}),{toLoad:Object.keys(s),pending:Object.keys(a),toLoadLanguages:Object.keys(i),toLoadNamespaces:Object.keys(c)}}loaded(t,n,r){const o=t.split("|"),s=o[0],a=o[1];n&&this.emit("failedLoading",s,a,n),!n&&r&&this.store.addResourceBundle(s,a,r,void 0,void 0,{skipCopy:!0}),this.state[t]=n?-1:2,n&&r&&(this.state[t]=0);const i={};this.queue.forEach(c=>{cY(c.loaded,[s],a),TY(c,t),n&&c.errors.push(n),c.pendingCount===0&&!c.done&&(Object.keys(c.loaded).forEach(u=>{i[u]||(i[u]={});const d=c.loaded[u];d.length&&d.forEach(f=>{i[u][f]===void 0&&(i[u][f]=!0)})}),c.done=!0,c.errors.length?c.callback(c.errors):c.callback())}),this.emit("loaded",i),this.queue=this.queue.filter(c=>!c.done)}read(t,n,r){let o=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0,s=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:o,wait:s,callback:a});return}this.readingCalls++;const i=(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&&o{this.read.call(this,t,n,r,o+1,s*2,a)},s);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=>i(null,d)).catch(i):i(null,u)}catch(u){i(u)}return}return c(t,n,i)}prepareLoading(t,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},o=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."),o&&o();typeof t=="string"&&(t=this.languageUtils.toResolveHierarchy(t)),typeof n=="string"&&(n=[n]);const s=this.queueLoad(t,n,r,o);if(!s.toLoad.length)return s.pending.length||o(),null;s.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("|"),o=r[0],s=r[1];this.read(o,s,"read",void 0,void 0,(a,i)=>{a&&this.logger.warn(`${n}loading namespace ${s} for language ${o} failed`,a),!a&&i&&this.logger.log(`${n}loaded namespace ${s} for language ${o}`,i),this.loaded(t,a,i)})}saveMissing(t,n,r,o,s){let a=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{},i=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:s},u=this.backend.create.bind(this.backend);if(u.length<6)try{let d;u.length===5?d=u(t,n,r,o,c):d=u(t,n,r,o),d&&typeof d.then=="function"?d.then(f=>i(null,f)).catch(i):i(null,d)}catch(d){i(d)}else u(t,n,r,o,i,c)}!t||!t[0]||this.store.addResource(t[0],n,r,o)}}}const J1=()=>({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}}),Z1=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),Bd=()=>{},jY=e=>{Object.getOwnPropertyNames(Object.getPrototypeOf(e)).forEach(n=>{typeof e[n]=="function"&&(e[n]=e[n].bind(e))})};class ku extends Wg{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(super(),this.options=Z1(t),this.services={},this.logger=fo,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 o=J1();this.options={...o,...this.options,...Z1(n)},this.options.compatibilityAPI!=="v1"&&(this.options.interpolation={...o.interpolation,...this.options.interpolation}),n.keySeparator!==void 0&&(this.options.userDefinedKeySeparator=n.keySeparator),n.nsSeparator!==void 0&&(this.options.userDefinedNsSeparator=n.nsSeparator);const s=d=>d?typeof d=="function"?new d:d:null;if(!this.options.isClone){this.modules.logger?fo.init(s(this.modules.logger),this.options):fo.init(null,this.options);let d;this.modules.formatter?d=this.modules.formatter:typeof Intl<"u"&&(d=kY);const f=new G1(this.options);this.store=new H1(this.options.resources,this.options);const p=this.services;p.logger=fo,p.resourceStore=this.store,p.languageUtils=f,p.pluralResolver=new SY(f,{prepend:this.options.pluralSeparator,compatibilityJSON:this.options.compatibilityJSON,simplifyPluralSuffix:this.options.simplifyPluralSuffix}),d&&(!this.options.interpolation.format||this.options.interpolation.format===o.interpolation.format)&&(p.formatter=s(d),p.formatter.init(p,this.options),this.options.interpolation.format=p.formatter.format.bind(p.formatter)),p.interpolator=new CY(this.options),p.utils={hasLoadedNamespace:this.hasLoadedNamespace.bind(this)},p.backendConnector=new _Y(s(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=Bd),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=nc(),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]:Bd;const o=typeof t=="string"?t:this.language;if(typeof t=="function"&&(r=t),!this.options.resources||this.options.partialBundledLanguages){if(o&&o.toLowerCase()==="cimode"&&(!this.options.preload||this.options.preload.length===0))return r();const s=[],a=i=>{if(!i||i==="cimode")return;this.services.languageUtils.toResolveHierarchy(i).forEach(u=>{u!=="cimode"&&s.indexOf(u)<0&&s.push(u)})};o?a(o):this.services.languageUtils.getFallbackCodes(this.options.fallbackLng).forEach(c=>a(c)),this.options.preload&&this.options.preload.forEach(i=>a(i)),this.services.backendConnector.load(s,this.options.ns,i=>{!i&&!this.resolvedLanguage&&this.language&&this.setResolvedLanguage(this.language),r(i)})}else r(null)}reloadResources(t,n,r){const o=nc();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=Bd),this.services.backendConnector.reload(t,n,s=>{o.resolve(),r(s)}),o}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"&&HN.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 o=nc();this.emit("languageChanging",t);const s=c=>{this.language=c,this.languages=this.services.languageUtils.toResolveHierarchy(c),this.resolvedLanguage=void 0,this.setResolvedLanguage(c)},a=(c,u)=>{u?(s(u),this.translator.changeLanguage(u),this.isLanguageChangingTo=void 0,this.emit("languageChanged",u),this.logger.log("languageChanged",u)):this.isLanguageChangingTo=void 0,o.resolve(function(){return r.t(...arguments)}),n&&n(c,function(){return r.t(...arguments)})},i=c=>{!t&&!c&&this.services.languageDetector&&(c=[]);const u=typeof c=="string"?c:this.services.languageUtils.getBestMatchFromCodes(c);u&&(this.language||s(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?i(this.services.languageDetector.detect()):!t&&this.services.languageDetector&&this.services.languageDetector.async?this.services.languageDetector.detect.length===0?this.services.languageDetector.detect().then(i):this.services.languageDetector.detect(i):i(t),o}getFixedT(t,n,r){var o=this;const s=function(a,i){let c;if(typeof i!="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,o.t(h,c)};return typeof t=="string"?s.lng=t:s.lngs=t,s.ns=n,s.keyPrefix=r,s}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],o=this.options?this.options.fallbackLng:!1,s=this.languages[this.languages.length-1];if(r.toLowerCase()==="cimode")return!0;const a=(i,c)=>{const u=this.services.backendConnector.state[`${i}|${c}`];return u===-1||u===0||u===2};if(n.precheck){const i=n.precheck(this,a);if(i!==void 0)return i}return!!(this.hasResourceBundle(r,t)||!this.services.backendConnector.backend||this.options.resources&&!this.options.partialBundledLanguages||a(r,t)&&(!o||a(s,t)))}loadNamespaces(t,n){const r=nc();return this.options.ns?(typeof t=="string"&&(t=[t]),t.forEach(o=>{this.options.ns.indexOf(o)<0&&this.options.ns.push(o)}),this.loadResources(o=>{r.resolve(),n&&n(o)}),r):(n&&n(),Promise.resolve())}loadLanguages(t,n){const r=nc();typeof t=="string"&&(t=[t]);const o=this.options.preload||[],s=t.filter(a=>o.indexOf(a)<0&&this.services.languageUtils.isSupportedCode(a));return s.length?(this.options.preload=o.concat(s),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 G1(J1());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 ku(t,n)}cloneInstance(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Bd;const r=t.forkResourceStore;r&&delete t.forkResourceStore;const o={...this.options,...t,isClone:!0},s=new ku(o);return(t.debug!==void 0||t.prefix!==void 0)&&(s.logger=s.logger.clone(t)),["store","services","language"].forEach(i=>{s[i]=this[i]}),s.services={...this.services},s.services.utils={hasLoadedNamespace:s.hasLoadedNamespace.bind(s)},r&&(s.store=new H1(this.store.data,o),s.services.resourceStore=s.store),s.translator=new bp(s.services,o),s.translator.on("*",function(i){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 LZ(e){return typeof e=="object"&&typeof e.$$typeof=="symbol"&&["react.memo","react.forward_ref"].includes(e.$$typeof.description)}function Qu(e){const t={state:{},onStateChange:()=>{},renderFallbackValue:null,...e},[n]=m.useState(()=>({current:PZ(t)})),[r,o]=m.useState(()=>n.current.initialState);return n.current.setOptions(s=>({...s,...e,state:{...r,...e.state},onStateChange:a=>{o(a),e.onStateChange==null||e.onStateChange(a)}})),n.current}const jl=m.forwardRef(({className:e,...t},n)=>l.jsx("div",{className:"relative w-full overflow-auto",children:l.jsx("table",{ref:n,className:he("w-full caption-bottom text-sm",e),...t})}));jl.displayName="Table";const Rl=m.forwardRef(({className:e,...t},n)=>l.jsx("thead",{ref:n,className:he("[&_tr]:border-b",e),...t}));Rl.displayName="TableHeader";const Il=m.forwardRef(({className:e,...t},n)=>l.jsx("tbody",{ref:n,className:he("[&_tr:last-child]:border-0",e),...t}));Il.displayName="TableBody";const $Z=m.forwardRef(({className:e,...t},n)=>l.jsx("tfoot",{ref:n,className:he("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",e),...t}));$Z.displayName="TableFooter";const Sn=m.forwardRef(({className:e,...t},n)=>l.jsx("tr",{ref:n,className:he("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",e),...t}));Sn.displayName="TableRow";const Pl=m.forwardRef(({className:e,...t},n)=>l.jsx("th",{ref:n,className:he("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",e),...t}));Pl.displayName="TableHead";const Gr=m.forwardRef(({className:e,...t},n)=>l.jsx("td",{ref:n,className:he("p-4 align-middle [&:has([role=checkbox])]:pr-0",e),...t}));Gr.displayName="TableCell";const BZ=m.forwardRef(({className:e,...t},n)=>l.jsx("caption",{ref:n,className:he("mt-4 text-sm text-muted-foreground",e),...t}));BZ.displayName="TableCaption";const k1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const o=await UJ(e.name,r,n);t(o)}else console.error("Token not found.")}catch(r){console.error("Errors:",r)}};function IN({difyId:e}){var h,v;const{t}=We(),{instance:n}=ut(),[r,o]=m.useState([]),[s,a]=m.useState([]),[i,c]=m.useState(!1);m.useEffect(()=>{i&&k1(n,a,e)},[n,e,i]);function u(){k1(n,a,e)}const d=async(g,b)=>{var y,x,w;try{if(!n)return;await VJ(n.name,n.token,g,b),se.success(t("dify.toast.success.status")),u()}catch(S){console.error("Error:",S),se.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:()=>l.jsx("div",{className:"text-center",children:t("dify.sessions.table.remoteJid")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>l.jsx("div",{className:"text-center",children:t("dify.sessions.table.pushName")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("pushName")})},{accessorKey:"sessionId",header:()=>l.jsx("div",{className:"text-center",children:t("dify.sessions.table.sessionId")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("sessionId")})},{accessorKey:"status",header:()=>l.jsx("div",{className:"text-center",children:t("dify.sessions.table.status")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:g})=>{const b=g.original;return l.jsxs(ea,{children:[l.jsx(ta,{asChild:!0,children:l.jsxs(Y,{variant:"ghost",className:"h-8 w-8 p-0",children:[l.jsx("span",{className:"sr-only",children:t("dify.sessions.table.actions.title")}),l.jsx(Ou,{className:"h-4 w-4"})]})}),l.jsxs(Co,{align:"end",children:[l.jsx(vl,{children:t("dify.sessions.table.actions.title")}),l.jsx(Za,{}),b.status!=="opened"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"opened"),children:[l.jsx(ng,{className:"mr-2 h-4 w-4"}),t("dify.sessions.table.actions.open")]}),b.status!=="paused"&&b.status!=="closed"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"paused"),children:[l.jsx(tg,{className:"mr-2 h-4 w-4"}),t("dify.sessions.table.actions.pause")]}),b.status!=="closed"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"closed"),children:[l.jsx(Qp,{className:"mr-2 h-4 w-4"}),t("dify.sessions.table.actions.close")]}),l.jsxs(ft,{onClick:()=>d(b.remoteJid,"delete"),children:[l.jsx(Yp,{className:"mr-2 h-4 w-4"}),t("dify.sessions.table.actions.delete")]})]})]})}}],p=Qu({data:s,columns:f,onSortingChange:o,getCoreRowModel:qu(),getPaginationRowModel:Ju(),getSortedRowModel:Zu(),getFilteredRowModel:Ku(),state:{sorting:r}});return l.jsxs(Dt,{open:i,onOpenChange:c,children:[l.jsx(Wt,{asChild:!0,children:l.jsxs(Y,{variant:"secondary",size:"sm",children:[l.jsx(Xp,{size:16,className:"mr-1"}),l.jsx("span",{className:"hidden sm:inline",children:t("dify.sessions.label")})]})}),l.jsxs(It,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:u,children:[l.jsx(Pt,{children:l.jsx(Xt,{children:t("dify.sessions.label")})}),l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[l.jsx(B,{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)}}),l.jsx(Y,{variant:"outline",onClick:u,size:"icon",children:l.jsx(rg,{})})]}),l.jsxs(jl,{children:[l.jsx(Rl,{children:p.getHeaderGroups().map(g=>l.jsx(Sn,{children:g.headers.map(b=>l.jsx(Pl,{children:b.isPlaceholder?null:So(b.column.columnDef.header,b.getContext())},b.id))},g.id))}),l.jsx(Il,{children:(v=p.getRowModel().rows)!=null&&v.length?p.getRowModel().rows.map(g=>l.jsx(Sn,{"data-state":g.getIsSelected()&&"selected",children:g.getVisibleCells().map(b=>l.jsx(Gr,{children:So(b.column.columnDef.cell,b.getContext())},b.id))},g.id)):l.jsx(Sn,{children:l.jsx(Gr,{colSpan:f.length,className:"h-24 text-center",children:t("dify.sessions.table.none")})})})]})]})]})]})}const zZ=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 UZ({difyId:e,instance:t,resetTable:n}){const{t:r}=We(),[,o]=m.useState(""),[s,a]=m.useState(!0),[i,c]=m.useState(!1),u=Vn(),d=At({resolver:Ft(zZ),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){o(b);const y=await AJ(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 LJ(t.name,w,e,S),se.success(r("dify.toast.success.update"))}else console.error("Token not found")}catch(w){console.error("Error:",w),se.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 $J(t.name,g,e),se.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 l.jsxs(l.Fragment,{children:[s&&l.jsx(Wr,{}),!s&&l.jsx(Tr,{...d,children:l.jsxs("form",{onSubmit:d.handleSubmit(f),className:"w-full space-y-6 pl-4 pr-2",children:[l.jsxs("div",{className:"space-y-6",children:[l.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[l.jsxs("h3",{className:"mb-4 text-lg font-medium",children:["Dify: ",h]}),l.jsx(Ce,{name:"enabled",className:"flex items-center gap-3"})]}),l.jsxs("div",{className:"space-y-4",children:[l.jsx(L,{name:"description",label:r("dify.form.description.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("dify.form.difySettings.label")}),l.jsx(rt,{})]}),l.jsx(at,{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"}]}),l.jsx(L,{name:"apiUrl",label:r("dify.form.apiUrl.label"),required:!0,children:l.jsx(B,{})}),l.jsx(L,{name:"apiKey",label:r("dify.form.apiKey.label"),required:!0,children:l.jsx(B,{type:"password"})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("dify.form.triggerSettings.label")}),l.jsx(rt,{})]}),l.jsx(at,{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"&&l.jsxs(l.Fragment,{children:[l.jsx(at,{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}),l.jsx(L,{name:"triggerValue",label:r("dify.form.triggerValue.label"),required:!0,children:l.jsx(B,{})})]}),v==="advanced"&&l.jsx(L,{name:"triggerValue",label:r("dify.form.triggerConditions.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("dify.form.generalSettings.label")}),l.jsx(rt,{})]}),l.jsx(L,{name:"expire",label:r("dify.form.expire.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"keywordFinish",label:r("dify.form.keywordFinish.label"),required:!0,children:l.jsx(B,{})}),l.jsx(L,{name:"delayMessage",label:r("dify.form.delayMessage.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"unknownMessage",label:r("dify.form.unknownMessage.label"),children:l.jsx(B,{})}),l.jsx(Ce,{name:"listeningFromMe",label:r("dify.form.listeningFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"stopBotFromMe",label:r("dify.form.stopBotFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"keepOpen",label:r("dify.form.keepOpen.label"),reverse:!0}),l.jsx(L,{name:"debounceTime",label:r("dify.form.debounceTime.label"),children:l.jsx(B,{type:"number"})})]})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx(IN,{difyId:e}),l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsxs(Dt,{open:i,onOpenChange:c,children:[l.jsx(Wt,{asChild:!0,children:l.jsx(Y,{variant:"destructive",size:"sm",children:r("dify.button.delete")})}),l.jsx(It,{children:l.jsxs(Pt,{children:[l.jsx(Xt,{children:r("modal.delete.title")}),l.jsx(yl,{children:r("modal.delete.messageSingle")}),l.jsxs(gn,{children:[l.jsx(Y,{size:"sm",variant:"outline",onClick:()=>c(!1),children:r("button.cancel")}),l.jsx(Y,{variant:"destructive",onClick:p,children:r("button.delete")})]})]})})]}),l.jsx(Y,{type:"submit",children:r("dify.button.update")})]})]})]})})]})}const T1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const o=await xN(e.name,r);t(o)}else console.error("Token not found");n(!1)}catch(r){console.error("Error:",r),n(!1)}};function _1(){const{t:e}=We(),t=Wu("(min-width: 768px)"),{instance:n}=ut(),{difyId:r}=Ys(),[o,s]=m.useState(!0),[a,i]=m.useState([]),c=Vn();m.useEffect(()=>{n&&T1(n,i,s)},[n]);const u=f=>{n&&c(`/manager/instance/${n.id}/dify/${f}`)},d=()=>{T1(n,i,s)};return l.jsxs("main",{className:"pt-5",children:[l.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[l.jsx("h3",{className:"text-lg font-medium",children:e("dify.title")}),l.jsxs("div",{className:"flex items-center justify-end gap-2",children:[l.jsx(IN,{}),l.jsx(WJ,{}),l.jsx(qJ,{resetTable:d})]})]}),l.jsx(rt,{className:"my-4"}),l.jsxs(Vu,{direction:t?"horizontal":"vertical",children:[l.jsx(wo,{defaultSize:35,className:"pr-4",children:l.jsx("div",{className:"flex flex-col gap-3",children:o?l.jsx(Wr,{}):l.jsx(l.Fragment,{children:a&&a.length>0&&Array.isArray(a)?a.map(f=>l.jsxs(Y,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>u(`${f.id}`),variant:r===f.id?"secondary":"outline",children:[l.jsx("h4",{className:"text-base",children:f.description||f.id}),l.jsx("p",{className:"text-sm font-normal text-muted-foreground",children:f.botType})]},f.id)):l.jsx(Y,{variant:"link",children:e("dify.table.none")})})})}),r&&l.jsxs(l.Fragment,{children:[l.jsx(Hu,{withHandle:!0,className:"border border-border"}),l.jsx(wo,{className:"",children:l.jsx(UZ,{difyId:r,instance:n,resetTable:d})})]})]})]})}const cr=new Cr,Hg=async(e,t)=>(await cr.getInstance().get(`/openai/creds/${e}`,{headers:{apikey:t}})).data,VZ=async(e,t,n)=>(await cr.getInstance().post(`/openai/creds/${e}`,n,{headers:{apikey:t}})).data,HZ=async(e,t)=>(await cr.getInstance().delete(`/openai/creds/${e}/${t}`)).data,PN=async(e,t)=>(await cr.getInstance().get(`/openai/find/${e}`,{headers:{apikey:t}})).data,WZ=async(e,t,n)=>(await cr.getInstance().get(`/openai/fetch/${n}/${e}`,{headers:{apikey:t}})).data,GZ=async(e,t,n)=>(await cr.getInstance().post(`/openai/create/${e}`,n,{headers:{apikey:t}})).data,qZ=async(e,t,n,r)=>(await cr.getInstance().put(`/openai/update/${n}/${e}`,r,{headers:{apikey:t}})).data,KZ=async(e,t,n)=>(await cr.getInstance().delete(`/openai/delete/${n}/${e}`,{headers:{apikey:t}})).data,JZ=async(e,t)=>(await cr.getInstance().get(`/openai/fetchSettings/${e}`,{headers:{apikey:t}})).data,ZZ=async(e,t,n)=>(await cr.getInstance().post(`/openai/settings/${e}`,n,{headers:{apikey:t}})).data,QZ=async(e,t,n)=>(await cr.getInstance().get(`/openai/fetchSessions/${n}/${e}`,{headers:{apikey:t}})).data,YZ=async(e,t,n,r)=>(await cr.getInstance().post(`/openai/changeStatus/${e}`,{remoteJid:n,status:r},{headers:{apikey:t}})).data,NN=async(e,t)=>(await cr.getInstance().get(`/openai/getModels/${e}`,{headers:{apikey:t}})).data,XZ=k.object({name:k.string(),apiKey:k.string()}),fm=async(e,t)=>{try{const n=localStorage.getItem("token");if(n&&e&&e.name){const r=await Hg(e.name,n);t(r)}else console.error("Token not found.")}catch(n){console.error("Error:",n)}};function eQ(){var v;const{t:e}=We(),{instance:t}=ut(),[n,r]=m.useState(!1),[o,s]=m.useState([]),[a,i]=m.useState([]),c=At({resolver:Ft(XZ),defaultValues:{name:"",apiKey:""}});m.useEffect(()=>{n&&fm(t,i)},[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 VZ(t.name,t.token,w),se.success(e("openai.toast.success.credentialsCreate")),d()}catch(w){console.error("Error:",w),se.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(),fm(t,i)}const f=async g=>{var b,y,x;try{await HZ(g,t==null?void 0:t.name),se.success(e("openai.toast.success.credentialsDelete")),fm(t,i)}catch(w){console.error("Error:",w),se.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})=>l.jsxs(Y,{variant:"ghost",onClick:()=>g.toggleSorting(g.getIsSorted()==="asc"),children:[e("openai.credentials.table.name"),l.jsx(qL,{className:"ml-2 h-4 w-4"})]}),cell:({row:g})=>l.jsx("div",{children:g.getValue("name")})},{accessorKey:"apiKey",header:()=>l.jsx("div",{className:"text-right",children:e("openai.credentials.table.apiKey")}),cell:({row:g})=>l.jsxs("div",{children:[`${g.getValue("apiKey")}`.slice(0,20),"..."]})},{id:"actions",enableHiding:!1,cell:({row:g})=>{const b=g.original;return l.jsxs(ea,{children:[l.jsx(ta,{asChild:!0,children:l.jsxs(Y,{variant:"ghost",className:"h-8 w-8 p-0",children:[l.jsx("span",{className:"sr-only",children:e("openai.credentials.table.actions.title")}),l.jsx(Ou,{className:"h-4 w-4"})]})}),l.jsxs(Co,{align:"end",children:[l.jsx(vl,{children:e("openai.credentials.table.actions.title")}),l.jsx(Za,{}),l.jsx(ft,{onClick:()=>f(b.id),children:e("openai.credentials.table.actions.delete")})]})]})}}],h=Qu({data:a,columns:p,onSortingChange:s,getCoreRowModel:qu(),getPaginationRowModel:Ju(),getSortedRowModel:Zu(),getFilteredRowModel:Ku(),state:{sorting:o}});return l.jsxs(Dt,{open:n,onOpenChange:r,children:[l.jsx(Wt,{asChild:!0,children:l.jsxs(Y,{variant:"secondary",size:"sm",children:[l.jsx(u4,{size:16,className:"mr-1"}),l.jsx("span",{className:"hidden md:inline",children:e("openai.credentials.title")})]})}),l.jsxs(It,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:d,children:[l.jsx(Pt,{children:l.jsx(Xt,{children:e("openai.credentials.title")})}),l.jsx(Jr,{...c,children:l.jsxs("form",{onSubmit:c.handleSubmit(u),className:"w-full space-y-6",children:[l.jsx("div",{children:l.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[l.jsx(L,{name:"name",label:e("openai.credentials.table.name"),children:l.jsx(B,{})}),l.jsx(L,{name:"apiKey",label:e("openai.credentials.table.apiKey"),children:l.jsx(B,{type:"password"})})]})}),l.jsx(gn,{children:l.jsx(Y,{type:"submit",children:e("openai.button.save")})})]})}),l.jsx(rt,{}),l.jsx("div",{children:l.jsxs(jl,{children:[l.jsx(Rl,{children:h.getHeaderGroups().map(g=>l.jsx(Sn,{children:g.headers.map(b=>l.jsx(Pl,{children:b.isPlaceholder?null:So(b.column.columnDef.header,b.getContext())},b.id))},g.id))}),l.jsx(Il,{children:(v=h.getRowModel().rows)!=null&&v.length?h.getRowModel().rows.map(g=>l.jsx(Sn,{"data-state":g.getIsSelected()&&"selected",children:g.getVisibleCells().map(b=>l.jsx(Gr,{children:So(b.column.columnDef.cell,b.getContext())},b.id))},g.id)):l.jsx(Sn,{children:l.jsx(Gr,{colSpan:p.length,className:"h-24 text-center",children:e("openai.credentials.table.none")})})})]})})]})]})}const tQ=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()}),j1=async(e,t,n,r)=>{try{const o=localStorage.getItem("token");if(o&&e&&e.name){const s=await JZ(e.name,o);t(s);const a=await PN(e.name,o);n(a);const i=await Hg(e.name,o);r(i)}else console.error("Token not found")}catch(o){console.error("Error:",o)}};function nQ(){const{t:e}=We(),{instance:t}=ut(),[n,r]=m.useState(!1),[o,s]=m.useState(),[a,i]=m.useState([]),[c,u]=m.useState(),d=At({resolver:Ft(tQ),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&&j1(t,s,i,u)},[t,n]),m.useEffect(()=>{o&&d.reset({openaiCredsId:o.openaiCredsId,expire:(o==null?void 0:o.expire)??0,keywordFinish:o.keywordFinish,delayMessage:o.delayMessage??0,unknownMessage:o.unknownMessage,listeningFromMe:o.listeningFromMe,stopBotFromMe:o.stopBotFromMe,keepOpen:o.keepOpen,debounceTime:o.debounceTime??0,speechToText:o.speechToText,ignoreJids:o.ignoreJids,openaiIdFallback:o.openaiIdFallback})},[o]);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 ZZ(t.name,t.token,y),se.success(e("openai.toast.defaultSettings.success"))}catch(y){console.error("Error:",y),se.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(){j1(t,s,i,u)}return l.jsxs(Dt,{open:n,onOpenChange:r,children:[l.jsx(Wt,{asChild:!0,children:l.jsxs(Y,{variant:"secondary",size:"sm",children:[l.jsx(pl,{size:16,className:"mr-1"}),l.jsx("span",{className:"hidden md:inline",children:e("openai.defaultSettings")})]})}),l.jsxs(It,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:p,children:[l.jsx(Pt,{children:l.jsx(Xt,{children:e("openai.defaultSettings")})}),l.jsx(Jr,{...d,children:l.jsxs("form",{className:"w-full space-y-6",onSubmit:d.handleSubmit(f),children:[l.jsx("div",{children:l.jsxs("div",{className:"space-y-4",children:[l.jsx(at,{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})))||[]}),l.jsx(at,{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})))??[]}),l.jsx(L,{name:"expire",label:e("openai.form.expire.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"keywordFinish",label:e("openai.form.keywordFinish.label"),children:l.jsx(B,{})}),l.jsx(L,{name:"delayMessage",label:e("openai.form.delayMessage.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"unknownMessage",label:e("openai.form.unknownMessage.label"),children:l.jsx(B,{})}),l.jsx(Ce,{name:"listeningFromMe",label:e("openai.form.listeningFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"stopBotFromMe",label:e("openai.form.stopBotFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"keepOpen",label:e("openai.form.keepOpen.label"),reverse:!0}),l.jsx(Ce,{name:"speechToText",label:e("openai.form.speechToText.label"),reverse:!0}),l.jsx(L,{name:"debounceTime",label:e("openai.form.debounceTime.label"),children:l.jsx(B,{type:"number"})}),l.jsx(Uu,{name:"ignoreJids",label:e("openai.form.ignoreJids.label"),placeholder:e("openai.form.ignoreJids.placeholder")})]})}),l.jsx(gn,{children:l.jsx(Y,{type:"submit",children:e("openai.button.save")})})]})})]})]})}const rQ=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 oQ({resetTable:e}){const{t}=We(),{instance:n}=ut(),[r,o]=m.useState(!1),[s,a]=m.useState(!1),[i,c]=m.useState([]),[u,d]=m.useState([]),f=At({resolver:Ft(rQ),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(()=>{s&&(async()=>{try{if(!n)return;const y=await NN(n.name,n.token);c(y);const x=await Hg(n.name,n.token);d(x)}catch(y){console.error("Error:",y)}})()},[n,s]);const p=async b=>{var y,x,w;try{if(!n||!n.name)throw new Error("instance not found.");o(!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 GZ(n.name,n.token,S),se.success(t("openai.toast.success.create")),a(!1),h(),e()}catch(S){console.error("Error:",S),se.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{o(!1)}};function h(){f.reset()}const v=f.watch("botType"),g=f.watch("triggerType");return l.jsxs(Dt,{open:s,onOpenChange:a,children:[l.jsx(Wt,{asChild:!0,children:l.jsxs(Y,{size:"sm",children:[l.jsx(gl,{size:16,className:"mr-1"}),l.jsx("span",{className:"hidden sm:inline",children:t("openai.button.create")})]})}),l.jsxs(It,{className:"max-w-xl",onCloseAutoFocus:h,children:[l.jsx(Pt,{children:l.jsx(Xt,{children:t("openai.form.title")})}),l.jsx(Jr,{...f,children:l.jsxs("form",{onSubmit:f.handleSubmit(p),className:"w-full space-y-6",children:[l.jsx("div",{children:l.jsxs("div",{className:"space-y-4",children:[l.jsx(Ce,{name:"enabled",label:t("openai.form.enabled.label"),reverse:!0}),l.jsx(L,{name:"description",label:t("openai.form.description.label"),required:!0,children:l.jsx(B,{})}),l.jsx(at,{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}))}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:t("openai.form.openaiSettings.label")}),l.jsx(rt,{})]}),l.jsx(at,{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"&&l.jsxs(l.Fragment,{children:[l.jsx(L,{name:"assistantId",label:t("openai.form.assistantId.label"),required:!0,children:l.jsx(B,{})}),l.jsx(L,{name:"functionUrl",label:t("openai.form.functionUrl.label"),required:!0,children:l.jsx(B,{})})]}),v==="chatCompletion"&&l.jsxs(l.Fragment,{children:[l.jsx(at,{name:"model",label:t("openai.form.model.label"),required:!0,options:i.map(b=>({label:b.id,value:b.id}))}),l.jsx(L,{name:"systemMessages",label:t("openai.form.systemMessages.label"),children:l.jsx(Uo,{})}),l.jsx(L,{name:"assistantMessages",label:t("openai.form.assistantMessages.label"),children:l.jsx(Uo,{})}),l.jsx(L,{name:"userMessages",label:t("openai.form.userMessages.label"),children:l.jsx(Uo,{})}),l.jsx(L,{name:"maxTokens",label:t("openai.form.maxTokens.label"),children:l.jsx(B,{type:"number"})})]}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:t("openai.form.triggerSettings.label")}),l.jsx(rt,{})]}),l.jsx(at,{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"&&l.jsxs(l.Fragment,{children:[l.jsx(at,{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"}]}),l.jsx(L,{name:"triggerValue",label:t("openai.form.triggerValue.label"),required:!0,children:l.jsx(B,{})})]}),g==="advanced"&&l.jsx(L,{name:"triggerValue",label:t("openai.form.triggerConditions.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:t("openai.form.generalSettings.label")}),l.jsx(rt,{})]}),l.jsx(L,{name:"expire",label:t("openai.form.expire.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"keywordFinish",label:t("openai.form.keywordFinish.label"),children:l.jsx(B,{})}),l.jsx(L,{name:"delayMessage",label:t("openai.form.delayMessage.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"unknownMessage",label:t("openai.form.unknownMessage.label"),children:l.jsx(B,{})}),l.jsx(Ce,{name:"listeningFromMe",label:t("openai.form.listeningFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"stopBotFromMe",label:t("openai.form.stopBotFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"keepOpen",label:t("openai.form.keepOpen.label"),reverse:!0}),l.jsx(L,{name:"debounceTime",label:t("openai.form.debounceTime.label"),children:l.jsx(B,{type:"number"})})]})}),l.jsx(gn,{children:l.jsx(Y,{disabled:r,type:"submit",children:t(r?"openai.button.saving":"openai.button.save")})})]})})]})]})}const R1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const o=await QZ(e.name,r,n);t(o)}else console.error("Token not found")}catch(r){console.error("Error:",r)}};function ON({botId:e}){var h,v;const{t}=We(),{instance:n}=ut(),[r,o]=m.useState([]),[s,a]=m.useState([]),[i,c]=m.useState(!1);m.useEffect(()=>{i&&R1(n,a,e)},[n,e,i]);function u(){R1(n,a,e)}const d=async(g,b)=>{var y,x,w;try{if(!n)return;await YZ(n.name,n.token,g,b),se.success(t("openai.toast.success.status")),u()}catch(S){console.error("Error:",S),se.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:()=>l.jsx("div",{className:"text-center",children:t("openai.sessions.table.remoteJid")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>l.jsx("div",{className:"text-center",children:t("openai.sessions.table.pushName")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("pushName")})},{accessorKey:"sessionId",header:()=>l.jsx("div",{className:"text-center",children:t("openai.sessions.table.sessionId")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("sessionId")})},{accessorKey:"status",header:()=>l.jsx("div",{className:"text-center",children:t("openai.sessions.table.status")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:g})=>{const b=g.original;return l.jsxs(ea,{children:[l.jsx(ta,{asChild:!0,children:l.jsxs(Y,{variant:"ghost",size:"icon",children:[l.jsx("span",{className:"sr-only",children:t("openai.sessions.table.actions.title")}),l.jsx(Ou,{className:"h-4 w-4"})]})}),l.jsxs(Co,{align:"end",children:[l.jsx(vl,{children:t("openai.sessions.table.actions.title")}),l.jsx(Za,{}),b.status!=="opened"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"opened"),children:[l.jsx(ng,{className:"mr-2 h-4 w-4"}),t("openai.sessions.table.actions.open")]}),b.status!=="paused"&&b.status!=="closed"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"paused"),children:[l.jsx(tg,{className:"mr-2 h-4 w-4"}),t("openai.sessions.table.actions.pause")]}),b.status!=="closed"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"closed"),children:[l.jsx(Qp,{className:"mr-2 h-4 w-4"}),t("openai.sessions.table.actions.close")]}),l.jsxs(ft,{onClick:()=>d(b.remoteJid,"delete"),children:[l.jsx(Yp,{className:"mr-2 h-4 w-4"}),t("openai.sessions.table.actions.delete")]})]})]})}}],p=Qu({data:s,columns:f,onSortingChange:o,getCoreRowModel:qu(),getPaginationRowModel:Ju(),getSortedRowModel:Zu(),getFilteredRowModel:Ku(),state:{sorting:r}});return l.jsxs(Dt,{open:i,onOpenChange:c,children:[l.jsx(Wt,{asChild:!0,children:l.jsxs(Y,{variant:"secondary",size:"sm",children:[l.jsx(Xp,{size:16,className:"mr-1"}),l.jsx("span",{className:"hidden md:inline",children:t("openai.sessions.label")})]})}),l.jsxs(It,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:u,children:[l.jsx(Pt,{children:l.jsx(Xt,{children:t("openai.sessions.label")})}),l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[l.jsx(B,{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)}}),l.jsx(Y,{variant:"outline",onClick:u,size:"icon",children:l.jsx(rg,{size:16})})]}),l.jsxs(jl,{children:[l.jsx(Rl,{children:p.getHeaderGroups().map(g=>l.jsx(Sn,{children:g.headers.map(b=>l.jsx(Pl,{children:b.isPlaceholder?null:So(b.column.columnDef.header,b.getContext())},b.id))},g.id))}),l.jsx(Il,{children:(v=p.getRowModel().rows)!=null&&v.length?p.getRowModel().rows.map(g=>l.jsx(Sn,{"data-state":g.getIsSelected()&&"selected",children:g.getVisibleCells().map(b=>l.jsx(Gr,{children:So(b.column.columnDef.cell,b.getContext())},b.id))},g.id)):l.jsx(Sn,{children:l.jsx(Gr,{colSpan:f.length,className:"h-24 text-center",children:t("openai.sessions.table.none")})})})]})]})]})]})}const sQ=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 aQ({botId:e,instance:t,resetTable:n}){const{t:r}=We(),[,o]=m.useState(""),[s,a]=m.useState(!0),[i,c]=m.useState(!1),[u,d]=m.useState([]),[f,p]=m.useState([]),h=Vn(),v=At({resolver:Ft(sQ),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){o(C);const T=await WZ(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 NN(t.name,t.token);d(C);const T=await Hg(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 _=localStorage.getItem("token");if(_&&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 qZ(t.name,_,e,I),se.success(r("openai.toast.success.update"))}else console.error("Instance not found")}catch(_){console.error("Error:",_),se.error(`Error: ${(T=(C=(E=_==null?void 0:_.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 KZ(t.name,S,e),se.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 l.jsxs(l.Fragment,{children:[s&&l.jsx(Wr,{}),!s&&l.jsx(Tr,{...v,children:l.jsxs("form",{onSubmit:v.handleSubmit(g),className:"w-full space-y-6 pl-4 pr-2",children:[l.jsxs("div",{className:"space-y-6",children:[l.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[l.jsxs("h3",{className:"mb-4 text-lg font-medium",children:["OpenAI: ",y]}),l.jsx(Ce,{name:"enabled",className:"flex items-center gap-3"})]}),l.jsxs("div",{className:"space-y-4",children:[l.jsx(L,{name:"description",label:r("openai.form.description.label"),required:!0,children:l.jsx(B,{})}),l.jsx(at,{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}))}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("openai.form.openaiSettings.label")}),l.jsx(rt,{})]}),l.jsx(at,{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"&&l.jsxs(l.Fragment,{children:[l.jsx(L,{name:"assistantId",label:r("openai.form.assistantId.label"),required:!0,children:l.jsx(B,{})}),l.jsx(L,{name:"functionUrl",label:r("openai.form.functionUrl.label"),required:!0,children:l.jsx(B,{})})]}),x==="chatCompletion"&&l.jsxs(l.Fragment,{children:[l.jsx(at,{name:"model",label:r("openai.form.model.label"),required:!0,options:u.map(S=>({label:S.id,value:S.id}))}),l.jsx(L,{name:"systemMessages",label:r("openai.form.systemMessages.label"),children:l.jsx(Uo,{})}),l.jsx(L,{name:"assistantMessages",label:r("openai.form.assistantMessages.label"),children:l.jsx(Uo,{})}),l.jsx(L,{name:"userMessages",label:r("openai.form.userMessages.label"),children:l.jsx(Uo,{})}),l.jsx(L,{name:"maxTokens",label:r("openai.form.maxTokens"),children:l.jsx(B,{type:"number"})})]}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("openai.form.triggerSettings.label")}),l.jsx(rt,{})]}),l.jsx(at,{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"&&l.jsxs(l.Fragment,{children:[l.jsx(at,{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"}]}),l.jsx(L,{name:"triggerValue",label:r("openai.form.triggerValue.label"),required:!0,children:l.jsx(B,{})})]}),w==="advanced"&&l.jsx(L,{name:"triggerValue",label:r("openai.form.triggerConditions.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("openai.form.generalSettings.label")}),l.jsx(rt,{})]}),l.jsx(L,{name:"expire",label:r("openai.form.expire.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"keywordFinish",label:r("openai.form.keywordFinish.label"),children:l.jsx(B,{})}),l.jsx(L,{name:"delayMessage",label:r("openai.form.delayMessage.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"unknownMessage",label:r("openai.form.unknownMessage.label"),children:l.jsx(B,{})}),l.jsx(Ce,{name:"listeningFromMe",label:r("openai.form.listeningFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"stopBotFromMe",label:r("openai.form.stopBotFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"keepOpen",label:r("openai.form.keepOpen.label"),reverse:!0}),l.jsx(L,{name:"debounceTime",label:r("openai.form.debounceTime.label"),children:l.jsx(B,{type:"number"})})]})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx(ON,{botId:e}),l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsxs(Dt,{open:i,onOpenChange:c,children:[l.jsx(Wt,{asChild:!0,children:l.jsx(Y,{variant:"destructive",size:"sm",children:r("openai.button.delete")})}),l.jsx(It,{children:l.jsxs(Pt,{children:[l.jsx(Xt,{children:r("modal.delete.title")}),l.jsx(yl,{children:r("modal.delete.messageSingle")}),l.jsxs(gn,{children:[l.jsx(Y,{size:"sm",variant:"outline",onClick:()=>c(!1),children:r("button.cancel")}),l.jsx(Y,{variant:"destructive",onClick:b,children:r("button.delete")})]})]})})]}),l.jsx(Y,{type:"submit",children:r("openai.button.update")})]})]})]})})]})}const I1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const o=await PN(e.name,r);t(o)}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}=We(),t=Wu("(min-width: 768px)"),{instance:n}=ut(),{botId:r}=Ys(),[o,s]=m.useState(!0),[a,i]=m.useState([]),c=Vn();m.useEffect(()=>{n&&I1(n,i,s)},[n]);const u=f=>{n&&c(`/manager/instance/${n.id}/openai/${f}`)},d=()=>{I1(n,i,s)};return l.jsxs("main",{className:"pt-5",children:[l.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[l.jsx("h3",{className:"text-lg font-medium",children:e("openai.title")}),l.jsxs("div",{className:"flex items-center justify-end gap-2",children:[l.jsx(ON,{}),l.jsx(nQ,{}),l.jsx(eQ,{}),l.jsx(oQ,{resetTable:d})]})]}),l.jsx(rt,{className:"my-4"}),l.jsxs(Vu,{direction:t?"horizontal":"vertical",children:[l.jsx(wo,{defaultSize:35,className:"pr-4",children:l.jsx("div",{className:"flex flex-col gap-3",children:o?l.jsx(Wr,{}):l.jsx(l.Fragment,{children:a&&a.length>0&&Array.isArray(a)?a.map(f=>l.jsxs(Y,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>u(`${f.id}`),variant:r===f.id?"secondary":"outline",children:[l.jsx("h4",{className:"text-base",children:f.description||f.id}),l.jsx("p",{className:"text-sm font-normal text-muted-foreground",children:f.botType})]},f.id)):l.jsx(Y,{variant:"link",children:e("openai.table.none")})})})}),r&&l.jsxs(l.Fragment,{children:[l.jsx(Hu,{withHandle:!0,className:"border border-border"}),l.jsx(wo,{className:"",children:l.jsx(aQ,{botId:r,instance:n,resetTable:d})})]})]})]})}const MN=new Cr,iQ=async(e,t)=>(await MN.getInstance().get(`/proxy/find/${e}`,{headers:{apikey:t}})).data,lQ=async(e,t,n)=>(await MN.getInstance().post(`/proxy/set/${e}`,n,{headers:{apikey:t}})).data,cQ=k.object({enabled:k.boolean(),host:k.string(),port:k.string(),protocol:k.string(),username:k.string(),password:k.string()});function uQ(){const{t:e}=We(),{instance:t}=ut(),[n,r]=m.useState(!1),o=At({resolver:Ft(cQ),defaultValues:{enabled:!1,host:"",port:"",protocol:"http",username:"",password:""}});m.useEffect(()=>{(async()=>{if(t){r(!0);try{const i=await iQ(t.name,t.token);o.reset(i)}catch(i){console.error("Error:",i)}finally{r(!1)}}})()},[t,o]);const s=async a=>{var i,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 lQ(t.name,t.token,d),se.success(e("proxy.toast.success"))}catch(d){console.error(e("proxy.toast.error"),d),se.error(`Error : ${(u=(c=(i=d==null?void 0:d.response)==null?void 0:i.data)==null?void 0:c.response)==null?void 0:u.message}`)}finally{r(!1)}}};return l.jsx(l.Fragment,{children:l.jsx(Tr,{...o,children:l.jsx("form",{onSubmit:o.handleSubmit(s),className:"w-full space-y-6",children:l.jsxs("div",{children:[l.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("proxy.title")}),l.jsx(Xs,{className:"my-4"}),l.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[l.jsx(Ce,{name:"enabled",label:e("proxy.form.enabled.label"),className:"w-full justify-between",helper:e("proxy.form.enabled.description")}),l.jsxs("div",{className:"grid gap-4 sm:grid-cols-[10rem_1fr_10rem] md:gap-8",children:[l.jsx(L,{name:"protocol",label:e("proxy.form.protocol.label"),children:l.jsx(B,{})}),l.jsx(L,{name:"host",label:e("proxy.form.host.label"),children:l.jsx(B,{})}),l.jsx(L,{name:"port",label:e("proxy.form.port.label"),children:l.jsx(B,{type:"number"})})]}),l.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 md:gap-8",children:[l.jsx(L,{name:"username",label:e("proxy.form.username.label"),children:l.jsx(B,{})}),l.jsx(L,{name:"password",label:e("proxy.form.password.label"),children:l.jsx(B,{type:"password"})})]}),l.jsx("div",{className:"flex justify-end px-4 pt-6",children:l.jsx(Y,{type:"submit",disabled:n,children:e(n?"proxy.button.saving":"proxy.button.save")})})]})]})})})})}const DN=new Cr,dQ=async(e,t)=>(await DN.getInstance().get(`/rabbitmq/find/${e}`,{headers:{apikey:t}})).data,fQ=async(e,t,n)=>(await DN.getInstance().post(`/rabbitmq/set/${e}`,n,{headers:{apikey:t}})).data,pQ=k.object({enabled:k.boolean(),events:k.array(k.string())});function gQ(){const{t:e}=We(),{instance:t}=ut(),[n,r]=m.useState(!1),o=At({resolver:Ft(pQ),defaultValues:{enabled:!1,events:[]}});m.useEffect(()=>{(async()=>{if(t){r(!0);try{const c=await dQ(t.name,t.token);o.reset(c)}catch(c){console.error("Error:",c)}finally{r(!1)}}})()},[t,o]);const s=async i=>{var c,u,d;if(t){r(!0);try{const f={enabled:i.enabled,events:i.events};await fQ(t.name,t.token,f),se.success(e("rabbitmq.toast.success"))}catch(f){console.error(e("rabbitmq.toast.error"),f),se.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 l.jsx(l.Fragment,{children:l.jsx(Tr,{...o,children:l.jsx("form",{onSubmit:o.handleSubmit(s),className:"w-full space-y-6",children:l.jsxs("div",{children:[l.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("rabbitmq.title")}),l.jsx(Xs,{className:"my-4"}),l.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[l.jsx(Ce,{name:"enabled",label:e("rabbitmq.form.enabled.label"),className:"w-full justify-between",helper:e("rabbitmq.form.enabled.description")}),l.jsx(oa,{control:o.control,name:"events",render:({field:i})=>l.jsxs(ns,{className:"flex flex-col",children:[l.jsx(or,{className:"my-2 text-lg",children:e("rabbitmq.form.events.label")}),l.jsx(xo,{children:l.jsx("div",{className:"flex flex-col gap-2 space-y-1 divide-y",children:a.sort((c,u)=>c.localeCompare(u)).map(c=>l.jsxs("div",{className:"flex items-center justify-between gap-3 pt-3",children:[l.jsx(or,{className:he("break-all",i.value.includes(c)?"text-foreground":"text-muted-foreground"),children:c}),l.jsx(_l,{checked:i.value.includes(c),onCheckedChange:u=>{u?i.onChange([...i.value,c]):i.onChange(i.value.filter(d=>d!==c))}})]},c))})})]})})]}),l.jsx("div",{className:"mx-4 flex justify-end pt-6",children:l.jsx(Y,{type:"submit",disabled:n,children:e(n?"rabbitmq.button.saving":"rabbitmq.button.save")})})]})})})})}const hQ=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 mQ(){const{t:e}=We(),[t,n]=m.useState(!0),[r,o]=m.useState(!1),[s,a]=m.useState(""),{instance:i}=ut(),c=At({resolver:Ft(hQ),defaultValues:{rejectCall:!1,msgCall:"",groupsIgnore:!1,alwaysOnline:!1,readMessages:!1,syncFullHistory:!1,readStatus:!1}});m.useEffect(()=>{(async()=>{try{if(i&&i.name&&i.token){a(i.token);const h=await w4(i.name,i.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,i]);const u=async p=>{try{if(!i||!i.name)throw new Error("instance not found");o(!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 S4(i.name,s,h),se.success(e("settings.toast.success"))}catch(h){console.error(e("settings.toast.success"),h),se.error(e("settings.toast.error"))}finally{o(!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?l.jsx(Wr,{}):l.jsx(l.Fragment,{children:l.jsx(Tr,{...c,children:l.jsx("form",{onSubmit:c.handleSubmit(u),className:"w-full space-y-6",children:l.jsxs("div",{children:[l.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("settings.title")}),l.jsx(rt,{className:"my-4"}),l.jsxs("div",{className:"mx-4 space-y-2 divide-y",children:[l.jsxs("div",{className:"flex flex-col p-4",children:[l.jsx(Ce,{name:"rejectCall",label:e("settings.form.rejectCall.label"),className:"w-full justify-between",helper:e("settings.form.rejectCall.description")}),f&&l.jsx("div",{className:"mr-16 mt-2",children:l.jsx(L,{name:"msgCall",children:l.jsx(Uo,{placeholder:e("settings.form.msgCall.description")})})})]}),d.map(p=>l.jsx("div",{className:"flex p-4",children:l.jsx(Ce,{name:p.name,label:p.label,className:"w-full justify-between",helper:p.description})},p.name)),l.jsx("div",{className:"flex justify-end pt-6",children:l.jsx(Y,{type:"submit",disabled:r,children:e(r?"settings.button.saving":"settings.button.save")})})]})]})})})})}const AN=new Cr,vQ=async(e,t)=>(await AN.getInstance().get(`/sqs/find/${e}`,{headers:{apikey:t}})).data,yQ=async(e,t,n)=>(await AN.getInstance().post(`/sqs/set/${e}`,n,{headers:{apikey:t}})).data,bQ=k.object({enabled:k.boolean(),events:k.array(k.string())});function xQ(){const{t:e}=We(),{instance:t}=ut(),[n,r]=m.useState(!1),o=At({resolver:Ft(bQ),defaultValues:{enabled:!1,events:[]}});m.useEffect(()=>{(async()=>{if(t){r(!0);try{const c=await vQ(t.name,t.token);o.reset(c)}catch(c){console.error("Error",c)}finally{r(!1)}}})()},[t,o]);const s=async i=>{var c,u,d;if(t){r(!0);try{const f={enabled:i.enabled,events:i.events};await yQ(t.name,t.token,f),se.success(e("sqs.toast.success"))}catch(f){console.error(e("sqs.toast.error"),f),se.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 l.jsx(l.Fragment,{children:l.jsx(Tr,{...o,children:l.jsx("form",{onSubmit:o.handleSubmit(s),className:"w-full space-y-6",children:l.jsxs("div",{children:[l.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("sqs.title")}),l.jsx(Xs,{className:"my-4"}),l.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[l.jsx(Ce,{name:"enabled",label:e("sqs.form.enabled.label"),className:"w-full justify-between",helper:e("sqs.form.enabled.description")}),l.jsx(oa,{control:o.control,name:"events",render:({field:i})=>l.jsxs(ns,{className:"flex flex-col",children:[l.jsx(or,{className:"my-2 text-lg",children:e("sqs.form.events.label")}),l.jsx(xo,{children:l.jsx("div",{className:"flex flex-col gap-2 space-y-1 divide-y",children:a.sort((c,u)=>c.localeCompare(u)).map(c=>l.jsxs("div",{className:"flex items-center justify-between gap-3 pt-3",children:[l.jsx(or,{className:he("break-all",i.value.includes(c)?"text-foreground":"text-muted-foreground"),children:c}),l.jsx(_l,{checked:i.value.includes(c),onCheckedChange:u=>{u?i.onChange([...i.value,c]):i.onChange(i.value.filter(d=>d!==c))}})]},c))})})]})})]}),l.jsx("div",{className:"mx-4 flex justify-end pt-6",children:l.jsx(Y,{type:"submit",disabled:n,children:e(n?"sqs.button.saving":"sqs.button.save")})})]})})})})}const os=new Cr,FN=async(e,t)=>(await os.getInstance().get(`/typebot/find/${e}`,{headers:{apikey:t}})).data,wQ=async(e,t,n)=>(await os.getInstance().get(`/typebot/fetch/${n}/${e}`,{headers:{apikey:t}})).data,SQ=async(e,t,n)=>(await os.getInstance().post(`/typebot/create/${e}`,n,{headers:{apikey:t}})).data,CQ=async(e,t,n,r)=>(await os.getInstance().put(`/typebot/update/${n}/${e}`,r,{headers:{apikey:t}})).data,EQ=async(e,t,n)=>(await os.getInstance().delete(`/typebot/delete/${n}/${e}`,{headers:{apikey:t}})).data,kQ=async(e,t)=>(await os.getInstance().get(`/typebot/fetchSettings/${e}`,{headers:{apikey:t}})).data,TQ=async(e,t,n)=>(await os.getInstance().post(`/typebot/settings/${e}`,n,{headers:{apikey:t}})).data,_Q=async(e,t,n)=>(await os.getInstance().get(`/typebot/fetchSessions/${n}/${e}`,{headers:{apikey:t}})).data,jQ=async(e,t,n,r)=>(await os.getInstance().post(`/typebot/changeStatus/${e}`,{remoteJid:n,status:r},{headers:{apikey:t}})).data,RQ=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()}),N1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const o=await kQ(e.name,r);t(o);const s=await FN(e.name,r);n(s)}else console.error("token not found.")}catch(r){console.error("Error:",r)}};function IQ(){const{t:e}=We(),{instance:t}=ut(),[n,r]=m.useState(),[o,s]=m.useState([]),[a,i]=m.useState(!1),c=At({resolver:Ft(RQ),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&&N1(t,r,s)},[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 TQ(t.name,t.token,g),se.success(e("typebot.toast.defaultSettings.success"))}catch(g){console.error(e("typebot.toast.defaultSettings.error"),g),se.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(){N1(t,r,s)}return l.jsxs(Dt,{open:a,onOpenChange:i,children:[l.jsx(Wt,{asChild:!0,children:l.jsxs(Y,{variant:"secondary",size:"sm",children:[l.jsx(pl,{size:16,className:"mr-1"}),l.jsx("span",{className:"hidden sm:inline",children:e("typebot.button.defaultSettings")})]})}),l.jsxs(It,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:d,children:[l.jsx(Pt,{children:l.jsx(Xt,{children:e("typebot.modal.defaultSettings.title")})}),l.jsx(Jr,{...c,children:l.jsxs("form",{className:"w-full space-y-6",onSubmit:c.handleSubmit(u),children:[l.jsx("div",{children:l.jsxs("div",{className:"space-y-4",children:[l.jsx(at,{name:"typebotIdFallback",label:e("typebot.form.typebotIdFallback.label"),options:(o==null?void 0:o.filter(f=>!!f.id).map(f=>({label:f.typebot,value:f.description})))??[]}),l.jsx(L,{name:"expire",label:e("typebot.form.expire.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"keywordFinish",label:e("typebot.form.keywordFinish.label"),children:l.jsx(B,{})}),l.jsx(L,{name:"delayMessage",label:e("typebot.form.delayMessage.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"unknownMessage",label:e("typebot.form.unknownMessage.label"),children:l.jsx(B,{})}),l.jsx(Ce,{name:"listeningFromMe",label:e("typebot.form.listeningFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"stopBotFromMe",label:e("typebot.form.stopBotFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"keepOpen",label:e("typebot.form.keepOpen.label"),reverse:!0}),l.jsx(L,{name:"debounceTime",label:e("typebot.form.debounceTime.label"),children:l.jsx(B,{type:"number"})}),l.jsx(Uu,{name:"ignoreJids",label:e("typebot.form.ignoreJids.label"),placeholder:e("typebot.form.ignoreJids.placeholder")})]})}),l.jsx(gn,{children:l.jsx(Y,{type:"submit",children:e("typebot.button.save")})})]})})]})]})}const PQ=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 NQ({resetTable:e}){const{t}=We(),{instance:n}=ut(),[r,o]=m.useState(!1),[s,a]=m.useState(!1),i=At({resolver:Ft(PQ),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.");o(!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 SQ(n.name,n.token,g),se.success(t("typebot.toast.success.create")),a(!1),u(),e()}catch(g){console.error(t("typebot.toast.error"),g),se.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{o(!1)}};function u(){i.reset()}const d=i.watch("triggerType");return l.jsxs(Dt,{open:s,onOpenChange:a,children:[l.jsx(Wt,{asChild:!0,children:l.jsxs(Y,{variant:"default",className:"mr-5 text-white",children:[l.jsx(gl,{}),l.jsx("span",{className:"hidden sm:inline",children:t("typebot.button.create")})]})}),l.jsxs(It,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:u,children:[l.jsx(Pt,{children:l.jsx(Xt,{children:t("typebot.form.title")})}),l.jsx(Jr,{...i,children:l.jsxs("form",{onSubmit:i.handleSubmit(c),className:"w-full space-y-6",children:[l.jsx("div",{children:l.jsxs("div",{className:"space-y-4",children:[l.jsx(Ce,{name:"enabled",label:t("typebot.form.enabled.label"),reverse:!0}),l.jsx(L,{name:"description",label:t("typebot.form.description.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:t("typebot.form.typebotSettings.label")}),l.jsx(rt,{})]}),l.jsx(L,{name:"url",label:t("typebot.form.url.label"),required:!0,children:l.jsx(B,{})}),l.jsx(L,{name:"typebot",label:t("typebot.form.typebot.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:t("typebot.form.triggerSettings.label")}),l.jsx(rt,{})]}),l.jsx(at,{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"&&l.jsxs(l.Fragment,{children:[l.jsx(at,{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"}]}),l.jsx(L,{name:"triggerValue",label:t("typebot.form.triggerValue.label"),required:!0,children:l.jsx(B,{})})]}),d==="advanced"&&l.jsx(L,{name:"triggerValue",label:t("typebot.form.triggerConditions.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:t("typebot.form.generalSettings.label")}),l.jsx(rt,{})]}),l.jsx(L,{name:"expire",label:t("typebot.form.expire.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"keywordFinish",label:t("typebot.form.keywordFinish.label"),children:l.jsx(B,{})}),l.jsx(L,{name:"delayMessage",label:t("typebot.form.delayMessage.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"unknownMessage",label:t("typebot.form.unknownMessage.label"),children:l.jsx(B,{})}),l.jsx(Ce,{name:"listeningFromMe",label:t("typebot.form.listeningFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"stopBotFromMe",label:t("typebot.form.stopBotFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"keepOpen",label:t("typebot.form.keepOpen.label"),reverse:!0}),l.jsx(L,{name:"debounceTime",label:t("typebot.form.debounceTime.label"),children:l.jsx(B,{type:"number"})})]})}),l.jsx(gn,{children:l.jsx(Y,{disabled:r,type:"submit",children:t("typebot.button.save")})})]})})]})]})}const O1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const o=await _Q(e.name,r,n);t(o)}else console.error("Token ou nome da instância não encontrados.")}catch(r){console.error("Erro ao carregar sessões:",r)}};function LN({typebotId:e}){var h,v;const{t}=We(),{instance:n}=ut(),[r,o]=m.useState([]),[s,a]=m.useState([]),[i,c]=m.useState(!1);m.useEffect(()=>{i&&O1(n,a,e)},[n,e,i]);function u(){O1(n,a,e)}const d=async(g,b)=>{var y,x,w;try{if(!n)return;await jQ(n.name,n.token,g,b),se.success(t("typebot.toast.success.status")),u()}catch(S){console.error("Error:",S),se.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:()=>l.jsx("div",{className:"text-center",children:t("typebot.sessions.table.remoteJid")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>l.jsx("div",{className:"text-center",children:t("typebot.sessions.table.pushName")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("pushName")})},{accessorKey:"sessionId",header:()=>l.jsx("div",{className:"text-center",children:t("typebot.sessions.table.sessionId")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("sessionId")})},{accessorKey:"status",header:()=>l.jsx("div",{className:"text-center",children:t("typebot.sessions.table.status")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:g})=>{const b=g.original;return l.jsxs(ea,{children:[l.jsx(ta,{asChild:!0,children:l.jsxs(Y,{variant:"ghost",className:"h-8 w-8 p-0",children:[l.jsx("span",{className:"sr-only",children:t("typebot.sessions.table.actions.title")}),l.jsx(Ou,{className:"h-4 w-4"})]})}),l.jsxs(Co,{align:"end",children:[l.jsx(vl,{children:"Actions"}),l.jsx(Za,{}),b.status!=="opened"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"opened"),children:[l.jsx(ng,{className:"mr-2 h-4 w-4"}),t("typebot.sessions.table.actions.open")]}),b.status!=="paused"&&b.status!=="closed"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"paused"),children:[l.jsx(tg,{className:"mr-2 h-4 w-4"}),t("typebot.sessions.table.actions.pause")]}),b.status!=="closed"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"closed"),children:[l.jsx(Qp,{className:"mr-2 h-4 w-4"}),t("typebot.sessions.table.actions.close")]}),l.jsxs(ft,{onClick:()=>d(b.remoteJid,"delete"),children:[l.jsx(Yp,{className:"mr-2 h-4 w-4"}),t("typebot.sessions.table.actions.delete")]})]})]})}}],p=Qu({data:s,columns:f,onSortingChange:o,getCoreRowModel:qu(),getPaginationRowModel:Ju(),getSortedRowModel:Zu(),getFilteredRowModel:Ku(),state:{sorting:r}});return l.jsxs(Dt,{open:i,onOpenChange:c,children:[l.jsx(Wt,{asChild:!0,children:l.jsxs(Y,{variant:"secondary",size:"sm",children:[l.jsx(Xp,{size:16,className:"mr-1"})," ",l.jsx("span",{className:"hidden sm:inline",children:t("typebot.sessions.label")})]})}),l.jsxs(It,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:u,children:[l.jsx(Pt,{children:l.jsx(Xt,{children:t("typebot.sessions.label")})}),l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[l.jsx(B,{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)}}),l.jsx(Y,{variant:"outline",onClick:u,size:"icon",children:l.jsx(rg,{size:16})})]}),l.jsxs(jl,{children:[l.jsx(Rl,{children:p.getHeaderGroups().map(g=>l.jsx(Sn,{children:g.headers.map(b=>l.jsx(Pl,{children:b.isPlaceholder?null:So(b.column.columnDef.header,b.getContext())},b.id))},g.id))}),l.jsx(Il,{children:(v=p.getRowModel().rows)!=null&&v.length?p.getRowModel().rows.map(g=>l.jsx(Sn,{"data-state":g.getIsSelected()&&"selected",children:g.getVisibleCells().map(b=>l.jsx(Gr,{children:So(b.column.columnDef.cell,b.getContext())},b.id))},g.id)):l.jsx(Sn,{children:l.jsx(Gr,{colSpan:f.length,className:"h-24 text-center",children:t("typebot.sessions.table.none")})})})]})]})]})]})}const OQ=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 MQ({typebotId:e,instance:t,resetTable:n}){const{t:r}=We(),[,o]=m.useState(""),[s,a]=m.useState(!0),[i,c]=m.useState(!1),u=Vn(),d=At({resolver:Ft(OQ),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){o(b);const y=await wQ(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 CQ(t.name,w,e,S),se.success(r("typebot.toast.success.update"))}else console.error("Token not found")}catch(w){console.error("Error:",w),se.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 EQ(t.name,g,e),se.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 l.jsxs(l.Fragment,{children:[s&&l.jsx(Wr,{}),!s&&l.jsx(Tr,{...d,children:l.jsxs("form",{onSubmit:d.handleSubmit(f),className:"w-full space-y-6 pl-4 pr-2",children:[l.jsxs("div",{className:"space-y-6",children:[l.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[l.jsxs("h3",{className:"mb-4 text-lg font-medium",children:["Typebot: ",h]}),l.jsx(Ce,{name:"enabled",className:"flex items-center gap-3"})]}),l.jsxs("div",{className:"space-y-4",children:[l.jsx(L,{name:"description",label:r("typebot.form.description.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("typebot.form.typebotSettings.label")}),l.jsx(rt,{})]}),l.jsx(L,{name:"url",label:r("typebot.form.url.label"),required:!0,children:l.jsx(B,{})}),l.jsx(L,{name:"typebot",label:r("typebot.form.typebot.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("typebot.form.triggerSettings.label")}),l.jsx(rt,{})]}),l.jsx(at,{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"&&l.jsxs(l.Fragment,{children:[l.jsx(at,{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"}]}),l.jsx(L,{name:"triggerValue",label:r("typebot.form.triggerValue.label"),required:!0,children:l.jsx(B,{})})]}),v==="advanced"&&l.jsx(L,{name:"triggerValue",label:r("typebot.form.triggerConditions.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("typebot.form.generalSettings.label")}),l.jsx(rt,{})]}),l.jsx(L,{name:"expire",label:r("typebot.form.expire.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"keywordFinish",label:r("typebot.form.keywordFinish.label"),children:l.jsx(B,{})}),l.jsx(L,{name:"delayMessage",label:r("typebot.form.delay.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"unknownMessage",label:r("typebot.form.unknownMessage.label"),children:l.jsx(B,{})}),l.jsx(Ce,{name:"listeningFromMe",label:r("typebot.form.listeningFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"stopBotFromMe",label:r("typebot.form.stopBotFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"keepOpen",label:r("typebot.form.keepOpen.label"),reverse:!0}),l.jsx(L,{name:"debounceTime",label:r("typebot.form.debounceTime.label"),children:l.jsx(B,{type:"number"})})]})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx(LN,{typebotId:e}),l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsxs(Dt,{open:i,onOpenChange:c,children:[l.jsx(Wt,{asChild:!0,children:l.jsx(Y,{variant:"destructive",size:"sm",children:r("typebot.button.delete")})}),l.jsx(It,{children:l.jsxs(Pt,{children:[l.jsx(Xt,{children:r("modal.delete.title")}),l.jsx(yl,{children:r("modal.delete.messageSingle")}),l.jsxs(gn,{children:[l.jsx(Y,{size:"sm",variant:"outline",onClick:()=>c(!1),children:r("button.cancel")}),l.jsx(Y,{variant:"destructive",onClick:p,children:r("button.delete")})]})]})})]}),l.jsx(Y,{type:"submit",children:r("typebot.button.update")})]})]})]})})]})}const M1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const o=await FN(e.name,r);t(o)}else console.error("token not found.");n(!1)}catch(r){console.error("Error",r),n(!1)}};function D1(){const{t:e}=We(),t=Wu("(min-width: 768px)"),{instance:n}=ut(),{typebotId:r}=Ys(),[o,s]=m.useState(!0),[a,i]=m.useState([]),c=Vn();m.useEffect(()=>{n&&M1(n,i,s)},[n]);const u=f=>{n&&c(`/manager/instance/${n.id}/typebot/${f}`)},d=()=>{M1(n,i,s)};return l.jsxs("main",{className:"pt-5",children:[l.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[l.jsx("h3",{className:"text-lg font-medium",children:e("typebot.title")}),l.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[l.jsx(LN,{}),l.jsx(IQ,{}),l.jsx(NQ,{resetTable:d})]})]}),l.jsx(rt,{className:"my-4"}),l.jsxs(Vu,{direction:t?"horizontal":"vertical",children:[l.jsx(wo,{defaultSize:35,className:"pr-4",children:l.jsx("div",{className:"flex flex-col gap-3",children:o?l.jsx(Wr,{}):l.jsx(l.Fragment,{children:a&&a.length>0&&Array.isArray(a)?a.map(f=>l.jsx(Y,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>u(`${f.id}`),variant:r===f.id?"secondary":"outline",children:f.description?l.jsxs(l.Fragment,{children:[l.jsx("h4",{className:"text-base",children:f.description}),l.jsxs("p",{className:"text-wrap text-sm font-normal text-muted-foreground",children:[f.url," - ",f.typebot]})]}):l.jsxs(l.Fragment,{children:[l.jsx("h4",{className:"text-base",children:f.url}),l.jsx("p",{className:"text-wrap text-sm font-normal text-muted-foreground",children:f.typebot})]})},f.id)):l.jsx(Y,{variant:"link",children:e("typebot.table.none")})})})}),r&&l.jsxs(l.Fragment,{children:[l.jsx(Hu,{withHandle:!0,className:"border border-black"}),l.jsx(wo,{className:"",children:l.jsx(MQ,{typebotId:r,instance:n,resetTable:d})})]})]})]})}const $N=new Cr,DQ=async(e,t)=>(await $N.getInstance().get(`/webhook/find/${e}`,{headers:{apikey:t}})).data,AQ=async(e,t,n)=>(await $N.getInstance().post(`/webhook/set/${e}`,n,{headers:{apikey:t}})).data,FQ=k.object({enabled:k.boolean(),url:k.string().url("Invalid URL format"),events:k.array(k.string()),webhookBase64:k.boolean(),webhookByEvents:k.boolean()});function LQ(){const{t:e}=We(),{instance:t}=ut(),[n,r]=m.useState(!1),o=At({resolver:Ft(FQ),defaultValues:{enabled:!1,url:"",events:[],webhookBase64:!1,webhookByEvents:!1}});m.useEffect(()=>{(async()=>{if(t){r(!0);try{const c=await DQ(t.name,t.token);o.reset(c)}catch(c){console.error("Error:",c)}finally{r(!1)}}})()},[t,o]);const s=async i=>{var c,u,d;if(t){r(!0);try{const f={enabled:i.enabled,url:i.url,events:i.events,webhookBase64:i.webhookBase64,webhookByEvents:i.webhookByEvents};await AQ(t.name,t.token,f),se.success(e("webhook.toast.success"))}catch(f){console.error(e("webhook.toast.error"),f),se.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 l.jsx(l.Fragment,{children:l.jsx(Tr,{...o,children:l.jsx("form",{onSubmit:o.handleSubmit(s),className:"w-full space-y-6",children:l.jsxs("div",{children:[l.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("webhook.title")}),l.jsx(Xs,{className:"my-4"}),l.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[l.jsx(Ce,{name:"enabled",label:e("webhook.form.enabled.label"),className:"w-full justify-between",helper:e("webhook.form.enabled.description")}),l.jsx(L,{name:"url",label:"URL",children:l.jsx(B,{})}),l.jsx(Ce,{name:"webhookByEvents",label:e("webhook.form.webhookByEvents.label"),className:"w-full justify-between",helper:e("webhook.form.webhookByEvents.description")}),l.jsx(Ce,{name:"webhookBase64",label:e("webhook.form.webhookBase64.label"),className:"w-full justify-between",helper:e("webhook.form.webhookBase64.description")}),l.jsx(oa,{control:o.control,name:"events",render:({field:i})=>l.jsxs(ns,{className:"flex flex-col",children:[l.jsx(or,{className:"my-2 text-lg",children:e("webhook.form.events.label")}),l.jsx(xo,{children:l.jsx("div",{className:"flex flex-col gap-2 space-y-1 divide-y",children:a.sort((c,u)=>c.localeCompare(u)).map(c=>l.jsxs("div",{className:"flex items-center justify-between gap-3 pt-3",children:[l.jsx(or,{className:he("break-all",i.value.includes(c)?"text-foreground":"text-muted-foreground"),children:c}),l.jsx(_l,{checked:i.value.includes(c),onCheckedChange:u=>{u?i.onChange([...i.value,c]):i.onChange(i.value.filter(d=>d!==c))}})]},c))})})]})})]}),l.jsx("div",{className:"mx-4 flex justify-end pt-6",children:l.jsx(Y,{type:"submit",disabled:n,children:e(n?"webhook.button.saving":"webhook.button.save")})})]})})})})}const BN=new Cr,$Q=async(e,t)=>(await BN.getInstance().get(`/websocket/find/${e}`,{headers:{apikey:t}})).data,BQ=async(e,t,n)=>(await BN.getInstance().post(`/websocket/set/${e}`,n,{headers:{apikey:t}})).data,zQ=k.object({enabled:k.boolean(),events:k.array(k.string())});function UQ(){const{t:e}=We(),{instance:t}=ut(),[n,r]=m.useState(!1),o=At({resolver:Ft(zQ),defaultValues:{enabled:!1,events:[]}});m.useEffect(()=>{(async()=>{if(t){r(!0);try{const c=await $Q(t.name,t.token);o.reset(c)}catch(c){console.error("Erro ao buscar dados do websocket:",c)}finally{r(!1)}}})()},[t,o]);const s=async i=>{var c,u,d;if(t){r(!0);try{const f={enabled:i.enabled,events:i.events};await BQ(t.name,t.token,f),se.success(e("websocket.toast.success"))}catch(f){console.error(e("websocket.toast.error"),f),se.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 l.jsx(l.Fragment,{children:l.jsx(Tr,{...o,children:l.jsx("form",{onSubmit:o.handleSubmit(s),className:"w-full space-y-6",children:l.jsxs("div",{children:[l.jsx("h3",{className:"mb-1 text-lg font-medium",children:e("websocket.title")}),l.jsx(Xs,{className:"my-4"}),l.jsxs("div",{className:"mx-4 space-y-2 divide-y [&>*]:p-4",children:[l.jsx(Ce,{name:"enabled",label:e("websocket.form.enabled.label"),className:"w-full justify-between",helper:e("websocket.form.enabled.description")}),l.jsx(oa,{control:o.control,name:"events",render:({field:i})=>l.jsxs(ns,{className:"flex flex-col",children:[l.jsx(or,{className:"my-2 text-lg",children:e("websocket.form.events.label")}),l.jsx(xo,{children:l.jsx("div",{className:"flex flex-col gap-2 space-y-1 divide-y",children:a.sort((c,u)=>c.localeCompare(u)).map(c=>l.jsxs("div",{className:"flex items-center justify-between gap-3 pt-3",children:[l.jsx(or,{className:he("break-all",i.value.includes(c)?"text-foreground":"text-muted-foreground"),children:c}),l.jsx(_l,{checked:i.value.includes(c),onCheckedChange:u=>{u?i.onChange([...i.value,c]):i.onChange(i.value.filter(d=>d!==c))}})]},c))})})]})})]}),l.jsx("div",{className:"mx-4 flex justify-end pt-6",children:l.jsx(Y,{type:"submit",disabled:n,children:e(n?"websocket.button.saving":"websocket.button.save")})})]})})})})}const VQ=k.object({serverUrl:k.string({required_error:"serverUrl is required"}).url("URL inválida"),apiKey:k.string({required_error:"ApiKey is required"})});function HQ(){const{t:e}=We(),t=Vn(),n=At({resolver:Ft(VQ),defaultValues:{serverUrl:window.location.protocol+"//"+window.location.host,apiKey:""}}),r=async o=>{const s=await lT(o.serverUrl);if(!s||!s.version){cT(),n.setError("serverUrl",{type:"manual",message:e("login.message.invalidServer")});return}if(!await oL(o.serverUrl,o.apiKey)){n.setError("apiKey",{type:"manual",message:e("login.message.invalidCredentials")});return}if(!await rL(o.serverUrl,o.apiKey)){se.error(e("login.message.invalidCredentials"));return}localStorage.setItem("version",s.version),localStorage.setItem("clientName",s.clientName),t("/manager/")};return l.jsxs("div",{className:"flex min-h-screen flex-col",children:[l.jsx("div",{className:"flex items-center justify-center pt-2",children:l.jsx("img",{className:"h-10",src:"/assets/images/evolution-logo.png",alt:"logo"})}),l.jsx("div",{className:"flex flex-1 items-center justify-center p-8",children:l.jsxs(ba,{className:"b-none w-[350px] shadow-none",children:[l.jsxs(xa,{children:[l.jsx(Ec,{className:"text-center",children:e("login.title")}),l.jsx(rR,{className:"text-center",children:e("login.description")})]}),l.jsx(Tr,{...n,children:l.jsxs("form",{onSubmit:n.handleSubmit(r),children:[l.jsx(wa,{children:l.jsxs("div",{className:"grid w-full items-center gap-4",children:[l.jsx(L,{required:!0,name:"serverUrl",label:e("login.form.serverUrl"),children:l.jsx(B,{})}),l.jsx(L,{required:!0,name:"apiKey",label:e("login.form.apiKey"),children:l.jsx(B,{type:"password"})})]})}),l.jsx(xg,{className:"flex justify-center",children:l.jsx(Y,{className:"w-full",type:"submit",children:e("login.button.login")})})]})})]})}),l.jsx(db,{})]})}const ss=new Cr,zN=async(e,t)=>(await ss.getInstance().get(`/generic/find/${e}`,{headers:{apikey:t}})).data,WQ=async(e,t,n)=>(await ss.getInstance().get(`/generic/fetch/${n}/${e}`,{headers:{apikey:t}})).data,GQ=async(e,t,n)=>(await ss.getInstance().post(`/generic/create/${e}`,n,{headers:{apikey:t}})).data,qQ=async(e,t,n,r)=>(await ss.getInstance().put(`/generic/update/${n}/${e}`,r,{headers:{apikey:t}})).data,KQ=async(e,t,n)=>(await ss.getInstance().delete(`/generic/delete/${n}/${e}`,{headers:{apikey:t}})).data,JQ=async(e,t)=>(await ss.getInstance().get(`/generic/fetchSettings/${e}`,{headers:{apikey:t}})).data,ZQ=async(e,t,n)=>(await ss.getInstance().post(`/generic/settings/${e}`,n,{headers:{apikey:t}})).data,QQ=async(e,t,n)=>(await ss.getInstance().get(`/generic/fetchSessions/${n}/${e}`,{headers:{apikey:t}})).data,YQ=async(e,t,n,r)=>(await ss.getInstance().post(`/generic/changeStatus/${e}`,{remoteJid:n,status:r},{headers:{apikey:t}})).data,XQ=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()}),A1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const o=await JQ(e.name,r);t(o);const s=await zN(e.name,r);n(s)}else console.error("Token not found.")}catch(r){console.error("Error:",r)}};function eY(){const{t:e}=We(),{instance:t}=ut(),[n,r]=m.useState(!1),[o,s]=m.useState(),[a,i]=m.useState([]),c=At({resolver:Ft(XQ),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&&A1(t,s,i)},[t,n]),m.useEffect(()=>{o&&c.reset({expire:o!=null&&o.expire?o.expire.toString():"0",keywordFinish:o.keywordFinish,delayMessage:o.delayMessage?o.delayMessage.toString():"0",unknownMessage:o.unknownMessage,listeningFromMe:o.listeningFromMe,stopBotFromMe:o.stopBotFromMe,keepOpen:o.keepOpen,debounceTime:o.debounceTime?o.debounceTime.toString():"0",ignoreJids:o.ignoreJids,botIdFallback:o.botIdFallback})},[o]);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 ZQ(t.name,t.token,g),se.success(e("genericBot.toast.defaultSettings.success"))}catch(g){console.error("Error:",g),se.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(){A1(t,s,i)}return l.jsxs(Dt,{open:n,onOpenChange:r,children:[l.jsx(Wt,{asChild:!0,children:l.jsxs(Y,{variant:"secondary",size:"sm",children:[l.jsx(pl,{size:16,className:"mr-1"}),l.jsx("span",{className:"hidden sm:inline",children:e("genericBot.defaultSettings")})]})}),l.jsxs(It,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:d,children:[l.jsx(Pt,{children:l.jsx(Xt,{children:e("genericBot.defaultSettings")})}),l.jsx(Jr,{...c,children:l.jsxs("form",{className:"w-full space-y-6",onSubmit:c.handleSubmit(u),children:[l.jsx("div",{children:l.jsxs("div",{className:"space-y-4",children:[l.jsx(at,{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})))??[]}),l.jsx(L,{name:"expire",label:e("genericBot.form.expire.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"keywordFinish",label:e("genericBot.form.keywordFinish.label"),children:l.jsx(B,{})}),l.jsx(L,{name:"delayMessage",label:e("genericBot.form.delayMessage.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"unknownMessage",label:e("genericBot.form.unknownMessage.label"),children:l.jsx(B,{})}),l.jsx(Ce,{name:"listeningFromMe",label:e("genericBot.form.listeningFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"stopBotFromMe",label:e("genericBot.form.stopBotFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"keepOpen",label:e("genericBot.form.keepOpen.label"),reverse:!0}),l.jsx(L,{name:"debounceTime",label:e("genericBot.form.debounceTime.label"),children:l.jsx(B,{type:"number"})}),l.jsx(Uu,{name:"ignoreJids",label:e("genericBot.form.ignoreJids.label"),placeholder:e("genericBot.form.ignoreJids.placeholder")})]})}),l.jsx(gn,{children:l.jsx(Y,{type:"submit",children:e("genericBot.button.save")})})]})})]})]})}const tY=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 nY({resetTable:e}){const{t}=We(),{instance:n}=ut(),[r,o]=m.useState(!1),[s,a]=m.useState(!1),i=At({resolver:Ft(tY),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");o(!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 GQ(n.name,n.token,g),se.success(t("genericBot.toast.success.create")),a(!1),u(),e()}catch(g){console.error("Error:",g),se.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{o(!1)}};function u(){i.reset()}const d=i.watch("triggerType");return l.jsxs(Dt,{open:s,onOpenChange:a,children:[l.jsx(Wt,{asChild:!0,children:l.jsxs(Y,{size:"sm",children:[l.jsx(gl,{size:16,className:"mr-1"}),l.jsx("span",{className:"hidden sm:inline",children:t("genericBot.button.create")})]})}),l.jsxs(It,{className:"overflow-y-auto sm:max-h-[600px] sm:max-w-[740px]",onCloseAutoFocus:u,children:[l.jsx(Pt,{children:l.jsx(Xt,{children:t("genericBot.form.title")})}),l.jsx(Jr,{...i,children:l.jsxs("form",{onSubmit:i.handleSubmit(c),className:"w-full space-y-6",children:[l.jsx("div",{children:l.jsxs("div",{className:"space-y-4",children:[l.jsx(Ce,{name:"enabled",label:t("genericBot.form.enabled.label"),reverse:!0}),l.jsx(L,{name:"description",label:t("genericBot.form.description.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:t("genericBot.form.genericBotSettings.label")}),l.jsx(rt,{})]}),l.jsx(L,{name:"apiUrl",label:t("genericBot.form.apiUrl.label"),required:!0,children:l.jsx(B,{})}),l.jsx(L,{name:"apiKey",label:t("genericBot.form.apiKey.label"),children:l.jsx(B,{type:"password"})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:t("genericBot.form.triggerSettings.label")}),l.jsx(rt,{})]}),l.jsx(at,{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"&&l.jsxs(l.Fragment,{children:[l.jsx(at,{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}),l.jsx(L,{name:"triggerValue",label:t("genericBot.form.triggerValue.label"),required:!0,children:l.jsx(B,{})})]}),d==="advanced"&&l.jsx(L,{name:"triggerValue",label:t("genericBot.form.triggerConditions.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:t("genericBot.form.generalSettings.label")}),l.jsx(rt,{})]}),l.jsx(L,{name:"expire",label:t("genericBot.form.expire.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"keywordFinish",label:t("genericBot.form.keywordFinish.label"),children:l.jsx(B,{})}),l.jsx(L,{name:"delayMessage",label:t("genericBot.form.delayMessage.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"unknownMessage",label:t("genericBot.form.unknownMessage.label"),children:l.jsx(B,{})}),l.jsx(Ce,{name:"listeningFromMe",label:t("genericBot.form.listeningFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"stopBotFromMe",label:t("genericBot.form.stopBotFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"keepOpen",label:t("genericBot.form.keepOpen.label"),reverse:!0}),l.jsx(L,{name:"debounceTime",label:t("genericBot.form.debounceTime.label"),children:l.jsx(B,{type:"number"})})]})}),l.jsx(gn,{children:l.jsx(Y,{disabled:r,type:"submit",children:t("genericBot.button.save")})})]})})]})]})}const F1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const o=await QQ(e.name,r,n);t(o)}else console.error("Token not found.")}catch(r){console.error("Errors:",r)}};function UN({genericBotId:e}){var h,v;const{t}=We(),{instance:n}=ut(),[r,o]=m.useState([]),[s,a]=m.useState([]),[i,c]=m.useState(!1);m.useEffect(()=>{i&&F1(n,a,e)},[n,e,i]);function u(){F1(n,a,e)}const d=async(g,b)=>{var y,x,w;try{if(!n)return;await YQ(n.name,n.token,g,b),se.success(t("genericBot.toast.success.status")),u()}catch(S){console.error("Error:",S),se.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:()=>l.jsx("div",{className:"text-center",children:t("genericBot.sessions.table.remoteJid")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("remoteJid")})},{accessorKey:"pushName",header:()=>l.jsx("div",{className:"text-center",children:t("genericBot.sessions.table.pushName")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("pushName")})},{accessorKey:"sessionId",header:()=>l.jsx("div",{className:"text-center",children:t("genericBot.sessions.table.sessionId")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("sessionId")})},{accessorKey:"status",header:()=>l.jsx("div",{className:"text-center",children:t("genericBot.sessions.table.status")}),cell:({row:g})=>l.jsx("div",{children:g.getValue("status")})},{id:"actions",enableHiding:!1,cell:({row:g})=>{const b=g.original;return l.jsxs(ea,{children:[l.jsx(ta,{asChild:!0,children:l.jsxs(Y,{variant:"ghost",className:"h-8 w-8 p-0",children:[l.jsx("span",{className:"sr-only",children:t("genericBot.sessions.table.actions.title")}),l.jsx(Ou,{className:"h-4 w-4"})]})}),l.jsxs(Co,{align:"end",children:[l.jsx(vl,{children:t("genericBot.sessions.table.actions.title")}),l.jsx(Za,{}),b.status!=="opened"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"opened"),children:[l.jsx(ng,{className:"mr-2 h-4 w-4"}),t("genericBot.sessions.table.actions.open")]}),b.status!=="paused"&&b.status!=="closed"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"paused"),children:[l.jsx(tg,{className:"mr-2 h-4 w-4"}),t("genericBot.sessions.table.actions.pause")]}),b.status!=="closed"&&l.jsxs(ft,{onClick:()=>d(b.remoteJid,"closed"),children:[l.jsx(Qp,{className:"mr-2 h-4 w-4"}),t("genericBot.sessions.table.actions.close")]}),l.jsxs(ft,{onClick:()=>d(b.remoteJid,"delete"),children:[l.jsx(Yp,{className:"mr-2 h-4 w-4"}),t("genericBot.sessions.table.actions.delete")]})]})]})}}],p=Qu({data:s,columns:f,onSortingChange:o,getCoreRowModel:qu(),getPaginationRowModel:Ju(),getSortedRowModel:Zu(),getFilteredRowModel:Ku(),state:{sorting:r}});return l.jsxs(Dt,{open:i,onOpenChange:c,children:[l.jsx(Wt,{asChild:!0,children:l.jsxs(Y,{variant:"secondary",size:"sm",children:[l.jsx(Xp,{size:16,className:"mr-1"}),l.jsx("span",{className:"hidden sm:inline",children:t("genericBot.sessions.label")})]})}),l.jsxs(It,{className:"overflow-y-auto sm:max-w-[950px]",onCloseAutoFocus:u,children:[l.jsx(Pt,{children:l.jsx(Xt,{children:t("genericBot.sessions.label")})}),l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center justify-between gap-6 p-5",children:[l.jsx(B,{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)}}),l.jsx(Y,{variant:"outline",onClick:u,size:"icon",children:l.jsx(rg,{})})]}),l.jsxs(jl,{children:[l.jsx(Rl,{children:p.getHeaderGroups().map(g=>l.jsx(Sn,{children:g.headers.map(b=>l.jsx(Pl,{children:b.isPlaceholder?null:So(b.column.columnDef.header,b.getContext())},b.id))},g.id))}),l.jsx(Il,{children:(v=p.getRowModel().rows)!=null&&v.length?p.getRowModel().rows.map(g=>l.jsx(Sn,{"data-state":g.getIsSelected()&&"selected",children:g.getVisibleCells().map(b=>l.jsx(Gr,{children:So(b.column.columnDef.cell,b.getContext())},b.id))},g.id)):l.jsx(Sn,{children:l.jsx(Gr,{colSpan:f.length,className:"h-24 text-center",children:t("genericBot.sessions.table.none")})})})]})]})]})]})}const rY=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 oY({genericBotId:e,instance:t,resetTable:n}){const{t:r}=We(),[,o]=m.useState(""),[s,a]=m.useState(!0),[i,c]=m.useState(!1),u=Vn(),d=At({resolver:Ft(rY),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){o(b);const y=await WQ(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 qQ(t.name,w,e,S),se.success(r("genericBot.toast.success.update"))}else console.error("Token not found")}catch(w){console.error("Error:",w),se.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 KQ(t.name,g,e),se.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 l.jsxs(l.Fragment,{children:[s&&l.jsx(Wr,{}),!s&&l.jsx(Tr,{...d,children:l.jsxs("form",{onSubmit:d.handleSubmit(f),className:"w-full space-y-6 pl-4 pr-2",children:[l.jsxs("div",{className:"space-y-6",children:[l.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[l.jsxs("h3",{className:"mb-4 text-lg font-medium",children:["GenericBot: ",h]}),l.jsx(Ce,{name:"enabled",className:"flex items-center gap-3"})]}),l.jsxs("div",{className:"space-y-4",children:[l.jsx(L,{name:"description",label:r("genericBot.form.description.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("genericBot.form.genericBotSettings.label")}),l.jsx(rt,{})]}),l.jsx(L,{name:"apiUrl",label:r("genericBot.form.apiUrl.label"),required:!0,children:l.jsx(B,{})}),l.jsx(L,{name:"apiKey",label:r("genericBot.form.apiKey.label"),children:l.jsx(B,{type:"password"})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("genericBot.form.triggerSettings.label")}),l.jsx(rt,{})]}),l.jsx(at,{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"}],required:!0}),v==="keyword"&&l.jsxs(l.Fragment,{children:[l.jsx(at,{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"}],required:!0}),l.jsx(L,{name:"triggerValue",label:r("genericBot.form.triggerValue.label"),required:!0,children:l.jsx(B,{})})]}),v==="advanced"&&l.jsx(L,{name:"triggerValue",label:r("genericBot.form.triggerConditions.label"),required:!0,children:l.jsx(B,{})}),l.jsxs("div",{className:"flex flex-col",children:[l.jsx("h3",{className:"my-4 text-lg font-medium",children:r("genericBot.form.generalSettings.label")}),l.jsx(rt,{})]}),l.jsx(L,{name:"expire",label:r("genericBot.form.expire.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"keywordFinish",label:r("genericBot.form.keywordFinish.label"),required:!0,children:l.jsx(B,{})}),l.jsx(L,{name:"delayMessage",label:r("genericBot.form.delayMessage.label"),children:l.jsx(B,{type:"number"})}),l.jsx(L,{name:"unknownMessage",label:r("genericBot.form.unknownMessage.label"),children:l.jsx(B,{})}),l.jsx(Ce,{name:"listeningFromMe",label:r("genericBot.form.listeningFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"stopBotFromMe",label:r("genericBot.form.stopBotFromMe.label"),reverse:!0}),l.jsx(Ce,{name:"keepOpen",label:r("genericBot.form.keepOpen.label"),reverse:!0}),l.jsx(L,{name:"debounceTime",label:r("genericBot.form.debounceTime.label"),children:l.jsx(B,{type:"number"})})]})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx(UN,{genericBotId:e}),l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsxs(Dt,{open:i,onOpenChange:c,children:[l.jsx(Wt,{asChild:!0,children:l.jsx(Y,{variant:"destructive",size:"sm",children:r("genericBot.button.delete")})}),l.jsx(It,{children:l.jsxs(Pt,{children:[l.jsx(Xt,{children:r("modal.delete.title")}),l.jsx(yl,{children:r("modal.delete.messageSingle")}),l.jsxs(gn,{children:[l.jsx(Y,{size:"sm",variant:"outline",onClick:()=>c(!1),children:r("button.cancel")}),l.jsx(Y,{variant:"destructive",onClick:p,children:r("button.delete")})]})]})})]}),l.jsx(Y,{type:"submit",children:r("genericBot.button.update")})]})]})]})})]})}const L1=async(e,t,n)=>{try{const r=localStorage.getItem("token");if(r&&e&&e.name){const o=await zN(e.name,r);t(o)}else console.error("Token not found");n(!1)}catch(r){console.error("Error:",r),n(!1)}};function $1(){const{t:e}=We(),t=Wu("(min-width: 768px)"),{instance:n}=ut(),{genericBotId:r}=Ys(),[o,s]=m.useState(!0),[a,i]=m.useState([]),c=Vn();m.useEffect(()=>{n&&L1(n,i,s)},[n]);const u=f=>{n&&c(`/manager/instance/${n.id}/generic/${f}`)},d=()=>{L1(n,i,s)};return l.jsxs("main",{className:"pt-5",children:[l.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[l.jsx("h3",{className:"text-lg font-medium",children:e("genericBot.title")}),l.jsxs("div",{className:"flex items-center justify-end gap-2",children:[l.jsx(UN,{}),l.jsx(eY,{}),l.jsx(nY,{resetTable:d})]})]}),l.jsx(rt,{className:"my-4"}),l.jsxs(Vu,{direction:t?"horizontal":"vertical",children:[l.jsx(wo,{defaultSize:35,className:"pr-4",children:l.jsx("div",{className:"flex flex-col gap-3",children:o?l.jsx(Wr,{}):l.jsx(l.Fragment,{children:a&&a.length>0&&Array.isArray(a)?a.map(f=>l.jsx(Y,{className:"flex h-auto flex-col items-start justify-start",onClick:()=>u(`${f.id}`),variant:r===f.id?"secondary":"outline",children:l.jsx("h4",{className:"text-base",children:f.description||f.id})},f.id)):l.jsx(Y,{variant:"link",children:e("genericBot.table.none")})})})}),r&&l.jsxs(l.Fragment,{children:[l.jsx(Hu,{withHandle:!0,className:"border border-border"}),l.jsx(wo,{className:"",children:l.jsx(oY,{genericBotId:r,instance:n,resetTable:d})})]})]})]})}const sY=t2([{path:"/manager/login",element:l.jsx(I2,{children:l.jsx(HQ,{})})},{path:"/manager/",element:l.jsx(qt,{children:l.jsx(Gz,{children:l.jsx(pK,{})})})},{path:"/manager/instance/:instanceId/dashboard",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(NJ,{})})})},{path:"/manager/instance/:instanceId/chat",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(b1,{})})})},{path:"/manager/instance/:instanceId/chat/:remoteJid",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(b1,{})})})},{path:"/manager/instance/:instanceId/settings",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(mQ,{})})})},{path:"/manager/instance/:instanceId/openai",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(P1,{})})})},{path:"/manager/instance/:instanceId/openai/:botId",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(P1,{})})})},{path:"/manager/instance/:instanceId/webhook",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(LQ,{})})})},{path:"/manager/instance/:instanceId/websocket",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(UQ,{})})})},{path:"/manager/instance/:instanceId/rabbitmq",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(gQ,{})})})},{path:"/manager/instance/:instanceId/sqs",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(xQ,{})})})},{path:"/manager/instance/:instanceId/chatwoot",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(eJ,{})})})},{path:"/manager/instance/:instanceId/typebot",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(D1,{})})})},{path:"/manager/instance/:instanceId/typebot/:typebotId",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(D1,{})})})},{path:"/manager/instance/:instanceId/dify",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(_1,{})})})},{path:"/manager/instance/:instanceId/dify/:difyId",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(_1,{})})})},{path:"/manager/instance/:instanceId/generic",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx($1,{})})})},{path:"/manager/instance/:instanceId/generic/:genericBotId",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx($1,{})})})},{path:"/manager/instance/:instanceId/proxy",element:l.jsx(qt,{children:l.jsx(nn,{children:l.jsx(uQ,{})})})}]),aY={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 mp{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||aY,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 o=this.observers[r].get(n)||0;this.observers[r].set(n,o+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),o=1;o{let[i,c]=a;for(let u=0;u{let[i,c]=a;for(let u=0;u{let e,t;const n=new Promise((r,o)=>{e=r,t=o});return n.resolve=e,n.reject=t,n},B1=e=>e==null?"":""+e,iY=(e,t,n)=>{e.forEach(r=>{t[r]&&(n[r]=t[r])})},lY=/###/g,z1=e=>e&&e.indexOf("###")>-1?e.replace(lY,"."):e,U1=e=>!e||typeof e=="string",Ic=(e,t,n)=>{const r=typeof t!="string"?t:t.split(".");let o=0;for(;o{const{obj:r,k:o}=Ic(e,t,Object);if(r!==void 0||t.length===1){r[o]=n;return}let s=t[t.length-1],a=t.slice(0,t.length-1),i=Ic(e,a,Object);for(;i.obj===void 0&&a.length;)s=`${a[a.length-1]}.${s}`,a=a.slice(0,a.length-1),i=Ic(e,a,Object),i&&i.obj&&typeof i.obj[`${i.k}.${s}`]<"u"&&(i.obj=void 0);i.obj[`${i.k}.${s}`]=n},cY=(e,t,n,r)=>{const{obj:o,k:s}=Ic(e,t,Object);o[s]=o[s]||[],o[s].push(n)},vp=(e,t)=>{const{obj:n,k:r}=Ic(e,t);if(n)return n[r]},uY=(e,t,n)=>{const r=vp(e,n);return r!==void 0?r:vp(t,n)},VN=(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]):VN(e[r],t[r],n):e[r]=t[r]);return e},fi=e=>e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&");var dY={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};const fY=e=>typeof e=="string"?e.replace(/[&<>"'\/]/g,t=>dY[t]):e;class pY{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 gY=[" ",",","?","!",";"],hY=new pY(20),mY=(e,t,n)=>{t=t||"",n=n||"";const r=gY.filter(a=>t.indexOf(a)<0&&n.indexOf(a)<0);if(r.length===0)return!0;const o=hY.getRegExp(`(${r.map(a=>a==="?"?"\\?":a).join("|")})`);let s=!o.test(e);if(!s){const a=e.indexOf(n);a>0&&!o.test(e.substring(0,a))&&(s=!0)}return s},sy=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 o=e;for(let s=0;s-1&&ce&&e.indexOf("_")>0?e.replace("_","-"):e;class H1 extends Wg{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 o=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};const s=o.keySeparator!==void 0?o.keySeparator:this.options.keySeparator,a=o.ignoreJSONStructure!==void 0?o.ignoreJSONStructure:this.options.ignoreJSONStructure;let i;t.indexOf(".")>-1?i=t.split("."):(i=[t,n],r&&(Array.isArray(r)?i.push(...r):typeof r=="string"&&s?i.push(...r.split(s)):i.push(r)));const c=vp(this.data,i);return!c&&!n&&!r&&t.indexOf(".")>-1&&(t=i[0],n=i[1],r=i.slice(2).join(".")),c||!a||typeof r!="string"?c:sy(this.data&&this.data[t]&&this.data[t][n],r,s)}addResource(t,n,r,o){let s=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{silent:!1};const a=s.keySeparator!==void 0?s.keySeparator:this.options.keySeparator;let i=[t,n];r&&(i=i.concat(a?r.split(a):r)),t.indexOf(".")>-1&&(i=t.split("."),o=n,n=i[1]),this.addNamespaces(n),V1(this.data,i,o),s.silent||this.emit("added",t,n,r,o)}addResources(t,n,r){let o=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{silent:!1};for(const s in r)(typeof r[s]=="string"||Array.isArray(r[s]))&&this.addResource(t,n,s,r[s],{silent:!0});o.silent||this.emit("added",t,n,r)}addResourceBundle(t,n,r,o,s){let a=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{silent:!1,skipCopy:!1},i=[t,n];t.indexOf(".")>-1&&(i=t.split("."),o=r,r=n,n=i[1]),this.addNamespaces(n);let c=vp(this.data,i)||{};a.skipCopy||(r=JSON.parse(JSON.stringify(r))),o?VN(c,r,s):c={...c,...r},V1(this.data,i,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(o=>n[o]&&Object.keys(n[o]).length>0)}toJSON(){return this.data}}var HN={processors:{},addPostProcessor(e){this.processors[e.name]=e},handle(e,t,n,r,o){return e.forEach(s=>{this.processors[s]&&(t=this.processors[s].process(t,n,r,o))}),t}};const W1={};class bp extends Wg{constructor(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),iY(["resourceStore","languageUtils","pluralResolver","interpolator","backendConnector","i18nFormat","utils"],t,this),this.options=n,this.options.keySeparator===void 0&&(this.options.keySeparator="."),this.logger=fo.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 o=n.keySeparator!==void 0?n.keySeparator:this.options.keySeparator;let s=n.ns||this.options.defaultNS||[];const a=r&&t.indexOf(r)>-1,i=!this.options.userDefinedKeySeparator&&!n.keySeparator&&!this.options.userDefinedNsSeparator&&!n.nsSeparator&&!mY(t,r,o);if(a&&!i){const c=t.match(this.interpolator.nestingRegexp);if(c&&c.length>0)return{key:t,namespaces:s};const u=t.split(r);(r!==o||r===o&&this.options.ns.indexOf(u[0])>-1)&&(s=u.shift()),t=u.join(o)}return typeof s=="string"&&(s=[s]),{key:t,namespaces:s}}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 o=n.returnDetails!==void 0?n.returnDetails:this.options.returnDetails,s=n.keySeparator!==void 0?n.keySeparator:this.options.keySeparator,{key:a,namespaces:i}=this.extractFromKey(t[t.length-1],n),c=i[i.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 o?{res:`${c}${S}${a}`,usedKey:a,exactUsedKey:a,usedLng:u,usedNS:c,usedParams:this.getUsedParamsDetails(n)}:`${c}${S}${a}`}return o?{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:i}):`key '${a} (${this.language})' returned an object instead of string.`;return o?(f.res=S,f.usedParams=this.getUsedParamsDetails(n),f):S}if(s){const S=Array.isArray(p),E=S?[]:{},C=S?v:h;for(const T in p)if(Object.prototype.hasOwnProperty.call(p,T)){const _=`${C}${s}${T}`;E[T]=this.translate(_,{...n,joinArrays:!1,ns:i}),E[T]===_&&(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=bp.hasDefaultValue(n),_=C?this.pluralResolver.getSuffix(u,n.count,n):"",I=n.ordinal&&C?this.pluralResolver.getSuffix(u,n.count,{ordinal:!1}):"",N=C&&!n.ordinal&&n.count===0&&this.pluralResolver.shouldUseIntlApi(),V=N&&n[`defaultValue${this.options.pluralSeparator}zero`]||n[`defaultValue${_}`]||n[`defaultValue${I}`]||n.defaultValue;!this.isValidLookup(p)&&T&&(S=!0,p=V),this.isValidLookup(p)||(E=!0,p=a);const J=(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),s){const A=this.resolve(a,{...n,keySeparator:!1});A&&A.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 Q=this.languageUtils.getFallbackCodes(this.options.fallbackLng,n.lng||this.language);if(this.options.saveMissingTo==="fallback"&&Q&&Q[0])for(let A=0;A{const ue=T&&Z!==p?Z:J;this.options.missingKeyHandler?this.options.missingKeyHandler(A,c,D,ue,H,n):this.backendConnector&&this.backendConnector.saveMissing&&this.backendConnector.saveMissing(A,c,D,ue,H,n),this.emit("missingKey",A,c,D,p)};this.options.saveMissing&&(this.options.saveMissingPlurals&&C?K.forEach(A=>{const D=this.pluralResolver.getSuffixes(A,n);N&&n[`defaultValue${this.options.pluralSeparator}zero`]&&D.indexOf(`${this.options.pluralSeparator}zero`)<0&&D.push(`${this.options.pluralSeparator}zero`),D.forEach(Z=>{G([A],a+Z,n[`defaultValue${Z}`]||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 o?(f.res=p,f.usedParams=this.getUsedParamsDetails(n),f):p}extendTranslation(t,n,r,o,s){var a=this;if(this.i18nFormat&&this.i18nFormat.parse)t=this.i18nFormat.parse(t,{...this.options.interpolation.defaultVariables,...r},r.lng||this.language||o.usedLng,o.usedNS,o.usedKey,{resolved:o});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||o.usedLng,r),u){const p=t.match(this.interpolator.nestingRegexp),h=p&&p.length;d1&&arguments[1]!==void 0?arguments[1]:{},r,o,s,a,i;return typeof t=="string"&&(t=[t]),t.forEach(c=>{if(this.isValidLookup(r))return;const u=this.extractFromKey(c,n),d=u.key;o=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)||(i=b,!W1[`${g[0]}-${b}`]&&this.utils&&this.utils.hasLoadedNamespace&&!this.utils.hasLoadedNamespace(i)&&(W1[`${g[0]}-${b}`]=!0,this.logger.warn(`key "${o}" for languages "${g.join(", ")}" won't get resolved as namespace "${i}" 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)||(s=w,r=this.getResource(y,b,w,n))}))})}),{res:r,usedKey:o,exactUsedKey:s,usedLng:a,usedNS:i}}isValidLookup(t){return t!==void 0&&!(!this.options.returnNull&&t===null)&&!(!this.options.returnEmptyString&&t==="")}getResource(t,n,r){let o=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};return this.i18nFormat&&this.i18nFormat.getResource?this.i18nFormat.getResource(t,n,r,o):this.resourceStore.getResource(t,n,r,o)}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 o=r?t.replace:t;if(r&&typeof t.count<"u"&&(o.count=t.count),this.options.interpolation.defaultVariables&&(o={...this.options.interpolation.defaultVariables,...o}),!r){o={...o};for(const s of n)delete o[s]}return o}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 pm=e=>e.charAt(0).toUpperCase()+e.slice(1);class G1{constructor(t){this.options=t,this.supportedLngs=this.options.supportedLngs||!1,this.logger=fo.create("languageUtils")}getScriptPartFromCode(t){if(t=yp(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=yp(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(o=>o.toLowerCase()):r.length===2?(r[0]=r[0].toLowerCase(),r[1]=r[1].toUpperCase(),n.indexOf(r[1].toLowerCase())>-1&&(r[1]=pm(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]=pm(r[1].toLowerCase())),n.indexOf(r[2].toLowerCase())>-1&&(r[2]=pm(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 o=this.formatLanguageCode(r);(!this.options.supportedLngs||this.isSupportedCode(o))&&(n=o)}),!n&&this.options.supportedLngs&&t.forEach(r=>{if(n)return;const o=this.getLanguagePartFromCode(r);if(this.isSupportedCode(o))return n=o;n=this.options.supportedLngs.find(s=>{if(s===o)return s;if(!(s.indexOf("-")<0&&o.indexOf("-")<0)&&(s.indexOf("-")>0&&o.indexOf("-")<0&&s.substring(0,s.indexOf("-"))===o||s.indexOf(o)===0&&o.length>1))return s})}),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),o=[],s=a=>{a&&(this.isSupportedCode(a)?o.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"&&s(this.formatLanguageCode(t)),this.options.load!=="languageOnly"&&this.options.load!=="currentOnly"&&s(this.getScriptPartFromCode(t)),this.options.load!=="currentOnly"&&s(this.getLanguagePartFromCode(t))):typeof t=="string"&&s(this.formatLanguageCode(t)),r.forEach(a=>{o.indexOf(a)<0&&s(this.formatLanguageCode(a))}),o}}let vY=[{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}],yY={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"],xY=["v4"],q1={zero:0,one:1,two:2,few:3,many:4,other:5},wY=()=>{const e={};return vY.forEach(t=>{t.lngs.forEach(n=>{e[n]={numbers:t.nr,plurals:yY[t.fc]}})}),e};class SY{constructor(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.languageUtils=t,this.options=n,this.logger=fo.create("pluralResolver"),(!this.options.compatibilityJSON||xY.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=wY(),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=yp(t==="dev"?"en":t),o=n.ordinal?"ordinal":"cardinal",s=JSON.stringify({cleanedCode:r,type:o});if(s in this.pluralRulesCache)return this.pluralRulesCache[s];const a=new Intl.PluralRules(r,{type:o});return this.pluralRulesCache[s]=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(o=>`${n}${o}`)}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((o,s)=>q1[o]-q1[s]).map(o=>`${this.options.prepend}${n.ordinal?`ordinal${this.options.prepend}`:""}${o}`):r.numbers.map(o=>this.getSuffix(t,o,n)):[]}getSuffix(t,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const o=this.getRule(t,r);return o?this.shouldUseIntlApi()?`${this.options.prepend}${r.ordinal?`ordinal${this.options.prepend}`:""}${o.select(n)}`:this.getSuffixRetroCompatible(o,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 o=t.numbers[r];this.options.simplifyPluralSuffix&&t.numbers.length===2&&t.numbers[0]===1&&(o===2?o="plural":o===1&&(o=""));const s=()=>this.options.prepend&&o.toString()?this.options.prepend+o.toString():o.toString();return this.options.compatibilityJSON==="v1"?o===1?"":typeof o=="number"?`_plural_${o.toString()}`:s():this.options.compatibilityJSON==="v2"||this.options.simplifyPluralSuffix&&t.numbers.length===2&&t.numbers[0]===1?s():this.options.prepend&&r.toString()?this.options.prepend+r.toString():r.toString()}shouldUseIntlApi(){return!bY.includes(this.options.compatibilityJSON)}}const K1=function(e,t,n){let r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:".",o=arguments.length>4&&arguments[4]!==void 0?arguments[4]:!0,s=uY(e,t,n);return!s&&o&&typeof n=="string"&&(s=sy(e,n,r),s===void 0&&(s=sy(t,n,r))),s},gm=e=>e.replace(/\$/g,"$$$$");class CY{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.logger=fo.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:o,prefix:s,prefixEscaped:a,suffix:i,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:fY,this.escapeValue=r!==void 0?r:!0,this.useRawValueToEscape=o!==void 0?o:!1,this.prefix=s?fi(s):a||"{{",this.suffix=i?fi(i):c||"}}",this.formatSeparator=u||",",this.unescapePrefix=d?"":f||"-",this.unescapeSuffix=this.unescapePrefix?"":d||"",this.nestingPrefix=p?fi(p):h||fi("$t("),this.nestingSuffix=v?fi(v):g||fi(")"),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,o){let s,a,i;const c=this.options&&this.options.interpolation&&this.options.interpolation.defaultVariables||{},u=h=>{if(h.indexOf(this.formatSeparator)<0){const y=K1(n,c,h,this.options.keySeparator,this.options.ignoreJSONStructure);return this.alwaysFormat?this.format(y,void 0,r,{...o,...n,interpolationkey:h}):y}const v=h.split(this.formatSeparator),g=v.shift().trim(),b=v.join(this.formatSeparator).trim();return this.format(K1(n,c,g,this.options.keySeparator,this.options.ignoreJSONStructure),b,r,{...o,...n,interpolationkey:g})};this.resetRegExp();const d=o&&o.missingInterpolationHandler||this.options.missingInterpolationHandler,f=o&&o.interpolation&&o.interpolation.skipOnVariables!==void 0?o.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables;return[{regex:this.regexpUnescape,safeValue:h=>gm(h)},{regex:this.regexp,safeValue:h=>this.escapeValue?gm(this.escape(h)):gm(h)}].forEach(h=>{for(i=0;s=h.regex.exec(t);){const v=s[1].trim();if(a=u(v),a===void 0)if(typeof d=="function"){const b=d(t,s,o);a=typeof b=="string"?b:""}else if(o&&Object.prototype.hasOwnProperty.call(o,v))a="";else if(f){a=s[0];continue}else this.logger.warn(`missed to pass in variable ${v} for interpolating ${t}`),a="";else typeof a!="string"&&!this.useRawValueToEscape&&(a=B1(a));const g=h.safeValue(a);if(t=t.replace(s[0],g),f?(h.regex.lastIndex+=a.length,h.regex.lastIndex-=s[0].length):h.regex.lastIndex=0,i++,i>=this.maxReplaces)break}}),t}nest(t,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},o,s,a;const i=(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(;o=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(o[0].indexOf(this.formatSeparator)!==-1&&!/{.*}/.test(o[1])){const d=o[1].split(this.formatSeparator).map(f=>f.trim());o[1]=d.shift(),c=d,u=!0}if(s=n(i.call(this,o[1].trim(),a),a),s&&o[0]===t&&typeof s!="string")return s;typeof s!="string"&&(s=B1(s)),s||(this.logger.warn(`missed to resolve ${o[1]} for nesting ${t}`),s=""),u&&(s=c.reduce((d,f)=>this.format(d,f,r.lng,{...r,interpolationkey:o[1].trim()}),s.trim())),t=t.replace(o[0],s),this.regexp.lastIndex=0}return t}}const EY=e=>{let t=e.toLowerCase().trim();const n={};if(e.indexOf("(")>-1){const r=e.split("(");t=r[0].toLowerCase().trim();const o=r[1].substring(0,r[1].length-1);t==="currency"&&o.indexOf(":")<0?n.currency||(n.currency=o.trim()):t==="relativetime"&&o.indexOf(":")<0?n.range||(n.range=o.trim()):o.split(";").forEach(a=>{if(a){const[i,...c]=a.split(":"),u=c.join(":").trim().replace(/^'+|'+$/g,""),d=i.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}},pi=e=>{const t={};return(n,r,o)=>{let s=o;o&&o.interpolationkey&&o.formatParams&&o.formatParams[o.interpolationkey]&&o[o.interpolationkey]&&(s={...s,[o.interpolationkey]:void 0});const a=r+JSON.stringify(s);let i=t[a];return i||(i=e(yp(r),o),t[a]=i),i(n)}};class kY{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.logger=fo.create("formatter"),this.options=t,this.formats={number:pi((n,r)=>{const o=new Intl.NumberFormat(n,{...r});return s=>o.format(s)}),currency:pi((n,r)=>{const o=new Intl.NumberFormat(n,{...r,style:"currency"});return s=>o.format(s)}),datetime:pi((n,r)=>{const o=new Intl.DateTimeFormat(n,{...r});return s=>o.format(s)}),relativetime:pi((n,r)=>{const o=new Intl.RelativeTimeFormat(n,{...r});return s=>o.format(s,r.range||"day")}),list:pi((n,r)=>{const o=new Intl.ListFormat(n,{...r});return s=>o.format(s)})},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()]=pi(n)}format(t,n,r){let o=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};const s=n.split(this.formatSeparator);if(s.length>1&&s[0].indexOf("(")>1&&s[0].indexOf(")")<0&&s.find(i=>i.indexOf(")")>-1)){const i=s.findIndex(c=>c.indexOf(")")>-1);s[0]=[s[0],...s.splice(1,i)].join(this.formatSeparator)}return s.reduce((i,c)=>{const{formatName:u,formatOptions:d}=EY(c);if(this.formats[u]){let f=i;try{const p=o&&o.formatParams&&o.formatParams[o.interpolationkey]||{},h=p.locale||p.lng||o.locale||o.lng||r;f=this.formats[u](i,h,{...d,...o,...p})}catch(p){this.logger.warn(p)}return f}else this.logger.warn(`there was no format function for ${u}`);return i},t)}}const TY=(e,t)=>{e.pending[t]!==void 0&&(delete e.pending[t],e.pendingCount--)};class _Y extends Wg{constructor(t,n,r){let o=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=o,this.logger=fo.create("backendConnector"),this.waitingReads=[],this.maxParallelReads=o.maxParallelReads||10,this.readingCalls=0,this.maxRetries=o.maxRetries>=0?o.maxRetries:5,this.retryTimeout=o.retryTimeout>=1?o.retryTimeout:350,this.state={},this.queue=[],this.backend&&this.backend.init&&this.backend.init(r,o.backend,o)}queueLoad(t,n,r,o){const s={},a={},i={},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),s[p]===void 0&&(s[p]=!0),c[f]===void 0&&(c[f]=!0)))}),d||(i[u]=!0)}),(Object.keys(s).length||Object.keys(a).length)&&this.queue.push({pending:a,pendingCount:Object.keys(a).length,loaded:{},errors:[],callback:o}),{toLoad:Object.keys(s),pending:Object.keys(a),toLoadLanguages:Object.keys(i),toLoadNamespaces:Object.keys(c)}}loaded(t,n,r){const o=t.split("|"),s=o[0],a=o[1];n&&this.emit("failedLoading",s,a,n),!n&&r&&this.store.addResourceBundle(s,a,r,void 0,void 0,{skipCopy:!0}),this.state[t]=n?-1:2,n&&r&&(this.state[t]=0);const i={};this.queue.forEach(c=>{cY(c.loaded,[s],a),TY(c,t),n&&c.errors.push(n),c.pendingCount===0&&!c.done&&(Object.keys(c.loaded).forEach(u=>{i[u]||(i[u]={});const d=c.loaded[u];d.length&&d.forEach(f=>{i[u][f]===void 0&&(i[u][f]=!0)})}),c.done=!0,c.errors.length?c.callback(c.errors):c.callback())}),this.emit("loaded",i),this.queue=this.queue.filter(c=>!c.done)}read(t,n,r){let o=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0,s=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:o,wait:s,callback:a});return}this.readingCalls++;const i=(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&&o{this.read.call(this,t,n,r,o+1,s*2,a)},s);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=>i(null,d)).catch(i):i(null,u)}catch(u){i(u)}return}return c(t,n,i)}prepareLoading(t,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},o=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."),o&&o();typeof t=="string"&&(t=this.languageUtils.toResolveHierarchy(t)),typeof n=="string"&&(n=[n]);const s=this.queueLoad(t,n,r,o);if(!s.toLoad.length)return s.pending.length||o(),null;s.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("|"),o=r[0],s=r[1];this.read(o,s,"read",void 0,void 0,(a,i)=>{a&&this.logger.warn(`${n}loading namespace ${s} for language ${o} failed`,a),!a&&i&&this.logger.log(`${n}loaded namespace ${s} for language ${o}`,i),this.loaded(t,a,i)})}saveMissing(t,n,r,o,s){let a=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{},i=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:s},u=this.backend.create.bind(this.backend);if(u.length<6)try{let d;u.length===5?d=u(t,n,r,o,c):d=u(t,n,r,o),d&&typeof d.then=="function"?d.then(f=>i(null,f)).catch(i):i(null,d)}catch(d){i(d)}else u(t,n,r,o,i,c)}!t||!t[0]||this.store.addResource(t[0],n,r,o)}}}const J1=()=>({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}}),Z1=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),Bd=()=>{},jY=e=>{Object.getOwnPropertyNames(Object.getPrototypeOf(e)).forEach(n=>{typeof e[n]=="function"&&(e[n]=e[n].bind(e))})};class ku extends Wg{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(super(),this.options=Z1(t),this.services={},this.logger=fo,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 o=J1();this.options={...o,...this.options,...Z1(n)},this.options.compatibilityAPI!=="v1"&&(this.options.interpolation={...o.interpolation,...this.options.interpolation}),n.keySeparator!==void 0&&(this.options.userDefinedKeySeparator=n.keySeparator),n.nsSeparator!==void 0&&(this.options.userDefinedNsSeparator=n.nsSeparator);const s=d=>d?typeof d=="function"?new d:d:null;if(!this.options.isClone){this.modules.logger?fo.init(s(this.modules.logger),this.options):fo.init(null,this.options);let d;this.modules.formatter?d=this.modules.formatter:typeof Intl<"u"&&(d=kY);const f=new G1(this.options);this.store=new H1(this.options.resources,this.options);const p=this.services;p.logger=fo,p.resourceStore=this.store,p.languageUtils=f,p.pluralResolver=new SY(f,{prepend:this.options.pluralSeparator,compatibilityJSON:this.options.compatibilityJSON,simplifyPluralSuffix:this.options.simplifyPluralSuffix}),d&&(!this.options.interpolation.format||this.options.interpolation.format===o.interpolation.format)&&(p.formatter=s(d),p.formatter.init(p,this.options),this.options.interpolation.format=p.formatter.format.bind(p.formatter)),p.interpolator=new CY(this.options),p.utils={hasLoadedNamespace:this.hasLoadedNamespace.bind(this)},p.backendConnector=new _Y(s(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=Bd),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=nc(),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]:Bd;const o=typeof t=="string"?t:this.language;if(typeof t=="function"&&(r=t),!this.options.resources||this.options.partialBundledLanguages){if(o&&o.toLowerCase()==="cimode"&&(!this.options.preload||this.options.preload.length===0))return r();const s=[],a=i=>{if(!i||i==="cimode")return;this.services.languageUtils.toResolveHierarchy(i).forEach(u=>{u!=="cimode"&&s.indexOf(u)<0&&s.push(u)})};o?a(o):this.services.languageUtils.getFallbackCodes(this.options.fallbackLng).forEach(c=>a(c)),this.options.preload&&this.options.preload.forEach(i=>a(i)),this.services.backendConnector.load(s,this.options.ns,i=>{!i&&!this.resolvedLanguage&&this.language&&this.setResolvedLanguage(this.language),r(i)})}else r(null)}reloadResources(t,n,r){const o=nc();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=Bd),this.services.backendConnector.reload(t,n,s=>{o.resolve(),r(s)}),o}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"&&HN.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 o=nc();this.emit("languageChanging",t);const s=c=>{this.language=c,this.languages=this.services.languageUtils.toResolveHierarchy(c),this.resolvedLanguage=void 0,this.setResolvedLanguage(c)},a=(c,u)=>{u?(s(u),this.translator.changeLanguage(u),this.isLanguageChangingTo=void 0,this.emit("languageChanged",u),this.logger.log("languageChanged",u)):this.isLanguageChangingTo=void 0,o.resolve(function(){return r.t(...arguments)}),n&&n(c,function(){return r.t(...arguments)})},i=c=>{!t&&!c&&this.services.languageDetector&&(c=[]);const u=typeof c=="string"?c:this.services.languageUtils.getBestMatchFromCodes(c);u&&(this.language||s(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?i(this.services.languageDetector.detect()):!t&&this.services.languageDetector&&this.services.languageDetector.async?this.services.languageDetector.detect.length===0?this.services.languageDetector.detect().then(i):this.services.languageDetector.detect(i):i(t),o}getFixedT(t,n,r){var o=this;const s=function(a,i){let c;if(typeof i!="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,o.t(h,c)};return typeof t=="string"?s.lng=t:s.lngs=t,s.ns=n,s.keyPrefix=r,s}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],o=this.options?this.options.fallbackLng:!1,s=this.languages[this.languages.length-1];if(r.toLowerCase()==="cimode")return!0;const a=(i,c)=>{const u=this.services.backendConnector.state[`${i}|${c}`];return u===-1||u===0||u===2};if(n.precheck){const i=n.precheck(this,a);if(i!==void 0)return i}return!!(this.hasResourceBundle(r,t)||!this.services.backendConnector.backend||this.options.resources&&!this.options.partialBundledLanguages||a(r,t)&&(!o||a(s,t)))}loadNamespaces(t,n){const r=nc();return this.options.ns?(typeof t=="string"&&(t=[t]),t.forEach(o=>{this.options.ns.indexOf(o)<0&&this.options.ns.push(o)}),this.loadResources(o=>{r.resolve(),n&&n(o)}),r):(n&&n(),Promise.resolve())}loadLanguages(t,n){const r=nc();typeof t=="string"&&(t=[t]);const o=this.options.preload||[],s=t.filter(a=>o.indexOf(a)<0&&this.services.languageUtils.isSupportedCode(a));return s.length?(this.options.preload=o.concat(s),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 G1(J1());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 ku(t,n)}cloneInstance(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Bd;const r=t.forkResourceStore;r&&delete t.forkResourceStore;const o={...this.options,...t,isClone:!0},s=new ku(o);return(t.debug!==void 0||t.prefix!==void 0)&&(s.logger=s.logger.clone(t)),["store","services","language"].forEach(i=>{s[i]=this[i]}),s.services={...this.services},s.services.utils={hasLoadedNamespace:s.hasLoadedNamespace.bind(s)},r&&(s.store=new H1(this.store.data,o),s.services.resourceStore=s.store),s.translator=new bp(s.services,o),s.translator.on("*",function(i){for(var c=arguments.length,u=new Array(c>1?c-1:0),d=1;d