"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _styledComponents = _interopRequireDefault(require("styled-components"));
var _Row = require("./Row");
var _Header = require("./Header");
var _Footer = require("./Footer");
var _Cell = require("./Cell");
var _shared = require("./shared");
var _FlexTableProvider = require("./shared/FlexTableProvider");
var _ExpandCell = require("./Cell/ExpandCell");
var _ = require("../..");
var _utils = require("../../common/utils");
var _components = require("./Row/components");
var _excluded = ["className", "children"],
  _excluded2 = ["className", "density", "columnDistance", "expandable", "stickyHeader", "children", "title", "fontSize", "persistSortingOrder", "sm", "md", "lg", "xl"];
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
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 getStickyHeaderStyles = function getStickyHeaderStyles(_ref) {
  var stickyHeader = _ref.stickyHeader;
  return stickyHeader ? 'position: relative;' : '';
};
var StyledDiv = (0, _styledComponents.default)('div').withConfig({
  displayName: "FlexTable__StyledDiv",
  componentId: "sc-v6wpic-0"
})(["", ""], (0, _shared.getStylesForSizes)(function (p) {
  return {
    xs: p.$xs,
    sm: p.$sm,
    md: p.$md,
    lg: p.$lg,
    xl: p.$xl
  };
}, {
  stickyHeader: getStickyHeaderStyles
}));
var FlexTableContainer = function FlexTableContainer(_ref2) {
  var className = _ref2.className,
    children = _ref2.children,
    htmlDivProps = _objectWithoutProperties(_ref2, _excluded);
  var _useFlexTable = (0, _FlexTableProvider.useFlexTable)('stickyHeader'),
    xs = _useFlexTable.xs,
    sm = _useFlexTable.sm,
    md = _useFlexTable.md,
    lg = _useFlexTable.lg,
    xl = _useFlexTable.xl;
  return _react.default.createElement(StyledDiv, _extends({
    className: className,
    role: "table",
    $xs: xs,
    $sm: sm,
    $md: md,
    $lg: lg,
    $xl: xl
  }, htmlDivProps), children);
};
var StyledTitleWrapper = _styledComponents.default.div.withConfig({
  displayName: "FlexTable__StyledTitleWrapper",
  componentId: "sc-v6wpic-1"
})(["display:flex;"]);
var StyledTypography = (0, _styledComponents.default)(_.Typography).withConfig({
  displayName: "FlexTable__StyledTypography",
  componentId: "sc-v6wpic-2"
})(["padding-left:", "px;"], function (p) {
  return p.theme.spacing.unit(1);
});
var FlexTable = function FlexTable(_ref3) {
  var className = _ref3.className,
    _ref3$density = _ref3.density,
    density = _ref3$density === void 0 ? 'm' : _ref3$density,
    _ref3$columnDistance = _ref3.columnDistance,
    columnDistance = _ref3$columnDistance === void 0 ? 2 : _ref3$columnDistance,
    _ref3$expandable = _ref3.expandable,
    expandable = _ref3$expandable === void 0 ? false : _ref3$expandable,
    _ref3$stickyHeader = _ref3.stickyHeader,
    stickyHeader = _ref3$stickyHeader === void 0 ? true : _ref3$stickyHeader,
    children = _ref3.children,
    title = _ref3.title,
    _ref3$fontSize = _ref3.fontSize,
    fontSize = _ref3$fontSize === void 0 ? 'm' : _ref3$fontSize,
    _ref3$persistSortingO = _ref3.persistSortingOrder,
    persistSortingOrder = _ref3$persistSortingO === void 0 ? false : _ref3$persistSortingO,
    sm = _ref3.sm,
    md = _ref3.md,
    lg = _ref3.lg,
    xl = _ref3.xl,
    htmlProps = _objectWithoutProperties(_ref3, _excluded2);
  return _react.default.createElement(_FlexTableProvider.FlexTableProvider, {
    id: htmlProps.id,
    density: density,
    columnDistance: columnDistance,
    stickyHeader: stickyHeader,
    fontSize: fontSize,
    expandable: expandable,
    persistSortingOrder: persistSortingOrder,
    sm: sm,
    md: md,
    lg: lg,
    xl: xl
  }, _react.default.createElement(FlexTableContainer, _extends({
    className: className
  }, htmlProps, title ? {
    'aria-labelledby': "".concat(htmlProps.id, "-title")
  } : {}), Boolean(title) && _react.default.createElement(StyledTitleWrapper, {
    id: "".concat(htmlProps.id, "-title")
  }, (0, _utils.isElement)(title) ? title : _react.default.createElement(StyledTypography, {
    type: "title3"
  }, title)), _react.default.createElement(_shared.ColumnProvider, null, children)));
};
FlexTable.Row = _Row.Row;
FlexTable.HeaderRow = _Row.HeaderRow;
FlexTable.FooterRow = _Row.FooterRow;
FlexTable.Header = _Header.Header;
FlexTable.Footer = _Footer.Footer;
FlexTable.ExpandCell = _ExpandCell.ExpandCell;
FlexTable.ExpandItem = _components.ExpandItem;
FlexTable.Cell = _Cell.Cell;
FlexTable.CellInlineContainer = _shared.CellInlineContainer;
FlexTable.CONSTANTS = _shared.constants;
FlexTable.ExpandItems = _components.ExpandItems;
var _default = exports.default = FlexTable;