!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,a=window.nisje.router,i=window.wp.data,l=window.nisje.components,s=window.nisje.format;function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=e&&("undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"]);if(null!=n){var r,o,a=[],_n=!0,i=!1;try{for(n=n.call(e);!(_n=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);_n=!0);}catch(e){i=!0,o=e}finally{try{_n||null==n.return||n.return()}finally{if(i)throw o}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return c(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?c(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}(0,o.registerCardRender)("nisje-blogs-group",{render:function(e){var n=e.id,r=(0,i.useSelect)((function(e){return e("nisje/core").post(n)}));if(!r)return null;var o=r.group_id,c=r.title,u="/groups/".concat(o,"/blog/").concat(n,"/");return(0,t.createElement)(l.BaseCard,{url:u},(0,t.createElement)(l.TextDeprecated,{as:"h2",variant:"title-medium"},(0,t.createElement)(a.Link,{to:u},(0,s.decodeEntities)(c.rendered))))}});var d=window.lodash,g=window.nisje.url,m=window.nisje.interface,p=window.nisje.icons,w=window.nisje.data,f=(0,o.canUserCreate)("news"),E=function(e){var n=e.match,o=(0,i.useDispatch)("nisje/core").receiveRecords,a=n.params.id,s=parseInt(n.params.page||"1",10),c={per_page:24,page:s,group_id:a},E=(0,g.addQueryArgs)("/wp/v2/nisje-blogs-group",c),b=u((0,w.useApiFetch)(E,{fetchHeaders:!0,callback:function(e){return o(e)}}),2),h=b[0],y=b[1];return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(m.Header,{title:(0,r.__)("Blogs")},f&&(0,t.createElement)(m.HeaderButton,{icon:p.plusCircle,href:"/groups/".concat(a,"/blogs/new/")},(0,r.__)("New post"))),!h&&(0,t.createElement)(l.FeedGrid,null,(0,t.createElement)(l.BaseCardLoaders,null)),h&&!(0,d.isEmpty)(h)&&(0,t.createElement)(l.FeedGrid,null,(0,t.createElement)(l.Cards,{items:h})),h&&(0,d.isEmpty)(h)&&(0,t.createElement)(m.Message,{icon:p.postList},(0,r.__)("No posts yet...")),y&&(0,t.createElement)(l.Pagination,{totalPages:y.totalPages,currentPage:s,path:"/blog/"}))},b=window.nisje.views,h=window.nisje.comments,y=window.nisje.reactions,_=function(e){var n=e.match.params,a=n.blogId,s=n.id,c=u((0,w.useApiFetch)("/wp/v2/nisje-blogs-group/".concat(a,"?group_id=").concat(s),{callback:function(e){(0,i.dispatch)("nisje/reactions").setReactors(e.id,e.reactions)}}),2),d=c[0],g=c[1];if(g)return(0,t.createElement)(b.Message,{icon:p.warning},g.data.status,": ",g.message);if(!d)return(0,t.createElement)(l.PostLoader,null);var f=[{title:(0,r.__)("Blogs"),href:"/groups/".concat(s,"/blog/")}],E="open"===d.comment_status;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(l.EntryContainer,{autoHeight:E},(0,t.createElement)(l.EntryControls,{showOptions:(0,o.canUserEdit)("news")||o.currentUserId===d.author,controls:[(0,t.createElement)(l.ExperimentalButton,{isMenuItem:!0,href:"/groups/".concat(s,"/blogs/").concat(a,"/edit/")},(0,r.__)("Edit")),(0,t.createElement)(m.DeleteDialog,{closeOnClick:!1,restPath:"/wp/v2/nisje-blogs-group/".concat(a,"?force=true&group_id=").concat(s),redirect:"/groups/".concat(s,"/blog/"),title:(0,r.__)("Delete article?"),message:(0,r.__)("This will delete the article permanently"),successMessage:(0,r.__)("Successfully deleted the article")})],breadcrumbs:f}),(0,t.createElement)(l.EntryHeader,null,d.title.rendered),(0,t.createElement)(l.EntryByline,{authorId:d.author,authorName:d.author_name,date:d.date_gmt}),(0,t.createElement)(l.EntryContent,null,d.content.rendered),(0,t.createElement)(l.EntryActions,null,(0,t.createElement)(y.Reactions,{id:a}))),E&&(0,t.createElement)(h.Comments,{group:s,id:a,isEntryComments:!0}))};(0,o.registerPlugin)("group-blogs",{render:function(){return(0,t.createElement)(a.PluginGroupRoutes,null,(0,t.createElement)(a.Route,{path:"/groups/:id/blog",component:E,exact:!0}),(0,t.createElement)(a.Route,{path:"/groups/:id/blog/:blogId",component:_,exact:!0}))}}),(0,n.addFilter)("groups.menu.controls","nisje/plugin-blogs",(function(e,t){return t.enable_blogs&&e.push({icon:"postList",id:"blogs",title:(0,r.__)("Blog"),to:"/groups/".concat(t.id,"/blog/")}),e}),30),(window.nisje=window.nisje||{}).pluginBlogs=e}();