"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const dom = require("../../../base/browser/dom.js");
const event = require("../../../base/common/event.js");
const iconRegistry = require("../common/iconRegistry.js");
const themeService = require("../common/themeService.js");
function getIconsStyleSheet(themeService2) {
  const onDidChangeEmmiter = new event.Emitter();
  const iconRegistry$1 = iconRegistry.getIconRegistry();
  iconRegistry$1.onDidChange(() => onDidChangeEmmiter.fire());
  themeService2 === null || themeService2 === void 0 ? void 0 : themeService2.onDidProductIconThemeChange(() => onDidChangeEmmiter.fire());
  return {
    onDidChange: onDidChangeEmmiter.event,
    getCSS() {
      const productIconTheme = themeService2 ? themeService2.getProductIconTheme() : new UnthemedProductIconTheme();
      const usedFontIds = {};
      const formatIconRule = (contribution) => {
        const definition = productIconTheme.getIcon(contribution);
        if (!definition) {
          return void 0;
        }
        const fontContribution = definition.font;
        if (fontContribution) {
          usedFontIds[fontContribution.id] = fontContribution.definition;
          return `.codicon-${contribution.id}:before { content: '${definition.fontCharacter}'; font-family: ${dom.asCSSPropertyValue(fontContribution.id)}; }`;
        }
        return `.codicon-${contribution.id}:before { content: '${definition.fontCharacter}'; }`;
      };
      const rules = [];
      for (let contribution of iconRegistry$1.getIcons()) {
        const rule = formatIconRule(contribution);
        if (rule) {
          rules.push(rule);
        }
      }
      for (let id in usedFontIds) {
        const definition = usedFontIds[id];
        const fontWeight = definition.weight ? `font-weight: ${definition.weight};` : "";
        const fontStyle = definition.style ? `font-style: ${definition.style};` : "";
        const src = definition.src.map((l) => `${dom.asCSSUrl(l.location)} format('${l.format}')`).join(", ");
        rules.push(`@font-face { src: ${src}; font-family: ${dom.asCSSPropertyValue(id)};${fontWeight}${fontStyle} font-display: block; }`);
      }
      return rules.join("\n");
    }
  };
}
class UnthemedProductIconTheme {
  getIcon(contribution) {
    const iconRegistry$1 = iconRegistry.getIconRegistry();
    let definition = contribution.defaults;
    while (themeService.ThemeIcon.isThemeIcon(definition)) {
      const c = iconRegistry$1.getIcon(definition.id);
      if (!c) {
        return void 0;
      }
      definition = c.defaults;
    }
    return definition;
  }
}
exports.UnthemedProductIconTheme = UnthemedProductIconTheme;
exports.getIconsStyleSheet = getIconsStyleSheet;
