function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/*
Copyright (c) 2018-2019 Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import defaultProps from './default-props.js';
import { STATE_CHANGE_TYPE } from '../input/index.js';

const stateReducer = (type, nextState) => nextState;

export default class StatefulPinCodeContainer extends React.Component {
  constructor(...args) {
    super(...args);

    _defineProperty(this, "state", this.props.initialState);

    _defineProperty(this, "handleChange", ({
      values,
      event
    }) => {
      this.props.onChange({
        values,
        event
      });
      const nextState = this.props.stateReducer(STATE_CHANGE_TYPE.change, {
        values
      }, this.state);
      this.setState(nextState);
    });
  }

  render() {
    const {
      children,
      initialState,
      stateReducer,
      ...restProps
    } = this.props;
    return children({ ...defaultProps,
      ...restProps,
      ...this.state,
      onChange: this.handleChange
    });
  }

}

_defineProperty(StatefulPinCodeContainer, "defaultProps", {
  initialState: {
    values: defaultProps.values
  },
  stateReducer,
  onChange: defaultProps.onChange
});