import { injectNotifier } from '@dvn/alaca/global/notifier';
import { Component, h, Host, Prop } from '@stencil/core';
const copyToClipboard = str => {
  const el = document.createElement('textarea');
  el.value = str;
  document.body.appendChild(el);
  el.select();
  document.execCommand('copy');
  document.body.removeChild(el);
};
export class DvnHighlightedCode {
  constructor() {
    this.leaned = false;
  }
  componentDidLoad() {
    setTimeout(() => {
      // @ts-ignore
      (PR || {}).prettyPrint();
    }, 100);
  }
  render() {
    return (h(Host, { class: {
        leaned: this.leaned,
      } },
      h("pre", { class: "prettyprint" },
        h("slot", null)),
      this.textToCopy &&
        h("div", { class: "controls" },
          h("dvn-icon-button", { iconName: 'uil uil-copy', leaned: true, view: 'flat', tint: 'secondary', onClick: () => {
              copyToClipboard(this.textToCopy);
              this.notifier.congratulate('Copied to clipboard!');
            } }))));
  }
  static get is() { return "dvn-highlighted-code"; }
  static get originalStyleUrls() { return {
    "$": ["dvn-highlighted-code.css"]
  }; }
  static get styleUrls() { return {
    "$": ["dvn-highlighted-code.css"]
  }; }
  static get properties() { return {
    "leaned": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "leaned",
      "reflect": false,
      "defaultValue": "false"
    },
    "textToCopy": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "text-to-copy",
      "reflect": false
    },
    "notifier": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Notifier",
        "resolved": "Notifier",
        "references": {
          "Notifier": {
            "location": "import",
            "path": "@dvn/alaca/global/notifier/models"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
}
injectNotifier(DvnHighlightedCode);
