text: import { Validate, Guid } from '@microsoft/sp-core-library';
  import { SPComponentLoader } from '@microsoft/sp-loader';
  import ApplicationCustomizerContext from './ApplicationCustomizerContext';
  import CustomActionLocations from './customAction/CustomActionLocations';
  var ApplicationCustomizerContextFactory = /** @class */ (function () {
      function ApplicationCustomizerContextFactory(serviceScope) {
          this.applicationCustomizerTopHeight = 'preAllocatedApplicationCustomizerTopHeight';
          this.applicationCustomizerBottomHeight = 'preAllocatedApplicationCustomizerBottomHeight';
          this._cache = {};
          Validate.isNotNullOrUndefined(serviceScope, 'serviceScope');
          this._serviceScope = serviceScope;
      }
      ApplicationCustomizerContextFactory.prototype.initialize = function (customActions) {
          for (var _i = 0, customActions_1 = customActions; _i < customActions_1.length; _i++) {
              var customAction = customActions_1[_i];
              if (customAction.id) {
                  var id = customAction.id.toString();
                  if (id && customAction.location === CustomActionLocations.APPLICATION_CUSTOMIZER) {
                      if (!this._cache[id] || (this._cache[id] && this._cache[id].isDisposed)) {
                          this._cache[id] = this.createApplicationCustomizerContext(customAction);
                      }
                  }
              }
          }
      };
      ApplicationCustomizerContextFactory.prototype.getApplicationCustomizerContext = function (customAction) {
          Validate.isNotNullOrUndefined(customAction, 'customAction');
          if (customAction.id) {
              var id = customAction.id.toString();
              if (id) {
                  if (this._cache[id] && !this._cache[id].isDisposed) {
                      return this._cache[id];
                  }
                  var appCustomizerContext = this.createApplicationCustomizerContext(customAction);
                  this._cache[id] = appCustomizerContext;
                  return appCustomizerContext;
              }
          }
          return this.createApplicationCustomizerContext(customAction);
      };
      ApplicationCustomizerContextFactory.prototype.clear = function () {
          this._cache = {};
      };
      ApplicationCustomizerContextFactory.prototype.createApplicationCustomizerContext = function (customAction, extensionContextParameters, includeAllParams) {
          if (extensionContextParameters === void 0) { extensionContextParameters = {}; }
          if (includeAllParams === void 0) { includeAllParams = true; }
          var componentId = customAction.clientSideComponentId.toString();
          var topHeight = 0;
          var bottomHeight = 0;
          if (customAction.hostProperties) {
              topHeight = parseInt(JSON.parse(customAction.hostProperties)[this.applicationCustomizerTopHeight], 10)
                  || 0;
              bottomHeight = parseInt(JSON.parse(customAction.hostProperties)[this.applicationCustomizerBottomHeight], 10)
                  || 0;
          }
          var applicationCustomizerContextParameters = {
              sequence: customAction.sequence !== undefined ? customAction.sequence : 65535,
              preAllocatedApplicationCustomizerTopHeight: topHeight,
              preAllocatedApplicationCustomizerBottomHeight: bottomHeight
          };
          var applicationCustomizerContext;
          if (includeAllParams) {
              var manifest = SPComponentLoader.tryGetManifestById(componentId);
              if (!manifest) {
                  var error = new Error("Custom action with component id \"" + componentId + "\" didn't have a manifest.");
                  throw error;
              }
              var instanceId = Guid.newGuid().toString();
              var loggingTag = "Extension." + manifest.id + "." + instanceId;
              applicationCustomizerContext = new ApplicationCustomizerContext({ manifest: manifest,
                  parentServiceScope: this._serviceScope,
                  instanceId: instanceId,
                  loggingTag: loggingTag }, applicationCustomizerContextParameters);
          }
          else {
              applicationCustomizerContext = new ApplicationCustomizerContext(extensionContextParameters, applicationCustomizerContextParameters);
          }
          return applicationCustomizerContext;
      };
      return ApplicationCustomizerContextFactory;
  }());
  export default ApplicationCustomizerContextFactory;
  //# sourceMappingURL=ApplicationCustomizerContextFactory.js.map