(function () {
  'use strict';

  var choice = 'system';
  try {
    choice = localStorage.getItem('iav_theme') || 'system';
  } catch (error) {
    choice = 'system';
  }

  if (['system', 'light', 'dark'].indexOf(choice) === -1) {
    choice = 'system';
  }

  var resolved = choice === 'system'
    ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')
    : choice;

  document.documentElement.dataset.theme = resolved;
  document.documentElement.dataset.themeChoice = choice;
}());
