"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Primitive_1 = require("../../../../../Primitive");
const _ids_1 = require("../../../../_ids");
class _Notification extends Primitive_1.Primitive {
    constructor(system) {
        super({
            i: [],
            o: [],
        }, {}, system, _ids_1.ID_NOTIFICATION);
        this._notification = null;
        this._setup();
    }
    onDataInputData(name) {
        if (this.hasErr()) {
            this.takeErr();
        }
    }
    _setup() {
        if ('Notification' in window) {
            const { permission } = Notification;
            if (permission === 'default') {
                Notification.requestPermission().then((_permission) => {
                    this.err('not authorized');
                });
            }
            else {
                this.err('not authorized');
            }
        }
        else {
            this.err('not authorized');
        }
    }
    $show({ title, opt }, callback) {
        this._notification = new Notification(title, opt);
        this._notification.onclick = () => {
            this.emit('click');
        };
        this._notification.onclose = () => {
            this.emit('close');
        };
        this._notification.onerror = () => {
            this.emit('error');
        };
        this._notification.onshow = () => {
            this.emit('show');
        };
        callback();
    }
    $close({}, callback) {
        if (this._notification) {
            this._notification.close();
        }
        callback();
    }
}
exports.default = _Notification;
//# sourceMappingURL=index.js.map