"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.SavePane = SavePane;

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));

var _button = _interopRequireDefault(require("@alifd/next/lib/button"));

var _icon = _interopRequireDefault(require("@alifd/next/lib/icon"));

var _balloon = _interopRequireDefault(require("@alifd/next/lib/balloon"));

var _react = require("react");

var _lowcodeEngine = require("@alilc/lowcode-engine");

var _utils = require("../../utils");

require("./index.scss");

var Tooltip = _balloon["default"].Tooltip;

function SavePane(props) {
  var _props$config$content;

  var helpUrl = (_props$config$content = props.config.contentProps) === null || _props$config$content === void 0 ? void 0 : _props$config$content.helpUrl;
  (0, _react.useEffect)(function () {
    _lowcodeEngine.hotkey.bind(['command+s'], function (e, action) {
      e.preventDefault();
      handleSave();
    });
  }, []);

  var handleSave = function handleSave() {
    (0, _utils.saveSchema)();
  };

  return /*#__PURE__*/React.createElement("div", {
    className: "lowcode-save-actions"
  }, /*#__PURE__*/React.createElement(Tooltip, {
    v2: true,
    trigger: /*#__PURE__*/React.createElement("span", {
      className: "lowcode-action-item",
      onClick: _utils.preview
    }, /*#__PURE__*/React.createElement(_icon["default"], {
      type: "ic_preview_Selected"
    })),
    align: "b"
  }, "\u9884\u89C8"), /*#__PURE__*/React.createElement(Tooltip, {
    v2: true,
    trigger: /*#__PURE__*/React.createElement("span", {
      className: "lowcode-action-item",
      onClick: function onClick() {
        window.open(helpUrl || 'https://lowcode-engine.cn/docV2/funcv8#SIGYf', '_blank');
      }
    }, /*#__PURE__*/React.createElement(_icon["default"], {
      type: "help"
    })),
    align: "b"
  }, "\u5E2E\u52A9"), /*#__PURE__*/React.createElement(_button["default"], {
    className: "save-pane-button",
    onClick: _utils.resetSchema,
    type: "secondary",
    disabled: props.disabled
  }, "\u91CD\u7F6E"), /*#__PURE__*/React.createElement(_button["default"], {
    className: "save-pane-button",
    onClick: handleSave,
    type: "primary",
    disabled: props.disabled
  }, "\u4FDD \u5B58"));
}

var savePluginRegistry = function savePluginRegistry(ctx) {
  return {
    name: "save-plugin-registry",
    init: function init() {
      return (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
        return _regenerator["default"].wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                ctx.skeleton.add({
                  name: "saveSample",
                  area: "topArea",
                  type: "Widget",
                  props: {
                    align: "right"
                  },
                  contentProps: {
                    helpUrl: 'https://fusion.design/help.html/iuu6cm'
                  },
                  content: SavePane
                });

              case 1:
              case "end":
                return _context.stop();
            }
          }
        }, _callee);
      }))();
    }
  };
};

savePluginRegistry.pluginName = 'savePluginRegistry';

_lowcodeEngine.plugins.register(savePluginRegistry);