import { library } from './library.default.mjs';
export { addIcons } from './library.default.mjs';
import systemLibrary from './library.system.mjs';

let registry = [library, systemLibrary];
let watchedIcons = [];
function watchIcon(icon) {
  watchedIcons.push(icon);
}
function unwatchIcon(icon) {
  watchedIcons = watchedIcons.filter((el) => el !== icon);
}
function getIconLibrary(name) {
  return registry.find((lib) => lib.name === name);
}
function registerIconLibrary(name, options) {
  unregisterIconLibrary(name);
  registry.push({
    name,
    resolver: options.resolver,
    mutator: options.mutator
  });
  watchedIcons.forEach((icon) => {
    if (icon.library === name) {
      icon.setIcon();
    }
  });
}
function redrawWatchedIcons() {
  for (const icon of watchedIcons) {
    icon.setIcon();
  }
}
function unregisterIconLibrary(name) {
  registry = registry.filter((lib) => lib.name !== name);
}

export { getIconLibrary, redrawWatchedIcons, registerIconLibrary, unregisterIconLibrary, unwatchIcon, watchIcon };
