const editToggle = document.getElementById('editToggle');
const revIdLabel = document.getElementById('revId');
const apiUrl = document.getElementById('apiUrl');
const syncToken = document.getElementById('syncToken');

document.addEventListener('DOMContentLoaded', () => {
  chrome.storage.sync.get('apiUrl', (savedUrl) => {
    apiUrl.value = savedUrl.apiUrl || "No value stored";
  });

  chrome.storage.sync.get('syncToken', (savedToken) => {
    syncToken.value = savedToken.syncToken || "No value stored";
  });
});

editToggle.addEventListener('change', () => {
  if (editToggle.checked) {
    apiUrl.readOnly = false;
    syncToken.readOnly = false;
  }
  else {
    apiUrl.readOnly = true;
    syncToken.readOnly = true;
  }

});

apiUrl.addEventListener('input', () => {
  chrome.storage.sync.set({ apiUrl: apiUrl.value });
});

syncToken.addEventListener('input', () => {
  chrome.storage.sync.set({ syncToken: syncToken.value });
});