import React, { ComponentType } from 'react';
import { PreviewPanel, PreviewPanelProps } from './PreviewPanel';

export interface PreviewPanelHOCProps {
  ResourceComponent?: ComponentType<any>;
}

export const PreviewPanelHOC = (
  ResourceComponent: ComponentType<any>,
): React.FC<PreviewPanelHOCProps & PreviewPanelProps> => {
  const NewComponent: React.FC<PreviewPanelHOCProps & PreviewPanelProps> = (props) => {
    // Render OriginalComponent and pass on its props.
    return <PreviewPanel {...props} ResourceComponent={ResourceComponent} />;
  };

  return NewComponent;
};
