Hooks.once("init", function () {
  const MODULE_ID = "cm-ecos-del-pasado";
  const MODULE_VERSION_KEY = "moduleVersion";
  game.settings.register(MODULE_ID, MODULE_VERSION_KEY, {
    config: false,
    scope: "world",
    type: String,
    default: ""
  });
});

Hooks.on("ready", async function () {
  const MODULE_ID = "cm-ecos-del-pasado";
  const MODULE_VERSION_KEY = "moduleVersion";
  const PACK_ID = "cm-ecos-del-pasado.aventura";

  if (game.user.isGM) {
    const module = game.modules.get(MODULE_ID);
    const storedVersion = game.settings.get(MODULE_ID, MODULE_VERSION_KEY);
    if (!storedVersion || foundry.utils.isNewerVersion(module.version, storedVersion)) {
      const pack = game.packs.get(PACK_ID);
      for (const content of pack.index.contents) {
        const adventure = await pack.getDocument(content._id);
        await adventure.sheet.render(true);
      }
      game.settings.set(MODULE_ID, MODULE_VERSION_KEY, module.version);
    }
  }
});