text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  const request_1 = require("../../../../request");
  const clientsidepages_1 = require("./clientsidepages");
  const Utils_1 = require("../../../../Utils");
  class Page {
      static getPage(name, webUrl, cmd, debug, verbose) {
          return new Promise((resolve, reject) => {
              if (verbose) {
                  cmd.log(`Retrieving information about the page...`);
              }
              let pageName = name;
              if (pageName.indexOf('.aspx') < 0) {
                  pageName += '.aspx';
              }
              const requestOptions = {
                  url: `${webUrl}/_api/web/getfilebyserverrelativeurl('${Utils_1.default.getServerRelativeSiteUrl(webUrl)}/SitePages/${encodeURIComponent(pageName)}')?$expand=ListItemAllFields/ClientSideApplicationId`,
                  headers: {
                      'content-type': 'application/json;charset=utf-8',
                      accept: 'application/json;odata=nometadata'
                  },
                  json: true
              };
              request_1.default
                  .get(requestOptions)
                  .then((res) => {
                  if (res.ListItemAllFields.ClientSideApplicationId !== 'b6917cb1-93a0-4b97-a84d-7cf49975d4ec') {
                      reject(`Page ${name} is not a modern page.`);
                      return;
                  }
                  try {
                      resolve(clientsidepages_1.ClientSidePage.fromHtml(res.ListItemAllFields.CanvasContent1));
                  }
                  catch (e) {
                      reject(e);
                  }
              }, (error) => {
                  reject(error);
              });
          });
      }
      static getControlTypeDisplayName(controlType) {
          switch (controlType) {
              case 0:
                  return 'Empty column';
              case 3:
                  return 'Client-side web part';
              case 4:
                  return 'Client-side text';
              default:
                  return '' + controlType;
          }
      }
      static getControlsInformation(control, isJSONOutput) {
          // remove the column property to be able to serialize the object to JSON
          delete control.column;
          if (!isJSONOutput) {
              control.controlType = this.getControlTypeDisplayName(control.controlType);
          }
          if (!control.dynamicDataPaths) {
              delete control.dynamicDataPaths;
          }
          if (!control.dynamicDataValues) {
              delete control.dynamicDataValues;
          }
          return control;
      }
      static getColumnsInformation(column, isJSONOutput) {
          const output = {
              factor: column.factor,
              order: column.order
          };
          if (isJSONOutput) {
              output.dataVersion = column.dataVersion;
              output.jsonData = column.jsonData;
          }
          return output;
      }
      static getSectionInformation(section, isJSONOutput) {
          return {
              order: section.order,
              columns: section.columns.map(column => this.getColumnsInformation(column, isJSONOutput))
          };
      }
  }
  exports.Page = Page;
  //# sourceMappingURL=Page.js.map