import React, { PureComponent } from 'react';
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { Form, FormLabelPosition } from './Form';
const S = StyleSheet.create({
    container: {
        flexDirection: 'row',
        alignItems: 'baseline'
    },
    form: {
        flex: 1
    },
    submitButtonStyle: {
        width: 100,
        backgroundColor: '#EEE',
        padding: 10,
        alignItems: 'center',
        justifyContent: 'center',
        height: 38
    }
});
export class SingleLineForm extends PureComponent {
    constructor(props) {
        super(props);
        this.handleSubmit = () => {
            const value = this.form.getValue();
            if (value && this.props.onSubmit) {
                this.props.onSubmit(value);
            }
        };
        this.fieldsStyleConfig = Object.assign({}, props.fieldsStyleConfig);
        this.fieldsTypes = props.fieldsTypes;
        this.fieldsOptions = props.fieldsOptions;
        this.labelPosition = (typeof props.labelPosition === 'number') ?
            props.labelPosition : FormLabelPosition.Inline;
    }
    render() {
        return (this.labelPosition === 0 ?
            (<View>
        <View style={[S.container, this.props.style]}>
          <Form ref={ref => (this.form = ref)} fieldsTypes={this.fieldsTypes} fieldsOptions={this.fieldsOptions} fieldsStyleConfig={this.fieldsStyleConfig} labelPosition={this.labelPosition} value={this.props.value} style={S.form}/>
        </View>
        <TouchableOpacity style={[S.submitButtonStyle, this.props.submitButtonStyle,
                { marginLeft: 10, marginTop: -12 }]} onPress={this.handleSubmit}>
          <Text style={this.props.submitTextStyle}>
            {this.props.submitText || 'Submit'}
          </Text>
        </TouchableOpacity>
      </View>) :
            (<View style={[S.container, this.props.style]}>
        <Form ref={ref => (this.form = ref)} fieldsTypes={this.fieldsTypes} fieldsOptions={this.fieldsOptions} fieldsStyleConfig={this.fieldsStyleConfig} labelPosition={this.labelPosition} value={this.props.value} style={S.form}/>
        <TouchableOpacity style={[S.submitButtonStyle, this.props.submitButtonStyle]} onPress={this.handleSubmit}>
          <Text style={this.props.submitTextStyle}>
            {this.props.submitText || 'Submit'}
          </Text>
        </TouchableOpacity>
      </View>));
    }
}
//# sourceMappingURL=SingleLineForm.js.map