/*
 * 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 { Field, goog, BlockSvg, utils } from '@kano/kwc-blockly/blockly.js';
import { throttle } from '../../decorators.js';
import { subscribeTimeout } from '@kano/common/index.js';
import { flash } from './icons.js';
export class FlashField extends Field {
    constructor(text) {
        super(text);
        this.timeoutSub = null;
        this.height_ = 16;
        this.width_ = 16;
        this.size_ = new goog.math.Size(this.width_, this.height_ + 2 * BlockSvg.INLINE_PADDING_Y);
        this.text_ = text || '';
        this.tooltip_ = '';
    }
    static get EDITABLE() { return false; }
    init() {
        if (this.fieldGroup_) {
            // Image has already been initialized once.
            return;
        }
        // Build the DOM.
        this.fieldGroup_ = utils.createSvgElement('g', {}, null);
        const instance = flash.content.cloneNode(true);
        this.path = instance.querySelector('polygon');
        this.path.style.transform = `scale(${this.width_ / 40}, ${this.height_ / 40})`;
        this.path.style.fill = 'yellow';
        this.path.style.opacity = '0.3';
        this.fieldGroup_.appendChild(this.path);
        this.sourceBlock_.getSvgRoot().appendChild(this.fieldGroup_);
    }
    render_() { }
    trigger() {
        if (!this.path) {
            return;
        }
        if (this.timeoutSub) {
            this.timeoutSub.dispose();
            this.timeoutSub = null;
        }
        this.path.style.opacity = '0.3';
        setTimeout(() => {
            this.path.style.opacity = '1';
            this.timeoutSub = subscribeTimeout(() => {
                this.path.style.opacity = '0.3';
            }, 500);
        }, 50);
    }
}
__decorate([
    throttle(50)
], FlashField.prototype, "trigger", null);
//# sourceMappingURL=field.js.map