import React, {Component} from 'react'
import './index.scss';

class HeaderBar extends Component {
    constructor(props) {
        super(props);
    }

    goBack = () => {
        window.history.go(-1);
    }

    toLink = () => {
        const { toHref } = this.props;
        console.log(toHref);
        location.replace(toHref)
    }

    goShop = () => {
        location.replace('/shopcart');
    }

    render() {
        const { toHref } = this.props
        return (
            <div className="detail-header" style={{...this.props.style}}>
                {
                    !toHref && this.props.arrow &&
                    <i className='iconfont iconiconfront-68' onClick={this.goBack}></i>
                }
                {
                    toHref && typeof toHref === 'function' &&
                    <i className='iconfont iconiconfront-68' onClick={toHref}></i>
                }
                {
                    toHref && typeof toHref === 'string' &&
                    <i className='iconfont iconiconfront-68' onClick={this.toLink}></i>
                }
                <span className='herder'>{this.props.title}</span>
                {
                    this.props.cart &&
                    <i className='iconfont icongouwuche-xianxing' onClick={this.goShop}></i>
                }
                {
                    this.props.delete &&
                    <i className='iconfont iconiconfront-56' onClick={this.props.toDelete}></i>
                }
            </div>
        );
    }
};

export default HeaderBar;
