"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);

var _react = require("react");

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,
    _PagePoint$EventType = _index2["default"].EventType,
    clickType = _PagePoint$EventType.clickType,
    dblclickType = _PagePoint$EventType.dblclickType,
    keydownType = _PagePoint$EventType.keydownType,
    focusType = _PagePoint$EventType.focusType;

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

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

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

        var _this$props = _this.props,
            dataRegId = _this$props[regKey],
            onClick = _this$props.onClick,
            onChange = _this$props.onChange,
            onKeyDown = _this$props.onKeyDown,
            onFocus = _this$props.onFocus,
            onDoubleClick = _this$props.onDoubleClick;

        var newClick = void 0,
            newChange = void 0,
            newKeyDown = void 0,
            newFocus = void 0,
            newDoubleClick = void 0;
        _this.composedHandler = {};
        _this.origValue = "";
        switch (props.compType) {
            case "Input":
                if (dataRegId) {
                    newClick = function newClick(e) {
                        onClick && onClick(e);
                        e.eventType = clickType;
                        sendPagePoint(e, { origValue: _this.origValue });
                    };
                    //  change 事件对于input而言基本和keydown重复，保留keydown
                    //   newChange = e => {
                    //     onChange && onChange(e);
                    //     sendPagePoint(e.nativeEvent, { origValue: this.origValue });
                    //   };
                    newKeyDown = function newKeyDown(e) {
                        onKeyDown && onKeyDown(e);
                        e.nativeEvent.eventType = keydownType;
                        sendPagePoint(e.nativeEvent, { origValue: _this.origValue });
                    };
                    newFocus = function newFocus(e) {
                        onFocus && onFocus(e);
                        e.eventType = focusType;
                        sendPagePoint(e);
                        _this.origValue = e.target && e.target.value;
                    };
                    _this.composedHandler = {
                        onClick: newClick,
                        onFocus: newFocus,
                        onKeyDown: newKeyDown
                    };
                }
                break;
            case "InputNumber":
                if (dataRegId) {
                    newClick = function newClick(e) {
                        onClick && onClick(e);
                        e.eventType = clickType;
                        sendPagePoint(e, { origValue: _this.origValue });
                    };
                    // change 事件发送click
                    newChange = function newChange(value) {
                        var _sendPagePoint;

                        onChange && onChange(value);
                        sendPagePoint((_sendPagePoint = {
                            eventType: clickType,
                            tagname: "InputNumber",
                            value: value
                        }, (0, _defineProperty3["default"])(_sendPagePoint, regKey, dataRegId), (0, _defineProperty3["default"])(_sendPagePoint, "origValue", _this.origValue), _sendPagePoint));
                        _this.origValue = value;
                    };
                    newKeyDown = function newKeyDown(e) {
                        onKeyDown && onKeyDown(e);
                        e.eventType = keydownType;
                        sendPagePoint(e, { origValue: _this.origValue });
                    };
                    newFocus = function newFocus(e) {
                        onFocus && onFocus(e);
                        e.eventType = focusType;
                        sendPagePoint(e);
                    };
                    _this.composedHandler = {
                        onClick: newClick,
                        onChange: newChange,
                        onFocus: newFocus,
                        onKeyDown: newKeyDown
                    };
                }
                break;
            case "Button":
                if (dataRegId) {
                    var clickTimeId = void 0;
                    newClick = function newClick(e) {
                        onClick && onClick(e);
                        clearTimeout(clickTimeId);
                        var event = e.nativeEvent;
                        clickTimeId = setTimeout(function () {
                            event.eventType = clickType;
                            sendPagePoint(event);
                        }, 300);
                    };
                    newKeyDown = function newKeyDown(e) {
                        onKeyDown && onKeyDown(e);
                        e.eventType = keydownType;
                        sendPagePoint(e);
                    };
                    newDoubleClick = function newDoubleClick(e) {
                        onDoubleClick && onDoubleClick(e);
                        clearTimeout(clickTimeId);
                        e.eventType = dblclickType;
                        sendPagePoint(e);
                    };
                    _this.composedHandler = {
                        onClick: newClick,
                        onKeyDown: newKeyDown,
                        onDoubleClick: newDoubleClick
                    };
                }
                break;
            case "Icon":
                if (dataRegId) {
                    var count = 0;
                    // doubleclick 无效, 由click 触发
                    newClick = function newClick(e) {
                        onClick && onClick(e);
                        count += 1;
                        setTimeout(function () {
                            if (count === 1) {
                                var _sendPagePoint2;

                                sendPagePoint((_sendPagePoint2 = {
                                    eventType: clickType
                                }, (0, _defineProperty3["default"])(_sendPagePoint2, regKey, dataRegId), (0, _defineProperty3["default"])(_sendPagePoint2, "tagname", "icon"), _sendPagePoint2));
                            } else if (count > 1) {
                                var _sendPagePoint3;

                                sendPagePoint((_sendPagePoint3 = {
                                    eventType: dblclickType
                                }, (0, _defineProperty3["default"])(_sendPagePoint3, regKey, dataRegId), (0, _defineProperty3["default"])(_sendPagePoint3, "tagname", "icon"), _sendPagePoint3));
                            }
                            count = 0;
                        }, 300);
                    };
                    _this.composedHandler = {
                        onClick: newClick
                    };
                }
                break;
            case "Checkbox":
                if (dataRegId) {
                    newClick = function newClick(e) {
                        onClick && onClick(e);
                        e.eventType = clickType;
                        sendPagePoint(e);
                    };
                    //   newChange = e => {
                    //     onChange && onChange(e);
                    //     sendFdxPagePoint(e.nativeEvent, {
                    //       eventType: clickType,
                    //       value: e.target.checked
                    //     });
                    //  };
                    _this.composedHandler = {
                        onClick: newClick
                    };
                }
                break;
            case "CheckboxGroup":
                if (dataRegId) {
                    newChange = function newChange(value) {
                        var _sendPagePoint4;

                        onChange && onChange(value);
                        var valueStr = JSON.stringify(value);
                        sendPagePoint((_sendPagePoint4 = {
                            eventType: clickType,
                            tagname: "checkboxGroup",
                            value: valueStr
                        }, (0, _defineProperty3["default"])(_sendPagePoint4, regKey, dataRegId), (0, _defineProperty3["default"])(_sendPagePoint4, "origValue", _this.origValue), _sendPagePoint4));
                        _this.origValue = valueStr;
                    };
                    _this.composedHandler = {
                        onChange: newChange
                    };
                }
                break;
            case "Radio":
                if (dataRegId) {
                    newClick = function newClick(e) {
                        onClick && onClick(e);
                        e.eventType = clickType;
                        sendPagePoint(e);
                    };
                    //   newChange = e => {
                    //     onChange && onChange(e);
                    //     sendFdxPagePoint(e.nativeEvent, {
                    //       eventType: "change",
                    //       value: e.target.checked
                    //    });
                    //  };
                    _this.composedHandler = {
                        onClick: newClick
                    };
                }
                break;
            case "RadioGroup":
                if (dataRegId) {
                    newChange = function newChange(e) {
                        var _sendPagePoint5;

                        onChange && onChange(e);
                        sendPagePoint((_sendPagePoint5 = {
                            eventType: clickType
                        }, (0, _defineProperty3["default"])(_sendPagePoint5, regKey, dataRegId), (0, _defineProperty3["default"])(_sendPagePoint5, "tagname", "radioGroup"), (0, _defineProperty3["default"])(_sendPagePoint5, "value", e.target.value), (0, _defineProperty3["default"])(_sendPagePoint5, "origValue", _this.origValue), _sendPagePoint5));
                        _this.origValue = e.target.value;
                    };
                    _this.composedHandler = {
                        onChange: newChange
                    };
                }
                break;
            case "DatePicker":
            case "TimePicker":
            case "MonthPicker":
            case "RangePicker":
            case "WeekPicker":
                if (dataRegId) {
                    // click,keydown无效,focus被触发两次
                    // newFocus = (e) => {
                    //     onFocus && onFocus(e);
                    //     sendPagePoint(e);
                    //     this.origValue = e.target && e.target.value
                    // }
                    newChange = function newChange(dateMomnet, dateString) {
                        var _sendPagePoint6;

                        onChange && onChange(dateMomnet, dateString);
                        var dateStr = dateString;
                        // rangepicker为数组
                        if (Array.isArray(dateString)) {
                            dateStr = JSON.stringify(dateString);
                        }
                        // change 发送 click
                        sendPagePoint((_sendPagePoint6 = {
                            eventType: clickType,
                            tagname: "datetimePicker",
                            value: dateStr
                        }, (0, _defineProperty3["default"])(_sendPagePoint6, regKey, dataRegId), (0, _defineProperty3["default"])(_sendPagePoint6, "origValue", _this.origValue), _sendPagePoint6));
                        _this.origValue = dateStr;
                    };
                    _this.composedHandler = {
                        onChange: newChange
                    };
                }
                break;
            case "Select":
                if (dataRegId) {
                    // click,keydown无效
                    // change 发送 click
                    newChange = function newChange(value, option) {
                        var _sendPagePoint7;

                        onChange && onChange(value, option);
                        sendPagePoint((_sendPagePoint7 = {
                            eventType: clickType,
                            tagname: "select",
                            value: value
                        }, (0, _defineProperty3["default"])(_sendPagePoint7, regKey, dataRegId), (0, _defineProperty3["default"])(_sendPagePoint7, "origValue", _this.origValue), _sendPagePoint7));
                        _this.origValue = value;
                    };
                    newFocus = function newFocus(e) {
                        var _sendPagePoint8;

                        onFocus && onFocus(e);
                        sendPagePoint((_sendPagePoint8 = {
                            eventType: focusType,
                            tagname: "select"
                        }, (0, _defineProperty3["default"])(_sendPagePoint8, regKey, dataRegId), (0, _defineProperty3["default"])(_sendPagePoint8, "value", _this.origValue), _sendPagePoint8));
                    };
                    _this.composedHandler = {
                        onChange: newChange,
                        onFocus: newFocus
                    };
                }
                break;
            case "Modal":
                if (dataRegId) {
                    var _this$props2 = _this.props,
                        onOk = _this$props2.onOk,
                        onCancel = _this$props2.onCancel;

                    var newOk = void 0,
                        newCancel = void 0;
                    newOk = function newOk(e) {
                        onOk && onOk(e);
                        sendPagePoint((0, _defineProperty3["default"])({
                            eventType: clickType,
                            tagname: "modal",
                            value: "ok"
                        }, regKey, dataRegId));
                    };
                    newCancel = function newCancel() {
                        onCancel && onCancel();
                        sendPagePoint((0, _defineProperty3["default"])({
                            eventType: clickType,
                            tagname: "modal",
                            value: "cancel"
                        }, regKey, dataRegId));
                    };
                    _this.composedHandler = {
                        onOk: newOk,
                        onCancel: newCancel
                    };
                }
                break;
            case "Popconfirm":
                if (dataRegId) {
                    var _this$props3 = _this.props,
                        onConfirm = _this$props3.onConfirm,
                        _onCancel = _this$props3.onCancel;

                    var newConfirm = void 0,
                        _newCancel = void 0;
                    newConfirm = function newConfirm(e) {
                        onConfirm && onConfirm(e);
                        sendPagePoint((0, _defineProperty3["default"])({
                            eventType: clickType,
                            tagname: "popconfirm",
                            value: "ok"
                        }, regKey, dataRegId));
                    };
                    _newCancel = function _newCancel() {
                        _onCancel && _onCancel();
                        sendPagePoint((0, _defineProperty3["default"])({
                            eventType: clickType,
                            tagname: "popconfirm",
                            value: "cancel"
                        }, regKey, dataRegId));
                    };
                    _this.composedHandler = {
                        onConfirm: newConfirm,
                        onCancel: _newCancel
                    };
                }
                break;
            //  TableSelect onchange为自定义，需在内部修改
            case "Table":
                if (dataRegId) {
                    var _this$props4 = _this.props,
                        rowSelection = _this$props4.rowSelection,
                        onRow = _this$props4.onRow;

                    if (rowSelection) {
                        var _onChange = rowSelection.onChange;

                        newChange = function newChange(selectedRowKeys, selectedRows) {
                            var _sendPagePoint13;

                            _onChange && _onChange(selectedRowKeys, selectedRows);
                            // change 发送click
                            var rowKeys = JSON.stringify(selectedRowKeys);
                            sendPagePoint((_sendPagePoint13 = {
                                eventType: clickType,
                                tagname: "table",
                                value: rowKeys
                            }, (0, _defineProperty3["default"])(_sendPagePoint13, regKey, dataRegId), (0, _defineProperty3["default"])(_sendPagePoint13, "origValue", _this.origValue), _sendPagePoint13));
                            _this.origValue = rowKeys;
                        };
                        _this.composedHandler = {
                            onChange: newChange
                        };
                    }
                    var newOnRow = function newOnRow(record, index) {
                        return (0, _extends3["default"])((0, _extends3["default"])({}, onRow ? onRow(record, index) : {}), { onClick: function onClick(event) {
                                var _sendPagePoint14;

                                if (onRow && onRow(record, index)["onClick"]) {
                                    onRow(record, index)["onClick"](event);
                                }
                                var clientX = event.clientX,
                                    clientY = event.clientY,
                                    altKey = event.altKey,
                                    ctrlKey = event.ctrlKey,
                                    metaKey = event.metaKey,
                                    shiftKey = event.shiftKey;

                                sendPagePoint((_sendPagePoint14 = {
                                    eventType: clickType,
                                    tagname: "table",
                                    value: JSON.stringify(record)
                                }, (0, _defineProperty3["default"])(_sendPagePoint14, regKey, dataRegId), (0, _defineProperty3["default"])(_sendPagePoint14, "clientX", clientX), (0, _defineProperty3["default"])(_sendPagePoint14, "clientY", clientY), (0, _defineProperty3["default"])(_sendPagePoint14, "altKey", altKey), (0, _defineProperty3["default"])(_sendPagePoint14, "ctrlKey", ctrlKey), (0, _defineProperty3["default"])(_sendPagePoint14, "metaKey", metaKey), (0, _defineProperty3["default"])(_sendPagePoint14, "shiftKey", shiftKey), _sendPagePoint14));
                            }, onDoubleClick: function onDoubleClick(event) {
                                var _sendPagePoint15;

                                if (onRow && onRow(record, index)["onDoubleClick"]) {
                                    onRow(record, index)["onDoubleClick"](event);
                                }
                                var clientX = event.clientX,
                                    clientY = event.clientY,
                                    altKey = event.altKey,
                                    ctrlKey = event.ctrlKey,
                                    metaKey = event.metaKey,
                                    shiftKey = event.shiftKey;

                                sendPagePoint((_sendPagePoint15 = {
                                    eventType: dblclickType,
                                    tagname: "table",
                                    value: JSON.stringify(record)
                                }, (0, _defineProperty3["default"])(_sendPagePoint15, regKey, dataRegId), (0, _defineProperty3["default"])(_sendPagePoint15, "clientX", clientX), (0, _defineProperty3["default"])(_sendPagePoint15, "clientY", clientY), (0, _defineProperty3["default"])(_sendPagePoint15, "altKey", altKey), (0, _defineProperty3["default"])(_sendPagePoint15, "ctrlKey", ctrlKey), (0, _defineProperty3["default"])(_sendPagePoint15, "metaKey", metaKey), (0, _defineProperty3["default"])(_sendPagePoint15, "shiftKey", shiftKey), _sendPagePoint15));
                            } });
                    };
                    _this.composedHandler.onRow = newOnRow;
                }
                break;
            case "TreeSelect":
                if (dataRegId) {
                    newChange = function newChange(value, label, extra) {
                        var _sendPagePoint16;

                        onChange && onChange(value, label, extra);
                        // change 发送 click
                        sendPagePoint((_sendPagePoint16 = {
                            eventType: clickType,
                            tagname: "treeSelect",
                            value: value,
                            label: JSON.stringify(label)
                        }, (0, _defineProperty3["default"])(_sendPagePoint16, regKey, dataRegId), (0, _defineProperty3["default"])(_sendPagePoint16, "origValue", _this.origValue), _sendPagePoint16));
                        _this.origValue = value;
                    };
                    _this.composedHandler = {
                        onChange: newChange
                    };
                }
                break;
            case "Tree":
                if (dataRegId) {
                    var newCheck = function newCheck(value) {
                        var _sendPagePoint17;

                        var onCheck = _this.props.onCheck;

                        var valueStr = JSON.stringify(value);
                        onCheck && onCheck(value);
                        // check 发送 click
                        sendPagePoint((_sendPagePoint17 = {
                            eventType: clickType,
                            tagname: "Tree",
                            value: valueStr
                        }, (0, _defineProperty3["default"])(_sendPagePoint17, regKey, dataRegId), (0, _defineProperty3["default"])(_sendPagePoint17, "origValue", _this.origValue), _sendPagePoint17));
                        _this.origValue = valueStr;
                    };
                    _this.composedHandler = {
                        onCheck: newCheck
                    };
                }
                break;
            case "AutoComplete":
                //click keydown无效
                if (dataRegId) {
                    // change 发送 click
                    newChange = function newChange(value) {
                        var _sendPagePoint18;

                        onChange && onChange(value);
                        sendPagePoint((_sendPagePoint18 = {
                            eventType: clickType,
                            tagname: "autocomplete"
                        }, (0, _defineProperty3["default"])(_sendPagePoint18, regKey, dataRegId), (0, _defineProperty3["default"])(_sendPagePoint18, "origValue", _this.origValue), (0, _defineProperty3["default"])(_sendPagePoint18, "value", value), _sendPagePoint18));
                        _this.origValue = value;
                    };
                    //此处无参数
                    newFocus = function newFocus() {
                        onFocus && onFocus();
                        sendPagePoint((0, _defineProperty3["default"])({
                            eventType: focusType,
                            tagname: "autocomplete"
                        }, regKey, dataRegId));
                    };
                    _this.composedHandler = {
                        onChange: newChange,
                        onFocus: newFocus
                    };
                }
                break;
            default:
                break;
        }
        return _this;
    }

    (0, _createClass3["default"])(PagePointEnhanced, [{
        key: "render",
        value: function render() {
            return this.props.render(this.composedHandler);
        }
    }]);
    return PagePointEnhanced;
}(_react.Component);

exports["default"] = PagePointEnhanced;
module.exports = exports['default'];