/******/ (() => { // 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/popup.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 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/popup.js
document.addEventListener('DOMContentLoaded', function () {
  // --- UI ELEMENTS ---
  var activeView = document.getElementById('active-view');
  var inactiveView = document.getElementById('inactive-view');
  var authActions = document.getElementById('auth-actions');
  var userActions = document.getElementById('user-actions');
  var statusDiv = document.getElementById('auth-status');
  var creditsDisplay = document.getElementById('v2-credits-display');

  // Modal Elements
  var customModal = document.getElementById('custom-confirm-modal');
  var confirmMessage = document.getElementById('confirm-message');
  var confirmButtons = document.getElementById('confirm-buttons');
  var successButtons = document.getElementById('success-buttons');
  var modalCancelBtn = document.getElementById('modal-cancel-btn');
  var modalConfirmBtn = document.getElementById('modal-confirm-btn');
  var modalOkBtn = document.getElementById('modal-ok-btn');

  // Forms
  var loginForm = document.getElementById('login-form');
  var registerForm = document.getElementById('register-form');

  // Buttons
  var showLoginBtn = document.getElementById('show-login-btn');
  var showRegisterBtn = document.getElementById('show-register-btn');
  var signoutBtn = document.getElementById('signout-btn');
  var deactivateBtn = document.getElementById('deactivate-btn');
  var activateBtn = document.getElementById('activate-btn');
  // Removed websiteBtn
  var buyCreditsBtn = document.getElementById('buy-credits-btn');
  var deleteAccountBtn = document.getElementById('delete-account-btn');
  // NEW Elements for Profile Views
  var checkViewsBtn = document.getElementById('check-views-btn');
  var viewsContainer = document.getElementById('views-container');
  var viewsList = document.getElementById('views-list');
  var backFromViewsBtn = document.getElementById('back-from-views-btn');
  var btnProfile = document.getElementById('btn-profile');

  // --- 1. INITIAL STATE CHECK ---
  chrome.storage.local.get(['isActive'], function (result) {
    var isActive = result.isActive !== false;
    updateView(isActive);
  });
  function updateView(isActive) {
    if (isActive) {
      activeView.style.display = 'block';
      inactiveView.style.display = 'none';
      chrome.action.setBadgeText({
        text: ""
      });
      checkAuthStatus();
    } else {
      activeView.style.display = 'none';
      inactiveView.style.display = 'block';
      chrome.action.setBadgeText({
        text: "OFF"
      });
      chrome.action.setBadgeBackgroundColor({
        color: "#666666"
      });
    }
  }

  // --- 2. TOGGLE EXTENSION LOGIC ---
  deactivateBtn.addEventListener('click', function () {
    chrome.storage.local.set({
      isActive: false
    }, function () {
      updateView(false);
      chrome.tabs.reload();
    });
  });
  activateBtn.addEventListener('click', function () {
    chrome.storage.local.set({
      isActive: true
    }, function () {
      updateView(true);
      chrome.tabs.reload();
    });
  });

  // --- 3. AUTH & CREDIT LOGIC ---
  function checkAuthStatus() {
    chrome.runtime.sendMessage({
      type: 'getAuthStatus',
      target: 'background'
    }, function (response) {
      if (response && response.user) {
        statusDiv.textContent = "User: ".concat(response.user.email);
        statusDiv.style.color = '#28a745';
        authActions.style.display = 'none';
        loginForm.style.display = 'none';
        registerForm.style.display = 'none';
        userActions.style.display = 'block';
        fetchUserCredits(response.user.uid);
      } else {
        statusDiv.textContent = 'You are not signed in.';
        statusDiv.style.color = '#555';
        authActions.style.display = 'block';
        userActions.style.display = 'none';
      }
    });
  }
  function fetchUserCredits(uid) {
    chrome.runtime.sendMessage({
      type: 'getUserData',
      target: 'background',
      data: {
        uid: uid
      }
    }, function (response) {
      if (response && response.data) {
        creditsDisplay.textContent = response.data.creditsBalance || '0';
      }
    });
  }

  // --- 4. INLINE AUTH HANDLERS ---
  showLoginBtn.addEventListener('click', function () {
    authActions.style.display = 'none';
    loginForm.style.display = 'block';
  });
  showRegisterBtn.addEventListener('click', function () {
    authActions.style.display = 'none';
    registerForm.style.display = 'block';
  });
  document.getElementById('back-to-auth-btn').addEventListener('click', function () {
    loginForm.style.display = 'none';
    authActions.style.display = 'block';
  });
  document.getElementById('back-to-auth-reg-btn').addEventListener('click', function () {
    registerForm.style.display = 'none';
    authActions.style.display = 'block';
  });

  // Handle Login Submit
  document.getElementById('submit-login-btn').addEventListener('click', function () {
    var email = document.getElementById('login-email').value;
    var pass = document.getElementById('login-password').value;
    var errorMsg = document.getElementById('login-error');
    chrome.runtime.sendMessage({
      type: 'signInUser',
      target: 'background',
      data: {
        email: email,
        password: pass
      }
    }, function (response) {
      if (response.success) {
        checkAuthStatus();
      } else {
        errorMsg.textContent = response.error;
        errorMsg.style.display = 'block';
      }
    });
  });

  // --- NEW: FORGOT PASSWORD FLOW ---
  document.getElementById('forgot-password-link').addEventListener('click', function (e) {
    e.preventDefault();
    var emailInput = document.getElementById('login-email').value.trim();
    var errorEl = document.getElementById('login-error');
    var msgEl = document.getElementById('reset-msg');
    errorEl.style.display = 'none';
    msgEl.style.display = 'none';
    if (!emailInput) {
      errorEl.textContent = "Please enter your email address in the box above first.";
      errorEl.style.display = 'block';
      return;
    }
    chrome.runtime.sendMessage({
      type: 'resetPassword',
      // Assuming your background.js handles this type
      target: 'background',
      data: {
        email: emailInput
      }
    }, function (response) {
      if (response && response.success) {
        msgEl.textContent = "Password reset email sent! Check your inbox.If you do not see it, check your spam folder.";
        msgEl.style.display = 'block';
      } else {
        errorEl.textContent = response.error || "Failed to send reset email.";
        errorEl.style.display = 'block';
      }
    });
  });
  // ---------------------------------

  // Handle Register Submit
  document.getElementById('submit-register-btn').addEventListener('click', function () {
    var username = document.getElementById('reg-username').value;
    var email = document.getElementById('reg-email').value;
    var pass = document.getElementById('reg-password').value;
    var errorMsg = document.getElementById('reg-error');
    if (!username || username.trim().length < 3) {
      errorMsg.textContent = "Username must be at least 3 characters.";
      errorMsg.style.display = 'block';
      return;
    }
    chrome.runtime.sendMessage({
      type: 'registerUser',
      target: 'background',
      data: {
        username: username,
        email: email,
        password: pass
      }
    }, function (response) {
      if (response.success) {
        registerForm.style.display = 'none';
        document.getElementById('reg-success-screen').style.display = 'block';
      } else {
        errorMsg.textContent = response.error;
        errorMsg.style.display = 'block';
      }
    });
  });
  document.getElementById('close-success-btn').addEventListener('click', function () {
    document.getElementById('reg-success-screen').style.display = 'none';
    checkAuthStatus();
  });
  signoutBtn.addEventListener('click', function () {
    chrome.runtime.sendMessage({
      type: 'signOutUser',
      target: 'background'
    }, function (response) {
      if (response.success) checkAuthStatus();
    });
  });

  // --- 5. ACCOUNT & NAVIGATION LINKS ---

  // --- NEW: Open Profile & Settings Page ---
  document.getElementById('btn-profile').addEventListener('click', function () {
    // This bypasses the old options page and opens our new profile page directly
    chrome.tabs.create({
      url: chrome.runtime.getURL('html/profile.html')
    });
  });

  // 1. Show the custom modal when "Close Account" is clicked
  deleteAccountBtn.addEventListener('click', function () {
    // Reset the modal back to its default warning state
    confirmMessage.textContent = "Are you sure you want to close your account? This will take effect in 72 hours.";
    confirmMessage.style.color = "#333";
    confirmButtons.style.display = "flex";
    successButtons.style.display = "none";

    // Unhide the modal using Flexbox so it centers perfectly
    customModal.style.display = 'flex';
  });

  // 2. Hide the modal if they click Cancel
  modalCancelBtn.addEventListener('click', function () {
    customModal.style.display = 'none';
  });

  // 3. Process the deletion if they click Confirm
  modalConfirmBtn.addEventListener('click', function () {
    // Briefly disable the button so they don't double-click it
    modalConfirmBtn.textContent = "Processing...";
    modalConfirmBtn.disabled = true;
    chrome.runtime.sendMessage({
      type: 'requestAccountDeletion',
      target: 'background'
    }, function (response) {
      // Re-enable the button in the background
      modalConfirmBtn.textContent = "Close Account";
      modalConfirmBtn.disabled = false;

      // Switch the modal UI to the success state (replacing the native 'alert')
      confirmMessage.textContent = "Request received. Your account is scheduled for deletion.";
      confirmMessage.style.color = "#28a745"; // Green success text
      confirmButtons.style.display = "none";
      successButtons.style.display = "block";
    });
  });

  // 4. Close the modal when they acknowledge the success message
  modalOkBtn.addEventListener('click', function () {
    customModal.style.display = 'none';
  });
  buyCreditsBtn.addEventListener('click', function () {
      chrome.tabs.create({
      url: 'https://anotato.com/buy.html'
    });
   });
  // --- NEW: WHO VIEWED MY PROFILE LOGIC ---
  checkViewsBtn.addEventListener('click', function () {
    // Hide standard menu buttons to save space
    checkViewsBtn.style.display = 'none';
    btnProfile.style.display = 'none';
    buyCreditsBtn.style.display = 'none';
    signoutBtn.style.display = 'none';
    deleteAccountBtn.style.display = 'none';

    // Show the list container
    viewsContainer.style.display = 'block';
    viewsList.innerHTML = '<p style="text-align:center; color:#555;">Scanning database...</p>';
    chrome.runtime.sendMessage({
      type: 'checkProfileViews',
      target: 'background'
    }, function (response) {
      if (response && response.success) {
        viewsList.innerHTML = '';
        if (response.data.length === 0) {
          viewsList.innerHTML = "<p style=\"color: #28a745; text-align:center; font-weight:bold;\">".concat(response.message, "</p>");
        } else {
          // Populate the list
          response.data.forEach(function (view) {
            var div = document.createElement('div');
            div.style.padding = '6px 0';
            div.style.borderBottom = '1px solid #eee';
            div.innerHTML = "<strong>".concat(view.viewerName, "</strong> <span style=\"color:#777; float:right;\">").concat(view.timestamp, "</span>");
            viewsList.appendChild(div);
          });

          // Refresh the user's credits display since they just paid 1 credit!
          chrome.storage.local.get(['isActive'], function () {
            return checkAuthStatus();
          });
        }
      } else {
        viewsList.innerHTML = "<p style=\"color: red; text-align:center;\">Error: ".concat(response ? response.error : 'Unknown', "</p>");
      }
    });
  });
  backFromViewsBtn.addEventListener('click', function () {
    // Hide container and bring the menu back
    viewsContainer.style.display = 'none';
    checkViewsBtn.style.display = 'block';
    btnProfile.style.display = 'block';
    buyCreditsBtn.style.display = 'block';
    signoutBtn.style.display = 'block';
    deleteAccountBtn.style.display = 'block';
  });
});

// --- 6. MOBILE SUPPORT (Annotate Selection) ---
document.addEventListener('DOMContentLoaded', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
  var mobileContainer, annotateBtn, platformInfo, isMobile;
  return _regenerator().w(function (_context) {
    while (1) switch (_context.n) {
      case 0:
        mobileContainer = document.getElementById('mobile-actions');
        annotateBtn = document.getElementById('btn-annotate-selection');
        _context.n = 1;
        return chrome.runtime.getPlatformInfo();
      case 1:
        platformInfo = _context.v;
        isMobile = platformInfo.os === 'android' || /iPhone|iPad|iPod/.test(navigator.userAgent);
        if (isMobile && mobileContainer) {
          mobileContainer.style.display = 'block';
        }
        if (annotateBtn) {
          annotateBtn.addEventListener('click', function () {
            chrome.tabs.query({
              active: true,
              currentWindow: true
            }, function (tabs) {
              var currentTab = tabs[0];
              if (currentTab) {
                chrome.runtime.sendMessage({
                  target: 'background',
                  type: 'triggerMobileAnnotation',
                  data: {
                    tabId: currentTab.id
                  }
                });
                window.close();
              }
            });
          });
        }
      case 2:
        return _context.a(2);
    }
  }, _callee);
})));
/******/ })()
;
//# sourceMappingURL=popup.js.map
