// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var manager_base_1 = require('./manager-base');
var EmbedManager = (function (_super) {
    __extends(EmbedManager, _super);
    function EmbedManager() {
        _super.apply(this, arguments);
    }
    EmbedManager.prototype.display_widget_state = function (models, el) {
        return this.set_state(models, { el: el, displayOnce: true });
    };
    EmbedManager.prototype.display_view = function (msg, view, options) {
        return Promise.resolve(view).then(function (view) {
            options.el.appendChild(view.el);
            view.trigger('displayed');
            view.on('remove', function () {
                console.log('View removed', view);
            });
            return view;
        });
    };
    ;
    EmbedManager.prototype._get_comm_info = function () {
        return Promise.resolve({});
    };
    ;
    EmbedManager.prototype._create_comm = function () {
        return Promise.resolve({});
    };
    ;
    EmbedManager.prototype.require_error = function (success_callback) {
        /**
         * Takes a requirejs success handler and returns a requirejs error handler
         * that attempts loading the module from npmcdn.
         */
        return function (err) {
            var failedId = err.requireModules && err.requireModules[0];
            if (failedId) {
                // TODO: Get typing to work for requirejs
                window.require(['https://npmcdn.com/' + failedId + '/dist/index.js'], success_callback);
            }
            else {
                throw err;
            }
        };
    };
    return EmbedManager;
}(manager_base_1.ManagerBase));
exports.EmbedManager = EmbedManager;
;
