import { ArrowLeftOutlined } from "@ant-design/icons";
import { Divider } from "antd";
import "./index.less";

/**
 * 头部返回组件
 */
function HeaderBack(props) {
  const { title, history, previous = true } = props;

  return (
    <div className="header-back">
      <div className="action">
        {
          previous
          && (
            <>
              <div
                className="back"
                onClick={() => {
                  history?.goBack ? history.goBack() : window.history.back();
                }}
              >
                <ArrowLeftOutlined style={{ fontSize: 14 }} />
                <span>返回</span>
              </div>
              <Divider type="vertical" style={{ backgroundColor: "#dcdfe6", marginLeft: 15, marginRight: 15 }} />
            </>
          )
        }
        <div className="title">{title}</div>
      </div>
    </div>
  );
}

HeaderBack.displayName = "HeaderBack";

export default HeaderBack;
