"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RegisterExternalStylesheetsUC = void 0;
exports.makeRegisterExternalStylesheetsUC = makeRegisterExternalStylesheetsUC;
exports.registerExternalStylesheets = registerExternalStylesheets;
const core_1 = require("@vived/core");
const AppDispatcher_1 = require("../Entities/AppDispatcher");
class RegisterExternalStylesheetsUC extends core_1.AppObjectUC {
    constructor() {
        super(...arguments);
        this.requestType = "REGISTER_EXTERNAL_STYLESHEETS";
    }
}
exports.RegisterExternalStylesheetsUC = RegisterExternalStylesheetsUC;
RegisterExternalStylesheetsUC.type = "RegisterExternalStylesheetsUC";
RegisterExternalStylesheetsUC.get = (appObjects) => (0, core_1.getSingletonComponent)(RegisterExternalStylesheetsUC.type, appObjects);
function makeRegisterExternalStylesheetsUC(appObject) {
    return new RegisterExternalStylesheetsUCImp(appObject);
}
function registerExternalStylesheets(stylesheets, appObjects) {
    const dispatchUC = RegisterExternalStylesheetsUC.get(appObjects);
    if (dispatchUC) {
        dispatchUC.doDispatch(stylesheets);
    }
    else {
        appObjects.submitWarning("registerExternalStylesheets", "Can't find DispatchStateChangeUC");
    }
}
class RegisterExternalStylesheetsUCImp extends RegisterExternalStylesheetsUC {
    constructor(appObject) {
        super(appObject, RegisterExternalStylesheetsUC.type);
        this.requestVersion = 1;
        this.doDispatch = (stylesheets) => {
            const payload = {
                stylesheets,
            };
            this.appDispatcher?.formRequestAndDispatch(this.requestType, this.requestVersion, payload);
        };
        this.appDispatcher = appObject.getComponent(AppDispatcher_1.AppDispatcher.type);
        if (!this.appDispatcher) {
            this.warn("DispatchStateChangeUC has been added to an App Object that does not have a AppDispatcher. Add a dispatcher first");
            this.dispose();
        }
    }
}
//# sourceMappingURL=RegisterExternalStylesheetsUC.js.map