import React,{Component} from 'react'

import { Form, Input, DatePicker,Row, Col,Button,Icon ,Select} from 'antd';

import {InputSize,Currency,FormatAmount} from "./Utils"

const FormItem = Form.Item;
const Option = Select.Option

export default class T32K extends Component
{

    name='32K'
    desp = "Amount Traced"
    
    pattern = ""
    tno = -1

    keys=[1,2,3,4,5]

    onChange=(index,value)=>
    {
        let obj = {};
        if(!value)
            value = ""
        let objtemp =this.props.value
        
        objtemp = objtemp && objtemp.length? objtemp[0] : {}

        objtemp["s"+index] = value;

        this.keys.forEach(i=>{
            obj['s'+i] = objtemp['s'+i]
        });
        let temp = FormatAmount(obj.s5);
        
        let mval = `${obj.s1}${obj.s2}${obj.s3}${obj.s4}${temp}`.replace(/\//g,'')
        this.props.onValue([obj,mval])
    }

    render()
    {
       let value =this.props.value

        let mval = value && value.length? value[1] : ''
        let errmsg = value && value.length==3?value[2]:{}

        value = value && value.length? value[0] : {}
        return (<Row>
            <Col style={{"minWidth":'100px'}} span={4}>
                <FormItem
                    label="Day/Month"
                    required={this.props.status=='M' || mval?'required':null}
                  help={errmsg.s1}
                    validateStatus={errmsg.s1?'error':null}
                >
                           <Select size={InputSize} 
                           placeholder="Day/Month"
                           showSearch
                           allowClear={true}
                            optionFilterProp="children"
                            notFoundContent="Wrong Code"
                            style={{ width: "100%" }} value={value.s1} onChange={val=>this.onChange(1,val)} >
                                <Option value="D">D</Option>
                                <Option value="M">M</Option>
 
                            </Select>
                </FormItem>
            </Col>
            <Col span={4}> 
                <FormItem label="Days/Months"
                       required={this.props.status=='M' || mval?'required':null}
                  help={errmsg.s2}
                    validateStatus={errmsg.s2?'error':null}
                >
                        <Input  maxLength={3} value={value.s2} placeholder="Days/Months" style={{'imeMode':'disabled'}} onChange={e=>this.onChange(2,e.target.value)}/>
                </FormItem>
            </Col>

            <Col style={{"minWidth":'100px'}} span={4}>
                <FormItem
                    label="Code"
                    required={this.props.status=='M' || mval?'required':null}
                  help={errmsg.s3}
                    validateStatus={errmsg.s3?'error':null}
                >
                           <Select size={InputSize} 
                           placeholder="Code"
                           showSearch  allowClear={true}
                            optionFilterProp="children"
                            notFoundContent="Wrong Code"
                            style={{ width: "100%" }} value={value.s3} onChange={val=>this.onChange(3,val)} >
                                <Option value="BE">BE</Option>
                                <Option value="CC">CC</Option>
                                <Option value="FD">FD</Option>
                                <Option value="FP">FP</Option>
                                <Option value="GA">GA</Option>
                                <Option value="ID">ID</Option>
                                <Option value="ST">ST</Option>
                                <Option value="TD">TD</Option>
                                <Option value="XX">XX</Option>
                            </Select>
                </FormItem>
            </Col>
            
            <Col style={{"minWidth":'100px'}} span={4}>
                <FormItem
                    label="Currency"
                    required={this.props.status=='M' || mval?'required':null}
                  help={errmsg.s4}
                    validateStatus={errmsg.s4?'error':null}
                >
                           <Select size={InputSize} 
                           placeholder="Currency"
                           showSearch  allowClear={true}
                            optionFilterProp="children"
                            notFoundContent="Wrong Code"
                            style={{ width: "100%" }} value={value.s4} onChange={val=>this.onChange(4,val)} >
                                {
                                   Currency.map(cur=><Option key={cur} value={cur}>{cur}</Option>) 
                                }
                            </Select>
                </FormItem>
            </Col>
            <Col span={8}>
                <FormItem
                 label="Amount"  
                        required={this.props.status=='M' || mval?'required':null}
                  help={errmsg.s5}
                    validateStatus={errmsg.s5?'error':null}
                >
                        
                        <Input  value={value.s5} onChange={e=>this.onChange(5,e.target.value)}  maxLength={16} style={{imeMode:'disabled'}} placeholder="Amount"/>
                </FormItem>
            </Col>
        </Row>)
    }
}