import { objectWithoutProperties as _objectWithoutProperties, objectSpread2 as _objectSpread2, defineProperty as _defineProperty, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
import React__default, { forwardRef } from 'react';
import cls from 'classnames';
import { Prism } from 'react-syntax-highlighter';
import { renderCodeRows } from './utils/index.js';
import { Outer, Field, Overlay, Header, Content, Code, syntaxTheme, Action, base } from './CodeArea.styles.js';
import { classes, tokens } from './CodeArea.tokens.js';
import { base as base$1 } from './variations/_size/base.js';
import { base as base$2 } from './variations/_view/base.js';

var _excluded = ["children", "language", "showLineNumbers", "contentHeader", "hasDivider", "contentAction", "contentOuter", "style", "view", "size"];
var codeAreaRoot = function codeAreaRoot(Root) {
  return /*#__PURE__*/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 = _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 = _objectSpread2(_objectSpread2({}, style), {}, _defineProperty({}, tokens.lineNumberMinWidth, lineNumberWidth));
    return /*#__PURE__*/React__default.createElement(Root, _extends({
      ref: ref,
      style: rootStyle,
      view: view,
      size: size
    }, rest), contentOuter && /*#__PURE__*/React__default.createElement(Outer, {
      className: classes.contentOuter
    }, contentOuter), /*#__PURE__*/React__default.createElement(Field, null, /*#__PURE__*/React__default.createElement(Overlay, null, contentHeader && /*#__PURE__*/React__default.createElement(Header, {
      className: cls(classes.contentHeader, hasDivider ? classes.contentHeaderDivider : undefined)
    }, contentHeader), /*#__PURE__*/React__default.createElement(Content, null, /*#__PURE__*/React__default.createElement(Code, null, /*#__PURE__*/React__default.createElement(Prism, {
      language: language,
      renderer: renderCodeRows,
      showLineNumbers: showLineNumbers,
      showInlineLineNumbers: true,
      style: syntaxTheme,
      wrapLines: true,
      wrapLongLines: true
    }, code)), contentAction && /*#__PURE__*/React__default.createElement(Action, {
      className: classes.contentAction
    }, contentAction)))));
  });
};
var codeAreaConfig = {
  name: 'CodeArea',
  tag: 'div',
  layout: codeAreaRoot,
  base: base,
  variations: {
    size: {
      css: base$1
    },
    view: {
      css: base$2
    }
  },
  defaults: {
    size: 'm',
    view: 'default'
  }
};

export { codeAreaConfig, codeAreaRoot };
