import React, { Component } from 'react'
import {Input,Button,Card,message} from 'antd';
import './index.css'
import  request from '../../../utils/request'
const { TextArea } = Input;

export default class ProteinView extends Component {
  state={
    sequence:'',
    loading:false,
    listData:{}
  }
  onChange=(e)=>{
    const { value } = e.target;
    console.log(value);
       this.setState({sequence:value})
  }
  getList(){
    this.setState({loading:true})
    request.post('/tool/calc-protein-property',{sequence:this.state.sequence})
    .then(res => {
      console.log(res)
      this.setState({loading:false})
      if (res.data.code===0) {
          this.setState({listData:res.data.data })
      
      }else{
        
        message.error(res.data.msg);
      }
    })
    .catch(err => {
      this.setState({loading:false})
      console.error(err); 
     
    })

  }
  render() {
    const{listData,loading}=this.state
  
   const ProteinViewList = 
   <Card  loading={loading} hoverable style={{ width: '100%',  marginBottom: '20px' }}  >
      {
          Object.entries(listData).map( (item,index)=> {
            return(
             
              <div className='list-div-one'>
                  <div className='list-div-right' >
                      <div className='right-center' >
                        <span>{item[0]}：</span>
                      {
                           <p key={index}>
                            {item[1]}
                           </p>
                        }
                      </div>
                  </div>
                  <div>
                  </div>
          
              </div>
             
            )
          } )
      }
     </Card>

    return (
      <div className='ProteinView-div'>
        <div className='title-div' >
        Please input your sequence：  
        </div>
        <div className='center-div'>
        <TextArea
          onChange={this.onChange}
          placeholder=" Please input your sequence"
          style={{height:'200px'}}
         
        />
        </div>
        <div className='btn-div'>
        <Button type="primary" onClick={()=>this.getList()} disabled={this.state.loading}>Submit</Button>
        </div>
        {
         Object.entries(listData).length>0&& (ProteinViewList)
        }
      </div>
    )
  }
}
