import { ConnectProps, ConnectState } from '@/models/connect';
import { Icon, Tooltip, message } from 'antd';
import Avatar from './AvatarDropdown';
import HeaderSearch from '../HeaderSearch';
import React from 'react';
import SelectLang from '../SelectLang';
import { connect } from 'dva';
import { formatMessage } from 'umi-plugin-react/locale';
import styles from './index.less';
import NoticeIconView from './NoticeIconView';
import DefaultSettings from 'config/defaultSettings';

export type SiderTheme = 'light' | 'dark';
export interface GlobalHeaderRightProps extends ConnectProps {
  theme?: SiderTheme;
  layout: 'sidemenu' | 'topmenu';
}

const goHelpPage = (e: React.MouseEvent) => {
  e.preventDefault();
  message.info('go go  go! help page.');
};

const GlobalHeaderRight: React.SFC<GlobalHeaderRightProps> = props => {
  const { theme, layout } = props;
  let className = styles.right;

  if (theme === 'dark' && layout === 'topmenu') {
    className = `${styles.right}  ${styles.dark}`;
  }

  return (
    <div className={className}>
      <Tooltip
        title={formatMessage({
          id: 'component.globalHeader.help',
        })}
      >
        <a href="#" className={styles.action} onClick={goHelpPage}>
          <Icon type="question-circle-o" />
        </a>
      </Tooltip>
      <NoticeIconView />
      <Avatar menu />
      <SelectLang className={styles.action} locales={DefaultSettings.locales} />
    </div>
  );
};

export default connect(({ settings }: ConnectState) => ({
  theme: settings.navTheme,
  layout: settings.layout,
}))(GlobalHeaderRight);
