/*! Built with http://stenciljs.com */
const{h:t}=window.webcomponents;import{d as e}from"./chunk-d01c0689.js";import"./chunk-4bbd7b7f.js";var a=function(t,e,a,i){return new(a||(a=Promise))(function(n,o){function s(t){try{d(i.next(t))}catch(t){o(t)}}function l(t){try{d(i.throw(t))}catch(t){o(t)}}function d(t){t.done?n(t.value):new a(function(e){e(t.value)}).then(s,l)}d((i=i.apply(t,e||[])).next())})};class i{constructor(){this.loading=!0,this.authenticated=!1}componentDidLoad(){this.drupal=new e,this.init(JSON.parse(this.configJson))}init(t){this.drupal.init(t).then(t=>{this.getData().then(()=>{this.authenticated=this.drupal.authenticated,this.model=this.drupal.model,this.loading=!1,console.log(this.model),setTimeout(t=>{this.loginModal=document.getElementById("drupal-login-modal"),document.addEventListener("loginShouldOccur",t=>{this.login(t.detail.username,t.detail.password)})},200)})})}getData(){return a(this,void 0,void 0,function*(){yield this.drupal.jsonApi.getCollection("view--view"),yield this.drupal.nodeLoad(this.drupal.options.frontpage_nid),yield this.drupal.menuLoad(this.drupal.options.main_menu,!0),this.currentNode=yield this.drupal.jsonApi.getNode(this.drupal.options.frontpage_nid)})}login(t,e){this.drupal.login(t,e).then(t=>{this.loginModal.hide(),this.authenticated=!0})}logout(){this.drupal.logout().then(()=>{this.authenticated=!1})}onMenuClick(t){return a(this,void 0,void 0,function*(){t.link.route_parameters.node&&(this.currentNode=yield this.drupal.jsonApi.getNode(t.link.route_parameters.node))})}showLoginModal(){this.loginModal.show()}render(){if(console.log(this.match),this.model&&this.match)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"},currentNode:{state:!0},loading:{state:!0},match:{type:"Any",attr:"match"},model:{state:!0}}}static get style(){return".ema-app-drupal #login-button,.ema-app-drupal #logout-button{position:fixed;top:7.5px;right:7.5px;z-index:11000}\@media screen and (max-width:767px){.ema-app-drupal #login-button,.ema-app-drupal #logout-button{right:60px}}.ema-app-drupal ema-node .node{text-align:center;padding:15px 0}.ema-app-drupal ema-node .node .field{margin-bottom:7.5px}"}}class n{componentDidLoad(){this.postRender()}componentDidUpdate(){this.postRender()}postRender(){let t=this.el.querySelector(".field--name-body");this.data.attributes.body?t.innerHTML=this.data.attributes.body.value:t.innerHTML=""}parseNode(t){return t.type.split("--")[1],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:15px}"}}export{i as EmaAppDrupal,n as EmaDrupalNode};