import { Component, h, Method, Prop, State } from '@stencil/core';
export class AkordFileViewer {
  constructor() {
    this.darkMode = false;
    this.errorRef = h("span", null, "Could not load the file");
    this.printPopup = null;
  }
  componentWillLoad() {
    this.driverName = this.getDriver();
  }
  getDriver() {
    console.log(this.errorRef);
    switch (this.type) {
      case 'pdf':
        return 'akord-pdf-viewer-spa';
      case 'jpg':
      case 'jpeg':
      case 'gif':
      case 'bmp':
      case 'png':
        return 'akord-image-viewer';
      case 'mp4' || 'video/mp4' || 'video/webm' || 'video/ogg':
        return 'akord-video-viewer';
      // case 'mp3':
      //     return 'akord-audio-viewer'
      case 'doc':
        return 'akord-docs-viewer';
      case 'video-stream':
        return 'akord-video-stream-viewer';
      default:
        return null;
    }
  }
  async print() {
    this.printPopup = window.open(this.src, "_new");
    this.printPopup.onbeforeunload = this.closePrint;
    this.printPopup.onafterprint = this.closePrint;
    this.printPopup.focus(); // Required for IE
    this.printPopup.print();
  }
  async download() {
    const link = document.createElement("a");
    link.href = this.src;
    link.download = this.name;
    link.click();
  }
  closePrint() {
    if (this.printPopup) {
      this.printPopup.close();
    }
  }
  render() {
    return (h("div", null,
      this.driverName ?
        h(this.driverName, { width: this.width, height: this.height, src: this.src, zoomControlEnabled: this.zoomControlEnabled, containerClass: this.containerClass, darkMode: this.darkMode })
        : h("div", { innerHTML: this.errorRef.innerHTML }),
      h("div", { style: { display: this.driverName ? 'none' : 'block' } },
        h("slot", { name: "error" }))));
  }
  static get is() { return "akord-file-viewer"; }
  static get originalStyleUrls() { return {
    "$": ["akord-file-viewer.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["akord-file-viewer.css"]
  }; }
  static get properties() { return {
    "name": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "name",
      "reflect": false
    },
    "src": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "src",
      "reflect": false
    },
    "type": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "'jpg' | 'jpeg' | 'gif' | 'bmp' | 'png' | 'pdf' | 'mp4' | 'video/mp4' | 'video/webm' | 'video/ogg' | 'video-stream' | 'mp3' | 'doc'",
        "resolved": "\"bmp\" | \"doc\" | \"gif\" | \"jpeg\" | \"jpg\" | \"mp3\" | \"mp4\" | \"pdf\" | \"png\" | \"video-stream\" | \"video/mp4\" | \"video/ogg\" | \"video/webm\"",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "type",
      "reflect": false
    },
    "zoomControlEnabled": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "zoom-control-enabled",
      "reflect": false
    },
    "width": {
      "type": "number",
      "mutable": false,
      "complexType": {
        "original": "number",
        "resolved": "number",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "width",
      "reflect": false
    },
    "height": {
      "type": "number",
      "mutable": false,
      "complexType": {
        "original": "number",
        "resolved": "number",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "height",
      "reflect": false
    },
    "darkMode": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "dark-mode",
      "reflect": false,
      "defaultValue": "false"
    },
    "errorRef": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "HTMLElement",
        "resolved": "HTMLElement",
        "references": {
          "HTMLElement": {
            "location": "global"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "defaultValue": "<span>Could not load the file</span>"
    },
    "containerClass": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Container class name\n{string}"
      },
      "attribute": "container-class",
      "reflect": false
    }
  }; }
  static get states() { return {
    "driverName": {}
  }; }
  static get methods() { return {
    "print": {
      "complexType": {
        "signature": "() => Promise<void>",
        "parameters": [],
        "references": {
          "Promise": {
            "location": "global"
          }
        },
        "return": "Promise<void>"
      },
      "docs": {
        "text": "",
        "tags": []
      }
    },
    "download": {
      "complexType": {
        "signature": "() => Promise<void>",
        "parameters": [],
        "references": {
          "Promise": {
            "location": "global"
          }
        },
        "return": "Promise<void>"
      },
      "docs": {
        "text": "",
        "tags": []
      }
    }
  }; }
}
