import type { ReactNode, ComponentType, MemoExoticComponent, ComponentProps, FC } from '@/imports';
import { memo as reactMemo } from '@/imports';

interface MemoizedProps<T extends ComponentType<any>> {
  component: T;
  arePropsEqual?: (prevProps: Readonly<ComponentProps<T>>, nextProps: Readonly<ComponentProps<T>>) => boolean;
}

export function memo<T extends ComponentType<any>>({ 
  component: Component, 
  arePropsEqual 
}: MemoizedProps<T>): MemoExoticComponent<T> {
  return reactMemo(Component, arePropsEqual);
}

export function memoWithPropsCompare<T extends ComponentType<any>>(
  component: T,
  propsToCompare: string[]
): MemoExoticComponent<T> {
  return reactMemo(
    component,
    (prevProps, nextProps) => {
      return propsToCompare.every(prop => 
        prevProps[prop as keyof ComponentProps<T>] === 
        nextProps[prop as keyof ComponentProps<T>]
      );
    }
  );
}

export default memo;
