import ext from "./utils/ext";
import storage from "./utils/storage";

var urlInput = document.querySelector("[name=url]");
var tokenInput = document.querySelector("[name=token]");
var message = document.getElementById("msg");

storage.get('url', function(resp) {
    urlInput.value = resp.url || "https://app.readlater.shikiryu.com";
});

storage.get('token', function(resp) {
    tokenInput.value = resp.token;
});

urlInput.addEventListener("blur", function(e) {
    var value = this.value;
    storage.set({ url: value }, function() {
      message.innerHTML = ext.i18n.getMessage("URLChanged");
    });
});

tokenInput.addEventListener("blur", function(e) {
    var value = this.value;
    storage.set({ token: value }, function() {
      message.innerHTML = ext.i18n.getMessage("tokenSaved");
    });
});

document.querySelectorAll("[data-message]").forEach(function(elt) {
   elt.innerHTML = ext.i18n.getMessage(elt.dataset.message);
});
