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); }
import React from 'react';
import styled from 'styled-components';
import { isElement, isFunction } from '../../../common/utils';
import { Flexbox } from '../../..';
import { useFlexCellProps } from '../shared/ColumnProvider';
import { TextWrapper } from './TextWrapper';
import { getDensityPaddings } from '../shared/textUtils';
import getStylesForSizes from '../shared/getStylesForSizes';
import { useFlexTable } from '../shared/FlexTableProvider';
var getDensityStyles = function getDensityStyles(_ref) {
  var density = _ref.density;
  return "\n  padding-top: ".concat(getDensityPaddings(density), "px !important;\n  padding-bottom: ").concat(getDensityPaddings(density), "px;\n");
};
var StyledFlexbox = styled(Flexbox).withConfig({
  displayName: "Cell__StyledFlexbox",
  componentId: "sc-icfddc-0"
})(["overflow:hidden;", ""], getStylesForSizes(function (p) {
  return {
    xs: p.$xs,
    sm: p.$sm,
    md: p.$md,
    lg: p.$lg,
    xl: p.$xl
  };
}, {
  density: getDensityStyles
}));
var Cell = function Cell(props) {
  var children = props.children,
    columnId = props.columnId,
    className = props.className;
  var flexProps = useFlexCellProps(props);
  var _useFlexTable = useFlexTable('density'),
    xs = _useFlexTable.xs,
    sm = _useFlexTable.sm,
    md = _useFlexTable.md,
    lg = _useFlexTable.lg,
    xl = _useFlexTable.xl;
  return React.createElement(StyledFlexbox, _extends({
    className: className,
    role: "cell",
    $xs: xs,
    $sm: sm,
    $md: md,
    $lg: lg,
    $xl: xl
  }, flexProps), isElement(children) && children, isFunction(children) ? children({
    columnId: columnId
  }) : !isElement(children) && React.createElement(TextWrapper, null, children));
};
Cell.TextWrapper = React.memo(TextWrapper);
export default Cell;