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