import React,{Component} from 'react'

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

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

import TextArea from './ZTextArea'


import YBIC from './YBIC'

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

export default class T59F extends Component
{

    name='59F'
    desp = "Beneficiary Customer"
    
    pattern = ""
    tno = -1
    keys = [1,2]
    onChange=(index,value)=>
    {
        if(index == 2)
            this.fisrt_temp = undefined
        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 mval = ''
        if(obj.s1)
             mval = `/${obj.s1}\r\n`
        if(obj.s2 )
             mval = `${mval}${obj.s2}`

        this.props.onValue([obj,mval])
    }
    componentWillMount()
    {
        if(this.props.action == 'edit')
        {
            this.fisrt_temp = '1/(Name of Beneficiary Customer)\r2/(Address Line)\r3/(Country and Town)'
        }
    }
    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 (<div>
        <Row>
                    <Col style={{"minWidth":'100px'}} span={16}>
                        <FormItem
                            label="Account"
                            help={errmsg.s1}
                            validateStatus={errmsg.s1?'error':null}
                        >
                             <Input addonBefore={'/'}  value={value.s1} onChange={e=>this.onChange(1,e.target.value)}   maxLength={34} style={{imeMode:'disabled'}} placeholder="Account"/>
                                   
                        </FormItem>
                    </Col>
        </Row>
        <Row>
            <Col>
            <FormItem
                 label="Number/Name and Address"  
                 required={this.props.status=='M' || mval?'required':null}
                 help={errmsg.s2||'请替换模板为正常内容'}
                 validateStatus={errmsg.s2?'error':'warning'}
                >
                        <TextArea type="textarea"  onChange={e=>this.onChange(2,e.target.value)} value={value.s2||this.fisrt_temp} style={{imeMode:'disabled'}} placeholder="Number/Name and Address" rows={4} cols={35} maxLength={140}/> 
                </FormItem>
            </Col>
        </Row>
        {/*<SubItem value={value.s2} onValue={(val)=>this.onChange(2,val)} />*/}
        </div>)
    }
}

class SubItem extends Component
{

    constructor(props)
    {
        super(props)
        this.state={items:[{val1:""},{val1:""},{val1:""},{val1:""}]}
        this.keys=[1,2,3,4]
    }
    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 mval = `1/${obj.s1}\r\n2/${obj.s2}\r\n3/${obj.s3}\r\n4/${obj.s4}`.replace(/^\d\r\n/,'')
        this.props.onValue([obj,mval])
    }

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

        value = value && value.length?value[0] : {}
        
        return (<div>

            {
            this.state.items.map((item,index)=>{
                return (<Row key={index}>
                        
                        <Col span={24}>
                            <FormItem
                            >  
                                    <Input value={value['s'+index]} onChange={e=>this.onChange(index,e.target.value)} addonBefore={index+1+'/'} type="text" maxLength={33} style={{imeMode:'disabled'}} placeholder="Narrative"/>
                            </FormItem>
                        </Col>
                    </Row>)
                        
                })
            }
        </div>)
    }
    
}