"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var sp_core_library_1 = require("@microsoft/sp-core-library");
// Copyright (c) Microsoft. All rights reserved.
/**
 * Class to load async chunks.
 *
 * @internal
 */
var LegacyThirdPartyFabricCoreLoader = /** @class */ (function () {
    function LegacyThirdPartyFabricCoreLoader() {
    }
    /**
     * Method to dynamically load the legacy third-party fabric core styles.
     * This method should be called only when a third-party component(web part or extension)
     * is being loaded on to the page.
     *
     * NOTE: Remove this method when the below killswitch is graduated from \@microsoft/sp-webpart-base.
     * 'isStopLoadingLegacyFabricCSSKillSwitchActivated' - '57b771ed-2b57-41c2-aaaa-0e21c587c6dc'
     *
     * @param isComponentInternal - indicates whether the requesting component is internal to Microsoft or not.
     */
    LegacyThirdPartyFabricCoreLoader.load = function (isComponentInternal) {
        if (!isComponentInternal && !LegacyThirdPartyFabricCoreLoader.isLoaded) {
            return Promise.resolve().then(function () { return __importStar(require(
            /* webpackChunkName: 'legacy-third-party-fabric-core-localfont' */ './chunks/legacy-third-party-fabric-core/FabricLocalFont')); }).then(function () {
                LegacyThirdPartyFabricCoreLoader.isLoaded = true;
                return;
            });
        }
        else {
            return Promise.resolve();
        }
    };
    /**
     * Method to dynamically force load the legacy third-party fabric core styles.
     * All the below conditions are checked and needs to be true to force load the legacy css:
     *   1. Should be third party component (web part or extension)
     *   2. Should not be already loaded
     *   3. Component should ask to load the legacy css or if the component is built version \< 1.8
     *
     * @param manifest - component's manifest
     */
    LegacyThirdPartyFabricCoreLoader.forceLoad = function (manifest) {
        try {
            if (LegacyThirdPartyFabricCoreLoader._shouldLoad(manifest)) {
                return Promise.resolve().then(function () { return __importStar(require(
                /* webpackChunkName: 'legacy-third-party-fabric-core-localfont' */ './chunks/legacy-third-party-fabric-core/FabricLocalFont')); }).then(function () {
                    LegacyThirdPartyFabricCoreLoader.isLoaded = true;
                    return;
                });
            }
            else {
                return Promise.resolve();
            }
        }
        catch (error) {
            return Promise.reject(error);
        }
    };
    /**
     * Method to check if the web part need to load the legacy css.
     * @param manifest - component's manifest
     */
    LegacyThirdPartyFabricCoreLoader.needLegacyFabricCss = function (manifest) {
        if (manifest.isInternal) {
            return false;
        }
        /*
         * If loadLegacyFabricCss is not specified by the component, then load the css
         * if the component is built before SPFx 1.8.2 or in some cases when we cannot get
         * the version of the SPFx.
         */
        if (manifest.loadLegacyFabricCss === undefined) {
            var version = sp_core_library_1.Version._tryParseSPFxVersion(manifest);
            return !version || version.lessThan(sp_core_library_1.Version.parse('1.8.2'));
        }
        // Respect 'loadLegacyFabricCss' if a real value is provided.
        return manifest.loadLegacyFabricCss;
    };
    LegacyThirdPartyFabricCoreLoader._shouldLoad = function (manifest) {
        return (!LegacyThirdPartyFabricCoreLoader.isLoaded &&
            LegacyThirdPartyFabricCoreLoader.needLegacyFabricCss(manifest));
    };
    /**
     * Indicates whether the fabric-core styles are loaded on the page or not.
     */
    LegacyThirdPartyFabricCoreLoader.isLoaded = false;
    return LegacyThirdPartyFabricCoreLoader;
}());
exports.default = LegacyThirdPartyFabricCoreLoader;
//# sourceMappingURL=LegacyThirdPartyFabricCoreLoader.js.map