!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 r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},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);var n=window.wp.element,r=window.wp.hooks,o=window.wp.i18n,i=window.nisje.app.plugins,s=window.nisje.app.routes,a=window.nisje.app.router,l=window.wp.data,c=window.nisje.components,u=window.nisje.app.api,d=window.nisje.app.components,p=window.nisje.app.utils;(0,u.registerCard)("nisje-blogs-group",(function(e){let{id:t}=e;const r=(0,l.useSelect)((e=>e("nisje/core").post(t)));if(!r)return null;const{group_id:o,title:i}=r,s=`/groups/${o}/blog/${t}/`;return(0,n.createElement)(c.BaseCard,{url:s},(0,n.createElement)(c.TextDeprecated,{as:"h2",variant:"title-medium"},(0,n.createElement)(d.Link,{to:s},(0,p.decodeEntities)(i.rendered))))}));var g=window.lodash,m=window.nisje.app.url,w=window.nisje.app.constants,E=window.nisje.interface,j=window.nisje.icons,b=window.nisje.data;const _=(0,w.canUserCreate)("news");var h=function(e){let{match:t}=e;const{receiveRecords:r}=(0,l.useDispatch)("nisje/core"),{id:i}=t.params,s=parseInt(t.params.page||"1",10),a={per_page:24,page:s,group_id:i},u=(0,m.addQueryArgs)("/wp/v2/nisje-blogs-group",a),[d,p]=(0,b.useApiFetch)(u,{fetchHeaders:!0,callback:e=>r(e)});return(0,n.createElement)(n.Fragment,null,(0,n.createElement)(E.Header,{title:(0,o.__)("Blogs","nisje")},_&&(0,n.createElement)(E.HeaderButton,{icon:j.plusCircle,href:`/groups/${i}/blogs/new/`},(0,o.__)("New post","nisje"))),!d&&(0,n.createElement)(c.FeedGrid,null,(0,n.createElement)(c.BaseCardLoaders,null)),d&&!(0,g.isEmpty)(d)&&(0,n.createElement)(c.FeedGrid,null,(0,n.createElement)(c.Cards,{items:d})),d&&(0,g.isEmpty)(d)&&(0,n.createElement)(E.Message,{icon:j.postList},(0,o.__)("No posts yet...","nisje")),p&&(0,n.createElement)(c.Pagination,{totalPages:p.totalPages,currentPage:s,path:"/blog/"}))},f=window.nisje.views,y=window.nisje.app.comments,v=window.nisje.app.reactions,C=e.n(v),P=function(e){let{match:t}=e;const{blogId:r,id:i}=t.params,[s,a]=(0,b.useApiFetch)(`/wp/v2/nisje-blogs-group/${r}?group_id=${i}`,{callback:e=>{(0,l.dispatch)("nisje/reactions").setReactors(e.id,e.reactions)}});if(a)return(0,n.createElement)(f.Message,{icon:j.warning},a.data.status,": ",a.message);if(!s)return(0,n.createElement)(c.PostLoader,null);const u=[{title:(0,o.__)("Blogs","nisje"),href:`/groups/${i}/blog/`}],p="open"===s.comment_status;return(0,n.createElement)(n.Fragment,null,(0,n.createElement)(c.EntryContainer,{autoHeight:p},(0,n.createElement)(c.EntryControls,{showOptions:(0,w.canUserEdit)("news")||w.currentUserId===s.author,controls:[(0,n.createElement)(c.ExperimentalButton,{isMenuItem:!0,href:`/groups/${i}/blogs/${r}/edit/`},(0,o.__)("Edit","nisje")),(0,n.createElement)(E.DeleteDialog,{closeOnClick:!1,restPath:`/wp/v2/nisje-blogs-group/${r}?force=true&group_id=${i}`,redirect:`/groups/${i}/blog/`,title:(0,o.__)("Delete article?","nisje"),message:(0,o.__)("This will delete the article permanently","nisje"),successMessage:(0,o.__)("Successfully deleted the article","nisje")})],breadcrumbs:u}),(0,n.createElement)(c.EntryHeader,{title:s.title.rendered},(0,n.createElement)(d.Byline,{authorId:s.author,authorName:s.author_name,date:s.date_gmt})),(0,n.createElement)(c.EntryContent,null,s.content.rendered),(0,n.createElement)(c.EntryActions,null,(0,n.createElement)(C(),{id:r}))),p&&(0,n.createElement)(y.Comments,{group:i,id:r,isEntryComments:!0}))};(0,i.registerPlugin)("group-blogs",{render:()=>(0,n.createElement)(s.PluginGroupRoutes,null,(0,n.createElement)(a.Route,{path:"/groups/:id/blog",component:h,exact:!0}),(0,n.createElement)(a.Route,{path:"/groups/:id/blog/:blogId",component:P,exact:!0}))}),(0,r.addFilter)("groups.menu.controls","nisje/plugin-blogs",((e,t)=>(t.enable_blogs&&e.push({icon:"postList",id:"blogs",title:(0,o.__)("Blog","nisje"),to:`/groups/${t.id}/blog/`}),e)),30),(window.nisje=window.nisje||{}).pluginBlogs=t}();