import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { baseURI } from 'CONSTS/urlConsts';
import imgStatic from 'CONSTS/imgStatic';
import Carousel from './../../../3dview/common/Carousel';

const transitionTime = 500;

class Picture extends Component {

  static propTypes = {
    pictureList: PropTypes.object
  };

  static defaultProps = {
    pictureList: {}
  };

  constructor(props) {
    super(props);
    this.state = {
      carouselVisable: false
    };
  }

  componentDidMount() {
    //Carousel组件中会计算容器宽度，然而此容器是通过css3过渡属性将宽度在0.5秒内慢慢放大，故目前等待0.5秒进行展示
    this.timer = setTimeout(() => {
      this.setState({ carouselVisable: true });
    }, transitionTime);
  }

  componentWillUnmount() {
    clearTimeout(this.timer);
  }

  render() {
    const { pictureList } = this.props;
    // let { photosUrl = [] } = pictureList || {};
    let imgs = pictureList.map(e => `${baseURI}${e.substr(0, e.length)}`);
    // let imgs = pictureList;
    return (
      <div className="point-details-picture">
        { imgs.length > 0 && this.state.carouselVisable && <Carousel files={imgs} />}
        { imgs.length === 0 &&
          <div className="points-details-empty">
            <img src={imgStatic.datapane.smilingFace} alt="" />
            <p>暂无图片</p>
          </div>
        }
      </div>
    );
  }
}

export default Picture;
