import React from 'react';
import { useDictionary } from '@sensoro/core';
import { APP_TYPE } from '../../types';
import ApplicationDigest from '../application-digest';

export interface AppBannerProps {
  appType: APP_TYPE;
  statistics: any[];
}

const AppBanner: React.FC<AppBannerProps> = props => {
  const { appType, children, statistics = [] } = props;
  const { getAppByType } = useDictionary();
  const appInfo = getAppByType(appType);

  const renderChildren = () => {
    if (typeof children === 'function') {
      return children(appInfo, statistics);
    } else if (children) {
      return React.Children.map(children, (child: any) =>
        React.cloneElement(child, {
          applicationInfo: appInfo,
          digestData: statistics,
        }),
      );
    } else {
      return (
        <ApplicationDigest applicationInfo={appInfo} digestData={statistics} />
      );
    }
  };
  // const renderChildren = () => {

  //   return React.Children.map(children, (child: any) =>
  //     React.cloneElement(child, {
  //       applicationInfo: appInfo,
  //       digestData: data || [],
  //     }),
  //   );
  // };
  return <div>{renderChildren()}</div>;
};

export default AppBanner;
