"use strict";

exports.__esModule = true;
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _mobxReact = require("mobx-react");
var _shell = require("../../../shell");
var _icons = require("@ant-design/icons");
var _antd = require("antd");
require("./operation.less");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
var ComponentTreeOutLook = function ComponentTreeOutLook(props) {
  if (props.node) {
    return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
      style: {
        marginRight: props.level * 8 + 'px'
      },
      className: "vitis-node-component-tree-item"
    }, props.node.title), /*#__PURE__*/_react["default"].createElement(ComponentTreeOutLook, {
      node: props.node.parent,
      level: props.level + 1
    }));
  }
  return null;
};
var _default = exports["default"] = (0, _mobxReact.observer)(function Operation() {
  var _observableProject$do, _observableProject$do2;
  var _useState = (0, _react.useState)({}),
    style = _useState[0],
    setStyle = _useState[1];
  var rootRef = (0, _react.useRef)(null);
  (0, _react.useLayoutEffect)(function () {
    var rect = _shell.observableProject.designer.detection.selectedNodePosition;
    if (rect && _shell.observableProject.documentModel.currentNode) {
      var _rootRef$current;
      setStyle({
        left: rect.right - (((_rootRef$current = rootRef.current) === null || _rootRef$current === void 0 ? void 0 : _rootRef$current.clientWidth) || 0),
        top: rect.top,
        visibility: 'visible'
      });
    } else {
      setStyle({});
    }
  }, [_shell.observableProject.designer.detection.selectedNodePosition, _shell.observableProject.documentModel.currentNode]);
  var onDel = function onDel() {
    _shell.observableProject.documentModel.delNode(_shell.observableProject.documentModel.selectedNodeId);
    _shell.observableProject.designer.selectNode(undefined);
  };
  var onCopy = function onCopy() {
    var _currentNode$parent;
    var currentNode = _shell.observableProject.documentModel.currentNode;
    var node = _shell.observableProject.documentModel.copyNode(currentNode);
    (_currentNode$parent = currentNode.parent) === null || _currentNode$parent === void 0 ? void 0 : _currentNode$parent.insertAfter(node, currentNode);
    _shell.observableProject.designer.rerender();
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "vitis-node-operation",
    style: style,
    ref: rootRef
  }, _shell.observableProject.documentModel.currentNode && /*#__PURE__*/_react["default"].createElement(_antd.Popover, {
    placement: "bottomRight",
    trigger: "hover",
    showArrow: false,
    content: /*#__PURE__*/_react["default"].createElement(ComponentTreeOutLook, {
      node: _shell.observableProject.documentModel.currentNode,
      level: 0
    }),
    overlayClassName: "vitis-node-operation-component-tree-popover"
  }, /*#__PURE__*/_react["default"].createElement(_icons.UnorderedListOutlined, {
    className: "icon"
  })), ((_observableProject$do = _shell.observableProject.documentModel.currentNode) === null || _observableProject$do === void 0 ? void 0 : _observableProject$do.componentSpec.unableDel) === false && /*#__PURE__*/_react["default"].createElement(_icons.DeleteOutlined, {
    className: "icon",
    onClick: onDel
  }), ((_observableProject$do2 = _shell.observableProject.documentModel.currentNode) === null || _observableProject$do2 === void 0 ? void 0 : _observableProject$do2.componentSpec.unableCopy) === false && /*#__PURE__*/_react["default"].createElement(_icons.CopyOutlined, {
    className: "icon",
    onClick: onCopy
  }));
});