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

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

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