import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _Button from "@alifd/next/es/button";
import _Icon from "@alifd/next/es/icon";
import _Balloon from "@alifd/next/es/balloon";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { useEffect } from 'react';
import { hotkey } from '@alilc/lowcode-engine';
import { saveSchema, resetSchema, preview } from "../../utils";
import './index.scss';
var Tooltip = _Balloon.Tooltip;
export 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;
  useEffect(function () {
    hotkey.bind(['command+s'], function (e, action) {
      e.preventDefault();
      handleSave();
    });
  }, []);

  var handleSave = function handleSave() {
    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: preview
    }, /*#__PURE__*/React.createElement(_Icon, {
      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, {
      type: "help"
    })),
    align: "b"
  }, "\u5E2E\u52A9"), /*#__PURE__*/React.createElement(_Button, {
    className: "reset-pane-button",
    onClick: resetSchema,
    type: "primary",
    disabled: props.disabled
  }, "\u91CD\u7F6E"), /*#__PURE__*/React.createElement(_Button, {
    className: "save-pane-button",
    onClick: handleSave,
    type: "primary",
    disabled: props.disabled
  }, "\u4FDD \u5B58"));
}
export var savePluginRegistry = function savePluginRegistry(ctx) {
  return {
    name: "save-plugin-registry",
    init: function init() {
      return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
        return _regeneratorRuntime.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';
export default savePluginRegistry;