import*as tslib_1 from"../polyfills/tslib.js";import{h}from"../webcomponents.core.js";import"./chunk-de721f0a.js";import{f as ConfigService,p as Wordpress}from"./chunk-f9f1602a.js";var AppWordpress=function(){function t(){var t=this;this.loading=!0,this.authenticated=!1,this.config=ConfigService.instance,this.wordpress=new Wordpress,this.loginModal=document.getElementById("login-modal"),document.addEventListener("loginShouldOccur",function(e){t.login(e.detail.username,e.detail.password)})}return t.prototype.componentWillLoad=function(){var t=this;document.getElementsByTagName("ema-router")[0].getState().then(function(e){t.currentPostId=e.context.params.pid}),this.wordpress.init(this.config.get("wordpress")["wordpress-dev-local"]).then(function(e){t.getData().then(function(){t.authenticated=t.wordpress.authenticated;var e=t.wordpress.settings.frontpage;t.currentPost=t.wordpress.model.collections[e.type][e.id],t.model=t.wordpress.model,t.loading=!1})})},t.prototype.componentDidLoad=function(){},t.prototype.getData=function(){return tslib_1.__awaiter(this,void 0,void 0,function(){var t=this;return tslib_1.__generator(this,function(e){switch(e.label){case 0:return[4,this.wordpress.getPosts().then(function(e){t.posts=e,t.wordpress.saveLocal()})];case 1:return e.sent(),[2]}})})},t.prototype.login=function(t,e){console.log(t,e)},t.prototype.logout=function(){},t.prototype.onMenuClick=function(t){return tslib_1.__awaiter(this,void 0,void 0,function(){var e;return tslib_1.__generator(this,function(n){switch(n.label){case 0:return e=this,[4,this.wordpress.getPost(t.object_id,t.object)];case 1:return e.currentPost=n.sent(),[2]}})})},t.prototype.showLoginModal=function(){this.loginModal.show()},t.prototype.render=function(){var t=this;if(this.model&&this.currentPostId)return h("div",{class:"ema-app-wordpress"},!this.authenticated&&h("button",{class:"btn btn-primary float-right",id:"login-button",onClick:function(){return t.showLoginModal()}},"login"),this.authenticated&&h("button",{class:"btn btn-primary float-right",id:"logout-button",onClick:function(){return t.logout()}},"logout"),h("ema-post",{"data-json":JSON.stringify(this.currentPost)}),h("footer",null,h("nav",{class:"navbar navbar-expand-md fixed-bottom"},h("div",{class:"collapse navbar-collapse",id:"navbarCollapse"},h("ul",{class:"navbar-nav"},this.model.menus[this.wordpress.settings.mainMenu].items.map(function(e){return h("li",null,h("a",{onClick:function(n){return t.onMenuClick(e)},class:"nav-link"},e.title))}))))))},Object.defineProperty(t,"is",{get:function(){return"ema-app-wordpress"},enumerable:!0,configurable:!0}),Object.defineProperty(t,"properties",{get:function(){return{authenticated:{state:!0},currentPost:{state:!0},currentPostId:{state:!0},loading:{state:!0},model:{state:!0}}},enumerable:!0,configurable:!0}),Object.defineProperty(t,"style",{get:function(){return"ema-app-wordpress #login-button,ema-app-wordpress #logout-button{position:fixed;top:.5rem;right:.5rem;z-index:11000}\@media screen and (max-width:767px){ema-app-wordpress #login-button,ema-app-wordpress #logout-button{right:4rem}}ema-app-wordpress ema-post .post{text-align:center;padding:1rem 0}ema-app-wordpress ema-post .post.post-type-iframe{padding:0}ema-app-wordpress ema-post .post.post-type-iframe .field--name-title{display:none}ema-app-wordpress ema-post .post .field{margin-bottom:.5rem}"},enumerable:!0,configurable:!0}),t}(),Post=function(){function t(){}return t.prototype.componentDidLoad=function(){this.postRender()},t.prototype.componentDidUpdate=function(){this.postRender()},t.prototype.postRender=function(){var t=this.el.querySelector(".field--name-title"),e=this.el.querySelector(".field--name-content");this.data.title&&(t.innerHTML=this.data.title.rendered),e.innerHTML=this.data.content?this.data.content.rendered:""},t.prototype.parsePost=function(t){return t},t.prototype.render=function(){if(this.dataJson){var t=this.parsePost(JSON.parse(this.dataJson));this.data=t}return h("article",{class:"post post-type-"+t.type+" clearfix",id:"post-"+t.id},h("header",null,h("h2",{class:"field field--name-title"})),h("div",{class:"content clearfix"},h("div",{class:"field field--name-content"}),"iframe"==t.type&&t.url&&h("div",{class:"field field--name-url"},h("ema-iframe",{src:t.url,width:t.width,height:t.height}))))},Object.defineProperty(t,"is",{get:function(){return"ema-post"},enumerable:!0,configurable:!0}),Object.defineProperty(t,"properties",{get:function(){return{data:{state:!0},dataJson:{type:String,attr:"data-json"},el:{elementRef:!0}}},enumerable:!0,configurable:!0}),Object.defineProperty(t,"style",{get:function(){return"ema-post .node .field{margin-bottom:var(--ema-padding-md,1rem)}"},enumerable:!0,configurable:!0}),t}();export{AppWordpress as EmaAppWordpress,Post as EmaPost};