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;
};
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/* eslint-disable @typescript-eslint/no-namespace */
import { memo } from "react";
import { Text } from "../theme";
import { tss } from "../theme";
import { breakpointsValues } from "../theme";
import { useEffect, useState } from "react";
import { useStateRef } from "powerhooks/useStateRef";
export var GlCards = memo(function (props) {
    var title = props.title, children = props.children, className = props.className, id = props.id;
    var ref = useStateRef(null);
    var _a = __read(useState(0), 2), numberOfCards = _a[0], setNumberOfCards = _a[1];
    useEffect(function () {
        if (!ref.current) {
            return;
        }
        setNumberOfCards(ref.current.childElementCount);
    }, []);
    var _b = useStyles({
        numberOfCards: numberOfCards,
        "classesOverrides": props.classes,
    }), classes = _b.classes, cx = _b.cx;
    return (_jsxs("section", __assign({ id: id, className: cx(classes.root, className) }, { children: [_jsx("div", __assign({ className: classes.titleWrapper }, { children: typeof title === "string" ? (_jsx(Text, __assign({ className: classes.title, typo: "page heading" }, { children: title }))) : (title) })), _jsx("div", __assign({ ref: ref, className: classes.cardsWrapper }, { children: children }))] })));
});
var useStyles = tss
    .withName({ GlCards: GlCards })
    .withParams()
    .create(function (_a) {
    var theme = _a.theme, 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 >= breakpointsValues.lg) {
                    return "repeat(".concat(numberOfCards > 4 ? 4 : numberOfCards, ", 1fr)");
                }
                if (theme.windowInnerWidth >= breakpointsValues.md) {
                    return "repeat(".concat(numberOfCards > 3 ? 2 : numberOfCards, ", 1fr)");
                }
                if (theme.windowInnerWidth >= breakpointsValues.sm) {
                    return "repeat(".concat(numberOfCards > 3 ? 2 : 1, ", 1fr)");
                }
                return undefined;
            })(),
        },
    });
});
//# sourceMappingURL=GlCards.js.map