"use strict";
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
            t[p[i]] = s[p[i]];
    return t;
};
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/* @flow */
const React = __importStar(require("react"));
{
    PhoneNumberFieldProps;
}
from;
'./types';
// import cx from 'classnames';
const prop_types_1 = __importDefault(require("prop-types"));
const withStyles_1 = __importDefault(require("components/hoc/withStyles"));
const ErrorBoundary_1 = __importDefault(require("components/hoc/ErrorBoundary"));
const TextField_1 = __importDefault(require("components/bosons/TextField"));
const styles_1 = __importDefault(require("./styles"));
class PhoneNumberField extends React.Component {
    constructor(props) {
        super(props);
        this._onAreaCodeChange = (text) => {
            this.setState({ areaCodeValue: text });
            if (this.props.onChangeText) {
                this.props.onChangeText({
                    areaCode: text,
                    phoneNumber: this.state.phoneNumberValue,
                });
            }
        };
        this._onPhoneNumberChange = (text) => {
            this.setState({ phoneNumberValue: text });
            if (this.props.onChangeText) {
                this.props.onChangeText({
                    phoneNumber: text,
                    areaCode: this.state.areaCodeValue,
                });
            }
        };
        this.state = {
            areaCodeValue: props.areaCodeValue || '',
            phoneNumberValue: props.phoneNumberValue || '',
        };
    }
    componentDidUpdate(prevProps) {
        const props = this.props;
        if (props.areaCodeValue !== prevProps.areaCodeValue) {
            this.setState({
                areaCodeValue: props.areaCodeValue,
            });
        }
        if (props.phoneNumberValue !== prevProps.phoneNumberValue) {
            this.setState({
                phoneNumberValue: props.phoneNumberValue,
            });
        }
    }
    render() {
        const _a = this.props, { classes, areaCodeValue, // eslint-disable-line
        phoneNumberValue, // eslint-disable-line
        areaCodeLabel, areaCodePlaceholder, phoneNumberPlaceholder, phoneNumberLabel, id } = _a, rest = __rest(_a, ["classes", "areaCodeValue", "phoneNumberValue", "areaCodeLabel", "areaCodePlaceholder", "phoneNumberPlaceholder", "phoneNumberLabel", "id"]);
        return (React.createElement(ErrorBoundary_1.default, null,
            React.createElement("div", { className: classes.component },
                React.createElement("div", { className: classes.areaCode },
                    React.createElement(TextField_1.default, { label: areaCodeLabel, icon: React.createElement("div", { className: classes.plusIcon }, "+"), placeholder: areaCodePlaceholder || '', showClearIcon: false, onChangeText: this._onAreaCodeChange, value: this.state.areaCodeValue, error: rest.error, showErrorMessage: false, id: id + '-code' })),
                React.createElement("div", { className: classes.phoneNumber },
                    React.createElement(TextField_1.default, Object.assign({}, rest, { id: id + '-number', label: phoneNumberLabel, placeholder: phoneNumberPlaceholder || '', value: this.state.phoneNumberValue, onChangeText: this._onPhoneNumberChange }))))));
    }
}
PhoneNumberField.propTypes = Object.assign({}, TextField_1.default.propTypes, { showAreaCode: prop_types_1.default.bool, areaCodeLabel: prop_types_1.default.string, areaCodeValue: prop_types_1.default.string, areaCodePlaceholder: prop_types_1.default.string, phoneNumberLabel: prop_types_1.default.string, phoneNumberValue: prop_types_1.default.string, phoneNumberPlaceholder: prop_types_1.default.string });
PhoneNumberField.defaultProps = {
    onChangeText: () => { },
    showAreaCode: true,
    id: 'phone-number-field',
};
exports.default = withStyles_1.default(styles_1.default)(PhoneNumberField);
//# sourceMappingURL=index.js.map