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 __());
};
define(["require", "exports", 'react', '../../Fabric'], function (require, exports, React, Fabric_1) {
    "use strict";
    var LayerHost = (function (_super) {
        __extends(LayerHost, _super);
        function LayerHost(props) {
            _super.call(this, props);
            this._layers = [];
            this.state = {
                layers: this._layers
            };
        }
        LayerHost.prototype.render = function () {
            var layers = this.state.layers.map(function (layer, index) {
                return (React.createElement("div", {className: 'ms-LayerHost-layer', key: layer.id}, layer.children));
            });
            return (React.createElement(Fabric_1.Fabric, {className: 'ms-LayerHost'}, layers));
        };
        LayerHost.prototype.addLayer = function (layerToAdd, onComplete) {
            this._layers.push(layerToAdd);
            this.setState({
                layers: this._layers
            }, function () {
                if (onComplete) {
                    onComplete();
                }
            });
        };
        LayerHost.prototype.updateLayer = function (layerToUpdate) {
            this.forceUpdate();
        };
        LayerHost.prototype.removeLayer = function (layerToRemove) {
            var index = this._layers.indexOf(layerToRemove);
            if (index > -1) {
                this._layers.splice(index, 1);
                this.forceUpdate();
            }
        };
        return LayerHost;
    }(React.Component));
    exports.LayerHost = LayerHost;
});
