"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ThemeProvider = exports.ThemeChangedEventArgs = void 0;
var tslib_1 = require("tslib");
var sp_core_library_1 = require("@microsoft/sp-core-library");
/**
 * The object passed when the IThemeProvider.themeChangedEvent is raised.
 *
 * @public
 */
var ThemeChangedEventArgs = /** @class */ (function (_super) {
    (0, tslib_1.__extends)(ThemeChangedEventArgs, _super);
    function ThemeChangedEventArgs() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return ThemeChangedEventArgs;
}(sp_core_library_1.SPEventArgs));
exports.ThemeChangedEventArgs = ThemeChangedEventArgs;
/**
 * The ThemeProvider class provides the capability to get different themes from the Framework. Themes can be provided
 * in different contexts, e.g. Canvas sections may provide a variant of the global theme in some contexts.
 *
 * @public
 */
var ThemeProvider = /** @class */ (function () {
    /**
     * Construct a new instance of the ThemeProvider class.
     *
     * @param serviceScope - The current service scope.
     * @param theme - Theme to provide.
     */
    function ThemeProvider(serviceScope, theme) {
        this._id = ThemeProvider._instanceCount++;
        this.themeChangedEvent = new sp_core_library_1.SPEvent(this._themeChangedEventName);
        if (theme) {
            this._theme = Object.freeze(theme);
        }
    }
    Object.defineProperty(ThemeProvider.prototype, "_themeChangedEventName", {
        get: function () {
            return ThemeProvider._themeChangedEventNameLiteral + this._id;
        },
        enumerable: false,
        configurable: true
    });
    /**
     * Clear the currently set theme and raise the themeChangedEvent.
     *
     * @internal
     */
    ThemeProvider.prototype._clearTheme = function () {
        this._theme = undefined;
        this._raiseEvent();
    };
    /**
     * Change the theme and raise the themeChangedEvent.
     *
     * @param theme - The new theme.
     *
     * @internal
     */
    ThemeProvider.prototype._setTheme = function (theme) {
        sp_core_library_1.Validate.isNotNullOrUndefined(theme, 'theme');
        this._theme = Object.freeze(theme);
        this._raiseEvent();
    };
    /**
     * If set, get the current scoped theme.
     */
    ThemeProvider.prototype.tryGetTheme = function () {
        return this._theme;
    };
    ThemeProvider.prototype._raiseEvent = function () {
        sp_core_library_1._SPEventManager.instance.raiseEvent(this._themeChangedEventName, {
            theme: this._theme
        });
    };
    /**
     * The service key for ThemeProvider.
     */
    ThemeProvider.serviceKey = sp_core_library_1.ServiceKey.create('sp-component-base.ThemeProvider', ThemeProvider);
    ThemeProvider._themeChangedEventNameLiteral = 'ThemeProvider.themeChangedEvent';
    /**
     * Used to register a unique event for each ThemeProvider instance by appending
     * the instance count to themeChangedEventNameLiteral.
     */
    ThemeProvider._instanceCount = 0;
    return ThemeProvider;
}());
exports.ThemeProvider = ThemeProvider;
//# sourceMappingURL=ThemeProvider.js.map