"use strict";

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

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

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

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

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

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

var CommentText = function CommentText(_ref) {
  var text = _ref.text,
      onClickTag = _ref.onClickTag;
  // markup @[__display__](user:__id__)
  var tags = text.match(/@\[.*?\]\(user:.*?\)/gi) || [];
  var otherText = text.split(/@\[.*?\]\(user:.*?\)/gi);
  return tags.reduce(function (display, myTag, index) {
    var tagDisplay = myTag.match(/\[.*?\]/gi)[0].slice(1, -1);
    var tagData = myTag.match(/\(user:.*?\)/gi)[0].slice(6, -1);
    return [].concat(_toConsumableArray(display), [/*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
      type: "button",
      onClick: function onClick() {
        return onClickTag("user", tagData);
      },
      className: "bg-blue-200 rounded",
      children: tagDisplay
    }, tagData), otherText[index + 1]]);
  }, [otherText[0]]);
};

exports.CommentText = CommentText;
CommentText.propTypes = {
  text: _propTypes.default.string.isRequired,
  onClickTag: _propTypes.default.func.isRequired
};