/*
 * Copyright (C) 2016-2020 Kano Computing Ltd.
 * License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
 */
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import 'prismjs/prism.js';
import { LitElement, customElement, property, css, html, query } from 'lit-element';
import { prismTheme } from './kano-prism-theme.js';
const CODE_DISPLAY_LINE_HEIGHT = 20;
let KanoCodeDisplay = class KanoCodeDisplay extends LitElement {
    constructor() {
        super(...arguments);
        this.code = '';
        this.lang = 'javascript';
        this.lines = 0;
    }
    static get styles() {
        return [prismTheme, css `
            :host {
                box-sizing: border-box;
                padding: 8px 8px 0 0;
                display: flex;
                flex-direction: row;
            }
            :host pre {
                width: 100%;
                color: #fff;
                white-space: pre-wrap;
                padding: 0;
                margin: 0 0 0 10px;
                font-size: 14px;
                line-height: 20px;
                counter-reset: line;
            }
            :host .line-number-container {
                color: #fff;
                opacity: 0.1;
                margin-right: 8px;
                display: flex;
                flex-direction: column;
            }
            :host .line-number {
                height: 20px;
                counter-increment: line;
            }
            :host .line-number:before {
                line-height: 20px;
                font-family: var(--font-body);
                font-size: 14px;
                font-weight: bold;
                content: counter(line);
            }
        `];
    }
    render() {
        return html `
            <div class="line-number-container">
                ${this.getLines()}
            </div>
            <pre id="output"></pre>
        `;
    }
    getLines() {
        const l = [];
        for (let i = 0; i < this.lines; i += 1) {
            l.push(html `<span class="line-number"></span>`);
        }
        return l;
    }
    updated(changes) {
        if (changes.has('code')) {
            this._render();
        }
    }
    _render() {
        if (!this.outputEl || !this.code) {
            return;
        }
        this.outputEl.style.height = '0';
        this.outputEl.innerHTML = window.Prism.highlight(this.code, window.Prism.languages[this.lang]);
        this._computeLineNumbers();
    }
    _computeLineNumbers() {
        if (!this.outputEl) {
            return;
        }
        let codeSpaceHeight = this.outputEl.scrollHeight;
        this.lines = Math.round(codeSpaceHeight / CODE_DISPLAY_LINE_HEIGHT);
    }
};
__decorate([
    property({ type: String })
], KanoCodeDisplay.prototype, "code", void 0);
__decorate([
    property({ type: String })
], KanoCodeDisplay.prototype, "lang", void 0);
__decorate([
    property({ type: Number })
], KanoCodeDisplay.prototype, "lines", void 0);
__decorate([
    query('#output')
], KanoCodeDisplay.prototype, "outputEl", void 0);
KanoCodeDisplay = __decorate([
    customElement('kano-code-display')
], KanoCodeDisplay);
export { KanoCodeDisplay };
//# sourceMappingURL=kano-code-display.js.map