"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.tableSharedStyle = exports.tableResizeHandleWidth = exports.tableNewColumnMinWidth = exports.tableMarginTopWithControl = exports.tableMarginTop = exports.tableMarginSides = exports.tableMarginBottom = exports.tableCellPadding = exports.tableCellMinWidth = exports.tableCellBorderWidth = exports.calcTableWidth = exports.TableSharedCssClassName = void 0;
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
var _react = require("@emotion/react");
var _adfSchema = require("@atlaskit/adf-schema");
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
var _browser = _interopRequireDefault(require("../../utils/browser"));
var _codeBlock = require("./code-block");
var _tableCell = require("./tableCell");
var _templateObject;
var tableMarginTop = exports.tableMarginTop = 24;
var tableMarginBottom = exports.tableMarginBottom = 16;
var tableMarginTopWithControl = exports.tableMarginTopWithControl = 14;
var tableMarginSides = exports.tableMarginSides = 8;
var tableCellMinWidth = exports.tableCellMinWidth = 48;
var tableNewColumnMinWidth = exports.tableNewColumnMinWidth = 140;
var tableCellBorderWidth = exports.tableCellBorderWidth = 1;
var tableCellPadding = exports.tableCellPadding = 8;
var tableResizeHandleWidth = exports.tableResizeHandleWidth = 6;
var TableSharedCssClassName = exports.TableSharedCssClassName = {
  TABLE_CONTAINER: "".concat(_adfSchema.tablePrefixSelector, "-container"),
  TABLE_NODE_WRAPPER: "".concat(_adfSchema.tablePrefixSelector, "-wrapper"),
  TABLE_LEFT_SHADOW: "".concat(_adfSchema.tablePrefixSelector, "-with-left-shadow"),
  TABLE_RIGHT_SHADOW: "".concat(_adfSchema.tablePrefixSelector, "-with-right-shadow"),
  TABLE_STICKY_SHADOW: "".concat(_adfSchema.tablePrefixSelector, "-sticky-shadow"),
  TABLE_STICKY_WRAPPER: "".concat(_adfSchema.tablePrefixSelector, "-sticky-wrapper"),
  TABLE_STICKY_SCROLLBAR_CONTAINER: "".concat(_adfSchema.tablePrefixSelector, "-sticky-scrollbar-container"),
  TABLE_STICKY_SENTINEL_TOP: "".concat(_adfSchema.tablePrefixSelector, "-sticky-sentinel-top"),
  TABLE_STICKY_SENTINEL_BOTTOM: "".concat(_adfSchema.tablePrefixSelector, "-sticky-sentinel-bottom"),
  TABLE_STICKY_SCROLLBAR_SENTINEL_TOP: "".concat(_adfSchema.tablePrefixSelector, "-sticky-scrollbar-sentinel-top"),
  TABLE_STICKY_SCROLLBAR_SENTINEL_BOTTOM: "".concat(_adfSchema.tablePrefixSelector, "-sticky-scrollbar-sentinel-bottom"),
  TABLE_SHADOW_SENTINEL_LEFT: "".concat(_adfSchema.tablePrefixSelector, "-shadow-sentinel-left"),
  TABLE_SHADOW_SENTINEL_RIGHT: "".concat(_adfSchema.tablePrefixSelector, "-shadow-sentinel-right"),
  TABLE_CELL_NODEVIEW_CONTENT_DOM: _adfSchema.tableCellContentDomSelector,
  TABLE_CELL_WRAPPER: _adfSchema.tableCellSelector,
  TABLE_HEADER_CELL_WRAPPER: _adfSchema.tableHeaderSelector,
  TABLE_ROW_CONTROLS_WRAPPER: "".concat(_adfSchema.tablePrefixSelector, "-row-controls-wrapper"),
  TABLE_COLUMN_CONTROLS_DECORATIONS: "".concat(_adfSchema.tablePrefixSelector, "-column-controls-decoration"),
  TABLE_RESIZER_CONTAINER: "".concat(_adfSchema.tablePrefixSelector, "-resizer-container")
};

// eslint-disable-next-line @atlaskit/design-system/no-css-tagged-template-expression -- Appears safe to auto-fix, but leaving it up to the team to remediate as the readability only gets worse with autofixing
var tableSharedStyle = exports.tableSharedStyle = function tableSharedStyle() {
  return (0, _react.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n  ", "\n  .", " {\n    position: relative;\n    margin: 0 auto ", ";\n    box-sizing: border-box;\n\n    /**\n     * Fix block top alignment inside table cells.\n     */\n    .decisionItemView-content-wrap:first-of-type > div {\n      margin-top: 0;\n    }\n  }\n  .", "[data-number-column='true'] {\n    padding-left: ", "px;\n    clear: both;\n  }\n\n  .", " {\n    will-change: width, margin-left;\n  }\n\n  .", " table {\n    will-change: width;\n  }\n\n  .", " > table {\n    margin: ", " 0 0 0;\n  }\n\n  .", " > table,\n  .", " > table {\n    margin: ", " ", " 0 0;\n  }\n\n  /* avoid applying styles to nested tables (possible via extensions) */\n  .", " > table,\n  .", " > table,\n  .", " > table {\n    border-collapse: collapse;\n    border: ", "px solid\n      ", ";\n    table-layout: fixed;\n    font-size: 1em;\n    width: 100%;\n\n    &[data-autosize='true'] {\n      table-layout: auto;\n    }\n\n    & {\n      * {\n        box-sizing: border-box;\n      }\n      hr {\n        box-sizing: content-box;\n      }\n\n      tbody {\n        border-bottom: none;\n      }\n      th td {\n        background-color: ", ";\n      }\n      th,\n      td {\n        min-width: ", "px;\n        font-weight: normal;\n        vertical-align: top;\n        border: 1px solid\n          ", ";\n        border-right-width: 0;\n        border-bottom-width: 0;\n        padding: ", ";\n        /* https://stackoverflow.com/questions/7517127/borders-not-shown-in-firefox-with-border-collapse-on-table-position-relative-o */\n        ", "\n\n        > :first-child:not(style),\n        > style:first-child + * {\n          margin-top: 0;\n        }\n\n        > .ProseMirror-gapcursor:first-child + *,\n        > style:first-child + .ProseMirror-gapcursor + * {\n          margin-top: 0;\n        }\n\n        > .ProseMirror-gapcursor:first-child + span + *,\n        > style:first-child + .ProseMirror-gapcursor + span + * {\n          margin-top: 0;\n        }\n\n        th p:not(:first-of-type),\n        td p:not(:first-of-type) {\n          margin-top: ", ";\n        }\n      }\n      th {\n        background-color: ", ";\n        text-align: left;\n\n        /* only apply this styling to codeblocks in default background headercells */\n        /* TODO this needs to be overhauled as it relies on unsafe selectors */\n        &:not([style]):not(.danger) {\n          .", ":not(.danger) {\n            background-color: ", ";\n\n            :not(.", ") {\n              box-shadow: 0px 0px 0px 1px\n                ", ";\n            }\n\n            .", " {\n              background-image: ", ";\n\n              background-color: ", ";\n            }\n\n            .", " {\n              background-color: ", ";\n            }\n\n            /* this is only relevant to the element taken care of by renderer */\n            > [data-ds--code--code-block] {\n              background-image: ", "!important;\n\n              background-color: ", "!important;\n\n              // selector lives inside @atlaskit/code\n              --ds--code--line-number-bg-color: ", ";\n            }\n          }\n        }\n      }\n    }\n  }\n"])), (0, _tableCell.tableCellBackgroundStyleOverride)(), TableSharedCssClassName.TABLE_CONTAINER, "var(--ds-space-200, 16px)", TableSharedCssClassName.TABLE_CONTAINER, _editorSharedStyles.akEditorTableNumberColumnWidth - 1, TableSharedCssClassName.TABLE_RESIZER_CONTAINER, TableSharedCssClassName.TABLE_RESIZER_CONTAINER, TableSharedCssClassName.TABLE_NODE_WRAPPER, "var(--ds-space-300, 24px)", TableSharedCssClassName.TABLE_CONTAINER, TableSharedCssClassName.TABLE_STICKY_WRAPPER, "var(--ds-space-300, 24px)", "var(--ds-space-100, 8px)", TableSharedCssClassName.TABLE_CONTAINER, TableSharedCssClassName.TABLE_NODE_WRAPPER, TableSharedCssClassName.TABLE_STICKY_WRAPPER, tableCellBorderWidth, "var(--ds-background-accent-gray-subtler, ".concat(_editorSharedStyles.akEditorTableBorder, ")"), "var(--ds-background-neutral-subtle, white)", tableCellMinWidth, "var(--ds-background-accent-gray-subtler, ".concat(_editorSharedStyles.akEditorTableBorder, ")"), "var(--ds-space-100, 8px)", _browser.default.gecko || _browser.default.ie || _browser.default.mac && _browser.default.chrome ? 'background-clip: padding-box;' : '', "var(--ds-space-150, 12px)", "var(--ds-background-accent-gray-subtlest, ".concat(_editorSharedStyles.akEditorTableToolbar, ")"), _codeBlock.CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER, "var(--ds-surface-raised, rgb(235, 237, 240))", _editorSharedStyles.akEditorSelectedNodeClassName, "var(--ds-border, transparent)", _codeBlock.CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPER, (0, _editorSharedStyles.overflowShadow)({
    leftCoverWidth: "var(--ds-space-300, 24px)"
  }), "var(--ds-background-neutral, rgb(235, 237, 240))", _codeBlock.CodeBlockSharedCssClassName.CODEBLOCK_LINE_NUMBER_GUTTER, "var(--ds-background-neutral, rgb(226, 229, 233))", (0, _editorSharedStyles.overflowShadow)({
    leftCoverWidth: "var(--ds-space-300, 24px)"
  }), "var(--ds-background-neutral, rgb(235, 237, 240))", "var(--ds-background-neutral, rgb(226, 229, 233))");
};
var calcTableWidth = exports.calcTableWidth = function calcTableWidth(layout, containerWidth) {
  var addControllerPadding = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  switch (layout) {
    case 'full-width':
      return containerWidth ? Math.min(containerWidth - (addControllerPadding ? _editorSharedStyles.akEditorBreakoutPadding : 0), _editorSharedStyles.akEditorFullWidthLayoutWidth) : _editorSharedStyles.akEditorFullWidthLayoutWidth;
    case 'wide':
      if (containerWidth) {
        return Math.min(containerWidth - (addControllerPadding ? _editorSharedStyles.akEditorBreakoutPadding : 0), _editorSharedStyles.akEditorWideLayoutWidth);
      }
      return _editorSharedStyles.akEditorWideLayoutWidth;
    default:
      return 'inherit';
  }
};