import { Component, h, Prop, Event } from '@stencil/core';
export class UxplPopup {
  componentWillLoad() {
  }
  componentDidLoad() {
    // attach listener for click outside of pop-up
    document.addEventListener('mousedown', (event) => {
      this.childOf(event.target, this.contentId);
      // @ts-ignore
      if (event.target === this.el || event.target === this.el.parentElement || event.target.id === this.contentId || this.childOf(event.target, this.contentId)) {
        // ignore event as inside control
      }
      else {
        if (this.show === true) {
          this.hide.emit();
        }
      }
    });
  }
  childOf(childObject, containerObject) {
    var returnValue = false;
    var currentObject;
    if (typeof containerObject === 'string') {
      containerObject = document.getElementById(containerObject);
    }
    if (typeof childObject === 'string') {
      childObject = document.getElementById(childObject);
    }
    currentObject = childObject.parentNode;
    while (currentObject !== undefined) {
      if (currentObject === document.body) {
        break;
      }
      if (currentObject && containerObject && (currentObject.id == containerObject.id)) {
        returnValue = true;
        break;
      }
      // Move up the hierarchy
      currentObject = currentObject.parentNode;
    }
    return returnValue;
  }
  render() {
    if (this.show) {
      return (h("host", null,
        h("div", { class: "popup-marker-container" },
          h("div", { class: "popup-marker" })),
        h("div", { class: {
            'uxpl-popup': true,
            "above": this.yPosition && this.yPosition.toLowerCase() === 'above',
            "below": this.yPosition && this.yPosition.toLowerCase() === 'below',
            "before": this.xPosition && this.xPosition.toLowerCase() === 'before',
            "after": this.xPosition && this.xPosition.toLowerCase() === 'after'
          }, style: {
            "max-height": this.maxHeight ? this.maxHeight : '300px',
            "height": this.maxHeight ? this.maxHeight : '300px',
            "max-width": this.maxWidth ? this.maxWidth : '300px',
            "width": this.maxWidth ? this.maxWidth : '300px'
          } },
          h("div", { class: "popup-container" },
            h("slot", null)))));
    }
    else {
      return (h("host", null));
    }
  }
  static get is() { return "uxpl-popup"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() { return {
    "$": ["uxpl-popup.css"]
  }; }
  static get styleUrls() { return {
    "$": ["uxpl-popup.css"]
  }; }
  static get properties() { return {
    "label": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "label"
      },
      "attribute": "label",
      "reflect": false
    },
    "show": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "show"
      },
      "attribute": "show",
      "reflect": false
    },
    "maxHeight": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Max height for pop up eg: 300px"
      },
      "attribute": "max-height",
      "reflect": false
    },
    "maxWidth": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Max width for pop up eg: 300px"
      },
      "attribute": "max-width",
      "reflect": false
    },
    "xPosition": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "xPosition (before/after)"
      },
      "attribute": "x-position",
      "reflect": false
    },
    "yPosition": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "yPosition (above/below)"
      },
      "attribute": "y-position",
      "reflect": false
    },
    "contentId": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Id of the slot content"
      },
      "attribute": "content-id",
      "reflect": false
    }
  }; }
  static get events() { return [{
      "method": "hide",
      "name": "hide",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }]; }
  static get elementRef() { return "el"; }
}
