"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.GlCards = void 0;
var jsx_runtime_1 = require("react/jsx-runtime");
/* eslint-disable @typescript-eslint/no-namespace */
var react_1 = require("react");
var theme_1 = require("../theme");
var theme_2 = require("../theme");
var theme_3 = require("../theme");
var react_2 = require("react");
var useStateRef_1 = require("powerhooks/useStateRef");
exports.GlCards = (0, react_1.memo)(function (props) {
    var title = props.title, children = props.children, className = props.className, id = props.id;
    var ref = (0, useStateRef_1.useStateRef)(null);
    var _a = __read((0, react_2.useState)(0), 2), numberOfCards = _a[0], setNumberOfCards = _a[1];
    (0, react_2.useEffect)(function () {
        if (!ref.current) {
            return;
        }
        setNumberOfCards(ref.current.childElementCount);
    }, []);
    var _b = useStyles({ numberOfCards: numberOfCards }, { props: props }), classes = _b.classes, cx = _b.cx;
    return ((0, jsx_runtime_1.jsxs)("section", __assign({ id: id, className: cx(classes.root, className) }, { children: [(0, jsx_runtime_1.jsx)("div", __assign({ className: classes.titleWrapper }, { children: typeof title === "string" ? ((0, jsx_runtime_1.jsx)(theme_1.Text, __assign({ className: classes.title, typo: "page heading" }, { children: title }))) : (title) })), (0, jsx_runtime_1.jsx)("div", __assign({ ref: ref, className: classes.cardsWrapper }, { children: children }))] })));
});
var useStyles = (0, theme_2.makeStyles)({
    "name": { GlCards: exports.GlCards },
})(function (theme, _a) {
    var numberOfCards = _a.numberOfCards;
    return ({
        "root": __assign(__assign({}, theme.spacing.rightLeft("padding", "".concat(theme.paddingRightLeft, "px"))), theme.spacing.topBottom("margin", "".concat(theme.spacing(7), "px"))),
        "titleWrapper": {
            "marginTop": theme.spacing(5),
            "marginBottom": theme.spacing(7),
            "display": "flex",
            "justifyContent": "center",
        },
        "title": {},
        "cardsWrapper": {
            "display": "grid",
            "gridTemplateColumns": (function () {
                if (theme.windowInnerWidth >= theme_3.breakpointsValues.lg) {
                    return "repeat(".concat(numberOfCards > 4 ? 4 : numberOfCards, ", 1fr)");
                }
                if (theme.windowInnerWidth >= theme_3.breakpointsValues.md) {
                    return "repeat(".concat(numberOfCards > 3 ? 2 : numberOfCards, ", 1fr)");
                }
                if (theme.windowInnerWidth >= theme_3.breakpointsValues.sm) {
                    return "repeat(".concat(numberOfCards > 3 ? 2 : 1, ", 1fr)");
                }
                return undefined;
            })(),
        },
    });
});
//# sourceMappingURL=GlCards.js.map