"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const codicons = require("../../../base/common/codicons.js");
const event = require("../../../base/common/event.js");
const lifecycle = require("../../../base/common/lifecycle.js");
const instantiation = require("../../instantiation/common/instantiation.js");
const platform = require("../../registry/common/platform.js");
const theme = require("./theme.js");
const IThemeService = instantiation.createDecorator("themeService");
exports.ThemeColor = void 0;
(function(ThemeColor) {
  function isThemeColor(obj) {
    return obj && typeof obj === "object" && typeof obj.id === "string";
  }
  ThemeColor.isThemeColor = isThemeColor;
})(exports.ThemeColor || (exports.ThemeColor = {}));
function themeColorFromId(id) {
  return { id };
}
exports.ThemeIcon = void 0;
(function(ThemeIcon) {
  function isThemeIcon(obj) {
    return obj && typeof obj === "object" && typeof obj.id === "string" && (typeof obj.color === "undefined" || exports.ThemeColor.isThemeColor(obj.color));
  }
  ThemeIcon.isThemeIcon = isThemeIcon;
  const _regexFromString = new RegExp(`^\\$\\((${codicons.CSSIcon.iconNameExpression}(?:${codicons.CSSIcon.iconModifierExpression})?)\\)$`);
  function fromString(str) {
    const match = _regexFromString.exec(str);
    if (!match) {
      return void 0;
    }
    let [, name] = match;
    return { id: name };
  }
  ThemeIcon.fromString = fromString;
  function fromId(id) {
    return { id };
  }
  ThemeIcon.fromId = fromId;
  function modify(icon, modifier) {
    let id = icon.id;
    const tildeIndex = id.lastIndexOf("~");
    if (tildeIndex !== -1) {
      id = id.substring(0, tildeIndex);
    }
    if (modifier) {
      id = `${id}~${modifier}`;
    }
    return { id };
  }
  ThemeIcon.modify = modify;
  function getModifier(icon) {
    const tildeIndex = icon.id.lastIndexOf("~");
    if (tildeIndex !== -1) {
      return icon.id.substring(tildeIndex + 1);
    }
    return void 0;
  }
  ThemeIcon.getModifier = getModifier;
  function isEqual(ti1, ti2) {
    var _a, _b;
    return ti1.id === ti2.id && ((_a = ti1.color) === null || _a === void 0 ? void 0 : _a.id) === ((_b = ti2.color) === null || _b === void 0 ? void 0 : _b.id);
  }
  ThemeIcon.isEqual = isEqual;
  function asThemeIcon(codicon, color) {
    return { id: codicon.id, color: color ? themeColorFromId(color) : void 0 };
  }
  ThemeIcon.asThemeIcon = asThemeIcon;
  ThemeIcon.asClassNameArray = codicons.CSSIcon.asClassNameArray;
  ThemeIcon.asClassName = codicons.CSSIcon.asClassName;
  ThemeIcon.asCSSSelector = codicons.CSSIcon.asCSSSelector;
})(exports.ThemeIcon || (exports.ThemeIcon = {}));
function getThemeTypeSelector(type) {
  switch (type) {
    case theme.ColorScheme.DARK:
      return "vs-dark";
    case theme.ColorScheme.HIGH_CONTRAST:
      return "hc-black";
    default:
      return "vs";
  }
}
const Extensions = {
  ThemingContribution: "base.contributions.theming"
};
class ThemingRegistry {
  constructor() {
    this.themingParticipants = [];
    this.themingParticipants = [];
    this.onThemingParticipantAddedEmitter = new event.Emitter();
  }
  onColorThemeChange(participant) {
    this.themingParticipants.push(participant);
    this.onThemingParticipantAddedEmitter.fire(participant);
    return lifecycle.toDisposable(() => {
      const idx = this.themingParticipants.indexOf(participant);
      this.themingParticipants.splice(idx, 1);
    });
  }
  getThemingParticipants() {
    return this.themingParticipants;
  }
}
let themingRegistry = new ThemingRegistry();
platform.Registry.add(Extensions.ThemingContribution, themingRegistry);
function registerThemingParticipant(participant) {
  return themingRegistry.onColorThemeChange(participant);
}
class Themable extends lifecycle.Disposable {
  constructor(themeService) {
    super();
    this.themeService = themeService;
    this.theme = themeService.getColorTheme();
    this._register(this.themeService.onDidColorThemeChange((theme2) => this.onThemeChange(theme2)));
  }
  onThemeChange(theme2) {
    this.theme = theme2;
    this.updateStyles();
  }
  updateStyles() {
  }
}
exports.Extensions = Extensions;
exports.IThemeService = IThemeService;
exports.Themable = Themable;
exports.getThemeTypeSelector = getThemeTypeSelector;
exports.registerThemingParticipant = registerThemingParticipant;
exports.themeColorFromId = themeColorFromId;
