var _excluded = ["className", "children"],
  _excluded2 = ["className", "density", "columnDistance", "expandable", "stickyHeader", "children", "title", "fontSize", "persistSortingOrder", "sm", "md", "lg", "xl"];
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; }
import React from 'react';
import styled from 'styled-components';
import { FooterRow, HeaderRow, Row } from './Row';
import { Header } from './Header';
import { Footer } from './Footer';
import { Cell } from './Cell';
import { CellInlineContainer, ColumnProvider, constants, getStylesForSizes } from './shared';
import { FlexTableProvider, useFlexTable } from './shared/FlexTableProvider';
import { ExpandCell } from './Cell/ExpandCell';
import { Typography } from '../..';
import { isElement } from '../../common/utils';
import { ExpandItem, ExpandItems } from './Row/components';
var getStickyHeaderStyles = function getStickyHeaderStyles(_ref) {
  var stickyHeader = _ref.stickyHeader;
  return stickyHeader ? 'position: relative;' : '';
};
var StyledDiv = styled('div').withConfig({
  displayName: "FlexTable__StyledDiv",
  componentId: "sc-v6wpic-0"
})(["", ""], 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 = useFlexTable('stickyHeader'),
    xs = _useFlexTable.xs,
    sm = _useFlexTable.sm,
    md = _useFlexTable.md,
    lg = _useFlexTable.lg,
    xl = _useFlexTable.xl;
  return React.createElement(StyledDiv, _extends({
    className: className,
    role: "table",
    $xs: xs,
    $sm: sm,
    $md: md,
    $lg: lg,
    $xl: xl
  }, htmlDivProps), children);
};
var StyledTitleWrapper = styled.div.withConfig({
  displayName: "FlexTable__StyledTitleWrapper",
  componentId: "sc-v6wpic-1"
})(["display:flex;"]);
var StyledTypography = styled(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.createElement(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.createElement(FlexTableContainer, _extends({
    className: className
  }, htmlProps, title ? {
    'aria-labelledby': "".concat(htmlProps.id, "-title")
  } : {}), Boolean(title) && React.createElement(StyledTitleWrapper, {
    id: "".concat(htmlProps.id, "-title")
  }, isElement(title) ? title : React.createElement(StyledTypography, {
    type: "title3"
  }, title)), React.createElement(ColumnProvider, null, children)));
};
FlexTable.Row = Row;
FlexTable.HeaderRow = HeaderRow;
FlexTable.FooterRow = FooterRow;
FlexTable.Header = Header;
FlexTable.Footer = Footer;
FlexTable.ExpandCell = ExpandCell;
FlexTable.ExpandItem = ExpandItem;
FlexTable.Cell = Cell;
FlexTable.CellInlineContainer = CellInlineContainer;
FlexTable.CONSTANTS = constants;
FlexTable.ExpandItems = ExpandItems;
export default FlexTable;