import React, { Component } from 'react'

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

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

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


export default class T77H extends Component {

    name = '77H'
    desp = "Type, Date, Version of the Agreement"

    pattern = "6a[/8!n][//4!n]"
    tno = -1

    keys = [1, 2, 3]

    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 = `${obj.s1}`

        if(obj.s2)
            mval = mval + `/${obj.s2}`
        if(obj.s3)
            mval = mval + `//${obj.s3}`
     
        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 (
            <div>
                <Row>
                    <Col style={{ "minWidth": '100px' }} span={20}>
                        <Col span={15}>
                            <FormItem
                                help={errmsg.s1}
                                required={this.props.status == 'M' || mval ? 'required' : null}
                                validateStatus={errmsg.s1 ? 'error' : null}
                                label="Type of Agreement"
                            >
                                <Select allowClear={true} value={value.s1} style={{ width: "100%" }} placeholder="Type of Agreement" onChange={(val) => this.onChange(1, val)}>
                                {
mt300_77H.map(item=><Option key={item.code}  value={item.code}>{item.code+'-'+item.name}</Option>)
}
                                </Select>
                            </FormItem>
                        </Col>
                        <Col style={{ "minWidth": '100px' }} span={3}>
                            <FormItem
                                label="Date"
                                help={errmsg.s2}
                                validateStatus={errmsg.s2 ? 'error' : null}
                            >
                                <DatePicker defaultValue="" format="yyyyMMdd" value={value.s2} onChange={(date, dateString) => this.onChange(2, dateString)} />
                            </FormItem>
                        </Col>
                        <Col style={{ "minWidth": '100px' }} span={3}>
                            <FormItem
                                label="Version"
                                help={errmsg.s3}
                                validateStatus={errmsg.s3 ? 'error' : null}
                            >
                                <DatePicker defaultValue="" format="yyyy" value={value.s3} onChange={(date, dateString) => this.onChange(3, dateString)} />
                            </FormItem>
                        </Col>

                    </Col>
                </Row>

            </div>
        )
    }
}