"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("react/jsx-runtime"),h=require("../conf/index.js"),m=require("react"),p=require("semantic-ui-react"),u=a=>{window.location=window.location.origin+"/"+a.toLowerCase()+window.location.pathname.toString().substring(3)},g=(a,t,c)=>Object.keys(a).map(n=>({key:n,text:t==="name"||t==="both"?a[n].name:n.toUpperCase(),value:n,selected:n.toUpperCase()===c.toUpperCase(),icon:t==="flag"||t==="both"?s.jsx(p.Image,{src:"/wp/wp-content/plugins/wp-multilang/flags/"+a[n].flag}):null})),w=a=>{const{menu:{menu_item_languages_show:t},settings:{languages:c},locale:n}=a,o=g(c,t,n);return s.jsx(p.Dropdown,{button:!0,className:"icon language selector",floating:!0,labeled:!0,icon:"world",options:o,onChange:(e,{name:r,value:l})=>{u(l)},text:"Language"})},_=a=>{const{menu:{menu_item_languages_show:t},settings:{languages:c},locale:n}=a,o=g(c,t,n);return s.jsx("p",{className:"inline language selector",children:o.map(e=>s.jsxs("span",{className:e.selected?"selected":"",children:[e.icon,s.jsx("a",{onClick:r=>u(e.value),children:e.text}),"  "]}))})},j=a=>{const{menu:{menu_item_languages_show:t},settings:{languages:c},locale:n}=a,o=g(c,t,n);return s.jsx("p",{className:"single language selector",children:o.map(e=>s.jsx("a",{className:e.selected?"selected":"",onClick:r=>u(e.value),children:e.value}))})},x=a=>{const{menu:{menu_item_languages_show:t},settings:{languages:c},locale:n}=a;g(c,t,n);const[o,e]=m.useState(n),r=()=>{const l=o==="en"?"fr":"en";e(l);const i=document.querySelector(".circle");i.classList.toggle("en"),i.classList.toggle("fr"),setTimeout(()=>{u(l)},300)};return s.jsxs("div",{className:"toggler language selector",children:[s.jsx("a",{className:`language-label ${o==="en"?"active":""}`,onClick:()=>{u("en"),e("en")},children:"EN"}),s.jsx("button",{className:"toggle-button",onClick:r,children:s.jsx("div",{className:`circle ${o==="en"?"en":"fr"}`})}),s.jsx("a",{className:`language-label ${o==="fr"?"active":""}`,onClick:()=>{u("fr"),e("fr")},children:"FR"})]})},f=a=>{const{locale:t,menu:c}=a,n=c.items.filter(l=>l.url==="#wpm-languages"),o=n.length>0,[e,r]=m.useState(null);return m.useEffect(()=>{async function l(){const d=await(await fetch(h.Config.REACT_APP_WP_API+"/dg/v1/settings",{headers:{"Content-Type":"application/json"}})).json();r(d)}l()},[]),o&&e?n.map(l=>{const i=l.menu_item_languages_type;switch(l.menu_item_languages_show,i){case"dropdown":return s.jsx(w,{locale:t,menu:l,settings:e});case"inline":return s.jsx(_,{locale:t,menu:l,settings:e});case"single":return s.jsx(j,{locale:t,menu:l,settings:e});case"toggler":return s.jsx(x,{locale:t,menu:l,settings:e})}return null}):null};exports.default=f;
