import {CardRenderer} from "./CardRenderers";
import {cloneElement, ReactElement} from "react";

export const iconWithClassName = (callable: (...params: Parameters<CardRenderer['icon']>) => ReactElement) => (...params: Parameters<CardRenderer['icon']>): ReactElement => {
    const element = callable(...params)

    const {className} = params[0]

    if (element.props && element.props.className) {
        return cloneElement(element, {
            className: `${element.props.className} ${className}`.trim()
        });
    }

    return cloneElement(element, {
        className: className
    });
}