"use strict";

exports.__esModule = true;
exports.default = exports.TableData = void 0;
var _react = _interopRequireDefault(require("react"));
var _styledComponents = _interopRequireDefault(require("styled-components"));
var _reactIntl = require("react-intl");
var _utils = require("../../utils");
var _Switch = _interopRequireDefault(require("../Switch"));
var _Checkbox = _interopRequireDefault(require("../Checkbox"));
var _Text = _interopRequireDefault(require("../Text"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
var arrify = function arrify(thing) {
  return Array.isArray(thing) ? thing : [thing];
};
var renderByType = function renderByType(value, def, rowId, selected, row) {
  var transformedValue = def.transform ? def.transform(value) : value;
  switch (def.type) {
    case "custom":
      {
        var Comp = def.component;
        return /*#__PURE__*/_react.default.createElement(Comp, _extends({}, row, def.funcs));
      }
    case "currency":
      {
        var currency = def.currency;
        if (Array.isArray(currency)) {
          currency = _utils.safeGet.apply(void 0, [row].concat(currency));
        }
        return /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedNumber, {
          style: "currency" // eslint-disable-line react/style-prop-object
          ,
          currency: currency,
          value: transformedValue || "0"
        });
      }
    case "date":
      return /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedDate, {
        value: transformedValue
      });
    case "datetime":
      return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedDate, {
        value: transformedValue
      }), " ", /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedTime, {
        value: transformedValue
      }));
    case "select":
      return /*#__PURE__*/_react.default.createElement(_Checkbox.default, {
        id: "select_" + rowId,
        value: selected,
        "data-row-id": rowId,
        onChange: def.onChange
      });
    case "switch":
      return /*#__PURE__*/_react.default.createElement(_Switch.default, _extends({
        value: !!transformedValue
      }, def.switch, {
        "data-row-id": rowId,
        onChange: def.onChange
      }));
    default:
      return transformedValue ? /*#__PURE__*/_react.default.createElement(_Text.default, {
        message: transformedValue
      }) : null;
  }
};
var TableData = exports.TableData = _styledComponents.default.td.withConfig({
  displayName: "DataCell__TableData",
  componentId: "sc-n6hj69-0"
})(["border:0 solid ", ";border-top-width:1px;tr:first-child &{border-top-width:0;}tr:last-child &{border-bottom-width:1px;}height:20px;padding:15px 20px;white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;"], (0, _utils.getThemeProp)(["colors", "borderLight"], "#cccccc"));
var DataCell = function DataCell(_ref) {
  var columnDef = _ref.columnDef,
    row = _ref.row,
    rowId = _ref.rowId,
    selected = _ref.selected;
  return /*#__PURE__*/_react.default.createElement(TableData, null, renderByType(_utils.safeGet.apply(void 0, [row].concat(arrify(columnDef.fieldName))) || columnDef.defaultValue, columnDef, rowId, selected, row));
};
var _default = DataCell;
var _default2 = _default;
var _default3 = exports.default = _default2;
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(arrify, "arrify", "/home/vsts/work/1/s/src/components/List/DataCell.js");
  reactHotLoader.register(renderByType, "renderByType", "/home/vsts/work/1/s/src/components/List/DataCell.js");
  reactHotLoader.register(TableData, "TableData", "/home/vsts/work/1/s/src/components/List/DataCell.js");
  reactHotLoader.register(DataCell, "DataCell", "/home/vsts/work/1/s/src/components/List/DataCell.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/List/DataCell.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(arrify, "arrify", "/home/vsts/work/1/s/src/components/List/DataCell.js");
  reactHotLoader.register(renderByType, "renderByType", "/home/vsts/work/1/s/src/components/List/DataCell.js");
  reactHotLoader.register(TableData, "TableData", "/home/vsts/work/1/s/src/components/List/DataCell.js");
  reactHotLoader.register(DataCell, "DataCell", "/home/vsts/work/1/s/src/components/List/DataCell.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/List/DataCell.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();