"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var Utilities_1 = require("../../Utilities");
var ShimmerElementsGroup_1 = require("./ShimmerElementsGroup/ShimmerElementsGroup");
var TRANSITION_ANIMATION_INTERVAL = 200; /* ms */
var getClassNames = Utilities_1.classNamesFunction();
var ShimmerBase = /** @class */ (function (_super) {
    tslib_1.__extends(ShimmerBase, _super);
    function ShimmerBase(props) {
        var _this = _super.call(this, props) || this;
        _this.state = {
            contentLoaded: props.isDataLoaded
        };
        return _this;
    }
    ShimmerBase.prototype.componentWillReceiveProps = function (nextProps) {
        var _this = this;
        var isDataLoaded = nextProps.isDataLoaded;
        if (this._lastTimeoutId !== undefined) {
            this._async.clearTimeout(this._lastTimeoutId);
            this._lastTimeoutId = undefined;
        }
        if (isDataLoaded) {
            this._lastTimeoutId = this._async.setTimeout(function () {
                _this.setState({
                    contentLoaded: isDataLoaded
                });
                _this._lastTimeoutId = undefined;
            }, TRANSITION_ANIMATION_INTERVAL);
        }
        else {
            this.setState({
                contentLoaded: isDataLoaded
            });
        }
    };
    ShimmerBase.prototype.render = function () {
        var _a = this.props, styles = _a.styles, shimmerElements = _a.shimmerElements, children = _a.children, isDataLoaded = _a.isDataLoaded, width = _a.width, className = _a.className, customElementsGroup = _a.customElementsGroup, theme = _a.theme, ariaLabel = _a.ariaLabel;
        var contentLoaded = this.state.contentLoaded;
        this._classNames = getClassNames(styles, {
            theme: theme,
            isDataLoaded: isDataLoaded,
            className: className,
            transitionAnimationInterval: TRANSITION_ANIMATION_INTERVAL
        });
        var divProps = Utilities_1.getNativeProps(this.props, Utilities_1.divProperties);
        return (React.createElement("div", tslib_1.__assign({}, divProps, { className: this._classNames.root }),
            !contentLoaded && (React.createElement("div", { style: { width: width ? width : '100%' }, className: this._classNames.shimmerWrapper }, customElementsGroup ? customElementsGroup : React.createElement(ShimmerElementsGroup_1.ShimmerElementsGroup, { shimmerElements: shimmerElements }))),
            children && React.createElement("div", { className: this._classNames.dataWrapper }, children),
            ariaLabel &&
                !isDataLoaded && (React.createElement("div", { role: "status", "aria-live": "polite" },
                React.createElement(Utilities_1.DelayedRender, null,
                    React.createElement("div", { className: this._classNames.screenReaderText }, ariaLabel))))));
    };
    ShimmerBase.defaultProps = {
        isDataLoaded: false
    };
    ShimmerBase = tslib_1.__decorate([
        Utilities_1.customizable('Shimmer', ['theme'])
    ], ShimmerBase);
    return ShimmerBase;
}(Utilities_1.BaseComponent));
exports.ShimmerBase = ShimmerBase;
//# sourceMappingURL=Shimmer.base.js.map