/**
 * @license MIT
 * author: Cube Dev Team
 * @cube-dev/ui-kit v0.0.0-canary-68a4774
 * Released under the MIT license.
 */

import { jsx as _jsx } from "react/jsx-runtime";
import React, { isValidElement, memo } from 'react';
import * as flattenModule from 'react-keyed-flatten-children';
import { tasty } from '../../../../tasty/index.js';
import { ButtonGroup } from '../../../actions/index.js';
// Handle CJS/ESM interop - the package exports via `exports.default`
// Vite's __toESM can create nested default: { default: fn } structure
const flatten = (() => {
    const mod = flattenModule;
    if (typeof mod === 'function')
        return mod;
    if (typeof mod.default === 'function')
        return mod.default;
    if (mod.default &&
        typeof mod.default === 'object' &&
        'default' in mod.default &&
        typeof mod.default.default === 'function') {
        return mod.default.default;
    }
    throw new Error('Failed to resolve react-keyed-flatten-children');
})();
const FooterArea = tasty(ButtonGroup, {
    styles: {
        gridArea: 'footer',
        gap: '1x 2x',
        flow: 'row wrap',
        margin: {
            '': '0.5x top',
            'has-description': '1x top',
            ':empty': '0',
        },
    },
});
/**
 * @internal This component is unstable and must not be used outside of `NotificationView`.
 */
export const NotificationFooter = memo(function NotificationFooter(props) {
    const { actions, onClose, onDismiss, hasDescription } = props;
    return (_jsx(FooterArea, { mods: { 'has-description': hasDescription }, children: flatten(typeof actions === 'function'
            ? actions({ onClose, onDismiss })
            : actions)
            .filter((action) => isValidElement(action))
            .map((action, index) => {
            const { props } = action;
            const defaultType = index === 0 ? 'primary' : 'secondary';
            return React.cloneElement(action, {
                ...props,
                type: props.type ?? defaultType,
            }, props.children);
        }) }));
});

        