import React from 'react';
import PropTypes from 'prop-types';
import { NavBar, Icon, } from 'antd-mobile';
import { withRouter } from 'dva/router';

/**
 * 页面顶部返回条
 * @prop {String|ReactNode} title 中间文字内容
 * @prop {String|ReactNode} rightContent 右边文字内容
 * @prop {Function} onLeftClick 左边返回图标点击事件，默认执行返回操作
 */
function NavBarDiy ({ history, title, rightContent, onLeftClick }) {
  return (
    <NavBar
      mode="light"
      icon={<Icon type="left" />}
      onLeftClick={ onLeftClick ? onLeftClick : () => history.goBack()}
      rightContent={rightContent}
    >
      <span>
        {title}
      </span>
    </NavBar>
  );
}

NavBarDiy.propTypes = {
  title: PropTypes.string.isRequired,
  rightContent: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
  onLeftClick: PropTypes.func,
};

export default (withRouter(NavBarDiy));
