"use strict";

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

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

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _uuid = require("uuid");

var _branding = require("../../../../mixins/branding");

var _box = require("../../../../primitives/box");

var _span = require("../../../typography/span");

var _defaultSearchResult = require("./default-search-result.css-rules");

var _primitives = require("../../../../primitives");

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

var DefaultSearchResult = function DefaultSearchResult(_ref) {
  var isSelected = _ref.isSelected,
      isFirst = _ref.isFirst,
      matchedValue = _ref.matchedValue,
      text = _ref.text;
  var regex;
  var contentParts = [text];
  var regexMatches = [];

  if (matchedValue != null && matchedValue !== '') {
    var _text$match;

    regex = new RegExp(matchedValue, 'ig');
    contentParts = text.split(regex);
    regexMatches = (_text$match = text.match(regex)) !== null && _text$match !== void 0 ? _text$match : [];
  }

  return /*#__PURE__*/_react["default"].createElement(DefaultSearchResultOuter, {
    fontSize: "f1",
    isSelected: isSelected
  }, /*#__PURE__*/_react["default"].createElement(DefaultSearchResultInner, {
    isSelected: isSelected,
    isFirst: isFirst
  }, /*#__PURE__*/_react["default"].createElement(_primitives.HideAccessibly, null, text), /*#__PURE__*/_react["default"].createElement("div", {
    "aria-hidden": true
  }, contentParts.map(function (part) {
    return /*#__PURE__*/_react["default"].createElement("span", {
      key: (0, _uuid.v4)()
    }, part, /*#__PURE__*/_react["default"].createElement(_span.Span, {
      bold: true
    }, regexMatches.shift()));
  }))));
};

exports.DefaultSearchResult = DefaultSearchResult;

var getBorderTopColor = function getBorderTopColor(_ref2) {
  var isFirst = _ref2.isFirst,
      isSelected = _ref2.isSelected,
      theme = _ref2.theme;

  if (isSelected) {
    return (0, _branding.getPaletteColor)('greyscale-black')({
      theme: theme
    });
  }

  return (0, _branding.getPaletteColor)(isFirst ? 'white' : 'greyscale-light')({
    theme: theme
  });
};

var DefaultSearchResultInner = (0, _styledComponents["default"])(_box.Box).withConfig({
  displayName: "DefaultSearchResultInner",
  componentId: "sc-71kn0k-0"
})(["padding:11px 0;border-top:solid 1px ", ";pointer-events:none;"], getBorderTopColor);
var DefaultSearchResultOuter = (0, _styledComponents["default"])(_span.Span).withConfig({
  displayName: "DefaultSearchResultOuter",
  componentId: "sc-71kn0k-1"
})(["color:", ";background:", ";display:block;padding:0 20px;width:100%;text-align:left;box-shadow:", ";border-radius:inherit;line-height:1.4;&:hover{background:", ";}&:focus{border:solid ", " 2px;}"], (0, _branding.getPaletteColor)('greyscale-black'), (0, _branding.getPaletteColor)('white'), _defaultSearchResult.getBoxShadow, (0, _branding.getPaletteColor)('background'), (0, _branding.getPaletteColor)('greyscale-black'));