"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.RowStatusCell = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireDefault(require("react"));
var _wixUiIconsCommon = require("@wix/wix-ui-icons-common");
var _Box = _interopRequireDefault(require("../../Box"));
var _Tooltip = _interopRequireDefault(require("../../Tooltip"));
var _WixDesignSystemIconThemeProvider = require("../../WixDesignSystemIconThemeProvider");
var _RowStatusCellSt = require("./RowStatusCell.st.css.js");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/Table/components/RowStatusCell.jsx",
  _this = void 0;
var renderMessages = function renderMessages(messages) {
  if (!(messages != null && messages.length)) return undefined;
  if (messages.length === 1) return messages[0];
  return /*#__PURE__*/_react["default"].createElement("ul", {
    className: _RowStatusCellSt.classes.messageList,
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 15,
      columnNumber: 5
    }
  }, messages.map(function (line, i) {
    return /*#__PURE__*/_react["default"].createElement("li", {
      key: i,
      __self: _this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 17,
        columnNumber: 9
      }
    }, line);
  }));
};
var RowStatusCell = exports.RowStatusCell = function RowStatusCell(_ref) {
  var status = _ref.status,
    messages = _ref.messages;
  var icons = (0, _WixDesignSystemIconThemeProvider.useIcons)('RowStatusCell', {
    StatusAlertFilledSmall: _wixUiIconsCommon.StatusAlertFilledSmall,
    StatusWarningFilledSmall: _wixUiIconsCommon.StatusWarningFilledSmall
  });
  var resolvedStatus = status === 'warning' ? 'warning' : 'error';
  var Icon = resolvedStatus === 'warning' ? icons.StatusWarningFilledSmall : icons.StatusAlertFilledSmall;
  var message = renderMessages(messages);
  var iconElement = /*#__PURE__*/_react["default"].createElement("span", (0, _extends2["default"])({
    "data-hook": "row-status-indicator",
    "data-status": resolvedStatus
  }, message ? {
    tabIndex: 0
  } : {}, {
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 36,
      columnNumber: 5
    }
  }), /*#__PURE__*/_react["default"].createElement(Icon, {
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 41,
      columnNumber: 7
    }
  }));
  return /*#__PURE__*/_react["default"].createElement(_Box["default"], {
    className: (0, _RowStatusCellSt.st)(_RowStatusCellSt.classes.root, {
      status: resolvedStatus
    }),
    align: "center",
    verticalAlign: "middle",
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 46,
      columnNumber: 5
    }
  }, message ? /*#__PURE__*/_react["default"].createElement(_Tooltip["default"], {
    content: message,
    appendTo: "window",
    maxWidth: 250,
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 52,
      columnNumber: 9
    }
  }, iconElement) : iconElement);
};