"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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GlHeaderLink = void 0;
var jsx_runtime_1 = require("react/jsx-runtime");
var react_1 = require("react");
var theme_1 = require("../theme");
var symToStr_1 = require("tsafe/symToStr");
var useCallbackFactory_1 = require("powerhooks/useCallbackFactory");
var useDomRect_1 = require("powerhooks/useDomRect");
exports.GlHeaderLink = (0, react_1.memo)(function (props) {
    var href = props.href, label = props.label, className = props.className, onClick = props.onClick;
    var _a = __read((0, react_1.useState)(false), 2), isUnderlined = _a[0], setIsUnderlined = _a[1];
    var _b = __read((0, react_1.useState)(false), 2), isActive = _b[0], setIsActive = _b[1];
    var handleHoverFactory = (0, useCallbackFactory_1.useCallbackFactory)(function (_a) {
        var _b = __read(_a, 1), state = _b[0];
        switch (state) {
            case "enter":
                setIsUnderlined(true);
                return;
            case "leave":
                setIsUnderlined(false);
        }
    });
    var handleClickFactory = (0, useCallbackFactory_1.useCallbackFactory)(function (_a) {
        var _b = __read(_a, 1), state = _b[0];
        switch (state) {
            case "down":
                setIsActive(true);
                return;
            case "up":
                setIsActive(false);
        }
    });
    var _c = (0, useDomRect_1.useDomRect)(), ref = _c.ref, width = _c.domRect.width;
    var _d = useStyles({ isUnderlined: isUnderlined, width: width, isActive: isActive }, { props: props }), classes = _d.classes, cx = _d.cx;
    return ((0, jsx_runtime_1.jsxs)("div", __assign({ ref: ref, className: cx(classes.root, className) }, { children: [(0, jsx_runtime_1.jsx)("a", __assign({ onMouseLeave: handleHoverFactory("leave"), onMouseEnter: handleHoverFactory("enter"), onMouseDown: handleClickFactory("down"), onMouseUp: handleClickFactory("up"), className: classes.link, href: href, onClick: onClick }, { children: label })), (0, jsx_runtime_1.jsx)("div", { className: classes.underline })] })));
});
var useStyles = (0, theme_1.makeStyles)({
    "name": "".concat((0, symToStr_1.symToStr)({ GlHeaderLink: exports.GlHeaderLink })),
})(function (theme, _a) {
    var isUnderlined = _a.isUnderlined, isActive = _a.isActive, width = _a.width;
    return {
        "root": {
            "display": "flex",
            "flexDirection": "column",
            "alignItems": "center",
        },
        "link": __assign(__assign({ "transition": "color 200ms", "color": isActive
                ? theme.colors.useCases.buttons.actionActive
                : theme.colors.useCases.typography.textPrimary, "textDecoration": "none" }, theme.spacing.rightLeft("padding", "".concat(theme.spacing(3), "px"))), { "whiteSpace": "nowrap" }),
        "underline": {
            "width": isUnderlined ? width - theme.spacing(3) : 0,
            "marginTop": theme.spacing(1),
            "height": 1,
            "backgroundColor": isActive
                ? theme.colors.useCases.buttons.actionActive
                : theme.colors.useCases.typography.textPrimary,
            "transition": "width 200ms, background-color 200ms",
        },
    };
});
//# sourceMappingURL=GlHeaderLink.js.map