tybotflow-widget 0.8.2 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -59671,19 +59671,19 @@ function Oz({ onValidate: g, agentChatResponseColor: A, agentChatResponseBgColor
59671
59671
  /* @__PURE__ */ u.jsx("div", { className: "mt-2 text-xs opacity-70 text-center", children: "* الحقول الإلزامية" })
59672
59672
  ] });
59673
59673
  }
59674
- function Jz({ onValidate: g, agentChatResponseColor: A, agentChatResponseBgColor: I, buttonsBgColor: B, buttonColor: E, chatRoundness: C, panelWidth: Q, inputBackgroundColor: o }) {
59675
- const [w, M] = vA.useState({
59674
+ function Jz({ onValidate: g, agentChatResponseColor: A, agentChatResponseBgColor: I, buttonsBgColor: B, buttonColor: E, chatRoundness: C, panelWidth: Q, inputBackgroundColor: o, formVars: w }) {
59675
+ const [M, D] = vA.useState({
59676
59676
  nomComplet: "",
59677
59677
  numero: "",
59678
- nomMachine: "",
59678
+ nomMachine: w?.Nom_machine || "",
59679
59679
  email: "",
59680
59680
  ville: "",
59681
59681
  typeDeProjet: ""
59682
- }), D = (G, R) => {
59683
- M((U) => ({ ...U, [G]: R }));
59684
- }, t = () => {
59685
- g(w);
59686
- }, s = () => w.nomComplet.trim() !== "" && w.numero.trim() !== "" && w.nomMachine.trim() !== "" && w.ville.trim() !== "", a = {
59682
+ }), t = (R, U) => {
59683
+ D((r) => ({ ...r, [R]: U }));
59684
+ }, s = () => {
59685
+ g(M);
59686
+ }, a = () => M.nomComplet.trim() !== "" && M.numero.trim() !== "" && M.nomMachine.trim() !== "" && M.ville.trim() !== "", G = {
59687
59687
  backgroundColor: bC(I, 50),
59688
59688
  color: A,
59689
59689
  borderRadius: `${C}px`,
@@ -59712,12 +59712,12 @@ function Jz({ onValidate: g, agentChatResponseColor: A, agentChatResponseBgColor
59712
59712
  "input",
59713
59713
  {
59714
59714
  type: "text",
59715
- value: w.nomComplet,
59716
- onChange: (G) => D("nomComplet", G.target.value),
59715
+ value: M.nomComplet,
59716
+ onChange: (R) => t("nomComplet", R.target.value),
59717
59717
  placeholder: "Entrez votre nom complet...",
59718
59718
  className: "w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",
59719
59719
  style: {
59720
- ...a,
59720
+ ...G,
59721
59721
  "--tw-ring-color": B
59722
59722
  }
59723
59723
  }
@@ -59732,12 +59732,12 @@ function Jz({ onValidate: g, agentChatResponseColor: A, agentChatResponseBgColor
59732
59732
  "input",
59733
59733
  {
59734
59734
  type: "tel",
59735
- value: w.numero,
59736
- onChange: (G) => D("numero", G.target.value),
59735
+ value: M.numero,
59736
+ onChange: (R) => t("numero", R.target.value),
59737
59737
  placeholder: "Entrez votre numéro...",
59738
59738
  className: "w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",
59739
59739
  style: {
59740
- ...a,
59740
+ ...G,
59741
59741
  "--tw-ring-color": B
59742
59742
  }
59743
59743
  }
@@ -59752,12 +59752,12 @@ function Jz({ onValidate: g, agentChatResponseColor: A, agentChatResponseBgColor
59752
59752
  "input",
59753
59753
  {
59754
59754
  type: "email",
59755
- value: w.email,
59756
- onChange: (G) => D("email", G.target.value),
59755
+ value: M.email,
59756
+ onChange: (R) => t("email", R.target.value),
59757
59757
  placeholder: "Entrez votre adresse email...",
59758
59758
  className: "w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",
59759
59759
  style: {
59760
- ...a,
59760
+ ...G,
59761
59761
  "--tw-ring-color": B
59762
59762
  }
59763
59763
  }
@@ -59772,12 +59772,12 @@ function Jz({ onValidate: g, agentChatResponseColor: A, agentChatResponseBgColor
59772
59772
  "input",
59773
59773
  {
59774
59774
  type: "text",
59775
- value: w.ville,
59776
- onChange: (G) => D("ville", G.target.value),
59775
+ value: M.ville,
59776
+ onChange: (R) => t("ville", R.target.value),
59777
59777
  placeholder: "Entrez votre ville...",
59778
59778
  className: "w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",
59779
59779
  style: {
59780
- ...a,
59780
+ ...G,
59781
59781
  "--tw-ring-color": B
59782
59782
  }
59783
59783
  }
@@ -59792,12 +59792,12 @@ function Jz({ onValidate: g, agentChatResponseColor: A, agentChatResponseBgColor
59792
59792
  "input",
59793
59793
  {
59794
59794
  type: "text",
59795
- value: w.nomMachine,
59796
- onChange: (G) => D("nomMachine", G.target.value),
59795
+ value: M.nomMachine,
59796
+ onChange: (R) => t("nomMachine", R.target.value),
59797
59797
  placeholder: "Entrez le nom de la machine...",
59798
59798
  className: "w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",
59799
59799
  style: {
59800
- ...a,
59800
+ ...G,
59801
59801
  "--tw-ring-color": B
59802
59802
  }
59803
59803
  }
@@ -59811,11 +59811,11 @@ function Jz({ onValidate: g, agentChatResponseColor: A, agentChatResponseBgColor
59811
59811
  /* @__PURE__ */ u.jsxs(
59812
59812
  "select",
59813
59813
  {
59814
- value: w.typeDeProjet,
59815
- onChange: (G) => D("typeDeProjet", G.target.value),
59814
+ value: M.typeDeProjet,
59815
+ onChange: (R) => t("typeDeProjet", R.target.value),
59816
59816
  className: "w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",
59817
59817
  style: {
59818
- ...a,
59818
+ ...G,
59819
59819
  "--tw-ring-color": B
59820
59820
  },
59821
59821
  children: [
@@ -59834,8 +59834,8 @@ function Jz({ onValidate: g, agentChatResponseColor: A, agentChatResponseBgColor
59834
59834
  /* @__PURE__ */ u.jsxs(
59835
59835
  "button",
59836
59836
  {
59837
- onClick: t,
59838
- disabled: !s(),
59837
+ onClick: s,
59838
+ disabled: !a(),
59839
59839
  className: "w-full px-6 py-3 mt-4 text-sm font-medium rounded-lg transition-colors flex items-center justify-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed",
59840
59840
  style: {
59841
59841
  backgroundColor: B,
@@ -64789,7 +64789,8 @@ const wh = "https://api.tybotflow.com/api/v1", NrA = "https://api.tybotflow.com/
64789
64789
  buttonColor: J,
64790
64790
  chatRoundness: m,
64791
64791
  panelWidth: bA,
64792
- inputBackgroundColor: r
64792
+ inputBackgroundColor: r,
64793
+ formVars: JSON.parse(p.text[0])
64793
64794
  }
64794
64795
  );
64795
64796
  case "auditec-form":
@@ -64960,7 +64961,8 @@ const wh = "https://api.tybotflow.com/api/v1", NrA = "https://api.tybotflow.com/
64960
64961
  buttonColor: J,
64961
64962
  chatRoundness: m,
64962
64963
  panelWidth: bA,
64963
- inputBackgroundColor: r
64964
+ inputBackgroundColor: r,
64965
+ formVars: UA?.items || {}
64964
64966
  }
64965
64967
  );
64966
64968
  case "auditec-form":
package/dist/index.umd.js CHANGED
@@ -547,7 +547,7 @@ end`};A.events.push(["putFont",function(C){(function(Q){var o=Q.font,w=Q.out,M=Q
547
547
  input::placeholder {
548
548
  color: ${A+"80"};
549
549
  }
550
- `}),u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center gap-2 pb-2 border-b",style:{borderColor:B+"40"},children:[u.jsx(Fo,{className:"w-4 h-4",style:{color:A}}),u.jsx("h3",{className:"text-sm font-semibold",children:"Informations personnelles"})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx("label",{className:"block text-sm font-medium",children:"Nom complet *"}),u.jsx("input",{type:"text",value:M.nom,onChange:r=>s("nom",r.target.value),placeholder:"Votre nom et prénom",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...R,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx("label",{className:"block text-sm font-medium",children:"Nom de l'entreprise *"}),u.jsx("input",{type:"text",value:M.entreprise,onChange:r=>s("entreprise",r.target.value),placeholder:"Ex. : ACME SARL",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...R,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx("label",{className:"block text-sm font-medium",children:"Email professionnel *"}),u.jsx("input",{type:"email",value:M.email,onChange:r=>s("email",r.target.value),placeholder:"ex. nom@startup.com",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...R,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx("label",{className:"block text-sm font-medium",children:"Numéro de téléphone *"}),u.jsx("input",{type:"tel",value:M.phone,onChange:r=>s("phone",r.target.value),placeholder:"Inclure l'indicatif international (ex. +212...)",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...R,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx("label",{className:"block text-sm font-medium",children:"Poste *"}),u.jsx("input",{type:"text",value:M.poste,onChange:r=>s("poste",r.target.value),placeholder:"Ex. : CEO, Ingénieur, Étudient ...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...R,"--tw-ring-color":B}})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx("label",{className:"block text-sm font-medium",children:"Secteur d'activité *"}),u.jsx("div",{className:`grid ${t?"grid-cols-1":"grid-cols-2"} gap-2`,children:U.map(r=>u.jsx("button",{onClick:()=>s("secteur",r),className:"px-3 py-2 text-sm rounded-lg transition-colors text-left",style:{backgroundColor:M.secteur===r?w:o||I+"60",color:M.secteur===r?E:A,borderRadius:"10px",border:`1px solid ${B}`},children:r},r))})]})]}),u.jsxs("button",{onClick:a,disabled:!G(),className:"w-full px-6 py-3 mt-4 text-sm font-medium rounded-lg transition-colors flex items-center justify-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed",style:{backgroundColor:B,color:E,borderRadius:`${C}px`},children:[u.jsx(VQ,{className:"w-4 h-4"}),"Valider ma candidature"]})]})}function mW({onValidate:g,agentChatResponseColor:A,agentChatResponseBgColor:I,buttonsBgColor:B,buttonColor:E,chatRoundness:C,panelWidth:Q,inputBackgroundColor:o}){const[w,M]=vA.useState({fullName:"",phone:"",email:"",ville:""}),D=(G,R)=>{M(U=>({...U,[G]:R}))},t=()=>{g(w)},s=()=>w.fullName.trim()!==""&&w.phone.trim()!==""&&w.email.trim()!==""&&w.ville.trim()!=="",a={backgroundColor:OC(I,50),color:A,borderRadius:`${C}px`,border:`1px solid ${B}`};return u.jsxs("div",{className:"w-full mx-auto",style:{color:A},children:[u.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[u.jsx(Fo,{className:"w-5 h-5",style:{color:B}}),u.jsx("h2",{className:"text-lg font-semibold mt-1",children:"Formulaire de contact"})]}),u.jsxs("div",{className:"p-4 rounded-lg space-y-4",style:{backgroundColor:I,borderRadius:`${C}px`},children:[u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(Fo,{className:"w-4 h-4"}),"Nom complet *"]}),u.jsx("input",{type:"text",value:w.fullName,onChange:G=>D("fullName",G.target.value),placeholder:"Entrez votre nom complet...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...a,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(Tr,{className:"w-4 h-4"}),"Numéro de téléphone *"]}),u.jsx("input",{type:"tel",value:w.phone,onChange:G=>D("phone",G.target.value),placeholder:"Entrez votre numéro de téléphone...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...a,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(qr,{className:"w-4 h-4"}),"Email *"]}),u.jsx("input",{type:"email",value:w.email,onChange:G=>D("email",G.target.value),placeholder:"Entrez votre adresse email...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...a,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(HD,{className:"w-4 h-4"}),"Ville *"]}),u.jsx("input",{type:"text",value:w.ville,onChange:G=>D("ville",G.target.value),placeholder:"Entrez votre ville...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...a,"--tw-ring-color":B}})]})]}),u.jsxs("button",{onClick:t,disabled:!s(),className:"w-full px-6 py-3 mt-4 text-sm font-medium rounded-lg transition-colors flex items-center justify-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed",style:{backgroundColor:B,color:E,borderRadius:`${C}px`},children:[u.jsx(VQ,{className:"w-4 h-4"}),"Envoyer"]}),u.jsx("div",{className:"mt-2 text-xs opacity-70 text-center",children:"* Champs obligatoires"})]})}function kW({onValidate:g,agentChatResponseColor:A,agentChatResponseBgColor:I,buttonsBgColor:B,buttonColor:E,chatRoundness:C,panelWidth:Q,inputBackgroundColor:o}){const[w,M]=vA.useState({fullName:"",phone:"",email:"",ville:""}),D=(G,R)=>{M(U=>({...U,[G]:R}))},t=()=>{g(w)},s=()=>w.fullName.trim()!==""&&w.phone.trim()!==""&&w.email.trim()!==""&&w.ville.trim()!=="",a={backgroundColor:OC(I,50),color:A,borderRadius:`${C}px`,border:`1px solid ${B}`,direction:"rtl",textAlign:"right"};return u.jsxs("div",{className:"w-full mx-auto",style:{color:A},dir:"rtl",children:[u.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[u.jsx(Fo,{className:"w-5 h-5",style:{color:B}}),u.jsx("h2",{className:"text-lg font-semibold mt-1",children:"نموذج التواصل"})]}),u.jsxs("div",{className:"p-4 rounded-lg space-y-4",style:{backgroundColor:I,borderRadius:`${C}px`},children:[u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(Fo,{className:"w-4 h-4"}),"الاسم الكامل *"]}),u.jsx("input",{type:"text",value:w.fullName,onChange:G=>D("fullName",G.target.value),placeholder:"أدخل اسمك الكامل...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...a,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(Tr,{className:"w-4 h-4"}),"رقم الهاتف *"]}),u.jsx("input",{type:"tel",value:w.phone,onChange:G=>D("phone",G.target.value),placeholder:"أدخل رقم هاتفك...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...a,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(qr,{className:"w-4 h-4"}),"البريد الإلكتروني *"]}),u.jsx("input",{type:"email",value:w.email,onChange:G=>D("email",G.target.value),placeholder:"أدخل بريدك الإلكتروني...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...a,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(HD,{className:"w-4 h-4"}),"المدينة *"]}),u.jsx("input",{type:"text",value:w.ville,onChange:G=>D("ville",G.target.value),placeholder:"أدخل مدينتك...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...a,"--tw-ring-color":B}})]})]}),u.jsxs("button",{onClick:t,disabled:!s(),className:"w-full px-6 py-3 mt-4 text-sm font-medium rounded-lg transition-colors flex items-center justify-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed",style:{backgroundColor:B,color:E,borderRadius:`${C}px`},children:[u.jsx(VQ,{className:"w-4 h-4"}),"إرسال"]}),u.jsx("div",{className:"mt-2 text-xs opacity-70 text-center",children:"* الحقول الإلزامية"})]})}function OW({onValidate:g,agentChatResponseColor:A,agentChatResponseBgColor:I,buttonsBgColor:B,buttonColor:E,chatRoundness:C,panelWidth:Q,inputBackgroundColor:o}){const[w,M]=vA.useState({nomComplet:"",numero:"",nomMachine:"",email:"",ville:"",typeDeProjet:""}),D=(G,R)=>{M(U=>({...U,[G]:R}))},t=()=>{g(w)},s=()=>w.nomComplet.trim()!==""&&w.numero.trim()!==""&&w.nomMachine.trim()!==""&&w.ville.trim()!=="",a={backgroundColor:OC(I,50),color:A,borderRadius:`${C}px`,border:`1px solid ${B}`};return u.jsxs("div",{className:"w-full mx-auto",style:{color:A},children:[u.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[u.jsx(Ce,{className:"w-5 h-5",style:{color:B}}),u.jsx("h2",{className:"text-lg font-semibold mt-1",children:"Formulaire XCMG"})]}),u.jsxs("div",{className:"p-4 rounded-lg space-y-4",style:{backgroundColor:I,borderRadius:`${C}px`},children:[u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(Fo,{className:"w-4 h-4"}),"Nom complet *"]}),u.jsx("input",{type:"text",value:w.nomComplet,onChange:G=>D("nomComplet",G.target.value),placeholder:"Entrez votre nom complet...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...a,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(Tr,{className:"w-4 h-4"}),"Numéro *"]}),u.jsx("input",{type:"tel",value:w.numero,onChange:G=>D("numero",G.target.value),placeholder:"Entrez votre numéro...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...a,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(qr,{className:"w-4 h-4"}),"Email"]}),u.jsx("input",{type:"email",value:w.email,onChange:G=>D("email",G.target.value),placeholder:"Entrez votre adresse email...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...a,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(HD,{className:"w-4 h-4"}),"Ville *"]}),u.jsx("input",{type:"text",value:w.ville,onChange:G=>D("ville",G.target.value),placeholder:"Entrez votre ville...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...a,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(Ce,{className:"w-4 h-4"}),"Nom machine *"]}),u.jsx("input",{type:"text",value:w.nomMachine,onChange:G=>D("nomMachine",G.target.value),placeholder:"Entrez le nom de la machine...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...a,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(Ce,{className:"w-4 h-4"}),"Type de projet"]}),u.jsxs("select",{value:w.typeDeProjet,onChange:G=>D("typeDeProjet",G.target.value),className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...a,"--tw-ring-color":B},children:[u.jsx("option",{value:"",children:"Sélectionnez le type de projet"}),u.jsx("option",{value:"BTP",children:"BTP"}),u.jsx("option",{value:"infrastructure",children:"infrastructure"}),u.jsx("option",{value:"PME",children:"PME"}),u.jsx("option",{value:"Autre",children:"Autre"})]})]})]}),u.jsxs("button",{onClick:t,disabled:!s(),className:"w-full px-6 py-3 mt-4 text-sm font-medium rounded-lg transition-colors flex items-center justify-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed",style:{backgroundColor:B,color:E,borderRadius:`${C}px`},children:[u.jsx(VQ,{className:"w-4 h-4"}),"Envoyer"]}),u.jsx("div",{className:"mt-2 text-xs opacity-70 text-center",children:"* Champs obligatoires"})]})}const wsA=["Étudiant(e) en préparation du Bac","Titulaire du Bac (moins de 3 ans)","Étudiant(e) en études supérieures","Diplômé(e) sans emploi"];function JW({onValidate:g,agentChatResponseColor:A,agentChatResponseBgColor:I,buttonsBgColor:B,buttonColor:E,chatRoundness:C,panelWidth:Q,inputBackgroundColor:o}){const[w,M]=vA.useState(""),[D,t]=vA.useState(""),s={backgroundColor:OC(I,50),color:A,borderRadius:`${C}px`,border:`1px solid ${B}`},a=()=>{g({situation:w,ville:D})},G=()=>w.trim()!==""&&D.trim()!=="";return u.jsxs("div",{className:"w-full mx-auto",style:{color:A},children:[u.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[u.jsx(Fo,{className:"w-5 h-5",style:{color:B}}),u.jsx("h2",{className:"text-lg font-semibold mt-1",children:"Formulaire Jadara"})]}),u.jsxs("div",{className:"p-4 rounded-lg space-y-4",style:{backgroundColor:I,borderRadius:`${C}px`},children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx("label",{className:"block text-sm font-medium",children:"Choisissez votre situation actuelle *"}),u.jsx("div",{className:"grid grid-cols-1 gap-2",children:wsA.map(R=>u.jsxs("button",{type:"button",onClick:()=>M(R),className:"w-full flex items-center gap-3 px-3 py-2 text-sm",style:{background:w===R?B:OC(I,50),color:w===R?E:A,borderRadius:`${C}px`,border:`1px solid ${B}`,textAlign:"left"},children:[u.jsx("div",{style:{width:18,display:"flex",alignItems:"center",justifyContent:"center"},children:w===R?u.jsx(cj,{className:"w-4 h-4"}):u.jsx("div",{style:{width:14}})}),u.jsx("span",{className:"text-sm",children:R})]},R))})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(HD,{className:"w-4 h-4"}),"Ville *"]}),u.jsx("input",{type:"text",value:D,onChange:R=>t(R.target.value),placeholder:"Entrez votre ville...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...s,"--tw-ring-color":B}})]})]}),u.jsxs("button",{onClick:a,disabled:!G(),className:"w-full px-6 py-3 mt-4 text-sm font-medium rounded-lg transition-colors flex items-center justify-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed",style:{backgroundColor:B,color:E,borderRadius:`${C}px`},children:[u.jsx(VQ,{className:"w-4 h-4"}),"Envoyer"]}),u.jsx("div",{className:"mt-2 text-xs opacity-70 text-center",children:"* Champs obligatoires"})]})}const esA=["طالب(ة) يستعد/تستعد للباكالوريا","حاصل(ة) على الباكالوريا (منذ أقل من 3 سنوات)","طالب(ة) في التعليم العالي","خريج(ة) بدون عمل"];function HW({onValidate:g,agentChatResponseColor:A,agentChatResponseBgColor:I,buttonsBgColor:B,buttonColor:E,chatRoundness:C,panelWidth:Q,inputBackgroundColor:o}){const[w,M]=vA.useState(""),[D,t]=vA.useState(""),s={backgroundColor:OC(I,50),color:A,borderRadius:`${C}px`,border:`1px solid ${B}`,direction:"rtl",textAlign:"right"},a=()=>{g({situation:w,ville:D})},G=()=>w.trim()!==""&&D.trim()!=="";return u.jsxs("div",{className:"w-full mx-auto",style:{color:A},dir:"rtl",children:[u.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[u.jsx(Fo,{className:"w-5 h-5",style:{color:B}}),u.jsx("h2",{className:"text-lg font-semibold mt-1",children:"نموذج جدارة"})]}),u.jsxs("div",{className:"p-4 rounded-lg space-y-4",style:{backgroundColor:I,borderRadius:`${C}px`},children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx("label",{className:"block text-sm font-medium",children:"اختر وضعك الحالي *"}),u.jsx("div",{className:"grid grid-cols-1 gap-2",children:esA.map(R=>u.jsxs("button",{type:"button",onClick:()=>M(R),className:"w-full flex items-center gap-3 px-3 py-2 text-sm",style:{background:w===R?B:OC(I,50),color:w===R?E:A,borderRadius:`${C}px`,border:`1px solid ${B}`,textAlign:"right",direction:"rtl"},children:[u.jsx("div",{style:{width:18,display:"flex",alignItems:"center",justifyContent:"center"},children:w===R?u.jsx(cj,{className:"w-4 h-4"}):u.jsx("div",{style:{width:14}})}),u.jsx("span",{className:"text-sm",children:R})]},R))})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(HD,{className:"w-4 h-4"}),"المدينة *"]}),u.jsx("input",{type:"text",value:D,onChange:R=>t(R.target.value),placeholder:"أدخل مدينتك...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...s,"--tw-ring-color":B}})]})]}),u.jsxs("button",{onClick:a,disabled:!G(),className:"w-full px-6 py-3 mt-4 text-sm font-medium rounded-lg transition-colors flex items-center justify-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed",style:{backgroundColor:B,color:E,borderRadius:`${C}px`},children:[u.jsx(VQ,{className:"w-4 h-4"}),"إرسال"]}),u.jsx("div",{className:"mt-2 text-xs opacity-70 text-center",children:"* الحقول الإلزامية"})]})}const MsA=["Marketing digital","Développement web","Création de contenu"];function NW({onValidate:g,agentChatResponseColor:A,agentChatResponseBgColor:I,buttonsBgColor:B,buttonColor:E,chatRoundness:C,panelWidth:Q,inputBackgroundColor:o}){const[w,M]=vA.useState(""),D=t=>{M(t),g({Domaines_qui_vous_interessent:t})};return u.jsxs("div",{className:"w-full mx-auto",style:{color:A},children:[u.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[u.jsx(JIA,{className:"w-5 h-5",style:{color:B}}),u.jsx("h2",{className:"text-lg font-semibold mt-1",children:"Domaines d'intérêt"})]}),u.jsx("div",{className:"p-3 rounded-lg space-y-3",style:{backgroundColor:I,borderRadius:`${C}px`},children:u.jsxs("div",{className:"space-y-2",children:[u.jsx("label",{className:"block text-sm font-medium",children:"Domaines qui vous intéressent"}),u.jsx("div",{className:"grid grid-cols-1 gap-2",children:MsA.map(t=>u.jsxs("button",{type:"button",onClick:()=>D(t),className:"w-full flex items-center gap-3 px-3 py-2 text-sm",style:{background:w===t?B:OC(I,50),color:w===t?E:A,borderRadius:`${C}px`,border:`1px solid ${B}`,textAlign:"left"},children:[u.jsx("div",{style:{width:18,display:"flex",alignItems:"center",justifyContent:"center"},children:w===t?u.jsx(VQ,{className:"w-4 h-4"}):u.jsx("div",{style:{width:14}})}),u.jsx("span",{className:"text-sm",children:t})]},t))})]})})]})}function BG({products:g,onValidate:A,agentChatResponseColor:I,agentChatResponseBgColor:B,buttonsBgColor:E,buttonColor:C,chatRoundness:Q,panelWidth:o,inputBackgroundColor:w}){const[M,D]=vA.useState({}),[t,s]=vA.useState(!1),[a,G]=vA.useState(0),R=o<700,U=o>=1300,r=Math.ceil((g?.length||0)/(R?1:U?3:2)),l=()=>{G(W=>(W+1)%r)},K=()=>{G(W=>(W-1+r)%r)},m=W=>{G(W)},x=W=>{D(T=>({...T,[W]:(T[W]||0)+1}))},O=W=>{D(T=>{const X={...T};return X[W]>1?X[W]-=1:delete X[W],X})},y=()=>Object.entries(M).map(([W,T])=>({id_produit:W,quantite:T})),L=()=>Object.values(M).reduce((W,T)=>W+T,0),j=()=>{const T={products:y()};A(T)},z=()=>Object.entries(M).map(([W,T])=>({product:g.find(P=>P.id===W),quantity:T})).filter(W=>W.product),d=()=>z().reduce((W,{product:T,quantity:X})=>W+T.price*X,0),Z=()=>{const W=[];for(let T=0;T<g.length;T+=R?1:U?3:2)W.push(g.slice(T,T+(R?1:U?3:2)));return W};return u.jsxs("div",{className:"w-full mx-auto",style:{color:I},children:[u.jsxs("div",{className:"flex items-center justify-between mb-4",children:[u.jsx("h2",{className:"text-lg font-semibold",children:"Produits Disponibles"}),L()>0&&u.jsxs("button",{onClick:()=>s(!t),className:"flex items-center gap-2 px-3 py-2 rounded-lg transition-colors",style:{backgroundColor:E+"20",color:C,borderRadius:`${Q}px`},children:[u.jsx(VIA,{className:"w-4 h-4"}),u.jsxs("div",{className:"flex flex-col items-end text-xs",children:[u.jsxs("span",{children:[L()," articles"]}),u.jsx("span",{children:d()>0?`${d().toFixed(2)} DH`:""})]})]})]}),u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"relative overflow-hidden mb-6",children:[u.jsx("div",{className:"flex transition-transform duration-300 ease-in-out",style:{transform:`translateX(-${a*100}%)`},children:Z().map((W,T)=>u.jsx("div",{className:`w-full flex-shrink-0 grid ${R?"grid-cols-1":U&&g.length>=3?"grid-cols-3":"grid-cols-2"} gap-4 p-2`,children:W.map(X=>u.jsxs("div",{className:"p-4 rounded-lg border border-opacity-20",style:{backgroundColor:B+"40",borderColor:I,borderRadius:`${Q}px`},children:[u.jsx("div",{className:"relative w-full h-40 mb-3 rounded-md overflow-hidden",children:u.jsx("img",{src:X?.image??"",alt:X.nomProduit,className:"w-full h-full object-contain bg-gray-100"})}),u.jsx("h3",{className:"font-semibold text-sm mb-2",style:{color:I},children:X.nomProduit}),u.jsx("p",{className:"text-xs text-opacity-70 mb-2 line-clamp-2",style:{color:I},title:X.description,children:X.description}),u.jsxs("div",{className:"flex items-center justify-between gap-4",children:[u.jsxs("div",{className:"text-xs",style:{color:I},children:[X.stock>0?"In Stock":"Out of stock",u.jsx("br",{}),"Prix: ",X.price!=0?`${X.price} DH`:"-"]}),u.jsx("div",{className:"flex items-center gap-2",children:M[X.id]?u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("button",{onClick:()=>O(X.id),className:"w-8 h-8 rounded-full flex items-center justify-center transition-colors",style:{backgroundColor:E+"80",color:C},children:u.jsx(Zr,{className:"w-4 h-4"})}),u.jsx("span",{className:"min-w-[20px] text-center text-sm font-semibold",children:M[X.id]}),u.jsx("button",{onClick:()=>x(X.id),disabled:M[X.id]>=X.stock,className:"w-8 h-8 rounded-full flex items-center justify-center transition-colors disabled:opacity-50",style:{backgroundColor:E,color:C},children:u.jsx(fs,{className:"w-4 h-4"})})]}):u.jsx("button",{onClick:()=>x(X.id),disabled:X.stock===0,className:"px-3 py-1 text-xs rounded-lg transition-colors disabled:opacity-50",style:{backgroundColor:E,color:C,borderRadius:`${Q}px`},children:X.price===0?"Ajouter au devis":"Ajouter au panier"})})]})]},X.id))},T))}),r>1&&u.jsxs(u.Fragment,{children:[a>0&&u.jsx("button",{onClick:K,className:"absolute left-0 top-24 w-8 h-8 rounded-full flex items-center justify-center transition-all duration-200 hover:scale-110 shadow-lg backdrop-blur-sm",style:{backgroundColor:`${E}CC`,color:C},children:u.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})})}),a<r-1&&u.jsx("button",{onClick:l,className:"absolute right-0 top-24 w-8 h-8 rounded-full flex items-center justify-center transition-all duration-200 hover:scale-110 shadow-lg backdrop-blur-sm",style:{backgroundColor:`${E}CC`,color:C},children:u.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})})]})]}),r>1&&u.jsx("div",{className:"flex justify-center space-x-2 mt-3",children:Array.from({length:r}).map((W,T)=>u.jsx("button",{onClick:()=>m(T),className:`w-2 h-2 rounded-full transition-all duration-200 ${T===a?"scale-125 opacity-100":"opacity-40 hover:opacity-70"}`,style:{backgroundColor:E}},T))})]}),t&&L()>0&&u.jsxs("div",{className:"mt-3 p-4 rounded-lg border border-opacity-20 mb-4",style:{backgroundColor:B+"60",borderColor:I,borderRadius:`${Q}px`},children:[u.jsxs("h3",{className:"font-semibold mb-3",children:["Produits sélectionnés: (",L()," articles)"]}),u.jsx("div",{className:"space-y-2",children:z().map(({product:W,quantity:T})=>u.jsxs("div",{className:"flex justify-between items-center text-sm",children:[u.jsxs("div",{className:"flex-1",children:[u.jsx("div",{children:W.nomProduit}),u.jsx("div",{className:"text-xs opacity-70",children:W.price>0?`${W.price.toFixed(2)} DH × ${T}`:`× ${T}`})]}),u.jsx("span",{className:"ml-2 font-medium",children:W.price*T>0?`${(W.price*T).toFixed(2)} DH`:""})]},W.id))}),d()>0&&u.jsx("div",{className:"border-t border-opacity-30 mt-3 pt-3",style:{borderColor:I},children:u.jsxs("div",{className:"flex justify-between items-center font-semibold",children:[u.jsx("span",{children:"Total:"}),u.jsxs("span",{children:[d().toFixed(2)," DH"]})]})})]}),L()>0&&u.jsxs("button",{onClick:j,className:"w-full px-6 py-3 mt-3 text-sm font-medium rounded-lg transition-colors flex items-center justify-center gap-2",style:{backgroundColor:E,color:C,borderRadius:`${Q}px`},children:[u.jsx(VQ,{className:"w-4 h-4"}),"Valider la sélection (",L()," articles) ",d()!==0?`- ${d().toFixed(2)} DH`:""]})]})}const DsA=({options:g,message:A,allowMultiple:I,chatRoundness:B,buttonsBgColor:E,buttonColor:C,agentChatResponseColor:Q,agentChatResponseBgColor:o,isRtl:w,onSend:M,onScroll:D})=>{const[t,s]=vA.useState([]),a=o?OC(o,10):E,G=U=>{I?s(r=>r.includes(U)?r.filter(K=>K!==U):[...r,U]):M(U)},R=()=>{t.length>0&&(M(t.join(",")),s([]))};return u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"mt-2 flex flex-col",dir:w?"rtl":"ltr",children:g?.map((U,r)=>{const l=I&&t.includes(U.value);return u.jsxs("button",{className:"w-full mb-1 flex items-center justify-between px-4 py-2.5 hover:opacity-95 transition-all duration-100",dir:aw(U.label)?"rtl":"ltr",onClick:()=>G(U.value),onMouseEnter:K=>{K.currentTarget.style.borderColor=`${E}`},onMouseLeave:K=>{const m=l?E:OC(a,20);K.currentTarget.style.border=`2px solid ${m}`},style:{background:l?`linear-gradient(135deg, ${E}, ${E}DD)`:a,borderRadius:"18px",color:Q,border:`2px solid ${OC(a,20)}`,opacity:l?.95:1,transform:l?"scale(0.99)":"scale(1)"},children:[u.jsxs("div",{className:"flex items-center gap-2 w-full",children:[I&&l&&u.jsx(VQ,{className:"w-4 h-4 flex-shrink-0"}),u.jsx(cE,{sequence:[U.label,0,D],cursor:!1,speed:90})]}),u.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center"},children:aw(U.label)?u.jsx(tj,{className:"w-4 h-4"}):u.jsx(aj,{className:"w-4 h-4"})})]},r)})}),I&&t.length>0&&u.jsx("div",{className:"mt-3 flex justify-end",dir:w?"rtl":"ltr",children:u.jsxs("button",{onClick:R,className:"px-6 py-2 font-semibold hover:scale-105 transition-all duration-200 flex items-center gap-2",style:{background:`linear-gradient(135deg, ${E}, ${E}AA)`,borderRadius:`${B}px`,color:C},children:[u.jsx(Gj,{className:"w-4 h-4"}),u.jsxs("span",{children:["Send (",t.length,")"]})]})})]})},r4=({items:g,chatRoundness:A,agentChatResponseBgColor:I,agentChatResponseColor:B,buttonsBgColor:E,buttonColor:C,inputBackgroundColor:Q,onButtonClick:o,setMessages:w})=>{const[M,D]=vA.useState(0),t=g?.length||0,s=()=>{D(R=>(R+1)%t)},a=()=>{D(R=>(R-1+t)%t)},G=R=>{D(R)};return u.jsx("div",{className:"mt-2 w-full",children:u.jsxs("div",{className:"relative max-w-md mx-auto",children:[u.jsx("div",{className:"overflow-hidden rounded-lg",style:{borderRadius:`${A}px`},children:u.jsx("div",{className:"flex transition-transform duration-300 ease-in-out",style:{transform:`translateX(-${M*100}%)`},children:g?.map((R,U)=>u.jsxs("div",{className:"w-full flex-shrink-0 px-2",style:{background:I},children:[u.jsxs("div",{className:"relative h-40 w-full mb-3 ",children:[u.jsx("img",{src:R.image,alt:R.title,className:"size-full object-cover rounded-lg"}),t>1&&u.jsxs(u.Fragment,{children:[M>0&&u.jsx("button",{onClick:a,className:"absolute -left-2 top-1/2 -translate-y-1/2 w-8 h-8 rounded-full flex items-center justify-center transition-all duration-200 hover:scale-110 shadow-lg backdrop-blur-sm",style:{backgroundColor:`${E}CC`,color:C},children:u.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})})}),M<t-1&&u.jsx("button",{onClick:s,className:"absolute -right-2 top-1/2 -translate-y-1/2 w-8 h-8 rounded-full flex items-center justify-center transition-all duration-200 hover:scale-110 shadow-lg backdrop-blur-sm",style:{backgroundColor:`${E}CC`,color:C},children:u.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})})]})]}),u.jsx("h3",{className:"text-sm font-bold mb-2",style:{color:B},children:R.title}),u.jsx("p",{className:"text-xs mb-3 leading-relaxed",style:{color:B},children:R.subtitle}),u.jsx("div",{className:"space-y-2",children:R.actions?.map((r,l)=>u.jsx("button",{className:"w-full px-4 py-2 text-sm font-medium hover:scale-[0.98] transition-all duration-200",onClick:()=>{r.action==="link"||r.action==="Open URL"?window.open(r.url,"_blank"):r.action==="postback"||r.action==="Postback"?o(r.title,r.payload):r.action==="say-something"&&typeof r.action=="string"&&w(K=>[...K,{sender:"agent",content:r.payload,id:`msg-${Date.now()}`,timestamp:new Date,seen:!0}])},style:{background:E,borderRadius:`${A}px`,color:C},children:r.title},l))})]},U))})}),t>1&&u.jsxs("div",{className:"absolute top-2 right-2 px-2 py-1 text-xs font-medium rounded-full backdrop-blur-sm",style:{backgroundColor:`${Q}CC`,color:B},children:[M+1," / ",t]}),t>1&&u.jsx("div",{className:"flex justify-center space-x-2 mt-3",children:g?.map((R,U)=>u.jsx("button",{onClick:()=>G(U),className:`w-2 h-2 rounded-full transition-all duration-200 ${U===M?"scale-125 opacity-100":"opacity-40 hover:opacity-70"}`,style:{backgroundColor:E}},U))})]})})};function MC(g,A,I,B){return new(I||(I=Promise))(function(E,C){function Q(M){try{w(B.next(M))}catch(D){C(D)}}function o(M){try{w(B.throw(M))}catch(D){C(D)}}function w(M){var D;M.done?E(M.value):(D=M.value,D instanceof I?D:new I(function(t){t(D)})).then(Q,o)}w((B=B.apply(g,A||[])).next())})}typeof SuppressedError=="function"&&SuppressedError;let Xt=class{constructor(){this.listeners={}}on(A,I,B){if(this.listeners[A]||(this.listeners[A]=new Set),this.listeners[A].add(I),B?.once){const E=()=>{this.un(A,E),this.un(A,I)};return this.on(A,E),E}return()=>this.un(A,I)}un(A,I){var B;(B=this.listeners[A])===null||B===void 0||B.delete(I)}once(A,I){return this.on(A,I,{once:!0})}unAll(){this.listeners={}}emit(A,...I){this.listeners[A]&&this.listeners[A].forEach(B=>B(...I))}};const EG={decode:function(g,A){return MC(this,void 0,void 0,function*(){const I=new AudioContext({sampleRate:A});return I.decodeAudioData(g).finally(()=>I.close())})},createBuffer:function(g,A){return typeof g[0]=="number"&&(g=[g]),function(I){const B=I[0];if(B.some(E=>E>1||E<-1)){const E=B.length;let C=0;for(let Q=0;Q<E;Q++){const o=Math.abs(B[Q]);o>C&&(C=o)}for(const Q of I)for(let o=0;o<E;o++)Q[o]/=C}}(g),{duration:A,length:g[0].length,sampleRate:g[0].length/A,numberOfChannels:g.length,getChannelData:I=>g?.[I],copyFromChannel:AudioBuffer.prototype.copyFromChannel,copyToChannel:AudioBuffer.prototype.copyToChannel}}};function xW(g,A){const I=A.xmlns?document.createElementNS(A.xmlns,g):document.createElement(g);for(const[B,E]of Object.entries(A))if(B==="children"&&E)for(const[C,Q]of Object.entries(E))Q instanceof Node?I.appendChild(Q):typeof Q=="string"?I.appendChild(document.createTextNode(Q)):I.appendChild(xW(C,Q));else B==="style"?Object.assign(I.style,E):B==="textContent"?I.textContent=E:I.setAttribute(B,E.toString());return I}function dW(g,A,I){const B=xW(g,A||{});return I?.appendChild(B),B}var hsA=Object.freeze({__proto__:null,createElement:dW,default:dW});const tsA={fetchBlob:function(g,A,I){return MC(this,void 0,void 0,function*(){const B=yield fetch(g,I);if(B.status>=400)throw new Error(`Failed to fetch ${g}: ${B.status} (${B.statusText})`);return function(E,C){MC(this,void 0,void 0,function*(){if(!E.body||!E.headers)return;const Q=E.body.getReader(),o=Number(E.headers.get("Content-Length"))||0;let w=0;const M=t=>MC(this,void 0,void 0,function*(){w+=t?.length||0;const s=Math.round(w/o*100);C(s)}),D=()=>MC(this,void 0,void 0,function*(){let t;try{t=yield Q.read()}catch{return}t.done||(M(t.value),yield D())});D()})}(B.clone(),A),B.blob()})}};let asA=class extends Xt{constructor(A){super(),this.isExternalMedia=!1,A.media?(this.media=A.media,this.isExternalMedia=!0):this.media=document.createElement("audio"),A.mediaControls&&(this.media.controls=!0),A.autoplay&&(this.media.autoplay=!0),A.playbackRate!=null&&this.onMediaEvent("canplay",()=>{A.playbackRate!=null&&(this.media.playbackRate=A.playbackRate)},{once:!0})}onMediaEvent(A,I,B){return this.media.addEventListener(A,I,B),()=>this.media.removeEventListener(A,I,B)}getSrc(){return this.media.currentSrc||this.media.src||""}revokeSrc(){const A=this.getSrc();A.startsWith("blob:")&&URL.revokeObjectURL(A)}canPlayType(A){return this.media.canPlayType(A)!==""}setSrc(A,I){const B=this.getSrc();if(A&&B===A)return;this.revokeSrc();const E=I instanceof Blob&&(this.canPlayType(I.type)||!A)?URL.createObjectURL(I):A;if(B&&this.media.removeAttribute("src"),E||A)try{this.media.src=E}catch{this.media.src=A}}destroy(){this.isExternalMedia||(this.media.pause(),this.media.remove(),this.revokeSrc(),this.media.removeAttribute("src"),this.media.load())}setMediaElement(A){this.media=A}play(){return MC(this,void 0,void 0,function*(){try{return yield this.media.play()}catch(A){if(A instanceof DOMException&&A.name==="AbortError")return;throw A}})}pause(){this.media.pause()}isPlaying(){return!this.media.paused&&!this.media.ended}setTime(A){this.media.currentTime=Math.max(0,Math.min(A,this.getDuration()))}getDuration(){return this.media.duration}getCurrentTime(){return this.media.currentTime}getVolume(){return this.media.volume}setVolume(A){this.media.volume=A}getMuted(){return this.media.muted}setMuted(A){this.media.muted=A}getPlaybackRate(){return this.media.playbackRate}isSeeking(){return this.media.seeking}setPlaybackRate(A,I){I!=null&&(this.media.preservesPitch=I),this.media.playbackRate=A}getMediaElement(){return this.media}setSinkId(A){return this.media.setSinkId(A)}},n4=class rN extends Xt{constructor(A,I){super(),this.timeouts=[],this.isScrollable=!1,this.audioData=null,this.resizeObserver=null,this.lastContainerWidth=0,this.isDragging=!1,this.subscriptions=[],this.unsubscribeOnScroll=[],this.subscriptions=[],this.options=A;const B=this.parentFromOptionsContainer(A.container);this.parent=B;const[E,C]=this.initHtml();B.appendChild(E),this.container=E,this.scrollContainer=C.querySelector(".scroll"),this.wrapper=C.querySelector(".wrapper"),this.canvasWrapper=C.querySelector(".canvases"),this.progressWrapper=C.querySelector(".progress"),this.cursor=C.querySelector(".cursor"),I&&C.appendChild(I),this.initEvents()}parentFromOptionsContainer(A){let I;if(typeof A=="string"?I=document.querySelector(A):A instanceof HTMLElement&&(I=A),!I)throw new Error("Container not found");return I}initEvents(){const A=I=>{const B=this.wrapper.getBoundingClientRect(),E=I.clientX-B.left,C=I.clientY-B.top;return[E/B.width,C/B.height]};if(this.wrapper.addEventListener("click",I=>{const[B,E]=A(I);this.emit("click",B,E)}),this.wrapper.addEventListener("dblclick",I=>{const[B,E]=A(I);this.emit("dblclick",B,E)}),this.options.dragToSeek!==!0&&typeof this.options.dragToSeek!="object"||this.initDrag(),this.scrollContainer.addEventListener("scroll",()=>{const{scrollLeft:I,scrollWidth:B,clientWidth:E}=this.scrollContainer,C=I/B,Q=(I+E)/B;this.emit("scroll",C,Q,I,I+E)}),typeof ResizeObserver=="function"){const I=this.createDelay(100);this.resizeObserver=new ResizeObserver(()=>{I().then(()=>this.onContainerResize()).catch(()=>{})}),this.resizeObserver.observe(this.scrollContainer)}}onContainerResize(){const A=this.parent.clientWidth;A===this.lastContainerWidth&&this.options.height!=="auto"||(this.lastContainerWidth=A,this.reRender())}initDrag(){this.subscriptions.push(function(A,I,B,E,C=3,Q=0,o=100){if(!A)return()=>{};const w=matchMedia("(pointer: coarse)").matches;let M=()=>{};const D=t=>{if(t.button!==Q)return;t.preventDefault(),t.stopPropagation();let s=t.clientX,a=t.clientY,G=!1;const R=Date.now(),U=x=>{if(x.preventDefault(),x.stopPropagation(),w&&Date.now()-R<o)return;const O=x.clientX,y=x.clientY,L=O-s,j=y-a;if(G||Math.abs(L)>C||Math.abs(j)>C){const z=A.getBoundingClientRect(),{left:d,top:Z}=z;G||(B?.(s-d,a-Z),G=!0),I(L,j,O-d,y-Z),s=O,a=y}},r=x=>{if(G){const O=x.clientX,y=x.clientY,L=A.getBoundingClientRect(),{left:j,top:z}=L;E?.(O-j,y-z)}M()},l=x=>{x.relatedTarget&&x.relatedTarget!==document.documentElement||r(x)},K=x=>{G&&(x.stopPropagation(),x.preventDefault())},m=x=>{G&&x.preventDefault()};document.addEventListener("pointermove",U),document.addEventListener("pointerup",r),document.addEventListener("pointerout",l),document.addEventListener("pointercancel",l),document.addEventListener("touchmove",m,{passive:!1}),document.addEventListener("click",K,{capture:!0}),M=()=>{document.removeEventListener("pointermove",U),document.removeEventListener("pointerup",r),document.removeEventListener("pointerout",l),document.removeEventListener("pointercancel",l),document.removeEventListener("touchmove",m),setTimeout(()=>{document.removeEventListener("click",K,{capture:!0})},10)}};return A.addEventListener("pointerdown",D),()=>{M(),A.removeEventListener("pointerdown",D)}}(this.wrapper,(A,I,B)=>{this.emit("drag",Math.max(0,Math.min(1,B/this.wrapper.getBoundingClientRect().width)))},A=>{this.isDragging=!0,this.emit("dragstart",Math.max(0,Math.min(1,A/this.wrapper.getBoundingClientRect().width)))},A=>{this.isDragging=!1,this.emit("dragend",Math.max(0,Math.min(1,A/this.wrapper.getBoundingClientRect().width)))}))}getHeight(A,I){var B;const E=((B=this.audioData)===null||B===void 0?void 0:B.numberOfChannels)||1;if(A==null)return 128;if(!isNaN(Number(A)))return Number(A);if(A==="auto"){const C=this.parent.clientHeight||128;return I?.every(Q=>!Q.overlay)?C/E:C}return 128}initHtml(){const A=document.createElement("div"),I=A.attachShadow({mode:"open"}),B=this.options.cspNonce&&typeof this.options.cspNonce=="string"?this.options.cspNonce.replace(/"/g,""):"";return I.innerHTML=`
550
+ `}),u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center gap-2 pb-2 border-b",style:{borderColor:B+"40"},children:[u.jsx(Fo,{className:"w-4 h-4",style:{color:A}}),u.jsx("h3",{className:"text-sm font-semibold",children:"Informations personnelles"})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx("label",{className:"block text-sm font-medium",children:"Nom complet *"}),u.jsx("input",{type:"text",value:M.nom,onChange:r=>s("nom",r.target.value),placeholder:"Votre nom et prénom",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...R,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx("label",{className:"block text-sm font-medium",children:"Nom de l'entreprise *"}),u.jsx("input",{type:"text",value:M.entreprise,onChange:r=>s("entreprise",r.target.value),placeholder:"Ex. : ACME SARL",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...R,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx("label",{className:"block text-sm font-medium",children:"Email professionnel *"}),u.jsx("input",{type:"email",value:M.email,onChange:r=>s("email",r.target.value),placeholder:"ex. nom@startup.com",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...R,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx("label",{className:"block text-sm font-medium",children:"Numéro de téléphone *"}),u.jsx("input",{type:"tel",value:M.phone,onChange:r=>s("phone",r.target.value),placeholder:"Inclure l'indicatif international (ex. +212...)",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...R,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx("label",{className:"block text-sm font-medium",children:"Poste *"}),u.jsx("input",{type:"text",value:M.poste,onChange:r=>s("poste",r.target.value),placeholder:"Ex. : CEO, Ingénieur, Étudient ...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...R,"--tw-ring-color":B}})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx("label",{className:"block text-sm font-medium",children:"Secteur d'activité *"}),u.jsx("div",{className:`grid ${t?"grid-cols-1":"grid-cols-2"} gap-2`,children:U.map(r=>u.jsx("button",{onClick:()=>s("secteur",r),className:"px-3 py-2 text-sm rounded-lg transition-colors text-left",style:{backgroundColor:M.secteur===r?w:o||I+"60",color:M.secteur===r?E:A,borderRadius:"10px",border:`1px solid ${B}`},children:r},r))})]})]}),u.jsxs("button",{onClick:a,disabled:!G(),className:"w-full px-6 py-3 mt-4 text-sm font-medium rounded-lg transition-colors flex items-center justify-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed",style:{backgroundColor:B,color:E,borderRadius:`${C}px`},children:[u.jsx(VQ,{className:"w-4 h-4"}),"Valider ma candidature"]})]})}function mW({onValidate:g,agentChatResponseColor:A,agentChatResponseBgColor:I,buttonsBgColor:B,buttonColor:E,chatRoundness:C,panelWidth:Q,inputBackgroundColor:o}){const[w,M]=vA.useState({fullName:"",phone:"",email:"",ville:""}),D=(G,R)=>{M(U=>({...U,[G]:R}))},t=()=>{g(w)},s=()=>w.fullName.trim()!==""&&w.phone.trim()!==""&&w.email.trim()!==""&&w.ville.trim()!=="",a={backgroundColor:OC(I,50),color:A,borderRadius:`${C}px`,border:`1px solid ${B}`};return u.jsxs("div",{className:"w-full mx-auto",style:{color:A},children:[u.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[u.jsx(Fo,{className:"w-5 h-5",style:{color:B}}),u.jsx("h2",{className:"text-lg font-semibold mt-1",children:"Formulaire de contact"})]}),u.jsxs("div",{className:"p-4 rounded-lg space-y-4",style:{backgroundColor:I,borderRadius:`${C}px`},children:[u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(Fo,{className:"w-4 h-4"}),"Nom complet *"]}),u.jsx("input",{type:"text",value:w.fullName,onChange:G=>D("fullName",G.target.value),placeholder:"Entrez votre nom complet...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...a,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(Tr,{className:"w-4 h-4"}),"Numéro de téléphone *"]}),u.jsx("input",{type:"tel",value:w.phone,onChange:G=>D("phone",G.target.value),placeholder:"Entrez votre numéro de téléphone...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...a,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(qr,{className:"w-4 h-4"}),"Email *"]}),u.jsx("input",{type:"email",value:w.email,onChange:G=>D("email",G.target.value),placeholder:"Entrez votre adresse email...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...a,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(HD,{className:"w-4 h-4"}),"Ville *"]}),u.jsx("input",{type:"text",value:w.ville,onChange:G=>D("ville",G.target.value),placeholder:"Entrez votre ville...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...a,"--tw-ring-color":B}})]})]}),u.jsxs("button",{onClick:t,disabled:!s(),className:"w-full px-6 py-3 mt-4 text-sm font-medium rounded-lg transition-colors flex items-center justify-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed",style:{backgroundColor:B,color:E,borderRadius:`${C}px`},children:[u.jsx(VQ,{className:"w-4 h-4"}),"Envoyer"]}),u.jsx("div",{className:"mt-2 text-xs opacity-70 text-center",children:"* Champs obligatoires"})]})}function kW({onValidate:g,agentChatResponseColor:A,agentChatResponseBgColor:I,buttonsBgColor:B,buttonColor:E,chatRoundness:C,panelWidth:Q,inputBackgroundColor:o}){const[w,M]=vA.useState({fullName:"",phone:"",email:"",ville:""}),D=(G,R)=>{M(U=>({...U,[G]:R}))},t=()=>{g(w)},s=()=>w.fullName.trim()!==""&&w.phone.trim()!==""&&w.email.trim()!==""&&w.ville.trim()!=="",a={backgroundColor:OC(I,50),color:A,borderRadius:`${C}px`,border:`1px solid ${B}`,direction:"rtl",textAlign:"right"};return u.jsxs("div",{className:"w-full mx-auto",style:{color:A},dir:"rtl",children:[u.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[u.jsx(Fo,{className:"w-5 h-5",style:{color:B}}),u.jsx("h2",{className:"text-lg font-semibold mt-1",children:"نموذج التواصل"})]}),u.jsxs("div",{className:"p-4 rounded-lg space-y-4",style:{backgroundColor:I,borderRadius:`${C}px`},children:[u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(Fo,{className:"w-4 h-4"}),"الاسم الكامل *"]}),u.jsx("input",{type:"text",value:w.fullName,onChange:G=>D("fullName",G.target.value),placeholder:"أدخل اسمك الكامل...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...a,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(Tr,{className:"w-4 h-4"}),"رقم الهاتف *"]}),u.jsx("input",{type:"tel",value:w.phone,onChange:G=>D("phone",G.target.value),placeholder:"أدخل رقم هاتفك...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...a,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(qr,{className:"w-4 h-4"}),"البريد الإلكتروني *"]}),u.jsx("input",{type:"email",value:w.email,onChange:G=>D("email",G.target.value),placeholder:"أدخل بريدك الإلكتروني...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...a,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(HD,{className:"w-4 h-4"}),"المدينة *"]}),u.jsx("input",{type:"text",value:w.ville,onChange:G=>D("ville",G.target.value),placeholder:"أدخل مدينتك...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...a,"--tw-ring-color":B}})]})]}),u.jsxs("button",{onClick:t,disabled:!s(),className:"w-full px-6 py-3 mt-4 text-sm font-medium rounded-lg transition-colors flex items-center justify-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed",style:{backgroundColor:B,color:E,borderRadius:`${C}px`},children:[u.jsx(VQ,{className:"w-4 h-4"}),"إرسال"]}),u.jsx("div",{className:"mt-2 text-xs opacity-70 text-center",children:"* الحقول الإلزامية"})]})}function OW({onValidate:g,agentChatResponseColor:A,agentChatResponseBgColor:I,buttonsBgColor:B,buttonColor:E,chatRoundness:C,panelWidth:Q,inputBackgroundColor:o,formVars:w}){const[M,D]=vA.useState({nomComplet:"",numero:"",nomMachine:w?.Nom_machine||"",email:"",ville:"",typeDeProjet:""}),t=(R,U)=>{D(r=>({...r,[R]:U}))},s=()=>{g(M)},a=()=>M.nomComplet.trim()!==""&&M.numero.trim()!==""&&M.nomMachine.trim()!==""&&M.ville.trim()!=="",G={backgroundColor:OC(I,50),color:A,borderRadius:`${C}px`,border:`1px solid ${B}`};return u.jsxs("div",{className:"w-full mx-auto",style:{color:A},children:[u.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[u.jsx(Ce,{className:"w-5 h-5",style:{color:B}}),u.jsx("h2",{className:"text-lg font-semibold mt-1",children:"Formulaire XCMG"})]}),u.jsxs("div",{className:"p-4 rounded-lg space-y-4",style:{backgroundColor:I,borderRadius:`${C}px`},children:[u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(Fo,{className:"w-4 h-4"}),"Nom complet *"]}),u.jsx("input",{type:"text",value:M.nomComplet,onChange:R=>t("nomComplet",R.target.value),placeholder:"Entrez votre nom complet...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...G,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(Tr,{className:"w-4 h-4"}),"Numéro *"]}),u.jsx("input",{type:"tel",value:M.numero,onChange:R=>t("numero",R.target.value),placeholder:"Entrez votre numéro...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...G,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(qr,{className:"w-4 h-4"}),"Email"]}),u.jsx("input",{type:"email",value:M.email,onChange:R=>t("email",R.target.value),placeholder:"Entrez votre adresse email...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...G,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(HD,{className:"w-4 h-4"}),"Ville *"]}),u.jsx("input",{type:"text",value:M.ville,onChange:R=>t("ville",R.target.value),placeholder:"Entrez votre ville...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...G,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(Ce,{className:"w-4 h-4"}),"Nom machine *"]}),u.jsx("input",{type:"text",value:M.nomMachine,onChange:R=>t("nomMachine",R.target.value),placeholder:"Entrez le nom de la machine...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...G,"--tw-ring-color":B}})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(Ce,{className:"w-4 h-4"}),"Type de projet"]}),u.jsxs("select",{value:M.typeDeProjet,onChange:R=>t("typeDeProjet",R.target.value),className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...G,"--tw-ring-color":B},children:[u.jsx("option",{value:"",children:"Sélectionnez le type de projet"}),u.jsx("option",{value:"BTP",children:"BTP"}),u.jsx("option",{value:"infrastructure",children:"infrastructure"}),u.jsx("option",{value:"PME",children:"PME"}),u.jsx("option",{value:"Autre",children:"Autre"})]})]})]}),u.jsxs("button",{onClick:s,disabled:!a(),className:"w-full px-6 py-3 mt-4 text-sm font-medium rounded-lg transition-colors flex items-center justify-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed",style:{backgroundColor:B,color:E,borderRadius:`${C}px`},children:[u.jsx(VQ,{className:"w-4 h-4"}),"Envoyer"]}),u.jsx("div",{className:"mt-2 text-xs opacity-70 text-center",children:"* Champs obligatoires"})]})}const wsA=["Étudiant(e) en préparation du Bac","Titulaire du Bac (moins de 3 ans)","Étudiant(e) en études supérieures","Diplômé(e) sans emploi"];function JW({onValidate:g,agentChatResponseColor:A,agentChatResponseBgColor:I,buttonsBgColor:B,buttonColor:E,chatRoundness:C,panelWidth:Q,inputBackgroundColor:o}){const[w,M]=vA.useState(""),[D,t]=vA.useState(""),s={backgroundColor:OC(I,50),color:A,borderRadius:`${C}px`,border:`1px solid ${B}`},a=()=>{g({situation:w,ville:D})},G=()=>w.trim()!==""&&D.trim()!=="";return u.jsxs("div",{className:"w-full mx-auto",style:{color:A},children:[u.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[u.jsx(Fo,{className:"w-5 h-5",style:{color:B}}),u.jsx("h2",{className:"text-lg font-semibold mt-1",children:"Formulaire Jadara"})]}),u.jsxs("div",{className:"p-4 rounded-lg space-y-4",style:{backgroundColor:I,borderRadius:`${C}px`},children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx("label",{className:"block text-sm font-medium",children:"Choisissez votre situation actuelle *"}),u.jsx("div",{className:"grid grid-cols-1 gap-2",children:wsA.map(R=>u.jsxs("button",{type:"button",onClick:()=>M(R),className:"w-full flex items-center gap-3 px-3 py-2 text-sm",style:{background:w===R?B:OC(I,50),color:w===R?E:A,borderRadius:`${C}px`,border:`1px solid ${B}`,textAlign:"left"},children:[u.jsx("div",{style:{width:18,display:"flex",alignItems:"center",justifyContent:"center"},children:w===R?u.jsx(cj,{className:"w-4 h-4"}):u.jsx("div",{style:{width:14}})}),u.jsx("span",{className:"text-sm",children:R})]},R))})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(HD,{className:"w-4 h-4"}),"Ville *"]}),u.jsx("input",{type:"text",value:D,onChange:R=>t(R.target.value),placeholder:"Entrez votre ville...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...s,"--tw-ring-color":B}})]})]}),u.jsxs("button",{onClick:a,disabled:!G(),className:"w-full px-6 py-3 mt-4 text-sm font-medium rounded-lg transition-colors flex items-center justify-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed",style:{backgroundColor:B,color:E,borderRadius:`${C}px`},children:[u.jsx(VQ,{className:"w-4 h-4"}),"Envoyer"]}),u.jsx("div",{className:"mt-2 text-xs opacity-70 text-center",children:"* Champs obligatoires"})]})}const esA=["طالب(ة) يستعد/تستعد للباكالوريا","حاصل(ة) على الباكالوريا (منذ أقل من 3 سنوات)","طالب(ة) في التعليم العالي","خريج(ة) بدون عمل"];function HW({onValidate:g,agentChatResponseColor:A,agentChatResponseBgColor:I,buttonsBgColor:B,buttonColor:E,chatRoundness:C,panelWidth:Q,inputBackgroundColor:o}){const[w,M]=vA.useState(""),[D,t]=vA.useState(""),s={backgroundColor:OC(I,50),color:A,borderRadius:`${C}px`,border:`1px solid ${B}`,direction:"rtl",textAlign:"right"},a=()=>{g({situation:w,ville:D})},G=()=>w.trim()!==""&&D.trim()!=="";return u.jsxs("div",{className:"w-full mx-auto",style:{color:A},dir:"rtl",children:[u.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[u.jsx(Fo,{className:"w-5 h-5",style:{color:B}}),u.jsx("h2",{className:"text-lg font-semibold mt-1",children:"نموذج جدارة"})]}),u.jsxs("div",{className:"p-4 rounded-lg space-y-4",style:{backgroundColor:I,borderRadius:`${C}px`},children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx("label",{className:"block text-sm font-medium",children:"اختر وضعك الحالي *"}),u.jsx("div",{className:"grid grid-cols-1 gap-2",children:esA.map(R=>u.jsxs("button",{type:"button",onClick:()=>M(R),className:"w-full flex items-center gap-3 px-3 py-2 text-sm",style:{background:w===R?B:OC(I,50),color:w===R?E:A,borderRadius:`${C}px`,border:`1px solid ${B}`,textAlign:"right",direction:"rtl"},children:[u.jsx("div",{style:{width:18,display:"flex",alignItems:"center",justifyContent:"center"},children:w===R?u.jsx(cj,{className:"w-4 h-4"}):u.jsx("div",{style:{width:14}})}),u.jsx("span",{className:"text-sm",children:R})]},R))})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[u.jsx(HD,{className:"w-4 h-4"}),"المدينة *"]}),u.jsx("input",{type:"text",value:D,onChange:R=>t(R.target.value),placeholder:"أدخل مدينتك...",className:"w-full px-3 py-2 text-sm focus:outline-none focus:ring-2",style:{...s,"--tw-ring-color":B}})]})]}),u.jsxs("button",{onClick:a,disabled:!G(),className:"w-full px-6 py-3 mt-4 text-sm font-medium rounded-lg transition-colors flex items-center justify-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed",style:{backgroundColor:B,color:E,borderRadius:`${C}px`},children:[u.jsx(VQ,{className:"w-4 h-4"}),"إرسال"]}),u.jsx("div",{className:"mt-2 text-xs opacity-70 text-center",children:"* الحقول الإلزامية"})]})}const MsA=["Marketing digital","Développement web","Création de contenu"];function NW({onValidate:g,agentChatResponseColor:A,agentChatResponseBgColor:I,buttonsBgColor:B,buttonColor:E,chatRoundness:C,panelWidth:Q,inputBackgroundColor:o}){const[w,M]=vA.useState(""),D=t=>{M(t),g({Domaines_qui_vous_interessent:t})};return u.jsxs("div",{className:"w-full mx-auto",style:{color:A},children:[u.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[u.jsx(JIA,{className:"w-5 h-5",style:{color:B}}),u.jsx("h2",{className:"text-lg font-semibold mt-1",children:"Domaines d'intérêt"})]}),u.jsx("div",{className:"p-3 rounded-lg space-y-3",style:{backgroundColor:I,borderRadius:`${C}px`},children:u.jsxs("div",{className:"space-y-2",children:[u.jsx("label",{className:"block text-sm font-medium",children:"Domaines qui vous intéressent"}),u.jsx("div",{className:"grid grid-cols-1 gap-2",children:MsA.map(t=>u.jsxs("button",{type:"button",onClick:()=>D(t),className:"w-full flex items-center gap-3 px-3 py-2 text-sm",style:{background:w===t?B:OC(I,50),color:w===t?E:A,borderRadius:`${C}px`,border:`1px solid ${B}`,textAlign:"left"},children:[u.jsx("div",{style:{width:18,display:"flex",alignItems:"center",justifyContent:"center"},children:w===t?u.jsx(VQ,{className:"w-4 h-4"}):u.jsx("div",{style:{width:14}})}),u.jsx("span",{className:"text-sm",children:t})]},t))})]})})]})}function BG({products:g,onValidate:A,agentChatResponseColor:I,agentChatResponseBgColor:B,buttonsBgColor:E,buttonColor:C,chatRoundness:Q,panelWidth:o,inputBackgroundColor:w}){const[M,D]=vA.useState({}),[t,s]=vA.useState(!1),[a,G]=vA.useState(0),R=o<700,U=o>=1300,r=Math.ceil((g?.length||0)/(R?1:U?3:2)),l=()=>{G(W=>(W+1)%r)},K=()=>{G(W=>(W-1+r)%r)},m=W=>{G(W)},x=W=>{D(T=>({...T,[W]:(T[W]||0)+1}))},O=W=>{D(T=>{const X={...T};return X[W]>1?X[W]-=1:delete X[W],X})},y=()=>Object.entries(M).map(([W,T])=>({id_produit:W,quantite:T})),L=()=>Object.values(M).reduce((W,T)=>W+T,0),j=()=>{const T={products:y()};A(T)},z=()=>Object.entries(M).map(([W,T])=>({product:g.find(P=>P.id===W),quantity:T})).filter(W=>W.product),d=()=>z().reduce((W,{product:T,quantity:X})=>W+T.price*X,0),Z=()=>{const W=[];for(let T=0;T<g.length;T+=R?1:U?3:2)W.push(g.slice(T,T+(R?1:U?3:2)));return W};return u.jsxs("div",{className:"w-full mx-auto",style:{color:I},children:[u.jsxs("div",{className:"flex items-center justify-between mb-4",children:[u.jsx("h2",{className:"text-lg font-semibold",children:"Produits Disponibles"}),L()>0&&u.jsxs("button",{onClick:()=>s(!t),className:"flex items-center gap-2 px-3 py-2 rounded-lg transition-colors",style:{backgroundColor:E+"20",color:C,borderRadius:`${Q}px`},children:[u.jsx(VIA,{className:"w-4 h-4"}),u.jsxs("div",{className:"flex flex-col items-end text-xs",children:[u.jsxs("span",{children:[L()," articles"]}),u.jsx("span",{children:d()>0?`${d().toFixed(2)} DH`:""})]})]})]}),u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"relative overflow-hidden mb-6",children:[u.jsx("div",{className:"flex transition-transform duration-300 ease-in-out",style:{transform:`translateX(-${a*100}%)`},children:Z().map((W,T)=>u.jsx("div",{className:`w-full flex-shrink-0 grid ${R?"grid-cols-1":U&&g.length>=3?"grid-cols-3":"grid-cols-2"} gap-4 p-2`,children:W.map(X=>u.jsxs("div",{className:"p-4 rounded-lg border border-opacity-20",style:{backgroundColor:B+"40",borderColor:I,borderRadius:`${Q}px`},children:[u.jsx("div",{className:"relative w-full h-40 mb-3 rounded-md overflow-hidden",children:u.jsx("img",{src:X?.image??"",alt:X.nomProduit,className:"w-full h-full object-contain bg-gray-100"})}),u.jsx("h3",{className:"font-semibold text-sm mb-2",style:{color:I},children:X.nomProduit}),u.jsx("p",{className:"text-xs text-opacity-70 mb-2 line-clamp-2",style:{color:I},title:X.description,children:X.description}),u.jsxs("div",{className:"flex items-center justify-between gap-4",children:[u.jsxs("div",{className:"text-xs",style:{color:I},children:[X.stock>0?"In Stock":"Out of stock",u.jsx("br",{}),"Prix: ",X.price!=0?`${X.price} DH`:"-"]}),u.jsx("div",{className:"flex items-center gap-2",children:M[X.id]?u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("button",{onClick:()=>O(X.id),className:"w-8 h-8 rounded-full flex items-center justify-center transition-colors",style:{backgroundColor:E+"80",color:C},children:u.jsx(Zr,{className:"w-4 h-4"})}),u.jsx("span",{className:"min-w-[20px] text-center text-sm font-semibold",children:M[X.id]}),u.jsx("button",{onClick:()=>x(X.id),disabled:M[X.id]>=X.stock,className:"w-8 h-8 rounded-full flex items-center justify-center transition-colors disabled:opacity-50",style:{backgroundColor:E,color:C},children:u.jsx(fs,{className:"w-4 h-4"})})]}):u.jsx("button",{onClick:()=>x(X.id),disabled:X.stock===0,className:"px-3 py-1 text-xs rounded-lg transition-colors disabled:opacity-50",style:{backgroundColor:E,color:C,borderRadius:`${Q}px`},children:X.price===0?"Ajouter au devis":"Ajouter au panier"})})]})]},X.id))},T))}),r>1&&u.jsxs(u.Fragment,{children:[a>0&&u.jsx("button",{onClick:K,className:"absolute left-0 top-24 w-8 h-8 rounded-full flex items-center justify-center transition-all duration-200 hover:scale-110 shadow-lg backdrop-blur-sm",style:{backgroundColor:`${E}CC`,color:C},children:u.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})})}),a<r-1&&u.jsx("button",{onClick:l,className:"absolute right-0 top-24 w-8 h-8 rounded-full flex items-center justify-center transition-all duration-200 hover:scale-110 shadow-lg backdrop-blur-sm",style:{backgroundColor:`${E}CC`,color:C},children:u.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})})]})]}),r>1&&u.jsx("div",{className:"flex justify-center space-x-2 mt-3",children:Array.from({length:r}).map((W,T)=>u.jsx("button",{onClick:()=>m(T),className:`w-2 h-2 rounded-full transition-all duration-200 ${T===a?"scale-125 opacity-100":"opacity-40 hover:opacity-70"}`,style:{backgroundColor:E}},T))})]}),t&&L()>0&&u.jsxs("div",{className:"mt-3 p-4 rounded-lg border border-opacity-20 mb-4",style:{backgroundColor:B+"60",borderColor:I,borderRadius:`${Q}px`},children:[u.jsxs("h3",{className:"font-semibold mb-3",children:["Produits sélectionnés: (",L()," articles)"]}),u.jsx("div",{className:"space-y-2",children:z().map(({product:W,quantity:T})=>u.jsxs("div",{className:"flex justify-between items-center text-sm",children:[u.jsxs("div",{className:"flex-1",children:[u.jsx("div",{children:W.nomProduit}),u.jsx("div",{className:"text-xs opacity-70",children:W.price>0?`${W.price.toFixed(2)} DH × ${T}`:`× ${T}`})]}),u.jsx("span",{className:"ml-2 font-medium",children:W.price*T>0?`${(W.price*T).toFixed(2)} DH`:""})]},W.id))}),d()>0&&u.jsx("div",{className:"border-t border-opacity-30 mt-3 pt-3",style:{borderColor:I},children:u.jsxs("div",{className:"flex justify-between items-center font-semibold",children:[u.jsx("span",{children:"Total:"}),u.jsxs("span",{children:[d().toFixed(2)," DH"]})]})})]}),L()>0&&u.jsxs("button",{onClick:j,className:"w-full px-6 py-3 mt-3 text-sm font-medium rounded-lg transition-colors flex items-center justify-center gap-2",style:{backgroundColor:E,color:C,borderRadius:`${Q}px`},children:[u.jsx(VQ,{className:"w-4 h-4"}),"Valider la sélection (",L()," articles) ",d()!==0?`- ${d().toFixed(2)} DH`:""]})]})}const DsA=({options:g,message:A,allowMultiple:I,chatRoundness:B,buttonsBgColor:E,buttonColor:C,agentChatResponseColor:Q,agentChatResponseBgColor:o,isRtl:w,onSend:M,onScroll:D})=>{const[t,s]=vA.useState([]),a=o?OC(o,10):E,G=U=>{I?s(r=>r.includes(U)?r.filter(K=>K!==U):[...r,U]):M(U)},R=()=>{t.length>0&&(M(t.join(",")),s([]))};return u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"mt-2 flex flex-col",dir:w?"rtl":"ltr",children:g?.map((U,r)=>{const l=I&&t.includes(U.value);return u.jsxs("button",{className:"w-full mb-1 flex items-center justify-between px-4 py-2.5 hover:opacity-95 transition-all duration-100",dir:aw(U.label)?"rtl":"ltr",onClick:()=>G(U.value),onMouseEnter:K=>{K.currentTarget.style.borderColor=`${E}`},onMouseLeave:K=>{const m=l?E:OC(a,20);K.currentTarget.style.border=`2px solid ${m}`},style:{background:l?`linear-gradient(135deg, ${E}, ${E}DD)`:a,borderRadius:"18px",color:Q,border:`2px solid ${OC(a,20)}`,opacity:l?.95:1,transform:l?"scale(0.99)":"scale(1)"},children:[u.jsxs("div",{className:"flex items-center gap-2 w-full",children:[I&&l&&u.jsx(VQ,{className:"w-4 h-4 flex-shrink-0"}),u.jsx(cE,{sequence:[U.label,0,D],cursor:!1,speed:90})]}),u.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center"},children:aw(U.label)?u.jsx(tj,{className:"w-4 h-4"}):u.jsx(aj,{className:"w-4 h-4"})})]},r)})}),I&&t.length>0&&u.jsx("div",{className:"mt-3 flex justify-end",dir:w?"rtl":"ltr",children:u.jsxs("button",{onClick:R,className:"px-6 py-2 font-semibold hover:scale-105 transition-all duration-200 flex items-center gap-2",style:{background:`linear-gradient(135deg, ${E}, ${E}AA)`,borderRadius:`${B}px`,color:C},children:[u.jsx(Gj,{className:"w-4 h-4"}),u.jsxs("span",{children:["Send (",t.length,")"]})]})})]})},r4=({items:g,chatRoundness:A,agentChatResponseBgColor:I,agentChatResponseColor:B,buttonsBgColor:E,buttonColor:C,inputBackgroundColor:Q,onButtonClick:o,setMessages:w})=>{const[M,D]=vA.useState(0),t=g?.length||0,s=()=>{D(R=>(R+1)%t)},a=()=>{D(R=>(R-1+t)%t)},G=R=>{D(R)};return u.jsx("div",{className:"mt-2 w-full",children:u.jsxs("div",{className:"relative max-w-md mx-auto",children:[u.jsx("div",{className:"overflow-hidden rounded-lg",style:{borderRadius:`${A}px`},children:u.jsx("div",{className:"flex transition-transform duration-300 ease-in-out",style:{transform:`translateX(-${M*100}%)`},children:g?.map((R,U)=>u.jsxs("div",{className:"w-full flex-shrink-0 px-2",style:{background:I},children:[u.jsxs("div",{className:"relative h-40 w-full mb-3 ",children:[u.jsx("img",{src:R.image,alt:R.title,className:"size-full object-cover rounded-lg"}),t>1&&u.jsxs(u.Fragment,{children:[M>0&&u.jsx("button",{onClick:a,className:"absolute -left-2 top-1/2 -translate-y-1/2 w-8 h-8 rounded-full flex items-center justify-center transition-all duration-200 hover:scale-110 shadow-lg backdrop-blur-sm",style:{backgroundColor:`${E}CC`,color:C},children:u.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})})}),M<t-1&&u.jsx("button",{onClick:s,className:"absolute -right-2 top-1/2 -translate-y-1/2 w-8 h-8 rounded-full flex items-center justify-center transition-all duration-200 hover:scale-110 shadow-lg backdrop-blur-sm",style:{backgroundColor:`${E}CC`,color:C},children:u.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})})]})]}),u.jsx("h3",{className:"text-sm font-bold mb-2",style:{color:B},children:R.title}),u.jsx("p",{className:"text-xs mb-3 leading-relaxed",style:{color:B},children:R.subtitle}),u.jsx("div",{className:"space-y-2",children:R.actions?.map((r,l)=>u.jsx("button",{className:"w-full px-4 py-2 text-sm font-medium hover:scale-[0.98] transition-all duration-200",onClick:()=>{r.action==="link"||r.action==="Open URL"?window.open(r.url,"_blank"):r.action==="postback"||r.action==="Postback"?o(r.title,r.payload):r.action==="say-something"&&typeof r.action=="string"&&w(K=>[...K,{sender:"agent",content:r.payload,id:`msg-${Date.now()}`,timestamp:new Date,seen:!0}])},style:{background:E,borderRadius:`${A}px`,color:C},children:r.title},l))})]},U))})}),t>1&&u.jsxs("div",{className:"absolute top-2 right-2 px-2 py-1 text-xs font-medium rounded-full backdrop-blur-sm",style:{backgroundColor:`${Q}CC`,color:B},children:[M+1," / ",t]}),t>1&&u.jsx("div",{className:"flex justify-center space-x-2 mt-3",children:g?.map((R,U)=>u.jsx("button",{onClick:()=>G(U),className:`w-2 h-2 rounded-full transition-all duration-200 ${U===M?"scale-125 opacity-100":"opacity-40 hover:opacity-70"}`,style:{backgroundColor:E}},U))})]})})};function MC(g,A,I,B){return new(I||(I=Promise))(function(E,C){function Q(M){try{w(B.next(M))}catch(D){C(D)}}function o(M){try{w(B.throw(M))}catch(D){C(D)}}function w(M){var D;M.done?E(M.value):(D=M.value,D instanceof I?D:new I(function(t){t(D)})).then(Q,o)}w((B=B.apply(g,A||[])).next())})}typeof SuppressedError=="function"&&SuppressedError;let Xt=class{constructor(){this.listeners={}}on(A,I,B){if(this.listeners[A]||(this.listeners[A]=new Set),this.listeners[A].add(I),B?.once){const E=()=>{this.un(A,E),this.un(A,I)};return this.on(A,E),E}return()=>this.un(A,I)}un(A,I){var B;(B=this.listeners[A])===null||B===void 0||B.delete(I)}once(A,I){return this.on(A,I,{once:!0})}unAll(){this.listeners={}}emit(A,...I){this.listeners[A]&&this.listeners[A].forEach(B=>B(...I))}};const EG={decode:function(g,A){return MC(this,void 0,void 0,function*(){const I=new AudioContext({sampleRate:A});return I.decodeAudioData(g).finally(()=>I.close())})},createBuffer:function(g,A){return typeof g[0]=="number"&&(g=[g]),function(I){const B=I[0];if(B.some(E=>E>1||E<-1)){const E=B.length;let C=0;for(let Q=0;Q<E;Q++){const o=Math.abs(B[Q]);o>C&&(C=o)}for(const Q of I)for(let o=0;o<E;o++)Q[o]/=C}}(g),{duration:A,length:g[0].length,sampleRate:g[0].length/A,numberOfChannels:g.length,getChannelData:I=>g?.[I],copyFromChannel:AudioBuffer.prototype.copyFromChannel,copyToChannel:AudioBuffer.prototype.copyToChannel}}};function xW(g,A){const I=A.xmlns?document.createElementNS(A.xmlns,g):document.createElement(g);for(const[B,E]of Object.entries(A))if(B==="children"&&E)for(const[C,Q]of Object.entries(E))Q instanceof Node?I.appendChild(Q):typeof Q=="string"?I.appendChild(document.createTextNode(Q)):I.appendChild(xW(C,Q));else B==="style"?Object.assign(I.style,E):B==="textContent"?I.textContent=E:I.setAttribute(B,E.toString());return I}function dW(g,A,I){const B=xW(g,A||{});return I?.appendChild(B),B}var hsA=Object.freeze({__proto__:null,createElement:dW,default:dW});const tsA={fetchBlob:function(g,A,I){return MC(this,void 0,void 0,function*(){const B=yield fetch(g,I);if(B.status>=400)throw new Error(`Failed to fetch ${g}: ${B.status} (${B.statusText})`);return function(E,C){MC(this,void 0,void 0,function*(){if(!E.body||!E.headers)return;const Q=E.body.getReader(),o=Number(E.headers.get("Content-Length"))||0;let w=0;const M=t=>MC(this,void 0,void 0,function*(){w+=t?.length||0;const s=Math.round(w/o*100);C(s)}),D=()=>MC(this,void 0,void 0,function*(){let t;try{t=yield Q.read()}catch{return}t.done||(M(t.value),yield D())});D()})}(B.clone(),A),B.blob()})}};let asA=class extends Xt{constructor(A){super(),this.isExternalMedia=!1,A.media?(this.media=A.media,this.isExternalMedia=!0):this.media=document.createElement("audio"),A.mediaControls&&(this.media.controls=!0),A.autoplay&&(this.media.autoplay=!0),A.playbackRate!=null&&this.onMediaEvent("canplay",()=>{A.playbackRate!=null&&(this.media.playbackRate=A.playbackRate)},{once:!0})}onMediaEvent(A,I,B){return this.media.addEventListener(A,I,B),()=>this.media.removeEventListener(A,I,B)}getSrc(){return this.media.currentSrc||this.media.src||""}revokeSrc(){const A=this.getSrc();A.startsWith("blob:")&&URL.revokeObjectURL(A)}canPlayType(A){return this.media.canPlayType(A)!==""}setSrc(A,I){const B=this.getSrc();if(A&&B===A)return;this.revokeSrc();const E=I instanceof Blob&&(this.canPlayType(I.type)||!A)?URL.createObjectURL(I):A;if(B&&this.media.removeAttribute("src"),E||A)try{this.media.src=E}catch{this.media.src=A}}destroy(){this.isExternalMedia||(this.media.pause(),this.media.remove(),this.revokeSrc(),this.media.removeAttribute("src"),this.media.load())}setMediaElement(A){this.media=A}play(){return MC(this,void 0,void 0,function*(){try{return yield this.media.play()}catch(A){if(A instanceof DOMException&&A.name==="AbortError")return;throw A}})}pause(){this.media.pause()}isPlaying(){return!this.media.paused&&!this.media.ended}setTime(A){this.media.currentTime=Math.max(0,Math.min(A,this.getDuration()))}getDuration(){return this.media.duration}getCurrentTime(){return this.media.currentTime}getVolume(){return this.media.volume}setVolume(A){this.media.volume=A}getMuted(){return this.media.muted}setMuted(A){this.media.muted=A}getPlaybackRate(){return this.media.playbackRate}isSeeking(){return this.media.seeking}setPlaybackRate(A,I){I!=null&&(this.media.preservesPitch=I),this.media.playbackRate=A}getMediaElement(){return this.media}setSinkId(A){return this.media.setSinkId(A)}},n4=class rN extends Xt{constructor(A,I){super(),this.timeouts=[],this.isScrollable=!1,this.audioData=null,this.resizeObserver=null,this.lastContainerWidth=0,this.isDragging=!1,this.subscriptions=[],this.unsubscribeOnScroll=[],this.subscriptions=[],this.options=A;const B=this.parentFromOptionsContainer(A.container);this.parent=B;const[E,C]=this.initHtml();B.appendChild(E),this.container=E,this.scrollContainer=C.querySelector(".scroll"),this.wrapper=C.querySelector(".wrapper"),this.canvasWrapper=C.querySelector(".canvases"),this.progressWrapper=C.querySelector(".progress"),this.cursor=C.querySelector(".cursor"),I&&C.appendChild(I),this.initEvents()}parentFromOptionsContainer(A){let I;if(typeof A=="string"?I=document.querySelector(A):A instanceof HTMLElement&&(I=A),!I)throw new Error("Container not found");return I}initEvents(){const A=I=>{const B=this.wrapper.getBoundingClientRect(),E=I.clientX-B.left,C=I.clientY-B.top;return[E/B.width,C/B.height]};if(this.wrapper.addEventListener("click",I=>{const[B,E]=A(I);this.emit("click",B,E)}),this.wrapper.addEventListener("dblclick",I=>{const[B,E]=A(I);this.emit("dblclick",B,E)}),this.options.dragToSeek!==!0&&typeof this.options.dragToSeek!="object"||this.initDrag(),this.scrollContainer.addEventListener("scroll",()=>{const{scrollLeft:I,scrollWidth:B,clientWidth:E}=this.scrollContainer,C=I/B,Q=(I+E)/B;this.emit("scroll",C,Q,I,I+E)}),typeof ResizeObserver=="function"){const I=this.createDelay(100);this.resizeObserver=new ResizeObserver(()=>{I().then(()=>this.onContainerResize()).catch(()=>{})}),this.resizeObserver.observe(this.scrollContainer)}}onContainerResize(){const A=this.parent.clientWidth;A===this.lastContainerWidth&&this.options.height!=="auto"||(this.lastContainerWidth=A,this.reRender())}initDrag(){this.subscriptions.push(function(A,I,B,E,C=3,Q=0,o=100){if(!A)return()=>{};const w=matchMedia("(pointer: coarse)").matches;let M=()=>{};const D=t=>{if(t.button!==Q)return;t.preventDefault(),t.stopPropagation();let s=t.clientX,a=t.clientY,G=!1;const R=Date.now(),U=x=>{if(x.preventDefault(),x.stopPropagation(),w&&Date.now()-R<o)return;const O=x.clientX,y=x.clientY,L=O-s,j=y-a;if(G||Math.abs(L)>C||Math.abs(j)>C){const z=A.getBoundingClientRect(),{left:d,top:Z}=z;G||(B?.(s-d,a-Z),G=!0),I(L,j,O-d,y-Z),s=O,a=y}},r=x=>{if(G){const O=x.clientX,y=x.clientY,L=A.getBoundingClientRect(),{left:j,top:z}=L;E?.(O-j,y-z)}M()},l=x=>{x.relatedTarget&&x.relatedTarget!==document.documentElement||r(x)},K=x=>{G&&(x.stopPropagation(),x.preventDefault())},m=x=>{G&&x.preventDefault()};document.addEventListener("pointermove",U),document.addEventListener("pointerup",r),document.addEventListener("pointerout",l),document.addEventListener("pointercancel",l),document.addEventListener("touchmove",m,{passive:!1}),document.addEventListener("click",K,{capture:!0}),M=()=>{document.removeEventListener("pointermove",U),document.removeEventListener("pointerup",r),document.removeEventListener("pointerout",l),document.removeEventListener("pointercancel",l),document.removeEventListener("touchmove",m),setTimeout(()=>{document.removeEventListener("click",K,{capture:!0})},10)}};return A.addEventListener("pointerdown",D),()=>{M(),A.removeEventListener("pointerdown",D)}}(this.wrapper,(A,I,B)=>{this.emit("drag",Math.max(0,Math.min(1,B/this.wrapper.getBoundingClientRect().width)))},A=>{this.isDragging=!0,this.emit("dragstart",Math.max(0,Math.min(1,A/this.wrapper.getBoundingClientRect().width)))},A=>{this.isDragging=!1,this.emit("dragend",Math.max(0,Math.min(1,A/this.wrapper.getBoundingClientRect().width)))}))}getHeight(A,I){var B;const E=((B=this.audioData)===null||B===void 0?void 0:B.numberOfChannels)||1;if(A==null)return 128;if(!isNaN(Number(A)))return Number(A);if(A==="auto"){const C=this.parent.clientHeight||128;return I?.every(Q=>!Q.overlay)?C/E:C}return 128}initHtml(){const A=document.createElement("div"),I=A.attachShadow({mode:"open"}),B=this.options.cspNonce&&typeof this.options.cspNonce=="string"?this.options.cspNonce.replace(/"/g,""):"";return I.innerHTML=`
551
551
  <style${B?` nonce="${B}"`:""}>
552
552
  :host {
553
553
  user-select: none;
@@ -632,7 +632,7 @@ end`};A.events.push(["putFont",function(C){(function(Q){var o=Q.font,w=Q.out,M=Q
632
632
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
633
633
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
634
634
  PERFORMANCE OF THIS SOFTWARE.
635
- ***************************************************************************** */function jW(g,A){const[I,B]=vA.useState(null),E=vA.useMemo(()=>Object.entries(A).flat(),[A]);return vA.useEffect(()=>{if(!g?.current)return;const C=U4.create(Object.assign(Object.assign({},A),{container:g.current}));return B(C),()=>{C.destroy()}},[g,...E]),I}const pW=/^on([A-Z])/,GsA=g=>pW.test(g);function YsA(g,A){const I=vA.useMemo(()=>Object.entries(A).flat(),[A]);vA.useEffect(()=>{if(!g)return;const B=Object.entries(A);if(!B.length)return;const E=B.map(([C,Q])=>{const o=C.replace(pW,(w,M)=>M.toLowerCase());return g.on(o,(...w)=>Q(g,...w))});return()=>{E.forEach(C=>C())}},[g,...I])}vA.memo(g=>{const A=vA.useRef(null),[I,B]=function(E){return vA.useMemo(()=>{const C=Object.assign({},E),Q=Object.assign({},E);for(const o in C)GsA(o)?delete C[o]:delete Q[o];return[C,Q]},[E])}(g);return YsA(jW(A,I),B),u.jsx("div",{ref:A})});function RsA(g){var{container:A}=g;const I=jW(A,function(E,C){var Q={};for(var o in E)Object.prototype.hasOwnProperty.call(E,o)&&C.indexOf(o)<0&&(Q[o]=E[o]);if(E!=null&&typeof Object.getOwnPropertySymbols=="function"){var w=0;for(o=Object.getOwnPropertySymbols(E);w<o.length;w++)C.indexOf(o[w])<0&&Object.prototype.propertyIsEnumerable.call(E,o[w])&&(Q[o[w]]=E[o[w]])}return Q}(g,["container"])),B=function(E){const[C,Q]=vA.useState(!1),[o,w]=vA.useState(!1),[M,D]=vA.useState(!1),[t,s]=vA.useState(0);return vA.useEffect(()=>{if(!E)return;const a=[E.on("load",()=>{Q(!1),w(!1),s(0)}),E.on("ready",()=>{Q(!0),w(!1),D(!1),s(0)}),E.on("finish",()=>{D(!0)}),E.on("play",()=>{w(!0)}),E.on("pause",()=>{w(!1)}),E.on("timeupdate",()=>{s(E.getCurrentTime())}),E.on("destroy",()=>{Q(!1),w(!1)})];return()=>{a.forEach(G=>G())}},[E]),vA.useMemo(()=>({isReady:C,isPlaying:o,hasFinished:M,currentTime:t}),[o,M,t,C])}(I);return vA.useMemo(()=>Object.assign(Object.assign({},B),{wavesurfer:I}),[B,I])}const yW=({src:g,mainColor:A,secondaryColor:I,controlsColor:B})=>{const E=vA.useRef(null),[C,Q]=vA.useState(1),{wavesurfer:o,isPlaying:w}=RsA({container:E,waveColor:A,progressColor:I,barWidth:2,height:50,url:g}),M=()=>{o&&o.playPause()},D=()=>{const a=C===0?1:0;Q(a),o?.setVolume(a)},t=()=>{o?.skip(-.096)},s=()=>{o?.skip(.096)};return u.jsxs("div",{className:"flex w-full flex-col items-center rounded-xl pt-1",children:[u.jsx("div",{ref:E,className:"w-full px-2"}),u.jsxs("div",{className:"flex w-full items-center justify-between",children:[u.jsx("div",{className:"relative flex items-center",children:u.jsx("button",{className:"transition-colors",style:{color:B},onClick:D,"aria-label":"Toggle volume",children:C===0?u.jsx(WIA,{size:20}):u.jsx(TIA,{size:20})})}),u.jsxs("div",{className:"-ml-9 flex flex-1 cursor-auto justify-center gap-2 rounded-full py-2 text-white",children:[u.jsx("button",{onClick:t,className:"cursor-pointer hover:scale-110 transition-colors",style:{color:B},"aria-label":"Step back",children:u.jsx(qIA,{})}),u.jsx("button",{onClick:M,className:"cursor-pointer hover:scale-110 transition-colors",style:{color:B},"aria-label":w?"Pause":"Play",children:w?u.jsx(jIA,{}):u.jsx(pIA,{})}),u.jsx("button",{onClick:s,className:"cursor-pointer hover:scale-110 transition-colors",style:{color:B},"aria-label":"Step forward",children:u.jsx(ZIA,{})})]})]})]})},rsA=({attachment:g,formatFileSize:A,mainColor:I,secondaryColor:B,controlsColor:E})=>{const{type:C,url:Q,name:o,size:w}=g;switch(C){case"image":return u.jsxs("div",{className:"relative group",children:[u.jsx("img",{src:Q,alt:o,className:"max-w-xs max-h-48 size-full rounded-lg object-cover cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>window.open(Q,"_blank")}),u.jsx("div",{className:"absolute bottom-2 left-2 bg-black bg-opacity-60 text-white text-xs px-2 py-1 rounded",children:A(w)})]});case"video":return u.jsxs("div",{className:"max-w-xs",children:[u.jsx("video",{src:Q,controls:!0,className:"w-full max-h-48 rounded-lg",preload:"metadata",onError:()=>{console.error("Video failed to load:",Q)},children:"Your browser does not support the video tag."}),u.jsxs("div",{className:"flex text-xs text-white mt-1 w-full overflow-hidden whitespace-nowrap text-ellipsis",children:[u.jsx("span",{className:"block w-full overflow-hidden whitespace-nowrap text-ellipsis",title:o,children:o}),u.jsxs("span",{className:"ml-2",children:["• ",A(w)]})]})]});case"audio":return u.jsxs("div",{className:"bg-gray-800 bg-opacity-70 p-3 rounded-lg flex-1 w-full",children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[u.jsx(zr,{className:"w-4 h-4",style:{color:I}}),u.jsx("span",{className:"text-sm font-medium truncate text-white",title:o,children:o})]}),u.jsx(yW,{src:Q,mainColor:I,secondaryColor:B,controlsColor:E}),u.jsx("p",{className:"text-xs text-gray-400 mt-1",children:A(w)})]});case"document":return u.jsx("div",{className:"bg-gray-800 bg-opacity-50 p-3 rounded-lg max-w-xs cursor-pointer hover:bg-opacity-70 transition-colors",onClick:()=>window.open(Q,"_blank"),children:u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsx("div",{className:"w-10 h-10 bg-purple-600 rounded-lg flex items-center justify-center",children:u.jsx(Ce,{className:"w-5 h-5 text-white"})}),u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsx("p",{className:"text-sm font-medium truncate text-white",children:o}),u.jsx("p",{className:"text-xs text-gray-400",children:A(w)})]})]})});default:return null}},nsA=vA.memo(({attachment:g,onRemove:A})=>u.jsxs("div",{className:"relative group w-24 h-24 rounded-xl overflow-hidden bg-gray-900 shadow-md border border-gray-700",children:[g.type==="image"&&g.url?u.jsx("img",{src:g.url,alt:g.name,className:"w-full h-full object-cover"}):u.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center text-gray-300 px-1 text-center text-xs",children:[g.type==="video"&&u.jsx(Rj,{className:"w-5 h-5 mb-1 text-red-400"}),g.type==="audio"&&u.jsx(zr,{className:"w-5 h-5 mb-1 text-green-400"}),g.type==="document"&&u.jsx(sj,{className:"w-5 h-5 mb-1 text-yellow-400"}),u.jsx("span",{className:"w-full truncate",title:g.name,children:g.name})]}),u.jsx("button",{onClick:A,className:"absolute top-1 right-1 w-5 h-5 bg-black bg-opacity-50 rounded-full text-white flex items-center justify-center hover:bg-opacity-80",title:"Remove",children:u.jsx(Qe,{className:"w-3 h-3"})})]})),No=Object.create(null);No.open="0",No.close="1",No.ping="2",No.pong="3",No.message="4",No.upgrade="5",No.noop="6";const CG=Object.create(null);Object.keys(No).forEach(g=>{CG[No[g]]=g});const l4={type:"error",data:"parser error"},LW=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",VW=typeof ArrayBuffer=="function",qW=g=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(g):g&&g.buffer instanceof ArrayBuffer,K4=({type:g,data:A},I,B)=>LW&&A instanceof Blob?I?B(A):ZW(A,B):VW&&(A instanceof ArrayBuffer||qW(A))?I?B(A):ZW(new Blob([A]),B):B(No[g]+(A||"")),ZW=(g,A)=>{const I=new FileReader;return I.onload=function(){const B=I.result.split(",")[1];A("b"+(B||""))},I.readAsDataURL(g)};function zW(g){return g instanceof Uint8Array?g:g instanceof ArrayBuffer?new Uint8Array(g):new Uint8Array(g.buffer,g.byteOffset,g.byteLength)}let S4;function FsA(g,A){if(LW&&g.data instanceof Blob)return g.data.arrayBuffer().then(zW).then(A);if(VW&&(g.data instanceof ArrayBuffer||qW(g.data)))return A(zW(g.data));K4(g,!1,I=>{S4||(S4=new TextEncoder),A(S4.encode(I))})}const TW="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",vt=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let g=0;g<TW.length;g++)vt[TW.charCodeAt(g)]=g;const UsA=g=>{let A=g.length*.75,I=g.length,B,E=0,C,Q,o,w;g[g.length-1]==="="&&(A--,g[g.length-2]==="="&&A--);const M=new ArrayBuffer(A),D=new Uint8Array(M);for(B=0;B<I;B+=4)C=vt[g.charCodeAt(B)],Q=vt[g.charCodeAt(B+1)],o=vt[g.charCodeAt(B+2)],w=vt[g.charCodeAt(B+3)],D[E++]=C<<2|Q>>4,D[E++]=(Q&15)<<4|o>>2,D[E++]=(o&3)<<6|w&63;return M},lsA=typeof ArrayBuffer=="function",u4=(g,A)=>{if(typeof g!="string")return{type:"message",data:WW(g,A)};const I=g.charAt(0);return I==="b"?{type:"message",data:KsA(g.substring(1),A)}:CG[I]?g.length>1?{type:CG[I],data:g.substring(1)}:{type:CG[I]}:l4},KsA=(g,A)=>{if(lsA){const I=UsA(g);return WW(I,A)}else return{base64:!0,data:g}},WW=(g,A)=>{switch(A){case"blob":return g instanceof Blob?g:new Blob([g]);case"arraybuffer":default:return g instanceof ArrayBuffer?g:g.buffer}},bW="",SsA=(g,A)=>{const I=g.length,B=new Array(I);let E=0;g.forEach((C,Q)=>{K4(C,!1,o=>{B[Q]=o,++E===I&&A(B.join(bW))})})},usA=(g,A)=>{const I=g.split(bW),B=[];for(let E=0;E<I.length;E++){const C=u4(I[E],A);if(B.push(C),C.type==="error")break}return B};function msA(){return new TransformStream({transform(g,A){FsA(g,I=>{const B=I.length;let E;if(B<126)E=new Uint8Array(1),new DataView(E.buffer).setUint8(0,B);else if(B<65536){E=new Uint8Array(3);const C=new DataView(E.buffer);C.setUint8(0,126),C.setUint16(1,B)}else{E=new Uint8Array(9);const C=new DataView(E.buffer);C.setUint8(0,127),C.setBigUint64(1,BigInt(B))}g.data&&typeof g.data!="string"&&(E[0]|=128),A.enqueue(E),A.enqueue(I)})}})}let m4;function QG(g){return g.reduce((A,I)=>A+I.length,0)}function iG(g,A){if(g[0].length===A)return g.shift();const I=new Uint8Array(A);let B=0;for(let E=0;E<A;E++)I[E]=g[0][B++],B===g[0].length&&(g.shift(),B=0);return g.length&&B<g[0].length&&(g[0]=g[0].slice(B)),I}function ksA(g,A){m4||(m4=new TextDecoder);const I=[];let B=0,E=-1,C=!1;return new TransformStream({transform(Q,o){for(I.push(Q);;){if(B===0){if(QG(I)<1)break;const w=iG(I,1);C=(w[0]&128)===128,E=w[0]&127,E<126?B=3:E===126?B=1:B=2}else if(B===1){if(QG(I)<2)break;const w=iG(I,2);E=new DataView(w.buffer,w.byteOffset,w.length).getUint16(0),B=3}else if(B===2){if(QG(I)<8)break;const w=iG(I,8),M=new DataView(w.buffer,w.byteOffset,w.length),D=M.getUint32(0);if(D>Math.pow(2,21)-1){o.enqueue(l4);break}E=D*Math.pow(2,32)+M.getUint32(4),B=3}else{if(QG(I)<E)break;const w=iG(I,E);o.enqueue(u4(C?w:m4.decode(w),A)),B=0}if(E===0||E>g){o.enqueue(l4);break}}}})}const PW=4;function jE(g){if(g)return OsA(g)}function OsA(g){for(var A in jE.prototype)g[A]=jE.prototype[A];return g}jE.prototype.on=jE.prototype.addEventListener=function(g,A){return this._callbacks=this._callbacks||{},(this._callbacks["$"+g]=this._callbacks["$"+g]||[]).push(A),this},jE.prototype.once=function(g,A){function I(){this.off(g,I),A.apply(this,arguments)}return I.fn=A,this.on(g,I),this},jE.prototype.off=jE.prototype.removeListener=jE.prototype.removeAllListeners=jE.prototype.removeEventListener=function(g,A){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var I=this._callbacks["$"+g];if(!I)return this;if(arguments.length==1)return delete this._callbacks["$"+g],this;for(var B,E=0;E<I.length;E++)if(B=I[E],B===A||B.fn===A){I.splice(E,1);break}return I.length===0&&delete this._callbacks["$"+g],this},jE.prototype.emit=function(g){this._callbacks=this._callbacks||{};for(var A=new Array(arguments.length-1),I=this._callbacks["$"+g],B=1;B<arguments.length;B++)A[B-1]=arguments[B];if(I){I=I.slice(0);for(var B=0,E=I.length;B<E;++B)I[B].apply(this,A)}return this},jE.prototype.emitReserved=jE.prototype.emit,jE.prototype.listeners=function(g){return this._callbacks=this._callbacks||{},this._callbacks["$"+g]||[]},jE.prototype.hasListeners=function(g){return!!this.listeners(g).length};const oG=typeof Promise=="function"&&typeof Promise.resolve=="function"?A=>Promise.resolve().then(A):(A,I)=>I(A,0),oi=typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),JsA="arraybuffer";function BmA(){}function fW(g,...A){return A.reduce((I,B)=>(g.hasOwnProperty(B)&&(I[B]=g[B]),I),{})}const HsA=oi.setTimeout,NsA=oi.clearTimeout;function wG(g,A){A.useNativeTimers?(g.setTimeoutFn=HsA.bind(oi),g.clearTimeoutFn=NsA.bind(oi)):(g.setTimeoutFn=oi.setTimeout.bind(oi),g.clearTimeoutFn=oi.clearTimeout.bind(oi))}const xsA=1.33;function dsA(g){return typeof g=="string"?jsA(g):Math.ceil((g.byteLength||g.size)*xsA)}function jsA(g){let A=0,I=0;for(let B=0,E=g.length;B<E;B++)A=g.charCodeAt(B),A<128?I+=1:A<2048?I+=2:A<55296||A>=57344?I+=3:(B++,I+=4);return I}function XW(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function psA(g){let A="";for(let I in g)g.hasOwnProperty(I)&&(A.length&&(A+="&"),A+=encodeURIComponent(I)+"="+encodeURIComponent(g[I]));return A}function ysA(g){let A={},I=g.split("&");for(let B=0,E=I.length;B<E;B++){let C=I[B].split("=");A[decodeURIComponent(C[0])]=decodeURIComponent(C[1])}return A}class LsA extends Error{constructor(A,I,B){super(A),this.description=I,this.context=B,this.type="TransportError"}}class k4 extends jE{constructor(A){super(),this.writable=!1,wG(this,A),this.opts=A,this.query=A.query,this.socket=A.socket,this.supportsBinary=!A.forceBase64}onError(A,I,B){return super.emitReserved("error",new LsA(A,I,B)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(A){this.readyState==="open"&&this.write(A)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(A){const I=u4(A,this.socket.binaryType);this.onPacket(I)}onPacket(A){super.emitReserved("packet",A)}onClose(A){this.readyState="closed",super.emitReserved("close",A)}pause(A){}createUri(A,I={}){return A+"://"+this._hostname()+this._port()+this.opts.path+this._query(I)}_hostname(){const A=this.opts.hostname;return A.indexOf(":")===-1?A:"["+A+"]"}_port(){return this.opts.port&&(this.opts.secure&&+(this.opts.port!==443)||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(A){const I=psA(A);return I.length?"?"+I:""}}class VsA extends k4{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(A){this.readyState="pausing";const I=()=>{this.readyState="paused",A()};if(this._polling||!this.writable){let B=0;this._polling&&(B++,this.once("pollComplete",function(){--B||I()})),this.writable||(B++,this.once("drain",function(){--B||I()}))}else I()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(A){const I=B=>{if(this.readyState==="opening"&&B.type==="open"&&this.onOpen(),B.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(B)};usA(A,this.socket.binaryType).forEach(I),this.readyState!=="closed"&&(this._polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this._poll())}doClose(){const A=()=>{this.write([{type:"close"}])};this.readyState==="open"?A():this.once("open",A)}write(A){this.writable=!1,SsA(A,I=>{this.doWrite(I,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const A=this.opts.secure?"https":"http",I=this.query||{};return this.opts.timestampRequests!==!1&&(I[this.opts.timestampParam]=XW()),!this.supportsBinary&&!I.sid&&(I.b64=1),this.createUri(A,I)}}let vW=!1;try{vW=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}const qsA=vW;function ZsA(){}class zsA extends VsA{constructor(A){if(super(A),typeof location<"u"){const I=location.protocol==="https:";let B=location.port;B||(B=I?"443":"80"),this.xd=typeof location<"u"&&A.hostname!==location.hostname||B!==A.port}}doWrite(A,I){const B=this.request({method:"POST",data:A});B.on("success",I),B.on("error",(E,C)=>{this.onError("xhr post error",E,C)})}doPoll(){const A=this.request();A.on("data",this.onData.bind(this)),A.on("error",(I,B)=>{this.onError("xhr poll error",I,B)}),this.pollXhr=A}}let Eh=class OR extends jE{constructor(A,I,B){super(),this.createRequest=A,wG(this,B),this._opts=B,this._method=B.method||"GET",this._uri=I,this._data=B.data!==void 0?B.data:null,this._create()}_create(){var A;const I=fW(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");I.xdomain=!!this._opts.xd;const B=this._xhr=this.createRequest(I);try{B.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){B.setDisableHeaderCheck&&B.setDisableHeaderCheck(!0);for(let E in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(E)&&B.setRequestHeader(E,this._opts.extraHeaders[E])}}catch{}if(this._method==="POST")try{B.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{B.setRequestHeader("Accept","*/*")}catch{}(A=this._opts.cookieJar)===null||A===void 0||A.addCookies(B),"withCredentials"in B&&(B.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(B.timeout=this._opts.requestTimeout),B.onreadystatechange=()=>{var E;B.readyState===3&&((E=this._opts.cookieJar)===null||E===void 0||E.parseCookies(B.getResponseHeader("set-cookie"))),B.readyState===4&&(B.status===200||B.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof B.status=="number"?B.status:0)},0))},B.send(this._data)}catch(E){this.setTimeoutFn(()=>{this._onError(E)},0);return}typeof document<"u"&&(this._index=OR.requestsCount++,OR.requests[this._index]=this)}_onError(A){this.emitReserved("error",A,this._xhr),this._cleanup(!0)}_cleanup(A){if(!(typeof this._xhr>"u"||this._xhr===null)){if(this._xhr.onreadystatechange=ZsA,A)try{this._xhr.abort()}catch{}typeof document<"u"&&delete OR.requests[this._index],this._xhr=null}}_onLoad(){const A=this._xhr.responseText;A!==null&&(this.emitReserved("data",A),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}};if(Eh.requestsCount=0,Eh.requests={},typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",_W);else if(typeof addEventListener=="function"){const g="onpagehide"in oi?"pagehide":"unload";addEventListener(g,_W,!1)}}function _W(){for(let g in Eh.requests)Eh.requests.hasOwnProperty(g)&&Eh.requests[g].abort()}const TsA=function(){const g=$W({xdomain:!1});return g&&g.responseType!==null}();class WsA extends zsA{constructor(A){super(A);const I=A&&A.forceBase64;this.supportsBinary=TsA&&!I}request(A={}){return Object.assign(A,{xd:this.xd},this.opts),new Eh($W,this.uri(),A)}}function $W(g){const A=g.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!A||qsA))return new XMLHttpRequest}catch{}if(!A)try{return new oi[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}const Ab=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class bsA extends k4{get name(){return"websocket"}doOpen(){const A=this.uri(),I=this.opts.protocols,B=Ab?{}:fW(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(B.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(A,I,B)}catch(E){return this.emitReserved("error",E)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=A=>this.onClose({description:"websocket connection closed",context:A}),this.ws.onmessage=A=>this.onData(A.data),this.ws.onerror=A=>this.onError("websocket error",A)}write(A){this.writable=!1;for(let I=0;I<A.length;I++){const B=A[I],E=I===A.length-1;K4(B,this.supportsBinary,C=>{try{this.doWrite(B,C)}catch{}E&&oG(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){const A=this.opts.secure?"wss":"ws",I=this.query||{};return this.opts.timestampRequests&&(I[this.opts.timestampParam]=XW()),this.supportsBinary||(I.b64=1),this.createUri(A,I)}}const O4=oi.WebSocket||oi.MozWebSocket;class PsA extends bsA{createSocket(A,I,B){return Ab?new O4(A,I,B):I?new O4(A,I):new O4(A)}doWrite(A,I){this.ws.send(I)}}class fsA extends k4{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(A){return this.emitReserved("error",A)}this._transport.closed.then(()=>{this.onClose()}).catch(A=>{this.onError("webtransport error",A)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(A=>{const I=ksA(Number.MAX_SAFE_INTEGER,this.socket.binaryType),B=A.readable.pipeThrough(I).getReader(),E=msA();E.readable.pipeTo(A.writable),this._writer=E.writable.getWriter();const C=()=>{B.read().then(({done:o,value:w})=>{o||(this.onPacket(w),C())}).catch(o=>{})};C();const Q={type:"open"};this.query.sid&&(Q.data=`{"sid":"${this.query.sid}"}`),this._writer.write(Q).then(()=>this.onOpen())})})}write(A){this.writable=!1;for(let I=0;I<A.length;I++){const B=A[I],E=I===A.length-1;this._writer.write(B).then(()=>{E&&oG(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var A;(A=this._transport)===null||A===void 0||A.close()}}const XsA={websocket:PsA,webtransport:fsA,polling:WsA},vsA=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,_sA=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function J4(g){if(g.length>8e3)throw"URI too long";const A=g,I=g.indexOf("["),B=g.indexOf("]");I!=-1&&B!=-1&&(g=g.substring(0,I)+g.substring(I,B).replace(/:/g,";")+g.substring(B,g.length));let E=vsA.exec(g||""),C={},Q=14;for(;Q--;)C[_sA[Q]]=E[Q]||"";return I!=-1&&B!=-1&&(C.source=A,C.host=C.host.substring(1,C.host.length-1).replace(/;/g,":"),C.authority=C.authority.replace("[","").replace("]","").replace(/;/g,":"),C.ipv6uri=!0),C.pathNames=$sA(C,C.path),C.queryKey=AcA(C,C.query),C}function $sA(g,A){const I=/\/{2,9}/g,B=A.replace(I,"/").split("/");return(A.slice(0,1)=="/"||A.length===0)&&B.splice(0,1),A.slice(-1)=="/"&&B.splice(B.length-1,1),B}function AcA(g,A){const I={};return A.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(B,E,C){E&&(I[E]=C)}),I}const H4=typeof addEventListener=="function"&&typeof removeEventListener=="function",eG=[];H4&&addEventListener("offline",()=>{eG.forEach(g=>g())},!1);class Fe extends jE{constructor(A,I){if(super(),this.binaryType=JsA,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,A&&typeof A=="object"&&(I=A,A=null),A){const B=J4(A);I.hostname=B.host,I.secure=B.protocol==="https"||B.protocol==="wss",I.port=B.port,B.query&&(I.query=B.query)}else I.host&&(I.hostname=J4(I.host).host);wG(this,I),this.secure=I.secure!=null?I.secure:typeof location<"u"&&location.protocol==="https:",I.hostname&&!I.port&&(I.port=this.secure?"443":"80"),this.hostname=I.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=I.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},I.transports.forEach(B=>{const E=B.prototype.name;this.transports.push(E),this._transportsByName[E]=B}),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},I),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=ysA(this.opts.query)),H4&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},eG.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(A){const I=Object.assign({},this.opts.query);I.EIO=PW,I.transport=A,this.id&&(I.sid=this.id);const B=Object.assign({},this.opts,{query:I,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[A]);return new this._transportsByName[A](B)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}const A=this.opts.rememberUpgrade&&Fe.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports[0];this.readyState="opening";const I=this.createTransport(A);I.open(),this.setTransport(I)}setTransport(A){this.transport&&this.transport.removeAllListeners(),this.transport=A,A.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",I=>this._onClose("transport close",I))}onOpen(){this.readyState="open",Fe.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush()}_onPacket(A){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(this.emitReserved("packet",A),this.emitReserved("heartbeat"),A.type){case"open":this.onHandshake(JSON.parse(A.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":const I=new Error("server error");I.code=A.data,this._onError(I);break;case"message":this.emitReserved("data",A.data),this.emitReserved("message",A.data);break}}onHandshake(A){this.emitReserved("handshake",A),this.id=A.sid,this.transport.query.sid=A.sid,this._pingInterval=A.pingInterval,this._pingTimeout=A.pingTimeout,this._maxPayload=A.maxPayload,this.onOpen(),this.readyState!=="closed"&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);const A=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+A,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},A),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const A=this._getWritablePackets();this.transport.send(A),this._prevBufferLen=A.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let I=1;for(let B=0;B<this.writeBuffer.length;B++){const E=this.writeBuffer[B].data;if(E&&(I+=dsA(E)),B>0&&I>this._maxPayload)return this.writeBuffer.slice(0,B);I+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const A=Date.now()>this._pingTimeoutTime;return A&&(this._pingTimeoutTime=0,oG(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),A}write(A,I,B){return this._sendPacket("message",A,I,B),this}send(A,I,B){return this._sendPacket("message",A,I,B),this}_sendPacket(A,I,B,E){if(typeof I=="function"&&(E=I,I=void 0),typeof B=="function"&&(E=B,B=null),this.readyState==="closing"||this.readyState==="closed")return;B=B||{},B.compress=B.compress!==!1;const C={type:A,data:I,options:B};this.emitReserved("packetCreate",C),this.writeBuffer.push(C),E&&this.once("flush",E),this.flush()}close(){const A=()=>{this._onClose("forced close"),this.transport.close()},I=()=>{this.off("upgrade",I),this.off("upgradeError",I),A()},B=()=>{this.once("upgrade",I),this.once("upgradeError",I)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?B():A()}):this.upgrading?B():A()),this}_onError(A){if(Fe.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState==="opening")return this.transports.shift(),this._open();this.emitReserved("error",A),this._onClose("transport error",A)}_onClose(A,I){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing"){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),H4&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const B=eG.indexOf(this._offlineEventListener);B!==-1&&eG.splice(B,1)}this.readyState="closed",this.id=null,this.emitReserved("close",A,I),this.writeBuffer=[],this._prevBufferLen=0}}}Fe.protocol=PW;class gcA extends Fe{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState==="open"&&this.opts.upgrade)for(let A=0;A<this._upgrades.length;A++)this._probe(this._upgrades[A])}_probe(A){let I=this.createTransport(A),B=!1;Fe.priorWebsocketSuccess=!1;const E=()=>{B||(I.send([{type:"ping",data:"probe"}]),I.once("packet",t=>{if(!B)if(t.type==="pong"&&t.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",I),!I)return;Fe.priorWebsocketSuccess=I.name==="websocket",this.transport.pause(()=>{B||this.readyState!=="closed"&&(D(),this.setTransport(I),I.send([{type:"upgrade"}]),this.emitReserved("upgrade",I),I=null,this.upgrading=!1,this.flush())})}else{const s=new Error("probe error");s.transport=I.name,this.emitReserved("upgradeError",s)}}))};function C(){B||(B=!0,D(),I.close(),I=null)}const Q=t=>{const s=new Error("probe error: "+t);s.transport=I.name,C(),this.emitReserved("upgradeError",s)};function o(){Q("transport closed")}function w(){Q("socket closed")}function M(t){I&&t.name!==I.name&&C()}const D=()=>{I.removeListener("open",E),I.removeListener("error",Q),I.removeListener("close",o),this.off("close",w),this.off("upgrading",M)};I.once("open",E),I.once("error",Q),I.once("close",o),this.once("close",w),this.once("upgrading",M),this._upgrades.indexOf("webtransport")!==-1&&A!=="webtransport"?this.setTimeoutFn(()=>{B||I.open()},200):I.open()}onHandshake(A){this._upgrades=this._filterUpgrades(A.upgrades),super.onHandshake(A)}_filterUpgrades(A){const I=[];for(let B=0;B<A.length;B++)~this.transports.indexOf(A[B])&&I.push(A[B]);return I}}let IcA=class extends gcA{constructor(A,I={}){const B=typeof A=="object"?A:I;(!B.transports||B.transports&&typeof B.transports[0]=="string")&&(B.transports=(B.transports||["polling","websocket","webtransport"]).map(E=>XsA[E]).filter(E=>!!E)),super(A,B)}};function BcA(g,A="",I){let B=g;I=I||typeof location<"u"&&location,g==null&&(g=I.protocol+"//"+I.host),typeof g=="string"&&(g.charAt(0)==="/"&&(g.charAt(1)==="/"?g=I.protocol+g:g=I.host+g),/^(https?|wss?):\/\//.test(g)||(typeof I<"u"?g=I.protocol+"//"+g:g="https://"+g),B=J4(g)),B.port||(/^(http|ws)$/.test(B.protocol)?B.port="80":/^(http|ws)s$/.test(B.protocol)&&(B.port="443")),B.path=B.path||"/";const C=B.host.indexOf(":")!==-1?"["+B.host+"]":B.host;return B.id=B.protocol+"://"+C+":"+B.port+A,B.href=B.protocol+"://"+C+(I&&I.port===B.port?"":":"+B.port),B}const EcA=typeof ArrayBuffer=="function",CcA=g=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(g):g.buffer instanceof ArrayBuffer,gb=Object.prototype.toString,QcA=typeof Blob=="function"||typeof Blob<"u"&&gb.call(Blob)==="[object BlobConstructor]",icA=typeof File=="function"||typeof File<"u"&&gb.call(File)==="[object FileConstructor]";function N4(g){return EcA&&(g instanceof ArrayBuffer||CcA(g))||QcA&&g instanceof Blob||icA&&g instanceof File}function MG(g,A){if(!g||typeof g!="object")return!1;if(Array.isArray(g)){for(let I=0,B=g.length;I<B;I++)if(MG(g[I]))return!0;return!1}if(N4(g))return!0;if(g.toJSON&&typeof g.toJSON=="function"&&arguments.length===1)return MG(g.toJSON(),!0);for(const I in g)if(Object.prototype.hasOwnProperty.call(g,I)&&MG(g[I]))return!0;return!1}function ocA(g){const A=[],I=g.data,B=g;return B.data=x4(I,A),B.attachments=A.length,{packet:B,buffers:A}}function x4(g,A){if(!g)return g;if(N4(g)){const I={_placeholder:!0,num:A.length};return A.push(g),I}else if(Array.isArray(g)){const I=new Array(g.length);for(let B=0;B<g.length;B++)I[B]=x4(g[B],A);return I}else if(typeof g=="object"&&!(g instanceof Date)){const I={};for(const B in g)Object.prototype.hasOwnProperty.call(g,B)&&(I[B]=x4(g[B],A));return I}return g}function wcA(g,A){return g.data=d4(g.data,A),delete g.attachments,g}function d4(g,A){if(!g)return g;if(g&&g._placeholder===!0){if(typeof g.num=="number"&&g.num>=0&&g.num<A.length)return A[g.num];throw new Error("illegal attachments")}else if(Array.isArray(g))for(let I=0;I<g.length;I++)g[I]=d4(g[I],A);else if(typeof g=="object")for(const I in g)Object.prototype.hasOwnProperty.call(g,I)&&(g[I]=d4(g[I],A));return g}const ecA=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],McA=5;var bI;(function(g){g[g.CONNECT=0]="CONNECT",g[g.DISCONNECT=1]="DISCONNECT",g[g.EVENT=2]="EVENT",g[g.ACK=3]="ACK",g[g.CONNECT_ERROR=4]="CONNECT_ERROR",g[g.BINARY_EVENT=5]="BINARY_EVENT",g[g.BINARY_ACK=6]="BINARY_ACK"})(bI||(bI={}));class DcA{constructor(A){this.replacer=A}encode(A){return(A.type===bI.EVENT||A.type===bI.ACK)&&MG(A)?this.encodeAsBinary({type:A.type===bI.EVENT?bI.BINARY_EVENT:bI.BINARY_ACK,nsp:A.nsp,data:A.data,id:A.id}):[this.encodeAsString(A)]}encodeAsString(A){let I=""+A.type;return(A.type===bI.BINARY_EVENT||A.type===bI.BINARY_ACK)&&(I+=A.attachments+"-"),A.nsp&&A.nsp!=="/"&&(I+=A.nsp+","),A.id!=null&&(I+=A.id),A.data!=null&&(I+=JSON.stringify(A.data,this.replacer)),I}encodeAsBinary(A){const I=ocA(A),B=this.encodeAsString(I.packet),E=I.buffers;return E.unshift(B),E}}function Ib(g){return Object.prototype.toString.call(g)==="[object Object]"}class j4 extends jE{constructor(A){super(),this.reviver=A}add(A){let I;if(typeof A=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");I=this.decodeString(A);const B=I.type===bI.BINARY_EVENT;B||I.type===bI.BINARY_ACK?(I.type=B?bI.EVENT:bI.ACK,this.reconstructor=new hcA(I),I.attachments===0&&super.emitReserved("decoded",I)):super.emitReserved("decoded",I)}else if(N4(A)||A.base64)if(this.reconstructor)I=this.reconstructor.takeBinaryData(A),I&&(this.reconstructor=null,super.emitReserved("decoded",I));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+A)}decodeString(A){let I=0;const B={type:Number(A.charAt(0))};if(bI[B.type]===void 0)throw new Error("unknown packet type "+B.type);if(B.type===bI.BINARY_EVENT||B.type===bI.BINARY_ACK){const C=I+1;for(;A.charAt(++I)!=="-"&&I!=A.length;);const Q=A.substring(C,I);if(Q!=Number(Q)||A.charAt(I)!=="-")throw new Error("Illegal attachments");B.attachments=Number(Q)}if(A.charAt(I+1)==="/"){const C=I+1;for(;++I&&!(A.charAt(I)===","||I===A.length););B.nsp=A.substring(C,I)}else B.nsp="/";const E=A.charAt(I+1);if(E!==""&&Number(E)==E){const C=I+1;for(;++I;){const Q=A.charAt(I);if(Q==null||Number(Q)!=Q){--I;break}if(I===A.length)break}B.id=Number(A.substring(C,I+1))}if(A.charAt(++I)){const C=this.tryParse(A.substr(I));if(j4.isPayloadValid(B.type,C))B.data=C;else throw new Error("invalid payload")}return B}tryParse(A){try{return JSON.parse(A,this.reviver)}catch{return!1}}static isPayloadValid(A,I){switch(A){case bI.CONNECT:return Ib(I);case bI.DISCONNECT:return I===void 0;case bI.CONNECT_ERROR:return typeof I=="string"||Ib(I);case bI.EVENT:case bI.BINARY_EVENT:return Array.isArray(I)&&(typeof I[0]=="number"||typeof I[0]=="string"&&ecA.indexOf(I[0])===-1);case bI.ACK:case bI.BINARY_ACK:return Array.isArray(I)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class hcA{constructor(A){this.packet=A,this.buffers=[],this.reconPack=A}takeBinaryData(A){if(this.buffers.push(A),this.buffers.length===this.reconPack.attachments){const I=wcA(this.reconPack,this.buffers);return this.finishedReconstruction(),I}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const tcA=Object.freeze(Object.defineProperty({__proto__:null,Decoder:j4,Encoder:DcA,get PacketType(){return bI},protocol:McA},Symbol.toStringTag,{value:"Module"}));function qi(g,A,I){return g.on(A,I),function(){g.off(A,I)}}const acA=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Bb extends jE{constructor(A,I,B){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=A,this.nsp=I,B&&B.auth&&(this.auth=B.auth),this._opts=Object.assign({},B),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const A=this.io;this.subs=[qi(A,"open",this.onopen.bind(this)),qi(A,"packet",this.onpacket.bind(this)),qi(A,"error",this.onerror.bind(this)),qi(A,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected?this:(this.subEvents(),this.io._reconnecting||this.io.open(),this.io._readyState==="open"&&this.onopen(),this)}open(){return this.connect()}send(...A){return A.unshift("message"),this.emit.apply(this,A),this}emit(A,...I){var B,E,C;if(acA.hasOwnProperty(A))throw new Error('"'+A.toString()+'" is a reserved event name');if(I.unshift(A),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(I),this;const Q={type:bI.EVENT,data:I};if(Q.options={},Q.options.compress=this.flags.compress!==!1,typeof I[I.length-1]=="function"){const D=this.ids++,t=I.pop();this._registerAckCallback(D,t),Q.id=D}const o=(E=(B=this.io.engine)===null||B===void 0?void 0:B.transport)===null||E===void 0?void 0:E.writable,w=this.connected&&!(!((C=this.io.engine)===null||C===void 0)&&C._hasPingExpired());return this.flags.volatile&&!o||(w?(this.notifyOutgoingListeners(Q),this.packet(Q)):this.sendBuffer.push(Q)),this.flags={},this}_registerAckCallback(A,I){var B;const E=(B=this.flags.timeout)!==null&&B!==void 0?B:this._opts.ackTimeout;if(E===void 0){this.acks[A]=I;return}const C=this.io.setTimeoutFn(()=>{delete this.acks[A];for(let o=0;o<this.sendBuffer.length;o++)this.sendBuffer[o].id===A&&this.sendBuffer.splice(o,1);I.call(this,new Error("operation has timed out"))},E),Q=(...o)=>{this.io.clearTimeoutFn(C),I.apply(this,o)};Q.withError=!0,this.acks[A]=Q}emitWithAck(A,...I){return new Promise((B,E)=>{const C=(Q,o)=>Q?E(Q):B(o);C.withError=!0,I.push(C),this.emit(A,...I)})}_addToQueue(A){let I;typeof A[A.length-1]=="function"&&(I=A.pop());const B={id:this._queueSeq++,tryCount:0,pending:!1,args:A,flags:Object.assign({fromQueue:!0},this.flags)};A.push((E,...C)=>B!==this._queue[0]?void 0:(E!==null?B.tryCount>this._opts.retries&&(this._queue.shift(),I&&I(E)):(this._queue.shift(),I&&I(null,...C)),B.pending=!1,this._drainQueue())),this._queue.push(B),this._drainQueue()}_drainQueue(A=!1){if(!this.connected||this._queue.length===0)return;const I=this._queue[0];I.pending&&!A||(I.pending=!0,I.tryCount++,this.flags=I.flags,this.emit.apply(this,I.args))}packet(A){A.nsp=this.nsp,this.io._packet(A)}onopen(){typeof this.auth=="function"?this.auth(A=>{this._sendConnectPacket(A)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(A){this.packet({type:bI.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},A):A})}onerror(A){this.connected||this.emitReserved("connect_error",A)}onclose(A,I){this.connected=!1,delete this.id,this.emitReserved("disconnect",A,I),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(A=>{if(!this.sendBuffer.some(B=>String(B.id)===A)){const B=this.acks[A];delete this.acks[A],B.withError&&B.call(this,new Error("socket has been disconnected"))}})}onpacket(A){if(A.nsp===this.nsp)switch(A.type){case bI.CONNECT:A.data&&A.data.sid?this.onconnect(A.data.sid,A.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case bI.EVENT:case bI.BINARY_EVENT:this.onevent(A);break;case bI.ACK:case bI.BINARY_ACK:this.onack(A);break;case bI.DISCONNECT:this.ondisconnect();break;case bI.CONNECT_ERROR:this.destroy();const B=new Error(A.data.message);B.data=A.data.data,this.emitReserved("connect_error",B);break}}onevent(A){const I=A.data||[];A.id!=null&&I.push(this.ack(A.id)),this.connected?this.emitEvent(I):this.receiveBuffer.push(Object.freeze(I))}emitEvent(A){if(this._anyListeners&&this._anyListeners.length){const I=this._anyListeners.slice();for(const B of I)B.apply(this,A)}super.emit.apply(this,A),this._pid&&A.length&&typeof A[A.length-1]=="string"&&(this._lastOffset=A[A.length-1])}ack(A){const I=this;let B=!1;return function(...E){B||(B=!0,I.packet({type:bI.ACK,id:A,data:E}))}}onack(A){const I=this.acks[A.id];typeof I=="function"&&(delete this.acks[A.id],I.withError&&A.data.unshift(null),I.apply(this,A.data))}onconnect(A,I){this.id=A,this.recovered=I&&this._pid===I,this._pid=I,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach(A=>this.emitEvent(A)),this.receiveBuffer=[],this.sendBuffer.forEach(A=>{this.notifyOutgoingListeners(A),this.packet(A)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(A=>A()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:bI.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(A){return this.flags.compress=A,this}get volatile(){return this.flags.volatile=!0,this}timeout(A){return this.flags.timeout=A,this}onAny(A){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(A),this}prependAny(A){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(A),this}offAny(A){if(!this._anyListeners)return this;if(A){const I=this._anyListeners;for(let B=0;B<I.length;B++)if(A===I[B])return I.splice(B,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(A){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(A),this}prependAnyOutgoing(A){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(A),this}offAnyOutgoing(A){if(!this._anyOutgoingListeners)return this;if(A){const I=this._anyOutgoingListeners;for(let B=0;B<I.length;B++)if(A===I[B])return I.splice(B,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(A){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const I=this._anyOutgoingListeners.slice();for(const B of I)B.apply(this,A.data)}}}function Ch(g){g=g||{},this.ms=g.min||100,this.max=g.max||1e4,this.factor=g.factor||2,this.jitter=g.jitter>0&&g.jitter<=1?g.jitter:0,this.attempts=0}Ch.prototype.duration=function(){var g=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var A=Math.random(),I=Math.floor(A*this.jitter*g);g=(Math.floor(A*10)&1)==0?g-I:g+I}return Math.min(g,this.max)|0},Ch.prototype.reset=function(){this.attempts=0},Ch.prototype.setMin=function(g){this.ms=g},Ch.prototype.setMax=function(g){this.max=g},Ch.prototype.setJitter=function(g){this.jitter=g};class p4 extends jE{constructor(A,I){var B;super(),this.nsps={},this.subs=[],A&&typeof A=="object"&&(I=A,A=void 0),I=I||{},I.path=I.path||"/socket.io",this.opts=I,wG(this,I),this.reconnection(I.reconnection!==!1),this.reconnectionAttempts(I.reconnectionAttempts||1/0),this.reconnectionDelay(I.reconnectionDelay||1e3),this.reconnectionDelayMax(I.reconnectionDelayMax||5e3),this.randomizationFactor((B=I.randomizationFactor)!==null&&B!==void 0?B:.5),this.backoff=new Ch({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(I.timeout==null?2e4:I.timeout),this._readyState="closed",this.uri=A;const E=I.parser||tcA;this.encoder=new E.Encoder,this.decoder=new E.Decoder,this._autoConnect=I.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(A){return arguments.length?(this._reconnection=!!A,A||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(A){return A===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=A,this)}reconnectionDelay(A){var I;return A===void 0?this._reconnectionDelay:(this._reconnectionDelay=A,(I=this.backoff)===null||I===void 0||I.setMin(A),this)}randomizationFactor(A){var I;return A===void 0?this._randomizationFactor:(this._randomizationFactor=A,(I=this.backoff)===null||I===void 0||I.setJitter(A),this)}reconnectionDelayMax(A){var I;return A===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=A,(I=this.backoff)===null||I===void 0||I.setMax(A),this)}timeout(A){return arguments.length?(this._timeout=A,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(A){if(~this._readyState.indexOf("open"))return this;this.engine=new IcA(this.uri,this.opts);const I=this.engine,B=this;this._readyState="opening",this.skipReconnect=!1;const E=qi(I,"open",function(){B.onopen(),A&&A()}),C=o=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",o),A?A(o):this.maybeReconnectOnOpen()},Q=qi(I,"error",C);if(this._timeout!==!1){const o=this._timeout,w=this.setTimeoutFn(()=>{E(),C(new Error("timeout")),I.close()},o);this.opts.autoUnref&&w.unref(),this.subs.push(()=>{this.clearTimeoutFn(w)})}return this.subs.push(E),this.subs.push(Q),this}connect(A){return this.open(A)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const A=this.engine;this.subs.push(qi(A,"ping",this.onping.bind(this)),qi(A,"data",this.ondata.bind(this)),qi(A,"error",this.onerror.bind(this)),qi(A,"close",this.onclose.bind(this)),qi(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(A){try{this.decoder.add(A)}catch(I){this.onclose("parse error",I)}}ondecoded(A){oG(()=>{this.emitReserved("packet",A)},this.setTimeoutFn)}onerror(A){this.emitReserved("error",A)}socket(A,I){let B=this.nsps[A];return B?this._autoConnect&&!B.active&&B.connect():(B=new Bb(this,A,I),this.nsps[A]=B),B}_destroy(A){const I=Object.keys(this.nsps);for(const B of I)if(this.nsps[B].active)return;this._close()}_packet(A){const I=this.encoder.encode(A);for(let B=0;B<I.length;B++)this.engine.write(I[B],A.options)}cleanup(){this.subs.forEach(A=>A()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(A,I){var B;this.cleanup(),(B=this.engine)===null||B===void 0||B.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",A,I),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const A=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const I=this.backoff.duration();this._reconnecting=!0;const B=this.setTimeoutFn(()=>{A.skipReconnect||(this.emitReserved("reconnect_attempt",A.backoff.attempts),!A.skipReconnect&&A.open(E=>{E?(A._reconnecting=!1,A.reconnect(),this.emitReserved("reconnect_error",E)):A.onreconnect()}))},I);this.opts.autoUnref&&B.unref(),this.subs.push(()=>{this.clearTimeoutFn(B)})}}onreconnect(){const A=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",A)}}const _t={};function DG(g,A){typeof g=="object"&&(A=g,g=void 0),A=A||{};const I=BcA(g,A.path||"/socket.io"),B=I.source,E=I.id,C=I.path,Q=_t[E]&&C in _t[E].nsps,o=A.forceNew||A["force new connection"]||A.multiplex===!1||Q;let w;return o?w=new p4(B,A):(_t[E]||(_t[E]=new p4(B,A)),w=_t[E]),I.query&&!A.query&&(A.query=I.queryKey),w.socket(I.path,A)}Object.assign(DG,{Manager:p4,Socket:Bb,io:DG,connect:DG});const Qh="https://api.tybotflow.com/api/v1",scA="https://api.tybotflow.com/api/v1/chatbots-config",Eb="https://migration-meta.tybotflow.com/",Cb=Eb+"webhook/v",hG=DG(Eb,{transports:["websocket","polling"],reconnection:!0,reconnectionAttempts:3,autoConnect:!0,reconnectionDelay:2e3}),Qb=new rw,y4=g=>{if(!g||!g.message)return"👋 Hey there! how can I help you?";const A=g.message;if(typeof A=="string")return A;if(Array.isArray(A)){const I=window.location.href,B=window.location.origin,E=window.location.pathname,C=B+E;for(const o of A){if(!o.urls||o.urls.length===0)continue;if(o.urls.some(M=>{if(!M||M.trim()==="")return!1;try{let D=M.trim();!D.startsWith("http://")&&!D.startsWith("https://")&&(D="https://"+D);const t=new URL(D),s=t.origin,a=t.pathname,G=s+a;return C===G||I===D?!0:a==="/"||a===""?B===s:!!I.startsWith(D)}catch{return console.warn("Invalid URL in message:",M),!1}}))return o.text||"👋 Hey there! how can I help you?"}const Q=A.find(o=>!o.urls||o.urls.length===0||o.urls.every(w=>!w||w.trim()===""));if(Q)return Q.text||"👋 Hey there! how can I help you?";if(A.length>0)return A[0].text||"👋 Hey there! how can I help you?"}return"👋 Hey there! how can I help you?"},ib=(g,A)=>{const I={className:"w-5 h-5",style:{color:A}};switch(g?.toLowerCase()){case"pdf":return u.jsx(Ce,{...I});case"doc":case"docx":return u.jsx(Ce,{...I});case"xls":case"xlsx":case"csv":return u.jsx(OIA,{...I});case"ppt":case"pptx":return u.jsx(yIA,{...I});case"zip":case"rar":case"7z":case"tar":case"gz":return u.jsx(lIA,{...I});case"txt":case"md":case"rtf":return u.jsx(sj,{...I});default:return u.jsx(Ce,{...I})}},ccA=({config:g})=>{const A=vA.useRef(null),I=vA.useRef(null),B=vA.useRef(null),E=vA.useRef(null),C=vA.useRef(null),[Q,o]=vA.useState(null),[w,M]=vA.useState(!0),[D,t]=vA.useState(!1);vA.useEffect(()=>{(async()=>{M(!0),await OB.get(`${scA}/bot/${g.bot?.botId}`,{}).then(uA=>{o(uA.data)}).catch(uA=>{console.error("Error fetching bot config:",uA)}).finally(()=>{M(!1)})})()},[g.bot?.botId,g?.token]);const s=Q?.mainColor||"#59168b",a=Q?.secondaryColor||"#6366f1",G=Q?.thirdColor||"#0f172b",R=Q?.headerFirstColor||"#6e11b0",U=Q?.headerSecondColor||"#372aac",r=Q?.inputBackgroundColor||"#1f2937",l=Q?.inputTextColor||"#fff",K=Q?.roundness||24,m=Q?.chatRoundness||16,x=(Q?.minPanelWidth||434)>window.innerWidth?window.innerWidth:Q?.minPanelWidth||434,O=(Q?.maxPanelWidth||window.innerWidth)>window.innerWidth?window.innerWidth:Q?.maxPanelWidth||window.innerWidth,y=Q?.chatMaxWidth||88,L=Q?.toggleBtnBorderTopLeftRadius||12,j=Q?.toggleBtnBorderTopRightRadius||0,z=Q?.toggleBtnBorderBottomLeftRadius||12,d=Q?.toggleBtnBorderBottomRightRadius||0,Z=Q?.menuBackgroundColor||"#1f2937",W=Q?.menuTextColor||"#e5e7eb",T=Q?.menuHoverBackgroundColor||"#374151",X=Q?.agentChatResponseColor||"#e5e7eb",P=Q?.agentChatResponseBgColor||"#1f2937",EA=Q?.agentIconBgColor||"#59168b",$=Q?.agentIconColor||"#fff",oA=Q?.userChatMessagesColor||"#fff",H=Q?.userChatMessagesBgColor||"#7a1ebe",AA=Q?.userIconBgColor||"#7a1ebe",q=Q?.userIconColor||"#fff",J=Q?.ButtonColor||"#fff",f=Q?.ButtonsBgColor||"#59168b",iA=OC(P,10),wA=Q?.fontSize||13,tA=Q?.toggleBtnPosition||"bottom-right",RA=Q?.autoOpenPanel??!0,lA=Q?.tempToken||"",PA=(()=>{const p=Q?.firstMessageKeyword;if(Array.isArray(p)){const uA=window.location.href,UA=p.find(Gg=>Gg.url&&Gg.url===uA);if(UA)return UA.message;const LA=p.find(Gg=>!Gg.url||Gg.url==="");return LA?LA.message:p[0]?.message||"hi"}return p||"hi"})(),sg=p=>({ip:p.ip||"",flag:{img:p.flag||"",emoji:p.emoji_flag||"",emoji_unicode:p.emoji_unicode||""},is_eu:p.is_eu??!1,postal:p.postal||"",borders:"",latitude:p.latitude||0,platform:p?.platform||"",timezone:{id:p.time_zone?.name||"",utc:p.time_zone?.offset||"",abbr:p.time_zone?.abbr||"",is_dst:p.time_zone?.is_dst??!1,offset:p.time_zone?.offset||0,current_time:p.time_zone?.current_time||""},continent:p.continent_name||"",longitude:p.longitude||0,connection:{asn:p.asn?.asn||0,isp:p.asn?.name||"",org:p.asn?.name||"",domain:p.asn?.domain||""}}),[bA,JA]=vA.useState(x),BA=vA.useRef(!1),Bg=vA.useRef(0),Yg=vA.useRef(x),wg=p=>{BA.current=!0,Bg.current=p.clientX,Yg.current=bA,document.body.style.cursor="ew-resize"};vA.useEffect(()=>{const p=UA=>{if(!BA.current)return;const LA=Bg.current-UA.clientX;let Gg=Yg.current+LA;Gg=Math.max(x,Math.min(O,Gg)),JA(Gg)},uA=()=>{BA.current&&(BA.current=!1,document.body.style.cursor="")};return window.addEventListener("mousemove",p),window.addEventListener("mouseup",uA),()=>{window.removeEventListener("mousemove",p),window.removeEventListener("mouseup",uA)}},[bA,x,O]);const[kA,Cg]=vA.useState(!1),[Ig,lg]=vA.useState(!1),[Dg,xA]=vA.useState(!1),[ZA,sA]=vA.useState(()=>tA==="bottom-left"?{x:48,y:window.innerHeight-120}:tA==="middle-right"?{x:window.innerWidth-80,y:window.innerHeight/2-35}:{x:window.innerWidth-123,y:window.innerHeight-100}),[rA,HA]=vA.useState(!1),[zA,Rg]=vA.useState({x:0,y:0}),Ug=vA.useRef(null),[Vg,jg]=vA.useState(""),[rg,ng]=vA.useState(!1),[qg,Sg]=vA.useState(!1),[Ng,Jg]=vA.useState([]),[$g,KI]=vA.useState(!1),Xg=vA.useRef(0),[Wg,SI]=vA.useState(!1),[gC,MI]=vA.useState(!1),qB=vA.useRef(!1),[aC,bg]=vA.useState("00:00"),XI=vA.useRef(null),dI=vA.useRef(0),[vI,ZB]=vA.useState(null),[DI,QB]=vA.useState(!1),[EB,IC]=vA.useState(new Set),[MB,gB]=vA.useState([]),{startRecording:hB,stopRecording:zB,pauseRecording:DE,resumeRecording:TB,status:QI,error:TE}=tiA.useReactMediaRecorder({video:!1,onStop(p,uA){if(qB.current){qB.current=!1,bg("00:00"),dI.current=0;return}Jg(UA=>[...UA,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),file:uA,type:"audio",url:p,name:`recording-${new Date().toISOString()}.webm`,size:uA.size}]),bg("00:00"),dI.current=0}}),kg=Q?.icon||g?.bot.avatar_url||Bz,cA=Q?.title||g?.bot.name||"Tybot webchat",[$A,ug]=vA.useState(null),[OI,YB]=vA.useState(()=>{const p=localStorage.getItem("phone_client");if(g.bot?.botId==="rockskin"&&p)return p;if(!Q?.botNeedsAuth){let uA=localStorage.getItem("externalUser");if(!uA){const UA=new Uint8Array(16);window.crypto.getRandomValues(UA),uA=Array.from(UA).map(LA=>LA.toString(16).padStart(2,"0")).join("")}return localStorage.setItem("externalUser",uA),uA}});vA.useEffect(()=>{if(!$A)return;const p=uA=>{if(uA.bot.conversationId!==parseInt($A)||uA.bot.botId!==g?.bot?.botId){ng(!1);return}const UA={id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:uA.bot.item,timestamp:new Date,seen:LC.current,nMessage:Array.isArray(uA.bot.item)?uA.bot.item.length:1};gB(LA=>LA.some(OA=>OA.id===UA.id)?LA:[...LA,UA]),ng(!1)};return hG.on("bot-message",p),()=>{hG.off("bot-message",p)}},[$A,g?.bot?.botId]),vA.useEffect(()=>{(async()=>{if(!($A||!g.bot?.botId||!OI))try{const UA=(await OB.post(`${Qh}/conversations/start-conversation`,{bot_id:g.bot?.botId,externalUser:OI})).data.conversationId;ug(UA),localStorage.setItem("conversationId",UA),hG.emit("join_room",parseInt(UA))}catch(uA){console.error("Error initializing conversation:",uA)}})()},[$A,g.bot?.botId,OI]);const[ZI,NB]=vA.useState(()=>Q?.botNeedsAuth?!!localStorage.getItem("conversationId"):!0),[PI,WB]=vA.useState(""),[sC,RB]=vA.useState(""),[WE,WQ]=vA.useState(""),[yC,Vo]=vA.useState(null),LC=vA.useRef(!1),nI=MB.reduce((p,uA)=>uA.seen?p:p+(uA.sender==="agent"?uA.nMessage||1:0),0),vi=()=>{gB(p=>p.map(uA=>({...uA,seen:!0})))};vA.useEffect(()=>{let p;return!localStorage.getItem("webChatOpen")&&Q&&RA&&(p=setTimeout(()=>{Cg(!0),LC.current=!0,vi(),localStorage.setItem("webChatOpen","true")},3200)),()=>clearTimeout(p)},[Q]),vA.useEffect(()=>{const p=Q?.widgetLoadBehavior;if(!p||!(()=>{const LA=p.message;if(typeof LA=="string"){if(!p.urls||p.urls.length===0)return!0;const Gg=window.location.origin,OA=window.location.href;return p.urls.some(gI=>{if(!gI||gI.trim()==="")return!0;try{return Gg.includes(gI)||OA.includes(gI)||gI.includes(Gg)}catch{return console.warn("Invalid URL in widgetLoadBehavior:",gI),!1}})}if(Array.isArray(LA)){const Gg=window.location.href,OA=window.location.origin,gI=window.location.pathname,aI=OA+gI;for(const SB of LA)if(!SB.urls||SB.urls.length===0||SB.urls.every(bB=>!bB||bB.trim()==="")||SB.urls.some(bB=>{if(!bB||bB.trim()==="")return!1;try{let KE=bB.trim();!KE.startsWith("http://")&&!KE.startsWith("https://")&&(KE="https://"+KE);const VE=new URL(KE),zg=VE.origin,oQ=VE.pathname,pI=zg+oQ;return aI===pI||Gg===KE?!0:oQ==="/"||oQ===""?OA===zg:!!Gg.startsWith(KE)}catch{return console.warn("Invalid URL in message:",bB),!1}}))return!0;return!1}return!0})())return;let UA;if(p.behavior==="after seconds")UA=setTimeout(()=>{xA(!0)},p.value*1e3);else if(p.behavior==="after scroll"){const LA=()=>{const Gg=window.pageYOffset||document.documentElement.scrollTop,OA=document.documentElement.scrollHeight-document.documentElement.clientHeight;Gg/OA*100>=p.value&&(xA(!0),window.removeEventListener("scroll",LA))};return window.addEventListener("scroll",LA),()=>{window.removeEventListener("scroll",LA)}}return()=>{UA&&clearTimeout(UA)}},[Q?.widgetLoadBehavior]),vA.useEffect(()=>{kA&&xA(!1)},[kA]),vA.useEffect(()=>{fetch("https://api.ipdata.co/?api-key=7930ffd0621dafcb6cd830a503d726bf514b74c1cae21ffff8131890").then(function(p){p.json().then(uA=>{Vo({...uA,platform:Qb.getOS().name+" "+Qb.getOS().version})})}).catch(function(p){console.log(p)})},[]);const qo=vA.useCallback(async(p,uA=[],UA)=>{if(!g.bot.botId||!$A){ng(!1),gB(Gg=>[...Gg,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:[{type:"text",text:"⚠️ Unable to send message: No bot selected or conversation not initialized."}],timestamp:new Date}]);return}if(uA.length>0||UA&&typeof UA=="object"&&UA.attachment!==void 0){const Gg=UA&&typeof UA!="string"?UA.attachment.file:uA[0]?.file,OA=UA&&typeof UA!="string"?UA.attachment.type:uA[0]?.type||"file";let gI=UA;if(UA&&typeof UA=="object"&&UA.attachment!==void 0){const{attachment:SB,...RI}=UA;gI=RI}const aI=new FormData;aI.append("type",OA),aI.append("file",Gg),aI.append("botId",g.bot.botId),aI.append("external_id",OI||""),aI.append("isintern",g.token?"true":"false"),aI.append("host",window.location.origin),aI.append("channel","web"),aI.append("payload",gI?JSON.stringify(gI):""),await OB.post(Cb,aI,{headers:{Authorization:`Bearer ${g?.token}`,"Content-Type":"multipart/form-data"}})}else{const Gg={type:"text",messageText:p,botId:g.bot.botId,external_id:OI||"",isintern:!!g.token,host:window.location.origin,channel:"web"};UA&&(Gg.payload=UA),await OB.post(Cb,Gg,{headers:{Authorization:`Bearer ${g?.token}`,"Content-Type":"application/json"}})}},[g.bot.botId,$A,g.token,g.user?.id]),cC=vA.useCallback(async()=>{if(g.bot.botId&&$A){ng(!0);try{await qo(PA)}catch(p){console.error("Error sending first message:",p),ng(!1)}}},[g.bot.botId,PA,$A,qo]);vA.useEffect(()=>{$A&&ZI&&g?.bot&&MB.length===0&&Q&&RA&&(cC(),localStorage.getItem("webChatAuth")&&JSON.parse(localStorage.getItem("webChatAuth"))&&Q?.botNeedsAuth&&$A&&(PI||WE||sC)&&(setTimeout(()=>{zC($A)},2e3),localStorage.setItem("webChatAuth","true")))},[ZI,g?.bot,$A,Q]),vA.useEffect(()=>(QI==="recording"?XI.current||(XI.current=setInterval(()=>{dI.current+=1;const p=Math.floor(dI.current/60).toString().padStart(2,"0"),uA=(dI.current%60).toString().padStart(2,"0");bg(`${p}:${uA}`)},1e3)):XI.current&&(clearInterval(XI.current),XI.current=null),()=>{XI.current&&(clearInterval(XI.current),XI.current=null)}),[QI]),vA.useEffect(()=>{TE&&TE.toLowerCase().includes("permission_denied")&&(MI(!1),bg("00:00"),dI.current=0,XI.current&&(clearInterval(XI.current),XI.current=null),alert("Microphone permission denied. Please allow access to record audio."))},[TE]),vA.useEffect(()=>{QI!=="recording"&&QI!=="paused"&&(bg("00:00"),dI.current=0)},[QI]);const EQ=vA.useRef(null);vA.useEffect(()=>{if(EQ&&EQ.current){const p=EQ.current;p.style.height="auto";const uA=120;p.scrollHeight>uA?(p.style.height=uA+"px",p.style.overflowY="auto"):(p.style.height=p.scrollHeight+"px",p.style.overflowY="hidden")}},[Vg]),vA.useEffect(()=>{(kA||rg)&&A.current&&(A.current.scrollTop=A.current.scrollHeight)},[MB,rg,kA]);const BC=p=>{const uA=p.type.toLowerCase();return uA.startsWith("image/")?"image":uA.startsWith("video/")?"video":uA.startsWith("audio/")?"audio":"document"},VC=vA.useCallback((p,uA)=>{const UA=[];Array.from(p).forEach(LA=>{if(LA.size>10*1024*1024){alert(`File ${LA.name} is too large. Maximum size is 10MB.`);return}const Gg={id:Date.now().toString()+Math.random().toString(36).substring(2,9),file:LA,type:BC(LA),url:URL.createObjectURL(LA),name:LA.name,size:LA.size};UA.push(Gg)}),Jg(LA=>[...LA,...UA]),uA&&uA.current&&(uA.current.value="")},[]),zI=vA.useCallback(p=>{p.preventDefault(),Xg.current=0,KI(!1);const uA=p.dataTransfer.files;uA.length>0&&VC(uA)},[VC]),_i=vA.useCallback(p=>{p.preventDefault(),Xg.current+=1,KI(!0)},[]),je=vA.useCallback(p=>{p.preventDefault()},[]),Jw=vA.useCallback(p=>{p.preventDefault(),Xg.current-=1,Xg.current<=0&&KI(!1)},[]),ai=vA.useCallback(p=>{Jg(uA=>{const UA=uA.find(LA=>LA.id===p);return UA&&URL.revokeObjectURL(UA.url),uA.filter(LA=>LA.id!==p)})},[]),CQ=p=>{if(p===0)return"0 Bytes";const uA=1024,UA=["Bytes","KB","MB","GB"],LA=Math.floor(Math.log(p)/Math.log(uA));return Number.parseFloat((p/Math.pow(uA,LA)).toFixed(2))+" "+UA[LA]},jI=async(p=Vg,uA)=>{if(p.trim()||Ng.length!==0){const LA={id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"user",content:p,attachments:[...Ng],timestamp:new Date};if(gB(Gg=>[...Gg,LA]),jg(""),Jg([]),ng(!0),g?.bot)try{if(!$A){ng(!1),gB(Gg=>[...Gg,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:"⚠️ Conversation not initialized. Please try again later.",timestamp:new Date,seen:LC.current,nMessage:1}]);return}await qo(p,Ng,uA)}catch{gB(Gg=>[...Gg,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:"Erreur du serveur",timestamp:new Date,seen:LC.current,nMessage:1}]),ng(!1)}else gB(Gg=>[...Gg,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:"Aucun bot sélectionné",timestamp:new Date,seen:LC.current,nMessage:1}]),ng(!1)}else return},qC=p=>{switch(SI(!1),p){case"image":I.current?.click();break;case"video":B.current?.click();break;case"audio":E.current?.click();break;case"document":C.current?.click();break}};vA.useEffect(()=>{const p=MB.slice().reverse().find(uA=>uA.sender==="agent");if(p){let uA=!1;Array.isArray(p.content)&&(uA=p.content.some(UA=>UA.type==="text"&&typeof UA.text=="object"&&UA.text.type==="EVFORM")),Sg(uA)}else Sg(!1)},[MB]);const[si,SQ]=vA.useState(!1),bQ=vA.useRef({x:0,y:0}),Hw=p=>{p.preventDefault(),p.stopPropagation(),HA(!0),SQ(!1),bQ.current={x:p.clientX,y:p.clientY},Rg({x:p.clientX-ZA.x,y:p.clientY-ZA.y}),document.body.style.cursor="grabbing",document.body.style.userSelect="none"},$M=p=>{p.preventDefault(),p.stopPropagation();const uA=p.touches[0];HA(!0),SQ(!1),bQ.current={x:uA.clientX,y:uA.clientY},Rg({x:uA.clientX-ZA.x,y:uA.clientY-ZA.y})},uQ=p=>{if(p.preventDefault(),p.stopPropagation(),si){SQ(!1);return}Cg(uA=>!uA),LC.current=!kA,kA||vi(),!RA&&MB.length===0&&cC()};vA.useEffect(()=>{const p=Gg=>{if(!rA)return;const OA=Math.abs(Gg.clientX-bQ.current.x),gI=Math.abs(Gg.clientY-bQ.current.y);(OA>5||gI>5)&&SQ(!0);const aI=Gg.clientX-zA.x,SB=Gg.clientY-zA.y,RI=67,bB=window.innerWidth-document.body.clientWidth,KE=Math.max(0,Math.min(window.innerWidth-RI-bB,aI)),VE=Math.max(0,Math.min(window.innerHeight-RI,SB));sA({x:KE,y:VE})},uA=Gg=>{if(!rA)return;Gg.preventDefault();const OA=Gg.touches[0],gI=Math.abs(OA.clientX-bQ.current.x),aI=Math.abs(OA.clientY-bQ.current.y);(gI>5||aI>5)&&SQ(!0);const SB=OA.clientX-zA.x,RI=OA.clientY-zA.y,bB=67,KE=window.innerWidth-document.body.clientWidth,VE=Math.max(0,Math.min(window.innerWidth-bB-KE,SB)),zg=Math.max(0,Math.min(window.innerHeight-bB,RI));sA({x:VE,y:zg})},UA=()=>{rA&&(HA(!1),document.body.style.cursor="",document.body.style.userSelect="")},LA=()=>{rA&&HA(!1)};return rA&&(document.addEventListener("mousemove",p),document.addEventListener("touchmove",uA,{passive:!1}),document.addEventListener("mouseup",UA),document.addEventListener("touchend",LA)),()=>{document.removeEventListener("mousemove",p),document.removeEventListener("touchmove",uA),document.removeEventListener("mouseup",UA),document.removeEventListener("touchend",LA)}},[rA,zA,ZA]),vA.useEffect(()=>{const p=()=>{const UA=window.innerWidth-67,LA=window.innerHeight-67;sA(Gg=>({x:Math.max(0,Math.min(UA,Gg.x)),y:Math.max(0,Math.min(LA,Gg.y))}))};return window.addEventListener("resize",p),()=>window.removeEventListener("resize",p)},[]),vA.useEffect(()=>{const p=async()=>{try{await OB.patch(`${Qh}/widget/endusers/${OI}`,{fiche_contact:{city:yC.city,platform:yC.platform,region:yC.region,country:yC.country_name,age:0,full_name:PI,gender:"",address:"",company:"","phone 2":"",facebook:"",whatsapp:"",job_title:"",avatar_url:""},user_info:sg(yC)},{headers:{Authorization:`Bearer ${lA}`}}),localStorage.setItem("enduserUpdated","true")}catch(UA){console.error("Error updating end user info:",UA)}};let uA;return yC&&$A&&lA&&MB.length>0&&!localStorage.getItem("enduserUpdated")&&(uA=setTimeout(()=>{p()},5e3)),()=>clearTimeout(uA)},[yC,Q,MB,$A]);const lE=vA.useMemo(()=>({h1:({children:p})=>u.jsx("h1",{className:"sm:text-2xl text-xl font-bold my-2",dir:tw(p)?"rtl":"ltr",children:u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h2:({children:p})=>u.jsx("h2",{className:"sm:text-xl text-lg font-semibold my-2",dir:tw(p)?"rtl":"ltr",children:u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h3:({children:p})=>u.jsx("h3",{className:"sm:text-lg text-base font-semibold my-2",dir:tw(p)?"rtl":"ltr",children:u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h4:({children:p})=>u.jsx("h4",{className:"sm:text-base text-sm font-semibold my-2",dir:tw(p)?"rtl":"ltr",children:u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h5:({children:p})=>u.jsx("h5",{className:"sm:text-base text-sm font-semibold my-2",dir:tw(p)?"rtl":"ltr",children:u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h6:({children:p})=>u.jsx("h6",{className:"sm:text-base text-sm font-semibold my-2",dir:tw(p)?"rtl":"ltr",children:u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),p:({children:p})=>{const uA=(LA,Gg)=>{const OA=aw(LA);return u.jsx("span",{dir:OA?"rtl":"ltr",style:{display:"block",textAlign:OA?"right":"left"},children:u.jsx(cE,{sequence:[LA,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],wrapper:"span",cursor:!1,speed:70})},Gg)};if(typeof p=="string")return u.jsx("div",{className:"leading-relaxed my-0.5",children:uA(p,0)});if(Array.isArray(p)){const LA=[[]];for(const Gg of p)Gg?.type==="br"?LA.push([]):LA[LA.length-1].push(Gg);return u.jsx("div",{className:"leading-relaxed my-0.5",children:LA.map((Gg,OA)=>{const gI=Gg.map(RI=>typeof RI=="string"?RI:"").join(""),aI=aw(gI),SB=Gg.every(RI=>typeof RI=="string");return u.jsx("span",{dir:aI?"rtl":"ltr",style:{display:"block",textAlign:aI?"right":"left"},children:SB&&gI?u.jsx(cE,{sequence:[gI,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],wrapper:"span",cursor:!1,speed:70}):Gg},OA)})})}const UA=!!(p?.props?.children&&aw(String(p?.props?.children??"")));return u.jsx("div",{className:"leading-relaxed my-0.5",dir:UA?"rtl":"ltr",children:p})},ul:({children:p})=>u.jsx("ul",{className:"list-disc list-inside ml-2 my-2",style:{color:X},dir:aw(p)?"rtl":"ltr",children:p}),ol:({children:p})=>{let uA=!1;return p.filter(UA=>typeof UA!="string").every(UA=>aw(UA?.props?.children))?uA=!0:uA=!1,u.jsx("ol",{className:"list-decimal list-inside ml-2 my-2",style:{color:X},dir:uA?"rtl":"ltr",children:typeof p=="string"?u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):p})},li:({children:p})=>u.jsx("li",{className:"my-1",dir:tw(p)?"rtl":"ltr",style:{color:X},children:typeof p=="string"?u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):p}),a:({href:p,children:uA})=>u.jsx("a",{href:p,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:typeof uA=="string"?u.jsx(cE,{sequence:[uA,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):uA}),blockquote:({children:p})=>u.jsx("blockquote",{className:"border-l-4 pl-4 italic my-2",style:{borderColor:f,color:X},children:typeof p=="string"?u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):p}),code({node:p,className:uA,children:UA,...LA}){const Gg=/language-(\w+)/.exec(uA||"");return Gg?u.jsx(Iz,{...LA,PreTag:"div",children:String(UA).replace(/\n$/,""),language:Gg[1],style:_DA,customStyle:{scrollbarWidth:"thin"}}):u.jsx("code",{className:"px-1 rounded font-mono inline",style:{backgroundColor:r,color:X},...LA,children:typeof UA=="string"?u.jsx(cE,{sequence:[UA,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):UA})},table:({children:p})=>u.jsx("table",{className:"min-w-full my-2",style:{border:`1px solid ${X}`,color:P,backgroundColor:X},children:p}),thead:({children:p})=>u.jsx("thead",{children:p}),tbody:({children:p})=>u.jsx("tbody",{children:p}),tr:({children:p})=>u.jsx("tr",{style:{border:`1px solid ${P}`},children:p}),th:({children:p})=>u.jsx("th",{className:"px-3 py-2 font-bold text-left",children:p}),td:({children:p})=>u.jsx("td",{className:"px-3 py-2",children:typeof p=="string"?u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):p}),strong:({children:p})=>u.jsx("strong",{className:"font-bold",children:typeof p=="string"?u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):p}),em:({children:p})=>u.jsx("em",{className:"italic ",children:typeof p=="string"?u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):p}),hr:()=>u.jsx("hr",{className:"my-4",style:{borderColor:`1px solid ${X}`}})}),[l,X,f,r,m]);vA.useEffect(()=>{const p=uA=>{Wg&&uA.target instanceof Element&&!uA.composedPath().some(UA=>UA?.id==="upload-button-toggle"||UA?.id==="document-button"||UA?.id==="image-button"||UA?.id==="video-button"||UA?.id==="audio-button")&&SI(!1)};return document.addEventListener("mousedown",p),()=>{document.removeEventListener("mousedown",p)}},[Wg]);const ZC=p=>{switch(p.type){case"text":if(Array.isArray(p.text))switch(p.text[0].type){case"products":return u.jsx(BG,{products:p.text[0].items||[],onValidate:UA=>{jI("cart",UA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA});case"easyspaceform":return u.jsx(Qz,{onValidate:UA=>{jI("easyspace-form-data",UA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"xcmgform":return u.jsx(OW,{onValidate:UA=>{jI("xcmg-form-data",UA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"auditec-form":return u.jsx(mW,{onValidate:UA=>{jI("auditec-form-data",UA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"auditec-form-ar":return u.jsx(kW,{onValidate:UA=>{jI("تم إرسال النموذج",UA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"nousserform":return u.jsx(NW,{onValidate:UA=>{jI("nousserform-data",UA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"jadaraform":case"Jadaraform":case"JadaraForm":return u.jsx(JW,{onValidate:UA=>{jI("jadaraform-data",UA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"jadara-form-ar":return u.jsx(HW,{onValidate:UA=>{jI("تم إرسال النموذج",UA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});default:return u.jsx(Be,{remarkPlugins:[Ee],components:lE,children:te(p.text)})}else try{const UA=typeof p.text=="string"?JSON.parse(p.text):p.text;switch(UA.type.toLowerCase()){case"products":return u.jsx(BG,{products:UA[0].items||[],onValidate:LA=>{jI("cart",LA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA});case"easyspaceform":return u.jsx(Qz,{onValidate:LA=>{jI("formulaire soumis",LA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"evform":return u.jsx(isA,{onValidate:LA=>{jI("formulaire soumis",LA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r,mainColor:H});case"evform-visiteur":return u.jsx(osA,{onValidate:LA=>{jI("formulaire soumis",LA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r,mainColor:H});case"xcmgform":return u.jsx(OW,{onValidate:LA=>{jI("formulaire soumis",LA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"auditec-form":return u.jsx(mW,{onValidate:LA=>{jI("formulaire soumis",LA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"auditec-form-ar":return u.jsx(kW,{onValidate:LA=>{jI("تم إرسال النموذج",LA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"nousserform":return u.jsx(NW,{onValidate:LA=>{jI("formulaire soumis",LA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"jadaraform":case"Jadaraform":case"JadaraForm":return u.jsx(JW,{onValidate:LA=>{jI("formulaire soumis",LA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"jadara-form-ar":return u.jsx(HW,{onValidate:LA=>{jI("تم إرسال النموذج",LA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});default:return u.jsx(Be,{remarkPlugins:[Ee],components:lE,children:te(p.text)})}}catch{return u.jsx(Be,{remarkPlugins:[Ee],components:lE,children:te(p.text)})}case"single-choice":return u.jsxs(u.Fragment,{children:[u.jsx(Be,{remarkPlugins:[Ee],components:lE,children:te(p.text)||""}),u.jsx("div",{className:"mt-2 flex flex-col gap-1",dir:tw(p.text||"")?"rtl":"ltr",children:p.choices?.map((UA,LA)=>u.jsxs("button",{onClick:()=>jI(UA.title),className:"w-full flex items-center justify-between px-4 py-2.5 hover:opacity-95 transition-all duration-100",style:{background:iA,borderRadius:"18px",color:X,border:`2px solid ${OC(iA,20)}`},onMouseEnter:Gg=>{Gg.currentTarget.style.borderColor=`${f}`},onMouseLeave:Gg=>{Gg.currentTarget.style.border=`2px solid ${OC(iA,15)}`},dir:aw(UA.title)?"rtl":"ltr",children:[u.jsx("div",{className:"w-full flex items-start gap-2",children:u.jsx(cE,{sequence:[UA.title,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92})}),u.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center"},children:aw(UA.title)?u.jsx(tj,{className:"w-4 h-4",color:f}):u.jsx(aj,{className:"w-4 h-4",color:f})})]},LA))})]});case"image":return u.jsx(u.Fragment,{children:u.jsx("div",{className:"relative group",children:u.jsx("img",{src:p.image,className:"max-w-full max-h-full rounded-lg object-cover cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>window.open(p.image,"_blank")})})});case"dropdown":return u.jsxs(u.Fragment,{children:[u.jsx(Be,{remarkPlugins:[Ee],components:lE,children:te(p.message)}),u.jsx(DsA,{options:p.options||[],message:p.message,allowMultiple:p.allowMultiple||!1,chatRoundness:m,buttonsBgColor:f,buttonColor:J,agentChatResponseColor:X,agentChatResponseBgColor:P,isRtl:tw(p.message||""),onSend:jI,onScroll:()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}})]});case"carousel":return u.jsx(r4,{items:p.items||[],chatRoundness:m,agentChatResponseBgColor:P,agentChatResponseColor:X,buttonsBgColor:f,buttonColor:J,inputBackgroundColor:r,onButtonClick:jI,setMessages:gB});case"card":return u.jsx("div",{className:"mt-2 w-full",children:u.jsx("div",{className:"grid grid-cols-1 gap-3",children:u.jsxs("div",{className:"flex-shrink-0 border rounded-lg p-3 shadow-md",style:{background:P},children:[u.jsx("img",{src:p.image,alt:p.title,className:"max-h-48 w-full object-contain rounded-md mb-2"}),u.jsx("h3",{className:"font-bold",children:p.title}),p.actions?.map((UA,LA)=>u.jsx("button",{className:"mb-1 mr-1 px-4 py-1 hover:scale-105 transition-all duration-100",onClick:()=>{UA.action==="Open URL"?window.open(UA.url,"_blank"):UA.title==="scan"?p.image&&fetch(p.image).then(Gg=>Gg.blob()).then(Gg=>{const OA=URL.createObjectURL(Gg),gI=document.createElement("a");gI.href=OA,gI.download="qrcode.png",document.body.appendChild(gI),gI.click(),document.body.removeChild(gI),URL.revokeObjectURL(OA)}).catch(()=>{alert("Failed to download image.")}):jI(p.title,UA.payload||void 0)},style:{background:f,borderRadius:`${m}px`,color:J},children:UA.title},LA))]})})});case"video":return u.jsx("div",{className:"relative group w-[250px]",children:u.jsx("video",{src:p.video,className:"w-full rounded-lg cursor-pointer hover:opacity-90 transition-opacity",controls:!0})});case"file":const uA=p.file?.split(".").pop?.()?.toLowerCase()||"";return u.jsx("div",{className:"p-2 rounded-lg max-w-xs cursor-pointer transition-colors",onClick:()=>window.open(p.file,"_blank"),onMouseEnter:UA=>UA.currentTarget.style.backgroundColor=f,onMouseLeave:UA=>UA.currentTarget.style.backgroundColor="transparent",title:p.title,children:u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsx("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center",style:{background:f},children:ib(uA,X)}),u.jsx("div",{className:"flex-1 min-w-0",children:u.jsx("p",{className:"text-sm font-medium truncate",style:{color:X},children:p.title})})]})});case"products":return u.jsx(BG,{products:p.products||[],onValidate:UA=>{jI("cart ",UA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"json":switch(p.json?.type){case"text":return u.jsx(Be,{remarkPlugins:[Ee],components:lE,children:te(p.json.content)});case"image":return u.jsx("div",{className:"relative group",children:u.jsx("img",{src:p.json.content,className:"max-h-48 rounded-lg object-cover cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>window.open(p.json?.content,"_blank")})});case"video":return u.jsx("div",{className:"relative group",children:u.jsx("video",{src:p.json.content,className:"max-h-48 rounded-lg object-cover cursor-pointer hover:opacity-90 transition-opacity",controls:!0})});case"document":const UA=p.json.content.split(".").pop?.()?.toLowerCase();return u.jsx("div",{className:"w-[300px] p-2 rounded-lg max-w-xs cursor-pointer transition-colors",onClick:()=>window.open(p.json?.content,"_blank"),onMouseEnter:OA=>OA.currentTarget.style.backgroundColor=f,onMouseLeave:OA=>OA.currentTarget.style.backgroundColor="transparent",title:p.json?.title,children:u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsx("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center",style:{background:f},children:ib(UA||"",X)}),u.jsx("div",{className:"flex-1 min-w-0",children:u.jsx("p",{className:"text-sm font-medium truncate",style:{color:X},children:p.json.title})})]})});case"audio":return u.jsx("div",{className:"w-[300px]",children:u.jsx(yW,{src:p.json.content,mainColor:s,secondaryColor:a,controlsColor:X})});case"cards":return p.json.content.map((OA,gI)=>u.jsx("div",{className:"mt-2 w-full",children:u.jsx("div",{className:"grid grid-cols-1 gap-3",children:u.jsxs("div",{className:"flex-shrink-0 border rounded-lg p-3 shadow-md",style:{background:P},children:[u.jsx("img",{src:OA.image,alt:OA.title,className:"max-h-48 w-full rounded-md mb-2"}),u.jsx("h3",{className:"font-bold",children:OA.title}),OA.button?.map((aI,SB)=>u.jsx("button",{className:"mb-1 mr-1 px-4 py-1 hover:scale-105 transition-all duration-100",onClick:()=>{if(aI.type==="link"&&typeof aI.action=="string")window.open(aI.action,"_blank");else if(aI.type==="postback"){const RI=(typeof aI.action=="string",aI.action);jI(aI.label,RI)}else aI.type==="say-something"&&typeof aI.action=="string"&&gB(RI=>[...RI,{sender:"agent",content:aI.action,id:`msg-${Date.now()}`,timestamp:new Date,seen:!0}])},style:{background:f,borderRadius:`${m}px`,color:J},children:aI.label},SB))]})})},gI));case"slider":const LA=p.json.content.map(OA=>({image:OA.image,title:OA.caption,subtitle:"",actions:[]}));return u.jsx(r4,{items:LA,chatRoundness:m,agentChatResponseBgColor:P,agentChatResponseColor:X,buttonsBgColor:f,buttonColor:J,inputBackgroundColor:r,onButtonClick:jI,setMessages:gB});case"carousel":const Gg=p.json.content.map(OA=>({image:OA.image,title:OA.title,subtitle:OA.description||"",actions:OA.button?.map(gI=>({title:gI.label,payload:gI.action,action:gI.type,url:typeof gI.action=="string"?gI.action:""}))||[]}));return u.jsx(r4,{items:Gg,chatRoundness:m,agentChatResponseBgColor:P,agentChatResponseColor:X,buttonsBgColor:f,buttonColor:J,inputBackgroundColor:r,onButtonClick:jI,setMessages:gB});case"products":return u.jsx(BG,{products:p.json.content,onValidate:OA=>{jI("cart ",OA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});default:return null}}},Nw=async p=>{if(!ZI)return;const uA=await fetch(`${Qh}/endusers/get-by-username`,{headers:{Authorization:`Bearer ${g?.token}`,"Content-Type":"application/json"},method:"POST",body:JSON.stringify({username:`web_user_${p}`})});if(!uA.ok)throw new Error(`HTTP error! status: ${uA.status}`);return(await uA.json()).id},zC=async p=>{if(!ZI)return;const uA=await Nw(p);let UA;PI&&(UA={last_name:PI.split(" ")[1]||PI.split(" ")[0]||`web_user_${p}`,first_name:PI.split(" ")[0]||`web_user_${p}`}),sC&&(UA={...UA,phone:sC}),WE&&(UA={...UA,email:WE});const LA=await fetch(`${Qh}/endusers/${uA}`,{headers:{Authorization:`Bearer ${g?.token}`,"Content-Type":"application/json"},method:"PUT",body:JSON.stringify(UA)});if(!LA.ok)throw new Error(`HTTP error! status: ${LA.status}`);return await LA.json()},mQ=async p=>{p.preventDefault();try{const UA=(await OB.post(`${Qh}/conversations/start-conversation`,{bot_id:g.bot?.botId,externalUser:g.user.id})).data.conversationId;ug(UA),localStorage.setItem("conversationId",UA),localStorage.setItem("webChatAuth","true"),NB(!0),hG.emit("join_room",parseInt(UA))}catch(uA){console.error("Error during login:",uA)}},[EI,PQ]=vA.useState(!1),pe=async()=>{gB([]),localStorage.removeItem("enduserUpdated");const p=localStorage.getItem("phone_client");if(g.bot?.botId==="rockskin"&&p)return YB(p),localStorage.setItem("externalUser",p),p;const uA=new Uint8Array(16);window.crypto.getRandomValues(uA);const UA=Array.from(uA).map(LA=>LA.toString(16).padStart(2,"0")).join("");YB(UA),localStorage.setItem("externalUser",UA),localStorage.removeItem("conversationId"),ug(null)},$i=`linear-gradient(to bottom right, ${G}, ${s}, ${G})`,TC=`linear-gradient(to right, ${s}, ${a})`,QQ=`linear-gradient(to right, ${R}, ${U})`,GC=async(p,uA)=>{try{let UA="";if(typeof p=="string")UA=p;else for(const LA of p)LA.type==="text"&&LA.text?UA+=`
635
+ ***************************************************************************** */function jW(g,A){const[I,B]=vA.useState(null),E=vA.useMemo(()=>Object.entries(A).flat(),[A]);return vA.useEffect(()=>{if(!g?.current)return;const C=U4.create(Object.assign(Object.assign({},A),{container:g.current}));return B(C),()=>{C.destroy()}},[g,...E]),I}const pW=/^on([A-Z])/,GsA=g=>pW.test(g);function YsA(g,A){const I=vA.useMemo(()=>Object.entries(A).flat(),[A]);vA.useEffect(()=>{if(!g)return;const B=Object.entries(A);if(!B.length)return;const E=B.map(([C,Q])=>{const o=C.replace(pW,(w,M)=>M.toLowerCase());return g.on(o,(...w)=>Q(g,...w))});return()=>{E.forEach(C=>C())}},[g,...I])}vA.memo(g=>{const A=vA.useRef(null),[I,B]=function(E){return vA.useMemo(()=>{const C=Object.assign({},E),Q=Object.assign({},E);for(const o in C)GsA(o)?delete C[o]:delete Q[o];return[C,Q]},[E])}(g);return YsA(jW(A,I),B),u.jsx("div",{ref:A})});function RsA(g){var{container:A}=g;const I=jW(A,function(E,C){var Q={};for(var o in E)Object.prototype.hasOwnProperty.call(E,o)&&C.indexOf(o)<0&&(Q[o]=E[o]);if(E!=null&&typeof Object.getOwnPropertySymbols=="function"){var w=0;for(o=Object.getOwnPropertySymbols(E);w<o.length;w++)C.indexOf(o[w])<0&&Object.prototype.propertyIsEnumerable.call(E,o[w])&&(Q[o[w]]=E[o[w]])}return Q}(g,["container"])),B=function(E){const[C,Q]=vA.useState(!1),[o,w]=vA.useState(!1),[M,D]=vA.useState(!1),[t,s]=vA.useState(0);return vA.useEffect(()=>{if(!E)return;const a=[E.on("load",()=>{Q(!1),w(!1),s(0)}),E.on("ready",()=>{Q(!0),w(!1),D(!1),s(0)}),E.on("finish",()=>{D(!0)}),E.on("play",()=>{w(!0)}),E.on("pause",()=>{w(!1)}),E.on("timeupdate",()=>{s(E.getCurrentTime())}),E.on("destroy",()=>{Q(!1),w(!1)})];return()=>{a.forEach(G=>G())}},[E]),vA.useMemo(()=>({isReady:C,isPlaying:o,hasFinished:M,currentTime:t}),[o,M,t,C])}(I);return vA.useMemo(()=>Object.assign(Object.assign({},B),{wavesurfer:I}),[B,I])}const yW=({src:g,mainColor:A,secondaryColor:I,controlsColor:B})=>{const E=vA.useRef(null),[C,Q]=vA.useState(1),{wavesurfer:o,isPlaying:w}=RsA({container:E,waveColor:A,progressColor:I,barWidth:2,height:50,url:g}),M=()=>{o&&o.playPause()},D=()=>{const a=C===0?1:0;Q(a),o?.setVolume(a)},t=()=>{o?.skip(-.096)},s=()=>{o?.skip(.096)};return u.jsxs("div",{className:"flex w-full flex-col items-center rounded-xl pt-1",children:[u.jsx("div",{ref:E,className:"w-full px-2"}),u.jsxs("div",{className:"flex w-full items-center justify-between",children:[u.jsx("div",{className:"relative flex items-center",children:u.jsx("button",{className:"transition-colors",style:{color:B},onClick:D,"aria-label":"Toggle volume",children:C===0?u.jsx(WIA,{size:20}):u.jsx(TIA,{size:20})})}),u.jsxs("div",{className:"-ml-9 flex flex-1 cursor-auto justify-center gap-2 rounded-full py-2 text-white",children:[u.jsx("button",{onClick:t,className:"cursor-pointer hover:scale-110 transition-colors",style:{color:B},"aria-label":"Step back",children:u.jsx(qIA,{})}),u.jsx("button",{onClick:M,className:"cursor-pointer hover:scale-110 transition-colors",style:{color:B},"aria-label":w?"Pause":"Play",children:w?u.jsx(jIA,{}):u.jsx(pIA,{})}),u.jsx("button",{onClick:s,className:"cursor-pointer hover:scale-110 transition-colors",style:{color:B},"aria-label":"Step forward",children:u.jsx(ZIA,{})})]})]})]})},rsA=({attachment:g,formatFileSize:A,mainColor:I,secondaryColor:B,controlsColor:E})=>{const{type:C,url:Q,name:o,size:w}=g;switch(C){case"image":return u.jsxs("div",{className:"relative group",children:[u.jsx("img",{src:Q,alt:o,className:"max-w-xs max-h-48 size-full rounded-lg object-cover cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>window.open(Q,"_blank")}),u.jsx("div",{className:"absolute bottom-2 left-2 bg-black bg-opacity-60 text-white text-xs px-2 py-1 rounded",children:A(w)})]});case"video":return u.jsxs("div",{className:"max-w-xs",children:[u.jsx("video",{src:Q,controls:!0,className:"w-full max-h-48 rounded-lg",preload:"metadata",onError:()=>{console.error("Video failed to load:",Q)},children:"Your browser does not support the video tag."}),u.jsxs("div",{className:"flex text-xs text-white mt-1 w-full overflow-hidden whitespace-nowrap text-ellipsis",children:[u.jsx("span",{className:"block w-full overflow-hidden whitespace-nowrap text-ellipsis",title:o,children:o}),u.jsxs("span",{className:"ml-2",children:["• ",A(w)]})]})]});case"audio":return u.jsxs("div",{className:"bg-gray-800 bg-opacity-70 p-3 rounded-lg flex-1 w-full",children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[u.jsx(zr,{className:"w-4 h-4",style:{color:I}}),u.jsx("span",{className:"text-sm font-medium truncate text-white",title:o,children:o})]}),u.jsx(yW,{src:Q,mainColor:I,secondaryColor:B,controlsColor:E}),u.jsx("p",{className:"text-xs text-gray-400 mt-1",children:A(w)})]});case"document":return u.jsx("div",{className:"bg-gray-800 bg-opacity-50 p-3 rounded-lg max-w-xs cursor-pointer hover:bg-opacity-70 transition-colors",onClick:()=>window.open(Q,"_blank"),children:u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsx("div",{className:"w-10 h-10 bg-purple-600 rounded-lg flex items-center justify-center",children:u.jsx(Ce,{className:"w-5 h-5 text-white"})}),u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsx("p",{className:"text-sm font-medium truncate text-white",children:o}),u.jsx("p",{className:"text-xs text-gray-400",children:A(w)})]})]})});default:return null}},nsA=vA.memo(({attachment:g,onRemove:A})=>u.jsxs("div",{className:"relative group w-24 h-24 rounded-xl overflow-hidden bg-gray-900 shadow-md border border-gray-700",children:[g.type==="image"&&g.url?u.jsx("img",{src:g.url,alt:g.name,className:"w-full h-full object-cover"}):u.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center text-gray-300 px-1 text-center text-xs",children:[g.type==="video"&&u.jsx(Rj,{className:"w-5 h-5 mb-1 text-red-400"}),g.type==="audio"&&u.jsx(zr,{className:"w-5 h-5 mb-1 text-green-400"}),g.type==="document"&&u.jsx(sj,{className:"w-5 h-5 mb-1 text-yellow-400"}),u.jsx("span",{className:"w-full truncate",title:g.name,children:g.name})]}),u.jsx("button",{onClick:A,className:"absolute top-1 right-1 w-5 h-5 bg-black bg-opacity-50 rounded-full text-white flex items-center justify-center hover:bg-opacity-80",title:"Remove",children:u.jsx(Qe,{className:"w-3 h-3"})})]})),No=Object.create(null);No.open="0",No.close="1",No.ping="2",No.pong="3",No.message="4",No.upgrade="5",No.noop="6";const CG=Object.create(null);Object.keys(No).forEach(g=>{CG[No[g]]=g});const l4={type:"error",data:"parser error"},LW=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",VW=typeof ArrayBuffer=="function",qW=g=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(g):g&&g.buffer instanceof ArrayBuffer,K4=({type:g,data:A},I,B)=>LW&&A instanceof Blob?I?B(A):ZW(A,B):VW&&(A instanceof ArrayBuffer||qW(A))?I?B(A):ZW(new Blob([A]),B):B(No[g]+(A||"")),ZW=(g,A)=>{const I=new FileReader;return I.onload=function(){const B=I.result.split(",")[1];A("b"+(B||""))},I.readAsDataURL(g)};function zW(g){return g instanceof Uint8Array?g:g instanceof ArrayBuffer?new Uint8Array(g):new Uint8Array(g.buffer,g.byteOffset,g.byteLength)}let S4;function FsA(g,A){if(LW&&g.data instanceof Blob)return g.data.arrayBuffer().then(zW).then(A);if(VW&&(g.data instanceof ArrayBuffer||qW(g.data)))return A(zW(g.data));K4(g,!1,I=>{S4||(S4=new TextEncoder),A(S4.encode(I))})}const TW="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",vt=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let g=0;g<TW.length;g++)vt[TW.charCodeAt(g)]=g;const UsA=g=>{let A=g.length*.75,I=g.length,B,E=0,C,Q,o,w;g[g.length-1]==="="&&(A--,g[g.length-2]==="="&&A--);const M=new ArrayBuffer(A),D=new Uint8Array(M);for(B=0;B<I;B+=4)C=vt[g.charCodeAt(B)],Q=vt[g.charCodeAt(B+1)],o=vt[g.charCodeAt(B+2)],w=vt[g.charCodeAt(B+3)],D[E++]=C<<2|Q>>4,D[E++]=(Q&15)<<4|o>>2,D[E++]=(o&3)<<6|w&63;return M},lsA=typeof ArrayBuffer=="function",u4=(g,A)=>{if(typeof g!="string")return{type:"message",data:WW(g,A)};const I=g.charAt(0);return I==="b"?{type:"message",data:KsA(g.substring(1),A)}:CG[I]?g.length>1?{type:CG[I],data:g.substring(1)}:{type:CG[I]}:l4},KsA=(g,A)=>{if(lsA){const I=UsA(g);return WW(I,A)}else return{base64:!0,data:g}},WW=(g,A)=>{switch(A){case"blob":return g instanceof Blob?g:new Blob([g]);case"arraybuffer":default:return g instanceof ArrayBuffer?g:g.buffer}},bW="",SsA=(g,A)=>{const I=g.length,B=new Array(I);let E=0;g.forEach((C,Q)=>{K4(C,!1,o=>{B[Q]=o,++E===I&&A(B.join(bW))})})},usA=(g,A)=>{const I=g.split(bW),B=[];for(let E=0;E<I.length;E++){const C=u4(I[E],A);if(B.push(C),C.type==="error")break}return B};function msA(){return new TransformStream({transform(g,A){FsA(g,I=>{const B=I.length;let E;if(B<126)E=new Uint8Array(1),new DataView(E.buffer).setUint8(0,B);else if(B<65536){E=new Uint8Array(3);const C=new DataView(E.buffer);C.setUint8(0,126),C.setUint16(1,B)}else{E=new Uint8Array(9);const C=new DataView(E.buffer);C.setUint8(0,127),C.setBigUint64(1,BigInt(B))}g.data&&typeof g.data!="string"&&(E[0]|=128),A.enqueue(E),A.enqueue(I)})}})}let m4;function QG(g){return g.reduce((A,I)=>A+I.length,0)}function iG(g,A){if(g[0].length===A)return g.shift();const I=new Uint8Array(A);let B=0;for(let E=0;E<A;E++)I[E]=g[0][B++],B===g[0].length&&(g.shift(),B=0);return g.length&&B<g[0].length&&(g[0]=g[0].slice(B)),I}function ksA(g,A){m4||(m4=new TextDecoder);const I=[];let B=0,E=-1,C=!1;return new TransformStream({transform(Q,o){for(I.push(Q);;){if(B===0){if(QG(I)<1)break;const w=iG(I,1);C=(w[0]&128)===128,E=w[0]&127,E<126?B=3:E===126?B=1:B=2}else if(B===1){if(QG(I)<2)break;const w=iG(I,2);E=new DataView(w.buffer,w.byteOffset,w.length).getUint16(0),B=3}else if(B===2){if(QG(I)<8)break;const w=iG(I,8),M=new DataView(w.buffer,w.byteOffset,w.length),D=M.getUint32(0);if(D>Math.pow(2,21)-1){o.enqueue(l4);break}E=D*Math.pow(2,32)+M.getUint32(4),B=3}else{if(QG(I)<E)break;const w=iG(I,E);o.enqueue(u4(C?w:m4.decode(w),A)),B=0}if(E===0||E>g){o.enqueue(l4);break}}}})}const PW=4;function jE(g){if(g)return OsA(g)}function OsA(g){for(var A in jE.prototype)g[A]=jE.prototype[A];return g}jE.prototype.on=jE.prototype.addEventListener=function(g,A){return this._callbacks=this._callbacks||{},(this._callbacks["$"+g]=this._callbacks["$"+g]||[]).push(A),this},jE.prototype.once=function(g,A){function I(){this.off(g,I),A.apply(this,arguments)}return I.fn=A,this.on(g,I),this},jE.prototype.off=jE.prototype.removeListener=jE.prototype.removeAllListeners=jE.prototype.removeEventListener=function(g,A){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var I=this._callbacks["$"+g];if(!I)return this;if(arguments.length==1)return delete this._callbacks["$"+g],this;for(var B,E=0;E<I.length;E++)if(B=I[E],B===A||B.fn===A){I.splice(E,1);break}return I.length===0&&delete this._callbacks["$"+g],this},jE.prototype.emit=function(g){this._callbacks=this._callbacks||{};for(var A=new Array(arguments.length-1),I=this._callbacks["$"+g],B=1;B<arguments.length;B++)A[B-1]=arguments[B];if(I){I=I.slice(0);for(var B=0,E=I.length;B<E;++B)I[B].apply(this,A)}return this},jE.prototype.emitReserved=jE.prototype.emit,jE.prototype.listeners=function(g){return this._callbacks=this._callbacks||{},this._callbacks["$"+g]||[]},jE.prototype.hasListeners=function(g){return!!this.listeners(g).length};const oG=typeof Promise=="function"&&typeof Promise.resolve=="function"?A=>Promise.resolve().then(A):(A,I)=>I(A,0),oi=typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),JsA="arraybuffer";function BmA(){}function fW(g,...A){return A.reduce((I,B)=>(g.hasOwnProperty(B)&&(I[B]=g[B]),I),{})}const HsA=oi.setTimeout,NsA=oi.clearTimeout;function wG(g,A){A.useNativeTimers?(g.setTimeoutFn=HsA.bind(oi),g.clearTimeoutFn=NsA.bind(oi)):(g.setTimeoutFn=oi.setTimeout.bind(oi),g.clearTimeoutFn=oi.clearTimeout.bind(oi))}const xsA=1.33;function dsA(g){return typeof g=="string"?jsA(g):Math.ceil((g.byteLength||g.size)*xsA)}function jsA(g){let A=0,I=0;for(let B=0,E=g.length;B<E;B++)A=g.charCodeAt(B),A<128?I+=1:A<2048?I+=2:A<55296||A>=57344?I+=3:(B++,I+=4);return I}function XW(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function psA(g){let A="";for(let I in g)g.hasOwnProperty(I)&&(A.length&&(A+="&"),A+=encodeURIComponent(I)+"="+encodeURIComponent(g[I]));return A}function ysA(g){let A={},I=g.split("&");for(let B=0,E=I.length;B<E;B++){let C=I[B].split("=");A[decodeURIComponent(C[0])]=decodeURIComponent(C[1])}return A}class LsA extends Error{constructor(A,I,B){super(A),this.description=I,this.context=B,this.type="TransportError"}}class k4 extends jE{constructor(A){super(),this.writable=!1,wG(this,A),this.opts=A,this.query=A.query,this.socket=A.socket,this.supportsBinary=!A.forceBase64}onError(A,I,B){return super.emitReserved("error",new LsA(A,I,B)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(A){this.readyState==="open"&&this.write(A)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(A){const I=u4(A,this.socket.binaryType);this.onPacket(I)}onPacket(A){super.emitReserved("packet",A)}onClose(A){this.readyState="closed",super.emitReserved("close",A)}pause(A){}createUri(A,I={}){return A+"://"+this._hostname()+this._port()+this.opts.path+this._query(I)}_hostname(){const A=this.opts.hostname;return A.indexOf(":")===-1?A:"["+A+"]"}_port(){return this.opts.port&&(this.opts.secure&&+(this.opts.port!==443)||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(A){const I=psA(A);return I.length?"?"+I:""}}class VsA extends k4{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(A){this.readyState="pausing";const I=()=>{this.readyState="paused",A()};if(this._polling||!this.writable){let B=0;this._polling&&(B++,this.once("pollComplete",function(){--B||I()})),this.writable||(B++,this.once("drain",function(){--B||I()}))}else I()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(A){const I=B=>{if(this.readyState==="opening"&&B.type==="open"&&this.onOpen(),B.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(B)};usA(A,this.socket.binaryType).forEach(I),this.readyState!=="closed"&&(this._polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this._poll())}doClose(){const A=()=>{this.write([{type:"close"}])};this.readyState==="open"?A():this.once("open",A)}write(A){this.writable=!1,SsA(A,I=>{this.doWrite(I,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const A=this.opts.secure?"https":"http",I=this.query||{};return this.opts.timestampRequests!==!1&&(I[this.opts.timestampParam]=XW()),!this.supportsBinary&&!I.sid&&(I.b64=1),this.createUri(A,I)}}let vW=!1;try{vW=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}const qsA=vW;function ZsA(){}class zsA extends VsA{constructor(A){if(super(A),typeof location<"u"){const I=location.protocol==="https:";let B=location.port;B||(B=I?"443":"80"),this.xd=typeof location<"u"&&A.hostname!==location.hostname||B!==A.port}}doWrite(A,I){const B=this.request({method:"POST",data:A});B.on("success",I),B.on("error",(E,C)=>{this.onError("xhr post error",E,C)})}doPoll(){const A=this.request();A.on("data",this.onData.bind(this)),A.on("error",(I,B)=>{this.onError("xhr poll error",I,B)}),this.pollXhr=A}}let Eh=class OR extends jE{constructor(A,I,B){super(),this.createRequest=A,wG(this,B),this._opts=B,this._method=B.method||"GET",this._uri=I,this._data=B.data!==void 0?B.data:null,this._create()}_create(){var A;const I=fW(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");I.xdomain=!!this._opts.xd;const B=this._xhr=this.createRequest(I);try{B.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){B.setDisableHeaderCheck&&B.setDisableHeaderCheck(!0);for(let E in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(E)&&B.setRequestHeader(E,this._opts.extraHeaders[E])}}catch{}if(this._method==="POST")try{B.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{B.setRequestHeader("Accept","*/*")}catch{}(A=this._opts.cookieJar)===null||A===void 0||A.addCookies(B),"withCredentials"in B&&(B.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(B.timeout=this._opts.requestTimeout),B.onreadystatechange=()=>{var E;B.readyState===3&&((E=this._opts.cookieJar)===null||E===void 0||E.parseCookies(B.getResponseHeader("set-cookie"))),B.readyState===4&&(B.status===200||B.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof B.status=="number"?B.status:0)},0))},B.send(this._data)}catch(E){this.setTimeoutFn(()=>{this._onError(E)},0);return}typeof document<"u"&&(this._index=OR.requestsCount++,OR.requests[this._index]=this)}_onError(A){this.emitReserved("error",A,this._xhr),this._cleanup(!0)}_cleanup(A){if(!(typeof this._xhr>"u"||this._xhr===null)){if(this._xhr.onreadystatechange=ZsA,A)try{this._xhr.abort()}catch{}typeof document<"u"&&delete OR.requests[this._index],this._xhr=null}}_onLoad(){const A=this._xhr.responseText;A!==null&&(this.emitReserved("data",A),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}};if(Eh.requestsCount=0,Eh.requests={},typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",_W);else if(typeof addEventListener=="function"){const g="onpagehide"in oi?"pagehide":"unload";addEventListener(g,_W,!1)}}function _W(){for(let g in Eh.requests)Eh.requests.hasOwnProperty(g)&&Eh.requests[g].abort()}const TsA=function(){const g=$W({xdomain:!1});return g&&g.responseType!==null}();class WsA extends zsA{constructor(A){super(A);const I=A&&A.forceBase64;this.supportsBinary=TsA&&!I}request(A={}){return Object.assign(A,{xd:this.xd},this.opts),new Eh($W,this.uri(),A)}}function $W(g){const A=g.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!A||qsA))return new XMLHttpRequest}catch{}if(!A)try{return new oi[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}const Ab=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class bsA extends k4{get name(){return"websocket"}doOpen(){const A=this.uri(),I=this.opts.protocols,B=Ab?{}:fW(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(B.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(A,I,B)}catch(E){return this.emitReserved("error",E)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=A=>this.onClose({description:"websocket connection closed",context:A}),this.ws.onmessage=A=>this.onData(A.data),this.ws.onerror=A=>this.onError("websocket error",A)}write(A){this.writable=!1;for(let I=0;I<A.length;I++){const B=A[I],E=I===A.length-1;K4(B,this.supportsBinary,C=>{try{this.doWrite(B,C)}catch{}E&&oG(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){const A=this.opts.secure?"wss":"ws",I=this.query||{};return this.opts.timestampRequests&&(I[this.opts.timestampParam]=XW()),this.supportsBinary||(I.b64=1),this.createUri(A,I)}}const O4=oi.WebSocket||oi.MozWebSocket;class PsA extends bsA{createSocket(A,I,B){return Ab?new O4(A,I,B):I?new O4(A,I):new O4(A)}doWrite(A,I){this.ws.send(I)}}class fsA extends k4{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(A){return this.emitReserved("error",A)}this._transport.closed.then(()=>{this.onClose()}).catch(A=>{this.onError("webtransport error",A)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(A=>{const I=ksA(Number.MAX_SAFE_INTEGER,this.socket.binaryType),B=A.readable.pipeThrough(I).getReader(),E=msA();E.readable.pipeTo(A.writable),this._writer=E.writable.getWriter();const C=()=>{B.read().then(({done:o,value:w})=>{o||(this.onPacket(w),C())}).catch(o=>{})};C();const Q={type:"open"};this.query.sid&&(Q.data=`{"sid":"${this.query.sid}"}`),this._writer.write(Q).then(()=>this.onOpen())})})}write(A){this.writable=!1;for(let I=0;I<A.length;I++){const B=A[I],E=I===A.length-1;this._writer.write(B).then(()=>{E&&oG(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var A;(A=this._transport)===null||A===void 0||A.close()}}const XsA={websocket:PsA,webtransport:fsA,polling:WsA},vsA=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,_sA=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function J4(g){if(g.length>8e3)throw"URI too long";const A=g,I=g.indexOf("["),B=g.indexOf("]");I!=-1&&B!=-1&&(g=g.substring(0,I)+g.substring(I,B).replace(/:/g,";")+g.substring(B,g.length));let E=vsA.exec(g||""),C={},Q=14;for(;Q--;)C[_sA[Q]]=E[Q]||"";return I!=-1&&B!=-1&&(C.source=A,C.host=C.host.substring(1,C.host.length-1).replace(/;/g,":"),C.authority=C.authority.replace("[","").replace("]","").replace(/;/g,":"),C.ipv6uri=!0),C.pathNames=$sA(C,C.path),C.queryKey=AcA(C,C.query),C}function $sA(g,A){const I=/\/{2,9}/g,B=A.replace(I,"/").split("/");return(A.slice(0,1)=="/"||A.length===0)&&B.splice(0,1),A.slice(-1)=="/"&&B.splice(B.length-1,1),B}function AcA(g,A){const I={};return A.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(B,E,C){E&&(I[E]=C)}),I}const H4=typeof addEventListener=="function"&&typeof removeEventListener=="function",eG=[];H4&&addEventListener("offline",()=>{eG.forEach(g=>g())},!1);class Fe extends jE{constructor(A,I){if(super(),this.binaryType=JsA,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,A&&typeof A=="object"&&(I=A,A=null),A){const B=J4(A);I.hostname=B.host,I.secure=B.protocol==="https"||B.protocol==="wss",I.port=B.port,B.query&&(I.query=B.query)}else I.host&&(I.hostname=J4(I.host).host);wG(this,I),this.secure=I.secure!=null?I.secure:typeof location<"u"&&location.protocol==="https:",I.hostname&&!I.port&&(I.port=this.secure?"443":"80"),this.hostname=I.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=I.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},I.transports.forEach(B=>{const E=B.prototype.name;this.transports.push(E),this._transportsByName[E]=B}),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},I),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=ysA(this.opts.query)),H4&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},eG.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(A){const I=Object.assign({},this.opts.query);I.EIO=PW,I.transport=A,this.id&&(I.sid=this.id);const B=Object.assign({},this.opts,{query:I,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[A]);return new this._transportsByName[A](B)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}const A=this.opts.rememberUpgrade&&Fe.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports[0];this.readyState="opening";const I=this.createTransport(A);I.open(),this.setTransport(I)}setTransport(A){this.transport&&this.transport.removeAllListeners(),this.transport=A,A.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",I=>this._onClose("transport close",I))}onOpen(){this.readyState="open",Fe.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush()}_onPacket(A){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(this.emitReserved("packet",A),this.emitReserved("heartbeat"),A.type){case"open":this.onHandshake(JSON.parse(A.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":const I=new Error("server error");I.code=A.data,this._onError(I);break;case"message":this.emitReserved("data",A.data),this.emitReserved("message",A.data);break}}onHandshake(A){this.emitReserved("handshake",A),this.id=A.sid,this.transport.query.sid=A.sid,this._pingInterval=A.pingInterval,this._pingTimeout=A.pingTimeout,this._maxPayload=A.maxPayload,this.onOpen(),this.readyState!=="closed"&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);const A=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+A,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},A),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const A=this._getWritablePackets();this.transport.send(A),this._prevBufferLen=A.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let I=1;for(let B=0;B<this.writeBuffer.length;B++){const E=this.writeBuffer[B].data;if(E&&(I+=dsA(E)),B>0&&I>this._maxPayload)return this.writeBuffer.slice(0,B);I+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const A=Date.now()>this._pingTimeoutTime;return A&&(this._pingTimeoutTime=0,oG(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),A}write(A,I,B){return this._sendPacket("message",A,I,B),this}send(A,I,B){return this._sendPacket("message",A,I,B),this}_sendPacket(A,I,B,E){if(typeof I=="function"&&(E=I,I=void 0),typeof B=="function"&&(E=B,B=null),this.readyState==="closing"||this.readyState==="closed")return;B=B||{},B.compress=B.compress!==!1;const C={type:A,data:I,options:B};this.emitReserved("packetCreate",C),this.writeBuffer.push(C),E&&this.once("flush",E),this.flush()}close(){const A=()=>{this._onClose("forced close"),this.transport.close()},I=()=>{this.off("upgrade",I),this.off("upgradeError",I),A()},B=()=>{this.once("upgrade",I),this.once("upgradeError",I)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?B():A()}):this.upgrading?B():A()),this}_onError(A){if(Fe.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState==="opening")return this.transports.shift(),this._open();this.emitReserved("error",A),this._onClose("transport error",A)}_onClose(A,I){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing"){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),H4&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const B=eG.indexOf(this._offlineEventListener);B!==-1&&eG.splice(B,1)}this.readyState="closed",this.id=null,this.emitReserved("close",A,I),this.writeBuffer=[],this._prevBufferLen=0}}}Fe.protocol=PW;class gcA extends Fe{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState==="open"&&this.opts.upgrade)for(let A=0;A<this._upgrades.length;A++)this._probe(this._upgrades[A])}_probe(A){let I=this.createTransport(A),B=!1;Fe.priorWebsocketSuccess=!1;const E=()=>{B||(I.send([{type:"ping",data:"probe"}]),I.once("packet",t=>{if(!B)if(t.type==="pong"&&t.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",I),!I)return;Fe.priorWebsocketSuccess=I.name==="websocket",this.transport.pause(()=>{B||this.readyState!=="closed"&&(D(),this.setTransport(I),I.send([{type:"upgrade"}]),this.emitReserved("upgrade",I),I=null,this.upgrading=!1,this.flush())})}else{const s=new Error("probe error");s.transport=I.name,this.emitReserved("upgradeError",s)}}))};function C(){B||(B=!0,D(),I.close(),I=null)}const Q=t=>{const s=new Error("probe error: "+t);s.transport=I.name,C(),this.emitReserved("upgradeError",s)};function o(){Q("transport closed")}function w(){Q("socket closed")}function M(t){I&&t.name!==I.name&&C()}const D=()=>{I.removeListener("open",E),I.removeListener("error",Q),I.removeListener("close",o),this.off("close",w),this.off("upgrading",M)};I.once("open",E),I.once("error",Q),I.once("close",o),this.once("close",w),this.once("upgrading",M),this._upgrades.indexOf("webtransport")!==-1&&A!=="webtransport"?this.setTimeoutFn(()=>{B||I.open()},200):I.open()}onHandshake(A){this._upgrades=this._filterUpgrades(A.upgrades),super.onHandshake(A)}_filterUpgrades(A){const I=[];for(let B=0;B<A.length;B++)~this.transports.indexOf(A[B])&&I.push(A[B]);return I}}let IcA=class extends gcA{constructor(A,I={}){const B=typeof A=="object"?A:I;(!B.transports||B.transports&&typeof B.transports[0]=="string")&&(B.transports=(B.transports||["polling","websocket","webtransport"]).map(E=>XsA[E]).filter(E=>!!E)),super(A,B)}};function BcA(g,A="",I){let B=g;I=I||typeof location<"u"&&location,g==null&&(g=I.protocol+"//"+I.host),typeof g=="string"&&(g.charAt(0)==="/"&&(g.charAt(1)==="/"?g=I.protocol+g:g=I.host+g),/^(https?|wss?):\/\//.test(g)||(typeof I<"u"?g=I.protocol+"//"+g:g="https://"+g),B=J4(g)),B.port||(/^(http|ws)$/.test(B.protocol)?B.port="80":/^(http|ws)s$/.test(B.protocol)&&(B.port="443")),B.path=B.path||"/";const C=B.host.indexOf(":")!==-1?"["+B.host+"]":B.host;return B.id=B.protocol+"://"+C+":"+B.port+A,B.href=B.protocol+"://"+C+(I&&I.port===B.port?"":":"+B.port),B}const EcA=typeof ArrayBuffer=="function",CcA=g=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(g):g.buffer instanceof ArrayBuffer,gb=Object.prototype.toString,QcA=typeof Blob=="function"||typeof Blob<"u"&&gb.call(Blob)==="[object BlobConstructor]",icA=typeof File=="function"||typeof File<"u"&&gb.call(File)==="[object FileConstructor]";function N4(g){return EcA&&(g instanceof ArrayBuffer||CcA(g))||QcA&&g instanceof Blob||icA&&g instanceof File}function MG(g,A){if(!g||typeof g!="object")return!1;if(Array.isArray(g)){for(let I=0,B=g.length;I<B;I++)if(MG(g[I]))return!0;return!1}if(N4(g))return!0;if(g.toJSON&&typeof g.toJSON=="function"&&arguments.length===1)return MG(g.toJSON(),!0);for(const I in g)if(Object.prototype.hasOwnProperty.call(g,I)&&MG(g[I]))return!0;return!1}function ocA(g){const A=[],I=g.data,B=g;return B.data=x4(I,A),B.attachments=A.length,{packet:B,buffers:A}}function x4(g,A){if(!g)return g;if(N4(g)){const I={_placeholder:!0,num:A.length};return A.push(g),I}else if(Array.isArray(g)){const I=new Array(g.length);for(let B=0;B<g.length;B++)I[B]=x4(g[B],A);return I}else if(typeof g=="object"&&!(g instanceof Date)){const I={};for(const B in g)Object.prototype.hasOwnProperty.call(g,B)&&(I[B]=x4(g[B],A));return I}return g}function wcA(g,A){return g.data=d4(g.data,A),delete g.attachments,g}function d4(g,A){if(!g)return g;if(g&&g._placeholder===!0){if(typeof g.num=="number"&&g.num>=0&&g.num<A.length)return A[g.num];throw new Error("illegal attachments")}else if(Array.isArray(g))for(let I=0;I<g.length;I++)g[I]=d4(g[I],A);else if(typeof g=="object")for(const I in g)Object.prototype.hasOwnProperty.call(g,I)&&(g[I]=d4(g[I],A));return g}const ecA=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],McA=5;var bI;(function(g){g[g.CONNECT=0]="CONNECT",g[g.DISCONNECT=1]="DISCONNECT",g[g.EVENT=2]="EVENT",g[g.ACK=3]="ACK",g[g.CONNECT_ERROR=4]="CONNECT_ERROR",g[g.BINARY_EVENT=5]="BINARY_EVENT",g[g.BINARY_ACK=6]="BINARY_ACK"})(bI||(bI={}));class DcA{constructor(A){this.replacer=A}encode(A){return(A.type===bI.EVENT||A.type===bI.ACK)&&MG(A)?this.encodeAsBinary({type:A.type===bI.EVENT?bI.BINARY_EVENT:bI.BINARY_ACK,nsp:A.nsp,data:A.data,id:A.id}):[this.encodeAsString(A)]}encodeAsString(A){let I=""+A.type;return(A.type===bI.BINARY_EVENT||A.type===bI.BINARY_ACK)&&(I+=A.attachments+"-"),A.nsp&&A.nsp!=="/"&&(I+=A.nsp+","),A.id!=null&&(I+=A.id),A.data!=null&&(I+=JSON.stringify(A.data,this.replacer)),I}encodeAsBinary(A){const I=ocA(A),B=this.encodeAsString(I.packet),E=I.buffers;return E.unshift(B),E}}function Ib(g){return Object.prototype.toString.call(g)==="[object Object]"}class j4 extends jE{constructor(A){super(),this.reviver=A}add(A){let I;if(typeof A=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");I=this.decodeString(A);const B=I.type===bI.BINARY_EVENT;B||I.type===bI.BINARY_ACK?(I.type=B?bI.EVENT:bI.ACK,this.reconstructor=new hcA(I),I.attachments===0&&super.emitReserved("decoded",I)):super.emitReserved("decoded",I)}else if(N4(A)||A.base64)if(this.reconstructor)I=this.reconstructor.takeBinaryData(A),I&&(this.reconstructor=null,super.emitReserved("decoded",I));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+A)}decodeString(A){let I=0;const B={type:Number(A.charAt(0))};if(bI[B.type]===void 0)throw new Error("unknown packet type "+B.type);if(B.type===bI.BINARY_EVENT||B.type===bI.BINARY_ACK){const C=I+1;for(;A.charAt(++I)!=="-"&&I!=A.length;);const Q=A.substring(C,I);if(Q!=Number(Q)||A.charAt(I)!=="-")throw new Error("Illegal attachments");B.attachments=Number(Q)}if(A.charAt(I+1)==="/"){const C=I+1;for(;++I&&!(A.charAt(I)===","||I===A.length););B.nsp=A.substring(C,I)}else B.nsp="/";const E=A.charAt(I+1);if(E!==""&&Number(E)==E){const C=I+1;for(;++I;){const Q=A.charAt(I);if(Q==null||Number(Q)!=Q){--I;break}if(I===A.length)break}B.id=Number(A.substring(C,I+1))}if(A.charAt(++I)){const C=this.tryParse(A.substr(I));if(j4.isPayloadValid(B.type,C))B.data=C;else throw new Error("invalid payload")}return B}tryParse(A){try{return JSON.parse(A,this.reviver)}catch{return!1}}static isPayloadValid(A,I){switch(A){case bI.CONNECT:return Ib(I);case bI.DISCONNECT:return I===void 0;case bI.CONNECT_ERROR:return typeof I=="string"||Ib(I);case bI.EVENT:case bI.BINARY_EVENT:return Array.isArray(I)&&(typeof I[0]=="number"||typeof I[0]=="string"&&ecA.indexOf(I[0])===-1);case bI.ACK:case bI.BINARY_ACK:return Array.isArray(I)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class hcA{constructor(A){this.packet=A,this.buffers=[],this.reconPack=A}takeBinaryData(A){if(this.buffers.push(A),this.buffers.length===this.reconPack.attachments){const I=wcA(this.reconPack,this.buffers);return this.finishedReconstruction(),I}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const tcA=Object.freeze(Object.defineProperty({__proto__:null,Decoder:j4,Encoder:DcA,get PacketType(){return bI},protocol:McA},Symbol.toStringTag,{value:"Module"}));function qi(g,A,I){return g.on(A,I),function(){g.off(A,I)}}const acA=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Bb extends jE{constructor(A,I,B){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=A,this.nsp=I,B&&B.auth&&(this.auth=B.auth),this._opts=Object.assign({},B),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const A=this.io;this.subs=[qi(A,"open",this.onopen.bind(this)),qi(A,"packet",this.onpacket.bind(this)),qi(A,"error",this.onerror.bind(this)),qi(A,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected?this:(this.subEvents(),this.io._reconnecting||this.io.open(),this.io._readyState==="open"&&this.onopen(),this)}open(){return this.connect()}send(...A){return A.unshift("message"),this.emit.apply(this,A),this}emit(A,...I){var B,E,C;if(acA.hasOwnProperty(A))throw new Error('"'+A.toString()+'" is a reserved event name');if(I.unshift(A),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(I),this;const Q={type:bI.EVENT,data:I};if(Q.options={},Q.options.compress=this.flags.compress!==!1,typeof I[I.length-1]=="function"){const D=this.ids++,t=I.pop();this._registerAckCallback(D,t),Q.id=D}const o=(E=(B=this.io.engine)===null||B===void 0?void 0:B.transport)===null||E===void 0?void 0:E.writable,w=this.connected&&!(!((C=this.io.engine)===null||C===void 0)&&C._hasPingExpired());return this.flags.volatile&&!o||(w?(this.notifyOutgoingListeners(Q),this.packet(Q)):this.sendBuffer.push(Q)),this.flags={},this}_registerAckCallback(A,I){var B;const E=(B=this.flags.timeout)!==null&&B!==void 0?B:this._opts.ackTimeout;if(E===void 0){this.acks[A]=I;return}const C=this.io.setTimeoutFn(()=>{delete this.acks[A];for(let o=0;o<this.sendBuffer.length;o++)this.sendBuffer[o].id===A&&this.sendBuffer.splice(o,1);I.call(this,new Error("operation has timed out"))},E),Q=(...o)=>{this.io.clearTimeoutFn(C),I.apply(this,o)};Q.withError=!0,this.acks[A]=Q}emitWithAck(A,...I){return new Promise((B,E)=>{const C=(Q,o)=>Q?E(Q):B(o);C.withError=!0,I.push(C),this.emit(A,...I)})}_addToQueue(A){let I;typeof A[A.length-1]=="function"&&(I=A.pop());const B={id:this._queueSeq++,tryCount:0,pending:!1,args:A,flags:Object.assign({fromQueue:!0},this.flags)};A.push((E,...C)=>B!==this._queue[0]?void 0:(E!==null?B.tryCount>this._opts.retries&&(this._queue.shift(),I&&I(E)):(this._queue.shift(),I&&I(null,...C)),B.pending=!1,this._drainQueue())),this._queue.push(B),this._drainQueue()}_drainQueue(A=!1){if(!this.connected||this._queue.length===0)return;const I=this._queue[0];I.pending&&!A||(I.pending=!0,I.tryCount++,this.flags=I.flags,this.emit.apply(this,I.args))}packet(A){A.nsp=this.nsp,this.io._packet(A)}onopen(){typeof this.auth=="function"?this.auth(A=>{this._sendConnectPacket(A)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(A){this.packet({type:bI.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},A):A})}onerror(A){this.connected||this.emitReserved("connect_error",A)}onclose(A,I){this.connected=!1,delete this.id,this.emitReserved("disconnect",A,I),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(A=>{if(!this.sendBuffer.some(B=>String(B.id)===A)){const B=this.acks[A];delete this.acks[A],B.withError&&B.call(this,new Error("socket has been disconnected"))}})}onpacket(A){if(A.nsp===this.nsp)switch(A.type){case bI.CONNECT:A.data&&A.data.sid?this.onconnect(A.data.sid,A.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case bI.EVENT:case bI.BINARY_EVENT:this.onevent(A);break;case bI.ACK:case bI.BINARY_ACK:this.onack(A);break;case bI.DISCONNECT:this.ondisconnect();break;case bI.CONNECT_ERROR:this.destroy();const B=new Error(A.data.message);B.data=A.data.data,this.emitReserved("connect_error",B);break}}onevent(A){const I=A.data||[];A.id!=null&&I.push(this.ack(A.id)),this.connected?this.emitEvent(I):this.receiveBuffer.push(Object.freeze(I))}emitEvent(A){if(this._anyListeners&&this._anyListeners.length){const I=this._anyListeners.slice();for(const B of I)B.apply(this,A)}super.emit.apply(this,A),this._pid&&A.length&&typeof A[A.length-1]=="string"&&(this._lastOffset=A[A.length-1])}ack(A){const I=this;let B=!1;return function(...E){B||(B=!0,I.packet({type:bI.ACK,id:A,data:E}))}}onack(A){const I=this.acks[A.id];typeof I=="function"&&(delete this.acks[A.id],I.withError&&A.data.unshift(null),I.apply(this,A.data))}onconnect(A,I){this.id=A,this.recovered=I&&this._pid===I,this._pid=I,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach(A=>this.emitEvent(A)),this.receiveBuffer=[],this.sendBuffer.forEach(A=>{this.notifyOutgoingListeners(A),this.packet(A)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(A=>A()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:bI.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(A){return this.flags.compress=A,this}get volatile(){return this.flags.volatile=!0,this}timeout(A){return this.flags.timeout=A,this}onAny(A){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(A),this}prependAny(A){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(A),this}offAny(A){if(!this._anyListeners)return this;if(A){const I=this._anyListeners;for(let B=0;B<I.length;B++)if(A===I[B])return I.splice(B,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(A){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(A),this}prependAnyOutgoing(A){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(A),this}offAnyOutgoing(A){if(!this._anyOutgoingListeners)return this;if(A){const I=this._anyOutgoingListeners;for(let B=0;B<I.length;B++)if(A===I[B])return I.splice(B,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(A){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const I=this._anyOutgoingListeners.slice();for(const B of I)B.apply(this,A.data)}}}function Ch(g){g=g||{},this.ms=g.min||100,this.max=g.max||1e4,this.factor=g.factor||2,this.jitter=g.jitter>0&&g.jitter<=1?g.jitter:0,this.attempts=0}Ch.prototype.duration=function(){var g=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var A=Math.random(),I=Math.floor(A*this.jitter*g);g=(Math.floor(A*10)&1)==0?g-I:g+I}return Math.min(g,this.max)|0},Ch.prototype.reset=function(){this.attempts=0},Ch.prototype.setMin=function(g){this.ms=g},Ch.prototype.setMax=function(g){this.max=g},Ch.prototype.setJitter=function(g){this.jitter=g};class p4 extends jE{constructor(A,I){var B;super(),this.nsps={},this.subs=[],A&&typeof A=="object"&&(I=A,A=void 0),I=I||{},I.path=I.path||"/socket.io",this.opts=I,wG(this,I),this.reconnection(I.reconnection!==!1),this.reconnectionAttempts(I.reconnectionAttempts||1/0),this.reconnectionDelay(I.reconnectionDelay||1e3),this.reconnectionDelayMax(I.reconnectionDelayMax||5e3),this.randomizationFactor((B=I.randomizationFactor)!==null&&B!==void 0?B:.5),this.backoff=new Ch({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(I.timeout==null?2e4:I.timeout),this._readyState="closed",this.uri=A;const E=I.parser||tcA;this.encoder=new E.Encoder,this.decoder=new E.Decoder,this._autoConnect=I.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(A){return arguments.length?(this._reconnection=!!A,A||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(A){return A===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=A,this)}reconnectionDelay(A){var I;return A===void 0?this._reconnectionDelay:(this._reconnectionDelay=A,(I=this.backoff)===null||I===void 0||I.setMin(A),this)}randomizationFactor(A){var I;return A===void 0?this._randomizationFactor:(this._randomizationFactor=A,(I=this.backoff)===null||I===void 0||I.setJitter(A),this)}reconnectionDelayMax(A){var I;return A===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=A,(I=this.backoff)===null||I===void 0||I.setMax(A),this)}timeout(A){return arguments.length?(this._timeout=A,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(A){if(~this._readyState.indexOf("open"))return this;this.engine=new IcA(this.uri,this.opts);const I=this.engine,B=this;this._readyState="opening",this.skipReconnect=!1;const E=qi(I,"open",function(){B.onopen(),A&&A()}),C=o=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",o),A?A(o):this.maybeReconnectOnOpen()},Q=qi(I,"error",C);if(this._timeout!==!1){const o=this._timeout,w=this.setTimeoutFn(()=>{E(),C(new Error("timeout")),I.close()},o);this.opts.autoUnref&&w.unref(),this.subs.push(()=>{this.clearTimeoutFn(w)})}return this.subs.push(E),this.subs.push(Q),this}connect(A){return this.open(A)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const A=this.engine;this.subs.push(qi(A,"ping",this.onping.bind(this)),qi(A,"data",this.ondata.bind(this)),qi(A,"error",this.onerror.bind(this)),qi(A,"close",this.onclose.bind(this)),qi(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(A){try{this.decoder.add(A)}catch(I){this.onclose("parse error",I)}}ondecoded(A){oG(()=>{this.emitReserved("packet",A)},this.setTimeoutFn)}onerror(A){this.emitReserved("error",A)}socket(A,I){let B=this.nsps[A];return B?this._autoConnect&&!B.active&&B.connect():(B=new Bb(this,A,I),this.nsps[A]=B),B}_destroy(A){const I=Object.keys(this.nsps);for(const B of I)if(this.nsps[B].active)return;this._close()}_packet(A){const I=this.encoder.encode(A);for(let B=0;B<I.length;B++)this.engine.write(I[B],A.options)}cleanup(){this.subs.forEach(A=>A()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(A,I){var B;this.cleanup(),(B=this.engine)===null||B===void 0||B.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",A,I),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const A=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const I=this.backoff.duration();this._reconnecting=!0;const B=this.setTimeoutFn(()=>{A.skipReconnect||(this.emitReserved("reconnect_attempt",A.backoff.attempts),!A.skipReconnect&&A.open(E=>{E?(A._reconnecting=!1,A.reconnect(),this.emitReserved("reconnect_error",E)):A.onreconnect()}))},I);this.opts.autoUnref&&B.unref(),this.subs.push(()=>{this.clearTimeoutFn(B)})}}onreconnect(){const A=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",A)}}const _t={};function DG(g,A){typeof g=="object"&&(A=g,g=void 0),A=A||{};const I=BcA(g,A.path||"/socket.io"),B=I.source,E=I.id,C=I.path,Q=_t[E]&&C in _t[E].nsps,o=A.forceNew||A["force new connection"]||A.multiplex===!1||Q;let w;return o?w=new p4(B,A):(_t[E]||(_t[E]=new p4(B,A)),w=_t[E]),I.query&&!A.query&&(A.query=I.queryKey),w.socket(I.path,A)}Object.assign(DG,{Manager:p4,Socket:Bb,io:DG,connect:DG});const Qh="https://api.tybotflow.com/api/v1",scA="https://api.tybotflow.com/api/v1/chatbots-config",Eb="https://migration-meta.tybotflow.com/",Cb=Eb+"webhook/v",hG=DG(Eb,{transports:["websocket","polling"],reconnection:!0,reconnectionAttempts:3,autoConnect:!0,reconnectionDelay:2e3}),Qb=new rw,y4=g=>{if(!g||!g.message)return"👋 Hey there! how can I help you?";const A=g.message;if(typeof A=="string")return A;if(Array.isArray(A)){const I=window.location.href,B=window.location.origin,E=window.location.pathname,C=B+E;for(const o of A){if(!o.urls||o.urls.length===0)continue;if(o.urls.some(M=>{if(!M||M.trim()==="")return!1;try{let D=M.trim();!D.startsWith("http://")&&!D.startsWith("https://")&&(D="https://"+D);const t=new URL(D),s=t.origin,a=t.pathname,G=s+a;return C===G||I===D?!0:a==="/"||a===""?B===s:!!I.startsWith(D)}catch{return console.warn("Invalid URL in message:",M),!1}}))return o.text||"👋 Hey there! how can I help you?"}const Q=A.find(o=>!o.urls||o.urls.length===0||o.urls.every(w=>!w||w.trim()===""));if(Q)return Q.text||"👋 Hey there! how can I help you?";if(A.length>0)return A[0].text||"👋 Hey there! how can I help you?"}return"👋 Hey there! how can I help you?"},ib=(g,A)=>{const I={className:"w-5 h-5",style:{color:A}};switch(g?.toLowerCase()){case"pdf":return u.jsx(Ce,{...I});case"doc":case"docx":return u.jsx(Ce,{...I});case"xls":case"xlsx":case"csv":return u.jsx(OIA,{...I});case"ppt":case"pptx":return u.jsx(yIA,{...I});case"zip":case"rar":case"7z":case"tar":case"gz":return u.jsx(lIA,{...I});case"txt":case"md":case"rtf":return u.jsx(sj,{...I});default:return u.jsx(Ce,{...I})}},ccA=({config:g})=>{const A=vA.useRef(null),I=vA.useRef(null),B=vA.useRef(null),E=vA.useRef(null),C=vA.useRef(null),[Q,o]=vA.useState(null),[w,M]=vA.useState(!0),[D,t]=vA.useState(!1);vA.useEffect(()=>{(async()=>{M(!0),await OB.get(`${scA}/bot/${g.bot?.botId}`,{}).then(uA=>{o(uA.data)}).catch(uA=>{console.error("Error fetching bot config:",uA)}).finally(()=>{M(!1)})})()},[g.bot?.botId,g?.token]);const s=Q?.mainColor||"#59168b",a=Q?.secondaryColor||"#6366f1",G=Q?.thirdColor||"#0f172b",R=Q?.headerFirstColor||"#6e11b0",U=Q?.headerSecondColor||"#372aac",r=Q?.inputBackgroundColor||"#1f2937",l=Q?.inputTextColor||"#fff",K=Q?.roundness||24,m=Q?.chatRoundness||16,x=(Q?.minPanelWidth||434)>window.innerWidth?window.innerWidth:Q?.minPanelWidth||434,O=(Q?.maxPanelWidth||window.innerWidth)>window.innerWidth?window.innerWidth:Q?.maxPanelWidth||window.innerWidth,y=Q?.chatMaxWidth||88,L=Q?.toggleBtnBorderTopLeftRadius||12,j=Q?.toggleBtnBorderTopRightRadius||0,z=Q?.toggleBtnBorderBottomLeftRadius||12,d=Q?.toggleBtnBorderBottomRightRadius||0,Z=Q?.menuBackgroundColor||"#1f2937",W=Q?.menuTextColor||"#e5e7eb",T=Q?.menuHoverBackgroundColor||"#374151",X=Q?.agentChatResponseColor||"#e5e7eb",P=Q?.agentChatResponseBgColor||"#1f2937",EA=Q?.agentIconBgColor||"#59168b",$=Q?.agentIconColor||"#fff",oA=Q?.userChatMessagesColor||"#fff",H=Q?.userChatMessagesBgColor||"#7a1ebe",AA=Q?.userIconBgColor||"#7a1ebe",q=Q?.userIconColor||"#fff",J=Q?.ButtonColor||"#fff",f=Q?.ButtonsBgColor||"#59168b",iA=OC(P,10),wA=Q?.fontSize||13,tA=Q?.toggleBtnPosition||"bottom-right",RA=Q?.autoOpenPanel??!0,lA=Q?.tempToken||"",PA=(()=>{const p=Q?.firstMessageKeyword;if(Array.isArray(p)){const uA=window.location.href,UA=p.find(Gg=>Gg.url&&Gg.url===uA);if(UA)return UA.message;const LA=p.find(Gg=>!Gg.url||Gg.url==="");return LA?LA.message:p[0]?.message||"hi"}return p||"hi"})(),sg=p=>({ip:p.ip||"",flag:{img:p.flag||"",emoji:p.emoji_flag||"",emoji_unicode:p.emoji_unicode||""},is_eu:p.is_eu??!1,postal:p.postal||"",borders:"",latitude:p.latitude||0,platform:p?.platform||"",timezone:{id:p.time_zone?.name||"",utc:p.time_zone?.offset||"",abbr:p.time_zone?.abbr||"",is_dst:p.time_zone?.is_dst??!1,offset:p.time_zone?.offset||0,current_time:p.time_zone?.current_time||""},continent:p.continent_name||"",longitude:p.longitude||0,connection:{asn:p.asn?.asn||0,isp:p.asn?.name||"",org:p.asn?.name||"",domain:p.asn?.domain||""}}),[bA,JA]=vA.useState(x),BA=vA.useRef(!1),Bg=vA.useRef(0),Yg=vA.useRef(x),wg=p=>{BA.current=!0,Bg.current=p.clientX,Yg.current=bA,document.body.style.cursor="ew-resize"};vA.useEffect(()=>{const p=UA=>{if(!BA.current)return;const LA=Bg.current-UA.clientX;let Gg=Yg.current+LA;Gg=Math.max(x,Math.min(O,Gg)),JA(Gg)},uA=()=>{BA.current&&(BA.current=!1,document.body.style.cursor="")};return window.addEventListener("mousemove",p),window.addEventListener("mouseup",uA),()=>{window.removeEventListener("mousemove",p),window.removeEventListener("mouseup",uA)}},[bA,x,O]);const[kA,Cg]=vA.useState(!1),[Ig,lg]=vA.useState(!1),[Dg,xA]=vA.useState(!1),[ZA,sA]=vA.useState(()=>tA==="bottom-left"?{x:48,y:window.innerHeight-120}:tA==="middle-right"?{x:window.innerWidth-80,y:window.innerHeight/2-35}:{x:window.innerWidth-123,y:window.innerHeight-100}),[rA,HA]=vA.useState(!1),[zA,Rg]=vA.useState({x:0,y:0}),Ug=vA.useRef(null),[Vg,jg]=vA.useState(""),[rg,ng]=vA.useState(!1),[qg,Sg]=vA.useState(!1),[Ng,Jg]=vA.useState([]),[$g,KI]=vA.useState(!1),Xg=vA.useRef(0),[Wg,SI]=vA.useState(!1),[gC,MI]=vA.useState(!1),qB=vA.useRef(!1),[aC,bg]=vA.useState("00:00"),XI=vA.useRef(null),dI=vA.useRef(0),[vI,ZB]=vA.useState(null),[DI,QB]=vA.useState(!1),[EB,IC]=vA.useState(new Set),[MB,gB]=vA.useState([]),{startRecording:hB,stopRecording:zB,pauseRecording:DE,resumeRecording:TB,status:QI,error:TE}=tiA.useReactMediaRecorder({video:!1,onStop(p,uA){if(qB.current){qB.current=!1,bg("00:00"),dI.current=0;return}Jg(UA=>[...UA,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),file:uA,type:"audio",url:p,name:`recording-${new Date().toISOString()}.webm`,size:uA.size}]),bg("00:00"),dI.current=0}}),kg=Q?.icon||g?.bot.avatar_url||Bz,cA=Q?.title||g?.bot.name||"Tybot webchat",[$A,ug]=vA.useState(null),[OI,YB]=vA.useState(()=>{const p=localStorage.getItem("phone_client");if(g.bot?.botId==="rockskin"&&p)return p;if(!Q?.botNeedsAuth){let uA=localStorage.getItem("externalUser");if(!uA){const UA=new Uint8Array(16);window.crypto.getRandomValues(UA),uA=Array.from(UA).map(LA=>LA.toString(16).padStart(2,"0")).join("")}return localStorage.setItem("externalUser",uA),uA}});vA.useEffect(()=>{if(!$A)return;const p=uA=>{if(uA.bot.conversationId!==parseInt($A)||uA.bot.botId!==g?.bot?.botId){ng(!1);return}const UA={id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:uA.bot.item,timestamp:new Date,seen:LC.current,nMessage:Array.isArray(uA.bot.item)?uA.bot.item.length:1};gB(LA=>LA.some(OA=>OA.id===UA.id)?LA:[...LA,UA]),ng(!1)};return hG.on("bot-message",p),()=>{hG.off("bot-message",p)}},[$A,g?.bot?.botId]),vA.useEffect(()=>{(async()=>{if(!($A||!g.bot?.botId||!OI))try{const UA=(await OB.post(`${Qh}/conversations/start-conversation`,{bot_id:g.bot?.botId,externalUser:OI})).data.conversationId;ug(UA),localStorage.setItem("conversationId",UA),hG.emit("join_room",parseInt(UA))}catch(uA){console.error("Error initializing conversation:",uA)}})()},[$A,g.bot?.botId,OI]);const[ZI,NB]=vA.useState(()=>Q?.botNeedsAuth?!!localStorage.getItem("conversationId"):!0),[PI,WB]=vA.useState(""),[sC,RB]=vA.useState(""),[WE,WQ]=vA.useState(""),[yC,Vo]=vA.useState(null),LC=vA.useRef(!1),nI=MB.reduce((p,uA)=>uA.seen?p:p+(uA.sender==="agent"?uA.nMessage||1:0),0),vi=()=>{gB(p=>p.map(uA=>({...uA,seen:!0})))};vA.useEffect(()=>{let p;return!localStorage.getItem("webChatOpen")&&Q&&RA&&(p=setTimeout(()=>{Cg(!0),LC.current=!0,vi(),localStorage.setItem("webChatOpen","true")},3200)),()=>clearTimeout(p)},[Q]),vA.useEffect(()=>{const p=Q?.widgetLoadBehavior;if(!p||!(()=>{const LA=p.message;if(typeof LA=="string"){if(!p.urls||p.urls.length===0)return!0;const Gg=window.location.origin,OA=window.location.href;return p.urls.some(gI=>{if(!gI||gI.trim()==="")return!0;try{return Gg.includes(gI)||OA.includes(gI)||gI.includes(Gg)}catch{return console.warn("Invalid URL in widgetLoadBehavior:",gI),!1}})}if(Array.isArray(LA)){const Gg=window.location.href,OA=window.location.origin,gI=window.location.pathname,aI=OA+gI;for(const SB of LA)if(!SB.urls||SB.urls.length===0||SB.urls.every(bB=>!bB||bB.trim()==="")||SB.urls.some(bB=>{if(!bB||bB.trim()==="")return!1;try{let KE=bB.trim();!KE.startsWith("http://")&&!KE.startsWith("https://")&&(KE="https://"+KE);const VE=new URL(KE),zg=VE.origin,oQ=VE.pathname,pI=zg+oQ;return aI===pI||Gg===KE?!0:oQ==="/"||oQ===""?OA===zg:!!Gg.startsWith(KE)}catch{return console.warn("Invalid URL in message:",bB),!1}}))return!0;return!1}return!0})())return;let UA;if(p.behavior==="after seconds")UA=setTimeout(()=>{xA(!0)},p.value*1e3);else if(p.behavior==="after scroll"){const LA=()=>{const Gg=window.pageYOffset||document.documentElement.scrollTop,OA=document.documentElement.scrollHeight-document.documentElement.clientHeight;Gg/OA*100>=p.value&&(xA(!0),window.removeEventListener("scroll",LA))};return window.addEventListener("scroll",LA),()=>{window.removeEventListener("scroll",LA)}}return()=>{UA&&clearTimeout(UA)}},[Q?.widgetLoadBehavior]),vA.useEffect(()=>{kA&&xA(!1)},[kA]),vA.useEffect(()=>{fetch("https://api.ipdata.co/?api-key=7930ffd0621dafcb6cd830a503d726bf514b74c1cae21ffff8131890").then(function(p){p.json().then(uA=>{Vo({...uA,platform:Qb.getOS().name+" "+Qb.getOS().version})})}).catch(function(p){console.log(p)})},[]);const qo=vA.useCallback(async(p,uA=[],UA)=>{if(!g.bot.botId||!$A){ng(!1),gB(Gg=>[...Gg,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:[{type:"text",text:"⚠️ Unable to send message: No bot selected or conversation not initialized."}],timestamp:new Date}]);return}if(uA.length>0||UA&&typeof UA=="object"&&UA.attachment!==void 0){const Gg=UA&&typeof UA!="string"?UA.attachment.file:uA[0]?.file,OA=UA&&typeof UA!="string"?UA.attachment.type:uA[0]?.type||"file";let gI=UA;if(UA&&typeof UA=="object"&&UA.attachment!==void 0){const{attachment:SB,...RI}=UA;gI=RI}const aI=new FormData;aI.append("type",OA),aI.append("file",Gg),aI.append("botId",g.bot.botId),aI.append("external_id",OI||""),aI.append("isintern",g.token?"true":"false"),aI.append("host",window.location.origin),aI.append("channel","web"),aI.append("payload",gI?JSON.stringify(gI):""),await OB.post(Cb,aI,{headers:{Authorization:`Bearer ${g?.token}`,"Content-Type":"multipart/form-data"}})}else{const Gg={type:"text",messageText:p,botId:g.bot.botId,external_id:OI||"",isintern:!!g.token,host:window.location.origin,channel:"web"};UA&&(Gg.payload=UA),await OB.post(Cb,Gg,{headers:{Authorization:`Bearer ${g?.token}`,"Content-Type":"application/json"}})}},[g.bot.botId,$A,g.token,g.user?.id]),cC=vA.useCallback(async()=>{if(g.bot.botId&&$A){ng(!0);try{await qo(PA)}catch(p){console.error("Error sending first message:",p),ng(!1)}}},[g.bot.botId,PA,$A,qo]);vA.useEffect(()=>{$A&&ZI&&g?.bot&&MB.length===0&&Q&&RA&&(cC(),localStorage.getItem("webChatAuth")&&JSON.parse(localStorage.getItem("webChatAuth"))&&Q?.botNeedsAuth&&$A&&(PI||WE||sC)&&(setTimeout(()=>{zC($A)},2e3),localStorage.setItem("webChatAuth","true")))},[ZI,g?.bot,$A,Q]),vA.useEffect(()=>(QI==="recording"?XI.current||(XI.current=setInterval(()=>{dI.current+=1;const p=Math.floor(dI.current/60).toString().padStart(2,"0"),uA=(dI.current%60).toString().padStart(2,"0");bg(`${p}:${uA}`)},1e3)):XI.current&&(clearInterval(XI.current),XI.current=null),()=>{XI.current&&(clearInterval(XI.current),XI.current=null)}),[QI]),vA.useEffect(()=>{TE&&TE.toLowerCase().includes("permission_denied")&&(MI(!1),bg("00:00"),dI.current=0,XI.current&&(clearInterval(XI.current),XI.current=null),alert("Microphone permission denied. Please allow access to record audio."))},[TE]),vA.useEffect(()=>{QI!=="recording"&&QI!=="paused"&&(bg("00:00"),dI.current=0)},[QI]);const EQ=vA.useRef(null);vA.useEffect(()=>{if(EQ&&EQ.current){const p=EQ.current;p.style.height="auto";const uA=120;p.scrollHeight>uA?(p.style.height=uA+"px",p.style.overflowY="auto"):(p.style.height=p.scrollHeight+"px",p.style.overflowY="hidden")}},[Vg]),vA.useEffect(()=>{(kA||rg)&&A.current&&(A.current.scrollTop=A.current.scrollHeight)},[MB,rg,kA]);const BC=p=>{const uA=p.type.toLowerCase();return uA.startsWith("image/")?"image":uA.startsWith("video/")?"video":uA.startsWith("audio/")?"audio":"document"},VC=vA.useCallback((p,uA)=>{const UA=[];Array.from(p).forEach(LA=>{if(LA.size>10*1024*1024){alert(`File ${LA.name} is too large. Maximum size is 10MB.`);return}const Gg={id:Date.now().toString()+Math.random().toString(36).substring(2,9),file:LA,type:BC(LA),url:URL.createObjectURL(LA),name:LA.name,size:LA.size};UA.push(Gg)}),Jg(LA=>[...LA,...UA]),uA&&uA.current&&(uA.current.value="")},[]),zI=vA.useCallback(p=>{p.preventDefault(),Xg.current=0,KI(!1);const uA=p.dataTransfer.files;uA.length>0&&VC(uA)},[VC]),_i=vA.useCallback(p=>{p.preventDefault(),Xg.current+=1,KI(!0)},[]),je=vA.useCallback(p=>{p.preventDefault()},[]),Jw=vA.useCallback(p=>{p.preventDefault(),Xg.current-=1,Xg.current<=0&&KI(!1)},[]),ai=vA.useCallback(p=>{Jg(uA=>{const UA=uA.find(LA=>LA.id===p);return UA&&URL.revokeObjectURL(UA.url),uA.filter(LA=>LA.id!==p)})},[]),CQ=p=>{if(p===0)return"0 Bytes";const uA=1024,UA=["Bytes","KB","MB","GB"],LA=Math.floor(Math.log(p)/Math.log(uA));return Number.parseFloat((p/Math.pow(uA,LA)).toFixed(2))+" "+UA[LA]},jI=async(p=Vg,uA)=>{if(p.trim()||Ng.length!==0){const LA={id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"user",content:p,attachments:[...Ng],timestamp:new Date};if(gB(Gg=>[...Gg,LA]),jg(""),Jg([]),ng(!0),g?.bot)try{if(!$A){ng(!1),gB(Gg=>[...Gg,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:"⚠️ Conversation not initialized. Please try again later.",timestamp:new Date,seen:LC.current,nMessage:1}]);return}await qo(p,Ng,uA)}catch{gB(Gg=>[...Gg,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:"Erreur du serveur",timestamp:new Date,seen:LC.current,nMessage:1}]),ng(!1)}else gB(Gg=>[...Gg,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:"Aucun bot sélectionné",timestamp:new Date,seen:LC.current,nMessage:1}]),ng(!1)}else return},qC=p=>{switch(SI(!1),p){case"image":I.current?.click();break;case"video":B.current?.click();break;case"audio":E.current?.click();break;case"document":C.current?.click();break}};vA.useEffect(()=>{const p=MB.slice().reverse().find(uA=>uA.sender==="agent");if(p){let uA=!1;Array.isArray(p.content)&&(uA=p.content.some(UA=>UA.type==="text"&&typeof UA.text=="object"&&UA.text.type==="EVFORM")),Sg(uA)}else Sg(!1)},[MB]);const[si,SQ]=vA.useState(!1),bQ=vA.useRef({x:0,y:0}),Hw=p=>{p.preventDefault(),p.stopPropagation(),HA(!0),SQ(!1),bQ.current={x:p.clientX,y:p.clientY},Rg({x:p.clientX-ZA.x,y:p.clientY-ZA.y}),document.body.style.cursor="grabbing",document.body.style.userSelect="none"},$M=p=>{p.preventDefault(),p.stopPropagation();const uA=p.touches[0];HA(!0),SQ(!1),bQ.current={x:uA.clientX,y:uA.clientY},Rg({x:uA.clientX-ZA.x,y:uA.clientY-ZA.y})},uQ=p=>{if(p.preventDefault(),p.stopPropagation(),si){SQ(!1);return}Cg(uA=>!uA),LC.current=!kA,kA||vi(),!RA&&MB.length===0&&cC()};vA.useEffect(()=>{const p=Gg=>{if(!rA)return;const OA=Math.abs(Gg.clientX-bQ.current.x),gI=Math.abs(Gg.clientY-bQ.current.y);(OA>5||gI>5)&&SQ(!0);const aI=Gg.clientX-zA.x,SB=Gg.clientY-zA.y,RI=67,bB=window.innerWidth-document.body.clientWidth,KE=Math.max(0,Math.min(window.innerWidth-RI-bB,aI)),VE=Math.max(0,Math.min(window.innerHeight-RI,SB));sA({x:KE,y:VE})},uA=Gg=>{if(!rA)return;Gg.preventDefault();const OA=Gg.touches[0],gI=Math.abs(OA.clientX-bQ.current.x),aI=Math.abs(OA.clientY-bQ.current.y);(gI>5||aI>5)&&SQ(!0);const SB=OA.clientX-zA.x,RI=OA.clientY-zA.y,bB=67,KE=window.innerWidth-document.body.clientWidth,VE=Math.max(0,Math.min(window.innerWidth-bB-KE,SB)),zg=Math.max(0,Math.min(window.innerHeight-bB,RI));sA({x:VE,y:zg})},UA=()=>{rA&&(HA(!1),document.body.style.cursor="",document.body.style.userSelect="")},LA=()=>{rA&&HA(!1)};return rA&&(document.addEventListener("mousemove",p),document.addEventListener("touchmove",uA,{passive:!1}),document.addEventListener("mouseup",UA),document.addEventListener("touchend",LA)),()=>{document.removeEventListener("mousemove",p),document.removeEventListener("touchmove",uA),document.removeEventListener("mouseup",UA),document.removeEventListener("touchend",LA)}},[rA,zA,ZA]),vA.useEffect(()=>{const p=()=>{const UA=window.innerWidth-67,LA=window.innerHeight-67;sA(Gg=>({x:Math.max(0,Math.min(UA,Gg.x)),y:Math.max(0,Math.min(LA,Gg.y))}))};return window.addEventListener("resize",p),()=>window.removeEventListener("resize",p)},[]),vA.useEffect(()=>{const p=async()=>{try{await OB.patch(`${Qh}/widget/endusers/${OI}`,{fiche_contact:{city:yC.city,platform:yC.platform,region:yC.region,country:yC.country_name,age:0,full_name:PI,gender:"",address:"",company:"","phone 2":"",facebook:"",whatsapp:"",job_title:"",avatar_url:""},user_info:sg(yC)},{headers:{Authorization:`Bearer ${lA}`}}),localStorage.setItem("enduserUpdated","true")}catch(UA){console.error("Error updating end user info:",UA)}};let uA;return yC&&$A&&lA&&MB.length>0&&!localStorage.getItem("enduserUpdated")&&(uA=setTimeout(()=>{p()},5e3)),()=>clearTimeout(uA)},[yC,Q,MB,$A]);const lE=vA.useMemo(()=>({h1:({children:p})=>u.jsx("h1",{className:"sm:text-2xl text-xl font-bold my-2",dir:tw(p)?"rtl":"ltr",children:u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h2:({children:p})=>u.jsx("h2",{className:"sm:text-xl text-lg font-semibold my-2",dir:tw(p)?"rtl":"ltr",children:u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h3:({children:p})=>u.jsx("h3",{className:"sm:text-lg text-base font-semibold my-2",dir:tw(p)?"rtl":"ltr",children:u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h4:({children:p})=>u.jsx("h4",{className:"sm:text-base text-sm font-semibold my-2",dir:tw(p)?"rtl":"ltr",children:u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h5:({children:p})=>u.jsx("h5",{className:"sm:text-base text-sm font-semibold my-2",dir:tw(p)?"rtl":"ltr",children:u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h6:({children:p})=>u.jsx("h6",{className:"sm:text-base text-sm font-semibold my-2",dir:tw(p)?"rtl":"ltr",children:u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),p:({children:p})=>{const uA=(LA,Gg)=>{const OA=aw(LA);return u.jsx("span",{dir:OA?"rtl":"ltr",style:{display:"block",textAlign:OA?"right":"left"},children:u.jsx(cE,{sequence:[LA,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],wrapper:"span",cursor:!1,speed:70})},Gg)};if(typeof p=="string")return u.jsx("div",{className:"leading-relaxed my-0.5",children:uA(p,0)});if(Array.isArray(p)){const LA=[[]];for(const Gg of p)Gg?.type==="br"?LA.push([]):LA[LA.length-1].push(Gg);return u.jsx("div",{className:"leading-relaxed my-0.5",children:LA.map((Gg,OA)=>{const gI=Gg.map(RI=>typeof RI=="string"?RI:"").join(""),aI=aw(gI),SB=Gg.every(RI=>typeof RI=="string");return u.jsx("span",{dir:aI?"rtl":"ltr",style:{display:"block",textAlign:aI?"right":"left"},children:SB&&gI?u.jsx(cE,{sequence:[gI,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],wrapper:"span",cursor:!1,speed:70}):Gg},OA)})})}const UA=!!(p?.props?.children&&aw(String(p?.props?.children??"")));return u.jsx("div",{className:"leading-relaxed my-0.5",dir:UA?"rtl":"ltr",children:p})},ul:({children:p})=>u.jsx("ul",{className:"list-disc list-inside ml-2 my-2",style:{color:X},dir:aw(p)?"rtl":"ltr",children:p}),ol:({children:p})=>{let uA=!1;return p.filter(UA=>typeof UA!="string").every(UA=>aw(UA?.props?.children))?uA=!0:uA=!1,u.jsx("ol",{className:"list-decimal list-inside ml-2 my-2",style:{color:X},dir:uA?"rtl":"ltr",children:typeof p=="string"?u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):p})},li:({children:p})=>u.jsx("li",{className:"my-1",dir:tw(p)?"rtl":"ltr",style:{color:X},children:typeof p=="string"?u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):p}),a:({href:p,children:uA})=>u.jsx("a",{href:p,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:typeof uA=="string"?u.jsx(cE,{sequence:[uA,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):uA}),blockquote:({children:p})=>u.jsx("blockquote",{className:"border-l-4 pl-4 italic my-2",style:{borderColor:f,color:X},children:typeof p=="string"?u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):p}),code({node:p,className:uA,children:UA,...LA}){const Gg=/language-(\w+)/.exec(uA||"");return Gg?u.jsx(Iz,{...LA,PreTag:"div",children:String(UA).replace(/\n$/,""),language:Gg[1],style:_DA,customStyle:{scrollbarWidth:"thin"}}):u.jsx("code",{className:"px-1 rounded font-mono inline",style:{backgroundColor:r,color:X},...LA,children:typeof UA=="string"?u.jsx(cE,{sequence:[UA,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):UA})},table:({children:p})=>u.jsx("table",{className:"min-w-full my-2",style:{border:`1px solid ${X}`,color:P,backgroundColor:X},children:p}),thead:({children:p})=>u.jsx("thead",{children:p}),tbody:({children:p})=>u.jsx("tbody",{children:p}),tr:({children:p})=>u.jsx("tr",{style:{border:`1px solid ${P}`},children:p}),th:({children:p})=>u.jsx("th",{className:"px-3 py-2 font-bold text-left",children:p}),td:({children:p})=>u.jsx("td",{className:"px-3 py-2",children:typeof p=="string"?u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):p}),strong:({children:p})=>u.jsx("strong",{className:"font-bold",children:typeof p=="string"?u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):p}),em:({children:p})=>u.jsx("em",{className:"italic ",children:typeof p=="string"?u.jsx(cE,{sequence:[p,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):p}),hr:()=>u.jsx("hr",{className:"my-4",style:{borderColor:`1px solid ${X}`}})}),[l,X,f,r,m]);vA.useEffect(()=>{const p=uA=>{Wg&&uA.target instanceof Element&&!uA.composedPath().some(UA=>UA?.id==="upload-button-toggle"||UA?.id==="document-button"||UA?.id==="image-button"||UA?.id==="video-button"||UA?.id==="audio-button")&&SI(!1)};return document.addEventListener("mousedown",p),()=>{document.removeEventListener("mousedown",p)}},[Wg]);const ZC=p=>{switch(p.type){case"text":if(Array.isArray(p.text))switch(p.text[0].type){case"products":return u.jsx(BG,{products:p.text[0].items||[],onValidate:UA=>{jI("cart",UA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA});case"easyspaceform":return u.jsx(Qz,{onValidate:UA=>{jI("easyspace-form-data",UA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"xcmgform":return u.jsx(OW,{onValidate:UA=>{jI("xcmg-form-data",UA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r,formVars:JSON.parse(p.text[0])});case"auditec-form":return u.jsx(mW,{onValidate:UA=>{jI("auditec-form-data",UA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"auditec-form-ar":return u.jsx(kW,{onValidate:UA=>{jI("تم إرسال النموذج",UA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"nousserform":return u.jsx(NW,{onValidate:UA=>{jI("nousserform-data",UA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"jadaraform":case"Jadaraform":case"JadaraForm":return u.jsx(JW,{onValidate:UA=>{jI("jadaraform-data",UA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"jadara-form-ar":return u.jsx(HW,{onValidate:UA=>{jI("تم إرسال النموذج",UA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});default:return u.jsx(Be,{remarkPlugins:[Ee],components:lE,children:te(p.text)})}else try{const UA=typeof p.text=="string"?JSON.parse(p.text):p.text;switch(UA.type.toLowerCase()){case"products":return u.jsx(BG,{products:UA[0].items||[],onValidate:LA=>{jI("cart",LA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA});case"easyspaceform":return u.jsx(Qz,{onValidate:LA=>{jI("formulaire soumis",LA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"evform":return u.jsx(isA,{onValidate:LA=>{jI("formulaire soumis",LA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r,mainColor:H});case"evform-visiteur":return u.jsx(osA,{onValidate:LA=>{jI("formulaire soumis",LA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r,mainColor:H});case"xcmgform":return u.jsx(OW,{onValidate:LA=>{jI("formulaire soumis",LA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r,formVars:UA?.items||{}});case"auditec-form":return u.jsx(mW,{onValidate:LA=>{jI("formulaire soumis",LA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"auditec-form-ar":return u.jsx(kW,{onValidate:LA=>{jI("تم إرسال النموذج",LA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"nousserform":return u.jsx(NW,{onValidate:LA=>{jI("formulaire soumis",LA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"jadaraform":case"Jadaraform":case"JadaraForm":return u.jsx(JW,{onValidate:LA=>{jI("formulaire soumis",LA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"jadara-form-ar":return u.jsx(HW,{onValidate:LA=>{jI("تم إرسال النموذج",LA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});default:return u.jsx(Be,{remarkPlugins:[Ee],components:lE,children:te(p.text)})}}catch{return u.jsx(Be,{remarkPlugins:[Ee],components:lE,children:te(p.text)})}case"single-choice":return u.jsxs(u.Fragment,{children:[u.jsx(Be,{remarkPlugins:[Ee],components:lE,children:te(p.text)||""}),u.jsx("div",{className:"mt-2 flex flex-col gap-1",dir:tw(p.text||"")?"rtl":"ltr",children:p.choices?.map((UA,LA)=>u.jsxs("button",{onClick:()=>jI(UA.title),className:"w-full flex items-center justify-between px-4 py-2.5 hover:opacity-95 transition-all duration-100",style:{background:iA,borderRadius:"18px",color:X,border:`2px solid ${OC(iA,20)}`},onMouseEnter:Gg=>{Gg.currentTarget.style.borderColor=`${f}`},onMouseLeave:Gg=>{Gg.currentTarget.style.border=`2px solid ${OC(iA,15)}`},dir:aw(UA.title)?"rtl":"ltr",children:[u.jsx("div",{className:"w-full flex items-start gap-2",children:u.jsx(cE,{sequence:[UA.title,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92})}),u.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center"},children:aw(UA.title)?u.jsx(tj,{className:"w-4 h-4",color:f}):u.jsx(aj,{className:"w-4 h-4",color:f})})]},LA))})]});case"image":return u.jsx(u.Fragment,{children:u.jsx("div",{className:"relative group",children:u.jsx("img",{src:p.image,className:"max-w-full max-h-full rounded-lg object-cover cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>window.open(p.image,"_blank")})})});case"dropdown":return u.jsxs(u.Fragment,{children:[u.jsx(Be,{remarkPlugins:[Ee],components:lE,children:te(p.message)}),u.jsx(DsA,{options:p.options||[],message:p.message,allowMultiple:p.allowMultiple||!1,chatRoundness:m,buttonsBgColor:f,buttonColor:J,agentChatResponseColor:X,agentChatResponseBgColor:P,isRtl:tw(p.message||""),onSend:jI,onScroll:()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}})]});case"carousel":return u.jsx(r4,{items:p.items||[],chatRoundness:m,agentChatResponseBgColor:P,agentChatResponseColor:X,buttonsBgColor:f,buttonColor:J,inputBackgroundColor:r,onButtonClick:jI,setMessages:gB});case"card":return u.jsx("div",{className:"mt-2 w-full",children:u.jsx("div",{className:"grid grid-cols-1 gap-3",children:u.jsxs("div",{className:"flex-shrink-0 border rounded-lg p-3 shadow-md",style:{background:P},children:[u.jsx("img",{src:p.image,alt:p.title,className:"max-h-48 w-full object-contain rounded-md mb-2"}),u.jsx("h3",{className:"font-bold",children:p.title}),p.actions?.map((UA,LA)=>u.jsx("button",{className:"mb-1 mr-1 px-4 py-1 hover:scale-105 transition-all duration-100",onClick:()=>{UA.action==="Open URL"?window.open(UA.url,"_blank"):UA.title==="scan"?p.image&&fetch(p.image).then(Gg=>Gg.blob()).then(Gg=>{const OA=URL.createObjectURL(Gg),gI=document.createElement("a");gI.href=OA,gI.download="qrcode.png",document.body.appendChild(gI),gI.click(),document.body.removeChild(gI),URL.revokeObjectURL(OA)}).catch(()=>{alert("Failed to download image.")}):jI(p.title,UA.payload||void 0)},style:{background:f,borderRadius:`${m}px`,color:J},children:UA.title},LA))]})})});case"video":return u.jsx("div",{className:"relative group w-[250px]",children:u.jsx("video",{src:p.video,className:"w-full rounded-lg cursor-pointer hover:opacity-90 transition-opacity",controls:!0})});case"file":const uA=p.file?.split(".").pop?.()?.toLowerCase()||"";return u.jsx("div",{className:"p-2 rounded-lg max-w-xs cursor-pointer transition-colors",onClick:()=>window.open(p.file,"_blank"),onMouseEnter:UA=>UA.currentTarget.style.backgroundColor=f,onMouseLeave:UA=>UA.currentTarget.style.backgroundColor="transparent",title:p.title,children:u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsx("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center",style:{background:f},children:ib(uA,X)}),u.jsx("div",{className:"flex-1 min-w-0",children:u.jsx("p",{className:"text-sm font-medium truncate",style:{color:X},children:p.title})})]})});case"products":return u.jsx(BG,{products:p.products||[],onValidate:UA=>{jI("cart ",UA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});case"json":switch(p.json?.type){case"text":return u.jsx(Be,{remarkPlugins:[Ee],components:lE,children:te(p.json.content)});case"image":return u.jsx("div",{className:"relative group",children:u.jsx("img",{src:p.json.content,className:"max-h-48 rounded-lg object-cover cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>window.open(p.json?.content,"_blank")})});case"video":return u.jsx("div",{className:"relative group",children:u.jsx("video",{src:p.json.content,className:"max-h-48 rounded-lg object-cover cursor-pointer hover:opacity-90 transition-opacity",controls:!0})});case"document":const UA=p.json.content.split(".").pop?.()?.toLowerCase();return u.jsx("div",{className:"w-[300px] p-2 rounded-lg max-w-xs cursor-pointer transition-colors",onClick:()=>window.open(p.json?.content,"_blank"),onMouseEnter:OA=>OA.currentTarget.style.backgroundColor=f,onMouseLeave:OA=>OA.currentTarget.style.backgroundColor="transparent",title:p.json?.title,children:u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsx("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center",style:{background:f},children:ib(UA||"",X)}),u.jsx("div",{className:"flex-1 min-w-0",children:u.jsx("p",{className:"text-sm font-medium truncate",style:{color:X},children:p.json.title})})]})});case"audio":return u.jsx("div",{className:"w-[300px]",children:u.jsx(yW,{src:p.json.content,mainColor:s,secondaryColor:a,controlsColor:X})});case"cards":return p.json.content.map((OA,gI)=>u.jsx("div",{className:"mt-2 w-full",children:u.jsx("div",{className:"grid grid-cols-1 gap-3",children:u.jsxs("div",{className:"flex-shrink-0 border rounded-lg p-3 shadow-md",style:{background:P},children:[u.jsx("img",{src:OA.image,alt:OA.title,className:"max-h-48 w-full rounded-md mb-2"}),u.jsx("h3",{className:"font-bold",children:OA.title}),OA.button?.map((aI,SB)=>u.jsx("button",{className:"mb-1 mr-1 px-4 py-1 hover:scale-105 transition-all duration-100",onClick:()=>{if(aI.type==="link"&&typeof aI.action=="string")window.open(aI.action,"_blank");else if(aI.type==="postback"){const RI=(typeof aI.action=="string",aI.action);jI(aI.label,RI)}else aI.type==="say-something"&&typeof aI.action=="string"&&gB(RI=>[...RI,{sender:"agent",content:aI.action,id:`msg-${Date.now()}`,timestamp:new Date,seen:!0}])},style:{background:f,borderRadius:`${m}px`,color:J},children:aI.label},SB))]})})},gI));case"slider":const LA=p.json.content.map(OA=>({image:OA.image,title:OA.caption,subtitle:"",actions:[]}));return u.jsx(r4,{items:LA,chatRoundness:m,agentChatResponseBgColor:P,agentChatResponseColor:X,buttonsBgColor:f,buttonColor:J,inputBackgroundColor:r,onButtonClick:jI,setMessages:gB});case"carousel":const Gg=p.json.content.map(OA=>({image:OA.image,title:OA.title,subtitle:OA.description||"",actions:OA.button?.map(gI=>({title:gI.label,payload:gI.action,action:gI.type,url:typeof gI.action=="string"?gI.action:""}))||[]}));return u.jsx(r4,{items:Gg,chatRoundness:m,agentChatResponseBgColor:P,agentChatResponseColor:X,buttonsBgColor:f,buttonColor:J,inputBackgroundColor:r,onButtonClick:jI,setMessages:gB});case"products":return u.jsx(BG,{products:p.json.content,onValidate:OA=>{jI("cart ",OA)},agentChatResponseColor:X,agentChatResponseBgColor:P,buttonsBgColor:f,buttonColor:J,chatRoundness:m,panelWidth:bA,inputBackgroundColor:r});default:return null}}},Nw=async p=>{if(!ZI)return;const uA=await fetch(`${Qh}/endusers/get-by-username`,{headers:{Authorization:`Bearer ${g?.token}`,"Content-Type":"application/json"},method:"POST",body:JSON.stringify({username:`web_user_${p}`})});if(!uA.ok)throw new Error(`HTTP error! status: ${uA.status}`);return(await uA.json()).id},zC=async p=>{if(!ZI)return;const uA=await Nw(p);let UA;PI&&(UA={last_name:PI.split(" ")[1]||PI.split(" ")[0]||`web_user_${p}`,first_name:PI.split(" ")[0]||`web_user_${p}`}),sC&&(UA={...UA,phone:sC}),WE&&(UA={...UA,email:WE});const LA=await fetch(`${Qh}/endusers/${uA}`,{headers:{Authorization:`Bearer ${g?.token}`,"Content-Type":"application/json"},method:"PUT",body:JSON.stringify(UA)});if(!LA.ok)throw new Error(`HTTP error! status: ${LA.status}`);return await LA.json()},mQ=async p=>{p.preventDefault();try{const UA=(await OB.post(`${Qh}/conversations/start-conversation`,{bot_id:g.bot?.botId,externalUser:g.user.id})).data.conversationId;ug(UA),localStorage.setItem("conversationId",UA),localStorage.setItem("webChatAuth","true"),NB(!0),hG.emit("join_room",parseInt(UA))}catch(uA){console.error("Error during login:",uA)}},[EI,PQ]=vA.useState(!1),pe=async()=>{gB([]),localStorage.removeItem("enduserUpdated");const p=localStorage.getItem("phone_client");if(g.bot?.botId==="rockskin"&&p)return YB(p),localStorage.setItem("externalUser",p),p;const uA=new Uint8Array(16);window.crypto.getRandomValues(uA);const UA=Array.from(uA).map(LA=>LA.toString(16).padStart(2,"0")).join("");YB(UA),localStorage.setItem("externalUser",UA),localStorage.removeItem("conversationId"),ug(null)},$i=`linear-gradient(to bottom right, ${G}, ${s}, ${G})`,TC=`linear-gradient(to right, ${s}, ${a})`,QQ=`linear-gradient(to right, ${R}, ${U})`,GC=async(p,uA)=>{try{let UA="";if(typeof p=="string")UA=p;else for(const LA of p)LA.type==="text"&&LA.text?UA+=`
636
636
  `+LA.text||"":LA.type==="single-choice"&&LA.choices&&LA.choices.length>0?(UA+=`
637
637
  `+LA.text||"",UA+=`
638
638
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tybotflow-widget",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "A modern, customizable React widget for Tybot chat integration.",
5
5
  "license": "ISC",
6
6
  "main": "dist/index.umd.js",