"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var electron_1 = require("electron");
Polymer({
    is: 'lint-panel',
    properties: {
        messages: {
            type: Array,
            observer: '_messagesUpdated',
        },
        lint_url: String,
        voice_src: {
            type: String,
            value: '',
        },
        enable_inset: {
            type: Boolean,
            value: false,
        },
        already_previewed: {
            type: Boolean,
            value: false,
        },
        sanitize_error: Object,
    },
    attached: function () {
        var _this = this;
        if (this.enable_inset && process.platform === 'darwin') {
            var header = document.getElementById('lint-header');
            header.style.textAlign = 'center';
        }
        electron_1.ipcRenderer.on('shiba:return-lint-rule-url', function (_, url) {
            _this.lint_url = url;
        });
        electron_1.ipcRenderer.send('shiba:request-lint-rule-url');
    },
    showLintResult: function () {
        this.already_previewed = true;
        if (!this.messages) {
            return;
        }
        var content = document.querySelector('.lint-content');
        while (content.firstChild) {
            content.removeChild(content.firstChild);
        }
        if (this.sanitize_error) {
            this.messages.unshift(this.sanitize_error);
        }
        for (var _i = 0, _a = this.messages; _i < _a.length; _i++) {
            var m = _a[_i];
            var msg = document.createElement('lint-message');
            msg.header = m.header;
            msg.body = m.body;
            content.appendChild(msg);
        }
        var header = document.getElementById('lint-header');
        if (this.messages.length > 0) {
            header.innerText = 'Error';
            header.setAttribute('error', '');
            if (this.voice_src !== '') {
                var voice = document.querySelector('.voice-notification');
                if (voice) {
                    voice.play().catch(function (err) {
                        console.error('Failed to play voice:', err);
                    });
                }
            }
        }
        else {
            header.innerText = 'No Error';
            header.setAttribute('no_error', '');
        }
    },
    _messagesUpdated: function (_) {
        if (this.messages && this.already_previewed) {
            this.showLintResult();
        }
    },
    _showLintRules: function () {
        if (this.lint_url === undefined) {
            console.log('No lint URL');
            return;
        }
        electron_1.shell.openExternal(this.lint_url);
    },
});
//# sourceMappingURL=lint-panel.js.map