import React from "react";
import { connect } from "dva";
import styles from "../styles/header_content.less";

class HeaderContent extends React.Component {
  componentDidMount() {
    this.updateTime();
    this.timeInterval = setInterval(this.updateTime, 1000);
    // this.props.dispatch({ type: 'header/fetchWeather' });
  }

  componentWillUnmount() {
    clearInterval(this.timeInterval);
  }

  updateTime = () => {
    const now = new Date();
    const pad = (n) => n.toString().padStart(2, "0");
    const currentTime = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(
      now.getDate()
    )} ${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(
      now.getSeconds()
    )}`;
    this.setState({ currentTime });
  };

  state = {
    currentTime: "",
  };

  render() {
    const { currentTime } = this.state;
    const { weatherData } = this.props;
    return (
      <div className={styles.headerContent}>
        <div className={styles.headerContentTitle}>这是一个大屏</div>
        <div className={styles.headerContentTime}>{currentTime}</div>
      </div>
    );
  }
}

export default connect(() => ({}))(HeaderContent);
