"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),a=require("semantic-ui-react"),d=require("react"),u=require("@devgateway/wp-react-lib"),_=require("react-intl"),o=require("react-router"),w=require("./SearchControl.js"),N=require("./LangSwitcher.js"),I=(s,l)=>{const c=[];return s.items.forEach(t=>{t.child_items?t.child_items.forEach(n=>{n.slug==l.slug&&(c.push(t),c.push(n))}):t.slug==l.slug&&t.url!="/"&&c.push(t)}),c},k=(s,l)=>s?s.substr(s.indexOf("/wp")+3).startsWith("/"+l)?s.substr(s.indexOf("/wp")+3):"/"+l+s.substr(s.indexOf("/wp")+3):"",L=_.injectIntl(({menu:s,intl:l})=>{const c=o.useParams(),t=I(s,c);return e.jsx(d.Fragment,{children:t.filter(n=>n.url!="#wpm-languages").map(n=>n.child_items?e.jsxs("span",{children:[n.post_title," "]}):e.jsxs("a",{className:n.slug==c.slug?"active":"",href:u.utils.replaceLink(n.url,l.locale),children:[" ",n.post_title]}))})}),p=_.injectIntl(({settings:s,withIcons:l,active:c,menu:t,onSetSelected:n,selected:m,intl:{locale:h}})=>{const v=o.useParams();d.useEffect(r=>{if(!m){const i=I(t,v).filter(j=>j.menu_item_parent==0);i&&n(i[0])}},[t,n,m]);const[f,g]=d.useState(null);return d.useEffect(()=>{g(t)},[t]),d.useEffect(()=>{if(s&&s.menu_settings&&f){const r=[],x=t.items.map(i=>(s.menu_settings&&s.menu_settings["nav_menu_item["+i.ID+"]"]===!1&&r.push(i.ID),s.menu_settings&&s.menu_settings["nav_menu_item["+i.ID+"]"]?(s.menu_settings["nav_menu_item["+i.ID+"]"],{...i,...s.menu_settings["nav_menu_item["+i.ID+"]"]}):i));Object.keys(s.menu_settings).map(i=>{const j=s.menu_settings[i];if(j.type=="nav_menu_item"){const M=/(-)?[0-9]+/g.exec(i),b=parseInt(M[0]);x.find(C=>C.ID==b)||x.push(j.value)}}),g({...t,items:x.filter(i=>r.indexOf(i.ID)===-1)})}},[s]),f&&e.jsx(d.Fragment,{children:f.items.filter(r=>r.url!="#wpm-languages").map(r=>e.jsx(a.Menu.Item,{as:o.Link,className:`divided ${r.child_items?"has-child-items":""} ${m&&m.ID==r.ID?"selected":""}  ${c==r.slug?"active":""}`,children:r.child_items?e.jsx("span",{onClick:x=>n(r),children:r.title}):e.jsx(o.Link,{onClick:x=>n(r),to:r.type==="custom"?u.utils.replaceLink(r.url,h):k(r.url,h),children:r.title})}))})}),D=({intl:s,settings:l})=>{const[c,t]=d.useState(),{slug:n}=o.useParams(),m=({media:h})=>h?e.jsx(a.Image,{src:h.guid.rendered}):e.jsx("img",{className:"brand logo",size:"large",src:"/logo_full.png"});return e.jsx(d.Fragment,{children:e.jsxs(u.MenuProvider,{slug:"main",locale:s.locale,children:[e.jsxs(a.Container,{fluid:!0,className:"header classic",children:[e.jsx(a.Container,{fluid:!0,className:"background",children:e.jsxs(a.Menu,{className:"branding",text:!0,children:[e.jsx(a.Menu.Item,{children:e.jsxs(o.NavLink,{to:"/",children:[l.site_logo!=0&&e.jsx(u.MediaProvider,{id:l.site_logo,children:e.jsx(u.MediaConsumer,{children:e.jsx(m,{})})}),!window.isCustomizedPreview&&l.site_logo==0&&e.jsx("img",{className:"brand logo",size:"large",src:"/dc-logo_01.png"})]})}),e.jsx(a.Menu.Item,{className:"divider",children:e.jsx("div",{})}),e.jsx(a.Menu.Item,{as:o.Link,fitted:!0,href:"/",children:e.jsx("div",{className:"site name",children:l.name})}),e.jsx(a.Menu.Menu,{className:"pages",children:e.jsx(u.MenuConsumer,{children:e.jsx(p,{settings:l,active:n,selected:c,onSetSelected:t})})}),e.jsx(a.Menu.Item,{children:e.jsx(u.MenuConsumer,{children:e.jsx(N.default,{locale:s.locale})})}),e.jsx(a.Menu.Item,{fitted:!0,children:e.jsx(w.default,{})})]})}),e.jsx(a.Container,{fluid:!0,className:"child",children:c&&c.child_items&&e.jsx(a.Menu,{fluid:!0,text:!0,children:e.jsx(p,{active:n,locale:s.locale,withIcons:!0,onSetSelected:h=>null,menu:{items:c.child_items}})})})]}),e.jsx(a.Container,{className:"url breadcrumbs",children:e.jsx(u.MenuConsumer,{children:e.jsx(L,{})})})]})})},q=_.injectIntl(D);exports.default=q;
