'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var cls = require('classnames');
var reactSyntaxHighlighter = require('react-syntax-highlighter');
var index = require('./utils/index.js');
var CodeArea_styles = require('./CodeArea.styles.js');
var CodeArea_tokens = require('./CodeArea.tokens.js');
var base = require('./variations/_size/base.js');
var base$1 = require('./variations/_view/base.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);
var cls__default = /*#__PURE__*/_interopDefault(cls);

var _excluded = ["children", "language", "showLineNumbers", "contentHeader", "hasDivider", "contentAction", "contentOuter", "style", "view", "size"];
var codeAreaRoot = function codeAreaRoot(Root) {
  return /*#__PURE__*/React.forwardRef(function (_ref, ref) {
    var children = _ref.children,
      _ref$language = _ref.language,
      language = _ref$language === void 0 ? 'text' : _ref$language,
      _ref$showLineNumbers = _ref.showLineNumbers,
      showLineNumbers = _ref$showLineNumbers === void 0 ? false : _ref$showLineNumbers,
      contentHeader = _ref.contentHeader,
      _ref$hasDivider = _ref.hasDivider,
      hasDivider = _ref$hasDivider === void 0 ? false : _ref$hasDivider,
      contentAction = _ref.contentAction,
      contentOuter = _ref.contentOuter,
      style = _ref.style,
      view = _ref.view,
      size = _ref.size,
      rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
    var code = children !== null && children !== void 0 ? children : '';
    var lineCount = String(code).split('\n').length;
    var lineNumberWidth = "".concat(String(lineCount).length, "ch");
    var rootStyle = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, style), {}, _rollupPluginBabelHelpers.defineProperty({}, CodeArea_tokens.tokens.lineNumberMinWidth, lineNumberWidth));
    return /*#__PURE__*/React__default.default.createElement(Root, _rollupPluginBabelHelpers.extends({
      ref: ref,
      style: rootStyle,
      view: view,
      size: size
    }, rest), contentOuter && /*#__PURE__*/React__default.default.createElement(CodeArea_styles.Outer, {
      className: CodeArea_tokens.classes.contentOuter
    }, contentOuter), /*#__PURE__*/React__default.default.createElement(CodeArea_styles.Field, null, /*#__PURE__*/React__default.default.createElement(CodeArea_styles.Overlay, null, contentHeader && /*#__PURE__*/React__default.default.createElement(CodeArea_styles.Header, {
      className: cls__default.default(CodeArea_tokens.classes.contentHeader, hasDivider ? CodeArea_tokens.classes.contentHeaderDivider : undefined)
    }, contentHeader), /*#__PURE__*/React__default.default.createElement(CodeArea_styles.Content, null, /*#__PURE__*/React__default.default.createElement(CodeArea_styles.Code, null, /*#__PURE__*/React__default.default.createElement(reactSyntaxHighlighter.Prism, {
      language: language,
      renderer: index.renderCodeRows,
      showLineNumbers: showLineNumbers,
      showInlineLineNumbers: true,
      style: CodeArea_styles.syntaxTheme,
      wrapLines: true,
      wrapLongLines: true
    }, code)), contentAction && /*#__PURE__*/React__default.default.createElement(CodeArea_styles.Action, {
      className: CodeArea_tokens.classes.contentAction
    }, contentAction)))));
  });
};
var codeAreaConfig = {
  name: 'CodeArea',
  tag: 'div',
  layout: codeAreaRoot,
  base: CodeArea_styles.base,
  variations: {
    size: {
      css: base.base
    },
    view: {
      css: base$1.base
    }
  },
  defaults: {
    size: 'm',
    view: 'default'
  }
};

exports.codeAreaConfig = codeAreaConfig;
exports.codeAreaRoot = codeAreaRoot;
