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);
};
import React, { Children, } from 'react';
import classNames from 'classnames';
import { Tag, } from '@alifd/next';
import { Color, COLORED_GROUP_CLASS_NAME, PROTECTED_TYPE, } from '../const';
import ColoredTag from '../colored-tag';
var TagGroup = Tag.Group;
var defaultAvailableColors = [
    Color.LIGHT_STEEL_BLUE,
    Color.PLUM,
    Color.MISTY_ROSE,
    Color.LIGHT_GOLDENROD_YELLOW,
    Color.PALE_GREEN,
];
export default function ColoredTagGroup(_a) {
    var className = _a.className, style = _a.style, _b = _a.availableColors, availableColors = _b === void 0 ? defaultAvailableColors : _b, children = _a.children;
    return (React.createElement(TagGroup, __assign({}, {
        className: classNames(COLORED_GROUP_CLASS_NAME, className),
        style: style,
    }), Children.map(children, function (elem, i) {
        var hijackedElem = elem;
        try {
            var protectedElemType = elem.type[PROTECTED_TYPE];
            if (protectedElemType === 'Tag') {
                hijackedElem = React.createElement(ColoredTag, __assign({}, elem.props, { type: availableColors[i % 5] }));
            }
        }
        catch (err) {
            // ignore
        }
        return hijackedElem;
    })));
}
