"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.nameStyle = exports.default = exports.containerSelected = exports.containerName = exports.container = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = _interopRequireWildcard(require("react"));
var _react2 = require("@emotion/react");
var _reactIntlNext = require("react-intl-next");
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
var _colors = require("@atlaskit/theme/colors");
var _constants = require("@atlaskit/theme/constants");
var _listItemAlts = require("./listItemAlts");
var _transformTimeStamp = require("./transformTimeStamp");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } /** @jsx jsx */ // AFP-2532 TODO: Fix automatic suppressions below
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
var container = exports.container = (0, _react2.css)({
  backgroundColor: 'transparent',
  padding: "var(--ds-space-100, 8px)".concat(" ", "var(--ds-space-150, 12px)"),
  cursor: 'pointer',
  display: 'flex',
  marginTop: 0
});
var containerSelected = exports.containerSelected = (0, _react2.css)({
  backgroundColor: "var(--ds-background-neutral-subtle-hovered, ".concat(_colors.N20, ")")
});
var nameWrapper = (0, _react2.css)({
  overflow: 'hidden'
});
var nameStyle = exports.nameStyle = (0, _react2.css)({
  color: "var(--ds-text, ".concat(_colors.N800, ")"),
  overflow: 'hidden',
  textOverflow: 'ellipsis',
  whiteSpace: 'nowrap',
  lineHeight: '20px'
});
var containerName = exports.containerName = (0, _react2.css)({
  color: "var(--ds-text-subtlest, ".concat(_colors.N300, ")"),
  lineHeight: '14px',
  fontSize: (0, _editorSharedStyles.relativeFontSizeToBase16)((0, _constants.fontSizeSmall)())
});
var iconStyle = (0, _react2.css)({
  minWidth: '16px',
  marginTop: "var(--ds-space-050, 4px)",
  marginRight: "var(--ds-space-150, 12px)",
  img: {
    maxWidth: '16px'
  }
});
var LinkSearchListItem = /*#__PURE__*/function (_React$PureComponent) {
  (0, _inherits2.default)(LinkSearchListItem, _React$PureComponent);
  var _super = _createSuper(LinkSearchListItem);
  function LinkSearchListItem() {
    var _this;
    (0, _classCallCheck2.default)(this, LinkSearchListItem);
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _super.call.apply(_super, [this].concat(args));
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleSelect", function (e) {
      e.preventDefault(); // don't let editor lose focus
      var _this$props = _this.props,
        item = _this$props.item,
        onSelect = _this$props.onSelect;
      onSelect(item.url, item.name);
    });
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleMouseMove", function () {
      var _this$props2 = _this.props,
        onMouseMove = _this$props2.onMouseMove,
        item = _this$props2.item;
      onMouseMove && onMouseMove(item.objectId);
    });
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleMouseEnter", function () {
      var _this$props3 = _this.props,
        onMouseEnter = _this$props3.onMouseEnter,
        item = _this$props3.item;
      onMouseEnter && onMouseEnter(item.objectId);
    });
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleMouseLeave", function () {
      var _this$props4 = _this.props,
        onMouseLeave = _this$props4.onMouseLeave,
        item = _this$props4.item;
      onMouseLeave && onMouseLeave(item.objectId);
    });
    return _this;
  }
  (0, _createClass2.default)(LinkSearchListItem, [{
    key: "renderIcon",
    value: function renderIcon() {
      var _this$props5 = this.props,
        _this$props5$item = _this$props5.item,
        icon = _this$props5$item.icon,
        iconUrl = _this$props5$item.iconUrl,
        intl = _this$props5.intl;
      if (icon) {
        return (0, _react2.jsx)("span", {
          css: iconStyle
        }, icon);
      }
      if (iconUrl) {
        return (0, _react2.jsx)("span", {
          css: iconStyle
        }, (0, _react2.jsx)("img", {
          src: iconUrl,
          alt: (0, _listItemAlts.getCorrectAltByIconUrl)(iconUrl, intl)
        }));
      }
      return null;
    }
  }, {
    key: "renderTimeStamp",
    value: function renderTimeStamp() {
      var _this$props6 = this.props,
        item = _this$props6.item,
        intl = _this$props6.intl;
      var date = (0, _transformTimeStamp.transformTimeStamp)(intl, item.lastViewedDate, item.lastUpdatedDate);
      return date && (0, _react2.jsx)(_react.Fragment, null, "\xA0 \u2022", (0, _react2.jsx)("span", {
        className: "link-search-timestamp",
        "data-test-id": "link-search-timestamp"
      }, "\xA0 ", date.pageAction, " ", date.dateString, " ", date.timeSince || ''));
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props7 = this.props,
        item = _this$props7.item,
        selected = _this$props7.selected,
        id = _this$props7.id,
        role = _this$props7.role;
      return (0, _react2.jsx)("li", {
        css: [container, selected && containerSelected],
        role: role,
        id: id,
        "aria-selected": selected,
        "data-testid": "link-search-list-item",
        onMouseMove: this.handleMouseMove,
        onMouseEnter: this.handleMouseEnter,
        onMouseLeave: this.handleMouseLeave,
        onClick: this.handleSelect
      }, this.renderIcon(), (0, _react2.jsx)("span", {
        css: nameWrapper
      }, (0, _react2.jsx)("div", {
        css: nameStyle
      }, item.name), (0, _react2.jsx)("div", {
        "data-testid": "link-search-list-item-container",
        css: containerName
      }, item.container, this.renderTimeStamp())));
    }
  }]);
  return LinkSearchListItem;
}(_react.default.PureComponent);
var _default = exports.default = (0, _reactIntlNext.injectIntl)(LinkSearchListItem);