const t=window.webcomponents.h;import"./chunk-de721f0a.js";import{f as e,k as a}from"./chunk-f9f1602a.js";class i{constructor(){this.config=e.instance,this.loading=!0,this.authenticated=!1}componentWillLoad(){this.drupal=new a,this.init(this.config.get("drupal")[this.drupalHost])}async init(t){let e=document.getElementsByTagName("ema-router")[0];this.currentNid=t.front_page_nid,await e.getState().then(t=>{t.context.params.nid&&(this.currentNid=t.context.params.nid)}),await this.drupal.init(t).then(t=>{this.getData().then(()=>{this.authenticated=this.drupal.authenticated,this.model=this.drupal.model,this.loading=!1,setTimeout(t=>{this.loginModal=document.getElementById("drupal-login-modal"),document.addEventListener("loginShouldOccur",t=>{this.login(t.detail.username,t.detail.password)})},200)})})}async getData(){await this.drupal.jsonApi.getCollection("view--view"),await this.drupal.nodeLoad(this.drupal.options.frontpage_nid),await this.drupal.menuLoad(this.drupal.options.main_menu,!0),this.currentNode=await this.drupal.jsonApi.getNode(this.currentNid)}login(t,e){this.drupal.login(t,e).then(t=>{this.loginModal.hide(),this.authenticated=!0})}logout(){this.drupal.logout().then(()=>{this.authenticated=!1})}async onMenuClick(t){t.link.route_parameters.node&&(this.currentNode=await this.drupal.jsonApi.getNode(t.link.route_parameters.node))}showLoginModal(){this.loginModal.show()}render(){if(this.model&&this.currentNode)return t("div",{class:"ema-app-drupal"},t("ema-drupal-node",{class:"text-center","data-json":JSON.stringify(this.currentNode)}),!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-modal",{id:"drupal-login-modal","modal-title":"Login",width:"80%","allow-close":"true"},t("ema-login-form",{errorMessage:""})),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.drupal.options.main_menu].map(e=>t("li",null,t("a",{onClick:t=>this.onMenuClick(e),class:"nav-link"},e.link.title))))),t("button",{class:"navbar-toggler",type:"button","data-toggle":"collapse","data-target":"#navbarCollapse","aria-controls":"navbarCollapse","aria-expanded":"false","aria-label":"Toggle navigation"},t("span",{class:"navbar-toggler-icon"})))))}static get is(){return"ema-app-drupal"}static get properties(){return{authenticated:{state:!0},configJson:{type:"Any",attr:"config-json"},currentNid:{state:!0},currentNode:{state:!0},drupalHost:{type:String,attr:"drupal-host"},loading:{state:!0},model:{state:!0}}}static get style(){return".ema-app-drupal #login-button,.ema-app-drupal #logout-button{position:fixed;top:.5rem;right:.5rem;z-index:11000}\@media screen and (max-width:767px){.ema-app-drupal #login-button,.ema-app-drupal #logout-button{right:4rem}}.ema-app-drupal ema-node .node{text-align:center;padding:1rem 0}.ema-app-drupal ema-node .node .field{margin-bottom:.5rem}"}}class n{componentDidLoad(){this.postRender()}componentDidUpdate(){this.postRender()}postRender(){this.el.querySelector(".field--name-body").innerHTML=this.data.attributes.body?this.data.attributes.body.value:""}parseNode(t){return t.type.split("--"),t}render(){let e;return this.dataJson&&(e=this.data=this.parseNode(JSON.parse(this.dataJson).data)),t("article",{id:"node-"+e.attributes.nid,class:"node node--type-"+e.type.split("--")[1]+" node--view-mode-full clearfix"},t("header",null,t("h2",{class:"title node__title"},e.attributes.title)),t("div",{class:"node__content clearfix"},t("div",{class:"field field--name-body"}),e.attributes.field_iframe&&t("div",{class:"field field--name-iframe"},t("ema-iframe",{src:e.attributes.field_iframe.uri,width:e.attributes.field_width,height:e.attributes.field_height}))))}static get is(){return"ema-drupal-node"}static get properties(){return{data:{state:!0},dataJson:{type:String,attr:"data-json"},el:{elementRef:!0}}}static get style(){return"ema-drupal-node .node .field{margin-bottom:var(--ema-padding-md,1rem)}"}}export{i as EmaAppDrupal,n as EmaDrupalNode};