var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import React, { forwardRef } from "react";
import { omit } from "../../utils-external/index.js";
import { Slot } from "../../utils/components/slot/Slot.js";
import { cl } from "../../utils/helpers/index.js";
import BasePrimitive, { PRIMITIVE_PROPS, } from "../base/BasePrimitive.js";
import { getResponsiveProps, getResponsiveValue } from "../utilities/css.js";
/**
 * Horizontal Grid Primitive with dynamic columns and gap based on breakpoints.
 *
 * @see [📝 Documentation](https://aksel.nav.no/komponenter/primitives/hgrid)
 * @see 🏷️ {@link HGridProps}
 *
 * @example
 * <HGrid gap="space-24" columns={3}>
 *   <div />
 *   <div />
 *   <div />
 * </HGrid>
 * @example
 * <HGrid gap={{xs: "space-8", md: "space-24"}} columns={3}>
 *   <div />
 *   <div />
 *   <div />
 * </HGrid>
 * @example
 * <HGrid gap="space-24" columns={{ sm: 1, md: 1, lg: "1fr auto", xl: "1fr auto"}}>
 *   <div />
 *   <div />
 *   <div />
 * </HGrid>
 */
export const HGrid = forwardRef((_a, ref) => {
    var { children, className, as: Component = "div", columns, gap, style, align, asChild } = _a, rest = __rest(_a, ["children", "className", "as", "columns", "gap", "style", "align", "asChild"]);
    const styles = Object.assign(Object.assign(Object.assign(Object.assign({}, style), { "--__axc-hgrid-align": align }), getResponsiveProps(`hgrid`, "gap", "space", gap)), getResponsiveValue(`hgrid`, "columns", formatGrid(columns)));
    const Comp = asChild ? Slot : Component;
    return (React.createElement(BasePrimitive, Object.assign({}, rest),
        React.createElement(Comp, Object.assign({}, omit(rest, PRIMITIVE_PROPS), { ref: ref, className: cl("aksel-hgrid", className, {
                "aksel-hgrid-gap": gap,
                "aksel-hgrid-align": align,
            }), style: styles }), children)));
});
function formatGrid(props) {
    if (!props) {
        return {};
    }
    if (typeof props === "string" || typeof props === "number") {
        return getColumnValue(props);
    }
    return Object.fromEntries(Object.entries(props).map(([breakpointToken, columnValue]) => [
        breakpointToken,
        getColumnValue(columnValue),
    ]));
}
const getColumnValue = (prop) => {
    if (typeof prop === "number") {
        return `repeat(${prop}, minmax(0, 1fr))`;
    }
    return prop;
};
export default HGrid;
//# sourceMappingURL=HGrid.js.map