import React, { Component } from 'react'
import { connect } from 'react-redux';
import {http, getParam} from '@/utils'
import PythonDes from './pythomDes'
import PythonStudy from './pythonStudy'
import {Toast} from 'antd-mobile'

@connect(state => ({
  user: state.user
}))
class Python extends Component {
  constructor(props) {
    super(props);
    this.state = {
      isPay: 0,
    }
  }

  componentDidMount() {
    this.fetchCourseInfo();
  }

  fetchCourseInfo = () => {
    const id = getParam('id');
    http.get(`${API.home}/m/course/detail/${id}`).then((res) => {
        const {data, code} = res.data;
        if (code === 200) {

            this.setState({
              // TODO
              // isPay: data.course_info.is_pay
              isPay: 1
            })
        }
    });
}

  render() {
    const {isPay} = this.state;
    const {user: {hasError}} = this.props;
    return (
      <div>
        {
          isPay === 0 && <PythonDes ></PythonDes>
        }
        {
          isPay === 1 && <PythonStudy></PythonStudy>
        }
      </div>
    )
  }
}

export default Python
