import React from 'react';
import type { UserType } from '../UserInfo/link';
import UserLink from '../UserInfo/link';

export const reloadReactNode = (defaultNode, setOpen, children?: React.ReactNode) => {
  if (!children) {
    return defaultNode;
  }
  if (React.isValidElement(children)) {
    return React.cloneElement(children as React.ReactElement<any>, {
      onClick: () => {
        setOpen(true);
        if (children.props.onClick) {
          children.props.onClick();
        }
      },
    });
  }
  return null;
};

export const formatUserRender = (
  user?: UserType,
  isDisabled?: boolean,
  showDetail: boolean = true,
) => {
  return <UserLink user={user} isDisabled={isDisabled} showDetail={showDetail} bracket={'en'} />;
};
