"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.name = void 0;

var React = _interopRequireWildcard(require("react"));

var PropTypes = _interopRequireWildcard(require("prop-types"));

var _styles = require("@fluent-ui/styles");

var _Table = require("../Table.styled");

var _TableContext = require("./TableContext");

var _classnames = _interopRequireDefault(require("classnames"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _extends() { _extends = Object.assign || 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 _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

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 name = 'TableCell';
exports.name = name;
var useStyles = (0, _styles.createUseStyles)(_Table.styles, {
  name: name
});
var Cell = React.forwardRef(function (props, ref) {
  var _classNames;

  var classNameProp = props.className,
      _props$textAlign = props.textAlign,
      textAlign = _props$textAlign === void 0 ? 'left' : _props$textAlign,
      children = props.children,
      rest = _objectWithoutProperties(props, ["className", "textAlign", "children"]);

  var tableContext = React.useContext(_TableContext.TableContext);
  var Component = tableContext.variant === 'head' ? 'th' : 'td';
  var classes = useStyles(props);
  var className = (0, _classnames["default"])((_classNames = {}, _defineProperty(_classNames, classes.cellRoot, tableContext.variant !== 'head'), _defineProperty(_classNames, classes.headCellRoot, tableContext.variant === 'head'), _defineProperty(_classNames, classes.cellTextAlignLeft, textAlign === 'left'), _defineProperty(_classNames, classes.cellTextAlignRight, textAlign === 'right'), _defineProperty(_classNames, classes.cellTextAlignCenter, textAlign === 'center'), _defineProperty(_classNames, classes.cellTextAlignJustify, textAlign === 'justify'), _classNames), classNameProp);
  return React.createElement(Component, _extends({
    className: className,
    ref: ref
  }, rest), children);
});
Cell.displayName = "F".concat(name);
Cell.propTypes = {
  className: PropTypes.string,
  children: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.element]).isRequired,
  textAlign: PropTypes.oneOf(['inherit', 'left', 'right', 'center', 'justify'])
};
Cell.defaultProps = {
  textAlign: 'left'
};
var _default = Cell;
exports["default"] = _default;