import classNames from "classnames/dedupe";
import type { ReactElement } from "react";
import { cloneElement } from "react";

export const adornmentWithClassName = (
  component?: ReactElement,
  validationClasses?: string,
  className?: string,
) => {
  if (!component) return null;

  const typedComponent = component as ReactElement<{ className?: string }>;
  return cloneElement(typedComponent, {
    className: classNames(
      typedComponent.props.className,
      validationClasses,
      className,
    ),
  });
};
