"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.VALID_MIME_TYPES = void 0;
const Semifunctional_1 = require("../../../../../Class/Semifunctional");
const _ids_1 = require("../../../../_ids");
exports.VALID_MIME_TYPES = ['text/plain', 'text/html', 'text/uri-list'];
class AttachText extends Semifunctional_1.Semifunctional {
    constructor(system) {
        super({
            fi: ['component', 'text', 'type'],
            i: ['done'],
            o: [],
        }, {
            input: {
                component: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_ATTACH_TEXT);
    }
    f({ component, text, type }, done) {
        return __awaiter(this, void 0, void 0, function* () {
            if (!exports.VALID_MIME_TYPES.includes(type)) {
                done(undefined, 'invalid mime type');
                return;
            }
            // AD HOC
            setTimeout(() => {
                component.emit('call', { method: 'attachText', data: [type, text] });
            }, 0);
        });
    }
    onIterDataInputData(name, data) {
        // if (name === 'done')  {
        if (this._input.component.active() && this._input.text.active()) {
            setTimeout(() => {
                this._i.component.emit('call', {
                    method: 'dettachText',
                    data: [this._i.type, this._i.text],
                });
                this._done();
            }, 0);
        }
        this._input.done.pull();
        // }
    }
}
exports.default = AttachText;
//# sourceMappingURL=index.js.map