"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

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

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

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

var _vsLight = _interopRequireDefault(require("prism-react-renderer/themes/vsLight"));

var _jsxRuntime = require("react/jsx-runtime");

var _excluded = ["getTokenProps", "onClick", "showLineNo", "idx", "line"],
    _excluded2 = ["style"];

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

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

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

var Line = function Line(_ref) {
  var getTokenProps = _ref.getTokenProps,
      onClick = _ref.onClick,
      showLineNo = _ref.showLineNo,
      idx = _ref.idx,
      line = _ref.line,
      props = _objectWithoutProperties(_ref, _excluded);

  var onSelect = function onSelect() {
    return onClick && onClick(idx);
  };

  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", _objectSpread(_objectSpread({}, props), {}, {
    role: "button",
    tabIndex: "0",
    onClick: onSelect,
    onKeyUp: onSelect,
    children: [showLineNo && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
      className: "text-gray-400 text-xs px-1",
      style: {
        display: "table-cell"
      },
      children: idx + 1
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
      style: {
        display: "table-cell"
      },
      children: line.map(function (token, key) {
        return (
          /*#__PURE__*/
          // key is in the getTokenProps responses. Disabling eslint to skip
          // check for explicit keys.
          // eslint-disable-next-line react/jsx-key
          (0, _jsxRuntime.jsx)("span", _objectSpread({}, getTokenProps({
            token: token,
            key: key
          })))
        );
      })
    })]
  }));
};

function JSONViewer(_ref2) {
  var code = _ref2.code,
      showLineNo = _ref2.showLineNo,
      selections = _ref2.selections,
      onClick = _ref2.onClick;
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_prismReactRenderer.default, _objectSpread(_objectSpread({}, _prismReactRenderer.defaultProps), {}, {
    code: code,
    theme: _vsLight.default,
    language: "json",
    children: function children(_ref3) {
      var className = _ref3.className,
          style = _ref3.style,
          tokens = _ref3.tokens,
          getLineProps = _ref3.getLineProps,
          getTokenProps = _ref3.getTokenProps;
      return /*#__PURE__*/(0, _jsxRuntime.jsx)("pre", {
        className: "".concat(className, " text-sm"),
        style: style,
        children: tokens.map(function (line, i) {
          var _getLineProps = getLineProps({
            line: line,
            key: i
          }),
              style = _getLineProps.style,
              props = _objectWithoutProperties(_getLineProps, _excluded2);
          /* eslint-disable react/jsx-key */


          return /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, _objectSpread(_objectSpread({}, props), {}, {
            style: _objectSpread(_objectSpread({}, style), {}, {
              display: showLineNo ? "table-row" : "block",
              backgroundColor: selections && selections[i] ? "#cfe3ff" : ""
            }),
            onClick: onClick,
            getTokenProps: getTokenProps,
            showLineNo: showLineNo,
            idx: i,
            line: line
          }));
          /* eslint-enable react/jsx-key */
        })
      });
    }
  }));
}