import type React from "react";

// Use unknown for inputs since we're checking if an unknown value is a React component
// The return types use proper type guards to narrow the type after validation
type ReactComponent = React.FC<unknown> | React.ComponentClass<unknown, unknown>;

/**
 * Checks if a given value is a function component.
 */
export const isFunctionComponent = (component: unknown): component is React.FC<unknown> => {
    return typeof component === "function";
};

/**
 * Checks if a given value is a class component.
 */
export const isClassComponent = (component: unknown): component is React.ComponentClass<unknown, unknown> => {
    return typeof component === "function" && 
           typeof component === "function" && 
           component.prototype !== undefined && 
           component.prototype !== null &&
           (!!component.prototype.isReactComponent || !!component.prototype.render);
};

/**
 * Checks if a given value is a forward ref component.
 */
export const isForwardRefComponent = (component: unknown): component is React.ForwardRefExoticComponent<unknown> => {
    return typeof component === "object" && 
           component !== null && 
           '$$typeof' in component &&
           component.$$typeof !== undefined &&
           component.$$typeof !== null &&
           component.$$typeof.toString() === "Symbol(react.forward_ref)";
};

/**
 * Checks if a given value is a valid React component.
 */
export const isReactComponent = (component: unknown): component is ReactComponent => {
    return isFunctionComponent(component) || isForwardRefComponent(component) || isClassComponent(component);
};
