"use strict";

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

var _extends2 = require("babel-runtime/helpers/extends");

var _extends3 = _interopRequireDefault(_extends2);

var _defineProperty2 = require("babel-runtime/helpers/defineProperty");

var _defineProperty3 = _interopRequireDefault(_defineProperty2);

var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require("babel-runtime/helpers/createClass");

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn");

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require("babel-runtime/helpers/inherits");

var _inherits3 = _interopRequireDefault(_inherits2);

exports["default"] = PagePointHOC;

var _react = require("react");

var _react2 = _interopRequireDefault(_react);

var _hoistNonReactStatics = require("hoist-non-react-statics");

var _hoistNonReactStatics2 = _interopRequireDefault(_hoistNonReactStatics);

var _index = require("./index");

var _index2 = _interopRequireDefault(_index);

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

var sendPagePoint = _index2["default"].sendPagePoint,
    regKey = _index2["default"].pagePointConfig.regKey;
function PagePointHOC(WrappedComponent, componentType) {
    var enableForwardRef = ["MonthPicker", "RangePicker", "WeekPicker"];

    var WithPagePoint = function (_Component) {
        (0, _inherits3["default"])(WithPagePoint, _Component);

        function WithPagePoint(props) {
            (0, _classCallCheck3["default"])(this, WithPagePoint);

            var _this = (0, _possibleConstructorReturn3["default"])(this, (WithPagePoint.__proto__ || Object.getPrototypeOf(WithPagePoint)).call(this, props));

            var _this$props = _this.props,
                dataRegId = _this$props[regKey],
                onChange = _this$props.onChange;

            var newChange = void 0;
            _this.composedHandler = {};
            _this.origValue = "";
            switch (componentType) {
                case "CheckboxGroup":
                    if (dataRegId) {
                        newChange = function newChange(value) {
                            var _sendPagePoint;

                            onChange && onChange(value);
                            sendPagePoint(null, (_sendPagePoint = {
                                eventType: "change",
                                tagName: "checkboxGroup",
                                value: value
                            }, (0, _defineProperty3["default"])(_sendPagePoint, regKey, dataRegId), (0, _defineProperty3["default"])(_sendPagePoint, "origValue", _this.origValue), _sendPagePoint));
                            _this.origValue = value;
                        };
                        _this.composedHandler = {
                            onChange: newChange
                        };
                    }
                    break;
                case "RadioGroup":
                    if (dataRegId) {
                        newChange = function newChange(e) {
                            var _sendPagePoint2;

                            onChange && onChange(e);
                            sendPagePoint(e.nativeEvent, (_sendPagePoint2 = {
                                eventType: "change",
                                tagName: "radioGroup"
                            }, (0, _defineProperty3["default"])(_sendPagePoint2, regKey, dataRegId), (0, _defineProperty3["default"])(_sendPagePoint2, "value", e.target.value), (0, _defineProperty3["default"])(_sendPagePoint2, "origValue", _this.origValue), _sendPagePoint2));
                            _this.origValue = e.target.value;
                        };
                        _this.composedHandler = {
                            onChange: newChange
                        };
                    }
                    break;
                case "MonthPicker":
                case "RangePicker":
                case "WeekPicker":
                    if (dataRegId) {
                        newChange = function newChange(dateMomnet, dateString) {
                            var _sendPagePoint3;

                            onChange && onChange(dateMomnet, dateString);
                            sendPagePoint(null, (_sendPagePoint3 = {
                                eventType: "change",
                                tagName: "monthPicker",
                                value: dateString
                            }, (0, _defineProperty3["default"])(_sendPagePoint3, regKey, dataRegId), (0, _defineProperty3["default"])(_sendPagePoint3, "origValue", _this.origValue), _sendPagePoint3));
                            _this.origValue = dateString;
                        };
                        _this.composedHandler = {
                            onChange: newChange
                        };
                    }
                    break;
                default:
                    break;
            }
            return _this;
        }

        (0, _createClass3["default"])(WithPagePoint, [{
            key: "render",
            value: function render() {
                var forwardedRef = this.props.forwardedRef;

                return _react2["default"].createElement(WrappedComponent, (0, _extends3["default"])({ ref: forwardedRef }, this.props, this.composedHandler));
            }
        }]);
        return WithPagePoint;
    }(_react.Component);

    (0, _hoistNonReactStatics2["default"])(WithPagePoint, WrappedComponent);
    return enableForwardRef.indexOf(componentType) > -1 ? _react2["default"].forwardRef(function (props, ref) {
        return _react2["default"].createElement(WithPagePoint, (0, _extends3["default"])({}, props, { forwardedRef: ref }));
    }) : WithPagePoint;
}
module.exports = exports['default'];