const t=window.webcomponents.h;import"./chunk-de721f0a.js";import{f as e,p as s}from"./chunk-f9f1602a.js";class a{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(){document.getElementsByTagName("ema-router")[0].getState().then(t=>{this.currentPostId=t.context.params.pid}),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})})}componentDidLoad(){}async getData(){await this.wordpress.getPosts().then(t=>{this.posts=t,this.wordpress.saveLocal()})}login(t,e){console.log(t,e)}logout(){}async onMenuClick(t){this.currentPost=await this.wordpress.getPost(t.object_id,t.object)}showLoginModal(){this.loginModal.show()}render(){if(this.model&&this.currentPostId)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},currentPostId:{state:!0},loading:{state:!0},model:{state:!0}}}static get style(){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}"}}class i{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),e.innerHTML=this.data.content?this.data.content.rendered:""}parsePost(t){return 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:var(--ema-padding-md,1rem)}"}}export{a as EmaAppWordpress,i as EmaPost};