import React, { ComponentType, VoidFunctionComponent } from 'react';
import { WixPatternsBMProvider } from './WixPatternsBMProvider';

type ExtractProps<C> = C extends ComponentType<infer P> ? P : never;

export function withWixPatternsProvider<C extends VoidFunctionComponent<any>>(
  WrappedComponent: C,
): C {
  return ((props: ExtractProps<C>) => (
    <WixPatternsBMProvider>
      <WrappedComponent {...props} />
    </WixPatternsBMProvider>
  )) as C;
}
