"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _react = require("react");

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

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

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

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; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }

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

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

var sendPagePoint = _index.default.sendPagePoint,
    regKey = _index.default.pagePointConfig.regKey,
    _PagePoint$EventType = _index.default.EventType,
    clickType = _PagePoint$EventType.clickType,
    dblclickType = _PagePoint$EventType.dblclickType,
    keydownType = _PagePoint$EventType.keydownType,
    focusType = _PagePoint$EventType.focusType;

var PagePointEnhanced = /*#__PURE__*/function (_Component) {
  _inherits(PagePointEnhanced, _Component);

  var _super = _createSuper(PagePointEnhanced);

  function PagePointEnhanced(props) {
    var _this;

    _classCallCheck(this, PagePointEnhanced);

    _this = _super.call(this, props);
    _this.composedHandler = void 0;
    _this.origValue = void 0;
    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, newChange, newKeyDown, newFocus, newDoubleClick;
    _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
            }, _defineProperty(_sendPagePoint, regKey, dataRegId), _defineProperty(_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;

          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
                }, _defineProperty(_sendPagePoint2, regKey, dataRegId), _defineProperty(_sendPagePoint2, "tagname", "icon"), _sendPagePoint2));
              } else if (count > 1) {
                var _sendPagePoint3;

                sendPagePoint((_sendPagePoint3 = {
                  eventType: dblclickType
                }, _defineProperty(_sendPagePoint3, regKey, dataRegId), _defineProperty(_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
            }, _defineProperty(_sendPagePoint4, regKey, dataRegId), _defineProperty(_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
            }, _defineProperty(_sendPagePoint5, regKey, dataRegId), _defineProperty(_sendPagePoint5, "tagname", "radioGroup"), _defineProperty(_sendPagePoint5, "value", e.target.value), _defineProperty(_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
            }, _defineProperty(_sendPagePoint6, regKey, dataRegId), _defineProperty(_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
            }, _defineProperty(_sendPagePoint7, regKey, dataRegId), _defineProperty(_sendPagePoint7, "origValue", _this.origValue), _sendPagePoint7));
            _this.origValue = value;
          };

          newFocus = function newFocus(e) {
            var _sendPagePoint8;

            onFocus && onFocus(e);
            sendPagePoint((_sendPagePoint8 = {
              eventType: focusType,
              tagname: "select"
            }, _defineProperty(_sendPagePoint8, regKey, dataRegId), _defineProperty(_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, newCancel;

          newOk = function newOk(e) {
            onOk && onOk(e);
            sendPagePoint(_defineProperty({
              eventType: clickType,
              tagname: "modal",
              value: "ok"
            }, regKey, dataRegId));
          };

          newCancel = function newCancel() {
            onCancel && onCancel();
            sendPagePoint(_defineProperty({
              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, _newCancel;

          newConfirm = function newConfirm(e) {
            onConfirm && onConfirm(e);
            sendPagePoint(_defineProperty({
              eventType: clickType,
              tagname: "popconfirm",
              value: "ok"
            }, regKey, dataRegId));
          };

          _newCancel = function _newCancel() {
            _onCancel && _onCancel();
            sendPagePoint(_defineProperty({
              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
              }, _defineProperty(_sendPagePoint13, regKey, dataRegId), _defineProperty(_sendPagePoint13, "origValue", _this.origValue), _sendPagePoint13));
              _this.origValue = rowKeys;
            };

            _this.composedHandler = {
              onChange: newChange
            };
          }

          var newOnRow = function newOnRow(record, index) {
            return _objectSpread(_objectSpread({}, 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)
                }, _defineProperty(_sendPagePoint14, regKey, dataRegId), _defineProperty(_sendPagePoint14, "clientX", clientX), _defineProperty(_sendPagePoint14, "clientY", clientY), _defineProperty(_sendPagePoint14, "altKey", altKey), _defineProperty(_sendPagePoint14, "ctrlKey", ctrlKey), _defineProperty(_sendPagePoint14, "metaKey", metaKey), _defineProperty(_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)
                }, _defineProperty(_sendPagePoint15, regKey, dataRegId), _defineProperty(_sendPagePoint15, "clientX", clientX), _defineProperty(_sendPagePoint15, "clientY", clientY), _defineProperty(_sendPagePoint15, "altKey", altKey), _defineProperty(_sendPagePoint15, "ctrlKey", ctrlKey), _defineProperty(_sendPagePoint15, "metaKey", metaKey), _defineProperty(_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)
            }, _defineProperty(_sendPagePoint16, regKey, dataRegId), _defineProperty(_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
            }, _defineProperty(_sendPagePoint17, regKey, dataRegId), _defineProperty(_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"
            }, _defineProperty(_sendPagePoint18, regKey, dataRegId), _defineProperty(_sendPagePoint18, "origValue", _this.origValue), _defineProperty(_sendPagePoint18, "value", value), _sendPagePoint18));
            _this.origValue = value;
          }; //此处无参数


          newFocus = function newFocus() {
            onFocus && onFocus();
            sendPagePoint(_defineProperty({
              eventType: focusType,
              tagname: "autocomplete"
            }, regKey, dataRegId));
          };

          _this.composedHandler = {
            onChange: newChange,
            onFocus: newFocus
          };
        }

        break;

      default:
        break;
    }

    return _this;
  }

  _createClass(PagePointEnhanced, [{
    key: "render",
    value: function render() {
      return this.props.render(this.composedHandler);
    }
  }]);

  return PagePointEnhanced;
}(_react.Component);

exports.default = PagePointEnhanced;