import { Component, h, Method, Prop, State } from '@stencil/core';
export class AkordFileViewer {
  constructor() {
    this.darkMode = false;
    this.printPopup = null;
  }
  componentWillLoad() {
    this.driverName = this.getDriver();
  }
  getDriver() {
    switch (this.type) {
      case 'pdf':
        return 'akord-pdf-viewer-spa';
      case 'image':
        return 'akord-image-viewer';
      case 'video/mp4' || 'video/webm' || 'video/ogg':
        return 'akord-video-viewer';
      case 'audio':
        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", { slot: 'error-component', style: { display: this.driverName ? 'none' : 'block' } })));
  }
  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": "'image' | 'pdf' | 'video/mp4' | 'video/webm' | 'video/ogg' | 'video-stream' | 'audio' | 'doc'",
        "resolved": "\"audio\" | \"doc\" | \"image\" | \"pdf\" | \"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"
    },
    "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": []
      }
    }
  }; }
}
