"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VALID_MIME_TYPES = void 0;
const Holder_1 = require("../../../../../Class/Holder");
const _ids_1 = require("../../../../_ids");
exports.VALID_MIME_TYPES = ['text/plain', 'text/html', 'text/uri-list'];
class AttachText extends Holder_1.Holder {
    constructor(system) {
        super({
            fi: ['component', 'text', 'type'],
            fo: [],
            i: [],
            o: [],
        }, {
            input: {
                component: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_ATTACH_TEXT);
    }
    async f({ component, text, type }, done) {
        if (!exports.VALID_MIME_TYPES.includes(type)) {
            done(undefined, 'invalid mime type');
            return;
        }
        this._component = component;
        this._text = text;
        this._type = type;
        // AD HOC
        setTimeout(() => {
            component.emit('call', { method: 'attachText', data: [type, text] });
        }, 0);
    }
    d() {
        const { api: { window: { setTimeout }, }, } = this.__system;
        if (this._component) {
            setTimeout(() => {
                if (this._component) {
                    this._component.emit('call', {
                        method: 'detachText',
                        data: [this._type, this._text],
                    });
                    this._component = undefined;
                }
            }, 0);
        }
    }
}
exports.default = AttachText;
//# sourceMappingURL=index.js.map