'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

exports.default = function (Picker) {
    var _class, _temp;

    var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

    var defaultStyle = _ref.style,
        defaultTranslations = _ref.translations,
        defaultProps = _objectWithoutProperties(_ref, ['style', 'translations']);

    return _temp = _class = function (_Component) {
        _inherits(Widget, _Component);

        function Widget(props) {
            _classCallCheck(this, Widget);

            var _this = _possibleConstructorReturn(this, (Widget.__proto__ || Object.getPrototypeOf(Widget)).call(this, props));

            _this.handleChange = function (value) {
                var valueFormat = _this.props.valueFormat;

                var text = value === null || !value.isValid() ? null : value.format(valueFormat);
                _this.props.onChange(text);
            };

            _this.handleChange = _this.handleChange.bind(_this);
            return _this;
        }

        _createClass(Widget, [{
            key: 'render',
            value: function render() {
                var _props = this.props,
                    value = _props.value,
                    valueFormat = _props.valueFormat,
                    textFormat = _props.textFormat,
                    translations = _props.translations,
                    minDate = _props.minDate,
                    maxDate = _props.maxDate,
                    style = _props.style,
                    rest = _objectWithoutProperties(_props, ['value', 'valueFormat', 'textFormat', 'translations', 'minDate', 'maxDate', 'style']);

                return _react2.default.createElement(Picker, _extends({}, rest, {
                    value: value ? (0, _moment2.default)(value, valueFormat) : null,
                    minDate: minDate ? (0, _moment2.default)(minDate, valueFormat) : null,
                    maxDate: maxDate ? (0, _moment2.default)(maxDate, valueFormat) : null,
                    format: textFormat,
                    onChange: this.handleChange,
                    style: (0, _utils.deepAssign)(defaultStyle, style),
                    translations: (0, _utils.deepAssign)(defaultTranslations, translations)
                }));
            }
        }]);

        return Widget;
    }(_react.Component), _class.propTypes = {
        clearText: _react.PropTypes.string,
        value: _react.PropTypes.string,
        withClear: _react.PropTypes.bool,
        placeholder: _react.PropTypes.string,
        textFormat: _react.PropTypes.string.isRequired,
        valueFormat: _react.PropTypes.string.isRequired,
        style: _react.PropTypes.object,
        className: _react.PropTypes.string,
        onChange: _react.PropTypes.func,
        translations: _react.PropTypes.object,
        maxDate: _react.PropTypes.string,
        minDate: _react.PropTypes.string
    }, _class.defaultProps = _extends({
        clearText: 'clear',
        defaultValue: (0, _moment2.default)(),
        onChange: function onChange() {}
    }, defaultProps), _temp;
};

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _moment = require('moment');

var _moment2 = _interopRequireDefault(_moment);

var _utils = require('../common/utils');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
//# sourceMappingURL=widget.js.map