import React,{Component} from 'react';
import axios from 'axios';
import { useState,useEffect } from "react";
import { useParams,Link } from 'react-router-dom';
import { Helmet } from 'react-helmet';

export default class Bank extends Component{
    constructor(props){
        super(props);
         this.state={
            assetsLoaded:false,bank:'',ac_num:'',ifsc:'',ac_name:''
         }
      }

      componentDidMount(){
        axios.get('https://capitalsgrowth.in/Rest/user_details_api/'+localStorage.getItem('userid')).then(res => {
            this.setState({bank:res.bank_name,ac_num:res.acc_no,ifsc:res.ifsc,ac_name:res.acc_holder});
        });
      }

      update_amt(at){
          this.setState({amt:at})
      }

      submitForm(){

        axios.post('https://capitalsgrowth.in/Rest/withdraw_submit_api/'+localStorage.getItem('userid'),{withdrawAmt:this.state.wamt})
        .then((res) => {
            //console.log(res.data);return false;
            alert(res.data.msg);
        }).catch((err) => alert("Couldnot reach to server"));    
    }


    render(){
        return (     
            <div>
            <Helmet>
            <title>MCX Trading</title>
            <link rel="stylesheet" href="/site/css/style.css"/>
            <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/> 
            <script src="/site/js/lib/bootstrap.bundle.min.js"></script>
            <script src="/site/js/plugins/splide/splide.min.js"></script>
            
            </Helmet>
            <div className="appHeader no-border">
                <div className="left">
                    <Link to="/dashboard" className="headerButton goBack">
                        <i className="fa fa-arrow-left"></i> 
                    </Link>
                </div>
                <div className="pageTitle">Withdrawl</div>
                <div className="right"> </div>
            </div>

            <div id="appCapsule">    
                <div className="section pt-1">
                <div className="wallet-card text-center">
                <div className="balance">
                        <input type="number" value={this.state.amt} onChange={(e)=>this.setState({amt:e.target.value})}
                        className="form-control" placeholder='Enter Amount' required />
                        <button type="button" onClick={()=>this.submitForm()} className="btn btn-warning">WITHDRAW</button>
                    
                </div>
                
            </div>
               </div>
                
            </div>
            
            </div>
        )}
}


