!function(){"use strict";var e={n:function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,{a:n}),n},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 F}});var n={};e.r(n),e.d(n,{changeReacted:function(){return g},receiveReactors:function(){return p},setReactors:function(){return u}});var o={};e.r(o),e.d(o,{getReactors:function(){return w}});var i={};e.r(i),e.d(i,{getCount:function(){return m},getReactors:function(){return f},hasReacted:function(){return v}});var r=window.wp.dataControls,a=window.wp.data,c=window.lodash;const s=(0,window.nisje.data.onSubKey)("context")((function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0;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}}));var d=s;const l="post";function u(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:l;return{type:"SET_REACTORS",id:e,context:n,reactions:t}}function p(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:l,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;return{type:"RECEIVE_REACTORS",id:e,reactors:t,context:n,reactionsType:o}}function*g(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:l,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,o=arguments.length>3?arguments[3]:void 0;yield{type:"CHANGE_REACTED",id:e,context:t,reacted:o},yield(0,r.apiFetch)({path:"/dekode-intranet/v1/reactions/"+(o?"add":"remove"),method:"POST",data:{object_id:e,object_type:t,reaction_type_id:n}})}var h=window.nisje.app.url;function*w(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:l,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1;const i=(0,h.addQueryArgs)("/dekode-intranet/v1/reactions",{object_id:e,object_type:t,page:o,reaction_type_id:n}),a=yield(0,r.apiFetch)({path:i});yield p(e,a,t,n)}function m(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:l;return(0,c.get)(e[n],`${t}.total`,0)}function v(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:l;return(0,c.get)(e[n],`${t}.reacted`,!1)}function f(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:l,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;return(0,c.get)(e[n],`${t}.reactors.${o}`,[])}function _(){return _=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:d,controls:r.controls,actions:n,selectors:i,resolvers:o});var E=window.wp.element,y=window.React,j=window.wp.i18n,R=window.nisje.app.utils,b=window.nisje.icons,C=window.nisje.app.track,S=window.nisje.app.constants,k=window.nisje.app.components,T=window.nisje.components,x=window.nisje.app.emotion.styled,O=e.n(x),L=window.nisje.app.ui;const A=O()(k.Button)`
	justify-content: center;
	margin-top: 15px;
	width: 100%;
`,N=O().div`
	padding: 3.125rem;
	text-align: center;
`,P=O()(k.Button)`
	padding-left: 0;
	padding-right: 0;
	color: ${e=>{let{hasReacted:t}=e;return t?L.colors.primary:"inherit"}};
`;var B=(0,a.withSelect)(((e,t)=>{let{context:n,id:o,page:i,type:r}=t;const{getReactors:a,getCount:c,isResolving:s}=e("nisje/reactions"),d=a(o,n,r,i),l=s("getReactors",[o,n,r,i]);return{reactors:d,showLoadButton:d.length<c(o,n),isLoading:l}}))((function(e){let{handleNextPageClick:t,isLoading:n,reactors:o,showLoadButton:i}=e;return(0,E.createElement)("div",null,0===o.length?(0,E.createElement)(N,null,(0,E.createElement)(T.Loader,{size:30})):(0,E.createElement)(T.MembersList,{members:o}),0!==o.length&&i&&(0,E.createElement)(A,{isSecondary:!0,onClick:t,isBusy:n},(0,j.__)("Load more","nisje")))})),$=(0,a.withSelect)(((e,t)=>{let{id:n,context:o}=t;const{getCount:i,getReactors:r}=e("nisje/reactions");return{count:i(n,o),reactors:r(n,o).slice(0,10)}}))((function(e){let{reactors:t,count:n}=e;return(0,y.useEffect)((()=>{(0,C.trackEvent)("view_reactions_tooltip","engagement")}),[]),(0,E.createElement)("div",{className:"reactions__tooltip"},0===t.length?(0,j.__)("Loading...","nisje"):(0,E.createElement)(E.Fragment,null,t.map((e=>{let{id:t,name:n}=e;return(0,E.createElement)("div",{key:`reactor-${t}`},(0,R.decodeEntities)(n))})),n>10&&(0,E.createElement)("div",null,
/* translators: %d: number of additional reactors */
(0,j.sprintf)((0,j.__)("and %d more...","nisje"),n-10))))})),F=(0,c.flowRight)((0,a.withSelect)(((e,t)=>{let{id:n,context:o}=t;const{getCount:i,hasReacted:r}=e("nisje/reactions");return{count:i(n,o),hasReacted:r(n,o)}})),(0,a.withDispatch)(((e,t)=>{let{id:n,context:o}=t;return{changeReacted(t,i){e("nisje/reactions").changeReacted(n,o,i,t)}}})))((function(e){let{changeReacted:t,count:n,hasReacted:o,...i}=e;const[r,a]=(0,y.useState)(!1),[c,s]=(0,y.useState)(1);return(0,E.createElement)("span",{className:"reactions"},(0,E.createElement)(P,{hasReacted:o,icon:o?b.likeFilled:b.like,onClick:()=>t(!o),disabled:!S.isUserLoggedIn},(0,j.__)("Like","nisje")),0!==n&&(0,E.createElement)(k.Tooltip,{text:(0,E.createElement)($,i),position:"top center"},(0,E.createElement)("button",{type:"button",className:"reactions__count",onClick:()=>{a(!0),(0,C.trackEvent)("view_reactions_list","engagement")}},(0,R.abbreviate)(n))),r&&(0,E.createElement)(k.Modal,{className:"reactions__modal",title:(0,E.createElement)("span",{className:"reactions__modal-title"},(0,E.createElement)(b.Icon,{icon:b.likeFilled})," ",(0,j.__)("Likes","nisje")),onRequestClose:()=>a(!1),closeButtonLabel:(0,j.__)("Close","nisje")},(0,E.createElement)(B,_({},i,{page:c,type:1,handleNextPageClick:()=>s(c+1)}))))}));(window.nisje=window.nisje||{}).reactions=t}();