!function(){var e={94184:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function s(){for(var e=[],t=0;t<arguments.length;t++){var n=arguments[t];if(n){var a=typeof n;if("string"===a||"number"===a)e.push(n);else if(Array.isArray(n)){if(n.length){var i=s.apply(null,n);i&&e.push(i)}}else if("object"===a)if(n.toString===Object.prototype.toString)for(var o in n)r.call(n,o)&&n[o]&&e.push(o);else e.push(n.toString())}}return e.join(" ")}e.exports?(s.default=s,e.exports=s):void 0===(n=function(){return s}.apply(t,[]))||(e.exports=n)}()}},t={};function n(r){var s=t[r];if(void 0!==s)return s.exports;var a=t[r]={exports:{}};return e[r](a,a.exports,n),a.exports}n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};!function(){"use strict";n.r(r);var e={};n.r(e),n.d(e,{setResult:function(){return m},setTab:function(){return p},setValue:function(){return l},setVisible:function(){return u}});var t={};n.r(t),n.d(t,{getResults:function(){return h},getTab:function(){return v},getValue:function(){return d},isVisible:function(){return f}});var s=window.wp.element,a=window.wp.data,i=window.nisje.app.plugins,o=window.wp.dataControls;const c={visible:!1,value:"",results:!1,tab:""};function u(e){return{type:"VIEW_SEARCH",visible:e}}function l(e){return{type:"SET_VALUE",value:e}}function m(e){return{type:"SET_RESULT",value:e}}function p(e){return{type:"SET_TAB",tab:e}}function f(e){return e.visible}function d(e){return e.value}function h(e){return e.results}function v(e){return e.tab}(0,a.registerStore)("nisje/search",{reducer:function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:c,t=arguments.length>1?arguments[1]:void 0;switch(t.type){case"VIEW_SEARCH":return{...e,visible:t.visible};case"SET_VALUE":return t.value===e.value?e:{...e,value:t.value,results:!1};case"SET_RESULT":return{...e,results:t.value};case"SET_TAB":return{...e,tab:t.tab};default:return e}},controls:o.controls,actions:e,selectors:t});var w=window.wp.i18n,b=window.nisje.interface,g=window.nisje.app.track,E=window.nisje.icons,j=function(){const{setVisible:e}=(0,a.useDispatch)("nisje/search");return(0,s.createElement)(b.ToolbarMenuControls,null,(0,s.createElement)(b.ToolbarMenuButton,{icon:E.search,label:(0,w.__)("Search","nisje"),onClick:()=>{e(!0),(0,g.trackEvent)("view_search","engagement")}}))},y=window.lodash,S=window.React,_=n(94184),T=n.n(_),C=window.wp.components,R=window.wp.hooks,x=window.nisje.app.fetch,V=window.nisje.app.api,A=window.nisje.components,k=window.nisje.app.emotion.styled,N=n.n(k),D=window.nisje.app.components,O=window.nisje.app.ui;const M=N()(D.Button)`
	border-bottom: 2px solid
		${e=>{let{isActive:t}=e;return t?O.colors.primary:"transparent"}};
	border-radius: 0;
	font-size: 0.875rem;
	height: 2.75rem;
	margin-bottom: -1px;
	margin-right: 1rem;
	padding: 0 0.25rem;
`;function P(){return(0,y.map)((0,V.getSearchTypes)(),(e=>{let{render:t,name:n,title:r}=e;return{Component:t,context:{title:r,name:n}}}))}var L=function(e){let{value:t,onRequestClose:n}=e;const[r,i]=(0,S.useState)(P()),{results:o,tab:c}=(0,a.useSelect)((e=>{const{getResults:t,getTab:n}=e("nisje/search");return{results:t(),tab:n()}})),{setResult:u,setTab:l}=(0,a.useDispatch)("nisje/search"),{receiveRecords:m}=(0,a.useDispatch)("nisje/core");function p(){i(P())}(0,S.useEffect)((()=>((0,R.addAction)("search.typesRegistered","core/search/types-registered",p),()=>{(0,R.removeAction)("search.typesRegistered","core/search/types-registered")})),[]),(0,S.useEffect)((()=>{(0,x.apiFetch)({path:`/nisje/v1/search?search=${t}`}).then((e=>{m(e["user-content"].items),u(e)}))}),[t]),(0,S.useEffect)((()=>{!o||c&&0!==o[c].total||l((0,y.findKey)(o,(e=>0!==e.total)))}),[o,l,c]);const f=r.some((e=>{let{context:t}=e;return o[t.name]&&0!==o[t.name].total}));return o&&!f?(0,s.createElement)("div",{className:"search-no-results"},(0,s.createElement)(A.TextDeprecated,{as:"h2",variant:"title-small"},(0,w.sprintf)((0,w.__)("No results for “%s”","nisje"),t))):(0,s.createElement)(s.Fragment,null,(0,s.createElement)("div",{className:"search-tabs"},r.map((e=>{let{context:t}=e;const n=`search-${t.name}`;return o?o[t.name]&&0!==o[t.name].total?(0,s.createElement)(M,{key:n,onClick:()=>l(t.name),isActive:t.name===c},t.title," ",o[t.name].total):null:(0,s.createElement)("span",{key:n,className:"search-tab-loader nisje-post-loader__stroke"})}))),(0,s.createElement)("div",{className:"search-content"},!o&&(0,s.createElement)("div",{className:"search-content__loader"},(0,s.createElement)(A.Loader,{size:24})),o&&r.map((e=>{var t;let{context:r,Component:a}=e;if(!o[r.name]||0===o[r.name].total)return null;const i=`search-${r.name}`;return(0,s.createElement)(a,{key:i,items:null===(t=o[r.name])||void 0===t?void 0:t.items,isActive:r.name===c,onClick:n})}))))};function B(e){let{value:t,onChange:n,handleSubmit:r}=e;const i=(0,S.useRef)(),{setValue:o}=(0,a.useDispatch)("nisje/search");return(0,S.useEffect)((()=>{i.current.focus()}),[]),(0,s.createElement)(s.Fragment,null,(0,s.createElement)(E.Icon,{icon:E.search,size:20}),(0,s.createElement)("form",{onSubmit:function(e){e.preventDefault(),r(t)},className:"nisje-search__form"},(0,s.createElement)("input",{className:"nisje-search__input",value:t,onChange:e=>{o(""),n(e.target.value)},ref:i})))}var F=function(){const{setVisible:e,setValue:t}=(0,a.useDispatch)("nisje/search"),n=(0,a.useSelect)((e=>e("nisje/search").getValue())),[r,i]=(0,S.useState)(n),o=!(0,y.isEmpty)(n),c=!o&&r;function u(e){t(e),(0,g.trackEvent)("search","engagement",e)}return(0,s.createElement)(C.Modal,{onRequestClose:()=>e(!1),className:T()("nisje-search",{"has-value":o,"has-border":o||c}),title:(0,s.createElement)(B,{value:r,onChange:i,handleSubmit:u})},c&&(0,s.createElement)("button",{className:"nisje-search__trigger",onClick:()=>u(r),type:"button"},
/* translators: %s: search string */
(0,w.sprintf)((0,w.__)("Search for “%s”","nisje"),r)),o&&(0,s.createElement)(L,{value:n,onRequestClose:()=>e(!1)}))};(0,i.registerPlugin)("search",{render(){const e=(0,a.useSelect)((e=>e("nisje/search").isVisible()));return(0,s.createElement)(s.Fragment,null,(0,s.createElement)(j,null),e&&(0,s.createElement)(F,null))}})}(),(window.nisje=window.nisje||{}).search=r}();