"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.HypothesisBar = void 0;

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

var _propTypes = _interopRequireDefault(require("prop-types"));

var _clsx = _interopRequireDefault(require("clsx"));

var _all = require("react-icons/all");

var _solid = require("@heroicons/react/solid");

var _ai = require("react-icons/ai");

var _hypothesisStatuses = require("../../constants/hypothesis-statuses");

var _Avatar = require("../Avatar");

var _jsxRuntime = require("react/jsx-runtime");

var _statusToStatusIconMa;

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

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

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; }

var statusToStatusIconMapping = (_statusToStatusIconMa = {}, _defineProperty(_statusToStatusIconMa, _hypothesisStatuses.HypothesisStatuses.Proven, {
  StatusIcon: _solid.ThumbUpIcon,
  statusColorClass: "text-bright-green"
}), _defineProperty(_statusToStatusIconMa, _hypothesisStatuses.HypothesisStatuses.Likely, {
  StatusIcon: _solid.ThumbUpIcon,
  statusColorClass: "text-warm-green"
}), _defineProperty(_statusToStatusIconMa, _hypothesisStatuses.HypothesisStatuses.Possible, {
  StatusIcon: _solid.ThumbUpIcon,
  statusColorClass: "text-warmer-gray"
}), _defineProperty(_statusToStatusIconMa, _hypothesisStatuses.HypothesisStatuses.Unlikely, {
  StatusIcon: _solid.ThumbDownIcon,
  statusColorClass: "text-warmer-gray"
}), _defineProperty(_statusToStatusIconMa, _hypothesisStatuses.HypothesisStatuses.Improbable, {
  StatusIcon: _solid.ThumbDownIcon,
  statusColorClass: "text-bright-orange"
}), _defineProperty(_statusToStatusIconMa, _hypothesisStatuses.HypothesisStatuses.Disproven, {
  StatusIcon: _solid.ThumbDownIcon,
  statusColorClass: "text-bright-red"
}), _defineProperty(_statusToStatusIconMa, "fallback", {
  StatusIcon: _ai.AiOutlineSearch,
  statusColorClass: "text-bright-red"
}), _statusToStatusIconMa);

var renderInfoIcon = function renderInfoIcon(icon) {
  var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  var mapping = {
    comment: _all.BsFillChatSquareTextFill,
    log: _all.BsFillBarChartFill
  };

  if (mapping[icon]) {
    var Component = mapping[icon];
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, _objectSpread({}, props), icon);
  }

  return null;
};

var HypothesisBar = function HypothesisBar(_ref) {
  var hypothesis = _ref.hypothesis,
      onTitleClick = _ref.onTitleClick,
      startAdornment = _ref.startAdornment;
  var rawTitle = hypothesis.title,
      status = hypothesis.status,
      createdBy = hypothesis.created_by;
  var title = (0, _react.useMemo)(function () {
    return (rawTitle !== null && rawTitle !== void 0 ? rawTitle : "").trim();
  }, [rawTitle]);

  var _useMemo = (0, _react.useMemo)(function () {
    return statusToStatusIconMapping[status] || statusToStatusIconMapping.fallback;
  }, [status]),
      StatusIcon = _useMemo.StatusIcon,
      statusColorClass = _useMemo.statusColorClass;

  var infoIcons = ["comment", "log"];
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: "w-full flex justify-between rounded-8px border focus:outline-none bg-white cursor-pointer",
    children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: "flex items-center min-h-12 w-full py-2",
      children: [startAdornment && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: "w-5 h-5 ml-4 mr-1 flex-0-0-a",
        children: startAdornment
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: (0, _clsx.default)("ml-2 bg-lighter-gray rounded-full p-2 w-8 h-8 flex-0-0-a", statusColorClass),
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(StatusIcon, {})
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
        className: "ml-3 text-sm font-normal w-full text-left flex-1 min-h-full inline-flex items-center",
        onClick: onTitleClick,
        role: "presentation",
        children: title || "(none)"
      })]
    }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: "flex items-center min-h-12 pr-3 ml-1.5 py-2",
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: "-mx-1 flex flex-row",
        children: infoIcons.map(function (i) {
          return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
            className: "px-1",
            children: renderInfoIcon(i, {
              className: "text-dark-blue"
            })
          }, i);
        })
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: "ml-3",
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.Avatar, {
          user: createdBy,
          size: "sm"
        })
      })]
    })]
  });
};

exports.HypothesisBar = HypothesisBar;
HypothesisBar.propTypes = {
  onTitleClick: _propTypes.default.func,
  startAdornment: _propTypes.default.node,
  hypothesis: _propTypes.default.shape({}).isRequired
};
HypothesisBar.defaultProps = {
  onTitleClick: function onTitleClick() {},
  startAdornment: null
};