import _Input from "@alifd/next/es/input";
import _Radio from "@alifd/next/es/radio";
import _extends from "@babel/runtime/helpers/extends";
import _Box from "@alifd/next/es/box";
import * as React from 'react';
var findReact = function findReact(id, traverseUp) {
  if (traverseUp === void 0) {
    traverseUp = 0;
  }
  var dom = document.querySelector("#" + id);
  if (!dom) return;
  var key = Object.keys(dom).find(function (item) {
    return item.startsWith('__reactFiber$') ||
    // react 17+
    item.startsWith('__reactInternalInstance$'); // react <17
  });
  var domFiber = dom[key];
  if (domFiber == null) return null;

  // react <16
  if (domFiber._currentElement) {
    var _compFiber = domFiber._currentElement._owner;
    for (var i = 0; i < traverseUp; i++) {
      _compFiber = _compFiber._currentElement._owner;
    }
    return _compFiber._instance;
  }

  // react 16+
  var GetCompFiber = function GetCompFiber(fiber) {
    // return fiber._debugOwner; // this also works, but is __DEV__ only
    var parentFiber = fiber["return"];
    while (typeof parentFiber.type === 'string') {
      parentFiber = parentFiber["return"];
    }
    return parentFiber;
  };
  var compFiber = GetCompFiber(domFiber);
  for (var _i = 0; _i < traverseUp; _i++) {
    compFiber = GetCompFiber(compFiber);
  }
  return compFiber.stateNode;
};
var TooltipActionContent = function TooltipActionContent(_ref) {
  var _ref$value = _ref.value,
    value = _ref$value === void 0 ? {} : _ref$value,
    _onChange = _ref.onChange;
  return /*#__PURE__*/React.createElement(_Box, null, /*#__PURE__*/React.createElement(_Box, {
    direction: "row",
    align: "center",
    className: "behavior-item"
  }, /*#__PURE__*/React.createElement(_Box, {
    style: {
      width: 70
    }
  }, "\u89E6\u53D1\u65B9\u5F0F"), /*#__PURE__*/React.createElement(_Box, {
    className: "behavior-radio"
  }, /*#__PURE__*/React.createElement(_Radio.Group, {
    size: "small",
    dataSource: ['click', 'hover'],
    defaultValue: "click",
    shape: "button",
    value: value.triggerType || 'click',
    onChange: function onChange(triggerType) {
      _onChange(_extends({}, value, {
        triggerType: triggerType
      }));
    }
  }))), /*#__PURE__*/React.createElement(_Box, {
    direction: "row",
    align: "center",
    className: "behavior-item"
  }, /*#__PURE__*/React.createElement(_Box, {
    style: {
      width: 70
    }
  }, "\u901A\u77E5\u5185\u5BB9"), /*#__PURE__*/React.createElement(_Box, {
    direction: "row",
    className: "behavior-radio",
    spacing: 10
  }, /*#__PURE__*/React.createElement(_Input.TextArea, {
    size: "small",
    placeholder: "\u8BF7\u8F93\u5165\u5185\u5BB9",
    value: value.content,
    onChange: function onChange(content) {
      _onChange(_extends({}, value, {
        content: content
      }));
    }
  }))));
};
export var tooltipBehaviorAction = {
  name: 'tooltip',
  title: 'Tooltip',
  render: function render(props) {
    return /*#__PURE__*/React.createElement(TooltipActionContent, props);
  },
  toActionValue: function toActionValue(value, options) {
    return {
      type: 'JSExpression',
      value: "function() {\n      const id = '" + options.id + "';\n      const findReact = " + findReact + ";\n      const node = findReact(id);\n      if (!node) return;\n      if (typeof node.enableTooltip === 'function') {\n        node.enableTooltip('" + value.triggerType + "', '" + value.content + "');\n      } else if (typeof node.toggleTip === 'function') {\n        node.toggleTip('" + value.content + "');\n      }\n    }"
    };
  }
};