/******/ (() => { // webpackBootstrap
/******/ 	"use strict";
/******/ 	// The require scope
/******/ 	var __webpack_require__ = {};
/******/ 	
/************************************************************************/
/******/ 	/* webpack/runtime/make namespace object */
/******/ 	(() => {
/******/ 		// define __esModule on exports
/******/ 		__webpack_require__.r = (exports) => {
/******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ 			}
/******/ 			Object.defineProperty(exports, '__esModule', { value: true });
/******/ 		};
/******/ 	})();
/******/ 	
/************************************************************************/
var __webpack_exports__ = {};
/*!********************************!*\
  !*** ./extension/js/report.js ***!
  \********************************/
__webpack_require__.r(__webpack_exports__);
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
// js/report.js
// This script controls the 'Submit Report' popup window.

document.addEventListener('DOMContentLoaded', function () {
  // Get references to all the UI elements
  // THIS IS THE FIX: The ID is 'annotation-text', not 'annotationTextEl'
  var annotationTextEl = document.getElementById('annotation-text');
  var reportForm = document.getElementById('report-form');
  var reportReasonEl = document.getElementById('report-reason');
  var messageDiv = document.getElementById('message-div');
  var submitButton = reportForm.querySelector('button[type="submit"]');

  // --- State Variables ---
  var urlId = '';
  var anchorId = '';
  var annotationId = '';
  var annotationText = '';
  var anchorText = ''; // <--- ADDED THIS LINE to v2.2.1

  // --- Initialization ---
  // Get all the data passed in the URL from the annotation viewer
  var urlParams = new URLSearchParams(window.location.search);
  urlId = urlParams.get('urlId');
  anchorId = urlParams.get('anchorId');
  annotationId = urlParams.get('annotationId');
  annotationText = urlParams.get('annotationText');
  anchorText = urlParams.get('anchorText'); // <--- ADDED THIS LINE to v2.2.1

  // Display the annotation text so the user knows what they're reporting
  if (annotationText) {
    annotationTextEl.textContent = annotationText;
  }

  // --- Event Listeners ---

  // ADDITION: Add the no-paste functionality
  reportReasonEl.addEventListener('paste', function (e) {
    e.preventDefault();
    alert("Pasting text is not allowed. Please type your reason manually.");
  });

  // Make the function async so we can fetch the IP and URL
  reportForm.addEventListener('submit', /*#__PURE__*/function () {
    var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(e) {
      var reason, userIp, ipResponse, ipData, reportedUrl, tabs, _t, _t2, _t3;
      return _regenerator().w(function (_context) {
        while (1) switch (_context.p = _context.n) {
          case 0:
            e.preventDefault(); // Stop the form from submitting normally
            reason = reportReasonEl.value; // Show a loading message so the user knows it's working
            messageDiv.className = 'message';
            messageDiv.textContent = 'Gathering data and submitting report...';
            submitButton.disabled = true; // Prevent double-clicks
            _context.p = 1;
            // 1. Fetch the user's IP Address
            userIp = 'Unknown IP';
            _context.p = 2;
            _context.n = 3;
            return fetch('https://api.ipify.org?format=json');
          case 3:
            ipResponse = _context.v;
            _context.n = 4;
            return ipResponse.json();
          case 4:
            ipData = _context.v;
            userIp = ipData.ip;
            _context.n = 6;
            break;
          case 5:
            _context.p = 5;
            _t = _context.v;
            console.warn("Could not fetch IP address:", _t);
          case 6:
            // 2. Grab the URL of the active tab
            reportedUrl = 'Unknown URL';
            _context.p = 7;
            _context.n = 8;
            return chrome.tabs.query({
              active: true,
              lastFocusedWindow: true
            });
          case 8:
            tabs = _context.v;
            if (tabs && tabs.length > 0) {
              reportedUrl = tabs[0].url;
            }
            _context.n = 10;
            break;
          case 9:
            _context.p = 9;
            _t2 = _context.v;
            console.warn("Could not fetch tab URL:", _t2);
          case 10:
            // 3. Send all the report data to the background script
            chrome.runtime.sendMessage({
              type: 'reportAnnotation',
              target: 'background',
              data: {
                urlId: urlId,
                anchorId: anchorId,
                annotationId: annotationId,
                reason: reason,
                url: reportedUrl,
                // <-- NEW: Added URL
                ipAddress: userIp,
                // <-- NEW: Added IP
                // ADDED THESE TWO LINES HERE IN v2.2.1:
                reportedAnnotationText: annotationText,
                reportedAnchorText: anchorText
              }
            }, function (response) {
              if (chrome.runtime.lastError) {
                messageDiv.className = 'message error';
                messageDiv.textContent = "Error: ".concat(chrome.runtime.lastError.message);
                submitButton.disabled = false;
                return;
              }
              if (response && response.success) {
                messageDiv.className = 'message success';
                messageDiv.textContent = 'Report submitted successfully. This window will now close.';
                reportForm.style.display = 'none';

                // --- INSTANT GREYING SIGNAL ---
                // Broadcast the success signal to ALL open tabs to guarantee the webpage hears it
                chrome.tabs.query({}, function (tabs) {
                  var _iterator = _createForOfIteratorHelper(tabs),
                    _step;
                  try {
                    for (_iterator.s(); !(_step = _iterator.n()).done;) {
                      var tab = _step.value;
                      chrome.tabs.sendMessage(tab.id, {
                        action: 'reportSubmittedSuccessfully',
                        annotationId: annotationId
                      }, function () {
                        // This silent catch stops the red card errors
                        var ignoreError = chrome.runtime.lastError;
                      });
                    }
                  } catch (err) {
                    _iterator.e(err);
                  } finally {
                    _iterator.f();
                  }
                });

                // Close the window after 2 seconds
                setTimeout(function () {
                  window.close();
                }, 2000);
              } else {
                messageDiv.className = 'message error';
                messageDiv.textContent = "Error: ".concat((response === null || response === void 0 ? void 0 : response.error) || 'Unknown error');
                submitButton.disabled = false;
              }
            });
            _context.n = 12;
            break;
          case 11:
            _context.p = 11;
            _t3 = _context.v;
            messageDiv.className = 'message error';
            messageDiv.textContent = "System Error: ".concat(_t3.message);
            submitButton.disabled = false;
          case 12:
            return _context.a(2);
        }
      }, _callee, null, [[7, 9], [2, 5], [1, 11]]);
    }));
    return function (_x) {
      return _ref.apply(this, arguments);
    };
  }());
});
/******/ })()
;
//# sourceMappingURL=report.js.map