"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

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

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

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

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

var _react = _interopRequireDefault(require("react"));

var _prismReactRenderer = _interopRequireWildcard(require("prism-react-renderer"));

var _components = require("@alicloudfe/components");

var _copyToClipboard = _interopRequireDefault(require("copy-to-clipboard"));

var _theme = _interopRequireDefault(require("../codesnippet/theme.js"));

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

var BDesignContainer = function BDesignContainer(props) {
  var code = props.code,
      type = props.type,
      width = props.width,
      height = props.height,
      rest = (0, _objectWithoutProperties2.default)(props, ["code", "type", "width", "height"]);
  return /*#__PURE__*/_react.default.createElement(_prismReactRenderer.default, (0, _extends2.default)({}, _prismReactRenderer.defaultProps, {
    code: code,
    language: "jsx",
    theme: _theme.default
  }), type === 'number' ? function (_ref) {
    var className = _ref.className,
        style = _ref.style,
        tokens = _ref.tokens,
        getLineProps = _ref.getLineProps,
        getTokenProps = _ref.getTokenProps;
    return /*#__PURE__*/_react.default.createElement("pre", {
      className: "".concat(className, " codesnippet-numberPre"),
      style: _objectSpread(_objectSpread({}, style), {}, {
        width: width
      })
    }, tokens.map(function (line, i) {
      return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
        className: "codesnippet-line",
        key: i
      }, getLineProps({
        line: line,
        key: i
      })), /*#__PURE__*/_react.default.createElement("span", {
        className: "codesnippet-lineno"
      }, i + 1), /*#__PURE__*/_react.default.createElement("span", {
        className: "codesnippet-linecontent"
      }, line.map(function (token, key) {
        return /*#__PURE__*/_react.default.createElement("span", (0, _extends2.default)({
          key: key
        }, getTokenProps({
          token: token,
          key: key
        })));
      })));
    }));
  } : function (_ref2) {
    var className = _ref2.className,
        style = _ref2.style,
        tokens = _ref2.tokens,
        getLineProps = _ref2.getLineProps,
        getTokenProps = _ref2.getTokenProps;
    return /*#__PURE__*/_react.default.createElement("pre", {
      className: className,
      style: style
    }, tokens.map(function (line, i) {
      return /*#__PURE__*/_react.default.createElement("div", getLineProps({
        line: line,
        key: i
      }), line.map(function (token, key) {
        return /*#__PURE__*/_react.default.createElement("span", getTokenProps({
          token: token,
          key: key
        }));
      }));
    }), /*#__PURE__*/_react.default.createElement("i", {
      className: "iconfont icon-copy icon-Copy-2-Outlined",
      onClick: function onClick() {
        (0, _copyToClipboard.default)(code);

        _components.Message.success("代码已复制成功");
      }
    }));
  });
};

var _default = BDesignContainer;
exports.default = _default;