"use strict";
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 __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var jsx_runtime_1 = require("react/jsx-runtime");
/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
var icon_1 = require("@cocalc/frontend/components/icon");
var react_1 = require("react");
var mounted_1 = __importDefault(require("lib/hooks/mounted"));
function Loading(_a) {
    var delay = _a.delay, style = _a.style, children = _a.children, before = _a.before, center = _a.center, large = _a.large;
    var _b = __read((0, react_1.useState)(false), 2), show = _b[0], setShow = _b[1];
    var isMounted = (0, mounted_1.default)();
    (0, react_1.useEffect)(function () {
        setTimeout(function () {
            if (!isMounted.current)
                return;
            setShow(true);
        }, delay !== null && delay !== void 0 ? delay : 500);
    }, []);
    if (!show) {
        return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: before });
    }
    return ((0, jsx_runtime_1.jsxs)("div", __assign({ style: __assign({ textAlign: center ? "center" : undefined, fontSize: large ? "32pt" : undefined, color: "#666" }, style) }, { children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { name: "spinner", spin: true }), " ", children !== null && children !== void 0 ? children : (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: "Loading..." })] })));
}
exports.default = Loading;
//# sourceMappingURL=loading.js.map