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 T38G extends Component {

    name = '38G'
    desp = "First Stub Period, Interpolation Period"

    pattern = "2n1!a/2n1!a"
    tno = -1
    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 = `${obj.s1}${obj.s2}/${obj.s3}${obj.s4}`

        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={3}>
                <FormItem
                    label="Number From"
                    required={this.props.status == 'M' || mval ? 'required' : null}
                    help={errmsg.s1}
                    validateStatus={errmsg.s1 ? 'error' : null}
                >
                    <Input value={value.s1} onChange={e => this.onChange(1, e.target.value)} maxLength={2} style={{ imeMode: 'disabled' }} placeholder="Number From" />
                </FormItem>
            </Col>
            <Col style={{ "minWidth": '200px' }} span={3}>
                <FormItem
                    label="Period From"
                    required={this.props.status == 'M' || mval ? 'required' : null}
                    help={errmsg.s2}
                    validateStatus={errmsg.s2 ? 'error' : null}
                >
                    <Select size={InputSize}
                        placeholder="Period From"
                        allowClear={true}
                        style={{ width: "100%" }} value={value.s2} onChange={val => this.onChange(2, val)} >
                        <Option value="D">D</Option>
                        <Option value="M">M</Option>
                        <Option value="O">O</Option>
                        <Option value="W">W</Option>
                        <Option value="Y">Y</Option>
                    </Select>
                </FormItem>
            </Col>
            <Col style={{ "minWidth": '100px' }} span={3}>
                <FormItem
                    label="Number To"
                    required={this.props.status == 'M' || mval ? 'required' : null}
                    help={errmsg.s3}
                    validateStatus={errmsg.s3 ? 'error' : null}
                >
                    <Input value={value.s3} onChange={e => this.onChange(3, e.target.value)} maxLength={2} style={{ imeMode: 'disabled' }} placeholder="Number To" />
                </FormItem>
            </Col>
            <Col style={{ "minWidth": '200px' }} span={3}>
                <FormItem
                    label="Period To"
                    required={this.props.status == 'M' || mval ? 'required' : null}
                    help={errmsg.s4}
                    validateStatus={errmsg.s4 ? 'error' : null}
                >
                    <Select size={InputSize}
                        placeholder="Period To"
                        allowClear={true}
                        style={{ width: "100%" }} value={value.s4} onChange={val => this.onChange(4, val)} >
                        <Option value="D">D</Option>
                        <Option value="M">M</Option>
                        <Option value="O">O</Option>
                        <Option value="W">W</Option>
                        <Option value="Y">Y</Option>
                    </Select>
                </FormItem>
            </Col>
        </Row>)
    }
}