import React, { Component } from 'react';

import { AbstractForm } from 'lib/components';
import Toast from 'components/Toast';

import form from 'lib/form';
import validator from 'lib/validator';
import { injectIntl } from 'react-intl';


import messages from './messages.js';
import { unitI18n } from "utils/settings";


class CompanySettings extends AbstractForm {


    constructor(props) {
        super(props);
    }

    render() {
        let { intl } = this.props;
        let formProps = {};
        let i18n = unitI18n(this.props.data);

        return (
            <div className={ `form ${this.props.className}` }>
                { this.renderField("name", intl.formatMessage(messages.name), { ...formProps, className: "big" }) }
                <div className="row row-margin-10">
                    <div className="col-xs-6 ph10">
                        { this.renderField("idNumber", intl.formatMessage(messages.idNumber), formProps) }
                    </div>
                    <div className="col-xs-6 ph10">
                        { this.renderField("taxNumber", intl.formatMessage(messages.taxNumber), formProps) }
                    </div>
                </div>
                { this.renderTextArea("address", intl.formatMessage(messages.address), formProps) }


                <div className="pv20 init-settings-jumbotron">
                    
                </div>
                {/*<PaymentAccounts
                    title={ intl.formatMessage(messages.accountsTitle) }
                    description={ intl.formatMessage(messages.accountsMessage) }
                    disabled={ this.props.disabled }
                    className="table small-list"
                    items={ this.props.valueOf('paymentAccounts') }
                    onChange={ this.props.onChangeHandler('paymentAccounts', items => items, (accounts) => { window.cfg.unit.paymentAccounts = accounts }) }
                    sortFunction={ (items) => items.sortBy(p => p.get("name")) }
                    />
                */}

            </div>
        );
    }

}



export default form(injectIntl(CompanySettings), {
    onValidationFailed: Toast.validationFailed,
    validate: (unit, error) => {
        let valid = true;
        if (!validator.required(unit.name)) {
            error({ field: "name", code: messages.nameRequiredError.id });
            valid = false;
        }
        return valid;
    }
});