"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importStar(require("react"));
const react_native_1 = require("react-native");
const ConfigProvider_1 = require("../utils/ConfigProvider");
const components_1 = require("../themes/components");
const OrientationContext_1 = require("../services/OrientationContext");
function LoadingScreen(props) {
    const { text, inStage, showTextAfter, childComponents, errorText, loading } = props;
    const { sessionConfig } = react_1.useContext(ConfigProvider_1.ConfigServiceContext);
    const windowDimensions = react_native_1.useWindowDimensions();
    const { orientation } = react_1.default.useContext(OrientationContext_1.OrientationContext);
    // eslint-disable-next-line prefer-const
    let { height, width } = sessionConfig.theme.dimensions || windowDimensions;
    // Fixed height header and control bars
    height -= inStage && orientation !== 'LANDSCAPE' ? 128 : 0;
    const [showText, setShowText] = react_1.useState(showTextAfter === 0);
    react_1.useEffect(() => {
        let timeout;
        if (showTextAfter) {
            timeout = setTimeout(() => setShowText(true), showTextAfter * 1000);
        }
        return () => clearTimeout(timeout);
    }, []);
    return (react_1.default.createElement(components_1.Box, { height: height, width: width, bg: "secondary.800", justify: "center", align: "center" },
        react_1.default.createElement(components_1.Stack, null,
            !errorText && loading && react_1.default.createElement(components_1.Spinner, null),
            !!showText && (!!errorText || !!text) && (react_1.default.createElement(components_1.Text, { ml: 5, color: "textPrimary.100" }, errorText || text))),
        childComponents && childComponents));
}
LoadingScreen.defaultProps = {
    text: '',
    inStage: false,
    showTextAfter: 0,
    loading: true,
    childComponents: null,
    errorText: null,
};
exports.default = LoadingScreen;
//# sourceMappingURL=LoadingScreen.js.map