"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = require("../../../../../Class/$");
const Holder_1 = require("../../../../../Class/Holder");
const id_1 = require("../../../../../util/id");
const _ids_1 = require("../../../../_ids");
class Animate extends Holder_1.Holder {
    constructor(system) {
        super({
            fi: ['opt', 'keyframes', 'element'],
            fo: ['animation'],
        }, {
            input: {
                element: {
                    ref: true,
                },
                done: {},
            },
            output: {
                animation: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_ANIMATE);
    }
    f({ opt, keyframes, element }, done) {
        var _a;
        const id = (_a = opt.id) !== null && _a !== void 0 ? _a : (0, id_1.randomId)();
        this._id = id;
        this._element = element;
        const _opt = {
            ...opt,
            id,
        };
        element.animate(keyframes, _opt);
        const animation = new (class Node extends _1.$ {
            constructor() {
                super(...arguments);
                this.__ = ['ANI'];
            }
            stop() {
                element.emit('call', {
                    method: 'stopAnimation',
                    data: [id],
                });
            }
            play() {
                element.emit('call', {
                    method: 'playAnimation',
                    data: [id],
                });
            }
            cancel() {
                element.emit('call', {
                    method: 'cancelAnimation',
                    data: [id],
                });
            }
            finish() {
                element.emit('call', {
                    method: 'finishAnimation',
                    data: [id],
                });
            }
            commit() {
                element.emit('call', {
                    method: 'commitAnimation',
                    data: [id],
                });
            }
        })(this.__system);
        done({ animation });
    }
    d() {
        if (this._id) {
            this._element.cancelAnimation(this._id);
            this._id = undefined;
            this._element = undefined;
        }
    }
}
exports.default = Animate;
//# sourceMappingURL=index.js.map