"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get flowConfig () {
        return flowConfig;
    },
    get flowRoot () {
        return flowRoot;
    }
});
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
const _classnames = /*#__PURE__*/ _interop_require_default(require("classnames"));
const _lodashchunk = /*#__PURE__*/ _interop_require_default(require("lodash.chunk"));
const _Flowstyles = require("./Flow.styles");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
function _getRequireWildcardCache(nodeInterop) {
    if (typeof WeakMap !== "function") return null;
    var cacheBabelInterop = new WeakMap();
    var cacheNodeInterop = new WeakMap();
    return (_getRequireWildcardCache = function(nodeInterop) {
        return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
    })(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
    if (!nodeInterop && obj && obj.__esModule) {
        return obj;
    }
    if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
        return {
            default: obj
        };
    }
    var cache = _getRequireWildcardCache(nodeInterop);
    if (cache && cache.has(obj)) {
        return cache.get(obj);
    }
    var newObj = {
        __proto__: null
    };
    var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
    for(var key in obj){
        if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
            var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
            if (desc && (desc.get || desc.set)) {
                Object.defineProperty(newObj, key, desc);
            } else {
                newObj[key] = obj[key];
            }
        }
    }
    newObj.default = obj;
    if (cache) {
        cache.set(obj, newObj);
    }
    return newObj;
}
const flowRoot = (Root)=>/*#__PURE__*/ (0, _react.forwardRef)(({ children, className, style, orientation = 'horizontal', arrangement, alignment, mainAxisGap = '0', crossAxisGap = '0', minColWidth = 'auto', itemsPerLine, ...rest }, ref)=>{
        const isVertical = orientation === 'vertical';
        const hasMinWidth = Boolean(minColWidth && minColWidth !== 'auto');
        const needGrid = Boolean(Number(itemsPerLine) > 0 || hasMinWidth);
        let innerMainAxisGap = typeof mainAxisGap === 'number' || !Number.isNaN(+mainAxisGap) ? `${mainAxisGap || 0}px` : mainAxisGap;
        const innerCrossAxisGap = typeof crossAxisGap === 'number' || !Number.isNaN(+crossAxisGap) ? `${crossAxisGap || 0}px` : crossAxisGap;
        if (arrangement === 'spaceBetween' || arrangement === 'spaceAround') {
            innerMainAxisGap = '0';
        }
        const hasChunks = Number(itemsPerLine) > 0;
        const chunks = hasChunks ? (0, _lodashchunk.default)(_react.default.Children.toArray(children), itemsPerLine) : [];
        const gap = isVertical ? `${innerMainAxisGap} ${innerCrossAxisGap}` : `${innerCrossAxisGap} ${innerMainAxisGap}`;
        const wrapperGap = isVertical ? `0 ${innerCrossAxisGap}` : `${innerCrossAxisGap} 0`;
        const lineGap = isVertical ? `${innerMainAxisGap} 0` : `0 ${innerMainAxisGap}`;
        return /*#__PURE__*/ _react.default.createElement(Root, {
            ref: ref,
            className: (0, _classnames.default)(className, {
                vertical: isVertical,
                grid: hasMinWidth,
                elastic: hasMinWidth,
                hasChunks
            }),
            style: {
                ...style,
                '--plasma-private-gap': hasChunks ? wrapperGap : gap,
                '--plasma-private-items': String(itemsPerLine),
                '--plasma-private-min-width': String(minColWidth)
            },
            "data-arrangement": arrangement,
            "data-alignment": alignment,
            ...rest
        }, hasChunks && chunks.map((chunkNode)=>/*#__PURE__*/ _react.default.createElement(_Flowstyles.Line, {
                className: (0, _classnames.default)({
                    vertical: isVertical,
                    grid: needGrid,
                    elastic: hasMinWidth
                }),
                style: {
                    '--plasma-private-gap': lineGap
                },
                "data-arrangement": arrangement,
                "data-alignment": alignment
            }, chunkNode)), !hasChunks && children);
    });
const flowConfig = {
    name: 'Flow',
    tag: 'div',
    layout: flowRoot,
    base: _Flowstyles.base,
    defaults: {},
    variations: {}
};
