!function(){"use strict";var e={d:function(t,n){for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{Reactions:function(){return O}});var n={};e.r(n),e.d(n,{changeReacted:function(){return u},receiveReactors:function(){return l},setReactors:function(){return d}});var o={};e.r(o),e.d(o,{getReactors:function(){return w}});var r={};e.r(r),e.d(r,{getCount:function(){return m},getReactors:function(){return _},hasReacted:function(){return g}});var i=window.wp.dataControls,a=window.wp.data,c=window.lodash,s=(0,window.nisje.data.onSubKey)("context")(((e={},t)=>{switch(t.type){case"SET_REACTORS":return{...e,[t.id]:{reactors:{},...e[t.id],...t.reactions}};case"RECEIVE_REACTORS":{const n=String(t.reactionsType);return{...e,[t.id]:{...e[t.id],reactors:{...e[t.id].reactors,[n]:(0,c.unionBy)(e[t.id].reactors[n],t.reactors,"id")}}}}case"CHANGE_REACTED":return{...e,[t.id]:{...e[t.id],reacted:t.reacted,total:e[t.id].total+(t.reacted?1:-1)}};default:return e}}));function d(e,t,n="post"){return{type:"SET_REACTORS",id:e,context:n,reactions:t}}function l(e,t,n="post",o=0){return{type:"RECEIVE_REACTORS",id:e,reactors:t,context:n,reactionsType:o}}function*u(e,t="post",n=1,o){yield{type:"CHANGE_REACTED",id:e,context:t,reacted:o},yield(0,i.apiFetch)({path:"/dekode-intranet/v1/reactions/"+(o?"add":"remove"),method:"POST",data:{object_id:e,object_type:t,reaction_type_id:n}})}var p=window.nisje.url;function*w(e,t="post",n=0,o=1){const r=(0,p.addQueryArgs)("/dekode-intranet/v1/reactions",{object_id:e,object_type:t,page:o,reaction_type_id:n}),a=yield(0,i.apiFetch)({path:r});yield l(e,a,t,n)}function m(e,t,n="post"){return(0,c.get)(e[n],`${t}.total`,0)}function g(e,t,n="post"){return(0,c.get)(e[n],`${t}.reacted`,!1)}function _(e,t,n="post",o=0){return(0,c.get)(e[n],`${t}.reactors.${o}`,[])}function E(){return(E=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e}).apply(this,arguments)}(0,a.registerStore)("nisje/reactions",{reducer:s,controls:i.controls,actions:n,selectors:r,resolvers:o});var f=window.wp.element,y=window.React,h=window.wp.i18n,j=window.wp.components,R=window.nisje.format,v=window.nisje.icons,b=window.nisje.track,C=window.nisje.settings,S=window.nisje.components;const k=(0,window.nisje.styled.styled)(S.ExperimentalButton)`
	justify-content: center;
	margin-top: 15px;
	width: 100%;
`;var T=(0,a.withSelect)(((e,{context:t,id:n,page:o,type:r})=>{const{getReactors:i,getCount:a,isResolving:c}=e("nisje/reactions"),s=i(n,t,r,o),d=c("getReactors",[n,t,r,o]);return{reactors:s,showLoadButton:s.length<a(n,t),isLoading:d}}))((function({handleNextPageClick:e,isLoading:t,reactors:n,showLoadButton:o}){return(0,f.createElement)("div",null,0===n.length?(0,f.createElement)("div",{className:"reactions__modal-loader"},(0,f.createElement)(S.Loader,{size:30})):(0,f.createElement)(S.MembersList,{members:n}),0!==n.length&&o&&(0,f.createElement)(k,{isSecondary:!0,onClick:e,isBusy:t},(0,h.__)("Load more","nisje")))})),x=(0,a.withSelect)(((e,{id:t,context:n})=>{const{getCount:o,getReactors:r}=e("nisje/reactions");return{count:o(t,n),reactors:r(t,n).slice(0,10)}}))((function({reactors:e,count:t}){return(0,y.useEffect)((()=>{(0,b.trackEvent)("view_reactions_tooltip","engagement")}),[]),(0,f.createElement)("div",{className:"reactions__tooltip"},0===e.length?(0,h.__)("Loading...","nisje"):(0,f.createElement)(f.Fragment,null,e.map((({id:e,name:t})=>(0,f.createElement)("div",{key:`reactor-${e}`},(0,R.decodeEntities)(t)))),t>10&&(0,f.createElement)("div",null,
/* translators: %d: number of additional reactors */
(0,h.sprintf)((0,h.__)("and %d more...","nisje"),t-10))))})),O=(0,c.flowRight)((0,a.withSelect)(((e,{id:t,context:n})=>{const{getCount:o,hasReacted:r}=e("nisje/reactions");return{count:o(t,n),hasReacted:r(t,n)}})),(0,a.withDispatch)(((e,{id:t,context:n})=>({changeReacted(o,r){e("nisje/reactions").changeReacted(t,n,r,o)}}))))((function({changeReacted:e,count:t,hasReacted:n,...o}){const[r,i]=(0,y.useState)(!1),[a,c]=(0,y.useState)(1),s=(0,R.classnames)("reactions__action",{"has-reacted":n});return(0,f.createElement)("span",{className:"reactions"},(0,f.createElement)(j.Button,{className:s,icon:n?v.likeFilled:v.like,onClick:()=>e(!n),disabled:!C.isUserLoggedIn},(0,h.__)("Like","nisje")),0!==t&&(0,f.createElement)(j.Tooltip,{text:(0,f.createElement)(x,o),position:"top center"},(0,f.createElement)("button",{type:"button",className:"reactions__count",onClick:()=>{i(!0),(0,b.trackEvent)("view_reactions_list","engagement")}},(0,R.abbreviate)(t))),r&&(0,f.createElement)(j.Modal,{className:"reactions__modal",title:(0,f.createElement)("span",{className:"reactions__modal-title"},(0,f.createElement)(v.Icon,{icon:v.likeFilled})," ",(0,h.__)("Likes","nisje")),onRequestClose:()=>i(!1),closeButtonLabel:(0,h.__)("Close","nisje")},(0,f.createElement)(T,E({},o,{page:a,type:1,handleNextPageClick:()=>c(a+1)}))))}));(window.nisje=window.nisje||{}).reactions=t}();