"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = __importStar(require("react"));
var classnames_1 = __importDefault(require("classnames"));
var Spinner_1 = require("../Spinner");
var flexBlock_1 = require("../flexBlock");
var CardImage = /** @class */ (function (_super) {
    __extends(CardImage, _super);
    function CardImage() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.state = {
            loaded: false
        };
        return _this;
    }
    CardImage.prototype.componentWillMount = function () {
        this.loadImage();
    };
    CardImage.prototype.componentDidUpdate = function (prevProps) {
        if (prevProps.url !== this.props.url) {
            this.loadImage();
        }
    };
    CardImage.prototype.loadImage = function () {
        var _this = this;
        var url = this.props.url;
        var loaded = this.state.loaded;
        if (loaded) {
            this.setState({
                loaded: false
            });
        }
        var image = new Image();
        image.addEventListener('load', function () {
            _this.setState({
                loaded: true
            });
        });
        image.src = url;
    };
    CardImage.prototype.renderContent = function () {
        var _a = this.props, url = _a.url, cover = _a.cover;
        var loaded = this.state.loaded;
        if (!loaded) {
            return React.createElement(Spinner_1.Spinner, { size: 24 });
        }
        var className = classnames_1.default('rc-card__image', {
            'rc-card__image--cover': cover
        });
        return React.createElement("img", { src: url, className: className });
    };
    CardImage.prototype.render = function () {
        return (React.createElement(flexBlock_1.FlexBlock, { className: "rc-card__image-placeholder", align: flexBlock_1.FlexBlock.CENTER, justify: flexBlock_1.FlexBlock.CENTER, gutterWidth: 0 }, this.renderContent()));
    };
    return CardImage;
}(React.PureComponent));
exports.CardImage = CardImage;
//# sourceMappingURL=CardImage.js.map