import React from "react";
import { Spin, type SpinProps } from "antd";

export interface WhenProps extends SpinProps {
  /**
   * 条件
   */
  test: boolean;
  /**
   * 成功内容
   */
  children?: React.ReactNode;
}

export const When = React.forwardRef<HTMLDivElement, WhenProps>(
  ({ test, children, ...props }, ref) => {
    if (test) {
      return <div ref={ref}>{children}</div>;
    }
    return <Spin {...props} />;
  }
);
