"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 });
exports.GlLinkToTop = void 0;
var jsx_runtime_1 = require("react/jsx-runtime");
var react_1 = require("react");
var ArrowUpward_1 = __importDefault(require("@mui/icons-material/ArrowUpward"));
var theme_1 = require("../theme");
var GlTemplate_1 = require("../GlTemplate");
var useConstCallback_1 = require("powerhooks/useConstCallback");
var evt_1 = require("evt");
exports.GlLinkToTop = react_1.memo(function () {
    var _a = __read(react_1.useState(false), 2), isShown = _a[0], setIsShown = _a[1];
    var onClick = useConstCallback_1.useConstCallback(function () {
        var scrollableElement = document.getElementById(GlTemplate_1.scrollableDivId);
        if (scrollableElement === null) {
            return;
        }
        scrollableElement.scrollTo({
            "top": 0,
            "behavior": "smooth",
        });
    });
    react_1.useEffect(function () {
        var scrollableElement = document.getElementById(GlTemplate_1.scrollableDivId);
        if (scrollableElement === null) {
            return;
        }
        var ctx = evt_1.Evt.newCtx();
        evt_1.Evt.from(ctx, scrollableElement, "scroll").attach(function () {
            if (scrollableElement.scrollTop / (window.innerHeight / 100) >=
                70) {
                setIsShown(true);
                return;
            }
            setIsShown(false);
        });
    }, []);
    var classes = useStyles({ isShown: isShown }).classes;
    return (jsx_runtime_1.jsx("div", __assign({ onClick: onClick, className: classes.root }, { children: jsx_runtime_1.jsx(ArrowUpward_1.default, {}, void 0) }), void 0));
});
var useStyles = theme_1.makeStyles()(function (theme, _a) {
    var isShown = _a.isShown;
    return ({
        "root": {
            "transition": "opacity, 500ms",
            "display": "flex",
            "backgroundColor": theme.colors.useCases.surfaces.background,
            "alignItems": "center",
            "borderRadius": 5,
            "justifyContent": "center",
            "padding": theme.spacing(1),
            "opacity": isShown ? 0.6 : 0,
            "pointerEvents": isShown ? undefined : "none",
            "position": "fixed",
            "border": "solid " + theme.colors.useCases.typography.textPrimary + " 3px",
            "zIndex": 9000,
            "top": "90%",
            "right": theme.paddingRightLeft,
            "cursor": "pointer",
        },
    });
});
//# sourceMappingURL=GlLinkToTop.js.map