var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import React, { forwardRef, useContext, useRef } from 'react';
import { useEmotion, useStyles } from '../../lib/renderEnvironment/index.js';
import { ZIndex } from '../../internal/ZIndex/index.js';
import { ThemeContext } from '../../lib/theming/ThemeContext.js';
import { CommonWrapper } from '../../internal/CommonWrapper/index.js';
import { getAnimations, getStyles } from './GlobalLoaderView.styles.js';
import { useGlobalLoaderPosition, useGlobalLoaderWidth } from './useParams.js';
export var GlobalLoaderView = forwardRef(function (_a, externalRef) {
    var expectedResponseTime = _a.expectedResponseTime, delayBeforeHide = _a.delayBeforeHide, status = _a.status, disableAnimations = _a.disableAnimations, rest = __rest(_a, ["expectedResponseTime", "delayBeforeHide", "status", "disableAnimations"]);
    var ref = useRef(null);
    var theme = useContext(ThemeContext);
    var cx = useEmotion().cx;
    var styles = useStyles(getStyles);
    var animations = useStyles(getAnimations);
    var _b = useGlobalLoaderWidth(status, ref), width = _b.width, startWidth = _b.startWidth, fullWidth = _b.fullWidth;
    var left = useGlobalLoaderPosition(ref).left;
    var getAnimationClass = function (status) {
        if (!disableAnimations) {
            switch (status) {
                case 'success':
                    return animations.successAnimation(delayBeforeHide, width, left);
                case 'accept':
                    if (startWidth < fullWidth * 0.8) {
                        return animations.acceptAnimation(theme, startWidth, expectedResponseTime, width, left);
                    }
                    return animations.slowAcceptAnimation(theme, startWidth, width, left);
                case 'error':
                    return animations.errorAnimation(theme);
                case 'standard':
                    return animations.standardAnimation(theme, expectedResponseTime);
            }
        }
        if (disableAnimations) {
            switch (status) {
                case 'success':
                    return styles.successWithoutAnimation();
                case 'accept':
                    return animations.acceptWithoutAnimation(startWidth);
                case 'error':
                    return styles.errorWithoutAnimation();
                case 'standard':
                    return styles.standardWithoutAnimation();
            }
        }
    };
    return (React.createElement(CommonWrapper, __assign({}, rest, { "data-status": status, ref: externalRef }),
        React.createElement(ZIndex, { priority: "GlobalLoader", className: styles.outer(theme) },
            React.createElement("div", { ref: ref, className: cx(styles.inner(theme), getAnimationClass(status)) }))));
});
//# sourceMappingURL=GlobalLoaderView.js.map