'use strict';

/**
 * Returns the current appearance, starts listening to the appearance change events and notifies the callback.
 *
 * @param callback
 */
function watchDeviceAppearance(callback) {
  window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (event) => {
    callback(event.matches ? 'dark' : 'light');
  });
  if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
    return 'dark';
  }
  return 'light';
}

exports.watchDeviceAppearance = watchDeviceAppearance;
