/*! Built with http://stenciljs.com */
const{h:t}=window.webcomponents;import{a as e,h as s}from"./chunk-524d1b07.js";var i=function(t,e,s,i){return new(s||(s=Promise))(function(o,n){function a(t){try{l(i.next(t))}catch(t){n(t)}}function r(t){try{l(i.throw(t))}catch(t){n(t)}}function l(t){t.done?o(t.value):new s(function(e){e(t.value)}).then(a,r)}l((i=i.apply(t,e||[])).next())})};class o{constructor(){this.loading=!0,this.authenticated=!1,this.config=e.instance,this.wordpress=new s,this.loginModal=document.getElementById("login-modal"),document.addEventListener("loginShouldOccur",t=>{this.login(t.detail.username,t.detail.password)})}componentWillLoad(){this.wordpress.init(this.config.get("wordpress")["wordpress-dev-local"]).then(t=>{this.getData().then(()=>{this.authenticated=this.wordpress.authenticated;let t=this.wordpress.settings.frontpage;this.currentPost=this.wordpress.model.collections[t.type][t.id],this.model=this.wordpress.model,this.loading=!1,console.log(this.wordpress)})})}componentDidLoad(){}getData(){return i(this,void 0,void 0,function*(){yield this.wordpress.getPosts().then(t=>{this.posts=t,this.wordpress.saveLocal()})})}login(t,e){console.log(t,e)}logout(){}onMenuClick(t){return i(this,void 0,void 0,function*(){this.currentPost=yield this.wordpress.getPost(t.object_id,t.object)})}showLoginModal(){this.loginModal.show()}render(){if(this.model&&this.match&&this.match.params.pid)return t("div",{class:"ema-app-wordpress"},!this.authenticated&&t("button",{class:"btn btn-primary float-right",id:"login-button",onClick:()=>this.showLoginModal()},"login"),this.authenticated&&t("button",{class:"btn btn-primary float-right",id:"logout-button",onClick:()=>this.logout()},"logout"),t("ema-post",{"data-json":JSON.stringify(this.currentPost)}),t("footer",null,t("nav",{class:"navbar navbar-expand-md fixed-bottom"},t("div",{class:"collapse navbar-collapse",id:"navbarCollapse"},t("ul",{class:"navbar-nav"},this.model.menus[this.wordpress.settings.mainMenu].items.map(e=>t("li",null,t("a",{onClick:t=>this.onMenuClick(e),class:"nav-link"},e.title))))))))}static get is(){return"ema-app-wordpress"}static get properties(){return{authenticated:{state:!0},currentPost:{state:!0},loading:{state:!0},match:{type:"Any",attr:"match"},model:{state:!0}}}static get style(){return"ema-app-wordpress #login-button,ema-app-wordpress #logout-button{position:fixed;top:7.5px;right:7.5px;z-index:11000}\@media screen and (max-width:767px){ema-app-wordpress #login-button,ema-app-wordpress #logout-button{right:60px}}ema-app-wordpress ema-post .post{text-align:center;padding:15px 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:7.5px}"}}class n{componentDidLoad(){this.postRender()}componentDidUpdate(){this.postRender()}postRender(){let t=this.el.querySelector(".field--name-title"),e=this.el.querySelector(".field--name-content");this.data.title&&(t.innerHTML=this.data.title.rendered),this.data.content?e.innerHTML=this.data.content.rendered:e.innerHTML=""}parsePost(t){return console.log(t),t}render(){if(this.dataJson){var e=this.parsePost(JSON.parse(this.dataJson));this.data=e}return t("article",{class:"post post-type-"+e.type+" clearfix",id:"post-"+e.id},t("header",null,t("h2",{class:"field field--name-title"})),t("div",{class:"content clearfix"},t("div",{class:"field field--name-content"}),"iframe"==e.type&&e.url&&t("div",{class:"field field--name-url"},t("ema-iframe",{src:e.url,width:e.width,height:e.height}))))}static get is(){return"ema-post"}static get properties(){return{data:{state:!0},dataJson:{type:String,attr:"data-json"},el:{elementRef:!0}}}static get style(){return"ema-post .node .field{margin-bottom:15px}"}}export{o as EmaAppWordpress,n as EmaPost};