"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireDefault(require("styled-components"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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; }
var StyledHiglightedText = _styledComponents.default.span.withConfig({
  displayName: "useHighlightText__StyledHiglightedText",
  componentId: "sc-13agf6o-0"
})(["background-color:var(--color-primary-200);"]);
StyledHiglightedText.displayName = "StyledHiglightedText";
var useHighlightText = function useHighlightText(text, searchBy) {
  var matchCase = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  var textComparator = text;
  var searchByComparator = searchBy;
  if (!matchCase) {
    textComparator = text.toLowerCase();
    searchByComparator = searchBy.toLowerCase();
  }
  if (searchBy && textComparator && textComparator.indexOf(searchByComparator) >= 0) {
    var beforeHighlighted = text.substring(0, textComparator.indexOf(searchByComparator));
    var highLighted = text.substring(textComparator.indexOf(searchByComparator), textComparator.indexOf(searchByComparator) + searchBy.length);
    var afterHighlighted = text.substring(textComparator.indexOf(searchByComparator) + searchBy.length);
    return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, beforeHighlighted.replace(/ /g, "\u00a0"), /*#__PURE__*/_react.default.createElement(StyledHiglightedText, {
      className: "c-option--text__highlight"
    }, highLighted.replace(/ /g, "\u00a0")), afterHighlighted.replace(/ /g, "\u00a0"));
  }
  return text;
};
var _default = exports.default = useHighlightText;
//# sourceMappingURL=useHighlightText.js.map